app/testpmd: add port configuration settings
[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 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
85
86 /* *** HELP *** */
87 struct cmd_help_result {
88         cmdline_fixed_string_t help;
89 };
90
91 static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
92                             struct cmdline *cl,
93                             __attribute__((unused)) void *data)
94 {
95         cmdline_printf(cl,
96                        "\n"
97                        "TEST PMD\n"
98                        "--------\n"
99                        "\n"
100                        "This commandline can be used to configure forwarding\n"
101                        "\n");
102         cmdline_printf(cl,
103                        "Display informations:\n"
104                        "---------------------\n"
105                        "- show port info|stats|fdir|stat_qmap X|all\n"
106                        "    Diplays information or stats or stats queue mapping on port X, or all\n"
107                        "- clear port stats X|all\n"
108                        "    Clear stats for port X, or all\n"
109                        "- show config rxtx|cores|fwd\n"
110                        "    Displays the given configuration\n"
111                        "- read reg port_id reg_off\n"
112                        "    Displays value of a port register\n"
113                        "- read regfield port_id reg_off bit_x bit_y\n"
114                        "    Displays value of a port register bit field\n"
115                        "- read regbit port_id reg_off bit_x\n"
116                        "    Displays value of a port register bit\n"
117                        "- read rxd port_id queue_id rxd_id\n"
118                        "    Displays a RX descriptor of a port RX queue\n"
119                        "- read txd port_id queue_id txd_id\n"
120                        "    Displays a TX descriptor of a port TX queue\n"
121                        "\n");
122         cmdline_printf(cl,
123                        "Configure:\n"
124                        "----------\n"
125                        "Modifications are taken into account once "
126                        "forwarding is restarted.\n"
127                        "- set default\n"
128                        "    Set forwarding to default configuration\n"
129                        "- set nbport|nbcore|burst|verbose X\n"
130                        "    Set number of ports, number of cores, number "
131                        "of packets per burst,\n    or verbose level to X\n"
132                        "- set txpkts x[,y]*\n"
133                        "    Set the length of each segment of TXONLY packets\n"
134                        "- set coremask|portmask X\n"
135                        "    Set the hexadecimal mask of forwarding cores / "
136                        "forwarding ports\n"
137                        "- set corelist|portlist x[,y]*\n"
138                        "    Set the list of forwarding cores / forwarding "
139                        "ports\n"
140                        "- vlan set strip|filter|qinq on/off port_id\n"
141                        "    Set the VLAN strip, filter, QinQ(extended) on a port"
142                        "- rx_vlan add/rm vlan_id|all port_id\n"
143                        "    Set the VLAN filter table, add/remove vlan_id, or all "
144                        "identifiers, to/from the set of VLAN Identifiers\n"
145                        "filtered by port_id\n"
146                        "- rx_vlan set tpid value port_id\n"
147                        "    Set Outer VLAN TPID for Packet Filtering on a port \n"
148                        "- tx_vlan set vlan_id port_id\n"
149                        "    Set hardware insertion of VLAN ID in packets sent on a port\n"
150                        "- tx_vlan reset port_id\n"
151                        "    Disable hardware insertion of a VLAN header in "
152                        "packets sent on port_id\n"
153                        "- tx_checksum set mask port_id\n"
154                        "    Enable hardware insertion of checksum offload with "
155                        "the 4-bit mask (0~0xf)\n    in packets sent on port_id\n"
156                        "    Please check the NIC datasheet for HW limits\n"
157                        "      bit 0 - insert ip checksum offload if set \n"
158                        "      bit 1 - insert udp checksum offload if set \n"
159                        "      bit 2 - insert tcp checksum offload if set\n"
160                        "      bit 3 - insert sctp checksum offload if set\n"
161 #ifdef RTE_LIBRTE_IEEE1588
162                        "- set fwd io|mac|rxonly|txonly|csum|ieee1588\n"
163                        "    Set IO, MAC, RXONLY, TXONLY, CSUM or IEEE1588 "
164                        "packet forwarding mode\n"
165 #else
166                        "- set fwd io|mac|rxonly|txonly|csum\n"
167                        "    Set IO, MAC, RXONLY, CSUM or TXONLY packet "
168                        "forwarding mode\n"
169 #endif
170                        "- mac_addr add|remove X <xx:xx:xx:xx:xx:xx>\n"
171                        "    Add/Remove the MAC address <xx:xx:xx:xx:xx:xx> on port X\n"
172                        "- set promisc|allmulti [all|X] on|off\n"
173                        "    Set/unset promisc|allmulti mode on port X, or all\n"
174                        "- set flow_ctrl rx on|off tx on|off high_water low_water "
175                                                 "pause_time send_xon port_id \n"
176                        "    Set the link flow control parameter on the port \n"
177                        "- write reg port_id reg_off value\n"
178                        "    Set value of a port register\n"
179                        "- write regfield port_id reg_off bit_x bit_y value\n"
180                        "    Set bit field value of a port register\n"
181                        "- write regbit port_id reg_off bit_x value\n"
182                        "    Set bit value of a port register\n"
183                        "- set stat_qmap tx|rx port_id queue_id qmapping\n"
184                        "    Set statistics mapping (qmapping 0..15) for tx|rx queue_id on port_id\n"
185                        "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2 on port 0 to mapping 5\n"
186                        "\n");
187         cmdline_printf(cl,
188                        "Control forwarding:\n"
189                        "-------------------\n"
190                        "- start\n"
191                        "    Start packet forwarding with current config\n"
192                        "- start tx_first\n"
193                        "    Start packet forwarding with current config"
194                        " after sending one burst\n    of packets\n"
195                        "- stop\n"
196                        "    Stop packet forwarding, and displays accumulated"
197                        " stats\n"
198                        "\n");
199         cmdline_printf(cl,
200                        "Flow director mode:\n"
201                        "-------------------\n"
202                        "- add_signature_filter port_id ip|udp|tcp|sctp src\n"
203                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
204                        "    flexbytes flexbytes_values vlan vlan_id queue queue_id\n"
205                        "- upd_signature_filter port_id ip|udp|tcp|sctp src \n"
206                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
207                        "    flexbytes flexbytes_values vlan vlan_id queue queue_id\n"
208                        "- rm_signature_filter port_id ip|udp|tcp|sctp src\n"
209                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
210                        "    flexbytes flexbytes_values vlan vlan_id\n"
211                        "- add_perfect_filter port_id ip|udp|tcp|sctp src\n"
212                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
213                        "    flexbytes flexbytes_values vlan vlan_id queue \n"
214                        "    queue_id soft soft_id\n"
215                        "- upd_perfect_filter port_id ip|udp|tcp|sctp src\n"
216                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
217                        "    flexbytes flexbytes_values vlan vlan_id queue queue_id\n"
218                        "- rm_perfect_filter port_id ip|udp|tcp|sctp src\n"
219                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
220                        "    flexbytes flexbytes_values vlan vlan_id soft soft_id\n"
221                        "- set_masks_filter port_id only_ip_flow 0|1 src_mask\n"
222                        "    ip_src_mask port_src_mask dst_mask ip_dst_mask\n"
223                        "    port_dst_mask flexbytes 0|1 vlan_id 0|1 vlan_prio 0|1\n"
224                        "- set_ipv6_masks_filter port_id only_ip_flow 0|1 src_mask\n"
225                        "    ip_src_mask port_src_mask dst_mask ip_dst_mask\n"
226                        "    port_dst_mask flexbytes 0|1 vlan_id 0|1\n"
227                        "    vlan_prio 0|1 compare_dst 0|1\n"
228                        "\n");
229         cmdline_printf(cl,
230                        "Port Operations:\n"
231                        "--------------\n"
232                        "- port start|stop|close all|X\n"
233                        "    start/stop/close all ports or port X\n"
234                        "- port config all|X speed 10|100|1000|10000|auto "
235                        "duplex half|full|auto\n"
236                        "    set speed for all ports or port X\n"
237                        "- port config all rxq|txq|rxd|txd value\n"
238                        "    set number for rxq/txq/rxd/txd\n"
239                        "- port config all max-pkt-len value\n"
240                        "    set the max packet lenght\n"
241                        "- port config all crc-strip|rx-cksum|hw-vlan|drop-en on|off\n"
242                        "    set crc-strip/rx-checksum/hardware-vlan/drop_en on or off"
243                        "\n"
244                        "- port config all rss ip|udp|none\n"
245                        "    set rss mode\n"
246                        "- port config all burst value\n"
247                        "    set the number of packet per burst\n"
248                        "- port config all txpt|txht|txwt|rxpt|rxht|rxwt value\n"
249                        "    set ring prefetch/host/writeback threshold for "
250                        "tx/rx queue\n"
251                        "- port config all txfreet|txrst|rxfreet value\n"
252                        "    set free threshold for rx/tx, or set tx rs bit "
253                        "threshold\n"
254                        "\n");
255         cmdline_printf(cl,
256                        "Misc:\n"
257                        "-----\n"
258                        "- quit\n"
259                        "    Quit to prompt in linux, and reboot on baremetal\n"
260                        "\n");
261 }
262
263 cmdline_parse_token_string_t cmd_help_help =
264         TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");
265
266 cmdline_parse_inst_t cmd_help = {
267         .f = cmd_help_parsed,
268         .data = NULL,
269         .help_str = "show help",
270         .tokens = {
271                 (void *)&cmd_help_help,
272                 NULL,
273         },
274 };
275
276 /* *** start/stop/close all ports *** */
277 struct cmd_operate_port_result {
278         cmdline_fixed_string_t keyword;
279         cmdline_fixed_string_t name;
280         cmdline_fixed_string_t value;
281 };
282
283 static void cmd_operate_port_parsed(void *parsed_result,
284                                 __attribute__((unused)) struct cmdline *cl,
285                                 __attribute__((unused)) void *data)
286 {
287         struct cmd_operate_port_result *res = parsed_result;
288
289         if (!strcmp(res->name, "start"))
290                 start_port(RTE_PORT_ALL);
291         else if (!strcmp(res->name, "stop"))
292                 stop_port(RTE_PORT_ALL);
293         else if (!strcmp(res->name, "close"))
294                 close_port(RTE_PORT_ALL);
295         else
296                 printf("Unknown parameter\n");
297 }
298
299 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
300         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
301                                                                 "port");
302 cmdline_parse_token_string_t cmd_operate_port_all_port =
303         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
304                                                 "start#stop#close");
305 cmdline_parse_token_string_t cmd_operate_port_all_all =
306         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
307
308 cmdline_parse_inst_t cmd_operate_port = {
309         .f = cmd_operate_port_parsed,
310         .data = NULL,
311         .help_str = "port start|stop|close all: start/stop/close all ports",
312         .tokens = {
313                 (void *)&cmd_operate_port_all_cmd,
314                 (void *)&cmd_operate_port_all_port,
315                 (void *)&cmd_operate_port_all_all,
316                 NULL,
317         },
318 };
319
320 /* *** start/stop/close specific port *** */
321 struct cmd_operate_specific_port_result {
322         cmdline_fixed_string_t keyword;
323         cmdline_fixed_string_t name;
324         uint8_t value;
325 };
326
327 static void cmd_operate_specific_port_parsed(void *parsed_result,
328                         __attribute__((unused)) struct cmdline *cl,
329                                 __attribute__((unused)) void *data)
330 {
331         struct cmd_operate_specific_port_result *res = parsed_result;
332
333         if (!strcmp(res->name, "start"))
334                 start_port(res->value);
335         else if (!strcmp(res->name, "stop"))
336                 stop_port(res->value);
337         else if (!strcmp(res->name, "close"))
338                 close_port(res->value);
339         else
340                 printf("Unknown parameter\n");
341 }
342
343 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
344         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
345                                                         keyword, "port");
346 cmdline_parse_token_string_t cmd_operate_specific_port_port =
347         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
348                                                 name, "start#stop#close");
349 cmdline_parse_token_num_t cmd_operate_specific_port_id =
350         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
351                                                         value, UINT8);
352
353 cmdline_parse_inst_t cmd_operate_specific_port = {
354         .f = cmd_operate_specific_port_parsed,
355         .data = NULL,
356         .help_str = "port start|stop|close X: start/stop/close port X",
357         .tokens = {
358                 (void *)&cmd_operate_specific_port_cmd,
359                 (void *)&cmd_operate_specific_port_port,
360                 (void *)&cmd_operate_specific_port_id,
361                 NULL,
362         },
363 };
364
365 /* *** configure speed for all ports *** */
366 struct cmd_config_speed_all {
367         cmdline_fixed_string_t port;
368         cmdline_fixed_string_t keyword;
369         cmdline_fixed_string_t all;
370         cmdline_fixed_string_t item1;
371         cmdline_fixed_string_t item2;
372         cmdline_fixed_string_t value1;
373         cmdline_fixed_string_t value2;
374 };
375
376 static void
377 cmd_config_speed_all_parsed(void *parsed_result,
378                         __attribute__((unused)) struct cmdline *cl,
379                         __attribute__((unused)) void *data)
380 {
381         struct cmd_config_speed_all *res = parsed_result;
382         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
383         uint16_t link_duplex = 0;
384         portid_t pid;
385
386         if (!all_ports_stopped()) {
387                 printf("Please stop all ports first\n");
388                 return;
389         }
390
391         if (!strcmp(res->value1, "10"))
392                 link_speed = ETH_LINK_SPEED_10;
393         else if (!strcmp(res->value1, "100"))
394                 link_speed = ETH_LINK_SPEED_100;
395         else if (!strcmp(res->value1, "1000"))
396                 link_speed = ETH_LINK_SPEED_1000;
397         else if (!strcmp(res->value1, "10000"))
398                 link_speed = ETH_LINK_SPEED_10000;
399         else if (!strcmp(res->value1, "auto"))
400                 link_speed = ETH_LINK_SPEED_AUTONEG;
401         else {
402                 printf("Unknown parameter\n");
403                 return;
404         }
405
406         if (!strcmp(res->value2, "half"))
407                 link_duplex = ETH_LINK_HALF_DUPLEX;
408         else if (!strcmp(res->value2, "full"))
409                 link_duplex = ETH_LINK_FULL_DUPLEX;
410         else if (!strcmp(res->value2, "auto"))
411                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
412         else {
413                 printf("Unknown parameter\n");
414                 return;
415         }
416
417         for (pid = 0; pid < nb_ports; pid++) {
418                 ports[pid].dev_conf.link_speed = link_speed;
419                 ports[pid].dev_conf.link_duplex = link_duplex;
420         }
421
422         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
423 }
424
425 cmdline_parse_token_string_t cmd_config_speed_all_port =
426         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
427 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
428         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
429                                                         "config");
430 cmdline_parse_token_string_t cmd_config_speed_all_all =
431         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
432 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
433         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
434 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
435         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
436                                                 "10#100#1000#10000#auto");
437 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
438         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
439 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
440         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
441                                                 "half#full#auto");
442
443 cmdline_parse_inst_t cmd_config_speed_all = {
444         .f = cmd_config_speed_all_parsed,
445         .data = NULL,
446         .help_str = "port config all speed 10|100|1000|10000|auto duplex "
447                                                         "half|full|auto",
448         .tokens = {
449                 (void *)&cmd_config_speed_all_port,
450                 (void *)&cmd_config_speed_all_keyword,
451                 (void *)&cmd_config_speed_all_all,
452                 (void *)&cmd_config_speed_all_item1,
453                 (void *)&cmd_config_speed_all_value1,
454                 (void *)&cmd_config_speed_all_item2,
455                 (void *)&cmd_config_speed_all_value2,
456                 NULL,
457         },
458 };
459
460 /* *** configure speed for specific port *** */
461 struct cmd_config_speed_specific {
462         cmdline_fixed_string_t port;
463         cmdline_fixed_string_t keyword;
464         uint8_t id;
465         cmdline_fixed_string_t item1;
466         cmdline_fixed_string_t item2;
467         cmdline_fixed_string_t value1;
468         cmdline_fixed_string_t value2;
469 };
470
471 static void
472 cmd_config_speed_specific_parsed(void *parsed_result,
473                                 __attribute__((unused)) struct cmdline *cl,
474                                 __attribute__((unused)) void *data)
475 {
476         struct cmd_config_speed_specific *res = parsed_result;
477         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
478         uint16_t link_duplex = 0;
479
480         if (!all_ports_stopped()) {
481                 printf("Please stop all ports first\n");
482                 return;
483         }
484
485         if (res->id >= nb_ports) {
486                 printf("Port id %d must be less than %d\n", res->id, nb_ports);
487                 return;
488         }
489
490         if (!strcmp(res->value1, "10"))
491                 link_speed = ETH_LINK_SPEED_10;
492         else if (!strcmp(res->value1, "100"))
493                 link_speed = ETH_LINK_SPEED_100;
494         else if (!strcmp(res->value1, "1000"))
495                 link_speed = ETH_LINK_SPEED_1000;
496         else if (!strcmp(res->value1, "10000"))
497                 link_speed = ETH_LINK_SPEED_10000;
498         else if (!strcmp(res->value1, "auto"))
499                 link_speed = ETH_LINK_SPEED_AUTONEG;
500         else {
501                 printf("Unknown parameter\n");
502                 return;
503         }
504
505         if (!strcmp(res->value2, "half"))
506                 link_duplex = ETH_LINK_HALF_DUPLEX;
507         else if (!strcmp(res->value2, "full"))
508                 link_duplex = ETH_LINK_FULL_DUPLEX;
509         else if (!strcmp(res->value2, "auto"))
510                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
511         else {
512                 printf("Unknown parameter\n");
513                 return;
514         }
515
516         ports[res->id].dev_conf.link_speed = link_speed;
517         ports[res->id].dev_conf.link_duplex = link_duplex;
518
519         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
520 }
521
522
523 cmdline_parse_token_string_t cmd_config_speed_specific_port =
524         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
525                                                                 "port");
526 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
527         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
528                                                                 "config");
529 cmdline_parse_token_num_t cmd_config_speed_specific_id =
530         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
531 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
532         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
533                                                                 "speed");
534 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
535         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
536                                                 "10#100#1000#10000#auto");
537 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
538         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
539                                                                 "duplex");
540 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
541         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
542                                                         "half#full#auto");
543
544 cmdline_parse_inst_t cmd_config_speed_specific = {
545         .f = cmd_config_speed_specific_parsed,
546         .data = NULL,
547         .help_str = "port config X speed 10|100|1000|10000|auto duplex "
548                                                         "half|full|auto",
549         .tokens = {
550                 (void *)&cmd_config_speed_specific_port,
551                 (void *)&cmd_config_speed_specific_keyword,
552                 (void *)&cmd_config_speed_specific_id,
553                 (void *)&cmd_config_speed_specific_item1,
554                 (void *)&cmd_config_speed_specific_value1,
555                 (void *)&cmd_config_speed_specific_item2,
556                 (void *)&cmd_config_speed_specific_value2,
557                 NULL,
558         },
559 };
560
561 /* *** configure txq/rxq, txd/rxd *** */
562 struct cmd_config_rx_tx {
563         cmdline_fixed_string_t port;
564         cmdline_fixed_string_t keyword;
565         cmdline_fixed_string_t all;
566         cmdline_fixed_string_t name;
567         uint16_t value;
568 };
569
570 static void
571 cmd_config_rx_tx_parsed(void *parsed_result,
572                         __attribute__((unused)) struct cmdline *cl,
573                         __attribute__((unused)) void *data)
574 {
575         struct cmd_config_rx_tx *res = parsed_result;
576
577         if (!all_ports_stopped()) {
578                 printf("Please stop all ports first\n");
579                 return;
580         }
581
582         if (!strcmp(res->name, "rxq")) {
583                 if (res->value <= 0) {
584                         printf("rxq %d invalid - must be > 0\n", res->value);
585                         return;
586                 }
587                 nb_rxq = res->value;
588         }
589         else if (!strcmp(res->name, "txq")) {
590                 if (res->value <= 0) {
591                         printf("txq %d invalid - must be > 0\n", res->value);
592                         return;
593                 }
594                 nb_txq = res->value;
595         }
596         else if (!strcmp(res->name, "rxd")) {
597                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
598                         printf("rxd %d invalid - must be > 0 && <= %d\n",
599                                         res->value, RTE_TEST_RX_DESC_MAX);
600                         return;
601                 }
602                 nb_rxd = res->value;
603         } else if (!strcmp(res->name, "txd")) {
604                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
605                         printf("txd %d invalid - must be > 0 && <= %d\n",
606                                         res->value, RTE_TEST_TX_DESC_MAX);
607                         return;
608                 }
609                 nb_txd = res->value;
610         } else {
611                 printf("Unknown parameter\n");
612                 return;
613         }
614
615         init_port_config();
616
617         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
618 }
619
620 cmdline_parse_token_string_t cmd_config_rx_tx_port =
621         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
622 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
623         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
624 cmdline_parse_token_string_t cmd_config_rx_tx_all =
625         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
626 cmdline_parse_token_string_t cmd_config_rx_tx_name =
627         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
628                                                 "rxq#txq#rxd#txd");
629 cmdline_parse_token_num_t cmd_config_rx_tx_value =
630         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
631
632 cmdline_parse_inst_t cmd_config_rx_tx = {
633         .f = cmd_config_rx_tx_parsed,
634         .data = NULL,
635         .help_str = "port config all rxq|txq|rxd|txd value",
636         .tokens = {
637                 (void *)&cmd_config_rx_tx_port,
638                 (void *)&cmd_config_rx_tx_keyword,
639                 (void *)&cmd_config_rx_tx_all,
640                 (void *)&cmd_config_rx_tx_name,
641                 (void *)&cmd_config_rx_tx_value,
642                 NULL,
643         },
644 };
645
646 /* *** config max packet length *** */
647 struct cmd_config_max_pkt_len_result {
648         cmdline_fixed_string_t port;
649         cmdline_fixed_string_t keyword;
650         cmdline_fixed_string_t all;
651         cmdline_fixed_string_t name;
652         uint32_t value;
653 };
654
655 static void
656 cmd_config_max_pkt_len_parsed(void *parsed_result,
657                                 __attribute__((unused)) struct cmdline *cl,
658                                 __attribute__((unused)) void *data)
659 {
660         struct cmd_config_max_pkt_len_result *res = parsed_result;
661
662         if (!all_ports_stopped()) {
663                 printf("Please stop all ports first\n");
664                 return;
665         }
666
667         if (!strcmp(res->name, "max-pkt-len")) {
668                 if (res->value < ETHER_MIN_LEN) {
669                         printf("max-pkt-len can not be less than %d\n",
670                                                         ETHER_MIN_LEN);
671                         return;
672                 }
673                 if (res->value == rx_mode.max_rx_pkt_len)
674                         return;
675
676                 rx_mode.max_rx_pkt_len = res->value;
677                 if (res->value > ETHER_MAX_LEN)
678                         rx_mode.jumbo_frame = 1;
679                 else
680                         rx_mode.jumbo_frame = 0;
681         } else {
682                 printf("Unknown parameter\n");
683                 return;
684         }
685
686         init_port_config();
687
688         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
689 }
690
691 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
692         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
693                                                                 "port");
694 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
695         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
696                                                                 "config");
697 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
698         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
699                                                                 "all");
700 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
701         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
702                                                                 "max-pkt-len");
703 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
704         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
705                                                                 UINT32);
706
707 cmdline_parse_inst_t cmd_config_max_pkt_len = {
708         .f = cmd_config_max_pkt_len_parsed,
709         .data = NULL,
710         .help_str = "port config all max-pkt-len value",
711         .tokens = {
712                 (void *)&cmd_config_max_pkt_len_port,
713                 (void *)&cmd_config_max_pkt_len_keyword,
714                 (void *)&cmd_config_max_pkt_len_all,
715                 (void *)&cmd_config_max_pkt_len_name,
716                 (void *)&cmd_config_max_pkt_len_value,
717                 NULL,
718         },
719 };
720
721 /* *** configure rx mode *** */
722 struct cmd_config_rx_mode_flag {
723         cmdline_fixed_string_t port;
724         cmdline_fixed_string_t keyword;
725         cmdline_fixed_string_t all;
726         cmdline_fixed_string_t name;
727         cmdline_fixed_string_t value;
728 };
729
730 static void
731 cmd_config_rx_mode_flag_parsed(void *parsed_result,
732                                 __attribute__((unused)) struct cmdline *cl,
733                                 __attribute__((unused)) void *data)
734 {
735         struct cmd_config_rx_mode_flag *res = parsed_result;
736
737         if (!all_ports_stopped()) {
738                 printf("Please stop all ports first\n");
739                 return;
740         }
741
742         if (!strcmp(res->name, "crc-strip")) {
743                 if (!strcmp(res->value, "on"))
744                         rx_mode.hw_strip_crc = 1;
745                 else if (!strcmp(res->value, "off"))
746                         rx_mode.hw_strip_crc = 0;
747                 else {
748                         printf("Unknown parameter\n");
749                         return;
750                 }
751         } else if (!strcmp(res->name, "rx-cksum")) {
752                 if (!strcmp(res->value, "on"))
753                         rx_mode.hw_ip_checksum = 1;
754                 else if (!strcmp(res->value, "off"))
755                         rx_mode.hw_ip_checksum = 0;
756                 else {
757                         printf("Unknown parameter\n");
758                         return;
759                 }
760         } else if (!strcmp(res->name, "hw-vlan")) {
761                 if (!strcmp(res->value, "on")) {
762                         rx_mode.hw_vlan_filter = 1;
763                         rx_mode.hw_vlan_strip  = 1;
764                 }
765                 else if (!strcmp(res->value, "off")) {
766                         rx_mode.hw_vlan_filter = 0;
767                         rx_mode.hw_vlan_strip  = 0;
768                 }
769                 else {
770                         printf("Unknown parameter\n");
771                         return;
772                 }
773         } else if (!strcmp(res->name, "drop-en")) {
774                 if (!strcmp(res->value, "on"))
775                         rx_drop_en = 1;
776                 else if (!strcmp(res->value, "off"))
777                         rx_drop_en = 0;
778                 else {
779                         printf("Unknown parameter\n");
780                         return;
781                 }
782         } else {
783                 printf("Unknown parameter\n");
784                 return;
785         }
786
787         init_port_config();
788
789         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
790 }
791
792 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
793         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
794 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
795         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
796                                                                 "config");
797 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
798         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
799 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
800         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
801                                         "crc-strip#rx-cksum#hw-vlan");
802 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
803         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
804                                                         "on#off");
805
806 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
807         .f = cmd_config_rx_mode_flag_parsed,
808         .data = NULL,
809         .help_str = "port config all crc-strip|rx-cksum|hw-vlan on|off",
810         .tokens = {
811                 (void *)&cmd_config_rx_mode_flag_port,
812                 (void *)&cmd_config_rx_mode_flag_keyword,
813                 (void *)&cmd_config_rx_mode_flag_all,
814                 (void *)&cmd_config_rx_mode_flag_name,
815                 (void *)&cmd_config_rx_mode_flag_value,
816                 NULL,
817         },
818 };
819
820 /* *** configure rss *** */
821 struct cmd_config_rss {
822         cmdline_fixed_string_t port;
823         cmdline_fixed_string_t keyword;
824         cmdline_fixed_string_t all;
825         cmdline_fixed_string_t name;
826         cmdline_fixed_string_t value;
827 };
828
829 static void
830 cmd_config_rss_parsed(void *parsed_result,
831                         __attribute__((unused)) struct cmdline *cl,
832                         __attribute__((unused)) void *data)
833 {
834         struct cmd_config_rss *res = parsed_result;
835
836         if (!all_ports_stopped()) {
837                 printf("Please stop all ports first\n");
838                 return;
839         }
840
841         if (!strcmp(res->value, "ip"))
842                 rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6;
843         else if (!strcmp(res->value, "udp"))
844                 rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6 | ETH_RSS_IPV4_UDP;
845         else if (!strcmp(res->value, "none"))
846                 rss_hf = 0;
847         else {
848                 printf("Unknown parameter\n");
849                 return;
850         }
851
852         init_port_config();
853
854         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
855 }
856
857 cmdline_parse_token_string_t cmd_config_rss_port =
858         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
859 cmdline_parse_token_string_t cmd_config_rss_keyword =
860         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
861 cmdline_parse_token_string_t cmd_config_rss_all =
862         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
863 cmdline_parse_token_string_t cmd_config_rss_name =
864         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
865 cmdline_parse_token_string_t cmd_config_rss_value =
866         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, "ip#udp#none");
867
868 cmdline_parse_inst_t cmd_config_rss = {
869         .f = cmd_config_rss_parsed,
870         .data = NULL,
871         .help_str = "port config all rss ip|udp|none",
872         .tokens = {
873                 (void *)&cmd_config_rss_port,
874                 (void *)&cmd_config_rss_keyword,
875                 (void *)&cmd_config_rss_all,
876                 (void *)&cmd_config_rss_name,
877                 (void *)&cmd_config_rss_value,
878                 NULL,
879         },
880 };
881
882 /* *** configure number of packets per burst *** */
883 struct cmd_config_burst {
884         cmdline_fixed_string_t port;
885         cmdline_fixed_string_t keyword;
886         cmdline_fixed_string_t all;
887         cmdline_fixed_string_t name;
888         uint16_t value;
889 };
890
891 static void
892 cmd_config_burst_parsed(void *parsed_result,
893                         __attribute__((unused)) struct cmdline *cl,
894                         __attribute__((unused)) void *data)
895 {
896         struct cmd_config_burst *res = parsed_result;
897
898         if (!all_ports_stopped()) {
899                 printf("Please stop all ports first\n");
900                 return;
901         }
902
903         if (!strcmp(res->name, "burst")) {
904                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
905                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
906                         return;
907                 }
908                 nb_pkt_per_burst = res->value;
909         } else {
910                 printf("Unknown parameter\n");
911                 return;
912         }
913
914         init_port_config();
915
916         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
917 }
918
919 cmdline_parse_token_string_t cmd_config_burst_port =
920         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
921 cmdline_parse_token_string_t cmd_config_burst_keyword =
922         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
923 cmdline_parse_token_string_t cmd_config_burst_all =
924         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
925 cmdline_parse_token_string_t cmd_config_burst_name =
926         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
927 cmdline_parse_token_num_t cmd_config_burst_value =
928         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
929
930 cmdline_parse_inst_t cmd_config_burst = {
931         .f = cmd_config_burst_parsed,
932         .data = NULL,
933         .help_str = "port config all burst value",
934         .tokens = {
935                 (void *)&cmd_config_burst_port,
936                 (void *)&cmd_config_burst_keyword,
937                 (void *)&cmd_config_burst_all,
938                 (void *)&cmd_config_burst_name,
939                 (void *)&cmd_config_burst_value,
940                 NULL,
941         },
942 };
943
944 /* *** configure rx/tx queues *** */
945 struct cmd_config_thresh {
946         cmdline_fixed_string_t port;
947         cmdline_fixed_string_t keyword;
948         cmdline_fixed_string_t all;
949         cmdline_fixed_string_t name;
950         uint8_t value;
951 };
952
953 static void
954 cmd_config_thresh_parsed(void *parsed_result,
955                         __attribute__((unused)) struct cmdline *cl,
956                         __attribute__((unused)) void *data)
957 {
958         struct cmd_config_thresh *res = parsed_result;
959
960         if (!all_ports_stopped()) {
961                 printf("Please stop all ports first\n");
962                 return;
963         }
964
965         if (!strcmp(res->name, "txpt"))
966                 tx_thresh.pthresh = res->value;
967         else if(!strcmp(res->name, "txht"))
968                 tx_thresh.hthresh = res->value;
969         else if(!strcmp(res->name, "txwt"))
970                 tx_thresh.wthresh = res->value;
971         else if(!strcmp(res->name, "rxpt"))
972                 rx_thresh.pthresh = res->value;
973         else if(!strcmp(res->name, "rxht"))
974                 rx_thresh.hthresh = res->value;
975         else if(!strcmp(res->name, "rxwt"))
976                 rx_thresh.wthresh = res->value;
977         else {
978                 printf("Unknown parameter\n");
979                 return;
980         }
981
982         init_port_config();
983
984         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
985 }
986
987 cmdline_parse_token_string_t cmd_config_thresh_port =
988         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
989 cmdline_parse_token_string_t cmd_config_thresh_keyword =
990         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
991 cmdline_parse_token_string_t cmd_config_thresh_all =
992         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
993 cmdline_parse_token_string_t cmd_config_thresh_name =
994         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
995                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
996 cmdline_parse_token_num_t cmd_config_thresh_value =
997         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
998
999 cmdline_parse_inst_t cmd_config_thresh = {
1000         .f = cmd_config_thresh_parsed,
1001         .data = NULL,
1002         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt value",
1003         .tokens = {
1004                 (void *)&cmd_config_thresh_port,
1005                 (void *)&cmd_config_thresh_keyword,
1006                 (void *)&cmd_config_thresh_all,
1007                 (void *)&cmd_config_thresh_name,
1008                 (void *)&cmd_config_thresh_value,
1009                 NULL,
1010         },
1011 };
1012
1013 /* *** configure free/rs threshold *** */
1014 struct cmd_config_threshold {
1015         cmdline_fixed_string_t port;
1016         cmdline_fixed_string_t keyword;
1017         cmdline_fixed_string_t all;
1018         cmdline_fixed_string_t name;
1019         uint16_t value;
1020 };
1021
1022 static void
1023 cmd_config_threshold_parsed(void *parsed_result,
1024                         __attribute__((unused)) struct cmdline *cl,
1025                         __attribute__((unused)) void *data)
1026 {
1027         struct cmd_config_threshold *res = parsed_result;
1028
1029         if (!all_ports_stopped()) {
1030                 printf("Please stop all ports first\n");
1031                 return;
1032         }
1033
1034         if (!strcmp(res->name, "txfreet"))
1035                 tx_free_thresh = res->value;
1036         else if (!strcmp(res->name, "txrst"))
1037                 tx_rs_thresh = res->value;
1038         else if (!strcmp(res->name, "rxfreet"))
1039                 rx_free_thresh = res->value;
1040         else {
1041                 printf("Unknown parameter\n");
1042                 return;
1043         }
1044
1045         init_port_config();
1046
1047         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1048 }
1049
1050 cmdline_parse_token_string_t cmd_config_threshold_port =
1051         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
1052 cmdline_parse_token_string_t cmd_config_threshold_keyword =
1053         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
1054                                                                 "config");
1055 cmdline_parse_token_string_t cmd_config_threshold_all =
1056         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
1057 cmdline_parse_token_string_t cmd_config_threshold_name =
1058         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
1059                                                 "txfreet#txrst#rxfreet");
1060 cmdline_parse_token_num_t cmd_config_threshold_value =
1061         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
1062
1063 cmdline_parse_inst_t cmd_config_threshold = {
1064         .f = cmd_config_threshold_parsed,
1065         .data = NULL,
1066         .help_str = "port config all txfreet|txrst|rxfreet value",
1067         .tokens = {
1068                 (void *)&cmd_config_threshold_port,
1069                 (void *)&cmd_config_threshold_keyword,
1070                 (void *)&cmd_config_threshold_all,
1071                 (void *)&cmd_config_threshold_name,
1072                 (void *)&cmd_config_threshold_value,
1073                 NULL,
1074         },
1075 };
1076
1077 /* *** stop *** */
1078 struct cmd_stop_result {
1079         cmdline_fixed_string_t stop;
1080 };
1081
1082 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
1083                             __attribute__((unused)) struct cmdline *cl,
1084                             __attribute__((unused)) void *data)
1085 {
1086         stop_packet_forwarding();
1087 }
1088
1089 cmdline_parse_token_string_t cmd_stop_stop =
1090         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
1091
1092 cmdline_parse_inst_t cmd_stop = {
1093         .f = cmd_stop_parsed,
1094         .data = NULL,
1095         .help_str = "stop - stop packet forwarding",
1096         .tokens = {
1097                 (void *)&cmd_stop_stop,
1098                 NULL,
1099         },
1100 };
1101
1102 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
1103
1104 static unsigned int
1105 parse_item_list(char* str, const char* item_name, unsigned int max_items,
1106                 unsigned int *parsed_items, int check_unique_values)
1107 {
1108         unsigned int nb_item;
1109         unsigned int value;
1110         unsigned int i;
1111         unsigned int j;
1112         int value_ok;
1113         char c;
1114
1115         /*
1116          * First parse all items in the list and store their value.
1117          */
1118         value = 0;
1119         nb_item = 0;
1120         value_ok = 0;
1121         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
1122                 c = str[i];
1123                 if ((c >= '0') && (c <= '9')) {
1124                         value = (unsigned int) (value * 10 + (c - '0'));
1125                         value_ok = 1;
1126                         continue;
1127                 }
1128                 if (c != ',') {
1129                         printf("character %c is not a decimal digit\n", c);
1130                         return (0);
1131                 }
1132                 if (! value_ok) {
1133                         printf("No valid value before comma\n");
1134                         return (0);
1135                 }
1136                 if (nb_item < max_items) {
1137                         parsed_items[nb_item] = value;
1138                         value_ok = 0;
1139                         value = 0;
1140                 }
1141                 nb_item++;
1142         }
1143         if (nb_item >= max_items) {
1144                 printf("Number of %s = %u > %u (maximum items)\n",
1145                        item_name, nb_item + 1, max_items);
1146                 return (0);
1147         }
1148         parsed_items[nb_item++] = value;
1149         if (! check_unique_values)
1150                 return (nb_item);
1151
1152         /*
1153          * Then, check that all values in the list are differents.
1154          * No optimization here...
1155          */
1156         for (i = 0; i < nb_item; i++) {
1157                 for (j = i + 1; j < nb_item; j++) {
1158                         if (parsed_items[j] == parsed_items[i]) {
1159                                 printf("duplicated %s %u at index %u and %u\n",
1160                                        item_name, parsed_items[i], i, j);
1161                                 return (0);
1162                         }
1163                 }
1164         }
1165         return (nb_item);
1166 }
1167
1168 struct cmd_set_list_result {
1169         cmdline_fixed_string_t cmd_keyword;
1170         cmdline_fixed_string_t list_name;
1171         cmdline_fixed_string_t list_of_items;
1172 };
1173
1174 static void cmd_set_list_parsed(void *parsed_result,
1175                                 __attribute__((unused)) struct cmdline *cl,
1176                                 __attribute__((unused)) void *data)
1177 {
1178         struct cmd_set_list_result *res;
1179         union {
1180                 unsigned int lcorelist[RTE_MAX_LCORE];
1181                 unsigned int portlist[RTE_MAX_ETHPORTS];
1182         } parsed_items;
1183         unsigned int nb_item;
1184
1185         res = parsed_result;
1186         if (!strcmp(res->list_name, "corelist")) {
1187                 nb_item = parse_item_list(res->list_of_items, "core",
1188                                           RTE_MAX_LCORE,
1189                                           parsed_items.lcorelist, 1);
1190                 if (nb_item > 0)
1191                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
1192                 return;
1193         }
1194         if (!strcmp(res->list_name, "portlist")) {
1195                 nb_item = parse_item_list(res->list_of_items, "port",
1196                                           RTE_MAX_ETHPORTS,
1197                                           parsed_items.portlist, 1);
1198                 if (nb_item > 0)
1199                         set_fwd_ports_list(parsed_items.portlist, nb_item);
1200         }
1201 }
1202
1203 cmdline_parse_token_string_t cmd_set_list_keyword =
1204         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
1205                                  "set");
1206 cmdline_parse_token_string_t cmd_set_list_name =
1207         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
1208                                  "corelist#portlist");
1209 cmdline_parse_token_string_t cmd_set_list_of_items =
1210         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
1211                                  NULL);
1212
1213 cmdline_parse_inst_t cmd_set_fwd_list = {
1214         .f = cmd_set_list_parsed,
1215         .data = NULL,
1216         .help_str = "set corelist|portlist x[,y]*",
1217         .tokens = {
1218                 (void *)&cmd_set_list_keyword,
1219                 (void *)&cmd_set_list_name,
1220                 (void *)&cmd_set_list_of_items,
1221                 NULL,
1222         },
1223 };
1224
1225 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
1226
1227 struct cmd_setmask_result {
1228         cmdline_fixed_string_t set;
1229         cmdline_fixed_string_t mask;
1230         uint64_t hexavalue;
1231 };
1232
1233 static void cmd_set_mask_parsed(void *parsed_result,
1234                                 __attribute__((unused)) struct cmdline *cl,
1235                                 __attribute__((unused)) void *data)
1236 {
1237         struct cmd_setmask_result *res = parsed_result;
1238
1239         if (!strcmp(res->mask, "coremask"))
1240                 set_fwd_lcores_mask(res->hexavalue);
1241         else if (!strcmp(res->mask, "portmask"))
1242                 set_fwd_ports_mask(res->hexavalue);
1243 }
1244
1245 cmdline_parse_token_string_t cmd_setmask_set =
1246         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
1247 cmdline_parse_token_string_t cmd_setmask_mask =
1248         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
1249                                  "coremask#portmask");
1250 cmdline_parse_token_num_t cmd_setmask_value =
1251         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
1252
1253 cmdline_parse_inst_t cmd_set_fwd_mask = {
1254         .f = cmd_set_mask_parsed,
1255         .data = NULL,
1256         .help_str = "set coremask|portmask hexadecimal value",
1257         .tokens = {
1258                 (void *)&cmd_setmask_set,
1259                 (void *)&cmd_setmask_mask,
1260                 (void *)&cmd_setmask_value,
1261                 NULL,
1262         },
1263 };
1264
1265 /*
1266  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
1267  */
1268 struct cmd_set_result {
1269         cmdline_fixed_string_t set;
1270         cmdline_fixed_string_t what;
1271         uint16_t value;
1272 };
1273
1274 static void cmd_set_parsed(void *parsed_result,
1275                            __attribute__((unused)) struct cmdline *cl,
1276                            __attribute__((unused)) void *data)
1277 {
1278         struct cmd_set_result *res = parsed_result;
1279         if (!strcmp(res->what, "nbport"))
1280                 set_fwd_ports_number(res->value);
1281         else if (!strcmp(res->what, "nbcore"))
1282                 set_fwd_lcores_number(res->value);
1283         else if (!strcmp(res->what, "burst"))
1284                 set_nb_pkt_per_burst(res->value);
1285         else if (!strcmp(res->what, "verbose"))
1286                 set_verbose_level(res->value);
1287 }
1288
1289 cmdline_parse_token_string_t cmd_set_set =
1290         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
1291 cmdline_parse_token_string_t cmd_set_what =
1292         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
1293                                  "nbport#nbcore#burst#verbose");
1294 cmdline_parse_token_num_t cmd_set_value =
1295         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
1296
1297 cmdline_parse_inst_t cmd_set_numbers = {
1298         .f = cmd_set_parsed,
1299         .data = NULL,
1300         .help_str = "set nbport|nbcore|burst|verbose value",
1301         .tokens = {
1302                 (void *)&cmd_set_set,
1303                 (void *)&cmd_set_what,
1304                 (void *)&cmd_set_value,
1305                 NULL,
1306         },
1307 };
1308
1309 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
1310
1311 struct cmd_set_txpkts_result {
1312         cmdline_fixed_string_t cmd_keyword;
1313         cmdline_fixed_string_t txpkts;
1314         cmdline_fixed_string_t seg_lengths;
1315 };
1316
1317 static void
1318 cmd_set_txpkts_parsed(void *parsed_result,
1319                       __attribute__((unused)) struct cmdline *cl,
1320                       __attribute__((unused)) void *data)
1321 {
1322         struct cmd_set_txpkts_result *res;
1323         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
1324         unsigned int nb_segs;
1325
1326         res = parsed_result;
1327         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
1328                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
1329         if (nb_segs > 0)
1330                 set_tx_pkt_segments(seg_lengths, nb_segs);
1331 }
1332
1333 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
1334         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
1335                                  cmd_keyword, "set");
1336 cmdline_parse_token_string_t cmd_set_txpkts_name =
1337         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
1338                                  txpkts, "txpkts");
1339 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
1340         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
1341                                  seg_lengths, NULL);
1342
1343 cmdline_parse_inst_t cmd_set_txpkts = {
1344         .f = cmd_set_txpkts_parsed,
1345         .data = NULL,
1346         .help_str = "set txpkts x[,y]*",
1347         .tokens = {
1348                 (void *)&cmd_set_txpkts_keyword,
1349                 (void *)&cmd_set_txpkts_name,
1350                 (void *)&cmd_set_txpkts_lengths,
1351                 NULL,
1352         },
1353 };
1354
1355 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
1356 struct cmd_rx_vlan_filter_all_result {
1357         cmdline_fixed_string_t rx_vlan;
1358         cmdline_fixed_string_t what;
1359         cmdline_fixed_string_t all;
1360         uint8_t port_id;
1361 };
1362
1363 static void
1364 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
1365                               __attribute__((unused)) struct cmdline *cl,
1366                               __attribute__((unused)) void *data)
1367 {
1368         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
1369
1370         if (!strcmp(res->what, "add"))
1371                 rx_vlan_all_filter_set(res->port_id, 1);
1372         else
1373                 rx_vlan_all_filter_set(res->port_id, 0);
1374 }
1375
1376 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
1377         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
1378                                  rx_vlan, "rx_vlan");
1379 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
1380         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
1381                                  what, "add#rm");
1382 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
1383         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
1384                                  all, "all");
1385 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
1386         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
1387                               port_id, UINT8);
1388
1389 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
1390         .f = cmd_rx_vlan_filter_all_parsed,
1391         .data = NULL,
1392         .help_str = "add/remove all identifiers to/from the set of VLAN "
1393         "Identifiers filtered by a port",
1394         .tokens = {
1395                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
1396                 (void *)&cmd_rx_vlan_filter_all_what,
1397                 (void *)&cmd_rx_vlan_filter_all_all,
1398                 (void *)&cmd_rx_vlan_filter_all_portid,
1399                 NULL,
1400         },
1401 };
1402
1403 /* *** VLAN OFFLOAD SET ON A PORT *** */
1404 struct cmd_vlan_offload_result {
1405         cmdline_fixed_string_t vlan;
1406         cmdline_fixed_string_t set;
1407         cmdline_fixed_string_t what;
1408         cmdline_fixed_string_t on;
1409         cmdline_fixed_string_t port_id;
1410 };
1411
1412 static void
1413 cmd_vlan_offload_parsed(void *parsed_result,
1414                           __attribute__((unused)) struct cmdline *cl,
1415                           __attribute__((unused)) void *data)
1416 {
1417         int on;
1418         struct cmd_vlan_offload_result *res = parsed_result;    
1419         char *str;
1420         int i, len = 0;
1421         portid_t port_id = 0;
1422         unsigned int tmp;
1423         
1424         str = res->port_id;
1425         len = strnlen(str, STR_TOKEN_SIZE);
1426         i = 0;
1427         /* Get port_id first */
1428         while(i < len){
1429                 if(str[i] == ',')
1430                         break;
1431                 
1432                 i++;
1433         }
1434         str[i]='\0';
1435         tmp = strtoul(str, NULL, 0);
1436         /* If port_id greater that what portid_t can represent, return */
1437         if(tmp > 255)
1438                 return;
1439         port_id = (portid_t)tmp;
1440
1441         if (!strcmp(res->on, "on"))
1442                 on = 1;
1443         else
1444                 on = 0;
1445
1446         if (!strcmp(res->what, "strip"))
1447                 rx_vlan_strip_set(port_id,  on);
1448         else if(!strcmp(res->what, "stripq")){
1449                 uint16_t queue_id = 0;
1450
1451                 /* No queue_id, return */
1452                 if(i + 1 >= len)
1453                         return;
1454                 tmp = strtoul(str + i + 1, NULL, 0);
1455                 /* If queue_id greater that what 16-bits can represent, return */
1456                 if(tmp > 0xffff)
1457                         return;
1458                 
1459                 queue_id = (uint16_t)tmp;
1460                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
1461         }
1462         else if (!strcmp(res->what, "filter"))
1463                 rx_vlan_filter_set(port_id, on);
1464         else
1465                 vlan_extend_set(port_id, on);
1466
1467         return;
1468 }
1469
1470 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
1471         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
1472                                  vlan, "vlan");
1473 cmdline_parse_token_string_t cmd_vlan_offload_set =
1474         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
1475                                  set, "set");
1476 cmdline_parse_token_string_t cmd_vlan_offload_what =
1477         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
1478                                  what, "strip#filter#qinq#stripq");
1479 cmdline_parse_token_string_t cmd_vlan_offload_on =
1480         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
1481                               on, "on#off");
1482 cmdline_parse_token_string_t cmd_vlan_offload_portid =
1483         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
1484                               port_id, NULL);
1485
1486 cmdline_parse_inst_t cmd_vlan_offload = {
1487         .f = cmd_vlan_offload_parsed,
1488         .data = NULL,
1489         .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side"
1490         " qinq(extended) for both rx/tx sides ",
1491         .tokens = {
1492                 (void *)&cmd_vlan_offload_vlan,
1493                 (void *)&cmd_vlan_offload_set,
1494                 (void *)&cmd_vlan_offload_what,
1495                 (void *)&cmd_vlan_offload_on,
1496                 (void *)&cmd_vlan_offload_portid,
1497                 NULL,
1498         },
1499 };
1500
1501 /* *** VLAN TPID SET ON A PORT *** */
1502 struct cmd_vlan_tpid_result {
1503         cmdline_fixed_string_t vlan;
1504         cmdline_fixed_string_t set;
1505         cmdline_fixed_string_t what;
1506         uint16_t tp_id;
1507         uint8_t port_id;
1508 };
1509
1510 static void
1511 cmd_vlan_tpid_parsed(void *parsed_result,
1512                           __attribute__((unused)) struct cmdline *cl,
1513                           __attribute__((unused)) void *data)
1514 {
1515         struct cmd_vlan_tpid_result *res = parsed_result;
1516         vlan_tpid_set(res->port_id, res->tp_id);
1517         return;
1518 }
1519
1520 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
1521         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
1522                                  vlan, "vlan");
1523 cmdline_parse_token_string_t cmd_vlan_tpid_set =
1524         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
1525                                  set, "set");
1526 cmdline_parse_token_string_t cmd_vlan_tpid_what =
1527         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
1528                                  what, "tpid");
1529 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
1530         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
1531                               tp_id, UINT16);
1532 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
1533         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
1534                               port_id, UINT8);
1535
1536 cmdline_parse_inst_t cmd_vlan_tpid = {
1537         .f = cmd_vlan_tpid_parsed,
1538         .data = NULL,
1539         .help_str = "set tpid tp_id port_id, set the Outer VLAN Ether type",
1540         .tokens = {
1541                 (void *)&cmd_vlan_tpid_vlan,
1542                 (void *)&cmd_vlan_tpid_set,
1543                 (void *)&cmd_vlan_tpid_what,
1544                 (void *)&cmd_vlan_tpid_tpid,
1545                 (void *)&cmd_vlan_tpid_portid,
1546                 NULL,
1547         },
1548 };
1549
1550 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
1551 struct cmd_rx_vlan_filter_result {
1552         cmdline_fixed_string_t rx_vlan;
1553         cmdline_fixed_string_t what;
1554         uint16_t vlan_id;
1555         uint8_t port_id;
1556 };
1557
1558 static void
1559 cmd_rx_vlan_filter_parsed(void *parsed_result,
1560                           __attribute__((unused)) struct cmdline *cl,
1561                           __attribute__((unused)) void *data)
1562 {
1563         struct cmd_rx_vlan_filter_result *res = parsed_result;
1564
1565         if (!strcmp(res->what, "add"))
1566                 rx_vft_set(res->port_id, res->vlan_id, 1);
1567         else
1568                 rx_vft_set(res->port_id, res->vlan_id, 0);
1569 }
1570
1571 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
1572         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
1573                                  rx_vlan, "rx_vlan");
1574 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
1575         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
1576                                  what, "add#rm");
1577 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
1578         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
1579                               vlan_id, UINT16);
1580 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
1581         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
1582                               port_id, UINT8);
1583
1584 cmdline_parse_inst_t cmd_rx_vlan_filter = {
1585         .f = cmd_rx_vlan_filter_parsed,
1586         .data = NULL,
1587         .help_str = "add/remove a VLAN identifier to/from the set of VLAN "
1588         "Identifiers filtered by a port",
1589         .tokens = {
1590                 (void *)&cmd_rx_vlan_filter_rx_vlan,
1591                 (void *)&cmd_rx_vlan_filter_what,
1592                 (void *)&cmd_rx_vlan_filter_vlanid,
1593                 (void *)&cmd_rx_vlan_filter_portid,
1594                 NULL,
1595         },
1596 };
1597
1598 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
1599 struct cmd_tx_vlan_set_result {
1600         cmdline_fixed_string_t tx_vlan;
1601         cmdline_fixed_string_t set;
1602         uint16_t vlan_id;
1603         uint8_t port_id;
1604 };
1605
1606 static void
1607 cmd_tx_vlan_set_parsed(void *parsed_result,
1608                        __attribute__((unused)) struct cmdline *cl,
1609                        __attribute__((unused)) void *data)
1610 {
1611         struct cmd_tx_vlan_set_result *res = parsed_result;
1612         tx_vlan_set(res->port_id, res->vlan_id);
1613 }
1614
1615 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
1616         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
1617                                  tx_vlan, "tx_vlan");
1618 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
1619         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
1620                                  set, "set");
1621 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
1622         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
1623                               vlan_id, UINT16);
1624 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
1625         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
1626                               port_id, UINT8);
1627
1628 cmdline_parse_inst_t cmd_tx_vlan_set = {
1629         .f = cmd_tx_vlan_set_parsed,
1630         .data = NULL,
1631         .help_str = "enable hardware insertion of a VLAN header with a given "
1632         "TAG Identifier in packets sent on a port",
1633         .tokens = {
1634                 (void *)&cmd_tx_vlan_set_tx_vlan,
1635                 (void *)&cmd_tx_vlan_set_set,
1636                 (void *)&cmd_tx_vlan_set_vlanid,
1637                 (void *)&cmd_tx_vlan_set_portid,
1638                 NULL,
1639         },
1640 };
1641
1642 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
1643 struct cmd_tx_vlan_reset_result {
1644         cmdline_fixed_string_t tx_vlan;
1645         cmdline_fixed_string_t reset;
1646         uint8_t port_id;
1647 };
1648
1649 static void
1650 cmd_tx_vlan_reset_parsed(void *parsed_result,
1651                          __attribute__((unused)) struct cmdline *cl,
1652                          __attribute__((unused)) void *data)
1653 {
1654         struct cmd_tx_vlan_reset_result *res = parsed_result;
1655
1656         tx_vlan_reset(res->port_id);
1657 }
1658
1659 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
1660         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
1661                                  tx_vlan, "tx_vlan");
1662 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
1663         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
1664                                  reset, "reset");
1665 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
1666         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
1667                               port_id, UINT8);
1668
1669 cmdline_parse_inst_t cmd_tx_vlan_reset = {
1670         .f = cmd_tx_vlan_reset_parsed,
1671         .data = NULL,
1672         .help_str = "disable hardware insertion of a VLAN header in packets "
1673         "sent on a port",
1674         .tokens = {
1675                 (void *)&cmd_tx_vlan_reset_tx_vlan,
1676                 (void *)&cmd_tx_vlan_reset_reset,
1677                 (void *)&cmd_tx_vlan_reset_portid,
1678                 NULL,
1679         },
1680 };
1681
1682
1683 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
1684 struct cmd_tx_cksum_set_result {
1685         cmdline_fixed_string_t tx_cksum;
1686         cmdline_fixed_string_t set;
1687         uint8_t cksum_mask;
1688         uint8_t port_id;
1689 };
1690
1691 static void
1692 cmd_tx_cksum_set_parsed(void *parsed_result,
1693                        __attribute__((unused)) struct cmdline *cl,
1694                        __attribute__((unused)) void *data)
1695 {
1696         struct cmd_tx_cksum_set_result *res = parsed_result;
1697
1698         tx_cksum_set(res->port_id, res->cksum_mask);
1699 }
1700
1701 cmdline_parse_token_string_t cmd_tx_cksum_set_tx_cksum =
1702         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
1703                                 tx_cksum, "tx_checksum");
1704 cmdline_parse_token_string_t cmd_tx_cksum_set_set =
1705         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
1706                                 set, "set");
1707 cmdline_parse_token_num_t cmd_tx_cksum_set_cksum_mask =
1708         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
1709                                 cksum_mask, UINT8);
1710 cmdline_parse_token_num_t cmd_tx_cksum_set_portid =
1711         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
1712                                 port_id, UINT8);
1713
1714 cmdline_parse_inst_t cmd_tx_cksum_set = {
1715         .f = cmd_tx_cksum_set_parsed,
1716         .data = NULL,
1717         .help_str = "enable hardware insertion of L3/L4checksum with a given "
1718         "mask in packets sent on a port, the bit mapping is given as, Bit 0 for ip"
1719         "Bit 1 for UDP, Bit 2 for TCP, Bit 3 for SCTP",
1720         .tokens = {
1721                 (void *)&cmd_tx_cksum_set_tx_cksum,
1722                 (void *)&cmd_tx_cksum_set_set,
1723                 (void *)&cmd_tx_cksum_set_cksum_mask,
1724                 (void *)&cmd_tx_cksum_set_portid,
1725                 NULL,
1726         },
1727 };
1728
1729 /* *** SET FORWARDING MODE *** */
1730 struct cmd_set_fwd_mode_result {
1731         cmdline_fixed_string_t set;
1732         cmdline_fixed_string_t fwd;
1733         cmdline_fixed_string_t mode;
1734 };
1735
1736 static void cmd_set_fwd_mode_parsed(void *parsed_result,
1737                                     __attribute__((unused)) struct cmdline *cl,
1738                                     __attribute__((unused)) void *data)
1739 {
1740         struct cmd_set_fwd_mode_result *res = parsed_result;
1741
1742         set_pkt_forwarding_mode(res->mode);
1743 }
1744
1745 cmdline_parse_token_string_t cmd_setfwd_set =
1746         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
1747 cmdline_parse_token_string_t cmd_setfwd_fwd =
1748         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
1749 cmdline_parse_token_string_t cmd_setfwd_mode =
1750         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
1751 #ifdef RTE_LIBRTE_IEEE1588
1752                                  "io#mac#rxonly#txonly#csum#ieee1588");
1753 #else
1754                                  "io#mac#rxonly#txonly#csum");
1755 #endif
1756
1757 cmdline_parse_inst_t cmd_set_fwd_mode = {
1758         .f = cmd_set_fwd_mode_parsed,
1759         .data = NULL,
1760 #ifdef RTE_LIBRTE_IEEE1588
1761         .help_str = "set fwd io|mac|rxonly|txonly|csum|ieee1588 - set IO, MAC,"
1762         " RXONLY, TXONLY, CSUM or IEEE1588 packet forwarding mode",
1763 #else
1764         .help_str = "set fwd io|mac|rxonly|txonly|csum - set IO, MAC,"
1765         " RXONLY, CSUM or TXONLY packet forwarding mode",
1766 #endif
1767         .tokens = {
1768                 (void *)&cmd_setfwd_set,
1769                 (void *)&cmd_setfwd_fwd,
1770                 (void *)&cmd_setfwd_mode,
1771                 NULL,
1772         },
1773 };
1774
1775 /* *** SET PROMISC MODE *** */
1776 struct cmd_set_promisc_mode_result {
1777         cmdline_fixed_string_t set;
1778         cmdline_fixed_string_t promisc;
1779         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
1780         uint8_t port_num;                /* valid if "allports" argument == 0 */
1781         cmdline_fixed_string_t mode;
1782 };
1783
1784 static void cmd_set_promisc_mode_parsed(void *parsed_result,
1785                                         __attribute__((unused)) struct cmdline *cl,
1786                                         void *allports)
1787 {
1788         struct cmd_set_promisc_mode_result *res = parsed_result;
1789         int enable;
1790         portid_t i;
1791
1792         if (!strcmp(res->mode, "on"))
1793                 enable = 1;
1794         else
1795                 enable = 0;
1796
1797         /* all ports */
1798         if (allports) {
1799                 for (i = 0; i < nb_ports; i++) {
1800                         if (enable)
1801                                 rte_eth_promiscuous_enable(i);
1802                         else
1803                                 rte_eth_promiscuous_disable(i);
1804                 }
1805         }
1806         else {
1807                 if (enable)
1808                         rte_eth_promiscuous_enable(res->port_num);
1809                 else
1810                         rte_eth_promiscuous_disable(res->port_num);
1811         }
1812 }
1813
1814 cmdline_parse_token_string_t cmd_setpromisc_set =
1815         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
1816 cmdline_parse_token_string_t cmd_setpromisc_promisc =
1817         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
1818                                  "promisc");
1819 cmdline_parse_token_string_t cmd_setpromisc_portall =
1820         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
1821                                  "all");
1822 cmdline_parse_token_num_t cmd_setpromisc_portnum =
1823         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
1824                               UINT8);
1825 cmdline_parse_token_string_t cmd_setpromisc_mode =
1826         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
1827                                  "on#off");
1828
1829 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
1830         .f = cmd_set_promisc_mode_parsed,
1831         .data = (void *)1,
1832         .help_str = "set promisc all on|off: set promisc mode for all ports",
1833         .tokens = {
1834                 (void *)&cmd_setpromisc_set,
1835                 (void *)&cmd_setpromisc_promisc,
1836                 (void *)&cmd_setpromisc_portall,
1837                 (void *)&cmd_setpromisc_mode,
1838                 NULL,
1839         },
1840 };
1841
1842 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
1843         .f = cmd_set_promisc_mode_parsed,
1844         .data = (void *)0,
1845         .help_str = "set promisc X on|off: set promisc mode on port X",
1846         .tokens = {
1847                 (void *)&cmd_setpromisc_set,
1848                 (void *)&cmd_setpromisc_promisc,
1849                 (void *)&cmd_setpromisc_portnum,
1850                 (void *)&cmd_setpromisc_mode,
1851                 NULL,
1852         },
1853 };
1854
1855 /* *** SET ALLMULTI MODE *** */
1856 struct cmd_set_allmulti_mode_result {
1857         cmdline_fixed_string_t set;
1858         cmdline_fixed_string_t allmulti;
1859         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
1860         uint8_t port_num;                /* valid if "allports" argument == 0 */
1861         cmdline_fixed_string_t mode;
1862 };
1863
1864 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
1865                                         __attribute__((unused)) struct cmdline *cl,
1866                                         void *allports)
1867 {
1868         struct cmd_set_allmulti_mode_result *res = parsed_result;
1869         int enable;
1870         portid_t i;
1871
1872         if (!strcmp(res->mode, "on"))
1873                 enable = 1;
1874         else
1875                 enable = 0;
1876
1877         /* all ports */
1878         if (allports) {
1879                 for (i = 0; i < nb_ports; i++) {
1880                         if (enable)
1881                                 rte_eth_allmulticast_enable(i);
1882                         else
1883                                 rte_eth_allmulticast_disable(i);
1884                 }
1885         }
1886         else {
1887                 if (enable)
1888                         rte_eth_allmulticast_enable(res->port_num);
1889                 else
1890                         rte_eth_allmulticast_disable(res->port_num);
1891         }
1892 }
1893
1894 cmdline_parse_token_string_t cmd_setallmulti_set =
1895         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
1896 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
1897         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
1898                                  "allmulti");
1899 cmdline_parse_token_string_t cmd_setallmulti_portall =
1900         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
1901                                  "all");
1902 cmdline_parse_token_num_t cmd_setallmulti_portnum =
1903         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
1904                               UINT8);
1905 cmdline_parse_token_string_t cmd_setallmulti_mode =
1906         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
1907                                  "on#off");
1908
1909 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
1910         .f = cmd_set_allmulti_mode_parsed,
1911         .data = (void *)1,
1912         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
1913         .tokens = {
1914                 (void *)&cmd_setallmulti_set,
1915                 (void *)&cmd_setallmulti_allmulti,
1916                 (void *)&cmd_setallmulti_portall,
1917                 (void *)&cmd_setallmulti_mode,
1918                 NULL,
1919         },
1920 };
1921
1922 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
1923         .f = cmd_set_allmulti_mode_parsed,
1924         .data = (void *)0,
1925         .help_str = "set allmulti X on|off: set allmulti mode on port X",
1926         .tokens = {
1927                 (void *)&cmd_setallmulti_set,
1928                 (void *)&cmd_setallmulti_allmulti,
1929                 (void *)&cmd_setallmulti_portnum,
1930                 (void *)&cmd_setallmulti_mode,
1931                 NULL,
1932         },
1933 };
1934
1935 /* *** ADD/REMOVE A PKT FILTER *** */
1936 struct cmd_pkt_filter_result {
1937         cmdline_fixed_string_t pkt_filter;
1938         uint8_t  port_id;
1939         cmdline_fixed_string_t protocol;
1940         cmdline_fixed_string_t src;
1941         cmdline_ipaddr_t ip_src;
1942         uint16_t port_src;
1943         cmdline_fixed_string_t dst;
1944         cmdline_ipaddr_t ip_dst;
1945         uint16_t port_dst;
1946         cmdline_fixed_string_t flexbytes;
1947         uint16_t flexbytes_value;
1948         cmdline_fixed_string_t vlan;
1949         uint16_t  vlan_id;
1950         cmdline_fixed_string_t queue;
1951         int8_t  queue_id;
1952         cmdline_fixed_string_t soft;
1953         uint8_t  soft_id;
1954 };
1955
1956 static void
1957 cmd_pkt_filter_parsed(void *parsed_result,
1958                           __attribute__((unused)) struct cmdline *cl,
1959                           __attribute__((unused)) void *data)
1960 {
1961         struct rte_fdir_filter fdir_filter;
1962         struct cmd_pkt_filter_result *res = parsed_result;
1963
1964         memset(&fdir_filter, 0, sizeof(struct rte_fdir_filter));
1965
1966         if (res->ip_src.family == AF_INET)
1967                 fdir_filter.ip_src.ipv4_addr = res->ip_src.addr.ipv4.s_addr;
1968         else
1969                 memcpy(&(fdir_filter.ip_src.ipv6_addr),
1970                        &(res->ip_src.addr.ipv6),
1971                        sizeof(struct in6_addr));
1972
1973         if (res->ip_dst.family == AF_INET)
1974                 fdir_filter.ip_dst.ipv4_addr = res->ip_dst.addr.ipv4.s_addr;
1975         else
1976                 memcpy(&(fdir_filter.ip_dst.ipv6_addr),
1977                        &(res->ip_dst.addr.ipv6),
1978                        sizeof(struct in6_addr));
1979
1980         fdir_filter.port_dst = rte_cpu_to_be_16(res->port_dst);
1981         fdir_filter.port_src = rte_cpu_to_be_16(res->port_src);
1982
1983         if (!strcmp(res->protocol, "udp"))
1984                 fdir_filter.l4type = RTE_FDIR_L4TYPE_UDP;
1985         else if (!strcmp(res->protocol, "tcp"))
1986                 fdir_filter.l4type = RTE_FDIR_L4TYPE_TCP;
1987         else if (!strcmp(res->protocol, "sctp"))
1988                 fdir_filter.l4type = RTE_FDIR_L4TYPE_SCTP;
1989         else /* default only IP */
1990                 fdir_filter.l4type = RTE_FDIR_L4TYPE_NONE;
1991
1992         if (res->ip_dst.family == AF_INET6)
1993                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV6;
1994         else
1995                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV4;
1996
1997         fdir_filter.vlan_id    = rte_cpu_to_be_16(res->vlan_id);
1998         fdir_filter.flex_bytes = rte_cpu_to_be_16(res->flexbytes_value);
1999
2000         if (!strcmp(res->pkt_filter, "add_signature_filter"))
2001                 fdir_add_signature_filter(res->port_id, res->queue_id,
2002                                           &fdir_filter);
2003         else if (!strcmp(res->pkt_filter, "upd_signature_filter"))
2004                 fdir_update_signature_filter(res->port_id, res->queue_id,
2005                                              &fdir_filter);
2006         else if (!strcmp(res->pkt_filter, "rm_signature_filter"))
2007                 fdir_remove_signature_filter(res->port_id, &fdir_filter);
2008         else if (!strcmp(res->pkt_filter, "add_perfect_filter"))
2009                 fdir_add_perfect_filter(res->port_id, res->soft_id,
2010                                         res->queue_id,
2011                                         (uint8_t) (res->queue_id < 0),
2012                                         &fdir_filter);
2013         else if (!strcmp(res->pkt_filter, "upd_perfect_filter"))
2014                 fdir_update_perfect_filter(res->port_id, res->soft_id,
2015                                            res->queue_id,
2016                                            (uint8_t) (res->queue_id < 0),
2017                                            &fdir_filter);
2018         else if (!strcmp(res->pkt_filter, "rm_perfect_filter"))
2019                 fdir_remove_perfect_filter(res->port_id, res->soft_id,
2020                                            &fdir_filter);
2021
2022 }
2023
2024
2025 cmdline_parse_token_num_t cmd_pkt_filter_port_id =
2026         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2027                               port_id, UINT8);
2028 cmdline_parse_token_string_t cmd_pkt_filter_protocol =
2029         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2030                                  protocol, "ip#tcp#udp#sctp");
2031 cmdline_parse_token_string_t cmd_pkt_filter_src =
2032         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2033                                  src, "src");
2034 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_src =
2035         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
2036                                  ip_src);
2037 cmdline_parse_token_num_t cmd_pkt_filter_port_src =
2038         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2039                               port_src, UINT16);
2040 cmdline_parse_token_string_t cmd_pkt_filter_dst =
2041         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2042                                  dst, "dst");
2043 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_dst =
2044         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
2045                                  ip_dst);
2046 cmdline_parse_token_num_t cmd_pkt_filter_port_dst =
2047         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2048                               port_dst, UINT16);
2049 cmdline_parse_token_string_t cmd_pkt_filter_flexbytes =
2050         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2051                                  flexbytes, "flexbytes");
2052 cmdline_parse_token_num_t cmd_pkt_filter_flexbytes_value =
2053         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2054                               flexbytes_value, UINT16);
2055 cmdline_parse_token_string_t cmd_pkt_filter_vlan =
2056         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2057                                  vlan, "vlan");
2058 cmdline_parse_token_num_t cmd_pkt_filter_vlan_id =
2059         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2060                               vlan_id, UINT16);
2061 cmdline_parse_token_string_t cmd_pkt_filter_queue =
2062         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2063                                  queue, "queue");
2064 cmdline_parse_token_num_t cmd_pkt_filter_queue_id =
2065         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2066                               queue_id, INT8);
2067 cmdline_parse_token_string_t cmd_pkt_filter_soft =
2068         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2069                                  soft, "soft");
2070 cmdline_parse_token_num_t cmd_pkt_filter_soft_id =
2071         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2072                               soft_id, UINT16);
2073
2074
2075 cmdline_parse_token_string_t cmd_pkt_filter_add_signature_filter =
2076         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2077                                  pkt_filter, "add_signature_filter");
2078 cmdline_parse_inst_t cmd_add_signature_filter = {
2079         .f = cmd_pkt_filter_parsed,
2080         .data = NULL,
2081         .help_str = "add a signature filter",
2082         .tokens = {
2083                 (void *)&cmd_pkt_filter_add_signature_filter,
2084                 (void *)&cmd_pkt_filter_port_id,
2085                 (void *)&cmd_pkt_filter_protocol,
2086                 (void *)&cmd_pkt_filter_src,
2087                 (void *)&cmd_pkt_filter_ip_src,
2088                 (void *)&cmd_pkt_filter_port_src,
2089                 (void *)&cmd_pkt_filter_dst,
2090                 (void *)&cmd_pkt_filter_ip_dst,
2091                 (void *)&cmd_pkt_filter_port_dst,
2092                 (void *)&cmd_pkt_filter_flexbytes,
2093                 (void *)&cmd_pkt_filter_flexbytes_value,
2094                 (void *)&cmd_pkt_filter_vlan,
2095                 (void *)&cmd_pkt_filter_vlan_id,
2096                 (void *)&cmd_pkt_filter_queue,
2097                 (void *)&cmd_pkt_filter_queue_id,
2098                 NULL,
2099         },
2100 };
2101
2102
2103 cmdline_parse_token_string_t cmd_pkt_filter_upd_signature_filter =
2104         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2105                                  pkt_filter, "upd_signature_filter");
2106 cmdline_parse_inst_t cmd_upd_signature_filter = {
2107         .f = cmd_pkt_filter_parsed,
2108         .data = NULL,
2109         .help_str = "update a signature filter",
2110         .tokens = {
2111                 (void *)&cmd_pkt_filter_upd_signature_filter,
2112                 (void *)&cmd_pkt_filter_port_id,
2113                 (void *)&cmd_pkt_filter_protocol,
2114                 (void *)&cmd_pkt_filter_src,
2115                 (void *)&cmd_pkt_filter_ip_src,
2116                 (void *)&cmd_pkt_filter_port_src,
2117                 (void *)&cmd_pkt_filter_dst,
2118                 (void *)&cmd_pkt_filter_ip_dst,
2119                 (void *)&cmd_pkt_filter_port_dst,
2120                 (void *)&cmd_pkt_filter_flexbytes,
2121                 (void *)&cmd_pkt_filter_flexbytes_value,
2122                 (void *)&cmd_pkt_filter_vlan,
2123                 (void *)&cmd_pkt_filter_vlan_id,
2124                 (void *)&cmd_pkt_filter_queue,
2125                 (void *)&cmd_pkt_filter_queue_id,
2126                 NULL,
2127         },
2128 };
2129
2130
2131 cmdline_parse_token_string_t cmd_pkt_filter_rm_signature_filter =
2132         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2133                                  pkt_filter, "rm_signature_filter");
2134 cmdline_parse_inst_t cmd_rm_signature_filter = {
2135         .f = cmd_pkt_filter_parsed,
2136         .data = NULL,
2137         .help_str = "remove a signature filter",
2138         .tokens = {
2139                 (void *)&cmd_pkt_filter_rm_signature_filter,
2140                 (void *)&cmd_pkt_filter_port_id,
2141                 (void *)&cmd_pkt_filter_protocol,
2142                 (void *)&cmd_pkt_filter_src,
2143                 (void *)&cmd_pkt_filter_ip_src,
2144                 (void *)&cmd_pkt_filter_port_src,
2145                 (void *)&cmd_pkt_filter_dst,
2146                 (void *)&cmd_pkt_filter_ip_dst,
2147                 (void *)&cmd_pkt_filter_port_dst,
2148                 (void *)&cmd_pkt_filter_flexbytes,
2149                 (void *)&cmd_pkt_filter_flexbytes_value,
2150                 (void *)&cmd_pkt_filter_vlan,
2151                 (void *)&cmd_pkt_filter_vlan_id,
2152                 NULL
2153                 },
2154 };
2155
2156
2157 cmdline_parse_token_string_t cmd_pkt_filter_add_perfect_filter =
2158         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2159                                  pkt_filter, "add_perfect_filter");
2160 cmdline_parse_inst_t cmd_add_perfect_filter = {
2161         .f = cmd_pkt_filter_parsed,
2162         .data = NULL,
2163         .help_str = "add a perfect filter",
2164         .tokens = {
2165                 (void *)&cmd_pkt_filter_add_perfect_filter,
2166                 (void *)&cmd_pkt_filter_port_id,
2167                 (void *)&cmd_pkt_filter_protocol,
2168                 (void *)&cmd_pkt_filter_src,
2169                 (void *)&cmd_pkt_filter_ip_src,
2170                 (void *)&cmd_pkt_filter_port_src,
2171                 (void *)&cmd_pkt_filter_dst,
2172                 (void *)&cmd_pkt_filter_ip_dst,
2173                 (void *)&cmd_pkt_filter_port_dst,
2174                 (void *)&cmd_pkt_filter_flexbytes,
2175                 (void *)&cmd_pkt_filter_flexbytes_value,
2176                 (void *)&cmd_pkt_filter_vlan,
2177                 (void *)&cmd_pkt_filter_vlan_id,
2178                 (void *)&cmd_pkt_filter_queue,
2179                 (void *)&cmd_pkt_filter_queue_id,
2180                 (void *)&cmd_pkt_filter_soft,
2181                 (void *)&cmd_pkt_filter_soft_id,
2182                 NULL,
2183         },
2184 };
2185
2186
2187 cmdline_parse_token_string_t cmd_pkt_filter_upd_perfect_filter =
2188         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2189                                  pkt_filter, "upd_perfect_filter");
2190 cmdline_parse_inst_t cmd_upd_perfect_filter = {
2191         .f = cmd_pkt_filter_parsed,
2192         .data = NULL,
2193         .help_str = "update a perfect filter",
2194         .tokens = {
2195                 (void *)&cmd_pkt_filter_upd_perfect_filter,
2196                 (void *)&cmd_pkt_filter_port_id,
2197                 (void *)&cmd_pkt_filter_protocol,
2198                 (void *)&cmd_pkt_filter_src,
2199                 (void *)&cmd_pkt_filter_ip_src,
2200                 (void *)&cmd_pkt_filter_port_src,
2201                 (void *)&cmd_pkt_filter_dst,
2202                 (void *)&cmd_pkt_filter_ip_dst,
2203                 (void *)&cmd_pkt_filter_port_dst,
2204                 (void *)&cmd_pkt_filter_flexbytes,
2205                 (void *)&cmd_pkt_filter_flexbytes_value,
2206                 (void *)&cmd_pkt_filter_vlan,
2207                 (void *)&cmd_pkt_filter_vlan_id,
2208                 (void *)&cmd_pkt_filter_queue,
2209                 (void *)&cmd_pkt_filter_queue_id,
2210                 (void *)&cmd_pkt_filter_soft,
2211                 (void *)&cmd_pkt_filter_soft_id,
2212                 NULL,
2213         },
2214 };
2215
2216
2217 cmdline_parse_token_string_t cmd_pkt_filter_rm_perfect_filter =
2218         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2219                                  pkt_filter, "rm_perfect_filter");
2220 cmdline_parse_inst_t cmd_rm_perfect_filter = {
2221         .f = cmd_pkt_filter_parsed,
2222         .data = NULL,
2223         .help_str = "remove a perfect filter",
2224         .tokens = {
2225                 (void *)&cmd_pkt_filter_rm_perfect_filter,
2226                 (void *)&cmd_pkt_filter_port_id,
2227                 (void *)&cmd_pkt_filter_protocol,
2228                 (void *)&cmd_pkt_filter_src,
2229                 (void *)&cmd_pkt_filter_ip_src,
2230                 (void *)&cmd_pkt_filter_port_src,
2231                 (void *)&cmd_pkt_filter_dst,
2232                 (void *)&cmd_pkt_filter_ip_dst,
2233                 (void *)&cmd_pkt_filter_port_dst,
2234                 (void *)&cmd_pkt_filter_flexbytes,
2235                 (void *)&cmd_pkt_filter_flexbytes_value,
2236                 (void *)&cmd_pkt_filter_vlan,
2237                 (void *)&cmd_pkt_filter_vlan_id,
2238                 (void *)&cmd_pkt_filter_soft,
2239                 (void *)&cmd_pkt_filter_soft_id,
2240                 NULL,
2241         },
2242 };
2243
2244 /* *** SETUP MASKS FILTER *** */
2245 struct cmd_pkt_filter_masks_result {
2246         cmdline_fixed_string_t filter_mask;
2247         uint8_t  port_id;
2248         cmdline_fixed_string_t src_mask;
2249         uint32_t ip_src_mask;
2250         uint16_t ipv6_src_mask;
2251         uint16_t port_src_mask;
2252         cmdline_fixed_string_t dst_mask;
2253         uint32_t ip_dst_mask;
2254         uint16_t ipv6_dst_mask;
2255         uint16_t port_dst_mask;
2256         cmdline_fixed_string_t flexbytes;
2257         uint8_t flexbytes_value;
2258         cmdline_fixed_string_t vlan_id;
2259         uint8_t  vlan_id_value;
2260         cmdline_fixed_string_t vlan_prio;
2261         uint8_t  vlan_prio_value;
2262         cmdline_fixed_string_t only_ip_flow;
2263         uint8_t  only_ip_flow_value;
2264         cmdline_fixed_string_t comp_ipv6_dst;
2265         uint8_t  comp_ipv6_dst_value;
2266 };
2267
2268 static void
2269 cmd_pkt_filter_masks_parsed(void *parsed_result,
2270                           __attribute__((unused)) struct cmdline *cl,
2271                           __attribute__((unused)) void *data)
2272 {
2273         struct rte_fdir_masks fdir_masks;
2274         struct cmd_pkt_filter_masks_result *res = parsed_result;
2275
2276         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
2277
2278         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
2279         fdir_masks.vlan_id       = res->vlan_id_value;
2280         fdir_masks.vlan_prio     = res->vlan_prio_value;
2281         fdir_masks.dst_ipv4_mask = res->ip_dst_mask;
2282         fdir_masks.src_ipv4_mask = res->ip_src_mask;
2283         fdir_masks.src_port_mask = res->port_src_mask;
2284         fdir_masks.dst_port_mask = res->port_dst_mask;
2285         fdir_masks.flexbytes     = res->flexbytes_value;
2286
2287         fdir_set_masks(res->port_id, &fdir_masks);
2288 }
2289
2290 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask =
2291         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2292                                  filter_mask, "set_masks_filter");
2293 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_id =
2294         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2295                               port_id, UINT8);
2296 cmdline_parse_token_string_t cmd_pkt_filter_masks_only_ip_flow =
2297         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2298                                  only_ip_flow, "only_ip_flow");
2299 cmdline_parse_token_num_t cmd_pkt_filter_masks_only_ip_flow_value =
2300         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2301                               only_ip_flow_value, UINT8);
2302 cmdline_parse_token_string_t cmd_pkt_filter_masks_src_mask =
2303         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2304                                  src_mask, "src_mask");
2305 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_src_mask =
2306         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2307                               ip_src_mask, UINT32);
2308 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_src_mask =
2309         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2310                               port_src_mask, UINT16);
2311 cmdline_parse_token_string_t cmd_pkt_filter_masks_dst_mask =
2312         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2313                                  dst_mask, "dst_mask");
2314 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_dst_mask =
2315         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2316                               ip_dst_mask, UINT32);
2317 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_dst_mask =
2318         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2319                               port_dst_mask, UINT16);
2320 cmdline_parse_token_string_t cmd_pkt_filter_masks_flexbytes =
2321         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2322                                  flexbytes, "flexbytes");
2323 cmdline_parse_token_num_t cmd_pkt_filter_masks_flexbytes_value =
2324         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2325                               flexbytes_value, UINT8);
2326 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_id =
2327         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2328                                  vlan_id, "vlan_id");
2329 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_id_value =
2330         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2331                               vlan_id_value, UINT8);
2332 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_prio =
2333         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2334                                  vlan_prio, "vlan_prio");
2335 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_prio_value =
2336         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2337                               vlan_prio_value, UINT8);
2338
2339 cmdline_parse_inst_t cmd_set_masks_filter = {
2340         .f = cmd_pkt_filter_masks_parsed,
2341         .data = NULL,
2342         .help_str = "setup masks filter",
2343         .tokens = {
2344                 (void *)&cmd_pkt_filter_masks_filter_mask,
2345                 (void *)&cmd_pkt_filter_masks_port_id,
2346                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
2347                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
2348                 (void *)&cmd_pkt_filter_masks_src_mask,
2349                 (void *)&cmd_pkt_filter_masks_ip_src_mask,
2350                 (void *)&cmd_pkt_filter_masks_port_src_mask,
2351                 (void *)&cmd_pkt_filter_masks_dst_mask,
2352                 (void *)&cmd_pkt_filter_masks_ip_dst_mask,
2353                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
2354                 (void *)&cmd_pkt_filter_masks_flexbytes,
2355                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
2356                 (void *)&cmd_pkt_filter_masks_vlan_id,
2357                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
2358                 (void *)&cmd_pkt_filter_masks_vlan_prio,
2359                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
2360                 NULL,
2361         },
2362 };
2363
2364 static void
2365 cmd_pkt_filter_masks_ipv6_parsed(void *parsed_result,
2366                           __attribute__((unused)) struct cmdline *cl,
2367                           __attribute__((unused)) void *data)
2368 {
2369         struct rte_fdir_masks fdir_masks;
2370         struct cmd_pkt_filter_masks_result *res = parsed_result;
2371
2372         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
2373
2374         fdir_masks.set_ipv6_mask = 1;
2375         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
2376         fdir_masks.vlan_id       = res->vlan_id_value;
2377         fdir_masks.vlan_prio     = res->vlan_prio_value;
2378         fdir_masks.dst_ipv6_mask = res->ipv6_dst_mask;
2379         fdir_masks.src_ipv6_mask = res->ipv6_src_mask;
2380         fdir_masks.src_port_mask = res->port_src_mask;
2381         fdir_masks.dst_port_mask = res->port_dst_mask;
2382         fdir_masks.flexbytes     = res->flexbytes_value;
2383         fdir_masks.comp_ipv6_dst = res->comp_ipv6_dst_value;
2384
2385         fdir_set_masks(res->port_id, &fdir_masks);
2386 }
2387
2388 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask_ipv6 =
2389         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2390                                  filter_mask, "set_ipv6_masks_filter");
2391 cmdline_parse_token_num_t cmd_pkt_filter_masks_src_mask_ipv6_value =
2392         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2393                               ipv6_src_mask, UINT16);
2394 cmdline_parse_token_num_t cmd_pkt_filter_masks_dst_mask_ipv6_value =
2395         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2396                               ipv6_dst_mask, UINT16);
2397
2398 cmdline_parse_token_string_t cmd_pkt_filter_masks_comp_ipv6_dst =
2399         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2400                                  comp_ipv6_dst, "compare_dst");
2401 cmdline_parse_token_num_t cmd_pkt_filter_masks_comp_ipv6_dst_value =
2402         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2403                               comp_ipv6_dst_value, UINT8);
2404
2405 cmdline_parse_inst_t cmd_set_ipv6_masks_filter = {
2406         .f = cmd_pkt_filter_masks_ipv6_parsed,
2407         .data = NULL,
2408         .help_str = "setup ipv6 masks filter",
2409         .tokens = {
2410                 (void *)&cmd_pkt_filter_masks_filter_mask_ipv6,
2411                 (void *)&cmd_pkt_filter_masks_port_id,
2412                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
2413                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
2414                 (void *)&cmd_pkt_filter_masks_src_mask,
2415                 (void *)&cmd_pkt_filter_masks_src_mask_ipv6_value,
2416                 (void *)&cmd_pkt_filter_masks_port_src_mask,
2417                 (void *)&cmd_pkt_filter_masks_dst_mask,
2418                 (void *)&cmd_pkt_filter_masks_dst_mask_ipv6_value,
2419                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
2420                 (void *)&cmd_pkt_filter_masks_flexbytes,
2421                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
2422                 (void *)&cmd_pkt_filter_masks_vlan_id,
2423                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
2424                 (void *)&cmd_pkt_filter_masks_vlan_prio,
2425                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
2426                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst,
2427                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst_value,
2428                 NULL,
2429         },
2430 };
2431
2432 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
2433 struct cmd_link_flow_ctrl_set_result {
2434         cmdline_fixed_string_t set;
2435         cmdline_fixed_string_t flow_ctrl;
2436         cmdline_fixed_string_t rx;
2437         cmdline_fixed_string_t rx_lfc_mode;
2438         cmdline_fixed_string_t tx;
2439         cmdline_fixed_string_t tx_lfc_mode;
2440         uint32_t high_water;
2441         uint32_t low_water;
2442         uint16_t pause_time;
2443         uint16_t send_xon;
2444         uint8_t  port_id;
2445 };
2446
2447 static void
2448 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
2449                        __attribute__((unused)) struct cmdline *cl,
2450                        __attribute__((unused)) void *data)
2451 {
2452         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
2453         struct rte_eth_fc_conf fc_conf;
2454         int rx_fc_enable, tx_fc_enable;
2455         int ret;
2456
2457         /*
2458          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
2459          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
2460          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
2461          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
2462          */
2463         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
2464                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
2465         };
2466
2467         rx_fc_enable = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
2468         tx_fc_enable = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
2469
2470         fc_conf.mode       = rx_tx_onoff_2_lfc_mode[rx_fc_enable][tx_fc_enable];
2471         fc_conf.high_water = res->high_water;
2472         fc_conf.low_water  = res->low_water;
2473         fc_conf.pause_time = res->pause_time;
2474         fc_conf.send_xon   = res->send_xon;
2475
2476         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
2477         if (ret != 0)
2478                 printf("bad flow contrl parameter, return code = %d \n", ret);
2479 }
2480
2481 cmdline_parse_token_string_t cmd_lfc_set_set =
2482         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2483                                 set, "set");
2484 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
2485         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2486                                 flow_ctrl, "flow_ctrl");
2487 cmdline_parse_token_string_t cmd_lfc_set_rx =
2488         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2489                                 rx, "rx");
2490 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
2491         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2492                                 rx_lfc_mode, "on#off");
2493 cmdline_parse_token_string_t cmd_lfc_set_tx =
2494         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2495                                 tx, "tx");
2496 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
2497         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2498                                 tx_lfc_mode, "on#off");
2499 cmdline_parse_token_num_t cmd_lfc_set_high_water =
2500         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2501                                 high_water, UINT32);
2502 cmdline_parse_token_num_t cmd_lfc_set_low_water =
2503         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2504                                 low_water, UINT32);
2505 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
2506         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2507                                 pause_time, UINT16);
2508 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
2509         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2510                                 send_xon, UINT16);
2511 cmdline_parse_token_num_t cmd_lfc_set_portid =
2512         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2513                                 port_id, UINT8);
2514
2515 cmdline_parse_inst_t cmd_link_flow_control_set = {
2516         .f = cmd_link_flow_ctrl_set_parsed,
2517         .data = NULL,
2518         .help_str = "Configure the Ethernet link flow control...",
2519         .tokens = {
2520                 (void *)&cmd_lfc_set_set,
2521                 (void *)&cmd_lfc_set_flow_ctrl,
2522                 (void *)&cmd_lfc_set_rx,
2523                 (void *)&cmd_lfc_set_rx_mode,
2524                 (void *)&cmd_lfc_set_tx,
2525                 (void *)&cmd_lfc_set_tx_mode,
2526                 (void *)&cmd_lfc_set_high_water,
2527                 (void *)&cmd_lfc_set_low_water,
2528                 (void *)&cmd_lfc_set_pause_time,
2529                 (void *)&cmd_lfc_set_send_xon,
2530                 (void *)&cmd_lfc_set_portid,
2531                 NULL,
2532         },
2533 };
2534
2535 /* *** RESET CONFIGURATION *** */
2536 struct cmd_reset_result {
2537         cmdline_fixed_string_t reset;
2538         cmdline_fixed_string_t def;
2539 };
2540
2541 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
2542                              struct cmdline *cl,
2543                              __attribute__((unused)) void *data)
2544 {
2545         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
2546         set_def_fwd_config();
2547 }
2548
2549 cmdline_parse_token_string_t cmd_reset_set =
2550         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
2551 cmdline_parse_token_string_t cmd_reset_def =
2552         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
2553                                  "default");
2554
2555 cmdline_parse_inst_t cmd_reset = {
2556         .f = cmd_reset_parsed,
2557         .data = NULL,
2558         .help_str = "set default: reset default forwarding configuration",
2559         .tokens = {
2560                 (void *)&cmd_reset_set,
2561                 (void *)&cmd_reset_def,
2562                 NULL,
2563         },
2564 };
2565
2566 /* *** START FORWARDING *** */
2567 struct cmd_start_result {
2568         cmdline_fixed_string_t start;
2569 };
2570
2571 cmdline_parse_token_string_t cmd_start_start =
2572         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
2573
2574 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
2575                              __attribute__((unused)) struct cmdline *cl,
2576                              __attribute__((unused)) void *data)
2577 {
2578         start_packet_forwarding(0);
2579 }
2580
2581 cmdline_parse_inst_t cmd_start = {
2582         .f = cmd_start_parsed,
2583         .data = NULL,
2584         .help_str = "start packet forwarding",
2585         .tokens = {
2586                 (void *)&cmd_start_start,
2587                 NULL,
2588         },
2589 };
2590
2591 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
2592 struct cmd_start_tx_first_result {
2593         cmdline_fixed_string_t start;
2594         cmdline_fixed_string_t tx_first;
2595 };
2596
2597 static void
2598 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
2599                           __attribute__((unused)) struct cmdline *cl,
2600                           __attribute__((unused)) void *data)
2601 {
2602         start_packet_forwarding(1);
2603 }
2604
2605 cmdline_parse_token_string_t cmd_start_tx_first_start =
2606         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
2607                                  "start");
2608 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
2609         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
2610                                  tx_first, "tx_first");
2611
2612 cmdline_parse_inst_t cmd_start_tx_first = {
2613         .f = cmd_start_tx_first_parsed,
2614         .data = NULL,
2615         .help_str = "start packet forwarding, after sending 1 burst of packets",
2616         .tokens = {
2617                 (void *)&cmd_start_tx_first_start,
2618                 (void *)&cmd_start_tx_first_tx_first,
2619                 NULL,
2620         },
2621 };
2622
2623 /* *** SHOW CFG *** */
2624 struct cmd_showcfg_result {
2625         cmdline_fixed_string_t show;
2626         cmdline_fixed_string_t cfg;
2627         cmdline_fixed_string_t what;
2628 };
2629
2630 static void cmd_showcfg_parsed(void *parsed_result,
2631                                __attribute__((unused)) struct cmdline *cl,
2632                                __attribute__((unused)) void *data)
2633 {
2634         struct cmd_showcfg_result *res = parsed_result;
2635         if (!strcmp(res->what, "rxtx"))
2636                 rxtx_config_display();
2637         else if (!strcmp(res->what, "cores"))
2638                 fwd_lcores_config_display();
2639         else if (!strcmp(res->what, "fwd"))
2640                 fwd_config_display();
2641 }
2642
2643 cmdline_parse_token_string_t cmd_showcfg_show =
2644         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
2645 cmdline_parse_token_string_t cmd_showcfg_port =
2646         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
2647 cmdline_parse_token_string_t cmd_showcfg_what =
2648         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
2649                                  "rxtx#cores#fwd");
2650
2651 cmdline_parse_inst_t cmd_showcfg = {
2652         .f = cmd_showcfg_parsed,
2653         .data = NULL,
2654         .help_str = "show config rxtx|cores|fwd",
2655         .tokens = {
2656                 (void *)&cmd_showcfg_show,
2657                 (void *)&cmd_showcfg_port,
2658                 (void *)&cmd_showcfg_what,
2659                 NULL,
2660         },
2661 };
2662
2663 /* *** SHOW ALL PORT INFO *** */
2664 struct cmd_showportall_result {
2665         cmdline_fixed_string_t show;
2666         cmdline_fixed_string_t port;
2667         cmdline_fixed_string_t what;
2668         cmdline_fixed_string_t all;
2669 };
2670
2671 static void cmd_showportall_parsed(void *parsed_result,
2672                                 __attribute__((unused)) struct cmdline *cl,
2673                                 __attribute__((unused)) void *data)
2674 {
2675         portid_t i;
2676
2677         struct cmd_showportall_result *res = parsed_result;
2678         if (!strcmp(res->show, "clear")) {
2679                 if (!strcmp(res->what, "stats"))
2680                         for (i = 0; i < nb_ports; i++)
2681                                 nic_stats_clear(i);
2682         } else if (!strcmp(res->what, "info"))
2683                 for (i = 0; i < nb_ports; i++)
2684                         port_infos_display(i);
2685         else if (!strcmp(res->what, "stats"))
2686                 for (i = 0; i < nb_ports; i++)
2687                         nic_stats_display(i);
2688         else if (!strcmp(res->what, "fdir"))
2689                 for (i = 0; i < nb_ports; i++)
2690                         fdir_get_infos(i);
2691         else if (!strcmp(res->what, "stat_qmap"))
2692                 for (i = 0; i < nb_ports; i++)
2693                         nic_stats_mapping_display(i);
2694 }
2695
2696 cmdline_parse_token_string_t cmd_showportall_show =
2697         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
2698                                  "show#clear");
2699 cmdline_parse_token_string_t cmd_showportall_port =
2700         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
2701 cmdline_parse_token_string_t cmd_showportall_what =
2702         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
2703                                  "info#stats#fdir#stat_qmap");
2704 cmdline_parse_token_string_t cmd_showportall_all =
2705         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
2706 cmdline_parse_inst_t cmd_showportall = {
2707         .f = cmd_showportall_parsed,
2708         .data = NULL,
2709         .help_str = "show|clear port info|stats|fdir|stat_qmap all",
2710         .tokens = {
2711                 (void *)&cmd_showportall_show,
2712                 (void *)&cmd_showportall_port,
2713                 (void *)&cmd_showportall_what,
2714                 (void *)&cmd_showportall_all,
2715                 NULL,
2716         },
2717 };
2718
2719 /* *** SHOW PORT INFO *** */
2720 struct cmd_showport_result {
2721         cmdline_fixed_string_t show;
2722         cmdline_fixed_string_t port;
2723         cmdline_fixed_string_t what;
2724         uint8_t portnum;
2725 };
2726
2727 static void cmd_showport_parsed(void *parsed_result,
2728                                 __attribute__((unused)) struct cmdline *cl,
2729                                 __attribute__((unused)) void *data)
2730 {
2731         struct cmd_showport_result *res = parsed_result;
2732         if (!strcmp(res->show, "clear")) {
2733                 if (!strcmp(res->what, "stats"))
2734                         nic_stats_clear(res->portnum);
2735         } else if (!strcmp(res->what, "info"))
2736                 port_infos_display(res->portnum);
2737         else if (!strcmp(res->what, "stats"))
2738                 nic_stats_display(res->portnum);
2739         else if (!strcmp(res->what, "fdir"))
2740                  fdir_get_infos(res->portnum);
2741         else if (!strcmp(res->what, "stat_qmap"))
2742                 nic_stats_mapping_display(res->portnum);
2743 }
2744
2745 cmdline_parse_token_string_t cmd_showport_show =
2746         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
2747                                  "show#clear");
2748 cmdline_parse_token_string_t cmd_showport_port =
2749         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
2750 cmdline_parse_token_string_t cmd_showport_what =
2751         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
2752                                  "info#stats#fdir#stat_qmap");
2753 cmdline_parse_token_num_t cmd_showport_portnum =
2754         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, INT32);
2755
2756 cmdline_parse_inst_t cmd_showport = {
2757         .f = cmd_showport_parsed,
2758         .data = NULL,
2759         .help_str = "show|clear port info|stats|fdir|stat_qmap X (X = port number)",
2760         .tokens = {
2761                 (void *)&cmd_showport_show,
2762                 (void *)&cmd_showport_port,
2763                 (void *)&cmd_showport_what,
2764                 (void *)&cmd_showport_portnum,
2765                 NULL,
2766         },
2767 };
2768
2769 /* *** READ PORT REGISTER *** */
2770 struct cmd_read_reg_result {
2771         cmdline_fixed_string_t read;
2772         cmdline_fixed_string_t reg;
2773         uint8_t port_id;
2774         uint32_t reg_off;
2775 };
2776
2777 static void
2778 cmd_read_reg_parsed(void *parsed_result,
2779                     __attribute__((unused)) struct cmdline *cl,
2780                     __attribute__((unused)) void *data)
2781 {
2782         struct cmd_read_reg_result *res = parsed_result;
2783         port_reg_display(res->port_id, res->reg_off);
2784 }
2785
2786 cmdline_parse_token_string_t cmd_read_reg_read =
2787         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
2788 cmdline_parse_token_string_t cmd_read_reg_reg =
2789         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
2790 cmdline_parse_token_num_t cmd_read_reg_port_id =
2791         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
2792 cmdline_parse_token_num_t cmd_read_reg_reg_off =
2793         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
2794
2795 cmdline_parse_inst_t cmd_read_reg = {
2796         .f = cmd_read_reg_parsed,
2797         .data = NULL,
2798         .help_str = "read reg port_id reg_off",
2799         .tokens = {
2800                 (void *)&cmd_read_reg_read,
2801                 (void *)&cmd_read_reg_reg,
2802                 (void *)&cmd_read_reg_port_id,
2803                 (void *)&cmd_read_reg_reg_off,
2804                 NULL,
2805         },
2806 };
2807
2808 /* *** READ PORT REGISTER BIT FIELD *** */
2809 struct cmd_read_reg_bit_field_result {
2810         cmdline_fixed_string_t read;
2811         cmdline_fixed_string_t regfield;
2812         uint8_t port_id;
2813         uint32_t reg_off;
2814         uint8_t bit1_pos;
2815         uint8_t bit2_pos;
2816 };
2817
2818 static void
2819 cmd_read_reg_bit_field_parsed(void *parsed_result,
2820                               __attribute__((unused)) struct cmdline *cl,
2821                               __attribute__((unused)) void *data)
2822 {
2823         struct cmd_read_reg_bit_field_result *res = parsed_result;
2824         port_reg_bit_field_display(res->port_id, res->reg_off,
2825                                    res->bit1_pos, res->bit2_pos);
2826 }
2827
2828 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
2829         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
2830                                  "read");
2831 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
2832         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
2833                                  regfield, "regfield");
2834 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
2835         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
2836                               UINT8);
2837 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
2838         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
2839                               UINT32);
2840 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
2841         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
2842                               UINT8);
2843 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
2844         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
2845                               UINT8);
2846
2847 cmdline_parse_inst_t cmd_read_reg_bit_field = {
2848         .f = cmd_read_reg_bit_field_parsed,
2849         .data = NULL,
2850         .help_str = "read regfield port_id reg_off bit_x bit_y "
2851         "(read register bit field between bit_x and bit_y included)",
2852         .tokens = {
2853                 (void *)&cmd_read_reg_bit_field_read,
2854                 (void *)&cmd_read_reg_bit_field_regfield,
2855                 (void *)&cmd_read_reg_bit_field_port_id,
2856                 (void *)&cmd_read_reg_bit_field_reg_off,
2857                 (void *)&cmd_read_reg_bit_field_bit1_pos,
2858                 (void *)&cmd_read_reg_bit_field_bit2_pos,
2859                 NULL,
2860         },
2861 };
2862
2863 /* *** READ PORT REGISTER BIT *** */
2864 struct cmd_read_reg_bit_result {
2865         cmdline_fixed_string_t read;
2866         cmdline_fixed_string_t regbit;
2867         uint8_t port_id;
2868         uint32_t reg_off;
2869         uint8_t bit_pos;
2870 };
2871
2872 static void
2873 cmd_read_reg_bit_parsed(void *parsed_result,
2874                         __attribute__((unused)) struct cmdline *cl,
2875                         __attribute__((unused)) void *data)
2876 {
2877         struct cmd_read_reg_bit_result *res = parsed_result;
2878         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
2879 }
2880
2881 cmdline_parse_token_string_t cmd_read_reg_bit_read =
2882         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
2883 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
2884         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
2885                                  regbit, "regbit");
2886 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
2887         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
2888 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
2889         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
2890 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
2891         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
2892
2893 cmdline_parse_inst_t cmd_read_reg_bit = {
2894         .f = cmd_read_reg_bit_parsed,
2895         .data = NULL,
2896         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
2897         .tokens = {
2898                 (void *)&cmd_read_reg_bit_read,
2899                 (void *)&cmd_read_reg_bit_regbit,
2900                 (void *)&cmd_read_reg_bit_port_id,
2901                 (void *)&cmd_read_reg_bit_reg_off,
2902                 (void *)&cmd_read_reg_bit_bit_pos,
2903                 NULL,
2904         },
2905 };
2906
2907 /* *** WRITE PORT REGISTER *** */
2908 struct cmd_write_reg_result {
2909         cmdline_fixed_string_t write;
2910         cmdline_fixed_string_t reg;
2911         uint8_t port_id;
2912         uint32_t reg_off;
2913         uint32_t value;
2914 };
2915
2916 static void
2917 cmd_write_reg_parsed(void *parsed_result,
2918                      __attribute__((unused)) struct cmdline *cl,
2919                      __attribute__((unused)) void *data)
2920 {
2921         struct cmd_write_reg_result *res = parsed_result;
2922         port_reg_set(res->port_id, res->reg_off, res->value);
2923 }
2924
2925 cmdline_parse_token_string_t cmd_write_reg_write =
2926         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
2927 cmdline_parse_token_string_t cmd_write_reg_reg =
2928         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
2929 cmdline_parse_token_num_t cmd_write_reg_port_id =
2930         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
2931 cmdline_parse_token_num_t cmd_write_reg_reg_off =
2932         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
2933 cmdline_parse_token_num_t cmd_write_reg_value =
2934         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
2935
2936 cmdline_parse_inst_t cmd_write_reg = {
2937         .f = cmd_write_reg_parsed,
2938         .data = NULL,
2939         .help_str = "write reg port_id reg_off reg_value",
2940         .tokens = {
2941                 (void *)&cmd_write_reg_write,
2942                 (void *)&cmd_write_reg_reg,
2943                 (void *)&cmd_write_reg_port_id,
2944                 (void *)&cmd_write_reg_reg_off,
2945                 (void *)&cmd_write_reg_value,
2946                 NULL,
2947         },
2948 };
2949
2950 /* *** WRITE PORT REGISTER BIT FIELD *** */
2951 struct cmd_write_reg_bit_field_result {
2952         cmdline_fixed_string_t write;
2953         cmdline_fixed_string_t regfield;
2954         uint8_t port_id;
2955         uint32_t reg_off;
2956         uint8_t bit1_pos;
2957         uint8_t bit2_pos;
2958         uint32_t value;
2959 };
2960
2961 static void
2962 cmd_write_reg_bit_field_parsed(void *parsed_result,
2963                                __attribute__((unused)) struct cmdline *cl,
2964                                __attribute__((unused)) void *data)
2965 {
2966         struct cmd_write_reg_bit_field_result *res = parsed_result;
2967         port_reg_bit_field_set(res->port_id, res->reg_off,
2968                           res->bit1_pos, res->bit2_pos, res->value);
2969 }
2970
2971 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
2972         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
2973                                  "write");
2974 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
2975         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
2976                                  regfield, "regfield");
2977 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
2978         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
2979                               UINT8);
2980 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
2981         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
2982                               UINT32);
2983 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
2984         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
2985                               UINT8);
2986 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
2987         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
2988                               UINT8);
2989 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
2990         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
2991                               UINT32);
2992
2993 cmdline_parse_inst_t cmd_write_reg_bit_field = {
2994         .f = cmd_write_reg_bit_field_parsed,
2995         .data = NULL,
2996         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
2997         "(set register bit field between bit_x and bit_y included)",
2998         .tokens = {
2999                 (void *)&cmd_write_reg_bit_field_write,
3000                 (void *)&cmd_write_reg_bit_field_regfield,
3001                 (void *)&cmd_write_reg_bit_field_port_id,
3002                 (void *)&cmd_write_reg_bit_field_reg_off,
3003                 (void *)&cmd_write_reg_bit_field_bit1_pos,
3004                 (void *)&cmd_write_reg_bit_field_bit2_pos,
3005                 (void *)&cmd_write_reg_bit_field_value,
3006                 NULL,
3007         },
3008 };
3009
3010 /* *** WRITE PORT REGISTER BIT *** */
3011 struct cmd_write_reg_bit_result {
3012         cmdline_fixed_string_t write;
3013         cmdline_fixed_string_t regbit;
3014         uint8_t port_id;
3015         uint32_t reg_off;
3016         uint8_t bit_pos;
3017         uint8_t value;
3018 };
3019
3020 static void
3021 cmd_write_reg_bit_parsed(void *parsed_result,
3022                          __attribute__((unused)) struct cmdline *cl,
3023                          __attribute__((unused)) void *data)
3024 {
3025         struct cmd_write_reg_bit_result *res = parsed_result;
3026         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
3027 }
3028
3029 cmdline_parse_token_string_t cmd_write_reg_bit_write =
3030         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
3031                                  "write");
3032 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
3033         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
3034                                  regbit, "regbit");
3035 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
3036         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
3037 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
3038         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
3039 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
3040         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
3041 cmdline_parse_token_num_t cmd_write_reg_bit_value =
3042         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
3043
3044 cmdline_parse_inst_t cmd_write_reg_bit = {
3045         .f = cmd_write_reg_bit_parsed,
3046         .data = NULL,
3047         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
3048         .tokens = {
3049                 (void *)&cmd_write_reg_bit_write,
3050                 (void *)&cmd_write_reg_bit_regbit,
3051                 (void *)&cmd_write_reg_bit_port_id,
3052                 (void *)&cmd_write_reg_bit_reg_off,
3053                 (void *)&cmd_write_reg_bit_bit_pos,
3054                 (void *)&cmd_write_reg_bit_value,
3055                 NULL,
3056         },
3057 };
3058
3059 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
3060 struct cmd_read_rxd_txd_result {
3061         cmdline_fixed_string_t read;
3062         cmdline_fixed_string_t rxd_txd;
3063         uint8_t port_id;
3064         uint16_t queue_id;
3065         uint16_t desc_id;
3066 };
3067
3068 static void
3069 cmd_read_rxd_txd_parsed(void *parsed_result,
3070                         __attribute__((unused)) struct cmdline *cl,
3071                         __attribute__((unused)) void *data)
3072 {
3073         struct cmd_read_rxd_txd_result *res = parsed_result;
3074
3075         if (!strcmp(res->rxd_txd, "rxd"))
3076                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
3077         else if (!strcmp(res->rxd_txd, "txd"))
3078                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
3079 }
3080
3081 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
3082         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
3083 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
3084         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
3085                                  "rxd#txd");
3086 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
3087         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
3088 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
3089         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
3090 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
3091         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
3092
3093 cmdline_parse_inst_t cmd_read_rxd_txd = {
3094         .f = cmd_read_rxd_txd_parsed,
3095         .data = NULL,
3096         .help_str = "read rxd|txd port_id queue_id rxd_id",
3097         .tokens = {
3098                 (void *)&cmd_read_rxd_txd_read,
3099                 (void *)&cmd_read_rxd_txd_rxd_txd,
3100                 (void *)&cmd_read_rxd_txd_port_id,
3101                 (void *)&cmd_read_rxd_txd_queue_id,
3102                 (void *)&cmd_read_rxd_txd_desc_id,
3103                 NULL,
3104         },
3105 };
3106
3107 /* *** QUIT *** */
3108 struct cmd_quit_result {
3109         cmdline_fixed_string_t quit;
3110 };
3111
3112 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
3113                             struct cmdline *cl,
3114                             __attribute__((unused)) void *data)
3115 {
3116         pmd_test_exit();
3117         cmdline_quit(cl);
3118 }
3119
3120 cmdline_parse_token_string_t cmd_quit_quit =
3121         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
3122
3123 cmdline_parse_inst_t cmd_quit = {
3124         .f = cmd_quit_parsed,
3125         .data = NULL,
3126         .help_str = "exit application",
3127         .tokens = {
3128                 (void *)&cmd_quit_quit,
3129                 NULL,
3130         },
3131 };
3132
3133 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
3134 struct cmd_mac_addr_result {
3135         cmdline_fixed_string_t mac_addr_cmd;
3136         cmdline_fixed_string_t what;
3137         uint8_t port_num;
3138         struct ether_addr address;
3139 };
3140
3141 static void cmd_mac_addr_parsed(void *parsed_result,
3142                 __attribute__((unused)) struct cmdline *cl,
3143                 __attribute__((unused)) void *data)
3144 {
3145         struct cmd_mac_addr_result *res = parsed_result;
3146         int ret;
3147
3148         if (strcmp(res->what, "add") == 0)
3149                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
3150         else
3151                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
3152
3153         /* check the return value and print it if is < 0 */
3154         if(ret < 0)
3155                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
3156
3157 }
3158
3159 cmdline_parse_token_string_t cmd_mac_addr_cmd =
3160         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
3161                                 "mac_addr");
3162 cmdline_parse_token_string_t cmd_mac_addr_what =
3163         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
3164                                 "add#remove");
3165 cmdline_parse_token_num_t cmd_mac_addr_portnum =
3166                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
3167 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
3168                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
3169
3170 cmdline_parse_inst_t cmd_mac_addr = {
3171         .f = cmd_mac_addr_parsed,
3172         .data = (void *)0,
3173         .help_str = "mac_addr add|remove X <address>: "
3174                         "add/remove MAC address on port X",
3175         .tokens = {
3176                 (void *)&cmd_mac_addr_cmd,
3177                 (void *)&cmd_mac_addr_what,
3178                 (void *)&cmd_mac_addr_portnum,
3179                 (void *)&cmd_mac_addr_addr,
3180                 NULL,
3181         },
3182 };
3183
3184
3185 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
3186 struct cmd_set_qmap_result {
3187         cmdline_fixed_string_t set;
3188         cmdline_fixed_string_t qmap;
3189         cmdline_fixed_string_t what;
3190         uint8_t port_id;
3191         uint16_t queue_id;
3192         uint8_t map_value;
3193 };
3194
3195 static void
3196 cmd_set_qmap_parsed(void *parsed_result,
3197                        __attribute__((unused)) struct cmdline *cl,
3198                        __attribute__((unused)) void *data)
3199 {
3200         struct cmd_set_qmap_result *res = parsed_result;
3201         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
3202
3203         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
3204 }
3205
3206 cmdline_parse_token_string_t cmd_setqmap_set =
3207         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
3208                                  set, "set");
3209 cmdline_parse_token_string_t cmd_setqmap_qmap =
3210         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
3211                                  qmap, "stat_qmap");
3212 cmdline_parse_token_string_t cmd_setqmap_what =
3213         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
3214                                  what, "tx#rx");
3215 cmdline_parse_token_num_t cmd_setqmap_portid =
3216         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
3217                               port_id, UINT8);
3218 cmdline_parse_token_num_t cmd_setqmap_queueid =
3219         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
3220                               queue_id, UINT16);
3221 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
3222         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
3223                               map_value, UINT8);
3224
3225 cmdline_parse_inst_t cmd_set_qmap = {
3226         .f = cmd_set_qmap_parsed,
3227         .data = NULL,
3228         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
3229         .tokens = {
3230                 (void *)&cmd_setqmap_set,
3231                 (void *)&cmd_setqmap_qmap,
3232                 (void *)&cmd_setqmap_what,
3233                 (void *)&cmd_setqmap_portid,
3234                 (void *)&cmd_setqmap_queueid,
3235                 (void *)&cmd_setqmap_mapvalue,
3236                 NULL,
3237         },
3238 };
3239
3240 /* ******************************************************************************** */
3241
3242 /* list of instructions */
3243 cmdline_parse_ctx_t main_ctx[] = {
3244         (cmdline_parse_inst_t *)&cmd_help,
3245         (cmdline_parse_inst_t *)&cmd_quit,
3246         (cmdline_parse_inst_t *)&cmd_showport,
3247         (cmdline_parse_inst_t *)&cmd_showportall,
3248         (cmdline_parse_inst_t *)&cmd_showcfg,
3249         (cmdline_parse_inst_t *)&cmd_start,
3250         (cmdline_parse_inst_t *)&cmd_start_tx_first,
3251         (cmdline_parse_inst_t *)&cmd_reset,
3252         (cmdline_parse_inst_t *)&cmd_set_numbers,
3253         (cmdline_parse_inst_t *)&cmd_set_txpkts,
3254         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
3255         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
3256         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
3257         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
3258         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
3259         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
3260         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
3261         (cmdline_parse_inst_t *)&cmd_vlan_offload,
3262         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
3263         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
3264         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
3265         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
3266         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
3267         (cmdline_parse_inst_t *)&cmd_tx_cksum_set,
3268         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
3269         (cmdline_parse_inst_t *)&cmd_read_reg,
3270         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
3271         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
3272         (cmdline_parse_inst_t *)&cmd_write_reg,
3273         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
3274         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
3275         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
3276         (cmdline_parse_inst_t *)&cmd_add_signature_filter,
3277         (cmdline_parse_inst_t *)&cmd_upd_signature_filter,
3278         (cmdline_parse_inst_t *)&cmd_rm_signature_filter,
3279         (cmdline_parse_inst_t *)&cmd_add_perfect_filter,
3280         (cmdline_parse_inst_t *)&cmd_upd_perfect_filter,
3281         (cmdline_parse_inst_t *)&cmd_rm_perfect_filter,
3282         (cmdline_parse_inst_t *)&cmd_set_masks_filter,
3283         (cmdline_parse_inst_t *)&cmd_set_ipv6_masks_filter,
3284         (cmdline_parse_inst_t *)&cmd_stop,
3285         (cmdline_parse_inst_t *)&cmd_mac_addr,
3286         (cmdline_parse_inst_t *)&cmd_set_qmap,
3287         (cmdline_parse_inst_t *)&cmd_operate_port,
3288         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
3289         (cmdline_parse_inst_t *)&cmd_config_speed_all,
3290         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
3291         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
3292         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
3293         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
3294         (cmdline_parse_inst_t *)&cmd_config_rss,
3295         (cmdline_parse_inst_t *)&cmd_config_burst,
3296         (cmdline_parse_inst_t *)&cmd_config_thresh,
3297         (cmdline_parse_inst_t *)&cmd_config_threshold,
3298         NULL,
3299 };
3300
3301 /* prompt function, called from main on MASTER lcore */
3302 void
3303 prompt(void)
3304 {
3305         struct cmdline *cl;
3306
3307         cl = cmdline_stdin_new(main_ctx, "testpmd> ");
3308         if (cl == NULL) {
3309                 return;
3310         }
3311         cmdline_interact(cl);
3312         cmdline_stdin_exit(cl);
3313 }
3314
3315 static void
3316 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
3317 {
3318         if (id < nb_ports) {
3319                 /* check if need_reconfig has been set to 1 */
3320                 if (ports[id].need_reconfig == 0)
3321                         ports[id].need_reconfig = dev;
3322                 /* check if need_reconfig_queues has been set to 1 */
3323                 if (ports[id].need_reconfig_queues == 0)
3324                         ports[id].need_reconfig_queues = queue;
3325         } else {
3326                 portid_t pid;
3327
3328                 for (pid = 0; pid < nb_ports; pid++) {
3329                         /* check if need_reconfig has been set to 1 */
3330                         if (ports[pid].need_reconfig == 0)
3331                                 ports[pid].need_reconfig = dev;
3332                         /* check if need_reconfig_queues has been set to 1 */
3333                         if (ports[pid].need_reconfig_queues == 0)
3334                                 ports[pid].need_reconfig_queues = queue;
3335                 }
3336         }
3337 }