From: Jingjing Wu Date: Tue, 10 Feb 2015 04:48:31 +0000 (+0800) Subject: app/testpmd: new commands for ntuple filter X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=990d3703662c6c4b131d0820e640dc7200cc67df;p=dpdk.git app/testpmd: new commands for ntuple filter Following commands of 5tuple and 2tuple filter are removed: - add_2tuple_filter (port_id) protocol (pro_value) (pro_mask) dst_port (port_value) (port_mask) flags (flg_value) priority (prio_value) queue (queue_id) index (idx) - remove_2tuple_filter (port_id) index (idx) - get_2tuple_filter (port_id) index (idx) - add_5tuple_filter (port_id) dst_ip (dst_address) src_ip (src_address) dst_port (dst_port_value) src_port (src_port_value) protocol (protocol_value) mask (mask_value) flags (flags_value) priority (prio_value)" queue (queue_id) index (idx) - remove_5tuple_filter (port_id) index (idx) - get_5tuple_filter (port_id) index (idx) New commands are added for 5tuple and 2tuple filter by using filter_ctrl API and new ntuple filter structure: - 2tuple_filter (port_id) (add|del) dst_port (dst_port_value) protocol (protocol_value) mask (mask_value) tcp_flags (tcp_flags_value) priority (prio_value) queue (queue_id) - 5tuple_filter (port_id) (add|del) dst_ip (dst_address) src_ip (src_address) dst_port (dst_port_value) src_port (src_port_value) protocol (protocol_value) mask (mask_value) tcp_flags (tcp_flags_value) priority (prio_value) queue (queue_id) Test report: http://dpdk.org/ml/archives/dev/2015-February/013049.html Signed-off-by: Jingjing Wu Tested-by: Huilong Xu Acked-by: Pablo de Lara --- diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 0c304a0d49..7fbb2f554a 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -600,28 +600,19 @@ static void cmd_help_long_parsed(void *parsed_result, " (ether_type) (drop|fwd) queue (queue_id)\n" " Add/Del an 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_value)" - " 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 (protocol_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" + "2tuple_filter (port_id) (add|del)" + " dst_port (dst_port_value) protocol (protocol_value)" + " mask (mask_value) tcp_flags (tcp_flags_value)" + " priority (prio_value) queue (queue_id)\n" + " Add/Del a 2tuple filter.\n\n" - "get_5tuple_filter (port_id) index (idx)\n" - " get info of a 5tuple filter.\n\n" + "5tuple_filter (port_id) (add|del)" + " dst_ip (dst_address) src_ip (src_address)" + " dst_port (dst_port_value) src_port (src_port_value)" + " protocol (protocol_value)" + " mask (mask_value) tcp_flags (tcp_flags_value)" + " priority (prio_value) queue (queue_id)\n" + " Add/Del a 5tuple filter.\n\n" "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)" " Add/Del syn filter.\n\n" @@ -6886,21 +6877,20 @@ cmdline_parse_inst_t cmd_syn_filter = { /* *** 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; + uint8_t port_id; + cmdline_fixed_string_t ops; 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 protocol; + uint8_t protocol_value; + cmdline_fixed_string_t mask; + uint8_t mask_value; + cmdline_fixed_string_t tcp_flags; + uint8_t tcp_flags_value; cmdline_fixed_string_t priority; - uint8_t priority_value; + uint8_t priority_value; cmdline_fixed_string_t queue; - uint16_t queue_id; - cmdline_fixed_string_t index; - uint16_t index_value; + uint16_t queue_id; }; static void @@ -6908,59 +6898,92 @@ cmd_2tuple_filter_parsed(void *parsed_result, __attribute__((unused)) struct cmdline *cl, __attribute__((unused)) void *data) { - int ret = 0; - struct rte_2tuple_filter filter; + struct rte_eth_ntuple_filter filter; struct cmd_2tuple_filter_result *res = parsed_result; + int ret = 0; - memset(&filter, 0, sizeof(struct rte_2tuple_filter)); + ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE); + if (ret < 0) { + printf("ntuple filter is not supported on port %u.\n", + res->port_id); + return; + } - if (!strcmp(res->filter, "add_2tuple_filter")) { - /* need convert to big endian. */ - filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); - filter.protocol = res->protocol_value; - filter.dst_port_mask = (res->dst_port_mask) ? 0 : 1; - filter.protocol_mask = (res->protocol_mask) ? 0 : 1; - filter.priority = res->priority_value; - filter.tcp_flags = res->flags_value; - ret = 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 = 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); + memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter)); + filter.flags = RTE_2TUPLE_FLAGS; + filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0; + filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0; + filter.proto = res->protocol_value; + filter.priority = res->priority_value; + if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) { + printf("nonzero tcp_flags is only meaningful" + " when protocol is TCP.\n"); + return; + } + if (res->tcp_flags_value > TCP_FLAG_ALL) { + printf("invalid TCP flags.\n"); + return; + } + + if (res->tcp_flags_value != 0) { + filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG; + filter.tcp_flags = res->tcp_flags_value; + } + + /* need convert to big endian. */ + filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); + filter.queue = res->queue_id; + + if (!strcmp(res->ops, "add")) + ret = rte_eth_dev_filter_ctrl(res->port_id, + RTE_ETH_FILTER_NTUPLE, + RTE_ETH_FILTER_ADD, + &filter); + else + ret = rte_eth_dev_filter_ctrl(res->port_id, + RTE_ETH_FILTER_NTUPLE, + RTE_ETH_FILTER_DELETE, + &filter); if (ret < 0) - printf("2tuple filter setting error: (%s)\n", strerror(-ret)); + printf("2tuple filter programming error: (%s)\n", + strerror(-ret)); + } +cmdline_parse_token_string_t cmd_2tuple_filter_filter = + TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, + filter, "2tuple_filter"); cmdline_parse_token_num_t cmd_2tuple_filter_port_id = TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, port_id, UINT8); -cmdline_parse_token_string_t cmd_2tuple_filter_protocol = +cmdline_parse_token_string_t cmd_2tuple_filter_ops = TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, - protocol, "protocol"); -cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value = - TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, - protocol_value, UINT8); -cmdline_parse_token_num_t cmd_2tuple_filter_protocol_mask = - TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, - protocol_mask, UINT8); + ops, "add#del"); cmdline_parse_token_string_t cmd_2tuple_filter_dst_port = TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, dst_port, "dst_port"); cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value = TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, dst_port_value, UINT16); -cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_mask = +cmdline_parse_token_string_t cmd_2tuple_filter_protocol = + TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, + protocol, "protocol"); +cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value = + TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, + protocol_value, UINT8); +cmdline_parse_token_string_t cmd_2tuple_filter_mask = + TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, + mask, "mask"); +cmdline_parse_token_num_t cmd_2tuple_filter_mask_value = TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, - dst_port_mask, UINT16); -cmdline_parse_token_string_t cmd_2tuple_filter_flags = + mask_value, INT8); +cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags = TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, - flags, "flags"); -cmdline_parse_token_num_t cmd_2tuple_filter_flags_value = + tcp_flags, "tcp_flags"); +cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value = TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, - flags_value, UINT8); + tcp_flags_value, UINT8); cmdline_parse_token_string_t cmd_2tuple_filter_priority = TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, priority, "priority"); @@ -6973,67 +6996,27 @@ cmdline_parse_token_string_t cmd_2tuple_filter_queue = cmdline_parse_token_num_t cmd_2tuple_filter_queue_id = TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, queue_id, UINT16); -cmdline_parse_token_string_t cmd_2tuple_filter_index = - TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, - index, "index"); -cmdline_parse_token_num_t cmd_2tuple_filter_index_value = - TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, - index_value, UINT16); -cmdline_parse_token_string_t cmd_2tuple_filter_add_filter = - TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, - filter, "add_2tuple_filter"); -cmdline_parse_inst_t cmd_add_2tuple_filter = { + +cmdline_parse_inst_t cmd_2tuple_filter = { .f = cmd_2tuple_filter_parsed, .data = NULL, .help_str = "add a 2tuple filter", .tokens = { - (void *)&cmd_2tuple_filter_add_filter, + (void *)&cmd_2tuple_filter_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_ops, (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_protocol, + (void *)&cmd_2tuple_filter_protocol_value, + (void *)&cmd_2tuple_filter_mask, + (void *)&cmd_2tuple_filter_mask_value, + (void *)&cmd_2tuple_filter_tcp_flags, + (void *)&cmd_2tuple_filter_tcp_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 = - TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, - filter, "remove_2tuple_filter"); -cmdline_parse_inst_t cmd_remove_2tuple_filter = { - .f = cmd_2tuple_filter_parsed, - .data = NULL, - .help_str = "remove a 2tuple filter", - .tokens = { - (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 = - TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, - filter, "get_2tuple_filter"); -cmdline_parse_inst_t cmd_get_2tuple_filter = { - .f = cmd_2tuple_filter_parsed, - .data = NULL, - .help_str = "get a 2tuple filter", - .tokens = { - (void *)&cmd_2tuple_filter_get_filter, - (void *)&cmd_2tuple_filter_port_id, - (void *)&cmd_2tuple_filter_index, - (void *)&cmd_2tuple_filter_index_value, NULL, }, }; @@ -7042,6 +7025,7 @@ cmdline_parse_inst_t cmd_get_2tuple_filter = { struct cmd_5tuple_filter_result { cmdline_fixed_string_t filter; uint8_t port_id; + cmdline_fixed_string_t ops; cmdline_fixed_string_t dst_ip; cmdline_ipaddr_t dst_ip_value; cmdline_fixed_string_t src_ip; @@ -7054,14 +7038,12 @@ struct cmd_5tuple_filter_result { 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 tcp_flags; + uint8_t tcp_flags_value; cmdline_fixed_string_t priority; uint8_t priority_value; cmdline_fixed_string_t queue; uint16_t queue_id; - cmdline_fixed_string_t index; - uint16_t index_value; }; static void @@ -7069,62 +7051,92 @@ cmd_5tuple_filter_parsed(void *parsed_result, __attribute__((unused)) struct cmdline *cl, __attribute__((unused)) void *data) { - int ret = 0; - struct rte_5tuple_filter filter; + struct rte_eth_ntuple_filter filter; struct cmd_5tuple_filter_result *res = parsed_result; + int ret = 0; - memset(&filter, 0, sizeof(struct rte_5tuple_filter)); - - if (!strcmp(res->filter, "add_5tuple_filter")) { - filter.dst_ip_mask = (res->mask_value & 0x10) ? 0 : 1; - filter.src_ip_mask = (res->mask_value & 0x08) ? 0 : 1; - filter.dst_port_mask = (res->mask_value & 0x04) ? 0 : 1; - filter.src_port_mask = (res->mask_value & 0x02) ? 0 : 1; - filter.protocol = res->protocol_value; - filter.protocol_mask = (res->mask_value & 0x01) ? 0 : 1; - filter.priority = res->priority_value; - filter.tcp_flags = res->flags_value; - - if (res->dst_ip_value.family == AF_INET) - /* no need to convert, already big endian. */ - filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr; - else { - if (filter.dst_ip_mask == 0) { - printf("can not support ipv6 involved compare.\n"); - return; - } - filter.dst_ip = 0; + ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE); + if (ret < 0) { + printf("ntuple filter is not supported on port %u.\n", + res->port_id); + return; + } + + memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter)); + + filter.flags = RTE_5TUPLE_FLAGS; + filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0; + filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0; + filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0; + filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0; + filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0; + filter.proto = res->protocol_value; + filter.priority = res->priority_value; + if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) { + printf("nonzero tcp_flags is only meaningful" + " when protocol is TCP.\n"); + return; + } + if (res->tcp_flags_value > TCP_FLAG_ALL) { + printf("invalid TCP flags.\n"); + return; + } + + if (res->tcp_flags_value != 0) { + filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG; + filter.tcp_flags = res->tcp_flags_value; + } + + if (res->dst_ip_value.family == AF_INET) + /* no need to convert, already big endian. */ + filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr; + else { + if (filter.dst_ip_mask == 0) { + printf("can not support ipv6 involved compare.\n"); + return; } + filter.dst_ip = 0; + } - if (res->src_ip_value.family == AF_INET) - /* no need to convert, already big endian. */ - filter.src_ip = res->src_ip_value.addr.ipv4.s_addr; - else { - if (filter.src_ip_mask == 0) { - printf("can not support ipv6 involved compare.\n"); - return; - } - filter.src_ip = 0; + if (res->src_ip_value.family == AF_INET) + /* no need to convert, already big endian. */ + filter.src_ip = res->src_ip_value.addr.ipv4.s_addr; + else { + if (filter.src_ip_mask == 0) { + printf("can not support ipv6 involved compare.\n"); + return; } - /* need convert to big endian. */ - filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); - filter.src_port = rte_cpu_to_be_16(res->src_port_value); - - ret = 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 = 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); + filter.src_ip = 0; + } + /* need convert to big endian. */ + filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); + filter.src_port = rte_cpu_to_be_16(res->src_port_value); + filter.queue = res->queue_id; + + if (!strcmp(res->ops, "add")) + ret = rte_eth_dev_filter_ctrl(res->port_id, + RTE_ETH_FILTER_NTUPLE, + RTE_ETH_FILTER_ADD, + &filter); + else + ret = rte_eth_dev_filter_ctrl(res->port_id, + RTE_ETH_FILTER_NTUPLE, + RTE_ETH_FILTER_DELETE, + &filter); if (ret < 0) - printf("5tuple filter setting error: (%s)\n", strerror(-ret)); + printf("5tuple filter programming error: (%s)\n", + strerror(-ret)); } - +cmdline_parse_token_string_t cmd_5tuple_filter_filter = + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + filter, "5tuple_filter"); cmdline_parse_token_num_t cmd_5tuple_filter_port_id = TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, port_id, UINT8); +cmdline_parse_token_string_t cmd_5tuple_filter_ops = + TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, + ops, "add#del"); cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip = TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, dst_ip, "dst_ip"); @@ -7161,12 +7173,12 @@ cmdline_parse_token_string_t cmd_5tuple_filter_mask = cmdline_parse_token_num_t cmd_5tuple_filter_mask_value = TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, mask_value, INT8); -cmdline_parse_token_string_t cmd_5tuple_filter_flags = +cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags = TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, - flags, "flags"); -cmdline_parse_token_num_t cmd_5tuple_filter_flags_value = + tcp_flags, "tcp_flags"); +cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value = TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, - flags_value, UINT8); + tcp_flags_value, UINT8); cmdline_parse_token_string_t cmd_5tuple_filter_priority = TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, priority, "priority"); @@ -7179,23 +7191,15 @@ cmdline_parse_token_string_t cmd_5tuple_filter_queue = cmdline_parse_token_num_t cmd_5tuple_filter_queue_id = TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, queue_id, UINT16); -cmdline_parse_token_string_t cmd_5tuple_filter_index = - TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, - index, "index"); -cmdline_parse_token_num_t cmd_5tuple_filter_index_value = - TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, - index_value, UINT16); -cmdline_parse_token_string_t cmd_5tuple_filter_add_filter = - TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, - filter, "add_5tuple_filter"); -cmdline_parse_inst_t cmd_add_5tuple_filter = { +cmdline_parse_inst_t cmd_5tuple_filter = { .f = cmd_5tuple_filter_parsed, .data = NULL, - .help_str = "add a 5tuple filter", + .help_str = "add/del a 5tuple filter", .tokens = { - (void *)&cmd_5tuple_filter_add_filter, + (void *)&cmd_5tuple_filter_filter, (void *)&cmd_5tuple_filter_port_id, + (void *)&cmd_5tuple_filter_ops, (void *)&cmd_5tuple_filter_dst_ip, (void *)&cmd_5tuple_filter_dst_ip_value, (void *)&cmd_5tuple_filter_src_ip, @@ -7208,46 +7212,12 @@ cmdline_parse_inst_t cmd_add_5tuple_filter = { (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_tcp_flags, + (void *)&cmd_5tuple_filter_tcp_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 = - TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, - filter, "remove_5tuple_filter"); -cmdline_parse_inst_t cmd_remove_5tuple_filter = { - .f = cmd_5tuple_filter_parsed, - .data = NULL, - .help_str = "remove a 5tuple filter", - .tokens = { - (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 = - TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, - filter, "get_5tuple_filter"); -cmdline_parse_inst_t cmd_get_5tuple_filter = { - .f = cmd_5tuple_filter_parsed, - .data = NULL, - .help_str = "get a 5tuple filter", - .tokens = { - (void *)&cmd_5tuple_filter_get_filter, - (void *)&cmd_5tuple_filter_port_id, - (void *)&cmd_5tuple_filter_index, - (void *)&cmd_5tuple_filter_index_value, NULL, }, }; @@ -8714,12 +8684,8 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_dump_one, (cmdline_parse_inst_t *)&cmd_ethertype_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, - (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_2tuple_filter, + (cmdline_parse_inst_t *)&cmd_5tuple_filter, (cmdline_parse_inst_t *)&cmd_flex_filter, (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director, (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director, diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index fc91a6d24a..a636dcaf1b 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -2058,70 +2058,3 @@ set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk) port_id, diag); return diag; } - -void -get_2tuple_filter(uint8_t port_id, uint16_t index) -{ - struct rte_2tuple_filter filter; - int ret = 0; - uint16_t rx_queue; - - memset(&filter, 0, sizeof(filter)); - ret = rte_eth_dev_get_2tuple_filter(port_id, index, - &filter, &rx_queue); - if (ret < 0) { - if (ret == (-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 = 0; - uint16_t rx_queue; - - memset(&filter, 0, sizeof(filter)); - ret = rte_eth_dev_get_5tuple_filter(port_id, index, - &filter, &rx_queue); - if (ret < 0) { - if (ret == (-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); - } -} diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 6b3cf86217..afe197012d 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -1234,76 +1234,48 @@ Example, to add/remove an ethertype filter rule: testpmd> ethertype_filter 0 add mac_ignr ethertype 0x0806 fwd queue 3 testpmd> ethertype_filter 0 del mac_ignr ethertype 0x0806 fwd queue 3 -add_2tuple_filter +2tuple_filter ~~~~~~~~~~~~~~~~~ -Add a 2-tuple filter, +Add or delete a 2-tuple filter, which identify packets by specific protocol and destination TCP/UDP port and forwards packets into one of the receive queues. -add_2tuple_filter (port_id) protocol (pro_value) (pro_mask) dst_port (port_value) (port_mask) -flags (flg_value) priority (prio_value) queue (queue_id) index (idx) +2tuple_filter (port_id) (add|del) dst_port (dst_port_value) protocol (protocol_value) +mask (mask_value) tcp_flags (tcp_flags_value) priority (prio_value) queue (queue_id) The available information parameters are: * port_id: the port which the 2-tuple filter assigned on. -* pro_value: IP L4 protocol +* dst_port_value: destination port in L4. -* pro_mask: protocol participates in the match or not, 1 means participate +* protocol_value: IP L4 protocol. -* port_value: destination port in L4. +* mask_value: participates in the match or not by bit for field above, 1b means participate. -* port_mask: destination port participates in the match or not, 1 means participate. +* tcp_flags_value: TCP control bits. The non-zero value is invalid, when the pro_value is not set to 0x06 (TCP). -* flg_value: TCP control bits. The non-zero value is invalid, when the pro_value is not set to 0x06 (TCP). +* prio_value: priority of this filter. -* prio_value: the priority of this filter. - -* queue_id: The receive queue associated with this 2-tuple filter - -* index: the index of this 2-tuple filter - -Example: +* queue_id: The receive queue associated with this 2-tuple filter. -.. code-block:: console - - testpmd> add_2tuple_filter 0 protocol 0x06 1 dst_port 32 1 flags 0x02 priority 3 queue 3 index 0 - -remove_2tuple_filter -~~~~~~~~~~~~~~~~~~~~ - -Remove a 2-tuple filter - -remove_2tuple_filter (port_id) index (idx) - -get_2tuple_filter -~~~~~~~~~~~~~~~~~ - -Get and display a 2-tuple filter - -get_2tuple_filter (port_id) index (idx) - -Example: +Example, to add/remove an 2tuple filter rule: .. code-block:: console - testpmd> get_2tuple_filter 0 index 0 + testpmd> 2tuple_filter 0 add dst_port 32 protocol 0x06 mask 0x03 tcp_flags 0x02 priority 3 queue 3 + testpmd> 2tuple_filter 0 del dst_port 32 protocol 0x06 mask 0x03 tcp_flags 0x02 priority 3 queue 3 - filter[0]: - Destination Port: 0x0020 mask: 1 - protocol: 0x06 mask:1 tcp_flags: 0x02 - priority: 3 queue: 3 - -add_5tuple_filter +5tuple_filter ~~~~~~~~~~~~~~~~~ -Add a 5-tuple filter, +Add or delete a 5-tuple filter, which consists of a 5-tuple (protocol, source and destination IP addresses, source and destination TCP/UDP/SCTP port) and routes packets into one of the receive queues. -add_5tuple_filter (port_id) dst_ip (dst_address) src_ip (src_address) dst_port (dst_port_value) src_port (src_port_value) -protocol (protocol_value) mask (mask_value) flags (flags_value) priority (prio_value) queue (queue_id) index (idx) +5tuple_filter (port_id) (add|del) dst_ip (dst_address) src_ip (src_address) dst_port (dst_port_value) src_port (src_port_value) +protocol (protocol_value) mask (mask_value) tcp_flags (tcp_flags_value) priority (prio_value) queue (queue_id) The available information parameters are: @@ -1321,47 +1293,18 @@ The available information parameters are: * mask_value: participates in the match or not by bit for field above, 1b means participate -* flags_value: TCP control bits. The non-zero value is invalid, when the protocol_value is not set to 0x06 (TCP). +* tcp_flags_value: TCP control bits. The non-zero value is invalid, when the protocol_value is not set to 0x06 (TCP). * prio_value: the priority of this filter. * queue_id: The receive queue associated with this 5-tuple filter. -* index: the index of this 5-tuple filter - -Example: +Example, to add/remove an 5tuple filter rule: .. code-block:: console - testpmd> add_5tuple_filter 1 dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 64 src_port 32 protocol 0x06 mask 0x1F flags 0x0 priority 3 queue 3 index 0 - -remove_5tuple_filter -~~~~~~~~~~~~~~~~~~~~ - -Remove a 5-tuple filter - -remove_5tuple_filter (port_id) index (idx) - -get_5tuple_filter -~~~~~~~~~~~~~~~~~ - -Get and display a 5-tuple filter - -get_5tuple_filter (port_id) index (idx) - -Example: - -.. code-block:: console - - testpmd> get_5tuple_filter 1 index 0 - - filter[0]: - Destination IP: 0x02020205 mask: 1 - Source IP: 0x02020204 mask: 1 - Destination Port: 0x0040 mask: 1 - Source Port: 0x0020 mask: 1 - protocol: 0x06 mask: 1 - priority: 3 flags: 0x00 queue: 3 + testpmd> 5tuple_filter 0 add dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 64 src_port 32 protocol 0x06 mask 0x1F flags 0x0 priority 3 queue 3 + testpmd> 5tuple_filter 0 del dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 64 src_port 32 protocol 0x06 mask 0x1F flags 0x0 priority 3 queue 3 syn_filter ~~~~~~~~~~~~~~