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_config(struct app_params *app,
427 struct app_link_params *p;
428 uint32_t i, netmask, host, bcast;
430 /* Check input arguments */
434 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
436 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
442 APP_LOG(app, HIGH, "%s is UP, please bring it DOWN first",
447 netmask = (~0U) << (32 - depth);
449 bcast = host | (~netmask);
452 (ip == UINT32_MAX) ||
455 APP_LOG(app, HIGH, "Illegal IP address");
459 for (i = 0; i < app->n_links; i++) {
460 struct app_link_params *link = &app->link_params[i];
462 if (strcmp(p->name, link->name) == 0)
465 if (link->ip == ip) {
467 "%s is already assigned this IP address",
473 if ((depth == 0) || (depth > 32)) {
474 APP_LOG(app, HIGH, "Illegal value for depth parameter "
480 /* Save link parameters */
488 app_link_up(struct app_params *app,
491 struct app_link_params *p;
493 /* Check input arguments */
497 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
499 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
504 /* Check link state */
506 APP_LOG(app, HIGH, "%s is already UP", p->name);
510 /* Check that IP address is valid */
512 APP_LOG(app, HIGH, "%s IP address is not set", p->name);
516 app_link_up_internal(app, p);
522 app_link_down(struct app_params *app,
525 struct app_link_params *p;
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 /* Check link state */
540 APP_LOG(app, HIGH, "%s is already DOWN", p->name);
544 app_link_down_internal(app, p);
553 struct cmd_ping_result {
554 cmdline_fixed_string_t p_string;
555 uint32_t pipeline_id;
556 cmdline_fixed_string_t ping_string;
562 __rte_unused struct cmdline *cl,
565 struct cmd_ping_result *params = parsed_result;
566 struct app_params *app = data;
569 status = app_pipeline_ping(app, params->pipeline_id);
571 printf("Command failed\n");
574 static cmdline_parse_token_string_t cmd_ping_p_string =
575 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, p_string, "p");
577 static cmdline_parse_token_num_t cmd_ping_pipeline_id =
578 TOKEN_NUM_INITIALIZER(struct cmd_ping_result, pipeline_id, UINT32);
580 static cmdline_parse_token_string_t cmd_ping_ping_string =
581 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, ping_string, "ping");
583 static cmdline_parse_inst_t cmd_ping = {
584 .f = cmd_ping_parsed,
586 .help_str = "Pipeline ping",
588 (void *) &cmd_ping_p_string,
589 (void *) &cmd_ping_pipeline_id,
590 (void *) &cmd_ping_ping_string,
599 struct cmd_stats_port_in_result {
600 cmdline_fixed_string_t p_string;
601 uint32_t pipeline_id;
602 cmdline_fixed_string_t stats_string;
603 cmdline_fixed_string_t port_string;
604 cmdline_fixed_string_t in_string;
610 cmd_stats_port_in_parsed(
612 __rte_unused struct cmdline *cl,
615 struct cmd_stats_port_in_result *params = parsed_result;
616 struct app_params *app = data;
617 struct rte_pipeline_port_in_stats stats;
620 status = app_pipeline_stats_port_in(app,
626 printf("Command failed\n");
631 printf("Pipeline %" PRIu32 " - stats for input port %" PRIu32 ":\n"
632 "\tPkts in: %" PRIu64 "\n"
633 "\tPkts dropped by AH: %" PRIu64 "\n"
634 "\tPkts dropped by other: %" PRIu64 "\n",
637 stats.stats.n_pkts_in,
638 stats.n_pkts_dropped_by_ah,
639 stats.stats.n_pkts_drop);
642 static cmdline_parse_token_string_t cmd_stats_port_in_p_string =
643 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, p_string,
646 static cmdline_parse_token_num_t cmd_stats_port_in_pipeline_id =
647 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, pipeline_id,
650 static cmdline_parse_token_string_t cmd_stats_port_in_stats_string =
651 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, stats_string,
654 static cmdline_parse_token_string_t cmd_stats_port_in_port_string =
655 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, port_string,
658 static cmdline_parse_token_string_t cmd_stats_port_in_in_string =
659 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, in_string,
662 cmdline_parse_token_num_t cmd_stats_port_in_port_in_id =
663 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, port_in_id,
666 static cmdline_parse_inst_t cmd_stats_port_in = {
667 .f = cmd_stats_port_in_parsed,
669 .help_str = "Pipeline input port stats",
671 (void *) &cmd_stats_port_in_p_string,
672 (void *) &cmd_stats_port_in_pipeline_id,
673 (void *) &cmd_stats_port_in_stats_string,
674 (void *) &cmd_stats_port_in_port_string,
675 (void *) &cmd_stats_port_in_in_string,
676 (void *) &cmd_stats_port_in_port_in_id,
685 struct cmd_stats_port_out_result {
686 cmdline_fixed_string_t p_string;
687 uint32_t pipeline_id;
688 cmdline_fixed_string_t stats_string;
689 cmdline_fixed_string_t port_string;
690 cmdline_fixed_string_t out_string;
691 uint32_t port_out_id;
695 cmd_stats_port_out_parsed(
697 __rte_unused struct cmdline *cl,
701 struct cmd_stats_port_out_result *params = parsed_result;
702 struct app_params *app = data;
703 struct rte_pipeline_port_out_stats stats;
706 status = app_pipeline_stats_port_out(app,
712 printf("Command failed\n");
717 printf("Pipeline %" PRIu32 " - stats for output port %" PRIu32 ":\n"
718 "\tPkts in: %" PRIu64 "\n"
719 "\tPkts dropped by AH: %" PRIu64 "\n"
720 "\tPkts dropped by other: %" PRIu64 "\n",
723 stats.stats.n_pkts_in,
724 stats.n_pkts_dropped_by_ah,
725 stats.stats.n_pkts_drop);
728 static cmdline_parse_token_string_t cmd_stats_port_out_p_string =
729 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, p_string,
732 static cmdline_parse_token_num_t cmd_stats_port_out_pipeline_id =
733 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, pipeline_id,
736 static cmdline_parse_token_string_t cmd_stats_port_out_stats_string =
737 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, stats_string,
740 static cmdline_parse_token_string_t cmd_stats_port_out_port_string =
741 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, port_string,
744 static cmdline_parse_token_string_t cmd_stats_port_out_out_string =
745 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, out_string,
748 static cmdline_parse_token_num_t cmd_stats_port_out_port_out_id =
749 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, port_out_id,
752 static cmdline_parse_inst_t cmd_stats_port_out = {
753 .f = cmd_stats_port_out_parsed,
755 .help_str = "Pipeline output port stats",
757 (void *) &cmd_stats_port_out_p_string,
758 (void *) &cmd_stats_port_out_pipeline_id,
759 (void *) &cmd_stats_port_out_stats_string,
760 (void *) &cmd_stats_port_out_port_string,
761 (void *) &cmd_stats_port_out_out_string,
762 (void *) &cmd_stats_port_out_port_out_id,
771 struct cmd_stats_table_result {
772 cmdline_fixed_string_t p_string;
773 uint32_t pipeline_id;
774 cmdline_fixed_string_t stats_string;
775 cmdline_fixed_string_t table_string;
780 cmd_stats_table_parsed(
782 __rte_unused struct cmdline *cl,
785 struct cmd_stats_table_result *params = parsed_result;
786 struct app_params *app = data;
787 struct rte_pipeline_table_stats stats;
790 status = app_pipeline_stats_table(app,
796 printf("Command failed\n");
801 printf("Pipeline %" PRIu32 " - stats for table %" PRIu32 ":\n"
802 "\tPkts in: %" PRIu64 "\n"
803 "\tPkts in with lookup miss: %" PRIu64 "\n"
804 "\tPkts in with lookup hit dropped by AH: %" PRIu64 "\n"
805 "\tPkts in with lookup hit dropped by others: %" PRIu64 "\n"
806 "\tPkts in with lookup miss dropped by AH: %" PRIu64 "\n"
807 "\tPkts in with lookup miss dropped by others: %" PRIu64 "\n",
810 stats.stats.n_pkts_in,
811 stats.stats.n_pkts_lookup_miss,
812 stats.n_pkts_dropped_by_lkp_hit_ah,
813 stats.n_pkts_dropped_lkp_hit,
814 stats.n_pkts_dropped_by_lkp_miss_ah,
815 stats.n_pkts_dropped_lkp_miss);
818 static cmdline_parse_token_string_t cmd_stats_table_p_string =
819 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, p_string,
822 static cmdline_parse_token_num_t cmd_stats_table_pipeline_id =
823 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, pipeline_id,
826 static cmdline_parse_token_string_t cmd_stats_table_stats_string =
827 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, stats_string,
830 static cmdline_parse_token_string_t cmd_stats_table_table_string =
831 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, table_string,
834 static cmdline_parse_token_num_t cmd_stats_table_table_id =
835 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, table_id, UINT32);
837 static cmdline_parse_inst_t cmd_stats_table = {
838 .f = cmd_stats_table_parsed,
840 .help_str = "Pipeline table stats",
842 (void *) &cmd_stats_table_p_string,
843 (void *) &cmd_stats_table_pipeline_id,
844 (void *) &cmd_stats_table_stats_string,
845 (void *) &cmd_stats_table_table_string,
846 (void *) &cmd_stats_table_table_id,
855 struct cmd_port_in_enable_result {
856 cmdline_fixed_string_t p_string;
857 uint32_t pipeline_id;
858 cmdline_fixed_string_t port_string;
859 cmdline_fixed_string_t in_string;
861 cmdline_fixed_string_t enable_string;
865 cmd_port_in_enable_parsed(
867 __rte_unused struct cmdline *cl,
870 struct cmd_port_in_enable_result *params = parsed_result;
871 struct app_params *app = data;
874 status = app_pipeline_port_in_enable(app,
879 printf("Command failed\n");
882 static cmdline_parse_token_string_t cmd_port_in_enable_p_string =
883 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, p_string,
886 static cmdline_parse_token_num_t cmd_port_in_enable_pipeline_id =
887 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, pipeline_id,
890 static cmdline_parse_token_string_t cmd_port_in_enable_port_string =
891 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, port_string,
894 static cmdline_parse_token_string_t cmd_port_in_enable_in_string =
895 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, in_string,
898 static cmdline_parse_token_num_t cmd_port_in_enable_port_in_id =
899 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, port_in_id,
902 static cmdline_parse_token_string_t cmd_port_in_enable_enable_string =
903 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result,
904 enable_string, "enable");
906 static cmdline_parse_inst_t cmd_port_in_enable = {
907 .f = cmd_port_in_enable_parsed,
909 .help_str = "Pipeline input port enable",
911 (void *) &cmd_port_in_enable_p_string,
912 (void *) &cmd_port_in_enable_pipeline_id,
913 (void *) &cmd_port_in_enable_port_string,
914 (void *) &cmd_port_in_enable_in_string,
915 (void *) &cmd_port_in_enable_port_in_id,
916 (void *) &cmd_port_in_enable_enable_string,
925 struct cmd_port_in_disable_result {
926 cmdline_fixed_string_t p_string;
927 uint32_t pipeline_id;
928 cmdline_fixed_string_t port_string;
929 cmdline_fixed_string_t in_string;
931 cmdline_fixed_string_t disable_string;
935 cmd_port_in_disable_parsed(
937 __rte_unused struct cmdline *cl,
940 struct cmd_port_in_disable_result *params = parsed_result;
941 struct app_params *app = data;
944 status = app_pipeline_port_in_disable(app,
949 printf("Command failed\n");
952 static cmdline_parse_token_string_t cmd_port_in_disable_p_string =
953 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, p_string,
956 static cmdline_parse_token_num_t cmd_port_in_disable_pipeline_id =
957 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, pipeline_id,
960 static cmdline_parse_token_string_t cmd_port_in_disable_port_string =
961 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, port_string,
964 static cmdline_parse_token_string_t cmd_port_in_disable_in_string =
965 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, in_string,
968 static cmdline_parse_token_num_t cmd_port_in_disable_port_in_id =
969 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, port_in_id,
972 static cmdline_parse_token_string_t cmd_port_in_disable_disable_string =
973 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result,
974 disable_string, "disable");
976 static cmdline_parse_inst_t cmd_port_in_disable = {
977 .f = cmd_port_in_disable_parsed,
979 .help_str = "Pipeline input port disable",
981 (void *) &cmd_port_in_disable_p_string,
982 (void *) &cmd_port_in_disable_pipeline_id,
983 (void *) &cmd_port_in_disable_port_string,
984 (void *) &cmd_port_in_disable_in_string,
985 (void *) &cmd_port_in_disable_port_in_id,
986 (void *) &cmd_port_in_disable_disable_string,
996 print_link_info(struct app_link_params *p)
998 struct rte_eth_stats stats;
999 struct ether_addr *mac_addr;
1000 uint32_t netmask = (~0U) << (32 - p->depth);
1001 uint32_t host = p->ip & netmask;
1002 uint32_t bcast = host | (~netmask);
1004 memset(&stats, 0, sizeof(stats));
1005 rte_eth_stats_get(p->pmd_id, &stats);
1007 mac_addr = (struct ether_addr *) &p->mac_addr;
1009 if (strlen(p->pci_bdf))
1010 printf("%s(%s): flags=<%s>\n",
1013 (p->state) ? "UP" : "DOWN");
1015 printf("%s: flags=<%s>\n",
1017 (p->state) ? "UP" : "DOWN");
1020 printf("\tinet %" PRIu32 ".%" PRIu32
1021 ".%" PRIu32 ".%" PRIu32
1022 " netmask %" PRIu32 ".%" PRIu32
1023 ".%" PRIu32 ".%" PRIu32 " "
1024 "broadcast %" PRIu32 ".%" PRIu32
1025 ".%" PRIu32 ".%" PRIu32 "\n",
1026 (p->ip >> 24) & 0xFF,
1027 (p->ip >> 16) & 0xFF,
1028 (p->ip >> 8) & 0xFF,
1030 (netmask >> 24) & 0xFF,
1031 (netmask >> 16) & 0xFF,
1032 (netmask >> 8) & 0xFF,
1034 (bcast >> 24) & 0xFF,
1035 (bcast >> 16) & 0xFF,
1036 (bcast >> 8) & 0xFF,
1039 printf("\tether %02" PRIx32 ":%02" PRIx32 ":%02" PRIx32
1040 ":%02" PRIx32 ":%02" PRIx32 ":%02" PRIx32 "\n",
1041 mac_addr->addr_bytes[0],
1042 mac_addr->addr_bytes[1],
1043 mac_addr->addr_bytes[2],
1044 mac_addr->addr_bytes[3],
1045 mac_addr->addr_bytes[4],
1046 mac_addr->addr_bytes[5]);
1048 printf("\tRX packets %" PRIu64
1054 printf("\tRX errors %" PRIu64
1062 printf("\tTX packets %" PRIu64
1063 " bytes %" PRIu64 "\n",
1067 printf("\tTX errors %" PRIu64
1078 * link <linkid> config <ipaddr> <depth>
1084 * link <linkid> down
1090 struct cmd_link_result {
1091 cmdline_fixed_string_t link_string;
1092 cmdline_multi_string_t multi_string;
1097 void *parsed_result,
1098 __attribute__((unused)) struct cmdline *cl,
1101 struct cmd_link_result *params = parsed_result;
1102 struct app_params *app = data;
1105 uint32_t n_tokens = RTE_DIM(tokens);
1110 status = parse_tokenize_string(params->multi_string, tokens, &n_tokens);
1112 printf(CMD_MSG_TOO_MANY_ARGS, "link");
1117 if ((n_tokens == 1) && (strcmp(tokens[0], "ls") == 0)) {
1118 for (link_id = 0; link_id < app->n_links; link_id++) {
1119 struct app_link_params *p;
1121 APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1128 printf(CMD_MSG_MISMATCH_ARGS, "link");
1132 if (parser_read_uint32(&link_id, tokens[0])) {
1133 printf(CMD_MSG_INVALID_ARG, "linkid");
1138 if (strcmp(tokens[1], "config") == 0) {
1139 struct in_addr ipaddr_ipv4;
1142 if (n_tokens != 4) {
1143 printf(CMD_MSG_MISMATCH_ARGS, "link config");
1147 if (parse_ipv4_addr(tokens[2], &ipaddr_ipv4)) {
1148 printf(CMD_MSG_INVALID_ARG, "ipaddr");
1152 if (parser_read_uint32(&depth, tokens[3])) {
1153 printf(CMD_MSG_INVALID_ARG, "depth");
1157 status = app_link_config(app,
1159 rte_be_to_cpu_32(ipaddr_ipv4.s_addr),
1162 printf(CMD_MSG_FAIL, "link config");
1168 if (strcmp(tokens[1], "up") == 0) {
1169 if (n_tokens != 2) {
1170 printf(CMD_MSG_MISMATCH_ARGS, "link up");
1174 status = app_link_up(app, link_id);
1176 printf(CMD_MSG_FAIL, "link up");
1182 if (strcmp(tokens[1], "down") == 0) {
1183 if (n_tokens != 2) {
1184 printf(CMD_MSG_MISMATCH_ARGS, "link down");
1188 status = app_link_down(app, link_id);
1190 printf(CMD_MSG_FAIL, "link down");
1195 printf(CMD_MSG_MISMATCH_ARGS, "link");
1198 static cmdline_parse_token_string_t cmd_link_link_string =
1199 TOKEN_STRING_INITIALIZER(struct cmd_link_result, link_string, "link");
1201 static cmdline_parse_token_string_t cmd_link_multi_string =
1202 TOKEN_STRING_INITIALIZER(struct cmd_link_result, multi_string,
1203 TOKEN_STRING_MULTI);
1205 static cmdline_parse_inst_t cmd_link = {
1206 .f = cmd_link_parsed,
1208 .help_str = "link config / up / down / ls",
1210 (void *) &cmd_link_link_string,
1211 (void *) &cmd_link_multi_string,
1220 struct cmd_quit_result {
1221 cmdline_fixed_string_t quit;
1226 __rte_unused void *parsed_result,
1228 __rte_unused void *data)
1233 static cmdline_parse_token_string_t cmd_quit_quit =
1234 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
1236 static cmdline_parse_inst_t cmd_quit = {
1237 .f = cmd_quit_parsed,
1241 (void *) &cmd_quit_quit,
1250 * run <file> [<count> [<interval>]]
1251 <count> default is 1
1252 * <interval> is measured in milliseconds, default is 1 second
1257 cmdline_parse_ctx_t *ctx,
1258 const char *file_name)
1260 struct cmdline *file_cl;
1263 fd = open(file_name, O_RDONLY);
1265 printf("Cannot open file \"%s\"\n", file_name);
1269 file_cl = cmdline_new(ctx, "", fd, 1);
1270 cmdline_interact(file_cl);
1274 struct cmd_run_result {
1275 cmdline_fixed_string_t run_string;
1276 cmdline_multi_string_t multi_string;
1281 void *parsed_result,
1283 __attribute__((unused)) void *data)
1285 struct cmd_run_result *params = parsed_result;
1288 uint32_t n_tokens = RTE_DIM(tokens);
1292 uint32_t count, interval, i;
1294 status = parse_tokenize_string(params->multi_string, tokens, &n_tokens);
1296 printf(CMD_MSG_TOO_MANY_ARGS, "run");
1302 printf(CMD_MSG_NOT_ENOUGH_ARGS, "run");
1306 file_name = tokens[0];
1312 file_name = tokens[0];
1314 if (parser_read_uint32(&count, tokens[1]) ||
1316 printf(CMD_MSG_INVALID_ARG, "count");
1324 file_name = tokens[0];
1326 if (parser_read_uint32(&count, tokens[1]) ||
1328 printf(CMD_MSG_INVALID_ARG, "count");
1332 if (parser_read_uint32(&interval, tokens[2]) ||
1334 printf(CMD_MSG_INVALID_ARG, "interval");
1340 printf(CMD_MSG_MISMATCH_ARGS, "run");
1344 for (i = 0; i < count; i++) {
1345 app_run_file(cl->ctx, file_name);
1347 usleep(interval * 1000);
1351 static cmdline_parse_token_string_t cmd_run_run_string =
1352 TOKEN_STRING_INITIALIZER(struct cmd_run_result, run_string, "run");
1354 static cmdline_parse_token_string_t cmd_run_multi_string =
1355 TOKEN_STRING_INITIALIZER(struct cmd_run_result, multi_string,
1356 TOKEN_STRING_MULTI);
1359 static cmdline_parse_inst_t cmd_run = {
1360 .f = cmd_run_parsed,
1362 .help_str = "Run CLI script file",
1364 (void *) &cmd_run_run_string,
1365 (void *) &cmd_run_multi_string,
1370 static cmdline_parse_ctx_t pipeline_common_cmds[] = {
1371 (cmdline_parse_inst_t *) &cmd_quit,
1372 (cmdline_parse_inst_t *) &cmd_run,
1373 (cmdline_parse_inst_t *) &cmd_link,
1374 (cmdline_parse_inst_t *) &cmd_ping,
1375 (cmdline_parse_inst_t *) &cmd_stats_port_in,
1376 (cmdline_parse_inst_t *) &cmd_stats_port_out,
1377 (cmdline_parse_inst_t *) &cmd_stats_table,
1378 (cmdline_parse_inst_t *) &cmd_port_in_enable,
1379 (cmdline_parse_inst_t *) &cmd_port_in_disable,
1384 app_pipeline_common_cmd_push(struct app_params *app)
1388 /* Check for available slots in the application commands array */
1389 n_cmds = RTE_DIM(pipeline_common_cmds) - 1;
1390 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1393 /* Push pipeline commands into the application */
1394 memcpy(&app->cmds[app->n_cmds],
1395 pipeline_common_cmds,
1396 n_cmds * sizeof(cmdline_parse_ctx_t));
1398 for (i = 0; i < n_cmds; i++)
1399 app->cmds[app->n_cmds + i]->data = app;
1401 app->n_cmds += n_cmds;
1402 app->cmds[app->n_cmds] = NULL;