app/testpmd: new commands for syn filter
authorJingjing Wu <jingjing.wu@intel.com>
Wed, 11 Feb 2015 07:51:48 +0000 (15:51 +0800)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Sun, 22 Feb 2015 02:09:04 +0000 (03:09 +0100)
Following commands of syn filter are removed:
  - add_syn_filter (port_id) priority (high|low) queue (queue_id)
  - remove_syn_filter (port_id)
  - get_syn_filter (port_id)
New command is added for syn filter by using filter_ctrl API and new
syn filter structure:
  - syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)

Signed-off-by: Jingjing Wu <jingjing.wu@intel.com>
app/test-pmd/cmdline.c
app/test-pmd/config.c
doc/guides/testpmd_app_ug/testpmd_funcs.rst

index bf5e5f9..0c304a0 100644 (file)
@@ -623,14 +623,8 @@ static void cmd_help_long_parsed(void *parsed_result,
                        "get_5tuple_filter (port_id) index (idx)\n"
                        "    get info of a 5tuple filter.\n\n"
 
-                       "add_syn_filter (port_id) priority (high|low) queue (queue_id)"
-                       "    add syn filter.\n\n"
-
-                       "remove_syn_filter (port_id)"
-                       "    remove syn filter.\n\n"
-
-                       "get_syn_filter (port_id) "
-                       "    get syn filter info.\n\n"
+                       "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
+                       "    Add/Del syn filter.\n\n"
 
                        "flex_filter (port_id) (add|del) len (len_value)"
                        " bytes (bytes_value) mask (mask_value)"
@@ -6799,99 +6793,94 @@ cmdline_parse_inst_t cmd_dump_one = {
        },
 };
 
-/* *** set SYN filter *** */
-struct cmd_set_syn_filter_result {
+/* *** Add/Del syn filter *** */
+struct cmd_syn_filter_result {
        cmdline_fixed_string_t filter;
        uint8_t port_id;
+       cmdline_fixed_string_t ops;
        cmdline_fixed_string_t priority;
        cmdline_fixed_string_t high;
        cmdline_fixed_string_t queue;
-       uint16_t  queue_id;
+       uint16_t queue_id;
 };
 
 static void
-cmd_set_syn_filter_parsed(void *parsed_result,
+cmd_syn_filter_parsed(void *parsed_result,
                        __attribute__((unused)) struct cmdline *cl,
                        __attribute__((unused)) void *data)
 {
+       struct cmd_syn_filter_result *res = parsed_result;
+       struct rte_eth_syn_filter syn_filter;
        int ret = 0;
-       struct cmd_set_syn_filter_result *res = parsed_result;
-       struct rte_syn_filter filter;
 
-       if (!strcmp(res->filter, "add_syn_filter")) {
+       ret = rte_eth_dev_filter_supported(res->port_id,
+                                       RTE_ETH_FILTER_SYN);
+       if (ret < 0) {
+               printf("syn filter is not supported on port %u.\n",
+                               res->port_id);
+               return;
+       }
+
+       memset(&syn_filter, 0, sizeof(syn_filter));
+
+       if (!strcmp(res->ops, "add")) {
                if (!strcmp(res->high, "high"))
-                       filter.hig_pri = 1;
+                       syn_filter.hig_pri = 1;
                else
-                       filter.hig_pri = 0;
-               ret = rte_eth_dev_add_syn_filter(res->port_id,
-                               &filter, res->queue_id);
-       } else if (!strcmp(res->filter, "remove_syn_filter"))
-               ret = rte_eth_dev_remove_syn_filter(res->port_id);
-       else if (!strcmp(res->filter, "get_syn_filter"))
-               get_syn_filter(res->port_id);
-       if (ret < 0)
-               printf("syn filter setting error: (%s)\n", strerror(-ret));
+                       syn_filter.hig_pri = 0;
+
+               syn_filter.queue = res->queue_id;
+               ret = rte_eth_dev_filter_ctrl(res->port_id,
+                                               RTE_ETH_FILTER_SYN,
+                                               RTE_ETH_FILTER_ADD,
+                                               &syn_filter);
+       } else
+               ret = rte_eth_dev_filter_ctrl(res->port_id,
+                                               RTE_ETH_FILTER_SYN,
+                                               RTE_ETH_FILTER_DELETE,
+                                               &syn_filter);
 
+       if (ret < 0)
+               printf("syn filter programming error: (%s)\n",
+                               strerror(-ret));
 }
-cmdline_parse_token_num_t cmd_syn_filter_portid =
-       TOKEN_NUM_INITIALIZER(struct cmd_set_syn_filter_result,
-                               port_id, UINT8);
+
+cmdline_parse_token_string_t cmd_syn_filter_filter =
+       TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
+       filter, "syn_filter");
+cmdline_parse_token_num_t cmd_syn_filter_port_id =
+       TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
+       port_id, UINT8);
+cmdline_parse_token_string_t cmd_syn_filter_ops =
+       TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
+       ops, "add#del");
 cmdline_parse_token_string_t cmd_syn_filter_priority =
-       TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
+       TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
                                priority, "priority");
 cmdline_parse_token_string_t cmd_syn_filter_high =
-       TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
+       TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
                                high, "high#low");
 cmdline_parse_token_string_t cmd_syn_filter_queue =
-       TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
+       TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
                                queue, "queue");
 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
-       TOKEN_NUM_INITIALIZER(struct cmd_set_syn_filter_result,
+       TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
                                queue_id, UINT16);
