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"
34 #include "interface.h"
38 app_pipeline_ping(struct app_params *app,
41 struct app_pipeline_params *p;
42 struct pipeline_msg_req *req;
43 struct pipeline_msg_rsp *rsp;
46 /* Check input arguments */
50 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
54 /* Message buffer allocation */
55 req = app_msg_alloc(app);
60 req->type = PIPELINE_MSG_REQ_PING;
62 /* Send request and wait for response */
63 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
70 /* Message buffer free */
71 app_msg_free(app, rsp);
77 app_pipeline_stats_port_in(struct app_params *app,
80 struct rte_pipeline_port_in_stats *stats)
82 struct app_pipeline_params *p;
83 struct pipeline_stats_msg_req *req;
84 struct pipeline_stats_port_in_msg_rsp *rsp;
87 /* Check input arguments */
92 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
94 (port_id >= p->n_pktq_in))
97 /* Message buffer allocation */
98 req = app_msg_alloc(app);
102 /* Fill in request */
103 req->type = PIPELINE_MSG_REQ_STATS_PORT_IN;
106 /* Send request and wait for response */
107 rsp = (struct pipeline_stats_port_in_msg_rsp *)
108 app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
113 status = rsp->status;
115 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
117 /* Message buffer free */
118 app_msg_free(app, rsp);
124 app_pipeline_stats_port_out(struct app_params *app,
125 uint32_t pipeline_id,
127 struct rte_pipeline_port_out_stats *stats)
129 struct app_pipeline_params *p;
130 struct pipeline_stats_msg_req *req;
131 struct pipeline_stats_port_out_msg_rsp *rsp;
134 /* Check input arguments */
136 (pipeline_id >= app->n_pipelines) ||
140 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
142 (port_id >= p->n_pktq_out))
145 /* Message buffer allocation */
146 req = app_msg_alloc(app);
150 /* Fill in request */
151 req->type = PIPELINE_MSG_REQ_STATS_PORT_OUT;
154 /* Send request and wait for response */
155 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
160 status = rsp->status;
162 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
164 /* Message buffer free */
165 app_msg_free(app, rsp);
171 app_pipeline_stats_table(struct app_params *app,
172 uint32_t pipeline_id,
174 struct rte_pipeline_table_stats *stats)
176 struct app_pipeline_params *p;
177 struct pipeline_stats_msg_req *req;
178 struct pipeline_stats_table_msg_rsp *rsp;
181 /* Check input arguments */
186 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
190 /* Message buffer allocation */
191 req = app_msg_alloc(app);
195 /* Fill in request */
196 req->type = PIPELINE_MSG_REQ_STATS_TABLE;
199 /* Send request and wait for response */
200 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
205 status = rsp->status;
207 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
209 /* Message buffer free */
210 app_msg_free(app, rsp);
216 app_pipeline_port_in_enable(struct app_params *app,
217 uint32_t pipeline_id,
220 struct app_pipeline_params *p;
221 struct pipeline_port_in_msg_req *req;
222 struct pipeline_msg_rsp *rsp;
225 /* Check input arguments */
229 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
231 (port_id >= p->n_pktq_in))
234 /* Message buffer allocation */
235 req = app_msg_alloc(app);
239 /* Fill in request */
240 req->type = PIPELINE_MSG_REQ_PORT_IN_ENABLE;
241 req->port_id = port_id;
243 /* Send request and wait for response */
244 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
249 status = rsp->status;
251 /* Message buffer free */
252 app_msg_free(app, rsp);
258 app_pipeline_port_in_disable(struct app_params *app,
259 uint32_t pipeline_id,
262 struct app_pipeline_params *p;
263 struct pipeline_port_in_msg_req *req;
264 struct pipeline_msg_rsp *rsp;
267 /* Check input arguments */
271 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
273 (port_id >= p->n_pktq_in))
276 /* Message buffer allocation */
277 req = app_msg_alloc(app);
281 /* Fill in request */
282 req->type = PIPELINE_MSG_REQ_PORT_IN_DISABLE;
283 req->port_id = port_id;
285 /* Send request and wait for response */
286 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
291 status = rsp->status;
293 /* Message buffer free */
294 app_msg_free(app, rsp);
300 app_link_config(struct app_params *app,
305 struct app_link_params *p;
306 uint32_t i, netmask, host, bcast;
308 /* Check input arguments */
312 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
314 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
320 APP_LOG(app, HIGH, "%s is UP, please bring it DOWN first",
325 netmask = (~0U) << (32 - depth);
327 bcast = host | (~netmask);
330 (ip == UINT32_MAX) ||
333 APP_LOG(app, HIGH, "Illegal IP address");
337 for (i = 0; i < app->n_links; i++) {
338 struct app_link_params *link = &app->link_params[i];
340 if (strcmp(p->name, link->name) == 0)
343 if (link->ip == ip) {
345 "%s is already assigned this IP address",
351 if ((depth == 0) || (depth > 32)) {
352 APP_LOG(app, HIGH, "Illegal value for depth parameter "
358 /* Save link parameters */
361 if (ifm_add_ipv4_port(link_id, rte_bswap32(ip), depth) == IFM_FAILURE)
368 void convert_prefixlen_to_netmask_ipv6(uint32_t depth, uint8_t netmask_ipv6[])
372 memset(netmask_ipv6, 0, 16);
377 for (i = 0; i < div; i++)
378 netmask_ipv6[i] = 0xff;
380 netmask_ipv6[i] = (~0 << (8 - mod));
386 get_host_portion_ipv6(uint8_t ipv6[], uint8_t netmask[], uint8_t host_ipv6[])
390 for (i = 0; i < 16; i++) {
391 host_ipv6[i] = ipv6[i] & netmask[i];
398 get_bcast_portion_ipv6(uint8_t host[], uint8_t netmask[], uint8_t bcast_ipv6[])
402 for (i = 0; i < 16; i++) {
403 bcast_ipv6[i] = host[i] | ~netmask[i];
410 app_link_config_ipv6(struct app_params *app,
411 uint32_t link_id, uint8_t ipv6[], uint32_t depth)
413 struct app_link_params *p;
415 uint8_t netmask_ipv6[16], host[16], bcast[16];
417 /* Check input arguments */
421 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
423 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
429 APP_LOG(app, HIGH, "%s is UP, please bring it DOWN first",
434 convert_prefixlen_to_netmask_ipv6(depth, netmask_ipv6);
435 get_host_portion_ipv6(ipv6, netmask_ipv6, host);
436 get_bcast_portion_ipv6(host, netmask_ipv6, bcast);
438 for (i = 0; i < app->n_links; i++) {
439 struct app_link_params *link = &app->link_params[i];
441 if (strcmp(p->name, link->name) == 0)
444 if (!memcmp(link->ipv6, ipv6, 16)) {
446 "%s is already assigned this IPv6 address",
452 if ((depth == 0) || (depth > 128)) {
453 APP_LOG(app, HIGH, "Illegal value for depth parameter "
454 "(%" PRIu32 ")", depth);
458 /* Save link parameters */
459 memcpy(p->ipv6, ipv6, 16);
461 p->depth_ipv6 = depth;
463 printf("IPv6: %x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x",
464 ipv6[0], ipv6[1], ipv6[2], ipv6[3], ipv6[4], ipv6[5],
465 ipv6[6], ipv6[7], ipv6[8], ipv6[9], ipv6[10], ipv6[11],
466 ipv6[12], ipv6[13], ipv6[14], ipv6[15]);
468 if (ifm_add_ipv6_port(link_id, ipv6, depth) == IFM_FAILURE)
474 app_link_up(struct app_params *app,
477 struct app_link_params *p;
479 /* Check input arguments */
483 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
485 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
490 /* Check link state */
492 APP_LOG(app, HIGH, "%s is already UP", p->name);
496 /* Check that IP address is valid */
501 if ((p->ip || memcmp(p->ipv6, temp, 16)) == 0) {
502 APP_LOG(app, HIGH, "%s IP address is not set", p->name);
506 app_link_up_internal(app, p);
512 app_link_down(struct app_params *app,
515 struct app_link_params *p;
517 /* Check input arguments */
521 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
523 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
528 /* Check link state */
530 APP_LOG(app, HIGH, "%s is already DOWN", p->name);
534 app_link_down_internal(app, p);
542 struct cmd_routeadd_config_result {
543 cmdline_fixed_string_t routeadd_string;
546 cmdline_fixed_string_t depth;
549 extern struct lib_nd_route_table_entry lib_nd_route_table[MAX_ND_RT_ENTRY];
550 extern struct arp_data *p_arp_data;
551 extern uint32_t nd_route_tbl_index;
554 * This implements route add entries for ipv4
556 int app_routeadd_config_ipv4(struct app_params *app, uint32_t port_id,
557 uint32_t ip, uint32_t mask)
559 if (port_id > MAX_PORTS) {
560 printf("Max ports allowed is %d\n", MAX_PORTS);
564 printf("port id:%d ip: %x mask:%x", port_id, ip, mask);
566 struct lib_arp_route_table_entry *lentry =
567 &p_arp_data->lib_arp_route_table
570 p_arp_data->lib_arp_route_ent_cnt++;
573 lentry->port = port_id;
575 lentry->nh_mask = ip & mask;
581 * This implements route add entries for ipv6
583 int app_routeadd_config_ipv6(struct app_params *app, uint32_t port_id,
584 uint8_t ipv6[], uint32_t depth)
588 if (port_id > MAX_ND_RT_ENTRY) {
589 printf("Max ports allowed is %d\n", MAX_ND_RT_ENTRY);
593 if (port_id >= nd_route_tbl_index)
594 nd_route_tbl_index++;
596 printf("port id:%d depth:%d\n", port_id, depth);
597 printf("ipv6 address ");
598 for (i = 0; i < 16; i++) {
599 lib_nd_route_table[port_id].ipv6[i] = ipv6[i];
600 lib_nd_route_table[port_id].nhipv6[i] = ipv6[i];
601 printf("%x ", ipv6[i]);
606 lib_nd_route_table[port_id].depth = depth;
607 lib_nd_route_table[port_id].port = port_id;
609 printf("num ports :%d\n", nd_route_tbl_index);
615 * cmd handler for handling route add entry at runtime.
616 * the same handle takes care of both ipv4 & ipv6
621 __attribute__((unused)) struct cmdline *cl,
624 struct cmd_routeadd_config_result *params = parsed_result;
625 struct app_params *app = data;
628 uint32_t port_id = params->port_id;
629 uint32_t i, ip, depth, mask;
631 if (params->ip.family == AF_INET) {
632 ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr);
633 mask = strtoul(params->depth, NULL, 16);
634 printf("ip:%x mask:%x port_id:%d\n", ip, mask, port_id);
637 memcpy(ipv6, params->ip.addr.ipv6.s6_addr, 16);
638 depth = atoi(params->depth);
640 printf("%d ", ipv6[i]);
641 printf("\n port_id:%d depth:%d \n", port_id, depth);
645 if (params->ip.family == AF_INET)
646 status = app_routeadd_config_ipv4(app, port_id, ip, mask);
648 status = app_routeadd_config_ipv6(app, port_id, ipv6, depth);
651 printf("Command failed\n");
653 printf("Command Success\n");
656 cmdline_parse_token_string_t cmd_routeadd_config_string =
657 TOKEN_STRING_INITIALIZER(struct cmd_routeadd_config_result, routeadd_string,
660 cmdline_parse_token_num_t cmd_routeadd_config_port_id =
661 TOKEN_NUM_INITIALIZER(struct cmd_routeadd_config_result, port_id, UINT32);
663 cmdline_parse_token_ipaddr_t cmd_routeadd_config_ip =
664 TOKEN_IPADDR_INITIALIZER(struct cmd_routeadd_config_result, ip);
666 cmdline_parse_token_string_t cmd_routeadd_config_depth_string =
667 TOKEN_STRING_INITIALIZER(struct cmd_routeadd_config_result, depth, NULL);
669 cmdline_parse_inst_t cmd_routeadd = {
670 .f = cmd_routeadd_parsed,
672 .help_str = "Add Route entry",
674 (void *) &cmd_routeadd_config_string,
675 (void *) &cmd_routeadd_config_port_id,
676 (void *) &cmd_routeadd_config_ip,
677 (void *) &cmd_routeadd_config_depth_string,
686 struct cmd_ping_result {
687 cmdline_fixed_string_t p_string;
688 uint32_t pipeline_id;
689 cmdline_fixed_string_t ping_string;
695 __rte_unused struct cmdline *cl,
698 struct cmd_ping_result *params = parsed_result;
699 struct app_params *app = data;
702 status = app_pipeline_ping(app, params->pipeline_id);
704 printf("Command failed\n");
707 cmdline_parse_token_string_t cmd_ping_p_string =
708 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, p_string, "p");
710 cmdline_parse_token_num_t cmd_ping_pipeline_id =
711 TOKEN_NUM_INITIALIZER(struct cmd_ping_result, pipeline_id, UINT32);
713 cmdline_parse_token_string_t cmd_ping_ping_string =
714 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, ping_string, "ping");
716 cmdline_parse_inst_t cmd_ping = {
717 .f = cmd_ping_parsed,
719 .help_str = "Pipeline ping",
721 (void *) &cmd_ping_p_string,
722 (void *) &cmd_ping_pipeline_id,
723 (void *) &cmd_ping_ping_string,
732 struct cmd_stats_port_in_result {
733 cmdline_fixed_string_t p_string;
734 uint32_t pipeline_id;
735 cmdline_fixed_string_t stats_string;
736 cmdline_fixed_string_t port_string;
737 cmdline_fixed_string_t in_string;
742 cmd_stats_port_in_parsed(
744 __rte_unused struct cmdline *cl,
747 struct cmd_stats_port_in_result *params = parsed_result;
748 struct app_params *app = data;
749 struct rte_pipeline_port_in_stats stats;
752 status = app_pipeline_stats_port_in(app,
758 printf("Command failed\n");
763 printf("Pipeline %" PRIu32 " - stats for input port %" PRIu32 ":\n"
764 "\tPkts in: %" PRIu64 "\n"
765 "\tPkts dropped by AH: %" PRIu64 "\n"
766 "\tPkts dropped by other: %" PRIu64 "\n",
769 stats.stats.n_pkts_in,
770 stats.n_pkts_dropped_by_ah,
771 stats.stats.n_pkts_drop);
774 cmdline_parse_token_string_t cmd_stats_port_in_p_string =
775 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, p_string,
778 cmdline_parse_token_num_t cmd_stats_port_in_pipeline_id =
779 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, pipeline_id,
782 cmdline_parse_token_string_t cmd_stats_port_in_stats_string =
783 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, stats_string,
786 cmdline_parse_token_string_t cmd_stats_port_in_port_string =
787 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, port_string,
790 cmdline_parse_token_string_t cmd_stats_port_in_in_string =
791 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, in_string,
794 cmdline_parse_token_num_t cmd_stats_port_in_port_in_id =
795 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, port_in_id,
798 cmdline_parse_inst_t cmd_stats_port_in = {
799 .f = cmd_stats_port_in_parsed,
801 .help_str = "Pipeline input port stats",
803 (void *) &cmd_stats_port_in_p_string,
804 (void *) &cmd_stats_port_in_pipeline_id,
805 (void *) &cmd_stats_port_in_stats_string,
806 (void *) &cmd_stats_port_in_port_string,
807 (void *) &cmd_stats_port_in_in_string,
808 (void *) &cmd_stats_port_in_port_in_id,
817 struct cmd_stats_port_out_result {
818 cmdline_fixed_string_t p_string;
819 uint32_t pipeline_id;
820 cmdline_fixed_string_t stats_string;
821 cmdline_fixed_string_t port_string;
822 cmdline_fixed_string_t out_string;
823 uint32_t port_out_id;
827 cmd_stats_port_out_parsed(
829 __rte_unused struct cmdline *cl,
833 struct cmd_stats_port_out_result *params = parsed_result;
834 struct app_params *app = data;
835 struct rte_pipeline_port_out_stats stats;
838 status = app_pipeline_stats_port_out(app,
844 printf("Command failed\n");
849 printf("Pipeline %" PRIu32 " - stats for output port %" PRIu32 ":\n"
850 "\tPkts in: %" PRIu64 "\n"
851 "\tPkts dropped by AH: %" PRIu64 "\n"
852 "\tPkts dropped by other: %" PRIu64 "\n",
855 stats.stats.n_pkts_in,
856 stats.n_pkts_dropped_by_ah,
857 stats.stats.n_pkts_drop);
860 cmdline_parse_token_string_t cmd_stats_port_out_p_string =
861 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, p_string,
864 cmdline_parse_token_num_t cmd_stats_port_out_pipeline_id =
865 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, pipeline_id,
868 cmdline_parse_token_string_t cmd_stats_port_out_stats_string =
869 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, stats_string,
872 cmdline_parse_token_string_t cmd_stats_port_out_port_string =
873 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, port_string,
876 cmdline_parse_token_string_t cmd_stats_port_out_out_string =
877 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, out_string,
880 cmdline_parse_token_num_t cmd_stats_port_out_port_out_id =
881 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, port_out_id,
884 cmdline_parse_inst_t cmd_stats_port_out = {
885 .f = cmd_stats_port_out_parsed,
887 .help_str = "Pipeline output port stats",
889 (void *) &cmd_stats_port_out_p_string,
890 (void *) &cmd_stats_port_out_pipeline_id,
891 (void *) &cmd_stats_port_out_stats_string,
892 (void *) &cmd_stats_port_out_port_string,
893 (void *) &cmd_stats_port_out_out_string,
894 (void *) &cmd_stats_port_out_port_out_id,
903 struct cmd_stats_table_result {
904 cmdline_fixed_string_t p_string;
905 uint32_t pipeline_id;
906 cmdline_fixed_string_t stats_string;
907 cmdline_fixed_string_t table_string;
912 cmd_stats_table_parsed(
914 __rte_unused struct cmdline *cl,
917 struct cmd_stats_table_result *params = parsed_result;
918 struct app_params *app = data;
919 struct rte_pipeline_table_stats stats;
922 status = app_pipeline_stats_table(app,
928 printf("Command failed\n");
933 printf("Pipeline %" PRIu32 " - stats for table %" PRIu32 ":\n"
934 "\tPkts in: %" PRIu64 "\n"
935 "\tPkts in with lookup miss: %" PRIu64 "\n"
936 "\tPkts in with lookup hit dropped by AH: %" PRIu64 "\n"
937 "\tPkts in with lookup hit dropped by others: %" PRIu64 "\n"
938 "\tPkts in with lookup miss dropped by AH: %" PRIu64 "\n"
939 "\tPkts in with lookup miss dropped by others: %" PRIu64 "\n",
942 stats.stats.n_pkts_in,
943 stats.stats.n_pkts_lookup_miss,
944 stats.n_pkts_dropped_by_lkp_hit_ah,
945 stats.n_pkts_dropped_lkp_hit,
946 stats.n_pkts_dropped_by_lkp_miss_ah,
947 stats.n_pkts_dropped_lkp_miss);
950 cmdline_parse_token_string_t cmd_stats_table_p_string =
951 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, p_string,
954 cmdline_parse_token_num_t cmd_stats_table_pipeline_id =
955 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, pipeline_id,
958 cmdline_parse_token_string_t cmd_stats_table_stats_string =
959 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, stats_string,
962 cmdline_parse_token_string_t cmd_stats_table_table_string =
963 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, table_string,
966 cmdline_parse_token_num_t cmd_stats_table_table_id =
967 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, table_id, UINT32);
969 cmdline_parse_inst_t cmd_stats_table = {
970 .f = cmd_stats_table_parsed,
972 .help_str = "Pipeline table stats",
974 (void *) &cmd_stats_table_p_string,
975 (void *) &cmd_stats_table_pipeline_id,
976 (void *) &cmd_stats_table_stats_string,
977 (void *) &cmd_stats_table_table_string,
978 (void *) &cmd_stats_table_table_id,
987 struct cmd_port_in_enable_result {
988 cmdline_fixed_string_t p_string;
989 uint32_t pipeline_id;
990 cmdline_fixed_string_t port_string;
991 cmdline_fixed_string_t in_string;
993 cmdline_fixed_string_t enable_string;
997 cmd_port_in_enable_parsed(
999 __rte_unused struct cmdline *cl,
1002 struct cmd_port_in_enable_result *params = parsed_result;
1003 struct app_params *app = data;
1006 status = app_pipeline_port_in_enable(app,
1007 params->pipeline_id,
1008 params->port_in_id);
1011 printf("Command failed\n");
1014 cmdline_parse_token_string_t cmd_port_in_enable_p_string =
1015 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, p_string,
1018 cmdline_parse_token_num_t cmd_port_in_enable_pipeline_id =
1019 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, pipeline_id,
1022 cmdline_parse_token_string_t cmd_port_in_enable_port_string =
1023 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, port_string,
1026 cmdline_parse_token_string_t cmd_port_in_enable_in_string =
1027 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, in_string,
1030 cmdline_parse_token_num_t cmd_port_in_enable_port_in_id =
1031 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, port_in_id,
1034 cmdline_parse_token_string_t cmd_port_in_enable_enable_string =
1035 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result,
1036 enable_string, "enable");
1038 cmdline_parse_inst_t cmd_port_in_enable = {
1039 .f = cmd_port_in_enable_parsed,
1041 .help_str = "Pipeline input port enable",
1043 (void *) &cmd_port_in_enable_p_string,
1044 (void *) &cmd_port_in_enable_pipeline_id,
1045 (void *) &cmd_port_in_enable_port_string,
1046 (void *) &cmd_port_in_enable_in_string,
1047 (void *) &cmd_port_in_enable_port_in_id,
1048 (void *) &cmd_port_in_enable_enable_string,
1057 struct cmd_port_in_disable_result {
1058 cmdline_fixed_string_t p_string;
1059 uint32_t pipeline_id;
1060 cmdline_fixed_string_t port_string;
1061 cmdline_fixed_string_t in_string;
1062 uint32_t port_in_id;
1063 cmdline_fixed_string_t disable_string;
1067 cmd_port_in_disable_parsed(
1068 void *parsed_result,
1069 __rte_unused struct cmdline *cl,
1072 struct cmd_port_in_disable_result *params = parsed_result;
1073 struct app_params *app = data;
1076 status = app_pipeline_port_in_disable(app,
1077 params->pipeline_id,
1078 params->port_in_id);
1081 printf("Command failed\n");
1084 cmdline_parse_token_string_t cmd_port_in_disable_p_string =
1085 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, p_string,
1088 cmdline_parse_token_num_t cmd_port_in_disable_pipeline_id =
1089 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, pipeline_id,
1092 cmdline_parse_token_string_t cmd_port_in_disable_port_string =
1093 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, port_string,
1096 cmdline_parse_token_string_t cmd_port_in_disable_in_string =
1097 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, in_string,
1100 cmdline_parse_token_num_t cmd_port_in_disable_port_in_id =
1101 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, port_in_id,
1104 cmdline_parse_token_string_t cmd_port_in_disable_disable_string =
1105 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result,
1106 disable_string, "disable");
1108 cmdline_parse_inst_t cmd_port_in_disable = {
1109 .f = cmd_port_in_disable_parsed,
1111 .help_str = "Pipeline input port disable",
1113 (void *) &cmd_port_in_disable_p_string,
1114 (void *) &cmd_port_in_disable_pipeline_id,
1115 (void *) &cmd_port_in_disable_port_string,
1116 (void *) &cmd_port_in_disable_in_string,
1117 (void *) &cmd_port_in_disable_port_in_id,
1118 (void *) &cmd_port_in_disable_disable_string,
1128 print_link_info(struct app_link_params *p)
1130 struct rte_eth_stats stats;
1131 struct ether_addr *mac_addr;
1132 uint32_t netmask = (~0U) << (32 - p->depth);
1133 uint32_t host = p->ip & netmask;
1134 uint32_t bcast = host | (~netmask);
1136 memset(&stats, 0, sizeof(stats));
1137 rte_eth_stats_get(p->pmd_id, &stats);
1139 mac_addr = (struct ether_addr *) &p->mac_addr;
1141 if (strlen(p->pci_bdf))
1142 printf("%s(%s): flags=<%s>\n",
1145 (p->state) ? "UP" : "DOWN");
1147 printf("%s: flags=<%s>\n",
1149 (p->state) ? "UP" : "DOWN");
1152 printf("\tinet %" PRIu32 ".%" PRIu32
1153 ".%" PRIu32 ".%" PRIu32
1154 " netmask %" PRIu32 ".%" PRIu32
1155 ".%" PRIu32 ".%" PRIu32 " "
1156 "broadcast %" PRIu32 ".%" PRIu32
1157 ".%" PRIu32 ".%" PRIu32 "\n",
1158 (p->ip >> 24) & 0xFF,
1159 (p->ip >> 16) & 0xFF,
1160 (p->ip >> 8) & 0xFF,
1162 (netmask >> 24) & 0xFF,
1163 (netmask >> 16) & 0xFF,
1164 (netmask >> 8) & 0xFF,
1166 (bcast >> 24) & 0xFF,
1167 (bcast >> 16) & 0xFF,
1168 (bcast >> 8) & 0xFF,
1171 printf("\tether %02" PRIx32 ":%02" PRIx32 ":%02" PRIx32
1172 ":%02" PRIx32 ":%02" PRIx32 ":%02" PRIx32 "\n",
1173 mac_addr->addr_bytes[0],
1174 mac_addr->addr_bytes[1],
1175 mac_addr->addr_bytes[2],
1176 mac_addr->addr_bytes[3],
1177 mac_addr->addr_bytes[4],
1178 mac_addr->addr_bytes[5]);
1180 printf("\tRX packets %" PRIu64
1186 printf("\tRX errors %" PRIu64
1194 printf("\tTX packets %" PRIu64
1195 " bytes %" PRIu64 "\n",
1199 printf("\tTX errors %" PRIu64
1206 struct cmd_link_config_result {
1207 cmdline_fixed_string_t link_string;
1209 cmdline_fixed_string_t config_string;
1210 cmdline_ipaddr_t ip;
1215 cmd_link_config_parsed(
1216 void *parsed_result,
1217 __attribute__((unused)) struct cmdline *cl,
1220 struct cmd_link_config_result *params = parsed_result;
1221 struct app_params *app = data;
1224 uint32_t link_id = params->link_id;
1227 if (params->ip.family == AF_INET)
1228 ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr);
1230 memcpy(ipv6, params->ip.addr.ipv6.s6_addr, 16);
1232 uint32_t depth = params->depth;
1234 if (params->ip.family == AF_INET)
1235 status = app_link_config(app, link_id, ip, depth);
1237 status = app_link_config_ipv6(app, link_id, ipv6, depth);
1240 printf("Command failed\n");
1242 struct app_link_params *p;
1244 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1250 cmdline_parse_token_string_t cmd_link_config_link_string =
1251 TOKEN_STRING_INITIALIZER(struct cmd_link_config_result, link_string,
1254 cmdline_parse_token_num_t cmd_link_config_link_id =
1255 TOKEN_NUM_INITIALIZER(struct cmd_link_config_result, link_id, UINT32);
1257 cmdline_parse_token_string_t cmd_link_config_config_string =
1258 TOKEN_STRING_INITIALIZER(struct cmd_link_config_result, config_string,
1261 cmdline_parse_token_ipaddr_t cmd_link_config_ip =
1262 TOKEN_IPADDR_INITIALIZER(struct cmd_link_config_result, ip);
1264 cmdline_parse_token_num_t cmd_link_config_depth =
1265 TOKEN_NUM_INITIALIZER(struct cmd_link_config_result, depth, UINT32);
1267 cmdline_parse_inst_t cmd_link_config = {
1268 .f = cmd_link_config_parsed,
1270 .help_str = "Link configuration",
1272 (void *)&cmd_link_config_link_string,
1273 (void *)&cmd_link_config_link_id,
1274 (void *)&cmd_link_config_config_string,
1275 (void *)&cmd_link_config_ip,
1276 (void *)&cmd_link_config_depth,
1285 struct cmd_link_up_result {
1286 cmdline_fixed_string_t link_string;
1288 cmdline_fixed_string_t up_string;
1293 void *parsed_result,
1294 __attribute__((unused)) struct cmdline *cl,
1297 struct cmd_link_up_result *params = parsed_result;
1298 struct app_params *app = data;
1301 status = app_link_up(app, params->link_id);
1303 printf("Command failed\n");
1305 struct app_link_params *p;
1307 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", params->link_id,
1314 cmdline_parse_token_string_t cmd_link_up_link_string =
1315 TOKEN_STRING_INITIALIZER(struct cmd_link_up_result, link_string,
1318 cmdline_parse_token_num_t cmd_link_up_link_id =
1319 TOKEN_NUM_INITIALIZER(struct cmd_link_up_result, link_id, UINT32);
1321 cmdline_parse_token_string_t cmd_link_up_up_string =
1322 TOKEN_STRING_INITIALIZER(struct cmd_link_up_result, up_string, "up");
1324 cmdline_parse_inst_t cmd_link_up = {
1325 .f = cmd_link_up_parsed,
1327 .help_str = "Link UP",
1329 (void *)&cmd_link_up_link_string,
1330 (void *)&cmd_link_up_link_id,
1331 (void *)&cmd_link_up_up_string,
1340 struct cmd_link_down_result {
1341 cmdline_fixed_string_t link_string;
1343 cmdline_fixed_string_t down_string;
1347 cmd_link_down_parsed(
1348 void *parsed_result,
1349 __attribute__((unused)) struct cmdline *cl,
1352 struct cmd_link_down_result *params = parsed_result;
1353 struct app_params *app = data;
1356 status = app_link_down(app, params->link_id);
1358 printf("Command failed\n");
1360 struct app_link_params *p;
1362 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", params->link_id,
1369 cmdline_parse_token_string_t cmd_link_down_link_string =
1370 TOKEN_STRING_INITIALIZER(struct cmd_link_down_result, link_string,
1373 cmdline_parse_token_num_t cmd_link_down_link_id =
1374 TOKEN_NUM_INITIALIZER(struct cmd_link_down_result, link_id, UINT32);
1376 cmdline_parse_token_string_t cmd_link_down_down_string =
1377 TOKEN_STRING_INITIALIZER(struct cmd_link_down_result, down_string,
1380 cmdline_parse_inst_t cmd_link_down = {
1381 .f = cmd_link_down_parsed,
1383 .help_str = "Link DOWN",
1385 (void *) &cmd_link_down_link_string,
1386 (void *) &cmd_link_down_link_id,
1387 (void *) &cmd_link_down_down_string,
1396 struct cmd_link_ls_result {
1397 cmdline_fixed_string_t link_string;
1398 cmdline_fixed_string_t ls_string;
1403 __attribute__((unused)) void *parsed_result,
1404 __attribute__((unused)) struct cmdline *cl,
1407 struct app_params *app = data;
1410 for (link_id = 0; link_id < app->n_links; link_id++) {
1411 struct app_link_params *p;
1413 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1417 print_interface_details();
1420 cmdline_parse_token_string_t cmd_link_ls_link_string =
1421 TOKEN_STRING_INITIALIZER(struct cmd_link_ls_result, link_string,
1424 cmdline_parse_token_string_t cmd_link_ls_ls_string =
1425 TOKEN_STRING_INITIALIZER(struct cmd_link_ls_result, ls_string, "ls");
1427 cmdline_parse_inst_t cmd_link_ls = {
1428 .f = cmd_link_ls_parsed,
1430 .help_str = "Link list",
1432 (void *)&cmd_link_ls_link_string,
1433 (void *)&cmd_link_ls_ls_string,
1442 struct cmd_quit_result {
1443 cmdline_fixed_string_t quit;
1448 __rte_unused void *parsed_result,
1450 __rte_unused void *data)
1455 static cmdline_parse_token_string_t cmd_quit_quit =
1456 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
1458 static cmdline_parse_inst_t cmd_quit = {
1459 .f = cmd_quit_parsed,
1463 (void *) &cmd_quit_quit,
1474 cmdline_parse_ctx_t *ctx,
1475 const char *file_name)
1477 struct cmdline *file_cl;
1480 fd = open(file_name, O_RDONLY);
1482 printf("Cannot open file \"%s\"\n", file_name);
1486 file_cl = cmdline_new(ctx, "", fd, 1);
1487 cmdline_interact(file_cl);
1491 struct cmd_run_file_result {
1492 cmdline_fixed_string_t run_string;
1493 char file_name[APP_FILE_NAME_SIZE];
1498 void *parsed_result,
1500 __attribute__((unused)) void *data)
1502 struct cmd_run_file_result *params = parsed_result;
1504 app_run_file(cl->ctx, params->file_name);
1507 cmdline_parse_token_string_t cmd_run_run_string =
1508 TOKEN_STRING_INITIALIZER(struct cmd_run_file_result, run_string,
1511 cmdline_parse_token_string_t cmd_run_file_name =
1512 TOKEN_STRING_INITIALIZER(struct cmd_run_file_result, file_name, NULL);
1514 cmdline_parse_inst_t cmd_run = {
1515 .f = cmd_run_parsed,
1517 .help_str = "Run CLI script file",
1519 (void *) &cmd_run_run_string,
1520 (void *) &cmd_run_file_name,
1525 static cmdline_parse_ctx_t pipeline_common_cmds[] = {
1526 (cmdline_parse_inst_t *) &cmd_quit,
1527 (cmdline_parse_inst_t *) &cmd_run,
1528 (cmdline_parse_inst_t *) &cmd_routeadd,
1530 (cmdline_parse_inst_t *) &cmd_link_config,
1531 (cmdline_parse_inst_t *) &cmd_link_up,
1532 (cmdline_parse_inst_t *) &cmd_link_down,
1533 (cmdline_parse_inst_t *) &cmd_link_ls,
1535 (cmdline_parse_inst_t *) &cmd_ping,
1536 (cmdline_parse_inst_t *) &cmd_stats_port_in,
1537 (cmdline_parse_inst_t *) &cmd_stats_port_out,
1538 (cmdline_parse_inst_t *) &cmd_stats_table,
1539 (cmdline_parse_inst_t *) &cmd_port_in_enable,
1540 (cmdline_parse_inst_t *) &cmd_port_in_disable,
1545 app_pipeline_common_cmd_push(struct app_params *app)
1549 /* Check for available slots in the application commands array */
1550 n_cmds = RTE_DIM(pipeline_common_cmds) - 1;
1551 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1554 /* Push pipeline commands into the application */
1555 memcpy(&app->cmds[app->n_cmds],
1556 pipeline_common_cmds,
1557 n_cmds * sizeof(cmdline_parse_ctx_t));
1559 for (i = 0; i < n_cmds; i++)
1560 app->cmds[app->n_cmds + i]->data = app;
1562 app->n_cmds += n_cmds;
1563 app->cmds[app->n_cmds] = NULL;