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"
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 */
362 if (ifm_add_ipv4_port(link_id, rte_bswap32(ip), depth) == IFM_FAILURE)
369 void convert_prefixlen_to_netmask_ipv6(uint32_t depth, uint8_t netmask_ipv6[])
373 memset(netmask_ipv6, 0, 16);
378 for (i = 0; i < div; i++)
379 netmask_ipv6[i] = 0xff;
381 netmask_ipv6[i] = (~0 << (8 - mod));
387 get_host_portion_ipv6(uint8_t ipv6[], uint8_t netmask[], uint8_t host_ipv6[])
391 for (i = 0; i < 16; i++) {
392 host_ipv6[i] = ipv6[i] & netmask[i];
399 get_bcast_portion_ipv6(uint8_t host[], uint8_t netmask[], uint8_t bcast_ipv6[])
403 for (i = 0; i < 16; i++) {
404 bcast_ipv6[i] = host[i] | ~netmask[i];
411 app_link_config_ipv6(struct app_params *app,
412 uint32_t link_id, uint8_t ipv6[], uint32_t depth)
414 struct app_link_params *p;
416 uint8_t netmask_ipv6[16], host[16], bcast[16];
418 /* Check input arguments */
422 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
424 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
430 APP_LOG(app, HIGH, "%s is UP, please bring it DOWN first",
435 convert_prefixlen_to_netmask_ipv6(depth, netmask_ipv6);
436 get_host_portion_ipv6(ipv6, netmask_ipv6, host);
437 get_bcast_portion_ipv6(host, netmask_ipv6, bcast);
439 for (i = 0; i < app->n_links; i++) {
440 struct app_link_params *link = &app->link_params[i];
442 if (strcmp(p->name, link->name) == 0)
445 if (!memcmp(link->ipv6, ipv6, 16)) {
447 "%s is already assigned this IPv6 address",
453 if ((depth == 0) || (depth > 128)) {
454 APP_LOG(app, HIGH, "Illegal value for depth parameter "
455 "(%" PRIu32 ")", depth);
459 /* Save link parameters */
460 memcpy(p->ipv6, ipv6, 16);
462 p->depth_ipv6 = depth;
464 printf("IPv6: %x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x",
465 ipv6[0], ipv6[1], ipv6[2], ipv6[3], ipv6[4], ipv6[5],
466 ipv6[6], ipv6[7], ipv6[8], ipv6[9], ipv6[10], ipv6[11],
467 ipv6[12], ipv6[13], ipv6[14], ipv6[15]);
469 if (ifm_add_ipv6_port(link_id, ipv6, depth) == IFM_FAILURE)
475 app_link_up(struct app_params *app,
478 struct app_link_params *p;
480 /* Check input arguments */
484 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
486 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
491 /* Check link state */
493 APP_LOG(app, HIGH, "%s is already UP", p->name);
497 /* Check that IP address is valid */
502 if ((p->ip || memcmp(p->ipv6, temp, 16)) == 0) {
503 APP_LOG(app, HIGH, "%s IP address is not set", p->name);
507 app_link_up_internal(app, p);
513 app_link_down(struct app_params *app,
516 struct app_link_params *p;
518 /* Check input arguments */
522 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
524 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
529 /* Check link state */
531 APP_LOG(app, HIGH, "%s is already DOWN", p->name);
535 app_link_down_internal(app, p);
543 struct cmd_routeadd_config_result {
544 cmdline_fixed_string_t routeadd_string;
545 cmdline_fixed_string_t type_string;
548 cmdline_fixed_string_t depth;
551 extern struct arp_data *p_arp_data;
552 extern uint32_t nd_route_tbl_index;
555 * This implements route add entries for ipv4
557 int app_routeadd_config_ipv4(__attribute__((unused)) struct app_params *app,
558 uint32_t port_id, uint32_t ip, uint32_t mask)
561 if (port_id >= gw_get_num_ports()) {
562 printf("Max ports allowed is %d\n", gw_get_num_ports());
566 printf("port id:%d ip: %x mask:%x\n", port_id, ip, mask);
568 struct route_table_entry *lentry = NULL;
570 /* Check for matching entry */
571 for(i = 0 ; i< p_route_data[port_id]->route_ent_cnt; i++) {
573 lentry = &p_route_data[port_id]->route_table[i];
575 /* Entry already exists? */
580 if( lentry->nh_mask == (ip & mask))
584 if(i < MAX_ROUTE_ENTRY_SIZE) {
586 lentry = &p_route_data[port_id]->route_table[i];
588 p_route_data[port_id]->route_ent_cnt++;
590 lentry->port = port_id;
592 lentry->nh_mask = (ip & mask);
593 /* Set the VNF Gateway flag */
598 printf("Error: Number of entries more than supported\n");
605 * This implements route add entries for ipv6
607 int app_routeadd_config_ipv6(__attribute__((unused)) struct app_params *app,
608 uint32_t port_id, uint8_t ipv6[], uint32_t depth)
612 if (port_id >= gw_get_num_ports()) {
613 printf("Max ports allowed is %d\n", gw_get_num_ports());
617 if (port_id >= nd_route_tbl_index)
618 nd_route_tbl_index++;
620 printf("port id:%d depth:%d\n", port_id, depth);
621 printf("ipv6 address: ");
622 for(i = 0; i < IPV6_ADD_SIZE; i++)
623 printf("%02x ", ipv6[i]);
626 struct nd_route_table_entry *lentry = NULL;
628 uint8_t netmask_ipv6[16], netip_nd[16], netip_in[16];
629 uint8_t depthflags = 0, depthflags1 = 0;
633 /* Check for matching entry */
634 for(i = 0 ; i< p_nd_route_data[port_id]->nd_route_ent_cnt; i++) {
636 lentry = &p_nd_route_data[port_id]->nd_route_table[i];
638 memset(netmask_ipv6, 0, sizeof(netmask_ipv6));
639 memset(netip_nd, 0, sizeof(netip_nd));
640 memset(netip_in, 0, sizeof(netip_in));
642 /* Create netmask from depth */
643 convert_prefixlen_to_netmask_ipv6(lentry->depth, netmask_ipv6);
645 for (k = 0; k < 16; k++) {
646 if (lentry->nhipv6[k] & netmask_ipv6[k]) {
648 netip_nd[k] = lentry->nhipv6[k];
651 if (ipv6[k] & netmask_ipv6[k]) {
653 netip_in[k] = ipv6[k];
657 if ((depthflags == depthflags1)
658 && (memcmp(netip_nd, netip_in, sizeof(netip_nd)) == 0)) {
659 /* Route already exists */
660 printf("Route already exists \n");
665 if(i < MAX_ND_ROUTE_ENTRY_SIZE) {
667 lentry = &p_nd_route_data[port_id]->nd_route_table[i];
669 rte_mov16(lentry->nhipv6, ipv6);
671 lentry->depth = depth;
672 lentry->port = port_id;
673 p_nd_route_data[port_id]->nd_route_ent_cnt++;
674 /* Set the VNF Gateway flag */
680 printf("Error: Number of entries more than supported\n");
686 * cmd handler for handling route abj entry at runtime.
687 * the same handle takes care of both ipv4 & ipv6
692 __attribute__((unused)) struct cmdline *cl,
695 struct cmd_routeadd_config_result *params = parsed_result;
696 struct app_params *app = data;
699 uint32_t port_id = params->port_id;
700 uint32_t i, ip = 0, depth = 0, mask = 0;
703 printf("Adding route for %s \n", params->type_string);
705 if (params->ip.family == AF_INET) {
706 ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr);
708 if(strcmp(params->type_string, "net") == 0)
710 mask = strtoul(params->depth, NULL, 16);
715 printf("nhip:0x%08x mask:%x port_id:%d\n", ip, mask, port_id);
717 memcpy(ipv6, params->ip.addr.ipv6.s6_addr, 16);
718 if(strcmp(params->type_string, "net") == 0)
720 depth = atoi(params->depth);
725 for (i=0; i < 16; i++)
726 printf("%02x ", ipv6[i]);
727 printf("\n port_id:%d depth:%d \n", port_id, depth);
731 if (params->ip.family == AF_INET)
732 status = app_routeadd_config_ipv4(app, port_id, ip, mask);
734 status = app_routeadd_config_ipv6(app, port_id, ipv6, depth);
737 printf("Command failed\n");
739 printf("Command Success\n");
742 cmdline_parse_token_string_t cmd_routeadd_config_string =
743 TOKEN_STRING_INITIALIZER(struct cmd_routeadd_config_result, routeadd_string,
746 cmdline_parse_token_string_t cmd_routeadd_net_string =
747 TOKEN_STRING_INITIALIZER(struct cmd_routeadd_config_result, type_string,
750 cmdline_parse_token_string_t cmd_routeadd_host_string =
751 TOKEN_STRING_INITIALIZER(struct cmd_routeadd_config_result, type_string,
754 cmdline_parse_token_num_t cmd_routeadd_config_port_id =
755 TOKEN_NUM_INITIALIZER(struct cmd_routeadd_config_result, port_id, UINT32);
757 cmdline_parse_token_ipaddr_t cmd_routeadd_config_ip =
758 TOKEN_IPADDR_INITIALIZER(struct cmd_routeadd_config_result, ip);
760 cmdline_parse_token_string_t cmd_routeadd_config_depth_string =
761 TOKEN_STRING_INITIALIZER(struct cmd_routeadd_config_result, depth, NULL);
763 cmdline_parse_inst_t cmd_routeadd_net = {
764 .f = cmd_routeadd_parsed,
766 .help_str = "Add Route entry for gateway",
768 (void *) &cmd_routeadd_config_string,
769 (void *) &cmd_routeadd_net_string,
770 (void *) &cmd_routeadd_config_port_id,
771 (void *) &cmd_routeadd_config_ip,
772 (void *) &cmd_routeadd_config_depth_string,
777 cmdline_parse_inst_t cmd_routeadd_host = {
778 .f = cmd_routeadd_parsed,
780 .help_str = "Add Route entry for host",
782 (void *) &cmd_routeadd_config_string,
783 (void *) &cmd_routeadd_host_string,
784 (void *) &cmd_routeadd_config_port_id,
785 (void *) &cmd_routeadd_config_ip,
794 struct cmd_ping_result {
795 cmdline_fixed_string_t p_string;
796 uint32_t pipeline_id;
797 cmdline_fixed_string_t ping_string;
803 __rte_unused struct cmdline *cl,
806 struct cmd_ping_result *params = parsed_result;
807 struct app_params *app = data;
810 status = app_pipeline_ping(app, params->pipeline_id);
812 printf("Command failed\n");
815 cmdline_parse_token_string_t cmd_ping_p_string =
816 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, p_string, "p");
818 cmdline_parse_token_num_t cmd_ping_pipeline_id =
819 TOKEN_NUM_INITIALIZER(struct cmd_ping_result, pipeline_id, UINT32);
821 cmdline_parse_token_string_t cmd_ping_ping_string =
822 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, ping_string, "ping");
824 cmdline_parse_inst_t cmd_ping = {
825 .f = cmd_ping_parsed,
827 .help_str = "Pipeline ping",
829 (void *) &cmd_ping_p_string,
830 (void *) &cmd_ping_pipeline_id,
831 (void *) &cmd_ping_ping_string,
840 struct cmd_stats_port_in_result {
841 cmdline_fixed_string_t p_string;
842 uint32_t pipeline_id;
843 cmdline_fixed_string_t stats_string;
844 cmdline_fixed_string_t port_string;
845 cmdline_fixed_string_t in_string;
850 cmd_stats_port_in_parsed(
852 __rte_unused struct cmdline *cl,
855 struct cmd_stats_port_in_result *params = parsed_result;
856 struct app_params *app = data;
857 struct rte_pipeline_port_in_stats stats;
860 status = app_pipeline_stats_port_in(app,
866 printf("Command failed\n");
871 printf("Pipeline %" PRIu32 " - stats for input port %" PRIu32 ":\n"
872 "\tPkts in: %" PRIu64 "\n"
873 "\tPkts dropped by AH: %" PRIu64 "\n"
874 "\tPkts dropped by other: %" PRIu64 "\n",
877 stats.stats.n_pkts_in,
878 stats.n_pkts_dropped_by_ah,
879 stats.stats.n_pkts_drop);
882 cmdline_parse_token_string_t cmd_stats_port_in_p_string =
883 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, p_string,
886 cmdline_parse_token_num_t cmd_stats_port_in_pipeline_id =
887 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, pipeline_id,
890 cmdline_parse_token_string_t cmd_stats_port_in_stats_string =
891 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, stats_string,
894 cmdline_parse_token_string_t cmd_stats_port_in_port_string =
895 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, port_string,
898 cmdline_parse_token_string_t cmd_stats_port_in_in_string =
899 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, in_string,
902 cmdline_parse_token_num_t cmd_stats_port_in_port_in_id =
903 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, port_in_id,
906 cmdline_parse_inst_t cmd_stats_port_in = {
907 .f = cmd_stats_port_in_parsed,
909 .help_str = "Pipeline input port stats",
911 (void *) &cmd_stats_port_in_p_string,
912 (void *) &cmd_stats_port_in_pipeline_id,
913 (void *) &cmd_stats_port_in_stats_string,
914 (void *) &cmd_stats_port_in_port_string,
915 (void *) &cmd_stats_port_in_in_string,
916 (void *) &cmd_stats_port_in_port_in_id,
925 struct cmd_stats_port_out_result {
926 cmdline_fixed_string_t p_string;
927 uint32_t pipeline_id;
928 cmdline_fixed_string_t stats_string;
929 cmdline_fixed_string_t port_string;
930 cmdline_fixed_string_t out_string;
931 uint32_t port_out_id;
935 cmd_stats_port_out_parsed(
937 __rte_unused struct cmdline *cl,
941 struct cmd_stats_port_out_result *params = parsed_result;
942 struct app_params *app = data;
943 struct rte_pipeline_port_out_stats stats;
946 status = app_pipeline_stats_port_out(app,
952 printf("Command failed\n");
957 printf("Pipeline %" PRIu32 " - stats for output port %" PRIu32 ":\n"
958 "\tPkts in: %" PRIu64 "\n"
959 "\tPkts dropped by AH: %" PRIu64 "\n"
960 "\tPkts dropped by other: %" PRIu64 "\n",
963 stats.stats.n_pkts_in,
964 stats.n_pkts_dropped_by_ah,
965 stats.stats.n_pkts_drop);
968 cmdline_parse_token_string_t cmd_stats_port_out_p_string =
969 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, p_string,
972 cmdline_parse_token_num_t cmd_stats_port_out_pipeline_id =
973 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, pipeline_id,
976 cmdline_parse_token_string_t cmd_stats_port_out_stats_string =
977 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, stats_string,
980 cmdline_parse_token_string_t cmd_stats_port_out_port_string =
981 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, port_string,
984 cmdline_parse_token_string_t cmd_stats_port_out_out_string =
985 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, out_string,
988 cmdline_parse_token_num_t cmd_stats_port_out_port_out_id =
989 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, port_out_id,
992 cmdline_parse_inst_t cmd_stats_port_out = {
993 .f = cmd_stats_port_out_parsed,
995 .help_str = "Pipeline output port stats",
997 (void *) &cmd_stats_port_out_p_string,
998 (void *) &cmd_stats_port_out_pipeline_id,
999 (void *) &cmd_stats_port_out_stats_string,
1000 (void *) &cmd_stats_port_out_port_string,
1001 (void *) &cmd_stats_port_out_out_string,
1002 (void *) &cmd_stats_port_out_port_out_id,
1011 struct cmd_stats_table_result {
1012 cmdline_fixed_string_t p_string;
1013 uint32_t pipeline_id;
1014 cmdline_fixed_string_t stats_string;
1015 cmdline_fixed_string_t table_string;
1020 cmd_stats_table_parsed(
1021 void *parsed_result,
1022 __rte_unused struct cmdline *cl,
1025 struct cmd_stats_table_result *params = parsed_result;
1026 struct app_params *app = data;
1027 struct rte_pipeline_table_stats stats;
1030 status = app_pipeline_stats_table(app,
1031 params->pipeline_id,
1036 printf("Command failed\n");
1041 printf("Pipeline %" PRIu32 " - stats for table %" PRIu32 ":\n"
1042 "\tPkts in: %" PRIu64 "\n"
1043 "\tPkts in with lookup miss: %" PRIu64 "\n"
1044 "\tPkts in with lookup hit dropped by AH: %" PRIu64 "\n"
1045 "\tPkts in with lookup hit dropped by others: %" PRIu64 "\n"
1046 "\tPkts in with lookup miss dropped by AH: %" PRIu64 "\n"
1047 "\tPkts in with lookup miss dropped by others: %" PRIu64 "\n",
1048 params->pipeline_id,
1050 stats.stats.n_pkts_in,
1051 stats.stats.n_pkts_lookup_miss,
1052 stats.n_pkts_dropped_by_lkp_hit_ah,
1053 stats.n_pkts_dropped_lkp_hit,
1054 stats.n_pkts_dropped_by_lkp_miss_ah,
1055 stats.n_pkts_dropped_lkp_miss);
1058 cmdline_parse_token_string_t cmd_stats_table_p_string =
1059 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, p_string,
1062 cmdline_parse_token_num_t cmd_stats_table_pipeline_id =
1063 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, pipeline_id,
1066 cmdline_parse_token_string_t cmd_stats_table_stats_string =
1067 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, stats_string,
1070 cmdline_parse_token_string_t cmd_stats_table_table_string =
1071 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, table_string,
1074 cmdline_parse_token_num_t cmd_stats_table_table_id =
1075 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, table_id, UINT32);
1077 cmdline_parse_inst_t cmd_stats_table = {
1078 .f = cmd_stats_table_parsed,
1080 .help_str = "Pipeline table stats",
1082 (void *) &cmd_stats_table_p_string,
1083 (void *) &cmd_stats_table_pipeline_id,
1084 (void *) &cmd_stats_table_stats_string,
1085 (void *) &cmd_stats_table_table_string,
1086 (void *) &cmd_stats_table_table_id,
1095 struct cmd_port_in_enable_result {
1096 cmdline_fixed_string_t p_string;
1097 uint32_t pipeline_id;
1098 cmdline_fixed_string_t port_string;
1099 cmdline_fixed_string_t in_string;
1100 uint32_t port_in_id;
1101 cmdline_fixed_string_t enable_string;
1105 cmd_port_in_enable_parsed(
1106 void *parsed_result,
1107 __rte_unused struct cmdline *cl,
1110 struct cmd_port_in_enable_result *params = parsed_result;
1111 struct app_params *app = data;
1114 status = app_pipeline_port_in_enable(app,
1115 params->pipeline_id,
1116 params->port_in_id);
1119 printf("Command failed\n");
1122 cmdline_parse_token_string_t cmd_port_in_enable_p_string =
1123 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, p_string,
1126 cmdline_parse_token_num_t cmd_port_in_enable_pipeline_id =
1127 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, pipeline_id,
1130 cmdline_parse_token_string_t cmd_port_in_enable_port_string =
1131 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, port_string,
1134 cmdline_parse_token_string_t cmd_port_in_enable_in_string =
1135 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, in_string,
1138 cmdline_parse_token_num_t cmd_port_in_enable_port_in_id =
1139 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, port_in_id,
1142 cmdline_parse_token_string_t cmd_port_in_enable_enable_string =
1143 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result,
1144 enable_string, "enable");
1146 cmdline_parse_inst_t cmd_port_in_enable = {
1147 .f = cmd_port_in_enable_parsed,
1149 .help_str = "Pipeline input port enable",
1151 (void *) &cmd_port_in_enable_p_string,
1152 (void *) &cmd_port_in_enable_pipeline_id,
1153 (void *) &cmd_port_in_enable_port_string,
1154 (void *) &cmd_port_in_enable_in_string,
1155 (void *) &cmd_port_in_enable_port_in_id,
1156 (void *) &cmd_port_in_enable_enable_string,
1165 struct cmd_port_in_disable_result {
1166 cmdline_fixed_string_t p_string;
1167 uint32_t pipeline_id;
1168 cmdline_fixed_string_t port_string;
1169 cmdline_fixed_string_t in_string;
1170 uint32_t port_in_id;
1171 cmdline_fixed_string_t disable_string;
1175 cmd_port_in_disable_parsed(
1176 void *parsed_result,
1177 __rte_unused struct cmdline *cl,
1180 struct cmd_port_in_disable_result *params = parsed_result;
1181 struct app_params *app = data;
1184 status = app_pipeline_port_in_disable(app,
1185 params->pipeline_id,
1186 params->port_in_id);
1189 printf("Command failed\n");
1192 cmdline_parse_token_string_t cmd_port_in_disable_p_string =
1193 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, p_string,
1196 cmdline_parse_token_num_t cmd_port_in_disable_pipeline_id =
1197 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, pipeline_id,
1200 cmdline_parse_token_string_t cmd_port_in_disable_port_string =
1201 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, port_string,
1204 cmdline_parse_token_string_t cmd_port_in_disable_in_string =
1205 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, in_string,
1208 cmdline_parse_token_num_t cmd_port_in_disable_port_in_id =
1209 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, port_in_id,
1212 cmdline_parse_token_string_t cmd_port_in_disable_disable_string =
1213 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result,
1214 disable_string, "disable");
1216 cmdline_parse_inst_t cmd_port_in_disable = {
1217 .f = cmd_port_in_disable_parsed,
1219 .help_str = "Pipeline input port disable",
1221 (void *) &cmd_port_in_disable_p_string,
1222 (void *) &cmd_port_in_disable_pipeline_id,
1223 (void *) &cmd_port_in_disable_port_string,
1224 (void *) &cmd_port_in_disable_in_string,
1225 (void *) &cmd_port_in_disable_port_in_id,
1226 (void *) &cmd_port_in_disable_disable_string,
1236 print_link_info(struct app_link_params *p)
1238 struct rte_eth_stats stats;
1239 struct ether_addr *mac_addr;
1240 uint32_t netmask = (~0U) << (32 - p->depth);
1241 uint32_t host = p->ip & netmask;
1242 uint32_t bcast = host | (~netmask);
1244 memset(&stats, 0, sizeof(stats));
1245 rte_eth_stats_get(p->pmd_id, &stats);
1247 mac_addr = (struct ether_addr *) &p->mac_addr;
1249 if (strlen(p->pci_bdf))
1250 printf("%s(%s): flags=<%s>\n",
1253 (p->state) ? "UP" : "DOWN");
1255 printf("%s: flags=<%s>\n",
1257 (p->state) ? "UP" : "DOWN");
1260 printf("\tinet %" PRIu32 ".%" PRIu32
1261 ".%" PRIu32 ".%" PRIu32
1262 " netmask %" PRIu32 ".%" PRIu32
1263 ".%" PRIu32 ".%" PRIu32 " "
1264 "broadcast %" PRIu32 ".%" PRIu32
1265 ".%" PRIu32 ".%" PRIu32 "\n",
1266 (p->ip >> 24) & 0xFF,
1267 (p->ip >> 16) & 0xFF,
1268 (p->ip >> 8) & 0xFF,
1270 (netmask >> 24) & 0xFF,
1271 (netmask >> 16) & 0xFF,
1272 (netmask >> 8) & 0xFF,
1274 (bcast >> 24) & 0xFF,
1275 (bcast >> 16) & 0xFF,
1276 (bcast >> 8) & 0xFF,
1279 printf("\tether %02" PRIx32 ":%02" PRIx32 ":%02" PRIx32
1280 ":%02" PRIx32 ":%02" PRIx32 ":%02" PRIx32 "\n",
1281 mac_addr->addr_bytes[0],
1282 mac_addr->addr_bytes[1],
1283 mac_addr->addr_bytes[2],
1284 mac_addr->addr_bytes[3],
1285 mac_addr->addr_bytes[4],
1286 mac_addr->addr_bytes[5]);
1288 printf("\tRX packets %" PRIu64
1294 printf("\tRX errors %" PRIu64
1302 printf("\tTX packets %" PRIu64
1303 " bytes %" PRIu64 "\n",
1307 printf("\tTX errors %" PRIu64
1314 struct cmd_link_config_result {
1315 cmdline_fixed_string_t link_string;
1317 cmdline_fixed_string_t config_string;
1318 cmdline_ipaddr_t ip;
1323 cmd_link_config_parsed(
1324 void *parsed_result,
1325 __attribute__((unused)) struct cmdline *cl,
1328 struct cmd_link_config_result *params = parsed_result;
1329 struct app_params *app = data;
1332 uint32_t link_id = params->link_id;
1335 if (params->ip.family == AF_INET)
1336 ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr);
1338 memcpy(ipv6, params->ip.addr.ipv6.s6_addr, 16);
1340 uint32_t depth = params->depth;
1342 if (params->ip.family == AF_INET)
1343 status = app_link_config(app, link_id, ip, depth);
1345 status = app_link_config_ipv6(app, link_id, ipv6, depth);
1348 printf("Command failed\n");
1350 struct app_link_params *p;
1352 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1358 cmdline_parse_token_string_t cmd_link_config_link_string =
1359 TOKEN_STRING_INITIALIZER(struct cmd_link_config_result, link_string,
1362 cmdline_parse_token_num_t cmd_link_config_link_id =
1363 TOKEN_NUM_INITIALIZER(struct cmd_link_config_result, link_id, UINT32);
1365 cmdline_parse_token_string_t cmd_link_config_config_string =
1366 TOKEN_STRING_INITIALIZER(struct cmd_link_config_result, config_string,
1369 cmdline_parse_token_ipaddr_t cmd_link_config_ip =
1370 TOKEN_IPADDR_INITIALIZER(struct cmd_link_config_result, ip);
1372 cmdline_parse_token_num_t cmd_link_config_depth =
1373 TOKEN_NUM_INITIALIZER(struct cmd_link_config_result, depth, UINT32);
1375 cmdline_parse_inst_t cmd_link_config = {
1376 .f = cmd_link_config_parsed,
1378 .help_str = "Link configuration",
1380 (void *)&cmd_link_config_link_string,
1381 (void *)&cmd_link_config_link_id,
1382 (void *)&cmd_link_config_config_string,
1383 (void *)&cmd_link_config_ip,
1384 (void *)&cmd_link_config_depth,
1393 struct cmd_link_up_result {
1394 cmdline_fixed_string_t link_string;
1396 cmdline_fixed_string_t up_string;
1401 void *parsed_result,
1402 __attribute__((unused)) struct cmdline *cl,
1405 struct cmd_link_up_result *params = parsed_result;
1406 struct app_params *app = data;
1409 status = app_link_up(app, params->link_id);
1411 printf("Command failed\n");
1413 struct app_link_params *p;
1415 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", params->link_id,
1422 cmdline_parse_token_string_t cmd_link_up_link_string =
1423 TOKEN_STRING_INITIALIZER(struct cmd_link_up_result, link_string,
1426 cmdline_parse_token_num_t cmd_link_up_link_id =
1427 TOKEN_NUM_INITIALIZER(struct cmd_link_up_result, link_id, UINT32);
1429 cmdline_parse_token_string_t cmd_link_up_up_string =
1430 TOKEN_STRING_INITIALIZER(struct cmd_link_up_result, up_string, "up");
1432 cmdline_parse_inst_t cmd_link_up = {
1433 .f = cmd_link_up_parsed,
1435 .help_str = "Link UP",
1437 (void *)&cmd_link_up_link_string,
1438 (void *)&cmd_link_up_link_id,
1439 (void *)&cmd_link_up_up_string,
1448 struct cmd_link_down_result {
1449 cmdline_fixed_string_t link_string;
1451 cmdline_fixed_string_t down_string;
1455 cmd_link_down_parsed(
1456 void *parsed_result,
1457 __attribute__((unused)) struct cmdline *cl,
1460 struct cmd_link_down_result *params = parsed_result;
1461 struct app_params *app = data;
1464 status = app_link_down(app, params->link_id);
1466 printf("Command failed\n");
1468 struct app_link_params *p;
1470 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", params->link_id,
1477 cmdline_parse_token_string_t cmd_link_down_link_string =
1478 TOKEN_STRING_INITIALIZER(struct cmd_link_down_result, link_string,
1481 cmdline_parse_token_num_t cmd_link_down_link_id =
1482 TOKEN_NUM_INITIALIZER(struct cmd_link_down_result, link_id, UINT32);
1484 cmdline_parse_token_string_t cmd_link_down_down_string =
1485 TOKEN_STRING_INITIALIZER(struct cmd_link_down_result, down_string,
1488 cmdline_parse_inst_t cmd_link_down = {
1489 .f = cmd_link_down_parsed,
1491 .help_str = "Link DOWN",
1493 (void *) &cmd_link_down_link_string,
1494 (void *) &cmd_link_down_link_id,
1495 (void *) &cmd_link_down_down_string,
1504 struct cmd_link_ls_result {
1505 cmdline_fixed_string_t link_string;
1506 cmdline_fixed_string_t ls_string;
1511 __attribute__((unused)) void *parsed_result,
1512 __attribute__((unused)) struct cmdline *cl,
1515 struct app_params *app = data;
1518 for (link_id = 0; link_id < app->n_links; link_id++) {
1519 struct app_link_params *p;
1521 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1525 print_interface_details();
1528 cmdline_parse_token_string_t cmd_link_ls_link_string =
1529 TOKEN_STRING_INITIALIZER(struct cmd_link_ls_result, link_string,
1532 cmdline_parse_token_string_t cmd_link_ls_ls_string =
1533 TOKEN_STRING_INITIALIZER(struct cmd_link_ls_result, ls_string, "ls");
1535 cmdline_parse_inst_t cmd_link_ls = {
1536 .f = cmd_link_ls_parsed,
1538 .help_str = "Link list",
1540 (void *)&cmd_link_ls_link_string,
1541 (void *)&cmd_link_ls_ls_string,
1550 struct cmd_quit_result {
1551 cmdline_fixed_string_t quit;
1556 __rte_unused void *parsed_result,
1558 __rte_unused void *data)
1563 static cmdline_parse_token_string_t cmd_quit_quit =
1564 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
1566 static cmdline_parse_inst_t cmd_quit = {
1567 .f = cmd_quit_parsed,
1571 (void *) &cmd_quit_quit,
1582 cmdline_parse_ctx_t *ctx,
1583 const char *file_name)
1585 struct cmdline *file_cl;
1588 fd = open(file_name, O_RDONLY);
1590 printf("Cannot open file \"%s\"\n", file_name);
1594 file_cl = cmdline_new(ctx, "", fd, 1);
1595 cmdline_interact(file_cl);
1599 struct cmd_run_file_result {
1600 cmdline_fixed_string_t run_string;
1601 char file_name[APP_FILE_NAME_SIZE];
1606 void *parsed_result,
1608 __attribute__((unused)) void *data)
1610 struct cmd_run_file_result *params = parsed_result;
1612 app_run_file(cl->ctx, params->file_name);
1615 cmdline_parse_token_string_t cmd_run_run_string =
1616 TOKEN_STRING_INITIALIZER(struct cmd_run_file_result, run_string,
1619 cmdline_parse_token_string_t cmd_run_file_name =
1620 TOKEN_STRING_INITIALIZER(struct cmd_run_file_result, file_name, NULL);
1622 cmdline_parse_inst_t cmd_run = {
1623 .f = cmd_run_parsed,
1625 .help_str = "Run CLI script file",
1627 (void *) &cmd_run_run_string,
1628 (void *) &cmd_run_file_name,
1633 static cmdline_parse_ctx_t pipeline_common_cmds[] = {
1634 (cmdline_parse_inst_t *) &cmd_quit,
1635 (cmdline_parse_inst_t *) &cmd_run,
1636 (cmdline_parse_inst_t *) &cmd_routeadd_net,
1637 (cmdline_parse_inst_t *) &cmd_routeadd_host,
1639 (cmdline_parse_inst_t *) &cmd_link_config,
1640 (cmdline_parse_inst_t *) &cmd_link_up,
1641 (cmdline_parse_inst_t *) &cmd_link_down,
1642 (cmdline_parse_inst_t *) &cmd_link_ls,
1644 (cmdline_parse_inst_t *) &cmd_ping,
1645 (cmdline_parse_inst_t *) &cmd_stats_port_in,
1646 (cmdline_parse_inst_t *) &cmd_stats_port_out,
1647 (cmdline_parse_inst_t *) &cmd_stats_table,
1648 (cmdline_parse_inst_t *) &cmd_port_in_enable,
1649 (cmdline_parse_inst_t *) &cmd_port_in_disable,
1654 app_pipeline_common_cmd_push(struct app_params *app)
1658 /* Check for available slots in the application commands array */
1659 n_cmds = RTE_DIM(pipeline_common_cmds) - 1;
1660 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1663 /* Push pipeline commands into the application */
1664 memcpy(&app->cmds[app->n_cmds],
1665 pipeline_common_cmds,
1666 n_cmds * sizeof(cmdline_parse_ctx_t));
1668 for (i = 0; i < n_cmds; i++)
1669 app->cmds[app->n_cmds + i]->data = app;
1671 app->n_cmds += n_cmds;
1672 app->cmds[app->n_cmds] = NULL;