Imported Upstream version 16.07-rc1
[deb_dpdk.git] / examples / ip_pipeline / pipeline / pipeline_common_fe.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #include <stdio.h>
35 #include <fcntl.h>
36 #include <unistd.h>
37
38 #include <rte_common.h>
39 #include <rte_ring.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>
45 #include <cmdline.h>
46
47 #include "pipeline_common_fe.h"
48 #include "parser.h"
49
50 struct app_link_params *
51 app_pipeline_track_pktq_out_to_link(struct app_params *app,
52         uint32_t pipeline_id,
53         uint32_t pktq_out_id)
54 {
55         struct app_pipeline_params *p;
56
57         /* Check input arguments */
58         if (app == NULL)
59                 return NULL;
60
61         APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
62         if (p == NULL)
63                 return NULL;
64
65         for ( ; ; ) {
66                 struct app_pktq_out_params *pktq_out =
67                         &p->pktq_out[pktq_out_id];
68
69                 switch (pktq_out->type) {
70                 case APP_PKTQ_OUT_HWQ:
71                 {
72                         struct app_pktq_hwq_out_params *hwq_out;
73
74                         hwq_out = &app->hwq_out_params[pktq_out->id];
75
76                         return app_get_link_for_txq(app, hwq_out);
77                 }
78
79                 case APP_PKTQ_OUT_SWQ:
80                 {
81                         struct pipeline_params pp;
82                         struct pipeline_type *ptype;
83                         struct app_pktq_swq_params *swq;
84                         uint32_t pktq_in_id;
85                         int status;
86
87                         swq = &app->swq_params[pktq_out->id];
88                         p = app_swq_get_reader(app, swq, &pktq_in_id);
89                         if (p == NULL)
90                                 return NULL;
91
92                         ptype = app_pipeline_type_find(app, p->type);
93                         if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL))
94                                 return NULL;
95
96                         app_pipeline_params_get(app, p, &pp);
97                         status = ptype->fe_ops->f_track(&pp,
98                                 pktq_in_id,
99                                 &pktq_out_id);
100                         if (status)
101                                 return NULL;
102
103                         break;
104                 }
105
106                 case APP_PKTQ_OUT_TM:
107                 {
108                         struct pipeline_params pp;
109                         struct pipeline_type *ptype;
110                         struct app_pktq_tm_params *tm;
111                         uint32_t pktq_in_id;
112                         int status;
113
114                         tm = &app->tm_params[pktq_out->id];
115                         p = app_tm_get_reader(app, tm, &pktq_in_id);
116                         if (p == NULL)
117                                 return NULL;
118
119                         ptype = app_pipeline_type_find(app, p->type);
120                         if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL))
121                                 return NULL;
122
123                         app_pipeline_params_get(app, p, &pp);
124                         status = ptype->fe_ops->f_track(&pp,
125                                 pktq_in_id,
126                                 &pktq_out_id);
127                         if (status)
128                                 return NULL;
129
130                         break;
131                 }
132
133                 case APP_PKTQ_OUT_KNI:
134                 {
135                         struct pipeline_params pp;
136                         struct pipeline_type *ptype;
137                         struct app_pktq_kni_params *kni;
138                         uint32_t pktq_in_id;
139                         int status;
140
141                         kni = &app->kni_params[pktq_out->id];
142                         p = app_kni_get_reader(app, kni, &pktq_in_id);
143                         if (p == NULL)
144                                 return NULL;
145
146                         ptype = app_pipeline_type_find(app, p->type);
147                         if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL))
148                                 return NULL;
149
150                         app_pipeline_params_get(app, p, &pp);
151                         status = ptype->fe_ops->f_track(&pp,
152                                 pktq_in_id,
153                                 &pktq_out_id);
154                         if (status)
155                                 return NULL;
156
157                         break;
158                 }
159
160                 case APP_PKTQ_OUT_SINK:
161                 default:
162                         return NULL;
163                 }
164         }
165 }
166
167 int
168 app_pipeline_track_default(struct pipeline_params *p,
169         uint32_t port_in,
170         uint32_t *port_out)
171 {
172         /* Check input arguments */
173         if ((p == NULL) ||
174                 (port_in >= p->n_ports_in) ||
175                 (port_out == NULL))
176                 return -1;
177
178         if (p->n_ports_out == 1) {
179                 *port_out = 0;
180                 return 0;
181         }
182
183         return -1;
184 }
185
186 int
187 app_pipeline_ping(struct app_params *app,
188         uint32_t pipeline_id)
189 {
190         struct app_pipeline_params *p;
191         struct pipeline_msg_req *req;
192         struct pipeline_msg_rsp *rsp;
193         int status = 0;
194
195         /* Check input arguments */
196         if (app == NULL)
197                 return -1;
198
199         APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
200         if (p == NULL)
201                 return -1;
202
203         /* Message buffer allocation */
204         req = app_msg_alloc(app);
205         if (req == NULL)
206                 return -1;
207
208         /* Fill in request */
209         req->type = PIPELINE_MSG_REQ_PING;
210
211         /* Send request and wait for response */
212         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
213         if (rsp == NULL)
214                 return -1;
215
216         /* Check response */
217         status = rsp->status;
218
219         /* Message buffer free */
220         app_msg_free(app, rsp);
221
222         return status;
223 }
224
225 int
226 app_pipeline_stats_port_in(struct app_params *app,
227         uint32_t pipeline_id,
228         uint32_t port_id,
229         struct rte_pipeline_port_in_stats *stats)
230 {
231         struct app_pipeline_params *p;
232         struct pipeline_stats_msg_req *req;
233         struct pipeline_stats_port_in_msg_rsp *rsp;
234         int status = 0;
235
236         /* Check input arguments */
237         if ((app == NULL) ||
238                 (stats == NULL))
239                 return -1;
240
241         APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
242         if ((p == NULL) ||
243                 (port_id >= p->n_pktq_in))
244                 return -1;
245
246         /* Message buffer allocation */
247         req = app_msg_alloc(app);
248         if (req == NULL)
249                 return -1;
250
251         /* Fill in request */
252         req->type = PIPELINE_MSG_REQ_STATS_PORT_IN;
253         req->id = port_id;
254
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);
258         if (rsp == NULL)
259                 return -1;
260
261         /* Check response */
262         status = rsp->status;
263         if (status == 0)
264                 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
265
266         /* Message buffer free */
267         app_msg_free(app, rsp);
268
269         return status;
270 }
271
272 int
273 app_pipeline_stats_port_out(struct app_params *app,
274         uint32_t pipeline_id,
275         uint32_t port_id,
276         struct rte_pipeline_port_out_stats *stats)
277 {
278         struct app_pipeline_params *p;
279         struct pipeline_stats_msg_req *req;
280         struct pipeline_stats_port_out_msg_rsp *rsp;
281         int status = 0;
282
283         /* Check input arguments */
284         if ((app == NULL) ||
285                 (pipeline_id >= app->n_pipelines) ||
286                 (stats == NULL))
287                 return -1;
288
289         APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
290         if ((p == NULL) ||
291                 (port_id >= p->n_pktq_out))
292                 return -1;
293
294         /* Message buffer allocation */
295         req = app_msg_alloc(app);
296         if (req == NULL)
297                 return -1;
298
299         /* Fill in request */
300         req->type = PIPELINE_MSG_REQ_STATS_PORT_OUT;
301         req->id = port_id;
302
303         /* Send request and wait for response */
304         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
305         if (rsp == NULL)
306                 return -1;
307
308         /* Check response */
309         status = rsp->status;
310         if (status == 0)
311                 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
312
313         /* Message buffer free */
314         app_msg_free(app, rsp);
315
316         return status;
317 }
318
319 int
320 app_pipeline_stats_table(struct app_params *app,
321         uint32_t pipeline_id,
322         uint32_t table_id,
323         struct rte_pipeline_table_stats *stats)
324 {
325         struct app_pipeline_params *p;
326         struct pipeline_stats_msg_req *req;
327         struct pipeline_stats_table_msg_rsp *rsp;
328         int status = 0;
329
330         /* Check input arguments */
331         if ((app == NULL) ||
332                 (stats == NULL))
333                 return -1;
334
335         APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
336         if (p == NULL)
337                 return -1;
338
339         /* Message buffer allocation */
340         req = app_msg_alloc(app);
341         if (req == NULL)
342                 return -1;
343
344         /* Fill in request */
345         req->type = PIPELINE_MSG_REQ_STATS_TABLE;
346         req->id = table_id;
347
348         /* Send request and wait for response */
349         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
350         if (rsp == NULL)
351                 return -1;
352
353         /* Check response */
354         status = rsp->status;
355         if (status == 0)
356                 memcpy(stats, &rsp->stats, sizeof(rsp->stats));
357
358         /* Message buffer free */
359         app_msg_free(app, rsp);
360
361         return status;
362 }
363
364 int
365 app_pipeline_port_in_enable(struct app_params *app,
366         uint32_t pipeline_id,
367         uint32_t port_id)
368 {
369         struct app_pipeline_params *p;
370         struct pipeline_port_in_msg_req *req;
371         struct pipeline_msg_rsp *rsp;
372         int status = 0;
373
374         /* Check input arguments */
375         if (app == NULL)
376                 return -1;
377
378         APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
379         if ((p == NULL) ||
380                 (port_id >= p->n_pktq_in))
381                 return -1;
382
383         /* Message buffer allocation */
384         req = app_msg_alloc(app);
385         if (req == NULL)
386                 return -1;
387
388         /* Fill in request */
389         req->type = PIPELINE_MSG_REQ_PORT_IN_ENABLE;
390         req->port_id = port_id;
391
392         /* Send request and wait for response */
393         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
394         if (rsp == NULL)
395                 return -1;
396
397         /* Check response */
398         status = rsp->status;
399
400         /* Message buffer free */
401         app_msg_free(app, rsp);
402
403         return status;
404 }
405
406 int
407 app_pipeline_port_in_disable(struct app_params *app,
408         uint32_t pipeline_id,
409         uint32_t port_id)
410 {
411         struct app_pipeline_params *p;
412         struct pipeline_port_in_msg_req *req;
413         struct pipeline_msg_rsp *rsp;
414         int status = 0;
415
416         /* Check input arguments */
417         if (app == NULL)
418                 return -1;
419
420         APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p);
421         if ((p == NULL) ||
422                 (port_id >= p->n_pktq_in))
423                 return -1;
424
425         /* Message buffer allocation */
426         req = app_msg_alloc(app);
427         if (req == NULL)
428                 return -1;
429
430         /* Fill in request */
431         req->type = PIPELINE_MSG_REQ_PORT_IN_DISABLE;
432         req->port_id = port_id;
433
434         /* Send request and wait for response */
435         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
436         if (rsp == NULL)
437                 return -1;
438
439         /* Check response */
440         status = rsp->status;
441
442         /* Message buffer free */
443         app_msg_free(app, rsp);
444
445         return status;
446 }
447
448 int
449 app_link_set_op(struct app_params *app,
450         uint32_t link_id,
451         uint32_t pipeline_id,
452         app_link_op op,
453         void *arg)
454 {
455         struct app_pipeline_params *pp;
456         struct app_link_params *lp;
457         struct app_link_data *ld;
458         uint32_t ppos, lpos;
459
460         /* Check input arguments */
461         if ((app == NULL) ||
462                 (op == NULL))
463                 return -1;
464
465         APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, lp);
466         if (lp == NULL)
467                 return -1;
468         lpos = lp - app->link_params;
469         ld = &app->link_data[lpos];
470
471         APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, pp);
472         if (pp == NULL)
473                 return -1;
474         ppos = pp - app->pipeline_params;
475
476         ld->f_link[ppos] = op;
477         ld->arg[ppos] = arg;
478
479         return 0;
480 }
481
482 int
483 app_link_config(struct app_params *app,
484         uint32_t link_id,
485         uint32_t ip,
486         uint32_t depth)
487 {
488         struct app_link_params *p;
489         uint32_t i, netmask, host, bcast;
490
491         /* Check input arguments */
492         if (app == NULL)
493                 return -1;
494
495         APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
496         if (p == NULL) {
497                 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
498                         link_id);
499                 return -1;
500         }
501
502         if (p->state) {
503                 APP_LOG(app, HIGH, "%s is UP, please bring it DOWN first",
504                         p->name);
505                 return -1;
506         }
507
508         netmask = (~0U) << (32 - depth);
509         host = ip & netmask;
510         bcast = host | (~netmask);
511
512         if ((ip == 0) ||
513                 (ip == UINT32_MAX) ||
514                 (ip == host) ||
515                 (ip == bcast)) {
516                 APP_LOG(app, HIGH, "Illegal IP address");
517                 return -1;
518         }
519
520         for (i = 0; i < app->n_links; i++) {
521                 struct app_link_params *link = &app->link_params[i];
522
523                 if (strcmp(p->name, link->name) == 0)
524                         continue;
525
526                 if (link->ip == ip) {
527                         APP_LOG(app, HIGH,
528                                 "%s is already assigned this IP address",
529                                 link->name);
530                         return -1;
531                 }
532         }
533
534         if ((depth == 0) || (depth > 32)) {
535                 APP_LOG(app, HIGH, "Illegal value for depth parameter "
536                         "(%" PRIu32 ")",
537                         depth);
538                 return -1;
539         }
540
541         /* Save link parameters */
542         p->ip = ip;
543         p->depth = depth;
544
545         return 0;
546 }
547
548 int
549 app_link_up(struct app_params *app,
550         uint32_t link_id)
551 {
552         struct app_link_params *p;
553         struct app_link_data *d;
554         int i;
555
556         /* Check input arguments */
557         if (app == NULL)
558                 return -1;
559
560         APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
561         if (p == NULL) {
562                 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
563                         link_id);
564                 return -1;
565         }
566
567         d = &app->link_data[p - app->link_params];
568
569         /* Check link state */
570         if (p->state) {
571                 APP_LOG(app, HIGH, "%s is already UP", p->name);
572                 return 0;
573         }
574
575         /* Check that IP address is valid */
576         if (p->ip == 0) {
577                 APP_LOG(app, HIGH, "%s IP address is not set", p->name);
578                 return 0;
579         }
580
581         app_link_up_internal(app, p);
582
583         /* Callbacks */
584         for (i = 0; i < APP_MAX_PIPELINES; i++)
585                 if (d->f_link[i])
586                         d->f_link[i](app, link_id, 1, d->arg[i]);
587
588         return 0;
589 }
590
591 int
592 app_link_down(struct app_params *app,
593         uint32_t link_id)
594 {
595         struct app_link_params *p;
596         struct app_link_data *d;
597         uint32_t i;
598
599         /* Check input arguments */
600         if (app == NULL)
601                 return -1;
602
603         APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
604         if (p == NULL) {
605                 APP_LOG(app, HIGH, "LINK%" PRIu32 " is not a valid link",
606                         link_id);
607                 return -1;
608         }
609
610         d = &app->link_data[p - app->link_params];
611
612         /* Check link state */
613         if (p->state == 0) {
614                 APP_LOG(app, HIGH, "%s is already DOWN", p->name);
615                 return 0;
616         }
617
618         app_link_down_internal(app, p);
619
620         /* Callbacks */
621         for (i = 0; i < APP_MAX_PIPELINES; i++)
622                 if (d->f_link[i])
623                         d->f_link[i](app, link_id, 0, d->arg[i]);
624
625         return 0;
626 }
627
628 /*
629  * ping
630  */
631
632 struct cmd_ping_result {
633         cmdline_fixed_string_t p_string;
634         uint32_t pipeline_id;
635         cmdline_fixed_string_t ping_string;
636 };
637
638 static void
639 cmd_ping_parsed(
640         void *parsed_result,
641         __rte_unused struct cmdline *cl,
642         void *data)
643 {
644         struct cmd_ping_result *params = parsed_result;
645         struct app_params *app = data;
646         int status;
647
648         status = app_pipeline_ping(app, params->pipeline_id);
649         if (status != 0)
650                 printf("Command failed\n");
651 }
652
653 static cmdline_parse_token_string_t cmd_ping_p_string =
654         TOKEN_STRING_INITIALIZER(struct cmd_ping_result, p_string, "p");
655
656 static cmdline_parse_token_num_t cmd_ping_pipeline_id =
657         TOKEN_NUM_INITIALIZER(struct cmd_ping_result, pipeline_id, UINT32);
658
659 static cmdline_parse_token_string_t cmd_ping_ping_string =
660         TOKEN_STRING_INITIALIZER(struct cmd_ping_result, ping_string, "ping");
661
662 static cmdline_parse_inst_t cmd_ping = {
663         .f = cmd_ping_parsed,
664         .data = NULL,
665         .help_str = "Pipeline ping",
666         .tokens = {
667                 (void *) &cmd_ping_p_string,
668                 (void *) &cmd_ping_pipeline_id,
669                 (void *) &cmd_ping_ping_string,
670                 NULL,
671         },
672 };
673
674 /*
675  * stats port in
676  */
677
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;
684         uint32_t port_in_id;
685
686 };
687
688 static void
689 cmd_stats_port_in_parsed(
690         void *parsed_result,
691         __rte_unused struct cmdline *cl,
692         void *data)
693 {
694         struct cmd_stats_port_in_result *params = parsed_result;
695         struct app_params *app = data;
696         struct rte_pipeline_port_in_stats stats;
697         int status;
698
699         status = app_pipeline_stats_port_in(app,
700                         params->pipeline_id,
701                         params->port_in_id,
702                         &stats);
703
704         if (status != 0) {
705                 printf("Command failed\n");
706                 return;
707         }
708
709         /* Display stats */
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",
714                 params->pipeline_id,
715                 params->port_in_id,
716                 stats.stats.n_pkts_in,
717                 stats.n_pkts_dropped_by_ah,
718                 stats.stats.n_pkts_drop);
719 }
720
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,
723                 "p");
724
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,
727                 UINT32);
728
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,
731                 "stats");
732
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,
735                 "port");
736
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,
739                 "in");
740
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,
743                 UINT32);
744
745 static cmdline_parse_inst_t cmd_stats_port_in = {
746         .f = cmd_stats_port_in_parsed,
747         .data = NULL,
748         .help_str = "Pipeline input port stats",
749         .tokens = {
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,
756                 NULL,
757         },
758 };
759
760 /*
761  * stats port out
762  */
763
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;
771 };
772
773 static void
774 cmd_stats_port_out_parsed(
775         void *parsed_result,
776         __rte_unused struct cmdline *cl,
777         void *data)
778 {
779
780         struct cmd_stats_port_out_result *params = parsed_result;
781         struct app_params *app = data;
782         struct rte_pipeline_port_out_stats stats;
783         int status;
784
785         status = app_pipeline_stats_port_out(app,
786                         params->pipeline_id,
787                         params->port_out_id,
788                         &stats);
789
790         if (status != 0) {
791                 printf("Command failed\n");
792                 return;
793         }
794
795         /* Display stats */
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",
800                 params->pipeline_id,
801                 params->port_out_id,
802                 stats.stats.n_pkts_in,
803                 stats.n_pkts_dropped_by_ah,
804                 stats.stats.n_pkts_drop);
805 }
806
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,
809         "p");
810
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,
813                 UINT32);
814
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,
817                 "stats");
818
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,
821                 "port");
822
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,
825                 "out");
826
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,
829                 UINT32);
830
831 static cmdline_parse_inst_t cmd_stats_port_out = {
832         .f = cmd_stats_port_out_parsed,
833         .data = NULL,
834         .help_str = "Pipeline output port stats",
835         .tokens = {
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,
842                 NULL,
843         },
844 };
845
846 /*
847  * stats table
848  */
849
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;
855         uint32_t table_id;
856 };
857
858 static void
859 cmd_stats_table_parsed(
860         void *parsed_result,
861         __rte_unused struct cmdline *cl,
862         void *data)
863 {
864         struct cmd_stats_table_result *params = parsed_result;
865         struct app_params *app = data;
866         struct rte_pipeline_table_stats stats;
867         int status;
868
869         status = app_pipeline_stats_table(app,
870                         params->pipeline_id,
871                         params->table_id,
872                         &stats);
873
874         if (status != 0) {
875                 printf("Command failed\n");
876                 return;
877         }
878
879         /* Display stats */
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",
887                 params->pipeline_id,
888                 params->table_id,
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);
895 }
896
897 static cmdline_parse_token_string_t cmd_stats_table_p_string =
898         TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, p_string,
899                 "p");
900
901 static cmdline_parse_token_num_t cmd_stats_table_pipeline_id =
902         TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, pipeline_id,
903                 UINT32);
904
905 static cmdline_parse_token_string_t cmd_stats_table_stats_string =
906         TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, stats_string,
907                 "stats");
908
909 static cmdline_parse_token_string_t cmd_stats_table_table_string =
910         TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, table_string,
911                 "table");
912
913 static cmdline_parse_token_num_t cmd_stats_table_table_id =
914         TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, table_id, UINT32);
915
916 static cmdline_parse_inst_t cmd_stats_table = {
917         .f = cmd_stats_table_parsed,
918         .data = NULL,
919         .help_str = "Pipeline table stats",
920         .tokens = {
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,
926                 NULL,
927         },
928 };
929
930 /*
931  * port in enable
932  */
933
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;
939         uint32_t port_in_id;
940         cmdline_fixed_string_t enable_string;
941 };
942
943 static void
944 cmd_port_in_enable_parsed(
945         void *parsed_result,
946         __rte_unused struct cmdline *cl,
947         void *data)
948 {
949         struct cmd_port_in_enable_result *params = parsed_result;
950         struct app_params *app = data;
951         int status;
952
953         status = app_pipeline_port_in_enable(app,
954                         params->pipeline_id,
955                         params->port_in_id);
956
957         if (status != 0)
958                 printf("Command failed\n");
959 }
960
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,
963                 "p");
964
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,
967                 UINT32);
968
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,
971         "port");
972
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,
975                 "in");
976
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,
979                 UINT32);
980
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");
984
985 static cmdline_parse_inst_t cmd_port_in_enable = {
986         .f = cmd_port_in_enable_parsed,
987         .data = NULL,
988         .help_str = "Pipeline input port enable",
989         .tokens = {
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,
996                 NULL,
997         },
998 };
999
1000 /*
1001  * port in disable
1002  */
1003
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;
1011 };
1012
1013 static void
1014 cmd_port_in_disable_parsed(
1015         void *parsed_result,
1016         __rte_unused struct cmdline *cl,
1017         void *data)
1018 {
1019         struct cmd_port_in_disable_result *params = parsed_result;
1020         struct app_params *app = data;
1021         int status;
1022
1023         status = app_pipeline_port_in_disable(app,
1024                         params->pipeline_id,
1025                         params->port_in_id);
1026
1027         if (status != 0)
1028                 printf("Command failed\n");
1029 }
1030
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,
1033                 "p");
1034
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,
1037                 UINT32);
1038
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,
1041                 "port");
1042
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,
1045                 "in");
1046
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,
1049                 UINT32);
1050
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");
1054
1055 static cmdline_parse_inst_t cmd_port_in_disable = {
1056         .f = cmd_port_in_disable_parsed,
1057         .data = NULL,
1058         .help_str = "Pipeline input port disable",
1059         .tokens = {
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,
1066                 NULL,
1067         },
1068 };
1069
1070 /*
1071  * link config
1072  */
1073
1074 static void
1075 print_link_info(struct app_link_params *p)
1076 {
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);
1082
1083         memset(&stats, 0, sizeof(stats));
1084         rte_eth_stats_get(p->pmd_id, &stats);
1085
1086         mac_addr = (struct ether_addr *) &p->mac_addr;
1087
1088         if (strlen(p->pci_bdf))
1089                 printf("%s(%s): flags=<%s>\n",
1090                         p->name,
1091                         p->pci_bdf,
1092                         (p->state) ? "UP" : "DOWN");
1093         else
1094                 printf("%s: flags=<%s>\n",
1095                         p->name,
1096                         (p->state) ? "UP" : "DOWN");
1097
1098         if (p->ip)
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,
1108                         p->ip & 0xFF,
1109                         (netmask >> 24) & 0xFF,
1110                         (netmask >> 16) & 0xFF,
1111                         (netmask >> 8) & 0xFF,
1112                         netmask & 0xFF,
1113                         (bcast >> 24) & 0xFF,
1114                         (bcast >> 16) & 0xFF,
1115                         (bcast >> 8) & 0xFF,
1116                         bcast & 0xFF);
1117
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]);
1126
1127         printf("\tRX packets %" PRIu64
1128                 "  bytes %" PRIu64
1129                 "\n",
1130                 stats.ipackets,
1131                 stats.ibytes);
1132
1133         printf("\tRX errors %" PRIu64
1134                 "  missed %" PRIu64
1135                 "  no-mbuf %" PRIu64
1136                 "\n",
1137                 stats.ierrors,
1138                 stats.imissed,
1139                 stats.rx_nombuf);
1140
1141         printf("\tTX packets %" PRIu64
1142                 "  bytes %" PRIu64 "\n",
1143                 stats.opackets,
1144                 stats.obytes);
1145
1146         printf("\tTX errors %" PRIu64
1147                 "\n",
1148                 stats.oerrors);
1149
1150         printf("\n");
1151 }
1152
1153 /*
1154  * link
1155  *
1156  * link config:
1157  *    link <linkid> config <ipaddr> <depth>
1158  *
1159  * link up:
1160  *    link <linkid> up
1161  *
1162  * link down:
1163  *    link <linkid> down
1164  *
1165  * link ls:
1166  *    link ls
1167  */
1168
1169 struct cmd_link_result {
1170         cmdline_fixed_string_t link_string;
1171         cmdline_multi_string_t multi_string;
1172 };
1173
1174 static void
1175 cmd_link_parsed(
1176         void *parsed_result,
1177         __attribute__((unused)) struct cmdline *cl,
1178          void *data)
1179 {
1180         struct cmd_link_result *params = parsed_result;
1181         struct app_params *app = data;
1182
1183         char *tokens[16];
1184         uint32_t n_tokens = RTE_DIM(tokens);
1185         int status;
1186
1187         uint32_t link_id;
1188
1189         status = parse_tokenize_string(params->multi_string, tokens, &n_tokens);
1190         if (status != 0) {
1191                 printf(CMD_MSG_TOO_MANY_ARGS, "link");
1192                 return;
1193         }
1194
1195         /* link ls */
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;
1199
1200                         APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p);
1201                         print_link_info(p);
1202                 }
1203                 return;
1204         } /* link ls */
1205
1206         if (n_tokens < 2) {
1207                 printf(CMD_MSG_MISMATCH_ARGS, "link");
1208                 return;
1209         }
1210
1211         if (parser_read_uint32(&link_id, tokens[0])) {
1212                 printf(CMD_MSG_INVALID_ARG, "linkid");
1213                 return;
1214         }
1215
1216         /* link config */
1217         if (strcmp(tokens[1], "config") == 0) {
1218                 struct in_addr ipaddr_ipv4;
1219                 uint32_t depth;
1220
1221                 if (n_tokens != 4) {
1222                         printf(CMD_MSG_MISMATCH_ARGS, "link config");
1223                         return;
1224                 }
1225
1226                 if (parse_ipv4_addr(tokens[2], &ipaddr_ipv4)) {
1227                         printf(CMD_MSG_INVALID_ARG, "ipaddr");
1228                         return;
1229                 }
1230
1231                 if (parser_read_uint32(&depth, tokens[3])) {
1232                         printf(CMD_MSG_INVALID_ARG, "depth");
1233                         return;
1234                 }
1235
1236                 status = app_link_config(app,
1237                         link_id,
1238                         rte_be_to_cpu_32(ipaddr_ipv4.s_addr),
1239                         depth);
1240                 if (status)
1241                         printf(CMD_MSG_FAIL, "link config");
1242
1243                 return;
1244         } /* link config */
1245
1246         /* link up */
1247         if (strcmp(tokens[1], "up") == 0) {
1248                 if (n_tokens != 2) {
1249                         printf(CMD_MSG_MISMATCH_ARGS, "link up");
1250                         return;
1251                 }
1252
1253                 status = app_link_up(app, link_id);
1254                 if (status)
1255                         printf(CMD_MSG_FAIL, "link up");
1256
1257                 return;
1258         } /* link up */
1259
1260         /* link down */
1261         if (strcmp(tokens[1], "down") == 0) {
1262                 if (n_tokens != 2) {
1263                         printf(CMD_MSG_MISMATCH_ARGS, "link down");
1264                         return;
1265                 }
1266
1267                 status = app_link_down(app, link_id);
1268                 if (status)
1269                         printf(CMD_MSG_FAIL, "link down");
1270
1271                 return;
1272         } /* link down */
1273
1274         printf(CMD_MSG_MISMATCH_ARGS, "link");
1275 }
1276
1277 static cmdline_parse_token_string_t cmd_link_link_string =
1278         TOKEN_STRING_INITIALIZER(struct cmd_link_result, link_string, "link");
1279
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);
1283
1284 static cmdline_parse_inst_t cmd_link = {
1285         .f = cmd_link_parsed,
1286         .data = NULL,
1287         .help_str = "link config / up / down / ls",
1288         .tokens = {
1289                 (void *) &cmd_link_link_string,
1290                 (void *) &cmd_link_multi_string,
1291                 NULL,
1292         },
1293 };
1294
1295 /*
1296  * quit
1297  */
1298
1299 struct cmd_quit_result {
1300         cmdline_fixed_string_t quit;
1301 };
1302
1303 static void
1304 cmd_quit_parsed(
1305         __rte_unused void *parsed_result,
1306         struct cmdline *cl,
1307         __rte_unused void *data)
1308 {
1309         cmdline_quit(cl);
1310 }
1311
1312 static cmdline_parse_token_string_t cmd_quit_quit =
1313         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
1314
1315 static cmdline_parse_inst_t cmd_quit = {
1316         .f = cmd_quit_parsed,
1317         .data = NULL,
1318         .help_str = "Quit",
1319         .tokens = {
1320                 (void *) &cmd_quit_quit,
1321                 NULL,
1322         },
1323 };
1324
1325 /*
1326  * run
1327  *
1328  *    run <file>
1329  *    run <file> [<count> [<interval>]]
1330          <count> default is 1
1331  *       <interval> is measured in milliseconds, default is 1 second
1332  */
1333
1334 static void
1335 app_run_file(
1336         cmdline_parse_ctx_t *ctx,
1337         const char *file_name)
1338 {
1339         struct cmdline *file_cl;
1340         int fd;
1341
1342         fd = open(file_name, O_RDONLY);
1343         if (fd < 0) {
1344                 printf("Cannot open file \"%s\"\n", file_name);
1345                 return;
1346         }
1347
1348         file_cl = cmdline_new(ctx, "", fd, 1);
1349         cmdline_interact(file_cl);
1350         close(fd);
1351 }
1352
1353 struct cmd_run_result {
1354         cmdline_fixed_string_t run_string;
1355         cmdline_multi_string_t multi_string;
1356 };
1357
1358 static void
1359 cmd_run_parsed(
1360         void *parsed_result,
1361         struct cmdline *cl,
1362         __attribute__((unused)) void *data)
1363 {
1364         struct cmd_run_result *params = parsed_result;
1365
1366         char *tokens[16];
1367         uint32_t n_tokens = RTE_DIM(tokens);
1368         int status;
1369
1370         char *file_name;
1371         uint32_t count, interval, i;
1372
1373         status = parse_tokenize_string(params->multi_string, tokens, &n_tokens);
1374         if (status) {
1375                 printf(CMD_MSG_TOO_MANY_ARGS, "run");
1376                 return;
1377         }
1378
1379         switch (n_tokens) {
1380         case 0:
1381                 printf(CMD_MSG_NOT_ENOUGH_ARGS, "run");
1382                 return;
1383
1384         case 1:
1385                 file_name = tokens[0];
1386                 count = 1;
1387                 interval = 1000;
1388                 break;
1389
1390         case 2:
1391                 file_name = tokens[0];
1392
1393                 if (parser_read_uint32(&count, tokens[1]) ||
1394                         (count == 0)) {
1395                         printf(CMD_MSG_INVALID_ARG, "count");
1396                         return;
1397                 }
1398
1399                 interval = 1000;
1400                 break;
1401
1402         case 3:
1403                 file_name = tokens[0];
1404
1405                 if (parser_read_uint32(&count, tokens[1]) ||
1406                         (count == 0)) {
1407                         printf(CMD_MSG_INVALID_ARG, "count");
1408                         return;
1409                 }
1410
1411                 if (parser_read_uint32(&interval, tokens[2]) ||
1412                         (interval == 0)) {
1413                         printf(CMD_MSG_INVALID_ARG, "interval");
1414                         return;
1415                 }
1416                 break;
1417
1418         default:
1419                 printf(CMD_MSG_MISMATCH_ARGS, "run");
1420                 return;
1421         }
1422
1423         for (i = 0; i < count; i++) {
1424                 app_run_file(cl->ctx, file_name);
1425                 if (interval)
1426                         usleep(interval * 1000);
1427         }
1428 }
1429
1430 static cmdline_parse_token_string_t cmd_run_run_string =
1431         TOKEN_STRING_INITIALIZER(struct cmd_run_result, run_string, "run");
1432
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);
1436
1437
1438 static cmdline_parse_inst_t cmd_run = {
1439         .f = cmd_run_parsed,
1440         .data = NULL,
1441         .help_str = "Run CLI script file",
1442         .tokens = {
1443                 (void *) &cmd_run_run_string,
1444                 (void *) &cmd_run_multi_string,
1445                 NULL,
1446         },
1447 };
1448
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,
1459         NULL,
1460 };
1461
1462 int
1463 app_pipeline_common_cmd_push(struct app_params *app)
1464 {
1465         uint32_t n_cmds, i;
1466
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)
1470                 return -ENOMEM;
1471
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));
1476
1477         for (i = 0; i < n_cmds; i++)
1478                 app->cmds[app->n_cmds + i]->data = app;
1479
1480         app->n_cmds += n_cmds;
1481         app->cmds[app->n_cmds] = NULL;
1482
1483         return 0;
1484 }