From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 5675143676;
	Tue,  5 Dec 2023 10:27:26 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id ECB5042E00;
	Tue,  5 Dec 2023 10:27:21 +0100 (CET)
Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com
 [67.231.156.173])
 by mails.dpdk.org (Postfix) with ESMTP id D3B8E42E00
 for <dev@dpdk.org>; Tue,  5 Dec 2023 10:27:20 +0100 (CET)
Received: from pps.filterd (m0045851.ppops.net [127.0.0.1])
 by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id
 3B59Qcp1032618 for <dev@dpdk.org>; Tue, 5 Dec 2023 01:27:20 -0800
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com;
 h=from : to : cc :
 subject : date : message-id : in-reply-to : references : mime-version :
 content-transfer-encoding : content-type; s=pfpt0220;
 bh=CZHM07lCXioNMJolAh1SarWf9ZXUX4JkEEUkozhBELM=;
 b=iE0bODGUB+tj+JBzwtLQp9ShmB6zlwdGWCK6VV/Xtr5t1cmvniem8kmJFmZxmikmqpgr
 YeIpL7tNT78PGPfX96S73vhOBXSYuvc3n/ArmDOIPaU+8WVih39ADNqGNM3hpyS8koa4
 lC/kY6eVE+UHyksqWUcTMf/eHzOQm+9b48j+OAhchE6w2k8xjUu0fxk+cucjUqyc7LG0
 oNE0d59Z3Jj2hiUOSGCZzl8gnrbv21mWq77VYjBl60jGwzeK0gFWW5gNHw2rHhvgeXk3
 3FBFjQcnFyV5hQOUkIziq2J0ppwzsk2dQpSHb1gkrQsmdGTsE6HQRMfpHfFjDOfmYh2H 6w== 
