Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds cmd option to just check config #256

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dataplane/dataplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ eResult cDataPlane::init(const std::string& binaryPath,
return result;
}

eResult cDataPlane::DryRun(const std::string& configFilePath)
{
Comment on lines +268 to +269
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
eResult cDataPlane::DryRun(const std::string& configFilePath)
{
eResult cDataPlane::DryRun(std::string_view configFilePath)
{

We can use lightweight wrapper around const char* instead of creating dynamic std::string

return parseConfig(configFilePath);
}
Comment on lines +270 to +271
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that means this function should also accept std::string_view, which in turn implies that init function should accept std::string_view.

In parseConfig we should do this, instead of creating std::ifstream from std::string:

eResult cDataPlane::parseConfig(std::string_view configFilePath)
{
    eResult result = eResult::success;
    std::filesystem::path path(configFilePath);
    std::ifstream fromFileStream(path);

In summary, the following diff is all we need:

diff --git a/dataplane/dataplane.cpp b/dataplane/dataplane.cpp
index 97d9c20..fcf4577 100644
--- a/dataplane/dataplane.cpp
+++ b/dataplane/dataplane.cpp
@@ -74,7 +74,7 @@ cDataPlane::~cDataPlane()
 }
 
 eResult cDataPlane::init(const std::string& binaryPath,
-                         const std::string& configFilePath)
+                         std::string_view configFilePath)
 {
 	eResult result = eResult::success;
 
@@ -265,7 +265,7 @@ eResult cDataPlane::init(const std::string& binaryPath,
 	return result;
 }
 
-eResult cDataPlane::DryRun(const std::string& configFilePath)
+eResult cDataPlane::DryRun(std::string_view configFilePath)
 {
 	return parseConfig(configFilePath);
 }
@@ -1867,11 +1867,12 @@ void cDataPlane::switch_worker_base()
 	controlPlane->switchBase();
 }
 
-eResult cDataPlane::parseConfig(const std::string& configFilePath)
+eResult cDataPlane::parseConfig(std::string_view configFilePath)
 {
 	eResult result = eResult::success;
+	std::filesystem::path path(configFilePath);
+	std::ifstream fromFileStream(path);
 
-	std::ifstream fromFileStream(configFilePath);
 	if (!fromFileStream.is_open())
 	{
 		YADECAP_LOG_ERROR("can't open file '%s'\n", configFilePath.data());
diff --git a/dataplane/dataplane.h b/dataplane/dataplane.h
index f1437ee..fc737f6 100644
--- a/dataplane/dataplane.h
+++ b/dataplane/dataplane.h
@@ -99,8 +99,8 @@ public:
 	~cDataPlane();
 
 	eResult init(const std::string& binaryPath,
-	             const std::string& configFilePath);
-	eResult DryRun(const std::string& configFilePath);
+	             std::string_view configFilePath);
+	eResult DryRun(std::string_view configFilePath);
 
 	void start();
 	void join();
@@ -122,7 +122,7 @@ public:
 	std::string InterfaceNameFromPort(tPortId id) { return std::get<0>(ports[id]); };
 
 protected:
-	eResult parseConfig(const std::string& configFilePath);
+	eResult parseConfig(std::string_view configFilePath);
 	eResult parseJsonPorts(const nlohmann::json& json);
 	std::optional<std::map<tCoreId, CPlaneWorkerConfig>> parseControlPlaneWorkers(const nlohmann::json& config);
 	std::optional<std::pair<tCoreId, CPlaneWorkerConfig>> parseControlPlaneWorker(const nlohmann::json& cpwj);


std::string rss_flags_to_string(uint64_t rss_flags)
{
std::string flag_names;
Expand Down
1 change: 1 addition & 0 deletions dataplane/dataplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class cDataPlane

eResult init(const std::string& binaryPath,
const std::string& configFilePath);
eResult DryRun(const std::string& configFilePath);

Comment on lines +103 to 104
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

void start();
void join();
Expand Down
14 changes: 13 additions & 1 deletion dataplane/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,36 @@ int main(int argc,
return 1;
#endif

bool dry_run = false;
int config = argc;
for (int i = 1; i < argc; i++)
{
if (strcmp(argv[i], "-d") == 0)
{
common::log::logPriority = common::log::TLOG_DEBUG;
}
else if (strcmp(argv[i], "-t") == 0)
{
dry_run = true;
}
else if (strcmp(argv[i], "-c") == 0)
{
config = i + 1;
++i;
}
}
if (config >= argc)
{
std::cout << "usage: " << argv[0] << " [-d] -c <dataplane.conf>" << std::endl;
std::cout << "usage: " << argv[0] << " [-d] [-t] -c <dataplane.conf>" << std::endl;
return 1;
}

if (dry_run)
{
eResult res = dataPlane.DryRun(argv[config]);
return (res == eResult::success) ? 0 : 2;
}

auto result = dataPlane.init(argv[0], argv[config]);
if (result != eResult::success)
{
Expand Down
Loading