DPDK logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2010-2014 Intel Corporation
 */

#include <stdio.h>
#include <termios.h>
#include <inttypes.h>
#include <string.h>

#include <cmdline_rdline.h>
#include <cmdline_parse.h>
#include <cmdline_parse_num.h>
#include <cmdline_parse_string.h>
#include <cmdline_socket.h>
#include <cmdline.h>

#include "main.h"

/* *** Help command with introduction. *** */
struct cmd_help_result {
	cmdline_fixed_string_t help;
};

static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
                                  struct cmdline *cl,
                                  __attribute__((unused)) void *data)
{
	cmdline_printf(
		cl,
		"\n"
		"The following commands are currently available:\n\n"
		"Control:\n"
		"    quit                                      : Quit the application.\n"
		"\nStatistics:\n"
		"    stats app                                 : Show app statistics.\n"
		"    stats port X subport Y                    : Show stats of a specific subport.\n"
		"    stats port X subport Y pipe Z             : Show stats of a specific pipe.\n"
		"\nAverage queue size:\n"
		"    qavg port X subport Y                     : Show average queue size per subport.\n"
		"    qavg port X subport Y tc Z                : Show average queue size per subport and TC.\n"
		"    qavg port X subport Y pipe Z              : Show average queue size per pipe.\n"
		"    qavg port X subport Y pipe Z tc A         : Show average queue size per pipe and TC.\n"
		"    qavg port X subport Y pipe Z tc A q B     : Show average queue size of a specific queue.\n"
		"    qavg [n|period] X                     : Set number of times and peiod (us).\n\n"
	);

}

cmdline_parse_token_string_t cmd_help_help =
	TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");

cmdline_parse_inst_t cmd_help = {
	.f = cmd_help_parsed,
	.data = NULL,
	.help_str = "show help",
	.tokens = {
		(void *)&cmd_help_help,
		NULL,
	},
};

/* *** QUIT *** */
struct cmd_quit_result {
	cmdline_fixed_string_t quit;
};

static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
		struct cmdline *cl,
		__attribute__((unused)) void *data)
{
	cmdline_quit(cl);
}

cmdline_parse_token_string_t cmd_quit_quit =
		TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");

cmdline_parse_inst_t cmd_quit = {
	.f = cmd_quit_parsed,
	.data = NULL,
	.help_str = "exit application",
	.tokens = {
		(void *)&cmd_quit_quit,
		NULL,
		},
};

/* *** SET QAVG PARAMETERS *** */
struct cmd_setqavg_result {
        cmdline_fixed_string_t qavg_string;
        cmdline_fixed_string_t param_string;
        uint32_t number;
};

static void cmd_setqavg_parsed(void *parsed_result,
                                __attribute__((unused)) struct cmdline *cl,
                                __attribute__((unused)) void *data)
{
        struct cmd_setqavg_result *res = parsed_result;

	if (!strcmp(res->param_string, "period"))
		qavg_period = res->number;
	else if (!strcmp(res->param_string, "n"))
		qavg_ntimes = res->number;
	else
		printf("\nUnknown parameter.\n\n");
}

cmdline_parse_token_string_t cmd_setqavg_qavg_string =
        TOKEN_STRING_INITIALIZER(struct cmd_setqavg_result, qavg_string,
                                "qavg");
cmdline_parse_token_string_t cmd_setqavg_param_string =
        TOKEN_STRING_INITIALIZER(struct cmd_setqavg_result, param_string,
                                "period#n");
cmdline_parse_token_num_t cmd_setqavg_number =
        TOKEN_NUM_INITIALIZER(struct cmd_setqavg_result, number,
                                UINT32);

cmdline_parse_inst_t cmd_setqavg = {
        .f = cmd_setqavg_parsed,
        .data = NULL,
        .help_str = "Show subport stats.",
        .tokens = {
                (void *)&cmd_setqavg_qavg_string,
                (void *)&cmd_setqavg_param_string,
                (void *)&cmd_setqavg_number,
                NULL,
        },
};

/* *** SHOW APP STATS *** */
struct cmd_appstats_result {
	cmdline_fixed_string_t stats_string;
	cmdline_fixed_string_t app_string;
};

static void cmd_appstats_parsed(__attribute__((unused)) void *parsed_result,
				__attribute__((unused)) struct cmdline *cl,
				__attribute__((unused)) void *data)
{
	app_stat();
}

cmdline_parse_token_string_t cmd_appstats_stats_string =
	TOKEN_STRING_INITIALIZER(struct cmd_appstats_result, stats_string,
				"stats");
