4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <rte_common.h>
39 #include <rte_malloc.h>
40 #include <cmdline_rdline.h>
41 #include <cmdline_parse.h>
42 #include <cmdline_parse_num.h>
43 #include <cmdline_parse_string.h>
46 #include "pipeline_common_fe.h"
49 struct app_link_params *
50 app_pipeline_track_pktq_out_to_link(struct app_params *app,
54 struct app_pipeline_params *p;
56 /* Check input arguments */
60 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
65 struct app_pktq_out_params *pktq_out =
66 &p->pktq_out[pktq_out_id];
68 switch (pktq_out->type) {
69 case APP_PKTQ_OUT_HWQ:
71 struct app_pktq_hwq_out_params *hwq_out;
73 hwq_out = &app->hwq_out_params[pktq_out->id];
75 return app_get_link_for_txq(app, hwq_out);
78 case APP_PKTQ_OUT_SWQ:
80 struct pipeline_params pp;
81 struct pipeline_type *ptype;
82 struct app_pktq_swq_params *swq;
86 swq = &app->swq_params[pktq_out->id];
87 p = app_swq_get_reader(app, swq, &pktq_in_id);
91 ptype = app_pipeline_type_find(app, p->type);
92 if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL))
95 app_pipeline_params_get(app, p, &pp);
96 status = ptype->fe_ops->f_track(&pp,
105 case APP_PKTQ_OUT_TM:
107 struct pipeline_params pp;
108 struct pipeline_type *ptype;
109 struct app_pktq_tm_params *tm;
113 tm = &app->tm_params[pktq_out->id];
114 p = app_tm_get_reader(app, tm, &pktq_in_id);
118 ptype = app_pipeline_type_find(app, p->type);
119 if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL))
122 app_pipeline_params_get(app, p, &pp);
123 status = ptype->fe_ops->f_track(&pp,
132 case APP_PKTQ_OUT_KNI:
134 struct pipeline_params pp;
135 struct pipeline_type *ptype;
136 struct app_pktq_kni_params *kni;
140 kni = &app->kni_params[pktq_out->id];
141 p = app_kni_get_reader(app, kni, &pktq_in_id);
145 ptype = app_pipeline_type_find(app, p->type);
146 if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL))
149 app_pipeline_params_get(app, p, &pp);
150 status = ptype->fe_ops->f_track(&pp,
159 case APP_PKTQ_OUT_SINK:
167 app_pipeline_track_default(struct pipeline_params *p,
171 /* Check input arguments */
173 (port_in >= p->n_ports_in) ||
177 if (p->n_ports_out == 1) {
186 app_pipeline_ping(struct app_params *app,
187 uint32_t pipeline_id)
189 struct app_pipeline_params *p;
190 struct pipeline_msg_req *req;
191 struct pipeline_msg_rsp *rsp;
194 /* Check input arguments */
198 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
202 /* Message buffer allocation */
203 req = app_msg_alloc(app);
207 /* Fill in request */
208 req->type = PIPELINE_MSG_REQ_PING;
210 /* Send request and wait for response */
211 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
216 status = rsp->status;
218 /* Message buffer free */
219 app_msg_free(app, rsp);
225 app_pipeline_stats_port_in(struct app_params *app,
226 uint32_t pipeline_id,
228 struct rte_pipeline_port_in_stats *stats)
230 struct app_pipeline_params *p;
231 struct pipeline_stats_msg_req *req;
232 struct pipeline_stats_port_in_msg_rsp *rsp;
235 /* Check input arguments */
240 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
242 (port_id >= p->n_pktq_in))
245 /* Message buffer allocation */
246 req = app_msg_alloc(app);
250 /* Fill in request */
251 req->type = PIPELINE_MSG_REQ_STATS_PORT_IN;
254 /* Send request and wait for response */
255 rsp = (struct pipeline_stats_port_in_msg_rsp *)
256 app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
261 status = rsp->status;
263 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
265 /* Message buffer free */
266 app_msg_free(app, rsp);
272 app_pipeline_stats_port_out(struct app_params *app,
273 uint32_t pipeline_id,
275 struct rte_pipeline_port_out_stats *stats)
277 struct app_pipeline_params *p;
278 struct pipeline_stats_msg_req *req;
279 struct pipeline_stats_port_out_msg_rsp *rsp;
282 /* Check input arguments */
284 (pipeline_id >= app->n_pipelines) ||
288 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
290 (port_id >= p->n_pktq_out))
293 /* Message buffer allocation */
294 req = app_msg_alloc(app);
298 /* Fill in request */
299 req->type = PIPELINE_MSG_REQ_STATS_PORT_OUT;
302 /* Send request and wait for response */
303 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
308 status = rsp->status;
310 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
312 /* Message buffer free */
313 app_msg_free(app, rsp);
319 app_pipeline_stats_table(struct app_params *app,
320 uint32_t pipeline_id,
322 struct rte_pipeline_table_stats *stats)
324 struct app_pipeline_params *p;
325 struct pipeline_stats_msg_req *req;
326 struct pipeline_stats_table_msg_rsp *rsp;
329 /* Check input arguments */
334 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
338 /* Message buffer allocation */
339 req = app_msg_alloc(app);
343 /* Fill in request */
344 req->type = PIPELINE_MSG_REQ_STATS_TABLE;
347 /* Send request and wait for response */
348 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
353 status = rsp->status;
355 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
357 /* Message buffer free */
358 app_msg_free(app, rsp);
364 app_pipeline_port_in_enable(struct app_params *app,
365 uint32_t pipeline_id,
368 struct app_pipeline_params *p;
369 struct pipeline_port_in_msg_req *req;
370 struct pipeline_msg_rsp *rsp;
373 /* Check input arguments */
377 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
379 (port_id >= p->n_pktq_in))
382 /* Message buffer allocation */
383 req = app_msg_alloc(app);
387 /* Fill in request */
388 req->type = PIPELINE_MSG_REQ_PORT_IN_ENABLE;
389 req->port_id = port_id;
391 /* Send request and wait for response */
392 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
397 status = rsp->status;
399 /* Message buffer free */
400 app_msg_free(app, rsp);
406 app_pipeline_port_in_disable(struct app_params *app,
407 uint32_t pipeline_id,
410 struct app_pipeline_params *p;
411 struct pipeline_port_in_msg_req *req;
412 struct pipeline_msg_rsp *rsp;
415 /* Check input arguments */
419 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
421 (port_id >= p->n_pktq_in))
424 /* Message buffer allocation */
425 req = app_msg_alloc(app);
429 /* Fill in request */
430 req->type = PIPELINE_MSG_REQ_PORT_IN_DISABLE;
431 req->port_id = port_id;
433 /* Send request and wait for response */
434 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
439 status = rsp->status;
441 /* Message buffer free */
442 app_msg_free(app, rsp);
448 app_link_set_op(struct app_params *app,
450 uint32_t pipeline_id,
454 struct app_pipeline_params *pp;
455 struct app_link_params *lp;
456 struct app_link_data *ld;
459 /* Check input arguments */
464 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, lp);
467 lpos = lp - app->link_params;
468 ld = &app->link_data[lpos];
470 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, pp);
473 ppos = pp - app->pipeline_params;
475 ld->f_link[ppos] = op;
482 app_link_config(struct app_params *app,
487 struct app_link_params *p;
488 uint32_t i, netmask, host, bcast;
490 /* Check input arguments */
494 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
496 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
502 APP_LOG(app, HIGH, "%s is UP, please bring it DOWN first",
507 netmask = (~0U) << (32 - depth);
509 bcast = host | (~netmask);
512 (ip == UINT32_MAX) ||
515 APP_LOG(app, HIGH, "Illegal IP address");
519 for (i = 0; i < app->n_links; i++) {
520 struct app_link_params *link = &app->link_params[i];
522 if (strcmp(p->name, link->name) == 0)
525 if (link->ip == ip) {
527 "%s is already assigned this IP address",
533 if ((depth == 0) || (depth > 32)) {
534 APP_LOG(app, HIGH, "Illegal value for depth parameter "
540 /* Save link parameters */
548 app_link_up(struct app_params *app,
551 struct app_link_params *p;
552 struct app_link_data *d;
555 /* Check input arguments */
559 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
561 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
566 d = &app->link_data[p - app->link_params];
568 /* Check link state */
570 APP_LOG(app, HIGH, "%s is already UP", p->name);
574 /* Check that IP address is valid */
576 APP_LOG(app, HIGH, "%s IP address is not set", p->name);
580 app_link_up_internal(app, p);
583 for (i = 0; i < APP_MAX_PIPELINES; i++)
585 d->f_link[i](app, link_id, 1, d->arg[i]);
591 app_link_down(struct app_params *app,
594 struct app_link_params *p;
595 struct app_link_data *d;
598 /* Check input arguments */
602 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
604 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
609 d = &app->link_data[p - app->link_params];
611 /* Check link state */
613 APP_LOG(app, HIGH, "%s is already DOWN", p->name);
617 app_link_down_internal(app, p);
620 for (i = 0; i < APP_MAX_PIPELINES; i++)
622 d->f_link[i](app, link_id, 0, d->arg[i]);
631 struct cmd_ping_result {
632 cmdline_fixed_string_t p_string;
633 uint32_t pipeline_id;
634 cmdline_fixed_string_t ping_string;
640 __rte_unused struct cmdline *cl,
643 struct cmd_ping_result *params = parsed_result;
644 struct app_params *app = data;
647 status = app_pipeline_ping(app, params->pipeline_id);
649 printf("Command failed\n");
652 static cmdline_parse_token_string_t cmd_ping_p_string =
653 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, p_string, "p");
655 static cmdline_parse_token_num_t cmd_ping_pipeline_id =
656 TOKEN_NUM_INITIALIZER(struct cmd_ping_result, pipeline_id, UINT32);
658 static cmdline_parse_token_string_t cmd_ping_ping_string =
659 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, ping_string, "ping");
661 static cmdline_parse_inst_t cmd_ping = {
662 .f = cmd_ping_parsed,
664 .help_str = "Pipeline ping",
666 (void *) &cmd_ping_p_string,
667 (void *) &cmd_ping_pipeline_id,
668 (void *) &cmd_ping_ping_string,
677 struct cmd_stats_port_in_result {
678 cmdline_fixed_string_t p_string;
679 uint32_t pipeline_id;
680 cmdline_fixed_string_t stats_string;
681 cmdline_fixed_string_t port_string;
682 cmdline_fixed_string_t in_string;
688 cmd_stats_port_in_parsed(
690 __rte_unused struct cmdline *cl,
693 struct cmd_stats_port_in_result *params = parsed_result;
694 struct app_params *app = data;
695 struct rte_pipeline_port_in_stats stats;
698 status = app_pipeline_stats_port_in(app,
704 printf("Command failed\n");
709 printf("Pipeline %" PRIu32 " - stats for input port %" PRIu32 ":\n"
710 "\tPkts in: %" PRIu64 "\n"
711 "\tPkts dropped by AH: %" PRIu64 "\n"
712 "\tPkts dropped by other: %" PRIu64 "\n",
715 stats.stats.n_pkts_in,
716 stats.n_pkts_dropped_by_ah,
717 stats.stats.n_pkts_drop);
720 static cmdline_parse_token_string_t cmd_stats_port_in_p_string =
721 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, p_string,
724 static cmdline_parse_token_num_t cmd_stats_port_in_pipeline_id =
725 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, pipeline_id,
728 static cmdline_parse_token_string_t cmd_stats_port_in_stats_string =
729 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, stats_string,
732 static cmdline_parse_token_string_t cmd_stats_port_in_port_string =
733 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, port_string,
736 static cmdline_parse_token_string_t cmd_stats_port_in_in_string =
737 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, in_string,
740 cmdline_parse_token_num_t cmd_stats_port_in_port_in_id =
741 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, port_in_id,
744 static cmdline_parse_inst_t cmd_stats_port_in = {
745 .f = cmd_stats_port_in_parsed,
747 .help_str = "Pipeline input port stats",
749 (void *) &cmd_stats_port_in_p_string,
750 (void *) &cmd_stats_port_in_pipeline_id,
751 (void *) &cmd_stats_port_in_stats_string,
752 (void *) &cmd_stats_port_in_port_string,
753 (void *) &cmd_stats_port_in_in_string,
754 (void *) &cmd_stats_port_in_port_in_id,
763 struct cmd_stats_port_out_result {
764 cmdline_fixed_string_t p_string;
765 uint32_t pipeline_id;
766 cmdline_fixed_string_t stats_string;
767 cmdline_fixed_string_t port_string;
768 cmdline_fixed_string_t out_string;
769 uint32_t port_out_id;
773 cmd_stats_port_out_parsed(
775 __rte_unused struct cmdline *cl,
779 struct cmd_stats_port_out_result *params = parsed_result;
780 struct app_params *app = data;
781 struct rte_pipeline_port_out_stats stats;
784 status = app_pipeline_stats_port_out(app,
790 printf("Command failed\n");
795 printf("Pipeline %" PRIu32 " - stats for output port %" PRIu32 ":\n"
796 "\tPkts in: %" PRIu64 "\n"
797 "\tPkts dropped by AH: %" PRIu64 "\n"
798 "\tPkts dropped by other: %" PRIu64 "\n",
801 stats.stats.n_pkts_in,
802 stats.n_pkts_dropped_by_ah,
803 stats.stats.n_pkts_drop);
806 static cmdline_parse_token_string_t cmd_stats_port_out_p_string =
807 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, p_string,
810 static cmdline_parse_token_num_t cmd_stats_port_out_pipeline_id =
811 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, pipeline_id,
814 static cmdline_parse_token_string_t cmd_stats_port_out_stats_string =
815 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, stats_string,
818 static cmdline_parse_token_string_t cmd_stats_port_out_port_string =
819 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, port_string,
822 static cmdline_parse_token_string_t cmd_stats_port_out_out_string =
823 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, out_string,
826 static cmdline_parse_token_num_t cmd_stats_port_out_port_out_id =
827 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, port_out_id,
830 static cmdline_parse_inst_t cmd_stats_port_out = {
831 .f = cmd_stats_port_out_parsed,
833 .help_str = "Pipeline output port stats",
835 (void *) &cmd_stats_port_out_p_string,
836 (void *) &cmd_stats_port_out_pipeline_id,
837 (void *) &cmd_stats_port_out_stats_string,
838 (void *) &cmd_stats_port_out_port_string,
839 (void *) &cmd_stats_port_out_out_string,
840 (void *) &cmd_stats_port_out_port_out_id,
849 struct cmd_stats_table_result {
850 cmdline_fixed_string_t p_string;
851 uint32_t pipeline_id;
852 cmdline_fixed_string_t stats_string;
853 cmdline_fixed_string_t table_string;
858 cmd_stats_table_parsed(
860 __rte_unused struct cmdline *cl,
863 struct cmd_stats_table_result *params = parsed_result;
864 struct app_params *app = data;
865 struct rte_pipeline_table_stats stats;
868 status = app_pipeline_stats_table(app,
874 printf("Command failed\n");
879 printf("Pipeline %" PRIu32 " - stats for table %" PRIu32 ":\n"
880 "\tPkts in: %" PRIu64 "\n"
881 "\tPkts in with lookup miss: %" PRIu64 "\n"
882 "\tPkts in with lookup hit dropped by AH: %" PRIu64 "\n"
883 "\tPkts in with lookup hit dropped by others: %" PRIu64 "\n"
884 "\tPkts in with lookup miss dropped by AH: %" PRIu64 "\n"
885 "\tPkts in with lookup miss dropped by others: %" PRIu64 "\n",
888 stats.stats.n_pkts_in,
889 stats.stats.n_pkts_lookup_miss,
890 stats.n_pkts_dropped_by_lkp_hit_ah,
891 stats.n_pkts_dropped_lkp_hit,
892 stats.n_pkts_dropped_by_lkp_miss_ah,
893 stats.n_pkts_dropped_lkp_miss);
896 static cmdline_parse_token_string_t cmd_stats_table_p_string =
897 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, p_string,
900 static cmdline_parse_token_num_t cmd_stats_table_pipeline_id =
901 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, pipeline_id,
904 static cmdline_parse_token_string_t cmd_stats_table_stats_string =
905 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, stats_string,
908 static cmdline_parse_token_string_t cmd_stats_table_table_string =
909 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, table_string,
912 static cmdline_parse_token_num_t cmd_stats_table_table_id =
913 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, table_id, UINT32);
915 static cmdline_parse_inst_t cmd_stats_table = {
916 .f = cmd_stats_table_parsed,
918 .help_str = "Pipeline table stats",
920 (void *) &cmd_stats_table_p_string,
921 (void *) &cmd_stats_table_pipeline_id,
922 (void *) &cmd_stats_table_stats_string,
923 (void *) &cmd_stats_table_table_string,
924 (void *) &cmd_stats_table_table_id,
933 struct cmd_port_in_enable_result {
934 cmdline_fixed_string_t p_string;
935 uint32_t pipeline_id;
936 cmdline_fixed_string_t port_string;
937 cmdline_fixed_string_t in_string;
939 cmdline_fixed_string_t enable_string;
943 cmd_port_in_enable_parsed(
945 __rte_unused struct cmdline *cl,
948 struct cmd_port_in_enable_result *params = parsed_result;
949 struct app_params *app = data;
952 status = app_pipeline_port_in_enable(app,
957 printf("Command failed\n");
960 static cmdline_parse_token_string_t cmd_port_in_enable_p_string =
961 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, p_string,
964 static cmdline_parse_token_num_t cmd_port_in_enable_pipeline_id =
965 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, pipeline_id,
968 static cmdline_parse_token_string_t cmd_port_in_enable_port_string =
969 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, port_string,
972 static cmdline_parse_token_string_t cmd_port_in_enable_in_string =
973 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, in_string,
976 static cmdline_parse_token_num_t cmd_port_in_enable_port_in_id =
977 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, port_in_id,
980 static cmdline_parse_token_string_t cmd_port_in_enable_enable_string =
981 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result,
982 enable_string, "enable");
984 static cmdline_parse_inst_t cmd_port_in_enable = {
985 .f = cmd_port_in_enable_parsed,
987 .help_str = "Pipeline input port enable",
989 (void *) &cmd_port_in_enable_p_string,
990 (void *) &cmd_port_in_enable_pipeline_id,
991 (void *) &cmd_port_in_enable_port_string,
992 (void *) &cmd_port_in_enable_in_string,
993 (void *) &cmd_port_in_enable_port_in_id,
994 (void *) &cmd_port_in_enable_enable_string,
1003 struct cmd_port_in_disable_result {
1004 cmdline_fixed_string_t p_string;
1005 uint32_t pipeline_id;
1006 cmdline_fixed_string_t port_string;
1007 cmdline_fixed_string_t in_string;
1008 uint32_t port_in_id;
1009 cmdline_fixed_string_t disable_string;
1013 cmd_port_in_disable_parsed(
1014 void *parsed_result,
1015 __rte_unused struct cmdline *cl,
1018 struct cmd_port_in_disable_result *params = parsed_result;
1019 struct app_params *app = data;
1022 status = app_pipeline_port_in_disable(app,
1023 params->pipeline_id,
1024 params->port_in_id);
1027 printf("Command failed\n");
1030 static cmdline_parse_token_string_t cmd_port_in_disable_p_string =
1031 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, p_string,
1034 static cmdline_parse_token_num_t cmd_port_in_disable_pipeline_id =
1035 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, pipeline_id,
1038 static cmdline_parse_token_string_t cmd_port_in_disable_port_string =
1039 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, port_string,
1042 static cmdline_parse_token_string_t cmd_port_in_disable_in_string =
1043 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, in_string,
1046 static cmdline_parse_token_num_t cmd_port_in_disable_port_in_id =
1047 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, port_in_id,
1050 static cmdline_parse_token_string_t cmd_port_in_disable_disable_string =
1051 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result,
1052 disable_string, "disable");
1054 static cmdline_parse_inst_t cmd_port_in_disable = {
1055 .f = cmd_port_in_disable_parsed,
1057 .help_str = "Pipeline input port disable",
1059 (void *) &cmd_port_in_disable_p_string,
1060 (void *) &cmd_port_in_disable_pipeline_id,
1061 (void *) &cmd_port_in_disable_port_string,
1062 (void *) &cmd_port_in_disable_in_string,
1063 (void *) &cmd_port_in_disable_port_in_id,
1064 (void *) &cmd_port_in_disable_disable_string,
1074 print_link_info(struct app_link_params *p)
1076 struct rte_eth_stats stats;
1077 struct ether_addr *mac_addr;
1078 uint32_t netmask = (~0U) << (32 - p->depth);
1079 uint32_t host = p->ip & netmask;
1080 uint32_t bcast = host | (~netmask);
1082 memset(&stats, 0, sizeof(stats));
1083 rte_eth_stats_get(p->pmd_id, &stats);
1085 mac_addr = (struct ether_addr *) &p->mac_addr;
1087 if (strlen(p->pci_bdf))
1088 printf("%s(%s): flags=<%s>\n",
1091 (p->state) ? "UP" : "DOWN");
1093 printf("%s: flags=<%s>\n",
1095 (p->state) ? "UP" : "DOWN");
1098 printf("\tinet %" PRIu32 ".%" PRIu32
1099 ".%" PRIu32 ".%" PRIu32
1100 " netmask %" PRIu32 ".%" PRIu32
1101 ".%" PRIu32 ".%" PRIu32 " "
1102 "broadcast %" PRIu32 ".%" PRIu32
1103 ".%" PRIu32 ".%" PRIu32 "\n",
1104 (p->ip >> 24) & 0xFF,
1105 (p->ip >> 16) & 0xFF,
1106 (p->ip >> 8) & 0xFF,
1108 (netmask >> 24) & 0xFF,
1109 (netmask >> 16) & 0xFF,
1110 (netmask >> 8) & 0xFF,
1112 (bcast >> 24) & 0xFF,
1113 (bcast >> 16) & 0xFF,
1114 (bcast >> 8) & 0xFF,
1117 printf("\tether %02" PRIx32 ":%02" PRIx32 ":%02" PRIx32
1118 ":%02" PRIx32 ":%02" PRIx32 ":%02" PRIx32 "\n",
1119 mac_addr->addr_bytes[0],
1120 mac_addr->addr_bytes[1],
1121 mac_addr->addr_bytes[2],
1122 mac_addr->addr_bytes[3],
1123 mac_addr->addr_bytes[4],
1124 mac_addr->addr_bytes[5]);
1126 printf("\tRX packets %" PRIu64
1132 printf("\tRX errors %" PRIu64
1140 printf("\tTX packets %" PRIu64
1141 " bytes %" PRIu64 "\n",
1145 printf("\tTX errors %" PRIu64
1156 * link <linkid> config <ipaddr> <depth>
1162 * link <linkid> down
1168 struct cmd_link_result {
1169 cmdline_fixed_string_t link_string;
1170 cmdline_multi_string_t multi_string;
1175 void *parsed_result,
1176 __attribute__((unused)) struct cmdline *cl,
1179 struct cmd_link_result *params = parsed_result;
1180 struct app_params *app = data;
1183 uint32_t n_tokens = RTE_DIM(tokens);
1188 status = parse_tokenize_string(params->multi_string, tokens, &n_tokens);
1190 printf(CMD_MSG_TOO_MANY_ARGS, "link");
1195 if ((n_tokens == 1) && (strcmp(tokens[0], "ls") == 0)) {
1196 for (link_id = 0; link_id < app->n_links; link_id++) {
1197 struct app_link_params *p;
1199 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1206 printf(CMD_MSG_MISMATCH_ARGS, "link");
1210 if (parser_read_uint32(&link_id, tokens[0])) {
1211 printf(CMD_MSG_INVALID_ARG, "linkid");
1216 if (strcmp(tokens[1], "config") == 0) {
1217 struct in_addr ipaddr_ipv4;
1220 if (n_tokens != 4) {
1221 printf(CMD_MSG_MISMATCH_ARGS, "link config");
1225 if (parse_ipv4_addr(tokens[2], &ipaddr_ipv4)) {
1226 printf(CMD_MSG_INVALID_ARG, "ipaddr");
1230 if (parser_read_uint32(&depth, tokens[3])) {
1231 printf(CMD_MSG_INVALID_ARG, "depth");
1235 status = app_link_config(app,
1237 rte_be_to_cpu_32(ipaddr_ipv4.s_addr),
1240 printf(CMD_MSG_FAIL, "link config");
1246 if (strcmp(tokens[1], "up") == 0) {
1247 if (n_tokens != 2) {
1248 printf(CMD_MSG_MISMATCH_ARGS, "link up");
1252 status = app_link_up(app, link_id);
1254 printf(CMD_MSG_FAIL, "link up");
1260 if (strcmp(tokens[1], "down") == 0) {
1261 if (n_tokens != 2) {
1262 printf(CMD_MSG_MISMATCH_ARGS, "link down");
1266 status = app_link_down(app, link_id);
1268 printf(CMD_MSG_FAIL, "link down");
1273 printf(CMD_MSG_MISMATCH_ARGS, "link");
1276 static cmdline_parse_token_string_t cmd_link_link_string =
1277 TOKEN_STRING_INITIALIZER(struct cmd_link_result, link_string, "link");
1279 static cmdline_parse_token_string_t cmd_link_multi_string =
1280 TOKEN_STRING_INITIALIZER(struct cmd_link_result, multi_string,
1281 TOKEN_STRING_MULTI);
1283 static cmdline_parse_inst_t cmd_link = {
1284 .f = cmd_link_parsed,
1286 .help_str = "link config / up / down / ls",
1288 (void *) &cmd_link_link_string,
1289 (void *) &cmd_link_multi_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,
1328 * run <file> [<count> [<interval>]]
1329 <count> default is 1
1330 * <interval> is measured in milliseconds, default is 1 second
1335 cmdline_parse_ctx_t *ctx,
1336 const char *file_name)
1338 struct cmdline *file_cl;
1341 fd = open(file_name, O_RDONLY);
1343 printf("Cannot open file \"%s\"\n", file_name);
1347 file_cl = cmdline_new(ctx, "", fd, 1);
1348 cmdline_interact(file_cl);
1352 struct cmd_run_result {
1353 cmdline_fixed_string_t run_string;
1354 cmdline_multi_string_t multi_string;
1359 void *parsed_result,
1361 __attribute__((unused)) void *data)
1363 struct cmd_run_result *params = parsed_result;
1366 uint32_t n_tokens = RTE_DIM(tokens);
1370 uint32_t count, interval, i;
1372 status = parse_tokenize_string(params->multi_string, tokens, &n_tokens);
1374 printf(CMD_MSG_TOO_MANY_ARGS, "run");
1380 printf(CMD_MSG_NOT_ENOUGH_ARGS, "run");
1384 file_name = tokens[0];
1390 file_name = tokens[0];
1392 if (parser_read_uint32(&count, tokens[1]) ||
1394 printf(CMD_MSG_INVALID_ARG, "count");
1402 file_name = tokens[0];
1404 if (parser_read_uint32(&count, tokens[1]) ||
1406 printf(CMD_MSG_INVALID_ARG, "count");
1410 if (parser_read_uint32(&interval, tokens[2]) ||
1412 printf(CMD_MSG_INVALID_ARG, "interval");
1418 printf(CMD_MSG_MISMATCH_ARGS, "run");
1422 for (i = 0; i < count; i++) {
1423 app_run_file(cl->ctx, file_name);
1425 usleep(interval * 1000);
1429 static cmdline_parse_token_string_t cmd_run_run_string =
1430 TOKEN_STRING_INITIALIZER(struct cmd_run_result, run_string, "run");
1432 static cmdline_parse_token_string_t cmd_run_multi_string =
1433 TOKEN_STRING_INITIALIZER(struct cmd_run_result, multi_string,
1434 TOKEN_STRING_MULTI);
1437 static cmdline_parse_inst_t cmd_run = {
1438 .f = cmd_run_parsed,
1440 .help_str = "Run CLI script file",
1442 (void *) &cmd_run_run_string,
1443 (void *) &cmd_run_multi_string,
1448 static cmdline_parse_ctx_t pipeline_common_cmds[] = {
1449 (cmdline_parse_inst_t *) &cmd_quit,
1450 (cmdline_parse_inst_t *) &cmd_run,
1451 (cmdline_parse_inst_t *) &cmd_link,
1452 (cmdline_parse_inst_t *) &cmd_ping,
1453 (cmdline_parse_inst_t *) &cmd_stats_port_in,
1454 (cmdline_parse_inst_t *) &cmd_stats_port_out,
1455 (cmdline_parse_inst_t *) &cmd_stats_table,
1456 (cmdline_parse_inst_t *) &cmd_port_in_enable,
1457 (cmdline_parse_inst_t *) &cmd_port_in_disable,
1462 app_pipeline_common_cmd_push(struct app_params *app)
1466 /* Check for available slots in the application commands array */
1467 n_cmds = RTE_DIM(pipeline_common_cmds) - 1;
1468 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1471 /* Push pipeline commands into the application */
1472 memcpy(&app->cmds[app->n_cmds],
1473 pipeline_common_cmds,
1474 n_cmds * sizeof(cmdline_parse_ctx_t));
1476 for (i = 0; i < n_cmds; i++)
1477 app->cmds[app->n_cmds + i]->data = app;
1479 app->n_cmds += n_cmds;
1480 app->cmds[app->n_cmds] = NULL;