1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
9 #include <rte_common.h>
10 #include <rte_malloc.h>
11 #include <cmdline_rdline.h>
12 #include <cmdline_parse.h>
13 #include <cmdline_parse_num.h>
14 #include <cmdline_parse_string.h>
17 #include "pipeline_common_fe.h"
20 struct app_link_params *
21 app_pipeline_track_pktq_out_to_link(struct app_params *app,
25 struct app_pipeline_params *p;
27 /* Check input arguments */
31 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
36 struct app_pktq_out_params *pktq_out =
37 &p->pktq_out[pktq_out_id];
39 switch (pktq_out->type) {
40 case APP_PKTQ_OUT_HWQ:
42 struct app_pktq_hwq_out_params *hwq_out;
44 hwq_out = &app->hwq_out_params[pktq_out->id];
46 return app_get_link_for_txq(app, hwq_out);
49 case APP_PKTQ_OUT_SWQ:
51 struct pipeline_params pp;
52 struct pipeline_type *ptype;
53 struct app_pktq_swq_params *swq;
57 swq = &app->swq_params[pktq_out->id];
58 p = app_swq_get_reader(app, swq, &pktq_in_id);
62 ptype = app_pipeline_type_find(app, p->type);
63 if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL))
66 app_pipeline_params_get(app, p, &pp);
67 status = ptype->fe_ops->f_track(&pp,
78 struct pipeline_params pp;
79 struct pipeline_type *ptype;
80 struct app_pktq_tm_params *tm;
84 tm = &app->tm_params[pktq_out->id];
85 p = app_tm_get_reader(app, tm, &pktq_in_id);
89 ptype = app_pipeline_type_find(app, p->type);
90 if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL))
93 app_pipeline_params_get(app, p, &pp);
94 status = ptype->fe_ops->f_track(&pp,
103 case APP_PKTQ_OUT_KNI:
105 struct pipeline_params pp;
106 struct pipeline_type *ptype;
107 struct app_pktq_kni_params *kni;
111 kni = &app->kni_params[pktq_out->id];
112 p = app_kni_get_reader(app, kni, &pktq_in_id);
116 ptype = app_pipeline_type_find(app, p->type);
117 if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL))
120 app_pipeline_params_get(app, p, &pp);
121 status = ptype->fe_ops->f_track(&pp,
130 case APP_PKTQ_OUT_TAP:
131 case APP_PKTQ_OUT_SINK:
139 app_pipeline_track_default(struct pipeline_params *p,
143 /* Check input arguments */
145 (port_in >= p->n_ports_in) ||
149 if (p->n_ports_out == 1) {
158 app_pipeline_ping(struct app_params *app,
159 uint32_t pipeline_id)
161 struct app_pipeline_params *p;
162 struct pipeline_msg_req *req;
163 struct pipeline_msg_rsp *rsp;
166 /* Check input arguments */
170 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
174 /* Message buffer allocation */
175 req = app_msg_alloc(app);
179 /* Fill in request */
180 req->type = PIPELINE_MSG_REQ_PING;
182 /* Send request and wait for response */
183 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
188 status = rsp->status;
190 /* Message buffer free */
191 app_msg_free(app, rsp);
197 app_pipeline_stats_port_in(struct app_params *app,
198 uint32_t pipeline_id,
200 struct rte_pipeline_port_in_stats *stats)
202 struct app_pipeline_params *p;
203 struct pipeline_stats_msg_req *req;
204 struct pipeline_stats_port_in_msg_rsp *rsp;
207 /* Check input arguments */
212 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
214 (port_id >= p->n_pktq_in))
217 /* Message buffer allocation */
218 req = app_msg_alloc(app);
222 /* Fill in request */
223 req->type = PIPELINE_MSG_REQ_STATS_PORT_IN;
226 /* Send request and wait for response */
227 rsp = (struct pipeline_stats_port_in_msg_rsp *)
228 app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
233 status = rsp->status;
235 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
237 /* Message buffer free */
238 app_msg_free(app, rsp);
244 app_pipeline_stats_port_out(struct app_params *app,
245 uint32_t pipeline_id,
247 struct rte_pipeline_port_out_stats *stats)
249 struct app_pipeline_params *p;
250 struct pipeline_stats_msg_req *req;
251 struct pipeline_stats_port_out_msg_rsp *rsp;
254 /* Check input arguments */
256 (pipeline_id >= app->n_pipelines) ||
260 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
262 (port_id >= p->n_pktq_out))
265 /* Message buffer allocation */
266 req = app_msg_alloc(app);
270 /* Fill in request */
271 req->type = PIPELINE_MSG_REQ_STATS_PORT_OUT;
274 /* Send request and wait for response */
275 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
280 status = rsp->status;
282 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
284 /* Message buffer free */
285 app_msg_free(app, rsp);
291 app_pipeline_stats_table(struct app_params *app,
292 uint32_t pipeline_id,
294 struct rte_pipeline_table_stats *stats)
296 struct app_pipeline_params *p;
297 struct pipeline_stats_msg_req *req;
298 struct pipeline_stats_table_msg_rsp *rsp;
301 /* Check input arguments */
306 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
310 /* Message buffer allocation */
311 req = app_msg_alloc(app);
315 /* Fill in request */
316 req->type = PIPELINE_MSG_REQ_STATS_TABLE;
319 /* Send request and wait for response */
320 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
325 status = rsp->status;
327 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
329 /* Message buffer free */
330 app_msg_free(app, rsp);
336 app_pipeline_port_in_enable(struct app_params *app,
337 uint32_t pipeline_id,
340 struct app_pipeline_params *p;
341 struct pipeline_port_in_msg_req *req;
342 struct pipeline_msg_rsp *rsp;
345 /* Check input arguments */
349 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
351 (port_id >= p->n_pktq_in))
354 /* Message buffer allocation */
355 req = app_msg_alloc(app);
359 /* Fill in request */
360 req->type = PIPELINE_MSG_REQ_PORT_IN_ENABLE;
361 req->port_id = port_id;
363 /* Send request and wait for response */
364 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
369 status = rsp->status;
371 /* Message buffer free */
372 app_msg_free(app, rsp);
378 app_pipeline_port_in_disable(struct app_params *app,
379 uint32_t pipeline_id,
382 struct app_pipeline_params *p;
383 struct pipeline_port_in_msg_req *req;
384 struct pipeline_msg_rsp *rsp;
387 /* Check input arguments */
391 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
393 (port_id >= p->n_pktq_in))
396 /* Message buffer allocation */
397 req = app_msg_alloc(app);
401 /* Fill in request */
402 req->type = PIPELINE_MSG_REQ_PORT_IN_DISABLE;
403 req->port_id = port_id;
405 /* Send request and wait for response */
406 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
411 status = rsp->status;
413 /* Message buffer free */
414 app_msg_free(app, rsp);
420 app_link_set_op(struct app_params *app,
422 uint32_t pipeline_id,
426 struct app_pipeline_params *pp;
427 struct app_link_params *lp;
428 struct app_link_data *ld;
431 /* Check input arguments */
436 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, lp);
439 lpos = lp - app->link_params;
440 ld = &app->link_data[lpos];
442 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, pp);
445 ppos = pp - app->pipeline_params;
447 ld->f_link[ppos] = op;
454 app_link_config(struct app_params *app,
459 struct app_link_params *p;
460 uint32_t i, netmask, host, bcast;
462 /* Check input arguments */
466 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
468 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
474 APP_LOG(app, HIGH, "%s is UP, please bring it DOWN first",
479 netmask = (~0U) << (32 - depth);
481 bcast = host | (~netmask);
484 (ip == UINT32_MAX) ||
487 APP_LOG(app, HIGH, "Illegal IP address");
491 for (i = 0; i < app->n_links; i++) {
492 struct app_link_params *link = &app->link_params[i];
494 if (strcmp(p->name, link->name) == 0)
497 if (link->ip == ip) {
499 "%s is already assigned this IP address",
505 if ((depth == 0) || (depth > 32)) {
506 APP_LOG(app, HIGH, "Illegal value for depth parameter "
512 /* Save link parameters */
520 app_link_up(struct app_params *app,
523 struct app_link_params *p;
524 struct app_link_data *d;
527 /* Check input arguments */
531 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
533 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
538 d = &app->link_data[p - app->link_params];
540 /* Check link state */
542 APP_LOG(app, HIGH, "%s is already UP", p->name);
546 /* Check that IP address is valid */
548 APP_LOG(app, HIGH, "%s IP address is not set", p->name);
552 app_link_up_internal(app, p);
555 for (i = 0; i < APP_MAX_PIPELINES; i++)
557 d->f_link[i](app, link_id, 1, d->arg[i]);
563 app_link_down(struct app_params *app,
566 struct app_link_params *p;
567 struct app_link_data *d;
570 /* Check input arguments */
574 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
576 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
581 d = &app->link_data[p - app->link_params];
583 /* Check link state */
585 APP_LOG(app, HIGH, "%s is already DOWN", p->name);
589 app_link_down_internal(app, p);
592 for (i = 0; i < APP_MAX_PIPELINES; i++)
594 d->f_link[i](app, link_id, 0, d->arg[i]);
603 struct cmd_ping_result {
604 cmdline_fixed_string_t p_string;
605 uint32_t pipeline_id;
606 cmdline_fixed_string_t ping_string;
612 __rte_unused struct cmdline *cl,
615 struct cmd_ping_result *params = parsed_result;
616 struct app_params *app = data;
619 status = app_pipeline_ping(app, params->pipeline_id);
621 printf("Command failed\n");
624 static cmdline_parse_token_string_t cmd_ping_p_string =
625 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, p_string, "p");
627 static cmdline_parse_token_num_t cmd_ping_pipeline_id =
628 TOKEN_NUM_INITIALIZER(struct cmd_ping_result, pipeline_id, UINT32);
630 static cmdline_parse_token_string_t cmd_ping_ping_string =
631 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, ping_string, "ping");
633 static cmdline_parse_inst_t cmd_ping = {
634 .f = cmd_ping_parsed,
636 .help_str = "Pipeline ping",
638 (void *) &cmd_ping_p_string,
639 (void *) &cmd_ping_pipeline_id,
640 (void *) &cmd_ping_ping_string,
649 struct cmd_stats_port_in_result {
650 cmdline_fixed_string_t p_string;
651 uint32_t pipeline_id;
652 cmdline_fixed_string_t stats_string;
653 cmdline_fixed_string_t port_string;
654 cmdline_fixed_string_t in_string;
660 cmd_stats_port_in_parsed(
662 __rte_unused struct cmdline *cl,
665 struct cmd_stats_port_in_result *params = parsed_result;
666 struct app_params *app = data;
667 struct rte_pipeline_port_in_stats stats;
670 status = app_pipeline_stats_port_in(app,
676 printf("Command failed\n");
681 printf("Pipeline %" PRIu32 " - stats for input port %" PRIu32 ":\n"
682 "\tPkts in: %" PRIu64 "\n"
683 "\tPkts dropped by AH: %" PRIu64 "\n"
684 "\tPkts dropped by other: %" PRIu64 "\n",
687 stats.stats.n_pkts_in,
688 stats.n_pkts_dropped_by_ah,
689 stats.stats.n_pkts_drop);
692 static cmdline_parse_token_string_t cmd_stats_port_in_p_string =
693 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, p_string,
696 static cmdline_parse_token_num_t cmd_stats_port_in_pipeline_id =
697 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, pipeline_id,
700 static cmdline_parse_token_string_t cmd_stats_port_in_stats_string =
701 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, stats_string,
704 static cmdline_parse_token_string_t cmd_stats_port_in_port_string =
705 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, port_string,
708 static cmdline_parse_token_string_t cmd_stats_port_in_in_string =
709 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, in_string,
712 cmdline_parse_token_num_t cmd_stats_port_in_port_in_id =
713 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, port_in_id,
716 static cmdline_parse_inst_t cmd_stats_port_in = {
717 .f = cmd_stats_port_in_parsed,
719 .help_str = "Pipeline input port stats",
721 (void *) &cmd_stats_port_in_p_string,
722 (void *) &cmd_stats_port_in_pipeline_id,
723 (void *) &cmd_stats_port_in_stats_string,
724 (void *) &cmd_stats_port_in_port_string,
725 (void *) &cmd_stats_port_in_in_string,
726 (void *) &cmd_stats_port_in_port_in_id,
735 struct cmd_stats_port_out_result {
736 cmdline_fixed_string_t p_string;
737 uint32_t pipeline_id;
738 cmdline_fixed_string_t stats_string;
739 cmdline_fixed_string_t port_string;
740 cmdline_fixed_string_t out_string;
741 uint32_t port_out_id;
745 cmd_stats_port_out_parsed(
747 __rte_unused struct cmdline *cl,
751 struct cmd_stats_port_out_result *params = parsed_result;
752 struct app_params *app = data;
753 struct rte_pipeline_port_out_stats stats;
756 status = app_pipeline_stats_port_out(app,
762 printf("Command failed\n");
767 printf("Pipeline %" PRIu32 " - stats for output port %" PRIu32 ":\n"
768 "\tPkts in: %" PRIu64 "\n"
769 "\tPkts dropped by AH: %" PRIu64 "\n"
770 "\tPkts dropped by other: %" PRIu64 "\n",
773 stats.stats.n_pkts_in,
774 stats.n_pkts_dropped_by_ah,
775 stats.stats.n_pkts_drop);
778 static cmdline_parse_token_string_t cmd_stats_port_out_p_string =
779 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, p_string,
782 static cmdline_parse_token_num_t cmd_stats_port_out_pipeline_id =
783 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, pipeline_id,
786 static cmdline_parse_token_string_t cmd_stats_port_out_stats_string =
787 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, stats_string,
790 static cmdline_parse_token_string_t cmd_stats_port_out_port_string =
791 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, port_string,
794 static cmdline_parse_token_string_t cmd_stats_port_out_out_string =
795 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, out_string,
798 static cmdline_parse_token_num_t cmd_stats_port_out_port_out_id =
799 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, port_out_id,
802 static cmdline_parse_inst_t cmd_stats_port_out = {
803 .f = cmd_stats_port_out_parsed,
805 .help_str = "Pipeline output port stats",
807 (void *) &cmd_stats_port_out_p_string,
808 (void *) &cmd_stats_port_out_pipeline_id,
809 (void *) &cmd_stats_port_out_stats_string,
810 (void *) &cmd_stats_port_out_port_string,
811 (void *) &cmd_stats_port_out_out_string,
812 (void *) &cmd_stats_port_out_port_out_id,
821 struct cmd_stats_table_result {
822 cmdline_fixed_string_t p_string;
823 uint32_t pipeline_id;
824 cmdline_fixed_string_t stats_string;
825 cmdline_fixed_string_t table_string;
830 cmd_stats_table_parsed(
832 __rte_unused struct cmdline *cl,
835 struct cmd_stats_table_result *params = parsed_result;
836 struct app_params *app = data;
837 struct rte_pipeline_table_stats stats;
840 status = app_pipeline_stats_table(app,
846 printf("Command failed\n");
851 printf("Pipeline %" PRIu32 " - stats for table %" PRIu32 ":\n"
852 "\tPkts in: %" PRIu64 "\n"
853 "\tPkts in with lookup miss: %" PRIu64 "\n"
854 "\tPkts in with lookup hit dropped by AH: %" PRIu64 "\n"
855 "\tPkts in with lookup hit dropped by others: %" PRIu64 "\n"
856 "\tPkts in with lookup miss dropped by AH: %" PRIu64 "\n"
857 "\tPkts in with lookup miss dropped by others: %" PRIu64 "\n",
860 stats.stats.n_pkts_in,
861 stats.stats.n_pkts_lookup_miss,
862 stats.n_pkts_dropped_by_lkp_hit_ah,
863 stats.n_pkts_dropped_lkp_hit,
864 stats.n_pkts_dropped_by_lkp_miss_ah,
865 stats.n_pkts_dropped_lkp_miss);
868 static cmdline_parse_token_string_t cmd_stats_table_p_string =
869 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, p_string,
872 static cmdline_parse_token_num_t cmd_stats_table_pipeline_id =
873 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, pipeline_id,
876 static cmdline_parse_token_string_t cmd_stats_table_stats_string =
877 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, stats_string,
880 static cmdline_parse_token_string_t cmd_stats_table_table_string =
881 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, table_string,
884 static cmdline_parse_token_num_t cmd_stats_table_table_id =
885 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, table_id, UINT32);
887 static cmdline_parse_inst_t cmd_stats_table = {
888 .f = cmd_stats_table_parsed,
890 .help_str = "Pipeline table stats",
892 (void *) &cmd_stats_table_p_string,
893 (void *) &cmd_stats_table_pipeline_id,
894 (void *) &cmd_stats_table_stats_string,
895 (void *) &cmd_stats_table_table_string,
896 (void *) &cmd_stats_table_table_id,
905 struct cmd_port_in_enable_result {
906 cmdline_fixed_string_t p_string;
907 uint32_t pipeline_id;
908 cmdline_fixed_string_t port_string;
909 cmdline_fixed_string_t in_string;
911 cmdline_fixed_string_t enable_string;
915 cmd_port_in_enable_parsed(
917 __rte_unused struct cmdline *cl,
920 struct cmd_port_in_enable_result *params = parsed_result;
921 struct app_params *app = data;
924 status = app_pipeline_port_in_enable(app,
929 printf("Command failed\n");
932 static cmdline_parse_token_string_t cmd_port_in_enable_p_string =
933 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, p_string,
936 static cmdline_parse_token_num_t cmd_port_in_enable_pipeline_id =
937 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, pipeline_id,
940 static cmdline_parse_token_string_t cmd_port_in_enable_port_string =
941 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, port_string,
944 static cmdline_parse_token_string_t cmd_port_in_enable_in_string =
945 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, in_string,
948 static cmdline_parse_token_num_t cmd_port_in_enable_port_in_id =
949 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, port_in_id,
952 static cmdline_parse_token_string_t cmd_port_in_enable_enable_string =
953 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result,
954 enable_string, "enable");
956 static cmdline_parse_inst_t cmd_port_in_enable = {
957 .f = cmd_port_in_enable_parsed,
959 .help_str = "Pipeline input port enable",
961 (void *) &cmd_port_in_enable_p_string,
962 (void *) &cmd_port_in_enable_pipeline_id,
963 (void *) &cmd_port_in_enable_port_string,
964 (void *) &cmd_port_in_enable_in_string,
965 (void *) &cmd_port_in_enable_port_in_id,
966 (void *) &cmd_port_in_enable_enable_string,
975 struct cmd_port_in_disable_result {
976 cmdline_fixed_string_t p_string;
977 uint32_t pipeline_id;
978 cmdline_fixed_string_t port_string;
979 cmdline_fixed_string_t in_string;
981 cmdline_fixed_string_t disable_string;
985 cmd_port_in_disable_parsed(
987 __rte_unused struct cmdline *cl,
990 struct cmd_port_in_disable_result *params = parsed_result;
991 struct app_params *app = data;
994 status = app_pipeline_port_in_disable(app,
999 printf("Command failed\n");
1002 static cmdline_parse_token_string_t cmd_port_in_disable_p_string =
1003 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, p_string,
1006 static cmdline_parse_token_num_t cmd_port_in_disable_pipeline_id =
1007 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, pipeline_id,
1010 static cmdline_parse_token_string_t cmd_port_in_disable_port_string =
1011 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, port_string,
1014 static cmdline_parse_token_string_t cmd_port_in_disable_in_string =
1015 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, in_string,
1018 static cmdline_parse_token_num_t cmd_port_in_disable_port_in_id =
1019 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, port_in_id,
1022 static cmdline_parse_token_string_t cmd_port_in_disable_disable_string =
1023 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result,
1024 disable_string, "disable");
1026 static cmdline_parse_inst_t cmd_port_in_disable = {
1027 .f = cmd_port_in_disable_parsed,
1029 .help_str = "Pipeline input port disable",
1031 (void *) &cmd_port_in_disable_p_string,
1032 (void *) &cmd_port_in_disable_pipeline_id,
1033 (void *) &cmd_port_in_disable_port_string,
1034 (void *) &cmd_port_in_disable_in_string,
1035 (void *) &cmd_port_in_disable_port_in_id,
1036 (void *) &cmd_port_in_disable_disable_string,
1046 print_link_info(struct app_link_params *p)
1048 struct rte_eth_stats stats;
1049 struct ether_addr *mac_addr;
1050 uint32_t netmask = (~0U) << (32 - p->depth);
1051 uint32_t host = p->ip & netmask;
1052 uint32_t bcast = host | (~netmask);
1054 memset(&stats, 0, sizeof(stats));
1055 rte_eth_stats_get(p->pmd_id, &stats);
1057 mac_addr = (struct ether_addr *) &p->mac_addr;
1059 if (strlen(p->pci_bdf))
1060 printf("%s(%s): flags=<%s>\n",
1063 (p->state) ? "UP" : "DOWN");
1065 printf("%s: flags=<%s>\n",
1067 (p->state) ? "UP" : "DOWN");
1070 printf("\tinet %" PRIu32 ".%" PRIu32
1071 ".%" PRIu32 ".%" PRIu32
1072 " netmask %" PRIu32 ".%" PRIu32
1073 ".%" PRIu32 ".%" PRIu32 " "
1074 "broadcast %" PRIu32 ".%" PRIu32
1075 ".%" PRIu32 ".%" PRIu32 "\n",
1076 (p->ip >> 24) & 0xFF,
1077 (p->ip >> 16) & 0xFF,
1078 (p->ip >> 8) & 0xFF,
1080 (netmask >> 24) & 0xFF,
1081 (netmask >> 16) & 0xFF,
1082 (netmask >> 8) & 0xFF,
1084 (bcast >> 24) & 0xFF,
1085 (bcast >> 16) & 0xFF,
1086 (bcast >> 8) & 0xFF,
1089 printf("\tether %02" PRIx32 ":%02" PRIx32 ":%02" PRIx32
1090 ":%02" PRIx32 ":%02" PRIx32 ":%02" PRIx32 "\n",
1091 mac_addr->addr_bytes[0],
1092 mac_addr->addr_bytes[1],
1093 mac_addr->addr_bytes[2],
1094 mac_addr->addr_bytes[3],
1095 mac_addr->addr_bytes[4],
1096 mac_addr->addr_bytes[5]);
1098 printf("\tRX packets %" PRIu64
1104 printf("\tRX errors %" PRIu64
1112 printf("\tTX packets %" PRIu64
1113 " bytes %" PRIu64 "\n",
1117 printf("\tTX errors %" PRIu64
1128 * link <linkid> config <ipaddr> <depth>
1134 * link <linkid> down
1140 struct cmd_link_result {
1141 cmdline_fixed_string_t link_string;
1142 cmdline_multi_string_t multi_string;
1147 void *parsed_result,
1148 __attribute__((unused)) struct cmdline *cl,
1151 struct cmd_link_result *params = parsed_result;
1152 struct app_params *app = data;
1155 uint32_t n_tokens = RTE_DIM(tokens);
1160 status = parse_tokenize_string(params->multi_string, tokens, &n_tokens);
1162 printf(CMD_MSG_TOO_MANY_ARGS, "link");
1167 if ((n_tokens == 1) && (strcmp(tokens[0], "ls") == 0)) {
1168 for (link_id = 0; link_id < app->n_links; link_id++) {
1169 struct app_link_params *p;
1171 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1178 printf(CMD_MSG_MISMATCH_ARGS, "link");
1182 if (parser_read_uint32(&link_id, tokens[0])) {
1183 printf(CMD_MSG_INVALID_ARG, "linkid");
1188 if (strcmp(tokens[1], "config") == 0) {
1189 struct in_addr ipaddr_ipv4;
1192 if (n_tokens != 4) {
1193 printf(CMD_MSG_MISMATCH_ARGS, "link config");
1197 if (parse_ipv4_addr(tokens[2], &ipaddr_ipv4)) {
1198 printf(CMD_MSG_INVALID_ARG, "ipaddr");
1202 if (parser_read_uint32(&depth, tokens[3])) {
1203 printf(CMD_MSG_INVALID_ARG, "depth");
1207 status = app_link_config(app,
1209 rte_be_to_cpu_32(ipaddr_ipv4.s_addr),
1212 printf(CMD_MSG_FAIL, "link config");
1218 if (strcmp(tokens[1], "up") == 0) {
1219 if (n_tokens != 2) {
1220 printf(CMD_MSG_MISMATCH_ARGS, "link up");
1224 status = app_link_up(app, link_id);
1226 printf(CMD_MSG_FAIL, "link up");
1232 if (strcmp(tokens[1], "down") == 0) {
1233 if (n_tokens != 2) {
1234 printf(CMD_MSG_MISMATCH_ARGS, "link down");
1238 status = app_link_down(app, link_id);
1240 printf(CMD_MSG_FAIL, "link down");
1245 printf(CMD_MSG_MISMATCH_ARGS, "link");
1248 static cmdline_parse_token_string_t cmd_link_link_string =
1249 TOKEN_STRING_INITIALIZER(struct cmd_link_result, link_string, "link");
1251 static cmdline_parse_token_string_t cmd_link_multi_string =
1252 TOKEN_STRING_INITIALIZER(struct cmd_link_result, multi_string,
1253 TOKEN_STRING_MULTI);
1255 static cmdline_parse_inst_t cmd_link = {
1256 .f = cmd_link_parsed,
1258 .help_str = "link config / up / down / ls",
1260 (void *) &cmd_link_link_string,
1261 (void *) &cmd_link_multi_string,
1270 struct cmd_quit_result {
1271 cmdline_fixed_string_t quit;
1276 __rte_unused void *parsed_result,
1278 __rte_unused void *data)
1283 static cmdline_parse_token_string_t cmd_quit_quit =
1284 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
1286 static cmdline_parse_inst_t cmd_quit = {
1287 .f = cmd_quit_parsed,
1291 (void *) &cmd_quit_quit,
1300 * run <file> [<count> [<interval>]]
1301 <count> default is 1
1302 * <interval> is measured in milliseconds, default is 1 second
1307 cmdline_parse_ctx_t *ctx,
1308 const char *file_name)
1310 struct cmdline *file_cl;
1313 fd = open(file_name, O_RDONLY);
1315 printf("Cannot open file \"%s\"\n", file_name);
1319 file_cl = cmdline_new(ctx, "", fd, 1);
1320 cmdline_interact(file_cl);
1324 struct cmd_run_result {
1325 cmdline_fixed_string_t run_string;
1326 cmdline_multi_string_t multi_string;
1331 void *parsed_result,
1333 __attribute__((unused)) void *data)
1335 struct cmd_run_result *params = parsed_result;
1338 uint32_t n_tokens = RTE_DIM(tokens);
1342 uint32_t count, interval, i;
1344 status = parse_tokenize_string(params->multi_string, tokens, &n_tokens);
1346 printf(CMD_MSG_TOO_MANY_ARGS, "run");
1352 printf(CMD_MSG_NOT_ENOUGH_ARGS, "run");
1356 file_name = tokens[0];
1362 file_name = tokens[0];
1364 if (parser_read_uint32(&count, tokens[1]) ||
1366 printf(CMD_MSG_INVALID_ARG, "count");
1374 file_name = tokens[0];
1376 if (parser_read_uint32(&count, tokens[1]) ||
1378 printf(CMD_MSG_INVALID_ARG, "count");
1382 if (parser_read_uint32(&interval, tokens[2]) ||
1384 printf(CMD_MSG_INVALID_ARG, "interval");
1390 printf(CMD_MSG_MISMATCH_ARGS, "run");
1394 for (i = 0; i < count; i++) {
1395 app_run_file(cl->ctx, file_name);
1397 usleep(interval * 1000);
1401 static cmdline_parse_token_string_t cmd_run_run_string =
1402 TOKEN_STRING_INITIALIZER(struct cmd_run_result, run_string, "run");
1404 static cmdline_parse_token_string_t cmd_run_multi_string =
1405 TOKEN_STRING_INITIALIZER(struct cmd_run_result, multi_string,
1406 TOKEN_STRING_MULTI);
1409 static cmdline_parse_inst_t cmd_run = {
1410 .f = cmd_run_parsed,
1412 .help_str = "Run CLI script file",
1414 (void *) &cmd_run_run_string,
1415 (void *) &cmd_run_multi_string,
1420 static cmdline_parse_ctx_t pipeline_common_cmds[] = {
1421 (cmdline_parse_inst_t *) &cmd_quit,
1422 (cmdline_parse_inst_t *) &cmd_run,
1423 (cmdline_parse_inst_t *) &cmd_link,
1424 (cmdline_parse_inst_t *) &cmd_ping,
1425 (cmdline_parse_inst_t *) &cmd_stats_port_in,
1426 (cmdline_parse_inst_t *) &cmd_stats_port_out,
1427 (cmdline_parse_inst_t *) &cmd_stats_table,
1428 (cmdline_parse_inst_t *) &cmd_port_in_enable,
1429 (cmdline_parse_inst_t *) &cmd_port_in_disable,
1434 app_pipeline_common_cmd_push(struct app_params *app)
1438 /* Check for available slots in the application commands array */
1439 n_cmds = RTE_DIM(pipeline_common_cmds) - 1;
1440 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1443 /* Push pipeline commands into the application */
1444 memcpy(&app->cmds[app->n_cmds],
1445 pipeline_common_cmds,
1446 n_cmds * sizeof(cmdline_parse_ctx_t));
1448 for (i = 0; i < n_cmds; i++)
1449 app->cmds[app->n_cmds + i]->data = app;
1451 app->n_cmds += n_cmds;
1452 app->cmds[app->n_cmds] = NULL;