cmdline_parse_token_string_t cmd_appstats_app_string =
	TOKEN_STRING_INITIALIZER(struct cmd_appstats_result, app_string,
				"app");

cmdline_parse_inst_t cmd_appstats = {
	.f = cmd_appstats_parsed,
	.data = NULL,
	.help_str = "Show app stats.",
	.tokens = {
		(void *)&cmd_appstats_stats_string,
		(void *)&cmd_appstats_app_string,
		NULL,
	},
};

/* *** SHOW SUBPORT STATS *** */
struct cmd_subportstats_result {
        cmdline_fixed_string_t stats_string;
        cmdline_fixed_string_t port_string;
	uint16_t port_number;
        cmdline_fixed_string_t subport_string;
        uint32_t subport_number;
};

static void cmd_subportstats_parsed(void *parsed_result,
                                __attribute__((unused)) struct cmdline *cl,
                                __attribute__((unused)) void *data)
{
	struct cmd_subportstats_result *res = parsed_result;

	if (subport_stat(res->port_number, res->subport_number) < 0)
		printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
}

cmdline_parse_token_string_t cmd_subportstats_stats_string =
        TOKEN_STRING_INITIALIZER(struct cmd_subportstats_result, stats_string,
                                "stats");
cmdline_parse_token_string_t cmd_subportstats_port_string =
        TOKEN_STRING_INITIALIZER(struct cmd_subportstats_result, port_string,
                                "port");
cmdline_parse_token_string_t cmd_subportstats_subport_string =
        TOKEN_STRING_INITIALIZER(struct cmd_subportstats_result, subport_string,
                                "subport");
cmdline_parse_token_num_t cmd_subportstats_subport_number =
        TOKEN_NUM_INITIALIZER(struct cmd_subportstats_result, subport_number,
                                UINT32);
cmdline_parse_token_num_t cmd_subportstats_port_number =
        TOKEN_NUM_INITIALIZER(struct cmd_subportstats_result, port_number,
			       UINT16);

cmdline_parse_inst_t cmd_subportstats = {
        .f = cmd_subportstats_parsed,
        .data = NULL,
        .help_str = "Show subport stats.",
        .tokens = {
                (void *)&cmd_subportstats_stats_string,
                (void *)&cmd_subportstats_port_string,
                (void *)&cmd_subportstats_port_number,
                (void *)&cmd_subportstats_subport_string,
                (void *)&cmd_subportstats_subport_number,
                NULL,
        },
};

/* *** SHOW PIPE STATS *** */
struct cmd_pipestats_result {
        cmdline_fixed_string_t stats_string;
        cmdline_fixed_string_t port_string;
	uint16_t port_number;
        cmdline_fixed_string_t subport_string;
        uint32_t subport_number;
        cmdline_fixed_string_t pipe_string;
        uint32_t pipe_number;
};

static void cmd_pipestats_parsed(void *parsed_result,
                                __attribute__((unused)) struct cmdline *cl,
                                __attribute__((unused)) void *data)
{
        struct cmd_pipestats_result *res = parsed_result;

        if (pipe_stat(res->port_number, res->subport_number, res->pipe_number) < 0)
                printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
}

cmdline_parse_token_string_t cmd_pipestats_stats_string =
        TOKEN_STRING_INITIALIZER(struct cmd_pipestats_result, stats_string,
                                "stats");
cmdline_parse_token_string_t cmd_pipestats_port_string =
        TOKEN_STRING_INITIALIZER(struct cmd_pipestats_result, port_string,
                                "port");
cmdline_parse_token_num_t cmd_pipestats_port_number =
        TOKEN_NUM_INITIALIZER(struct cmd_pipestats_result, port_number,
			       UINT16);
cmdline_parse_token_string_t cmd_pipestats_subport_string =
        TOKEN_STRING_INITIALIZER(struct cmd_pipestats_result, subport_string,
                                "subport");
cmdline_parse_token_num_t cmd_pipestats_subport_number =
        TOKEN_NUM_INITIALIZER(struct cmd_pipestats_result, subport_number,
                                UINT32);
cmdline_parse_token_string_t cmd_pipestats_pipe_string =
        TOKEN_STRING_INITIALIZER(struct cmd_pipestats_result, pipe_string,
                                "pipe");
cmdline_parse_token_num_t cmd_pipestats_pipe_number =
        TOKEN_NUM_INITIALIZER(struct cmd_pipestats_result, pipe_number,
                                UINT32);

