From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Aman Singh <aman.deep.singh@intel.com>
Subject: [RFC 12/13] app/testpmd: support for port mirroring
Date: Fri, 11 Apr 2025 16:44:49 -0700 [thread overview]
Message-ID: <20250411234927.114568-13-stephen@networkplumber.org> (raw)
In-Reply-To: <20250411234927.114568-1-stephen@networkplumber.org>
Add new commands to enable testing of port mirror functionality.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
app/test-pmd/cmdline.c | 1 +
app/test-pmd/cmdline_mirror.c | 120 ++++++++++++++++++++
app/test-pmd/cmdline_mirror.h | 12 ++
app/test-pmd/meson.build | 1 +
doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 +++
5 files changed, 149 insertions(+)
create mode 100644 app/test-pmd/cmdline_mirror.c
create mode 100644 app/test-pmd/cmdline_mirror.h
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index b4089d281b..64ba094e04 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -66,6 +66,7 @@
#include "testpmd.h"
#include "cmdline_cman.h"
#include "cmdline_mtr.h"
+#include "cmdline_mirror.h"
#include "cmdline_tm.h"
#include "bpf_cmd.h"
diff --git a/app/test-pmd/cmdline_mirror.c b/app/test-pmd/cmdline_mirror.c
new file mode 100644
index 0000000000..cea41302e1
--- /dev/null
+++ b/app/test-pmd/cmdline_mirror.c
@@ -0,0 +1,120 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2025 Stephen Hemminger <stephen@networkplumber.org>
+ */
+
+#include <stdlib.h>
+
+#include <cmdline_parse.h>
+#include <cmdline_parse_num.h>
+#include <cmdline_parse_string.h>
+
+#include <rte_ethdev.h>
+
+#include "testpmd.h"
+#include "cmdline_mirror.h"
+
+/* *** Create Port Mirror Object *** */
+struct cmd_create_port_mirror_result {
+ cmdline_fixed_string_t create;
+ cmdline_fixed_string_t port;
+ cmdline_fixed_string_t mirror;
+ uint16_t port_id;
+ cmdline_fixed_string_t destination;
+ uint16_t target_id;
+};
+
+static cmdline_parse_token_string_t cmd_create_port_mirror_create =
+ TOKEN_STRING_INITIALIZER(struct cmd_create_port_mirror_result, create, "create");
+static cmdline_parse_token_string_t cmd_create_port_mirror_port =
+ TOKEN_STRING_INITIALIZER(struct cmd_create_port_mirror_result, port, "port");
+static cmdline_parse_token_string_t cmd_create_port_mirror_mirror =
+ TOKEN_STRING_INITIALIZER(struct cmd_create_port_mirror_result, mirror, "mirror");
+static cmdline_parse_token_string_t cmd_create_port_mirror_destination =
+ TOKEN_STRING_INITIALIZER(struct cmd_create_port_mirror_result, destination, "destination");
+static cmdline_parse_token_num_t cmd_create_port_mirror_port_id =
+ TOKEN_NUM_INITIALIZER(struct cmd_create_port_mirror_result, port_id, RTE_UINT16);
+static cmdline_parse_token_num_t cmd_create_port_mirror_target_id =
+ TOKEN_NUM_INITIALIZER(struct cmd_create_port_mirror_result, target_id, RTE_UINT16);
+
+static void cmd_create_port_mirror_parsed(void *parsed_result,
+ __rte_unused struct cmdline *cl,
+ __rte_unused void *data)
+{
+ const struct cmd_create_port_mirror_result *res = parsed_result;
+ struct rte_eth_mirror_conf mirror_conf = {
+ .snaplen = RTE_MBUF_DEFAULT_BUF_SIZE,
+ .direction = RTE_MIRROR_DIRECTION_INGRESS | RTE_MIRROR_DIRECTION_EGRESS
+ };
+ int ret;
+
+ if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+ return;
+
+ if (port_id_is_invalid(res->target_id, ENABLED_WARN))
+ return;
+
+ ret = rte_eth_add_mirror(res->port_id, res->target_id, &mirror_conf);
+ if (ret != 0)
+ fprintf(stderr, "%s\n", rte_strerror(-ret));
+}
+
+cmdline_parse_inst_t cmd_create_port_mirror = {
+ .f = cmd_create_port_mirror_parsed,
+ .data = NULL,
+ .help_str = "create port mirror <port_id> destination <port_id>",
+ .tokens = {
+ (void *)&cmd_create_port_mirror_create,
+ (void *)&cmd_create_port_mirror_port,
+ (void *)&cmd_create_port_mirror_mirror,
+ (void *)&cmd_create_port_mirror_port_id,
+ (void *)&cmd_create_port_mirror_destination,
+ (void *)&cmd_create_port_mirror_target_id,
+ NULL
+ },
+};
+
+/* *** Disable Port Mirror Object *** */
+struct cmd_disable_port_mirror_result {
+ cmdline_fixed_string_t disable;
+ cmdline_fixed_string_t port;
+ cmdline_fixed_string_t mirror;
+ uint16_t port_id;
+};
+
+static void cmd_disable_port_mirror_parsed(void *parsed_result,
+ __rte_unused struct cmdline *cl,
+ __rte_unused void *data)
+{
+ const struct cmd_disable_port_mirror_result *res = parsed_result;
+ int ret;
+
+ if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+ return;
+
+ /* Disable Mirror */
+ ret = rte_eth_remove_mirror(res->port_id);
+ if (ret != 0)
+ fprintf(stderr, "%s\n", rte_strerror(-ret));
+}
+
+static cmdline_parse_token_string_t cmd_disable_port_mirror_disable =
+ TOKEN_STRING_INITIALIZER(struct cmd_disable_port_mirror_result, disable, "disable");
+static cmdline_parse_token_string_t cmd_disable_port_mirror_port =
+ TOKEN_STRING_INITIALIZER(struct cmd_disable_port_mirror_result, port, "port");
+static cmdline_parse_token_string_t cmd_disable_port_mirror_mirror =
+ TOKEN_STRING_INITIALIZER(struct cmd_disable_port_mirror_result, mirror, "mirror");
+static cmdline_parse_token_num_t cmd_disable_port_mirror_port_id =
+ TOKEN_NUM_INITIALIZER(struct cmd_disable_port_mirror_result, port_id, RTE_UINT16);
+
+cmdline_parse_inst_t cmd_disable_port_mirror = {
+ .f = cmd_disable_port_mirror_parsed,
+ .data = NULL,
+ .help_str = "disable port mirror <port_id>",
+ .tokens = {
+ (void *)&cmd_disable_port_mirror_disable,
+ (void *)&cmd_disable_port_mirror_port,
+ (void *)&cmd_disable_port_mirror_mirror,
+ (void *)&cmd_disable_port_mirror_port_id,
+ NULL
+ },
+};
diff --git a/app/test-pmd/cmdline_mirror.h b/app/test-pmd/cmdline_mirror.h
new file mode 100644
index 0000000000..23ebe1ed75
--- /dev/null
+++ b/app/test-pmd/cmdline_mirror.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2025 Stephen Hemminger <stephen@networkplumber.org>
+ */
+
+#ifndef _CMDLINE_MIRROR_H_
+#define _CMDLINE_MIRROR_H_
+
+/* Port MIRROR commands */
+extern cmdline_parse_inst_t cmd_create_port_mirror;
+extern cmdline_parse_inst_t cmd_disable_port_mirror;
+
+#endif /* _CMDLINE_MIRROR_H_ */
diff --git a/app/test-pmd/meson.build b/app/test-pmd/meson.build
index 000548c261..f34d80bb5d 100644
--- a/app/test-pmd/meson.build
+++ b/app/test-pmd/meson.build
@@ -9,6 +9,7 @@ sources = files(
'cmdline_cman.c',
'cmdline_flow.c',
'cmdline_mtr.c',
+ 'cmdline_mirror.c',
'cmdline_tm.c',
'cmd_flex_item.c',
'config.c',
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index eeef49500f..ea94f993fe 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -2568,6 +2568,21 @@ where:
* ``clear``: Flag that indicates whether the statistics counters should
be cleared (i.e. set to zero) immediately after they have been read or not.
+create mirror
+-----------
+
+Create a new MIRROR port for an ethernet device::
+
+ testpmd> create port mirror (port_id) destination (port_id)
+
+delete mirror
+-----------
+
+Disable MIRROR port for an ethernet device::
+
+ testpmd> disable port mirror (port_id)
+
+
Traffic Management
------------------
--
2.47.2
next prev parent reply other threads:[~2025-04-11 23:51 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-11 23:44 [RFC 00/13] Packet capture using " Stephen Hemminger
2025-04-11 23:44 ` [RFC 01/13] app/testpmd: revert auto attach/detach Stephen Hemminger
2025-04-15 13:28 ` lihuisong (C)
2025-04-16 0:06 ` Stephen Hemminger
2025-04-11 23:44 ` [RFC 02/13] ethdev: allow start/stop from secondary process Stephen Hemminger
2025-04-15 0:19 ` Stephen Hemminger
2025-04-11 23:44 ` [RFC 03/13] test: add test for hotplug and secondary process operations Stephen Hemminger
2025-04-11 23:44 ` [RFC 04/13] net/ring: allow lockfree transmit if ring supports it Stephen Hemminger
2025-04-11 23:44 ` [RFC 05/13] net/ring: add argument to attach existing ring Stephen Hemminger
2025-04-11 23:44 ` [RFC 06/13] net/ring: add timestamp devargs Stephen Hemminger
2025-04-11 23:44 ` [RFC 07/13] net/null: all lockfree transmit Stephen Hemminger
2025-04-11 23:44 ` [RFC 08/13] mbuf: add fields for mirroring Stephen Hemminger
2025-04-12 9:59 ` Morten Brørup
2025-04-12 16:56 ` Stephen Hemminger
2025-04-13 7:00 ` Morten Brørup
2025-04-13 14:31 ` Stephen Hemminger
2025-04-13 14:44 ` Morten Brørup
2025-04-11 23:44 ` [RFC 09/13] ethdev: add port mirror capability Stephen Hemminger
2025-04-11 23:44 ` [RFC 10/13] pcapng: split packet copy from header insertion Stephen Hemminger
2025-04-11 23:44 ` [RFC 11/13] test: add tests for ethdev mirror Stephen Hemminger
2025-04-11 23:44 ` Stephen Hemminger [this message]
2025-04-11 23:44 ` [RFC 13/13] app/dumpcap: use port mirror instead of pdump Stephen Hemminger
2025-04-12 11:06 ` [RFC 00/13] Packet capture using port mirroring Morten Brørup
2025-04-12 17:04 ` Stephen Hemminger
2025-04-13 9:26 ` Morten Brørup
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=20250411234927.114568-13-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=aman.deep.singh@intel.com \
--cc=dev@dpdk.org \
/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).