Received: from dc5-exch01.marvell.com ([199.233.59.181])
 by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3ut0e685b4-1
 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT)
 for <dev@dpdk.org>; Tue, 05 Dec 2023 01:27:20 -0800
Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com
 (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48;
 Tue, 5 Dec 2023 01:27:18 -0800
Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com
 (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend
 Transport; Tue, 5 Dec 2023 01:27:18 -0800
Received: from localhost.localdomain (unknown [10.28.36.154])
 by maili.marvell.com (Postfix) with ESMTP id AE1DE3F70B1;
 Tue,  5 Dec 2023 01:27:14 -0800 (PST)
From: Rakesh Kudurumalla <rkudurumalla@marvell.com>
To: Sunil Kumar Kori <skori@marvell.com>, Rakesh Kudurumalla
 <rkudurumalla@marvell.com>
CC: <dev@dpdk.org>, <jerinj@marvell.com>, <ndabilpuram@marvell.com>
Subject: [PATCH v4 2/3] app/graph: add ethdev forward command
Date: Tue, 5 Dec 2023 14:57:09 +0530
Message-ID: <20231205092710.1375795-2-rkudurumalla@marvell.com>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20231205092710.1375795-1-rkudurumalla@marvell.com>
References: <20231205074645.1370608-1-rkudurumalla@marvell.com>
 <20231205092710.1375795-1-rkudurumalla@marvell.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Proofpoint-GUID: _TySJWvMFzo_guL7hjX9lQVtH15kHduw
X-Proofpoint-ORIG-GUID: _TySJWvMFzo_guL7hjX9lQVtH15kHduw
X-Proofpoint-Virus-Version: vendor=baseguard
 engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26
 definitions=2023-12-05_03,2023-12-04_01,2023-05-22_02
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

Adds a txport to forward packet for every rxport

Mapping will be used to forward packets to txport
received on rxport

Following commands are exposed:
	- ethdev forward <tx_dev_name> <rx_dev_name>"

Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
 app/graph/cli.c         |  1 +
 app/graph/ethdev.c      | 62 +++++++++++++++++++++++++++++++++++++++++
 app/graph/ethdev.h      |  1 +
 app/graph/ethdev_priv.h |  8 ++++++
 4 files changed, 72 insertions(+)

diff --git a/app/graph/cli.c b/app/graph/cli.c
index 30b12312d6..76f5b8e670 100644
--- a/app/graph/cli.c
+++ b/app/graph/cli.c
@@ -32,6 +32,7 @@ cmdline_parse_ctx_t modules_ctx[] = {
 	(cmdline_parse_inst_t *)&ethdev_prom_mode_cmd_ctx,
 	(cmdline_parse_inst_t *)&ethdev_ip4_cmd_ctx,
 	(cmdline_parse_inst_t *)&ethdev_ip6_cmd_ctx,
+	(cmdline_parse_inst_t *)&ethdev_forward_cmd_ctx,
 	(cmdline_parse_inst_t *)&ethdev_cmd_ctx,
 	(cmdline_parse_inst_t *)&ethdev_help_cmd_ctx,
 	(cmdline_parse_inst_t *)&ethdev_rx_cmd_ctx,
diff --git a/app/graph/ethdev.c b/app/graph/ethdev.c
index c9b09168c1..bceee659a2 100644
--- a/app/graph/ethdev.c
+++ b/app/graph/ethdev.c
@@ -38,6 +38,10 @@ cmd_ethdev_ip4_addr_help[] = "ethdev <ethdev_name> ip4 addr add <ip> netmask <ma
 static const char
 cmd_ethdev_ip6_addr_help[] = "ethdev <ethdev_name> ip6 addr add <ip> netmask <mask>";
 
+static const char
+cmd_ethdev_forward_help[] = "ethdev forward <tx_dev_name> <rx_dev_name>";
+
+
 static struct rte_eth_conf port_conf_default = {
 	.link_speeds = 0,
 	.rxmode = {
@@ -888,3 +892,61 @@ cmdline_parse_inst_t ethdev_help_cmd_ctx = {
 		NULL,
 	},
 };
+
+static int
+ethdev_forward_config(char *tx_name, char *rx_name)
+{
+	struct ethdev *port;
+	uint16_t portid_rx = 0;
+	uint16_t portid_tx = 0;
+	int rc = -EINVAL;
+
+	rc = rte_eth_dev_get_port_by_name(tx_name, &portid_tx);
+	if (rc < 0)
+		return rc;
+
+	rc = rte_eth_dev_get_port_by_name(rx_name, &portid_rx);
+	if (rc < 0)
+		return rc;
+
+	port = ethdev_port_by_id(portid_rx);
+	if (port) {
+		port->config.tx_port_id = portid_tx;
+		rc = 0;
+	}
+
+	return rc;
+}
+
+static void
+cli_ethdev_forward(void *parsed_result, __rte_unused struct cmdline *cl, void *data __rte_unused)
+{
+	struct ethdev_fwd_cmd_tokens *res = parsed_result;
+	int rc = -EINVAL;
+
+	rc = ethdev_forward_config(res->tx_dev, res->rx_dev);
+	if (rc < 0)
+		printf(MSG_CMD_FAIL, res->cmd);
+}
+
+cmdline_parse_token_string_t ethdev_l2_cmd =
+	TOKEN_STRING_INITIALIZER(struct ethdev_fwd_cmd_tokens, cmd, "ethdev");
+cmdline_parse_token_string_t ethdev_fwd_cmd =
+	TOKEN_STRING_INITIALIZER(struct ethdev_fwd_cmd_tokens, fwd, "forward");
+cmdline_parse_token_string_t ethdev_tx_device =
+	TOKEN_STRING_INITIALIZER(struct ethdev_fwd_cmd_tokens, tx_dev, NULL);
+cmdline_parse_token_string_t ethdev_rx_device =
+	TOKEN_STRING_INITIALIZER(struct ethdev_fwd_cmd_tokens, rx_dev, NULL);
+
+cmdline_parse_inst_t ethdev_forward_cmd_ctx = {
+	.f = cli_ethdev_forward,
+	.data = NULL,
+	.help_str = cmd_ethdev_forward_help,
+	.tokens = {
+	       (void *)&ethdev_l2_cmd,
+	       (void *)&ethdev_fwd_cmd,
+	       (void *)&ethdev_tx_device,
+	       (void *)&ethdev_rx_device,
+	       NULL,
+	},
+};
diff --git a/app/graph/ethdev.h b/app/graph/ethdev.h
index 94d3247a2c..836052046b 100644
--- a/app/graph/ethdev.h
+++ b/app/graph/ethdev.h
@@ -15,6 +15,7 @@ extern cmdline_parse_inst_t ethdev_mtu_cmd_ctx;
 extern cmdline_parse_inst_t ethdev_prom_mode_cmd_ctx;
 extern cmdline_parse_inst_t ethdev_ip4_cmd_ctx;
 extern cmdline_parse_inst_t ethdev_ip6_cmd_ctx;
+extern cmdline_parse_inst_t ethdev_forward_cmd_ctx;
 extern cmdline_parse_inst_t ethdev_cmd_ctx;
 extern cmdline_parse_inst_t ethdev_help_cmd_ctx;
 
diff --git a/app/graph/ethdev_priv.h b/app/graph/ethdev_priv.h
index f231f3f3e1..e5e5fbc9ae 100644
--- a/app/graph/ethdev_priv.h
+++ b/app/graph/ethdev_priv.h
@@ -61,6 +61,13 @@ struct ethdev_ip6_cmd_tokens {
 	cmdline_fixed_string_t mask;
 };
 
+struct ethdev_fwd_cmd_tokens {
+	cmdline_fixed_string_t cmd;
+	cmdline_fixed_string_t fwd;
+	cmdline_fixed_string_t tx_dev;
+	cmdline_fixed_string_t rx_dev;
+};
+
 struct ethdev_cmd_tokens {
 	cmdline_fixed_string_t cmd;
 	cmdline_fixed_string_t dev;
@@ -98,6 +105,7 @@ struct ethdev_config {
 		uint32_t queue_size;
 	} tx;
 
+	uint16_t tx_port_id;
 	int promiscuous;
 	uint32_t mtu;
 };
-- 
2.25.1