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_TAP
:
160 case APP_PKTQ_OUT_SINK
:
168 app_pipeline_track_default(struct pipeline_params
*p
,
172 /* Check input arguments */
174 (port_in
>= p
->n_ports_in
) ||
178 if (p
->n_ports_out
== 1) {
187 app_pipeline_ping(struct app_params
*app
,
188 uint32_t pipeline_id
)
190 struct app_pipeline_params
*p
;
191 struct pipeline_msg_req
*req
;
192 struct pipeline_msg_rsp
*rsp
;
195 /* Check input arguments */
199 APP_PARAM_FIND_BY_ID(app
->pipeline_params
, "PIPELINE", pipeline_id
, p
);
203 /* Message buffer allocation */
204 req
= app_msg_alloc(app
);
208 /* Fill in request */
209 req
->type
= PIPELINE_MSG_REQ_PING
;
211 /* Send request and wait for response */
212 rsp
= app_msg_send_recv(app
, pipeline_id
, req
, MSG_TIMEOUT_DEFAULT
);
217 status
= rsp
->status
;
219 /* Message buffer free */
220 app_msg_free(app
, rsp
);
226 app_pipeline_stats_port_in(struct app_params
*app
,
227 uint32_t pipeline_id
,
229 struct rte_pipeline_port_in_stats
*stats
)
231 struct app_pipeline_params
*p
;
232 struct pipeline_stats_msg_req
*req
;
233 struct pipeline_stats_port_in_msg_rsp
*rsp
;
236 /* Check input arguments */
241 APP_PARAM_FIND_BY_ID(app
->pipeline_params
, "PIPELINE", pipeline_id
, p
);
243 (port_id
>= p
->n_pktq_in
))
246 /* Message buffer allocation */
247 req
= app_msg_alloc(app
);
251 /* Fill in request */
252 req
->type
= PIPELINE_MSG_REQ_STATS_PORT_IN
;
255 /* Send request and wait for response */
256 rsp
= (struct pipeline_stats_port_in_msg_rsp
*)
257 app_msg_send_recv(app
, pipeline_id
, req
, MSG_TIMEOUT_DEFAULT
);
262 status
= rsp
->status
;
264 memcpy(stats
, &rsp
->stats
, sizeof(rsp
->stats
));
266 /* Message buffer free */
267 app_msg_free(app
, rsp
);
273 app_pipeline_stats_port_out(struct app_params
*app
,
274 uint32_t pipeline_id
,
276 struct rte_pipeline_port_out_stats
*stats
)
278 struct app_pipeline_params
*p
;
279 struct pipeline_stats_msg_req
*req
;
280 struct pipeline_stats_port_out_msg_rsp
*rsp
;
283 /* Check input arguments */
285 (pipeline_id
>= app
->n_pipelines
) ||
289 APP_PARAM_FIND_BY_ID(app
->pipeline_params
, "PIPELINE", pipeline_id
, p
);
291 (port_id
>= p
->n_pktq_out
))
294 /* Message buffer allocation */
295 req
= app_msg_alloc(app
);
299 /* Fill in request */
300 req
->type
= PIPELINE_MSG_REQ_STATS_PORT_OUT
;
303 /* Send request and wait for response */
304 rsp
= app_msg_send_recv(app
, pipeline_id
, req
, MSG_TIMEOUT_DEFAULT
);
309 status
= rsp
->status
;
311 memcpy(stats
, &rsp
->stats
, sizeof(rsp
->stats
));
313 /* Message buffer free */
314 app_msg_free(app
, rsp
);
320 app_pipeline_stats_table(struct app_params
*app
,
321 uint32_t pipeline_id
,
323 struct rte_pipeline_table_stats
*stats
)
325 struct app_pipeline_params
*p
;
326 struct pipeline_stats_msg_req
*req
;
327 struct pipeline_stats_table_msg_rsp
*rsp
;
330 /* Check input arguments */
335 APP_PARAM_FIND_BY_ID(app
->pipeline_params
, "PIPELINE", pipeline_id
, p
);
339 /* Message buffer allocation */
340 req
= app_msg_alloc(app
);
344 /* Fill in request */
345 req
->type
= PIPELINE_MSG_REQ_STATS_TABLE
;
348 /* Send request and wait for response */
349 rsp
= app_msg_send_recv(app
, pipeline_id
, req
, MSG_TIMEOUT_DEFAULT
);
354 status
= rsp
->status
;
356 memcpy(stats
, &rsp
->stats
, sizeof(rsp
->stats
));
358 /* Message buffer free */
359 app_msg_free(app
, rsp
);
365 app_pipeline_port_in_enable(struct app_params
*app
,
366 uint32_t pipeline_id
,
369 struct app_pipeline_params
*p
;
370 struct pipeline_port_in_msg_req
*req
;
371 struct pipeline_msg_rsp
*rsp
;
374 /* Check input arguments */
378 APP_PARAM_FIND_BY_ID(app
->pipeline_params
, "PIPELINE", pipeline_id
, p
);
380 (port_id
>= p
->n_pktq_in
))
383 /* Message buffer allocation */
384 req
= app_msg_alloc(app
);
388 /* Fill in request */
389 req
->type
= PIPELINE_MSG_REQ_PORT_IN_ENABLE
;
390 req
->port_id
= port_id
;
392 /* Send request and wait for response */
393 rsp
= app_msg_send_recv(app
, pipeline_id
, req
, MSG_TIMEOUT_DEFAULT
);
398 status
= rsp
->status
;
400 /* Message buffer free */
401 app_msg_free(app
, rsp
);
407 app_pipeline_port_in_disable(struct app_params
*app
,
408 uint32_t pipeline_id
,
411 struct app_pipeline_params
*p
;
412 struct pipeline_port_in_msg_req
*req
;
413 struct pipeline_msg_rsp
*rsp
;
416 /* Check input arguments */
420 APP_PARAM_FIND_BY_ID(app
->pipeline_params
, "PIPELINE", pipeline_id
, p
);
422 (port_id
>= p
->n_pktq_in
))
425 /* Message buffer allocation */
426 req
= app_msg_alloc(app
);
430 /* Fill in request */
431 req
->type
= PIPELINE_MSG_REQ_PORT_IN_DISABLE
;
432 req
->port_id
= port_id
;
434 /* Send request and wait for response */
435 rsp
= app_msg_send_recv(app
, pipeline_id
, req
, MSG_TIMEOUT_DEFAULT
);
440 status
= rsp
->status
;
442 /* Message buffer free */
443 app_msg_free(app
, rsp
);
449 app_link_set_op(struct app_params
*app
,
451 uint32_t pipeline_id
,
455 struct app_pipeline_params
*pp
;
456 struct app_link_params
*lp
;
457 struct app_link_data
*ld
;
460 /* Check input arguments */
465 APP_PARAM_FIND_BY_ID(app
->link_params
, "LINK", link_id
, lp
);
468 lpos
= lp
- app
->link_params
;
469 ld
= &app
->link_data
[lpos
];
471 APP_PARAM_FIND_BY_ID(app
->pipeline_params
, "PIPELINE", pipeline_id
, pp
);
474 ppos
= pp
- app
->pipeline_params
;
476 ld
->f_link
[ppos
] = op
;
483 app_link_config(struct app_params
*app
,
488 struct app_link_params
*p
;
489 uint32_t i
, netmask
, host
, bcast
;
491 /* Check input arguments */
495 APP_PARAM_FIND_BY_ID(app
->link_params
, "LINK", link_id
, p
);
497 APP_LOG(app
, HIGH
, "LINK%" PRIu32
" is not a valid link",
503 APP_LOG(app
, HIGH
, "%s is UP, please bring it DOWN first",
508 netmask
= (~0U) << (32 - depth
);
510 bcast
= host
| (~netmask
);
513 (ip
== UINT32_MAX
) ||
516 APP_LOG(app
, HIGH
, "Illegal IP address");
520 for (i
= 0; i
< app
->n_links
; i
++) {
521 struct app_link_params
*link
= &app
->link_params
[i
];
523 if (strcmp(p
->name
, link
->name
) == 0)
526 if (link
->ip
== ip
) {
528 "%s is already assigned this IP address",
534 if ((depth
== 0) || (depth
> 32)) {
535 APP_LOG(app
, HIGH
, "Illegal value for depth parameter "
541 /* Save link parameters */
549 app_link_up(struct app_params
*app
,
552 struct app_link_params
*p
;
553 struct app_link_data
*d
;
556 /* Check input arguments */
560 APP_PARAM_FIND_BY_ID(app
->link_params
, "LINK", link_id
, p
);
562 APP_LOG(app
, HIGH
, "LINK%" PRIu32
" is not a valid link",
567 d
= &app
->link_data
[p
- app
->link_params
];
569 /* Check link state */
571 APP_LOG(app
, HIGH
, "%s is already UP", p
->name
);
575 /* Check that IP address is valid */
577 APP_LOG(app
, HIGH
, "%s IP address is not set", p
->name
);
581 app_link_up_internal(app
, p
);
584 for (i
= 0; i
< APP_MAX_PIPELINES
; i
++)
586 d
->f_link
[i
](app
, link_id
, 1, d
->arg
[i
]);
592 app_link_down(struct app_params
*app
,
595 struct app_link_params
*p
;
596 struct app_link_data
*d
;
599 /* Check input arguments */
603 APP_PARAM_FIND_BY_ID(app
->link_params
, "LINK", link_id
, p
);
605 APP_LOG(app
, HIGH
, "LINK%" PRIu32
" is not a valid link",
610 d
= &app
->link_data
[p
- app
->link_params
];
612 /* Check link state */
614 APP_LOG(app
, HIGH
, "%s is already DOWN", p
->name
);
618 app_link_down_internal(app
, p
);
621 for (i
= 0; i
< APP_MAX_PIPELINES
; i
++)
623 d
->f_link
[i
](app
, link_id
, 0, d
->arg
[i
]);
632 struct cmd_ping_result
{
633 cmdline_fixed_string_t p_string
;
634 uint32_t pipeline_id
;
635 cmdline_fixed_string_t ping_string
;
641 __rte_unused
struct cmdline
*cl
,
644 struct cmd_ping_result
*params
= parsed_result
;
645 struct app_params
*app
= data
;
648 status
= app_pipeline_ping(app
, params
->pipeline_id
);
650 printf("Command failed\n");
653 static cmdline_parse_token_string_t cmd_ping_p_string
=
654 TOKEN_STRING_INITIALIZER(struct cmd_ping_result
, p_string
, "p");
656 static cmdline_parse_token_num_t cmd_ping_pipeline_id
=
657 TOKEN_NUM_INITIALIZER(struct cmd_ping_result
, pipeline_id
, UINT32
);
659 static cmdline_parse_token_string_t cmd_ping_ping_string
=
660 TOKEN_STRING_INITIALIZER(struct cmd_ping_result
, ping_string
, "ping");
662 static cmdline_parse_inst_t cmd_ping
= {
663 .f
= cmd_ping_parsed
,
665 .help_str
= "Pipeline ping",
667 (void *) &cmd_ping_p_string
,
668 (void *) &cmd_ping_pipeline_id
,
669 (void *) &cmd_ping_ping_string
,
678 struct cmd_stats_port_in_result
{
679 cmdline_fixed_string_t p_string
;
680 uint32_t pipeline_id
;
681 cmdline_fixed_string_t stats_string
;
682 cmdline_fixed_string_t port_string
;
683 cmdline_fixed_string_t in_string
;
689 cmd_stats_port_in_parsed(
691 __rte_unused
struct cmdline
*cl
,
694 struct cmd_stats_port_in_result
*params
= parsed_result
;
695 struct app_params
*app
= data
;
696 struct rte_pipeline_port_in_stats stats
;
699 status
= app_pipeline_stats_port_in(app
,
705 printf("Command failed\n");
710 printf("Pipeline %" PRIu32
" - stats for input port %" PRIu32
":\n"
711 "\tPkts in: %" PRIu64
"\n"
712 "\tPkts dropped by AH: %" PRIu64
"\n"
713 "\tPkts dropped by other: %" PRIu64
"\n",
716 stats
.stats
.n_pkts_in
,
717 stats
.n_pkts_dropped_by_ah
,
718 stats
.stats
.n_pkts_drop
);
721 static cmdline_parse_token_string_t cmd_stats_port_in_p_string
=
722 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result
, p_string
,
725 static cmdline_parse_token_num_t cmd_stats_port_in_pipeline_id
=
726 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result
, pipeline_id
,
729 static cmdline_parse_token_string_t cmd_stats_port_in_stats_string
=
730 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result
, stats_string
,
733 static cmdline_parse_token_string_t cmd_stats_port_in_port_string
=
734 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result
, port_string
,
737 static cmdline_parse_token_string_t cmd_stats_port_in_in_string
=
738 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result
, in_string
,
741 cmdline_parse_token_num_t cmd_stats_port_in_port_in_id
=
742 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result
, port_in_id
,
745 static cmdline_parse_inst_t cmd_stats_port_in
= {
746 .f
= cmd_stats_port_in_parsed
,
748 .help_str
= "Pipeline input port stats",
750 (void *) &cmd_stats_port_in_p_string
,
751 (void *) &cmd_stats_port_in_pipeline_id
,
752 (void *) &cmd_stats_port_in_stats_string
,
753 (void *) &cmd_stats_port_in_port_string
,
754 (void *) &cmd_stats_port_in_in_string
,
755 (void *) &cmd_stats_port_in_port_in_id
,
764 struct cmd_stats_port_out_result
{
765 cmdline_fixed_string_t p_string
;
766 uint32_t pipeline_id
;
767 cmdline_fixed_string_t stats_string
;
768 cmdline_fixed_string_t port_string
;
769 cmdline_fixed_string_t out_string
;
770 uint32_t port_out_id
;
774 cmd_stats_port_out_parsed(
776 __rte_unused
struct cmdline
*cl
,
780 struct cmd_stats_port_out_result
*params
= parsed_result
;
781 struct app_params
*app
= data
;
782 struct rte_pipeline_port_out_stats stats
;
785 status
= app_pipeline_stats_port_out(app
,
791 printf("Command failed\n");
796 printf("Pipeline %" PRIu32
" - stats for output port %" PRIu32
":\n"
797 "\tPkts in: %" PRIu64
"\n"
798 "\tPkts dropped by AH: %" PRIu64
"\n"
799 "\tPkts dropped by other: %" PRIu64
"\n",
802 stats
.stats
.n_pkts_in
,
803 stats
.n_pkts_dropped_by_ah
,
804 stats
.stats
.n_pkts_drop
);
807 static cmdline_parse_token_string_t cmd_stats_port_out_p_string
=
808 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result
, p_string
,
811 static cmdline_parse_token_num_t cmd_stats_port_out_pipeline_id
=
812 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result
, pipeline_id
,
815 static cmdline_parse_token_string_t cmd_stats_port_out_stats_string
=
816 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result
, stats_string
,
819 static cmdline_parse_token_string_t cmd_stats_port_out_port_string
=
820 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result
, port_string
,
823 static cmdline_parse_token_string_t cmd_stats_port_out_out_string
=
824 TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result
, out_string
,
827 static cmdline_parse_token_num_t cmd_stats_port_out_port_out_id
=
828 TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result
, port_out_id
,
831 static cmdline_parse_inst_t cmd_stats_port_out
= {
832 .f
= cmd_stats_port_out_parsed
,
834 .help_str
= "Pipeline output port stats",
836 (void *) &cmd_stats_port_out_p_string
,
837 (void *) &cmd_stats_port_out_pipeline_id
,
838 (void *) &cmd_stats_port_out_stats_string
,
839 (void *) &cmd_stats_port_out_port_string
,
840 (void *) &cmd_stats_port_out_out_string
,
841 (void *) &cmd_stats_port_out_port_out_id
,
850 struct cmd_stats_table_result
{
851 cmdline_fixed_string_t p_string
;
852 uint32_t pipeline_id
;
853 cmdline_fixed_string_t stats_string
;
854 cmdline_fixed_string_t table_string
;
859 cmd_stats_table_parsed(
861 __rte_unused
struct cmdline
*cl
,
864 struct cmd_stats_table_result
*params
= parsed_result
;
865 struct app_params
*app
= data
;
866 struct rte_pipeline_table_stats stats
;
869 status
= app_pipeline_stats_table(app
,
875 printf("Command failed\n");
880 printf("Pipeline %" PRIu32
" - stats for table %" PRIu32
":\n"
881 "\tPkts in: %" PRIu64
"\n"
882 "\tPkts in with lookup miss: %" PRIu64
"\n"
883 "\tPkts in with lookup hit dropped by AH: %" PRIu64
"\n"
884 "\tPkts in with lookup hit dropped by others: %" PRIu64
"\n"
885 "\tPkts in with lookup miss dropped by AH: %" PRIu64
"\n"
886 "\tPkts in with lookup miss dropped by others: %" PRIu64
"\n",
889 stats
.stats
.n_pkts_in
,
890 stats
.stats
.n_pkts_lookup_miss
,
891 stats
.n_pkts_dropped_by_lkp_hit_ah
,
892 stats
.n_pkts_dropped_lkp_hit
,
893 stats
.n_pkts_dropped_by_lkp_miss_ah
,
894 stats
.n_pkts_dropped_lkp_miss
);
897 static cmdline_parse_token_string_t cmd_stats_table_p_string
=
898 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result
, p_string
,
901 static cmdline_parse_token_num_t cmd_stats_table_pipeline_id
=
902 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result
, pipeline_id
,
905 static cmdline_parse_token_string_t cmd_stats_table_stats_string
=
906 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result
, stats_string
,
909 static cmdline_parse_token_string_t cmd_stats_table_table_string
=
910 TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result
, table_string
,
913 static cmdline_parse_token_num_t cmd_stats_table_table_id
=
914 TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result
, table_id
, UINT32
);
916 static cmdline_parse_inst_t cmd_stats_table
= {
917 .f
= cmd_stats_table_parsed
,
919 .help_str
= "Pipeline table stats",
921 (void *) &cmd_stats_table_p_string
,
922 (void *) &cmd_stats_table_pipeline_id
,
923 (void *) &cmd_stats_table_stats_string
,
924 (void *) &cmd_stats_table_table_string
,
925 (void *) &cmd_stats_table_table_id
,
934 struct cmd_port_in_enable_result
{
935 cmdline_fixed_string_t p_string
;
936 uint32_t pipeline_id
;
937 cmdline_fixed_string_t port_string
;
938 cmdline_fixed_string_t in_string
;
940 cmdline_fixed_string_t enable_string
;
944 cmd_port_in_enable_parsed(
946 __rte_unused
struct cmdline
*cl
,
949 struct cmd_port_in_enable_result
*params
= parsed_result
;
950 struct app_params
*app
= data
;
953 status
= app_pipeline_port_in_enable(app
,
958 printf("Command failed\n");
961 static cmdline_parse_token_string_t cmd_port_in_enable_p_string
=
962 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result
, p_string
,
965 static cmdline_parse_token_num_t cmd_port_in_enable_pipeline_id
=
966 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result
, pipeline_id
,
969 static cmdline_parse_token_string_t cmd_port_in_enable_port_string
=
970 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result
, port_string
,
973 static cmdline_parse_token_string_t cmd_port_in_enable_in_string
=
974 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result
, in_string
,
977 static cmdline_parse_token_num_t cmd_port_in_enable_port_in_id
=
978 TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result
, port_in_id
,
981 static cmdline_parse_token_string_t cmd_port_in_enable_enable_string
=
982 TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result
,
983 enable_string
, "enable");
985 static cmdline_parse_inst_t cmd_port_in_enable
= {
986 .f
= cmd_port_in_enable_parsed
,
988 .help_str
= "Pipeline input port enable",
990 (void *) &cmd_port_in_enable_p_string
,
991 (void *) &cmd_port_in_enable_pipeline_id
,
992 (void *) &cmd_port_in_enable_port_string
,
993 (void *) &cmd_port_in_enable_in_string
,
994 (void *) &cmd_port_in_enable_port_in_id
,
995 (void *) &cmd_port_in_enable_enable_string
,
1004 struct cmd_port_in_disable_result
{
1005 cmdline_fixed_string_t p_string
;
1006 uint32_t pipeline_id
;
1007 cmdline_fixed_string_t port_string
;
1008 cmdline_fixed_string_t in_string
;
1009 uint32_t port_in_id
;
1010 cmdline_fixed_string_t disable_string
;
1014 cmd_port_in_disable_parsed(
1015 void *parsed_result
,
1016 __rte_unused
struct cmdline
*cl
,
1019 struct cmd_port_in_disable_result
*params
= parsed_result
;
1020 struct app_params
*app
= data
;
1023 status
= app_pipeline_port_in_disable(app
,
1024 params
->pipeline_id
,
1025 params
->port_in_id
);
1028 printf("Command failed\n");
1031 static cmdline_parse_token_string_t cmd_port_in_disable_p_string
=
1032 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result
, p_string
,
1035 static cmdline_parse_token_num_t cmd_port_in_disable_pipeline_id
=
1036 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result
, pipeline_id
,
1039 static cmdline_parse_token_string_t cmd_port_in_disable_port_string
=
1040 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result
, port_string
,
1043 static cmdline_parse_token_string_t cmd_port_in_disable_in_string
=
1044 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result
, in_string
,
1047 static cmdline_parse_token_num_t cmd_port_in_disable_port_in_id
=
1048 TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result
, port_in_id
,
1051 static cmdline_parse_token_string_t cmd_port_in_disable_disable_string
=
1052 TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result
,
1053 disable_string
, "disable");
1055 static cmdline_parse_inst_t cmd_port_in_disable
= {
1056 .f
= cmd_port_in_disable_parsed
,
1058 .help_str
= "Pipeline input port disable",
1060 (void *) &cmd_port_in_disable_p_string
,
1061 (void *) &cmd_port_in_disable_pipeline_id
,
1062 (void *) &cmd_port_in_disable_port_string
,
1063 (void *) &cmd_port_in_disable_in_string
,
1064 (void *) &cmd_port_in_disable_port_in_id
,
1065 (void *) &cmd_port_in_disable_disable_string
,
1075 print_link_info(struct app_link_params
*p
)
1077 struct rte_eth_stats stats
;
1078 struct ether_addr
*mac_addr
;
1079 uint32_t netmask
= (~0U) << (32 - p
->depth
);
1080 uint32_t host
= p
->ip
& netmask
;
1081 uint32_t bcast
= host
| (~netmask
);
1083 memset(&stats
, 0, sizeof(stats
));
1084 rte_eth_stats_get(p
->pmd_id
, &stats
);
1086 mac_addr
= (struct ether_addr
*) &p
->mac_addr
;
1088 if (strlen(p
->pci_bdf
))
1089 printf("%s(%s): flags=<%s>\n",
1092 (p
->state
) ? "UP" : "DOWN");
1094 printf("%s: flags=<%s>\n",
1096 (p
->state
) ? "UP" : "DOWN");
1099 printf("\tinet %" PRIu32
".%" PRIu32
1100 ".%" PRIu32
".%" PRIu32
1101 " netmask %" PRIu32
".%" PRIu32
1102 ".%" PRIu32
".%" PRIu32
" "
1103 "broadcast %" PRIu32
".%" PRIu32
1104 ".%" PRIu32
".%" PRIu32
"\n",
1105 (p
->ip
>> 24) & 0xFF,
1106 (p
->ip
>> 16) & 0xFF,
1107 (p
->ip
>> 8) & 0xFF,
1109 (netmask
>> 24) & 0xFF,
1110 (netmask
>> 16) & 0xFF,
1111 (netmask
>> 8) & 0xFF,
1113 (bcast
>> 24) & 0xFF,
1114 (bcast
>> 16) & 0xFF,
1115 (bcast
>> 8) & 0xFF,
1118 printf("\tether %02" PRIx32
":%02" PRIx32
":%02" PRIx32
1119 ":%02" PRIx32
":%02" PRIx32
":%02" PRIx32
"\n",
1120 mac_addr
->addr_bytes
[0],
1121 mac_addr
->addr_bytes
[1],
1122 mac_addr
->addr_bytes
[2],
1123 mac_addr
->addr_bytes
[3],
1124 mac_addr
->addr_bytes
[4],
1125 mac_addr
->addr_bytes
[5]);
1127 printf("\tRX packets %" PRIu64
1133 printf("\tRX errors %" PRIu64
1141 printf("\tTX packets %" PRIu64
1142 " bytes %" PRIu64
"\n",
1146 printf("\tTX errors %" PRIu64
1157 * link <linkid> config <ipaddr> <depth>
1163 * link <linkid> down
1169 struct cmd_link_result
{
1170 cmdline_fixed_string_t link_string
;
1171 cmdline_multi_string_t multi_string
;
1176 void *parsed_result
,
1177 __attribute__((unused
)) struct cmdline
*cl
,
1180 struct cmd_link_result
*params
= parsed_result
;
1181 struct app_params
*app
= data
;
1184 uint32_t n_tokens
= RTE_DIM(tokens
);
1189 status
= parse_tokenize_string(params
->multi_string
, tokens
, &n_tokens
);
1191 printf(CMD_MSG_TOO_MANY_ARGS
, "link");
1196 if ((n_tokens
== 1) && (strcmp(tokens
[0], "ls") == 0)) {
1197 for (link_id
= 0; link_id
< app
->n_links
; link_id
++) {
1198 struct app_link_params
*p
;
1200 APP_PARAM_FIND_BY_ID(app
->link_params
, "LINK", link_id
, p
);
1207 printf(CMD_MSG_MISMATCH_ARGS
, "link");
1211 if (parser_read_uint32(&link_id
, tokens
[0])) {
1212 printf(CMD_MSG_INVALID_ARG
, "linkid");
1217 if (strcmp(tokens
[1], "config") == 0) {
1218 struct in_addr ipaddr_ipv4
;
1221 if (n_tokens
!= 4) {
1222 printf(CMD_MSG_MISMATCH_ARGS
, "link config");
1226 if (parse_ipv4_addr(tokens
[2], &ipaddr_ipv4
)) {
1227 printf(CMD_MSG_INVALID_ARG
, "ipaddr");
1231 if (parser_read_uint32(&depth
, tokens
[3])) {
1232 printf(CMD_MSG_INVALID_ARG
, "depth");
1236 status
= app_link_config(app
,
1238 rte_be_to_cpu_32(ipaddr_ipv4
.s_addr
),
1241 printf(CMD_MSG_FAIL
, "link config");
1247 if (strcmp(tokens
[1], "up") == 0) {
1248 if (n_tokens
!= 2) {
1249 printf(CMD_MSG_MISMATCH_ARGS
, "link up");
1253 status
= app_link_up(app
, link_id
);
1255 printf(CMD_MSG_FAIL
, "link up");
1261 if (strcmp(tokens
[1], "down") == 0) {
1262 if (n_tokens
!= 2) {
1263 printf(CMD_MSG_MISMATCH_ARGS
, "link down");
1267 status
= app_link_down(app
, link_id
);
1269 printf(CMD_MSG_FAIL
, "link down");
1274 printf(CMD_MSG_MISMATCH_ARGS
, "link");
1277 static cmdline_parse_token_string_t cmd_link_link_string
=
1278 TOKEN_STRING_INITIALIZER(struct cmd_link_result
, link_string
, "link");
1280 static cmdline_parse_token_string_t cmd_link_multi_string
=
1281 TOKEN_STRING_INITIALIZER(struct cmd_link_result
, multi_string
,
1282 TOKEN_STRING_MULTI
);
1284 static cmdline_parse_inst_t cmd_link
= {
1285 .f
= cmd_link_parsed
,
1287 .help_str
= "link config / up / down / ls",
1289 (void *) &cmd_link_link_string
,
1290 (void *) &cmd_link_multi_string
,
1299 struct cmd_quit_result
{
1300 cmdline_fixed_string_t quit
;
1305 __rte_unused
void *parsed_result
,
1307 __rte_unused
void *data
)
1312 static cmdline_parse_token_string_t cmd_quit_quit
=
1313 TOKEN_STRING_INITIALIZER(struct cmd_quit_result
, quit
, "quit");
1315 static cmdline_parse_inst_t cmd_quit
= {
1316 .f
= cmd_quit_parsed
,
1320 (void *) &cmd_quit_quit
,
1329 * run <file> [<count> [<interval>]]
1330 <count> default is 1
1331 * <interval> is measured in milliseconds, default is 1 second
1336 cmdline_parse_ctx_t
*ctx
,
1337 const char *file_name
)
1339 struct cmdline
*file_cl
;
1342 fd
= open(file_name
, O_RDONLY
);
1344 printf("Cannot open file \"%s\"\n", file_name
);
1348 file_cl
= cmdline_new(ctx
, "", fd
, 1);
1349 cmdline_interact(file_cl
);
1353 struct cmd_run_result
{
1354 cmdline_fixed_string_t run_string
;
1355 cmdline_multi_string_t multi_string
;
1360 void *parsed_result
,
1362 __attribute__((unused
)) void *data
)
1364 struct cmd_run_result
*params
= parsed_result
;
1367 uint32_t n_tokens
= RTE_DIM(tokens
);
1371 uint32_t count
, interval
, i
;
1373 status
= parse_tokenize_string(params
->multi_string
, tokens
, &n_tokens
);
1375 printf(CMD_MSG_TOO_MANY_ARGS
, "run");
1381 printf(CMD_MSG_NOT_ENOUGH_ARGS
, "run");
1385 file_name
= tokens
[0];
1391 file_name
= tokens
[0];
1393 if (parser_read_uint32(&count
, tokens
[1]) ||
1395 printf(CMD_MSG_INVALID_ARG
, "count");
1403 file_name
= tokens
[0];
1405 if (parser_read_uint32(&count
, tokens
[1]) ||
1407 printf(CMD_MSG_INVALID_ARG
, "count");
1411 if (parser_read_uint32(&interval
, tokens
[2]) ||
1413 printf(CMD_MSG_INVALID_ARG
, "interval");
1419 printf(CMD_MSG_MISMATCH_ARGS
, "run");
1423 for (i
= 0; i
< count
; i
++) {
1424 app_run_file(cl
->ctx
, file_name
);
1426 usleep(interval
* 1000);
1430 static cmdline_parse_token_string_t cmd_run_run_string
=
1431 TOKEN_STRING_INITIALIZER(struct cmd_run_result
, run_string
, "run");
1433 static cmdline_parse_token_string_t cmd_run_multi_string
=
1434 TOKEN_STRING_INITIALIZER(struct cmd_run_result
, multi_string
,
1435 TOKEN_STRING_MULTI
);
1438 static cmdline_parse_inst_t cmd_run
= {
1439 .f
= cmd_run_parsed
,
1441 .help_str
= "Run CLI script file",
1443 (void *) &cmd_run_run_string
,
1444 (void *) &cmd_run_multi_string
,
1449 static cmdline_parse_ctx_t pipeline_common_cmds
[] = {
1450 (cmdline_parse_inst_t
*) &cmd_quit
,
1451 (cmdline_parse_inst_t
*) &cmd_run
,
1452 (cmdline_parse_inst_t
*) &cmd_link
,
1453 (cmdline_parse_inst_t
*) &cmd_ping
,
1454 (cmdline_parse_inst_t
*) &cmd_stats_port_in
,
1455 (cmdline_parse_inst_t
*) &cmd_stats_port_out
,
1456 (cmdline_parse_inst_t
*) &cmd_stats_table
,
1457 (cmdline_parse_inst_t
*) &cmd_port_in_enable
,
1458 (cmdline_parse_inst_t
*) &cmd_port_in_disable
,
1463 app_pipeline_common_cmd_push(struct app_params
*app
)
1467 /* Check for available slots in the application commands array */
1468 n_cmds
= RTE_DIM(pipeline_common_cmds
) - 1;
1469 if (n_cmds
> APP_MAX_CMDS
- app
->n_cmds
)
1472 /* Push pipeline commands into the application */
1473 memcpy(&app
->cmds
[app
->n_cmds
],
1474 pipeline_common_cmds
,
1475 n_cmds
* sizeof(cmdline_parse_ctx_t
));
1477 for (i
= 0; i
< n_cmds
; i
++)
1478 app
->cmds
[app
->n_cmds
+ i
]->data
= app
;
1480 app
->n_cmds
+= n_cmds
;
1481 app
->cmds
[app
->n_cmds
] = NULL
;