[dpdk-dev] [PATCH] app/testpmd: add custom topology command

Wisam Jaddo wisamm at mellanox.com
Tue May 8 14:17:33 CEST 2018


Set custom topology for forwading packets by making the
given two ports as pair, in custom topology the active
ports will be the defiend in custum-topo only.

This command will be useful in testing, when special
topology is needed.

Signed-off-by: Wisam Jaddo <wisamm at mellanox.com>
---
 app/test-pmd/cmdline.c                      | 49 +++++++++++++++++++++++++++++
 app/test-pmd/config.c                       | 38 ++++++++++++++++++++++
 app/test-pmd/testpmd.c                      |  1 +
 app/test-pmd/testpmd.h                      |  7 ++++-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  8 +++++
 5 files changed, 102 insertions(+), 1 deletion(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 9615670..9d48048 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -466,6 +466,9 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"set eth-peer (port_id) (peer_addr)\n"
 			"    set the peer address for certain port.\n\n"
 
+			"set custom-topo (port_id_1) (port_id_2)\n"
+			"    set custom topo.\n\n"
+
 			"set port (port_id) uta (mac_address|all) (on|off)\n"
 			"    Add/Remove a or all unicast hash filter(s)"
 			"from port X.\n\n"
@@ -7649,6 +7652,51 @@ cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
 	},
 };
 
+/* *** SET CUSTOM TOPO FOR CERTAIN PORT *** */
+struct cmd_custom_topo_result {
+		cmdline_fixed_string_t set;
+		cmdline_fixed_string_t custom_topo;
+		portid_t port_id_1;
+		portid_t port_id_2;
+};
+
+static void cmd_set_custom_topo_parsed(void *parsed_result,
+				__attribute__((unused)) struct cmdline *cl,
+				__attribute__((unused)) void *data)
+{
+	struct cmd_custom_topo_result *res = parsed_result;
+
+	if (test_done == 0) {
+		printf("Please stop forwarding first\n");
+		return;
+	}
+	if (!strcmp(res->custom_topo, "custom-topo")) {
+		set_custom_topo(res->port_id_1, res->port_id_2);
+		fwd_config_setup();
+	}
+}
+cmdline_parse_token_string_t cmd_set_custom_topo_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_custom_topo_result, set, "set");
+cmdline_parse_token_string_t cmd_set_custom_topo_custom_topo =
+	TOKEN_STRING_INITIALIZER(struct cmd_custom_topo_result, custom_topo, "custom-topo");
+cmdline_parse_token_num_t cmd_set_custom_topo_port_id_1 =
+	TOKEN_NUM_INITIALIZER(struct cmd_custom_topo_result, port_id_1, UINT16);
+cmdline_parse_token_num_t cmd_set_custom_topo_port_id_2 =
+	TOKEN_NUM_INITIALIZER(struct cmd_custom_topo_result, port_id_2, UINT16);
+
+cmdline_parse_inst_t cmd_set_custom_topo = {
+	.f = cmd_set_custom_topo_parsed,
+	.data = NULL,
+	.help_str = "set custom-topo (port_id_1) (port_id_2)",
+	.tokens = {
+			(void *)&cmd_set_custom_topo_set,
+			(void *)&cmd_set_custom_topo_custom_topo,
+			(void *)&cmd_set_custom_topo_port_id_1,
+			(void *)&cmd_set_custom_topo_port_id_2,
+			NULL,
+	},
+};
+
 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
 struct cmd_set_qmap_result {
 	cmdline_fixed_string_t set;
@@ -16540,6 +16588,7 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_stop,
 	(cmdline_parse_inst_t *)&cmd_mac_addr,
 	(cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
+	(cmdline_parse_inst_t *)&cmd_set_custom_topo,
 	(cmdline_parse_inst_t *)&cmd_set_qmap,
 	(cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
 	(cmdline_parse_inst_t *)&cmd_operate_port,
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 16fc481..c90e879 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -2045,6 +2045,9 @@ setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
 static portid_t
 fwd_topology_tx_port_get(portid_t rxp)
 {
+	if (fwd_ports[rxp] == rxp)
+		return fwd_streams[rxp]->tx_port;
+
 	static int warning_once = 1;
 
 	RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
@@ -2378,6 +2381,41 @@ set_fwd_eth_peer(portid_t port_id, char *peer_addr)
 			new_peer_addr[c];
 }
 
+static void
+print_ports_range(void)
+{
+	portid_t pid;
+	printf("Valid port range is [");
+	RTE_ETH_FOREACH_DEV(pid)
+		printf(", %d", pid);
+	printf("]\n");
+}
+
+void
+set_custom_topo(portid_t port_id_1, portid_t port_id_2)
+{
+	unsigned int portlist[RTE_MAX_ETHPORTS];
+	unsigned int i;
+	unsigned int nb_pt = 0;
+	if (port_id_is_invalid(port_id_1, ENABLED_WARN)) {
+		print_ports_range();
+		return;
+	}
+	if (port_id_is_invalid(port_id_2, ENABLED_WARN)) {
+		print_ports_range();
+		return;
+	}
+	fwd_streams[port_id_1]->tx_port = port_id_2;
+	fwd_streams[port_id_2]->tx_port = port_id_1;
+	fwd_ports[port_id_1] = port_id_1;
+	fwd_ports[port_id_2] = port_id_2;
+
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+		if (fwd_ports[i] == i)
+			portlist[nb_pt++] = i;
+	set_fwd_ports_list(portlist, nb_pt);
+}
+
 int
 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
 {
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index db23f23..7e51817 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2590,6 +2590,7 @@ main(int argc, char** argv)
 	int diag;
 	portid_t port_id;
 	int ret;
+	fwd_ports[0] = 1;
 
 	signal(SIGINT, signal_handler);
 	signal(SIGTERM, signal_handler);
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 1af87b8..510023b 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -363,6 +363,11 @@ extern uint8_t txring_numa[RTE_MAX_ETHPORTS];
 extern uint8_t socket_num;
 
 /*
+ * Store the custom topo.
+ */
+portid_t fwd_ports[RTE_MAX_ETHPORTS];
+
+/*
  * Configuration of logical cores:
  * nb_fwd_lcores <= nb_cfg_lcores <= nb_lcores
  */
@@ -598,7 +603,7 @@ void reconfig(portid_t new_port_id, unsigned socket_id);
 int init_fwd_streams(void);
 
 void set_fwd_eth_peer(portid_t port_id, char *peer_addr);
-
+void set_custom_topo(portid_t port_id_1, portid_t port_id_2);
 void port_mtu_set(portid_t port_id, uint16_t mtu);
 void port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_pos);
 void port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 013a405..5edf210 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -1090,6 +1090,14 @@ Set the forwarding peer address for certain port::
 
 This is equivalent to the ``--eth-peer`` command-line option.
 
+set custom-topo
+~~~~~~~~~~~~~~
+
+Set custom topology for forwading packets by making the given two ports as pair.
+In custom topology the active ports will be the defiend in custum-topo only::
+
+   testpmd> set custom-topo (port_id_1) (port_id_2)
+
 set port-uta
 ~~~~~~~~~~~~
 
-- 
2.7.4



More information about the dev mailing list