2 // Copyright (c) 2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
21 #include <rte_common.h>
23 #include <rte_malloc.h>
24 #include <cmdline_rdline.h>
25 #include <cmdline_parse.h>
26 #include <cmdline_parse_num.h>
27 #include <cmdline_parse_string.h>
28 #include <cmdline_parse_ipaddr.h>
29 #include <cmdline_parse_etheraddr.h>
30 #include <cmdline_socket.h>
33 #include "pipeline_common_fe.h"
35 #include "interface.h"
39 app_pipeline_ping(struct app_params *app,
42 struct app_pipeline_params *p;
43 struct pipeline_msg_req *req;
44 struct pipeline_msg_rsp *rsp;
47 /* Check input arguments */
51 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
55 /* Message buffer allocation */
56 req = app_msg_alloc(app);
61 req->type = PIPELINE_MSG_REQ_PING;
63 /* Send request and wait for response */
64 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
71 /* Message buffer free */
72 app_msg_free(app, rsp);
78 app_pipeline_stats_port_in(struct app_params *app,
81 struct rte_pipeline_port_in_stats *stats)
83 struct app_pipeline_params *p;
84 struct pipeline_stats_msg_req *req;
85 struct pipeline_stats_port_in_msg_rsp *rsp;
88 /* Check input arguments */
93 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
95 (port_id >= p->n_pktq_in))
98 /* Message buffer allocation */
99 req = app_msg_alloc(app);
103 /* Fill in request */
104 req->type = PIPELINE_MSG_REQ_STATS_PORT_IN;
107 /* Send request and wait for response */
108 rsp = (struct pipeline_stats_port_in_msg_rsp *)
109 app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
114 status = rsp->status;
116 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
118 /* Message buffer free */
119 app_msg_free(app, rsp);
125 app_pipeline_stats_port_out(struct app_params *app,
126 uint32_t pipeline_id,
128 struct rte_pipeline_port_out_stats *stats)
130 struct app_pipeline_params *p;
131 struct pipeline_stats_msg_req *req;
132 struct pipeline_stats_port_out_msg_rsp *rsp;
135 /* Check input arguments */
137 (pipeline_id >= app->n_pipelines) ||
141 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
143 (port_id >= p->n_pktq_out))
146 /* Message buffer allocation */
147 req = app_msg_alloc(app);
151 /* Fill in request */
152 req->type = PIPELINE_MSG_REQ_STATS_PORT_OUT;
155 /* Send request and wait for response */
156 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
161 status = rsp->status;
163 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
165 /* Message buffer free */
166 app_msg_free(app, rsp);
172 app_pipeline_stats_table(struct app_params *app,
173 uint32_t pipeline_id,
175 struct rte_pipeline_table_stats *stats)
177 struct app_pipeline_params *p;
178 struct pipeline_stats_msg_req *req;
179 struct pipeline_stats_table_msg_rsp *rsp;
182 /* Check input arguments */
187 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
191 /* Message buffer allocation */
192 req = app_msg_alloc(app);
196 /* Fill in request */
197 req->type = PIPELINE_MSG_REQ_STATS_TABLE;
200 /* Send request and wait for response */
201 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
206 status = rsp->status;
208 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
210 /* Message buffer free */
211 app_msg_free(app, rsp);
217 app_pipeline_port_in_enable(struct app_params *app,
218 uint32_t pipeline_id,
221 struct app_pipeline_params *p;
222 struct pipeline_port_in_msg_req *req;
223 struct pipeline_msg_rsp *rsp;
226 /* Check input arguments */
230 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
232 (port_id >= p->n_pktq_in))
235 /* Message buffer allocation */
236 req = app_msg_alloc(app);
240 /* Fill in request */
241 req->type = PIPELINE_MSG_REQ_PORT_IN_ENABLE;
242 req->port_id = port_id;
244 /* Send request and wait for response */
245 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
250 status = rsp->status;
252 /* Message buffer free */
253 app_msg_free(app, rsp);
259 app_pipeline_port_in_disable(struct app_params *app,
260 uint32_t pipeline_id,
263 struct app_pipeline_params *p;
264 struct pipeline_port_in_msg_req *req;
265 struct pipeline_msg_rsp *rsp;
268 /* Check input arguments */
272 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
274 (port_id >= p->n_pktq_in))
277 /* Message buffer allocation */
278 req = app_msg_alloc(app);
282 /* Fill in request */
283 req->type = PIPELINE_MSG_REQ_PORT_IN_DISABLE;
284 req->port_id = port_id;
286 /* Send request and wait for response */
287 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
292 status = rsp->status;
294 /* Message buffer free */
295 app_msg_free(app, rsp);
301 app_link_config(struct app_params *app,
306 struct app_link_params *p;
307 uint32_t i, netmask, host, bcast;
309 /* Check input arguments */
313 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
315 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
321 APP_LOG(app, HIGH, "%s is UP, please bring it DOWN first",
326 netmask = (~0U) << (32 - depth);
328 bcast = host | (~netmask);
331 (ip == UINT32_MAX) ||
334 APP_LOG(app, HIGH, "Illegal IP address");
338 for (i = 0; i < app->n_links; i++) {
339 struct app_link_params *link = &app->link_params[i];
341 if (strcmp(p->name, link->name) == 0)
344 if (link->ip == ip) {
346 "%s is already assigned this IP address",
352 if ((depth == 0) || (depth > 32)) {
353 APP_LOG(app, HIGH, "Illegal value for depth parameter "
359 /* Save link parameters */
363 if (ifm_add_ipv4_port(link_id, rte_bswap32(ip), depth) == IFM_FAILURE)
371 void convert_prefixlen_to_netmask_ipv6(uint32_t depth, uint8_t netmask_ipv6[])
375 memset(netmask_ipv6, 0, 16);
380 for (i = 0; i < div; i++)
381 netmask_ipv6[i] = 0xff;
383 netmask_ipv6[i] = (~0 << (8 - mod));
389 get_host_portion_ipv6(uint8_t ipv6[], uint8_t netmask[], uint8_t host_ipv6[])
393 for (i = 0; i < 16; i++) {
394 host_ipv6[i] = ipv6[i] & netmask[i];
401 get_bcast_portion_ipv6(uint8_t host[], uint8_t netmask[], uint8_t bcast_ipv6[])
405 for (i = 0; i < 16; i++) {
406 bcast_ipv6[i] = host[i] | ~netmask[i];
413 app_link_config_ipv6(struct app_params *app,
414 uint32_t link_id, uint8_t ipv6[], uint32_t depth)
416 struct app_link_params *p;
418 uint8_t netmask_ipv6[16], host[16], bcast[16];
420 /* Check input arguments */
424 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
426 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
432 APP_LOG(app, HIGH, "%s is UP, please bring it DOWN first",
437 convert_prefixlen_to_netmask_ipv6(depth, netmask_ipv6);
438 get_host_portion_ipv6(ipv6, netmask_ipv6, host);
439 get_bcast_portion_ipv6(host, netmask_ipv6, bcast);
441 for (i = 0; i < app->n_links; i++) {
442 struct app_link_params *link = &app->link_params[i];
444 if (strcmp(p->name, link->name) == 0)
447 if (!memcmp(link->ipv6, ipv6, 16)) {
449 "%s is already assigned this IPv6 address",
455 if ((depth == 0) || (depth > 128)) {
456 APP_LOG(app, HIGH, "Illegal value for depth parameter "
457 "(%" PRIu32 ")", depth);
461 /* Save link parameters */
462 memcpy(p->ipv6, ipv6, 16);
464 p->depth_ipv6 = depth;
466 printf("IPv6: %x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x",
467 ipv6[0], ipv6[1], ipv6[2], ipv6[3], ipv6[4], ipv6[5],
468 ipv6[6], ipv6[7], ipv6[8], ipv6[9], ipv6[10], ipv6[11],
469 ipv6[12], ipv6[13], ipv6[14], ipv6[15]);
472 if (ifm_add_ipv6_port(link_id, ipv6, depth) == IFM_FAILURE)
479 app_link_up(struct app_params *app,
482 struct app_link_params *p;
484 /* Check input arguments */
488 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
490 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
495 /* Check link state */
497 APP_LOG(app, HIGH, "%s is already UP", p->name);
501 /* Check that IP address is valid */
506 if ((p->ip || memcmp(p->ipv6, temp, 16)) == 0) {
507 APP_LOG(app, HIGH, "%s IP address is not set", p->name);
511 app_link_up_internal(app, p);
517 app_link_down(struct app_params *app,
520 struct app_link_params *p;
522 /* Check input arguments */
526 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
528 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
533 /* Check link state */
535 APP_LOG(app, HIGH, "%s is already DOWN", p->name);
539 app_link_down_internal(app, p);
548 struct cmd_ping_result {
549 cmdline_fixed_string_t p_string;
550 uint32_t pipeline_id;
551 cmdline_fixed_string_t ping_string;
557 __rte_unused struct cmdline *cl,
560 struct cmd_ping_result *params = parsed_result;
561 struct app_params *app = data;
564 status = app_pipeline_ping(app, params->pipeline_id);
566 printf("Command failed\n");
569 cmdline_parse_token_string_t cmd_ping_p_string =
570 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, p_string, "p");
572 cmdline_parse_token_num_t cmd_ping_pipeline_id =
573 TOKEN_NUM_INITIALIZER(struct cmd_ping_result, pipeline_id, UINT32);
575 cmdline_parse_token_string_t cmd_ping_ping_string =
576 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, ping_string, "ping");
578 cmdline_parse_inst_t cmd_ping = {
579 .f = cmd_ping_parsed,
581 .help_str = "Pipeline ping",
583 (void *) &cmd_ping_p_string,
584 (void *) &cmd_ping_pipeline_id,
585 (void *) &cmd_ping_ping_string,
594 struct cmd_stats_port_in_result {
595 cmdline_fixed_string_t p_string;
596 uint32_t pipeline_id;
597 cmdline_fixed_string_t stats_string;
598 cmdline_fixed_string_t port_string;
599 cmdline_fixed_string_t in_string;
604 cmd_stats_port_in_parsed(
606 __rte_unused struct cmdline *cl,
609 struct cmd_stats_port_in_result *params = parsed_result;
610 struct app_params *app = data;
611 struct rte_pipeline_port_in_stats stats;
614 status = app_pipeline_stats_port_in(app,
620 printf("Command failed\n");
625 printf("Pipeline %" PRIu32 " - stats for input port %" PRIu32 ":\n"
626 "\tPkts in: %" PRIu64 "\n"
627 "\tPkts dropped by AH: %" PRIu64 "\n"
628 "\tPkts dropped by other: %" PRIu64 "\n",
631 stats.stats.n_pkts_in,
632 stats.n_pkts_dropped_by_ah,
633 stats.stats.n_pkts_drop);
636 cmdline_parse_token_string_t cmd_stats_port_in_p_string =
637 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, p_string,
640 cmdline_parse_token_num_t cmd_stats_port_in_pipeline_id =
641 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, pipeline_id,
644 cmdline_parse_token_string_t cmd_stats_port_in_stats_string =
645 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, stats_string,
648 cmdline_parse_token_string_t cmd_stats_port_in_port_string =
649 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, port_string,
652 cmdline_parse_token_string_t cmd_stats_port_in_in_string =
653 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, in_string,
656 cmdline_parse_token_num_t cmd_stats_port_in_port_in_id =
657 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, port_in_id,
660 cmdline_parse_inst_t cmd_stats_port_in = {
661 .f = cmd_stats_port_in_parsed,
663 .help_str = "Pipeline input port stats",
665 (void *) &cmd_stats_port_in_p_string,
666 (void *) &cmd_stats_port_in_pipeline_id,
667 (void *) &cmd_stats_port_in_stats_string,
668 (void *) &cmd_stats_port_in_port_string,
669 (void *) &cmd_stats_port_in_in_string,
670 (void *) &cmd_stats_port_in_port_in_id,
679 struct cmd_stats_port_out_result {
680 cmdline_fixed_string_t p_string;
681 uint32_t pipeline_id;
682 cmdline_fixed_string_t stats_string;
683 cmdline_fixed_string_t port_string;
684 cmdline_fixed_string_t out_string;
685 uint32_t port_out_id;
689 cmd_stats_port_out_parsed(
691 __rte_unused struct cmdline *cl,
695 struct cmd_stats_port_out_result *params = parsed_result;
696 struct app_params *app = data;
697 struct rte_pipeline_port_out_stats stats;
700 status = app_pipeline_stats_port_out(app,
706 printf("Command failed\n");
711 printf("Pipeline %" PRIu32 " - stats for output port %" PRIu32 ":\n"
712 "\tPkts in: %" PRIu64 "\n"
713 "\tPkts dropped by AH: %" PRIu64 "\n"
714 "\tPkts dropped by other: %" PRIu64 "\n",
717 stats.stats.n_pkts_in,
718 stats.n_pkts_dropped_by_ah,
719 stats.stats.n_pkts_drop);
722 cmdline_parse_token_string_t cmd_stats_port_out_p_string =
723 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, p_string,
726 cmdline_parse_token_num_t cmd_stats_port_out_pipeline_id =
727 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, pipeline_id,
730 cmdline_parse_token_string_t cmd_stats_port_out_stats_string =
731 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, stats_string,
734 cmdline_parse_token_string_t cmd_stats_port_out_port_string =
735 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, port_string,
738 cmdline_parse_token_string_t cmd_stats_port_out_out_string =
739 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, out_string,
742 cmdline_parse_token_num_t cmd_stats_port_out_port_out_id =
743 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, port_out_id,
746 cmdline_parse_inst_t cmd_stats_port_out = {
747 .f = cmd_stats_port_out_parsed,
749 .help_str = "Pipeline output port stats",
751 (void *) &cmd_stats_port_out_p_string,
752 (void *) &cmd_stats_port_out_pipeline_id,
753 (void *) &cmd_stats_port_out_stats_string,
754 (void *) &cmd_stats_port_out_port_string,
755 (void *) &cmd_stats_port_out_out_string,
756 (void *) &cmd_stats_port_out_port_out_id,
765 struct cmd_stats_table_result {
766 cmdline_fixed_string_t p_string;
767 uint32_t pipeline_id;
768 cmdline_fixed_string_t stats_string;
769 cmdline_fixed_string_t table_string;
774 cmd_stats_table_parsed(
776 __rte_unused struct cmdline *cl,
779 struct cmd_stats_table_result *params = parsed_result;
780 struct app_params *app = data;
781 struct rte_pipeline_table_stats stats;
784 status = app_pipeline_stats_table(app,
790 printf("Command failed\n");
795 printf("Pipeline %" PRIu32 " - stats for table %" PRIu32 ":\n"
796 "\tPkts in: %" PRIu64 "\n"
797 "\tPkts in with lookup miss: %" PRIu64 "\n"
798 "\tPkts in with lookup hit dropped by AH: %" PRIu64 "\n"
799 "\tPkts in with lookup hit dropped by others: %" PRIu64 "\n"
800 "\tPkts in with lookup miss dropped by AH: %" PRIu64 "\n"
801 "\tPkts in with lookup miss dropped by others: %" PRIu64 "\n",
804 stats.stats.n_pkts_in,
805 stats.stats.n_pkts_lookup_miss,
806 stats.n_pkts_dropped_by_lkp_hit_ah,
807 stats.n_pkts_dropped_lkp_hit,
808 stats.n_pkts_dropped_by_lkp_miss_ah,
809 stats.n_pkts_dropped_lkp_miss);
812 cmdline_parse_token_string_t cmd_stats_table_p_string =
813 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, p_string,
816 cmdline_parse_token_num_t cmd_stats_table_pipeline_id =
817 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, pipeline_id,
820 cmdline_parse_token_string_t cmd_stats_table_stats_string =
821 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, stats_string,
824 cmdline_parse_token_string_t cmd_stats_table_table_string =
825 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, table_string,
828 cmdline_parse_token_num_t cmd_stats_table_table_id =
829 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, table_id, UINT32);
831 cmdline_parse_inst_t cmd_stats_table = {
832 .f = cmd_stats_table_parsed,
834 .help_str = "Pipeline table stats",
836 (void *) &cmd_stats_table_p_string,
837 (void *) &cmd_stats_table_pipeline_id,
838 (void *) &cmd_stats_table_stats_string,
839 (void *) &cmd_stats_table_table_string,
840 (void *) &cmd_stats_table_table_id,
849 struct cmd_port_in_enable_result {
850 cmdline_fixed_string_t p_string;
851 uint32_t pipeline_id;
852 cmdline_fixed_string_t port_string;
853 cmdline_fixed_string_t in_string;
855 cmdline_fixed_string_t enable_string;
859 cmd_port_in_enable_parsed(
861 __rte_unused struct cmdline *cl,
864 struct cmd_port_in_enable_result *params = parsed_result;
865 struct app_params *app = data;
868 status = app_pipeline_port_in_enable(app,
873 printf("Command failed\n");
876 cmdline_parse_token_string_t cmd_port_in_enable_p_string =
877 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, p_string,
880 cmdline_parse_token_num_t cmd_port_in_enable_pipeline_id =
881 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, pipeline_id,
884 cmdline_parse_token_string_t cmd_port_in_enable_port_string =
885 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, port_string,
888 cmdline_parse_token_string_t cmd_port_in_enable_in_string =
889 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, in_string,
892 cmdline_parse_token_num_t cmd_port_in_enable_port_in_id =
893 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, port_in_id,
896 cmdline_parse_token_string_t cmd_port_in_enable_enable_string =
897 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result,
898 enable_string, "enable");
900 cmdline_parse_inst_t cmd_port_in_enable = {
901 .f = cmd_port_in_enable_parsed,
903 .help_str = "Pipeline input port enable",
905 (void *) &cmd_port_in_enable_p_string,
906 (void *) &cmd_port_in_enable_pipeline_id,
907 (void *) &cmd_port_in_enable_port_string,
908 (void *) &cmd_port_in_enable_in_string,
909 (void *) &cmd_port_in_enable_port_in_id,
910 (void *) &cmd_port_in_enable_enable_string,
919 struct cmd_port_in_disable_result {
920 cmdline_fixed_string_t p_string;
921 uint32_t pipeline_id;
922 cmdline_fixed_string_t port_string;
923 cmdline_fixed_string_t in_string;
925 cmdline_fixed_string_t disable_string;
929 cmd_port_in_disable_parsed(
931 __rte_unused struct cmdline *cl,
934 struct cmd_port_in_disable_result *params = parsed_result;
935 struct app_params *app = data;
938 status = app_pipeline_port_in_disable(app,
943 printf("Command failed\n");
946 cmdline_parse_token_string_t cmd_port_in_disable_p_string =
947 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, p_string,
950 cmdline_parse_token_num_t cmd_port_in_disable_pipeline_id =
951 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, pipeline_id,
954 cmdline_parse_token_string_t cmd_port_in_disable_port_string =
955 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, port_string,
958 cmdline_parse_token_string_t cmd_port_in_disable_in_string =
959 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, in_string,
962 cmdline_parse_token_num_t cmd_port_in_disable_port_in_id =
963 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, port_in_id,
966 cmdline_parse_token_string_t cmd_port_in_disable_disable_string =
967 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result,
968 disable_string, "disable");
970 cmdline_parse_inst_t cmd_port_in_disable = {
971 .f = cmd_port_in_disable_parsed,
973 .help_str = "Pipeline input port disable",
975 (void *) &cmd_port_in_disable_p_string,
976 (void *) &cmd_port_in_disable_pipeline_id,
977 (void *) &cmd_port_in_disable_port_string,
978 (void *) &cmd_port_in_disable_in_string,
979 (void *) &cmd_port_in_disable_port_in_id,
980 (void *) &cmd_port_in_disable_disable_string,
990 print_link_info(struct app_link_params *p)
992 struct rte_eth_stats stats;
993 struct ether_addr *mac_addr;
994 uint32_t netmask = (~0U) << (32 - p->depth);
995 uint32_t host = p->ip & netmask;
996 uint32_t bcast = host | (~netmask);
998 memset(&stats, 0, sizeof(stats));
999 rte_eth_stats_get(p->pmd_id, &stats);
1001 mac_addr = (struct ether_addr *) &p->mac_addr;
1003 if (strlen(p->pci_bdf))
1004 printf("%s(%s): flags=<%s>\n",
1007 (p->state) ? "UP" : "DOWN");
1009 printf("%s: flags=<%s>\n",
1011 (p->state) ? "UP" : "DOWN");
1014 printf("\tinet %" PRIu32 ".%" PRIu32
1015 ".%" PRIu32 ".%" PRIu32
1016 " netmask %" PRIu32 ".%" PRIu32
1017 ".%" PRIu32 ".%" PRIu32 " "
1018 "broadcast %" PRIu32 ".%" PRIu32
1019 ".%" PRIu32 ".%" PRIu32 "\n",
1020 (p->ip >> 24) & 0xFF,
1021 (p->ip >> 16) & 0xFF,
1022 (p->ip >> 8) & 0xFF,
1024 (netmask >> 24) & 0xFF,
1025 (netmask >> 16) & 0xFF,
1026 (netmask >> 8) & 0xFF,
1028 (bcast >> 24) & 0xFF,
1029 (bcast >> 16) & 0xFF,
1030 (bcast >> 8) & 0xFF,
1033 printf("\tether %02" PRIx32 ":%02" PRIx32 ":%02" PRIx32
1034 ":%02" PRIx32 ":%02" PRIx32 ":%02" PRIx32 "\n",
1035 mac_addr->addr_bytes[0],
1036 mac_addr->addr_bytes[1],
1037 mac_addr->addr_bytes[2],
1038 mac_addr->addr_bytes[3],
1039 mac_addr->addr_bytes[4],
1040 mac_addr->addr_bytes[5]);
1042 printf("\tRX packets %" PRIu64
1048 printf("\tRX errors %" PRIu64
1056 printf("\tTX packets %" PRIu64
1057 " bytes %" PRIu64 "\n",
1061 printf("\tTX errors %" PRIu64
1068 struct cmd_link_config_result {
1069 cmdline_fixed_string_t link_string;
1071 cmdline_fixed_string_t config_string;
1072 cmdline_ipaddr_t ip;
1077 cmd_link_config_parsed(
1078 void *parsed_result,
1079 __attribute__((unused)) struct cmdline *cl,
1082 struct cmd_link_config_result *params = parsed_result;
1083 struct app_params *app = data;
1086 uint32_t link_id = params->link_id;
1089 if (params->ip.family == AF_INET)
1090 ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr);
1092 memcpy(ipv6, params->ip.addr.ipv6.s6_addr, 16);
1094 uint32_t depth = params->depth;
1096 if (params->ip.family == AF_INET)
1097 status = app_link_config(app, link_id, ip, depth);
1099 status = app_link_config_ipv6(app, link_id, ipv6, depth);
1102 printf("Command failed\n");
1104 struct app_link_params *p;
1106 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1112 cmdline_parse_token_string_t cmd_link_config_link_string =
1113 TOKEN_STRING_INITIALIZER(struct cmd_link_config_result, link_string,
1116 cmdline_parse_token_num_t cmd_link_config_link_id =
1117 TOKEN_NUM_INITIALIZER(struct cmd_link_config_result, link_id, UINT32);
1119 cmdline_parse_token_string_t cmd_link_config_config_string =
1120 TOKEN_STRING_INITIALIZER(struct cmd_link_config_result, config_string,
1123 cmdline_parse_token_ipaddr_t cmd_link_config_ip =
1124 TOKEN_IPADDR_INITIALIZER(struct cmd_link_config_result, ip);
1126 cmdline_parse_token_num_t cmd_link_config_depth =
1127 TOKEN_NUM_INITIALIZER(struct cmd_link_config_result, depth, UINT32);
1129 cmdline_parse_inst_t cmd_link_config = {
1130 .f = cmd_link_config_parsed,
1132 .help_str = "Link configuration",
1134 (void *)&cmd_link_config_link_string,
1135 (void *)&cmd_link_config_link_id,
1136 (void *)&cmd_link_config_config_string,
1137 (void *)&cmd_link_config_ip,
1138 (void *)&cmd_link_config_depth,
1147 struct cmd_link_up_result {
1148 cmdline_fixed_string_t link_string;
1150 cmdline_fixed_string_t up_string;
1155 void *parsed_result,
1156 __attribute__((unused)) struct cmdline *cl,
1159 struct cmd_link_up_result *params = parsed_result;
1160 struct app_params *app = data;
1163 status = app_link_up(app, params->link_id);
1165 printf("Command failed\n");
1167 struct app_link_params *p;
1169 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", params->link_id,
1176 cmdline_parse_token_string_t cmd_link_up_link_string =
1177 TOKEN_STRING_INITIALIZER(struct cmd_link_up_result, link_string,
1180 cmdline_parse_token_num_t cmd_link_up_link_id =
1181 TOKEN_NUM_INITIALIZER(struct cmd_link_up_result, link_id, UINT32);
1183 cmdline_parse_token_string_t cmd_link_up_up_string =
1184 TOKEN_STRING_INITIALIZER(struct cmd_link_up_result, up_string, "up");
1186 cmdline_parse_inst_t cmd_link_up = {
1187 .f = cmd_link_up_parsed,
1189 .help_str = "Link UP",
1191 (void *)&cmd_link_up_link_string,
1192 (void *)&cmd_link_up_link_id,
1193 (void *)&cmd_link_up_up_string,
1202 struct cmd_link_down_result {
1203 cmdline_fixed_string_t link_string;
1205 cmdline_fixed_string_t down_string;
1209 cmd_link_down_parsed(
1210 void *parsed_result,
1211 __attribute__((unused)) struct cmdline *cl,
1214 struct cmd_link_down_result *params = parsed_result;
1215 struct app_params *app = data;
1218 status = app_link_down(app, params->link_id);
1220 printf("Command failed\n");
1222 struct app_link_params *p;
1224 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", params->link_id,
1231 cmdline_parse_token_string_t cmd_link_down_link_string =
1232 TOKEN_STRING_INITIALIZER(struct cmd_link_down_result, link_string,
1235 cmdline_parse_token_num_t cmd_link_down_link_id =
1236 TOKEN_NUM_INITIALIZER(struct cmd_link_down_result, link_id, UINT32);
1238 cmdline_parse_token_string_t cmd_link_down_down_string =
1239 TOKEN_STRING_INITIALIZER(struct cmd_link_down_result, down_string,
1242 cmdline_parse_inst_t cmd_link_down = {
1243 .f = cmd_link_down_parsed,
1245 .help_str = "Link DOWN",
1247 (void *) &cmd_link_down_link_string,
1248 (void *) &cmd_link_down_link_id,
1249 (void *) &cmd_link_down_down_string,
1258 struct cmd_link_ls_result {
1259 cmdline_fixed_string_t link_string;
1260 cmdline_fixed_string_t ls_string;
1265 __attribute__((unused)) void *parsed_result,
1266 __attribute__((unused)) struct cmdline *cl,
1269 struct app_params *app = data;
1272 for (link_id = 0; link_id < app->n_links; link_id++) {
1273 struct app_link_params *p;
1275 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1280 print_interface_details();
1284 cmdline_parse_token_string_t cmd_link_ls_link_string =
1285 TOKEN_STRING_INITIALIZER(struct cmd_link_ls_result, link_string,
1288 cmdline_parse_token_string_t cmd_link_ls_ls_string =
1289 TOKEN_STRING_INITIALIZER(struct cmd_link_ls_result, ls_string, "ls");
1291 cmdline_parse_inst_t cmd_link_ls = {
1292 .f = cmd_link_ls_parsed,
1294 .help_str = "Link list",
1296 (void *)&cmd_link_ls_link_string,
1297 (void *)&cmd_link_ls_ls_string,
1306 struct cmd_quit_result {
1307 cmdline_fixed_string_t quit;
1312 __rte_unused void *parsed_result,
1314 __rte_unused void *data)
1319 static cmdline_parse_token_string_t cmd_quit_quit =
1320 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
1322 static cmdline_parse_inst_t cmd_quit = {
1323 .f = cmd_quit_parsed,
1327 (void *) &cmd_quit_quit,
1338 cmdline_parse_ctx_t *ctx,
1339 const char *file_name)
1341 struct cmdline *file_cl;
1344 fd = open(file_name, O_RDONLY);
1346 printf("Cannot open file \"%s\"\n", file_name);
1350 file_cl = cmdline_new(ctx, "", fd, 1);
1351 cmdline_interact(file_cl);
1355 struct cmd_run_file_result {
1356 cmdline_fixed_string_t run_string;
1357 char file_name[APP_FILE_NAME_SIZE];
1362 void *parsed_result,
1364 __attribute__((unused)) void *data)
1366 struct cmd_run_file_result *params = parsed_result;
1368 app_run_file(cl->ctx, params->file_name);
1371 cmdline_parse_token_string_t cmd_run_run_string =
1372 TOKEN_STRING_INITIALIZER(struct cmd_run_file_result, run_string,
1375 cmdline_parse_token_string_t cmd_run_file_name =
1376 TOKEN_STRING_INITIALIZER(struct cmd_run_file_result, file_name, NULL);
1378 cmdline_parse_inst_t cmd_run = {
1379 .f = cmd_run_parsed,
1381 .help_str = "Run CLI script file",
1383 (void *) &cmd_run_run_string,
1384 (void *) &cmd_run_file_name,
1389 static cmdline_parse_ctx_t pipeline_common_cmds[] = {
1390 (cmdline_parse_inst_t *) &cmd_quit,
1391 (cmdline_parse_inst_t *) &cmd_run,
1393 (cmdline_parse_inst_t *) &cmd_link_config,
1394 (cmdline_parse_inst_t *) &cmd_link_up,
1395 (cmdline_parse_inst_t *) &cmd_link_down,
1396 (cmdline_parse_inst_t *) &cmd_link_ls,
1398 (cmdline_parse_inst_t *) &cmd_ping,
1399 (cmdline_parse_inst_t *) &cmd_stats_port_in,
1400 (cmdline_parse_inst_t *) &cmd_stats_port_out,
1401 (cmdline_parse_inst_t *) &cmd_stats_table,
1402 (cmdline_parse_inst_t *) &cmd_port_in_enable,
1403 (cmdline_parse_inst_t *) &cmd_port_in_disable,
1408 app_pipeline_common_cmd_push(struct app_params *app)
1412 /* Check for available slots in the application commands array */
1413 n_cmds = RTE_DIM(pipeline_common_cmds) - 1;
1414 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1417 /* Push pipeline commands into the application */
1418 memcpy(&app->cmds[app->n_cmds],
1419 pipeline_common_cmds,
1420 n_cmds * sizeof(cmdline_parse_ctx_t));
1422 for (i = 0; i < n_cmds; i++)
1423 app->cmds[app->n_cmds + i]->data = app;
1425 app->n_cmds += n_cmds;
1426 app->cmds[app->n_cmds] = NULL;