[dpdk-dev] [RFC][PATCH V2 2/3] examples/vhost: Add vswitch command line options

Pankaj Chauhan pankaj.chauhan at nxp.com
Mon Sep 5 12:54:30 CEST 2016


Add command line options for selecting switch implementation
and maximum ports for the vswitch.following are two new command
line options:

--switch <switch_name> [char string, Selects the switch imlementation]
--max-ports<port_count> [int, selects maximum number of ports to support]

For example:

$ ./vhost-switch -c 3 -n 2 --socket-mem 1024 --huge-dir /hugetlbfs -- -p
0x1 --dev-basename sock1 --switch "vmdq" --max-ports 3

Signed-off-by: Pankaj Chauhan <pankaj.chauhan at nxp.com>
---
 examples/vhost/main.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index c949df4..a4e51ae 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -142,6 +142,10 @@ static uint32_t burst_rx_retry_num = BURST_RX_RETRIES;
 /* Character device basename. Can be set by user. */
 static char dev_basename[MAX_BASENAME_SZ] = "vhost-net";
 
+/* vswitch device name and maximum number of ports */
+static char switch_dev[MAX_BASENAME_SZ] = "vmdq";
+static uint32_t switch_max_ports = MAX_DEVICES;
+
 /* empty vmdq configuration structure. Filled in programatically */
 static struct rte_eth_conf vmdq_conf_default = {
 	.rxmode = {
@@ -408,6 +412,22 @@ us_vhost_parse_basename(const char *q_arg)
 }
 
 /*
+ * Set switch device name.
+ */
+static int
+us_vhost_parse_switch_name(const char *q_arg)
+{
+	/* parse number string */
+
+	if (strnlen(q_arg, MAX_BASENAME_SZ) > MAX_BASENAME_SZ)
+		return -1;
+
+	snprintf(&switch_dev[0], MAX_BASENAME_SZ, "%s", q_arg);
+
+	return 0;
+}
+
+/*
  * Parse the portmask provided at run time.
  */
 static int
@@ -501,6 +521,8 @@ us_vhost_parse_args(int argc, char **argv)
 		{"tx-csum", required_argument, NULL, 0},
 		{"tso", required_argument, NULL, 0},
 		{"client", no_argument, &client_mode, 1},
+		{"switch", required_argument, NULL, 0},
+		{"max-ports", required_argument, NULL, 0},
 		{NULL, 0, 0, 0},
 	};
 
@@ -655,6 +677,27 @@ us_vhost_parse_args(int argc, char **argv)
 				}
 			}
 
+			/* Set vswitch_driver name */
+			if (!strncmp(long_option[option_index].name, "switch", MAX_LONG_OPT_SZ)) {
+				if (us_vhost_parse_switch_name(optarg) == -1) {
+					RTE_LOG(INFO, VHOST_CONFIG,
+						"Invalid argument for switch (Max len %d )\n", MAX_BASENAME_SZ);
+					us_vhost_usage(prgname);
+					return -EINVAL;
+				}
+			}
+
+			/* Specify Max ports in vswitch. */
+			if (!strncmp(long_option[option_index].name, "max-ports", MAX_LONG_OPT_SZ)) {
+				ret = parse_num_opt(optarg, INT32_MAX);
+				if (ret == -1) {
+					RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for switch max ports [0-N]\n");
+					us_vhost_usage(prgname);
+					return -1;
+				}
+				switch_max_ports = ret;
+			}
+
 			break;
 
 			/* Invalid option - print options. */
-- 
1.9.1



More information about the dev mailing list