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>
40 #include <rte_malloc.h>
41 #include <cmdline_rdline.h>
42 #include <cmdline_parse.h>
43 #include <cmdline_parse_num.h>
44 #include <cmdline_parse_string.h>
47 #include "pipeline_common_fe.h"
50 struct app_link_params *
51 app_pipeline_track_pktq_out_to_link(struct app_params *app,
55 struct app_pipeline_params *p;
57 /* Check input arguments */
61 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
66 struct app_pktq_out_params *pktq_out =
67 &p->pktq_out[pktq_out_id];
69 switch (pktq_out->type) {
70 case APP_PKTQ_OUT_HWQ:
72 struct app_pktq_hwq_out_params *hwq_out;
74 hwq_out = &app->hwq_out_params[pktq_out->id];
76 return app_get_link_for_txq(app, hwq_out);
79 case APP_PKTQ_OUT_SWQ:
81 struct pipeline_params pp;
82 struct pipeline_type *ptype;
83 struct app_pktq_swq_params *swq;
87 swq = &app->swq_params[pktq_out->id];
88 p = app_swq_get_reader(app, swq, &pktq_in_id);
92 ptype = app_pipeline_type_find(app, p->type);
93 if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL))
96 app_pipeline_params_get(app, p, &pp);
97 status = ptype->fe_ops->f_track(&pp,
106 case APP_PKTQ_OUT_TM:
108 struct pipeline_params pp;
109 struct pipeline_type *ptype;
110 struct app_pktq_tm_params *tm;
114 tm = &app->tm_params[pktq_out->id];
115 p = app_tm_get_reader(app, tm, &pktq_in_id);
119 ptype = app_pipeline_type_find(app, p->type);
120 if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL))
123 app_pipeline_params_get(app, p, &pp);
124 status = ptype->fe_ops->f_track(&pp,
133 case APP_PKTQ_OUT_SINK:
141 app_pipeline_track_default(struct pipeline_params *p,
145 /* Check input arguments */
147 (port_in >= p->n_ports_in) ||
151 if (p->n_ports_out == 1) {
160 app_pipeline_ping(struct app_params *app,
161 uint32_t pipeline_id)
163 struct app_pipeline_params *p;
164 struct pipeline_msg_req *req;
165 struct pipeline_msg_rsp *rsp;
168 /* Check input arguments */
172 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
176 /* Message buffer allocation */
177 req = app_msg_alloc(app);
181 /* Fill in request */
182 req->type = PIPELINE_MSG_REQ_PING;
184 /* Send request and wait for response */
185 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
190 status = rsp->status;
192 /* Message buffer free */
193 app_msg_free(app, rsp);
199 app_pipeline_stats_port_in(struct app_params *app,
200 uint32_t pipeline_id,
202 struct rte_pipeline_port_in_stats *stats)
204 struct app_pipeline_params *p;
205 struct pipeline_stats_msg_req *req;
206 struct pipeline_stats_port_in_msg_rsp *rsp;
209 /* Check input arguments */
214 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
216 (port_id >= p->n_pktq_in))
219 /* Message buffer allocation */
220 req = app_msg_alloc(app);
224 /* Fill in request */
225 req->type = PIPELINE_MSG_REQ_STATS_PORT_IN;
228 /* Send request and wait for response */
229 rsp = (struct pipeline_stats_port_in_msg_rsp *)
230 app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
235 status = rsp->status;
237 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
239 /* Message buffer free */
240 app_msg_free(app, rsp);
246 app_pipeline_stats_port_out(struct app_params *app,
247 uint32_t pipeline_id,
249 struct rte_pipeline_port_out_stats *stats)
251 struct app_pipeline_params *p;
252 struct pipeline_stats_msg_req *req;
253 struct pipeline_stats_port_out_msg_rsp *rsp;
256 /* Check input arguments */
258 (pipeline_id >= app->n_pipelines) ||
262 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
264 (port_id >= p->n_pktq_out))
267 /* Message buffer allocation */
268 req = app_msg_alloc(app);
272 /* Fill in request */
273 req->type = PIPELINE_MSG_REQ_STATS_PORT_OUT;
276 /* Send request and wait for response */
277 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
282 status = rsp->status;
284 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
286 /* Message buffer free */
287 app_msg_free(app, rsp);
293 app_pipeline_stats_table(struct app_params *app,
294 uint32_t pipeline_id,
296 struct rte_pipeline_table_stats *stats)
298 struct app_pipeline_params *p;
299 struct pipeline_stats_msg_req *req;
300 struct pipeline_stats_table_msg_rsp *rsp;
303 /* Check input arguments */
308 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
312 /* Message buffer allocation */
313 req = app_msg_alloc(app);
317 /* Fill in request */
318 req->type = PIPELINE_MSG_REQ_STATS_TABLE;
321 /* Send request and wait for response */
322 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
327 status = rsp->status;
329 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
331 /* Message buffer free */
332 app_msg_free(app, rsp);
338 app_pipeline_port_in_enable(struct app_params *app,
339 uint32_t pipeline_id,
342 struct app_pipeline_params *p;
343 struct pipeline_port_in_msg_req *req;
344 struct pipeline_msg_rsp *rsp;
347 /* Check input arguments */
351 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
353 (port_id >= p->n_pktq_in))
356 /* Message buffer allocation */
357 req = app_msg_alloc(app);
361 /* Fill in request */
362 req->type = PIPELINE_MSG_REQ_PORT_IN_ENABLE;
363 req->port_id = port_id;
365 /* Send request and wait for response */
366 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
371 status = rsp->status;
373 /* Message buffer free */
374 app_msg_free(app, rsp);
380 app_pipeline_port_in_disable(struct app_params *app,
381 uint32_t pipeline_id,
384 struct app_pipeline_params *p;
385 struct pipeline_port_in_msg_req *req;
386 struct pipeline_msg_rsp *rsp;
389 /* Check input arguments */
393 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
395 (port_id >= p->n_pktq_in))
398 /* Message buffer allocation */
399 req = app_msg_alloc(app);
403 /* Fill in request */
404 req->type = PIPELINE_MSG_REQ_PORT_IN_DISABLE;
405 req->port_id = port_id;
407 /* Send request and wait for response */
408 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
413 status = rsp->status;
415 /* Message buffer free */
416 app_msg_free(app, rsp);
422 app_link_set_op(struct app_params *app,
424 uint32_t pipeline_id,
428 struct app_pipeline_params *pp;
429 struct app_link_params *lp;
430 struct app_link_data *ld;
433 /* Check input arguments */
438 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, lp);
441 lpos = lp - app->link_params;
442 ld = &app->link_data[lpos];
444 APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, pp);
447 ppos = pp - app->pipeline_params;
449 ld->f_link[ppos] = op;
456 app_link_config(struct app_params *app,
461 struct app_link_params *p;
462 uint32_t i, netmask, host, bcast;
464 /* Check input arguments */
468 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
470 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
476 APP_LOG(app, HIGH, "%s is UP, please bring it DOWN first",
481 netmask = (~0U) << (32 - depth);
483 bcast = host | (~netmask);
486 (ip == UINT32_MAX) ||
489 APP_LOG(app, HIGH, "Illegal IP address");
493 for (i = 0; i < app->n_links; i++) {
494 struct app_link_params *link = &app->link_params[i];
496 if (strcmp(p->name, link->name) == 0)
499 if (link->ip == ip) {
501 "%s is already assigned this IP address",
507 if ((depth == 0) || (depth > 32)) {
508 APP_LOG(app, HIGH, "Illegal value for depth parameter "
514 /* Save link parameters */
522 app_link_up(struct app_params *app,
525 struct app_link_params *p;
526 struct app_link_data *d;
529 /* Check input arguments */
533 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
535 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
540 d = &app->link_data[p - app->link_params];
542 /* Check link state */
544 APP_LOG(app, HIGH, "%s is already UP", p->name);
548 /* Check that IP address is valid */
550 APP_LOG(app, HIGH, "%s IP address is not set", p->name);
554 app_link_up_internal(app, p);
557 for (i = 0; i < APP_MAX_PIPELINES; i++)
559 d->f_link[i](app, link_id, 1, d->arg[i]);
565 app_link_down(struct app_params *app,
568 struct app_link_params *p;
569 struct app_link_data *d;
572 /* Check input arguments */
576 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
578 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
583 d = &app->link_data[p - app->link_params];
585 /* Check link state */
587 APP_LOG(app, HIGH, "%s is already DOWN", p->name);
591 app_link_down_internal(app, p);
594 for (i = 0; i < APP_MAX_PIPELINES; i++)
596 d->f_link[i](app, link_id, 0, d->arg[i]);
605 struct cmd_ping_result {
606 cmdline_fixed_string_t p_string;
607 uint32_t pipeline_id;
608 cmdline_fixed_string_t ping_string;
614 __rte_unused struct cmdline *cl,
617 struct cmd_ping_result *params = parsed_result;
618 struct app_params *app = data;
621 status = app_pipeline_ping(app, params->pipeline_id);
623 printf("Command failed\n");
626 static cmdline_parse_token_string_t cmd_ping_p_string =
627 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, p_string, "p");
629 static cmdline_parse_token_num_t cmd_ping_pipeline_id =
630 TOKEN_NUM_INITIALIZER(struct cmd_ping_result, pipeline_id, UINT32);
632 static cmdline_parse_token_string_t cmd_ping_ping_string =
633 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, ping_string, "ping");
635 static cmdline_parse_inst_t cmd_ping = {
636 .f = cmd_ping_parsed,
638 .help_str = "Pipeline ping",
640 (void *) &cmd_ping_p_string,
641 (void *) &cmd_ping_pipeline_id,
642 (void *) &cmd_ping_ping_string,
651 struct cmd_stats_port_in_result {
652 cmdline_fixed_string_t p_string;
653 uint32_t pipeline_id;
654 cmdline_fixed_string_t stats_string;
655 cmdline_fixed_string_t port_string;
656 cmdline_fixed_string_t in_string;
662 cmd_stats_port_in_parsed(
664 __rte_unused struct cmdline *cl,
667 struct cmd_stats_port_in_result *params = parsed_result;
668 struct app_params *app = data;
669 struct rte_pipeline_port_in_stats stats;
672 status = app_pipeline_stats_port_in(app,
678 printf("Command failed\n");
683 printf("Pipeline %" PRIu32 " - stats for input port %" PRIu32 ":\n"
684 "\tPkts in: %" PRIu64 "\n"
685 "\tPkts dropped by AH: %" PRIu64 "\n"
686 "\tPkts dropped by other: %" PRIu64 "\n",
689 stats.stats.n_pkts_in,
690 stats.n_pkts_dropped_by_ah,
691 stats.stats.n_pkts_drop);
694 static cmdline_parse_token_string_t cmd_stats_port_in_p_string =
695 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, p_string,
698 static cmdline_parse_token_num_t cmd_stats_port_in_pipeline_id =
699 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, pipeline_id,
702 static cmdline_parse_token_string_t cmd_stats_port_in_stats_string =
703 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, stats_string,
706 static cmdline_parse_token_string_t cmd_stats_port_in_port_string =
707 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, port_string,
710 static cmdline_parse_token_string_t cmd_stats_port_in_in_string =
711 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, in_string,
714 cmdline_parse_token_num_t cmd_stats_port_in_port_in_id =
715 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, port_in_id,
718 static cmdline_parse_inst_t cmd_stats_port_in = {
719 .f = cmd_stats_port_in_parsed,
721 .help_str = "Pipeline input port stats",
723 (void *) &cmd_stats_port_in_p_string,
724 (void *) &cmd_stats_port_in_pipeline_id,
725 (void *) &cmd_stats_port_in_stats_string,
726 (void *) &cmd_stats_port_in_port_string,
727 (void *) &cmd_stats_port_in_in_string,
728 (void *) &cmd_stats_port_in_port_in_id,
737 struct cmd_stats_port_out_result {
738 cmdline_fixed_string_t p_string;
739 uint32_t pipeline_id;
740 cmdline_fixed_string_t stats_string;
741 cmdline_fixed_string_t port_string;
742 cmdline_fixed_string_t out_string;
743 uint32_t port_out_id;
747 cmd_stats_port_out_parsed(
749 __rte_unused struct cmdline *cl,
753 struct cmd_stats_port_out_result *params = parsed_result;
754 struct app_params *app = data;
755 struct rte_pipeline_port_out_stats stats;
758 status = app_pipeline_stats_port_out(app,
764 printf("Command failed\n");
769 printf("Pipeline %" PRIu32 " - stats for output port %" PRIu32 ":\n"
770 "\tPkts in: %" PRIu64 "\n"
771 "\tPkts dropped by AH: %" PRIu64 "\n"
772 "\tPkts dropped by other: %" PRIu64 "\n",
775 stats.stats.n_pkts_in,
776 stats.n_pkts_dropped_by_ah,
777 stats.stats.n_pkts_drop);
780 static cmdline_parse_token_string_t cmd_stats_port_out_p_string =
781 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, p_string,
784 static cmdline_parse_token_num_t cmd_stats_port_out_pipeline_id =
785 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, pipeline_id,
788 static cmdline_parse_token_string_t cmd_stats_port_out_stats_string =
789 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, stats_string,
792 static cmdline_parse_token_string_t cmd_stats_port_out_port_string =
793 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, port_string,
796 static cmdline_parse_token_string_t cmd_stats_port_out_out_string =
797 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, out_string,
800 static cmdline_parse_token_num_t cmd_stats_port_out_port_out_id =
801 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, port_out_id,
804 static cmdline_parse_inst_t cmd_stats_port_out = {
805 .f = cmd_stats_port_out_parsed,
807 .help_str = "Pipeline output port stats",
809 (void *) &cmd_stats_port_out_p_string,
810 (void *) &cmd_stats_port_out_pipeline_id,
811 (void *) &cmd_stats_port_out_stats_string,
812 (void *) &cmd_stats_port_out_port_string,
813 (void *) &cmd_stats_port_out_out_string,
814 (void *) &cmd_stats_port_out_port_out_id,
823 struct cmd_stats_table_result {
824 cmdline_fixed_string_t p_string;
825 uint32_t pipeline_id;
826 cmdline_fixed_string_t stats_string;
827 cmdline_fixed_string_t table_string;
832 cmd_stats_table_parsed(
834 __rte_unused struct cmdline *cl,
837 struct cmd_stats_table_result *params = parsed_result;
838 struct app_params *app = data;
839 struct rte_pipeline_table_stats stats;
842 status = app_pipeline_stats_table(app,
848 printf("Command failed\n");
853 printf("Pipeline %" PRIu32 " - stats for table %" PRIu32 ":\n"
854 "\tPkts in: %" PRIu64 "\n"
855 "\tPkts in with lookup miss: %" PRIu64 "\n"
856 "\tPkts in with lookup hit dropped by AH: %" PRIu64 "\n"
857 "\tPkts in with lookup hit dropped by others: %" PRIu64 "\n"
858 "\tPkts in with lookup miss dropped by AH: %" PRIu64 "\n"
859 "\tPkts in with lookup miss dropped by others: %" PRIu64 "\n",
862 stats.stats.n_pkts_in,
863 stats.stats.n_pkts_lookup_miss,
864 stats.n_pkts_dropped_by_lkp_hit_ah,
865 stats.n_pkts_dropped_lkp_hit,
866 stats.n_pkts_dropped_by_lkp_miss_ah,
867 stats.n_pkts_dropped_lkp_miss);
870 static cmdline_parse_token_string_t cmd_stats_table_p_string =
871 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, p_string,
874 static cmdline_parse_token_num_t cmd_stats_table_pipeline_id =
875 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, pipeline_id,
878 static cmdline_parse_token_string_t cmd_stats_table_stats_string =
879 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, stats_string,
882 static cmdline_parse_token_string_t cmd_stats_table_table_string =
883 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, table_string,
886 static cmdline_parse_token_num_t cmd_stats_table_table_id =
887 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, table_id, UINT32);
889 static cmdline_parse_inst_t cmd_stats_table = {
890 .f = cmd_stats_table_parsed,
892 .help_str = "Pipeline table stats",
894 (void *) &cmd_stats_table_p_string,
895 (void *) &cmd_stats_table_pipeline_id,
896 (void *) &cmd_stats_table_stats_string,
897 (void *) &cmd_stats_table_table_string,
898 (void *) &cmd_stats_table_table_id,
907 struct cmd_port_in_enable_result {
908 cmdline_fixed_string_t p_string;
909 uint32_t pipeline_id;
910 cmdline_fixed_string_t port_string;
911 cmdline_fixed_string_t in_string;
913 cmdline_fixed_string_t enable_string;
917 cmd_port_in_enable_parsed(
919 __rte_unused struct cmdline *cl,
922 struct cmd_port_in_enable_result *params = parsed_result;
923 struct app_params *app = data;
926 status = app_pipeline_port_in_enable(app,
931 printf("Command failed\n");
934 static cmdline_parse_token_string_t cmd_port_in_enable_p_string =
935 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, p_string,
938 static cmdline_parse_token_num_t cmd_port_in_enable_pipeline_id =
939 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, pipeline_id,
942 static cmdline_parse_token_string_t cmd_port_in_enable_port_string =
943 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, port_string,
946 static cmdline_parse_token_string_t cmd_port_in_enable_in_string =
947 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, in_string,
950 static cmdline_parse_token_num_t cmd_port_in_enable_port_in_id =
951 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, port_in_id,
954 static cmdline_parse_token_string_t cmd_port_in_enable_enable_string =
955 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result,
956 enable_string, "enable");
958 static cmdline_parse_inst_t cmd_port_in_enable = {
959 .f = cmd_port_in_enable_parsed,
961 .help_str = "Pipeline input port enable",
963 (void *) &cmd_port_in_enable_p_string,
964 (void *) &cmd_port_in_enable_pipeline_id,
965 (void *) &cmd_port_in_enable_port_string,
966 (void *) &cmd_port_in_enable_in_string,
967 (void *) &cmd_port_in_enable_port_in_id,
968 (void *) &cmd_port_in_enable_enable_string,
977 struct cmd_port_in_disable_result {
978 cmdline_fixed_string_t p_string;
979 uint32_t pipeline_id;
980 cmdline_fixed_string_t port_string;
981 cmdline_fixed_string_t in_string;
983 cmdline_fixed_string_t disable_string;
987 cmd_port_in_disable_parsed(
989 __rte_unused struct cmdline *cl,
992 struct cmd_port_in_disable_result *params = parsed_result;
993 struct app_params *app = data;
996 status = app_pipeline_port_in_disable(app,
1001 printf("Command failed\n");
1004 static cmdline_parse_token_string_t cmd_port_in_disable_p_string =
1005 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, p_string,
1008 static cmdline_parse_token_num_t cmd_port_in_disable_pipeline_id =
1009 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, pipeline_id,
1012 static cmdline_parse_token_string_t cmd_port_in_disable_port_string =
1013 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, port_string,
1016 static cmdline_parse_token_string_t cmd_port_in_disable_in_string =
1017 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, in_string,
1020 static cmdline_parse_token_num_t cmd_port_in_disable_port_in_id =
1021 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, port_in_id,
1024 static cmdline_parse_token_string_t cmd_port_in_disable_disable_string =
1025 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result,
1026 disable_string, "disable");
1028 static cmdline_parse_inst_t cmd_port_in_disable = {
1029 .f = cmd_port_in_disable_parsed,
1031 .help_str = "Pipeline input port disable",
1033 (void *) &cmd_port_in_disable_p_string,
1034 (void *) &cmd_port_in_disable_pipeline_id,
1035 (void *) &cmd_port_in_disable_port_string,
1036 (void *) &cmd_port_in_disable_in_string,
1037 (void *) &cmd_port_in_disable_port_in_id,
1038 (void *) &cmd_port_in_disable_disable_string,
1048 print_link_info(struct app_link_params *p)
1050 struct rte_eth_stats stats;
1051 struct ether_addr *mac_addr;
1052 uint32_t netmask = (~0U) << (32 - p->depth);
1053 uint32_t host = p->ip & netmask;
1054 uint32_t bcast = host | (~netmask);
1056 memset(&stats, 0, sizeof(stats));
1057 rte_eth_stats_get(p->pmd_id, &stats);
1059 mac_addr = (struct ether_addr *) &p->mac_addr;
1061 if (strlen(p->pci_bdf))
1062 printf("%s(%s): flags=<%s>\n",
1065 (p->state) ? "UP" : "DOWN");
1067 printf("%s: flags=<%s>\n",
1069 (p->state) ? "UP" : "DOWN");
1072 printf("\tinet %" PRIu32 ".%" PRIu32
1073 ".%" PRIu32 ".%" PRIu32
1074 " netmask %" PRIu32 ".%" PRIu32
1075 ".%" PRIu32 ".%" PRIu32 " "
1076 "broadcast %" PRIu32 ".%" PRIu32
1077 ".%" PRIu32 ".%" PRIu32 "\n",
1078 (p->ip >> 24) & 0xFF,
1079 (p->ip >> 16) & 0xFF,
1080 (p->ip >> 8) & 0xFF,
1082 (netmask >> 24) & 0xFF,
1083 (netmask >> 16) & 0xFF,
1084 (netmask >> 8) & 0xFF,
1086 (bcast >> 24) & 0xFF,
1087 (bcast >> 16) & 0xFF,
1088 (bcast >> 8) & 0xFF,
1091 printf("\tether %02" PRIx32 ":%02" PRIx32 ":%02" PRIx32
1092 ":%02" PRIx32 ":%02" PRIx32 ":%02" PRIx32 "\n",
1093 mac_addr->addr_bytes[0],
1094 mac_addr->addr_bytes[1],
1095 mac_addr->addr_bytes[2],
1096 mac_addr->addr_bytes[3],
1097 mac_addr->addr_bytes[4],
1098 mac_addr->addr_bytes[5]);
1100 printf("\tRX packets %" PRIu64
1106 printf("\tRX errors %" PRIu64
1114 printf("\tTX packets %" PRIu64
1115 " bytes %" PRIu64 "\n",
1119 printf("\tTX errors %" PRIu64
1130 * link <linkid> config <ipaddr> <depth>
1136 * link <linkid> down
1142 struct cmd_link_result {
1143 cmdline_fixed_string_t link_string;
1144 cmdline_multi_string_t multi_string;
1149 void *parsed_result,
1150 __attribute__((unused)) struct cmdline *cl,
1153 struct cmd_link_result *params = parsed_result;
1154 struct app_params *app = data;
1157 uint32_t n_tokens = RTE_DIM(tokens);
1162 status = parse_tokenize_string(params->multi_string, tokens, &n_tokens);
1164 printf(CMD_MSG_TOO_MANY_ARGS, "link");
1169 if ((n_tokens == 1) && (strcmp(tokens[0], "ls") == 0)) {
1170 for (link_id = 0; link_id < app->n_links; link_id++) {
1171 struct app_link_params *p;
1173 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1180 printf(CMD_MSG_MISMATCH_ARGS, "link");
1184 if (parser_read_uint32(&link_id, tokens[0])) {
1185 printf(CMD_MSG_INVALID_ARG, "linkid");
1190 if (strcmp(tokens[1], "config") == 0) {
1191 struct in_addr ipaddr_ipv4;
1194 if (n_tokens != 4) {
1195 printf(CMD_MSG_MISMATCH_ARGS, "link config");
1199 if (parse_ipv4_addr(tokens[2], &ipaddr_ipv4)) {
1200 printf(CMD_MSG_INVALID_ARG, "ipaddr");
1204 if (parser_read_uint32(&depth, tokens[3])) {
1205 printf(CMD_MSG_INVALID_ARG, "depth");
1209 status = app_link_config(app,
1211 rte_be_to_cpu_32(ipaddr_ipv4.s_addr),
1214 printf(CMD_MSG_FAIL, "link config");
1220 if (strcmp(tokens[1], "up") == 0) {
1221 if (n_tokens != 2) {
1222 printf(CMD_MSG_MISMATCH_ARGS, "link up");
1226 status = app_link_up(app, link_id);
1228 printf(CMD_MSG_FAIL, "link up");
1234 if (strcmp(tokens[1], "down") == 0) {
1235 if (n_tokens != 2) {
1236 printf(CMD_MSG_MISMATCH_ARGS, "link down");
1240 status = app_link_down(app, link_id);
1242 printf(CMD_MSG_FAIL, "link down");
1247 printf(CMD_MSG_MISMATCH_ARGS, "link");
1250 static cmdline_parse_token_string_t cmd_link_link_string =
1251 TOKEN_STRING_INITIALIZER(struct cmd_link_result, link_string, "link");
1253 static cmdline_parse_token_string_t cmd_link_multi_string =
1254 TOKEN_STRING_INITIALIZER(struct cmd_link_result, multi_string,
1255 TOKEN_STRING_MULTI);
1257 static cmdline_parse_inst_t cmd_link = {
1258 .f = cmd_link_parsed,
1260 .help_str = "link config / up / down / ls",
1262 (void *) &cmd_link_link_string,
1263 (void *) &cmd_link_multi_string,
1272 struct cmd_quit_result {
1273 cmdline_fixed_string_t quit;
1278 __rte_unused void *parsed_result,
1280 __rte_unused void *data)
1285 static cmdline_parse_token_string_t cmd_quit_quit =
1286 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
1288 static cmdline_parse_inst_t cmd_quit = {
1289 .f = cmd_quit_parsed,
1293 (void *) &cmd_quit_quit,
1302 * run <file> [<count> [<interval>]]
1303 <count> default is 1
1304 * <interval> is measured in milliseconds, default is 1 second
1309 cmdline_parse_ctx_t *ctx,
1310 const char *file_name)
1312 struct cmdline *file_cl;
1315 fd = open(file_name, O_RDONLY);
1317 printf("Cannot open file \"%s\"\n", file_name);
1321 file_cl = cmdline_new(ctx, "", fd, 1);
1322 cmdline_interact(file_cl);
1326 struct cmd_run_result {
1327 cmdline_fixed_string_t run_string;
1328 cmdline_multi_string_t multi_string;
1333 void *parsed_result,
1335 __attribute__((unused)) void *data)
1337 struct cmd_run_result *params = parsed_result;
1340 uint32_t n_tokens = RTE_DIM(tokens);
1344 uint32_t count, interval, i;
1346 status = parse_tokenize_string(params->multi_string, tokens, &n_tokens);
1348 printf(CMD_MSG_TOO_MANY_ARGS, "run");
1354 printf(CMD_MSG_NOT_ENOUGH_ARGS, "run");
1358 file_name = tokens[0];
1364 file_name = tokens[0];
1366 if (parser_read_uint32(&count, tokens[1]) ||
1368 printf(CMD_MSG_INVALID_ARG, "count");
1376 file_name = tokens[0];
1378 if (parser_read_uint32(&count, tokens[1]) ||
1380 printf(CMD_MSG_INVALID_ARG, "count");
1384 if (parser_read_uint32(&interval, tokens[2]) ||
1386 printf(CMD_MSG_INVALID_ARG, "interval");
1392 printf(CMD_MSG_MISMATCH_ARGS, "run");
1396 for (i = 0; i < count; i++) {
1397 app_run_file(cl->ctx, file_name);
1399 usleep(interval * 1000);
1403 static cmdline_parse_token_string_t cmd_run_run_string =
1404 TOKEN_STRING_INITIALIZER(struct cmd_run_result, run_string, "run");
1406 static cmdline_parse_token_string_t cmd_run_multi_string =
1407 TOKEN_STRING_INITIALIZER(struct cmd_run_result, multi_string,
1408 TOKEN_STRING_MULTI);
1411 static cmdline_parse_inst_t cmd_run = {
1412 .f = cmd_run_parsed,
1414 .help_str = "Run CLI script file",
1416 (void *) &cmd_run_run_string,
1417 (void *) &cmd_run_multi_string,
1422 static cmdline_parse_ctx_t pipeline_common_cmds[] = {
1423 (cmdline_parse_inst_t *) &cmd_quit,
1424 (cmdline_parse_inst_t *) &cmd_run,
1425 (cmdline_parse_inst_t *) &cmd_link,
1426 (cmdline_parse_inst_t *) &cmd_ping,
1427 (cmdline_parse_inst_t *) &cmd_stats_port_in,
1428 (cmdline_parse_inst_t *) &cmd_stats_port_out,
1429 (cmdline_parse_inst_t *) &cmd_stats_table,
1430 (cmdline_parse_inst_t *) &cmd_port_in_enable,
1431 (cmdline_parse_inst_t *) &cmd_port_in_disable,
1436 app_pipeline_common_cmd_push(struct app_params *app)
1440 /* Check for available slots in the application commands array */
1441 n_cmds = RTE_DIM(pipeline_common_cmds) - 1;
1442 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1445 /* Push pipeline commands into the application */
1446 memcpy(&app->cmds[app->n_cmds],
1447 pipeline_common_cmds,
1448 n_cmds * sizeof(cmdline_parse_ctx_t));
1450 for (i = 0; i < n_cmds; i++)
1451 app->cmds[app->n_cmds + i]->data = app;
1453 app->n_cmds += n_cmds;
1454 app->cmds[app->n_cmds] = NULL;