DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com, Long Wu <long.wu@corigine.com>,
	Chaoyong He <chaoyong.he@corigine.com>
Subject: [PATCH 3/3] app/testpmd: add a command to show VLAN filter IDs
Date: Fri, 11 Apr 2025 16:10:05 +0800	[thread overview]
Message-ID: <20250411081005.1133509-4-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20250411081005.1133509-1-chaoyong.he@corigine.com>

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(+)

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


      parent reply	other threads:[~2025-04-11  8:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-11  8:10 [PATCH 0/3] enhance the vlan filter feature Chaoyong He
2025-04-11  8:10 ` [PATCH 1/3] app/testpmd: add/remove multiple VLAN filter IDs at once Chaoyong He
2025-04-11 16:27   ` Stephen Hemminger
2025-04-14  6:26     ` Chaoyong He
2025-04-11  8:10 ` [PATCH 2/3] ethdev: retrieve VLAN filter configuration Chaoyong He
2025-04-11  8:10 ` Chaoyong He [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250411081005.1133509-4-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=dev@dpdk.org \
    --cc=long.wu@corigine.com \
    --cc=oss-drivers@corigine.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).