app/testpmd: load commands from file at runtime
authorAllain Legacy <allain.legacy@windriver.com>
Fri, 31 Mar 2017 19:13:20 +0000 (15:13 -0400)
committerThomas Monjalon <thomas@monjalon.net>
Mon, 1 May 2017 14:05:23 +0000 (16:05 +0200)
Adds support to testpmd to load a set of cmdline CLI commands at runtime.
This can be helpful when needing to cut-n-paste many commands where
cut-n-paste may not be practical.

   testpmd> load /home/ubuntu/somefile.txt

Signed-off-by: Allain Legacy <allain.legacy@windriver.com>
Acked-by: Jingjing Wu <jingjing.wu@intel.com>
app/test-pmd/cmdline.c
doc/guides/testpmd_app_ug/testpmd_funcs.rst

index e741882..06c1ce2 100644 (file)
@@ -13529,6 +13529,40 @@ cmdline_parse_inst_t cmd_ptype_mapping_update = {
        },
 };
 
+/* Common result structure for file commands */
+struct cmd_cmdfile_result {
+       cmdline_fixed_string_t load;
+       cmdline_fixed_string_t filename;
+};
+
+/* Common CLI fields for file commands */
+cmdline_parse_token_string_t cmd_load_cmdfile =
+       TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
+cmdline_parse_token_string_t cmd_load_cmdfile_filename =
+       TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
+
+static void
+cmd_load_from_file_parsed(
+       void *parsed_result,
+       __attribute__((unused)) struct cmdline *cl,
+       __attribute__((unused)) void *data)
+{
+       struct cmd_cmdfile_result *res = parsed_result;
+
+       cmdline_read_from_file(res->filename);
+}
+
+cmdline_parse_inst_t cmd_load_from_file = {
+       .f = cmd_load_from_file_parsed,
+       .data = NULL,
+       .help_str = "load <filename>",
+       .tokens = {
+               (void *)&cmd_load_cmdfile,
+               (void *)&cmd_load_cmdfile_filename,
+               NULL,
+       },
+};
+
 /* ******************************************************************************** */
 
 /* list of instructions */
@@ -13536,6 +13570,7 @@ cmdline_parse_ctx_t main_ctx[] = {
        (cmdline_parse_inst_t *)&cmd_help_brief,
        (cmdline_parse_inst_t *)&cmd_help_long,
        (cmdline_parse_inst_t *)&cmd_quit,
+       (cmdline_parse_inst_t *)&cmd_load_from_file,
        (cmdline_parse_inst_t *)&cmd_showport,
        (cmdline_parse_inst_t *)&cmd_showqueue,
        (cmdline_parse_inst_t *)&cmd_showportall,
index efb697e..dbfc486 100644 (file)
@@ -119,6 +119,22 @@ practical or possible testpmd supports alternative methods for executing command
    testpmd>
 
 
+* At run-time additional commands can be loaded in bulk by invoking the ``load FILENAME``
+  command.
+
+.. code-block:: console
+
+   testpmd> load /home/ubuntu/flow-create-commands.txt
+   Flow rule #0 created
+   Flow rule #1 created
+   ...
+   ...
+   Flow rule #498 created
+   Flow rule #499 created
+   Read all CLI commands from /home/ubuntu/flow-create-commands.txt
+   testpmd>
+
+
 In all cases output from any included command will be displayed as standard output.
 Execution will continue until the end of the file is reached regardless of
 whether any errors occur.  The end user must examine the output to determine if