ethdev: remove useless parameter in init functions
[dpdk.git] / examples / qos_sched / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 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 <termios.h>
36 #include <inttypes.h>
37 #include <string.h>
38
39 #include <cmdline_rdline.h>
40 #include <cmdline_parse.h>
41 #include <cmdline_parse_num.h>
42 #include <cmdline_parse_string.h>
43 #include <cmdline_socket.h>
44 #include <cmdline.h>
45
46 #include "main.h"
47
48 /* *** Help command with introduction. *** */
49 struct cmd_help_result {
50         cmdline_fixed_string_t help;
51 };
52
53 static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
54                                   struct cmdline *cl,
55                                   __attribute__((unused)) void *data)
56 {
57         cmdline_printf(
58                 cl,
59                 "\n"
60                 "The following commands are currently available:\n\n"
61                 "Control:\n"
62                 "    quit                                      : Quit the application.\n"
63                 "\nStatistics:\n"
64                 "    stats app                                 : Show app statistics.\n"
65                 "    stats port X subport Y                    : Show stats of a specific subport.\n"
66                 "    stats port X subport Y pipe Z             : Show stats of a specific pipe.\n"
67                 "\nAverage queue size:\n"
68                 "    qavg port X subport Y                     : Show average queue size per subport.\n"
69                 "    qavg port X subport Y tc Z                : Show average queue size per subport and TC.\n"
70                 "    qavg port X subport Y pipe Z              : Show average queue size per pipe.\n"
71                 "    qavg port X subport Y pipe Z tc A         : Show average queue size per pipe and TC.\n"
72                 "    qavg port X subport Y pipe Z tc A q B     : Show average queue size of a specific queue.\n"
73                 "    qavg [n|period] X                     : Set number of times and peiod (us).\n\n"
74         );
75
76 }
77
78 cmdline_parse_token_string_t cmd_help_help =
79         TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");
80
81 cmdline_parse_inst_t cmd_help = {
82         .f = cmd_help_parsed,
83         .data = NULL,
84         .help_str = "show help",
85         .tokens = {
86                 (void *)&cmd_help_help,
87                 NULL,
88         },
89 };
90
91 /* *** QUIT *** */
92 struct cmd_quit_result {
93         cmdline_fixed_string_t quit;
94 };
95
96 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
97                 struct cmdline *cl,
98                 __attribute__((unused)) void *data)
99 {
100         cmdline_quit(cl);
101 }
102
103 cmdline_parse_token_string_t cmd_quit_quit =
104                 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
105
106 cmdline_parse_inst_t cmd_quit = {
107         .f = cmd_quit_parsed,
108         .data = NULL,
109         .help_str = "exit application",
110         .tokens = {
111                 (void *)&cmd_quit_quit,
112                 NULL,
113                 },
114 };
115
116 /* *** SET QAVG PARAMETERS *** */
117 struct cmd_setqavg_result {
118         cmdline_fixed_string_t qavg_string;
119         cmdline_fixed_string_t param_string;
120         uint32_t number;
121 };
122
123 static void cmd_setqavg_parsed(void *parsed_result,
124                                 __attribute__((unused)) struct cmdline *cl,
125                                 __attribute__((unused)) void *data)
126 {
127         struct cmd_setqavg_result *res = parsed_result;
128
129         if (!strcmp(res->param_string, "period"))
130                 qavg_period = res->number;
131         else if (!strcmp(res->param_string, "n"))
132                 qavg_ntimes = res->number;
133         else
134                 printf("\nUnknown parameter.\n\n");
135 }
136
137 cmdline_parse_token_string_t cmd_setqavg_qavg_string =
138         TOKEN_STRING_INITIALIZER(struct cmd_setqavg_result, qavg_string,
139                                 "qavg");
140 cmdline_parse_token_string_t cmd_setqavg_param_string =
141         TOKEN_STRING_INITIALIZER(struct cmd_setqavg_result, param_string,
142                                 "period#n");
143 cmdline_parse_token_num_t cmd_setqavg_number =
144         TOKEN_NUM_INITIALIZER(struct cmd_setqavg_result, number,
145                                 UINT32);
146
147 cmdline_parse_inst_t cmd_setqavg = {
148         .f = cmd_setqavg_parsed,
149         .data = NULL,
150         .help_str = "Show subport stats.",
151         .tokens = {
152                 (void *)&cmd_setqavg_qavg_string,
153                 (void *)&cmd_setqavg_param_string,
154                 (void *)&cmd_setqavg_number,
155                 NULL,
156         },
157 };
158
159 /* *** SHOW APP STATS *** */
160 struct cmd_appstats_result {
161         cmdline_fixed_string_t stats_string;
162         cmdline_fixed_string_t app_string;
163 };
164
165 static void cmd_appstats_parsed(__attribute__((unused)) void *parsed_result,
166                                 __attribute__((unused)) struct cmdline *cl,
167                                 __attribute__((unused)) void *data)
168 {
169         app_stat();
170 }
171
172 cmdline_parse_token_string_t cmd_appstats_stats_string =
173         TOKEN_STRING_INITIALIZER(struct cmd_appstats_result, stats_string,
174                                 "stats");
175 cmdline_parse_token_string_t cmd_appstats_app_string =
176         TOKEN_STRING_INITIALIZER(struct cmd_appstats_result, app_string,
177                                 "app");
178
179 cmdline_parse_inst_t cmd_appstats = {
180         .f = cmd_appstats_parsed,
181         .data = NULL,
182         .help_str = "Show app stats.",
183         .tokens = {
184                 (void *)&cmd_appstats_stats_string,
185                 (void *)&cmd_appstats_app_string,
186                 NULL,
187         },
188 };
189
190 /* *** SHOW SUBPORT STATS *** */
191 struct cmd_subportstats_result {
192         cmdline_fixed_string_t stats_string;
193         cmdline_fixed_string_t port_string;
194         uint8_t port_number;
195         cmdline_fixed_string_t subport_string;
196         uint32_t subport_number;
197 };
198
199 static void cmd_subportstats_parsed(void *parsed_result,
200                                 __attribute__((unused)) struct cmdline *cl,
201                                 __attribute__((unused)) void *data)
202 {
203         struct cmd_subportstats_result *res = parsed_result;
204
205         if (subport_stat(res->port_number, res->subport_number) < 0)
206                 printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
207 }
208
209 cmdline_parse_token_string_t cmd_subportstats_stats_string =
210         TOKEN_STRING_INITIALIZER(struct cmd_subportstats_result, stats_string,
211                                 "stats");
212 cmdline_parse_token_string_t cmd_subportstats_port_string =
213         TOKEN_STRING_INITIALIZER(struct cmd_subportstats_result, port_string,
214                                 "port");
215 cmdline_parse_token_string_t cmd_subportstats_subport_string =
216         TOKEN_STRING_INITIALIZER(struct cmd_subportstats_result, subport_string,
217                                 "subport");
218 cmdline_parse_token_num_t cmd_subportstats_subport_number =
219         TOKEN_NUM_INITIALIZER(struct cmd_subportstats_result, subport_number,
220                                 UINT32);
221 cmdline_parse_token_num_t cmd_subportstats_port_number =
222         TOKEN_NUM_INITIALIZER(struct cmd_subportstats_result, port_number,
223                                 UINT8);
224
225 cmdline_parse_inst_t cmd_subportstats = {
226         .f = cmd_subportstats_parsed,
227         .data = NULL,
228         .help_str = "Show subport stats.",
229         .tokens = {
230                 (void *)&cmd_subportstats_stats_string,
231                 (void *)&cmd_subportstats_port_string,
232                 (void *)&cmd_subportstats_port_number,
233                 (void *)&cmd_subportstats_subport_string,
234                 (void *)&cmd_subportstats_subport_number,
235                 NULL,
236         },
237 };
238
239 /* *** SHOW PIPE STATS *** */
240 struct cmd_pipestats_result {
241         cmdline_fixed_string_t stats_string;
242         cmdline_fixed_string_t port_string;
243         uint8_t port_number;
244         cmdline_fixed_string_t subport_string;
245         uint32_t subport_number;
246         cmdline_fixed_string_t pipe_string;
247         uint32_t pipe_number;
248 };
249
250 static void cmd_pipestats_parsed(void *parsed_result,
251                                 __attribute__((unused)) struct cmdline *cl,
252                                 __attribute__((unused)) void *data)
253 {
254         struct cmd_pipestats_result *res = parsed_result;
255
256         if (pipe_stat(res->port_number, res->subport_number, res->pipe_number) < 0)
257                 printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
258 }
259
260 cmdline_parse_token_string_t cmd_pipestats_stats_string =
261         TOKEN_STRING_INITIALIZER(struct cmd_pipestats_result, stats_string,
262                                 "stats");
263 cmdline_parse_token_string_t cmd_pipestats_port_string =
264         TOKEN_STRING_INITIALIZER(struct cmd_pipestats_result, port_string,
265                                 "port");
266 cmdline_parse_token_num_t cmd_pipestats_port_number =
267         TOKEN_NUM_INITIALIZER(struct cmd_pipestats_result, port_number,
268                                 UINT8);
269 cmdline_parse_token_string_t cmd_pipestats_subport_string =
270         TOKEN_STRING_INITIALIZER(struct cmd_pipestats_result, subport_string,
271                                 "subport");
272 cmdline_parse_token_num_t cmd_pipestats_subport_number =
273         TOKEN_NUM_INITIALIZER(struct cmd_pipestats_result, subport_number,
274                                 UINT32);
275 cmdline_parse_token_string_t cmd_pipestats_pipe_string =
276         TOKEN_STRING_INITIALIZER(struct cmd_pipestats_result, pipe_string,
277                                 "pipe");
278 cmdline_parse_token_num_t cmd_pipestats_pipe_number =
279         TOKEN_NUM_INITIALIZER(struct cmd_pipestats_result, pipe_number,
280                                 UINT32);
281
282 cmdline_parse_inst_t cmd_pipestats = {
283         .f = cmd_pipestats_parsed,
284         .data = NULL,
285         .help_str = "Show pipe stats.",
286         .tokens = {
287                 (void *)&cmd_pipestats_stats_string,
288                 (void *)&cmd_pipestats_port_string,
289                 (void *)&cmd_pipestats_port_number,
290                 (void *)&cmd_pipestats_subport_string,
291                 (void *)&cmd_pipestats_subport_number,
292                 (void *)&cmd_pipestats_pipe_string,
293                 (void *)&cmd_pipestats_pipe_number,
294                 NULL,
295         },
296 };
297
298 /* *** SHOW AVERAGE QUEUE SIZE (QUEUE) *** */
299 struct cmd_avg_q_result {
300         cmdline_fixed_string_t qavg_string;
301         cmdline_fixed_string_t port_string;
302         uint8_t port_number;
303         cmdline_fixed_string_t subport_string;
304         uint32_t subport_number;
305         cmdline_fixed_string_t pipe_string;
306         uint32_t pipe_number;
307         cmdline_fixed_string_t tc_string;
308         uint8_t tc_number;
309         cmdline_fixed_string_t q_string;
310         uint8_t q_number;
311 };
312
313 static void cmd_avg_q_parsed(void *parsed_result,
314                                 __attribute__((unused)) struct cmdline *cl,
315                                 __attribute__((unused)) void *data)
316 {
317         struct cmd_avg_q_result *res = parsed_result;
318
319         if (qavg_q(res->port_number, res->subport_number, res->pipe_number, res->tc_number, res->q_number) < 0)
320                 printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
321 }
322
323 cmdline_parse_token_string_t cmd_avg_q_qavg_string =
324         TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, qavg_string,
325                                 "qavg");
326 cmdline_parse_token_string_t cmd_avg_q_port_string =
327         TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, port_string,
328                                 "port");
329 cmdline_parse_token_num_t cmd_avg_q_port_number =
330         TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, port_number,
331                                 UINT8);
332 cmdline_parse_token_string_t cmd_avg_q_subport_string =
333         TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, subport_string,
334                                 "subport");
335 cmdline_parse_token_num_t cmd_avg_q_subport_number =
336         TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, subport_number,
337                                 UINT32);
338 cmdline_parse_token_string_t cmd_avg_q_pipe_string =
339         TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, pipe_string,
340                                 "pipe");
341 cmdline_parse_token_num_t cmd_avg_q_pipe_number =
342         TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, pipe_number,
343                                 UINT32);
344 cmdline_parse_token_string_t cmd_avg_q_tc_string =
345         TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, tc_string,
346                                 "tc");
347 cmdline_parse_token_num_t cmd_avg_q_tc_number =
348         TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, tc_number,
349                                 UINT8);
350 cmdline_parse_token_string_t cmd_avg_q_q_string =
351         TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, q_string,
352                                 "q");
353 cmdline_parse_token_num_t cmd_avg_q_q_number =
354         TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, q_number,
355                                 UINT8);
356
357 cmdline_parse_inst_t cmd_avg_q = {
358         .f = cmd_avg_q_parsed,
359         .data = NULL,
360         .help_str = "Show pipe stats.",
361         .tokens = {
362                 (void *)&cmd_avg_q_qavg_string,
363                 (void *)&cmd_avg_q_port_string,
364                 (void *)&cmd_avg_q_port_number,
365                 (void *)&cmd_avg_q_subport_string,
366                 (void *)&cmd_avg_q_subport_number,
367                 (void *)&cmd_avg_q_pipe_string,
368                 (void *)&cmd_avg_q_pipe_number,
369                 (void *)&cmd_avg_q_tc_string,
370                 (void *)&cmd_avg_q_tc_number,
371                 (void *)&cmd_avg_q_q_string,
372                 (void *)&cmd_avg_q_q_number,
373                 NULL,
374         },
375 };
376
377 /* *** SHOW AVERAGE QUEUE SIZE (tc/pipe) *** */
378 struct cmd_avg_tcpipe_result {
379         cmdline_fixed_string_t qavg_string;
380         cmdline_fixed_string_t port_string;
381         uint8_t port_number;
382         cmdline_fixed_string_t subport_string;
383         uint32_t subport_number;
384         cmdline_fixed_string_t pipe_string;
385         uint32_t pipe_number;
386         cmdline_fixed_string_t tc_string;
387         uint8_t tc_number;
388 };
389
390 static void cmd_avg_tcpipe_parsed(void *parsed_result,
391                                 __attribute__((unused)) struct cmdline *cl,
392                                 __attribute__((unused)) void *data)
393 {
394         struct cmd_avg_tcpipe_result *res = parsed_result;
395
396         if (qavg_tcpipe(res->port_number, res->subport_number, res->pipe_number, res->tc_number) < 0)
397                 printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
398 }
399
400 cmdline_parse_token_string_t cmd_avg_tcpipe_qavg_string =
401         TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, qavg_string,
402                                 "qavg");
403 cmdline_parse_token_string_t cmd_avg_tcpipe_port_string =
404         TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, port_string,
405                                 "port");
406 cmdline_parse_token_num_t cmd_avg_tcpipe_port_number =
407         TOKEN_NUM_INITIALIZER(struct cmd_avg_tcpipe_result, port_number,
408                                 UINT8);
409 cmdline_parse_token_string_t cmd_avg_tcpipe_subport_string =
410         TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, subport_string,
411                                 "subport");
412 cmdline_parse_token_num_t cmd_avg_tcpipe_subport_number =
413         TOKEN_NUM_INITIALIZER(struct cmd_avg_tcpipe_result, subport_number,
414                                 UINT32);
415 cmdline_parse_token_string_t cmd_avg_tcpipe_pipe_string =
416         TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, pipe_string,
417                                 "pipe");
418 cmdline_parse_token_num_t cmd_avg_tcpipe_pipe_number =
419         TOKEN_NUM_INITIALIZER(struct cmd_avg_tcpipe_result, pipe_number,
420                                 UINT32);
421 cmdline_parse_token_string_t cmd_avg_tcpipe_tc_string =
422         TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, tc_string,
423                                 "tc");
424 cmdline_parse_token_num_t cmd_avg_tcpipe_tc_number =
425         TOKEN_NUM_INITIALIZER(struct cmd_avg_tcpipe_result, tc_number,
426                                 UINT8);
427
428 cmdline_parse_inst_t cmd_avg_tcpipe = {
429         .f = cmd_avg_tcpipe_parsed,
430         .data = NULL,
431         .help_str = "Show pipe stats.",
432         .tokens = {
433                 (void *)&cmd_avg_tcpipe_qavg_string,
434                 (void *)&cmd_avg_tcpipe_port_string,
435                 (void *)&cmd_avg_tcpipe_port_number,
436                 (void *)&cmd_avg_tcpipe_subport_string,
437                 (void *)&cmd_avg_tcpipe_subport_number,
438                 (void *)&cmd_avg_tcpipe_pipe_string,
439                 (void *)&cmd_avg_tcpipe_pipe_number,
440                 (void *)&cmd_avg_tcpipe_tc_string,
441                 (void *)&cmd_avg_tcpipe_tc_number,
442                 NULL,
443         },
444 };
445
446 /* *** SHOW AVERAGE QUEUE SIZE (pipe) *** */
447 struct cmd_avg_pipe_result {
448         cmdline_fixed_string_t qavg_string;
449         cmdline_fixed_string_t port_string;
450         uint8_t port_number;
451         cmdline_fixed_string_t subport_string;
452         uint32_t subport_number;
453         cmdline_fixed_string_t pipe_string;
454         uint32_t pipe_number;
455 };
456
457 static void cmd_avg_pipe_parsed(void *parsed_result,
458                                 __attribute__((unused)) struct cmdline *cl,
459                                 __attribute__((unused)) void *data)
460 {
461         struct cmd_avg_pipe_result *res = parsed_result;
462
463         if (qavg_pipe(res->port_number, res->subport_number, res->pipe_number) < 0)
464                 printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
465 }
466
467 cmdline_parse_token_string_t cmd_avg_pipe_qavg_string =
468         TOKEN_STRING_INITIALIZER(struct cmd_avg_pipe_result, qavg_string,
469                                 "qavg");
470 cmdline_parse_token_string_t cmd_avg_pipe_port_string =
471         TOKEN_STRING_INITIALIZER(struct cmd_avg_pipe_result, port_string,
472                                 "port");
473 cmdline_parse_token_num_t cmd_avg_pipe_port_number =
474         TOKEN_NUM_INITIALIZER(struct cmd_avg_pipe_result, port_number,
475                                 UINT8);
476 cmdline_parse_token_string_t cmd_avg_pipe_subport_string =
477         TOKEN_STRING_INITIALIZER(struct cmd_avg_pipe_result, subport_string,
478                                 "subport");
479 cmdline_parse_token_num_t cmd_avg_pipe_subport_number =
480         TOKEN_NUM_INITIALIZER(struct cmd_avg_pipe_result, subport_number,
481                                 UINT32);
482 cmdline_parse_token_string_t cmd_avg_pipe_pipe_string =
483         TOKEN_STRING_INITIALIZER(struct cmd_avg_pipe_result, pipe_string,
484                                 "pipe");
485 cmdline_parse_token_num_t cmd_avg_pipe_pipe_number =
486         TOKEN_NUM_INITIALIZER(struct cmd_avg_pipe_result, pipe_number,
487                                 UINT32);
488
489 cmdline_parse_inst_t cmd_avg_pipe = {
490         .f = cmd_avg_pipe_parsed,
491         .data = NULL,
492         .help_str = "Show pipe stats.",
493         .tokens = {
494                 (void *)&cmd_avg_pipe_qavg_string,
495                 (void *)&cmd_avg_pipe_port_string,
496                 (void *)&cmd_avg_pipe_port_number,
497                 (void *)&cmd_avg_pipe_subport_string,
498                 (void *)&cmd_avg_pipe_subport_number,
499                 (void *)&cmd_avg_pipe_pipe_string,
500                 (void *)&cmd_avg_pipe_pipe_number,
501                 NULL,
502         },
503 };
504
505 /* *** SHOW AVERAGE QUEUE SIZE (tc/subport) *** */
506 struct cmd_avg_tcsubport_result {
507         cmdline_fixed_string_t qavg_string;
508         cmdline_fixed_string_t port_string;
509         uint8_t port_number;
510         cmdline_fixed_string_t subport_string;
511         uint32_t subport_number;
512         cmdline_fixed_string_t tc_string;
513         uint8_t tc_number;
514 };
515
516 static void cmd_avg_tcsubport_parsed(void *parsed_result,
517                                 __attribute__((unused)) struct cmdline *cl,
518                                 __attribute__((unused)) void *data)
519 {
520         struct cmd_avg_tcsubport_result *res = parsed_result;
521
522         if (qavg_tcsubport(res->port_number, res->subport_number, res->tc_number) < 0)
523                 printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
524 }
525
526 cmdline_parse_token_string_t cmd_avg_tcsubport_qavg_string =
527         TOKEN_STRING_INITIALIZER(struct cmd_avg_tcsubport_result, qavg_string,
528                                 "qavg");
529 cmdline_parse_token_string_t cmd_avg_tcsubport_port_string =
530         TOKEN_STRING_INITIALIZER(struct cmd_avg_tcsubport_result, port_string,
531                                 "port");
532 cmdline_parse_token_num_t cmd_avg_tcsubport_port_number =
533         TOKEN_NUM_INITIALIZER(struct cmd_avg_tcsubport_result, port_number,
534                                 UINT8);
535 cmdline_parse_token_string_t cmd_avg_tcsubport_subport_string =
536         TOKEN_STRING_INITIALIZER(struct cmd_avg_tcsubport_result, subport_string,
537                                 "subport");
538 cmdline_parse_token_num_t cmd_avg_tcsubport_subport_number =
539         TOKEN_NUM_INITIALIZER(struct cmd_avg_tcsubport_result, subport_number,
540                                 UINT32);
541 cmdline_parse_token_string_t cmd_avg_tcsubport_tc_string =
542         TOKEN_STRING_INITIALIZER(struct cmd_avg_tcsubport_result, tc_string,
543                                 "tc");
544 cmdline_parse_token_num_t cmd_avg_tcsubport_tc_number =
545         TOKEN_NUM_INITIALIZER(struct cmd_avg_tcsubport_result, tc_number,
546                                 UINT8);
547
548 cmdline_parse_inst_t cmd_avg_tcsubport = {
549         .f = cmd_avg_tcsubport_parsed,
550         .data = NULL,
551         .help_str = "Show pipe stats.",
552         .tokens = {
553                 (void *)&cmd_avg_tcsubport_qavg_string,
554                 (void *)&cmd_avg_tcsubport_port_string,
555                 (void *)&cmd_avg_tcsubport_port_number,
556                 (void *)&cmd_avg_tcsubport_subport_string,
557                 (void *)&cmd_avg_tcsubport_subport_number,
558                 (void *)&cmd_avg_tcsubport_tc_string,
559                 (void *)&cmd_avg_tcsubport_tc_number,
560                 NULL,
561         },
562 };
563
564 /* *** SHOW AVERAGE QUEUE SIZE (subport) *** */
565 struct cmd_avg_subport_result {
566         cmdline_fixed_string_t qavg_string;
567         cmdline_fixed_string_t port_string;
568         uint8_t port_number;
569         cmdline_fixed_string_t subport_string;
570         uint32_t subport_number;
571 };
572
573 static void cmd_avg_subport_parsed(void *parsed_result,
574                                 __attribute__((unused)) struct cmdline *cl,
575                                 __attribute__((unused)) void *data)
576 {
577         struct cmd_avg_subport_result *res = parsed_result;
578
579         if (qavg_subport(res->port_number, res->subport_number) < 0)
580                 printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
581 }
582
583 cmdline_parse_token_string_t cmd_avg_subport_qavg_string =
584         TOKEN_STRING_INITIALIZER(struct cmd_avg_subport_result, qavg_string,
585                                 "qavg");
586 cmdline_parse_token_string_t cmd_avg_subport_port_string =
587         TOKEN_STRING_INITIALIZER(struct cmd_avg_subport_result, port_string,
588                                 "port");
589 cmdline_parse_token_num_t cmd_avg_subport_port_number =
590         TOKEN_NUM_INITIALIZER(struct cmd_avg_subport_result, port_number,
591                                 UINT8);
592 cmdline_parse_token_string_t cmd_avg_subport_subport_string =
593         TOKEN_STRING_INITIALIZER(struct cmd_avg_subport_result, subport_string,
594                                 "subport");
595 cmdline_parse_token_num_t cmd_avg_subport_subport_number =
596         TOKEN_NUM_INITIALIZER(struct cmd_avg_subport_result, subport_number,
597                                 UINT32);
598
599 cmdline_parse_inst_t cmd_avg_subport = {
600         .f = cmd_avg_subport_parsed,
601         .data = NULL,
602         .help_str = "Show pipe stats.",
603         .tokens = {
604                 (void *)&cmd_avg_subport_qavg_string,
605                 (void *)&cmd_avg_subport_port_string,
606                 (void *)&cmd_avg_subport_port_number,
607                 (void *)&cmd_avg_subport_subport_string,
608                 (void *)&cmd_avg_subport_subport_number,
609                 NULL,
610         },
611 };
612
613 /* ******************************************************************************** */
614
615 /* list of instructions */
616 cmdline_parse_ctx_t main_ctx[] = {
617         (cmdline_parse_inst_t *)&cmd_help,
618         (cmdline_parse_inst_t *)&cmd_setqavg,
619         (cmdline_parse_inst_t *)&cmd_appstats,
620         (cmdline_parse_inst_t *)&cmd_subportstats,
621         (cmdline_parse_inst_t *)&cmd_pipestats,
622         (cmdline_parse_inst_t *)&cmd_avg_q,
623         (cmdline_parse_inst_t *)&cmd_avg_tcpipe,
624         (cmdline_parse_inst_t *)&cmd_avg_pipe,
625         (cmdline_parse_inst_t *)&cmd_avg_tcsubport,
626         (cmdline_parse_inst_t *)&cmd_avg_subport,
627         (cmdline_parse_inst_t *)&cmd_quit,
628         NULL,
629 };
630
631 /* prompt function, called from main on MASTER lcore */
632 void
633 prompt(void)
634 {
635         struct cmdline *cl;
636
637         cl = cmdline_stdin_new(main_ctx, "qos_sched> ");
638         if (cl == NULL) {
639                 return;
640         }
641         cmdline_interact(cl);
642         cmdline_stdin_exit(cl);
643 }