app/testpmd: add option for number of flows in flowgen
[dpdk.git] / app / test-pmd / parameters.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2017 Intel Corporation
3  */
4
5 #include <errno.h>
6 #include <getopt.h>
7 #include <stdarg.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <signal.h>
11 #include <string.h>
12 #include <time.h>
13 #include <fcntl.h>
14 #include <sys/types.h>
15
16 #include <sys/queue.h>
17 #include <sys/stat.h>
18
19 #include <stdint.h>
20 #include <unistd.h>
21 #include <inttypes.h>
22
23 #include <rte_common.h>
24 #include <rte_byteorder.h>
25 #include <rte_log.h>
26 #include <rte_debug.h>
27 #include <rte_cycles.h>
28 #include <rte_memory.h>
29 #include <rte_launch.h>
30 #include <rte_eal.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>
37 #include <rte_pci.h>
38 #include <rte_ether.h>
39 #include <rte_ethdev.h>
40 #include <rte_string_fns.h>
41 #ifdef RTE_NET_BOND
42 #include <rte_eth_bond.h>
43 #endif
44 #include <rte_flow.h>
45
46 #include "testpmd.h"
47
48 static void
49 usage(char* progname)
50 {
51         printf("\nUsage: %s [EAL options] -- [testpmd options]\n\n",
52                progname);
53 #ifdef RTE_LIB_CMDLINE
54         printf("  --interactive: run in interactive mode.\n");
55         printf("  --cmdline-file: execute cli commands before startup.\n");
56 #endif
57         printf("  --auto-start: start forwarding on init "
58                "[always when non-interactive].\n");
59         printf("  --help: display this message and quit.\n");
60         printf("  --tx-first: start forwarding sending a burst first "
61                "(only if interactive is disabled).\n");
62         printf("  --stats-period=PERIOD: statistics will be shown "
63                "every PERIOD seconds (only if interactive is disabled).\n");
64         printf("  --nb-cores=N: set the number of forwarding cores "
65                "(1 <= N <= %d).\n", nb_lcores);
66         printf("  --nb-ports=N: set the number of forwarding ports "
67                "(1 <= N <= %d).\n", nb_ports);
68         printf("  --coremask=COREMASK: hexadecimal bitmask of cores running "
69                "the packet forwarding test. The main lcore is reserved for "
70                "command line parsing only, and cannot be masked on for "
71                "packet forwarding.\n");
72         printf("  --portmask=PORTMASK: hexadecimal bitmask of ports used "
73                "by the packet forwarding test.\n");
74         printf("  --portlist=PORTLIST: list of forwarding ports\n");
75         printf("  --numa: enable NUMA-aware allocation of RX/TX rings and of "
76                "RX memory buffers (mbufs).\n");
77         printf("  --no-numa: disable NUMA-aware allocation.\n");
78         printf("  --port-numa-config=(port,socket)[,(port,socket)]: "
79                "specify the socket on which the memory pool "
80                "used by the port will be allocated.\n");
81         printf("  --ring-numa-config=(port,flag,socket)[,(port,flag,socket)]: "
82                "specify the socket on which the TX/RX rings for "
83                "the port will be allocated "
84                "(flag: 1 for RX; 2 for TX; 3 for RX and TX).\n");
85         printf("  --socket-num=N: set socket from which all memory is allocated "
86                "in NUMA mode.\n");
87         printf("  --mbuf-size=N,[N1[,..Nn]: set the data size of mbuf to "
88                "N bytes. If multiple numbers are specified the extra pools "
89                "will be created to receive with packet split features\n");
90         printf("  --total-num-mbufs=N: set the number of mbufs to be allocated "
91                "in mbuf pools.\n");
92         printf("  --max-pkt-len=N: set the maximum size of packet to N bytes.\n");
93         printf("  --max-lro-pkt-size=N: set the maximum LRO aggregated packet "
94                "size to N bytes.\n");
95 #ifdef RTE_LIB_CMDLINE
96         printf("  --eth-peers-configfile=name: config file with ethernet addresses "
97                "of peer ports.\n");
98         printf("  --eth-peer=X,M:M:M:M:M:M: set the MAC address of the X peer "
99                "port (0 <= X < %d).\n", RTE_MAX_ETHPORTS);
100 #endif
101         printf("  --pkt-filter-mode=N: set Flow Director mode "
102                "(N: none (default mode) or signature or perfect).\n");
103         printf("  --pkt-filter-report-hash=N: set Flow Director report mode "
104                "(N: none  or match (default) or always).\n");
105         printf("  --pkt-filter-size=N: set Flow Director mode "
106                "(N: 64K (default mode) or 128K or 256K).\n");
107         printf("  --pkt-filter-drop-queue=N: set drop-queue. "
108                "In perfect mode, when you add a rule with queue = -1 "
109                "the packet will be enqueued into the rx drop-queue. "
110                "If the drop-queue doesn't exist, the packet is dropped. "
111                "By default drop-queue=127.\n");
112 #ifdef RTE_LIB_LATENCYSTATS
113         printf("  --latencystats=N: enable latency and jitter statistcs "
114                "monitoring on forwarding lcore id N.\n");
115 #endif
116         printf("  --disable-crc-strip: disable CRC stripping by hardware.\n");
117         printf("  --enable-scatter: enable scattered Rx.\n");
118         printf("  --enable-lro: enable large receive offload.\n");
119         printf("  --enable-rx-cksum: enable rx hardware checksum offload.\n");
120         printf("  --enable-rx-timestamp: enable rx hardware timestamp offload.\n");
121         printf("  --enable-hw-vlan: enable hardware vlan.\n");
122         printf("  --enable-hw-vlan-filter: enable hardware vlan filter.\n");
123         printf("  --enable-hw-vlan-strip: enable hardware vlan strip.\n");
124         printf("  --enable-hw-vlan-extend: enable hardware vlan extend.\n");
125         printf("  --enable-hw-qinq-strip: enable hardware qinq strip.\n");
126         printf("  --enable-drop-en: enable per queue packet drop.\n");
127         printf("  --disable-rss: disable rss.\n");
128         printf("  --port-topology=<paired|chained|loop>: set port topology (paired "
129                "is default).\n");
130         printf("  --forward-mode=N: set forwarding mode (N: %s).\n",
131                list_pkt_forwarding_modes());
132         printf("  --forward-mode=5tswap: set forwarding mode to "
133                         "swap L2,L3,L4 for MAC, IPv4/IPv6 and TCP/UDP only.\n");
134         printf("  --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
135         printf("  --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
136         printf("  --rss-level-inner: set RSS hash level to innermost\n");
137         printf("  --rss-level-outer: set RSS hash level to outermost\n");
138         printf("  --rxq=N: set the number of RX queues per port to N.\n");
139         printf("  --rxd=N: set the number of descriptors in RX rings to N.\n");
140         printf("  --txq=N: set the number of TX queues per port to N.\n");
141         printf("  --txd=N: set the number of descriptors in TX rings to N.\n");
142         printf("  --hairpinq=N: set the number of hairpin queues per port to "
143                "N.\n");
144         printf("  --burst=N: set the number of packets per burst to N.\n");
145         printf("  --flowgen-clones=N: set the number of single packet clones to send in flowgen mode. Should be less than burst value.\n");
146         printf("  --flowgen-flows=N: set the number of flows in flowgen mode to N (1 <= N <= INT32_MAX).\n");
147         printf("  --mbcache=N: set the cache of mbuf memory pool to N.\n");
148         printf("  --rxpt=N: set prefetch threshold register of RX rings to N.\n");
149         printf("  --rxht=N: set the host threshold register of RX rings to N.\n");
150         printf("  --rxfreet=N: set the free threshold of RX descriptors to N "
151                "(0 <= N < value of rxd).\n");
152         printf("  --rxwt=N: set the write-back threshold register of RX rings to N.\n");
153         printf("  --txpt=N: set the prefetch threshold register of TX rings to N.\n");
154         printf("  --txht=N: set the nhost threshold register of TX rings to N.\n");
155         printf("  --txwt=N: set the write-back threshold register of TX rings to N.\n");
156         printf("  --txfreet=N: set the transmit free threshold of TX rings to N "
157                "(0 <= N <= value of txd).\n");
158         printf("  --txrst=N: set the transmit RS bit threshold of TX rings to N "
159                "(0 <= N <= value of txd).\n");
160         printf("  --no-flush-rx: Don't flush RX streams before forwarding."
161                " Used mainly with PCAP drivers.\n");
162         printf("  --rxoffs=X[,Y]*: set RX segment offsets for split.\n");
163         printf("  --rxpkts=X[,Y]*: set RX segment sizes to split.\n");
164         printf("  --txpkts=X[,Y]*: set TX segment sizes"
165                 " or total packet length.\n");
166         printf("  --txonly-multi-flow: generate multiple flows in txonly mode\n");
167         printf("  --tx-ip=src,dst: IP addresses in Tx-only mode\n");
168         printf("  --tx-udp=src[,dst]: UDP ports in Tx-only mode\n");
169         printf("  --eth-link-speed: force link speed.\n");
170         printf("  --disable-link-check: disable check on link status when "
171                "starting/stopping ports.\n");
172         printf("  --disable-device-start: do not automatically start port\n");
173         printf("  --no-lsc-interrupt: disable link status change interrupt.\n");
174         printf("  --no-rmv-interrupt: disable device removal interrupt.\n");
175         printf("  --bitrate-stats=N: set the logical core N to perform "
176                 "bit-rate calculation.\n");
177         printf("  --print-event <unknown|intr_lsc|queue_state|intr_reset|vf_mbox|macsec|intr_rmv|flow_aged|all>: "
178                "enable print of designated event or all of them.\n");
179         printf("  --mask-event <unknown|intr_lsc|queue_state|intr_reset|vf_mbox|macsec|intr_rmv|flow_aged|all>: "
180                "disable print of designated event or all of them.\n");
181         printf("  --flow-isolate-all: "
182                "requests flow API isolated mode on all ports at initialization time.\n");
183         printf("  --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n");
184         printf("  --rx-offloads=0xXXXXXXXX: hexadecimal bitmask of RX queue offloads\n");
185         printf("  --hot-plug: enable hot plug for device.\n");
186         printf("  --vxlan-gpe-port=N: UPD port of tunnel VXLAN-GPE\n");
187         printf("  --geneve-parsed-port=N: UPD port to parse GENEVE tunnel protocol\n");
188 #ifndef RTE_EXEC_ENV_WINDOWS
189         printf("  --mlockall: lock all memory\n");
190         printf("  --no-mlockall: do not lock all memory\n");
191 #endif
192         printf("  --mp-alloc <native|anon|xmem|xmemhuge>: mempool allocation method.\n"
193                "    native: use regular DPDK memory to create and populate mempool\n"
194                "    anon: use regular DPDK memory to create and anonymous memory to populate mempool\n"
195                "    xmem: use anonymous memory to create and populate mempool\n"
196                "    xmemhuge: use anonymous hugepage memory to create and populate mempool\n");
197         printf("  --noisy-tx-sw-buffer-size=N: size of FIFO buffer\n");
198         printf("  --noisy-tx-sw-buffer-flushtime=N: flush FIFO after N ms\n");
199         printf("  --noisy-lkup-memory=N: allocate N MB of VNF memory\n");
200         printf("  --noisy-lkup-num-writes=N: do N random writes per packet\n");
201         printf("  --noisy-lkup-num-reads=N: do N random reads per packet\n");
202         printf("  --noisy-lkup-num-reads-writes=N: do N random reads and writes per packet\n");
203         printf("  --no-iova-contig: mempool memory can be IOVA non contiguous. "
204                "valid only with --mp-alloc=anon\n");
205         printf("  --rx-mq-mode=0xX: hexadecimal bitmask of RX mq mode can be "
206                "enabled\n");
207         printf("  --record-core-cycles: enable measurement of CPU cycles.\n");
208         printf("  --record-burst-stats: enable display of RX and TX bursts.\n");
209         printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n"
210                "    0x10 - explicit Tx rule, 0x02 - hairpin ports paired\n"
211                "    0x01 - hairpin ports loop, 0x00 - hairpin port self\n");
212 }
213
214 #ifdef RTE_LIB_CMDLINE
215 static int
216 init_peer_eth_addrs(const char *config_filename)
217 {
218         FILE *config_file;
219         portid_t i;
220         char buf[50];
221
222         config_file = fopen(config_filename, "r");
223         if (config_file == NULL) {
224                 perror("Failed to open eth config file\n");
225                 return -1;
226         }
227
228         for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
229
230                 if (fgets(buf, sizeof(buf), config_file) == NULL)
231                         break;
232
233                 if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) {
234                         fprintf(stderr, "Bad MAC address format on line %d\n",
235                                 i + 1);
236                         fclose(config_file);
237                         return -1;
238                 }
239         }
240         fclose(config_file);
241         nb_peer_eth_addrs = (portid_t) i;
242         return 0;
243 }
244 #endif
245
246 /*
247  * Parse the coremask given as argument (hexadecimal string) and set
248  * the global configuration of forwarding cores.
249  */
250 static void
251 parse_fwd_coremask(const char *coremask)
252 {
253         char *end;
254         unsigned long long int cm;
255
256         /* parse hexadecimal string */
257         end = NULL;
258         cm = strtoull(coremask, &end, 16);
259         if ((coremask[0] == '\0') || (end == NULL) || (*end != '\0'))
260                 rte_exit(EXIT_FAILURE, "Invalid fwd core mask\n");
261         else if (set_fwd_lcores_mask((uint64_t) cm) < 0)
262                 rte_exit(EXIT_FAILURE, "coremask is not valid\n");
263 }
264
265 /*
266  * Parse the coremask given as argument (hexadecimal string) and set
267  * the global configuration of forwarding cores.
268  */
269 static void
270 parse_fwd_portmask(const char *portmask)
271 {
272         char *end;
273         unsigned long long int pm;
274
275         /* parse hexadecimal string */
276         end = NULL;
277         pm = strtoull(portmask, &end, 16);
278         if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
279                 rte_exit(EXIT_FAILURE, "Invalid fwd port mask\n");
280         else
281                 set_fwd_ports_mask((uint64_t) pm);
282 }
283
284 static void
285 print_invalid_socket_id_error(void)
286 {
287         unsigned int i = 0;
288
289         fprintf(stderr, "Invalid socket id, options are: ");
290         for (i = 0; i < num_sockets; i++) {
291                 fprintf(stderr, "%u%s", socket_ids[i],
292                         (i == num_sockets - 1) ? "\n" : ",");
293         }
294 }
295
296 static int
297 parse_portnuma_config(const char *q_arg)
298 {
299         char s[256];
300         const char *p, *p0 = q_arg;
301         char *end;
302         uint8_t i, socket_id;
303         portid_t port_id;
304         unsigned size;
305         enum fieldnames {
306                 FLD_PORT = 0,
307                 FLD_SOCKET,
308                 _NUM_FLD
309         };
310         unsigned long int_fld[_NUM_FLD];
311         char *str_fld[_NUM_FLD];
312
313         /* reset from value set at definition */
314         while ((p = strchr(p0,'(')) != NULL) {
315                 ++p;
316                 if((p0 = strchr(p,')')) == NULL)
317                         return -1;
318
319                 size = p0 - p;
320                 if(size >= sizeof(s))
321                         return -1;
322
323                 snprintf(s, sizeof(s), "%.*s", size, p);
324                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
325                         return -1;
326                 for (i = 0; i < _NUM_FLD; i++) {
327                         errno = 0;
328                         int_fld[i] = strtoul(str_fld[i], &end, 0);
329                         if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
330                                 return -1;
331                 }
332                 port_id = (portid_t)int_fld[FLD_PORT];
333                 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
334                         port_id == (portid_t)RTE_PORT_ALL) {
335                         print_valid_ports();
336                         return -1;
337                 }
338                 socket_id = (uint8_t)int_fld[FLD_SOCKET];
339                 if (new_socket_id(socket_id)) {
340                         if (num_sockets >= RTE_MAX_NUMA_NODES) {
341                                 print_invalid_socket_id_error();
342                                 return -1;
343                         }
344                         socket_ids[num_sockets++] = socket_id;
345                 }
346                 port_numa[port_id] = socket_id;
347         }
348
349         return 0;
350 }
351
352 static int
353 parse_ringnuma_config(const char *q_arg)
354 {
355         char s[256];
356         const char *p, *p0 = q_arg;
357         char *end;
358         uint8_t i, ring_flag, socket_id;
359         portid_t port_id;
360         unsigned size;
361         enum fieldnames {
362                 FLD_PORT = 0,
363                 FLD_FLAG,
364                 FLD_SOCKET,
365                 _NUM_FLD
366         };
367         unsigned long int_fld[_NUM_FLD];
368         char *str_fld[_NUM_FLD];
369         #define RX_RING_ONLY 0x1
370         #define TX_RING_ONLY 0x2
371         #define RXTX_RING    0x3
372
373         /* reset from value set at definition */
374         while ((p = strchr(p0,'(')) != NULL) {
375                 ++p;
376                 if((p0 = strchr(p,')')) == NULL)
377                         return -1;
378
379                 size = p0 - p;
380                 if(size >= sizeof(s))
381                         return -1;
382
383                 snprintf(s, sizeof(s), "%.*s", size, p);
384                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
385                         return -1;
386                 for (i = 0; i < _NUM_FLD; i++) {
387                         errno = 0;
388                         int_fld[i] = strtoul(str_fld[i], &end, 0);
389                         if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
390                                 return -1;
391                 }
392                 port_id = (portid_t)int_fld[FLD_PORT];
393                 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
394                         port_id == (portid_t)RTE_PORT_ALL) {
395                         print_valid_ports();
396                         return -1;
397                 }
398                 socket_id = (uint8_t)int_fld[FLD_SOCKET];
399                 if (new_socket_id(socket_id)) {
400                         if (num_sockets >= RTE_MAX_NUMA_NODES) {
401                                 print_invalid_socket_id_error();
402                                 return -1;
403                         }
404                         socket_ids[num_sockets++] = socket_id;
405                 }
406                 ring_flag = (uint8_t)int_fld[FLD_FLAG];
407                 if ((ring_flag < RX_RING_ONLY) || (ring_flag > RXTX_RING)) {
408                         fprintf(stderr,
409                                 "Invalid ring-flag=%d config for port =%d\n",
410                                 ring_flag,port_id);
411                         return -1;
412                 }
413
414                 switch (ring_flag & RXTX_RING) {
415                 case RX_RING_ONLY:
416                         rxring_numa[port_id] = socket_id;
417                         break;
418                 case TX_RING_ONLY:
419                         txring_numa[port_id] = socket_id;
420                         break;
421                 case RXTX_RING:
422                         rxring_numa[port_id] = socket_id;
423                         txring_numa[port_id] = socket_id;
424                         break;
425                 default:
426                         fprintf(stderr,
427                                 "Invalid ring-flag=%d config for port=%d\n",
428                                 ring_flag,port_id);
429                         break;
430                 }
431         }
432
433         return 0;
434 }
435
436 static int
437 parse_event_printing_config(const char *optarg, int enable)
438 {
439         uint32_t mask = 0;
440
441         if (!strcmp(optarg, "unknown"))
442                 mask = UINT32_C(1) << RTE_ETH_EVENT_UNKNOWN;
443         else if (!strcmp(optarg, "intr_lsc"))
444                 mask = UINT32_C(1) << RTE_ETH_EVENT_INTR_LSC;
445         else if (!strcmp(optarg, "queue_state"))
446                 mask = UINT32_C(1) << RTE_ETH_EVENT_QUEUE_STATE;
447         else if (!strcmp(optarg, "intr_reset"))
448                 mask = UINT32_C(1) << RTE_ETH_EVENT_INTR_RESET;
449         else if (!strcmp(optarg, "vf_mbox"))
450                 mask = UINT32_C(1) << RTE_ETH_EVENT_VF_MBOX;
451         else if (!strcmp(optarg, "ipsec"))
452                 mask = UINT32_C(1) << RTE_ETH_EVENT_IPSEC;
453         else if (!strcmp(optarg, "macsec"))
454                 mask = UINT32_C(1) << RTE_ETH_EVENT_MACSEC;
455         else if (!strcmp(optarg, "intr_rmv"))
456                 mask = UINT32_C(1) << RTE_ETH_EVENT_INTR_RMV;
457         else if (!strcmp(optarg, "dev_probed"))
458                 mask = UINT32_C(1) << RTE_ETH_EVENT_NEW;
459         else if (!strcmp(optarg, "dev_released"))
460                 mask = UINT32_C(1) << RTE_ETH_EVENT_DESTROY;
461         else if (!strcmp(optarg, "flow_aged"))
462                 mask = UINT32_C(1) << RTE_ETH_EVENT_FLOW_AGED;
463         else if (!strcmp(optarg, "all"))
464                 mask = ~UINT32_C(0);
465         else {
466                 fprintf(stderr, "Invalid event: %s\n", optarg);
467                 return -1;
468         }
469         if (enable)
470                 event_print_mask |= mask;
471         else
472                 event_print_mask &= ~mask;
473         return 0;
474 }
475
476 static int
477 parse_link_speed(int n)
478 {
479         uint32_t speed = ETH_LINK_SPEED_FIXED;
480
481         switch (n) {
482         case 1000:
483                 speed |= ETH_LINK_SPEED_1G;
484                 break;
485         case 10000:
486                 speed |= ETH_LINK_SPEED_10G;
487                 break;
488         case 25000:
489                 speed |= ETH_LINK_SPEED_25G;
490                 break;
491         case 40000:
492                 speed |= ETH_LINK_SPEED_40G;
493                 break;
494         case 50000:
495                 speed |= ETH_LINK_SPEED_50G;
496                 break;
497         case 100000:
498                 speed |= ETH_LINK_SPEED_100G;
499                 break;
500         case 200000:
501                 speed |= ETH_LINK_SPEED_200G;
502                 break;
503         case 100:
504         case 10:
505         default:
506                 fprintf(stderr, "Unsupported fixed speed\n");
507                 return 0;
508         }
509
510         return speed;
511 }
512
513 void
514 launch_args_parse(int argc, char** argv)
515 {
516         int n, opt;
517         char **argvopt;
518         int opt_idx;
519         portid_t pid;
520         enum { TX, RX };
521         /* Default offloads for all ports. */
522         uint64_t rx_offloads = rx_mode.offloads;
523         uint64_t tx_offloads = tx_mode.offloads;
524         struct rte_eth_dev_info dev_info;
525         uint16_t rec_nb_pkts;
526         int ret;
527
528         static struct option lgopts[] = {
529                 { "help",                       0, 0, 0 },
530 #ifdef RTE_LIB_CMDLINE
531                 { "interactive",                0, 0, 0 },
532                 { "cmdline-file",               1, 0, 0 },
533                 { "auto-start",                 0, 0, 0 },
534                 { "eth-peers-configfile",       1, 0, 0 },
535                 { "eth-peer",                   1, 0, 0 },
536 #endif
537                 { "tx-first",                   0, 0, 0 },
538                 { "stats-period",               1, 0, 0 },
539                 { "nb-cores",                   1, 0, 0 },
540                 { "nb-ports",                   1, 0, 0 },
541                 { "coremask",                   1, 0, 0 },
542                 { "portmask",                   1, 0, 0 },
543                 { "portlist",                   1, 0, 0 },
544                 { "numa",                       0, 0, 0 },
545                 { "no-numa",                    0, 0, 0 },
546                 { "mp-anon",                    0, 0, 0 }, /* deprecated */
547                 { "port-numa-config",           1, 0, 0 },
548                 { "ring-numa-config",           1, 0, 0 },
549                 { "socket-num",                 1, 0, 0 },
550                 { "mbuf-size",                  1, 0, 0 },
551                 { "total-num-mbufs",            1, 0, 0 },
552                 { "max-pkt-len",                1, 0, 0 },
553                 { "max-lro-pkt-size",           1, 0, 0 },
554                 { "pkt-filter-mode",            1, 0, 0 },
555                 { "pkt-filter-report-hash",     1, 0, 0 },
556                 { "pkt-filter-size",            1, 0, 0 },
557                 { "pkt-filter-drop-queue",      1, 0, 0 },
558 #ifdef RTE_LIB_LATENCYSTATS
559                 { "latencystats",               1, 0, 0 },
560 #endif
561 #ifdef RTE_LIB_BITRATESTATS
562                 { "bitrate-stats",              1, 0, 0 },
563 #endif
564                 { "disable-crc-strip",          0, 0, 0 },
565                 { "enable-lro",                 0, 0, 0 },
566                 { "enable-rx-cksum",            0, 0, 0 },
567                 { "enable-rx-timestamp",        0, 0, 0 },
568                 { "enable-scatter",             0, 0, 0 },
569                 { "enable-hw-vlan",             0, 0, 0 },
570                 { "enable-hw-vlan-filter",      0, 0, 0 },
571                 { "enable-hw-vlan-strip",       0, 0, 0 },
572                 { "enable-hw-vlan-extend",      0, 0, 0 },
573                 { "enable-hw-qinq-strip",       0, 0, 0 },
574                 { "enable-drop-en",            0, 0, 0 },
575                 { "disable-rss",                0, 0, 0 },
576                 { "port-topology",              1, 0, 0 },
577                 { "forward-mode",               1, 0, 0 },
578                 { "rss-ip",                     0, 0, 0 },
579                 { "rss-udp",                    0, 0, 0 },
580                 { "rss-level-outer",            0, 0, 0 },
581                 { "rss-level-inner",            0, 0, 0 },
582                 { "rxq",                        1, 0, 0 },
583                 { "txq",                        1, 0, 0 },
584                 { "rxd",                        1, 0, 0 },
585                 { "txd",                        1, 0, 0 },
586                 { "hairpinq",                   1, 0, 0 },
587                 { "hairpin-mode",               1, 0, 0 },
588                 { "burst",                      1, 0, 0 },
589                 { "flowgen-clones",             1, 0, 0 },
590                 { "flowgen-flows",              1, 0, 0 },
591                 { "mbcache",                    1, 0, 0 },
592                 { "txpt",                       1, 0, 0 },
593                 { "txht",                       1, 0, 0 },
594                 { "txwt",                       1, 0, 0 },
595                 { "txfreet",                    1, 0, 0 },
596                 { "txrst",                      1, 0, 0 },
597                 { "rxpt",                       1, 0, 0 },
598                 { "rxht",                       1, 0, 0 },
599                 { "rxwt",                       1, 0, 0 },
600                 { "rxfreet",                    1, 0, 0 },
601                 { "no-flush-rx",        0, 0, 0 },
602                 { "flow-isolate-all",           0, 0, 0 },
603                 { "rxoffs",                     1, 0, 0 },
604                 { "rxpkts",                     1, 0, 0 },
605                 { "txpkts",                     1, 0, 0 },
606                 { "txonly-multi-flow",          0, 0, 0 },
607                 { "eth-link-speed",             1, 0, 0 },
608                 { "disable-link-check",         0, 0, 0 },
609                 { "disable-device-start",       0, 0, 0 },
610                 { "no-lsc-interrupt",           0, 0, 0 },
611                 { "no-rmv-interrupt",           0, 0, 0 },
612                 { "print-event",                1, 0, 0 },
613                 { "mask-event",                 1, 0, 0 },
614                 { "tx-offloads",                1, 0, 0 },
615                 { "rx-offloads",                1, 0, 0 },
616                 { "hot-plug",                   0, 0, 0 },
617                 { "vxlan-gpe-port",             1, 0, 0 },
618                 { "geneve-parsed-port",         1, 0, 0 },
619 #ifndef RTE_EXEC_ENV_WINDOWS
620                 { "mlockall",                   0, 0, 0 },
621                 { "no-mlockall",                0, 0, 0 },
622 #endif
623                 { "mp-alloc",                   1, 0, 0 },
624                 { "tx-ip",                      1, 0, 0 },
625                 { "tx-udp",                     1, 0, 0 },
626                 { "noisy-tx-sw-buffer-size",    1, 0, 0 },
627                 { "noisy-tx-sw-buffer-flushtime", 1, 0, 0 },
628                 { "noisy-lkup-memory",          1, 0, 0 },
629                 { "noisy-lkup-num-writes",      1, 0, 0 },
630                 { "noisy-lkup-num-reads",       1, 0, 0 },
631                 { "noisy-lkup-num-reads-writes", 1, 0, 0 },
632                 { "no-iova-contig",             0, 0, 0 },
633                 { "rx-mq-mode",                 1, 0, 0 },
634                 { "record-core-cycles",         0, 0, 0 },
635                 { "record-burst-stats",         0, 0, 0 },
636                 { 0, 0, 0, 0 },
637         };
638
639         argvopt = argv;
640
641 #ifdef RTE_LIB_CMDLINE
642 #define SHORTOPTS "i"
643 #else
644 #define SHORTOPTS ""
645 #endif
646         while ((opt = getopt_long(argc, argvopt, SHORTOPTS "ah",
647                                  lgopts, &opt_idx)) != EOF) {
648                 switch (opt) {
649 #ifdef RTE_LIB_CMDLINE
650                 case 'i':
651                         printf("Interactive-mode selected\n");
652                         interactive = 1;
653                         break;
654 #endif
655                 case 'a':
656                         printf("Auto-start selected\n");
657                         auto_start = 1;
658                         break;
659
660                 case 0: /*long options */
661                         if (!strcmp(lgopts[opt_idx].name, "help")) {
662                                 usage(argv[0]);
663                                 exit(EXIT_SUCCESS);
664                         }
665 #ifdef RTE_LIB_CMDLINE
666                         if (!strcmp(lgopts[opt_idx].name, "interactive")) {
667                                 printf("Interactive-mode selected\n");
668                                 interactive = 1;
669                         }
670                         if (!strcmp(lgopts[opt_idx].name, "cmdline-file")) {
671                                 printf("CLI commands to be read from %s\n",
672                                        optarg);
673                                 strlcpy(cmdline_filename, optarg,
674                                         sizeof(cmdline_filename));
675                         }
676                         if (!strcmp(lgopts[opt_idx].name, "auto-start")) {
677                                 printf("Auto-start selected\n");
678                                 auto_start = 1;
679                         }
680                         if (!strcmp(lgopts[opt_idx].name, "tx-first")) {
681                                 printf("Ports to start sending a burst of "
682                                                 "packets first\n");
683                                 tx_first = 1;
684                         }
685                         if (!strcmp(lgopts[opt_idx].name, "stats-period")) {
686                                 char *end = NULL;
687                                 unsigned int n;
688
689                                 n = strtoul(optarg, &end, 10);
690                                 if ((optarg[0] == '\0') || (end == NULL) ||
691                                                 (*end != '\0'))
692                                         break;
693
694                                 stats_period = n;
695                                 break;
696                         }
697                         if (!strcmp(lgopts[opt_idx].name,
698                                     "eth-peers-configfile")) {
699                                 if (init_peer_eth_addrs(optarg) != 0)
700                                         rte_exit(EXIT_FAILURE,
701                                                  "Cannot open logfile\n");
702                         }
703                         if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
704                                 char *port_end;
705
706                                 errno = 0;
707                                 n = strtoul(optarg, &port_end, 10);
708                                 if (errno != 0 || port_end == optarg || *port_end++ != ',')
709                                         rte_exit(EXIT_FAILURE,
710                                                  "Invalid eth-peer: %s", optarg);
711                                 if (n >= RTE_MAX_ETHPORTS)
712                                         rte_exit(EXIT_FAILURE,
713                                                  "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
714                                                  n, RTE_MAX_ETHPORTS);
715
716                                 if (rte_ether_unformat_addr(port_end,
717                                                 &peer_eth_addrs[n]) < 0)
718                                         rte_exit(EXIT_FAILURE,
719                                                  "Invalid ethernet address: %s\n",
720                                                  port_end);
721                                 nb_peer_eth_addrs++;
722                         }
723 #endif
724                         if (!strcmp(lgopts[opt_idx].name, "tx-ip")) {
725                                 struct in_addr in;
726                                 char *end;
727
728                                 end = strchr(optarg, ',');
729                                 if (end == optarg || !end)
730                                         rte_exit(EXIT_FAILURE,
731                                                  "Invalid tx-ip: %s", optarg);
732
733                                 *end++ = 0;
734                                 if (inet_pton(AF_INET, optarg, &in) == 0)
735                                         rte_exit(EXIT_FAILURE,
736                                                  "Invalid source IP address: %s\n",
737                                                  optarg);
738                                 tx_ip_src_addr = rte_be_to_cpu_32(in.s_addr);
739
740                                 if (inet_pton(AF_INET, end, &in) == 0)
741                                         rte_exit(EXIT_FAILURE,
742                                                  "Invalid destination IP address: %s\n",
743                                                  optarg);
744                                 tx_ip_dst_addr = rte_be_to_cpu_32(in.s_addr);
745                         }
746                         if (!strcmp(lgopts[opt_idx].name, "tx-udp")) {
747                                 char *end = NULL;
748
749                                 errno = 0;
750                                 n = strtoul(optarg, &end, 10);
751                                 if (errno != 0 || end == optarg ||
752                                     n > UINT16_MAX ||
753                                     !(*end == '\0' || *end == ','))
754                                         rte_exit(EXIT_FAILURE,
755                                                  "Invalid UDP port: %s\n",
756                                                  optarg);
757                                 tx_udp_src_port = n;
758                                 if (*end == ',') {
759                                         char *dst = end + 1;
760
761                                         n = strtoul(dst, &end, 10);
762                                         if (errno != 0 || end == dst ||
763                                             n > UINT16_MAX || *end)
764                                                 rte_exit(EXIT_FAILURE,
765                                                          "Invalid destination UDP port: %s\n",
766                                                          dst);
767                                         tx_udp_dst_port = n;
768                                 } else {
769                                         tx_udp_dst_port = n;
770                                 }
771
772                         }
773                         if (!strcmp(lgopts[opt_idx].name, "nb-ports")) {
774                                 n = atoi(optarg);
775                                 if (n > 0 && n <= nb_ports)
776                                         nb_fwd_ports = n;
777                                 else
778                                         rte_exit(EXIT_FAILURE,
779                                                  "Invalid port %d\n", n);
780                         }
781                         if (!strcmp(lgopts[opt_idx].name, "nb-cores")) {
782                                 n = atoi(optarg);
783                                 if (n > 0 && n <= nb_lcores)
784                                         nb_fwd_lcores = (uint8_t) n;
785                                 else
786                                         rte_exit(EXIT_FAILURE,
787                                                  "nb-cores should be > 0 and <= %d\n",
788                                                  nb_lcores);
789                         }
790                         if (!strcmp(lgopts[opt_idx].name, "coremask"))
791                                 parse_fwd_coremask(optarg);
792                         if (!strcmp(lgopts[opt_idx].name, "portmask"))
793                                 parse_fwd_portmask(optarg);
794                         if (!strcmp(lgopts[opt_idx].name, "portlist"))
795                                 parse_fwd_portlist(optarg);
796                         if (!strcmp(lgopts[opt_idx].name, "no-numa"))
797                                 numa_support = 0;
798                         if (!strcmp(lgopts[opt_idx].name, "numa"))
799                                 numa_support = 1;
800                         if (!strcmp(lgopts[opt_idx].name, "mp-anon")) {
801                                 mp_alloc_type = MP_ALLOC_ANON;
802                         }
803                         if (!strcmp(lgopts[opt_idx].name, "mp-alloc")) {
804                                 if (!strcmp(optarg, "native"))
805                                         mp_alloc_type = MP_ALLOC_NATIVE;
806                                 else if (!strcmp(optarg, "anon"))
807                                         mp_alloc_type = MP_ALLOC_ANON;
808                                 else if (!strcmp(optarg, "xmem"))
809                                         mp_alloc_type = MP_ALLOC_XMEM;
810                                 else if (!strcmp(optarg, "xmemhuge"))
811                                         mp_alloc_type = MP_ALLOC_XMEM_HUGE;
812                                 else if (!strcmp(optarg, "xbuf"))
813                                         mp_alloc_type = MP_ALLOC_XBUF;
814                                 else
815                                         rte_exit(EXIT_FAILURE,
816                                                 "mp-alloc %s invalid - must be: "
817                                                 "native, anon, xmem or xmemhuge\n",
818                                                  optarg);
819                         }
820                         if (!strcmp(lgopts[opt_idx].name, "port-numa-config")) {
821                                 if (parse_portnuma_config(optarg))
822                                         rte_exit(EXIT_FAILURE,
823                                            "invalid port-numa configuration\n");
824                         }
825                         if (!strcmp(lgopts[opt_idx].name, "ring-numa-config"))
826                                 if (parse_ringnuma_config(optarg))
827                                         rte_exit(EXIT_FAILURE,
828                                            "invalid ring-numa configuration\n");
829                         if (!strcmp(lgopts[opt_idx].name, "socket-num")) {
830                                 n = atoi(optarg);
831                                 if (!new_socket_id((uint8_t)n)) {
832                                         socket_num = (uint8_t)n;
833                                 } else {
834                                         print_invalid_socket_id_error();
835                                         rte_exit(EXIT_FAILURE,
836                                                 "Invalid socket id");
837                                 }
838                         }
839                         if (!strcmp(lgopts[opt_idx].name, "mbuf-size")) {
840                                 unsigned int mb_sz[MAX_SEGS_BUFFER_SPLIT];
841                                 unsigned int nb_segs, i;
842
843                                 nb_segs = parse_item_list(optarg, "mbuf-size",
844                                         MAX_SEGS_BUFFER_SPLIT, mb_sz, 0);
845                                 if (nb_segs <= 0)
846                                         rte_exit(EXIT_FAILURE,
847                                                  "bad mbuf-size\n");
848                                 for (i = 0; i < nb_segs; i++) {
849                                         if (mb_sz[i] <= 0 || mb_sz[i] > 0xFFFF)
850                                                 rte_exit(EXIT_FAILURE,
851                                                          "mbuf-size should be "
852                                                          "> 0 and < 65536\n");
853                                         mbuf_data_size[i] = (uint16_t) mb_sz[i];
854                                 }
855                                 mbuf_data_size_n = nb_segs;
856                         }
857                         if (!strcmp(lgopts[opt_idx].name, "total-num-mbufs")) {
858                                 n = atoi(optarg);
859                                 if (n > 1024)
860                                         param_total_num_mbufs = (unsigned)n;
861                                 else
862                                         rte_exit(EXIT_FAILURE,
863                                                  "total-num-mbufs should be > 1024\n");
864                         }
865                         if (!strcmp(lgopts[opt_idx].name, "max-pkt-len")) {
866                                 n = atoi(optarg);
867                                 if (n >= RTE_ETHER_MIN_LEN)
868                                         rx_mode.max_rx_pkt_len = (uint32_t) n;
869                                 else
870                                         rte_exit(EXIT_FAILURE,
871                                                  "Invalid max-pkt-len=%d - should be > %d\n",
872                                                  n, RTE_ETHER_MIN_LEN);
873                         }
874                         if (!strcmp(lgopts[opt_idx].name, "max-lro-pkt-size")) {
875                                 n = atoi(optarg);
876                                 rx_mode.max_lro_pkt_size = (uint32_t) n;
877                         }
878                         if (!strcmp(lgopts[opt_idx].name, "pkt-filter-mode")) {
879                                 if (!strcmp(optarg, "signature"))
880                                         fdir_conf.mode =
881                                                 RTE_FDIR_MODE_SIGNATURE;
882                                 else if (!strcmp(optarg, "perfect"))
883                                         fdir_conf.mode = RTE_FDIR_MODE_PERFECT;
884                                 else if (!strcmp(optarg, "perfect-mac-vlan"))
885                                         fdir_conf.mode = RTE_FDIR_MODE_PERFECT_MAC_VLAN;
886                                 else if (!strcmp(optarg, "perfect-tunnel"))
887                                         fdir_conf.mode = RTE_FDIR_MODE_PERFECT_TUNNEL;
888                                 else if (!strcmp(optarg, "none"))
889                                         fdir_conf.mode = RTE_FDIR_MODE_NONE;
890                                 else
891                                         rte_exit(EXIT_FAILURE,
892                                                  "pkt-mode-invalid %s invalid - must be: "
893                                                  "none, signature, perfect, perfect-mac-vlan"
894                                                  " or perfect-tunnel\n",
895                                                  optarg);
896                         }
897                         if (!strcmp(lgopts[opt_idx].name,
898                                     "pkt-filter-report-hash")) {
899                                 if (!strcmp(optarg, "none"))
900                                         fdir_conf.status =
901                                                 RTE_FDIR_NO_REPORT_STATUS;
902                                 else if (!strcmp(optarg, "match"))
903                                         fdir_conf.status =
904                                                 RTE_FDIR_REPORT_STATUS;
905                                 else if (!strcmp(optarg, "always"))
906                                         fdir_conf.status =
907                                                 RTE_FDIR_REPORT_STATUS_ALWAYS;
908                                 else
909                                         rte_exit(EXIT_FAILURE,
910                                                  "pkt-filter-report-hash %s invalid "
911                                                  "- must be: none or match or always\n",
912                                                  optarg);
913                         }
914                         if (!strcmp(lgopts[opt_idx].name, "pkt-filter-size")) {
915                                 if (!strcmp(optarg, "64K"))
916                                         fdir_conf.pballoc =
917                                                 RTE_FDIR_PBALLOC_64K;
918                                 else if (!strcmp(optarg, "128K"))
919                                         fdir_conf.pballoc =
920                                                 RTE_FDIR_PBALLOC_128K;
921                                 else if (!strcmp(optarg, "256K"))
922                                         fdir_conf.pballoc =
923                                                 RTE_FDIR_PBALLOC_256K;
924                                 else
925                                         rte_exit(EXIT_FAILURE, "pkt-filter-size %s invalid -"
926                                                  " must be: 64K or 128K or 256K\n",
927                                                  optarg);
928                         }
929                         if (!strcmp(lgopts[opt_idx].name,
930                                     "pkt-filter-drop-queue")) {
931                                 n = atoi(optarg);
932                                 if (n >= 0)
933                                         fdir_conf.drop_queue = (uint8_t) n;
934                                 else
935                                         rte_exit(EXIT_FAILURE,
936                                                  "drop queue %d invalid - must"
937                                                  "be >= 0 \n", n);
938                         }
939 #ifdef RTE_LIB_LATENCYSTATS
940                         if (!strcmp(lgopts[opt_idx].name,
941                                     "latencystats")) {
942                                 n = atoi(optarg);
943                                 if (n >= 0) {
944                                         latencystats_lcore_id = (lcoreid_t) n;
945                                         latencystats_enabled = 1;
946                                 } else
947                                         rte_exit(EXIT_FAILURE,
948                                                  "invalid lcore id %d for latencystats"
949                                                  " must be >= 0\n", n);
950                         }
951 #endif
952 #ifdef RTE_LIB_BITRATESTATS
953                         if (!strcmp(lgopts[opt_idx].name, "bitrate-stats")) {
954                                 n = atoi(optarg);
955                                 if (n >= 0) {
956                                         bitrate_lcore_id = (lcoreid_t) n;
957                                         bitrate_enabled = 1;
958                                 } else
959                                         rte_exit(EXIT_FAILURE,
960                                                  "invalid lcore id %d for bitrate stats"
961                                                  " must be >= 0\n", n);
962                         }
963 #endif
964                         if (!strcmp(lgopts[opt_idx].name, "disable-crc-strip"))
965                                 rx_offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
966                         if (!strcmp(lgopts[opt_idx].name, "enable-lro"))
967                                 rx_offloads |= DEV_RX_OFFLOAD_TCP_LRO;
968                         if (!strcmp(lgopts[opt_idx].name, "enable-scatter"))
969                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
970                         if (!strcmp(lgopts[opt_idx].name, "enable-rx-cksum"))
971                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
972                         if (!strcmp(lgopts[opt_idx].name,
973                                         "enable-rx-timestamp"))
974                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
975                         if (!strcmp(lgopts[opt_idx].name, "enable-hw-vlan"))
976                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN;
977
978                         if (!strcmp(lgopts[opt_idx].name,
979                                         "enable-hw-vlan-filter"))
980                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
981
982                         if (!strcmp(lgopts[opt_idx].name,
983                                         "enable-hw-vlan-strip"))
984                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
985
986                         if (!strcmp(lgopts[opt_idx].name,
987                                         "enable-hw-vlan-extend"))
988                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
989
990                         if (!strcmp(lgopts[opt_idx].name,
991                                         "enable-hw-qinq-strip"))
992                                 rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
993
994                         if (!strcmp(lgopts[opt_idx].name, "enable-drop-en"))
995                                 rx_drop_en = 1;
996
997                         if (!strcmp(lgopts[opt_idx].name, "disable-rss"))
998                                 rss_hf = 0;
999                         if (!strcmp(lgopts[opt_idx].name, "port-topology")) {
1000                                 if (!strcmp(optarg, "paired"))
1001                                         port_topology = PORT_TOPOLOGY_PAIRED;
1002                                 else if (!strcmp(optarg, "chained"))
1003                                         port_topology = PORT_TOPOLOGY_CHAINED;
1004                                 else if (!strcmp(optarg, "loop"))
1005                                         port_topology = PORT_TOPOLOGY_LOOP;
1006                                 else
1007                                         rte_exit(EXIT_FAILURE, "port-topology %s invalid -"
1008                                                  " must be: paired, chained or loop\n",
1009                                                  optarg);
1010                         }
1011                         if (!strcmp(lgopts[opt_idx].name, "forward-mode"))
1012                                 set_pkt_forwarding_mode(optarg);
1013                         if (!strcmp(lgopts[opt_idx].name, "rss-ip"))
1014                                 rss_hf = ETH_RSS_IP;
1015                         if (!strcmp(lgopts[opt_idx].name, "rss-udp"))
1016                                 rss_hf = ETH_RSS_UDP;
1017                         if (!strcmp(lgopts[opt_idx].name, "rss-level-inner"))
1018                                 rss_hf |= ETH_RSS_LEVEL_INNERMOST;
1019                         if (!strcmp(lgopts[opt_idx].name, "rss-level-outer"))
1020                                 rss_hf |= ETH_RSS_LEVEL_OUTERMOST;
1021                         if (!strcmp(lgopts[opt_idx].name, "rxq")) {
1022                                 n = atoi(optarg);
1023                                 if (n >= 0 && check_nb_rxq((queueid_t)n) == 0)
1024                                         nb_rxq = (queueid_t) n;
1025                                 else
1026                                         rte_exit(EXIT_FAILURE, "rxq %d invalid - must be"
1027                                                   " >= 0 && <= %u\n", n,
1028                                                   get_allowed_max_nb_rxq(&pid));
1029                         }
1030                         if (!strcmp(lgopts[opt_idx].name, "txq")) {
1031                                 n = atoi(optarg);
1032                                 if (n >= 0 && check_nb_txq((queueid_t)n) == 0)
1033                                         nb_txq = (queueid_t) n;
1034                                 else
1035                                         rte_exit(EXIT_FAILURE, "txq %d invalid - must be"
1036                                                   " >= 0 && <= %u\n", n,
1037                                                   get_allowed_max_nb_txq(&pid));
1038                         }
1039                         if (!strcmp(lgopts[opt_idx].name, "hairpinq")) {
1040                                 n = atoi(optarg);
1041                                 if (n >= 0 &&
1042                                     check_nb_hairpinq((queueid_t)n) == 0)
1043                                         nb_hairpinq = (queueid_t) n;
1044                                 else
1045                                         rte_exit(EXIT_FAILURE, "txq %d invalid - must be"
1046                                                   " >= 0 && <= %u\n", n,
1047                                                   get_allowed_max_nb_hairpinq
1048                                                   (&pid));
1049                                 if ((n + nb_txq) < 0 ||
1050                                     check_nb_txq((queueid_t)(n + nb_txq)) != 0)
1051                                         rte_exit(EXIT_FAILURE, "txq + hairpinq "
1052                                                  "%d invalid - must be"
1053                                                   " >= 0 && <= %u\n",
1054                                                   n + nb_txq,
1055                                                   get_allowed_max_nb_txq(&pid));
1056                                 if ((n + nb_rxq) < 0 ||
1057                                     check_nb_rxq((queueid_t)(n + nb_rxq)) != 0)
1058                                         rte_exit(EXIT_FAILURE, "rxq + hairpinq "
1059                                                  "%d invalid - must be"
1060                                                   " >= 0 && <= %u\n",
1061                                                   n + nb_rxq,
1062                                                   get_allowed_max_nb_rxq(&pid));
1063                         }
1064                         if (!nb_rxq && !nb_txq) {
1065                                 rte_exit(EXIT_FAILURE, "Either rx or tx queues should "
1066                                                 "be non-zero\n");
1067                         }
1068                         if (!strcmp(lgopts[opt_idx].name, "hairpin-mode")) {
1069                                 char *end = NULL;
1070                                 unsigned int n;
1071
1072                                 errno = 0;
1073                                 n = strtoul(optarg, &end, 0);
1074                                 if (errno != 0 || end == optarg)
1075                                         rte_exit(EXIT_FAILURE, "hairpin mode invalid\n");
1076                                 else
1077                                         hairpin_mode = (uint16_t)n;
1078                         }
1079                         if (!strcmp(lgopts[opt_idx].name, "burst")) {
1080                                 n = atoi(optarg);
1081                                 if (n == 0) {
1082                                         /* A burst size of zero means that the
1083                                          * PMD should be queried for
1084                                          * recommended Rx burst size. Since
1085                                          * testpmd uses a single size for all
1086                                          * ports, port 0 is queried for the
1087                                          * value, on the assumption that all
1088                                          * ports are of the same NIC model.
1089                                          */
1090                                         ret = eth_dev_info_get_print_err(
1091                                                                 0,
1092                                                                 &dev_info);
1093                                         if (ret != 0)
1094                                                 return;
1095
1096                                         rec_nb_pkts = dev_info
1097                                                 .default_rxportconf.burst_size;
1098
1099                                         if (rec_nb_pkts == 0)
1100                                                 rte_exit(EXIT_FAILURE,
1101                                                         "PMD does not recommend a burst size. "
1102                                                         "Provided value must be between "
1103                                                         "1 and %d\n", MAX_PKT_BURST);
1104                                         else if (rec_nb_pkts > MAX_PKT_BURST)
1105                                                 rte_exit(EXIT_FAILURE,
1106                                                         "PMD recommended burst size of %d"
1107                                                         " exceeds maximum value of %d\n",
1108                                                         rec_nb_pkts, MAX_PKT_BURST);
1109                                         printf("Using PMD-provided burst value of %d\n",
1110                                                 rec_nb_pkts);
1111                                         nb_pkt_per_burst = rec_nb_pkts;
1112                                 } else if (n > MAX_PKT_BURST)
1113                                         rte_exit(EXIT_FAILURE,
1114                                                 "burst must be between1 and %d\n",
1115                                                 MAX_PKT_BURST);
1116                                 else
1117                                         nb_pkt_per_burst = (uint16_t) n;
1118                         }
1119                         if (!strcmp(lgopts[opt_idx].name, "flowgen-clones")) {
1120                                 n = atoi(optarg);
1121                                 if (n >= 0)
1122                                         nb_pkt_flowgen_clones = (uint16_t) n;
1123                                 else
1124                                         rte_exit(EXIT_FAILURE,
1125                                                  "clones must be >= 0 and <= current burst\n");
1126                         }
1127                         if (!strcmp(lgopts[opt_idx].name, "flowgen-flows")) {
1128                                 n = atoi(optarg);
1129                                 if (n > 0)
1130                                         nb_flows_flowgen = (int) n;
1131                                 else
1132                                         rte_exit(EXIT_FAILURE,
1133                                                  "flows must be >= 1\n");
1134                         }
1135                         if (!strcmp(lgopts[opt_idx].name, "mbcache")) {
1136                                 n = atoi(optarg);
1137                                 if ((n >= 0) &&
1138                                     (n <= RTE_MEMPOOL_CACHE_MAX_SIZE))
1139                                         mb_mempool_cache = (uint16_t) n;
1140                                 else
1141                                         rte_exit(EXIT_FAILURE,
1142                                                  "mbcache must be >= 0 and <= %d\n",
1143                                                  RTE_MEMPOOL_CACHE_MAX_SIZE);
1144                         }
1145                         if (!strcmp(lgopts[opt_idx].name, "txfreet")) {
1146                                 n = atoi(optarg);
1147                                 if (n >= 0)
1148                                         tx_free_thresh = (int16_t)n;
1149                                 else
1150                                         rte_exit(EXIT_FAILURE, "txfreet must be >= 0\n");
1151                         }
1152                         if (!strcmp(lgopts[opt_idx].name, "txrst")) {
1153                                 n = atoi(optarg);
1154                                 if (n >= 0)
1155                                         tx_rs_thresh = (int16_t)n;
1156                                 else
1157                                         rte_exit(EXIT_FAILURE, "txrst must be >= 0\n");
1158                         }
1159                         if (!strcmp(lgopts[opt_idx].name, "rxd")) {
1160                                 n = atoi(optarg);
1161                                 if (n > 0) {
1162                                         if (rx_free_thresh >= n)
1163                                                 rte_exit(EXIT_FAILURE,
1164                                                          "rxd must be > "
1165                                                          "rx_free_thresh(%d)\n",
1166                                                          (int)rx_free_thresh);
1167                                         else
1168                                                 nb_rxd = (uint16_t) n;
1169                                 } else
1170                                         rte_exit(EXIT_FAILURE,
1171                                                  "rxd(%d) invalid - must be > 0\n",
1172                                                  n);
1173                         }
1174                         if (!strcmp(lgopts[opt_idx].name, "txd")) {
1175                                 n = atoi(optarg);
1176                                 if (n > 0)
1177                                         nb_txd = (uint16_t) n;
1178                                 else
1179                                         rte_exit(EXIT_FAILURE, "txd must be in > 0\n");
1180                         }
1181                         if (!strcmp(lgopts[opt_idx].name, "txpt")) {
1182                                 n = atoi(optarg);
1183                                 if (n >= 0)
1184                                         tx_pthresh = (int8_t)n;
1185                                 else
1186                                         rte_exit(EXIT_FAILURE, "txpt must be >= 0\n");
1187                         }
1188                         if (!strcmp(lgopts[opt_idx].name, "txht")) {
1189                                 n = atoi(optarg);
1190                                 if (n >= 0)
1191                                         tx_hthresh = (int8_t)n;
1192                                 else
1193                                         rte_exit(EXIT_FAILURE, "txht must be >= 0\n");
1194                         }
1195                         if (!strcmp(lgopts[opt_idx].name, "txwt")) {
1196                                 n = atoi(optarg);
1197                                 if (n >= 0)
1198                                         tx_wthresh = (int8_t)n;
1199                                 else
1200                                         rte_exit(EXIT_FAILURE, "txwt must be >= 0\n");
1201                         }
1202                         if (!strcmp(lgopts[opt_idx].name, "rxpt")) {
1203                                 n = atoi(optarg);
1204                                 if (n >= 0)
1205                                         rx_pthresh = (int8_t)n;
1206                                 else
1207                                         rte_exit(EXIT_FAILURE, "rxpt must be >= 0\n");
1208                         }
1209                         if (!strcmp(lgopts[opt_idx].name, "rxht")) {
1210                                 n = atoi(optarg);
1211                                 if (n >= 0)
1212                                         rx_hthresh = (int8_t)n;
1213                                 else
1214                                         rte_exit(EXIT_FAILURE, "rxht must be >= 0\n");
1215                         }
1216                         if (!strcmp(lgopts[opt_idx].name, "rxwt")) {
1217                                 n = atoi(optarg);
1218                                 if (n >= 0)
1219                                         rx_wthresh = (int8_t)n;
1220                                 else
1221                                         rte_exit(EXIT_FAILURE, "rxwt must be >= 0\n");
1222                         }
1223                         if (!strcmp(lgopts[opt_idx].name, "rxfreet")) {
1224                                 n = atoi(optarg);
1225                                 if (n >= 0)
1226                                         rx_free_thresh = (int16_t)n;
1227                                 else
1228                                         rte_exit(EXIT_FAILURE, "rxfreet must be >= 0\n");
1229                         }
1230                         if (!strcmp(lgopts[opt_idx].name, "rxoffs")) {
1231                                 unsigned int seg_off[MAX_SEGS_BUFFER_SPLIT];
1232                                 unsigned int nb_offs;
1233
1234                                 nb_offs = parse_item_list
1235                                                 (optarg, "rxpkt offsets",
1236                                                  MAX_SEGS_BUFFER_SPLIT,
1237                                                  seg_off, 0);
1238                                 if (nb_offs > 0)
1239                                         set_rx_pkt_offsets(seg_off, nb_offs);
1240                                 else
1241                                         rte_exit(EXIT_FAILURE, "bad rxoffs\n");
1242                         }
1243                         if (!strcmp(lgopts[opt_idx].name, "rxpkts")) {
1244                                 unsigned int seg_len[MAX_SEGS_BUFFER_SPLIT];
1245                                 unsigned int nb_segs;
1246
1247                                 nb_segs = parse_item_list
1248                                                 (optarg, "rxpkt segments",
1249                                                  MAX_SEGS_BUFFER_SPLIT,
1250                                                  seg_len, 0);
1251                                 if (nb_segs > 0)
1252                                         set_rx_pkt_segments(seg_len, nb_segs);
1253                                 else
1254                                         rte_exit(EXIT_FAILURE, "bad rxpkts\n");
1255                         }
1256                         if (!strcmp(lgopts[opt_idx].name, "txpkts")) {
1257                                 unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
1258                                 unsigned int nb_segs;
1259
1260                                 nb_segs = parse_item_list(optarg, "txpkt segments",
1261                                                 RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
1262                                 if (nb_segs > 0)
1263                                         set_tx_pkt_segments(seg_lengths, nb_segs);
1264                                 else
1265                                         rte_exit(EXIT_FAILURE, "bad txpkts\n");
1266                         }
1267                         if (!strcmp(lgopts[opt_idx].name, "txonly-multi-flow"))
1268                                 txonly_multi_flow = 1;
1269                         if (!strcmp(lgopts[opt_idx].name, "no-flush-rx"))
1270                                 no_flush_rx = 1;
1271                         if (!strcmp(lgopts[opt_idx].name, "eth-link-speed")) {
1272                                 n = atoi(optarg);
1273                                 if (n >= 0 && parse_link_speed(n) > 0)
1274                                         eth_link_speed = parse_link_speed(n);
1275                         }
1276                         if (!strcmp(lgopts[opt_idx].name, "disable-link-check"))
1277                                 no_link_check = 1;
1278                         if (!strcmp(lgopts[opt_idx].name, "disable-device-start"))
1279                                 no_device_start = 1;
1280                         if (!strcmp(lgopts[opt_idx].name, "no-lsc-interrupt"))
1281                                 lsc_interrupt = 0;
1282                         if (!strcmp(lgopts[opt_idx].name, "no-rmv-interrupt"))
1283                                 rmv_interrupt = 0;
1284                         if (!strcmp(lgopts[opt_idx].name, "flow-isolate-all"))
1285                                 flow_isolate_all = 1;
1286                         if (!strcmp(lgopts[opt_idx].name, "tx-offloads")) {
1287                                 char *end = NULL;
1288                                 n = strtoull(optarg, &end, 16);
1289                                 if (n >= 0)
1290                                         tx_offloads = (uint64_t)n;
1291                                 else
1292                                         rte_exit(EXIT_FAILURE,
1293                                                  "tx-offloads must be >= 0\n");
1294                         }
1295
1296                         if (!strcmp(lgopts[opt_idx].name, "rx-offloads")) {
1297                                 char *end = NULL;
1298                                 n = strtoull(optarg, &end, 16);
1299                                 if (n >= 0)
1300                                         rx_offloads = (uint64_t)n;
1301                                 else
1302                                         rte_exit(EXIT_FAILURE,
1303                                                  "rx-offloads must be >= 0\n");
1304                         }
1305
1306                         if (!strcmp(lgopts[opt_idx].name, "vxlan-gpe-port")) {
1307                                 n = atoi(optarg);
1308                                 if (n >= 0)
1309                                         vxlan_gpe_udp_port = (uint16_t)n;
1310                                 else
1311                                         rte_exit(EXIT_FAILURE,
1312                                                  "vxlan-gpe-port must be >= 0\n");
1313                         }
1314                         if (!strcmp(lgopts[opt_idx].name,
1315                                     "geneve-parsed-port")) {
1316                                 n = atoi(optarg);
1317                                 if (n >= 0)
1318                                         geneve_udp_port = (uint16_t)n;
1319                                 else
1320                                         rte_exit(EXIT_FAILURE,
1321                                                  "geneve-parsed-port must be >= 0\n");
1322                         }
1323                         if (!strcmp(lgopts[opt_idx].name, "print-event"))
1324                                 if (parse_event_printing_config(optarg, 1)) {
1325                                         rte_exit(EXIT_FAILURE,
1326                                                  "invalid print-event argument\n");
1327                                 }
1328                         if (!strcmp(lgopts[opt_idx].name, "mask-event"))
1329                                 if (parse_event_printing_config(optarg, 0)) {
1330                                         rte_exit(EXIT_FAILURE,
1331                                                  "invalid mask-event argument\n");
1332                                 }
1333                         if (!strcmp(lgopts[opt_idx].name, "hot-plug"))
1334                                 hot_plug = 1;
1335                         if (!strcmp(lgopts[opt_idx].name, "mlockall"))
1336                                 do_mlockall = 1;
1337                         if (!strcmp(lgopts[opt_idx].name, "no-mlockall"))
1338                                 do_mlockall = 0;
1339                         if (!strcmp(lgopts[opt_idx].name,
1340                                     "noisy-tx-sw-buffer-size")) {
1341                                 n = atoi(optarg);
1342                                 if (n >= 0)
1343                                         noisy_tx_sw_bufsz = n;
1344                                 else
1345                                         rte_exit(EXIT_FAILURE,
1346                                                 "noisy-tx-sw-buffer-size must be >= 0\n");
1347                         }
1348                         if (!strcmp(lgopts[opt_idx].name,
1349                                     "noisy-tx-sw-buffer-flushtime")) {
1350                                 n = atoi(optarg);
1351                                 if (n >= 0)
1352                                         noisy_tx_sw_buf_flush_time = n;
1353                                 else
1354                                         rte_exit(EXIT_FAILURE,
1355                                                  "noisy-tx-sw-buffer-flushtime must be >= 0\n");
1356                         }
1357                         if (!strcmp(lgopts[opt_idx].name,
1358                                     "noisy-lkup-memory")) {
1359                                 n = atoi(optarg);
1360                                 if (n >= 0)
1361                                         noisy_lkup_mem_sz = n;
1362                                 else
1363                                         rte_exit(EXIT_FAILURE,
1364                                                  "noisy-lkup-memory must be >= 0\n");
1365                         }
1366                         if (!strcmp(lgopts[opt_idx].name,
1367                                     "noisy-lkup-num-writes")) {
1368                                 n = atoi(optarg);
1369                                 if (n >= 0)
1370                                         noisy_lkup_num_writes = n;
1371                                 else
1372                                         rte_exit(EXIT_FAILURE,
1373                                                  "noisy-lkup-num-writes must be >= 0\n");
1374                         }
1375                         if (!strcmp(lgopts[opt_idx].name,
1376                                     "noisy-lkup-num-reads")) {
1377                                 n = atoi(optarg);
1378                                 if (n >= 0)
1379                                         noisy_lkup_num_reads = n;
1380                                 else
1381                                         rte_exit(EXIT_FAILURE,
1382                                                  "noisy-lkup-num-reads must be >= 0\n");
1383                         }
1384                         if (!strcmp(lgopts[opt_idx].name,
1385                                     "noisy-lkup-num-reads-writes")) {
1386                                 n = atoi(optarg);
1387                                 if (n >= 0)
1388                                         noisy_lkup_num_reads_writes = n;
1389                                 else
1390                                         rte_exit(EXIT_FAILURE,
1391                                                  "noisy-lkup-num-reads-writes must be >= 0\n");
1392                         }
1393                         if (!strcmp(lgopts[opt_idx].name, "no-iova-contig"))
1394                                 mempool_flags = MEMPOOL_F_NO_IOVA_CONTIG;
1395
1396                         if (!strcmp(lgopts[opt_idx].name, "rx-mq-mode")) {
1397                                 char *end = NULL;
1398                                 n = strtoul(optarg, &end, 16);
1399                                 if (n >= 0 && n <= ETH_MQ_RX_VMDQ_DCB_RSS)
1400                                         rx_mq_mode = (enum rte_eth_rx_mq_mode)n;
1401                                 else
1402                                         rte_exit(EXIT_FAILURE,
1403                                                  "rx-mq-mode must be >= 0 and <= %d\n",
1404                                                  ETH_MQ_RX_VMDQ_DCB_RSS);
1405                         }
1406                         if (!strcmp(lgopts[opt_idx].name, "record-core-cycles"))
1407                                 record_core_cycles = 1;
1408                         if (!strcmp(lgopts[opt_idx].name, "record-burst-stats"))
1409                                 record_burst_stats = 1;
1410                         break;
1411                 case 'h':
1412                         usage(argv[0]);
1413                         exit(EXIT_SUCCESS);
1414                         break;
1415                 default:
1416                         usage(argv[0]);
1417                         fprintf(stderr, "Invalid option: %s\n", argv[optind]);
1418                         rte_exit(EXIT_FAILURE,
1419                                  "Command line is incomplete or incorrect\n");
1420                         break;
1421                 }
1422         }
1423
1424         if (optind != argc) {
1425                 usage(argv[0]);
1426                 fprintf(stderr, "Invalid parameter: %s\n", argv[optind]);
1427                 rte_exit(EXIT_FAILURE, "Command line is incorrect\n");
1428         }
1429
1430         /* Set offload configuration from command line parameters. */
1431         rx_mode.offloads = rx_offloads;
1432         tx_mode.offloads = tx_offloads;
1433
1434         if (mempool_flags & MEMPOOL_F_NO_IOVA_CONTIG &&
1435             mp_alloc_type != MP_ALLOC_ANON) {
1436                 TESTPMD_LOG(WARNING, "cannot use no-iova-contig without "
1437                                   "mp-alloc=anon. mempool no-iova-contig is "
1438                                   "ignored\n");
1439                 mempool_flags = 0;
1440         }
1441 }