app/testpmd: allow txpkts to be setup via command line
[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
79 #include "testpmd.h"
80
81 static void
82 usage(char* progname)
83 {
84         printf("usage: %s "
85 #ifdef RTE_LIBRTE_CMDLINE
86                "[--interactive|-i] "
87 #endif
88                "[--help|-h] | [--auto-start|-a] | ["
89                "--coremask=COREMASK --portmask=PORTMASK --numa "
90                "--mbuf-size= | --total-num-mbufs= | "
91                "--nb-cores= | --nb-ports= | "
92 #ifdef RTE_LIBRTE_CMDLINE
93                "--eth-peers-configfile= | "
94                "--eth-peer=X,M:M:M:M:M:M | "
95 #endif
96                "--pkt-filter-mode= |"
97                "--rss-ip | --rss-udp | "
98                "--rxpt= | --rxht= | --rxwt= | --rxfreet= | "
99                "--txpt= | --txht= | --txwt= | --txfreet= | "
100                "--txrst= | --txqflags= ]\n",
101                progname);
102 #ifdef RTE_LIBRTE_CMDLINE
103         printf("  --interactive: run in interactive mode.\n");
104 #endif
105         printf("  --auto-start: start forwarding on init "
106                "[always when non-interactive].\n");
107         printf("  --help: display this message and quit.\n");
108         printf("  --nb-cores=N: set the number of forwarding cores "
109                "(1 <= N <= %d).\n", nb_lcores);
110         printf("  --nb-ports=N: set the number of forwarding ports "
111                "(1 <= N <= %d).\n", nb_ports);
112         printf("  --coremask=COREMASK: hexadecimal bitmask of cores running "
113                "the packet forwarding test. The master lcore is reserved for "
114                "command line parsing only, and cannot be masked on for "
115                "packet forwarding.\n");
116         printf("  --portmask=PORTMASK: hexadecimal bitmask of ports used "
117                "by the packet forwarding test.\n");
118         printf("  --numa: enable NUMA-aware allocation of RX/TX rings and of "
119                "RX memory buffers (mbufs).\n");
120         printf("  --port-numa-config=(port,socket)[,(port,socket)]: "
121                "specify the socket on which the memory pool "
122                "used by the port will be allocated.\n");
123         printf("  --ring-numa-config=(port,flag,socket)[,(port,flag,socket)]: "
124                "specify the socket on which the TX/RX rings for "
125                "the port will be allocated "
126                "(flag: 1 for RX; 2 for TX; 3 for RX and TX).\n");
127         printf("  --socket-num=N: set socket from which all memory is allocated "
128                "in NUMA mode.\n");
129         printf("  --mbuf-size=N: set the data size of mbuf to N bytes.\n");
130         printf("  --total-num-mbufs=N: set the number of mbufs to be allocated "
131                "in mbuf pools.\n");
132         printf("  --max-pkt-len=N: set the maximum size of packet to N bytes.\n");
133 #ifdef RTE_LIBRTE_CMDLINE
134         printf("  --eth-peers-configfile=name: config file with ethernet addresses "
135                "of peer ports.\n");
136         printf("  --eth-peer=X,M:M:M:M:M:M: set the MAC address of the X peer "
137                "port (0 <= X < %d).\n", RTE_MAX_ETHPORTS);
138 #endif
139         printf("  --pkt-filter-mode=N: set Flow Director mode "
140                "(N: none (default mode) or signature or perfect).\n");
141         printf("  --pkt-filter-report-hash=N: set Flow Director report mode "
142                "(N: none  or match (default) or always).\n");
143         printf("  --pkt-filter-size=N: set Flow Director mode "
144                "(N: 64K (default mode) or 128K or 256K).\n");
145         printf("  --pkt-filter-flexbytes-offset=N: set flexbytes-offset. "
146                "The offset is defined in word units counted from the "
147                "first byte of the destination Ethernet MAC address. "
148                "0 <= N <= 32.\n");
149         printf("  --pkt-filter-drop-queue=N: set drop-queue. "
150                "In perfect mode, when you add a rule with queue = -1 "
151                "the packet will be enqueued into the rx drop-queue. "
152                "If the drop-queue doesn't exist, the packet is dropped. "
153                "By default drop-queue=127.\n");
154         printf("  --crc-strip: enable CRC stripping by hardware.\n");
155         printf("  --enable-rx-cksum: enable rx hardware checksum offload.\n");
156         printf("  --disable-hw-vlan: disable hardware vlan.\n");
157         printf("  --enable-drop-en: enable per queue packet drop.\n");
158         printf("  --disable-rss: disable rss.\n");
159         printf("  --port-topology=N: set port topology (N: paired (default) or "
160                "chained).\n");
161         printf("  --forward-mode=N: set forwarding mode (N: %s).\n",
162                list_pkt_forwarding_modes());
163         printf("  --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
164         printf("  --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
165         printf("  --rxq=N: set the number of RX queues per port to N.\n");
166         printf("  --rxd=N: set the number of descriptors in RX rings to N.\n");
167         printf("  --txq=N: set the number of TX queues per port to N.\n");
168         printf("  --txd=N: set the number of descriptors in TX rings to N.\n");
169         printf("  --burst=N: set the number of packets per burst to N.\n");
170         printf("  --mbcache=N: set the cache of mbuf memory pool to N.\n");
171         printf("  --rxpt=N: set prefetch threshold register of RX rings to N "
172                "(0 <= N <= 16).\n");
173         printf("  --rxht=N: set the host threshold register of RX rings to N "
174                "(0 <= N <= 16).\n");
175         printf("  --rxfreet=N: set the free threshold of RX descriptors to N "
176                "(0 <= N < value of rxd).\n");
177         printf("  --rxwt=N: set the write-back threshold register of RX rings "
178                "to N (0 <= N <= 16).\n");
179         printf("  --txpt=N: set the prefetch threshold register of TX rings "
180                "to N (0 <= N <= 16).\n");
181         printf("  --txht=N: set the nhost threshold register of TX rings to N "
182                "(0 <= N <= 16).\n");
183         printf("  --txwt=N: set the write-back threshold register of TX rings "
184                "to N (0 <= N <= 16).\n");
185         printf("  --txfreet=N: set the transmit free threshold of TX rings to N "
186                "(0 <= N <= value of txd).\n");
187         printf("  --txrst=N: set the transmit RS bit threshold of TX rings to N "
188                "(0 <= N <= value of txd).\n");
189         printf("  --txqflags=0xXXXXXXXX: hexadecimal bitmask of TX queue flags "
190                "(0 <= N <= 0x7FFFFFFF).\n");
191         printf("  --tx-queue-stats-mapping=(port,queue,mapping)[,(port,queue,mapping]: "
192                "tx queues statistics counters mapping "
193                "(0 <= mapping <= %d).\n", RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
194         printf("  --rx-queue-stats-mapping=(port,queue,mapping)[,(port,queue,mapping]: "
195                "rx queues statistics counters mapping "
196                "(0 <= mapping <= %d).\n", RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
197         printf("  --no-flush-rx: Don't flush RX streams before forwarding."
198                " Used mainly with PCAP drivers.\n");
199         printf("  --txpkts=X[,Y]*: set TX segment sizes.\n");
200 }
201
202 #ifdef RTE_LIBRTE_CMDLINE
203 static int
204 init_peer_eth_addrs(char *config_filename)
205 {
206         FILE *config_file;
207         portid_t i;
208         char buf[50];
209
210         config_file = fopen(config_filename, "r");
211         if (config_file == NULL) {
212                 perror("Failed to open eth config file\n");
213                 return -1;
214         }
215
216         for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
217
218                 if (fgets(buf, sizeof(buf), config_file) == NULL)
219                         break;
220
221                 if (cmdline_parse_etheraddr(NULL, buf, &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                 rte_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 ? (nb_rx_queue_stats_mappings >= MAX_RX_QUEUE_STATS_MAPPINGS) :
318                     (nb_tx_queue_stats_mappings >= MAX_TX_QUEUE_STATS_MAPPINGS)) {
319                         printf("exceeded max number of %s queue statistics mappings: %hu\n",
320                                is_rx ? "RX" : "TX",
321                                is_rx ? nb_rx_queue_stats_mappings : nb_tx_queue_stats_mappings);
322                         return -1;
323                 }
324                 if (!is_rx) {
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                         rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].port_id =
335                                 (uint8_t)int_fld[FLD_PORT];
336                         rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].queue_id =
337                                 (uint8_t)int_fld[FLD_QUEUE];
338                         rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].stats_counter_id =
339                                 (uint8_t)int_fld[FLD_STATS_COUNTER];
340                         ++nb_rx_queue_stats_mappings;
341                 }
342
343         }
344 /* Reassign the rx/tx_queue_stats_mappings pointer to point to this newly populated array rather */
345 /* than to the default array (that was set at its definition) */
346         is_rx ? (rx_queue_stats_mappings = rx_queue_stats_mappings_array) :
347                 (tx_queue_stats_mappings = tx_queue_stats_mappings_array);
348         return 0;
349 }
350
351 static int
352 parse_portnuma_config(const char *q_arg)
353 {
354         char s[256];
355         const char *p, *p0 = q_arg;
356         char *end;
357         uint8_t i,port_id,socket_id;
358         unsigned size;
359         enum fieldnames {
360                 FLD_PORT = 0,
361                 FLD_SOCKET,
362                 _NUM_FLD
363         };
364         unsigned long int_fld[_NUM_FLD];
365         char *str_fld[_NUM_FLD];        
366
367         /* reset from value set at definition */
368         while ((p = strchr(p0,'(')) != NULL) {
369                 ++p;
370                 if((p0 = strchr(p,')')) == NULL)
371                         return -1;
372
373                 size = p0 - p;
374                 if(size >= sizeof(s))
375                         return -1;
376
377                 rte_snprintf(s, sizeof(s), "%.*s", size, p);
378                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
379                         return -1;
380                 for (i = 0; i < _NUM_FLD; i++) {
381                         errno = 0;
382                         int_fld[i] = strtoul(str_fld[i], &end, 0);
383                         if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
384                                 return -1;
385                 }
386                 port_id = (uint8_t)int_fld[FLD_PORT];
387                 if (port_id >= nb_ports) {
388                         printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
389                         return -1;
390                 }
391                 socket_id = (uint8_t)int_fld[FLD_SOCKET];
392                 if(socket_id >= MAX_SOCKET) {
393                         printf("Invalid socket id, range is [0, %d]\n",
394                                  MAX_SOCKET - 1);
395                         return -1;
396                 }
397                 port_numa[port_id] = socket_id;
398         }
399
400         return 0;
401 }
402
403 static int
404 parse_ringnuma_config(const char *q_arg)
405 {
406         char s[256];
407         const char *p, *p0 = q_arg;
408         char *end;
409         uint8_t i,port_id,ring_flag,socket_id;
410         unsigned size;
411         enum fieldnames {
412                 FLD_PORT = 0,
413                 FLD_FLAG,
414                 FLD_SOCKET,
415                 _NUM_FLD
416         };
417         unsigned long int_fld[_NUM_FLD];
418         char *str_fld[_NUM_FLD];        
419         #define RX_RING_ONLY 0x1
420         #define TX_RING_ONLY 0x2
421         #define RXTX_RING    0x3
422
423         /* reset from value set at definition */
424         while ((p = strchr(p0,'(')) != NULL) {
425                 ++p;
426                 if((p0 = strchr(p,')')) == NULL)
427                         return -1;
428
429                 size = p0 - p;
430                 if(size >= sizeof(s))
431                         return -1;
432
433                 rte_snprintf(s, sizeof(s), "%.*s", size, p);
434                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
435                         return -1;
436                 for (i = 0; i < _NUM_FLD; i++) {
437                         errno = 0;
438                         int_fld[i] = strtoul(str_fld[i], &end, 0);
439                         if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
440                                 return -1;
441                 }
442                 port_id = (uint8_t)int_fld[FLD_PORT];
443                 if (port_id >= nb_ports) {
444                         printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
445                         return -1;
446                 }
447                 socket_id = (uint8_t)int_fld[FLD_SOCKET];
448                 if (socket_id >= MAX_SOCKET) {
449                         printf("Invalid socket id, range is [0, %d]\n",
450                                 MAX_SOCKET - 1);
451                         return -1;
452                 }
453                 ring_flag = (uint8_t)int_fld[FLD_FLAG];
454                 if ((ring_flag < RX_RING_ONLY) || (ring_flag > RXTX_RING)) {
455                         printf("Invalid ring-flag=%d config for port =%d\n",
456                                 ring_flag,port_id);
457                         return -1;
458                 }
459
460                 switch (ring_flag & RXTX_RING) {
461                 case RX_RING_ONLY:
462                         rxring_numa[port_id] = socket_id;
463                         break;
464                 case TX_RING_ONLY:
465                         txring_numa[port_id] = socket_id;
466                         break;
467                 case RXTX_RING:
468                         rxring_numa[port_id] = socket_id;
469                         txring_numa[port_id] = socket_id;
470                         break;
471                 default:
472                         printf("Invalid ring-flag=%d config for port=%d\n",
473                                 ring_flag,port_id);
474                         break;
475                 }
476         }       
477         
478         return 0;
479 }
480
481 static unsigned int
482 parse_item_list(char* str, unsigned int max_items, unsigned int *parsed_items)
483 {
484         unsigned int nb_item;
485         unsigned int value;
486         unsigned int i;
487         int value_ok;
488         char c;
489
490         /*
491          * First parse all items in the list and store their value.
492          */
493         value = 0;
494         nb_item = 0;
495         value_ok = 0;
496         for (i = 0; i < strlen(str); i++) {
497                 c = str[i];
498                 if ((c >= '0') && (c <= '9')) {
499                         value = (unsigned int) (value * 10 + (c - '0'));
500                         value_ok = 1;
501                         continue;
502                 }
503                 if (c != ',') {
504                         printf("character %c is not a decimal digit\n", c);
505                         return (0);
506                 }
507                 if (! value_ok) {
508                         printf("No valid value before comma\n");
509                         return (0);
510                 }
511                 if (nb_item < max_items) {
512                         parsed_items[nb_item] = value;
513                         value_ok = 0;
514                         value = 0;
515                 }
516                 nb_item++;
517         }
518
519         if (nb_item >= max_items)
520                 rte_exit(EXIT_FAILURE, "too many txpkt segments!\n");
521
522         parsed_items[nb_item++] = value;
523
524         return (nb_item);
525 }
526
527 void
528 launch_args_parse(int argc, char** argv)
529 {
530         int n, opt;
531         char **argvopt;
532         int opt_idx;
533         enum { TX, RX };
534
535         static struct option lgopts[] = {
536                 { "help",                       0, 0, 0 },
537 #ifdef RTE_LIBRTE_CMDLINE
538                 { "interactive",                0, 0, 0 },
539                 { "auto-start",                 0, 0, 0 },
540                 { "eth-peers-configfile",       1, 0, 0 },
541                 { "eth-peer",                   1, 0, 0 },
542 #endif
543                 { "ports",                      1, 0, 0 },
544                 { "nb-cores",                   1, 0, 0 },
545                 { "nb-ports",                   1, 0, 0 },
546                 { "coremask",                   1, 0, 0 },
547                 { "portmask",                   1, 0, 0 },
548                 { "numa",                       0, 0, 0 },
549                 { "mp-anon",                    0, 0, 0 },
550                 { "port-numa-config",           1, 0, 0 },
551                 { "ring-numa-config",           1, 0, 0 },
552                 { "socket-num",                 1, 0, 0 },      
553                 { "mbuf-size",                  1, 0, 0 },
554                 { "total-num-mbufs",            1, 0, 0 },
555                 { "max-pkt-len",                1, 0, 0 },
556                 { "pkt-filter-mode",            1, 0, 0 },
557                 { "pkt-filter-report-hash",     1, 0, 0 },
558                 { "pkt-filter-size",            1, 0, 0 },
559                 { "pkt-filter-flexbytes-offset",1, 0, 0 },
560                 { "pkt-filter-drop-queue",      1, 0, 0 },
561                 { "crc-strip",                  0, 0, 0 },
562                 { "enable-rx-cksum",            0, 0, 0 },
563                 { "disable-hw-vlan",            0, 0, 0 },
564                 { "enable-drop-en",            0, 0, 0 },
565                 { "disable-rss",                0, 0, 0 },
566                 { "port-topology",              1, 0, 0 },
567                 { "forward-mode",               1, 0, 0 },
568                 { "rss-ip",                     0, 0, 0 },
569                 { "rss-udp",                    0, 0, 0 },
570                 { "rxq",                        1, 0, 0 },
571                 { "txq",                        1, 0, 0 },
572                 { "rxd",                        1, 0, 0 },
573                 { "txd",                        1, 0, 0 },
574                 { "burst",                      1, 0, 0 },
575                 { "mbcache",                    1, 0, 0 },
576                 { "txpt",                       1, 0, 0 },
577                 { "txht",                       1, 0, 0 },
578                 { "txwt",                       1, 0, 0 },
579                 { "txfreet",                    1, 0, 0 },
580                 { "txrst",                      1, 0, 0 },
581                 { "txqflags",                   1, 0, 0 },
582                 { "rxpt",                       1, 0, 0 },
583                 { "rxht",                       1, 0, 0 },
584                 { "rxwt",                       1, 0, 0 },
585                 { "rxfreet",                    1, 0, 0 },
586                 { "tx-queue-stats-mapping",     1, 0, 0 },
587                 { "rx-queue-stats-mapping",     1, 0, 0 },
588                 { "no-flush-rx",        0, 0, 0 },
589                 { "txpkts",                     1, 0, 0 },
590                 { 0, 0, 0, 0 },
591         };
592
593         argvopt = argv;
594
595 #ifdef RTE_LIBRTE_CMDLINE
596 #define SHORTOPTS "i"
597 #else
598 #define SHORTOPTS ""
599 #endif
600         while ((opt = getopt_long(argc, argvopt, SHORTOPTS "ah",
601                                  lgopts, &opt_idx)) != EOF) {
602                 switch (opt) {
603 #ifdef RTE_LIBRTE_CMDLINE
604                 case 'i':
605                         printf("Interactive-mode selected\n");
606                         interactive = 1;
607                         break;
608 #endif
609                 case 'a':
610                         printf("Auto-start selected\n");
611                         auto_start = 1;
612                         break;
613
614                 case 0: /*long options */
615                         if (!strcmp(lgopts[opt_idx].name, "help")) {
616                                 usage(argv[0]);
617                                 rte_exit(EXIT_SUCCESS, "Displayed help\n");
618                         }
619 #ifdef RTE_LIBRTE_CMDLINE
620                         if (!strcmp(lgopts[opt_idx].name, "interactive")) {
621                                 printf("Interactive-mode selected\n");
622                                 interactive = 1;
623                         }
624                         if (!strcmp(lgopts[opt_idx].name, "auto-start")) {
625                                 printf("Auto-start selected\n");
626                                 auto_start = 1;
627                         }
628                         if (!strcmp(lgopts[opt_idx].name,
629                                     "eth-peers-configfile")) {
630                                 if (init_peer_eth_addrs(optarg) != 0)
631                                         rte_exit(EXIT_FAILURE,
632                                                  "Cannot open logfile\n");
633                         }
634                         if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
635                                 char *port_end;
636                                 uint8_t c, peer_addr[6];
637
638                                 errno = 0;
639                                 n = strtoul(optarg, &port_end, 10);
640                                 if (errno != 0 || port_end == optarg || *port_end++ != ',')
641                                         rte_exit(EXIT_FAILURE,
642                                                  "Invalid eth-peer: %s", optarg);
643                                 if (n >= RTE_MAX_ETHPORTS)
644                                         rte_exit(EXIT_FAILURE,
645                                                  "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
646                                                  n, RTE_MAX_ETHPORTS);
647
648                                 if (cmdline_parse_etheraddr(NULL, port_end, &peer_addr) < 0 )
649                                         rte_exit(EXIT_FAILURE,
650                                                  "Invalid ethernet address: %s\n",
651                                                  port_end);
652                                 for (c = 0; c < 6; c++)
653                                         peer_eth_addrs[n].addr_bytes[c] =
654                                                 peer_addr[c];
655                                 nb_peer_eth_addrs++;
656                         }
657 #endif
658                         if (!strcmp(lgopts[opt_idx].name, "nb-ports")) {
659                                 n = atoi(optarg);
660                                 if (n > 0 && n <= nb_ports)
661                                         nb_fwd_ports = (uint8_t) n;
662                                 else
663                                         rte_exit(EXIT_FAILURE,
664                                                  "nb-ports should be > 0 and <= %d\n",
665                                                  nb_ports);
666                         }
667                         if (!strcmp(lgopts[opt_idx].name, "nb-cores")) {
668                                 n = atoi(optarg);
669                                 if (n > 0 && n <= nb_lcores)
670                                         nb_fwd_lcores = (uint8_t) n;
671                                 else
672                                         rte_exit(EXIT_FAILURE,
673                                                  "nb-cores should be > 0 and <= %d\n",
674                                                  nb_lcores);
675                         }
676                         if (!strcmp(lgopts[opt_idx].name, "coremask"))
677                                 parse_fwd_coremask(optarg);
678                         if (!strcmp(lgopts[opt_idx].name, "portmask"))
679                                 parse_fwd_portmask(optarg);
680                         if (!strcmp(lgopts[opt_idx].name, "numa")) {
681                                 numa_support = 1;
682                                 memset(port_numa,NUMA_NO_CONFIG,RTE_MAX_ETHPORTS);
683                                 memset(rxring_numa,NUMA_NO_CONFIG,RTE_MAX_ETHPORTS);
684                                 memset(txring_numa,NUMA_NO_CONFIG,RTE_MAX_ETHPORTS);
685                         }
686                         if (!strcmp(lgopts[opt_idx].name, "mp-anon")) {
687                                 mp_anon = 1;
688                         }
689                         if (!strcmp(lgopts[opt_idx].name, "port-numa-config")) {
690                                 if (parse_portnuma_config(optarg))
691                                         rte_exit(EXIT_FAILURE,
692                                            "invalid port-numa configuration\n");
693                         }
694                         if (!strcmp(lgopts[opt_idx].name, "ring-numa-config"))
695                                 if (parse_ringnuma_config(optarg))
696                                         rte_exit(EXIT_FAILURE,
697                                            "invalid ring-numa configuration\n");
698                         if (!strcmp(lgopts[opt_idx].name, "socket-num")) {
699                                 n = atoi(optarg);
700                                 if(n < MAX_SOCKET)
701                                         socket_num = (uint8_t)n;
702                                 else
703                                         rte_exit(EXIT_FAILURE,
704                                                 "The socket number should be < %d\n",
705                                                 MAX_SOCKET);
706                         }
707                         if (!strcmp(lgopts[opt_idx].name, "mbuf-size")) {
708                                 n = atoi(optarg);
709                                 if (n > 0 && n <= 0xFFFF)
710                                         mbuf_data_size = (uint16_t) n;
711                                 else
712                                         rte_exit(EXIT_FAILURE,
713                                                  "mbuf-size should be > 0 and < 65536\n");
714                         }
715                         if (!strcmp(lgopts[opt_idx].name, "total-num-mbufs")) {
716                                 n = atoi(optarg);
717                                 if (n > 1024)
718                                         param_total_num_mbufs = (unsigned)n;
719                                 else
720                                         rte_exit(EXIT_FAILURE,
721                                                  "total-num-mbufs should be > 1024\n");
722                         }
723                         if (!strcmp(lgopts[opt_idx].name, "max-pkt-len")) {
724                                 n = atoi(optarg);
725                                 if (n >= ETHER_MIN_LEN) {
726                                         rx_mode.max_rx_pkt_len = (uint32_t) n;
727                                         if (n > ETHER_MAX_LEN)
728                                             rx_mode.jumbo_frame = 1;
729                                 } else
730                                         rte_exit(EXIT_FAILURE,
731                                                  "Invalid max-pkt-len=%d - should be > %d\n",
732                                                  n, ETHER_MIN_LEN);
733                         }
734                         if (!strcmp(lgopts[opt_idx].name, "pkt-filter-mode")) {
735                                 if (!strcmp(optarg, "signature"))
736                                         fdir_conf.mode =
737                                                 RTE_FDIR_MODE_SIGNATURE;
738                                 else if (!strcmp(optarg, "perfect"))
739                                         fdir_conf.mode = RTE_FDIR_MODE_PERFECT;
740                                 else if (!strcmp(optarg, "none"))
741                                         fdir_conf.mode = RTE_FDIR_MODE_NONE;
742                                 else
743                                         rte_exit(EXIT_FAILURE,
744                                                  "pkt-mode-invalid %s invalid - must be: "
745                                                  "none, signature or perfect\n",
746                                                  optarg);
747                         }
748                         if (!strcmp(lgopts[opt_idx].name,
749                                     "pkt-filter-report-hash")) {
750                                 if (!strcmp(optarg, "none"))
751                                         fdir_conf.status =
752                                                 RTE_FDIR_NO_REPORT_STATUS;
753                                 else if (!strcmp(optarg, "match"))
754                                         fdir_conf.status =
755                                                 RTE_FDIR_REPORT_STATUS;
756                                 else if (!strcmp(optarg, "always"))
757                                         fdir_conf.status =
758                                                 RTE_FDIR_REPORT_STATUS_ALWAYS;
759                                 else
760                                         rte_exit(EXIT_FAILURE,
761                                                  "pkt-filter-report-hash %s invalid "
762                                                  "- must be: none or match or always\n",
763                                                  optarg);
764                         }
765                         if (!strcmp(lgopts[opt_idx].name, "pkt-filter-size")) {
766                                 if (!strcmp(optarg, "64K"))
767                                         fdir_conf.pballoc =
768                                                 RTE_FDIR_PBALLOC_64K;
769                                 else if (!strcmp(optarg, "128K"))
770                                         fdir_conf.pballoc =
771                                                 RTE_FDIR_PBALLOC_128K;
772                                 else if (!strcmp(optarg, "256K"))
773                                         fdir_conf.pballoc =
774                                                 RTE_FDIR_PBALLOC_256K;
775                                 else
776                                         rte_exit(EXIT_FAILURE, "pkt-filter-size %s invalid -"
777                                                  " must be: 64K or 128K or 256K\n",
778                                                  optarg);
779                         }
780                         if (!strcmp(lgopts[opt_idx].name,
781                                     "pkt-filter-flexbytes-offset")) {
782                                 n = atoi(optarg);
783                                 if ( n >= 0 && n <= (int) 32)
784                                         fdir_conf.flexbytes_offset =
785                                                 (uint8_t) n;
786                                 else
787                                         rte_exit(EXIT_FAILURE,
788                                                  "flexbytes %d invalid - must"
789                                                  "be  >= 0 && <= 32\n", n);
790                         }
791                         if (!strcmp(lgopts[opt_idx].name,
792                                     "pkt-filter-drop-queue")) {
793                                 n = atoi(optarg);
794                                 if (n >= 0)
795                                         fdir_conf.drop_queue = (uint8_t) n;
796                                 else
797                                         rte_exit(EXIT_FAILURE,
798                                                  "drop queue %d invalid - must"
799                                                  "be >= 0 \n", n);
800                         }
801                         if (!strcmp(lgopts[opt_idx].name, "crc-strip"))
802                                 rx_mode.hw_strip_crc = 1;
803                         if (!strcmp(lgopts[opt_idx].name, "enable-rx-cksum"))
804                                 rx_mode.hw_ip_checksum = 1;
805
806                         if (!strcmp(lgopts[opt_idx].name, "disable-hw-vlan")) {
807                                 rx_mode.hw_vlan_filter = 0;
808                                 rx_mode.hw_vlan_strip  = 0;
809                                 rx_mode.hw_vlan_extend = 0;
810                         }
811
812                         if (!strcmp(lgopts[opt_idx].name, "enable-drop-en"))
813                                 rx_drop_en = 1;
814
815                         if (!strcmp(lgopts[opt_idx].name, "disable-rss"))
816                                 rss_hf = 0;
817                         if (!strcmp(lgopts[opt_idx].name, "port-topology")) {
818                                 if (!strcmp(optarg, "paired"))
819                                         port_topology = PORT_TOPOLOGY_PAIRED;
820                                 else if (!strcmp(optarg, "chained"))
821                                         port_topology = PORT_TOPOLOGY_CHAINED;
822                                 else if (!strcmp(optarg, "loop"))
823                                         port_topology = PORT_TOPOLOGY_LOOP;
824                                 else
825                                         rte_exit(EXIT_FAILURE, "port-topology %s invalid -"
826                                                  " must be: paired or chained \n",
827                                                  optarg);
828                         }
829                         if (!strcmp(lgopts[opt_idx].name, "forward-mode"))
830                                 set_pkt_forwarding_mode(optarg);
831                         if (!strcmp(lgopts[opt_idx].name, "rss-ip"))
832                                 rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6;
833                         if (!strcmp(lgopts[opt_idx].name, "rss-udp"))
834                                 rss_hf = ETH_RSS_IPV4 |
835                                                 ETH_RSS_IPV6 | ETH_RSS_IPV4_UDP;
836                         if (!strcmp(lgopts[opt_idx].name, "rxq")) {
837                                 n = atoi(optarg);
838                                 if (n >= 1 && n <= (int) MAX_QUEUE_ID)
839                                         nb_rxq = (queueid_t) n;
840                                 else
841                                         rte_exit(EXIT_FAILURE, "rxq %d invalid - must be"
842                                                   " >= 1 && <= %d\n", n,
843                                                   (int) MAX_QUEUE_ID);
844                         }
845                         if (!strcmp(lgopts[opt_idx].name, "txq")) {
846                                 n = atoi(optarg);
847                                 if (n >= 1 && n <= (int) MAX_QUEUE_ID)
848                                         nb_txq = (queueid_t) n;
849                                 else
850                                         rte_exit(EXIT_FAILURE, "txq %d invalid - must be"
851                                                   " >= 1 && <= %d\n", n,
852                                                   (int) MAX_QUEUE_ID);
853                         }
854                         if (!strcmp(lgopts[opt_idx].name, "rxd")) {
855                                 n = atoi(optarg);
856                                 if (n > 0)
857                                         nb_rxd = (uint16_t) n;
858                                 else
859                                         rte_exit(EXIT_FAILURE, "rxd must be > 0\n");
860                         }
861                         if (!strcmp(lgopts[opt_idx].name, "txd")) {
862                                 n = atoi(optarg);
863                                 if (n > 0)
864                                         nb_txd = (uint16_t) n;
865                                 else
866                                         rte_exit(EXIT_FAILURE, "txd must be in > 0\n");
867                         }
868                         if (!strcmp(lgopts[opt_idx].name, "burst")) {
869                                 n = atoi(optarg);
870                                 if ((n >= 1) && (n <= MAX_PKT_BURST))
871                                         nb_pkt_per_burst = (uint16_t) n;
872                                 else
873                                         rte_exit(EXIT_FAILURE,
874                                                  "burst must >= 1 and <= %d]",
875                                                  MAX_PKT_BURST);
876                         }
877                         if (!strcmp(lgopts[opt_idx].name, "mbcache")) {
878                                 n = atoi(optarg);
879                                 if ((n >= 0) &&
880                                     (n <= RTE_MEMPOOL_CACHE_MAX_SIZE))
881                                         mb_mempool_cache = (uint16_t) n;
882                                 else
883                                         rte_exit(EXIT_FAILURE,
884                                                  "mbcache must be >= 0 and <= %d\n",
885                                                  RTE_MEMPOOL_CACHE_MAX_SIZE);
886                         }
887                         if (!strcmp(lgopts[opt_idx].name, "txpt")) {
888                                 n = atoi(optarg);
889                                 if (n >= 0)
890                                         tx_thresh.pthresh = (uint8_t)n;
891                                 else
892                                         rte_exit(EXIT_FAILURE, "txpt must be >= 0\n");
893                         }
894                         if (!strcmp(lgopts[opt_idx].name, "txht")) {
895                                 n = atoi(optarg);
896                                 if (n >= 0)
897                                         tx_thresh.hthresh = (uint8_t)n;
898                                 else
899                                         rte_exit(EXIT_FAILURE, "txht must be >= 0\n");
900                         }
901                         if (!strcmp(lgopts[opt_idx].name, "txwt")) {
902                                 n = atoi(optarg);
903                                 if (n >= 0)
904                                         tx_thresh.wthresh = (uint8_t)n;
905                                 else
906                                         rte_exit(EXIT_FAILURE, "txwt must be >= 0\n");
907                         }
908                         if (!strcmp(lgopts[opt_idx].name, "txfreet")) {
909                                 n = atoi(optarg);
910                                 if (n >= 0)
911                                         tx_free_thresh = (uint16_t)n;
912                                 else
913                                         rte_exit(EXIT_FAILURE, "txfreet must be >= 0\n");
914                         }
915                         if (!strcmp(lgopts[opt_idx].name, "txrst")) {
916                                 n = atoi(optarg);
917                                 if (n >= 0)
918                                         tx_rs_thresh = (uint16_t)n;
919                                 else
920                                         rte_exit(EXIT_FAILURE, "txrst must be >= 0\n");
921                         }
922                         if (!strcmp(lgopts[opt_idx].name, "txqflags")) {
923                                 char *end = NULL;
924                                 n = strtoul(optarg, &end, 16);
925                                 if (n >= 0)
926                                         txq_flags = (uint32_t)n;
927                                 else
928                                         rte_exit(EXIT_FAILURE,
929                                                  "txqflags must be >= 0\n");
930                         }
931                         if (!strcmp(lgopts[opt_idx].name, "rxpt")) {
932                                 n = atoi(optarg);
933                                 if (n >= 0)
934                                         rx_thresh.pthresh = (uint8_t)n;
935                                 else
936                                         rte_exit(EXIT_FAILURE, "rxpt must be >= 0\n");
937                         }
938                         if (!strcmp(lgopts[opt_idx].name, "rxht")) {
939                                 n = atoi(optarg);
940                                 if (n >= 0)
941                                         rx_thresh.hthresh = (uint8_t)n;
942                                 else
943                                         rte_exit(EXIT_FAILURE, "rxht must be >= 0\n");
944                         }
945                         if (!strcmp(lgopts[opt_idx].name, "rxwt")) {
946                                 n = atoi(optarg);
947                                 if (n >= 0)
948                                         rx_thresh.wthresh = (uint8_t)n;
949                                 else
950                                         rte_exit(EXIT_FAILURE, "rxwt must be >= 0\n");
951                         }
952                         if (!strcmp(lgopts[opt_idx].name, "rxd")) {
953                                 n = atoi(optarg);
954                                 if (n > 0) {
955                                         if (rx_free_thresh >= n)
956                                                 rte_exit(EXIT_FAILURE,
957                                                          "rxd must be > "
958                                                          "rx_free_thresh(%d)\n",
959                                                          (int)rx_free_thresh);
960                                         else
961                                                 nb_rxd = (uint16_t) n;
962                                 } else
963                                         rte_exit(EXIT_FAILURE,
964                                                  "rxd(%d) invalid - must be > 0\n",
965                                                  n);
966                         }
967                         if (!strcmp(lgopts[opt_idx].name, "txd")) {
968                                 n = atoi(optarg);
969                                 if (n > 0)
970                                         nb_txd = (uint16_t) n;
971                                 else
972                                         rte_exit(EXIT_FAILURE, "txd must be in > 0\n");
973                         }
974                         if (!strcmp(lgopts[opt_idx].name, "txpt")) {
975                                 n = atoi(optarg);
976                                 if (n >= 0)
977                                         tx_thresh.pthresh = (uint8_t)n;
978                                 else
979                                         rte_exit(EXIT_FAILURE, "txpt must be >= 0\n");
980                         }
981                         if (!strcmp(lgopts[opt_idx].name, "txht")) {
982                                 n = atoi(optarg);
983                                 if (n >= 0)
984                                         tx_thresh.hthresh = (uint8_t)n;
985                                 else
986                                         rte_exit(EXIT_FAILURE, "txht must be >= 0\n");
987                         }
988                         if (!strcmp(lgopts[opt_idx].name, "txwt")) {
989                                 n = atoi(optarg);
990                                 if (n >= 0)
991                                         tx_thresh.wthresh = (uint8_t)n;
992                                 else
993                                         rte_exit(EXIT_FAILURE, "txwt must be >= 0\n");
994                         }
995                         if (!strcmp(lgopts[opt_idx].name, "rxpt")) {
996                                 n = atoi(optarg);
997                                 if (n >= 0)
998                                         rx_thresh.pthresh = (uint8_t)n;
999                                 else
1000                                         rte_exit(EXIT_FAILURE, "rxpt must be >= 0\n");
1001                         }
1002                         if (!strcmp(lgopts[opt_idx].name, "rxht")) {
1003                                 n = atoi(optarg);
1004                                 if (n >= 0)
1005                                         rx_thresh.hthresh = (uint8_t)n;
1006                                 else
1007                                         rte_exit(EXIT_FAILURE, "rxht must be >= 0\n");
1008                         }
1009                         if (!strcmp(lgopts[opt_idx].name, "rxwt")) {
1010                                 n = atoi(optarg);
1011                                 if (n >= 0)
1012                                         rx_thresh.wthresh = (uint8_t)n;
1013                                 else
1014                                         rte_exit(EXIT_FAILURE, "rxwt must be >= 0\n");
1015                         }
1016                         if (!strcmp(lgopts[opt_idx].name, "rxfreet")) {
1017                                 n = atoi(optarg);
1018                                 if (n >= 0)
1019                                         rx_free_thresh = (uint16_t)n;
1020                                 else
1021                                         rte_exit(EXIT_FAILURE, "rxfreet must be >= 0\n");
1022                         }
1023                         if (!strcmp(lgopts[opt_idx].name, "tx-queue-stats-mapping")) {
1024                                 if (parse_queue_stats_mapping_config(optarg, TX)) {
1025                                         rte_exit(EXIT_FAILURE,
1026                                                  "invalid TX queue statistics mapping config entered\n");
1027                                 }
1028                         }
1029                         if (!strcmp(lgopts[opt_idx].name, "rx-queue-stats-mapping")) {
1030                                 if (parse_queue_stats_mapping_config(optarg, RX)) {
1031                                         rte_exit(EXIT_FAILURE,
1032                                                  "invalid RX queue statistics mapping config entered\n");
1033                                 }
1034                         }
1035                         if (!strcmp(lgopts[opt_idx].name, "txpkts")) {
1036                                 unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
1037                                 unsigned int nb_segs;
1038
1039                                 nb_segs = parse_item_list(optarg, RTE_MAX_SEGS_PER_PKT, seg_lengths);
1040                                 if (nb_segs > 0)
1041                                         set_tx_pkt_segments(seg_lengths, nb_segs);
1042                                 else
1043                                         rte_exit(EXIT_FAILURE, "bad txpkts\n");
1044                         }
1045                         if (!strcmp(lgopts[opt_idx].name, "no-flush-rx"))
1046                                 no_flush_rx = 1;
1047
1048                         break;
1049                 case 'h':
1050                         usage(argv[0]);
1051                         rte_exit(EXIT_SUCCESS, "Displayed help\n");
1052                         break;
1053                 default:
1054                         usage(argv[0]);
1055                         rte_exit(EXIT_FAILURE,
1056                                  "Command line is incomplete or incorrect\n");
1057                         break;
1058                 }
1059         }
1060 }