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"
37 app_pipeline_ping(struct app_params *app,
40 struct app_pipeline_params *p;
41 struct pipeline_msg_req *req;
42 struct pipeline_msg_rsp *rsp;
45 /* Check input arguments */
49 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
53 /* Message buffer allocation */
54 req = app_msg_alloc(app);
59 req->type = PIPELINE_MSG_REQ_PING;
61 /* Send request and wait for response */
62 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
69 /* Message buffer free */
70 app_msg_free(app, rsp);
76 app_pipeline_stats_port_in(struct app_params *app,
79 struct rte_pipeline_port_in_stats *stats)
81 struct app_pipeline_params *p;
82 struct pipeline_stats_msg_req *req;
83 struct pipeline_stats_port_in_msg_rsp *rsp;
86 /* Check input arguments */
91 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
93 (port_id >= p->n_pktq_in))
96 /* Message buffer allocation */
97 req = app_msg_alloc(app);
101 /* Fill in request */
102 req->type = PIPELINE_MSG_REQ_STATS_PORT_IN;
105 /* Send request and wait for response */
106 rsp = (struct pipeline_stats_port_in_msg_rsp *)
107 app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
112 status = rsp->status;
114 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
116 /* Message buffer free */
117 app_msg_free(app, rsp);
123 app_pipeline_stats_port_out(struct app_params *app,
124 uint32_t pipeline_id,
126 struct rte_pipeline_port_out_stats *stats)
128 struct app_pipeline_params *p;
129 struct pipeline_stats_msg_req *req;
130 struct pipeline_stats_port_out_msg_rsp *rsp;
133 /* Check input arguments */
135 (pipeline_id >= app->n_pipelines) ||
139 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
141 (port_id >= p->n_pktq_out))
144 /* Message buffer allocation */
145 req = app_msg_alloc(app);
149 /* Fill in request */
150 req->type = PIPELINE_MSG_REQ_STATS_PORT_OUT;
153 /* Send request and wait for response */
154 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
159 status = rsp->status;
161 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
163 /* Message buffer free */
164 app_msg_free(app, rsp);
170 app_pipeline_stats_table(struct app_params *app,
171 uint32_t pipeline_id,
173 struct rte_pipeline_table_stats *stats)
175 struct app_pipeline_params *p;
176 struct pipeline_stats_msg_req *req;
177 struct pipeline_stats_table_msg_rsp *rsp;
180 /* Check input arguments */
185 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
189 /* Message buffer allocation */
190 req = app_msg_alloc(app);
194 /* Fill in request */
195 req->type = PIPELINE_MSG_REQ_STATS_TABLE;
198 /* Send request and wait for response */
199 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
204 status = rsp->status;
206 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
208 /* Message buffer free */
209 app_msg_free(app, rsp);
215 app_pipeline_port_in_enable(struct app_params *app,
216 uint32_t pipeline_id,
219 struct app_pipeline_params *p;
220 struct pipeline_port_in_msg_req *req;
221 struct pipeline_msg_rsp *rsp;
224 /* Check input arguments */
228 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
230 (port_id >= p->n_pktq_in))
233 /* Message buffer allocation */
234 req = app_msg_alloc(app);
238 /* Fill in request */
239 req->type = PIPELINE_MSG_REQ_PORT_IN_ENABLE;
240 req->port_id = port_id;
242 /* Send request and wait for response */
243 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
248 status = rsp->status;
250 /* Message buffer free */
251 app_msg_free(app, rsp);
257 app_pipeline_port_in_disable(struct app_params *app,
258 uint32_t pipeline_id,
261 struct app_pipeline_params *p;
262 struct pipeline_port_in_msg_req *req;
263 struct pipeline_msg_rsp *rsp;
266 /* Check input arguments */
270 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
272 (port_id >= p->n_pktq_in))
275 /* Message buffer allocation */
276 req = app_msg_alloc(app);
280 /* Fill in request */
281 req->type = PIPELINE_MSG_REQ_PORT_IN_DISABLE;
282 req->port_id = port_id;
284 /* Send request and wait for response */
285 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
290 status = rsp->status;
292 /* Message buffer free */
293 app_msg_free(app, rsp);
299 app_link_config(struct app_params *app,
304 struct app_link_params *p;
305 uint32_t i, netmask, host, bcast;
307 /* Check input arguments */
311 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
313 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
319 APP_LOG(app, HIGH, "%s is UP, please bring it DOWN first",
324 netmask = (~0U) << (32 - depth);
326 bcast = host | (~netmask);
329 (ip == UINT32_MAX) ||
332 APP_LOG(app, HIGH, "Illegal IP address");
336 for (i = 0; i < app->n_links; i++) {
337 struct app_link_params *link = &app->link_params[i];
339 if (strcmp(p->name, link->name) == 0)
342 if (link->ip == ip) {
344 "%s is already assigned this IP address",
350 if ((depth == 0) || (depth > 32)) {
351 APP_LOG(app, HIGH, "Illegal value for depth parameter "
357 /* Save link parameters */
360 if (ifm_add_ipv4_port(link_id, rte_bswap32(ip), depth) == IFM_FAILURE)
367 void convert_prefixlen_to_netmask_ipv6(uint32_t depth, uint8_t netmask_ipv6[])
371 memset(netmask_ipv6, 0, 16);
376 for (i = 0; i < div; i++)
377 netmask_ipv6[i] = 0xff;
379 netmask_ipv6[i] = (~0 << (8 - mod));
385 get_host_portion_ipv6(uint8_t ipv6[], uint8_t netmask[], uint8_t host_ipv6[])
389 for (i = 0; i < 16; i++) {
390 host_ipv6[i] = ipv6[i] & netmask[i];
397 get_bcast_portion_ipv6(uint8_t host[], uint8_t netmask[], uint8_t bcast_ipv6[])
401 for (i = 0; i < 16; i++) {
402 bcast_ipv6[i] = host[i] | ~netmask[i];
409 app_link_config_ipv6(struct app_params *app,
410 uint32_t link_id, uint8_t ipv6[], uint32_t depth)
412 struct app_link_params *p;
414 uint8_t netmask_ipv6[16], host[16], bcast[16];
416 /* Check input arguments */
420 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
422 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
428 APP_LOG(app, HIGH, "%s is UP, please bring it DOWN first",
433 convert_prefixlen_to_netmask_ipv6(depth, netmask_ipv6);
434 get_host_portion_ipv6(ipv6, netmask_ipv6, host);
435 get_bcast_portion_ipv6(host, netmask_ipv6, bcast);
437 for (i = 0; i < app->n_links; i++) {
438 struct app_link_params *link = &app->link_params[i];
440 if (strcmp(p->name, link->name) == 0)
443 if (!memcmp(link->ipv6, ipv6, 16)) {
445 "%s is already assigned this IPv6 address",
451 if ((depth == 0) || (depth > 128)) {
452 APP_LOG(app, HIGH, "Illegal value for depth parameter "
453 "(%" PRIu32 ")", depth);
457 /* Save link parameters */
458 memcpy(p->ipv6, ipv6, 16);
460 p->depth_ipv6 = depth;
462 printf("IPv6: %x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x",
463 ipv6[0], ipv6[1], ipv6[2], ipv6[3], ipv6[4], ipv6[5],
464 ipv6[6], ipv6[7], ipv6[8], ipv6[9], ipv6[10], ipv6[11],
465 ipv6[12], ipv6[13], ipv6[14], ipv6[15]);
467 if (ifm_add_ipv6_port(link_id, ipv6, depth) == IFM_FAILURE)
473 app_link_up(struct app_params *app,
476 struct app_link_params *p;
478 /* Check input arguments */
482 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
484 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
489 /* Check link state */
491 APP_LOG(app, HIGH, "%s is already UP", p->name);
495 /* Check that IP address is valid */
500 if ((p->ip || memcmp(p->ipv6, temp, 16)) == 0) {
501 APP_LOG(app, HIGH, "%s IP address is not set", p->name);
505 app_link_up_internal(app, p);
511 app_link_down(struct app_params *app,
514 struct app_link_params *p;
516 /* Check input arguments */
520 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
522 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
527 /* Check link state */
529 APP_LOG(app, HIGH, "%s is already DOWN", p->name);
533 app_link_down_internal(app, p);
542 struct cmd_ping_result {
543 cmdline_fixed_string_t p_string;
544 uint32_t pipeline_id;
545 cmdline_fixed_string_t ping_string;
551 __rte_unused struct cmdline *cl,
554 struct cmd_ping_result *params = parsed_result;
555 struct app_params *app = data;
558 status = app_pipeline_ping(app, params->pipeline_id);
560 printf("Command failed\n");
563 cmdline_parse_token_string_t cmd_ping_p_string =
564 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, p_string, "p");
566 cmdline_parse_token_num_t cmd_ping_pipeline_id =
567 TOKEN_NUM_INITIALIZER(struct cmd_ping_result, pipeline_id, UINT32);
569 cmdline_parse_token_string_t cmd_ping_ping_string =
570 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, ping_string, "ping");
572 cmdline_parse_inst_t cmd_ping = {
573 .f = cmd_ping_parsed,
575 .help_str = "Pipeline ping",
577 (void *) &cmd_ping_p_string,
578 (void *) &cmd_ping_pipeline_id,
579 (void *) &cmd_ping_ping_string,
588 struct cmd_stats_port_in_result {
589 cmdline_fixed_string_t p_string;
590 uint32_t pipeline_id;
591 cmdline_fixed_string_t stats_string;
592 cmdline_fixed_string_t port_string;
593 cmdline_fixed_string_t in_string;
598 cmd_stats_port_in_parsed(
600 __rte_unused struct cmdline *cl,
603 struct cmd_stats_port_in_result *params = parsed_result;
604 struct app_params *app = data;
605 struct rte_pipeline_port_in_stats stats;
608 status = app_pipeline_stats_port_in(app,
614 printf("Command failed\n");
619 printf("Pipeline %" PRIu32 " - stats for input port %" PRIu32 ":\n"
620 "\tPkts in: %" PRIu64 "\n"
621 "\tPkts dropped by AH: %" PRIu64 "\n"
622 "\tPkts dropped by other: %" PRIu64 "\n",
625 stats.stats.n_pkts_in,
626 stats.n_pkts_dropped_by_ah,
627 stats.stats.n_pkts_drop);
630 cmdline_parse_token_string_t cmd_stats_port_in_p_string =
631 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, p_string,
634 cmdline_parse_token_num_t cmd_stats_port_in_pipeline_id =
635 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, pipeline_id,
638 cmdline_parse_token_string_t cmd_stats_port_in_stats_string =
639 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, stats_string,
642 cmdline_parse_token_string_t cmd_stats_port_in_port_string =
643 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, port_string,
646 cmdline_parse_token_string_t cmd_stats_port_in_in_string =
647 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, in_string,
650 cmdline_parse_token_num_t cmd_stats_port_in_port_in_id =
651 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, port_in_id,
654 cmdline_parse_inst_t cmd_stats_port_in = {
655 .f = cmd_stats_port_in_parsed,
657 .help_str = "Pipeline input port stats",
659 (void *) &cmd_stats_port_in_p_string,
660 (void *) &cmd_stats_port_in_pipeline_id,
661 (void *) &cmd_stats_port_in_stats_string,
662 (void *) &cmd_stats_port_in_port_string,
663 (void *) &cmd_stats_port_in_in_string,
664 (void *) &cmd_stats_port_in_port_in_id,
673 struct cmd_stats_port_out_result {
674 cmdline_fixed_string_t p_string;
675 uint32_t pipeline_id;
676 cmdline_fixed_string_t stats_string;
677 cmdline_fixed_string_t port_string;
678 cmdline_fixed_string_t out_string;
679 uint32_t port_out_id;
683 cmd_stats_port_out_parsed(
685 __rte_unused struct cmdline *cl,
689 struct cmd_stats_port_out_result *params = parsed_result;
690 struct app_params *app = data;
691 struct rte_pipeline_port_out_stats stats;
694 status = app_pipeline_stats_port_out(app,
700 printf("Command failed\n");
705 printf("Pipeline %" PRIu32 " - stats for output port %" PRIu32 ":\n"
706 "\tPkts in: %" PRIu64 "\n"
707 "\tPkts dropped by AH: %" PRIu64 "\n"
708 "\tPkts dropped by other: %" PRIu64 "\n",
711 stats.stats.n_pkts_in,
712 stats.n_pkts_dropped_by_ah,
713 stats.stats.n_pkts_drop);
716 cmdline_parse_token_string_t cmd_stats_port_out_p_string =
717 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, p_string,
720 cmdline_parse_token_num_t cmd_stats_port_out_pipeline_id =
721 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, pipeline_id,
724 cmdline_parse_token_string_t cmd_stats_port_out_stats_string =
725 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, stats_string,
728 cmdline_parse_token_string_t cmd_stats_port_out_port_string =
729 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, port_string,
732 cmdline_parse_token_string_t cmd_stats_port_out_out_string =
733 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, out_string,
736 cmdline_parse_token_num_t cmd_stats_port_out_port_out_id =
737 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, port_out_id,
740 cmdline_parse_inst_t cmd_stats_port_out = {
741 .f = cmd_stats_port_out_parsed,
743 .help_str = "Pipeline output port stats",
745 (void *) &cmd_stats_port_out_p_string,
746 (void *) &cmd_stats_port_out_pipeline_id,
747 (void *) &cmd_stats_port_out_stats_string,
748 (void *) &cmd_stats_port_out_port_string,
749 (void *) &cmd_stats_port_out_out_string,
750 (void *) &cmd_stats_port_out_port_out_id,
759 struct cmd_stats_table_result {
760 cmdline_fixed_string_t p_string;
761 uint32_t pipeline_id;
762 cmdline_fixed_string_t stats_string;
763 cmdline_fixed_string_t table_string;
768 cmd_stats_table_parsed(
770 __rte_unused struct cmdline *cl,
773 struct cmd_stats_table_result *params = parsed_result;
774 struct app_params *app = data;
775 struct rte_pipeline_table_stats stats;
778 status = app_pipeline_stats_table(app,
784 printf("Command failed\n");
789 printf("Pipeline %" PRIu32 " - stats for table %" PRIu32 ":\n"
790 "\tPkts in: %" PRIu64 "\n"
791 "\tPkts in with lookup miss: %" PRIu64 "\n"
792 "\tPkts in with lookup hit dropped by AH: %" PRIu64 "\n"
793 "\tPkts in with lookup hit dropped by others: %" PRIu64 "\n"
794 "\tPkts in with lookup miss dropped by AH: %" PRIu64 "\n"
795 "\tPkts in with lookup miss dropped by others: %" PRIu64 "\n",
798 stats.stats.n_pkts_in,
799 stats.stats.n_pkts_lookup_miss,
800 stats.n_pkts_dropped_by_lkp_hit_ah,
801 stats.n_pkts_dropped_lkp_hit,
802 stats.n_pkts_dropped_by_lkp_miss_ah,
803 stats.n_pkts_dropped_lkp_miss);
806 cmdline_parse_token_string_t cmd_stats_table_p_string =
807 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, p_string,
810 cmdline_parse_token_num_t cmd_stats_table_pipeline_id =
811 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, pipeline_id,
814 cmdline_parse_token_string_t cmd_stats_table_stats_string =
815 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, stats_string,
818 cmdline_parse_token_string_t cmd_stats_table_table_string =
819 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, table_string,
822 cmdline_parse_token_num_t cmd_stats_table_table_id =
823 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, table_id, UINT32);
825 cmdline_parse_inst_t cmd_stats_table = {
826 .f = cmd_stats_table_parsed,
828 .help_str = "Pipeline table stats",
830 (void *) &cmd_stats_table_p_string,
831 (void *) &cmd_stats_table_pipeline_id,
832 (void *) &cmd_stats_table_stats_string,
833 (void *) &cmd_stats_table_table_string,
834 (void *) &cmd_stats_table_table_id,
843 struct cmd_port_in_enable_result {
844 cmdline_fixed_string_t p_string;
845 uint32_t pipeline_id;
846 cmdline_fixed_string_t port_string;
847 cmdline_fixed_string_t in_string;
849 cmdline_fixed_string_t enable_string;
853 cmd_port_in_enable_parsed(
855 __rte_unused struct cmdline *cl,
858 struct cmd_port_in_enable_result *params = parsed_result;
859 struct app_params *app = data;
862 status = app_pipeline_port_in_enable(app,
867 printf("Command failed\n");
870 cmdline_parse_token_string_t cmd_port_in_enable_p_string =
871 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, p_string,
874 cmdline_parse_token_num_t cmd_port_in_enable_pipeline_id =
875 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, pipeline_id,
878 cmdline_parse_token_string_t cmd_port_in_enable_port_string =
879 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, port_string,
882 cmdline_parse_token_string_t cmd_port_in_enable_in_string =
883 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, in_string,
886 cmdline_parse_token_num_t cmd_port_in_enable_port_in_id =
887 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, port_in_id,
890 cmdline_parse_token_string_t cmd_port_in_enable_enable_string =
891 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result,
892 enable_string, "enable");
894 cmdline_parse_inst_t cmd_port_in_enable = {
895 .f = cmd_port_in_enable_parsed,
897 .help_str = "Pipeline input port enable",
899 (void *) &cmd_port_in_enable_p_string,
900 (void *) &cmd_port_in_enable_pipeline_id,
901 (void *) &cmd_port_in_enable_port_string,
902 (void *) &cmd_port_in_enable_in_string,
903 (void *) &cmd_port_in_enable_port_in_id,
904 (void *) &cmd_port_in_enable_enable_string,
913 struct cmd_port_in_disable_result {
914 cmdline_fixed_string_t p_string;
915 uint32_t pipeline_id;
916 cmdline_fixed_string_t port_string;
917 cmdline_fixed_string_t in_string;
919 cmdline_fixed_string_t disable_string;
923 cmd_port_in_disable_parsed(
925 __rte_unused struct cmdline *cl,
928 struct cmd_port_in_disable_result *params = parsed_result;
929 struct app_params *app = data;
932 status = app_pipeline_port_in_disable(app,
937 printf("Command failed\n");
940 cmdline_parse_token_string_t cmd_port_in_disable_p_string =
941 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, p_string,
944 cmdline_parse_token_num_t cmd_port_in_disable_pipeline_id =
945 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, pipeline_id,
948 cmdline_parse_token_string_t cmd_port_in_disable_port_string =
949 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, port_string,
952 cmdline_parse_token_string_t cmd_port_in_disable_in_string =
953 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, in_string,
956 cmdline_parse_token_num_t cmd_port_in_disable_port_in_id =
957 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, port_in_id,
960 cmdline_parse_token_string_t cmd_port_in_disable_disable_string =
961 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result,
962 disable_string, "disable");
964 cmdline_parse_inst_t cmd_port_in_disable = {
965 .f = cmd_port_in_disable_parsed,
967 .help_str = "Pipeline input port disable",
969 (void *) &cmd_port_in_disable_p_string,
970 (void *) &cmd_port_in_disable_pipeline_id,
971 (void *) &cmd_port_in_disable_port_string,
972 (void *) &cmd_port_in_disable_in_string,
973 (void *) &cmd_port_in_disable_port_in_id,
974 (void *) &cmd_port_in_disable_disable_string,
984 print_link_info(struct app_link_params *p)
986 struct rte_eth_stats stats;
987 struct ether_addr *mac_addr;
988 uint32_t netmask = (~0U) << (32 - p->depth);
989 uint32_t host = p->ip & netmask;
990 uint32_t bcast = host | (~netmask);
992 memset(&stats, 0, sizeof(stats));
993 rte_eth_stats_get(p->pmd_id, &stats);
995 mac_addr = (struct ether_addr *) &p->mac_addr;
997 if (strlen(p->pci_bdf))
998 printf("%s(%s): flags=<%s>\n",
1001 (p->state) ? "UP" : "DOWN");
1003 printf("%s: flags=<%s>\n",
1005 (p->state) ? "UP" : "DOWN");
1008 printf("\tinet %" PRIu32 ".%" PRIu32
1009 ".%" PRIu32 ".%" PRIu32
1010 " netmask %" PRIu32 ".%" PRIu32
1011 ".%" PRIu32 ".%" PRIu32 " "
1012 "broadcast %" PRIu32 ".%" PRIu32
1013 ".%" PRIu32 ".%" PRIu32 "\n",
1014 (p->ip >> 24) & 0xFF,
1015 (p->ip >> 16) & 0xFF,
1016 (p->ip >> 8) & 0xFF,
1018 (netmask >> 24) & 0xFF,
1019 (netmask >> 16) & 0xFF,
1020 (netmask >> 8) & 0xFF,
1022 (bcast >> 24) & 0xFF,
1023 (bcast >> 16) & 0xFF,
1024 (bcast >> 8) & 0xFF,
1027 printf("\tether %02" PRIx32 ":%02" PRIx32 ":%02" PRIx32
1028 ":%02" PRIx32 ":%02" PRIx32 ":%02" PRIx32 "\n",
1029 mac_addr->addr_bytes[0],
1030 mac_addr->addr_bytes[1],
1031 mac_addr->addr_bytes[2],
1032 mac_addr->addr_bytes[3],
1033 mac_addr->addr_bytes[4],
1034 mac_addr->addr_bytes[5]);
1036 printf("\tRX packets %" PRIu64
1042 printf("\tRX errors %" PRIu64
1050 printf("\tTX packets %" PRIu64
1051 " bytes %" PRIu64 "\n",
1055 printf("\tTX errors %" PRIu64
1062 struct cmd_link_config_result {
1063 cmdline_fixed_string_t link_string;
1065 cmdline_fixed_string_t config_string;
1066 cmdline_ipaddr_t ip;
1071 cmd_link_config_parsed(
1072 void *parsed_result,
1073 __attribute__((unused)) struct cmdline *cl,
1076 struct cmd_link_config_result *params = parsed_result;
1077 struct app_params *app = data;
1080 uint32_t link_id = params->link_id;
1083 if (params->ip.family == AF_INET)
1084 ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr);
1086 memcpy(ipv6, params->ip.addr.ipv6.s6_addr, 16);
1088 uint32_t depth = params->depth;
1090 if (params->ip.family == AF_INET)
1091 status = app_link_config(app, link_id, ip, depth);
1093 status = app_link_config_ipv6(app, link_id, ipv6, depth);
1096 printf("Command failed\n");
1098 struct app_link_params *p;
1100 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1106 cmdline_parse_token_string_t cmd_link_config_link_string =
1107 TOKEN_STRING_INITIALIZER(struct cmd_link_config_result, link_string,
1110 cmdline_parse_token_num_t cmd_link_config_link_id =
1111 TOKEN_NUM_INITIALIZER(struct cmd_link_config_result, link_id, UINT32);
1113 cmdline_parse_token_string_t cmd_link_config_config_string =
1114 TOKEN_STRING_INITIALIZER(struct cmd_link_config_result, config_string,
1117 cmdline_parse_token_ipaddr_t cmd_link_config_ip =
1118 TOKEN_IPADDR_INITIALIZER(struct cmd_link_config_result, ip);
1120 cmdline_parse_token_num_t cmd_link_config_depth =
1121 TOKEN_NUM_INITIALIZER(struct cmd_link_config_result, depth, UINT32);
1123 cmdline_parse_inst_t cmd_link_config = {
1124 .f = cmd_link_config_parsed,
1126 .help_str = "Link configuration",
1128 (void *)&cmd_link_config_link_string,
1129 (void *)&cmd_link_config_link_id,
1130 (void *)&cmd_link_config_config_string,
1131 (void *)&cmd_link_config_ip,
1132 (void *)&cmd_link_config_depth,
1141 struct cmd_link_up_result {
1142 cmdline_fixed_string_t link_string;
1144 cmdline_fixed_string_t up_string;
1149 void *parsed_result,
1150 __attribute__((unused)) struct cmdline *cl,
1153 struct cmd_link_up_result *params = parsed_result;
1154 struct app_params *app = data;
1157 status = app_link_up(app, params->link_id);
1159 printf("Command failed\n");
1161 struct app_link_params *p;
1163 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", params->link_id,
1170 cmdline_parse_token_string_t cmd_link_up_link_string =
1171 TOKEN_STRING_INITIALIZER(struct cmd_link_up_result, link_string,
1174 cmdline_parse_token_num_t cmd_link_up_link_id =
1175 TOKEN_NUM_INITIALIZER(struct cmd_link_up_result, link_id, UINT32);
1177 cmdline_parse_token_string_t cmd_link_up_up_string =
1178 TOKEN_STRING_INITIALIZER(struct cmd_link_up_result, up_string, "up");
1180 cmdline_parse_inst_t cmd_link_up = {
1181 .f = cmd_link_up_parsed,
1183 .help_str = "Link UP",
1185 (void *)&cmd_link_up_link_string,
1186 (void *)&cmd_link_up_link_id,
1187 (void *)&cmd_link_up_up_string,
1196 struct cmd_link_down_result {
1197 cmdline_fixed_string_t link_string;
1199 cmdline_fixed_string_t down_string;
1203 cmd_link_down_parsed(
1204 void *parsed_result,
1205 __attribute__((unused)) struct cmdline *cl,
1208 struct cmd_link_down_result *params = parsed_result;
1209 struct app_params *app = data;
1212 status = app_link_down(app, params->link_id);
1214 printf("Command failed\n");
1216 struct app_link_params *p;
1218 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", params->link_id,
1225 cmdline_parse_token_string_t cmd_link_down_link_string =
1226 TOKEN_STRING_INITIALIZER(struct cmd_link_down_result, link_string,
1229 cmdline_parse_token_num_t cmd_link_down_link_id =
1230 TOKEN_NUM_INITIALIZER(struct cmd_link_down_result, link_id, UINT32);
1232 cmdline_parse_token_string_t cmd_link_down_down_string =
1233 TOKEN_STRING_INITIALIZER(struct cmd_link_down_result, down_string,
1236 cmdline_parse_inst_t cmd_link_down = {
1237 .f = cmd_link_down_parsed,
1239 .help_str = "Link DOWN",
1241 (void *) &cmd_link_down_link_string,
1242 (void *) &cmd_link_down_link_id,
1243 (void *) &cmd_link_down_down_string,
1252 struct cmd_link_ls_result {
1253 cmdline_fixed_string_t link_string;
1254 cmdline_fixed_string_t ls_string;
1259 __attribute__((unused)) void *parsed_result,
1260 __attribute__((unused)) struct cmdline *cl,
1263 struct app_params *app = data;
1266 for (link_id = 0; link_id < app->n_links; link_id++) {
1267 struct app_link_params *p;
1269 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1273 print_interface_details();
1276 cmdline_parse_token_string_t cmd_link_ls_link_string =
1277 TOKEN_STRING_INITIALIZER(struct cmd_link_ls_result, link_string,
1280 cmdline_parse_token_string_t cmd_link_ls_ls_string =
1281 TOKEN_STRING_INITIALIZER(struct cmd_link_ls_result, ls_string, "ls");
1283 cmdline_parse_inst_t cmd_link_ls = {
1284 .f = cmd_link_ls_parsed,
1286 .help_str = "Link list",
1288 (void *)&cmd_link_ls_link_string,
1289 (void *)&cmd_link_ls_ls_string,
1298 struct cmd_quit_result {
1299 cmdline_fixed_string_t quit;
1304 __rte_unused void *parsed_result,
1306 __rte_unused void *data)
1311 static cmdline_parse_token_string_t cmd_quit_quit =
1312 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
1314 static cmdline_parse_inst_t cmd_quit = {
1315 .f = cmd_quit_parsed,
1319 (void *) &cmd_quit_quit,
1330 cmdline_parse_ctx_t *ctx,
1331 const char *file_name)
1333 struct cmdline *file_cl;
1336 fd = open(file_name, O_RDONLY);
1338 printf("Cannot open file \"%s\"\n", file_name);
1342 file_cl = cmdline_new(ctx, "", fd, 1);
1343 cmdline_interact(file_cl);
1347 struct cmd_run_file_result {
1348 cmdline_fixed_string_t run_string;
1349 char file_name[APP_FILE_NAME_SIZE];
1354 void *parsed_result,
1356 __attribute__((unused)) void *data)
1358 struct cmd_run_file_result *params = parsed_result;
1360 app_run_file(cl->ctx, params->file_name);
1363 cmdline_parse_token_string_t cmd_run_run_string =
1364 TOKEN_STRING_INITIALIZER(struct cmd_run_file_result, run_string,
1367 cmdline_parse_token_string_t cmd_run_file_name =
1368 TOKEN_STRING_INITIALIZER(struct cmd_run_file_result, file_name, NULL);
1370 cmdline_parse_inst_t cmd_run = {
1371 .f = cmd_run_parsed,
1373 .help_str = "Run CLI script file",
1375 (void *) &cmd_run_run_string,
1376 (void *) &cmd_run_file_name,
1381 static cmdline_parse_ctx_t pipeline_common_cmds[] = {
1382 (cmdline_parse_inst_t *) &cmd_quit,
1383 (cmdline_parse_inst_t *) &cmd_run,
1385 (cmdline_parse_inst_t *) &cmd_link_config,
1386 (cmdline_parse_inst_t *) &cmd_link_up,
1387 (cmdline_parse_inst_t *) &cmd_link_down,
1388 (cmdline_parse_inst_t *) &cmd_link_ls,
1390 (cmdline_parse_inst_t *) &cmd_ping,
1391 (cmdline_parse_inst_t *) &cmd_stats_port_in,
1392 (cmdline_parse_inst_t *) &cmd_stats_port_out,
1393 (cmdline_parse_inst_t *) &cmd_stats_table,
1394 (cmdline_parse_inst_t *) &cmd_port_in_enable,
1395 (cmdline_parse_inst_t *) &cmd_port_in_disable,
1400 app_pipeline_common_cmd_push(struct app_params *app)
1404 /* Check for available slots in the application commands array */
1405 n_cmds = RTE_DIM(pipeline_common_cmds) - 1;
1406 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1409 /* Push pipeline commands into the application */
1410 memcpy(&app->cmds[app->n_cmds],
1411 pipeline_common_cmds,
1412 n_cmds * sizeof(cmdline_parse_ctx_t));
1414 for (i = 0; i < n_cmds; i++)
1415 app->cmds[app->n_cmds + i]->data = app;
1417 app->n_cmds += n_cmds;
1418 app->cmds[app->n_cmds] = NULL;