-cmdline_parse_token_string_t cmd_syn_filter_add_filter =
-       TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
-                               filter, "add_syn_filter");
-cmdline_parse_token_string_t cmd_syn_filter_remove_filter =
-       TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
-                               filter, "remove_syn_filter");
-cmdline_parse_inst_t cmd_add_syn_filter = {
-               .f = cmd_set_syn_filter_parsed,
-               .data = NULL,
-               .help_str = "add syn filter",
-               .tokens = {
-                       (void *)&cmd_syn_filter_add_filter,
-                       (void *)&cmd_syn_filter_portid,
-                       (void *)&cmd_syn_filter_priority,
-                       (void *)&cmd_syn_filter_high,
-                       (void *)&cmd_syn_filter_queue,
-                       (void *)&cmd_syn_filter_queue_id,
-                       NULL,
-               },
-};
-cmdline_parse_inst_t cmd_remove_syn_filter = {
-               .f = cmd_set_syn_filter_parsed,
-               .data = NULL,
-               .help_str = "remove syn filter",
-               .tokens = {
-                       (void *)&cmd_syn_filter_remove_filter,
-                       (void *)&cmd_syn_filter_portid,
-                       NULL,
-               },
-};
-
-cmdline_parse_token_string_t cmd_syn_filter_get_filter =
-       TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
-                               filter, "get_syn_filter");
 
-cmdline_parse_inst_t cmd_get_syn_filter = {
-               .f = cmd_set_syn_filter_parsed,
-               .data = NULL,
-               .help_str = "get syn filter",
-               .tokens = {
-                       (void *)&cmd_syn_filter_get_filter,
-                       (void *)&cmd_syn_filter_portid,
-                       NULL,
-               },
+cmdline_parse_inst_t cmd_syn_filter = {
+       .f = cmd_syn_filter_parsed,
+       .data = NULL,
+       .help_str = "add/delete syn filter",
+       .tokens = {
+               (void *)&cmd_syn_filter_filter,
+               (void *)&cmd_syn_filter_port_id,
+               (void *)&cmd_syn_filter_ops,
+               (void *)&cmd_syn_filter_priority,
+               (void *)&cmd_syn_filter_high,
+               (void *)&cmd_syn_filter_queue,
+               (void *)&cmd_syn_filter_queue_id,
+               NULL,
+       },
 };
 
 /* *** ADD/REMOVE A 2tuple FILTER *** */
@@ -8724,9 +8713,7 @@ cmdline_parse_ctx_t main_ctx[] = {
        (cmdline_parse_inst_t *)&cmd_dump,
        (cmdline_parse_inst_t *)&cmd_dump_one,
        (cmdline_parse_inst_t *)&cmd_ethertype_filter,
-       (cmdline_parse_inst_t *)&cmd_add_syn_filter,
-       (cmdline_parse_inst_t *)&cmd_remove_syn_filter,
-       (cmdline_parse_inst_t *)&cmd_get_syn_filter,
+       (cmdline_parse_inst_t *)&cmd_syn_filter,
        (cmdline_parse_inst_t *)&cmd_add_2tuple_filter,
        (cmdline_parse_inst_t *)&cmd_remove_2tuple_filter,
        (cmdline_parse_inst_t *)&cmd_get_2tuple_filter,
index 5f7e6a6..fc91a6d 100644 (file)
@@ -2059,27 +2059,6 @@ set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
        return diag;
 }
 
-void
-get_syn_filter(uint8_t port_id)
-{
-       struct rte_syn_filter filter;
-       int ret = 0;
-       uint16_t rx_queue;
-
-       memset(&filter, 0, sizeof(filter));
-       ret = rte_eth_dev_get_syn_filter(port_id, &filter, &rx_queue);
-
-       if (ret < 0) {
-               if (ret == (-ENOENT))
-                       printf("syn filter is not enabled\n");
-               else
-                       printf("get syn filter fails(%s)\n", strerror(-ret));
-               return;
-       }
-       printf("syn filter: priority: %s, queue: %d\n",
-               filter.hig_pri ? "high" : "low",
-               rx_queue);
-}
 void
 get_2tuple_filter(uint8_t port_id, uint16_t index)
 {
index efff768..6b3cf86 100644 (file)
@@ -1363,12 +1363,12 @@ Example:
         protocol: 0x06 mask: 1
         priority: 3 flags: 0x00 queue: 3
 
-add_syn_filter
+syn_filter
 ~~~~~~~~~~~~~~
 
-Add SYN filter, which can forward TCP packets whose *SYN* flag is set into a separate queue.
+By SYN filter, TCP packets whose *SYN* flag is set can be forwarded to a separate queue.
 
-add_syn_filter (port_id) priority (high|low) queue (queue_id)
+syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)
 
 The available information parameters are:
 
@@ -1384,29 +1384,7 @@ Example:
 
 .. code-block:: console
 
-    testpmd> add_syn_filter 0 priority high queue 3,
-
-remove_syn_filter
-~~~~~~~~~~~~~~~~~
-
-Remove SYN filter
-
-remove_syn_filter (port_id)
-
-get_syn_filter
-~~~~~~~~~~~~~~
-
-Get and display SYN filter
-
-get_syn_filter (port_id)
-
-Example:
-
-.. code-block:: console
-
-    testpmd> get_syn_filter 0
-
-    syn filter: on, priority: high, queue: 3
+    testpmd> syn_filter 0 add priority high queue 3
 
 flex_filter
 ~~~~~~~~~~~