app/testpmd: add fdir ipv6 support
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  * 
7  *   Redistribution and use in source and binary forms, with or without 
8  *   modification, are permitted provided that the following conditions 
9  *   are met:
10  * 
11  *     * Redistributions of source code must retain the above copyright 
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright 
14  *       notice, this list of conditions and the following disclaimer in 
15  *       the documentation and/or other materials provided with the 
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its 
18  *       contributors may be used to endorse or promote products derived 
19  *       from this software without specific prior written permission.
20  * 
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  * 
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <stdarg.h>
40 #include <string.h>
41 #include <termios.h>
42 #include <unistd.h>
43 #include <inttypes.h>
44 #ifndef __linux__
45 #include <net/socket.h>
46 #endif
47 #include <netinet/in.h>
48
49 #include <sys/queue.h>
50
51 #include <rte_common.h>
52 #include <rte_byteorder.h>
53 #include <rte_log.h>
54 #include <rte_debug.h>
55 #include <rte_cycles.h>
56 #include <rte_memory.h>
57 #include <rte_memzone.h>
58 #include <rte_launch.h>
59 #include <rte_tailq.h>
60 #include <rte_eal.h>
61 #include <rte_per_lcore.h>
62 #include <rte_lcore.h>
63 #include <rte_atomic.h>
64 #include <rte_branch_prediction.h>
65 #include <rte_ring.h>
66 #include <rte_mempool.h>
67 #include <rte_interrupts.h>
68 #include <rte_pci.h>
69 #include <rte_ether.h>
70 #include <rte_ethdev.h>
71 #include <rte_string_fns.h>
72
73 #include <cmdline_rdline.h>
74 #include <cmdline_parse.h>
75 #include <cmdline_parse_num.h>
76 #include <cmdline_parse_string.h>
77 #include <cmdline_parse_ipaddr.h>
78 #include <cmdline_parse_etheraddr.h>
79 #include <cmdline_socket.h>
80 #include <cmdline.h>
81
82 #include "testpmd.h"
83
84 /* *** HELP *** */
85 struct cmd_help_result {
86         cmdline_fixed_string_t help;
87 };
88
89 static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
90                             struct cmdline *cl,
91                             __attribute__((unused)) void *data)
92 {
93         cmdline_printf(cl,
94                        "\n"
95                        "TEST PMD\n"
96                        "--------\n"
97                        "\n"
98                        "This commandline can be used to configure forwarding\n"
99                        "\n");
100         cmdline_printf(cl,
101                        "Display informations:\n"
102                        "---------------------\n"
103                        "- show port info|stats|fdir|stat_qmap X|all\n"
104                        "    Diplays information or stats or stats queue mapping on port X, or all\n"
105                        "- clear port stats X|all\n"
106                        "    Clear stats for port X, or all\n"
107                        "- show config rxtx|cores|fwd\n"
108                        "    Displays the given configuration\n"
109                        "- read reg port_id reg_off\n"
110                        "    Displays value of a port register\n"
111                        "- read regfield port_id reg_off bit_x bit_y\n"
112                        "    Displays value of a port register bit field\n"
113                        "- read regbit port_id reg_off bit_x\n"
114                        "    Displays value of a port register bit\n"
115                        "- read rxd port_id queue_id rxd_id\n"
116                        "    Displays a RX descriptor of a port RX queue\n"
117                        "- read txd port_id queue_id txd_id\n"
118                        "    Displays a TX descriptor of a port TX queue\n"
119                        "\n");
120         cmdline_printf(cl,
121                        "Configure:\n"
122                        "----------\n"
123                        "Modifications are taken into account once "
124                        "forwarding is restarted.\n"
125                        "- set default\n"
126                        "    Set forwarding to default configuration\n"
127                        "- set nbport|nbcore|burst|verbose X\n"
128                        "    Set number of ports, number of cores, number "
129                        "of packets per burst,\n    or verbose level to X\n"
130                        "- set txpkts x[,y]*\n"
131                        "    Set the length of each segment of TXONLY packets\n"
132                        "- set coremask|portmask X\n"
133                        "    Set the hexadecimal mask of forwarding cores / "
134                        "forwarding ports\n"
135                        "- set corelist|portlist x[,y]*\n"
136                        "    Set the list of forwarding cores / forwarding "
137                        "ports\n"
138                        "- vlan set strip|filter|qinq on/off port_id\n"
139                        "    Set the VLAN strip, filter, QinQ(extended) on a port"
140                        "- rx_vlan add/rm vlan_id|all port_id\n"
141                        "    Set the VLAN filter table, add/remove vlan_id, or all "
142                        "identifiers, to/from the set of VLAN Identifiers\n"
143                        "filtered by port_id\n"
144                        "- rx_vlan set tpid value port_id\n"
145                        "    Set Outer VLAN TPID for Packet Filtering on a port \n"
146                        "- tx_vlan set vlan_id port_id\n"
147                        "    Set hardware insertion of VLAN ID in packets sent on a port\n"
148                        "- tx_vlan reset port_id\n"
149                        "    Disable hardware insertion of a VLAN header in "
150                        "packets sent on port_id\n"
151                        "- tx_checksum set mask port_id\n"
152                        "    Enable hardware insertion of checksum offload with "
153                        "the 4-bit mask (0~0xf)\n    in packets sent on port_id\n"
154                        "    Please check the NIC datasheet for HW limits\n"
155                        "      bit 0 - insert ip checksum offload if set \n"
156                        "      bit 1 - insert udp checksum offload if set \n"
157                        "      bit 2 - insert tcp checksum offload if set\n"
158                        "      bit 3 - insert sctp checksum offload if set\n"
159 #ifdef RTE_LIBRTE_IEEE1588
160                        "- set fwd io|mac|rxonly|txonly|csum|ieee1588\n"
161                        "    Set IO, MAC, RXONLY, TXONLY, CSUM or IEEE1588 "
162                        "packet forwarding mode\n"
163 #else
164                        "- set fwd io|mac|rxonly|txonly|csum\n"
165                        "    Set IO, MAC, RXONLY, CSUM or TXONLY packet "
166                        "forwarding mode\n"
167 #endif
168                        "- mac_addr add|remove X <xx:xx:xx:xx:xx:xx>\n"
169                        "    Add/Remove the MAC address <xx:xx:xx:xx:xx:xx> on port X\n"
170                        "- set promisc|allmulti [all|X] on|off\n"
171                        "    Set/unset promisc|allmulti mode on port X, or all\n"
172                        "- set flow_ctrl rx on|off tx on|off high_water low_water "
173                                                 "pause_time send_xon port_id \n"
174                        "    Set the link flow control parameter on the port \n"
175                        "- write reg port_id reg_off value\n"
176                        "    Set value of a port register\n"
177                        "- write regfield port_id reg_off bit_x bit_y value\n"
178                        "    Set bit field value of a port register\n"
179                        "- write regbit port_id reg_off bit_x value\n"
180                        "    Set bit value of a port register\n"
181                        "- set stat_qmap tx|rx port_id queue_id qmapping\n"
182                        "    Set statistics mapping (qmapping 0..15) for tx|rx queue_id on port_id\n"
183                        "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2 on port 0 to mapping 5\n"
184                        "\n");
185         cmdline_printf(cl,
186                        "Control forwarding:\n"
187                        "-------------------\n"
188                        "- start\n"
189                        "    Start packet forwarding with current config\n"
190                        "- start tx_first\n"
191                        "    Start packet forwarding with current config"
192                        " after sending one burst\n    of packets\n"
193                        "- stop\n"
194                        "    Stop packet forwarding, and displays accumulated"
195                        " stats\n"
196                        "\n");
197         cmdline_printf(cl,
198                        "Flow director mode:\n"
199                        "-------------------\n"
200                        "- add_signature_filter port_id ip|udp|tcp|sctp src\n"
201                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
202                        "    flexbytes flexbytes_values vlan vlan_id queue queue_id\n"
203                        "- upd_signature_filter port_id ip|udp|tcp|sctp src \n"
204                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
205                        "    flexbytes flexbytes_values vlan vlan_id queue queue_id\n"
206                        "- rm_signature_filter port_id ip|udp|tcp|sctp src\n"
207                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
208                        "    flexbytes flexbytes_values vlan vlan_id\n"
209                        "- add_perfect_filter port_id ip|udp|tcp|sctp src\n"
210                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
211                        "    flexbytes flexbytes_values vlan vlan_id queue \n"
212                        "    queue_id soft soft_id\n"
213                        "- upd_perfect_filter port_id ip|udp|tcp|sctp src\n"
214                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
215                        "    flexbytes flexbytes_values vlan vlan_id queue queue_id\n"
216                        "- rm_perfect_filter port_id ip|udp|tcp|sctp src\n"
217                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
218                        "    flexbytes flexbytes_values vlan vlan_id soft soft_id\n"
219                        "- set_masks_filter port_id only_ip_flow 0|1 src_mask\n"
220                        "    ip_src_mask  port_src_mask dst_mask ip_dst_mask\n"
221                        "    port_dst_mask flexbytes 0|1 vlan_id 0|1 vlan_prio 0|1\n"
222                        "- set_ipv6_masks_filter port_id only_ip_flow 0|1 src_mask\n"
223                        "    ip_src_mask port_src_mask dst_mask ip_dst_mask\n"
224                        "    port_dst_mask flexbytes 0|1 vlan_id 0|1\n"
225                        "    vlan_prio 0|1 compare_dst 0|1\n"
226                        "\n");
227         cmdline_printf(cl,
228                        "Misc:\n"
229                        "-----\n"
230                        "- quit\n"
231                        "    Quit to prompt in linux, and reboot on baremetal\n"
232                        "\n");
233 }
234
235 cmdline_parse_token_string_t cmd_help_help =
236         TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");
237
238 cmdline_parse_inst_t cmd_help = {
239         .f = cmd_help_parsed,
240         .data = NULL,
241         .help_str = "show help",
242         .tokens = {
243                 (void *)&cmd_help_help,
244                 NULL,
245         },
246 };
247
248 /* *** stop *** */
249 struct cmd_stop_result {
250         cmdline_fixed_string_t stop;
251 };
252
253 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
254                             __attribute__((unused)) struct cmdline *cl,
255                             __attribute__((unused)) void *data)
256 {
257         stop_packet_forwarding();
258 }
259
260 cmdline_parse_token_string_t cmd_stop_stop =
261         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
262
263 cmdline_parse_inst_t cmd_stop = {
264         .f = cmd_stop_parsed,
265         .data = NULL,
266         .help_str = "stop - stop packet forwarding",
267         .tokens = {
268                 (void *)&cmd_stop_stop,
269                 NULL,
270         },
271 };
272
273 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
274
275 static unsigned int
276 parse_item_list(char* str, const char* item_name, unsigned int max_items,
277                 unsigned int *parsed_items, int check_unique_values)
278 {
279         unsigned int nb_item;
280         unsigned int value;
281         unsigned int i;
282         unsigned int j;
283         int value_ok;
284         char c;
285
286         /*
287          * First parse all items in the list and store their value.
288          */
289         value = 0;
290         nb_item = 0;
291         value_ok = 0;
292         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
293                 c = str[i];
294                 if ((c >= '0') && (c <= '9')) {
295                         value = (unsigned int) (value * 10 + (c - '0'));
296                         value_ok = 1;
297                         continue;
298                 }
299                 if (c != ',') {
300                         printf("character %c is not a decimal digit\n", c);
301                         return (0);
302                 }
303                 if (! value_ok) {
304                         printf("No valid value before comma\n");
305                         return (0);
306                 }
307                 if (nb_item < max_items) {
308                         parsed_items[nb_item] = value;
309                         value_ok = 0;
310                         value = 0;
311                 }
312                 nb_item++;
313         }
314         if (nb_item >= max_items) {
315                 printf("Number of %s = %u > %u (maximum items)\n",
316                        item_name, nb_item + 1, max_items);
317                 return (0);
318         }
319         parsed_items[nb_item++] = value;
320         if (! check_unique_values)
321                 return (nb_item);
322
323         /*
324          * Then, check that all values in the list are differents.
325          * No optimization here...
326          */
327         for (i = 0; i < nb_item; i++) {
328                 for (j = i + 1; j < nb_item; j++) {
329                         if (parsed_items[j] == parsed_items[i]) {
330                                 printf("duplicated %s %u at index %u and %u\n",
331                                        item_name, parsed_items[i], i, j);
332                                 return (0);
333                         }
334                 }
335         }
336         return (nb_item);
337 }
338
339 struct cmd_set_list_result {
340         cmdline_fixed_string_t cmd_keyword;
341         cmdline_fixed_string_t list_name;
342         cmdline_fixed_string_t list_of_items;
343 };
344
345 static void cmd_set_list_parsed(void *parsed_result,
346                                 __attribute__((unused)) struct cmdline *cl,
347                                 __attribute__((unused)) void *data)
348 {
349         struct cmd_set_list_result *res;
350         union {
351                 unsigned int lcorelist[RTE_MAX_LCORE];
352                 unsigned int portlist[RTE_MAX_ETHPORTS];
353         } parsed_items;
354         unsigned int nb_item;
355
356         res = parsed_result;
357         if (!strcmp(res->list_name, "corelist")) {
358                 nb_item = parse_item_list(res->list_of_items, "core",
359                                           RTE_MAX_LCORE,
360                                           parsed_items.lcorelist, 1);
361                 if (nb_item > 0)
362                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
363                 return;
364         }
365         if (!strcmp(res->list_name, "portlist")) {
366                 nb_item = parse_item_list(res->list_of_items, "port",
367                                           RTE_MAX_ETHPORTS,
368                                           parsed_items.portlist, 1);
369                 if (nb_item > 0)
370                         set_fwd_ports_list(parsed_items.portlist, nb_item);
371         }
372 }
373
374 cmdline_parse_token_string_t cmd_set_list_keyword =
375         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
376                                  "set");
377 cmdline_parse_token_string_t cmd_set_list_name =
378         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
379                                  "corelist#portlist");
380 cmdline_parse_token_string_t cmd_set_list_of_items =
381         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
382                                  NULL);
383
384 cmdline_parse_inst_t cmd_set_fwd_list = {
385         .f = cmd_set_list_parsed,
386         .data = NULL,
387         .help_str = "set corelist|portlist x[,y]*",
388         .tokens = {
389                 (void *)&cmd_set_list_keyword,
390                 (void *)&cmd_set_list_name,
391                 (void *)&cmd_set_list_of_items,
392                 NULL,
393         },
394 };
395
396 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
397
398 struct cmd_setmask_result {
399         cmdline_fixed_string_t set;
400         cmdline_fixed_string_t mask;
401         uint64_t hexavalue;
402 };
403
404 static void cmd_set_mask_parsed(void *parsed_result,
405                                 __attribute__((unused)) struct cmdline *cl,
406                                 __attribute__((unused)) void *data)
407 {
408         struct cmd_setmask_result *res = parsed_result;
409
410         if (!strcmp(res->mask, "coremask"))
411                 set_fwd_lcores_mask(res->hexavalue);
412         else if (!strcmp(res->mask, "portmask"))
413                 set_fwd_ports_mask(res->hexavalue);
414 }
415
416 cmdline_parse_token_string_t cmd_setmask_set =
417         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
418 cmdline_parse_token_string_t cmd_setmask_mask =
419         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
420                                  "coremask#portmask");
421 cmdline_parse_token_num_t cmd_setmask_value =
422         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
423
424 cmdline_parse_inst_t cmd_set_fwd_mask = {
425         .f = cmd_set_mask_parsed,
426         .data = NULL,
427         .help_str = "set coremask|portmask hexadecimal value",
428         .tokens = {
429                 (void *)&cmd_setmask_set,
430                 (void *)&cmd_setmask_mask,
431                 (void *)&cmd_setmask_value,
432                 NULL,
433         },
434 };
435
436 /*
437  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
438  */
439 struct cmd_set_result {
440         cmdline_fixed_string_t set;
441         cmdline_fixed_string_t what;
442         uint16_t value;
443 };
444
445 static void cmd_set_parsed(void *parsed_result,
446                            __attribute__((unused)) struct cmdline *cl,
447                            __attribute__((unused)) void *data)
448 {
449         struct cmd_set_result *res = parsed_result;
450         if (!strcmp(res->what, "nbport"))
451                 set_fwd_ports_number(res->value);
452         else if (!strcmp(res->what, "nbcore"))
453                 set_fwd_lcores_number(res->value);
454         else if (!strcmp(res->what, "burst"))
455                 set_nb_pkt_per_burst(res->value);
456         else if (!strcmp(res->what, "verbose"))
457                 set_verbose_level(res->value);
458 }
459
460 cmdline_parse_token_string_t cmd_set_set =
461         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
462 cmdline_parse_token_string_t cmd_set_what =
463         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
464                                  "nbport#nbcore#burst#verbose");
465 cmdline_parse_token_num_t cmd_set_value =
466         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
467
468 cmdline_parse_inst_t cmd_set_numbers = {
469         .f = cmd_set_parsed,
470         .data = NULL,
471         .help_str = "set nbport|nbcore|burst|verbose value",
472         .tokens = {
473                 (void *)&cmd_set_set,
474                 (void *)&cmd_set_what,
475                 (void *)&cmd_set_value,
476                 NULL,
477         },
478 };
479
480 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
481
482 struct cmd_set_txpkts_result {
483         cmdline_fixed_string_t cmd_keyword;
484         cmdline_fixed_string_t txpkts;
485         cmdline_fixed_string_t seg_lengths;
486 };
487
488 static void
489 cmd_set_txpkts_parsed(void *parsed_result,
490                       __attribute__((unused)) struct cmdline *cl,
491                       __attribute__((unused)) void *data)
492 {
493         struct cmd_set_txpkts_result *res;
494         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
495         unsigned int nb_segs;
496
497         res = parsed_result;
498         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
499                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
500         if (nb_segs > 0)
501                 set_tx_pkt_segments(seg_lengths, nb_segs);
502 }
503
504 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
505         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
506                                  cmd_keyword, "set");
507 cmdline_parse_token_string_t cmd_set_txpkts_name =
508         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
509                                  txpkts, "txpkts");
510 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
511         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
512                                  seg_lengths, NULL);
513
514 cmdline_parse_inst_t cmd_set_txpkts = {
515         .f = cmd_set_txpkts_parsed,
516         .data = NULL,
517         .help_str = "set txpkts x[,y]*",
518         .tokens = {
519                 (void *)&cmd_set_txpkts_keyword,
520                 (void *)&cmd_set_txpkts_name,
521                 (void *)&cmd_set_txpkts_lengths,
522                 NULL,
523         },
524 };
525
526 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
527 struct cmd_rx_vlan_filter_all_result {
528         cmdline_fixed_string_t rx_vlan;
529         cmdline_fixed_string_t what;
530         cmdline_fixed_string_t all;
531         uint8_t port_id;
532 };
533
534 static void
535 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
536                               __attribute__((unused)) struct cmdline *cl,
537                               __attribute__((unused)) void *data)
538 {
539         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
540
541         if (!strcmp(res->what, "add"))
542                 rx_vlan_all_filter_set(res->port_id, 1);
543         else
544                 rx_vlan_all_filter_set(res->port_id, 0);
545 }
546
547 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
548         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
549                                  rx_vlan, "rx_vlan");
550 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
551         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
552                                  what, "add#rm");
553 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
554         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
555                                  all, "all");
556 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
557         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
558                               port_id, UINT8);
559
560 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
561         .f = cmd_rx_vlan_filter_all_parsed,
562         .data = NULL,
563         .help_str = "add/remove all identifiers to/from the set of VLAN "
564         "Identifiers filtered by a port",
565         .tokens = {
566                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
567                 (void *)&cmd_rx_vlan_filter_all_what,
568                 (void *)&cmd_rx_vlan_filter_all_all,
569                 (void *)&cmd_rx_vlan_filter_all_portid,
570                 NULL,
571         },
572 };
573
574 /* *** VLAN OFFLOAD SET ON A PORT *** */
575 struct cmd_vlan_offload_result {
576         cmdline_fixed_string_t vlan;
577         cmdline_fixed_string_t set;
578         cmdline_fixed_string_t what;
579         cmdline_fixed_string_t on;
580         cmdline_fixed_string_t port_id;
581 };
582
583 static void
584 cmd_vlan_offload_parsed(void *parsed_result,
585                           __attribute__((unused)) struct cmdline *cl,
586                           __attribute__((unused)) void *data)
587 {
588         int on;
589         struct cmd_vlan_offload_result *res = parsed_result;    
590         char *str;
591         int i, len = 0;
592         portid_t port_id = 0;
593         unsigned int tmp;
594         
595         str = res->port_id;
596         len = strnlen(str, STR_TOKEN_SIZE);
597         i = 0;
598         /* Get port_id first */
599         while(i < len){
600                 if(str[i] == ',')
601                         break;
602                 
603                 i++;
604         }
605         str[i]='\0';
606         tmp = strtoul(str, NULL, 0);
607         /* If port_id greater that what portid_t can represent, return */
608         if(tmp > 255)
609                 return;
610         port_id = (portid_t)tmp;
611
612         if (!strcmp(res->on, "on"))
613                 on = 1;
614         else
615                 on = 0;
616
617         if (!strcmp(res->what, "strip"))
618                 rx_vlan_strip_set(port_id,  on);
619         else if(!strcmp(res->what, "stripq")){
620                 uint16_t queue_id = 0;
621
622                 /* No queue_id, return */
623                 if(i + 1 >= len)
624                         return;
625                 tmp = strtoul(str + i + 1, NULL, 0);
626                 /* If queue_id greater that what 16-bits can represent, return */
627                 if(tmp > 0xffff)
628                         return;
629                 
630                 queue_id = (uint16_t)tmp;
631                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
632         }
633         else if (!strcmp(res->what, "filter"))
634                 rx_vlan_filter_set(port_id, on);
635         else
636                 vlan_extend_set(port_id, on);
637
638         return;
639 }
640
641 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
642         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
643                                  vlan, "vlan");
644 cmdline_parse_token_string_t cmd_vlan_offload_set =
645         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
646                                  set, "set");
647 cmdline_parse_token_string_t cmd_vlan_offload_what =
648         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
649                                  what, "strip#filter#qinq#stripq");
650 cmdline_parse_token_string_t cmd_vlan_offload_on =
651         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
652                               on, "on#off");
653 cmdline_parse_token_string_t cmd_vlan_offload_portid =
654         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
655                               port_id, NULL);
656
657 cmdline_parse_inst_t cmd_vlan_offload = {
658         .f = cmd_vlan_offload_parsed,
659         .data = NULL,
660         .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side"
661         " qinq(extended) for both rx/tx sides ",
662         .tokens = {
663                 (void *)&cmd_vlan_offload_vlan,
664                 (void *)&cmd_vlan_offload_set,
665                 (void *)&cmd_vlan_offload_what,
666                 (void *)&cmd_vlan_offload_on,
667                 (void *)&cmd_vlan_offload_portid,
668                 NULL,
669         },
670 };
671
672 /* *** VLAN TPID SET ON A PORT *** */
673 struct cmd_vlan_tpid_result {
674         cmdline_fixed_string_t vlan;
675         cmdline_fixed_string_t set;
676         cmdline_fixed_string_t what;
677         uint16_t tp_id;
678         uint8_t port_id;
679 };
680
681 static void
682 cmd_vlan_tpid_parsed(void *parsed_result,
683                           __attribute__((unused)) struct cmdline *cl,
684                           __attribute__((unused)) void *data)
685 {
686         struct cmd_vlan_tpid_result *res = parsed_result;
687         vlan_tpid_set(res->port_id, res->tp_id);
688         return;
689 }
690
691 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
692         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
693                                  vlan, "vlan");
694 cmdline_parse_token_string_t cmd_vlan_tpid_set =
695         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
696                                  set, "set");
697 cmdline_parse_token_string_t cmd_vlan_tpid_what =
698         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
699                                  what, "tpid");
700 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
701         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
702                               tp_id, UINT16);
703 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
704         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
705                               port_id, UINT8);
706
707 cmdline_parse_inst_t cmd_vlan_tpid = {
708         .f = cmd_vlan_tpid_parsed,
709         .data = NULL,
710         .help_str = "set tpid tp_id port_id, set the Outer VLAN Ether type",
711         .tokens = {
712                 (void *)&cmd_vlan_tpid_vlan,
713                 (void *)&cmd_vlan_tpid_set,
714                 (void *)&cmd_vlan_tpid_what,
715                 (void *)&cmd_vlan_tpid_tpid,
716                 (void *)&cmd_vlan_tpid_portid,
717                 NULL,
718         },
719 };
720
721 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
722 struct cmd_rx_vlan_filter_result {
723         cmdline_fixed_string_t rx_vlan;
724         cmdline_fixed_string_t what;
725         uint16_t vlan_id;
726         uint8_t port_id;
727 };
728
729 static void
730 cmd_rx_vlan_filter_parsed(void *parsed_result,
731                           __attribute__((unused)) struct cmdline *cl,
732                           __attribute__((unused)) void *data)
733 {
734         struct cmd_rx_vlan_filter_result *res = parsed_result;
735
736         if (!strcmp(res->what, "add"))
737                 rx_vft_set(res->port_id, res->vlan_id, 1);
738         else
739                 rx_vft_set(res->port_id, res->vlan_id, 0);
740 }
741
742 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
743         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
744                                  rx_vlan, "rx_vlan");
745 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
746         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
747                                  what, "add#rm");
748 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
749         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
750                               vlan_id, UINT16);
751 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
752         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
753                               port_id, UINT8);
754
755 cmdline_parse_inst_t cmd_rx_vlan_filter = {
756         .f = cmd_rx_vlan_filter_parsed,
757         .data = NULL,
758         .help_str = "add/remove a VLAN identifier to/from the set of VLAN "
759         "Identifiers filtered by a port",
760         .tokens = {
761                 (void *)&cmd_rx_vlan_filter_rx_vlan,
762                 (void *)&cmd_rx_vlan_filter_what,
763                 (void *)&cmd_rx_vlan_filter_vlanid,
764                 (void *)&cmd_rx_vlan_filter_portid,
765                 NULL,
766         },
767 };
768
769 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
770 struct cmd_tx_vlan_set_result {
771         cmdline_fixed_string_t tx_vlan;
772         cmdline_fixed_string_t set;
773         uint16_t vlan_id;
774         uint8_t port_id;
775 };
776
777 static void
778 cmd_tx_vlan_set_parsed(void *parsed_result,
779                        __attribute__((unused)) struct cmdline *cl,
780                        __attribute__((unused)) void *data)
781 {
782         struct cmd_tx_vlan_set_result *res = parsed_result;
783         tx_vlan_set(res->port_id, res->vlan_id);
784 }
785
786 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
787         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
788                                  tx_vlan, "tx_vlan");
789 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
790         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
791                                  set, "set");
792 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
793         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
794                               vlan_id, UINT16);
795 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
796         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
797                               port_id, UINT8);
798
799 cmdline_parse_inst_t cmd_tx_vlan_set = {
800         .f = cmd_tx_vlan_set_parsed,
801         .data = NULL,
802         .help_str = "enable hardware insertion of a VLAN header with a given "
803         "TAG Identifier in packets sent on a port",
804         .tokens = {
805                 (void *)&cmd_tx_vlan_set_tx_vlan,
806                 (void *)&cmd_tx_vlan_set_set,
807                 (void *)&cmd_tx_vlan_set_vlanid,
808                 (void *)&cmd_tx_vlan_set_portid,
809                 NULL,
810         },
811 };
812
813 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
814 struct cmd_tx_vlan_reset_result {
815         cmdline_fixed_string_t tx_vlan;
816         cmdline_fixed_string_t reset;
817         uint8_t port_id;
818 };
819
820 static void
821 cmd_tx_vlan_reset_parsed(void *parsed_result,
822                          __attribute__((unused)) struct cmdline *cl,
823                          __attribute__((unused)) void *data)
824 {
825         struct cmd_tx_vlan_reset_result *res = parsed_result;
826
827         tx_vlan_reset(res->port_id);
828 }
829
830 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
831         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
832                                  tx_vlan, "tx_vlan");
833 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
834         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
835                                  reset, "reset");
836 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
837         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
838                               port_id, UINT8);
839
840 cmdline_parse_inst_t cmd_tx_vlan_reset = {
841         .f = cmd_tx_vlan_reset_parsed,
842         .data = NULL,
843         .help_str = "disable hardware insertion of a VLAN header in packets "
844         "sent on a port",
845         .tokens = {
846                 (void *)&cmd_tx_vlan_reset_tx_vlan,
847                 (void *)&cmd_tx_vlan_reset_reset,
848                 (void *)&cmd_tx_vlan_reset_portid,
849                 NULL,
850         },
851 };
852
853
854 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
855 struct cmd_tx_cksum_set_result {
856         cmdline_fixed_string_t tx_cksum;
857         cmdline_fixed_string_t set;
858         uint8_t cksum_mask;
859         uint8_t port_id;
860 };
861
862 static void
863 cmd_tx_cksum_set_parsed(void *parsed_result,
864                        __attribute__((unused)) struct cmdline *cl,
865                        __attribute__((unused)) void *data)
866 {
867         struct cmd_tx_cksum_set_result *res = parsed_result;
868
869         tx_cksum_set(res->port_id, res->cksum_mask);
870 }
871
872 cmdline_parse_token_string_t cmd_tx_cksum_set_tx_cksum =
873         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
874                                 tx_cksum, "tx_checksum");
875 cmdline_parse_token_string_t cmd_tx_cksum_set_set =
876         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
877                                 set, "set");
878 cmdline_parse_token_num_t cmd_tx_cksum_set_cksum_mask =
879         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
880                                 cksum_mask, UINT8);
881 cmdline_parse_token_num_t cmd_tx_cksum_set_portid =
882         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
883                                 port_id, UINT8);
884
885 cmdline_parse_inst_t cmd_tx_cksum_set = {
886         .f = cmd_tx_cksum_set_parsed,
887         .data = NULL,
888         .help_str = "enable hardware insertion of L3/L4checksum with a given "
889         "mask in packets sent on a port, the bit mapping is given as, Bit 0 for ip"
890         "Bit 1 for UDP, Bit 2 for TCP, Bit 3 for SCTP",
891         .tokens = {
892                 (void *)&cmd_tx_cksum_set_tx_cksum,
893                 (void *)&cmd_tx_cksum_set_set,
894                 (void *)&cmd_tx_cksum_set_cksum_mask,
895                 (void *)&cmd_tx_cksum_set_portid,
896                 NULL,
897         },
898 };
899
900 /* *** SET FORWARDING MODE *** */
901 struct cmd_set_fwd_mode_result {
902         cmdline_fixed_string_t set;
903         cmdline_fixed_string_t fwd;
904         cmdline_fixed_string_t mode;
905 };
906
907 static void cmd_set_fwd_mode_parsed(void *parsed_result,
908                                     __attribute__((unused)) struct cmdline *cl,
909                                     __attribute__((unused)) void *data)
910 {
911         struct cmd_set_fwd_mode_result *res = parsed_result;
912
913         set_pkt_forwarding_mode(res->mode);
914 }
915
916 cmdline_parse_token_string_t cmd_setfwd_set =
917         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
918 cmdline_parse_token_string_t cmd_setfwd_fwd =
919         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
920 cmdline_parse_token_string_t cmd_setfwd_mode =
921         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
922 #ifdef RTE_LIBRTE_IEEE1588
923                                  "io#mac#rxonly#txonly#csum#ieee1588");
924 #else
925                                  "io#mac#rxonly#txonly#csum");
926 #endif
927
928 cmdline_parse_inst_t cmd_set_fwd_mode = {
929         .f = cmd_set_fwd_mode_parsed,
930         .data = NULL,
931 #ifdef RTE_LIBRTE_IEEE1588
932         .help_str = "set fwd io|mac|rxonly|txonly|csum|ieee1588 - set IO, MAC,"
933         " RXONLY, TXONLY, CSUM or IEEE1588 packet forwarding mode",
934 #else
935         .help_str = "set fwd io|mac|rxonly|txonly|csum - set IO, MAC,"
936         " RXONLY, CSUM or TXONLY packet forwarding mode",
937 #endif
938         .tokens = {
939                 (void *)&cmd_setfwd_set,
940                 (void *)&cmd_setfwd_fwd,
941                 (void *)&cmd_setfwd_mode,
942                 NULL,
943         },
944 };
945
946 /* *** SET PROMISC MODE *** */
947 struct cmd_set_promisc_mode_result {
948         cmdline_fixed_string_t set;
949         cmdline_fixed_string_t promisc;
950         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
951         uint8_t port_num;                /* valid if "allports" argument == 0 */
952         cmdline_fixed_string_t mode;
953 };
954
955 static void cmd_set_promisc_mode_parsed(void *parsed_result,
956                                         __attribute__((unused)) struct cmdline *cl,
957                                         void *allports)
958 {
959         struct cmd_set_promisc_mode_result *res = parsed_result;
960         int enable;
961         portid_t i;
962
963         if (!strcmp(res->mode, "on"))
964                 enable = 1;
965         else
966                 enable = 0;
967
968         /* all ports */
969         if (allports) {
970                 for (i = 0; i < nb_ports; i++) {
971                         if (enable)
972                                 rte_eth_promiscuous_enable(i);
973                         else
974                                 rte_eth_promiscuous_disable(i);
975                 }
976         }
977         else {
978                 if (enable)
979                         rte_eth_promiscuous_enable(res->port_num);
980                 else
981                         rte_eth_promiscuous_disable(res->port_num);
982         }
983 }
984
985 cmdline_parse_token_string_t cmd_setpromisc_set =
986         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
987 cmdline_parse_token_string_t cmd_setpromisc_promisc =
988         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
989                                  "promisc");
990 cmdline_parse_token_string_t cmd_setpromisc_portall =
991         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
992                                  "all");
993 cmdline_parse_token_num_t cmd_setpromisc_portnum =
994         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
995                               UINT8);
996 cmdline_parse_token_string_t cmd_setpromisc_mode =
997         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
998                                  "on#off");
999
1000 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
1001         .f = cmd_set_promisc_mode_parsed,
1002         .data = (void *)1,
1003         .help_str = "set promisc all on|off: set promisc mode for all ports",
1004         .tokens = {
1005                 (void *)&cmd_setpromisc_set,
1006                 (void *)&cmd_setpromisc_promisc,
1007                 (void *)&cmd_setpromisc_portall,
1008                 (void *)&cmd_setpromisc_mode,
1009                 NULL,
1010         },
1011 };
1012
1013 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
1014         .f = cmd_set_promisc_mode_parsed,
1015         .data = (void *)0,
1016         .help_str = "set promisc X on|off: set promisc mode on port X",
1017         .tokens = {
1018                 (void *)&cmd_setpromisc_set,
1019                 (void *)&cmd_setpromisc_promisc,
1020                 (void *)&cmd_setpromisc_portnum,
1021                 (void *)&cmd_setpromisc_mode,
1022                 NULL,
1023         },
1024 };
1025
1026 /* *** SET ALLMULTI MODE *** */
1027 struct cmd_set_allmulti_mode_result {
1028         cmdline_fixed_string_t set;
1029         cmdline_fixed_string_t allmulti;
1030         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
1031         uint8_t port_num;                /* valid if "allports" argument == 0 */
1032         cmdline_fixed_string_t mode;
1033 };
1034
1035 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
1036                                         __attribute__((unused)) struct cmdline *cl,
1037                                         void *allports)
1038 {
1039         struct cmd_set_allmulti_mode_result *res = parsed_result;
1040         int enable;
1041         portid_t i;
1042
1043         if (!strcmp(res->mode, "on"))
1044                 enable = 1;
1045         else
1046                 enable = 0;
1047
1048         /* all ports */
1049         if (allports) {
1050                 for (i = 0; i < nb_ports; i++) {
1051                         if (enable)
1052                                 rte_eth_allmulticast_enable(i);
1053                         else
1054                                 rte_eth_allmulticast_disable(i);
1055                 }
1056         }
1057         else {
1058                 if (enable)
1059                         rte_eth_allmulticast_enable(res->port_num);
1060                 else
1061                         rte_eth_allmulticast_disable(res->port_num);
1062         }
1063 }
1064
1065 cmdline_parse_token_string_t cmd_setallmulti_set =
1066         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
1067 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
1068         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
1069                                  "allmulti");
1070 cmdline_parse_token_string_t cmd_setallmulti_portall =
1071         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
1072                                  "all");
1073 cmdline_parse_token_num_t cmd_setallmulti_portnum =
1074         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
1075                               UINT8);
1076 cmdline_parse_token_string_t cmd_setallmulti_mode =
1077         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
1078                                  "on#off");
1079
1080 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
1081         .f = cmd_set_allmulti_mode_parsed,
1082         .data = (void *)1,
1083         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
1084         .tokens = {
1085                 (void *)&cmd_setallmulti_set,
1086                 (void *)&cmd_setallmulti_allmulti,
1087                 (void *)&cmd_setallmulti_portall,
1088                 (void *)&cmd_setallmulti_mode,
1089                 NULL,
1090         },
1091 };
1092
1093 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
1094         .f = cmd_set_allmulti_mode_parsed,
1095         .data = (void *)0,
1096         .help_str = "set allmulti X on|off: set allmulti mode on port X",
1097         .tokens = {
1098                 (void *)&cmd_setallmulti_set,
1099                 (void *)&cmd_setallmulti_allmulti,
1100                 (void *)&cmd_setallmulti_portnum,
1101                 (void *)&cmd_setallmulti_mode,
1102                 NULL,
1103         },
1104 };
1105
1106 /* *** ADD/REMOVE A PKT FILTER *** */
1107 struct cmd_pkt_filter_result {
1108         cmdline_fixed_string_t pkt_filter;
1109         uint8_t  port_id;
1110         cmdline_fixed_string_t protocol;
1111         cmdline_fixed_string_t src;
1112         cmdline_ipaddr_t ip_src;
1113         uint16_t port_src;
1114         cmdline_fixed_string_t dst;
1115         cmdline_ipaddr_t ip_dst;
1116         uint16_t port_dst;
1117         cmdline_fixed_string_t flexbytes;
1118         uint16_t flexbytes_value;
1119         cmdline_fixed_string_t vlan;
1120         uint16_t  vlan_id;
1121         cmdline_fixed_string_t queue;
1122         int8_t  queue_id;
1123         cmdline_fixed_string_t soft;
1124         uint8_t  soft_id;
1125 };
1126
1127 static void
1128 cmd_pkt_filter_parsed(void *parsed_result,
1129                           __attribute__((unused)) struct cmdline *cl,
1130                           __attribute__((unused)) void *data)
1131 {
1132         struct rte_fdir_filter fdir_filter;
1133         struct cmd_pkt_filter_result *res = parsed_result;
1134
1135         memset(&fdir_filter, 0, sizeof(struct rte_fdir_filter));
1136
1137         if (res->ip_src.family == AF_INET)
1138                 fdir_filter.ip_src.ipv4_addr = res->ip_src.addr.ipv4.s_addr;
1139         else
1140                 memcpy(&(fdir_filter.ip_src.ipv6_addr),
1141                        &(res->ip_src.addr.ipv6),
1142                        sizeof(struct in6_addr));
1143
1144         if (res->ip_dst.family == AF_INET)
1145                 fdir_filter.ip_dst.ipv4_addr = res->ip_dst.addr.ipv4.s_addr;
1146         else
1147                 memcpy(&(fdir_filter.ip_dst.ipv6_addr),
1148                        &(res->ip_dst.addr.ipv6),
1149                        sizeof(struct in6_addr));
1150
1151         fdir_filter.port_dst = rte_cpu_to_be_16(res->port_dst);
1152         fdir_filter.port_src = rte_cpu_to_be_16(res->port_src);
1153
1154         if (!strcmp(res->protocol, "udp"))
1155                 fdir_filter.l4type = RTE_FDIR_L4TYPE_UDP;
1156         else if (!strcmp(res->protocol, "tcp"))
1157                 fdir_filter.l4type = RTE_FDIR_L4TYPE_TCP;
1158         else if (!strcmp(res->protocol, "sctp"))
1159                 fdir_filter.l4type = RTE_FDIR_L4TYPE_SCTP;
1160         else /* default only IP */
1161                 fdir_filter.l4type = RTE_FDIR_L4TYPE_NONE;
1162
1163         if (res->ip_dst.family == AF_INET6)
1164                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV6;
1165         else
1166                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV4;
1167
1168         fdir_filter.vlan_id    = rte_cpu_to_be_16(res->vlan_id);
1169         fdir_filter.flex_bytes = rte_cpu_to_be_16(res->flexbytes_value);
1170
1171         if (!strcmp(res->pkt_filter, "add_signature_filter"))
1172                 fdir_add_signature_filter(res->port_id, res->queue_id,
1173                                           &fdir_filter);
1174         else if (!strcmp(res->pkt_filter, "upd_signature_filter"))
1175                 fdir_update_signature_filter(res->port_id, res->queue_id,
1176                                              &fdir_filter);
1177         else if (!strcmp(res->pkt_filter, "rm_signature_filter"))
1178                 fdir_remove_signature_filter(res->port_id, &fdir_filter);
1179         else if (!strcmp(res->pkt_filter, "add_perfect_filter"))
1180                 fdir_add_perfect_filter(res->port_id, res->soft_id,
1181                                         res->queue_id,
1182                                         (uint8_t) (res->queue_id < 0),
1183                                         &fdir_filter);
1184         else if (!strcmp(res->pkt_filter, "upd_perfect_filter"))
1185                 fdir_update_perfect_filter(res->port_id, res->soft_id,
1186                                            res->queue_id,
1187                                            (uint8_t) (res->queue_id < 0),
1188                                            &fdir_filter);
1189         else if (!strcmp(res->pkt_filter, "rm_perfect_filter"))
1190                 fdir_remove_perfect_filter(res->port_id, res->soft_id,
1191                                            &fdir_filter);
1192
1193 }
1194
1195
1196 cmdline_parse_token_num_t cmd_pkt_filter_port_id =
1197         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1198                               port_id, UINT8);
1199 cmdline_parse_token_string_t cmd_pkt_filter_protocol =
1200         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1201                                  protocol, "ip#tcp#udp#sctp");
1202 cmdline_parse_token_string_t cmd_pkt_filter_src =
1203         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1204                                  src, "src");
1205 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_src =
1206         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
1207                                  ip_src);
1208 cmdline_parse_token_num_t cmd_pkt_filter_port_src =
1209         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1210                               port_src, UINT16);
1211 cmdline_parse_token_string_t cmd_pkt_filter_dst =
1212         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1213                                  dst, "dst");
1214 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_dst =
1215         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
1216                                  ip_dst);
1217 cmdline_parse_token_num_t cmd_pkt_filter_port_dst =
1218         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1219                               port_dst, UINT16);
1220 cmdline_parse_token_string_t cmd_pkt_filter_flexbytes =
1221         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1222                                  flexbytes, "flexbytes");
1223 cmdline_parse_token_num_t cmd_pkt_filter_flexbytes_value =
1224         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1225                               flexbytes_value, UINT16);
1226 cmdline_parse_token_string_t cmd_pkt_filter_vlan =
1227         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1228                                  vlan, "vlan");
1229 cmdline_parse_token_num_t cmd_pkt_filter_vlan_id =
1230         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1231                               vlan_id, UINT16);
1232 cmdline_parse_token_string_t cmd_pkt_filter_queue =
1233         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1234                                  queue, "queue");
1235 cmdline_parse_token_num_t cmd_pkt_filter_queue_id =
1236         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1237                               queue_id, INT8);
1238 cmdline_parse_token_string_t cmd_pkt_filter_soft =
1239         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1240                                  soft, "soft");
1241 cmdline_parse_token_num_t cmd_pkt_filter_soft_id =
1242         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1243                               soft_id, UINT16);
1244
1245
1246 cmdline_parse_token_string_t cmd_pkt_filter_add_signature_filter =
1247         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1248                                  pkt_filter, "add_signature_filter");
1249 cmdline_parse_inst_t cmd_add_signature_filter = {
1250         .f = cmd_pkt_filter_parsed,
1251         .data = NULL,
1252         .help_str = "add a signature filter",
1253         .tokens = {
1254                 (void *)&cmd_pkt_filter_add_signature_filter,
1255                 (void *)&cmd_pkt_filter_port_id,
1256                 (void *)&cmd_pkt_filter_protocol,
1257                 (void *)&cmd_pkt_filter_src,
1258                 (void *)&cmd_pkt_filter_ip_src,
1259                 (void *)&cmd_pkt_filter_port_src,
1260                 (void *)&cmd_pkt_filter_dst,
1261                 (void *)&cmd_pkt_filter_ip_dst,
1262                 (void *)&cmd_pkt_filter_port_dst,
1263                 (void *)&cmd_pkt_filter_flexbytes,
1264                 (void *)&cmd_pkt_filter_flexbytes_value,
1265                 (void *)&cmd_pkt_filter_vlan,
1266                 (void *)&cmd_pkt_filter_vlan_id,
1267                 (void *)&cmd_pkt_filter_queue,
1268                 (void *)&cmd_pkt_filter_queue_id,
1269                 NULL,
1270         },
1271 };
1272
1273
1274 cmdline_parse_token_string_t cmd_pkt_filter_upd_signature_filter =
1275         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1276                                  pkt_filter, "upd_signature_filter");
1277 cmdline_parse_inst_t cmd_upd_signature_filter = {
1278         .f = cmd_pkt_filter_parsed,
1279         .data = NULL,
1280         .help_str = "update a signature filter",
1281         .tokens = {
1282                 (void *)&cmd_pkt_filter_upd_signature_filter,
1283                 (void *)&cmd_pkt_filter_port_id,
1284                 (void *)&cmd_pkt_filter_protocol,
1285                 (void *)&cmd_pkt_filter_src,
1286                 (void *)&cmd_pkt_filter_ip_src,
1287                 (void *)&cmd_pkt_filter_port_src,
1288                 (void *)&cmd_pkt_filter_dst,
1289                 (void *)&cmd_pkt_filter_ip_dst,
1290                 (void *)&cmd_pkt_filter_port_dst,
1291                 (void *)&cmd_pkt_filter_flexbytes,
1292                 (void *)&cmd_pkt_filter_flexbytes_value,
1293                 (void *)&cmd_pkt_filter_vlan,
1294                 (void *)&cmd_pkt_filter_vlan_id,
1295                 (void *)&cmd_pkt_filter_queue,
1296                 (void *)&cmd_pkt_filter_queue_id,
1297                 NULL,
1298         },
1299 };
1300
1301
1302 cmdline_parse_token_string_t cmd_pkt_filter_rm_signature_filter =
1303         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1304                                  pkt_filter, "rm_signature_filter");
1305 cmdline_parse_inst_t cmd_rm_signature_filter = {
1306         .f = cmd_pkt_filter_parsed,
1307         .data = NULL,
1308         .help_str = "remove a signature filter",
1309         .tokens = {
1310                 (void *)&cmd_pkt_filter_rm_signature_filter,
1311                 (void *)&cmd_pkt_filter_port_id,
1312                 (void *)&cmd_pkt_filter_protocol,
1313                 (void *)&cmd_pkt_filter_src,
1314                 (void *)&cmd_pkt_filter_ip_src,
1315                 (void *)&cmd_pkt_filter_port_src,
1316                 (void *)&cmd_pkt_filter_dst,
1317                 (void *)&cmd_pkt_filter_ip_dst,
1318                 (void *)&cmd_pkt_filter_port_dst,
1319                 (void *)&cmd_pkt_filter_flexbytes,
1320                 (void *)&cmd_pkt_filter_flexbytes_value,
1321                 (void *)&cmd_pkt_filter_vlan,
1322                 (void *)&cmd_pkt_filter_vlan_id,
1323                 NULL
1324                 },
1325 };
1326
1327
1328 cmdline_parse_token_string_t cmd_pkt_filter_add_perfect_filter =
1329         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1330                                  pkt_filter, "add_perfect_filter");
1331 cmdline_parse_inst_t cmd_add_perfect_filter = {
1332         .f = cmd_pkt_filter_parsed,
1333         .data = NULL,
1334         .help_str = "add a perfect filter",
1335         .tokens = {
1336                 (void *)&cmd_pkt_filter_add_perfect_filter,
1337                 (void *)&cmd_pkt_filter_port_id,
1338                 (void *)&cmd_pkt_filter_protocol,
1339                 (void *)&cmd_pkt_filter_src,
1340                 (void *)&cmd_pkt_filter_ip_src,
1341                 (void *)&cmd_pkt_filter_port_src,
1342                 (void *)&cmd_pkt_filter_dst,
1343                 (void *)&cmd_pkt_filter_ip_dst,
1344                 (void *)&cmd_pkt_filter_port_dst,
1345                 (void *)&cmd_pkt_filter_flexbytes,
1346                 (void *)&cmd_pkt_filter_flexbytes_value,
1347                 (void *)&cmd_pkt_filter_vlan,
1348                 (void *)&cmd_pkt_filter_vlan_id,
1349                 (void *)&cmd_pkt_filter_queue,
1350                 (void *)&cmd_pkt_filter_queue_id,
1351                 (void *)&cmd_pkt_filter_soft,
1352                 (void *)&cmd_pkt_filter_soft_id,
1353                 NULL,
1354         },
1355 };
1356
1357
1358 cmdline_parse_token_string_t cmd_pkt_filter_upd_perfect_filter =
1359         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1360                                  pkt_filter, "upd_perfect_filter");
1361 cmdline_parse_inst_t cmd_upd_perfect_filter = {
1362         .f = cmd_pkt_filter_parsed,
1363         .data = NULL,
1364         .help_str = "update a perfect filter",
1365         .tokens = {
1366                 (void *)&cmd_pkt_filter_upd_perfect_filter,
1367                 (void *)&cmd_pkt_filter_port_id,
1368                 (void *)&cmd_pkt_filter_protocol,
1369                 (void *)&cmd_pkt_filter_src,
1370                 (void *)&cmd_pkt_filter_ip_src,
1371                 (void *)&cmd_pkt_filter_port_src,
1372                 (void *)&cmd_pkt_filter_dst,
1373                 (void *)&cmd_pkt_filter_ip_dst,
1374                 (void *)&cmd_pkt_filter_port_dst,
1375                 (void *)&cmd_pkt_filter_flexbytes,
1376                 (void *)&cmd_pkt_filter_flexbytes_value,
1377                 (void *)&cmd_pkt_filter_vlan,
1378                 (void *)&cmd_pkt_filter_vlan_id,
1379                 (void *)&cmd_pkt_filter_queue,
1380                 (void *)&cmd_pkt_filter_queue_id,
1381                 (void *)&cmd_pkt_filter_soft,
1382                 (void *)&cmd_pkt_filter_soft_id,
1383                 NULL,
1384         },
1385 };
1386
1387
1388 cmdline_parse_token_string_t cmd_pkt_filter_rm_perfect_filter =
1389         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1390                                  pkt_filter, "rm_perfect_filter");
1391 cmdline_parse_inst_t cmd_rm_perfect_filter = {
1392         .f = cmd_pkt_filter_parsed,
1393         .data = NULL,
1394         .help_str = "remove a perfect filter",
1395         .tokens = {
1396                 (void *)&cmd_pkt_filter_rm_perfect_filter,
1397                 (void *)&cmd_pkt_filter_port_id,
1398                 (void *)&cmd_pkt_filter_protocol,
1399                 (void *)&cmd_pkt_filter_src,
1400                 (void *)&cmd_pkt_filter_ip_src,
1401                 (void *)&cmd_pkt_filter_port_src,
1402                 (void *)&cmd_pkt_filter_dst,
1403                 (void *)&cmd_pkt_filter_ip_dst,
1404                 (void *)&cmd_pkt_filter_port_dst,
1405                 (void *)&cmd_pkt_filter_flexbytes,
1406                 (void *)&cmd_pkt_filter_flexbytes_value,
1407                 (void *)&cmd_pkt_filter_vlan,
1408                 (void *)&cmd_pkt_filter_vlan_id,
1409                 (void *)&cmd_pkt_filter_soft,
1410                 (void *)&cmd_pkt_filter_soft_id,
1411                 NULL,
1412         },
1413 };
1414
1415 /* *** SETUP MASKS FILTER *** */
1416 struct cmd_pkt_filter_masks_result {
1417         cmdline_fixed_string_t filter_mask;
1418         uint8_t  port_id;
1419         cmdline_fixed_string_t src_mask;
1420         uint32_t ip_src_mask;
1421         uint16_t ipv6_src_mask;
1422         uint16_t port_src_mask;
1423         cmdline_fixed_string_t dst_mask;
1424         uint32_t ip_dst_mask;
1425         uint16_t ipv6_dst_mask;
1426         uint16_t port_dst_mask;
1427         cmdline_fixed_string_t flexbytes;
1428         uint8_t flexbytes_value;
1429         cmdline_fixed_string_t vlan_id;
1430         uint8_t  vlan_id_value;
1431         cmdline_fixed_string_t vlan_prio;
1432         uint8_t  vlan_prio_value;
1433         cmdline_fixed_string_t only_ip_flow;
1434         uint8_t  only_ip_flow_value;
1435         cmdline_fixed_string_t comp_ipv6_dst;
1436         uint8_t  comp_ipv6_dst_value;
1437 };
1438
1439 static void
1440 cmd_pkt_filter_masks_parsed(void *parsed_result,
1441                           __attribute__((unused)) struct cmdline *cl,
1442                           __attribute__((unused)) void *data)
1443 {
1444         struct rte_fdir_masks fdir_masks;
1445         struct cmd_pkt_filter_masks_result *res = parsed_result;
1446
1447         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
1448
1449         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
1450         fdir_masks.vlan_id       = res->vlan_id_value;
1451         fdir_masks.vlan_prio     = res->vlan_prio_value;
1452         fdir_masks.dst_ipv4_mask = res->ip_dst_mask;
1453         fdir_masks.src_ipv4_mask = res->ip_src_mask;
1454         fdir_masks.src_port_mask = res->port_src_mask;
1455         fdir_masks.dst_port_mask = res->port_dst_mask;
1456         fdir_masks.flexbytes     = res->flexbytes_value;
1457
1458         fdir_set_masks(res->port_id, &fdir_masks);
1459 }
1460
1461 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask =
1462         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1463                                  filter_mask, "set_masks_filter");
1464 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_id =
1465         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1466                               port_id, UINT8);
1467 cmdline_parse_token_string_t cmd_pkt_filter_masks_only_ip_flow =
1468         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1469                                  only_ip_flow, "only_ip_flow");
1470 cmdline_parse_token_num_t cmd_pkt_filter_masks_only_ip_flow_value =
1471         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1472                               only_ip_flow_value, UINT8);
1473 cmdline_parse_token_string_t cmd_pkt_filter_masks_src_mask =
1474         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1475                                  src_mask, "src_mask");
1476 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_src_mask =
1477         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1478                               ip_src_mask, UINT32);
1479 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_src_mask =
1480         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1481                               port_src_mask, UINT16);
1482 cmdline_parse_token_string_t cmd_pkt_filter_masks_dst_mask =
1483         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1484                                  src_mask, "dst_mask");
1485 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_dst_mask =
1486         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1487                               ip_dst_mask, UINT32);
1488 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_dst_mask =
1489         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1490                               port_dst_mask, UINT16);
1491 cmdline_parse_token_string_t cmd_pkt_filter_masks_flexbytes =
1492         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1493                                  flexbytes, "flexbytes");
1494 cmdline_parse_token_num_t cmd_pkt_filter_masks_flexbytes_value =
1495         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1496                               flexbytes_value, UINT8);
1497 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_id =
1498         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1499                                  vlan_id, "vlan_id");
1500 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_id_value =
1501         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1502                               vlan_id_value, UINT8);
1503 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_prio =
1504         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1505                                  vlan_prio, "vlan_prio");
1506 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_prio_value =
1507         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1508                               vlan_prio_value, UINT8);
1509
1510 cmdline_parse_inst_t cmd_set_masks_filter = {
1511         .f = cmd_pkt_filter_masks_parsed,
1512         .data = NULL,
1513         .help_str = "setup masks filter",
1514         .tokens = {
1515                 (void *)&cmd_pkt_filter_masks_filter_mask,
1516                 (void *)&cmd_pkt_filter_masks_port_id,
1517                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
1518                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
1519                 (void *)&cmd_pkt_filter_masks_src_mask,
1520                 (void *)&cmd_pkt_filter_masks_ip_src_mask,
1521                 (void *)&cmd_pkt_filter_masks_port_src_mask,
1522                 (void *)&cmd_pkt_filter_masks_dst_mask,
1523                 (void *)&cmd_pkt_filter_masks_ip_dst_mask,
1524                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
1525                 (void *)&cmd_pkt_filter_masks_flexbytes,
1526                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
1527                 (void *)&cmd_pkt_filter_masks_vlan_id,
1528                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
1529                 (void *)&cmd_pkt_filter_masks_vlan_prio,
1530                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
1531                 NULL,
1532         },
1533 };
1534
1535 static void
1536 cmd_pkt_filter_masks_ipv6_parsed(void *parsed_result,
1537                           __attribute__((unused)) struct cmdline *cl,
1538                           __attribute__((unused)) void *data)
1539 {
1540         struct rte_fdir_masks fdir_masks;
1541         struct cmd_pkt_filter_masks_result *res = parsed_result;
1542
1543         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
1544
1545         fdir_masks.set_ipv6_mask = 1;
1546         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
1547         fdir_masks.vlan_id       = res->vlan_id_value;
1548         fdir_masks.vlan_prio     = res->vlan_prio_value;
1549         fdir_masks.dst_ipv6_mask = res->ipv6_dst_mask;
1550         fdir_masks.src_ipv6_mask = res->ipv6_src_mask;
1551         fdir_masks.src_port_mask = res->port_src_mask;
1552         fdir_masks.dst_port_mask = res->port_dst_mask;
1553         fdir_masks.flexbytes     = res->flexbytes_value;
1554         fdir_masks.comp_ipv6_dst = res->comp_ipv6_dst_value;
1555
1556         fdir_set_masks(res->port_id, &fdir_masks);
1557 }
1558
1559 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask_ipv6 =
1560         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1561                                  filter_mask, "set_ipv6_masks_filter");
1562 cmdline_parse_token_num_t cmd_pkt_filter_masks_src_mask_ipv6_value =
1563         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1564                               ipv6_src_mask, UINT16);
1565 cmdline_parse_token_num_t cmd_pkt_filter_masks_dst_mask_ipv6_value =
1566         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1567                               ipv6_dst_mask, UINT16);
1568
1569 cmdline_parse_token_string_t cmd_pkt_filter_masks_comp_ipv6_dst =
1570         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1571                                  comp_ipv6_dst, "compare_dst");
1572 cmdline_parse_token_num_t cmd_pkt_filter_masks_comp_ipv6_dst_value =
1573         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1574                               comp_ipv6_dst_value, UINT8);
1575
1576 cmdline_parse_inst_t cmd_set_ipv6_masks_filter = {
1577         .f = cmd_pkt_filter_masks_ipv6_parsed,
1578         .data = NULL,
1579         .help_str = "setup ipv6 masks filter",
1580         .tokens = {
1581                 (void *)&cmd_pkt_filter_masks_filter_mask_ipv6,
1582                 (void *)&cmd_pkt_filter_masks_port_id,
1583                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
1584                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
1585                 (void *)&cmd_pkt_filter_masks_src_mask,
1586                 (void *)&cmd_pkt_filter_masks_src_mask_ipv6_value,
1587                 (void *)&cmd_pkt_filter_masks_port_src_mask,
1588                 (void *)&cmd_pkt_filter_masks_dst_mask,
1589                 (void *)&cmd_pkt_filter_masks_dst_mask_ipv6_value,
1590                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
1591                 (void *)&cmd_pkt_filter_masks_flexbytes,
1592                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
1593                 (void *)&cmd_pkt_filter_masks_vlan_id,
1594                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
1595                 (void *)&cmd_pkt_filter_masks_vlan_prio,
1596                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
1597                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst,
1598                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst_value,
1599                 NULL,
1600         },
1601 };
1602
1603 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
1604 struct cmd_link_flow_ctrl_set_result {
1605         cmdline_fixed_string_t set;
1606         cmdline_fixed_string_t flow_ctrl;
1607         cmdline_fixed_string_t rx;
1608         cmdline_fixed_string_t rx_lfc_mode;
1609         cmdline_fixed_string_t tx;
1610         cmdline_fixed_string_t tx_lfc_mode;
1611         uint32_t high_water;
1612         uint32_t low_water;
1613         uint16_t pause_time;
1614         uint16_t send_xon;
1615         uint8_t  port_id;
1616 };
1617
1618 static void
1619 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
1620                        __attribute__((unused)) struct cmdline *cl,
1621                        __attribute__((unused)) void *data)
1622 {
1623         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
1624         struct rte_eth_fc_conf fc_conf;
1625         int rx_fc_enable, tx_fc_enable;
1626         int ret;
1627
1628         /*
1629          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
1630          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
1631          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
1632          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
1633          */
1634         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
1635                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
1636         };
1637
1638         rx_fc_enable = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
1639         tx_fc_enable = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
1640
1641         fc_conf.mode       = rx_tx_onoff_2_lfc_mode[rx_fc_enable][tx_fc_enable];
1642         fc_conf.high_water = res->high_water;
1643         fc_conf.low_water  = res->low_water;
1644         fc_conf.pause_time = res->pause_time;
1645         fc_conf.send_xon   = res->send_xon;
1646
1647         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
1648         if (ret != 0)
1649                 printf("bad flow contrl parameter, return code = %d \n", ret);
1650 }
1651
1652 cmdline_parse_token_string_t cmd_lfc_set_set =
1653         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1654                                 set, "set");
1655 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
1656         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1657                                 flow_ctrl, "flow_ctrl");
1658 cmdline_parse_token_string_t cmd_lfc_set_rx =
1659         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1660                                 rx, "rx");
1661 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
1662         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1663                                 rx_lfc_mode, "on#off");
1664 cmdline_parse_token_string_t cmd_lfc_set_tx =
1665         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1666                                 tx, "tx");
1667 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
1668         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1669                                 tx_lfc_mode, "on#off");
1670 cmdline_parse_token_num_t cmd_lfc_set_high_water =
1671         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1672                                 high_water, UINT32);
1673 cmdline_parse_token_num_t cmd_lfc_set_low_water =
1674         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1675                                 low_water, UINT32);
1676 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
1677         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1678                                 pause_time, UINT16);
1679 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
1680         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1681                                 send_xon, UINT16);
1682 cmdline_parse_token_num_t cmd_lfc_set_portid =
1683         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1684                                 port_id, UINT8);
1685
1686 cmdline_parse_inst_t cmd_link_flow_control_set = {
1687         .f = cmd_link_flow_ctrl_set_parsed,
1688         .data = NULL,
1689         .help_str = "Configure the Ethernet link flow control...",
1690         .tokens = {
1691                 (void *)&cmd_lfc_set_set,
1692                 (void *)&cmd_lfc_set_flow_ctrl,
1693                 (void *)&cmd_lfc_set_rx,
1694                 (void *)&cmd_lfc_set_rx_mode,
1695                 (void *)&cmd_lfc_set_tx,
1696                 (void *)&cmd_lfc_set_tx_mode,
1697                 (void *)&cmd_lfc_set_high_water,
1698                 (void *)&cmd_lfc_set_low_water,
1699                 (void *)&cmd_lfc_set_pause_time,
1700                 (void *)&cmd_lfc_set_send_xon,
1701                 (void *)&cmd_lfc_set_portid,
1702                 NULL,
1703         },
1704 };
1705
1706 /* *** RESET CONFIGURATION *** */
1707 struct cmd_reset_result {
1708         cmdline_fixed_string_t reset;
1709         cmdline_fixed_string_t def;
1710 };
1711
1712 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
1713                              struct cmdline *cl,
1714                              __attribute__((unused)) void *data)
1715 {
1716         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
1717         set_def_fwd_config();
1718 }
1719
1720 cmdline_parse_token_string_t cmd_reset_set =
1721         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
1722 cmdline_parse_token_string_t cmd_reset_def =
1723         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
1724                                  "default");
1725
1726 cmdline_parse_inst_t cmd_reset = {
1727         .f = cmd_reset_parsed,
1728         .data = NULL,
1729         .help_str = "set default: reset default forwarding configuration",
1730         .tokens = {
1731                 (void *)&cmd_reset_set,
1732                 (void *)&cmd_reset_def,
1733                 NULL,
1734         },
1735 };
1736
1737 /* *** START FORWARDING *** */
1738 struct cmd_start_result {
1739         cmdline_fixed_string_t start;
1740 };
1741
1742 cmdline_parse_token_string_t cmd_start_start =
1743         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
1744
1745 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
1746                              __attribute__((unused)) struct cmdline *cl,
1747                              __attribute__((unused)) void *data)
1748 {
1749         start_packet_forwarding(0);
1750 }
1751
1752 cmdline_parse_inst_t cmd_start = {
1753         .f = cmd_start_parsed,
1754         .data = NULL,
1755         .help_str = "start packet forwarding",
1756         .tokens = {
1757                 (void *)&cmd_start_start,
1758                 NULL,
1759         },
1760 };
1761
1762 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
1763 struct cmd_start_tx_first_result {
1764         cmdline_fixed_string_t start;
1765         cmdline_fixed_string_t tx_first;
1766 };
1767
1768 static void
1769 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
1770                           __attribute__((unused)) struct cmdline *cl,
1771                           __attribute__((unused)) void *data)
1772 {
1773         start_packet_forwarding(1);
1774 }
1775
1776 cmdline_parse_token_string_t cmd_start_tx_first_start =
1777         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
1778                                  "start");
1779 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
1780         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
1781                                  tx_first, "tx_first");
1782
1783 cmdline_parse_inst_t cmd_start_tx_first = {
1784         .f = cmd_start_tx_first_parsed,
1785         .data = NULL,
1786         .help_str = "start packet forwarding, after sending 1 burst of packets",
1787         .tokens = {
1788                 (void *)&cmd_start_tx_first_start,
1789                 (void *)&cmd_start_tx_first_tx_first,
1790                 NULL,
1791         },
1792 };
1793
1794 /* *** SHOW CFG *** */
1795 struct cmd_showcfg_result {
1796         cmdline_fixed_string_t show;
1797         cmdline_fixed_string_t cfg;
1798         cmdline_fixed_string_t what;
1799 };
1800
1801 static void cmd_showcfg_parsed(void *parsed_result,
1802                                __attribute__((unused)) struct cmdline *cl,
1803                                __attribute__((unused)) void *data)
1804 {
1805         struct cmd_showcfg_result *res = parsed_result;
1806         if (!strcmp(res->what, "rxtx"))
1807                 rxtx_config_display();
1808         else if (!strcmp(res->what, "cores"))
1809                 fwd_lcores_config_display();
1810         else if (!strcmp(res->what, "fwd"))
1811                 fwd_config_display();
1812 }
1813
1814 cmdline_parse_token_string_t cmd_showcfg_show =
1815         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
1816 cmdline_parse_token_string_t cmd_showcfg_port =
1817         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
1818 cmdline_parse_token_string_t cmd_showcfg_what =
1819         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
1820                                  "rxtx#cores#fwd");
1821
1822 cmdline_parse_inst_t cmd_showcfg = {
1823         .f = cmd_showcfg_parsed,
1824         .data = NULL,
1825         .help_str = "show config rxtx|cores|fwd",
1826         .tokens = {
1827                 (void *)&cmd_showcfg_show,
1828                 (void *)&cmd_showcfg_port,
1829                 (void *)&cmd_showcfg_what,
1830                 NULL,
1831         },
1832 };
1833
1834 /* *** SHOW ALL PORT INFO *** */
1835 struct cmd_showportall_result {
1836         cmdline_fixed_string_t show;
1837         cmdline_fixed_string_t port;
1838         cmdline_fixed_string_t what;
1839         cmdline_fixed_string_t all;
1840 };
1841
1842 static void cmd_showportall_parsed(void *parsed_result,
1843                                 __attribute__((unused)) struct cmdline *cl,
1844                                 __attribute__((unused)) void *data)
1845 {
1846         portid_t i;
1847
1848         struct cmd_showportall_result *res = parsed_result;
1849         if (!strcmp(res->show, "clear")) {
1850                 if (!strcmp(res->what, "stats"))
1851                         for (i = 0; i < nb_ports; i++)
1852                                 nic_stats_clear(i);
1853         } else if (!strcmp(res->what, "info"))
1854                 for (i = 0; i < nb_ports; i++)
1855                         port_infos_display(i);
1856         else if (!strcmp(res->what, "stats"))
1857                 for (i = 0; i < nb_ports; i++)
1858                         nic_stats_display(i);
1859         else if (!strcmp(res->what, "fdir"))
1860                 for (i = 0; i < nb_ports; i++)
1861                         fdir_get_infos(i);
1862         else if (!strcmp(res->what, "stat_qmap"))
1863                 for (i = 0; i < nb_ports; i++)
1864                         nic_stats_mapping_display(i);
1865 }
1866
1867 cmdline_parse_token_string_t cmd_showportall_show =
1868         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
1869                                  "show#clear");
1870 cmdline_parse_token_string_t cmd_showportall_port =
1871         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
1872 cmdline_parse_token_string_t cmd_showportall_what =
1873         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
1874                                  "info#stats#fdir#stat_qmap");
1875 cmdline_parse_token_string_t cmd_showportall_all =
1876         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
1877 cmdline_parse_inst_t cmd_showportall = {
1878         .f = cmd_showportall_parsed,
1879         .data = NULL,
1880         .help_str = "show|clear port info|stats|fdir|stat_qmap all",
1881         .tokens = {
1882                 (void *)&cmd_showportall_show,
1883                 (void *)&cmd_showportall_port,
1884                 (void *)&cmd_showportall_what,
1885                 (void *)&cmd_showportall_all,
1886                 NULL,
1887         },
1888 };
1889
1890 /* *** SHOW PORT INFO *** */
1891 struct cmd_showport_result {
1892         cmdline_fixed_string_t show;
1893         cmdline_fixed_string_t port;
1894         cmdline_fixed_string_t what;
1895         uint8_t portnum;
1896 };
1897
1898 static void cmd_showport_parsed(void *parsed_result,
1899                                 __attribute__((unused)) struct cmdline *cl,
1900                                 __attribute__((unused)) void *data)
1901 {
1902         struct cmd_showport_result *res = parsed_result;
1903         if (!strcmp(res->show, "clear")) {
1904                 if (!strcmp(res->what, "stats"))
1905                         nic_stats_clear(res->portnum);
1906         } else if (!strcmp(res->what, "info"))
1907                 port_infos_display(res->portnum);
1908         else if (!strcmp(res->what, "stats"))
1909                 nic_stats_display(res->portnum);
1910         else if (!strcmp(res->what, "fdir"))
1911                  fdir_get_infos(res->portnum);
1912         else if (!strcmp(res->what, "stat_qmap"))
1913                 nic_stats_mapping_display(res->portnum);
1914 }
1915
1916 cmdline_parse_token_string_t cmd_showport_show =
1917         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
1918                                  "show#clear");
1919 cmdline_parse_token_string_t cmd_showport_port =
1920         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
1921 cmdline_parse_token_string_t cmd_showport_what =
1922         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
1923                                  "info#stats#fdir#stat_qmap");
1924 cmdline_parse_token_num_t cmd_showport_portnum =
1925         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, INT32);
1926
1927 cmdline_parse_inst_t cmd_showport = {
1928         .f = cmd_showport_parsed,
1929         .data = NULL,
1930         .help_str = "show|clear port info|stats|fdir|stat_qmap X (X = port number)",
1931         .tokens = {
1932                 (void *)&cmd_showport_show,
1933                 (void *)&cmd_showport_port,
1934                 (void *)&cmd_showport_what,
1935                 (void *)&cmd_showport_portnum,
1936                 NULL,
1937         },
1938 };
1939
1940 /* *** READ PORT REGISTER *** */
1941 struct cmd_read_reg_result {
1942         cmdline_fixed_string_t read;
1943         cmdline_fixed_string_t reg;
1944         uint8_t port_id;
1945         uint32_t reg_off;
1946 };
1947
1948 static void
1949 cmd_read_reg_parsed(void *parsed_result,
1950                     __attribute__((unused)) struct cmdline *cl,
1951                     __attribute__((unused)) void *data)
1952 {
1953         struct cmd_read_reg_result *res = parsed_result;
1954         port_reg_display(res->port_id, res->reg_off);
1955 }
1956
1957 cmdline_parse_token_string_t cmd_read_reg_read =
1958         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
1959 cmdline_parse_token_string_t cmd_read_reg_reg =
1960         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
1961 cmdline_parse_token_num_t cmd_read_reg_port_id =
1962         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
1963 cmdline_parse_token_num_t cmd_read_reg_reg_off =
1964         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
1965
1966 cmdline_parse_inst_t cmd_read_reg = {
1967         .f = cmd_read_reg_parsed,
1968         .data = NULL,
1969         .help_str = "read reg port_id reg_off",
1970         .tokens = {
1971                 (void *)&cmd_read_reg_read,
1972                 (void *)&cmd_read_reg_reg,
1973                 (void *)&cmd_read_reg_port_id,
1974                 (void *)&cmd_read_reg_reg_off,
1975                 NULL,
1976         },
1977 };
1978
1979 /* *** READ PORT REGISTER BIT FIELD *** */
1980 struct cmd_read_reg_bit_field_result {
1981         cmdline_fixed_string_t read;
1982         cmdline_fixed_string_t regfield;
1983         uint8_t port_id;
1984         uint32_t reg_off;
1985         uint8_t bit1_pos;
1986         uint8_t bit2_pos;
1987 };
1988
1989 static void
1990 cmd_read_reg_bit_field_parsed(void *parsed_result,
1991                               __attribute__((unused)) struct cmdline *cl,
1992                               __attribute__((unused)) void *data)
1993 {
1994         struct cmd_read_reg_bit_field_result *res = parsed_result;
1995         port_reg_bit_field_display(res->port_id, res->reg_off,
1996                                    res->bit1_pos, res->bit2_pos);
1997 }
1998
1999 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
2000         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
2001                                  "read");
2002 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
2003         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
2004                                  regfield, "regfield");
2005 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
2006         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
2007                               UINT8);
2008 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
2009         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
2010                               UINT32);
2011 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
2012         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
2013                               UINT8);
2014 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
2015         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
2016                               UINT8);
2017
2018 cmdline_parse_inst_t cmd_read_reg_bit_field = {
2019         .f = cmd_read_reg_bit_field_parsed,
2020         .data = NULL,
2021         .help_str = "read regfield port_id reg_off bit_x bit_y "
2022         "(read register bit field between bit_x and bit_y included)",
2023         .tokens = {
2024                 (void *)&cmd_read_reg_bit_field_read,
2025                 (void *)&cmd_read_reg_bit_field_regfield,
2026                 (void *)&cmd_read_reg_bit_field_port_id,
2027                 (void *)&cmd_read_reg_bit_field_reg_off,
2028                 (void *)&cmd_read_reg_bit_field_bit1_pos,
2029                 (void *)&cmd_read_reg_bit_field_bit2_pos,
2030                 NULL,
2031         },
2032 };
2033
2034 /* *** READ PORT REGISTER BIT *** */
2035 struct cmd_read_reg_bit_result {
2036         cmdline_fixed_string_t read;
2037         cmdline_fixed_string_t regbit;
2038         uint8_t port_id;
2039         uint32_t reg_off;
2040         uint8_t bit_pos;
2041 };
2042
2043 static void
2044 cmd_read_reg_bit_parsed(void *parsed_result,
2045                         __attribute__((unused)) struct cmdline *cl,
2046                         __attribute__((unused)) void *data)
2047 {
2048         struct cmd_read_reg_bit_result *res = parsed_result;
2049         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
2050 }
2051
2052 cmdline_parse_token_string_t cmd_read_reg_bit_read =
2053         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
2054 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
2055         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
2056                                  regbit, "regbit");
2057 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
2058         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
2059 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
2060         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
2061 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
2062         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
2063
2064 cmdline_parse_inst_t cmd_read_reg_bit = {
2065         .f = cmd_read_reg_bit_parsed,
2066         .data = NULL,
2067         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
2068         .tokens = {
2069                 (void *)&cmd_read_reg_bit_read,
2070                 (void *)&cmd_read_reg_bit_regbit,
2071                 (void *)&cmd_read_reg_bit_port_id,
2072                 (void *)&cmd_read_reg_bit_reg_off,
2073                 (void *)&cmd_read_reg_bit_bit_pos,
2074                 NULL,
2075         },
2076 };
2077
2078 /* *** WRITE PORT REGISTER *** */
2079 struct cmd_write_reg_result {
2080         cmdline_fixed_string_t write;
2081         cmdline_fixed_string_t reg;
2082         uint8_t port_id;
2083         uint32_t reg_off;
2084         uint32_t value;
2085 };
2086
2087 static void
2088 cmd_write_reg_parsed(void *parsed_result,
2089                      __attribute__((unused)) struct cmdline *cl,
2090                      __attribute__((unused)) void *data)
2091 {
2092         struct cmd_write_reg_result *res = parsed_result;
2093         port_reg_set(res->port_id, res->reg_off, res->value);
2094 }
2095
2096 cmdline_parse_token_string_t cmd_write_reg_write =
2097         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
2098 cmdline_parse_token_string_t cmd_write_reg_reg =
2099         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
2100 cmdline_parse_token_num_t cmd_write_reg_port_id =
2101         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
2102 cmdline_parse_token_num_t cmd_write_reg_reg_off =
2103         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
2104 cmdline_parse_token_num_t cmd_write_reg_value =
2105         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
2106
2107 cmdline_parse_inst_t cmd_write_reg = {
2108         .f = cmd_write_reg_parsed,
2109         .data = NULL,
2110         .help_str = "write reg port_id reg_off reg_value",
2111         .tokens = {
2112                 (void *)&cmd_write_reg_write,
2113                 (void *)&cmd_write_reg_reg,
2114                 (void *)&cmd_write_reg_port_id,
2115                 (void *)&cmd_write_reg_reg_off,
2116                 (void *)&cmd_write_reg_value,
2117                 NULL,
2118         },
2119 };
2120
2121 /* *** WRITE PORT REGISTER BIT FIELD *** */
2122 struct cmd_write_reg_bit_field_result {
2123         cmdline_fixed_string_t write;
2124         cmdline_fixed_string_t regfield;
2125         uint8_t port_id;
2126         uint32_t reg_off;
2127         uint8_t bit1_pos;
2128         uint8_t bit2_pos;
2129         uint32_t value;
2130 };
2131
2132 static void
2133 cmd_write_reg_bit_field_parsed(void *parsed_result,
2134                                __attribute__((unused)) struct cmdline *cl,
2135                                __attribute__((unused)) void *data)
2136 {
2137         struct cmd_write_reg_bit_field_result *res = parsed_result;
2138         port_reg_bit_field_set(res->port_id, res->reg_off,
2139                           res->bit1_pos, res->bit2_pos, res->value);
2140 }
2141
2142 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
2143         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
2144                                  "write");
2145 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
2146         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
2147                                  regfield, "regfield");
2148 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
2149         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
2150                               UINT8);
2151 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
2152         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
2153                               UINT32);
2154 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
2155         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
2156                               UINT8);
2157 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
2158         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
2159                               UINT8);
2160 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
2161         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
2162                               UINT32);
2163
2164 cmdline_parse_inst_t cmd_write_reg_bit_field = {
2165         .f = cmd_write_reg_bit_field_parsed,
2166         .data = NULL,
2167         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
2168         "(set register bit field between bit_x and bit_y included)",
2169         .tokens = {
2170                 (void *)&cmd_write_reg_bit_field_write,
2171                 (void *)&cmd_write_reg_bit_field_regfield,
2172                 (void *)&cmd_write_reg_bit_field_port_id,
2173                 (void *)&cmd_write_reg_bit_field_reg_off,
2174                 (void *)&cmd_write_reg_bit_field_bit1_pos,
2175                 (void *)&cmd_write_reg_bit_field_bit2_pos,
2176                 (void *)&cmd_write_reg_bit_field_value,
2177                 NULL,
2178         },
2179 };
2180
2181 /* *** WRITE PORT REGISTER BIT *** */
2182 struct cmd_write_reg_bit_result {
2183         cmdline_fixed_string_t write;
2184         cmdline_fixed_string_t regbit;
2185         uint8_t port_id;
2186         uint32_t reg_off;
2187         uint8_t bit_pos;
2188         uint8_t value;
2189 };
2190
2191 static void
2192 cmd_write_reg_bit_parsed(void *parsed_result,
2193                          __attribute__((unused)) struct cmdline *cl,
2194                          __attribute__((unused)) void *data)
2195 {
2196         struct cmd_write_reg_bit_result *res = parsed_result;
2197         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
2198 }
2199
2200 cmdline_parse_token_string_t cmd_write_reg_bit_write =
2201         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
2202                                  "write");
2203 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
2204         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
2205                                  regbit, "regbit");
2206 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
2207         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
2208 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
2209         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
2210 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
2211         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
2212 cmdline_parse_token_num_t cmd_write_reg_bit_value =
2213         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
2214
2215 cmdline_parse_inst_t cmd_write_reg_bit = {
2216         .f = cmd_write_reg_bit_parsed,
2217         .data = NULL,
2218         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
2219         .tokens = {
2220                 (void *)&cmd_write_reg_bit_write,
2221                 (void *)&cmd_write_reg_bit_regbit,
2222                 (void *)&cmd_write_reg_bit_port_id,
2223                 (void *)&cmd_write_reg_bit_reg_off,
2224                 (void *)&cmd_write_reg_bit_bit_pos,
2225                 (void *)&cmd_write_reg_bit_value,
2226                 NULL,
2227         },
2228 };
2229
2230 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
2231 struct cmd_read_rxd_txd_result {
2232         cmdline_fixed_string_t read;
2233         cmdline_fixed_string_t rxd_txd;
2234         uint8_t port_id;
2235         uint16_t queue_id;
2236         uint16_t desc_id;
2237 };
2238
2239 static void
2240 cmd_read_rxd_txd_parsed(void *parsed_result,
2241                         __attribute__((unused)) struct cmdline *cl,
2242                         __attribute__((unused)) void *data)
2243 {
2244         struct cmd_read_rxd_txd_result *res = parsed_result;
2245
2246         if (!strcmp(res->rxd_txd, "rxd"))
2247                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
2248         else if (!strcmp(res->rxd_txd, "txd"))
2249                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
2250 }
2251
2252 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
2253         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
2254 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
2255         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
2256                                  "rxd#txd");
2257 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
2258         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
2259 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
2260         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
2261 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
2262         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
2263
2264 cmdline_parse_inst_t cmd_read_rxd_txd = {
2265         .f = cmd_read_rxd_txd_parsed,
2266         .data = NULL,
2267         .help_str = "read rxd|txd port_id queue_id rxd_id",
2268         .tokens = {
2269                 (void *)&cmd_read_rxd_txd_read,
2270                 (void *)&cmd_read_rxd_txd_rxd_txd,
2271                 (void *)&cmd_read_rxd_txd_port_id,
2272                 (void *)&cmd_read_rxd_txd_queue_id,
2273                 (void *)&cmd_read_rxd_txd_desc_id,
2274                 NULL,
2275         },
2276 };
2277
2278 /* *** QUIT *** */
2279 struct cmd_quit_result {
2280         cmdline_fixed_string_t quit;
2281 };
2282
2283 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
2284                             struct cmdline *cl,
2285                             __attribute__((unused)) void *data)
2286 {
2287         pmd_test_exit();
2288         cmdline_quit(cl);
2289 }
2290
2291 cmdline_parse_token_string_t cmd_quit_quit =
2292         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
2293
2294 cmdline_parse_inst_t cmd_quit = {
2295         .f = cmd_quit_parsed,
2296         .data = NULL,
2297         .help_str = "exit application",
2298         .tokens = {
2299                 (void *)&cmd_quit_quit,
2300                 NULL,
2301         },
2302 };
2303
2304 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
2305 struct cmd_mac_addr_result {
2306         cmdline_fixed_string_t mac_addr_cmd;
2307         cmdline_fixed_string_t what;
2308         uint8_t port_num;
2309         struct ether_addr address;
2310 };
2311
2312 static void cmd_mac_addr_parsed(void *parsed_result,
2313                 __attribute__((unused)) struct cmdline *cl,
2314                 __attribute__((unused)) void *data)
2315 {
2316         struct cmd_mac_addr_result *res = parsed_result;
2317         int ret;
2318
2319         if (strcmp(res->what, "add") == 0)
2320                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
2321         else
2322                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
2323
2324         /* check the return value and print it if is < 0 */
2325         if(ret < 0)
2326                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
2327
2328 }
2329
2330 cmdline_parse_token_string_t cmd_mac_addr_cmd =
2331         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
2332                                 "mac_addr");
2333 cmdline_parse_token_string_t cmd_mac_addr_what =
2334         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
2335                                 "add#remove");
2336 cmdline_parse_token_num_t cmd_mac_addr_portnum =
2337                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
2338 cmdline_parse_token_string_t cmd_mac_addr_addr =
2339                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
2340
2341 cmdline_parse_inst_t cmd_mac_addr = {
2342         .f = cmd_mac_addr_parsed,
2343         .data = (void *)0,
2344         .help_str = "mac_addr add|remove X <address>: "
2345                         "add/remove MAC address on port X",
2346         .tokens = {
2347                 (void *)&cmd_mac_addr_cmd,
2348                 (void *)&cmd_mac_addr_what,
2349                 (void *)&cmd_mac_addr_portnum,
2350                 (void *)&cmd_mac_addr_addr,
2351                 NULL,
2352         },
2353 };
2354
2355
2356 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
2357 struct cmd_set_qmap_result {
2358         cmdline_fixed_string_t set;
2359         cmdline_fixed_string_t qmap;
2360         cmdline_fixed_string_t what;
2361         uint8_t port_id;
2362         uint16_t queue_id;
2363         uint8_t map_value;
2364 };
2365
2366 static void
2367 cmd_set_qmap_parsed(void *parsed_result,
2368                        __attribute__((unused)) struct cmdline *cl,
2369                        __attribute__((unused)) void *data)
2370 {
2371         struct cmd_set_qmap_result *res = parsed_result;
2372         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
2373
2374         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
2375 }
2376
2377 cmdline_parse_token_string_t cmd_setqmap_set =
2378         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
2379                                  set, "set");
2380 cmdline_parse_token_string_t cmd_setqmap_qmap =
2381         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
2382                                  qmap, "stat_qmap");
2383 cmdline_parse_token_string_t cmd_setqmap_what =
2384         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
2385                                  what, "tx#rx");
2386 cmdline_parse_token_num_t cmd_setqmap_portid =
2387         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
2388                               port_id, UINT8);
2389 cmdline_parse_token_num_t cmd_setqmap_queueid =
2390         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
2391                               queue_id, UINT16);
2392 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
2393         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
2394                               map_value, UINT8);
2395
2396 cmdline_parse_inst_t cmd_set_qmap = {
2397         .f = cmd_set_qmap_parsed,
2398         .data = NULL,
2399         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
2400         .tokens = {
2401                 (void *)&cmd_setqmap_set,
2402                 (void *)&cmd_setqmap_qmap,
2403                 (void *)&cmd_setqmap_what,
2404                 (void *)&cmd_setqmap_portid,
2405                 (void *)&cmd_setqmap_queueid,
2406                 (void *)&cmd_setqmap_mapvalue,
2407                 NULL,
2408         },
2409 };
2410
2411 /* ******************************************************************************** */
2412
2413 /* list of instructions */
2414 cmdline_parse_ctx_t main_ctx[] = {
2415         (cmdline_parse_inst_t *)&cmd_help,
2416         (cmdline_parse_inst_t *)&cmd_quit,
2417         (cmdline_parse_inst_t *)&cmd_showport,
2418         (cmdline_parse_inst_t *)&cmd_showportall,
2419         (cmdline_parse_inst_t *)&cmd_showcfg,
2420         (cmdline_parse_inst_t *)&cmd_start,
2421         (cmdline_parse_inst_t *)&cmd_start_tx_first,
2422         (cmdline_parse_inst_t *)&cmd_reset,
2423         (cmdline_parse_inst_t *)&cmd_set_numbers,
2424         (cmdline_parse_inst_t *)&cmd_set_txpkts,
2425         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
2426         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
2427         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
2428         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
2429         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
2430         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
2431         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
2432         (cmdline_parse_inst_t *)&cmd_vlan_offload,
2433         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
2434         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
2435         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
2436         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
2437         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
2438         (cmdline_parse_inst_t *)&cmd_tx_cksum_set,
2439         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
2440         (cmdline_parse_inst_t *)&cmd_read_reg,
2441         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
2442         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
2443         (cmdline_parse_inst_t *)&cmd_write_reg,
2444         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
2445         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
2446         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
2447         (cmdline_parse_inst_t *)&cmd_add_signature_filter,
2448         (cmdline_parse_inst_t *)&cmd_upd_signature_filter,
2449         (cmdline_parse_inst_t *)&cmd_rm_signature_filter,
2450         (cmdline_parse_inst_t *)&cmd_add_perfect_filter,
2451         (cmdline_parse_inst_t *)&cmd_upd_perfect_filter,
2452         (cmdline_parse_inst_t *)&cmd_rm_perfect_filter,
2453         (cmdline_parse_inst_t *)&cmd_set_masks_filter,
2454         (cmdline_parse_inst_t *)&cmd_set_ipv6_masks_filter,
2455         (cmdline_parse_inst_t *)&cmd_stop,
2456         (cmdline_parse_inst_t *)&cmd_mac_addr,
2457         (cmdline_parse_inst_t *)&cmd_set_qmap,
2458         NULL,
2459 };
2460
2461 /* prompt function, called from main on MASTER lcore */
2462 void
2463 prompt(void)
2464 {
2465         struct cmdline *cl;
2466
2467         cl = cmdline_stdin_new(main_ctx, "testpmd> ");
2468         if (cl == NULL) {
2469                 return;
2470         }
2471         cmdline_interact(cl);
2472         cmdline_stdin_exit(cl);
2473 }