cmdline_parse_inst_t cmd_pipestats = {
        .f = cmd_pipestats_parsed,
        .data = NULL,
        .help_str = "Show pipe stats.",
        .tokens = {
                (void *)&cmd_pipestats_stats_string,
                (void *)&cmd_pipestats_port_string,
                (void *)&cmd_pipestats_port_number,
                (void *)&cmd_pipestats_subport_string,
                (void *)&cmd_pipestats_subport_number,
                (void *)&cmd_pipestats_pipe_string,
                (void *)&cmd_pipestats_pipe_number,
                NULL,
        },
};

/* *** SHOW AVERAGE QUEUE SIZE (QUEUE) *** */
struct cmd_avg_q_result {
        cmdline_fixed_string_t qavg_string;
        cmdline_fixed_string_t port_string;
	uint16_t port_number;
        cmdline_fixed_string_t subport_string;
        uint32_t subport_number;
        cmdline_fixed_string_t pipe_string;
        uint32_t pipe_number;
        cmdline_fixed_string_t tc_string;
        uint8_t tc_number;
        cmdline_fixed_string_t q_string;
        uint8_t q_number;
};

static void cmd_avg_q_parsed(void *parsed_result,
                                __attribute__((unused)) struct cmdline *cl,
                                __attribute__((unused)) void *data)
{
        struct cmd_avg_q_result *res = parsed_result;

        if (qavg_q(res->port_number, res->subport_number, res->pipe_number, res->tc_number, res->q_number) < 0)
                printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
}

cmdline_parse_token_string_t cmd_avg_q_qavg_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, qavg_string,
                                "qavg");
cmdline_parse_token_string_t cmd_avg_q_port_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, port_string,
                                "port");
cmdline_parse_token_num_t cmd_avg_q_port_number =
	TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, port_number,
			       UINT16);
cmdline_parse_token_string_t cmd_avg_q_subport_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, subport_string,
                                "subport");
cmdline_parse_token_num_t cmd_avg_q_subport_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, subport_number,
                                UINT32);
cmdline_parse_token_string_t cmd_avg_q_pipe_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, pipe_string,
                                "pipe");
cmdline_parse_token_num_t cmd_avg_q_pipe_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, pipe_number,
                                UINT32);
cmdline_parse_token_string_t cmd_avg_q_tc_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, tc_string,
                                "tc");
cmdline_parse_token_num_t cmd_avg_q_tc_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, tc_number,
                                UINT8);
cmdline_parse_token_string_t cmd_avg_q_q_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, q_string,
                                "q");
cmdline_parse_token_num_t cmd_avg_q_q_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, q_number,
                                UINT8);

cmdline_parse_inst_t cmd_avg_q = {
        .f = cmd_avg_q_parsed,
        .data = NULL,
        .help_str = "Show pipe stats.",
        .tokens = {
                (void *)&cmd_avg_q_qavg_string,
                (void *)&cmd_avg_q_port_string,
                (void *)&cmd_avg_q_port_number,
                (void *)&cmd_avg_q_subport_string,
                (void *)&cmd_avg_q_subport_number,
                (void *)&cmd_avg_q_pipe_string,
                (void *)&cmd_avg_q_pipe_number,
                (void *)&cmd_avg_q_tc_string,
                (void *)&cmd_avg_q_tc_number,
                (void *)&cmd_avg_q_q_string,
                (void *)&cmd_avg_q_q_number,
                NULL,
        },
};

/* *** SHOW AVERAGE QUEUE SIZE (tc/pipe) *** */
struct cmd_avg_tcpipe_result {
        cmdline_fixed_string_t qavg_string;
        cmdline_fixed_string_t port_string;
	uint16_t port_number;
        cmdline_fixed_string_t subport_string;
        uint32_t subport_number;
        cmdline_fixed_string_t pipe_string;
        uint32_t pipe_number;
        cmdline_fixed_string_t tc_string;
        uint8_t tc_number;
};

static void cmd_avg_tcpipe_parsed(void *parsed_result,
                                __attribute__((unused)) struct cmdline *cl,
                                __attribute__((unused)) void *data)
{
        struct cmd_avg_tcpipe_result *res = parsed_result;

        if (qavg_tcpipe(res->port_number, res->subport_number, res->pipe_number, res->tc_number) < 0)
                printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
}

cmdline_parse_token_string_t cmd_avg_tcpipe_qavg_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, qavg_string,
                                "qavg");
cmdline_parse_token_string_t cmd_avg_tcpipe_port_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, port_string,
                                "port");
cmdline_parse_token_num_t cmd_avg_tcpipe_port_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_tcpipe_result, port_number,
			       UINT16);
cmdline_parse_token_string_t cmd_avg_tcpipe_subport_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, subport_string,
                                "subport");
