4 * Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
45 #include <net/socket.h>
47 #include <netinet/in.h>
49 #include <sys/queue.h>
51 #include <rte_common.h>
52 #include <rte_byteorder.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>
61 #include <rte_per_lcore.h>
62 #include <rte_lcore.h>
63 #include <rte_atomic.h>
64 #include <rte_branch_prediction.h>
66 #include <rte_mempool.h>
67 #include <rte_interrupts.h>
69 #include <rte_ether.h>
70 #include <rte_ethdev.h>
71 #include <rte_string_fns.h>
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>
85 struct cmd_help_result {
86 cmdline_fixed_string_t help;
89 static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
91 __attribute__((unused)) void *data)
98 "This commandline can be used to configure forwarding\n"
101 "Display informations:\n"
102 "---------------------\n"
103 "- show port info|stats|fdir|stat_qmap X|all\n"
104 " Diplays information or stats or stats queue mapping on port X, or all\n"
105 "- clear port stats X|all\n"
106 " Clear stats for port X, or all\n"
107 "- show config rxtx|cores|fwd\n"
108 " Displays the given configuration\n"
109 "- read reg port_id reg_off\n"
110 " Displays value of a port register\n"
111 "- read regfield port_id reg_off bit_x bit_y\n"
112 " Displays value of a port register bit field\n"
113 "- read regbit port_id reg_off bit_x\n"
114 " Displays value of a port register bit\n"
115 "- read rxd port_id queue_id rxd_id\n"
116 " Displays a RX descriptor of a port RX queue\n"
117 "- read txd port_id queue_id txd_id\n"
118 " Displays a TX descriptor of a port TX queue\n"
123 "Modifications are taken into account once "
124 "forwarding is restarted.\n"
126 " Set forwarding to default configuration\n"
127 "- set nbport|nbcore|burst|verbose X\n"
128 " Set number of ports, number of cores, number "
129 "of packets per burst,\n or verbose level to X\n"
130 "- set txpkts x[,y]*\n"
131 " Set the length of each segment of TXONLY packets\n"
132 "- set coremask|portmask X\n"
133 " Set the hexadecimal mask of forwarding cores / "
135 "- set corelist|portlist x[,y]*\n"
136 " Set the list of forwarding cores / forwarding "
138 "- vlan set strip|filter|qinq on/off port_id\n"
139 " Set the VLAN strip, filter, QinQ(extended) on a port"
140 "- rx_vlan add/rm vlan_id|all port_id\n"
141 " Set the VLAN filter table, add/remove vlan_id, or all "
142 "identifiers, to/from the set of VLAN Identifiers\n"
143 "filtered by port_id\n"
144 "- rx_vlan set tpid value port_id\n"
145 " Set Outer VLAN TPID for Packet Filtering on a port \n"
146 "- tx_vlan set vlan_id port_id\n"
147 " Set hardware insertion of VLAN ID in packets sent on a port\n"
148 "- tx_vlan reset port_id\n"
149 " Disable hardware insertion of a VLAN header in "
150 "packets sent on port_id\n"
151 "- tx_checksum set mask port_id\n"
152 " Enable hardware insertion of checksum offload with "
153 "the 4-bit mask (0~0xf)\n in packets sent on port_id\n"
154 " Please check the NIC datasheet for HW limits\n"
155 " bit 0 - insert ip checksum offload if set \n"
156 " bit 1 - insert udp checksum offload if set \n"
157 " bit 2 - insert tcp checksum offload if set\n"
158 " bit 3 - insert sctp checksum offload if set\n"
159 #ifdef RTE_LIBRTE_IEEE1588
160 "- set fwd io|mac|rxonly|txonly|csum|ieee1588\n"
161 " Set IO, MAC, RXONLY, TXONLY, CSUM or IEEE1588 "
162 "packet forwarding mode\n"
164 "- set fwd io|mac|rxonly|txonly|csum\n"
165 " Set IO, MAC, RXONLY, CSUM or TXONLY packet "
168 "- mac_addr add|remove X <xx:xx:xx:xx:xx:xx>\n"
169 " Add/Remove the MAC address <xx:xx:xx:xx:xx:xx> on port X\n"
170 "- set promisc|allmulti [all|X] on|off\n"
171 " Set/unset promisc|allmulti mode on port X, or all\n"
172 "- set flow_ctrl rx on|off tx on|off high_water low_water "
173 "pause_time send_xon port_id \n"
174 " Set the link flow control parameter on the port \n"
175 "- write reg port_id reg_off value\n"
176 " Set value of a port register\n"
177 "- write regfield port_id reg_off bit_x bit_y value\n"
178 " Set bit field value of a port register\n"
179 "- write regbit port_id reg_off bit_x value\n"
180 " Set bit value of a port register\n"
181 "- set stat_qmap tx|rx port_id queue_id qmapping\n"
182 " Set statistics mapping (qmapping 0..15) for tx|rx queue_id on port_id\n"
183 " e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2 on port 0 to mapping 5\n"
186 "Control forwarding:\n"
187 "-------------------\n"
189 " Start packet forwarding with current config\n"
191 " Start packet forwarding with current config"
192 " after sending one burst\n of packets\n"
194 " Stop packet forwarding, and displays accumulated"
198 "Flow director mode:\n"
199 "-------------------\n"
200 "- add_signature_filter port_id ip|udp|tcp|sctp src\n"
201 " ip_src_address port_src dst ip_dst_address port_dst\n"
202 " flexbytes flexbytes_values vlan vlan_id queue queue_id\n"
203 "- upd_signature_filter port_id ip|udp|tcp|sctp src \n"
204 " ip_src_address port_src dst ip_dst_address port_dst\n"
205 " flexbytes flexbytes_values vlan vlan_id queue queue_id\n"
206 "- rm_signature_filter port_id ip|udp|tcp|sctp src\n"
207 " ip_src_address port_src dst ip_dst_address port_dst\n"
208 " flexbytes flexbytes_values vlan vlan_id\n"
209 "- add_perfect_filter port_id ip|udp|tcp|sctp src\n"
210 " ip_src_address port_src dst ip_dst_address port_dst\n"
211 " flexbytes flexbytes_values vlan vlan_id queue \n"
212 " queue_id soft soft_id\n"
213 "- upd_perfect_filter port_id ip|udp|tcp|sctp src\n"
214 " ip_src_address port_src dst ip_dst_address port_dst\n"
215 " flexbytes flexbytes_values vlan vlan_id queue queue_id\n"
216 "- rm_perfect_filter port_id ip|udp|tcp|sctp src\n"
217 " ip_src_address port_src dst ip_dst_address port_dst\n"
218 " flexbytes flexbytes_values vlan vlan_id soft soft_id\n"
219 "- set_masks_filter port_id only_ip_flow 0|1 src_mask\n"
220 " ip_src_mask port_src_mask dst_mask ip_dst_mask\n"
221 " port_dst_mask flexbytes 0|1 vlan_id 0|1 vlan_prio 0|1\n"
227 " Quit to prompt in linux, and reboot on baremetal\n"
231 cmdline_parse_token_string_t cmd_help_help =
232 TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");
234 cmdline_parse_inst_t cmd_help = {
235 .f = cmd_help_parsed,
237 .help_str = "show help",
239 (void *)&cmd_help_help,
245 struct cmd_stop_result {
246 cmdline_fixed_string_t stop;
249 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
250 __attribute__((unused)) struct cmdline *cl,
251 __attribute__((unused)) void *data)
253 stop_packet_forwarding();
256 cmdline_parse_token_string_t cmd_stop_stop =
257 TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
259 cmdline_parse_inst_t cmd_stop = {
260 .f = cmd_stop_parsed,
262 .help_str = "stop - stop packet forwarding",
264 (void *)&cmd_stop_stop,
269 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
272 parse_item_list(char* str, const char* item_name, unsigned int max_items,
273 unsigned int *parsed_items, int check_unique_values)
275 unsigned int nb_item;
283 * First parse all items in the list and store their value.
288 for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
290 if ((c >= '0') && (c <= '9')) {
291 value = (unsigned int) (value * 10 + (c - '0'));
296 printf("character %c is not a decimal digit\n", c);
300 printf("No valid value before comma\n");
303 if (nb_item < max_items) {
304 parsed_items[nb_item] = value;
310 if (nb_item >= max_items) {
311 printf("Number of %s = %u > %u (maximum items)\n",
312 item_name, nb_item + 1, max_items);
315 parsed_items[nb_item++] = value;
316 if (! check_unique_values)
320 * Then, check that all values in the list are differents.
321 * No optimization here...
323 for (i = 0; i < nb_item; i++) {
324 for (j = i + 1; j < nb_item; j++) {
325 if (parsed_items[j] == parsed_items[i]) {
326 printf("duplicated %s %u at index %u and %u\n",
327 item_name, parsed_items[i], i, j);
335 struct cmd_set_list_result {
336 cmdline_fixed_string_t cmd_keyword;
337 cmdline_fixed_string_t list_name;
338 cmdline_fixed_string_t list_of_items;
341 static void cmd_set_list_parsed(void *parsed_result,
342 __attribute__((unused)) struct cmdline *cl,
343 __attribute__((unused)) void *data)
345 struct cmd_set_list_result *res;
347 unsigned int lcorelist[RTE_MAX_LCORE];
348 unsigned int portlist[RTE_MAX_ETHPORTS];
350 unsigned int nb_item;
353 if (!strcmp(res->list_name, "corelist")) {
354 nb_item = parse_item_list(res->list_of_items, "core",
356 parsed_items.lcorelist, 1);
358 set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
361 if (!strcmp(res->list_name, "portlist")) {
362 nb_item = parse_item_list(res->list_of_items, "port",
364 parsed_items.portlist, 1);
366 set_fwd_ports_list(parsed_items.portlist, nb_item);
370 cmdline_parse_token_string_t cmd_set_list_keyword =
371 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
373 cmdline_parse_token_string_t cmd_set_list_name =
374 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
375 "corelist#portlist");
376 cmdline_parse_token_string_t cmd_set_list_of_items =
377 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
380 cmdline_parse_inst_t cmd_set_fwd_list = {
381 .f = cmd_set_list_parsed,
383 .help_str = "set corelist|portlist x[,y]*",
385 (void *)&cmd_set_list_keyword,
386 (void *)&cmd_set_list_name,
387 (void *)&cmd_set_list_of_items,
392 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
394 struct cmd_setmask_result {
395 cmdline_fixed_string_t set;
396 cmdline_fixed_string_t mask;
400 static void cmd_set_mask_parsed(void *parsed_result,
401 __attribute__((unused)) struct cmdline *cl,
402 __attribute__((unused)) void *data)
404 struct cmd_setmask_result *res = parsed_result;
406 if (!strcmp(res->mask, "coremask"))
407 set_fwd_lcores_mask(res->hexavalue);
408 else if (!strcmp(res->mask, "portmask"))
409 set_fwd_ports_mask(res->hexavalue);
412 cmdline_parse_token_string_t cmd_setmask_set =
413 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
414 cmdline_parse_token_string_t cmd_setmask_mask =
415 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
416 "coremask#portmask");
417 cmdline_parse_token_num_t cmd_setmask_value =
418 TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
420 cmdline_parse_inst_t cmd_set_fwd_mask = {
421 .f = cmd_set_mask_parsed,
423 .help_str = "set coremask|portmask hexadecimal value",
425 (void *)&cmd_setmask_set,
426 (void *)&cmd_setmask_mask,
427 (void *)&cmd_setmask_value,
433 * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
435 struct cmd_set_result {
436 cmdline_fixed_string_t set;
437 cmdline_fixed_string_t what;
441 static void cmd_set_parsed(void *parsed_result,
442 __attribute__((unused)) struct cmdline *cl,
443 __attribute__((unused)) void *data)
445 struct cmd_set_result *res = parsed_result;
446 if (!strcmp(res->what, "nbport"))
447 set_fwd_ports_number(res->value);
448 else if (!strcmp(res->what, "nbcore"))
449 set_fwd_lcores_number(res->value);
450 else if (!strcmp(res->what, "burst"))
451 set_nb_pkt_per_burst(res->value);
452 else if (!strcmp(res->what, "verbose"))
453 set_verbose_level(res->value);
456 cmdline_parse_token_string_t cmd_set_set =
457 TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
458 cmdline_parse_token_string_t cmd_set_what =
459 TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
460 "nbport#nbcore#burst#verbose");
461 cmdline_parse_token_num_t cmd_set_value =
462 TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
464 cmdline_parse_inst_t cmd_set_numbers = {
467 .help_str = "set nbport|nbcore|burst|verbose value",
469 (void *)&cmd_set_set,
470 (void *)&cmd_set_what,
471 (void *)&cmd_set_value,
476 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
478 struct cmd_set_txpkts_result {
479 cmdline_fixed_string_t cmd_keyword;
480 cmdline_fixed_string_t txpkts;
481 cmdline_fixed_string_t seg_lengths;
485 cmd_set_txpkts_parsed(void *parsed_result,
486 __attribute__((unused)) struct cmdline *cl,
487 __attribute__((unused)) void *data)
489 struct cmd_set_txpkts_result *res;
490 unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
491 unsigned int nb_segs;
494 nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
495 RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
497 set_tx_pkt_segments(seg_lengths, nb_segs);
500 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
501 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
503 cmdline_parse_token_string_t cmd_set_txpkts_name =
504 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
506 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
507 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
510 cmdline_parse_inst_t cmd_set_txpkts = {
511 .f = cmd_set_txpkts_parsed,
513 .help_str = "set txpkts x[,y]*",
515 (void *)&cmd_set_txpkts_keyword,
516 (void *)&cmd_set_txpkts_name,
517 (void *)&cmd_set_txpkts_lengths,
522 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
523 struct cmd_rx_vlan_filter_all_result {
524 cmdline_fixed_string_t rx_vlan;
525 cmdline_fixed_string_t what;
526 cmdline_fixed_string_t all;
531 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
532 __attribute__((unused)) struct cmdline *cl,
533 __attribute__((unused)) void *data)
535 struct cmd_rx_vlan_filter_all_result *res = parsed_result;
537 if (!strcmp(res->what, "add"))
538 rx_vlan_all_filter_set(res->port_id, 1);
540 rx_vlan_all_filter_set(res->port_id, 0);
543 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
544 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
546 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
547 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
549 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
550 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
552 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
553 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
556 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
557 .f = cmd_rx_vlan_filter_all_parsed,
559 .help_str = "add/remove all identifiers to/from the set of VLAN "
560 "Identifiers filtered by a port",
562 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
563 (void *)&cmd_rx_vlan_filter_all_what,
564 (void *)&cmd_rx_vlan_filter_all_all,
565 (void *)&cmd_rx_vlan_filter_all_portid,
570 /* *** VLAN OFFLOAD SET ON A PORT *** */
571 struct cmd_vlan_offload_result {
572 cmdline_fixed_string_t vlan;
573 cmdline_fixed_string_t set;
574 cmdline_fixed_string_t what;
575 cmdline_fixed_string_t on;
576 cmdline_fixed_string_t port_id;
580 cmd_vlan_offload_parsed(void *parsed_result,
581 __attribute__((unused)) struct cmdline *cl,
582 __attribute__((unused)) void *data)
585 struct cmd_vlan_offload_result *res = parsed_result;
588 portid_t port_id = 0;
592 len = strnlen(str, STR_TOKEN_SIZE);
594 /* Get port_id first */
602 tmp = strtoul(str, NULL, 0);
603 /* If port_id greater that what portid_t can represent, return */
606 port_id = (portid_t)tmp;
608 if (!strcmp(res->on, "on"))
613 if (!strcmp(res->what, "strip"))
614 rx_vlan_strip_set(port_id, on);
615 else if(!strcmp(res->what, "stripq")){
616 uint16_t queue_id = 0;
618 /* No queue_id, return */
621 tmp = strtoul(str + i + 1, NULL, 0);
622 /* If queue_id greater that what 16-bits can represent, return */
626 queue_id = (uint16_t)tmp;
627 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
629 else if (!strcmp(res->what, "filter"))
630 rx_vlan_filter_set(port_id, on);
632 vlan_extend_set(port_id, on);
637 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
638 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
640 cmdline_parse_token_string_t cmd_vlan_offload_set =
641 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
643 cmdline_parse_token_string_t cmd_vlan_offload_what =
644 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
645 what, "strip#filter#qinq#stripq");
646 cmdline_parse_token_string_t cmd_vlan_offload_on =
647 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
649 cmdline_parse_token_string_t cmd_vlan_offload_portid =
650 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
653 cmdline_parse_inst_t cmd_vlan_offload = {
654 .f = cmd_vlan_offload_parsed,
656 .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side"
657 " qinq(extended) for both rx/tx sides ",
659 (void *)&cmd_vlan_offload_vlan,
660 (void *)&cmd_vlan_offload_set,
661 (void *)&cmd_vlan_offload_what,
662 (void *)&cmd_vlan_offload_on,
663 (void *)&cmd_vlan_offload_portid,
668 /* *** VLAN TPID SET ON A PORT *** */
669 struct cmd_vlan_tpid_result {
670 cmdline_fixed_string_t vlan;
671 cmdline_fixed_string_t set;
672 cmdline_fixed_string_t what;
678 cmd_vlan_tpid_parsed(void *parsed_result,
679 __attribute__((unused)) struct cmdline *cl,
680 __attribute__((unused)) void *data)
682 struct cmd_vlan_tpid_result *res = parsed_result;
683 vlan_tpid_set(res->port_id, res->tp_id);
687 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
688 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
690 cmdline_parse_token_string_t cmd_vlan_tpid_set =
691 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
693 cmdline_parse_token_string_t cmd_vlan_tpid_what =
694 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
696 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
697 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
699 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
700 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
703 cmdline_parse_inst_t cmd_vlan_tpid = {
704 .f = cmd_vlan_tpid_parsed,
706 .help_str = "set tpid tp_id port_id, set the Outer VLAN Ether type",
708 (void *)&cmd_vlan_tpid_vlan,
709 (void *)&cmd_vlan_tpid_set,
710 (void *)&cmd_vlan_tpid_what,
711 (void *)&cmd_vlan_tpid_tpid,
712 (void *)&cmd_vlan_tpid_portid,
717 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
718 struct cmd_rx_vlan_filter_result {
719 cmdline_fixed_string_t rx_vlan;
720 cmdline_fixed_string_t what;
726 cmd_rx_vlan_filter_parsed(void *parsed_result,
727 __attribute__((unused)) struct cmdline *cl,
728 __attribute__((unused)) void *data)
730 struct cmd_rx_vlan_filter_result *res = parsed_result;
732 if (!strcmp(res->what, "add"))
733 rx_vft_set(res->port_id, res->vlan_id, 1);
735 rx_vft_set(res->port_id, res->vlan_id, 0);
738 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
739 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
741 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
742 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
744 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
745 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
747 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
748 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
751 cmdline_parse_inst_t cmd_rx_vlan_filter = {
752 .f = cmd_rx_vlan_filter_parsed,
754 .help_str = "add/remove a VLAN identifier to/from the set of VLAN "
755 "Identifiers filtered by a port",
757 (void *)&cmd_rx_vlan_filter_rx_vlan,
758 (void *)&cmd_rx_vlan_filter_what,
759 (void *)&cmd_rx_vlan_filter_vlanid,
760 (void *)&cmd_rx_vlan_filter_portid,
765 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
766 struct cmd_tx_vlan_set_result {
767 cmdline_fixed_string_t tx_vlan;
768 cmdline_fixed_string_t set;
774 cmd_tx_vlan_set_parsed(void *parsed_result,
775 __attribute__((unused)) struct cmdline *cl,
776 __attribute__((unused)) void *data)
778 struct cmd_tx_vlan_set_result *res = parsed_result;
779 tx_vlan_set(res->port_id, res->vlan_id);
782 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
783 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
785 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
786 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
788 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
789 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
791 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
792 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
795 cmdline_parse_inst_t cmd_tx_vlan_set = {
796 .f = cmd_tx_vlan_set_parsed,
798 .help_str = "enable hardware insertion of a VLAN header with a given "
799 "TAG Identifier in packets sent on a port",
801 (void *)&cmd_tx_vlan_set_tx_vlan,
802 (void *)&cmd_tx_vlan_set_set,
803 (void *)&cmd_tx_vlan_set_vlanid,
804 (void *)&cmd_tx_vlan_set_portid,
809 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
810 struct cmd_tx_vlan_reset_result {
811 cmdline_fixed_string_t tx_vlan;
812 cmdline_fixed_string_t reset;
817 cmd_tx_vlan_reset_parsed(void *parsed_result,
818 __attribute__((unused)) struct cmdline *cl,
819 __attribute__((unused)) void *data)
821 struct cmd_tx_vlan_reset_result *res = parsed_result;
823 tx_vlan_reset(res->port_id);
826 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
827 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
829 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
830 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
832 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
833 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
836 cmdline_parse_inst_t cmd_tx_vlan_reset = {
837 .f = cmd_tx_vlan_reset_parsed,
839 .help_str = "disable hardware insertion of a VLAN header in packets "
842 (void *)&cmd_tx_vlan_reset_tx_vlan,
843 (void *)&cmd_tx_vlan_reset_reset,
844 (void *)&cmd_tx_vlan_reset_portid,
850 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
851 struct cmd_tx_cksum_set_result {
852 cmdline_fixed_string_t tx_cksum;
853 cmdline_fixed_string_t set;
859 cmd_tx_cksum_set_parsed(void *parsed_result,
860 __attribute__((unused)) struct cmdline *cl,
861 __attribute__((unused)) void *data)
863 struct cmd_tx_cksum_set_result *res = parsed_result;
865 tx_cksum_set(res->port_id, res->cksum_mask);
868 cmdline_parse_token_string_t cmd_tx_cksum_set_tx_cksum =
869 TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
870 tx_cksum, "tx_checksum");
871 cmdline_parse_token_string_t cmd_tx_cksum_set_set =
872 TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
874 cmdline_parse_token_num_t cmd_tx_cksum_set_cksum_mask =
875 TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
877 cmdline_parse_token_num_t cmd_tx_cksum_set_portid =
878 TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
881 cmdline_parse_inst_t cmd_tx_cksum_set = {
882 .f = cmd_tx_cksum_set_parsed,
884 .help_str = "enable hardware insertion of L3/L4checksum with a given "
885 "mask in packets sent on a port, the bit mapping is given as, Bit 0 for ip"
886 "Bit 1 for UDP, Bit 2 for TCP, Bit 3 for SCTP",
888 (void *)&cmd_tx_cksum_set_tx_cksum,
889 (void *)&cmd_tx_cksum_set_set,
890 (void *)&cmd_tx_cksum_set_cksum_mask,
891 (void *)&cmd_tx_cksum_set_portid,
896 /* *** SET FORWARDING MODE *** */
897 struct cmd_set_fwd_mode_result {
898 cmdline_fixed_string_t set;
899 cmdline_fixed_string_t fwd;
900 cmdline_fixed_string_t mode;
903 static void cmd_set_fwd_mode_parsed(void *parsed_result,
904 __attribute__((unused)) struct cmdline *cl,
905 __attribute__((unused)) void *data)
907 struct cmd_set_fwd_mode_result *res = parsed_result;
909 set_pkt_forwarding_mode(res->mode);
912 cmdline_parse_token_string_t cmd_setfwd_set =
913 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
914 cmdline_parse_token_string_t cmd_setfwd_fwd =
915 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
916 cmdline_parse_token_string_t cmd_setfwd_mode =
917 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
918 #ifdef RTE_LIBRTE_IEEE1588
919 "io#mac#rxonly#txonly#csum#ieee1588");
921 "io#mac#rxonly#txonly#csum");
924 cmdline_parse_inst_t cmd_set_fwd_mode = {
925 .f = cmd_set_fwd_mode_parsed,
927 #ifdef RTE_LIBRTE_IEEE1588
928 .help_str = "set fwd io|mac|rxonly|txonly|csum|ieee1588 - set IO, MAC,"
929 " RXONLY, TXONLY, CSUM or IEEE1588 packet forwarding mode",
931 .help_str = "set fwd io|mac|rxonly|txonly|csum - set IO, MAC,"
932 " RXONLY, CSUM or TXONLY packet forwarding mode",
935 (void *)&cmd_setfwd_set,
936 (void *)&cmd_setfwd_fwd,
937 (void *)&cmd_setfwd_mode,
942 /* *** SET PROMISC MODE *** */
943 struct cmd_set_promisc_mode_result {
944 cmdline_fixed_string_t set;
945 cmdline_fixed_string_t promisc;
946 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
947 uint8_t port_num; /* valid if "allports" argument == 0 */
948 cmdline_fixed_string_t mode;
951 static void cmd_set_promisc_mode_parsed(void *parsed_result,
952 __attribute__((unused)) struct cmdline *cl,
955 struct cmd_set_promisc_mode_result *res = parsed_result;
959 if (!strcmp(res->mode, "on"))
966 for (i = 0; i < nb_ports; i++) {
968 rte_eth_promiscuous_enable(i);
970 rte_eth_promiscuous_disable(i);
975 rte_eth_promiscuous_enable(res->port_num);
977 rte_eth_promiscuous_disable(res->port_num);
981 cmdline_parse_token_string_t cmd_setpromisc_set =
982 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
983 cmdline_parse_token_string_t cmd_setpromisc_promisc =
984 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
986 cmdline_parse_token_string_t cmd_setpromisc_portall =
987 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
989 cmdline_parse_token_num_t cmd_setpromisc_portnum =
990 TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
992 cmdline_parse_token_string_t cmd_setpromisc_mode =
993 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
996 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
997 .f = cmd_set_promisc_mode_parsed,
999 .help_str = "set promisc all on|off: set promisc mode for all ports",
1001 (void *)&cmd_setpromisc_set,
1002 (void *)&cmd_setpromisc_promisc,
1003 (void *)&cmd_setpromisc_portall,
1004 (void *)&cmd_setpromisc_mode,
1009 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
1010 .f = cmd_set_promisc_mode_parsed,
1012 .help_str = "set promisc X on|off: set promisc mode on port X",
1014 (void *)&cmd_setpromisc_set,
1015 (void *)&cmd_setpromisc_promisc,
1016 (void *)&cmd_setpromisc_portnum,
1017 (void *)&cmd_setpromisc_mode,
1022 /* *** SET ALLMULTI MODE *** */
1023 struct cmd_set_allmulti_mode_result {
1024 cmdline_fixed_string_t set;
1025 cmdline_fixed_string_t allmulti;
1026 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
1027 uint8_t port_num; /* valid if "allports" argument == 0 */
1028 cmdline_fixed_string_t mode;
1031 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
1032 __attribute__((unused)) struct cmdline *cl,
1035 struct cmd_set_allmulti_mode_result *res = parsed_result;
1039 if (!strcmp(res->mode, "on"))
1046 for (i = 0; i < nb_ports; i++) {
1048 rte_eth_allmulticast_enable(i);
1050 rte_eth_allmulticast_disable(i);
1055 rte_eth_allmulticast_enable(res->port_num);
1057 rte_eth_allmulticast_disable(res->port_num);
1061 cmdline_parse_token_string_t cmd_setallmulti_set =
1062 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
1063 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
1064 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
1066 cmdline_parse_token_string_t cmd_setallmulti_portall =
1067 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
1069 cmdline_parse_token_num_t cmd_setallmulti_portnum =
1070 TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
1072 cmdline_parse_token_string_t cmd_setallmulti_mode =
1073 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
1076 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
1077 .f = cmd_set_allmulti_mode_parsed,
1079 .help_str = "set allmulti all on|off: set allmulti mode for all ports",
1081 (void *)&cmd_setallmulti_set,
1082 (void *)&cmd_setallmulti_allmulti,
1083 (void *)&cmd_setallmulti_portall,
1084 (void *)&cmd_setallmulti_mode,
1089 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
1090 .f = cmd_set_allmulti_mode_parsed,
1092 .help_str = "set allmulti X on|off: set allmulti mode on port X",
1094 (void *)&cmd_setallmulti_set,
1095 (void *)&cmd_setallmulti_allmulti,
1096 (void *)&cmd_setallmulti_portnum,
1097 (void *)&cmd_setallmulti_mode,
1102 /* *** ADD/REMOVE A PKT FILTER *** */
1103 struct cmd_pkt_filter_result {
1104 cmdline_fixed_string_t pkt_filter;
1106 cmdline_fixed_string_t protocol;
1107 cmdline_fixed_string_t src;
1108 cmdline_ipaddr_t ip_src;
1110 cmdline_fixed_string_t dst;
1111 cmdline_ipaddr_t ip_dst;
1113 cmdline_fixed_string_t flexbytes;
1114 uint16_t flexbytes_value;
1115 cmdline_fixed_string_t vlan;
1117 cmdline_fixed_string_t queue;
1119 cmdline_fixed_string_t soft;
1124 cmd_pkt_filter_parsed(void *parsed_result,
1125 __attribute__((unused)) struct cmdline *cl,
1126 __attribute__((unused)) void *data)
1128 struct rte_fdir_filter fdir_filter;
1129 struct cmd_pkt_filter_result *res = parsed_result;
1131 memset(&fdir_filter, 0, sizeof(struct rte_fdir_filter));
1133 if (res->ip_src.family == AF_INET)
1134 fdir_filter.ip_src.ipv4_addr = res->ip_src.addr.ipv4.s_addr;
1136 memcpy(&(fdir_filter.ip_src.ipv6_addr),
1137 &(res->ip_src.addr.ipv6),
1138 sizeof(struct in6_addr));
1140 if (res->ip_dst.family == AF_INET)
1141 fdir_filter.ip_dst.ipv4_addr = res->ip_dst.addr.ipv4.s_addr;
1143 memcpy(&(fdir_filter.ip_dst.ipv6_addr),
1144 &(res->ip_dst.addr.ipv6),
1145 sizeof(struct in6_addr));
1147 fdir_filter.port_dst = rte_cpu_to_be_16(res->port_dst);
1148 fdir_filter.port_src = rte_cpu_to_be_16(res->port_src);
1150 if (!strcmp(res->protocol, "udp"))
1151 fdir_filter.l4type = RTE_FDIR_L4TYPE_UDP;
1152 else if (!strcmp(res->protocol, "tcp"))
1153 fdir_filter.l4type = RTE_FDIR_L4TYPE_TCP;
1154 else if (!strcmp(res->protocol, "sctp"))
1155 fdir_filter.l4type = RTE_FDIR_L4TYPE_SCTP;
1156 else /* default only IP */
1157 fdir_filter.l4type = RTE_FDIR_L4TYPE_NONE;
1159 if (res->ip_dst.family == AF_INET6)
1160 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV6;
1162 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV4;
1164 fdir_filter.vlan_id = rte_cpu_to_be_16(res->vlan_id);
1165 fdir_filter.flex_bytes = rte_cpu_to_be_16(res->flexbytes_value);
1167 if (!strcmp(res->pkt_filter, "add_signature_filter"))
1168 fdir_add_signature_filter(res->port_id, res->queue_id,
1170 else if (!strcmp(res->pkt_filter, "upd_signature_filter"))
1171 fdir_update_signature_filter(res->port_id, res->queue_id,
1173 else if (!strcmp(res->pkt_filter, "rm_signature_filter"))
1174 fdir_remove_signature_filter(res->port_id, &fdir_filter);
1175 else if (!strcmp(res->pkt_filter, "add_perfect_filter"))
1176 fdir_add_perfect_filter(res->port_id, res->soft_id,
1178 (uint8_t) (res->queue_id < 0),
1180 else if (!strcmp(res->pkt_filter, "upd_perfect_filter"))
1181 fdir_update_perfect_filter(res->port_id, res->soft_id,
1183 (uint8_t) (res->queue_id < 0),
1185 else if (!strcmp(res->pkt_filter, "rm_perfect_filter"))
1186 fdir_remove_perfect_filter(res->port_id, res->soft_id,
1192 cmdline_parse_token_num_t cmd_pkt_filter_port_id =
1193 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1195 cmdline_parse_token_string_t cmd_pkt_filter_protocol =
1196 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1197 protocol, "ip#tcp#udp#sctp");
1198 cmdline_parse_token_string_t cmd_pkt_filter_src =
1199 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1201 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_src =
1202 TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
1204 cmdline_parse_token_num_t cmd_pkt_filter_port_src =
1205 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1207 cmdline_parse_token_string_t cmd_pkt_filter_dst =
1208 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1210 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_dst =
1211 TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
1213 cmdline_parse_token_num_t cmd_pkt_filter_port_dst =
1214 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1216 cmdline_parse_token_string_t cmd_pkt_filter_flexbytes =
1217 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1218 flexbytes, "flexbytes");
1219 cmdline_parse_token_num_t cmd_pkt_filter_flexbytes_value =
1220 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1221 flexbytes_value, UINT16);
1222 cmdline_parse_token_string_t cmd_pkt_filter_vlan =
1223 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1225 cmdline_parse_token_num_t cmd_pkt_filter_vlan_id =
1226 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1228 cmdline_parse_token_string_t cmd_pkt_filter_queue =
1229 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1231 cmdline_parse_token_num_t cmd_pkt_filter_queue_id =
1232 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1234 cmdline_parse_token_string_t cmd_pkt_filter_soft =
1235 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1237 cmdline_parse_token_num_t cmd_pkt_filter_soft_id =
1238 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1242 cmdline_parse_token_string_t cmd_pkt_filter_add_signature_filter =
1243 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1244 pkt_filter, "add_signature_filter");
1245 cmdline_parse_inst_t cmd_add_signature_filter = {
1246 .f = cmd_pkt_filter_parsed,
1248 .help_str = "add a signature filter",
1250 (void *)&cmd_pkt_filter_add_signature_filter,
1251 (void *)&cmd_pkt_filter_port_id,
1252 (void *)&cmd_pkt_filter_protocol,
1253 (void *)&cmd_pkt_filter_src,
1254 (void *)&cmd_pkt_filter_ip_src,
1255 (void *)&cmd_pkt_filter_port_src,
1256 (void *)&cmd_pkt_filter_dst,
1257 (void *)&cmd_pkt_filter_ip_dst,
1258 (void *)&cmd_pkt_filter_port_dst,
1259 (void *)&cmd_pkt_filter_flexbytes,
1260 (void *)&cmd_pkt_filter_flexbytes_value,
1261 (void *)&cmd_pkt_filter_vlan,
1262 (void *)&cmd_pkt_filter_vlan_id,
1263 (void *)&cmd_pkt_filter_queue,
1264 (void *)&cmd_pkt_filter_queue_id,
1270 cmdline_parse_token_string_t cmd_pkt_filter_upd_signature_filter =
1271 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1272 pkt_filter, "upd_signature_filter");
1273 cmdline_parse_inst_t cmd_upd_signature_filter = {
1274 .f = cmd_pkt_filter_parsed,
1276 .help_str = "update a signature filter",
1278 (void *)&cmd_pkt_filter_upd_signature_filter,
1279 (void *)&cmd_pkt_filter_port_id,
1280 (void *)&cmd_pkt_filter_protocol,
1281 (void *)&cmd_pkt_filter_src,
1282 (void *)&cmd_pkt_filter_ip_src,
1283 (void *)&cmd_pkt_filter_port_src,
1284 (void *)&cmd_pkt_filter_dst,
1285 (void *)&cmd_pkt_filter_ip_dst,
1286 (void *)&cmd_pkt_filter_port_dst,
1287 (void *)&cmd_pkt_filter_flexbytes,
1288 (void *)&cmd_pkt_filter_flexbytes_value,
1289 (void *)&cmd_pkt_filter_vlan,
1290 (void *)&cmd_pkt_filter_vlan_id,
1291 (void *)&cmd_pkt_filter_queue,
1292 (void *)&cmd_pkt_filter_queue_id,
1298 cmdline_parse_token_string_t cmd_pkt_filter_rm_signature_filter =
1299 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1300 pkt_filter, "rm_signature_filter");
1301 cmdline_parse_inst_t cmd_rm_signature_filter = {
1302 .f = cmd_pkt_filter_parsed,
1304 .help_str = "remove a signature filter",
1306 (void *)&cmd_pkt_filter_rm_signature_filter,
1307 (void *)&cmd_pkt_filter_port_id,
1308 (void *)&cmd_pkt_filter_protocol,
1309 (void *)&cmd_pkt_filter_src,
1310 (void *)&cmd_pkt_filter_ip_src,
1311 (void *)&cmd_pkt_filter_port_src,
1312 (void *)&cmd_pkt_filter_dst,
1313 (void *)&cmd_pkt_filter_ip_dst,
1314 (void *)&cmd_pkt_filter_port_dst,
1315 (void *)&cmd_pkt_filter_flexbytes,
1316 (void *)&cmd_pkt_filter_flexbytes_value,
1317 (void *)&cmd_pkt_filter_vlan,
1318 (void *)&cmd_pkt_filter_vlan_id,
1324 cmdline_parse_token_string_t cmd_pkt_filter_add_perfect_filter =
1325 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1326 pkt_filter, "add_perfect_filter");
1327 cmdline_parse_inst_t cmd_add_perfect_filter = {
1328 .f = cmd_pkt_filter_parsed,
1330 .help_str = "add a perfect filter",
1332 (void *)&cmd_pkt_filter_add_perfect_filter,
1333 (void *)&cmd_pkt_filter_port_id,
1334 (void *)&cmd_pkt_filter_protocol,
1335 (void *)&cmd_pkt_filter_src,
1336 (void *)&cmd_pkt_filter_ip_src,
1337 (void *)&cmd_pkt_filter_port_src,
1338 (void *)&cmd_pkt_filter_dst,
1339 (void *)&cmd_pkt_filter_ip_dst,
1340 (void *)&cmd_pkt_filter_port_dst,
1341 (void *)&cmd_pkt_filter_flexbytes,
1342 (void *)&cmd_pkt_filter_flexbytes_value,
1343 (void *)&cmd_pkt_filter_vlan,
1344 (void *)&cmd_pkt_filter_vlan_id,
1345 (void *)&cmd_pkt_filter_queue,
1346 (void *)&cmd_pkt_filter_queue_id,
1347 (void *)&cmd_pkt_filter_soft,
1348 (void *)&cmd_pkt_filter_soft_id,
1354 cmdline_parse_token_string_t cmd_pkt_filter_upd_perfect_filter =
1355 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1356 pkt_filter, "upd_perfect_filter");
1357 cmdline_parse_inst_t cmd_upd_perfect_filter = {
1358 .f = cmd_pkt_filter_parsed,
1360 .help_str = "update a perfect filter",
1362 (void *)&cmd_pkt_filter_upd_perfect_filter,
1363 (void *)&cmd_pkt_filter_port_id,
1364 (void *)&cmd_pkt_filter_protocol,
1365 (void *)&cmd_pkt_filter_src,
1366 (void *)&cmd_pkt_filter_ip_src,
1367 (void *)&cmd_pkt_filter_port_src,
1368 (void *)&cmd_pkt_filter_dst,
1369 (void *)&cmd_pkt_filter_ip_dst,
1370 (void *)&cmd_pkt_filter_port_dst,
1371 (void *)&cmd_pkt_filter_flexbytes,
1372 (void *)&cmd_pkt_filter_flexbytes_value,
1373 (void *)&cmd_pkt_filter_vlan,
1374 (void *)&cmd_pkt_filter_vlan_id,
1375 (void *)&cmd_pkt_filter_queue,
1376 (void *)&cmd_pkt_filter_queue_id,
1377 (void *)&cmd_pkt_filter_soft,
1378 (void *)&cmd_pkt_filter_soft_id,
1384 cmdline_parse_token_string_t cmd_pkt_filter_rm_perfect_filter =
1385 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1386 pkt_filter, "rm_perfect_filter");
1387 cmdline_parse_inst_t cmd_rm_perfect_filter = {
1388 .f = cmd_pkt_filter_parsed,
1390 .help_str = "remove a perfect filter",
1392 (void *)&cmd_pkt_filter_rm_perfect_filter,
1393 (void *)&cmd_pkt_filter_port_id,
1394 (void *)&cmd_pkt_filter_protocol,
1395 (void *)&cmd_pkt_filter_src,
1396 (void *)&cmd_pkt_filter_ip_src,
1397 (void *)&cmd_pkt_filter_port_src,
1398 (void *)&cmd_pkt_filter_dst,
1399 (void *)&cmd_pkt_filter_ip_dst,
1400 (void *)&cmd_pkt_filter_port_dst,
1401 (void *)&cmd_pkt_filter_flexbytes,
1402 (void *)&cmd_pkt_filter_flexbytes_value,
1403 (void *)&cmd_pkt_filter_vlan,
1404 (void *)&cmd_pkt_filter_vlan_id,
1405 (void *)&cmd_pkt_filter_soft,
1406 (void *)&cmd_pkt_filter_soft_id,
1411 /* *** SETUP MASKS FILTER *** */
1412 struct cmd_pkt_filter_masks_result {
1413 cmdline_fixed_string_t filter_mask;
1415 cmdline_fixed_string_t src_mask;
1416 uint32_t ip_src_mask;
1417 uint16_t port_src_mask;
1418 cmdline_fixed_string_t dst_mask;
1419 uint32_t ip_dst_mask;
1420 uint16_t port_dst_mask;
1421 cmdline_fixed_string_t flexbytes;
1422 uint8_t flexbytes_value;
1423 cmdline_fixed_string_t vlan_id;
1424 uint8_t vlan_id_value;
1425 cmdline_fixed_string_t vlan_prio;
1426 uint8_t vlan_prio_value;
1427 cmdline_fixed_string_t only_ip_flow;
1428 uint8_t only_ip_flow_value;
1432 cmd_pkt_filter_masks_parsed(void *parsed_result,
1433 __attribute__((unused)) struct cmdline *cl,
1434 __attribute__((unused)) void *data)
1436 struct rte_fdir_masks fdir_masks;
1437 struct cmd_pkt_filter_masks_result *res = parsed_result;
1439 memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
1441 fdir_masks.only_ip_flow = res->only_ip_flow_value;
1442 fdir_masks.vlan_id = res->vlan_id_value;
1443 fdir_masks.vlan_prio = res->vlan_prio_value;
1444 fdir_masks.dst_ipv4_mask = res->ip_dst_mask;
1445 fdir_masks.src_ipv4_mask = res->ip_src_mask;
1446 fdir_masks.src_port_mask = res->port_src_mask;
1447 fdir_masks.dst_port_mask = res->port_dst_mask;
1448 fdir_masks.flexbytes = res->flexbytes_value;
1450 fdir_set_masks(res->port_id, &fdir_masks);
1453 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask =
1454 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1455 filter_mask, "set_masks_filter");
1456 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_id =
1457 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1459 cmdline_parse_token_string_t cmd_pkt_filter_masks_only_ip_flow =
1460 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1461 only_ip_flow, "only_ip_flow");
1462 cmdline_parse_token_num_t cmd_pkt_filter_masks_only_ip_flow_value =
1463 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1464 only_ip_flow_value, UINT8);
1465 cmdline_parse_token_string_t cmd_pkt_filter_masks_src_mask =
1466 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1467 src_mask, "src_mask");
1468 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_src_mask =
1469 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1470 ip_src_mask, UINT32);
1471 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_src_mask =
1472 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1473 port_src_mask, UINT16);
1474 cmdline_parse_token_string_t cmd_pkt_filter_masks_dst_mask =
1475 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1476 src_mask, "dst_mask");
1477 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_dst_mask =
1478 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1479 ip_dst_mask, UINT32);
1480 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_dst_mask =
1481 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1482 port_dst_mask, UINT16);
1483 cmdline_parse_token_string_t cmd_pkt_filter_masks_flexbytes =
1484 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1485 flexbytes, "flexbytes");
1486 cmdline_parse_token_num_t cmd_pkt_filter_masks_flexbytes_value =
1487 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1488 flexbytes_value, UINT8);
1489 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_id =
1490 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1491 vlan_id, "vlan_id");
1492 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_id_value =
1493 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1494 vlan_id_value, UINT8);
1495 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_prio =
1496 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1497 vlan_prio, "vlan_prio");
1498 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_prio_value =
1499 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1500 vlan_prio_value, UINT8);
1502 cmdline_parse_inst_t cmd_set_masks_filter = {
1503 .f = cmd_pkt_filter_masks_parsed,
1505 .help_str = "setup masks filter",
1507 (void *)&cmd_pkt_filter_masks_filter_mask,
1508 (void *)&cmd_pkt_filter_masks_port_id,
1509 (void *)&cmd_pkt_filter_masks_only_ip_flow,
1510 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
1511 (void *)&cmd_pkt_filter_masks_src_mask,
1512 (void *)&cmd_pkt_filter_masks_ip_src_mask,
1513 (void *)&cmd_pkt_filter_masks_port_src_mask,
1514 (void *)&cmd_pkt_filter_masks_dst_mask,
1515 (void *)&cmd_pkt_filter_masks_ip_dst_mask,
1516 (void *)&cmd_pkt_filter_masks_port_dst_mask,
1517 (void *)&cmd_pkt_filter_masks_flexbytes,
1518 (void *)&cmd_pkt_filter_masks_flexbytes_value,
1519 (void *)&cmd_pkt_filter_masks_vlan_id,
1520 (void *)&cmd_pkt_filter_masks_vlan_id_value,
1521 (void *)&cmd_pkt_filter_masks_vlan_prio,
1522 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
1527 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
1528 struct cmd_link_flow_ctrl_set_result {
1529 cmdline_fixed_string_t set;
1530 cmdline_fixed_string_t flow_ctrl;
1531 cmdline_fixed_string_t rx;
1532 cmdline_fixed_string_t rx_lfc_mode;
1533 cmdline_fixed_string_t tx;
1534 cmdline_fixed_string_t tx_lfc_mode;
1535 uint32_t high_water;
1537 uint16_t pause_time;
1543 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
1544 __attribute__((unused)) struct cmdline *cl,
1545 __attribute__((unused)) void *data)
1547 struct cmd_link_flow_ctrl_set_result *res = parsed_result;
1548 struct rte_eth_fc_conf fc_conf;
1549 int rx_fc_enable, tx_fc_enable;
1553 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
1554 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
1555 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
1556 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
1558 static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
1559 {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
1562 rx_fc_enable = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
1563 tx_fc_enable = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
1565 fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_enable][tx_fc_enable];
1566 fc_conf.high_water = res->high_water;
1567 fc_conf.low_water = res->low_water;
1568 fc_conf.pause_time = res->pause_time;
1569 fc_conf.send_xon = res->send_xon;
1571 ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
1573 printf("bad flow contrl parameter, return code = %d \n", ret);
1576 cmdline_parse_token_string_t cmd_lfc_set_set =
1577 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1579 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
1580 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1581 flow_ctrl, "flow_ctrl");
1582 cmdline_parse_token_string_t cmd_lfc_set_rx =
1583 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1585 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
1586 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1587 rx_lfc_mode, "on#off");
1588 cmdline_parse_token_string_t cmd_lfc_set_tx =
1589 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1591 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
1592 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1593 tx_lfc_mode, "on#off");
1594 cmdline_parse_token_num_t cmd_lfc_set_high_water =
1595 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1596 high_water, UINT32);
1597 cmdline_parse_token_num_t cmd_lfc_set_low_water =
1598 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1600 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
1601 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1602 pause_time, UINT16);
1603 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
1604 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1606 cmdline_parse_token_num_t cmd_lfc_set_portid =
1607 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1610 cmdline_parse_inst_t cmd_link_flow_control_set = {
1611 .f = cmd_link_flow_ctrl_set_parsed,
1613 .help_str = "Configure the Ethernet link flow control...",
1615 (void *)&cmd_lfc_set_set,
1616 (void *)&cmd_lfc_set_flow_ctrl,
1617 (void *)&cmd_lfc_set_rx,
1618 (void *)&cmd_lfc_set_rx_mode,
1619 (void *)&cmd_lfc_set_tx,
1620 (void *)&cmd_lfc_set_tx_mode,
1621 (void *)&cmd_lfc_set_high_water,
1622 (void *)&cmd_lfc_set_low_water,
1623 (void *)&cmd_lfc_set_pause_time,
1624 (void *)&cmd_lfc_set_send_xon,
1625 (void *)&cmd_lfc_set_portid,
1630 /* *** RESET CONFIGURATION *** */
1631 struct cmd_reset_result {
1632 cmdline_fixed_string_t reset;
1633 cmdline_fixed_string_t def;
1636 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
1638 __attribute__((unused)) void *data)
1640 cmdline_printf(cl, "Reset to default forwarding configuration...\n");
1641 set_def_fwd_config();
1644 cmdline_parse_token_string_t cmd_reset_set =
1645 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
1646 cmdline_parse_token_string_t cmd_reset_def =
1647 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
1650 cmdline_parse_inst_t cmd_reset = {
1651 .f = cmd_reset_parsed,
1653 .help_str = "set default: reset default forwarding configuration",
1655 (void *)&cmd_reset_set,
1656 (void *)&cmd_reset_def,
1661 /* *** START FORWARDING *** */
1662 struct cmd_start_result {
1663 cmdline_fixed_string_t start;
1666 cmdline_parse_token_string_t cmd_start_start =
1667 TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
1669 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
1670 __attribute__((unused)) struct cmdline *cl,
1671 __attribute__((unused)) void *data)
1673 start_packet_forwarding(0);
1676 cmdline_parse_inst_t cmd_start = {
1677 .f = cmd_start_parsed,
1679 .help_str = "start packet forwarding",
1681 (void *)&cmd_start_start,
1686 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
1687 struct cmd_start_tx_first_result {
1688 cmdline_fixed_string_t start;
1689 cmdline_fixed_string_t tx_first;
1693 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
1694 __attribute__((unused)) struct cmdline *cl,
1695 __attribute__((unused)) void *data)
1697 start_packet_forwarding(1);
1700 cmdline_parse_token_string_t cmd_start_tx_first_start =
1701 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
1703 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
1704 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
1705 tx_first, "tx_first");
1707 cmdline_parse_inst_t cmd_start_tx_first = {
1708 .f = cmd_start_tx_first_parsed,
1710 .help_str = "start packet forwarding, after sending 1 burst of packets",
1712 (void *)&cmd_start_tx_first_start,
1713 (void *)&cmd_start_tx_first_tx_first,
1718 /* *** SHOW CFG *** */
1719 struct cmd_showcfg_result {
1720 cmdline_fixed_string_t show;
1721 cmdline_fixed_string_t cfg;
1722 cmdline_fixed_string_t what;
1725 static void cmd_showcfg_parsed(void *parsed_result,
1726 __attribute__((unused)) struct cmdline *cl,
1727 __attribute__((unused)) void *data)
1729 struct cmd_showcfg_result *res = parsed_result;
1730 if (!strcmp(res->what, "rxtx"))
1731 rxtx_config_display();
1732 else if (!strcmp(res->what, "cores"))
1733 fwd_lcores_config_display();
1734 else if (!strcmp(res->what, "fwd"))
1735 fwd_config_display();
1738 cmdline_parse_token_string_t cmd_showcfg_show =
1739 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
1740 cmdline_parse_token_string_t cmd_showcfg_port =
1741 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
1742 cmdline_parse_token_string_t cmd_showcfg_what =
1743 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
1746 cmdline_parse_inst_t cmd_showcfg = {
1747 .f = cmd_showcfg_parsed,
1749 .help_str = "show config rxtx|cores|fwd",
1751 (void *)&cmd_showcfg_show,
1752 (void *)&cmd_showcfg_port,
1753 (void *)&cmd_showcfg_what,
1758 /* *** SHOW ALL PORT INFO *** */
1759 struct cmd_showportall_result {
1760 cmdline_fixed_string_t show;
1761 cmdline_fixed_string_t port;
1762 cmdline_fixed_string_t what;
1763 cmdline_fixed_string_t all;
1766 static void cmd_showportall_parsed(void *parsed_result,
1767 __attribute__((unused)) struct cmdline *cl,
1768 __attribute__((unused)) void *data)
1772 struct cmd_showportall_result *res = parsed_result;
1773 if (!strcmp(res->show, "clear")) {
1774 if (!strcmp(res->what, "stats"))
1775 for (i = 0; i < nb_ports; i++)
1777 } else if (!strcmp(res->what, "info"))
1778 for (i = 0; i < nb_ports; i++)
1779 port_infos_display(i);
1780 else if (!strcmp(res->what, "stats"))
1781 for (i = 0; i < nb_ports; i++)
1782 nic_stats_display(i);
1783 else if (!strcmp(res->what, "fdir"))
1784 for (i = 0; i < nb_ports; i++)
1786 else if (!strcmp(res->what, "stat_qmap"))
1787 for (i = 0; i < nb_ports; i++)
1788 nic_stats_mapping_display(i);
1791 cmdline_parse_token_string_t cmd_showportall_show =
1792 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
1794 cmdline_parse_token_string_t cmd_showportall_port =
1795 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
1796 cmdline_parse_token_string_t cmd_showportall_what =
1797 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
1798 "info#stats#fdir#stat_qmap");
1799 cmdline_parse_token_string_t cmd_showportall_all =
1800 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
1801 cmdline_parse_inst_t cmd_showportall = {
1802 .f = cmd_showportall_parsed,
1804 .help_str = "show|clear port info|stats|fdir|stat_qmap all",
1806 (void *)&cmd_showportall_show,
1807 (void *)&cmd_showportall_port,
1808 (void *)&cmd_showportall_what,
1809 (void *)&cmd_showportall_all,
1814 /* *** SHOW PORT INFO *** */
1815 struct cmd_showport_result {
1816 cmdline_fixed_string_t show;
1817 cmdline_fixed_string_t port;
1818 cmdline_fixed_string_t what;
1822 static void cmd_showport_parsed(void *parsed_result,
1823 __attribute__((unused)) struct cmdline *cl,
1824 __attribute__((unused)) void *data)
1826 struct cmd_showport_result *res = parsed_result;
1827 if (!strcmp(res->show, "clear")) {
1828 if (!strcmp(res->what, "stats"))
1829 nic_stats_clear(res->portnum);
1830 } else if (!strcmp(res->what, "info"))
1831 port_infos_display(res->portnum);
1832 else if (!strcmp(res->what, "stats"))
1833 nic_stats_display(res->portnum);
1834 else if (!strcmp(res->what, "fdir"))
1835 fdir_get_infos(res->portnum);
1836 else if (!strcmp(res->what, "stat_qmap"))
1837 nic_stats_mapping_display(res->portnum);
1840 cmdline_parse_token_string_t cmd_showport_show =
1841 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
1843 cmdline_parse_token_string_t cmd_showport_port =
1844 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
1845 cmdline_parse_token_string_t cmd_showport_what =
1846 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
1847 "info#stats#fdir#stat_qmap");
1848 cmdline_parse_token_num_t cmd_showport_portnum =
1849 TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, INT32);
1851 cmdline_parse_inst_t cmd_showport = {
1852 .f = cmd_showport_parsed,
1854 .help_str = "show|clear port info|stats|fdir|stat_qmap X (X = port number)",
1856 (void *)&cmd_showport_show,
1857 (void *)&cmd_showport_port,
1858 (void *)&cmd_showport_what,
1859 (void *)&cmd_showport_portnum,
1864 /* *** READ PORT REGISTER *** */
1865 struct cmd_read_reg_result {
1866 cmdline_fixed_string_t read;
1867 cmdline_fixed_string_t reg;
1873 cmd_read_reg_parsed(void *parsed_result,
1874 __attribute__((unused)) struct cmdline *cl,
1875 __attribute__((unused)) void *data)
1877 struct cmd_read_reg_result *res = parsed_result;
1878 port_reg_display(res->port_id, res->reg_off);
1881 cmdline_parse_token_string_t cmd_read_reg_read =
1882 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
1883 cmdline_parse_token_string_t cmd_read_reg_reg =
1884 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
1885 cmdline_parse_token_num_t cmd_read_reg_port_id =
1886 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
1887 cmdline_parse_token_num_t cmd_read_reg_reg_off =
1888 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
1890 cmdline_parse_inst_t cmd_read_reg = {
1891 .f = cmd_read_reg_parsed,
1893 .help_str = "read reg port_id reg_off",
1895 (void *)&cmd_read_reg_read,
1896 (void *)&cmd_read_reg_reg,
1897 (void *)&cmd_read_reg_port_id,
1898 (void *)&cmd_read_reg_reg_off,
1903 /* *** READ PORT REGISTER BIT FIELD *** */
1904 struct cmd_read_reg_bit_field_result {
1905 cmdline_fixed_string_t read;
1906 cmdline_fixed_string_t regfield;
1914 cmd_read_reg_bit_field_parsed(void *parsed_result,
1915 __attribute__((unused)) struct cmdline *cl,
1916 __attribute__((unused)) void *data)
1918 struct cmd_read_reg_bit_field_result *res = parsed_result;
1919 port_reg_bit_field_display(res->port_id, res->reg_off,
1920 res->bit1_pos, res->bit2_pos);
1923 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
1924 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
1926 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
1927 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
1928 regfield, "regfield");
1929 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
1930 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
1932 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
1933 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
1935 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
1936 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
1938 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
1939 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
1942 cmdline_parse_inst_t cmd_read_reg_bit_field = {
1943 .f = cmd_read_reg_bit_field_parsed,
1945 .help_str = "read regfield port_id reg_off bit_x bit_y "
1946 "(read register bit field between bit_x and bit_y included)",
1948 (void *)&cmd_read_reg_bit_field_read,
1949 (void *)&cmd_read_reg_bit_field_regfield,
1950 (void *)&cmd_read_reg_bit_field_port_id,
1951 (void *)&cmd_read_reg_bit_field_reg_off,
1952 (void *)&cmd_read_reg_bit_field_bit1_pos,
1953 (void *)&cmd_read_reg_bit_field_bit2_pos,
1958 /* *** READ PORT REGISTER BIT *** */
1959 struct cmd_read_reg_bit_result {
1960 cmdline_fixed_string_t read;
1961 cmdline_fixed_string_t regbit;
1968 cmd_read_reg_bit_parsed(void *parsed_result,
1969 __attribute__((unused)) struct cmdline *cl,
1970 __attribute__((unused)) void *data)
1972 struct cmd_read_reg_bit_result *res = parsed_result;
1973 port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
1976 cmdline_parse_token_string_t cmd_read_reg_bit_read =
1977 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
1978 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
1979 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
1981 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
1982 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
1983 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
1984 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
1985 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
1986 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
1988 cmdline_parse_inst_t cmd_read_reg_bit = {
1989 .f = cmd_read_reg_bit_parsed,
1991 .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
1993 (void *)&cmd_read_reg_bit_read,
1994 (void *)&cmd_read_reg_bit_regbit,
1995 (void *)&cmd_read_reg_bit_port_id,
1996 (void *)&cmd_read_reg_bit_reg_off,
1997 (void *)&cmd_read_reg_bit_bit_pos,
2002 /* *** WRITE PORT REGISTER *** */
2003 struct cmd_write_reg_result {
2004 cmdline_fixed_string_t write;
2005 cmdline_fixed_string_t reg;
2012 cmd_write_reg_parsed(void *parsed_result,
2013 __attribute__((unused)) struct cmdline *cl,
2014 __attribute__((unused)) void *data)
2016 struct cmd_write_reg_result *res = parsed_result;
2017 port_reg_set(res->port_id, res->reg_off, res->value);
2020 cmdline_parse_token_string_t cmd_write_reg_write =
2021 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
2022 cmdline_parse_token_string_t cmd_write_reg_reg =
2023 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
2024 cmdline_parse_token_num_t cmd_write_reg_port_id =
2025 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
2026 cmdline_parse_token_num_t cmd_write_reg_reg_off =
2027 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
2028 cmdline_parse_token_num_t cmd_write_reg_value =
2029 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
2031 cmdline_parse_inst_t cmd_write_reg = {
2032 .f = cmd_write_reg_parsed,
2034 .help_str = "write reg port_id reg_off reg_value",
2036 (void *)&cmd_write_reg_write,
2037 (void *)&cmd_write_reg_reg,
2038 (void *)&cmd_write_reg_port_id,
2039 (void *)&cmd_write_reg_reg_off,
2040 (void *)&cmd_write_reg_value,
2045 /* *** WRITE PORT REGISTER BIT FIELD *** */
2046 struct cmd_write_reg_bit_field_result {
2047 cmdline_fixed_string_t write;
2048 cmdline_fixed_string_t regfield;
2057 cmd_write_reg_bit_field_parsed(void *parsed_result,
2058 __attribute__((unused)) struct cmdline *cl,
2059 __attribute__((unused)) void *data)
2061 struct cmd_write_reg_bit_field_result *res = parsed_result;
2062 port_reg_bit_field_set(res->port_id, res->reg_off,
2063 res->bit1_pos, res->bit2_pos, res->value);
2066 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
2067 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
2069 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
2070 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
2071 regfield, "regfield");
2072 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
2073 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
2075 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
2076 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
2078 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
2079 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
2081 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
2082 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
2084 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
2085 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
2088 cmdline_parse_inst_t cmd_write_reg_bit_field = {
2089 .f = cmd_write_reg_bit_field_parsed,
2091 .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
2092 "(set register bit field between bit_x and bit_y included)",
2094 (void *)&cmd_write_reg_bit_field_write,
2095 (void *)&cmd_write_reg_bit_field_regfield,
2096 (void *)&cmd_write_reg_bit_field_port_id,
2097 (void *)&cmd_write_reg_bit_field_reg_off,
2098 (void *)&cmd_write_reg_bit_field_bit1_pos,
2099 (void *)&cmd_write_reg_bit_field_bit2_pos,
2100 (void *)&cmd_write_reg_bit_field_value,
2105 /* *** WRITE PORT REGISTER BIT *** */
2106 struct cmd_write_reg_bit_result {
2107 cmdline_fixed_string_t write;
2108 cmdline_fixed_string_t regbit;
2116 cmd_write_reg_bit_parsed(void *parsed_result,
2117 __attribute__((unused)) struct cmdline *cl,
2118 __attribute__((unused)) void *data)
2120 struct cmd_write_reg_bit_result *res = parsed_result;
2121 port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
2124 cmdline_parse_token_string_t cmd_write_reg_bit_write =
2125 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
2127 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
2128 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
2130 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
2131 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
2132 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
2133 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
2134 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
2135 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
2136 cmdline_parse_token_num_t cmd_write_reg_bit_value =
2137 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
2139 cmdline_parse_inst_t cmd_write_reg_bit = {
2140 .f = cmd_write_reg_bit_parsed,
2142 .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
2144 (void *)&cmd_write_reg_bit_write,
2145 (void *)&cmd_write_reg_bit_regbit,
2146 (void *)&cmd_write_reg_bit_port_id,
2147 (void *)&cmd_write_reg_bit_reg_off,
2148 (void *)&cmd_write_reg_bit_bit_pos,
2149 (void *)&cmd_write_reg_bit_value,
2154 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
2155 struct cmd_read_rxd_txd_result {
2156 cmdline_fixed_string_t read;
2157 cmdline_fixed_string_t rxd_txd;
2164 cmd_read_rxd_txd_parsed(void *parsed_result,
2165 __attribute__((unused)) struct cmdline *cl,
2166 __attribute__((unused)) void *data)
2168 struct cmd_read_rxd_txd_result *res = parsed_result;
2170 if (!strcmp(res->rxd_txd, "rxd"))
2171 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
2172 else if (!strcmp(res->rxd_txd, "txd"))
2173 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
2176 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
2177 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
2178 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
2179 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
2181 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
2182 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
2183 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
2184 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
2185 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
2186 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
2188 cmdline_parse_inst_t cmd_read_rxd_txd = {
2189 .f = cmd_read_rxd_txd_parsed,
2191 .help_str = "read rxd|txd port_id queue_id rxd_id",
2193 (void *)&cmd_read_rxd_txd_read,
2194 (void *)&cmd_read_rxd_txd_rxd_txd,
2195 (void *)&cmd_read_rxd_txd_port_id,
2196 (void *)&cmd_read_rxd_txd_queue_id,
2197 (void *)&cmd_read_rxd_txd_desc_id,
2203 struct cmd_quit_result {
2204 cmdline_fixed_string_t quit;
2207 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
2209 __attribute__((unused)) void *data)
2215 cmdline_parse_token_string_t cmd_quit_quit =
2216 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
2218 cmdline_parse_inst_t cmd_quit = {
2219 .f = cmd_quit_parsed,
2221 .help_str = "exit application",
2223 (void *)&cmd_quit_quit,
2228 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
2229 struct cmd_mac_addr_result {
2230 cmdline_fixed_string_t mac_addr_cmd;
2231 cmdline_fixed_string_t what;
2233 struct ether_addr address;
2236 static void cmd_mac_addr_parsed(void *parsed_result,
2237 __attribute__((unused)) struct cmdline *cl,
2238 __attribute__((unused)) void *data)
2240 struct cmd_mac_addr_result *res = parsed_result;
2243 if (strcmp(res->what, "add") == 0)
2244 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
2246 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
2248 /* check the return value and print it if is < 0 */
2250 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
2254 cmdline_parse_token_string_t cmd_mac_addr_cmd =
2255 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
2257 cmdline_parse_token_string_t cmd_mac_addr_what =
2258 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
2260 cmdline_parse_token_num_t cmd_mac_addr_portnum =
2261 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
2262 cmdline_parse_token_string_t cmd_mac_addr_addr =
2263 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
2265 cmdline_parse_inst_t cmd_mac_addr = {
2266 .f = cmd_mac_addr_parsed,
2268 .help_str = "mac_addr add|remove X <address>: "
2269 "add/remove MAC address on port X",
2271 (void *)&cmd_mac_addr_cmd,
2272 (void *)&cmd_mac_addr_what,
2273 (void *)&cmd_mac_addr_portnum,
2274 (void *)&cmd_mac_addr_addr,
2280 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
2281 struct cmd_set_qmap_result {
2282 cmdline_fixed_string_t set;
2283 cmdline_fixed_string_t qmap;
2284 cmdline_fixed_string_t what;
2291 cmd_set_qmap_parsed(void *parsed_result,
2292 __attribute__((unused)) struct cmdline *cl,
2293 __attribute__((unused)) void *data)
2295 struct cmd_set_qmap_result *res = parsed_result;
2296 int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
2298 set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
2301 cmdline_parse_token_string_t cmd_setqmap_set =
2302 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
2304 cmdline_parse_token_string_t cmd_setqmap_qmap =
2305 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
2307 cmdline_parse_token_string_t cmd_setqmap_what =
2308 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
2310 cmdline_parse_token_num_t cmd_setqmap_portid =
2311 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
2313 cmdline_parse_token_num_t cmd_setqmap_queueid =
2314 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
2316 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
2317 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
2320 cmdline_parse_inst_t cmd_set_qmap = {
2321 .f = cmd_set_qmap_parsed,
2323 .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
2325 (void *)&cmd_setqmap_set,
2326 (void *)&cmd_setqmap_qmap,
2327 (void *)&cmd_setqmap_what,
2328 (void *)&cmd_setqmap_portid,
2329 (void *)&cmd_setqmap_queueid,
2330 (void *)&cmd_setqmap_mapvalue,
2335 /* ******************************************************************************** */
2337 /* list of instructions */
2338 cmdline_parse_ctx_t main_ctx[] = {
2339 (cmdline_parse_inst_t *)&cmd_help,
2340 (cmdline_parse_inst_t *)&cmd_quit,
2341 (cmdline_parse_inst_t *)&cmd_showport,
2342 (cmdline_parse_inst_t *)&cmd_showportall,
2343 (cmdline_parse_inst_t *)&cmd_showcfg,
2344 (cmdline_parse_inst_t *)&cmd_start,
2345 (cmdline_parse_inst_t *)&cmd_start_tx_first,
2346 (cmdline_parse_inst_t *)&cmd_reset,
2347 (cmdline_parse_inst_t *)&cmd_set_numbers,
2348 (cmdline_parse_inst_t *)&cmd_set_txpkts,
2349 (cmdline_parse_inst_t *)&cmd_set_fwd_list,
2350 (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
2351 (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
2352 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
2353 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
2354 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
2355 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
2356 (cmdline_parse_inst_t *)&cmd_vlan_offload,
2357 (cmdline_parse_inst_t *)&cmd_vlan_tpid,
2358 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
2359 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
2360 (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
2361 (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
2362 (cmdline_parse_inst_t *)&cmd_tx_cksum_set,
2363 (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
2364 (cmdline_parse_inst_t *)&cmd_read_reg,
2365 (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
2366 (cmdline_parse_inst_t *)&cmd_read_reg_bit,
2367 (cmdline_parse_inst_t *)&cmd_write_reg,
2368 (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
2369 (cmdline_parse_inst_t *)&cmd_write_reg_bit,
2370 (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
2371 (cmdline_parse_inst_t *)&cmd_add_signature_filter,
2372 (cmdline_parse_inst_t *)&cmd_upd_signature_filter,
2373 (cmdline_parse_inst_t *)&cmd_rm_signature_filter,
2374 (cmdline_parse_inst_t *)&cmd_add_perfect_filter,
2375 (cmdline_parse_inst_t *)&cmd_upd_perfect_filter,
2376 (cmdline_parse_inst_t *)&cmd_rm_perfect_filter,
2377 (cmdline_parse_inst_t *)&cmd_set_masks_filter,
2378 (cmdline_parse_inst_t *)&cmd_stop,
2379 (cmdline_parse_inst_t *)&cmd_mac_addr,
2380 (cmdline_parse_inst_t *)&cmd_set_qmap,
2384 /* prompt function, called from main on MASTER lcore */
2390 cl = cmdline_stdin_new(main_ctx, "testpmd> ");
2394 cmdline_interact(cl);
2395 cmdline_stdin_exit(cl);