DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] examples/pipeline: print table entries to file
@ 2022-01-12 18:35 Cristian Dumitrescu
  2022-01-12 18:59 ` [PATCH V2] " Cristian Dumitrescu
  0 siblings, 1 reply; 3+ messages in thread
From: Cristian Dumitrescu @ 2022-01-12 18:35 UTC (permalink / raw)
  To: dev; +Cc: Harshad Narayane

Add support for the show CLI command to print table entries to a file
instead of standard output.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Harshad Narayane <harshad.suresh.narayane@intel.com>
---
 examples/pipeline/cli.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c
index c32349e5f0..2278bcbd51 100644
--- a/examples/pipeline/cli.c
+++ b/examples/pipeline/cli.c
@@ -1346,7 +1346,7 @@ cmd_pipeline_table_default(char **tokens,
 }
 
 static const char cmd_pipeline_table_show_help[] =
-"pipeline <pipeline_name> table <table_name> show\n";
+"pipeline <pipeline_name> table <table_name> show [filename]\n";
 
 static void
 cmd_pipeline_table_show(char **tokens,
@@ -1357,9 +1357,10 @@ cmd_pipeline_table_show(char **tokens,
 {
 	struct pipeline *p;
 	char *pipeline_name, *table_name;
+	FILE *file = NULL;
 	int status;
 
-	if (n_tokens != 5) {
+	if (n_tokens != 5 && n_tokens != 6) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
@@ -1372,9 +1373,18 @@ cmd_pipeline_table_show(char **tokens,
 	}
 
 	table_name = tokens[3];
-	status = rte_swx_ctl_pipeline_table_fprintf(stdout, p->ctl, table_name);
+	file = (n_tokens == 6) ? fopen(tokens[5] , "w") : stdout;
+	if (!file) {
+		snprintf(out, out_size, "Cannot open file %s.\n", tokens[5]);
+		return;
+	}
+
+	status = rte_swx_ctl_pipeline_table_fprintf(file, p->ctl, table_name);
 	if (status)
 		snprintf(out, out_size, MSG_ARG_INVALID, "table_name");
+
+	if (file)
+		fclose(file);
 }
 
 static const char cmd_pipeline_selector_group_add_help[] =
@@ -1806,7 +1816,7 @@ cmd_pipeline_selector_group_member_delete(char **tokens,
 }
 
 static const char cmd_pipeline_selector_show_help[] =
-"pipeline <pipeline_name> selector <selector_name> show\n";
+"pipeline <pipeline_name> selector <selector_name> show [filename]\n";
 
 static void
 cmd_pipeline_selector_show(char **tokens,
@@ -1817,9 +1827,10 @@ cmd_pipeline_selector_show(char **tokens,
 {
 	struct pipeline *p;
 	char *pipeline_name, *selector_name;
+	FILE *file = NULL;
 	int status;
 
-	if (n_tokens != 5) {
+	if (n_tokens != 5 && n_tokens != 6) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
@@ -1832,10 +1843,19 @@ cmd_pipeline_selector_show(char **tokens,
 	}
 
 	selector_name = tokens[3];
-	status = rte_swx_ctl_pipeline_selector_fprintf(stdout,
-		p->ctl, selector_name);
+
+	file = (n_tokens == 6) ? fopen(tokens[5], "w") : stdout;
+	if (!file) {
+		snprintf(out, out_size, "Cannot open file %s.\n", tokens[5]);
+		return;
+	}
+
+	status = rte_swx_ctl_pipeline_selector_fprintf(file, p->ctl, selector_name);
 	if (status)
 		snprintf(out, out_size, MSG_ARG_INVALID, "selector_name");
+
+	if (file)
+		fclose(file);
 }
 
 static int
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH V2] examples/pipeline: print table entries to file
  2022-01-12 18:35 [PATCH] examples/pipeline: print table entries to file Cristian Dumitrescu
@ 2022-01-12 18:59 ` Cristian Dumitrescu
  2022-02-13 20:50   ` Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: Cristian Dumitrescu @ 2022-01-12 18:59 UTC (permalink / raw)
  To: dev; +Cc: Harshad Narayane

Add support for the show CLI command to print table entries to a file
instead of standard output.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Harshad Narayane <harshad.suresh.narayane@intel.com>
---
 examples/pipeline/cli.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c
index c32349e5f0..edae63dae6 100644
--- a/examples/pipeline/cli.c
+++ b/examples/pipeline/cli.c
@@ -1346,7 +1346,7 @@ cmd_pipeline_table_default(char **tokens,
 }
 
 static const char cmd_pipeline_table_show_help[] =
-"pipeline <pipeline_name> table <table_name> show\n";
+"pipeline <pipeline_name> table <table_name> show [filename]\n";
 
 static void
 cmd_pipeline_table_show(char **tokens,
@@ -1357,9 +1357,10 @@ cmd_pipeline_table_show(char **tokens,
 {
 	struct pipeline *p;
 	char *pipeline_name, *table_name;
+	FILE *file = NULL;
 	int status;
 
-	if (n_tokens != 5) {
+	if (n_tokens != 5 && n_tokens != 6) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
@@ -1372,9 +1373,18 @@ cmd_pipeline_table_show(char **tokens,
 	}
 
 	table_name = tokens[3];
-	status = rte_swx_ctl_pipeline_table_fprintf(stdout, p->ctl, table_name);
+	file = (n_tokens == 6) ? fopen(tokens[5], "w") : stdout;
+	if (!file) {
+		snprintf(out, out_size, "Cannot open file %s.\n", tokens[5]);
+		return;
+	}
+
+	status = rte_swx_ctl_pipeline_table_fprintf(file, p->ctl, table_name);
 	if (status)
 		snprintf(out, out_size, MSG_ARG_INVALID, "table_name");
+
+	if (file)
+		fclose(file);
 }
 
 static const char cmd_pipeline_selector_group_add_help[] =
@@ -1806,7 +1816,7 @@ cmd_pipeline_selector_group_member_delete(char **tokens,
 }
 
 static const char cmd_pipeline_selector_show_help[] =
-"pipeline <pipeline_name> selector <selector_name> show\n";
+"pipeline <pipeline_name> selector <selector_name> show [filename]\n";
 
 static void
 cmd_pipeline_selector_show(char **tokens,
@@ -1817,9 +1827,10 @@ cmd_pipeline_selector_show(char **tokens,
 {
 	struct pipeline *p;
 	char *pipeline_name, *selector_name;
+	FILE *file = NULL;
 	int status;
 
-	if (n_tokens != 5) {
+	if (n_tokens != 5 && n_tokens != 6) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
@@ -1832,10 +1843,19 @@ cmd_pipeline_selector_show(char **tokens,
 	}
 
 	selector_name = tokens[3];
-	status = rte_swx_ctl_pipeline_selector_fprintf(stdout,
-		p->ctl, selector_name);
+
+	file = (n_tokens == 6) ? fopen(tokens[5], "w") : stdout;
+	if (!file) {
+		snprintf(out, out_size, "Cannot open file %s.\n", tokens[5]);
+		return;
+	}
+
+	status = rte_swx_ctl_pipeline_selector_fprintf(file, p->ctl, selector_name);
 	if (status)
 		snprintf(out, out_size, MSG_ARG_INVALID, "selector_name");
+
+	if (file)
+		fclose(file);
 }
 
 static int
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V2] examples/pipeline: print table entries to file
  2022-01-12 18:59 ` [PATCH V2] " Cristian Dumitrescu
@ 2022-02-13 20:50   ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2022-02-13 20:50 UTC (permalink / raw)
  To: Harshad Narayane, Cristian Dumitrescu; +Cc: dev

12/01/2022 19:59, Cristian Dumitrescu:
> Add support for the show CLI command to print table entries to a file
> instead of standard output.
> 
> Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
> Signed-off-by: Harshad Narayane <harshad.suresh.narayane@intel.com>

Applied, thanks.




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-13 20:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-12 18:35 [PATCH] examples/pipeline: print table entries to file Cristian Dumitrescu
2022-01-12 18:59 ` [PATCH V2] " Cristian Dumitrescu
2022-02-13 20:50   ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).