a541f20f6c074c48dc8c94b11df44e78fb685073
[dpdk.git] / app / test-pmd / parameters.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  * 
7  *   Redistribution and use in source and binary forms, with or without 
8  *   modification, are permitted provided that the following conditions 
9  *   are met:
10  * 
11  *     * Redistributions of source code must retain the above copyright 
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright 
14  *       notice, this list of conditions and the following disclaimer in 
15  *       the documentation and/or other materials provided with the 
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its 
18  *       contributors may be used to endorse or promote products derived 
19  *       from this software without specific prior written permission.
20  * 
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  * 
33  */
34
35 #include <errno.h>
36 #include <getopt.h>
37 #include <stdarg.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <signal.h>
41 #include <string.h>
42 #include <time.h>
43 #include <fcntl.h>
44 #include <sys/types.h>
45 #include <errno.h>
46
47 #include <sys/queue.h>
48 #include <sys/stat.h>
49
50 #include <stdint.h>
51 #include <unistd.h>
52 #include <inttypes.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_launch.h>
62 #include <rte_tailq.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <cmdline_parse.h>
76 #include <cmdline_parse_etheraddr.h>
77
78 #include "testpmd.h"
79
80 static void
81 usage(char* progname)
82 {
83         printf("usage: %s [--interactive|-i] [--help|-h] | ["
84                "--coremask=COREMASK --portmask=PORTMASK --numa "
85                "--mbuf-size= | --total-num-mbufs= | "
86                "--nb-cores= | --nb-ports= | "
87                "--eth-peers-configfile= | "
88                "--eth-peer=X,M:M:M:M:M:M | "
89                "--pkt-filter-mode= |"
90                "--rss-ip | --rss-udp | "
91                "--rxpt= | --rxht= | --rxwt= | --rxfreet= | "
92                "--txpt= | --txht= | --txwt= | --txfreet= | "
93                "--txrst= | --txqflags= ]\n",
94                progname);
95         printf("  --interactive: run in interactive mode.\n");
96         printf("  --help: display this message and quit.\n");
97         printf("  --nb-cores=N: set the number of forwarding cores "
98                "(1 <= N <= %d).\n", nb_lcores);
99         printf("  --nb-ports=N: set the number of forwarding ports "
100                "(1 <= N <= %d).\n", nb_ports);
101         printf("  --coremask=COREMASK: hexadecimal bitmask of cores running "
102                "the packet forwarding test. The master lcore is reserved for "
103                "command line parsing only, and cannot be masked on for "
104                "packet forwarding.\n");
105         printf("  --portmask=PORTMASK: hexadecimal bitmask of ports used "
106                "by the packet forwarding test.\n");
107         printf("  --numa: enable NUMA-aware allocation of RX/TX rings and of "
108                "RX memory buffers (mbufs).\n");
109         printf("  --port-numa-config=(port,socket)[,(port,socket)]: "
110                "specify the socket on which the memory pool "
111                "used by the port will be allocated.\n");
112         printf("  --ring-numa-config=(port,flag,socket)[,(port,flag,socket)]: "
113                "specify the socket on which the TX/RX rings for "
114                "the port will be allocated "
115                "(flag: 1 for RX; 2 for TX; 3 for RX and TX).\n");
116         printf(" --socket-num=N: set socket from which all memory is allocated "
117                "in NUMA mode.\n");
118         printf("  --mbuf-size=N: set the data size of mbuf to N bytes.\n");
119         printf("  --total-num-mbufs=N: set the number of mbufs to be allocated "
120                "in mbuf pools.\n");
121         printf("  --max-pkt-len=N: set the maximum size of packet to N bytes.\n");
122         printf("  --eth-peers-configfile=name: config file with ethernet addresses "
123                "of peer ports.\n");
124         printf("  --eth-peer=X,M:M:M:M:M:M: set the MAC address of the X peer "
125                "port (0 <= X < %d).\n", RTE_MAX_ETHPORTS);
126         printf("  --pkt-filter-mode=N: set Flow Director mode "
127                "(N: none (default mode) or signature or perfect).\n");
128         printf("  --pkt-filter-report-hash=N: set Flow Director report mode "
129                "(N: none  or match (default) or always).\n");
130         printf("  --pkt-filter-size=N: set Flow Director mode "
131                "(N: 64K (default mode) or 128K or 256K).\n");
132         printf("  --pkt-filter-flexbytes-offset=N: set flexbytes-offset. "
133                "The offset is defined in word units counted from the "
134                "first byte of the destination Ethernet MAC address. "
135                "0 <= N <= 32.\n");
136         printf("  --pkt-filter-drop-queue=N: set drop-queue. "
137                "In perfect mode, when you add a rule with queue = -1 "
138                "the packet will be enqueued into the rx drop-queue. "
139                "If the drop-queue doesn't exist, the packet is dropped. "
140                "By default drop-queue=127.\n");
141         printf("  --crc-strip: enable CRC stripping by hardware.\n");
142         printf("  --enable-rx-cksum: enable rx hardware checksum offload.\n");
143         printf("  --disable-hw-vlan: disable hardware vlan.\n");
144         printf("  --enable-drop-en: enable per queue packet drop.\n");
145         printf("  --disable-rss: disable rss.\n");
146         printf("  --port-topology=N: set port topology (N: paired (default) or "
147                "chained).\n");
148         printf("  --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
149         printf("  --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
150         printf("  --rxq=N: set the number of RX queues per port to N.\n");
151         printf("  --rxd=N: set the number of descriptors in RX rings to N.\n");
152         printf("  --txq=N: set the number of TX queues per port to N.\n");
153         printf("  --txd=N: set the number of descriptors in TX rings to N.\n");
154         printf("  --burst=N: set the number of packets per burst to N.\n");
155         printf("  --mbcache=N: set the cache of mbuf memory pool to N.\n");
156         printf("  --rxpt=N: set prefetch threshold register of RX rings to N "
157                "(0 <= N <= 16).\n");
158         printf("  --rxht=N: set the host threshold register of RX rings to N "
159                "(0 <= N <= 16).\n");
160         printf("  --rxfreet=N: set the free threshold of RX descriptors to N "
161                "(0 <= N < value of rxd).\n");
162         printf("  --rxwt=N: set the write-back threshold register of RX rings "
163                "to N (0 <= N <= 16).\n");
164         printf("  --txpt=N: set the prefetch threshold register of TX rings "
165                "to N (0 <= N <= 16).\n");
166         printf("  --txht=N: set the nhost threshold register of TX rings to N "
167                "(0 <= N <= 16).\n");
168         printf("  --txwt=N: set the write-back threshold register of TX rings "
169                "to N (0 <= N <= 16).\n");
170         printf("  --txfreet=N: set the transmit free threshold of TX rings to N "
171                "(0 <= N <= value of txd).\n");
172         printf("  --txrst=N: set the transmit RS bit threshold of TX rings to N "
173                "(0 <= N <= value of txd).\n");
174         printf("  --txqflags=0xXXXXXXXX: hexadecimal bitmask of TX queue flags "
175                "(0 <= N <= 0x7FFFFFFF).\n");
176         printf("  --tx-queue-stats-mapping=(port,queue,mapping)[,(port,queue,mapping]: "
177                "tx queues statistics counters mapping "
178                "(0 <= mapping <= %d).\n", RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
179         printf("  --rx-queue-stats-mapping=(port,queue,mapping)[,(port,queue,mapping]: "
180                "rx queues statistics counters mapping "
181                "(0 <= mapping <= %d).\n", RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
182 }
183
184 static int
185 init_peer_eth_addrs(char *config_filename)
186 {
187         FILE *config_file;
188         portid_t i;
189         char buf[50];
190
191         config_file = fopen(config_filename, "r");
192         if (config_file == NULL) {
193                 perror("Failed to open eth config file\n");
194                 return -1;
195         }
196
197         for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
198
199                 if (fgets(buf, sizeof(buf), config_file) == NULL)
200                         break;
201
202                 if (cmdline_parse_etheraddr(NULL, buf, &peer_eth_addrs[i]) < 0 ){
203                         printf("Bad MAC address format on line %d\n", i+1);
204                         fclose(config_file);
205                         return -1;
206                 }
207         }
208         fclose(config_file);
209         nb_peer_eth_addrs = (portid_t) i;
210         return 0;
211 }
212
213 /*
214  * Parse the coremask given as argument (hexadecimal string) and set
215  * the global configuration of forwarding cores.
216  */
217 static void
218 parse_fwd_coremask(const char *coremask)
219 {
220         char *end;
221         unsigned long long int cm;
222
223         /* parse hexadecimal string */
224         end = NULL;
225         cm = strtoull(coremask, &end, 16);
226         if ((coremask[0] == '\0') || (end == NULL) || (*end != '\0'))
227                 rte_exit(EXIT_FAILURE, "Invalid fwd core mask\n");
228         else if (set_fwd_lcores_mask((uint64_t) cm) < 0)
229                 rte_exit(EXIT_FAILURE, "coremask is not valid\n");
230 }
231
232 /*
233  * Parse the coremask given as argument (hexadecimal string) and set
234  * the global configuration of forwarding cores.
235  */
236 static void
237 parse_fwd_portmask(const char *portmask)
238 {
239         char *end;
240         unsigned long long int pm;
241
242         /* parse hexadecimal string */
243         end = NULL;
244         pm = strtoull(portmask, &end, 16);
245         if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
246                 rte_exit(EXIT_FAILURE, "Invalid fwd port mask\n");
247         else
248                 set_fwd_ports_mask((uint64_t) pm);
249 }
250
251
252 static int
253 parse_queue_stats_mapping_config(const char *q_arg, int is_rx)
254 {
255         char s[256];
256         const char *p, *p0 = q_arg;
257         char *end;
258         enum fieldnames {
259                 FLD_PORT = 0,
260                 FLD_QUEUE,
261                 FLD_STATS_COUNTER,
262                 _NUM_FLD
263         };
264         unsigned long int_fld[_NUM_FLD];
265         char *str_fld[_NUM_FLD];
266         int i;
267         unsigned size;
268
269         /* reset from value set at definition */
270         is_rx ? (nb_rx_queue_stats_mappings = 0) : (nb_tx_queue_stats_mappings = 0);
271
272         while ((p = strchr(p0,'(')) != NULL) {
273                 ++p;
274                 if((p0 = strchr(p,')')) == NULL)
275                         return -1;
276
277                 size = p0 - p;
278                 if(size >= sizeof(s))
279                         return -1;
280
281                 rte_snprintf(s, sizeof(s), "%.*s", size, p);
282                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
283                         return -1;
284                 for (i = 0; i < _NUM_FLD; i++){
285                         errno = 0;
286                         int_fld[i] = strtoul(str_fld[i], &end, 0);
287                         if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
288                                 return -1;
289                 }
290                 /* Check mapping field is in correct range (0..RTE_ETHDEV_QUEUE_STAT_CNTRS-1) */
291                 if (int_fld[FLD_STATS_COUNTER] >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
292                         printf("Stats counter not in the correct range 0..%d\n",
293                                         RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
294                         return -1;
295                 }
296
297                 if (is_rx ? (nb_rx_queue_stats_mappings >= MAX_RX_QUEUE_STATS_MAPPINGS) :
298                     (nb_tx_queue_stats_mappings >= MAX_TX_QUEUE_STATS_MAPPINGS)) {
299                         printf("exceeded max number of %s queue statistics mappings: %hu\n",
300                                is_rx ? "RX" : "TX",
301                                is_rx ? nb_rx_queue_stats_mappings : nb_tx_queue_stats_mappings);
302                         return -1;
303                 }
304                 if (!is_rx) {
305                         tx_queue_stats_mappings_array[nb_tx_queue_stats_mappings].port_id =
306                                 (uint8_t)int_fld[FLD_PORT];
307                         tx_queue_stats_mappings_array[nb_tx_queue_stats_mappings].queue_id =
308                                 (uint8_t)int_fld[FLD_QUEUE];
309                         tx_queue_stats_mappings_array[nb_tx_queue_stats_mappings].stats_counter_id =
310                                 (uint8_t)int_fld[FLD_STATS_COUNTER];
311                         ++nb_tx_queue_stats_mappings;
312                 }
313                 else {
314                         rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].port_id =
315                                 (uint8_t)int_fld[FLD_PORT];
316                         rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].queue_id =
317                                 (uint8_t)int_fld[FLD_QUEUE];
318                         rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].stats_counter_id =
319                                 (uint8_t)int_fld[FLD_STATS_COUNTER];
320                         ++nb_rx_queue_stats_mappings;
321                 }
322
323         }
324 /* Reassign the rx/tx_queue_stats_mappings pointer to point to this newly populated array rather */
325 /* than to the default array (that was set at its definition) */
326         is_rx ? (rx_queue_stats_mappings = rx_queue_stats_mappings_array) :
327                 (tx_queue_stats_mappings = tx_queue_stats_mappings_array);
328         return 0;
329 }
330
331 static int
332 parse_portnuma_config(const char *q_arg)
333 {
334         char s[256];
335         const char *p, *p0 = q_arg;
336         char *end;
337         uint8_t i,port_id,socket_id;
338         unsigned size;
339         enum fieldnames {
340                 FLD_PORT = 0,
341                 FLD_SOCKET,
342                 _NUM_FLD
343         };
344         unsigned long int_fld[_NUM_FLD];
345         char *str_fld[_NUM_FLD];        
346
347         /* reset from value set at definition */
348         while ((p = strchr(p0,'(')) != NULL) {
349                 ++p;
350                 if((p0 = strchr(p,')')) == NULL)
351                         return -1;
352
353                 size = p0 - p;
354                 if(size >= sizeof(s))
355                         return -1;
356
357                 rte_snprintf(s, sizeof(s), "%.*s", size, p);
358                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
359                         return -1;
360                 for (i = 0; i < _NUM_FLD; i++) {
361                         errno = 0;
362                         int_fld[i] = strtoul(str_fld[i], &end, 0);
363                         if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
364                                 return -1;
365                 }
366                 port_id = (uint8_t)int_fld[FLD_PORT];
367                 if (port_id >= nb_ports) {
368                         printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
369                         return -1;
370                 }
371                 socket_id = (uint8_t)int_fld[FLD_SOCKET];
372                 if(socket_id >= MAX_SOCKET) {
373                         printf("Invalid socket id, range is [0, %d]\n",
374                                  MAX_SOCKET - 1);
375                         return -1;
376                 }
377                 port_numa[port_id] = socket_id;
378         }
379
380         return 0;
381 }
382
383 static int
384 parse_ringnuma_config(const char *q_arg)
385 {
386         char s[256];
387         const char *p, *p0 = q_arg;
388         char *end;
389         uint8_t i,port_id,ring_flag,socket_id;
390         unsigned size;
391         enum fieldnames {
392                 FLD_PORT = 0,
393                 FLD_FLAG,
394                 FLD_SOCKET,
395                 _NUM_FLD
396         };
397         unsigned long int_fld[_NUM_FLD];
398         char *str_fld[_NUM_FLD];        
399         #define RX_RING_ONLY 0x1
400         #define TX_RING_ONLY 0x2
401         #define RXTX_RING    0x3
402
403         /* reset from value set at definition */
404         while ((p = strchr(p0,'(')) != NULL) {
405                 ++p;
406                 if((p0 = strchr(p,')')) == NULL)
407                         return -1;
408
409                 size = p0 - p;
410                 if(size >= sizeof(s))
411                         return -1;
412
413                 rte_snprintf(s, sizeof(s), "%.*s", size, p);
414                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
415                         return -1;
416                 for (i = 0; i < _NUM_FLD; i++) {
417                         errno = 0;
418                         int_fld[i] = strtoul(str_fld[i], &end, 0);
419                         if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
420                                 return -1;
421                 }
422                 port_id = (uint8_t)int_fld[FLD_PORT];
423                 if (port_id >= nb_ports) {
424                         printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
425                         return -1;
426                 }
427                 socket_id = (uint8_t)int_fld[FLD_SOCKET];
428                 if (socket_id >= MAX_SOCKET) {
429                         printf("Invalid socket id, range is [0, %d]\n",
430                                 MAX_SOCKET - 1);
431                         return -1;
432                 }
433                 ring_flag = (uint8_t)int_fld[FLD_FLAG];
434                 if ((ring_flag < RX_RING_ONLY) || (ring_flag > RXTX_RING)) {
435                         printf("Invalid ring-flag=%d config for port =%d\n",
436                                 ring_flag,port_id);
437                         return -1;
438                 }
439
440                 switch (ring_flag & RXTX_RING) {
441                 case RX_RING_ONLY:
442                         rxring_numa[port_id] = socket_id;
443                         break;
444                 case TX_RING_ONLY:
445                         txring_numa[port_id] = socket_id;
446                         break;
447                 case RXTX_RING:
448                         rxring_numa[port_id] = socket_id;
449                         txring_numa[port_id] = socket_id;
450                         break;
451                 default:
452                         printf("Invalid ring-flag=%d config for port=%d\n",
453                                 ring_flag,port_id);
454                         break;
455                 }
456         }       
457         
458         return 0;
459 }
460
461 void
462 launch_args_parse(int argc, char** argv)
463 {
464         int n, opt;
465         char **argvopt;
466         int opt_idx;
467         enum { TX, RX };
468
469         static struct option lgopts[] = {
470                 { "help",                       0, 0, 0 },
471                 { "interactive",                0, 0, 0 },
472                 { "eth-peers-configfile",       1, 0, 0 },
473                 { "eth-peer",                   1, 0, 0 },
474                 { "ports",                      1, 0, 0 },
475                 { "nb-cores",                   1, 0, 0 },
476                 { "nb-ports",                   1, 0, 0 },
477                 { "coremask",                   1, 0, 0 },
478                 { "portmask",                   1, 0, 0 },
479                 { "numa",                       0, 0, 0 },
480                 { "port-numa-config",           1, 0, 0 },
481                 { "ring-numa-config",           1, 0, 0 },
482                 { "socket-num",                 1, 0, 0 },      
483                 { "mbuf-size",                  1, 0, 0 },
484                 { "total-num-mbufs",            1, 0, 0 },
485                 { "max-pkt-len",                1, 0, 0 },
486                 { "pkt-filter-mode",            1, 0, 0 },
487                 { "pkt-filter-report-hash",     1, 0, 0 },
488                 { "pkt-filter-size",            1, 0, 0 },
489                 { "pkt-filter-flexbytes-offset",1, 0, 0 },
490                 { "pkt-filter-drop-queue",      1, 0, 0 },
491                 { "crc-strip",                  0, 0, 0 },
492                 { "enable-rx-cksum",            0, 0, 0 },
493                 { "disable-hw-vlan",            0, 0, 0 },
494                 { "enable-drop-en",            0, 0, 0 },
495                 { "disable-rss",                0, 0, 0 },
496                 { "port-topology",              1, 0, 0 },
497                 { "rss-ip",                     0, 0, 0 },
498                 { "rss-udp",                    0, 0, 0 },
499                 { "rxq",                        1, 0, 0 },
500                 { "txq",                        1, 0, 0 },
501                 { "rxd",                        1, 0, 0 },
502                 { "txd",                        1, 0, 0 },
503                 { "burst",                      1, 0, 0 },
504                 { "mbcache",                    1, 0, 0 },
505                 { "txpt",                       1, 0, 0 },
506                 { "txht",                       1, 0, 0 },
507                 { "txwt",                       1, 0, 0 },
508                 { "txfreet",                    1, 0, 0 },
509                 { "txrst",                      1, 0, 0 },
510                 { "txqflags",                   1, 0, 0 },
511                 { "rxpt",                       1, 0, 0 },
512                 { "rxht",                       1, 0, 0 },
513                 { "rxwt",                       1, 0, 0 },
514                 { "rxfreet",                    1, 0, 0 },
515                 { "tx-queue-stats-mapping",     1, 0, 0 },
516                 { "rx-queue-stats-mapping",     1, 0, 0 },
517                 { 0, 0, 0, 0 },
518         };
519
520         argvopt = argv;
521
522         while ((opt = getopt_long(argc, argvopt, "ih",
523                                  lgopts, &opt_idx)) != EOF) {
524                 switch (opt) {
525                 case 'i':
526                         printf("Interactive-mode selected\n");
527                         interactive = 1;
528                         break;
529                 case 0: /*long options */
530                         if (!strcmp(lgopts[opt_idx].name, "help")) {
531                                 usage(argv[0]);
532                                 rte_exit(EXIT_SUCCESS, "Displayed help\n");
533                         }
534                         if (!strcmp(lgopts[opt_idx].name, "interactive")) {
535                                 printf("Interactive-mode selected\n");
536                                 interactive = 1;
537                         }
538                         if (!strcmp(lgopts[opt_idx].name,
539                                     "eth-peers-configfile")) {
540                                 if (init_peer_eth_addrs(optarg) != 0)
541                                         rte_exit(EXIT_FAILURE,
542                                                  "Cannot open logfile\n");
543                         }
544                         if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
545                                 char *port_end;
546                                 uint8_t c, peer_addr[6];
547
548                                 errno = 0;
549                                 n = strtoul(optarg, &port_end, 10);
550                                 if (errno != 0 || port_end == optarg || *port_end++ != ',')
551                                         rte_exit(EXIT_FAILURE,
552                                                  "Invalid eth-peer: %s", optarg);
553                                 if (n >= RTE_MAX_ETHPORTS)
554                                         rte_exit(EXIT_FAILURE,
555                                                  "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
556                                                  n, RTE_MAX_ETHPORTS);
557
558                                 if (cmdline_parse_etheraddr(NULL, port_end, &peer_addr) < 0 )
559                                         rte_exit(EXIT_FAILURE,
560                                                  "Invalid ethernet address: %s\n",
561                                                  port_end);
562                                 for (c = 0; c < 6; c++)
563                                         peer_eth_addrs[n].addr_bytes[c] =
564                                                 peer_addr[c];
565                                 nb_peer_eth_addrs++;
566                         }
567                         if (!strcmp(lgopts[opt_idx].name, "nb-ports")) {
568                                 n = atoi(optarg);
569                                 if (n > 0 && n <= nb_ports)
570                                         nb_fwd_ports = (uint8_t) n;
571                                 else
572                                         rte_exit(EXIT_FAILURE,
573                                                  "nb-ports should be > 0 and <= %d\n",
574                                                  nb_ports);
575                         }
576                         if (!strcmp(lgopts[opt_idx].name, "nb-cores")) {
577                                 n = atoi(optarg);
578                                 if (n > 0 && n <= nb_lcores)
579                                         nb_fwd_lcores = (uint8_t) n;
580                                 else
581                                         rte_exit(EXIT_FAILURE,
582                                                  "nb-cores should be > 0 and <= %d\n",
583                                                  nb_lcores);
584                         }
585                         if (!strcmp(lgopts[opt_idx].name, "coremask"))
586                                 parse_fwd_coremask(optarg);
587                         if (!strcmp(lgopts[opt_idx].name, "portmask"))
588                                 parse_fwd_portmask(optarg);
589                         if (!strcmp(lgopts[opt_idx].name, "numa")) {
590                                 numa_support = 1;
591                                 memset(port_numa,NUMA_NO_CONFIG,RTE_MAX_ETHPORTS);
592                                 memset(rxring_numa,NUMA_NO_CONFIG,RTE_MAX_ETHPORTS);
593                                 memset(txring_numa,NUMA_NO_CONFIG,RTE_MAX_ETHPORTS);
594                         }
595                         if (!strcmp(lgopts[opt_idx].name, "port-numa-config")) {
596                                 if (parse_portnuma_config(optarg))
597                                         rte_exit(EXIT_FAILURE,
598                                            "invalid port-numa configuration\n");
599                         }
600                         if (!strcmp(lgopts[opt_idx].name, "ring-numa-config"))
601                                 if (parse_ringnuma_config(optarg))
602                                         rte_exit(EXIT_FAILURE,
603                                            "invalid ring-numa configuration\n");
604                         if (!strcmp(lgopts[opt_idx].name, "socket-num")) {
605                                 n = atoi(optarg);
606                                 if(n < MAX_SOCKET)
607                                         socket_num = (uint8_t)n;
608                                 else
609                                         rte_exit(EXIT_FAILURE,
610                                                 "The socket number should be < %d\n",
611                                                 MAX_SOCKET);
612                         }
613                         if (!strcmp(lgopts[opt_idx].name, "mbuf-size")) {
614                                 n = atoi(optarg);
615                                 if (n > 0 && n <= 0xFFFF)
616                                         mbuf_data_size = (uint16_t) n;
617                                 else
618                                         rte_exit(EXIT_FAILURE,
619                                                  "mbuf-size should be > 0 and < 65536\n");
620                         }
621                         if (!strcmp(lgopts[opt_idx].name, "total-num-mbufs")) {
622                                 n = atoi(optarg);
623                                 if (n > 1024)
624                                         param_total_num_mbufs = (unsigned)n;
625                                 else
626                                         rte_exit(EXIT_FAILURE,
627                                                  "total-num-mbufs should be > 1024\n");
628                         }
629                         if (!strcmp(lgopts[opt_idx].name, "max-pkt-len")) {
630                                 n = atoi(optarg);
631                                 if (n >= ETHER_MIN_LEN) {
632                                         rx_mode.max_rx_pkt_len = (uint32_t) n;
633                                         if (n > ETHER_MAX_LEN)
634                                             rx_mode.jumbo_frame = 1;
635                                 } else
636                                         rte_exit(EXIT_FAILURE,
637                                                  "Invalid max-pkt-len=%d - should be > %d\n",
638                                                  n, ETHER_MIN_LEN);
639                         }
640                         if (!strcmp(lgopts[opt_idx].name, "pkt-filter-mode")) {
641                                 if (!strcmp(optarg, "signature"))
642                                         fdir_conf.mode =
643                                                 RTE_FDIR_MODE_SIGNATURE;
644                                 else if (!strcmp(optarg, "perfect"))
645                                         fdir_conf.mode = RTE_FDIR_MODE_PERFECT;
646                                 else if (!strcmp(optarg, "none"))
647                                         fdir_conf.mode = RTE_FDIR_MODE_NONE;
648                                 else
649                                         rte_exit(EXIT_FAILURE,
650                                                  "pkt-mode-invalid %s invalid - must be: "
651                                                  "none, signature or perfect\n",
652                                                  optarg);
653                         }
654                         if (!strcmp(lgopts[opt_idx].name,
655                                     "pkt-filter-report-hash")) {
656                                 if (!strcmp(optarg, "none"))
657                                         fdir_conf.status =
658                                                 RTE_FDIR_NO_REPORT_STATUS;
659                                 else if (!strcmp(optarg, "match"))
660                                         fdir_conf.status =
661                                                 RTE_FDIR_REPORT_STATUS;
662                                 else if (!strcmp(optarg, "always"))
663                                         fdir_conf.status =
664                                                 RTE_FDIR_REPORT_STATUS_ALWAYS;
665                                 else
666                                         rte_exit(EXIT_FAILURE,
667                                                  "pkt-filter-report-hash %s invalid "
668                                                  "- must be: none or match or always\n",
669                                                  optarg);
670                         }
671                         if (!strcmp(lgopts[opt_idx].name, "pkt-filter-size")) {
672                                 if (!strcmp(optarg, "64K"))
673                                         fdir_conf.pballoc =
674                                                 RTE_FDIR_PBALLOC_64K;
675                                 else if (!strcmp(optarg, "128K"))
676                                         fdir_conf.pballoc =
677                                                 RTE_FDIR_PBALLOC_128K;
678                                 else if (!strcmp(optarg, "256K"))
679                                         fdir_conf.pballoc =
680                                                 RTE_FDIR_PBALLOC_256K;
681                                 else
682                                         rte_exit(EXIT_FAILURE, "pkt-filter-size %s invalid -"
683                                                  " must be: 64K or 128K or 256K\n",
684                                                  optarg);
685                         }
686                         if (!strcmp(lgopts[opt_idx].name,
687                                     "pkt-filter-flexbytes-offset")) {
688                                 n = atoi(optarg);
689                                 if ( n >= 0 && n <= (int) 32)
690                                         fdir_conf.flexbytes_offset =
691                                                 (uint8_t) n;
692                                 else
693                                         rte_exit(EXIT_FAILURE,
694                                                  "flexbytes %d invalid - must"
695                                                  "be  >= 0 && <= 32\n", n);
696                         }
697                         if (!strcmp(lgopts[opt_idx].name,
698                                     "pkt-filter-drop-queue")) {
699                                 n = atoi(optarg);
700                                 if (n >= 0)
701                                         fdir_conf.drop_queue = (uint8_t) n;
702                                 else
703                                         rte_exit(EXIT_FAILURE,
704                                                  "drop queue %d invalid - must"
705                                                  "be >= 0 \n", n);
706                         }
707                         if (!strcmp(lgopts[opt_idx].name, "crc-strip"))
708                                 rx_mode.hw_strip_crc = 1;
709                         if (!strcmp(lgopts[opt_idx].name, "enable-rx-cksum"))
710                                 rx_mode.hw_ip_checksum = 1;
711
712                         if (!strcmp(lgopts[opt_idx].name, "disable-hw-vlan")) {
713                                 rx_mode.hw_vlan_filter = 0;
714                                 rx_mode.hw_vlan_strip  = 0;
715                                 rx_mode.hw_vlan_extend = 0;
716                         }
717
718                         if (!strcmp(lgopts[opt_idx].name, "enable-drop-en"))
719                                 rx_drop_en = 1;
720
721                         if (!strcmp(lgopts[opt_idx].name, "disable-rss"))
722                                 rss_hf = 0;
723                         if (!strcmp(lgopts[opt_idx].name, "port-topology")) {
724                                 if (!strcmp(optarg, "paired"))
725                                         port_topology = PORT_TOPOLOGY_PAIRED;
726                                 else if (!strcmp(optarg, "chained"))
727                                         port_topology = PORT_TOPOLOGY_CHAINED;
728                                 else
729                                         rte_exit(EXIT_FAILURE, "port-topology %s invalid -"
730                                                  " must be: paired or chained \n",
731                                                  optarg);
732                         }
733                         if (!strcmp(lgopts[opt_idx].name, "rss-ip"))
734                                 rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6;
735                         if (!strcmp(lgopts[opt_idx].name, "rss-udp"))
736                                 rss_hf = ETH_RSS_IPV4 |
737                                                 ETH_RSS_IPV6 | ETH_RSS_IPV4_UDP;
738                         if (!strcmp(lgopts[opt_idx].name, "rxq")) {
739                                 n = atoi(optarg);
740                                 if (n >= 1 && n <= (int) MAX_QUEUE_ID)
741                                         nb_rxq = (queueid_t) n;
742                                 else
743                                         rte_exit(EXIT_FAILURE, "rxq %d invalid - must be"
744                                                   " >= 1 && <= %d\n", n,
745                                                   (int) MAX_QUEUE_ID);
746                         }
747                         if (!strcmp(lgopts[opt_idx].name, "txq")) {
748                                 n = atoi(optarg);
749                                 if (n >= 1 && n <= (int) MAX_QUEUE_ID)
750                                         nb_txq = (queueid_t) n;
751                                 else
752                                         rte_exit(EXIT_FAILURE, "txq %d invalid - must be"
753                                                   " >= 1 && <= %d\n", n,
754                                                   (int) MAX_QUEUE_ID);
755                         }
756                         if (!strcmp(lgopts[opt_idx].name, "rxd")) {
757                                 n = atoi(optarg);
758                                 if (n > 0)
759                                         nb_rxd = (uint16_t) n;
760                                 else
761                                         rte_exit(EXIT_FAILURE, "rxd must be > 0\n");
762                         }
763                         if (!strcmp(lgopts[opt_idx].name, "txd")) {
764                                 n = atoi(optarg);
765                                 if (n > 0)
766                                         nb_txd = (uint16_t) n;
767                                 else
768                                         rte_exit(EXIT_FAILURE, "txd must be in > 0\n");
769                         }
770                         if (!strcmp(lgopts[opt_idx].name, "burst")) {
771                                 n = atoi(optarg);
772                                 if ((n >= 1) && (n <= MAX_PKT_BURST))
773                                         nb_pkt_per_burst = (uint16_t) n;
774                                 else
775                                         rte_exit(EXIT_FAILURE,
776                                                  "burst must >= 1 and <= %d]",
777                                                  MAX_PKT_BURST);
778                         }
779                         if (!strcmp(lgopts[opt_idx].name, "mbcache")) {
780                                 n = atoi(optarg);
781                                 if ((n >= 0) &&
782                                     (n <= RTE_MEMPOOL_CACHE_MAX_SIZE))
783                                         mb_mempool_cache = (uint16_t) n;
784                                 else
785                                         rte_exit(EXIT_FAILURE,
786                                                  "mbcache must be >= 0 and <= %d\n",
787                                                  RTE_MEMPOOL_CACHE_MAX_SIZE);
788                         }
789                         if (!strcmp(lgopts[opt_idx].name, "txpt")) {
790                                 n = atoi(optarg);
791                                 if (n >= 0)
792                                         tx_thresh.pthresh = (uint8_t)n;
793                                 else
794                                         rte_exit(EXIT_FAILURE, "txpt must be >= 0\n");
795                         }
796                         if (!strcmp(lgopts[opt_idx].name, "txht")) {
797                                 n = atoi(optarg);
798                                 if (n >= 0)
799                                         tx_thresh.hthresh = (uint8_t)n;
800                                 else
801                                         rte_exit(EXIT_FAILURE, "txht must be >= 0\n");
802                         }
803                         if (!strcmp(lgopts[opt_idx].name, "txwt")) {
804                                 n = atoi(optarg);
805                                 if (n >= 0)
806                                         tx_thresh.wthresh = (uint8_t)n;
807                                 else
808                                         rte_exit(EXIT_FAILURE, "txwt must be >= 0\n");
809                         }
810                         if (!strcmp(lgopts[opt_idx].name, "txfreet")) {
811                                 n = atoi(optarg);
812                                 if (n >= 0)
813                                         tx_free_thresh = (uint16_t)n;
814                                 else
815                                         rte_exit(EXIT_FAILURE, "txfreet must be >= 0\n");
816                         }
817                         if (!strcmp(lgopts[opt_idx].name, "txrst")) {
818                                 n = atoi(optarg);
819                                 if (n >= 0)
820                                         tx_rs_thresh = (uint16_t)n;
821                                 else
822                                         rte_exit(EXIT_FAILURE, "txrst must be >= 0\n");
823                         }
824                         if (!strcmp(lgopts[opt_idx].name, "txqflags")) {
825                                 char *end = NULL;
826                                 n = strtoul(optarg, &end, 16);
827                                 if (n >= 0)
828                                         txq_flags = (uint32_t)n;
829                                 else
830                                         rte_exit(EXIT_FAILURE,
831                                                  "txqflags must be >= 0\n");
832                         }
833                         if (!strcmp(lgopts[opt_idx].name, "rxpt")) {
834                                 n = atoi(optarg);
835                                 if (n >= 0)
836                                         rx_thresh.pthresh = (uint8_t)n;
837                                 else
838                                         rte_exit(EXIT_FAILURE, "rxpt must be >= 0\n");
839                         }
840                         if (!strcmp(lgopts[opt_idx].name, "rxht")) {
841                                 n = atoi(optarg);
842                                 if (n >= 0)
843                                         rx_thresh.hthresh = (uint8_t)n;
844                                 else
845                                         rte_exit(EXIT_FAILURE, "rxht must be >= 0\n");
846                         }
847                         if (!strcmp(lgopts[opt_idx].name, "rxwt")) {
848                                 n = atoi(optarg);
849                                 if (n >= 0)
850                                         rx_thresh.wthresh = (uint8_t)n;
851                                 else
852                                         rte_exit(EXIT_FAILURE, "rxwt must be >= 0\n");
853                         }
854                         if (!strcmp(lgopts[opt_idx].name, "rxd")) {
855                                 n = atoi(optarg);
856                                 if (n > 0) {
857                                         if (rx_free_thresh >= n)
858                                                 rte_exit(EXIT_FAILURE,
859                                                          "rxd must be > "
860                                                          "rx_free_thresh(%d)\n",
861                                                          (int)rx_free_thresh);
862                                         else
863                                                 nb_rxd = (uint16_t) n;
864                                 } else
865                                         rte_exit(EXIT_FAILURE,
866                                                  "rxd(%d) invalid - must be > 0\n",
867                                                  n);
868                         }
869                         if (!strcmp(lgopts[opt_idx].name, "txd")) {
870                                 n = atoi(optarg);
871                                 if (n > 0)
872                                         nb_txd = (uint16_t) n;
873                                 else
874                                         rte_exit(EXIT_FAILURE, "txd must be in > 0\n");
875                         }
876                         if (!strcmp(lgopts[opt_idx].name, "txpt")) {
877                                 n = atoi(optarg);
878                                 if (n >= 0)
879                                         tx_thresh.pthresh = (uint8_t)n;
880                                 else
881                                         rte_exit(EXIT_FAILURE, "txpt must be >= 0\n");
882                         }
883                         if (!strcmp(lgopts[opt_idx].name, "txht")) {
884                                 n = atoi(optarg);
885                                 if (n >= 0)
886                                         tx_thresh.hthresh = (uint8_t)n;
887                                 else
888                                         rte_exit(EXIT_FAILURE, "txht must be >= 0\n");
889                         }
890                         if (!strcmp(lgopts[opt_idx].name, "txwt")) {
891                                 n = atoi(optarg);
892                                 if (n >= 0)
893                                         tx_thresh.wthresh = (uint8_t)n;
894                                 else
895                                         rte_exit(EXIT_FAILURE, "txwt must be >= 0\n");
896                         }
897                         if (!strcmp(lgopts[opt_idx].name, "rxpt")) {
898                                 n = atoi(optarg);
899                                 if (n >= 0)
900                                         rx_thresh.pthresh = (uint8_t)n;
901                                 else
902                                         rte_exit(EXIT_FAILURE, "rxpt must be >= 0\n");
903                         }
904                         if (!strcmp(lgopts[opt_idx].name, "rxht")) {
905                                 n = atoi(optarg);
906                                 if (n >= 0)
907                                         rx_thresh.hthresh = (uint8_t)n;
908                                 else
909                                         rte_exit(EXIT_FAILURE, "rxht must be >= 0\n");
910                         }
911                         if (!strcmp(lgopts[opt_idx].name, "rxwt")) {
912                                 n = atoi(optarg);
913                                 if (n >= 0)
914                                         rx_thresh.wthresh = (uint8_t)n;
915                                 else
916                                         rte_exit(EXIT_FAILURE, "rxwt must be >= 0\n");
917                         }
918                         if (!strcmp(lgopts[opt_idx].name, "rxfreet")) {
919                                 n = atoi(optarg);
920                                 if (n >= 0)
921                                         rx_free_thresh = (uint16_t)n;
922                                 else
923                                         rte_exit(EXIT_FAILURE, "rxfreet must be >= 0\n");
924                         }
925                         if (!strcmp(lgopts[opt_idx].name, "tx-queue-stats-mapping")) {
926                                 if (parse_queue_stats_mapping_config(optarg, TX)) {
927                                         rte_exit(EXIT_FAILURE,
928                                                  "invalid TX queue statistics mapping config entered\n");
929                                 }
930                         }
931                         if (!strcmp(lgopts[opt_idx].name, "rx-queue-stats-mapping")) {
932                                 if (parse_queue_stats_mapping_config(optarg, RX)) {
933                                         rte_exit(EXIT_FAILURE,
934                                                  "invalid RX queue statistics mapping config entered\n");
935                                 }
936                         }
937                         break;
938                 case 'h':
939                         usage(argv[0]);
940                         rte_exit(EXIT_SUCCESS, "Displayed help\n");
941                         break;
942                 default:
943                         usage(argv[0]);
944                         rte_exit(EXIT_FAILURE,
945                                  "Command line is incomplete or incorrect\n");
946                         break;
947                 }
948         }
949 }