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