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