examples/pipeline: print table entries to file
[dpdk.git] / examples / pipeline / cli.c
index b9e1eea..edae63d 100644 (file)
@@ -555,7 +555,7 @@ static const char cmd_pipeline_port_in_help[] =
 "pipeline <pipeline_name> port in <port_id>\n"
 "   link <link_name> rxq <queue_id> bsz <burst_size>\n"
 "   ring <ring_name> bsz <burst_size>\n"
-"   | source <mempool_name> <file_name>\n"
+"   | source <mempool_name> <file_name> loop <n_loops>\n"
 "   | tap <tap_name> mempool <mempool_name> mtu <mtu> bsz <burst_size>\n";
 
 static void
@@ -682,7 +682,7 @@ cmd_pipeline_port_in(char **tokens,
                struct rte_swx_port_source_params params;
                struct mempool *mp;
 
-               if (n_tokens < t0 + 3) {
+               if (n_tokens < t0 + 5) {
                        snprintf(out, out_size, MSG_ARG_MISMATCH,
                                "pipeline port in source");
                        return;
@@ -698,7 +698,18 @@ cmd_pipeline_port_in(char **tokens,
 
                params.file_name = tokens[t0 + 2];
 
-               t0 += 3;
+               if (strcmp(tokens[t0 + 3], "loop") != 0) {
+                       snprintf(out, out_size, MSG_ARG_NOT_FOUND, "loop");
+                       return;
+               }
+
+               if (parser_read_uint64(&params.n_loops, tokens[t0 + 4])) {
+                       snprintf(out, out_size, MSG_ARG_INVALID,
+                               "n_loops");
+                       return;
+               }
+
+               t0 += 5;
 
                status = rte_swx_pipeline_port_in_config(p->p,
                        port_id,
@@ -1335,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,
@@ -1346,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;
        }
@@ -1361,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[] =
@@ -1795,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,
@@ -1806,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;
        }
@@ -1821,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
@@ -2540,10 +2571,17 @@ cmd_pipeline_stats(char **tokens,
 
                rte_swx_ctl_pipeline_port_out_stats_read(p->p, i, &stats);
 
-               snprintf(out, out_size, "\tPort %u:"
-                       " packets %" PRIu64
-                       " bytes %" PRIu64 "\n",
-                       i, stats.n_pkts, stats.n_bytes);
+               if (i != info.n_ports_out - 1)
+                       snprintf(out, out_size, "\tPort %u:"
+                               " packets %" PRIu64
+                               " bytes %" PRIu64 "\n",
+                               i, stats.n_pkts, stats.n_bytes);
+               else
+                       snprintf(out, out_size, "\tDROP:"
+                               " packets %" PRIu64
+                               " bytes %" PRIu64 "\n",
+                               stats.n_pkts, stats.n_bytes);
+
                out_size -= strlen(out);
                out += strlen(out);
        }