[3/3] app/testpmd: add a command to show VLAN filter IDs

Message ID 20250411081005.1133509-4-chaoyong.he@corigine.com (mailing list archive)
State Changes Requested
Delegated to: Stephen Hemminger
Headers
Series enhance the vlan filter feature |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-mellanox-Functional success Functional Testing PASS

Commit Message

Chaoyong He April 11, 2025, 8:10 a.m. UTC
From: Long Wu <long.wu@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.wu@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@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(+)
  

Comments

Stephen Hemminger April 18, 2025, 6:42 p.m. UTC | #1
On Fri, 11 Apr 2025 16:10:05 +0800
Chaoyong He <chaoyong.he@corigine.com> wrote:

> +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");
> +	}
> +}
> +

Since VLAN id's are unsigned, should really not be using int.

If you are really going to have lines that long, must be a real
mess of a config. 

Once again, this is getting to be overkill for normal usage.
  

Patch

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)
 ~~~~~~~~~~~~~~~~~~~~