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