[dpdk-dev,v2] app/testpmd: add eth peer CLI command

Message ID 1515918430-32108-1-git-send-email-wisamm@mellanox.com (mailing list archive)
State Accepted, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Wisam Jaddo Jan. 14, 2018, 8:27 a.m. UTC
  This command will simulate the process of setting the
eth-peer from command line.

It will be useful to preform extra testing.

usage:
 testpmd> set eth-peer <port_id> <peer_addr>.

Signed-off-by: Wisam Jaddo <wisamm@mellanox.com>
Acked-by: Wenzhuo Lu <wenzhuo.lu@intel.com>

---
changes in v2:
	added Ack from Wenzhuo, and sending to ML again
	due to the issue of not receiving it from the first time.
---
 app/test-pmd/cmdline.c                      | 49 +++++++++++++++++++++++++++++
 app/test-pmd/config.c                       | 19 +++++++++++
 app/test-pmd/testpmd.h                      |  1 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  9 ++++++
 4 files changed, 78 insertions(+)
  

Comments

Thomas Monjalon Jan. 15, 2018, 10:54 a.m. UTC | #1
14/01/2018 09:27, Wisam Jaddo:
> This command will simulate the process of setting the
> eth-peer from command line.
> 
> It will be useful to preform extra testing.
> 
> usage:
>  testpmd> set eth-peer <port_id> <peer_addr>.
> 
> Signed-off-by: Wisam Jaddo <wisamm@mellanox.com>
> Acked-by: Wenzhuo Lu <wenzhuo.lu@intel.com>
> 
> ---
> changes in v2:
> 	added Ack from Wenzhuo, and sending to ML again
> 	due to the issue of not receiving it from the first time.
> ---

Applied, thanks
  

Patch

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index f71d963..605720d 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -277,6 +277,9 @@  static void cmd_help_long_parsed(void *parsed_result,
 			"set nbcore (num)\n"
 			"    Set number of cores.\n\n"
 
+			"set eth-peer (port_id) (peer_addr)\n"
+			"    set the peer address for certain port.\n\n"
+
 			"set coremask (mask)\n"
 			"    Set the forwarding cores hexadecimal mask.\n\n"
 
@@ -2954,6 +2957,51 @@  cmdline_parse_inst_t cmd_set_fwd_mask = {
 	},
 };
 
+/* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
+struct cmd_eth_peer_result {
+	cmdline_fixed_string_t set;
+	cmdline_fixed_string_t eth_peer;
+	portid_t port_id;
+	cmdline_fixed_string_t peer_addr;
+};
+
+static void cmd_set_eth_peer_parsed(void *parsed_result,
+			__attribute__((unused)) struct cmdline *cl,
+			__attribute__((unused)) void *data)
+{
+		struct cmd_eth_peer_result *res = parsed_result;
+
+		if (test_done == 0) {
+			printf("Please stop forwarding first\n");
+			return;
+		}
+		if (!strcmp(res->eth_peer, "eth-peer")) {
+			set_fwd_eth_peer(res->port_id, res->peer_addr);
+			fwd_config_setup();
+		}
+}
+cmdline_parse_token_string_t cmd_eth_peer_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
+cmdline_parse_token_string_t cmd_eth_peer =
+	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
+cmdline_parse_token_num_t cmd_eth_peer_port_id =
+	TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
+cmdline_parse_token_string_t cmd_eth_peer_addr =
+	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
+
+cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
+	.f = cmd_set_eth_peer_parsed,
+	.data = NULL,
+	.help_str = "set eth-peer <port_id> <peer_mac>",
+	.tokens = {
+		(void *)&cmd_eth_peer_set,
+		(void *)&cmd_eth_peer,
+		(void *)&cmd_eth_peer_port_id,
+		(void *)&cmd_eth_peer_addr,
+		NULL,
+	},
+};
+
 /*
  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
  */
@@ -15558,6 +15606,7 @@  cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_set_txsplit,
 	(cmdline_parse_inst_t *)&cmd_set_fwd_list,
 	(cmdline_parse_inst_t *)&cmd_set_fwd_mask,
+	(cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
 	(cmdline_parse_inst_t *)&cmd_set_fwd_mode,
 	(cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
 	(cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index cd2ac11..876ee83 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -78,6 +78,7 @@ 
 #include <rte_pmd_bnxt.h>
 #endif
 #include <rte_gro.h>
+#include <cmdline_parse_etheraddr.h>
 
 #include "testpmd.h"
 
@@ -2234,6 +2235,24 @@  set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
 	return 0;
 }
 
+void
+set_fwd_eth_peer(portid_t port_id, char *peer_addr)
+{
+	uint8_t c, new_peer_addr[6];
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		printf("Error: Invalid port number %i\n", port_id);
+		return;
+	}
+	if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr,
+					sizeof(new_peer_addr)) < 0) {
+		printf("Error: Invalid ethernet address: %s\n", peer_addr);
+		return;
+	}
+	for (c = 0; c < 6; c++)
+		peer_eth_addrs[port_id].addr_bytes[c] =
+			new_peer_addr[c];
+}
+
 int
 set_fwd_lcores_mask(uint64_t lcoremask)
 {
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 1639d27..a2e1a5c 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -632,6 +632,7 @@  int set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc);
 int set_fwd_lcores_mask(uint64_t lcoremask);
 void set_fwd_lcores_number(uint16_t nb_lc);
 
+void set_fwd_eth_peer(portid_t port_id, char *peer_addr);
 void set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt);
 void set_fwd_ports_mask(uint64_t portmask);
 void set_fwd_ports_number(uint16_t nb_pt);
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 9789139..7f09cf9 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -459,6 +459,15 @@  set nbport (num)
 
 This is equivalent to the ``--nb-ports`` command-line option.
 
+set eth-peer
+~~~~~~~~~~~~
+
+Set the forwarding peer address for certain port::
+
+   testpmd> set eth-peer (port_id) (perr_addr)
+
+This is equivalent to the ``--eth-peer`` command-line option.
+
 set nbcore
 ~~~~~~~~~~