1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
14 #include <sys/types.h>
16 #include <sys/queue.h>
23 #include <rte_common.h>
24 #include <rte_byteorder.h>
26 #include <rte_debug.h>
27 #include <rte_cycles.h>
28 #include <rte_memory.h>
29 #include <rte_launch.h>
31 #include <rte_per_lcore.h>
32 #include <rte_lcore.h>
33 #include <rte_atomic.h>
34 #include <rte_branch_prediction.h>
35 #include <rte_mempool.h>
36 #include <rte_interrupts.h>
38 #include <rte_ether.h>
39 #include <rte_ethdev.h>
40 #include <rte_string_fns.h>
41 #ifdef RTE_LIBRTE_CMDLINE
42 #include <cmdline_parse.h>
43 #include <cmdline_parse_etheraddr.h>
45 #ifdef RTE_LIBRTE_PMD_BOND
46 #include <rte_eth_bond.h>
56 #ifdef RTE_LIBRTE_CMDLINE
58 "[--cmdline-file=FILENAME] "
60 "[--help|-h] | [--auto-start|-a] | ["
61 "--tx-first | --stats-period=PERIOD | "
62 "--coremask=COREMASK --portmask=PORTMASK --numa "
63 "--mbuf-size= | --total-num-mbufs= | "
64 "--nb-cores= | --nb-ports= | "
65 #ifdef RTE_LIBRTE_CMDLINE
66 "--eth-peers-configfile= | "
67 "--eth-peer=X,M:M:M:M:M:M | "
69 "--pkt-filter-mode= |"
70 "--rss-ip | --rss-udp | "
71 "--rxpt= | --rxht= | --rxwt= | --rxfreet= | "
72 "--txpt= | --txht= | --txwt= | --txfreet= | "
73 "--txrst= | --tx-offloads= | --vxlan-gpe-port= ]\n",
75 #ifdef RTE_LIBRTE_CMDLINE
76 printf(" --interactive: run in interactive mode.\n");
77 printf(" --cmdline-file: execute cli commands before startup.\n");
79 printf(" --auto-start: start forwarding on init "
80 "[always when non-interactive].\n");
81 printf(" --help: display this message and quit.\n");
82 printf(" --tx-first: start forwarding sending a burst first "
83 "(only if interactive is disabled).\n");
84 printf(" --stats-period=PERIOD: statistics will be shown "
85 "every PERIOD seconds (only if interactive is disabled).\n");
86 printf(" --nb-cores=N: set the number of forwarding cores "
87 "(1 <= N <= %d).\n", nb_lcores);
88 printf(" --nb-ports=N: set the number of forwarding ports "
89 "(1 <= N <= %d).\n", nb_ports);
90 printf(" --coremask=COREMASK: hexadecimal bitmask of cores running "
91 "the packet forwarding test. The master lcore is reserved for "
92 "command line parsing only, and cannot be masked on for "
93 "packet forwarding.\n");
94 printf(" --portmask=PORTMASK: hexadecimal bitmask of ports used "
95 "by the packet forwarding test.\n");
96 printf(" --numa: enable NUMA-aware allocation of RX/TX rings and of "
97 "RX memory buffers (mbufs).\n");
98 printf(" --port-numa-config=(port,socket)[,(port,socket)]: "
99 "specify the socket on which the memory pool "
100 "used by the port will be allocated.\n");
101 printf(" --ring-numa-config=(port,flag,socket)[,(port,flag,socket)]: "
102 "specify the socket on which the TX/RX rings for "
103 "the port will be allocated "
104 "(flag: 1 for RX; 2 for TX; 3 for RX and TX).\n");
105 printf(" --socket-num=N: set socket from which all memory is allocated "
107 printf(" --mbuf-size=N: set the data size of mbuf to N bytes.\n");
108 printf(" --total-num-mbufs=N: set the number of mbufs to be allocated "
110 printf(" --max-pkt-len=N: set the maximum size of packet to N bytes.\n");
111 #ifdef RTE_LIBRTE_CMDLINE
112 printf(" --eth-peers-configfile=name: config file with ethernet addresses "
114 printf(" --eth-peer=X,M:M:M:M:M:M: set the MAC address of the X peer "
115 "port (0 <= X < %d).\n", RTE_MAX_ETHPORTS);
117 printf(" --pkt-filter-mode=N: set Flow Director mode "
118 "(N: none (default mode) or signature or perfect).\n");
119 printf(" --pkt-filter-report-hash=N: set Flow Director report mode "
120 "(N: none or match (default) or always).\n");
121 printf(" --pkt-filter-size=N: set Flow Director mode "
122 "(N: 64K (default mode) or 128K or 256K).\n");
123 printf(" --pkt-filter-drop-queue=N: set drop-queue. "
124 "In perfect mode, when you add a rule with queue = -1 "
125 "the packet will be enqueued into the rx drop-queue. "
126 "If the drop-queue doesn't exist, the packet is dropped. "
127 "By default drop-queue=127.\n");
128 #ifdef RTE_LIBRTE_LATENCY_STATS
129 printf(" --latencystats=N: enable latency and jitter statistcs "
130 "monitoring on forwarding lcore id N.\n");
132 printf(" --disable-crc-strip: disable CRC stripping by hardware.\n");
133 printf(" --enable-lro: enable large receive offload.\n");
134 printf(" --enable-rx-cksum: enable rx hardware checksum offload.\n");
135 printf(" --enable-rx-timestamp: enable rx hardware timestamp offload.\n");
136 printf(" --enable-hw-vlan: enable hardware vlan.\n");
137 printf(" --enable-hw-vlan-filter: enable hardware vlan filter.\n");
138 printf(" --enable-hw-vlan-strip: enable hardware vlan strip.\n");
139 printf(" --enable-hw-vlan-extend: enable hardware vlan extend.\n");
140 printf(" --enable-drop-en: enable per queue packet drop.\n");
141 printf(" --disable-rss: disable rss.\n");
142 printf(" --port-topology=N: set port topology (N: paired (default) or "
144 printf(" --forward-mode=N: set forwarding mode (N: %s).\n",
145 list_pkt_forwarding_modes());
146 printf(" --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
147 printf(" --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
148 printf(" --rxq=N: set the number of RX queues per port to N.\n");
149 printf(" --rxd=N: set the number of descriptors in RX rings to N.\n");
150 printf(" --txq=N: set the number of TX queues per port to N.\n");
151 printf(" --txd=N: set the number of descriptors in TX rings to N.\n");
152 printf(" --burst=N: set the number of packets per burst to N.\n");
153 printf(" --mbcache=N: set the cache of mbuf memory pool to N.\n");
154 printf(" --rxpt=N: set prefetch threshold register of RX rings to N.\n");
155 printf(" --rxht=N: set the host threshold register of RX rings to N.\n");
156 printf(" --rxfreet=N: set the free threshold of RX descriptors to N "
157 "(0 <= N < value of rxd).\n");
158 printf(" --rxwt=N: set the write-back threshold register of RX rings to N.\n");
159 printf(" --txpt=N: set the prefetch threshold register of TX rings to N.\n");
160 printf(" --txht=N: set the nhost threshold register of TX rings to N.\n");
161 printf(" --txwt=N: set the write-back threshold register of TX rings to N.\n");
162 printf(" --txfreet=N: set the transmit free threshold of TX rings to N "
163 "(0 <= N <= value of txd).\n");
164 printf(" --txrst=N: set the transmit RS bit threshold of TX rings to N "
165 "(0 <= N <= value of txd).\n");
166 printf(" --tx-queue-stats-mapping=(port,queue,mapping)[,(port,queue,mapping]: "
167 "tx queues statistics counters mapping "
168 "(0 <= mapping <= %d).\n", RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
169 printf(" --rx-queue-stats-mapping=(port,queue,mapping)[,(port,queue,mapping]: "
170 "rx queues statistics counters mapping "
171 "(0 <= mapping <= %d).\n", RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
172 printf(" --no-flush-rx: Don't flush RX streams before forwarding."
173 " Used mainly with PCAP drivers.\n");
174 printf(" --txpkts=X[,Y]*: set TX segment sizes"
175 " or total packet length.\n");
176 printf(" --disable-link-check: disable check on link status when "
177 "starting/stopping ports.\n");
178 printf(" --no-lsc-interrupt: disable link status change interrupt.\n");
179 printf(" --no-rmv-interrupt: disable device removal interrupt.\n");
180 printf(" --bitrate-stats=N: set the logical core N to perform "
181 "bit-rate calculation.\n");
182 printf(" --print-event <unknown|intr_lsc|queue_state|intr_reset|vf_mbox|macsec|intr_rmv|all>: "
183 "enable print of designated event or all of them.\n");
184 printf(" --mask-event <unknown|intr_lsc|queue_state|intr_reset|vf_mbox|macsec|intr_rmv|all>: "
185 "disable print of designated event or all of them.\n");
186 printf(" --flow-isolate-all: "
187 "requests flow API isolated mode on all ports at initialization time.\n");
188 printf(" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n");
189 printf(" --hot-plug: enable hot plug for device.\n");
190 printf(" --vxlan-gpe-port=N: UPD port of tunnel VXLAN-GPE\n");
191 printf(" --mlockall: lock all memory\n");
192 printf(" --no-mlockall: do not lock all memory\n");
193 printf(" --mp-alloc <native|anon|xmem|xmemhuge>: mempool allocation method.\n"
194 " native: use regular DPDK memory to create and populate mempool\n"
195 " anon: use regular DPDK memory to create and anonymous memory to populate mempool\n"
196 " xmem: use anonymous memory to create and populate mempool\n"
197 " xmemhuge: use anonymous hugepage memory to create and populate mempool\n");
198 printf(" --noisy-tx-sw-buffer-size=N: size of FIFO buffer\n");
199 printf(" --noisy-tx-sw-buffer-flushtime=N: flush FIFO after N ms\n");
200 printf(" --noisy-lkup-memory=N: allocate N MB of VNF memory\n");
201 printf(" --noisy-lkup-num-writes=N: do N random writes per packet\n");
202 printf(" --noisy-lkup-num-reads=N: do N random reads per packet\n");
203 printf(" --noisy-lkup-num-writes=N: do N random reads and writes per packet\n");
206 #ifdef RTE_LIBRTE_CMDLINE
208 init_peer_eth_addrs(char *config_filename)
214 config_file = fopen(config_filename, "r");
215 if (config_file == NULL) {
216 perror("Failed to open eth config file\n");
220 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
222 if (fgets(buf, sizeof(buf), config_file) == NULL)
225 if (cmdline_parse_etheraddr(NULL, buf, &peer_eth_addrs[i],
226 sizeof(peer_eth_addrs[i])) < 0) {
227 printf("Bad MAC address format on line %d\n", i+1);
233 nb_peer_eth_addrs = (portid_t) i;
239 * Parse the coremask given as argument (hexadecimal string) and set
240 * the global configuration of forwarding cores.
243 parse_fwd_coremask(const char *coremask)
246 unsigned long long int cm;
248 /* parse hexadecimal string */
250 cm = strtoull(coremask, &end, 16);
251 if ((coremask[0] == '\0') || (end == NULL) || (*end != '\0'))
252 rte_exit(EXIT_FAILURE, "Invalid fwd core mask\n");
253 else if (set_fwd_lcores_mask((uint64_t) cm) < 0)
254 rte_exit(EXIT_FAILURE, "coremask is not valid\n");
258 * Parse the coremask given as argument (hexadecimal string) and set
259 * the global configuration of forwarding cores.
262 parse_fwd_portmask(const char *portmask)
265 unsigned long long int pm;
267 /* parse hexadecimal string */
269 pm = strtoull(portmask, &end, 16);
270 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
271 rte_exit(EXIT_FAILURE, "Invalid fwd port mask\n");
273 set_fwd_ports_mask((uint64_t) pm);
278 parse_queue_stats_mapping_config(const char *q_arg, int is_rx)
281 const char *p, *p0 = q_arg;
289 unsigned long int_fld[_NUM_FLD];
290 char *str_fld[_NUM_FLD];
294 /* reset from value set at definition */
295 is_rx ? (nb_rx_queue_stats_mappings = 0) : (nb_tx_queue_stats_mappings = 0);
297 while ((p = strchr(p0,'(')) != NULL) {
299 if((p0 = strchr(p,')')) == NULL)
303 if(size >= sizeof(s))
306 snprintf(s, sizeof(s), "%.*s", size, p);
307 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
309 for (i = 0; i < _NUM_FLD; i++){
311 int_fld[i] = strtoul(str_fld[i], &end, 0);
312 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
315 /* Check mapping field is in correct range (0..RTE_ETHDEV_QUEUE_STAT_CNTRS-1) */
316 if (int_fld[FLD_STATS_COUNTER] >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
317 printf("Stats counter not in the correct range 0..%d\n",
318 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
323 if ((nb_tx_queue_stats_mappings >=
324 MAX_TX_QUEUE_STATS_MAPPINGS)) {
325 printf("exceeded max number of TX queue "
326 "statistics mappings: %hu\n",
327 nb_tx_queue_stats_mappings);
330 tx_queue_stats_mappings_array[nb_tx_queue_stats_mappings].port_id =
331 (uint8_t)int_fld[FLD_PORT];
332 tx_queue_stats_mappings_array[nb_tx_queue_stats_mappings].queue_id =
333 (uint8_t)int_fld[FLD_QUEUE];
334 tx_queue_stats_mappings_array[nb_tx_queue_stats_mappings].stats_counter_id =
335 (uint8_t)int_fld[FLD_STATS_COUNTER];
336 ++nb_tx_queue_stats_mappings;
339 if ((nb_rx_queue_stats_mappings >=
340 MAX_RX_QUEUE_STATS_MAPPINGS)) {
341 printf("exceeded max number of RX queue "
342 "statistics mappings: %hu\n",
343 nb_rx_queue_stats_mappings);
346 rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].port_id =
347 (uint8_t)int_fld[FLD_PORT];
348 rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].queue_id =
349 (uint8_t)int_fld[FLD_QUEUE];
350 rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].stats_counter_id =
351 (uint8_t)int_fld[FLD_STATS_COUNTER];
352 ++nb_rx_queue_stats_mappings;
356 /* Reassign the rx/tx_queue_stats_mappings pointer to point to this newly populated array rather */
357 /* than to the default array (that was set at its definition) */
358 is_rx ? (rx_queue_stats_mappings = rx_queue_stats_mappings_array) :
359 (tx_queue_stats_mappings = tx_queue_stats_mappings_array);
364 print_invalid_socket_id_error(void)
368 printf("Invalid socket id, options are: ");
369 for (i = 0; i < num_sockets; i++) {
370 printf("%u%s", socket_ids[i],
371 (i == num_sockets - 1) ? "\n" : ",");
376 parse_portnuma_config(const char *q_arg)
379 const char *p, *p0 = q_arg;
381 uint8_t i, socket_id;
389 unsigned long int_fld[_NUM_FLD];
390 char *str_fld[_NUM_FLD];
392 /* reset from value set at definition */
393 while ((p = strchr(p0,'(')) != NULL) {
395 if((p0 = strchr(p,')')) == NULL)
399 if(size >= sizeof(s))
402 snprintf(s, sizeof(s), "%.*s", size, p);
403 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
405 for (i = 0; i < _NUM_FLD; i++) {
407 int_fld[i] = strtoul(str_fld[i], &end, 0);
408 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
411 port_id = (portid_t)int_fld[FLD_PORT];
412 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
413 port_id == (portid_t)RTE_PORT_ALL) {
417 socket_id = (uint8_t)int_fld[FLD_SOCKET];
418 if (new_socket_id(socket_id)) {
419 print_invalid_socket_id_error();
422 port_numa[port_id] = socket_id;
429 parse_ringnuma_config(const char *q_arg)
432 const char *p, *p0 = q_arg;
434 uint8_t i, ring_flag, socket_id;
443 unsigned long int_fld[_NUM_FLD];
444 char *str_fld[_NUM_FLD];
445 #define RX_RING_ONLY 0x1
446 #define TX_RING_ONLY 0x2
447 #define RXTX_RING 0x3
449 /* reset from value set at definition */
450 while ((p = strchr(p0,'(')) != NULL) {
452 if((p0 = strchr(p,')')) == NULL)
456 if(size >= sizeof(s))
459 snprintf(s, sizeof(s), "%.*s", size, p);
460 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
462 for (i = 0; i < _NUM_FLD; i++) {
464 int_fld[i] = strtoul(str_fld[i], &end, 0);
465 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
468 port_id = (portid_t)int_fld[FLD_PORT];
469 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
470 port_id == (portid_t)RTE_PORT_ALL) {
474 socket_id = (uint8_t)int_fld[FLD_SOCKET];
475 if (new_socket_id(socket_id)) {
476 print_invalid_socket_id_error();
479 ring_flag = (uint8_t)int_fld[FLD_FLAG];
480 if ((ring_flag < RX_RING_ONLY) || (ring_flag > RXTX_RING)) {
481 printf("Invalid ring-flag=%d config for port =%d\n",
486 switch (ring_flag & RXTX_RING) {
488 rxring_numa[port_id] = socket_id;
491 txring_numa[port_id] = socket_id;
494 rxring_numa[port_id] = socket_id;
495 txring_numa[port_id] = socket_id;
498 printf("Invalid ring-flag=%d config for port=%d\n",
508 parse_event_printing_config(const char *optarg, int enable)
512 if (!strcmp(optarg, "unknown"))
513 mask = UINT32_C(1) << RTE_ETH_EVENT_UNKNOWN;
514 else if (!strcmp(optarg, "intr_lsc"))
515 mask = UINT32_C(1) << RTE_ETH_EVENT_INTR_LSC;
516 else if (!strcmp(optarg, "queue_state"))
517 mask = UINT32_C(1) << RTE_ETH_EVENT_QUEUE_STATE;
518 else if (!strcmp(optarg, "intr_reset"))
519 mask = UINT32_C(1) << RTE_ETH_EVENT_INTR_RESET;
520 else if (!strcmp(optarg, "vf_mbox"))
521 mask = UINT32_C(1) << RTE_ETH_EVENT_VF_MBOX;
522 else if (!strcmp(optarg, "ipsec"))
523 mask = UINT32_C(1) << RTE_ETH_EVENT_IPSEC;
524 else if (!strcmp(optarg, "macsec"))
525 mask = UINT32_C(1) << RTE_ETH_EVENT_MACSEC;
526 else if (!strcmp(optarg, "intr_rmv"))
527 mask = UINT32_C(1) << RTE_ETH_EVENT_INTR_RMV;
528 else if (!strcmp(optarg, "dev_probed"))
529 mask = UINT32_C(1) << RTE_ETH_EVENT_NEW;
530 else if (!strcmp(optarg, "dev_released"))
531 mask = UINT32_C(1) << RTE_ETH_EVENT_DESTROY;
532 else if (!strcmp(optarg, "all"))
535 fprintf(stderr, "Invalid event: %s\n", optarg);
539 event_print_mask |= mask;
541 event_print_mask &= ~mask;
546 launch_args_parse(int argc, char** argv)
553 /* Default offloads for all ports. */
554 uint64_t rx_offloads = rx_mode.offloads;
555 uint64_t tx_offloads = tx_mode.offloads;
556 struct rte_eth_dev_info dev_info;
557 uint16_t rec_nb_pkts;
559 static struct option lgopts[] = {
561 #ifdef RTE_LIBRTE_CMDLINE
562 { "interactive", 0, 0, 0 },
563 { "cmdline-file", 1, 0, 0 },
564 { "auto-start", 0, 0, 0 },
565 { "eth-peers-configfile", 1, 0, 0 },
566 { "eth-peer", 1, 0, 0 },
568 { "tx-first", 0, 0, 0 },
569 { "stats-period", 1, 0, 0 },
570 { "ports", 1, 0, 0 },
571 { "nb-cores", 1, 0, 0 },
572 { "nb-ports", 1, 0, 0 },
573 { "coremask", 1, 0, 0 },
574 { "portmask", 1, 0, 0 },
576 { "no-numa", 0, 0, 0 },
577 { "mp-anon", 0, 0, 0 },
578 { "port-numa-config", 1, 0, 0 },
579 { "ring-numa-config", 1, 0, 0 },
580 { "socket-num", 1, 0, 0 },
581 { "mbuf-size", 1, 0, 0 },
582 { "total-num-mbufs", 1, 0, 0 },
583 { "max-pkt-len", 1, 0, 0 },
584 { "pkt-filter-mode", 1, 0, 0 },
585 { "pkt-filter-report-hash", 1, 0, 0 },
586 { "pkt-filter-size", 1, 0, 0 },
587 { "pkt-filter-drop-queue", 1, 0, 0 },
588 #ifdef RTE_LIBRTE_LATENCY_STATS
589 { "latencystats", 1, 0, 0 },
591 #ifdef RTE_LIBRTE_BITRATE
592 { "bitrate-stats", 1, 0, 0 },
594 { "disable-crc-strip", 0, 0, 0 },
595 { "enable-lro", 0, 0, 0 },
596 { "enable-rx-cksum", 0, 0, 0 },
597 { "enable-rx-timestamp", 0, 0, 0 },
598 { "enable-scatter", 0, 0, 0 },
599 { "enable-hw-vlan", 0, 0, 0 },
600 { "enable-hw-vlan-filter", 0, 0, 0 },
601 { "enable-hw-vlan-strip", 0, 0, 0 },
602 { "enable-hw-vlan-extend", 0, 0, 0 },
603 { "enable-drop-en", 0, 0, 0 },
604 { "disable-rss", 0, 0, 0 },
605 { "port-topology", 1, 0, 0 },
606 { "forward-mode", 1, 0, 0 },
607 { "rss-ip", 0, 0, 0 },
608 { "rss-udp", 0, 0, 0 },
613 { "burst", 1, 0, 0 },
614 { "mbcache", 1, 0, 0 },
618 { "txfreet", 1, 0, 0 },
619 { "txrst", 1, 0, 0 },
623 { "rxfreet", 1, 0, 0 },
624 { "tx-queue-stats-mapping", 1, 0, 0 },
625 { "rx-queue-stats-mapping", 1, 0, 0 },
626 { "no-flush-rx", 0, 0, 0 },
627 { "flow-isolate-all", 0, 0, 0 },
628 { "txpkts", 1, 0, 0 },
629 { "disable-link-check", 0, 0, 0 },
630 { "no-lsc-interrupt", 0, 0, 0 },
631 { "no-rmv-interrupt", 0, 0, 0 },
632 { "print-event", 1, 0, 0 },
633 { "mask-event", 1, 0, 0 },
634 { "tx-offloads", 1, 0, 0 },
635 { "hot-plug", 0, 0, 0 },
636 { "vxlan-gpe-port", 1, 0, 0 },
637 { "mlockall", 0, 0, 0 },
638 { "no-mlockall", 0, 0, 0 },
639 { "mp-alloc", 1, 0, 0 },
640 { "noisy-tx-sw-buffer-size", 1, 0, 0 },
641 { "noisy-tx-sw-buffer-flushtime", 1, 0, 0 },
642 { "noisy-lkup-memory", 1, 0, 0 },
643 { "noisy-lkup-num-writes", 1, 0, 0 },
644 { "noisy-lkup-num-reads", 1, 0, 0 },
645 { "noisy-lkup-num-reads-writes", 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 strlcpy(cmdline_filename, optarg,
684 sizeof(cmdline_filename));
686 if (!strcmp(lgopts[opt_idx].name, "auto-start")) {
687 printf("Auto-start selected\n");
690 if (!strcmp(lgopts[opt_idx].name, "tx-first")) {
691 printf("Ports to start sending a burst of "
695 if (!strcmp(lgopts[opt_idx].name, "stats-period")) {
699 n = strtoul(optarg, &end, 10);
700 if ((optarg[0] == '\0') || (end == NULL) ||
707 if (!strcmp(lgopts[opt_idx].name,
708 "eth-peers-configfile")) {
709 if (init_peer_eth_addrs(optarg) != 0)
710 rte_exit(EXIT_FAILURE,
711 "Cannot open logfile\n");
713 if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
715 uint8_t c, peer_addr[6];
718 n = strtoul(optarg, &port_end, 10);
719 if (errno != 0 || port_end == optarg || *port_end++ != ',')
720 rte_exit(EXIT_FAILURE,
721 "Invalid eth-peer: %s", optarg);
722 if (n >= RTE_MAX_ETHPORTS)
723 rte_exit(EXIT_FAILURE,
724 "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
725 n, RTE_MAX_ETHPORTS);
727 if (cmdline_parse_etheraddr(NULL, port_end,
728 &peer_addr, sizeof(peer_addr)) < 0)
729 rte_exit(EXIT_FAILURE,
730 "Invalid ethernet address: %s\n",
732 for (c = 0; c < 6; c++)
733 peer_eth_addrs[n].addr_bytes[c] =
738 if (!strcmp(lgopts[opt_idx].name, "nb-ports")) {
740 if (n > 0 && n <= nb_ports)
743 rte_exit(EXIT_FAILURE,
744 "Invalid port %d\n", n);
746 if (!strcmp(lgopts[opt_idx].name, "nb-cores")) {
748 if (n > 0 && n <= nb_lcores)
749 nb_fwd_lcores = (uint8_t) n;
751 rte_exit(EXIT_FAILURE,
752 "nb-cores should be > 0 and <= %d\n",
755 if (!strcmp(lgopts[opt_idx].name, "coremask"))
756 parse_fwd_coremask(optarg);
757 if (!strcmp(lgopts[opt_idx].name, "portmask"))
758 parse_fwd_portmask(optarg);
759 if (!strcmp(lgopts[opt_idx].name, "no-numa"))
761 if (!strcmp(lgopts[opt_idx].name, "numa"))
763 if (!strcmp(lgopts[opt_idx].name, "mp-anon")) {
764 mp_alloc_type = MP_ALLOC_ANON;
766 if (!strcmp(lgopts[opt_idx].name, "mp-alloc")) {
767 if (!strcmp(optarg, "native"))
768 mp_alloc_type = MP_ALLOC_NATIVE;
769 else if (!strcmp(optarg, "anon"))
770 mp_alloc_type = MP_ALLOC_ANON;
771 else if (!strcmp(optarg, "xmem"))
772 mp_alloc_type = MP_ALLOC_XMEM;
773 else if (!strcmp(optarg, "xmemhuge"))
774 mp_alloc_type = MP_ALLOC_XMEM_HUGE;
776 rte_exit(EXIT_FAILURE,
777 "mp-alloc %s invalid - must be: "
778 "native, anon, xmem or xmemhuge\n",
781 if (!strcmp(lgopts[opt_idx].name, "port-numa-config")) {
782 if (parse_portnuma_config(optarg))
783 rte_exit(EXIT_FAILURE,
784 "invalid port-numa configuration\n");
786 if (!strcmp(lgopts[opt_idx].name, "ring-numa-config"))
787 if (parse_ringnuma_config(optarg))
788 rte_exit(EXIT_FAILURE,
789 "invalid ring-numa configuration\n");
790 if (!strcmp(lgopts[opt_idx].name, "socket-num")) {
792 if (!new_socket_id((uint8_t)n)) {
793 socket_num = (uint8_t)n;
795 print_invalid_socket_id_error();
796 rte_exit(EXIT_FAILURE,
797 "Invalid socket id");
800 if (!strcmp(lgopts[opt_idx].name, "mbuf-size")) {
802 if (n > 0 && n <= 0xFFFF)
803 mbuf_data_size = (uint16_t) n;
805 rte_exit(EXIT_FAILURE,
806 "mbuf-size should be > 0 and < 65536\n");
808 if (!strcmp(lgopts[opt_idx].name, "total-num-mbufs")) {
811 param_total_num_mbufs = (unsigned)n;
813 rte_exit(EXIT_FAILURE,
814 "total-num-mbufs should be > 1024\n");
816 if (!strcmp(lgopts[opt_idx].name, "max-pkt-len")) {
818 if (n >= ETHER_MIN_LEN) {
819 rx_mode.max_rx_pkt_len = (uint32_t) n;
820 if (n > ETHER_MAX_LEN)
822 DEV_RX_OFFLOAD_JUMBO_FRAME;
824 rte_exit(EXIT_FAILURE,
825 "Invalid max-pkt-len=%d - should be > %d\n",
828 if (!strcmp(lgopts[opt_idx].name, "pkt-filter-mode")) {
829 if (!strcmp(optarg, "signature"))
831 RTE_FDIR_MODE_SIGNATURE;
832 else if (!strcmp(optarg, "perfect"))
833 fdir_conf.mode = RTE_FDIR_MODE_PERFECT;
834 else if (!strcmp(optarg, "perfect-mac-vlan"))
835 fdir_conf.mode = RTE_FDIR_MODE_PERFECT_MAC_VLAN;
836 else if (!strcmp(optarg, "perfect-tunnel"))
837 fdir_conf.mode = RTE_FDIR_MODE_PERFECT_TUNNEL;
838 else if (!strcmp(optarg, "none"))
839 fdir_conf.mode = RTE_FDIR_MODE_NONE;
841 rte_exit(EXIT_FAILURE,
842 "pkt-mode-invalid %s invalid - must be: "
843 "none, signature, perfect, perfect-mac-vlan"
844 " or perfect-tunnel\n",
847 if (!strcmp(lgopts[opt_idx].name,
848 "pkt-filter-report-hash")) {
849 if (!strcmp(optarg, "none"))
851 RTE_FDIR_NO_REPORT_STATUS;
852 else if (!strcmp(optarg, "match"))
854 RTE_FDIR_REPORT_STATUS;
855 else if (!strcmp(optarg, "always"))
857 RTE_FDIR_REPORT_STATUS_ALWAYS;
859 rte_exit(EXIT_FAILURE,
860 "pkt-filter-report-hash %s invalid "
861 "- must be: none or match or always\n",
864 if (!strcmp(lgopts[opt_idx].name, "pkt-filter-size")) {
865 if (!strcmp(optarg, "64K"))
867 RTE_FDIR_PBALLOC_64K;
868 else if (!strcmp(optarg, "128K"))
870 RTE_FDIR_PBALLOC_128K;
871 else if (!strcmp(optarg, "256K"))
873 RTE_FDIR_PBALLOC_256K;
875 rte_exit(EXIT_FAILURE, "pkt-filter-size %s invalid -"
876 " must be: 64K or 128K or 256K\n",
879 if (!strcmp(lgopts[opt_idx].name,
880 "pkt-filter-drop-queue")) {
883 fdir_conf.drop_queue = (uint8_t) n;
885 rte_exit(EXIT_FAILURE,
886 "drop queue %d invalid - must"
889 #ifdef RTE_LIBRTE_LATENCY_STATS
890 if (!strcmp(lgopts[opt_idx].name,
894 latencystats_lcore_id = (lcoreid_t) n;
895 latencystats_enabled = 1;
897 rte_exit(EXIT_FAILURE,
898 "invalid lcore id %d for latencystats"
899 " must be >= 0\n", n);
902 #ifdef RTE_LIBRTE_BITRATE
903 if (!strcmp(lgopts[opt_idx].name, "bitrate-stats")) {
906 bitrate_lcore_id = (lcoreid_t) n;
909 rte_exit(EXIT_FAILURE,
910 "invalid lcore id %d for bitrate stats"
911 " must be >= 0\n", n);
914 if (!strcmp(lgopts[opt_idx].name, "disable-crc-strip"))
915 rx_offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
916 if (!strcmp(lgopts[opt_idx].name, "enable-lro"))
917 rx_offloads |= DEV_RX_OFFLOAD_TCP_LRO;
918 if (!strcmp(lgopts[opt_idx].name, "enable-scatter"))
919 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
920 if (!strcmp(lgopts[opt_idx].name, "enable-rx-cksum"))
921 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
922 if (!strcmp(lgopts[opt_idx].name,
923 "enable-rx-timestamp"))
924 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
925 if (!strcmp(lgopts[opt_idx].name, "enable-hw-vlan"))
926 rx_offloads |= DEV_RX_OFFLOAD_VLAN;
928 if (!strcmp(lgopts[opt_idx].name,
929 "enable-hw-vlan-filter"))
930 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
932 if (!strcmp(lgopts[opt_idx].name,
933 "enable-hw-vlan-strip"))
934 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
936 if (!strcmp(lgopts[opt_idx].name,
937 "enable-hw-vlan-extend"))
938 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
940 if (!strcmp(lgopts[opt_idx].name, "enable-drop-en"))
943 if (!strcmp(lgopts[opt_idx].name, "disable-rss"))
945 if (!strcmp(lgopts[opt_idx].name, "port-topology")) {
946 if (!strcmp(optarg, "paired"))
947 port_topology = PORT_TOPOLOGY_PAIRED;
948 else if (!strcmp(optarg, "chained"))
949 port_topology = PORT_TOPOLOGY_CHAINED;
950 else if (!strcmp(optarg, "loop"))
951 port_topology = PORT_TOPOLOGY_LOOP;
953 rte_exit(EXIT_FAILURE, "port-topology %s invalid -"
954 " must be: paired, chained or loop\n",
957 if (!strcmp(lgopts[opt_idx].name, "forward-mode"))
958 set_pkt_forwarding_mode(optarg);
959 if (!strcmp(lgopts[opt_idx].name, "rss-ip"))
961 if (!strcmp(lgopts[opt_idx].name, "rss-udp"))
962 rss_hf = ETH_RSS_UDP;
963 if (!strcmp(lgopts[opt_idx].name, "rxq")) {
965 if (n >= 0 && check_nb_rxq((queueid_t)n) == 0)
966 nb_rxq = (queueid_t) n;
968 rte_exit(EXIT_FAILURE, "rxq %d invalid - must be"
969 " >= 0 && <= %u\n", n,
970 get_allowed_max_nb_rxq(&pid));
972 if (!strcmp(lgopts[opt_idx].name, "txq")) {
974 if (n >= 0 && check_nb_txq((queueid_t)n) == 0)
975 nb_txq = (queueid_t) n;
977 rte_exit(EXIT_FAILURE, "txq %d invalid - must be"
978 " >= 0 && <= %u\n", n,
979 get_allowed_max_nb_txq(&pid));
981 if (!nb_rxq && !nb_txq) {
982 rte_exit(EXIT_FAILURE, "Either rx or tx queues should "
985 if (!strcmp(lgopts[opt_idx].name, "burst")) {
988 /* A burst size of zero means that the
989 * PMD should be queried for
990 * recommended Rx burst size. Since
991 * testpmd uses a single size for all
992 * ports, port 0 is queried for the
993 * value, on the assumption that all
994 * ports are of the same NIC model.
996 rte_eth_dev_info_get(0, &dev_info);
997 rec_nb_pkts = dev_info
998 .default_rxportconf.burst_size;
1000 if (rec_nb_pkts == 0)
1001 rte_exit(EXIT_FAILURE,
1002 "PMD does not recommend a burst size. "
1003 "Provided value must be between "
1004 "1 and %d\n", MAX_PKT_BURST);
1005 else if (rec_nb_pkts > MAX_PKT_BURST)
1006 rte_exit(EXIT_FAILURE,
1007 "PMD recommended burst size of %d"
1008 " exceeds maximum value of %d\n",
1009 rec_nb_pkts, MAX_PKT_BURST);
1010 printf("Using PMD-provided burst value of %d\n",
1012 nb_pkt_per_burst = rec_nb_pkts;
1013 } else if (n > MAX_PKT_BURST)
1014 rte_exit(EXIT_FAILURE,
1015 "burst must be between1 and %d\n",
1018 nb_pkt_per_burst = (uint16_t) n;
1020 if (!strcmp(lgopts[opt_idx].name, "mbcache")) {
1023 (n <= RTE_MEMPOOL_CACHE_MAX_SIZE))
1024 mb_mempool_cache = (uint16_t) n;
1026 rte_exit(EXIT_FAILURE,
1027 "mbcache must be >= 0 and <= %d\n",
1028 RTE_MEMPOOL_CACHE_MAX_SIZE);
1030 if (!strcmp(lgopts[opt_idx].name, "txfreet")) {
1033 tx_free_thresh = (int16_t)n;
1035 rte_exit(EXIT_FAILURE, "txfreet must be >= 0\n");
1037 if (!strcmp(lgopts[opt_idx].name, "txrst")) {
1040 tx_rs_thresh = (int16_t)n;
1042 rte_exit(EXIT_FAILURE, "txrst must be >= 0\n");
1044 if (!strcmp(lgopts[opt_idx].name, "rxd")) {
1047 if (rx_free_thresh >= n)
1048 rte_exit(EXIT_FAILURE,
1050 "rx_free_thresh(%d)\n",
1051 (int)rx_free_thresh);
1053 nb_rxd = (uint16_t) n;
1055 rte_exit(EXIT_FAILURE,
1056 "rxd(%d) invalid - must be > 0\n",
1059 if (!strcmp(lgopts[opt_idx].name, "txd")) {
1062 nb_txd = (uint16_t) n;
1064 rte_exit(EXIT_FAILURE, "txd must be in > 0\n");
1066 if (!strcmp(lgopts[opt_idx].name, "txpt")) {
1069 tx_pthresh = (int8_t)n;
1071 rte_exit(EXIT_FAILURE, "txpt must be >= 0\n");
1073 if (!strcmp(lgopts[opt_idx].name, "txht")) {
1076 tx_hthresh = (int8_t)n;
1078 rte_exit(EXIT_FAILURE, "txht must be >= 0\n");
1080 if (!strcmp(lgopts[opt_idx].name, "txwt")) {
1083 tx_wthresh = (int8_t)n;
1085 rte_exit(EXIT_FAILURE, "txwt must be >= 0\n");
1087 if (!strcmp(lgopts[opt_idx].name, "rxpt")) {
1090 rx_pthresh = (int8_t)n;
1092 rte_exit(EXIT_FAILURE, "rxpt must be >= 0\n");
1094 if (!strcmp(lgopts[opt_idx].name, "rxht")) {
1097 rx_hthresh = (int8_t)n;
1099 rte_exit(EXIT_FAILURE, "rxht must be >= 0\n");
1101 if (!strcmp(lgopts[opt_idx].name, "rxwt")) {
1104 rx_wthresh = (int8_t)n;
1106 rte_exit(EXIT_FAILURE, "rxwt must be >= 0\n");
1108 if (!strcmp(lgopts[opt_idx].name, "rxfreet")) {
1111 rx_free_thresh = (int16_t)n;
1113 rte_exit(EXIT_FAILURE, "rxfreet must be >= 0\n");
1115 if (!strcmp(lgopts[opt_idx].name, "tx-queue-stats-mapping")) {
1116 if (parse_queue_stats_mapping_config(optarg, TX)) {
1117 rte_exit(EXIT_FAILURE,
1118 "invalid TX queue statistics mapping config entered\n");
1121 if (!strcmp(lgopts[opt_idx].name, "rx-queue-stats-mapping")) {
1122 if (parse_queue_stats_mapping_config(optarg, RX)) {
1123 rte_exit(EXIT_FAILURE,
1124 "invalid RX queue statistics mapping config entered\n");
1127 if (!strcmp(lgopts[opt_idx].name, "txpkts")) {
1128 unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
1129 unsigned int nb_segs;
1131 nb_segs = parse_item_list(optarg, "txpkt segments",
1132 RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
1134 set_tx_pkt_segments(seg_lengths, nb_segs);
1136 rte_exit(EXIT_FAILURE, "bad txpkts\n");
1138 if (!strcmp(lgopts[opt_idx].name, "no-flush-rx"))
1140 if (!strcmp(lgopts[opt_idx].name, "disable-link-check"))
1142 if (!strcmp(lgopts[opt_idx].name, "no-lsc-interrupt"))
1144 if (!strcmp(lgopts[opt_idx].name, "no-rmv-interrupt"))
1146 if (!strcmp(lgopts[opt_idx].name, "flow-isolate-all"))
1147 flow_isolate_all = 1;
1148 if (!strcmp(lgopts[opt_idx].name, "tx-offloads")) {
1150 n = strtoull(optarg, &end, 16);
1152 tx_offloads = (uint64_t)n;
1154 rte_exit(EXIT_FAILURE,
1155 "tx-offloads must be >= 0\n");
1157 if (!strcmp(lgopts[opt_idx].name, "vxlan-gpe-port")) {
1160 vxlan_gpe_udp_port = (uint16_t)n;
1162 rte_exit(EXIT_FAILURE,
1163 "vxlan-gpe-port must be >= 0\n");
1165 if (!strcmp(lgopts[opt_idx].name, "print-event"))
1166 if (parse_event_printing_config(optarg, 1)) {
1167 rte_exit(EXIT_FAILURE,
1168 "invalid print-event argument\n");
1170 if (!strcmp(lgopts[opt_idx].name, "mask-event"))
1171 if (parse_event_printing_config(optarg, 0)) {
1172 rte_exit(EXIT_FAILURE,
1173 "invalid mask-event argument\n");
1175 if (!strcmp(lgopts[opt_idx].name, "hot-plug"))
1177 if (!strcmp(lgopts[opt_idx].name, "mlockall"))
1179 if (!strcmp(lgopts[opt_idx].name, "no-mlockall"))
1181 if (!strcmp(lgopts[opt_idx].name,
1182 "noisy-tx-sw-buffer-size")) {
1185 noisy_tx_sw_bufsz = n;
1187 rte_exit(EXIT_FAILURE,
1188 "noisy-tx-sw-buffer-size must be >= 0\n");
1190 if (!strcmp(lgopts[opt_idx].name,
1191 "noisy-tx-sw-buffer-flushtime")) {
1194 noisy_tx_sw_buf_flush_time = n;
1196 rte_exit(EXIT_FAILURE,
1197 "noisy-tx-sw-buffer-flushtime must be >= 0\n");
1199 if (!strcmp(lgopts[opt_idx].name,
1200 "noisy-lkup-memory")) {
1203 noisy_lkup_mem_sz = n;
1205 rte_exit(EXIT_FAILURE,
1206 "noisy-lkup-memory must be >= 0\n");
1208 if (!strcmp(lgopts[opt_idx].name,
1209 "noisy-lkup-num-writes")) {
1212 noisy_lkup_num_writes = n;
1214 rte_exit(EXIT_FAILURE,
1215 "noisy-lkup-num-writes must be >= 0\n");
1217 if (!strcmp(lgopts[opt_idx].name,
1218 "noisy-lkup-num-reads")) {
1221 noisy_lkup_num_reads = n;
1223 rte_exit(EXIT_FAILURE,
1224 "noisy-lkup-num-reads must be >= 0\n");
1226 if (!strcmp(lgopts[opt_idx].name,
1227 "noisy-lkup-num-reads-writes")) {
1230 noisy_lkup_num_reads_writes = n;
1232 rte_exit(EXIT_FAILURE,
1233 "noisy-lkup-num-reads-writes must be >= 0\n");
1238 rte_exit(EXIT_SUCCESS, "Displayed help\n");
1242 rte_exit(EXIT_FAILURE,
1243 "Command line is incomplete or incorrect\n");
1248 /* Set offload configuration from command line parameters. */
1249 rx_mode.offloads = rx_offloads;
1250 tx_mode.offloads = tx_offloads;