From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 72F544C6E for ; Tue, 27 May 2014 10:00:51 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 27 May 2014 01:01:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.98,917,1392192000"; d="scan'208";a="545371235" Received: from fmsmsx107.amr.corp.intel.com ([10.19.9.54]) by fmsmga002.fm.intel.com with ESMTP; 27 May 2014 01:00:33 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX107.amr.corp.intel.com (10.19.9.54) with Microsoft SMTP Server (TLS) id 14.3.123.3; Tue, 27 May 2014 01:00:33 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.192]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.23]) with mapi id 14.03.0123.003; Tue, 27 May 2014 16:00:32 +0800 From: "Ming, LiX" To: "Wu, Jingjing" , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v2 4/4]app/test-pmd: add commands in testpmd for NIC filters Thread-Index: AQHPdvDnP3XE73PGHkCa1hsOcsVtSptUFXbw Date: Tue, 27 May 2014 08:00:31 +0000 Message-ID: <0976FC66838DDE4585886952506C9436FBA648@SHSMSX104.ccr.corp.intel.com> References: <1400895442-32433-1-git-send-email-jingjing.wu@intel.com> <1400895442-32433-5-git-send-email-jingjing.wu@intel.com> In-Reply-To: <1400895442-32433-5-git-send-email-jingjing.wu@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-cr-hashedpuzzle: KtA= AokE B9ko CicY DE79 DQdY D5Wv EiZd E2mR Fjgm Fjq3 FoT+ GFL+ IFjl KB3D KRTN; 1; ZABlAHYAQABkAHAAZABrAC4AbwByAGcA; Sosha1_v1; 7; {6A92D4CF-D5B6-48C5-9643-75E6FB2E1905}; bABpAHgALgBtAGkAbgBnAEAAaQBuAHQAZQBsAC4AYwBvAG0A; Tue, 27 May 2014 08:00:29 GMT; UgBFADoAIABbAGQAcABkAGsALQBkAGUAdgBdACAAWwBQAEEAVABDAEgAIAB2ADIAIAA0AC8ANABdAGEAcABwAC8AdABlAHMAdAAtAHAAbQBkADoAIABhAGQAZAAgAGMAbwBtAG0AYQBuAGQAcwAgAGkAbgAgAHQAZQBzAHQAcABtAGQAIABmAG8AcgAJAE4ASQBDACAAZgBpAGwAdABlAHIAcwA= x-cr-puzzleid: {6A92D4CF-D5B6-48C5-9643-75E6FB2E1905} x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v2 4/4]app/test-pmd: add commands in testpmd for NIC filters X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 May 2014 08:00:52 -0000 add commands in testpmd for NIC filters: add_ethertype_filter remove_ethertype_filter get_ethertype_filter add_2tuple_filter remove_2tuple_filter get_2tuple_filter add_5tuple_filter remove_5tuple_filter get_5tuple_filter add_syn_filter remove_syn_filter get_syn_filter add_flex_filter remove_flex_filter get_flex_filter Signed-off-by: jingjing.wu --- app/test-pmd/cmdline.c | 907 +++++++++++++++++++++++++++++++++++++++++++++= +++- app/test-pmd/config.c | 145 ++++++++ app/test-pmd/testpmd.h | 6 + 3 files changed, 1057 insertions(+), 1 deletion(-) Test-by: lmingX lix,ming@intel.com Compile pass >>Compile OS: FC20 x86_64 >>Kernel version: 3.11.10-301 >>GCC version: 4.8.2 >>Server: Crownpass diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index b3824f9..6bdfa6b 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -113,6 +113,7 @@ static void cmd_help_brief_parsed(__attribute__((unused= )) void *parsed_result, " help ports : Configuring ports.\n" " help flowdir : Flow Director filter help.\n" " help registers : Reading and setting port registers.\n" + " help filters : Filters configuration help.\n" " help all : All of the above sections.\n\n" ); =20 @@ -543,6 +544,67 @@ static void cmd_help_long_parsed(void *parsed_result, " Set single bit value of a port register.\n\n" ); } + if (show_all || !strcmp(res->section, "filters")) { + + cmdline_printf( + cl, + "\n" + "filters:\n" + "----------\n\n" + + "add_ethertype_filter (port_id) ethertype (eth_value)" + " priority (enable|disable)(pri_value) queue (queue_id) index (idx)\n" + " add an ethertype filter.\n\n" + + "remove_ethertype_filter (port_id) index (idx)\n" + " remove an ethertype filter.\n\n" + + "get_ethertype_filter (port_id) index (idx)\n" + " get info of a ethertype filter.\n\n" + + "add_2tuple_filter (port_id) protocol (pro_value) (pro_mask)" + " dst_port (port_value) (port_mask) flags (flg_value) priority (prio_va= lue)" + " queue (queue_id) index (idx)\n" + " add a 2tuple filter.\n\n" + + "remove_2tuple_filter (port_id) index (idx)\n" + " remove a 2tuple filter.\n\n" + + "get_2tuple_filter (port_id) index (idx)\n" + " get info of a 2tuple filter.\n\n" + + "add_5tuple_filter (port_id) dst_ip (dst_address) src_ip (src_address)" + " dst_port (dst_port_value) src_port (src_port_value) protocol (protoco= l_value)" + " mask (mask_value) flags (flags_value) priority (prio_value)" + " queue (queue_id) index (idx)\n" + " add a 5tuple filter.\n\n" + + "remove_5tuple_filter (port_id) index (idx)\n" + " remove a 5tuple filter.\n\n" + + "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" + + "add_flex_filter (port_id) len (len_value) bytes (bytes_string) mask (m= ask_value)" + " priority (prio_value) queue (queue_id) index (idx)\n" + " add a flex filter.\n\n" + + "remove_flex_filter (port_id) index (idx)\n" + " remove a flex filter.\n\n" + + "get_flex_filter (port_id) index (idx)\n" + " get info of a flex filter.\n\n" + ); + } } =20 cmdline_parse_token_string_t cmd_help_long_help =3D @@ -551,7 +613,7 @@ cmdline_parse_token_string_t cmd_help_long_help =3D cmdline_parse_token_string_t cmd_help_long_section =3D TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section, "all#control#display#config#flowdir#" - "ports#registers"); + "ports#registers#filters"); =20 cmdline_parse_inst_t cmd_help_long =3D { .f =3D cmd_help_long_parsed, @@ -5152,6 +5214,834 @@ cmdline_parse_inst_t cmd_dump_one =3D { }, }; =20 +/* *** ADD/REMOVE an ethertype FILTER *** */ +struct cmd_ethertype_filter_result { + cmdline_fixed_string_t filter; + uint8_t port_id; + cmdline_fixed_string_t ethertype; + uint16_t ethertype_value; + cmdline_fixed_string_t priority; + cmdline_fixed_string_t priority_en; + uint8_t priority_value; + cmdline_fixed_string_t queue; + uint8_t queue_id; + cmdline_fixed_string_t index; + uint16_t index_value; +}; + +static void +cmd_ethertype_filter_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + int ret =3D 0; + struct cmd_ethertype_filter_result *res =3D parsed_result; + struct rte_ethertype_filter filter; + + memset(&filter, 0, sizeof(struct rte_ethertype_filter)); + filter.ethertype =3D rte_cpu_to_le_16(res->ethertype_value); + filter.priority =3D res->priority_value; + + if (!strcmp(res->priority_en, "enable")) + filter.priority_en =3D 1; + if (!strcmp(res->filter, "add_ethertype_filter")) + ret =3D rte_eth_dev_add_ethertype_filter(res->port_id, + res->index_value, + &filter, res->queue_id); + else if (!strcmp(res->filter, "remove_ethertype_filter")) + ret =3D rte_eth_dev_remove_ethertype_filter(res->port_id, + res->index_value); + else if (!strcmp(res->filter, "get_ethertype_filter")) + get_ethertype_filter(res->port_id, res->index_value); + + if (ret < 0) + printf("ethertype filter setting error: (%s)\n", + strerror(-ret)); +} + +cmdline_parse_token_num_t cmd_ethertype_filter_port_id =3D + TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, + port_id, UINT8); +cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =3D + TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, + ethertype, "ethertype"); +cmdline_parse_token_ipaddr_t cmd_ethertype_filter_ethertype_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, + ethertype_value, UINT16); +cmdline_parse_token_string_t cmd_ethertype_filter_priority =3D + TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, + priority, "priority"); +cmdline_parse_token_string_t cmd_ethertype_filter_priority_en =3D + TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, + priority_en, "enable#disable"); +cmdline_parse_token_num_t cmd_ethertype_filter_priority_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, + priority_value, UINT8); +cmdline_parse_token_string_t cmd_ethertype_filter_queue =3D + TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, + queue, "queue"); +cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =3D + TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, + queue_id, UINT8); +cmdline_parse_token_string_t cmd_ethertype_filter_index =3D + TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, + index, "index"); +cmdline_parse_token_num_t cmd_ethertype_filter_index_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, + index_value, UINT16); +cmdline_parse_token_string_t cmd_ethertype_filter_add_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, + filter, "add_ethertype_filter"); +cmdline_parse_inst_t cmd_add_ethertype_filter =3D { + .f =3D cmd_ethertype_filter_parsed, + .data =3D NULL, + .help_str =3D "add an ethertype filter", + .tokens =3D { + (void *)&cmd_ethertype_filter_add_filter, + (void *)&cmd_ethertype_filter_port_id, + (void *)&cmd_ethertype_filter_ethertype, + (void *)&cmd_ethertype_filter_ethertype_value, + (void *)&cmd_ethertype_filter_priority, + (void *)&cmd_ethertype_filter_priority_en, + (void *)&cmd_ethertype_filter_priority_value, + (void *)&cmd_ethertype_filter_queue, + (void *)&cmd_ethertype_filter_queue_id, + (void *)&cmd_ethertype_filter_index, + (void *)&cmd_ethertype_filter_index_value, + NULL, + }, +}; + +cmdline_parse_token_string_t cmd_ethertype_filter_remove_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, + filter, "remove_ethertype_filter"); +cmdline_parse_inst_t cmd_remove_ethertype_filter =3D { + .f =3D cmd_ethertype_filter_parsed, + .data =3D NULL, + .help_str =3D "remove an ethertype filter", + .tokens =3D { + (void *)&cmd_ethertype_filter_remove_filter, + (void *)&cmd_ethertype_filter_port_id, + (void *)&cmd_ethertype_filter_index, + (void *)&cmd_ethertype_filter_index_value, + NULL, + }, +}; +cmdline_parse_token_string_t cmd_ethertype_filter_get_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, + filter, "get_ethertype_filter"); +cmdline_parse_inst_t cmd_get_ethertype_filter =3D { + .f =3D cmd_ethertype_filter_parsed, + .data =3D NULL, + .help_str =3D "get an ethertype filter", + .tokens =3D { + (void *)&cmd_ethertype_filter_get_filter, + (void *)&cmd_ethertype_filter_port_id, + (void *)&cmd_ethertype_filter_index, + (void *)&cmd_ethertype_filter_index_value, + NULL, + }, +}; + +/* *** set SYN filter *** */ +struct cmd_set_syn_filter_result { + cmdline_fixed_string_t filter; + uint8_t port_id; + cmdline_fixed_string_t priority; + cmdline_fixed_string_t high; + cmdline_fixed_string_t queue; + uint8_t queue_id; +}; + +static void +cmd_set_syn_filter_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + int ret =3D 0; + struct cmd_set_syn_filter_result *res =3D parsed_result; + if (!strcmp(res->filter, "add_syn_filter")) { + if (!strcmp(res->high, "high")) + ret =3D rte_eth_dev_add_syn_filter(res->port_id, + 1, res->queue_id); + else + ret =3D rte_eth_dev_add_syn_filter(res->port_id, + 0, res->queue_id); + } else if (!strcmp(res->filter, "remove_syn_filter")) + ret =3D 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)); + +} +cmdline_parse_token_string_t cmd_syn_filter_portid =3D + TOKEN_NUM_INITIALIZER(struct cmd_set_syn_filter_result, + port_id, UINT8); +cmdline_parse_token_string_t cmd_syn_filter_priority =3D + TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result, + priority, "priority"); +cmdline_parse_token_string_t cmd_syn_filter_high =3D + TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result, + high, "high#low"); +cmdline_parse_token_string_t cmd_syn_filter_queue =3D + TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result, + queue, "queue"); +cmdline_parse_token_num_t cmd_syn_filter_queue_id =3D + TOKEN_NUM_INITIALIZER(struct cmd_set_syn_filter_result, + queue_id, UINT8); +cmdline_parse_token_string_t cmd_syn_filter_add_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result, + filter, "add_syn_filter"); +cmdline_parse_token_string_t cmd_syn_filter_remove_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result, + filter, "remove_syn_filter"); +cmdline_parse_inst_t cmd_add_syn_filter =3D { + .f =3D cmd_set_syn_filter_parsed, + .data =3D NULL, + .help_str =3D "add syn filter", + .tokens =3D { + (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 =3D { + .f =3D cmd_set_syn_filter_parsed, + .data =3D NULL, + .help_str =3D "remove syn filter", + .tokens =3D { + (void *)&cmd_syn_filter_remove_filter, + (void *)&cmd_syn_filter_portid, + NULL, + }, +}; + +cmdline_parse_token_string_t cmd_syn_filter_get_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result, + filter, "get_syn_filter"); + +cmdline_parse_inst_t cmd_get_syn_filter =3D { + .f =3D cmd_set_syn_filter_parsed, + .data =3D NULL, + .help_str =3D "get syn filter", + .tokens =3D { + (void *)&cmd_syn_filter_get_filter, + (void *)&cmd_syn_filter_portid, + NULL, + }, +}; + +/* *** ADD/REMOVE A 2tuple FILTER *** */ +struct cmd_2tuple_filter_result { + cmdline_fixed_string_t filter; + uint8_t port_id; + cmdline_fixed_string_t protocol; + uint8_t protocol_value; + uint8_t protocol_mask; + cmdline_fixed_string_t dst_port; + uint16_t dst_port_value; + uint16_t dst_port_mask; + cmdline_fixed_string_t flags; + uint8_t flags_value; + cmdline_fixed_string_t priority; + uint8_t priority_value; + cmdline_fixed_string_t queue; + uint8_t queue_id; + cmdline_fixed_string_t index; + uint16_t index_value; +}; + +static void +cmd_2tuple_filter_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + int ret =3D 0; + struct rte_2tuple_filter filter; + struct cmd_2tuple_filter_result *res =3D parsed_result; + + memset(&filter, 0, sizeof(struct rte_2tuple_filter)); + + if (!strcmp(res->filter, "add_2tuple_filter")) { + /** need convert to big endian*/ + filter.dst_port =3D rte_cpu_to_be_16(res->dst_port_value); + filter.protocol =3D res->protocol_value; + filter.dst_port_mask =3D (res->dst_port_mask) ? 0 : 1; + filter.protocol_mask =3D (res->protocol_mask) ? 0 : 1; + filter.priority =3D res->priority_value; + filter.tcp_flags =3D res->flags_value; + ret =3D rte_eth_dev_add_2tuple_filter(res->port_id, + res->index_value, &filter, res->queue_id); + } else if (!strcmp(res->filter, "remove_2tuple_filter")) + ret =3D rte_eth_dev_remove_2tuple_filter(res->port_id, + res->index_value); + else if (!strcmp(res->filter, "get_2tuple_filter")) + get_2tuple_filter(res->port_id, res->index_value); + + if (ret < 0) + printf("2tuple filter setting error: (%s)\n", strerror(-ret)); +} + +cmdline_parse_token_num_t cmd_2tuple_filter_port_id =3D + TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, + port_id, UINT8); +cmdline_parse_token_string_t cmd_2tuple_filter_protocol =3D + TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, + protocol, "protocol"); +cmdline_parse_token_string_t cmd_2tuple_filter_protocol_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, + protocol_value, UINT8); +cmdline_parse_token_num_t cmd_2tuple_filter_protocol_mask =3D + TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, + protocol_mask, UINT8); +cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =3D + TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, + dst_port, "dst_port"); +cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, + dst_port_value, UINT16); +cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_mask =3D + TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, + dst_port_mask, UINT16); +cmdline_parse_token_string_t cmd_2tuple_filter_flags =3D + TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, + flags, "flags"); +cmdline_parse_token_string_t cmd_2tuple_filter_flags_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, + flags_value, UINT8); +cmdline_parse_token_string_t cmd_2tuple_filter_priority =3D + TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, + priority, "priority"); +cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, + priority_value, UINT8); +cmdline_parse_token_string_t cmd_2tuple_filter_queue =3D + TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, + queue, "queue"); +cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =3D + TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, + queue_id, UINT8); +cmdline_parse_token_string_t cmd_2tuple_filter_index =3D + TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, + index, "index"); +cmdline_parse_token_num_t cmd_2tuple_filter_index_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, + index_value, UINT16); +cmdline_parse_token_string_t cmd_2tuple_filter_add_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, + filter, "add_2tuple_filter"); +cmdline_parse_inst_t cmd_add_2tuple_filter =3D { + .f =3D cmd_2tuple_filter_parsed, + .data =3D NULL, + .help_str =3D "add a 2tuple filter", + .tokens =3D { + (void *)&cmd_2tuple_filter_add_filter, + (void *)&cmd_2tuple_filter_port_id, + (void *)&cmd_2tuple_filter_protocol, + (void *)&cmd_2tuple_filter_protocol_value, + (void *)&cmd_2tuple_filter_protocol_mask, + (void *)&cmd_2tuple_filter_dst_port, + (void *)&cmd_2tuple_filter_dst_port_value, + (void *)&cmd_2tuple_filter_dst_port_mask, + (void *)&cmd_2tuple_filter_flags, + (void *)&cmd_2tuple_filter_flags_value, + (void *)&cmd_2tuple_filter_priority, + (void *)&cmd_2tuple_filter_priority_value, + (void *)&cmd_2tuple_filter_queue, + (void *)&cmd_2tuple_filter_queue_id, + (void *)&cmd_2tuple_filter_index, + (void *)&cmd_2tuple_filter_index_value, + NULL, + }, +}; + +cmdline_parse_token_string_t cmd_2tuple_filter_remove_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, + filter, "remove_2tuple_filter"); +cmdline_parse_inst_t cmd_remove_2tuple_filter =3D { + .f =3D cmd_2tuple_filter_parsed, + .data =3D NULL, + .help_str =3D "remove a 2tuple filter", + .tokens =3D { + (void *)&cmd_2tuple_filter_remove_filter, + (void *)&cmd_2tuple_filter_port_id, + (void *)&cmd_2tuple_filter_index, + (void *)&cmd_2tuple_filter_index_value, + NULL, + }, +}; +cmdline_parse_token_string_t cmd_2tuple_filter_get_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, + filter, "get_2tuple_filter"); +cmdline_parse_inst_t cmd_get_2tuple_filter =3D { + .f =3D cmd_2tuple_filter_parsed, + .data =3D NULL, + .help_str =3D "get a 2tuple filter", + .tokens =3D { + (void *)&cmd_2tuple_filter_get_filter, + (void *)&cmd_2tuple_filter_port_id, + (void *)&cmd_2tuple_filter_index, + (void *)&cmd_2tuple_filter_index_value, + NULL, + }, +}; + +/* *** ADD/REMOVE A 5tuple FILTER *** */ +struct cmd_5tuple_filter_result { + cmdline_fixed_string_t filter; + uint8_t port_id; + cmdline_fixed_string_t dst_ip; + cmdline_ipaddr_t dst_ip_value; + cmdline_fixed_string_t src_ip; + cmdline_ipaddr_t src_ip_value; + cmdline_fixed_string_t dst_port; + uint16_t dst_port_value; + cmdline_fixed_string_t src_port; + uint16_t src_port_value; + cmdline_fixed_string_t protocol; + uint8_t protocol_value; + cmdline_fixed_string_t mask; + uint8_t mask_value; + cmdline_fixed_string_t flags; + uint8_t flags_value; + cmdline_fixed_string_t priority; + uint8_t priority_value; + cmdline_fixed_string_t queue; + uint8_t queue_id; + cmdline_fixed_string_t index; + uint16_t index_value; +}; + +static void +cmd_5tuple_filter_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + int ret =3D 0; + struct rte_5tuple_filter filter; + struct cmd_5tuple_filter_result *res =3D parsed_result; + + memset(&filter, 0, sizeof(struct rte_5tuple_filter)); + + if (!strcmp(res->filter, "add_5tuple_filter")) { + filter.dst_ip_mask =3D (res->mask_value & 0x10) ? 0 : 1; + filter.src_ip_mask =3D (res->mask_value & 0x08) ? 0 : 1; + filter.dst_port_mask =3D (res->mask_value & 0x04) ? 0 : 1; + filter.src_port_mask =3D (res->mask_value & 0x02) ? 0 : 1; + filter.protocol =3D res->protocol_value; + filter.protocol_mask =3D (res->mask_value & 0x01) ? 0 : 1; + filter.priority =3D res->priority_value; + filter.tcp_flags =3D res->flags_value; + + if (res->dst_ip_value.family =3D=3D AF_INET) + /** no need to convert, already big endian*/ + filter.dst_ip =3D res->dst_ip_value.addr.ipv4.s_addr; + else { + if (filter.dst_ip_mask =3D=3D 0) { + printf("can not support ipv6 involved compare.\n"); + return; + } + filter.dst_ip =3D 0; + } + + if (res->src_ip_value.family =3D=3D AF_INET) + /** no need to convert, already big endian*/ + filter.src_ip =3D res->src_ip_value.addr.ipv4.s_addr; + else { + if (filter.src_ip_mask =3D=3D 0) { + printf("can not support ipv6 involved compare.\n"); + return; + } + filter.src_ip =3D 0; + } + /** need convert to big endian*/ + filter.dst_port =3D rte_cpu_to_be_16(res->dst_port_value); + filter.src_port =3D rte_cpu_to_be_16(res->src_port_value); + + ret =3D rte_eth_dev_add_5tuple_filter(res->port_id, + res->index_value, &filter, res->queue_id); + } else if (!strcmp(res->filter, "remove_5tuple_filter")) + ret =3D rte_eth_dev_remove_5tuple_filter(res->port_id, + res->index_value); + else if (!strcmp(res->filter, "get_5tuple_filter")) + get_5tuple_filter(res->port_id, res->index_value); + if (ret < 0) + printf("5tuple filter setting error: (%s)\n", strerror(-ret)); +} + + +cmdline_parse_token_num_t cmd_5tuple_filter_port_id =3D + TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, + port_id, UINT8); +cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =3D + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + dst_ip, "dst_ip"); +cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =3D + TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result, + dst_ip_value); +cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =3D + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + src_ip, "src_ip"); +cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =3D + TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result, + src_ip_value); +cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =3D + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + dst_port, "dst_port"); +cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, + dst_port_value, UINT16); +cmdline_parse_token_string_t cmd_5tuple_filter_src_port =3D + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + src_port, "src_port"); +cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, + src_port_value, UINT16); +cmdline_parse_token_string_t cmd_5tuple_filter_protocol =3D + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + protocol, "protocol"); +cmdline_parse_token_string_t cmd_5tuple_filter_protocol_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, + protocol_value, UINT8); +cmdline_parse_token_string_t cmd_5tuple_filter_mask =3D + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + mask, "mask"); +cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, + mask_value, INT8); +cmdline_parse_token_string_t cmd_5tuple_filter_flags =3D + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + flags, "flags"); +cmdline_parse_token_num_t cmd_5tuple_filter_flags_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, + flags_value, UINT8); +cmdline_parse_token_string_t cmd_5tuple_filter_priority =3D + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + priority, "priority"); +cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, + priority_value, UINT8); +cmdline_parse_token_string_t cmd_5tuple_filter_queue =3D + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + queue, "queue"); +cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =3D + TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, + queue_id, UINT8); +cmdline_parse_token_string_t cmd_5tuple_filter_index =3D + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + index, "index"); +cmdline_parse_token_num_t cmd_5tuple_filter_index_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, + index_value, UINT16); + +cmdline_parse_token_string_t cmd_5tuple_filter_add_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + filter, "add_5tuple_filter"); +cmdline_parse_inst_t cmd_add_5tuple_filter =3D { + .f =3D cmd_5tuple_filter_parsed, + .data =3D NULL, + .help_str =3D "add a 5tuple filter", + .tokens =3D { + (void *)&cmd_5tuple_filter_add_filter, + (void *)&cmd_5tuple_filter_port_id, + (void *)&cmd_5tuple_filter_dst_ip, + (void *)&cmd_5tuple_filter_dst_ip_value, + (void *)&cmd_5tuple_filter_src_ip, + (void *)&cmd_5tuple_filter_src_ip_value, + (void *)&cmd_5tuple_filter_dst_port, + (void *)&cmd_5tuple_filter_dst_port_value, + (void *)&cmd_5tuple_filter_src_port, + (void *)&cmd_5tuple_filter_src_port_value, + (void *)&cmd_5tuple_filter_protocol, + (void *)&cmd_5tuple_filter_protocol_value, + (void *)&cmd_5tuple_filter_mask, + (void *)&cmd_5tuple_filter_mask_value, + (void *)&cmd_5tuple_filter_flags, + (void *)&cmd_5tuple_filter_flags_value, + (void *)&cmd_5tuple_filter_priority, + (void *)&cmd_5tuple_filter_priority_value, + (void *)&cmd_5tuple_filter_queue, + (void *)&cmd_5tuple_filter_queue_id, + (void *)&cmd_5tuple_filter_index, + (void *)&cmd_5tuple_filter_index_value, + NULL, + }, +}; + +cmdline_parse_token_string_t cmd_5tuple_filter_remove_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + filter, "remove_5tuple_filter"); +cmdline_parse_inst_t cmd_remove_5tuple_filter =3D { + .f =3D cmd_5tuple_filter_parsed, + .data =3D NULL, + .help_str =3D "remove a 5tuple filter", + .tokens =3D { + (void *)&cmd_5tuple_filter_remove_filter, + (void *)&cmd_5tuple_filter_port_id, + (void *)&cmd_5tuple_filter_index, + (void *)&cmd_5tuple_filter_index_value, + NULL, + }, +}; + +cmdline_parse_token_string_t cmd_5tuple_filter_get_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + filter, "get_5tuple_filter"); +cmdline_parse_inst_t cmd_get_5tuple_filter =3D { + .f =3D cmd_5tuple_filter_parsed, + .data =3D NULL, + .help_str =3D "get a 5tuple filter", + .tokens =3D { + (void *)&cmd_5tuple_filter_get_filter, + (void *)&cmd_5tuple_filter_port_id, + (void *)&cmd_5tuple_filter_index, + (void *)&cmd_5tuple_filter_index_value, + NULL, + }, +}; + +/* *** ADD/REMOVE A flex FILTER *** */ +struct cmd_flex_filter_result { + cmdline_fixed_string_t filter; + uint8_t port_id; + cmdline_fixed_string_t len; + uint8_t len_value; + cmdline_fixed_string_t bytes; + cmdline_fixed_string_t bytes_value; + cmdline_fixed_string_t mask; + cmdline_fixed_string_t mask_value; + cmdline_fixed_string_t priority; + uint8_t priority_value; + cmdline_fixed_string_t queue; + uint8_t queue_id; + cmdline_fixed_string_t index; + uint16_t index_value; +}; + +static int xdigit2val(unsigned char c) +{ + int val; + if (isdigit(c)) + val =3D c - '0'; + else if (isupper(c)) + val =3D c - 'A' + 10; + else + val =3D c - 'a' + 10; + return val; +} + +static void +cmd_flex_filter_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + int ret =3D 0; + struct rte_flex_filter filter; + struct cmd_flex_filter_result *res =3D parsed_result; + char *bytes_ptr, *mask_ptr; + uint16_t len, i, j; + char c; + int val, mod =3D 0; + uint32_t dword =3D 0; + uint8_t byte =3D 0; + uint8_t hex =3D 0; + + if (!strcmp(res->filter, "add_flex_filter")) { + if (res->len_value > 128) { + printf("the len exceed the max length 128\n"); + return; + } + memset(&filter, 0, sizeof(struct rte_flex_filter)); + filter.len =3D res->len_value; + filter.priority =3D res->priority_value; + bytes_ptr =3D res->bytes_value; + mask_ptr =3D res->mask_value; + + j =3D 0; + /** translate bytes string to uint_32 array*/ + if (bytes_ptr[0] =3D=3D '0' && ((bytes_ptr[1] =3D=3D 'x') || + (bytes_ptr[1] =3D=3D 'X'))) + bytes_ptr +=3D 2; + len =3D strnlen(bytes_ptr, res->len_value * 2); + if (len =3D=3D 0 || (len % 8 !=3D 0)) { + printf("please check len and bytes input\n"); + return; + } + for (i =3D 0; i < len; i++) { + c =3D bytes_ptr[i]; + if (isxdigit(c) =3D=3D 0) { + /** invalid characters */ + printf("invalid input\n"); + return; + } + val =3D xdigit2val(c); + mod =3D i % 8; + if (i % 2) { + byte |=3D val; + dword |=3D byte << (4 * mod - 4); + byte =3D 0; + } else + byte |=3D val << 4; + if (mod =3D=3D 7) { + filter.dwords[j] =3D dword; + printf("dwords[%d]:%08x ", j, filter.dwords[j]); + j++; + dword =3D 0; + } + } + printf("\n"); + /** translate mask string to uint8_t array*/ + j =3D 0; + if (mask_ptr[0] =3D=3D '0' && ((mask_ptr[1] =3D=3D 'x') || + (mask_ptr[1] =3D=3D 'X'))) + mask_ptr +=3D 2; + len =3D strnlen(mask_ptr, (res->len_value+3)/4); + if (len =3D=3D 0) { + printf("invalid input\n"); + return; + } + for (i =3D 0; i < len; i++) { + c =3D mask_ptr[i]; + if (isxdigit(c) =3D=3D 0) { + /** invalid characters */ + printf("invalid input\n"); + return; + } + val =3D xdigit2val(c); + hex |=3D (uint8_t)(val & 0x8) >> 3; + hex |=3D (uint8_t)(val & 0x4) >> 1; + hex |=3D (uint8_t)(val & 0x2) << 1; + hex |=3D (uint8_t)(val & 0x1) << 3; + if (i % 2) { + byte |=3D hex << 4; + filter.mask[j] =3D byte; + printf("mask[%d]:%02x ", j, filter.mask[j]); + j++; + byte =3D 0; + } else + byte |=3D hex; + hex =3D 0; + } + printf("\n"); + printf("call function rte_eth_dev_add_flex_filter: " + "index =3D %d, queue-id =3D %d, len =3D %d, priority =3D %d\n", + res->index_value, res->queue_id, + filter.len, filter.priority); + ret =3D rte_eth_dev_add_flex_filter(res->port_id, res->index_value, + &filter, res->queue_id); + + } else if (!strcmp(res->filter, "remove_flex_filter")) + ret =3D rte_eth_dev_remove_flex_filter(res->port_id, + res->index_value); + else if (!strcmp(res->filter, "get_flex_filter")) + get_flex_filter(res->port_id, res->index_value); + + if (ret < 0) + printf("flex filter setting error: (%s)\n", strerror(-ret)); +} + +cmdline_parse_token_num_t cmd_flex_filter_port_id =3D + TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, + port_id, UINT8); +cmdline_parse_token_string_t cmd_flex_filter_len =3D + TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, + len, "len"); +cmdline_parse_token_string_t cmd_flex_filter_len_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, + len_value, UINT8); +cmdline_parse_token_string_t cmd_flex_filter_bytes =3D + TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, + bytes, "bytes"); +cmdline_parse_token_string_t cmd_flex_filter_bytes_value =3D + TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, + bytes_value, NULL); +cmdline_parse_token_string_t cmd_flex_filter_mask =3D + TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, + mask, "mask"); +cmdline_parse_token_string_t cmd_flex_filter_mask_value =3D + TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, + mask_value, NULL); +cmdline_parse_token_string_t cmd_flex_filter_priority =3D + TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, + priority, "priority"); +cmdline_parse_token_num_t cmd_flex_filter_priority_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, + priority_value, UINT8); +cmdline_parse_token_string_t cmd_flex_filter_queue =3D + TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, + queue, "queue"); +cmdline_parse_token_num_t cmd_flex_filter_queue_id =3D + TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, + queue_id, UINT8); +cmdline_parse_token_string_t cmd_flex_filter_index =3D + TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, + index, "index"); +cmdline_parse_token_num_t cmd_flex_filter_index_value =3D + TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, + index_value, UINT16); +cmdline_parse_token_string_t cmd_flex_filter_add_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, + filter, "add_flex_filter"); +cmdline_parse_inst_t cmd_add_flex_filter =3D { + .f =3D cmd_flex_filter_parsed, + .data =3D NULL, + .help_str =3D "add a flex filter", + .tokens =3D { + (void *)&cmd_flex_filter_add_filter, + (void *)&cmd_flex_filter_port_id, + (void *)&cmd_flex_filter_len, + (void *)&cmd_flex_filter_len_value, + (void *)&cmd_flex_filter_bytes, + (void *)&cmd_flex_filter_bytes_value, + (void *)&cmd_flex_filter_mask, + (void *)&cmd_flex_filter_mask_value, + (void *)&cmd_flex_filter_priority, + (void *)&cmd_flex_filter_priority_value, + (void *)&cmd_flex_filter_queue, + (void *)&cmd_flex_filter_queue_id, + (void *)&cmd_flex_filter_index, + (void *)&cmd_flex_filter_index_value, + NULL, + }, +}; + +cmdline_parse_token_string_t cmd_flex_filter_remove_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, + filter, "remove_flex_filter"); +cmdline_parse_inst_t cmd_remove_flex_filter =3D { + .f =3D cmd_flex_filter_parsed, + .data =3D NULL, + .help_str =3D "remove a flex filter", + .tokens =3D { + (void *)&cmd_flex_filter_remove_filter, + (void *)&cmd_flex_filter_port_id, + (void *)&cmd_flex_filter_index, + (void *)&cmd_flex_filter_index_value, + NULL, + }, +}; + +cmdline_parse_token_string_t cmd_flex_filter_get_filter =3D + TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, + filter, "get_flex_filter"); +cmdline_parse_inst_t cmd_get_flex_filter =3D { + .f =3D cmd_flex_filter_parsed, + .data =3D NULL, + .help_str =3D "get a flex filter", + .tokens =3D { + (void *)&cmd_flex_filter_get_filter, + (void *)&cmd_flex_filter_port_id, + (void *)&cmd_flex_filter_index, + (void *)&cmd_flex_filter_index_value, + NULL, + }, +}; + /* ***********************************************************************= ********* */ =20 /* list of instructions */ @@ -5235,6 +6125,21 @@ cmdline_parse_ctx_t main_ctx[] =3D { (cmdline_parse_inst_t *)&cmd_reset_mirror_rule, (cmdline_parse_inst_t *)&cmd_dump, (cmdline_parse_inst_t *)&cmd_dump_one, + (cmdline_parse_inst_t *)&cmd_add_ethertype_filter, + (cmdline_parse_inst_t *)&cmd_remove_ethertype_filter, + (cmdline_parse_inst_t *)&cmd_get_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_add_2tuple_filter, + (cmdline_parse_inst_t *)&cmd_remove_2tuple_filter, + (cmdline_parse_inst_t *)&cmd_get_2tuple_filter, + (cmdline_parse_inst_t *)&cmd_add_5tuple_filter, + (cmdline_parse_inst_t *)&cmd_remove_5tuple_filter, + (cmdline_parse_inst_t *)&cmd_get_5tuple_filter, + (cmdline_parse_inst_t *)&cmd_add_flex_filter, + (cmdline_parse_inst_t *)&cmd_remove_flex_filter, + (cmdline_parse_inst_t *)&cmd_get_flex_filter, NULL, }; =20 diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 20ad0a8..3c38f14 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -1731,3 +1731,148 @@ set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, = uint64_t vf_mask, uint8_t on) "diag=3D%d\n", port_id, diag); } =20 +void +get_ethertype_filter(uint8_t port_id, uint16_t index) +{ + struct rte_ethertype_filter filter; + int ret =3D 0; + uint8_t rx_queue; + + memset(&filter, 0, sizeof(filter)); + ret =3D rte_eth_dev_get_ethertype_filter(port_id, index, + &filter, &rx_queue); + if (ret < 0) { + if (ret =3D=3D (-ENOENT)) + printf("filter[%d] is not enabled\n", index); + else + printf("get ethertype filter fails(%s)\n", strerror(-ret)); + return; + } else { + printf("filter[%d]:\n", index); + printf(" ethertype: 0x%04x\n", + rte_le_to_cpu_32(filter.ethertype)); + printf(" priority: %s, %d\n", + filter.priority_en ? "enable" : "disable", + filter.priority); + printf(" queue: %d\n", rx_queue); + } +} + +void +get_syn_filter(uint8_t port_id) +{ + struct rte_syn_filter filter; + int ret =3D 0; + uint8_t rx_queue; + + memset(&filter, 0, sizeof(filter)); + ret =3D rte_eth_dev_get_syn_filter(port_id, &filter, &rx_queue); + + if (ret < 0) { + printf("get syn filter fails(%s)\n", strerror(-ret)); + return; + } + printf("syn filter: %s, priority: %s, queue: %d\n", + filter.enable ? "on" : "off", + filter.hig_pri ? "high" : "low", + rx_queue); +} +void +get_2tuple_filter(uint8_t port_id, uint16_t index) +{ + struct rte_2tuple_filter filter; + int ret =3D 0; + uint8_t rx_queue; + + memset(&filter, 0, sizeof(filter)); + ret =3D rte_eth_dev_get_2tuple_filter(port_id, index, + &filter, &rx_queue); + if (ret < 0) { + if (ret =3D=3D (-ENOENT)) + printf("filter[%d] is not enabled\n", index); + else + printf("get 2tuple filter fails(%s)\n", strerror(-ret)); + return; + } else { + printf("filter[%d]:\n", index); + printf(" Destination Port: 0x%04x mask: %d\n", + rte_be_to_cpu_16(filter.dst_port), + filter.dst_port_mask ? 0 : 1); + printf(" protocol: 0x%02x mask:%d tcp_flags: 0x%02x\n", + filter.protocol, filter.protocol_mask ? 0 : 1, + filter.tcp_flags); + printf(" priority: %d queue: %d\n", + filter.priority, rx_queue); + } +} + +void +get_5tuple_filter(uint8_t port_id, uint16_t index) +{ + struct rte_5tuple_filter filter; + int ret =3D 0; + uint8_t rx_queue; + + memset(&filter, 0, sizeof(filter)); + ret =3D rte_eth_dev_get_5tuple_filter(port_id, index, + &filter, &rx_queue); + if (ret < 0) { + if (ret =3D=3D (-ENOENT)) + printf("filter[%d] is not enabled\n", index); + else + printf("get 5tuple filter fails(%s)\n", strerror(-ret)); + return; + } else { + printf("filter[%d]:\n", index); + printf(" Destination IP: 0x%08x mask: %d\n", + (unsigned)rte_be_to_cpu_32(filter.dst_ip), + filter.dst_ip_mask ? 0 : 1); + printf(" Source IP: 0x%08x mask: %d\n", + (unsigned)rte_be_to_cpu_32(filter.src_ip), + filter.src_ip_mask ? 0 : 1); + printf(" Destination Port: 0x%04x mask: %d\n", + rte_be_to_cpu_16(filter.dst_port), + filter.dst_port_mask ? 0 : 1); + printf(" Source Port: 0x%04x mask: %d\n", + rte_be_to_cpu_16(filter.src_port), + filter.src_port_mask ? 0 : 1); + printf(" protocol: 0x%02x mask: %d\n", + filter.protocol, + filter.protocol_mask ? 0 : 1); + printf(" priority: %d flags: 0x%02x queue: %d\n", + filter.priority, filter.tcp_flags, rx_queue); + } +} +void +get_flex_filter(uint8_t port_id, uint16_t index) + +{ + struct rte_flex_filter filter; + int ret =3D 0; + uint8_t rx_queue; + int i, j; + + memset(&filter, 0, sizeof(filter)); + ret =3D rte_eth_dev_get_flex_filter(port_id, index, + &filter, &rx_queue); + if (ret < 0) { + if (ret =3D=3D (-ENOENT)) + printf("filter[%d] is not enabled\n", index); + else + printf("get flex filter fails(%s)\n", strerror(-ret)); + return; + } else { + printf("filter[%d]: ", index); + printf("\n length: %d", filter.len); + printf("\n dword[]: 0x"); + for (i =3D 0; i < 32; i++) + printf("%08x ", (unsigned)rte_be_to_cpu_32(filter.dwords[i])); + printf("\n mask[]: 0b"); + for (i =3D 0; i < 16; i++) { + for (j =3D 0; j < 8; j++) + printf("%c", (filter.mask[i] & (1 << j)) ? '1' : '0'); + } + printf("\n priority: %d queue: %d\n", + filter.priority, rx_queue); + } +} diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 2bdb1a2..c7998a6 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -528,6 +528,12 @@ void set_vf_traffic(portid_t port_id, uint8_t is_rx, u= int16_t vf, uint8_t on); void set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id,=20 uint64_t vf_mask, uint8_t on); =20 +void get_syn_filter(uint8_t port_id); +void get_ethertype_filter(uint8_t port_id, uint16_t index); +void get_2tuple_filter(uint8_t port_id, uint16_t index); +void get_5tuple_filter(uint8_t port_id, uint16_t index); +void get_flex_filter(uint8_t port_id, uint16_t index); + /* * Work-around of a compilation error with ICC on invocations of the * rte_be_to_cpu_16() function. --=20 1.8.1.4