From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2C79D46BE5; Tue, 22 Jul 2025 19:37:13 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A57E240A67; Tue, 22 Jul 2025 19:36:14 +0200 (CEST) Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by mails.dpdk.org (Postfix) with ESMTP id D1A3840A7D for ; Tue, 22 Jul 2025 19:36:11 +0200 (CEST) Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7e344e0212eso12178385a.0 for ; Tue, 22 Jul 2025 10:36:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1753205771; x=1753810571; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0zIbdjbIsBTJGrUPuCW20jRSg85NEdhyJwxltX+PYxI=; b=3UyZarUwnoqIsSlUBG16wpAhAgvAKDyI04WflVhV9nmuF6vNCtb3B9nE4iUmwf+7Op NIyZeJdODIWHwvHK+VeEfvFqRp4BJ6fouzDgNU1Nkz/TcjLNzdXpKaZSas00wYcnGxQ1 oHpfrb4LxbE7Re5cF9p3FNViFUbqc0HfKzBh5Xl52Ctub0BouWE9ciujewdFfJg9McJV q9Lk8bedc9qtfzQRRB+ouunyzuxVqVgVwbRH5FHrcsU/s1H/sck0dTKJ1/4eFe1HTrEt AlFtZDMI2wEpvPWbF6E5nSFSxJ6M/8pfL9SFpCCj9Su5XZrrIS98DfIQ+kO0ZztJu+cL +57Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753205771; x=1753810571; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0zIbdjbIsBTJGrUPuCW20jRSg85NEdhyJwxltX+PYxI=; b=lpah1IxRzvK/aioFwbMsw7JEa8Kd70KsSU1YEZaIwYV6r7zdj0DdXOBbMKmy0M0XGJ piVK88gUSc1QG/zjAFw35BXN3r2OAuTMzZhvpIH528QCbeYCr3o0Xk/TczPIlL0EPEdQ qdkCWNAyvWROErZCHAPaGi/UZApC4tCLlrfqU+Ru4EX4bbZBEQFPFXCU9qJQtVOw5VpL lEtrQwsljyFdOQGrdpWJHHgCMKNcZ0uLIEr5v1qM4MMVtwkJvTYQpa8vPxRFH+PNE8E9 +eAHoxzi3fzOaCp/FPN2xlihyKXhN3xTDeLOD+4TpSKfdSpC4nV3RfUHIOcmQSnFT55a BWxA== X-Gm-Message-State: AOJu0YyWe3JivwrZLISz3PdSP2/0E+/a/W8mtHFE7kysKOsxWe3ghFyB 7VPNn4F95hoabyU8lzUvP2L4ApTj0dKL+SkdygyTrBwFSjNdjoDnZwSPlQ080keQvc1MO1IFnEP BBXgX X-Gm-Gg: ASbGncuV0q4DbO11YDjxgR+erTuvoXTBdgb54Tm5XOygJvLtF/PhCj1cuQrsz6t5sE5 963KAwObWc1Oa8eYmH4BdulYaXprI+ep5uzmCox89WdfCy50x5I3FuALW3VCza5Nv5AvC0kJzrc /Xg8vWGIyD1yY0eKoERVenQpIG7TmpdcO/nTI4D+b3OBXGmHDYmGzm0NkUkCxJJI8843BXlgW8z Nm8yZxZpuGyKECZhFPBx5AJq6mjwf8WeqYbDHBxcDFBMWbM2XZ6LXs/fC1daIF0311kWwRr7yHS 54MIxL0733LKEcsklrSG/YRGDxoVrbws9QPSgdzY2tPCcOc9I1nH3Ysyscj3ltYjnrF9KpdkA0b 10Q9Wr31Zsle15i0viEFZuIjJcQ4f3ZVU4SK5U7XizEUYGn6ygzDAH1P1BjOmiLCYmZMlPgCb X-Google-Smtp-Source: AGHT+IEjbCBQCp/HTKshFiK/Z3Jqq49llv1ErUIYDlUPuXFMOtAQQuDrzSzgoODkD3o1uSWIHzOMWQ== X-Received: by 2002:a05:620a:6404:b0:7d9:bde3:79a1 with SMTP id af79cd13be357-7e6211edc06mr543270985a.4.1753205770947; Tue, 22 Jul 2025 10:36:10 -0700 (PDT) Received: from hermes.lan (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7e356b282aasm552155885a.14.2025.07.22.10.36.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Jul 2025 10:36:10 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Aman Singh Subject: [PATCH v6 11/13] app/testpmd: support for port mirroring Date: Tue, 22 Jul 2025 10:34:42 -0700 Message-ID: <20250722173552.184141-12-stephen@networkplumber.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250722173552.184141-1-stephen@networkplumber.org> References: <20250411234927.114568-1-stephen@networkplumber.org> <20250722173552.184141-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add new commands to enable testing of port mirror functionality. Signed-off-by: Stephen Hemminger --- app/test-pmd/cmdline.c | 1 + app/test-pmd/cmdline_mirror.c | 129 ++++++++++++++++++++ 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, 158 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 7b4e27eddf..bc4b8b3b72 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..2c645ffafe --- /dev/null +++ b/app/test-pmd/cmdline_mirror.c @@ -0,0 +1,129 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2025 Stephen Hemminger + */ + +#include + +#include +#include +#include + +#include + +#include "testpmd.h" +#include "cmdline_mirror.h" + +/* *** Create MIRROR port 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; + /* TODO these should be set by command */ + struct rte_eth_mirror_conf mirror_conf = { + .direction = RTE_ETH_MIRROR_DIRECTION_INGRESS | RTE_ETH_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; + + mirror_conf.target = res->target_id; + + ret = rte_eth_add_mirror(res->port_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 destination ", + .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 + }, +}; + +/* *** Delete Port Mirror Object *** */ +struct cmd_delete_port_mirror_result { + cmdline_fixed_string_t delete; + cmdline_fixed_string_t port; + cmdline_fixed_string_t mirror; + uint16_t port_id; + cmdline_fixed_string_t destination; + uint16_t target_id; +}; + +static void cmd_delete_port_mirror_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + const struct cmd_delete_port_mirror_result *res = parsed_result; + int ret; + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + + ret = rte_eth_remove_mirror(res->port_id, res->target_id); + if (ret != 0) + fprintf(stderr, "%s\n", rte_strerror(-ret)); +} + +static cmdline_parse_token_string_t cmd_delete_port_mirror_delete = + TOKEN_STRING_INITIALIZER(struct cmd_delete_port_mirror_result, delete, "delete"); +static cmdline_parse_token_string_t cmd_delete_port_mirror_port = + TOKEN_STRING_INITIALIZER(struct cmd_delete_port_mirror_result, port, "port"); +static cmdline_parse_token_string_t cmd_delete_port_mirror_mirror = + TOKEN_STRING_INITIALIZER(struct cmd_delete_port_mirror_result, mirror, "mirror"); +static cmdline_parse_token_num_t cmd_delete_port_mirror_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_delete_port_mirror_result, port_id, RTE_UINT16); +static cmdline_parse_token_string_t cmd_delete_port_mirror_destination = + TOKEN_STRING_INITIALIZER(struct cmd_create_port_mirror_result, destination, "destination"); +static cmdline_parse_token_num_t cmd_delete_port_mirror_target_id = + TOKEN_NUM_INITIALIZER(struct cmd_delete_port_mirror_result, target_id, RTE_UINT16); + +cmdline_parse_inst_t cmd_delete_port_mirror = { + .f = cmd_delete_port_mirror_parsed, + .data = NULL, + .help_str = "delete port mirror destination ", + .tokens = { + (void *)&cmd_delete_port_mirror_delete, + (void *)&cmd_delete_port_mirror_port, + (void *)&cmd_delete_port_mirror_mirror, + (void *)&cmd_delete_port_mirror_port_id, + (void *)&cmd_delete_port_mirror_destination, + (void *)&cmd_delete_port_mirror_target_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 + */ + +#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..e67665028f 100644 --- a/app/test-pmd/meson.build +++ b/app/test-pmd/meson.build @@ -8,6 +8,7 @@ sources = files( 'cmdline.c', 'cmdline_cman.c', 'cmdline_flow.c', + 'cmdline_mirror.c', 'cmdline_mtr.c', 'cmdline_tm.c', 'cmd_flex_item.c', diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 6ad83ae50d..603468a70d 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -2570,6 +2570,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 +------------- + +Delete an existing MIRROR port on ethernet device:: + + testpmd> delete port mirror (port_id) + + Traffic Management ------------------ -- 2.47.2