From: Long Wu <long...@corigine.com> Introduce a new command to show the VLAN identifiers filtered by a port. Usage example: testpmd> rx_vlan show port 0 VLAN filter IDs: 1,4-5,9,12,14,18,3864-3865,3869,3874,3878,4076-4091,4093,4095, testpmd>
Signed-off-by: Long Wu <long...@corigine.com> Reviewed-by: Chaoyong He <chaoyong...@corigine.com> --- app/test-pmd/cmdline.c | 46 +++++++++++++++ app/test-pmd/config.c | 64 +++++++++++++++++++++ app/test-pmd/testpmd.h | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 7 +++ 4 files changed, 118 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 5a627a9bc6..0ac50545b0 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -4718,6 +4718,51 @@ static cmdline_parse_inst_t cmd_rx_vlan_filter = { }, }; +/* *** SHOW VLAN IDENTIFIERS FROM A PORT VLAN RX FILTER *** */ +struct cmd_rx_vlan_filter_show_result { + cmdline_fixed_string_t rx_vlan; + cmdline_fixed_string_t show; + cmdline_fixed_string_t port; + portid_t port_id; +}; + +static void +cmd_rx_vlan_filter_show_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_rx_vlan_filter_show_result *res = parsed_result; + + rx_vft_dump(res->port_id); +} + +static cmdline_parse_token_string_t cmd_rx_vlan_filter_show_rx_vlan = + TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_show_result, + rx_vlan, "rx_vlan"); +static cmdline_parse_token_string_t cmd_rx_vlan_filter_show_show = + TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_show_result, + show, "show"); +static cmdline_parse_token_string_t cmd_rx_vlan_filter_show_port = + TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_show_result, + port, "port"); +static cmdline_parse_token_num_t cmd_rx_vlan_filter_show_portid = + TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_show_result, + port_id, RTE_UINT16); +static cmdline_parse_inst_t cmd_rx_vlan_filter_show = { + .f = cmd_rx_vlan_filter_show_parsed, + .data = NULL, + .help_str = "rx_vlan show port <port_id>: " + "Show VLAN identifiers from the set of VLAN identifiers " + "filtered by a port", + .tokens = { + (void *)&cmd_rx_vlan_filter_show_rx_vlan, + (void *)&cmd_rx_vlan_filter_show_show, + (void *)&cmd_rx_vlan_filter_show_port, + (void *)&cmd_rx_vlan_filter_show_portid, + NULL, + }, +}; + /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ struct cmd_tx_vlan_set_result { cmdline_fixed_string_t tx_vlan; @@ -13756,6 +13801,7 @@ static cmdline_parse_ctx_t builtin_ctx[] = { &cmd_vlan_tpid, &cmd_rx_vlan_filter_all, &cmd_rx_vlan_filter, + &cmd_rx_vlan_filter_show, &cmd_tx_vlan_set, &cmd_tx_vlan_set_qinq, &cmd_tx_vlan_reset, diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 61f93a9ca5..313d49812d 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -6676,6 +6676,70 @@ rx_vft_list_parse(uint16_t *vlan_id, char *vlan_id_list) return count; } +static void +rx_vft_dump_printf(int left, int right, int *c_count) +{ + if (left == right) + *c_count += printf("%d,", left); + else + *c_count += printf("%d-%d,", left, right); + + if (*c_count >= 120) { + *c_count = 0; + printf("\n"); + } +} + +void +rx_vft_dump(uint16_t port_id) +{ + int ret; + uint16_t vidx; + uint16_t vbit; + uint64_t vmap; + int left, right, c_count; + struct rte_vlan_filter_conf vfc; + + ret = rte_eth_dev_get_vlan_filter_conf(port_id, &vfc); + if (ret != 0) { + fprintf(stderr, + "Get VLAN filter configuration from port %u failed, ret = %d\n", + port_id, ret); + return; + } + + printf("VLAN filter IDs:\n"); + + left = -1; + right = -1; + c_count = 0; + for (vidx = 0; vidx < 64; vidx++) { + vmap = vfc.ids[vidx]; + for (vbit = 0; vbit < 64; vbit++) { + if ((vmap & RTE_BIT64(vbit)) != 0) { + if (left == -1) + left = vidx * 64 + vbit; + + continue; + } + + if (left != -1) { + right = vidx * 64 + vbit - 1; + rx_vft_dump_printf(left, right, &c_count); + left = -1; + right = -1; + } + } + } + + if (left != -1 && right == -1) { + right = 4095; + rx_vft_dump_printf(left, right, &c_count); + } + + printf("\n"); +} + void vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id) { diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index ac4f716408..610e130c56 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -1104,6 +1104,7 @@ void rx_vlan_filter_set(portid_t port_id, int on); void rx_vlan_all_filter_set(portid_t port_id, int on); void rx_vlan_qinq_strip_set(portid_t port_id, int on); int rx_vft_list_parse(uint16_t *vlan_id, char *vlan_id_list); +void rx_vft_dump(uint16_t port_id); int rx_vft_set(portid_t port_id, uint16_t vlan_id, int on); void vlan_extend_set(portid_t port_id, int on); void vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index b35722d2f5..0eb326e1d2 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -1064,6 +1064,13 @@ For example, to remove some VLAN identifiers filtered by port: testpmd> rx_vlan rm 1,3-4,7 0 +rx_vlan show +~~~~~~~~~~~~ + +Show VLAN identifiers from the set of VLAN identifiers filtered by a port:: + + testpmd> rx_vlan show port (port_id) + rx_vlan add (for VF) ~~~~~~~~~~~~~~~~~~~~ -- 2.43.5