app/testpmd: handle SIGINT and SIGTERM
[dpdk.git] / app / test-pmd / cmdline.c
index c637198..6d28c1b 100644 (file)
@@ -90,6 +90,8 @@
 
 #include "testpmd.h"
 
+static struct cmdline *testpmd_cl;
+
 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
 
 #ifdef RTE_NIC_BYPASS
@@ -199,7 +201,10 @@ static void cmd_help_long_parsed(void *parsed_result,
                        "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
                        "    Clear information for port_id, or all.\n\n"
 
-                       "show config (rxtx|cores|fwd)\n"
+                       "show (rxq|txq) info (port_id) (queue_id)\n"
+                       "    Display information for configured RX/TX queue.\n\n"
+
+                       "show config (rxtx|cores|fwd|txpkts)\n"
                        "    Display the given configuration.\n\n"
 
                        "read rxd (port_id) (queue_id) (rxd_id)\n"
@@ -246,7 +251,12 @@ static void cmd_help_long_parsed(void *parsed_result,
 
                        "set txpkts (x[,y]*)\n"
                        "    Set the length of each segment of TXONLY"
-                       " packets.\n\n"
+                       " and optionally CSUM packets.\n\n"
+
+                       "set txsplit (off|on|rand)\n"
+                       "    Set the split policy for the TX packets."
+                       " Right now only applicable for CSUM and TXONLY"
+                       " modes\n\n"
 
                        "set corelist (x[,y]*)\n"
                        "    Set the list of forwarding cores.\n\n"
@@ -629,7 +639,7 @@ static void cmd_help_long_parsed(void *parsed_result,
                        " priority (prio_value) queue (queue_id)\n"
                        "    Add/Del a flex filter.\n\n"
 
-                       "flow_director_filter (port_id) (add|del|update)"
+                       "flow_director_filter (port_id) mode IP (add|del|update)"
                        " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
                        " src (src_ip_address) dst (dst_ip_address)"
                        " vlan (vlan_value) flexbytes (flexbytes_value)"
@@ -637,7 +647,7 @@ static void cmd_help_long_parsed(void *parsed_result,
                        " fd_id (fd_id_value)\n"
                        "    Add/Del an IP type flow director filter.\n\n"
 
-                       "flow_director_filter (port_id) (add|del|update)"
+                       "flow_director_filter (port_id) mode IP (add|del|update)"
                        " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
                        " src (src_ip_address) (src_port)"
                        " dst (dst_ip_address) (dst_port)"
@@ -646,7 +656,7 @@ static void cmd_help_long_parsed(void *parsed_result,
                        " fd_id (fd_id_value)\n"
                        "    Add/Del an UDP/TCP type flow director filter.\n\n"
 
-                       "flow_director_filter (port_id) (add|del|update)"
+                       "flow_director_filter (port_id) mode IP (add|del|update)"
                        " flow (ipv4-sctp|ipv6-sctp)"
                        " src (src_ip_address) (src_port)"
                        " dst (dst_ip_address) (dst_port)"
@@ -655,19 +665,42 @@ static void cmd_help_long_parsed(void *parsed_result,
                        " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
                        "    Add/Del a SCTP type flow director filter.\n\n"
 
-                       "flow_director_filter (port_id) (add|del|update)"
+                       "flow_director_filter (port_id) mode IP (add|del|update)"
                        " flow l2_payload ether (ethertype)"
                        " flexbytes (flexbytes_value) (drop|fwd)"
                        " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
                        "    Add/Del a l2 payload type flow director filter.\n\n"
 
+                       "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
+                       " mac (mac_address) vlan (vlan_value)"
+                       " flexbytes (flexbytes_value) (drop|fwd)"
+                       " queue (queue_id) fd_id (fd_id_value)\n"
+                       "    Add/Del a MAC-VLAN flow director filter.\n\n"
+
+                       "flow_director_filter (port_id) mode Tunnel (add|del|update)"
+                       " mac (mac_address) vlan (vlan_value)"
+                       " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
+                       " flexbytes (flexbytes_value) (drop|fwd)"
+                       " queue (queue_id) fd_id (fd_id_value)\n"
+                       "    Add/Del a Tunnel flow director filter.\n\n"
+
                        "flush_flow_director (port_id)\n"
                        "    Flush all flow director entries of a device.\n\n"
 
-                       "flow_director_mask (port_id) vlan (vlan_value)"
+                       "flow_director_mask (port_id) mode IP vlan (vlan_value)"
                        " src_mask (ipv4_src) (ipv6_src) (src_port)"
                        " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
-                       "    Set flow director mask.\n\n"
+                       "    Set flow director IP mask.\n\n"
+
+                       "flow_director_mask (port_id) mode MAC-VLAN"
+                       " vlan (vlan_value) mac (mac_value)\n"
+                       "    Set flow director MAC-VLAN mask.\n\n"
+
+                       "flow_director_mask (port_id) mode Tunnel"
+                       " vlan (vlan_value) mac (mac_value)"
+                       " tunnel-type (tunnel_type_value)"
+                       " tunnel-id (tunnel_id_value)\n"
+                       "    Set flow director Tunnel mask.\n\n"
 
                        "flow_director_flex_mask (port_id)"
                        " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
@@ -2621,6 +2654,47 @@ cmdline_parse_inst_t cmd_set_txpkts = {
        },
 };
 
+/* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
+
+struct cmd_set_txsplit_result {
+       cmdline_fixed_string_t cmd_keyword;
+       cmdline_fixed_string_t txsplit;
+       cmdline_fixed_string_t mode;
+};
+
+static void
+cmd_set_txsplit_parsed(void *parsed_result,
+                     __attribute__((unused)) struct cmdline *cl,
+                     __attribute__((unused)) void *data)
+{
+       struct cmd_set_txsplit_result *res;
+
+       res = parsed_result;
+       set_tx_pkt_split(res->mode);
+}
+
+cmdline_parse_token_string_t cmd_set_txsplit_keyword =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
+                                cmd_keyword, "set");
+cmdline_parse_token_string_t cmd_set_txsplit_name =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
+                                txsplit, "txsplit");
+cmdline_parse_token_string_t cmd_set_txsplit_mode =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
+                                mode, NULL);
+
+cmdline_parse_inst_t cmd_set_txsplit = {
+       .f = cmd_set_txsplit_parsed,
+       .data = NULL,
+       .help_str = "set txsplit on|off|rand",
+       .tokens = {
+               (void *)&cmd_set_txsplit_keyword,
+               (void *)&cmd_set_txsplit_name,
+               (void *)&cmd_set_txsplit_mode,
+               NULL,
+       },
+};
+
 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
 struct cmd_rx_vlan_filter_all_result {
        cmdline_fixed_string_t rx_vlan;
@@ -5233,6 +5307,8 @@ static void cmd_showcfg_parsed(void *parsed_result,
                fwd_lcores_config_display();
        else if (!strcmp(res->what, "fwd"))
                fwd_config_display();
+       else if (!strcmp(res->what, "txpkts"))
+               show_tx_pkt_segments();
 }
 
 cmdline_parse_token_string_t cmd_showcfg_show =
@@ -5241,12 +5317,12 @@ cmdline_parse_token_string_t cmd_showcfg_port =
        TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
 cmdline_parse_token_string_t cmd_showcfg_what =
        TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
-                                "rxtx#cores#fwd");
+                                "rxtx#cores#fwd#txpkts");
 
 cmdline_parse_inst_t cmd_showcfg = {
        .f = cmd_showcfg_parsed,
        .data = NULL,
-       .help_str = "show config rxtx|cores|fwd",
+       .help_str = "show config rxtx|cores|fwd|txpkts",
        .tokens = {
                (void *)&cmd_showcfg_show,
                (void *)&cmd_showcfg_port,
@@ -7996,14 +8072,14 @@ str2flowtype(char *string)
        return RTE_ETH_FLOW_UNKNOWN;
 }
 
-static uint8_t
+static enum rte_eth_fdir_tunnel_type
 str2fdir_tunneltype(char *string)
 {
        uint8_t i = 0;
 
        static const struct {
                char str[32];
-               uint8_t type;
+               enum rte_eth_fdir_tunnel_type type;
        } tunneltype_str[] = {
                {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
                {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
@@ -9574,6 +9650,7 @@ cmdline_parse_ctx_t main_ctx[] = {
        (cmdline_parse_inst_t *)&cmd_reset,
        (cmdline_parse_inst_t *)&cmd_set_numbers,
        (cmdline_parse_inst_t *)&cmd_set_txpkts,
+       (cmdline_parse_inst_t *)&cmd_set_txsplit,
        (cmdline_parse_inst_t *)&cmd_set_fwd_list,
        (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
        (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
@@ -9703,17 +9780,21 @@ cmdline_parse_ctx_t main_ctx[] = {
 void
 prompt(void)
 {
-       struct cmdline *cl;
-
        /* initialize non-constant commands */
        cmd_set_fwd_mode_init();
 
-       cl = cmdline_stdin_new(main_ctx, "testpmd> ");
-       if (cl == NULL) {
+       testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
+       if (testpmd_cl == NULL)
                return;
-       }
-       cmdline_interact(cl);
-       cmdline_stdin_exit(cl);
+       cmdline_interact(testpmd_cl);
+       cmdline_stdin_exit(testpmd_cl);
+}
+
+void
+prompt_exit(void)
+{
+       if (testpmd_cl != NULL)
+               cmdline_quit(testpmd_cl);
 }
 
 static void