4 * Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 #include <sys/types.h>
45 #include <sys/queue.h>
52 #include <rte_common.h>
53 #include <rte_byteorder.h>
55 #include <rte_debug.h>
56 #include <rte_cycles.h>
57 #include <rte_memory.h>
58 #include <rte_launch.h>
60 #include <rte_per_lcore.h>
61 #include <rte_lcore.h>
62 #include <rte_atomic.h>
63 #include <rte_branch_prediction.h>
64 #include <rte_mempool.h>
65 #include <rte_interrupts.h>
67 #include <rte_ether.h>
68 #include <rte_ethdev.h>
69 #include <rte_string_fns.h>
70 #ifdef RTE_LIBRTE_CMDLINE
71 #include <cmdline_parse.h>
72 #include <cmdline_parse_etheraddr.h>
74 #ifdef RTE_LIBRTE_PMD_BOND
75 #include <rte_eth_bond.h>
85 #ifdef RTE_LIBRTE_CMDLINE
87 "[--cmdline-file=FILENAME] "
89 "[--help|-h] | [--auto-start|-a] | ["
90 "--tx-first | --stats-period=PERIOD | "
91 "--coremask=COREMASK --portmask=PORTMASK --numa "
92 "--mbuf-size= | --total-num-mbufs= | "
93 "--nb-cores= | --nb-ports= | "
94 #ifdef RTE_LIBRTE_CMDLINE
95 "--eth-peers-configfile= | "
96 "--eth-peer=X,M:M:M:M:M:M | "
98 "--pkt-filter-mode= |"
99 "--rss-ip | --rss-udp | "
100 "--rxpt= | --rxht= | --rxwt= | --rxfreet= | "
101 "--txpt= | --txht= | --txwt= | --txfreet= | "
102 "--txrst= | --txqflags= ]\n",
104 #ifdef RTE_LIBRTE_CMDLINE
105 printf(" --interactive: run in interactive mode.\n");
106 printf(" --cmdline-file: execute cli commands before startup.\n");
108 printf(" --auto-start: start forwarding on init "
109 "[always when non-interactive].\n");
110 printf(" --help: display this message and quit.\n");
111 printf(" --tx-first: start forwarding sending a burst first "
112 "(only if interactive is disabled).\n");
113 printf(" --stats-period=PERIOD: statistics will be shown "
114 "every PERIOD seconds (only if interactive is disabled).\n");
115 printf(" --nb-cores=N: set the number of forwarding cores "
116 "(1 <= N <= %d).\n", nb_lcores);
117 printf(" --nb-ports=N: set the number of forwarding ports "
118 "(1 <= N <= %d).\n", nb_ports);
119 printf(" --coremask=COREMASK: hexadecimal bitmask of cores running "
120 "the packet forwarding test. The master lcore is reserved for "
121 "command line parsing only, and cannot be masked on for "
122 "packet forwarding.\n");
123 printf(" --portmask=PORTMASK: hexadecimal bitmask of ports used "
124 "by the packet forwarding test.\n");
125 printf(" --numa: enable NUMA-aware allocation of RX/TX rings and of "
126 "RX memory buffers (mbufs).\n");
127 printf(" --port-numa-config=(port,socket)[,(port,socket)]: "
128 "specify the socket on which the memory pool "
129 "used by the port will be allocated.\n");
130 printf(" --ring-numa-config=(port,flag,socket)[,(port,flag,socket)]: "
131 "specify the socket on which the TX/RX rings for "
132 "the port will be allocated "
133 "(flag: 1 for RX; 2 for TX; 3 for RX and TX).\n");
134 printf(" --socket-num=N: set socket from which all memory is allocated "
136 printf(" --mbuf-size=N: set the data size of mbuf to N bytes.\n");
137 printf(" --total-num-mbufs=N: set the number of mbufs to be allocated "
139 printf(" --max-pkt-len=N: set the maximum size of packet to N bytes.\n");
140 #ifdef RTE_LIBRTE_CMDLINE
141 printf(" --eth-peers-configfile=name: config file with ethernet addresses "
143 printf(" --eth-peer=X,M:M:M:M:M:M: set the MAC address of the X peer "
144 "port (0 <= X < %d).\n", RTE_MAX_ETHPORTS);
146 printf(" --pkt-filter-mode=N: set Flow Director mode "
147 "(N: none (default mode) or signature or perfect).\n");
148 printf(" --pkt-filter-report-hash=N: set Flow Director report mode "
149 "(N: none or match (default) or always).\n");
150 printf(" --pkt-filter-size=N: set Flow Director mode "
151 "(N: 64K (default mode) or 128K or 256K).\n");
152 printf(" --pkt-filter-drop-queue=N: set drop-queue. "
153 "In perfect mode, when you add a rule with queue = -1 "
154 "the packet will be enqueued into the rx drop-queue. "
155 "If the drop-queue doesn't exist, the packet is dropped. "
156 "By default drop-queue=127.\n");
157 #ifdef RTE_LIBRTE_LATENCY_STATS
158 printf(" --latencystats=N: enable latency and jitter statistcs "
159 "monitoring on forwarding lcore id N.\n");
161 printf(" --disable-crc-strip: disable CRC stripping by hardware.\n");
162 printf(" --enable-lro: enable large receive offload.\n");
163 printf(" --enable-rx-cksum: enable rx hardware checksum offload.\n");
164 printf(" --enable-rx-timestamp: enable rx hardware timestamp offload.\n");
165 printf(" --disable-hw-vlan: disable hardware vlan.\n");
166 printf(" --disable-hw-vlan-filter: disable hardware vlan filter.\n");
167 printf(" --disable-hw-vlan-strip: disable hardware vlan strip.\n");
168 printf(" --disable-hw-vlan-extend: disable hardware vlan extend.\n");
169 printf(" --enable-drop-en: enable per queue packet drop.\n");
170 printf(" --disable-rss: disable rss.\n");
171 printf(" --port-topology=N: set port topology (N: paired (default) or "
173 printf(" --forward-mode=N: set forwarding mode (N: %s).\n",
174 list_pkt_forwarding_modes());
175 printf(" --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
176 printf(" --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
177 printf(" --rxq=N: set the number of RX queues per port to N.\n");
178 printf(" --rxd=N: set the number of descriptors in RX rings to N.\n");
179 printf(" --txq=N: set the number of TX queues per port to N.\n");
180 printf(" --txd=N: set the number of descriptors in TX rings to N.\n");
181 printf(" --burst=N: set the number of packets per burst to N.\n");
182 printf(" --mbcache=N: set the cache of mbuf memory pool to N.\n");
183 printf(" --rxpt=N: set prefetch threshold register of RX rings to N.\n");
184 printf(" --rxht=N: set the host threshold register of RX rings to N.\n");
185 printf(" --rxfreet=N: set the free threshold of RX descriptors to N "
186 "(0 <= N < value of rxd).\n");
187 printf(" --rxwt=N: set the write-back threshold register of RX rings to N.\n");
188 printf(" --txpt=N: set the prefetch threshold register of TX rings to N.\n");
189 printf(" --txht=N: set the nhost threshold register of TX rings to N.\n");
190 printf(" --txwt=N: set the write-back threshold register of TX rings to N.\n");
191 printf(" --txfreet=N: set the transmit free threshold of TX rings to N "
192 "(0 <= N <= value of txd).\n");
193 printf(" --txrst=N: set the transmit RS bit threshold of TX rings to N "
194 "(0 <= N <= value of txd).\n");
195 printf(" --txqflags=0xXXXXXXXX: hexadecimal bitmask of TX queue flags "
196 "(0 <= N <= 0x7FFFFFFF).\n");
197 printf(" --tx-queue-stats-mapping=(port,queue,mapping)[,(port,queue,mapping]: "
198 "tx queues statistics counters mapping "
199 "(0 <= mapping <= %d).\n", RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
200 printf(" --rx-queue-stats-mapping=(port,queue,mapping)[,(port,queue,mapping]: "
201 "rx queues statistics counters mapping "
202 "(0 <= mapping <= %d).\n", RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
203 printf(" --no-flush-rx: Don't flush RX streams before forwarding."
204 " Used mainly with PCAP drivers.\n");
205 printf(" --txpkts=X[,Y]*: set TX segment sizes"
206 " or total packet length.\n");
207 printf(" --disable-link-check: disable check on link status when "
208 "starting/stopping ports.\n");
209 printf(" --no-lsc-interrupt: disable link status change interrupt.\n");
210 printf(" --no-rmv-interrupt: disable device removal interrupt.\n");
211 printf(" --bitrate-stats=N: set the logical core N to perform "
212 "bit-rate calculation.\n");
213 printf(" --print-event <unknown|intr_lsc|queue_state|intr_reset|vf_mbox|macsec|intr_rmv|all>: "
214 "enable print of designated event or all of them.\n");
215 printf(" --mask-event <unknown|intr_lsc|queue_state|intr_reset|vf_mbox|macsec|intr_rmv|all>: "
216 "disable print of designated event or all of them.\n");
217 printf(" --flow-isolate-all: "
218 "requests flow API isolated mode on all ports at initialization time.\n");
221 #ifdef RTE_LIBRTE_CMDLINE
223 init_peer_eth_addrs(char *config_filename)
229 config_file = fopen(config_filename, "r");
230 if (config_file == NULL) {
231 perror("Failed to open eth config file\n");
235 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
237 if (fgets(buf, sizeof(buf), config_file) == NULL)
240 if (cmdline_parse_etheraddr(NULL, buf, &peer_eth_addrs[i],
241 sizeof(peer_eth_addrs[i])) < 0) {
242 printf("Bad MAC address format on line %d\n", i+1);
248 nb_peer_eth_addrs = (portid_t) i;
254 * Parse the coremask given as argument (hexadecimal string) and set
255 * the global configuration of forwarding cores.
258 parse_fwd_coremask(const char *coremask)
261 unsigned long long int cm;
263 /* parse hexadecimal string */
265 cm = strtoull(coremask, &end, 16);
266 if ((coremask[0] == '\0') || (end == NULL) || (*end != '\0'))
267 rte_exit(EXIT_FAILURE, "Invalid fwd core mask\n");
268 else if (set_fwd_lcores_mask((uint64_t) cm) < 0)
269 rte_exit(EXIT_FAILURE, "coremask is not valid\n");
273 * Parse the coremask given as argument (hexadecimal string) and set
274 * the global configuration of forwarding cores.
277 parse_fwd_portmask(const char *portmask)
280 unsigned long long int pm;
282 /* parse hexadecimal string */
284 pm = strtoull(portmask, &end, 16);
285 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
286 rte_exit(EXIT_FAILURE, "Invalid fwd port mask\n");
288 set_fwd_ports_mask((uint64_t) pm);
293 parse_queue_stats_mapping_config(const char *q_arg, int is_rx)
296 const char *p, *p0 = q_arg;
304 unsigned long int_fld[_NUM_FLD];
305 char *str_fld[_NUM_FLD];
309 /* reset from value set at definition */
310 is_rx ? (nb_rx_queue_stats_mappings = 0) : (nb_tx_queue_stats_mappings = 0);
312 while ((p = strchr(p0,'(')) != NULL) {
314 if((p0 = strchr(p,')')) == NULL)
318 if(size >= sizeof(s))
321 snprintf(s, sizeof(s), "%.*s", size, p);
322 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
324 for (i = 0; i < _NUM_FLD; i++){
326 int_fld[i] = strtoul(str_fld[i], &end, 0);
327 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
330 /* Check mapping field is in correct range (0..RTE_ETHDEV_QUEUE_STAT_CNTRS-1) */
331 if (int_fld[FLD_STATS_COUNTER] >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
332 printf("Stats counter not in the correct range 0..%d\n",
333 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
338 if ((nb_tx_queue_stats_mappings >=
339 MAX_TX_QUEUE_STATS_MAPPINGS)) {
340 printf("exceeded max number of TX queue "
341 "statistics mappings: %hu\n",
342 nb_tx_queue_stats_mappings);
345 tx_queue_stats_mappings_array[nb_tx_queue_stats_mappings].port_id =
346 (uint8_t)int_fld[FLD_PORT];
347 tx_queue_stats_mappings_array[nb_tx_queue_stats_mappings].queue_id =
348 (uint8_t)int_fld[FLD_QUEUE];
349 tx_queue_stats_mappings_array[nb_tx_queue_stats_mappings].stats_counter_id =
350 (uint8_t)int_fld[FLD_STATS_COUNTER];
351 ++nb_tx_queue_stats_mappings;
354 if ((nb_rx_queue_stats_mappings >=
355 MAX_RX_QUEUE_STATS_MAPPINGS)) {
356 printf("exceeded max number of RX queue "
357 "statistics mappings: %hu\n",
358 nb_rx_queue_stats_mappings);
361 rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].port_id =
362 (uint8_t)int_fld[FLD_PORT];
363 rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].queue_id =
364 (uint8_t)int_fld[FLD_QUEUE];
365 rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].stats_counter_id =
366 (uint8_t)int_fld[FLD_STATS_COUNTER];
367 ++nb_rx_queue_stats_mappings;
371 /* Reassign the rx/tx_queue_stats_mappings pointer to point to this newly populated array rather */
372 /* than to the default array (that was set at its definition) */
373 is_rx ? (rx_queue_stats_mappings = rx_queue_stats_mappings_array) :
374 (tx_queue_stats_mappings = tx_queue_stats_mappings_array);
379 print_invalid_socket_id_error(void)
383 printf("Invalid socket id, options are: ");
384 for (i = 0; i < num_sockets; i++) {
385 printf("%u%s", socket_ids[i],
386 (i == num_sockets - 1) ? "\n" : ",");
391 parse_portnuma_config(const char *q_arg)
394 const char *p, *p0 = q_arg;
396 uint8_t i, socket_id;
404 unsigned long int_fld[_NUM_FLD];
405 char *str_fld[_NUM_FLD];
408 /* reset from value set at definition */
409 while ((p = strchr(p0,'(')) != NULL) {
411 if((p0 = strchr(p,')')) == NULL)
415 if(size >= sizeof(s))
418 snprintf(s, sizeof(s), "%.*s", size, p);
419 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
421 for (i = 0; i < _NUM_FLD; i++) {
423 int_fld[i] = strtoul(str_fld[i], &end, 0);
424 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
427 port_id = (portid_t)int_fld[FLD_PORT];
428 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
429 port_id == (portid_t)RTE_PORT_ALL) {
430 printf("Valid port range is [0");
431 RTE_ETH_FOREACH_DEV(pid)
436 socket_id = (uint8_t)int_fld[FLD_SOCKET];
437 if (new_socket_id(socket_id)) {
438 print_invalid_socket_id_error();
441 port_numa[port_id] = socket_id;
448 parse_ringnuma_config(const char *q_arg)
451 const char *p, *p0 = q_arg;
453 uint8_t i, ring_flag, socket_id;
462 unsigned long int_fld[_NUM_FLD];
463 char *str_fld[_NUM_FLD];
465 #define RX_RING_ONLY 0x1
466 #define TX_RING_ONLY 0x2
467 #define RXTX_RING 0x3
469 /* reset from value set at definition */
470 while ((p = strchr(p0,'(')) != NULL) {
472 if((p0 = strchr(p,')')) == NULL)
476 if(size >= sizeof(s))
479 snprintf(s, sizeof(s), "%.*s", size, p);
480 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
482 for (i = 0; i < _NUM_FLD; i++) {
484 int_fld[i] = strtoul(str_fld[i], &end, 0);
485 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
488 port_id = (portid_t)int_fld[FLD_PORT];
489 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
490 port_id == (portid_t)RTE_PORT_ALL) {
491 printf("Valid port range is [0");
492 RTE_ETH_FOREACH_DEV(pid)
497 socket_id = (uint8_t)int_fld[FLD_SOCKET];
498 if (new_socket_id(socket_id)) {
499 print_invalid_socket_id_error();
502 ring_flag = (uint8_t)int_fld[FLD_FLAG];
503 if ((ring_flag < RX_RING_ONLY) || (ring_flag > RXTX_RING)) {
504 printf("Invalid ring-flag=%d config for port =%d\n",
509 switch (ring_flag & RXTX_RING) {
511 rxring_numa[port_id] = socket_id;
514 txring_numa[port_id] = socket_id;
517 rxring_numa[port_id] = socket_id;
518 txring_numa[port_id] = socket_id;
521 printf("Invalid ring-flag=%d config for port=%d\n",
531 parse_event_printing_config(const char *optarg, int enable)
535 if (!strcmp(optarg, "unknown"))
536 mask = UINT32_C(1) << RTE_ETH_EVENT_UNKNOWN;
537 else if (!strcmp(optarg, "intr_lsc"))
538 mask = UINT32_C(1) << RTE_ETH_EVENT_INTR_LSC;
539 else if (!strcmp(optarg, "queue_state"))
540 mask = UINT32_C(1) << RTE_ETH_EVENT_QUEUE_STATE;
541 else if (!strcmp(optarg, "intr_reset"))
542 mask = UINT32_C(1) << RTE_ETH_EVENT_INTR_RESET;
543 else if (!strcmp(optarg, "vf_mbox"))
544 mask = UINT32_C(1) << RTE_ETH_EVENT_VF_MBOX;
545 else if (!strcmp(optarg, "macsec"))
546 mask = UINT32_C(1) << RTE_ETH_EVENT_MACSEC;
547 else if (!strcmp(optarg, "intr_rmv"))
548 mask = UINT32_C(1) << RTE_ETH_EVENT_INTR_RMV;
549 else if (!strcmp(optarg, "all"))
552 fprintf(stderr, "Invalid event: %s\n", optarg);
556 event_print_mask |= mask;
558 event_print_mask &= ~mask;
563 launch_args_parse(int argc, char** argv)
570 static struct option lgopts[] = {
572 #ifdef RTE_LIBRTE_CMDLINE
573 { "interactive", 0, 0, 0 },
574 { "cmdline-file", 1, 0, 0 },
575 { "auto-start", 0, 0, 0 },
576 { "eth-peers-configfile", 1, 0, 0 },
577 { "eth-peer", 1, 0, 0 },
579 { "tx-first", 0, 0, 0 },
580 { "stats-period", 1, 0, 0 },
581 { "ports", 1, 0, 0 },
582 { "nb-cores", 1, 0, 0 },
583 { "nb-ports", 1, 0, 0 },
584 { "coremask", 1, 0, 0 },
585 { "portmask", 1, 0, 0 },
587 { "no-numa", 0, 0, 0 },
588 { "mp-anon", 0, 0, 0 },
589 { "port-numa-config", 1, 0, 0 },
590 { "ring-numa-config", 1, 0, 0 },
591 { "socket-num", 1, 0, 0 },
592 { "mbuf-size", 1, 0, 0 },
593 { "total-num-mbufs", 1, 0, 0 },
594 { "max-pkt-len", 1, 0, 0 },
595 { "pkt-filter-mode", 1, 0, 0 },
596 { "pkt-filter-report-hash", 1, 0, 0 },
597 { "pkt-filter-size", 1, 0, 0 },
598 { "pkt-filter-drop-queue", 1, 0, 0 },
599 #ifdef RTE_LIBRTE_LATENCY_STATS
600 { "latencystats", 1, 0, 0 },
602 #ifdef RTE_LIBRTE_BITRATE
603 { "bitrate-stats", 1, 0, 0 },
605 { "disable-crc-strip", 0, 0, 0 },
606 { "enable-lro", 0, 0, 0 },
607 { "enable-rx-cksum", 0, 0, 0 },
608 { "enable-rx-timestamp", 0, 0, 0 },
609 { "enable-scatter", 0, 0, 0 },
610 { "disable-hw-vlan", 0, 0, 0 },
611 { "disable-hw-vlan-filter", 0, 0, 0 },
612 { "disable-hw-vlan-strip", 0, 0, 0 },
613 { "disable-hw-vlan-extend", 0, 0, 0 },
614 { "enable-drop-en", 0, 0, 0 },
615 { "disable-rss", 0, 0, 0 },
616 { "port-topology", 1, 0, 0 },
617 { "forward-mode", 1, 0, 0 },
618 { "rss-ip", 0, 0, 0 },
619 { "rss-udp", 0, 0, 0 },
624 { "burst", 1, 0, 0 },
625 { "mbcache", 1, 0, 0 },
629 { "txfreet", 1, 0, 0 },
630 { "txrst", 1, 0, 0 },
631 { "txqflags", 1, 0, 0 },
635 { "rxfreet", 1, 0, 0 },
636 { "tx-queue-stats-mapping", 1, 0, 0 },
637 { "rx-queue-stats-mapping", 1, 0, 0 },
638 { "no-flush-rx", 0, 0, 0 },
639 { "flow-isolate-all", 0, 0, 0 },
640 { "txpkts", 1, 0, 0 },
641 { "disable-link-check", 0, 0, 0 },
642 { "no-lsc-interrupt", 0, 0, 0 },
643 { "no-rmv-interrupt", 0, 0, 0 },
644 { "print-event", 1, 0, 0 },
645 { "mask-event", 1, 0, 0 },
651 #ifdef RTE_LIBRTE_CMDLINE
652 #define SHORTOPTS "i"
656 while ((opt = getopt_long(argc, argvopt, SHORTOPTS "ah",
657 lgopts, &opt_idx)) != EOF) {
659 #ifdef RTE_LIBRTE_CMDLINE
661 printf("Interactive-mode selected\n");
666 printf("Auto-start selected\n");
670 case 0: /*long options */
671 if (!strcmp(lgopts[opt_idx].name, "help")) {
673 rte_exit(EXIT_SUCCESS, "Displayed help\n");
675 #ifdef RTE_LIBRTE_CMDLINE
676 if (!strcmp(lgopts[opt_idx].name, "interactive")) {
677 printf("Interactive-mode selected\n");
680 if (!strcmp(lgopts[opt_idx].name, "cmdline-file")) {
681 printf("CLI commands to be read from %s\n",
683 snprintf(cmdline_filename,
684 sizeof(cmdline_filename), "%s",
687 if (!strcmp(lgopts[opt_idx].name, "auto-start")) {
688 printf("Auto-start selected\n");
691 if (!strcmp(lgopts[opt_idx].name, "tx-first")) {
692 printf("Ports to start sending a burst of "
696 if (!strcmp(lgopts[opt_idx].name, "stats-period")) {
700 n = strtoul(optarg, &end, 10);
701 if ((optarg[0] == '\0') || (end == NULL) ||
708 if (!strcmp(lgopts[opt_idx].name,
709 "eth-peers-configfile")) {
710 if (init_peer_eth_addrs(optarg) != 0)
711 rte_exit(EXIT_FAILURE,
712 "Cannot open logfile\n");
714 if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
716 uint8_t c, peer_addr[6];
719 n = strtoul(optarg, &port_end, 10);
720 if (errno != 0 || port_end == optarg || *port_end++ != ',')
721 rte_exit(EXIT_FAILURE,
722 "Invalid eth-peer: %s", optarg);
723 if (n >= RTE_MAX_ETHPORTS)
724 rte_exit(EXIT_FAILURE,
725 "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
726 n, RTE_MAX_ETHPORTS);
728 if (cmdline_parse_etheraddr(NULL, port_end,
729 &peer_addr, sizeof(peer_addr)) < 0)
730 rte_exit(EXIT_FAILURE,
731 "Invalid ethernet address: %s\n",
733 for (c = 0; c < 6; c++)
734 peer_eth_addrs[n].addr_bytes[c] =
739 if (!strcmp(lgopts[opt_idx].name, "nb-ports")) {
741 if (n > 0 && n <= nb_ports)
744 rte_exit(EXIT_FAILURE,
745 "Invalid port %d\n", n);
747 if (!strcmp(lgopts[opt_idx].name, "nb-cores")) {
749 if (n > 0 && n <= nb_lcores)
750 nb_fwd_lcores = (uint8_t) n;
752 rte_exit(EXIT_FAILURE,
753 "nb-cores should be > 0 and <= %d\n",
756 if (!strcmp(lgopts[opt_idx].name, "coremask"))
757 parse_fwd_coremask(optarg);
758 if (!strcmp(lgopts[opt_idx].name, "portmask"))
759 parse_fwd_portmask(optarg);
760 if (!strcmp(lgopts[opt_idx].name, "no-numa"))
762 if (!strcmp(lgopts[opt_idx].name, "numa"))
764 if (!strcmp(lgopts[opt_idx].name, "mp-anon")) {
767 if (!strcmp(lgopts[opt_idx].name, "port-numa-config")) {
768 if (parse_portnuma_config(optarg))
769 rte_exit(EXIT_FAILURE,
770 "invalid port-numa configuration\n");
772 if (!strcmp(lgopts[opt_idx].name, "ring-numa-config"))
773 if (parse_ringnuma_config(optarg))
774 rte_exit(EXIT_FAILURE,
775 "invalid ring-numa configuration\n");
776 if (!strcmp(lgopts[opt_idx].name, "socket-num")) {
778 if (!new_socket_id((uint8_t)n)) {
779 socket_num = (uint8_t)n;
781 print_invalid_socket_id_error();
782 rte_exit(EXIT_FAILURE,
783 "Invalid socket id");
786 if (!strcmp(lgopts[opt_idx].name, "mbuf-size")) {
788 if (n > 0 && n <= 0xFFFF)
789 mbuf_data_size = (uint16_t) n;
791 rte_exit(EXIT_FAILURE,
792 "mbuf-size should be > 0 and < 65536\n");
794 if (!strcmp(lgopts[opt_idx].name, "total-num-mbufs")) {
797 param_total_num_mbufs = (unsigned)n;
799 rte_exit(EXIT_FAILURE,
800 "total-num-mbufs should be > 1024\n");
802 if (!strcmp(lgopts[opt_idx].name, "max-pkt-len")) {
804 if (n >= ETHER_MIN_LEN) {
805 rx_mode.max_rx_pkt_len = (uint32_t) n;
806 if (n > ETHER_MAX_LEN)
807 rx_mode.jumbo_frame = 1;
809 rte_exit(EXIT_FAILURE,
810 "Invalid max-pkt-len=%d - should be > %d\n",
813 if (!strcmp(lgopts[opt_idx].name, "pkt-filter-mode")) {
814 if (!strcmp(optarg, "signature"))
816 RTE_FDIR_MODE_SIGNATURE;
817 else if (!strcmp(optarg, "perfect"))
818 fdir_conf.mode = RTE_FDIR_MODE_PERFECT;
819 else if (!strcmp(optarg, "perfect-mac-vlan"))
820 fdir_conf.mode = RTE_FDIR_MODE_PERFECT_MAC_VLAN;
821 else if (!strcmp(optarg, "perfect-tunnel"))
822 fdir_conf.mode = RTE_FDIR_MODE_PERFECT_TUNNEL;
823 else if (!strcmp(optarg, "none"))
824 fdir_conf.mode = RTE_FDIR_MODE_NONE;
826 rte_exit(EXIT_FAILURE,
827 "pkt-mode-invalid %s invalid - must be: "
828 "none, signature, perfect, perfect-mac-vlan"
829 " or perfect-tunnel\n",
832 if (!strcmp(lgopts[opt_idx].name,
833 "pkt-filter-report-hash")) {
834 if (!strcmp(optarg, "none"))
836 RTE_FDIR_NO_REPORT_STATUS;
837 else if (!strcmp(optarg, "match"))
839 RTE_FDIR_REPORT_STATUS;
840 else if (!strcmp(optarg, "always"))
842 RTE_FDIR_REPORT_STATUS_ALWAYS;
844 rte_exit(EXIT_FAILURE,
845 "pkt-filter-report-hash %s invalid "
846 "- must be: none or match or always\n",
849 if (!strcmp(lgopts[opt_idx].name, "pkt-filter-size")) {
850 if (!strcmp(optarg, "64K"))
852 RTE_FDIR_PBALLOC_64K;
853 else if (!strcmp(optarg, "128K"))
855 RTE_FDIR_PBALLOC_128K;
856 else if (!strcmp(optarg, "256K"))
858 RTE_FDIR_PBALLOC_256K;
860 rte_exit(EXIT_FAILURE, "pkt-filter-size %s invalid -"
861 " must be: 64K or 128K or 256K\n",
864 if (!strcmp(lgopts[opt_idx].name,
865 "pkt-filter-drop-queue")) {
868 fdir_conf.drop_queue = (uint8_t) n;
870 rte_exit(EXIT_FAILURE,
871 "drop queue %d invalid - must"
874 #ifdef RTE_LIBRTE_LATENCY_STATS
875 if (!strcmp(lgopts[opt_idx].name,
879 latencystats_lcore_id = (lcoreid_t) n;
880 latencystats_enabled = 1;
882 rte_exit(EXIT_FAILURE,
883 "invalid lcore id %d for latencystats"
884 " must be >= 0\n", n);
887 #ifdef RTE_LIBRTE_BITRATE
888 if (!strcmp(lgopts[opt_idx].name, "bitrate-stats")) {
891 bitrate_lcore_id = (lcoreid_t) n;
894 rte_exit(EXIT_FAILURE,
895 "invalid lcore id %d for bitrate stats"
896 " must be >= 0\n", n);
899 if (!strcmp(lgopts[opt_idx].name, "disable-crc-strip"))
900 rx_mode.hw_strip_crc = 0;
901 if (!strcmp(lgopts[opt_idx].name, "enable-lro"))
902 rx_mode.enable_lro = 1;
903 if (!strcmp(lgopts[opt_idx].name, "enable-scatter"))
904 rx_mode.enable_scatter = 1;
905 if (!strcmp(lgopts[opt_idx].name, "enable-rx-cksum"))
906 rx_mode.hw_ip_checksum = 1;
907 if (!strcmp(lgopts[opt_idx].name,
908 "enable-rx-timestamp"))
909 rx_mode.hw_timestamp = 1;
911 if (!strcmp(lgopts[opt_idx].name, "disable-hw-vlan")) {
912 rx_mode.hw_vlan_filter = 0;
913 rx_mode.hw_vlan_strip = 0;
914 rx_mode.hw_vlan_extend = 0;
917 if (!strcmp(lgopts[opt_idx].name,
918 "disable-hw-vlan-filter"))
919 rx_mode.hw_vlan_filter = 0;
921 if (!strcmp(lgopts[opt_idx].name,
922 "disable-hw-vlan-strip"))
923 rx_mode.hw_vlan_strip = 0;
925 if (!strcmp(lgopts[opt_idx].name,
926 "disable-hw-vlan-extend"))
927 rx_mode.hw_vlan_extend = 0;
929 if (!strcmp(lgopts[opt_idx].name, "enable-drop-en"))
932 if (!strcmp(lgopts[opt_idx].name, "disable-rss"))
934 if (!strcmp(lgopts[opt_idx].name, "port-topology")) {
935 if (!strcmp(optarg, "paired"))
936 port_topology = PORT_TOPOLOGY_PAIRED;
937 else if (!strcmp(optarg, "chained"))
938 port_topology = PORT_TOPOLOGY_CHAINED;
939 else if (!strcmp(optarg, "loop"))
940 port_topology = PORT_TOPOLOGY_LOOP;
942 rte_exit(EXIT_FAILURE, "port-topology %s invalid -"
943 " must be: paired, chained or loop\n",
946 if (!strcmp(lgopts[opt_idx].name, "forward-mode"))
947 set_pkt_forwarding_mode(optarg);
948 if (!strcmp(lgopts[opt_idx].name, "rss-ip"))
950 if (!strcmp(lgopts[opt_idx].name, "rss-udp"))
951 rss_hf = ETH_RSS_UDP;
952 if (!strcmp(lgopts[opt_idx].name, "rxq")) {
954 if (n >= 0 && n <= (int) MAX_QUEUE_ID)
955 nb_rxq = (queueid_t) n;
957 rte_exit(EXIT_FAILURE, "rxq %d invalid - must be"
958 " >= 0 && <= %d\n", n,
961 if (!strcmp(lgopts[opt_idx].name, "txq")) {
963 if (n >= 0 && n <= (int) MAX_QUEUE_ID)
964 nb_txq = (queueid_t) n;
966 rte_exit(EXIT_FAILURE, "txq %d invalid - must be"
967 " >= 0 && <= %d\n", n,
970 if (!nb_rxq && !nb_txq) {
971 rte_exit(EXIT_FAILURE, "Either rx or tx queues should "
974 if (!strcmp(lgopts[opt_idx].name, "burst")) {
976 if ((n >= 1) && (n <= MAX_PKT_BURST))
977 nb_pkt_per_burst = (uint16_t) n;
979 rte_exit(EXIT_FAILURE,
980 "burst must >= 1 and <= %d]",
983 if (!strcmp(lgopts[opt_idx].name, "mbcache")) {
986 (n <= RTE_MEMPOOL_CACHE_MAX_SIZE))
987 mb_mempool_cache = (uint16_t) n;
989 rte_exit(EXIT_FAILURE,
990 "mbcache must be >= 0 and <= %d\n",
991 RTE_MEMPOOL_CACHE_MAX_SIZE);
993 if (!strcmp(lgopts[opt_idx].name, "txfreet")) {
996 tx_free_thresh = (int16_t)n;
998 rte_exit(EXIT_FAILURE, "txfreet must be >= 0\n");
1000 if (!strcmp(lgopts[opt_idx].name, "txrst")) {
1003 tx_rs_thresh = (int16_t)n;
1005 rte_exit(EXIT_FAILURE, "txrst must be >= 0\n");
1007 if (!strcmp(lgopts[opt_idx].name, "txqflags")) {
1009 n = strtoul(optarg, &end, 16);
1011 txq_flags = (int32_t)n;
1013 rte_exit(EXIT_FAILURE,
1014 "txqflags must be >= 0\n");
1016 if (!strcmp(lgopts[opt_idx].name, "rxd")) {
1019 if (rx_free_thresh >= n)
1020 rte_exit(EXIT_FAILURE,
1022 "rx_free_thresh(%d)\n",
1023 (int)rx_free_thresh);
1025 nb_rxd = (uint16_t) n;
1027 rte_exit(EXIT_FAILURE,
1028 "rxd(%d) invalid - must be > 0\n",
1031 if (!strcmp(lgopts[opt_idx].name, "txd")) {
1034 nb_txd = (uint16_t) n;
1036 rte_exit(EXIT_FAILURE, "txd must be in > 0\n");
1038 if (!strcmp(lgopts[opt_idx].name, "txpt")) {
1041 tx_pthresh = (int8_t)n;
1043 rte_exit(EXIT_FAILURE, "txpt must be >= 0\n");
1045 if (!strcmp(lgopts[opt_idx].name, "txht")) {
1048 tx_hthresh = (int8_t)n;
1050 rte_exit(EXIT_FAILURE, "txht must be >= 0\n");
1052 if (!strcmp(lgopts[opt_idx].name, "txwt")) {
1055 tx_wthresh = (int8_t)n;
1057 rte_exit(EXIT_FAILURE, "txwt must be >= 0\n");
1059 if (!strcmp(lgopts[opt_idx].name, "rxpt")) {
1062 rx_pthresh = (int8_t)n;
1064 rte_exit(EXIT_FAILURE, "rxpt must be >= 0\n");
1066 if (!strcmp(lgopts[opt_idx].name, "rxht")) {
1069 rx_hthresh = (int8_t)n;
1071 rte_exit(EXIT_FAILURE, "rxht must be >= 0\n");
1073 if (!strcmp(lgopts[opt_idx].name, "rxwt")) {
1076 rx_wthresh = (int8_t)n;
1078 rte_exit(EXIT_FAILURE, "rxwt must be >= 0\n");
1080 if (!strcmp(lgopts[opt_idx].name, "rxfreet")) {
1083 rx_free_thresh = (int16_t)n;
1085 rte_exit(EXIT_FAILURE, "rxfreet must be >= 0\n");
1087 if (!strcmp(lgopts[opt_idx].name, "tx-queue-stats-mapping")) {
1088 if (parse_queue_stats_mapping_config(optarg, TX)) {
1089 rte_exit(EXIT_FAILURE,
1090 "invalid TX queue statistics mapping config entered\n");
1093 if (!strcmp(lgopts[opt_idx].name, "rx-queue-stats-mapping")) {
1094 if (parse_queue_stats_mapping_config(optarg, RX)) {
1095 rte_exit(EXIT_FAILURE,
1096 "invalid RX queue statistics mapping config entered\n");
1099 if (!strcmp(lgopts[opt_idx].name, "txpkts")) {
1100 unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
1101 unsigned int nb_segs;
1103 nb_segs = parse_item_list(optarg, "txpkt segments",
1104 RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
1106 set_tx_pkt_segments(seg_lengths, nb_segs);
1108 rte_exit(EXIT_FAILURE, "bad txpkts\n");
1110 if (!strcmp(lgopts[opt_idx].name, "no-flush-rx"))
1112 if (!strcmp(lgopts[opt_idx].name, "disable-link-check"))
1114 if (!strcmp(lgopts[opt_idx].name, "no-lsc-interrupt"))
1116 if (!strcmp(lgopts[opt_idx].name, "no-rmv-interrupt"))
1118 if (!strcmp(lgopts[opt_idx].name, "flow-isolate-all"))
1119 flow_isolate_all = 1;
1120 if (!strcmp(lgopts[opt_idx].name, "print-event"))
1121 if (parse_event_printing_config(optarg, 1)) {
1122 rte_exit(EXIT_FAILURE,
1123 "invalid print-event argument\n");
1125 if (!strcmp(lgopts[opt_idx].name, "mask-event"))
1126 if (parse_event_printing_config(optarg, 0)) {
1127 rte_exit(EXIT_FAILURE,
1128 "invalid mask-event argument\n");
1134 rte_exit(EXIT_SUCCESS, "Displayed help\n");
1138 rte_exit(EXIT_FAILURE,
1139 "Command line is incomplete or incorrect\n");