[v9,2/3] app/graph: add ethdev forward command

Message ID 20240102072818.886476-2-rkudurumalla@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v9,1/3] node: support to add next node to ethdev Rx node |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Rakesh Kudurumalla Jan. 2, 2024, 7:28 a.m. UTC
  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>
Acked-by: Sunil Kumar Kori <skori@marvell.com>
---
 app/graph/cli.c            |  1 +
 app/graph/ethdev.c         | 63 ++++++++++++++++++++++++++++++++++++++
 app/graph/ethdev.h         |  1 +
 app/graph/ethdev_priv.h    |  8 +++++
 doc/guides/tools/graph.rst |  4 +++
 5 files changed, 77 insertions(+)
  

Patch

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..bb502a6134 100644
--- a/app/graph/ethdev.c
+++ b/app/graph/ethdev.c
@@ -38,6 +38,9 @@  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 +891,63 @@  cmdline_parse_inst_t ethdev_help_cmd_ctx = {
 		NULL,
 	},
 };
+
+static int
+ethdev_forward_config(char *tx_dev, char *rx_dev)
+{
+	uint16_t portid_rx = 0;
+	uint16_t portid_tx = 0;
+	struct ethdev *port;
+	int rc = -EINVAL;
+
+	rc = rte_eth_dev_get_port_by_name(tx_dev, &portid_tx);
+	if (rc < 0)
+		return rc;
+
+	rc = rte_eth_dev_get_port_by_name(rx_dev, &portid_rx);
+	if (rc < 0)
+		return rc;
+
+	port = ethdev_port_by_id(portid_rx);
+	if (port) {
+		port->tx_port_id = portid_tx;
+		rc = 0;
+	} else {
+		rc = -EINVAL;
+	}
+
+	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_fwd_cfg =
+	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_fwd_cfg,
+	       (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..af79553438 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;
@@ -104,6 +111,7 @@  struct ethdev_config {
 
 struct ethdev {
 	TAILQ_ENTRY(ethdev) next;
+	uint16_t tx_port_id;
 	struct ethdev_config config;
 	struct ipv4_addr_config ip4_addr;
 	struct ipv6_addr_config ip6_addr;
diff --git a/doc/guides/tools/graph.rst b/doc/guides/tools/graph.rst
index 1855d12891..0aab41cbca 100644
--- a/doc/guides/tools/graph.rst
+++ b/doc/guides/tools/graph.rst
@@ -195,6 +195,9 @@  file to express the requested use case configuration.
    | ethdev <ethdev_name> mtu <mtu_sz>    | | Command to configure MTU of DPDK|   Yes   |    Yes   |
    |                                      | | port.                           |         |          |
    +--------------------------------------+-----------------------------------+---------+----------+
+   | | ethdev forward <tx_dev_name>       | | Command to configure port       |   No    |    Yes   |
+   | | <rx_dev_name>                      | | forwarding of DPDK              |         |          |
+   +--------------------------------------+-----------------------------------+---------+----------+
    |  | ethdev <ethdev_name> promiscuous  | | Command to enable/disable       |   Yes   |    Yes   |
    |  | <on/off>                          | | promiscuous mode on DPDK port.  |         |          |
    +--------------------------------------+-----------------------------------+---------+----------+
@@ -297,6 +300,7 @@  Example: ``dpdk-graph`` is started with ``-h 10.28.35.207`` and ``-p 50000`` the
    ethdev <ethdev_name> rxq <n_queues> txq <n_queues> <mempool_name>
    ethdev <ethdev_name> ip4 addr add <ip> netmask <mask>
    ethdev <ethdev_name> ip6 addr add <ip> netmask <mask>
+   ethdev forward <tx_dev_name> <rx_dev_name>
    ethdev <ethdev_name> promiscuous <on/off>
    ethdev <ethdev_name> mtu <mtu_sz>
    ethdev <ethdev_name> stats