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