cmdline_parse_token_num_t cmd_avg_tcpipe_subport_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_tcpipe_result, subport_number,
                                UINT32);
cmdline_parse_token_string_t cmd_avg_tcpipe_pipe_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, pipe_string,
                                "pipe");
cmdline_parse_token_num_t cmd_avg_tcpipe_pipe_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_tcpipe_result, pipe_number,
                                UINT32);
cmdline_parse_token_string_t cmd_avg_tcpipe_tc_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, tc_string,
                                "tc");
cmdline_parse_token_num_t cmd_avg_tcpipe_tc_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_tcpipe_result, tc_number,
                                UINT8);

cmdline_parse_inst_t cmd_avg_tcpipe = {
        .f = cmd_avg_tcpipe_parsed,
        .data = NULL,
        .help_str = "Show pipe stats.",
        .tokens = {
                (void *)&cmd_avg_tcpipe_qavg_string,
                (void *)&cmd_avg_tcpipe_port_string,
                (void *)&cmd_avg_tcpipe_port_number,
                (void *)&cmd_avg_tcpipe_subport_string,
                (void *)&cmd_avg_tcpipe_subport_number,
                (void *)&cmd_avg_tcpipe_pipe_string,
                (void *)&cmd_avg_tcpipe_pipe_number,
                (void *)&cmd_avg_tcpipe_tc_string,
                (void *)&cmd_avg_tcpipe_tc_number,
                NULL,
        },
};

/* *** SHOW AVERAGE QUEUE SIZE (pipe) *** */
struct cmd_avg_pipe_result {
        cmdline_fixed_string_t qavg_string;
        cmdline_fixed_string_t port_string;
	uint16_t port_number;
        cmdline_fixed_string_t subport_string;
        uint32_t subport_number;
        cmdline_fixed_string_t pipe_string;
        uint32_t pipe_number;
};

static void cmd_avg_pipe_parsed(void *parsed_result,
                                __attribute__((unused)) struct cmdline *cl,
                                __attribute__((unused)) void *data)
{
        struct cmd_avg_pipe_result *res = parsed_result;

        if (qavg_pipe(res->port_number, res->subport_number, res->pipe_number) < 0)
                printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
}

cmdline_parse_token_string_t cmd_avg_pipe_qavg_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_pipe_result, qavg_string,
                                "qavg");
cmdline_parse_token_string_t cmd_avg_pipe_port_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_pipe_result, port_string,
                                "port");
cmdline_parse_token_num_t cmd_avg_pipe_port_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_pipe_result, port_number,
			       UINT16);
cmdline_parse_token_string_t cmd_avg_pipe_subport_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_pipe_result, subport_string,
                                "subport");
cmdline_parse_token_num_t cmd_avg_pipe_subport_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_pipe_result, subport_number,
                                UINT32);
cmdline_parse_token_string_t cmd_avg_pipe_pipe_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_pipe_result, pipe_string,
                                "pipe");
cmdline_parse_token_num_t cmd_avg_pipe_pipe_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_pipe_result, pipe_number,
                                UINT32);

cmdline_parse_inst_t cmd_avg_pipe = {
        .f = cmd_avg_pipe_parsed,
        .data = NULL,
        .help_str = "Show pipe stats.",
        .tokens = {
                (void *)&cmd_avg_pipe_qavg_string,
                (void *)&cmd_avg_pipe_port_string,
                (void *)&cmd_avg_pipe_port_number,
                (void *)&cmd_avg_pipe_subport_string,
                (void *)&cmd_avg_pipe_subport_number,
                (void *)&cmd_avg_pipe_pipe_string,
                (void *)&cmd_avg_pipe_pipe_number,
                NULL,
        },
};

/* *** SHOW AVERAGE QUEUE SIZE (tc/subport) *** */
struct cmd_avg_tcsubport_result {
        cmdline_fixed_string_t qavg_string;
        cmdline_fixed_string_t port_string;
	uint16_t port_number;
        cmdline_fixed_string_t subport_string;
        uint32_t subport_number;
        cmdline_fixed_string_t tc_string;
        uint8_t tc_number;
};

static void cmd_avg_tcsubport_parsed(void *parsed_result,
                                __attribute__((unused)) struct cmdline *cl,
                                __attribute__((unused)) void *data)
{
        struct cmd_avg_tcsubport_result *res = parsed_result;

        if (qavg_tcsubport(res->port_number, res->subport_number, res->tc_number) < 0)
                printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
}

cmdline_parse_token_string_t cmd_avg_tcsubport_qavg_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_tcsubport_result, qavg_string,
                                "qavg");
