On 9/2/2016 8:14 PM, Maxime Coquelin wrote: > > > On 08/27/2016 06:26 PM, Pankaj Chauhan wrote: >> 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 92a9823..59cddb8 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; >> + else >> + snprintf((char*)&switch_dev, MAX_BASENAME_SZ, "%s", q_arg); > why casting?
yes not required, will remove it. >> + >> + 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 >> character switch dev (Max %d characters)\n", MAX_BASENAME_SZ); > ERR may be morez appropriate. I didn't get the comment, can you please help me understand. > And the message may be a little too long. I will shorten it, thanks. > >> + us_vhost_usage(prgname); >> + return -1; >> + } >> + } >> + >> + /* 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; >> + } else { >> + switch_max_ports = ret; >> + } > The else is not needed as the 'if' returns. Agreed, will fix it. >> + } >> + >> break; >> >> /* Invalid option - print options. */ >> >