From: Thomas Monjalon <thomas.monjalon@6wind.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2] app/testpmd: list forwarding modes
Date: Thu, 15 May 2014 11:35:13 +0200 [thread overview]
Message-ID: <1400146513-14283-1-git-send-email-thomas.monjalon@6wind.com> (raw)
In-Reply-To: <1400087113-5270-1-git-send-email-thomas.monjalon@6wind.com>
Having a function to list forwarding modes helps to show them
in cli help and in parameters usage witout duplicating code.
Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
---
app/test-pmd/cmdline.c | 55 ++++++++++++++++++++++++++++-------------------
app/test-pmd/config.c | 19 ++++++++++++++++
app/test-pmd/parameters.c | 3 ++-
app/test-pmd/testpmd.h | 1 +
4 files changed, 55 insertions(+), 23 deletions(-)
changes in v2:
- factorize also contextual help
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 7f59333..12a09d0 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -294,17 +294,9 @@ static void cmd_help_long_parsed(void *parsed_result,
" bit 3 - insert sctp checksum offload if set\n"
" Please check the NIC datasheet for HW limits.\n\n"
-#ifdef RTE_LIBRTE_IEEE1588
- "set fwd (io|mac|mac_retry|rxonly|txonly|csum|ieee1588)\n"
- " Set IO, MAC, MAC_RETRY, RXONLY, CSUM or TXONLY or ieee1588"
- " packet forwarding mode.\n\n"
+ "set fwd (%s)\n"
+ " Set packet forwarding mode.\n\n"
-#else
- "set fwd (io|mac|mac_retry|rxonly|txonly|csum)\n"
- " Set IO, MAC, MAC_RETRY, RXONLY, CSUM or TXONLY packet"
- " forwarding mode.\n\n"
-
-#endif
"mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
" Add a MAC address on port_id.\n\n"
@@ -398,6 +390,7 @@ static void cmd_help_long_parsed(void *parsed_result,
" using the lowest port on the NIC.\n\n"
#endif
+ , list_pkt_forwarding_modes()
);
}
@@ -2688,22 +2681,12 @@ cmdline_parse_token_string_t cmd_setfwd_fwd =
TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
cmdline_parse_token_string_t cmd_setfwd_mode =
TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
-#ifdef RTE_LIBRTE_IEEE1588
- "io#mac#mac_retry#rxonly#txonly#csum#ieee1588");
-#else
- "io#mac#mac_retry#rxonly#txonly#csum");
-#endif
+ "" /* defined at init */);
cmdline_parse_inst_t cmd_set_fwd_mode = {
.f = cmd_set_fwd_mode_parsed,
.data = NULL,
-#ifdef RTE_LIBRTE_IEEE1588
- .help_str = "set fwd io|mac|mac_retry|rxonly|txonly|csum|ieee1588 - set IO, MAC,"
- " MAC_RETRY, RXONLY, TXONLY, CSUM or IEEE1588 packet forwarding mode",
-#else
- .help_str = "set fwd io|mac|mac_retry|rxonly|txonly|csum - set IO, MAC,"
- " MAC_RETRY, RXONLY, CSUM or TXONLY packet forwarding mode",
-#endif
+ .help_str = NULL, /* defined at init */
.tokens = {
(void *)&cmd_setfwd_set,
(void *)&cmd_setfwd_fwd,
@@ -2712,6 +2695,26 @@ cmdline_parse_inst_t cmd_set_fwd_mode = {
},
};
+static void cmd_set_fwd_mode_init(cmdline_parse_inst_t *cmd)
+{
+ char *modes, *c;
+ static char token[128];
+ static char help[256];
+
+ modes = list_pkt_forwarding_modes();
+ rte_snprintf(help, sizeof help, "set fwd %s - "
+ "set packet forwarding mode", modes);
+ cmd->help_str = help;
+
+ /* string token separator is # */
+ for (c = token; *modes != '\0'; modes++)
+ if (*modes == '|')
+ *c++ = '#';
+ else
+ *c++ = *modes;
+ ((cmdline_parse_token_string_t *)cmd->tokens[2])->string_data.str = token;
+}
+
/* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
struct cmd_set_burst_tx_retry_result {
cmdline_fixed_string_t set;
@@ -5197,6 +5200,14 @@ void
prompt(void)
{
struct cmdline *cl;
+ unsigned i = 0;
+ cmdline_parse_inst_t *cmd;
+
+ /* initialize non-constant commands */
+ while ((cmd = main_ctx[i++]) != NULL) {
+ if (cmd->f == cmd_set_fwd_mode_parsed)
+ cmd_set_fwd_mode_init(cmd);
+ }
cl = cmdline_stdin_new(main_ctx, "testpmd> ");
if (cl == NULL) {
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index d0e21b7..2e4b7a5 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -1231,6 +1231,25 @@ set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
tx_pkt_nb_segs = (uint8_t) nb_segs;
}
+char*
+list_pkt_forwarding_modes(void)
+{
+ static char modes[128] = "";
+ const char *separator = "|";
+ struct fwd_engine *fwd_eng;
+ unsigned i = 0;
+
+ if (strlen (modes) == 0) {
+ while ((fwd_eng = fwd_engines[i++]) != NULL) {
+ strcat(modes, fwd_eng->fwd_mode_name);
+ strcat(modes, separator);
+ }
+ modes[strlen(modes) - strlen(separator)] = '\0';
+ }
+
+ return modes;
+}
+
void
set_pkt_forwarding_mode(const char *fwd_mode_name)
{
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 67081d7..8a3ce2c 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -158,7 +158,8 @@ usage(char* progname)
printf(" --disable-rss: disable rss.\n");
printf(" --port-topology=N: set port topology (N: paired (default) or "
"chained).\n");
- printf(" --forward-mode=N: set forwarding mode.\n");
+ printf(" --forward-mode=N: set forwarding mode (N: %s).\n",
+ list_pkt_forwarding_modes());
printf(" --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
printf(" --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
printf(" --rxq=N: set the number of RX queues per port to N.\n");
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 52d3543..0e4a35e 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -491,6 +491,7 @@ void tx_cksum_set(portid_t port_id, uint8_t cksum_mask);
void set_verbose_level(uint16_t vb_level);
void set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs);
void set_nb_pkt_per_burst(uint16_t pkt_burst);
+char *list_pkt_forwarding_modes(void);
void set_pkt_forwarding_mode(const char *fwd_mode);
void start_packet_forwarding(int with_tx_first);
void stop_packet_forwarding(void);
--
1.9.2
next prev parent reply other threads:[~2014-05-15 9:35 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-03 17:30 [dpdk-dev] [PATCH 0/6] Extensions to test-pmd Cyril Chemparathy
2014-04-03 17:30 ` [dpdk-dev] [PATCH 1/6] test-pmd: add support for single port loopback topology Cyril Chemparathy
2014-04-03 17:30 ` [dpdk-dev] [PATCH 2/6] test-pmd: add support for auto-start when interactive Cyril Chemparathy
2014-04-03 17:30 ` [dpdk-dev] [PATCH 3/6] test-pmd: allow command line selection of forwarding mode Cyril Chemparathy
2014-04-04 8:21 ` Richardson, Bruce
2014-05-14 17:05 ` [dpdk-dev] [PATCH] app/testpmd: list forwarding modes Thomas Monjalon
2014-05-15 9:35 ` Thomas Monjalon [this message]
2014-05-15 16:08 ` [dpdk-dev] [PATCH v3] app/testpmd: list forwarding engines Thomas Monjalon
2014-05-16 7:21 ` Ivan Boule
2014-05-16 14:24 ` Thomas Monjalon
2014-04-03 17:30 ` [dpdk-dev] [PATCH 4/6] test-pmd: allow txpkts to be setup via command line Cyril Chemparathy
2014-04-03 17:30 ` [dpdk-dev] [PATCH 5/6] test-pmd: add mac swap forwarding mode Cyril Chemparathy
2014-04-03 17:30 ` [dpdk-dev] [PATCH 6/6] test-pmd: add flowgen forwarding engine Cyril Chemparathy
2014-05-16 14:22 ` [dpdk-dev] [PATCH 0/6] Extensions to test-pmd Thomas Monjalon
2014-05-16 16:55 ` Cyril Chemparathy
2014-05-19 9:31 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1400146513-14283-1-git-send-email-thomas.monjalon@6wind.com \
--to=thomas.monjalon@6wind.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).