cmdline_parse_token_string_t cmd_avg_tcsubport_port_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_tcsubport_result, port_string,
                                "port");
cmdline_parse_token_num_t cmd_avg_tcsubport_port_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_tcsubport_result, port_number,
			       UINT16);
cmdline_parse_token_string_t cmd_avg_tcsubport_subport_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_tcsubport_result, subport_string,
                                "subport");
cmdline_parse_token_num_t cmd_avg_tcsubport_subport_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_tcsubport_result, subport_number,
                                UINT32);
cmdline_parse_token_string_t cmd_avg_tcsubport_tc_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_tcsubport_result, tc_string,
                                "tc");
cmdline_parse_token_num_t cmd_avg_tcsubport_tc_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_tcsubport_result, tc_number,
                                UINT8);

cmdline_parse_inst_t cmd_avg_tcsubport = {
        .f = cmd_avg_tcsubport_parsed,
        .data = NULL,
        .help_str = "Show pipe stats.",
        .tokens = {
                (void *)&cmd_avg_tcsubport_qavg_string,
                (void *)&cmd_avg_tcsubport_port_string,
                (void *)&cmd_avg_tcsubport_port_number,
                (void *)&cmd_avg_tcsubport_subport_string,
                (void *)&cmd_avg_tcsubport_subport_number,
                (void *)&cmd_avg_tcsubport_tc_string,
                (void *)&cmd_avg_tcsubport_tc_number,
                NULL,
        },
};

/* *** SHOW AVERAGE QUEUE SIZE (subport) *** */
struct cmd_avg_subport_result {
        cmdline_fixed_string_t qavg_string;
        cmdline_fixed_string_t port_string;
	uint16_t port_number;
        cmdline_fixed_string_t subport_string;
        uint32_t subport_number;
};

static void cmd_avg_subport_parsed(void *parsed_result,
                                __attribute__((unused)) struct cmdline *cl,
                                __attribute__((unused)) void *data)
{
        struct cmd_avg_subport_result *res = parsed_result;

        if (qavg_subport(res->port_number, res->subport_number) < 0)
                printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
}

cmdline_parse_token_string_t cmd_avg_subport_qavg_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_subport_result, qavg_string,
                                "qavg");
cmdline_parse_token_string_t cmd_avg_subport_port_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_subport_result, port_string,
                                "port");
cmdline_parse_token_num_t cmd_avg_subport_port_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_subport_result, port_number,
			       UINT16);
cmdline_parse_token_string_t cmd_avg_subport_subport_string =
        TOKEN_STRING_INITIALIZER(struct cmd_avg_subport_result, subport_string,
                                "subport");
cmdline_parse_token_num_t cmd_avg_subport_subport_number =
        TOKEN_NUM_INITIALIZER(struct cmd_avg_subport_result, subport_number,
                                UINT32);

cmdline_parse_inst_t cmd_avg_subport = {
        .f = cmd_avg_subport_parsed,
        .data = NULL,
        .help_str = "Show pipe stats.",
        .tokens = {
                (void *)&cmd_avg_subport_qavg_string,
                (void *)&cmd_avg_subport_port_string,
                (void *)&cmd_avg_subport_port_number,
                (void *)&cmd_avg_subport_subport_string,
                (void *)&cmd_avg_subport_subport_number,
                NULL,
        },
};

/* ******************************************************************************** */

/* list of instructions */
cmdline_parse_ctx_t main_ctx[] = {
	(cmdline_parse_inst_t *)&cmd_help,
	(cmdline_parse_inst_t *)&cmd_setqavg,
	(cmdline_parse_inst_t *)&cmd_appstats,
	(cmdline_parse_inst_t *)&cmd_subportstats,
        (cmdline_parse_inst_t *)&cmd_pipestats,
	(cmdline_parse_inst_t *)&cmd_avg_q,
	(cmdline_parse_inst_t *)&cmd_avg_tcpipe,
	(cmdline_parse_inst_t *)&cmd_avg_pipe,
	(cmdline_parse_inst_t *)&cmd_avg_tcsubport,
	(cmdline_parse_inst_t *)&cmd_avg_subport,
	(cmdline_parse_inst_t *)&cmd_quit,
	NULL,
};

/* prompt function, called from main on MASTER lcore */
void
prompt(void)
{
	struct cmdline *cl;

	cl = cmdline_stdin_new(main_ctx, "qos_sched> ");
	if (cl == NULL) {
		return;
	}
	cmdline_interact(cl);
	cmdline_stdin_exit(cl);
}