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 void app_run_file(cmdline_parse_ctx_t *ctx, const char *file_name);
41 app_pipeline_ping(struct app_params *app,
44 struct app_pipeline_params *p;
45 struct pipeline_msg_req *req;
46 struct pipeline_msg_rsp *rsp;
49 /* Check input arguments */
53 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
57 /* Message buffer allocation */
58 req = app_msg_alloc(app);
63 req->type = PIPELINE_MSG_REQ_PING;
65 /* Send request and wait for response */
66 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
73 /* Message buffer free */
74 app_msg_free(app, rsp);
80 app_pipeline_stats_port_in(struct app_params *app,
83 struct rte_pipeline_port_in_stats *stats)
85 struct app_pipeline_params *p;
86 struct pipeline_stats_msg_req *req;
87 struct pipeline_stats_port_in_msg_rsp *rsp;
90 /* Check input arguments */
95 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
97 (port_id >= p->n_pktq_in))
100 /* Message buffer allocation */
101 req = app_msg_alloc(app);
105 /* Fill in request */
106 req->type = PIPELINE_MSG_REQ_STATS_PORT_IN;
109 /* Send request and wait for response */
110 rsp = (struct pipeline_stats_port_in_msg_rsp *)
111 app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
116 status = rsp->status;
118 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
120 /* Message buffer free */
121 app_msg_free(app, rsp);
127 app_pipeline_stats_port_out(struct app_params *app,
128 uint32_t pipeline_id,
130 struct rte_pipeline_port_out_stats *stats)
132 struct app_pipeline_params *p;
133 struct pipeline_stats_msg_req *req;
134 struct pipeline_stats_port_out_msg_rsp *rsp;
137 /* Check input arguments */
139 (pipeline_id >= app->n_pipelines) ||
143 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
145 (port_id >= p->n_pktq_out))
148 /* Message buffer allocation */
149 req = app_msg_alloc(app);
153 /* Fill in request */
154 req->type = PIPELINE_MSG_REQ_STATS_PORT_OUT;
157 /* Send request and wait for response */
158 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
163 status = rsp->status;
165 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
167 /* Message buffer free */
168 app_msg_free(app, rsp);
174 app_pipeline_stats_table(struct app_params *app,
175 uint32_t pipeline_id,
177 struct rte_pipeline_table_stats *stats)
179 struct app_pipeline_params *p;
180 struct pipeline_stats_msg_req *req;
181 struct pipeline_stats_table_msg_rsp *rsp;
184 /* Check input arguments */
189 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
193 /* Message buffer allocation */
194 req = app_msg_alloc(app);
198 /* Fill in request */
199 req->type = PIPELINE_MSG_REQ_STATS_TABLE;
202 /* Send request and wait for response */
203 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
208 status = rsp->status;
210 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
212 /* Message buffer free */
213 app_msg_free(app, rsp);
219 app_pipeline_port_in_enable(struct app_params *app,
220 uint32_t pipeline_id,
223 struct app_pipeline_params *p;
224 struct pipeline_port_in_msg_req *req;
225 struct pipeline_msg_rsp *rsp;
228 /* Check input arguments */
232 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
234 (port_id >= p->n_pktq_in))
237 /* Message buffer allocation */
238 req = app_msg_alloc(app);
242 /* Fill in request */
243 req->type = PIPELINE_MSG_REQ_PORT_IN_ENABLE;
244 req->port_id = port_id;
246 /* Send request and wait for response */
247 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
252 status = rsp->status;
254 /* Message buffer free */
255 app_msg_free(app, rsp);
261 app_pipeline_port_in_disable(struct app_params *app,
262 uint32_t pipeline_id,
265 struct app_pipeline_params *p;
266 struct pipeline_port_in_msg_req *req;
267 struct pipeline_msg_rsp *rsp;
270 /* Check input arguments */
274 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
276 (port_id >= p->n_pktq_in))
279 /* Message buffer allocation */
280 req = app_msg_alloc(app);
284 /* Fill in request */
285 req->type = PIPELINE_MSG_REQ_PORT_IN_DISABLE;
286 req->port_id = port_id;
288 /* Send request and wait for response */
289 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
294 status = rsp->status;
296 /* Message buffer free */
297 app_msg_free(app, rsp);
303 app_link_config(struct app_params *app,
308 struct app_link_params *p;
309 uint32_t i, netmask, host, bcast;
311 /* Check input arguments */
315 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
317 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
323 APP_LOG(app, HIGH, "%s is UP, please bring it DOWN first",
328 netmask = (~0U) << (32 - depth);
330 bcast = host | (~netmask);
333 (ip == UINT32_MAX) ||
336 APP_LOG(app, HIGH, "Illegal IP address");
340 for (i = 0; i < app->n_links; i++) {
341 struct app_link_params *link = &app->link_params[i];
343 if (strcmp(p->name, link->name) == 0)
346 if (link->ip == ip) {
348 "%s is already assigned this IP address",
354 if ((depth == 0) || (depth > 32)) {
355 APP_LOG(app, HIGH, "Illegal value for depth parameter "
361 /* Save link parameters */
364 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]);
471 if (ifm_add_ipv6_port(link_id, ipv6, depth) == IFM_FAILURE)
477 app_link_up(struct app_params *app,
480 struct app_link_params *p;
482 /* Check input arguments */
486 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
488 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
493 /* Check link state */
495 APP_LOG(app, HIGH, "%s is already UP", p->name);
499 /* Check that IP address is valid */
504 if ((p->ip || memcmp(p->ipv6, temp, 16)) == 0) {
505 APP_LOG(app, HIGH, "%s IP address is not set", p->name);
509 app_link_up_internal(app, p);
515 app_link_down(struct app_params *app,
518 struct app_link_params *p;
520 /* Check input arguments */
524 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
526 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
531 /* Check link state */
533 APP_LOG(app, HIGH, "%s is already DOWN", p->name);
537 app_link_down_internal(app, p);
545 struct cmd_routeadd_config_result {
546 cmdline_fixed_string_t routeadd_string;
547 cmdline_fixed_string_t type_string;
550 cmdline_fixed_string_t depth;
553 extern struct arp_data *p_arp_data;
554 extern uint32_t nd_route_tbl_index;
557 * This implements route add entries for ipv4
559 int app_routeadd_config_ipv4(__attribute__((unused)) struct app_params *app,
560 uint32_t port_id, uint32_t ip, uint32_t mask)
563 if (port_id >= gw_get_num_ports()) {
564 printf("Max ports allowed is %d\n", gw_get_num_ports());
568 printf("port id:%d ip: %x mask:%x\n", port_id, ip, mask);
570 struct route_table_entry *lentry = NULL;
572 /* Check for matching entry */
573 for(i = 0 ; i< p_route_data[port_id]->route_ent_cnt; i++) {
575 lentry = &p_route_data[port_id]->route_table[i];
577 /* Entry already exists? */
582 if( lentry->nh_mask == (ip & mask))
586 if(i < MAX_ROUTE_ENTRY_SIZE) {
588 lentry = &p_route_data[port_id]->route_table[i];
590 p_route_data[port_id]->route_ent_cnt++;
592 lentry->port = port_id;
594 lentry->nh_mask = (ip & mask);
595 /* Set the VNF Gateway flag */
600 printf("Error: Number of entries more than supported\n");
607 * This implements route add entries for ipv6
609 int app_routeadd_config_ipv6(__attribute__((unused)) struct app_params *app,
610 uint32_t port_id, uint8_t ipv6[], uint32_t depth)
614 if (port_id >= gw_get_num_ports()) {
615 printf("Max ports allowed is %d\n", gw_get_num_ports());
619 if (port_id >= nd_route_tbl_index)
620 nd_route_tbl_index++;
622 printf("port id:%d depth:%d\n", port_id, depth);
623 printf("ipv6 address: ");
624 for(i = 0; i < IPV6_ADD_SIZE; i++)
625 printf("%02x ", ipv6[i]);
628 struct nd_route_table_entry *lentry = NULL;
630 uint8_t netmask_ipv6[16], netip_nd[16], netip_in[16];
631 uint8_t depthflags = 0, depthflags1 = 0;
635 /* Check for matching entry */
636 for(i = 0 ; i< p_nd_route_data[port_id]->nd_route_ent_cnt; i++) {
638 lentry = &p_nd_route_data[port_id]->nd_route_table[i];
640 memset(netmask_ipv6, 0, sizeof(netmask_ipv6));
641 memset(netip_nd, 0, sizeof(netip_nd));
642 memset(netip_in, 0, sizeof(netip_in));
644 /* Create netmask from depth */
645 convert_prefixlen_to_netmask_ipv6(lentry->depth, netmask_ipv6);
647 for (k = 0; k < 16; k++) {
648 if (lentry->nhipv6[k] & netmask_ipv6[k]) {
650 netip_nd[k] = lentry->nhipv6[k];
653 if (ipv6[k] & netmask_ipv6[k]) {
655 netip_in[k] = ipv6[k];
659 if ((depthflags == depthflags1)
660 && (memcmp(netip_nd, netip_in, sizeof(netip_nd)) == 0)) {
661 /* Route already exists */
662 printf("Route already exists \n");
667 if(i < MAX_ND_ROUTE_ENTRY_SIZE) {
669 lentry = &p_nd_route_data[port_id]->nd_route_table[i];
671 rte_mov16(lentry->nhipv6, ipv6);
673 lentry->depth = depth;
674 lentry->port = port_id;
675 p_nd_route_data[port_id]->nd_route_ent_cnt++;
676 /* Set the VNF Gateway flag */
682 printf("Error: Number of entries more than supported\n");
688 * cmd handler for handling route abj entry at runtime.
689 * the same handle takes care of both ipv4 & ipv6
694 __attribute__((unused)) struct cmdline *cl,
697 struct cmd_routeadd_config_result *params = parsed_result;
698 struct app_params *app = data;
701 uint32_t port_id = params->port_id;
702 uint32_t i, ip = 0, depth = 0, mask = 0;
705 printf("Adding route for %s \n", params->type_string);
707 if (params->ip.family == AF_INET) {
708 ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr);
710 if(strcmp(params->type_string, "net") == 0)
712 mask = strtoul(params->depth, NULL, 16);
717 printf("nhip:0x%08x mask:%x port_id:%d\n", ip, mask, port_id);
719 memcpy(ipv6, params->ip.addr.ipv6.s6_addr, 16);
720 if(strcmp(params->type_string, "net") == 0)
722 depth = atoi(params->depth);
727 for (i=0; i < 16; i++)
728 printf("%02x ", ipv6[i]);
729 printf("\n port_id:%d depth:%d \n", port_id, depth);
733 if (params->ip.family == AF_INET)
734 status = app_routeadd_config_ipv4(app, port_id, ip, mask);
736 status = app_routeadd_config_ipv6(app, port_id, ipv6, depth);
739 printf("Command failed\n");
741 printf("Command Success\n");
744 cmdline_parse_token_string_t cmd_routeadd_config_string =
745 TOKEN_STRING_INITIALIZER(struct cmd_routeadd_config_result, routeadd_string,
748 cmdline_parse_token_string_t cmd_routeadd_net_string =
749 TOKEN_STRING_INITIALIZER(struct cmd_routeadd_config_result, type_string,
752 cmdline_parse_token_string_t cmd_routeadd_host_string =
753 TOKEN_STRING_INITIALIZER(struct cmd_routeadd_config_result, type_string,
756 cmdline_parse_token_num_t cmd_routeadd_config_port_id =
757 TOKEN_NUM_INITIALIZER(struct cmd_routeadd_config_result, port_id, UINT32);
759 cmdline_parse_token_ipaddr_t cmd_routeadd_config_ip =
760 TOKEN_IPADDR_INITIALIZER(struct cmd_routeadd_config_result, ip);
762 cmdline_parse_token_string_t cmd_routeadd_config_depth_string =
763 TOKEN_STRING_INITIALIZER(struct cmd_routeadd_config_result, depth, NULL);
765 cmdline_parse_inst_t cmd_routeadd_net = {
766 .f = cmd_routeadd_parsed,
768 .help_str = "Add Route entry for gateway",
770 (void *) &cmd_routeadd_config_string,
771 (void *) &cmd_routeadd_net_string,
772 (void *) &cmd_routeadd_config_port_id,
773 (void *) &cmd_routeadd_config_ip,
774 (void *) &cmd_routeadd_config_depth_string,
779 cmdline_parse_inst_t cmd_routeadd_host = {
780 .f = cmd_routeadd_parsed,
782 .help_str = "Add Route entry for host",
784 (void *) &cmd_routeadd_config_string,
785 (void *) &cmd_routeadd_host_string,
786 (void *) &cmd_routeadd_config_port_id,
787 (void *) &cmd_routeadd_config_ip,
796 struct cmd_ping_result {
797 cmdline_fixed_string_t p_string;
798 uint32_t pipeline_id;
799 cmdline_fixed_string_t ping_string;
805 __rte_unused struct cmdline *cl,
808 struct cmd_ping_result *params = parsed_result;
809 struct app_params *app = data;
812 status = app_pipeline_ping(app, params->pipeline_id);
814 printf("Command failed\n");
817 cmdline_parse_token_string_t cmd_ping_p_string =
818 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, p_string, "p");
820 cmdline_parse_token_num_t cmd_ping_pipeline_id =
821 TOKEN_NUM_INITIALIZER(struct cmd_ping_result, pipeline_id, UINT32);
823 cmdline_parse_token_string_t cmd_ping_ping_string =
824 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, ping_string, "ping");
826 cmdline_parse_inst_t cmd_ping = {
827 .f = cmd_ping_parsed,
829 .help_str = "Pipeline ping",
831 (void *) &cmd_ping_p_string,
832 (void *) &cmd_ping_pipeline_id,
833 (void *) &cmd_ping_ping_string,
842 struct cmd_stats_port_in_result {
843 cmdline_fixed_string_t p_string;
844 uint32_t pipeline_id;
845 cmdline_fixed_string_t stats_string;
846 cmdline_fixed_string_t port_string;
847 cmdline_fixed_string_t in_string;
852 cmd_stats_port_in_parsed(
854 __rte_unused struct cmdline *cl,
857 struct cmd_stats_port_in_result *params = parsed_result;
858 struct app_params *app = data;
859 struct rte_pipeline_port_in_stats stats;
862 status = app_pipeline_stats_port_in(app,
868 printf("Command failed\n");
873 printf("Pipeline %" PRIu32 " - stats for input port %" PRIu32 ":\n"
874 "\tPkts in: %" PRIu64 "\n"
875 "\tPkts dropped by AH: %" PRIu64 "\n"
876 "\tPkts dropped by other: %" PRIu64 "\n",
879 stats.stats.n_pkts_in,
880 stats.n_pkts_dropped_by_ah,
881 stats.stats.n_pkts_drop);
884 cmdline_parse_token_string_t cmd_stats_port_in_p_string =
885 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, p_string,
888 cmdline_parse_token_num_t cmd_stats_port_in_pipeline_id =
889 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, pipeline_id,
892 cmdline_parse_token_string_t cmd_stats_port_in_stats_string =
893 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, stats_string,
896 cmdline_parse_token_string_t cmd_stats_port_in_port_string =
897 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, port_string,
900 cmdline_parse_token_string_t cmd_stats_port_in_in_string =
901 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, in_string,
904 cmdline_parse_token_num_t cmd_stats_port_in_port_in_id =
905 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, port_in_id,
908 cmdline_parse_inst_t cmd_stats_port_in = {
909 .f = cmd_stats_port_in_parsed,
911 .help_str = "Pipeline input port stats",
913 (void *) &cmd_stats_port_in_p_string,
914 (void *) &cmd_stats_port_in_pipeline_id,
915 (void *) &cmd_stats_port_in_stats_string,
916 (void *) &cmd_stats_port_in_port_string,
917 (void *) &cmd_stats_port_in_in_string,
918 (void *) &cmd_stats_port_in_port_in_id,
927 struct cmd_stats_port_out_result {
928 cmdline_fixed_string_t p_string;
929 uint32_t pipeline_id;
930 cmdline_fixed_string_t stats_string;
931 cmdline_fixed_string_t port_string;
932 cmdline_fixed_string_t out_string;
933 uint32_t port_out_id;
937 cmd_stats_port_out_parsed(
939 __rte_unused struct cmdline *cl,
943 struct cmd_stats_port_out_result *params = parsed_result;
944 struct app_params *app = data;
945 struct rte_pipeline_port_out_stats stats;
948 status = app_pipeline_stats_port_out(app,
954 printf("Command failed\n");
959 printf("Pipeline %" PRIu32 " - stats for output port %" PRIu32 ":\n"
960 "\tPkts in: %" PRIu64 "\n"
961 "\tPkts dropped by AH: %" PRIu64 "\n"
962 "\tPkts dropped by other: %" PRIu64 "\n",
965 stats.stats.n_pkts_in,
966 stats.n_pkts_dropped_by_ah,
967 stats.stats.n_pkts_drop);
970 cmdline_parse_token_string_t cmd_stats_port_out_p_string =
971 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, p_string,
974 cmdline_parse_token_num_t cmd_stats_port_out_pipeline_id =
975 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, pipeline_id,
978 cmdline_parse_token_string_t cmd_stats_port_out_stats_string =
979 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, stats_string,
982 cmdline_parse_token_string_t cmd_stats_port_out_port_string =
983 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, port_string,
986 cmdline_parse_token_string_t cmd_stats_port_out_out_string =
987 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, out_string,
990 cmdline_parse_token_num_t cmd_stats_port_out_port_out_id =
991 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, port_out_id,
994 cmdline_parse_inst_t cmd_stats_port_out = {
995 .f = cmd_stats_port_out_parsed,
997 .help_str = "Pipeline output port stats",
999 (void *) &cmd_stats_port_out_p_string,
1000 (void *) &cmd_stats_port_out_pipeline_id,
1001 (void *) &cmd_stats_port_out_stats_string,
1002 (void *) &cmd_stats_port_out_port_string,
1003 (void *) &cmd_stats_port_out_out_string,
1004 (void *) &cmd_stats_port_out_port_out_id,
1013 struct cmd_stats_table_result {
1014 cmdline_fixed_string_t p_string;
1015 uint32_t pipeline_id;
1016 cmdline_fixed_string_t stats_string;
1017 cmdline_fixed_string_t table_string;
1022 cmd_stats_table_parsed(
1023 void *parsed_result,
1024 __rte_unused struct cmdline *cl,
1027 struct cmd_stats_table_result *params = parsed_result;
1028 struct app_params *app = data;
1029 struct rte_pipeline_table_stats stats;
1032 status = app_pipeline_stats_table(app,
1033 params->pipeline_id,
1038 printf("Command failed\n");
1043 printf("Pipeline %" PRIu32 " - stats for table %" PRIu32 ":\n"
1044 "\tPkts in: %" PRIu64 "\n"
1045 "\tPkts in with lookup miss: %" PRIu64 "\n"
1046 "\tPkts in with lookup hit dropped by AH: %" PRIu64 "\n"
1047 "\tPkts in with lookup hit dropped by others: %" PRIu64 "\n"
1048 "\tPkts in with lookup miss dropped by AH: %" PRIu64 "\n"
1049 "\tPkts in with lookup miss dropped by others: %" PRIu64 "\n",
1050 params->pipeline_id,
1052 stats.stats.n_pkts_in,
1053 stats.stats.n_pkts_lookup_miss,
1054 stats.n_pkts_dropped_by_lkp_hit_ah,
1055 stats.n_pkts_dropped_lkp_hit,
1056 stats.n_pkts_dropped_by_lkp_miss_ah,
1057 stats.n_pkts_dropped_lkp_miss);
1060 cmdline_parse_token_string_t cmd_stats_table_p_string =
1061 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, p_string,
1064 cmdline_parse_token_num_t cmd_stats_table_pipeline_id =
1065 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, pipeline_id,
1068 cmdline_parse_token_string_t cmd_stats_table_stats_string =
1069 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, stats_string,
1072 cmdline_parse_token_string_t cmd_stats_table_table_string =
1073 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, table_string,
1076 cmdline_parse_token_num_t cmd_stats_table_table_id =
1077 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, table_id, UINT32);
1079 cmdline_parse_inst_t cmd_stats_table = {
1080 .f = cmd_stats_table_parsed,
1082 .help_str = "Pipeline table stats",
1084 (void *) &cmd_stats_table_p_string,
1085 (void *) &cmd_stats_table_pipeline_id,
1086 (void *) &cmd_stats_table_stats_string,
1087 (void *) &cmd_stats_table_table_string,
1088 (void *) &cmd_stats_table_table_id,
1097 struct cmd_port_in_enable_result {
1098 cmdline_fixed_string_t p_string;
1099 uint32_t pipeline_id;
1100 cmdline_fixed_string_t port_string;
1101 cmdline_fixed_string_t in_string;
1102 uint32_t port_in_id;
1103 cmdline_fixed_string_t enable_string;
1107 cmd_port_in_enable_parsed(
1108 void *parsed_result,
1109 __rte_unused struct cmdline *cl,
1112 struct cmd_port_in_enable_result *params = parsed_result;
1113 struct app_params *app = data;
1116 status = app_pipeline_port_in_enable(app,
1117 params->pipeline_id,
1118 params->port_in_id);
1121 printf("Command failed\n");
1124 cmdline_parse_token_string_t cmd_port_in_enable_p_string =
1125 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, p_string,
1128 cmdline_parse_token_num_t cmd_port_in_enable_pipeline_id =
1129 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, pipeline_id,
1132 cmdline_parse_token_string_t cmd_port_in_enable_port_string =
1133 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, port_string,
1136 cmdline_parse_token_string_t cmd_port_in_enable_in_string =
1137 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, in_string,
1140 cmdline_parse_token_num_t cmd_port_in_enable_port_in_id =
1141 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, port_in_id,
1144 cmdline_parse_token_string_t cmd_port_in_enable_enable_string =
1145 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result,
1146 enable_string, "enable");
1148 cmdline_parse_inst_t cmd_port_in_enable = {
1149 .f = cmd_port_in_enable_parsed,
1151 .help_str = "Pipeline input port enable",
1153 (void *) &cmd_port_in_enable_p_string,
1154 (void *) &cmd_port_in_enable_pipeline_id,
1155 (void *) &cmd_port_in_enable_port_string,
1156 (void *) &cmd_port_in_enable_in_string,
1157 (void *) &cmd_port_in_enable_port_in_id,
1158 (void *) &cmd_port_in_enable_enable_string,
1167 struct cmd_port_in_disable_result {
1168 cmdline_fixed_string_t p_string;
1169 uint32_t pipeline_id;
1170 cmdline_fixed_string_t port_string;
1171 cmdline_fixed_string_t in_string;
1172 uint32_t port_in_id;
1173 cmdline_fixed_string_t disable_string;
1177 cmd_port_in_disable_parsed(
1178 void *parsed_result,
1179 __rte_unused struct cmdline *cl,
1182 struct cmd_port_in_disable_result *params = parsed_result;
1183 struct app_params *app = data;
1186 status = app_pipeline_port_in_disable(app,
1187 params->pipeline_id,
1188 params->port_in_id);
1191 printf("Command failed\n");
1194 cmdline_parse_token_string_t cmd_port_in_disable_p_string =
1195 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, p_string,
1198 cmdline_parse_token_num_t cmd_port_in_disable_pipeline_id =
1199 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, pipeline_id,
1202 cmdline_parse_token_string_t cmd_port_in_disable_port_string =
1203 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, port_string,
1206 cmdline_parse_token_string_t cmd_port_in_disable_in_string =
1207 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, in_string,
1210 cmdline_parse_token_num_t cmd_port_in_disable_port_in_id =
1211 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, port_in_id,
1214 cmdline_parse_token_string_t cmd_port_in_disable_disable_string =
1215 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result,
1216 disable_string, "disable");
1218 cmdline_parse_inst_t cmd_port_in_disable = {
1219 .f = cmd_port_in_disable_parsed,
1221 .help_str = "Pipeline input port disable",
1223 (void *) &cmd_port_in_disable_p_string,
1224 (void *) &cmd_port_in_disable_pipeline_id,
1225 (void *) &cmd_port_in_disable_port_string,
1226 (void *) &cmd_port_in_disable_in_string,
1227 (void *) &cmd_port_in_disable_port_in_id,
1228 (void *) &cmd_port_in_disable_disable_string,
1238 print_link_info(struct app_link_params *p)
1240 struct rte_eth_stats stats;
1241 struct ether_addr *mac_addr;
1242 uint32_t netmask = (~0U) << (32 - p->depth);
1243 uint32_t host = p->ip & netmask;
1244 uint32_t bcast = host | (~netmask);
1246 memset(&stats, 0, sizeof(stats));
1247 rte_eth_stats_get(p->pmd_id, &stats);
1249 mac_addr = (struct ether_addr *) &p->mac_addr;
1251 if (strlen(p->pci_bdf))
1252 printf("%s(%s): flags=<%s>\n",
1255 (p->state) ? "UP" : "DOWN");
1257 printf("%s: flags=<%s>\n",
1259 (p->state) ? "UP" : "DOWN");
1262 printf("\tinet %" PRIu32 ".%" PRIu32
1263 ".%" PRIu32 ".%" PRIu32
1264 " netmask %" PRIu32 ".%" PRIu32
1265 ".%" PRIu32 ".%" PRIu32 " "
1266 "broadcast %" PRIu32 ".%" PRIu32
1267 ".%" PRIu32 ".%" PRIu32 "\n",
1268 (p->ip >> 24) & 0xFF,
1269 (p->ip >> 16) & 0xFF,
1270 (p->ip >> 8) & 0xFF,
1272 (netmask >> 24) & 0xFF,
1273 (netmask >> 16) & 0xFF,
1274 (netmask >> 8) & 0xFF,
1276 (bcast >> 24) & 0xFF,
1277 (bcast >> 16) & 0xFF,
1278 (bcast >> 8) & 0xFF,
1281 printf("\tether %02" PRIx32 ":%02" PRIx32 ":%02" PRIx32
1282 ":%02" PRIx32 ":%02" PRIx32 ":%02" PRIx32 "\n",
1283 mac_addr->addr_bytes[0],
1284 mac_addr->addr_bytes[1],
1285 mac_addr->addr_bytes[2],
1286 mac_addr->addr_bytes[3],
1287 mac_addr->addr_bytes[4],
1288 mac_addr->addr_bytes[5]);
1290 printf("\tRX packets %" PRIu64
1296 printf("\tRX errors %" PRIu64
1304 printf("\tTX packets %" PRIu64
1305 " bytes %" PRIu64 "\n",
1309 printf("\tTX errors %" PRIu64
1316 struct cmd_link_config_result {
1317 cmdline_fixed_string_t link_string;
1319 cmdline_fixed_string_t config_string;
1320 cmdline_ipaddr_t ip;
1325 cmd_link_config_parsed(
1326 void *parsed_result,
1327 __attribute__((unused)) struct cmdline *cl,
1330 struct cmd_link_config_result *params = parsed_result;
1331 struct app_params *app = data;
1334 uint32_t link_id = params->link_id;
1337 if (params->ip.family == AF_INET)
1338 ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr);
1340 memcpy(ipv6, params->ip.addr.ipv6.s6_addr, 16);
1342 uint32_t depth = params->depth;
1344 if (params->ip.family == AF_INET)
1345 status = app_link_config(app, link_id, ip, depth);
1347 status = app_link_config_ipv6(app, link_id, ipv6, depth);
1350 printf("Command failed\n");
1352 struct app_link_params *p;
1354 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1360 cmdline_parse_token_string_t cmd_link_config_link_string =
1361 TOKEN_STRING_INITIALIZER(struct cmd_link_config_result, link_string,
1364 cmdline_parse_token_num_t cmd_link_config_link_id =
1365 TOKEN_NUM_INITIALIZER(struct cmd_link_config_result, link_id, UINT32);
1367 cmdline_parse_token_string_t cmd_link_config_config_string =
1368 TOKEN_STRING_INITIALIZER(struct cmd_link_config_result, config_string,
1371 cmdline_parse_token_ipaddr_t cmd_link_config_ip =
1372 TOKEN_IPADDR_INITIALIZER(struct cmd_link_config_result, ip);
1374 cmdline_parse_token_num_t cmd_link_config_depth =
1375 TOKEN_NUM_INITIALIZER(struct cmd_link_config_result, depth, UINT32);
1377 cmdline_parse_inst_t cmd_link_config = {
1378 .f = cmd_link_config_parsed,
1380 .help_str = "Link configuration",
1382 (void *)&cmd_link_config_link_string,
1383 (void *)&cmd_link_config_link_id,
1384 (void *)&cmd_link_config_config_string,
1385 (void *)&cmd_link_config_ip,
1386 (void *)&cmd_link_config_depth,
1395 struct cmd_link_up_result {
1396 cmdline_fixed_string_t link_string;
1398 cmdline_fixed_string_t up_string;
1403 void *parsed_result,
1404 __attribute__((unused)) struct cmdline *cl,
1407 struct cmd_link_up_result *params = parsed_result;
1408 struct app_params *app = data;
1411 status = app_link_up(app, params->link_id);
1413 printf("Command failed\n");
1415 struct app_link_params *p;
1417 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", params->link_id,
1424 cmdline_parse_token_string_t cmd_link_up_link_string =
1425 TOKEN_STRING_INITIALIZER(struct cmd_link_up_result, link_string,
1428 cmdline_parse_token_num_t cmd_link_up_link_id =
1429 TOKEN_NUM_INITIALIZER(struct cmd_link_up_result, link_id, UINT32);
1431 cmdline_parse_token_string_t cmd_link_up_up_string =
1432 TOKEN_STRING_INITIALIZER(struct cmd_link_up_result, up_string, "up");
1434 cmdline_parse_inst_t cmd_link_up = {
1435 .f = cmd_link_up_parsed,
1437 .help_str = "Link UP",
1439 (void *)&cmd_link_up_link_string,
1440 (void *)&cmd_link_up_link_id,
1441 (void *)&cmd_link_up_up_string,
1450 struct cmd_link_down_result {
1451 cmdline_fixed_string_t link_string;
1453 cmdline_fixed_string_t down_string;
1457 cmd_link_down_parsed(
1458 void *parsed_result,
1459 __attribute__((unused)) struct cmdline *cl,
1462 struct cmd_link_down_result *params = parsed_result;
1463 struct app_params *app = data;
1466 status = app_link_down(app, params->link_id);
1468 printf("Command failed\n");
1470 struct app_link_params *p;
1472 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", params->link_id,
1479 cmdline_parse_token_string_t cmd_link_down_link_string =
1480 TOKEN_STRING_INITIALIZER(struct cmd_link_down_result, link_string,
1483 cmdline_parse_token_num_t cmd_link_down_link_id =
1484 TOKEN_NUM_INITIALIZER(struct cmd_link_down_result, link_id, UINT32);
1486 cmdline_parse_token_string_t cmd_link_down_down_string =
1487 TOKEN_STRING_INITIALIZER(struct cmd_link_down_result, down_string,
1490 cmdline_parse_inst_t cmd_link_down = {
1491 .f = cmd_link_down_parsed,
1493 .help_str = "Link DOWN",
1495 (void *) &cmd_link_down_link_string,
1496 (void *) &cmd_link_down_link_id,
1497 (void *) &cmd_link_down_down_string,
1506 struct cmd_link_ls_result {
1507 cmdline_fixed_string_t link_string;
1508 cmdline_fixed_string_t ls_string;
1513 __attribute__((unused)) void *parsed_result,
1514 __attribute__((unused)) struct cmdline *cl,
1517 struct app_params *app = data;
1520 for (link_id = 0; link_id < app->n_links; link_id++) {
1521 struct app_link_params *p;
1523 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1527 print_interface_details();
1530 cmdline_parse_token_string_t cmd_link_ls_link_string =
1531 TOKEN_STRING_INITIALIZER(struct cmd_link_ls_result, link_string,
1534 cmdline_parse_token_string_t cmd_link_ls_ls_string =
1535 TOKEN_STRING_INITIALIZER(struct cmd_link_ls_result, ls_string, "ls");
1537 cmdline_parse_inst_t cmd_link_ls = {
1538 .f = cmd_link_ls_parsed,
1540 .help_str = "Link list",
1542 (void *)&cmd_link_ls_link_string,
1543 (void *)&cmd_link_ls_ls_string,
1552 struct cmd_quit_result {
1553 cmdline_fixed_string_t quit;
1558 __rte_unused void *parsed_result,
1560 __rte_unused void *data)
1565 static cmdline_parse_token_string_t cmd_quit_quit =
1566 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
1568 static cmdline_parse_inst_t cmd_quit = {
1569 .f = cmd_quit_parsed,
1573 (void *) &cmd_quit_quit,
1584 cmdline_parse_ctx_t *ctx,
1585 const char *file_name)
1587 struct cmdline *file_cl;
1590 fd = open(file_name, O_RDONLY);
1592 printf("Cannot open file \"%s\"\n", file_name);
1596 file_cl = cmdline_new(ctx, "", fd, 1);
1597 cmdline_interact(file_cl);
1601 struct cmd_run_file_result {
1602 cmdline_fixed_string_t run_string;
1603 char file_name[APP_FILE_NAME_SIZE];
1608 void *parsed_result,
1610 __attribute__((unused)) void *data)
1612 struct cmd_run_file_result *params = parsed_result;
1614 app_run_file(cl->ctx, params->file_name);
1617 cmdline_parse_token_string_t cmd_run_run_string =
1618 TOKEN_STRING_INITIALIZER(struct cmd_run_file_result, run_string,
1621 cmdline_parse_token_string_t cmd_run_file_name =
1622 TOKEN_STRING_INITIALIZER(struct cmd_run_file_result, file_name, NULL);
1624 cmdline_parse_inst_t cmd_run = {
1625 .f = cmd_run_parsed,
1627 .help_str = "Run CLI script file",
1629 (void *) &cmd_run_run_string,
1630 (void *) &cmd_run_file_name,
1635 static cmdline_parse_ctx_t pipeline_common_cmds[] = {
1636 (cmdline_parse_inst_t *) &cmd_quit,
1637 (cmdline_parse_inst_t *) &cmd_run,
1638 (cmdline_parse_inst_t *) &cmd_routeadd_net,
1639 (cmdline_parse_inst_t *) &cmd_routeadd_host,
1641 (cmdline_parse_inst_t *) &cmd_link_config,
1642 (cmdline_parse_inst_t *) &cmd_link_up,
1643 (cmdline_parse_inst_t *) &cmd_link_down,
1644 (cmdline_parse_inst_t *) &cmd_link_ls,
1646 (cmdline_parse_inst_t *) &cmd_ping,
1647 (cmdline_parse_inst_t *) &cmd_stats_port_in,
1648 (cmdline_parse_inst_t *) &cmd_stats_port_out,
1649 (cmdline_parse_inst_t *) &cmd_stats_table,
1650 (cmdline_parse_inst_t *) &cmd_port_in_enable,
1651 (cmdline_parse_inst_t *) &cmd_port_in_disable,
1656 app_pipeline_common_cmd_push(struct app_params *app)
1660 /* Check for available slots in the application commands array */
1661 n_cmds = RTE_DIM(pipeline_common_cmds) - 1;
1662 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1665 /* Push pipeline commands into the application */
1666 memcpy(&app->cmds[app->n_cmds],
1667 pipeline_common_cmds,
1668 n_cmds * sizeof(cmdline_parse_ctx_t));
1670 for (i = 0; i < n_cmds; i++)
1671 app->cmds[app->n_cmds + i]->data = app;
1673 app->n_cmds += n_cmds;
1674 app->cmds[app->n_cmds] = NULL;