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