1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
5 #include <cmdline_parse.h>
6 #include <cmdline_parse_num.h>
7 #include <cmdline_parse_string.h>
9 #include <rte_ethdev.h>
14 #include "cmdline_mtr.h"
16 #define PARSE_DELIMITER " \f\n\r\t\v"
17 #define MAX_DSCP_TABLE_ENTRIES 64
19 /** Display Meter Error Message */
21 print_err_msg(struct rte_mtr_error *error)
23 static const char *const errstrlist[] = {
24 [RTE_MTR_ERROR_TYPE_NONE] = "no error",
25 [RTE_MTR_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
26 [RTE_MTR_ERROR_TYPE_METER_PROFILE_ID] = "meter profile id",
27 [RTE_MTR_ERROR_TYPE_METER_PROFILE] = "meter profile null",
28 [RTE_MTR_ERROR_TYPE_MTR_ID] = "meter id",
29 [RTE_MTR_ERROR_TYPE_MTR_PARAMS] = "meter params null",
30 [RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN]
31 = "policer action(green)",
32 [RTE_MTR_ERROR_TYPE_POLICER_ACTION_YELLOW]
33 = "policer action(yellow)",
34 [RTE_MTR_ERROR_TYPE_POLICER_ACTION_RED]
35 = "policer action(red)",
36 [RTE_MTR_ERROR_TYPE_STATS_MASK] = "stats mask",
37 [RTE_MTR_ERROR_TYPE_STATS] = "stats",
38 [RTE_MTR_ERROR_TYPE_SHARED]
45 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
46 !errstrlist[error->type])
47 errstr = "unknown type";
49 errstr = errstrlist[error->type];
52 snprintf(buf, sizeof(buf), "cause: %p, ", error->cause);
54 printf("%s: %s%s (error %d)\n", errstr, error->cause ? buf : "",
55 error->message ? error->message : "(no stated reason)",
60 parse_uint(uint64_t *value, const char *str)
66 /* Parse number string */
67 n = strtol(str, &next, 10);
68 if (errno != 0 || str == next || *next != '\0')
77 parse_dscp_table_entries(char *str, enum rte_mtr_color *dscp_table)
82 token = strtok_r(str, PARSE_DELIMITER, &str);
86 /* Allocate memory for dscp table */
87 dscp_table = (enum rte_mtr_color *)malloc(MAX_DSCP_TABLE_ENTRIES *
88 sizeof(enum rte_mtr_color));
91 if (strcmp(token, "G") == 0 ||
92 strcmp(token, "g") == 0)
93 dscp_table[i++] = RTE_MTR_GREEN;
94 else if (strcmp(token, "Y") == 0 ||
95 strcmp(token, "y") == 0)
96 dscp_table[i++] = RTE_MTR_YELLOW;
97 else if (strcmp(token, "R") == 0 ||
98 strcmp(token, "r") == 0)
99 dscp_table[i++] = RTE_MTR_RED;
104 if (i == MAX_DSCP_TABLE_ENTRIES)
107 token = strtok_r(str, PARSE_DELIMITER, &str);
115 parse_meter_color_str(char *c_str, uint32_t *use_prev_meter_color,
116 enum rte_mtr_color *dscp_table)
119 uint64_t previous_mtr_color = 0;
122 /* First token: use previous meter color */
123 token = strtok_r(c_str, PARSE_DELIMITER, &c_str);
127 ret = parse_uint(&previous_mtr_color, token);
131 /* Check if previous meter color to be used */
132 if (previous_mtr_color) {
133 *use_prev_meter_color = previous_mtr_color;
137 /* Parse dscp table entries */
138 ret = parse_dscp_table_entries(c_str, dscp_table);
146 string_to_policer_action(char *s)
148 if ((strcmp(s, "G") == 0) || (strcmp(s, "g") == 0))
149 return MTR_POLICER_ACTION_COLOR_GREEN;
151 if ((strcmp(s, "Y") == 0) || (strcmp(s, "y") == 0))
152 return MTR_POLICER_ACTION_COLOR_YELLOW;
154 if ((strcmp(s, "R") == 0) || (strcmp(s, "r") == 0))
155 return MTR_POLICER_ACTION_COLOR_RED;
157 if ((strcmp(s, "D") == 0) || (strcmp(s, "d") == 0))
158 return MTR_POLICER_ACTION_DROP;
164 parse_policer_action_string(char *p_str, uint32_t action_mask,
165 enum rte_mtr_policer_action actions[])
168 int count = __builtin_popcount(action_mask);
169 int g_color = 0, y_color = 0, action, i;
171 for (i = 0; i < count; i++) {
172 token = strtok_r(p_str, PARSE_DELIMITER, &p_str);
176 action = string_to_policer_action(token);
180 if (g_color == 0 && (action_mask & 0x1)) {
181 actions[RTE_MTR_GREEN] = action;
183 } else if (y_color == 0 && (action_mask & 0x2)) {
184 actions[RTE_MTR_YELLOW] = action;
187 actions[RTE_MTR_RED] = action;
191 /* *** Add Port Meter Profile srtcm_rfc2697 *** */
192 struct cmd_add_port_meter_profile_srtcm_result {
193 cmdline_fixed_string_t add;
194 cmdline_fixed_string_t port;
195 cmdline_fixed_string_t meter;
196 cmdline_fixed_string_t profile;
197 cmdline_fixed_string_t srtcm_rfc2697;
205 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_add =
206 TOKEN_STRING_INITIALIZER(
207 struct cmd_add_port_meter_profile_srtcm_result, add, "add");
208 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_port =
209 TOKEN_STRING_INITIALIZER(
210 struct cmd_add_port_meter_profile_srtcm_result,
212 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_meter =
213 TOKEN_STRING_INITIALIZER(
214 struct cmd_add_port_meter_profile_srtcm_result,
216 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_profile =
217 TOKEN_STRING_INITIALIZER(
218 struct cmd_add_port_meter_profile_srtcm_result,
220 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_srtcm_rfc2697 =
221 TOKEN_STRING_INITIALIZER(
222 struct cmd_add_port_meter_profile_srtcm_result,
223 srtcm_rfc2697, "srtcm_rfc2697");
224 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_port_id =
225 TOKEN_NUM_INITIALIZER(
226 struct cmd_add_port_meter_profile_srtcm_result,
228 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_profile_id =
229 TOKEN_NUM_INITIALIZER(
230 struct cmd_add_port_meter_profile_srtcm_result,
232 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cir =
233 TOKEN_NUM_INITIALIZER(
234 struct cmd_add_port_meter_profile_srtcm_result,
236 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cbs =
237 TOKEN_NUM_INITIALIZER(
238 struct cmd_add_port_meter_profile_srtcm_result,
240 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_ebs =
241 TOKEN_NUM_INITIALIZER(
242 struct cmd_add_port_meter_profile_srtcm_result,
245 static void cmd_add_port_meter_profile_srtcm_parsed(void *parsed_result,
246 __attribute__((unused)) struct cmdline *cl,
247 __attribute__((unused)) void *data)
249 struct cmd_add_port_meter_profile_srtcm_result *res = parsed_result;
250 struct rte_mtr_meter_profile mp;
251 struct rte_mtr_error error;
252 uint32_t profile_id = res->profile_id;
253 uint16_t port_id = res->port_id;
256 if (port_id_is_invalid(port_id, ENABLED_WARN))
259 /* Private shaper profile params */
260 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
261 mp.alg = RTE_MTR_SRTCM_RFC2697;
262 mp.srtcm_rfc2697.cir = res->cir;
263 mp.srtcm_rfc2697.cbs = res->cbs;
264 mp.srtcm_rfc2697.ebs = res->ebs;
266 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
268 print_err_msg(&error);
273 cmdline_parse_inst_t cmd_add_port_meter_profile_srtcm = {
274 .f = cmd_add_port_meter_profile_srtcm_parsed,
276 .help_str = "Add port meter profile srtcm (rfc2697)",
278 (void *)&cmd_add_port_meter_profile_srtcm_add,
279 (void *)&cmd_add_port_meter_profile_srtcm_port,
280 (void *)&cmd_add_port_meter_profile_srtcm_meter,
281 (void *)&cmd_add_port_meter_profile_srtcm_profile,
282 (void *)&cmd_add_port_meter_profile_srtcm_port_id,
283 (void *)&cmd_add_port_meter_profile_srtcm_profile_id,
284 (void *)&cmd_add_port_meter_profile_srtcm_srtcm_rfc2697,
285 (void *)&cmd_add_port_meter_profile_srtcm_cir,
286 (void *)&cmd_add_port_meter_profile_srtcm_cbs,
287 (void *)&cmd_add_port_meter_profile_srtcm_ebs,
292 /* *** Add Port Meter Profile trtcm_rfc2698 *** */
293 struct cmd_add_port_meter_profile_trtcm_result {
294 cmdline_fixed_string_t add;
295 cmdline_fixed_string_t port;
296 cmdline_fixed_string_t meter;
297 cmdline_fixed_string_t profile;
298 cmdline_fixed_string_t trtcm_rfc2698;
307 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_add =
308 TOKEN_STRING_INITIALIZER(
309 struct cmd_add_port_meter_profile_trtcm_result, add, "add");
310 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_port =
311 TOKEN_STRING_INITIALIZER(
312 struct cmd_add_port_meter_profile_trtcm_result,
314 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_meter =
315 TOKEN_STRING_INITIALIZER(
316 struct cmd_add_port_meter_profile_trtcm_result,
318 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_profile =
319 TOKEN_STRING_INITIALIZER(
320 struct cmd_add_port_meter_profile_trtcm_result,
322 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_trtcm_rfc2698 =
323 TOKEN_STRING_INITIALIZER(
324 struct cmd_add_port_meter_profile_trtcm_result,
325 trtcm_rfc2698, "trtcm_rfc2698");
326 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_port_id =
327 TOKEN_NUM_INITIALIZER(
328 struct cmd_add_port_meter_profile_trtcm_result,
330 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_profile_id =
331 TOKEN_NUM_INITIALIZER(
332 struct cmd_add_port_meter_profile_trtcm_result,
334 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cir =
335 TOKEN_NUM_INITIALIZER(
336 struct cmd_add_port_meter_profile_trtcm_result,
338 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pir =
339 TOKEN_NUM_INITIALIZER(
340 struct cmd_add_port_meter_profile_trtcm_result,
342 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cbs =
343 TOKEN_NUM_INITIALIZER(
344 struct cmd_add_port_meter_profile_trtcm_result,
346 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pbs =
347 TOKEN_NUM_INITIALIZER(
348 struct cmd_add_port_meter_profile_trtcm_result,
351 static void cmd_add_port_meter_profile_trtcm_parsed(void *parsed_result,
352 __attribute__((unused)) struct cmdline *cl,
353 __attribute__((unused)) void *data)
355 struct cmd_add_port_meter_profile_trtcm_result *res = parsed_result;
356 struct rte_mtr_meter_profile mp;
357 struct rte_mtr_error error;
358 uint32_t profile_id = res->profile_id;
359 uint16_t port_id = res->port_id;
362 if (port_id_is_invalid(port_id, ENABLED_WARN))
365 /* Private shaper profile params */
366 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
367 mp.alg = RTE_MTR_TRTCM_RFC2698;
368 mp.trtcm_rfc2698.cir = res->cir;
369 mp.trtcm_rfc2698.pir = res->pir;
370 mp.trtcm_rfc2698.cbs = res->cbs;
371 mp.trtcm_rfc2698.pbs = res->pbs;
373 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
375 print_err_msg(&error);
380 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm = {
381 .f = cmd_add_port_meter_profile_trtcm_parsed,
383 .help_str = "Add port meter profile trtcm (rfc2698)",
385 (void *)&cmd_add_port_meter_profile_trtcm_add,
386 (void *)&cmd_add_port_meter_profile_trtcm_port,
387 (void *)&cmd_add_port_meter_profile_trtcm_meter,
388 (void *)&cmd_add_port_meter_profile_trtcm_profile,
389 (void *)&cmd_add_port_meter_profile_trtcm_port_id,
390 (void *)&cmd_add_port_meter_profile_trtcm_profile_id,
391 (void *)&cmd_add_port_meter_profile_trtcm_trtcm_rfc2698,
392 (void *)&cmd_add_port_meter_profile_trtcm_cir,
393 (void *)&cmd_add_port_meter_profile_trtcm_pir,
394 (void *)&cmd_add_port_meter_profile_trtcm_cbs,
395 (void *)&cmd_add_port_meter_profile_trtcm_pbs,
400 /* *** Add Port Meter Profile trtcm_rfc4115 *** */
401 struct cmd_add_port_meter_profile_trtcm_rfc4115_result {
402 cmdline_fixed_string_t add;
403 cmdline_fixed_string_t port;
404 cmdline_fixed_string_t meter;
405 cmdline_fixed_string_t profile;
406 cmdline_fixed_string_t trtcm_rfc4115;
415 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_add =
416 TOKEN_STRING_INITIALIZER(
417 struct cmd_add_port_meter_profile_trtcm_rfc4115_result, add,
419 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_port =
420 TOKEN_STRING_INITIALIZER(
421 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
423 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_meter =
424 TOKEN_STRING_INITIALIZER(
425 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
427 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_profile =
428 TOKEN_STRING_INITIALIZER(
429 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
431 cmdline_parse_token_string_t
432 cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115 =
433 TOKEN_STRING_INITIALIZER(
434 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
435 trtcm_rfc4115, "trtcm_rfc4115");
436 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_port_id =
437 TOKEN_NUM_INITIALIZER(
438 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
440 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_profile_id =
441 TOKEN_NUM_INITIALIZER(
442 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
444 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cir =
445 TOKEN_NUM_INITIALIZER(
446 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
448 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_eir =
449 TOKEN_NUM_INITIALIZER(
450 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
452 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cbs =
453 TOKEN_NUM_INITIALIZER(
454 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
456 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_ebs =
457 TOKEN_NUM_INITIALIZER(
458 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
461 static void cmd_add_port_meter_profile_trtcm_rfc4115_parsed(
463 __attribute__((unused)) struct cmdline *cl,
464 __attribute__((unused)) void *data)
466 struct cmd_add_port_meter_profile_trtcm_rfc4115_result *res =
468 struct rte_mtr_meter_profile mp;
469 struct rte_mtr_error error;
470 uint32_t profile_id = res->profile_id;
471 uint16_t port_id = res->port_id;
474 if (port_id_is_invalid(port_id, ENABLED_WARN))
477 /* Private shaper profile params */
478 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
479 mp.alg = RTE_MTR_TRTCM_RFC4115;
480 mp.trtcm_rfc4115.cir = res->cir;
481 mp.trtcm_rfc4115.eir = res->eir;
482 mp.trtcm_rfc4115.cbs = res->cbs;
483 mp.trtcm_rfc4115.ebs = res->ebs;
485 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
487 print_err_msg(&error);
492 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm_rfc4115 = {
493 .f = cmd_add_port_meter_profile_trtcm_rfc4115_parsed,
495 .help_str = "Add port meter profile trtcm (rfc4115)",
497 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_add,
498 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port,
499 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_meter,
500 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile,
501 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port_id,
502 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile_id,
503 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115,
504 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cir,
505 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_eir,
506 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cbs,
507 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_ebs,
512 /* *** Delete Port Meter Profile *** */
513 struct cmd_del_port_meter_profile_result {
514 cmdline_fixed_string_t del;
515 cmdline_fixed_string_t port;
516 cmdline_fixed_string_t meter;
517 cmdline_fixed_string_t profile;
522 cmdline_parse_token_string_t cmd_del_port_meter_profile_del =
523 TOKEN_STRING_INITIALIZER(
524 struct cmd_del_port_meter_profile_result, del, "del");
525 cmdline_parse_token_string_t cmd_del_port_meter_profile_port =
526 TOKEN_STRING_INITIALIZER(
527 struct cmd_del_port_meter_profile_result,
529 cmdline_parse_token_string_t cmd_del_port_meter_profile_meter =
530 TOKEN_STRING_INITIALIZER(
531 struct cmd_del_port_meter_profile_result,
533 cmdline_parse_token_string_t cmd_del_port_meter_profile_profile =
534 TOKEN_STRING_INITIALIZER(
535 struct cmd_del_port_meter_profile_result,
537 cmdline_parse_token_num_t cmd_del_port_meter_profile_port_id =
538 TOKEN_NUM_INITIALIZER(
539 struct cmd_del_port_meter_profile_result,
541 cmdline_parse_token_num_t cmd_del_port_meter_profile_profile_id =
542 TOKEN_NUM_INITIALIZER(
543 struct cmd_del_port_meter_profile_result,
546 static void cmd_del_port_meter_profile_parsed(void *parsed_result,
547 __attribute__((unused)) struct cmdline *cl,
548 __attribute__((unused)) void *data)
550 struct cmd_del_port_meter_profile_result *res = parsed_result;
551 struct rte_mtr_error error;
552 uint32_t profile_id = res->profile_id;
553 uint16_t port_id = res->port_id;
556 if (port_id_is_invalid(port_id, ENABLED_WARN))
559 /* Delete meter profile */
560 ret = rte_mtr_meter_profile_delete(port_id, profile_id, &error);
562 print_err_msg(&error);
567 cmdline_parse_inst_t cmd_del_port_meter_profile = {
568 .f = cmd_del_port_meter_profile_parsed,
570 .help_str = "Delete port meter profile",
572 (void *)&cmd_del_port_meter_profile_del,
573 (void *)&cmd_del_port_meter_profile_port,
574 (void *)&cmd_del_port_meter_profile_meter,
575 (void *)&cmd_del_port_meter_profile_profile,
576 (void *)&cmd_del_port_meter_profile_port_id,
577 (void *)&cmd_del_port_meter_profile_profile_id,
582 /* *** Create Port Meter Object *** */
583 struct cmd_create_port_meter_result {
584 cmdline_fixed_string_t create;
585 cmdline_fixed_string_t port;
586 cmdline_fixed_string_t meter;
590 cmdline_fixed_string_t meter_enable;
591 cmdline_fixed_string_t g_action;
592 cmdline_fixed_string_t y_action;
593 cmdline_fixed_string_t r_action;
594 uint64_t statistics_mask;
596 cmdline_multi_string_t meter_input_color;
599 cmdline_parse_token_string_t cmd_create_port_meter_create =
600 TOKEN_STRING_INITIALIZER(
601 struct cmd_create_port_meter_result, create, "create");
602 cmdline_parse_token_string_t cmd_create_port_meter_port =
603 TOKEN_STRING_INITIALIZER(
604 struct cmd_create_port_meter_result, port, "port");
605 cmdline_parse_token_string_t cmd_create_port_meter_meter =
606 TOKEN_STRING_INITIALIZER(
607 struct cmd_create_port_meter_result, meter, "meter");
608 cmdline_parse_token_num_t cmd_create_port_meter_port_id =
609 TOKEN_NUM_INITIALIZER(
610 struct cmd_create_port_meter_result, port_id, UINT16);
611 cmdline_parse_token_num_t cmd_create_port_meter_mtr_id =
612 TOKEN_NUM_INITIALIZER(
613 struct cmd_create_port_meter_result, mtr_id, UINT32);
614 cmdline_parse_token_num_t cmd_create_port_meter_profile_id =
615 TOKEN_NUM_INITIALIZER(
616 struct cmd_create_port_meter_result, profile_id, UINT32);
617 cmdline_parse_token_string_t cmd_create_port_meter_meter_enable =
618 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
619 meter_enable, "yes#no");
620 cmdline_parse_token_string_t cmd_create_port_meter_g_action =
621 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
622 g_action, "R#Y#G#D#r#y#g#d");
623 cmdline_parse_token_string_t cmd_create_port_meter_y_action =
624 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
625 y_action, "R#Y#G#D#r#y#g#d");
626 cmdline_parse_token_string_t cmd_create_port_meter_r_action =
627 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
628 r_action, "R#Y#G#D#r#y#g#d");
629 cmdline_parse_token_num_t cmd_create_port_meter_statistics_mask =
630 TOKEN_NUM_INITIALIZER(struct cmd_create_port_meter_result,
631 statistics_mask, UINT64);
632 cmdline_parse_token_num_t cmd_create_port_meter_shared =
633 TOKEN_NUM_INITIALIZER(struct cmd_create_port_meter_result,
635 cmdline_parse_token_string_t cmd_create_port_meter_input_color =
636 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
637 meter_input_color, TOKEN_STRING_MULTI);
639 static void cmd_create_port_meter_parsed(void *parsed_result,
640 __attribute__((unused)) struct cmdline *cl,
641 __attribute__((unused)) void *data)
643 struct cmd_create_port_meter_result *res = parsed_result;
644 struct rte_mtr_error error;
645 struct rte_mtr_params params;
646 uint32_t mtr_id = res->mtr_id;
647 uint32_t shared = res->shared;
648 uint32_t use_prev_meter_color = 0;
649 uint16_t port_id = res->port_id;
650 enum rte_mtr_color *dscp_table = NULL;
651 char *c_str = res->meter_input_color;
654 if (port_id_is_invalid(port_id, ENABLED_WARN))
658 memset(¶ms, 0, sizeof(struct rte_mtr_params));
659 params.meter_profile_id = res->profile_id;
661 /* Parse meter input color string params */
662 ret = parse_meter_color_str(c_str, &use_prev_meter_color, dscp_table);
664 printf(" Meter input color params string parse error\n");
668 params.use_prev_mtr_color = use_prev_meter_color;
669 params.dscp_table = dscp_table;
671 if (strcmp(res->meter_enable, "yes") == 0)
672 params.meter_enable = 1;
674 params.meter_enable = 0;
676 params.action[RTE_MTR_GREEN] =
677 string_to_policer_action(res->g_action);
678 params.action[RTE_MTR_YELLOW] =
679 string_to_policer_action(res->y_action);
680 params.action[RTE_MTR_RED] =
681 string_to_policer_action(res->r_action);
682 params.stats_mask = res->statistics_mask;
684 ret = rte_mtr_create(port_id, mtr_id, ¶ms, shared, &error);
687 print_err_msg(&error);
692 cmdline_parse_inst_t cmd_create_port_meter = {
693 .f = cmd_create_port_meter_parsed,
695 .help_str = "Create port meter",
697 (void *)&cmd_create_port_meter_create,
698 (void *)&cmd_create_port_meter_port,
699 (void *)&cmd_create_port_meter_meter,
700 (void *)&cmd_create_port_meter_port_id,
701 (void *)&cmd_create_port_meter_mtr_id,
702 (void *)&cmd_create_port_meter_profile_id,
703 (void *)&cmd_create_port_meter_meter_enable,
704 (void *)&cmd_create_port_meter_g_action,
705 (void *)&cmd_create_port_meter_y_action,
706 (void *)&cmd_create_port_meter_r_action,
707 (void *)&cmd_create_port_meter_statistics_mask,
708 (void *)&cmd_create_port_meter_shared,
709 (void *)&cmd_create_port_meter_input_color,
714 /* *** Delete Port Meter Object *** */
715 struct cmd_del_port_meter_result {
716 cmdline_fixed_string_t del;
717 cmdline_fixed_string_t port;
718 cmdline_fixed_string_t meter;
723 cmdline_parse_token_string_t cmd_del_port_meter_del =
724 TOKEN_STRING_INITIALIZER(
725 struct cmd_del_port_meter_result, del, "del");
726 cmdline_parse_token_string_t cmd_del_port_meter_port =
727 TOKEN_STRING_INITIALIZER(
728 struct cmd_del_port_meter_result, port, "port");
729 cmdline_parse_token_string_t cmd_del_port_meter_meter =
730 TOKEN_STRING_INITIALIZER(
731 struct cmd_del_port_meter_result, meter, "meter");
732 cmdline_parse_token_num_t cmd_del_port_meter_port_id =
733 TOKEN_NUM_INITIALIZER(
734 struct cmd_del_port_meter_result, port_id, UINT16);
735 cmdline_parse_token_num_t cmd_del_port_meter_mtr_id =
736 TOKEN_NUM_INITIALIZER(
737 struct cmd_del_port_meter_result, mtr_id, UINT32);
739 static void cmd_del_port_meter_parsed(void *parsed_result,
740 __attribute__((unused)) struct cmdline *cl,
741 __attribute__((unused)) void *data)
743 struct cmd_del_port_meter_result *res = parsed_result;
744 struct rte_mtr_error error;
745 uint32_t mtr_id = res->mtr_id;
746 uint16_t port_id = res->port_id;
750 if (port_id_is_invalid(port_id, ENABLED_WARN))
754 ret = rte_mtr_destroy(port_id, mtr_id, &error);
756 print_err_msg(&error);
761 cmdline_parse_inst_t cmd_del_port_meter = {
762 .f = cmd_del_port_meter_parsed,
764 .help_str = "Delete port meter",
766 (void *)&cmd_del_port_meter_del,
767 (void *)&cmd_del_port_meter_port,
768 (void *)&cmd_del_port_meter_meter,
769 (void *)&cmd_del_port_meter_port_id,
770 (void *)&cmd_del_port_meter_mtr_id,
775 /* *** Set Port Meter Profile *** */
776 struct cmd_set_port_meter_profile_result {
777 cmdline_fixed_string_t set;
778 cmdline_fixed_string_t port;
779 cmdline_fixed_string_t meter;
780 cmdline_fixed_string_t profile;
786 cmdline_parse_token_string_t cmd_set_port_meter_profile_set =
787 TOKEN_STRING_INITIALIZER(
788 struct cmd_set_port_meter_profile_result, set, "set");
789 cmdline_parse_token_string_t cmd_set_port_meter_profile_port =
790 TOKEN_STRING_INITIALIZER(
791 struct cmd_set_port_meter_profile_result, port, "port");
792 cmdline_parse_token_string_t cmd_set_port_meter_profile_meter =
793 TOKEN_STRING_INITIALIZER(
794 struct cmd_set_port_meter_profile_result, meter, "meter");
795 cmdline_parse_token_string_t cmd_set_port_meter_profile_profile =
796 TOKEN_STRING_INITIALIZER(
797 struct cmd_set_port_meter_profile_result, profile, "profile");
798 cmdline_parse_token_num_t cmd_set_port_meter_profile_port_id =
799 TOKEN_NUM_INITIALIZER(
800 struct cmd_set_port_meter_profile_result, port_id, UINT16);
801 cmdline_parse_token_num_t cmd_set_port_meter_profile_mtr_id =
802 TOKEN_NUM_INITIALIZER(
803 struct cmd_set_port_meter_profile_result, mtr_id, UINT32);
804 cmdline_parse_token_num_t cmd_set_port_meter_profile_profile_id =
805 TOKEN_NUM_INITIALIZER(
806 struct cmd_set_port_meter_profile_result, profile_id, UINT32);
808 static void cmd_set_port_meter_profile_parsed(void *parsed_result,
809 __attribute__((unused)) struct cmdline *cl,
810 __attribute__((unused)) void *data)
812 struct cmd_set_port_meter_profile_result *res = parsed_result;
813 struct rte_mtr_error error;
814 uint32_t mtr_id = res->mtr_id;
815 uint32_t profile_id = res->profile_id;
816 uint16_t port_id = res->port_id;
820 if (port_id_is_invalid(port_id, ENABLED_WARN))
823 /* Set meter profile */
824 ret = rte_mtr_meter_profile_update(port_id, mtr_id,
827 print_err_msg(&error);
832 cmdline_parse_inst_t cmd_set_port_meter_profile = {
833 .f = cmd_set_port_meter_profile_parsed,
835 .help_str = "Set port meter profile",
837 (void *)&cmd_set_port_meter_profile_set,
838 (void *)&cmd_set_port_meter_profile_port,
839 (void *)&cmd_set_port_meter_profile_meter,
840 (void *)&cmd_set_port_meter_profile_profile,
841 (void *)&cmd_set_port_meter_profile_port_id,
842 (void *)&cmd_set_port_meter_profile_mtr_id,
843 (void *)&cmd_set_port_meter_profile_profile_id,
848 /* *** Set Port Meter Policer Action *** */
849 struct cmd_set_port_meter_policer_action_result {
850 cmdline_fixed_string_t set;
851 cmdline_fixed_string_t port;
852 cmdline_fixed_string_t meter;
853 cmdline_fixed_string_t policer;
854 cmdline_fixed_string_t action;
857 uint32_t action_mask;
858 cmdline_multi_string_t policer_action;
861 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_set =
862 TOKEN_STRING_INITIALIZER(
863 struct cmd_set_port_meter_policer_action_result, set, "set");
864 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_port =
865 TOKEN_STRING_INITIALIZER(
866 struct cmd_set_port_meter_policer_action_result, port, "port");
867 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_meter =
868 TOKEN_STRING_INITIALIZER(
869 struct cmd_set_port_meter_policer_action_result, meter,
871 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_policer =
872 TOKEN_STRING_INITIALIZER(
873 struct cmd_set_port_meter_policer_action_result, policer,
875 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_action =
876 TOKEN_STRING_INITIALIZER(
877 struct cmd_set_port_meter_policer_action_result, action,
879 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_port_id =
880 TOKEN_NUM_INITIALIZER(
881 struct cmd_set_port_meter_policer_action_result, port_id,
883 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_mtr_id =
884 TOKEN_NUM_INITIALIZER(
885 struct cmd_set_port_meter_policer_action_result, mtr_id,
887 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_action_mask =
888 TOKEN_NUM_INITIALIZER(
889 struct cmd_set_port_meter_policer_action_result, action_mask,
891 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_policer_action =
892 TOKEN_STRING_INITIALIZER(
893 struct cmd_set_port_meter_policer_action_result,
894 policer_action, TOKEN_STRING_MULTI);
896 static void cmd_set_port_meter_policer_action_parsed(void *parsed_result,
897 __attribute__((unused)) struct cmdline *cl,
898 __attribute__((unused)) void *data)
900 struct cmd_set_port_meter_policer_action_result *res = parsed_result;
901 enum rte_mtr_policer_action *actions;
902 struct rte_mtr_error error;
903 uint32_t mtr_id = res->mtr_id;
904 uint32_t action_mask = res->action_mask;
905 uint16_t port_id = res->port_id;
906 char *p_str = res->policer_action;
909 if (port_id_is_invalid(port_id, ENABLED_WARN))
912 /* Check: action mask */
913 if (action_mask == 0 || (action_mask & (~0x7UL))) {
914 printf(" Policer action mask not correct (error)\n");
918 /* Allocate memory for policer actions */
919 actions = (enum rte_mtr_policer_action *)malloc(RTE_MTR_COLORS *
920 sizeof(enum rte_mtr_policer_action));
921 if (actions == NULL) {
922 printf("Memory for policer actions not allocated (error)\n");
925 /* Parse policer action string */
926 ret = parse_policer_action_string(p_str, action_mask, actions);
928 printf(" Policer action string parse error\n");
933 ret = rte_mtr_policer_actions_update(port_id, mtr_id,
934 action_mask, actions, &error);
936 print_err_msg(&error);
943 cmdline_parse_inst_t cmd_set_port_meter_policer_action = {
944 .f = cmd_set_port_meter_policer_action_parsed,
946 .help_str = "Set port meter policer action",
948 (void *)&cmd_set_port_meter_policer_action_set,
949 (void *)&cmd_set_port_meter_policer_action_port,
950 (void *)&cmd_set_port_meter_policer_action_meter,
951 (void *)&cmd_set_port_meter_policer_action_policer,
952 (void *)&cmd_set_port_meter_policer_action_action,
953 (void *)&cmd_set_port_meter_policer_action_port_id,
954 (void *)&cmd_set_port_meter_policer_action_mtr_id,
955 (void *)&cmd_set_port_meter_policer_action_action_mask,
956 (void *)&cmd_set_port_meter_policer_action_policer_action,
961 /* *** Set Port Meter Stats Mask *** */
962 struct cmd_set_port_meter_stats_mask_result {
963 cmdline_fixed_string_t set;
964 cmdline_fixed_string_t port;
965 cmdline_fixed_string_t meter;
966 cmdline_fixed_string_t stats;
967 cmdline_fixed_string_t mask;
973 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_set =
974 TOKEN_STRING_INITIALIZER(
975 struct cmd_set_port_meter_stats_mask_result, set, "set");
976 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_port =
977 TOKEN_STRING_INITIALIZER(
978 struct cmd_set_port_meter_stats_mask_result, port, "port");
979 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_meter =
980 TOKEN_STRING_INITIALIZER(
981 struct cmd_set_port_meter_stats_mask_result, meter, "meter");
982 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_stats =
983 TOKEN_STRING_INITIALIZER(
984 struct cmd_set_port_meter_stats_mask_result, stats, "stats");
985 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_mask =
986 TOKEN_STRING_INITIALIZER(
987 struct cmd_set_port_meter_stats_mask_result, mask, "mask");
988 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_port_id =
989 TOKEN_NUM_INITIALIZER(
990 struct cmd_set_port_meter_stats_mask_result, port_id, UINT16);
991 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_mtr_id =
992 TOKEN_NUM_INITIALIZER(
993 struct cmd_set_port_meter_stats_mask_result, mtr_id, UINT32);
994 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_stats_mask =
995 TOKEN_NUM_INITIALIZER(
996 struct cmd_set_port_meter_stats_mask_result, stats_mask,
999 static void cmd_set_port_meter_stats_mask_parsed(void *parsed_result,
1000 __attribute__((unused)) struct cmdline *cl,
1001 __attribute__((unused)) void *data)
1003 struct cmd_set_port_meter_stats_mask_result *res = parsed_result;
1004 struct rte_mtr_error error;
1005 uint64_t stats_mask = res->stats_mask;
1006 uint32_t mtr_id = res->mtr_id;
1007 uint16_t port_id = res->port_id;
1010 if (port_id_is_invalid(port_id, ENABLED_WARN))
1013 ret = rte_mtr_stats_update(port_id, mtr_id, stats_mask, &error);
1015 print_err_msg(&error);
1020 cmdline_parse_inst_t cmd_set_port_meter_stats_mask = {
1021 .f = cmd_set_port_meter_stats_mask_parsed,
1023 .help_str = "Set port meter stats mask",
1025 (void *)&cmd_set_port_meter_stats_mask_set,
1026 (void *)&cmd_set_port_meter_stats_mask_port,
1027 (void *)&cmd_set_port_meter_stats_mask_meter,
1028 (void *)&cmd_set_port_meter_stats_mask_stats,
1029 (void *)&cmd_set_port_meter_stats_mask_mask,
1030 (void *)&cmd_set_port_meter_stats_mask_port_id,
1031 (void *)&cmd_set_port_meter_stats_mask_mtr_id,
1032 (void *)&cmd_set_port_meter_stats_mask_stats_mask,
1037 /* *** Show Port Meter Stats *** */
1038 struct cmd_show_port_meter_stats_result {
1039 cmdline_fixed_string_t show;
1040 cmdline_fixed_string_t port;
1041 cmdline_fixed_string_t meter;
1042 cmdline_fixed_string_t stats;
1045 cmdline_fixed_string_t clear;
1048 cmdline_parse_token_string_t cmd_show_port_meter_stats_show =
1049 TOKEN_STRING_INITIALIZER(
1050 struct cmd_show_port_meter_stats_result, show, "show");
1051 cmdline_parse_token_string_t cmd_show_port_meter_stats_port =
1052 TOKEN_STRING_INITIALIZER(
1053 struct cmd_show_port_meter_stats_result, port, "port");
1054 cmdline_parse_token_string_t cmd_show_port_meter_stats_meter =
1055 TOKEN_STRING_INITIALIZER(
1056 struct cmd_show_port_meter_stats_result, meter, "meter");
1057 cmdline_parse_token_string_t cmd_show_port_meter_stats_stats =
1058 TOKEN_STRING_INITIALIZER(
1059 struct cmd_show_port_meter_stats_result, stats, "stats");
1060 cmdline_parse_token_num_t cmd_show_port_meter_stats_port_id =
1061 TOKEN_NUM_INITIALIZER(
1062 struct cmd_show_port_meter_stats_result, port_id, UINT16);
1063 cmdline_parse_token_num_t cmd_show_port_meter_stats_mtr_id =
1064 TOKEN_NUM_INITIALIZER(
1065 struct cmd_show_port_meter_stats_result, mtr_id, UINT32);
1066 cmdline_parse_token_string_t cmd_show_port_meter_stats_clear =
1067 TOKEN_STRING_INITIALIZER(
1068 struct cmd_show_port_meter_stats_result, clear, "yes#no");
1070 static void cmd_show_port_meter_stats_parsed(void *parsed_result,
1071 __attribute__((unused)) struct cmdline *cl,
1072 __attribute__((unused)) void *data)
1074 struct cmd_show_port_meter_stats_result *res = parsed_result;
1075 struct rte_mtr_stats stats;
1076 uint64_t stats_mask = 0;
1077 struct rte_mtr_error error;
1078 uint32_t mtr_id = res->mtr_id;
1080 uint16_t port_id = res->port_id;
1083 if (port_id_is_invalid(port_id, ENABLED_WARN))
1086 if (strcmp(res->clear, "yes") == 0)
1089 memset(&stats, 0, sizeof(struct rte_mtr_stats));
1090 ret = rte_mtr_stats_read(port_id, mtr_id, &stats,
1091 &stats_mask, clear, &error);
1093 print_err_msg(&error);
1098 if (stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
1099 printf("\tPkts G: %" PRIu64 "\n",
1100 stats.n_pkts[RTE_MTR_GREEN]);
1101 if (stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
1102 printf("\tBytes G: %" PRIu64 "\n",
1103 stats.n_bytes[RTE_MTR_GREEN]);
1104 if (stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
1105 printf("\tPkts Y: %" PRIu64 "\n",
1106 stats.n_pkts[RTE_MTR_YELLOW]);
1107 if (stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
1108 printf("\tBytes Y: %" PRIu64 "\n",
1109 stats.n_bytes[RTE_MTR_YELLOW]);
1110 if (stats_mask & RTE_MTR_STATS_N_PKTS_RED)
1111 printf("\tPkts R: %" PRIu64 "\n",
1112 stats.n_pkts[RTE_MTR_RED]);
1113 if (stats_mask & RTE_MTR_STATS_N_BYTES_RED)
1114 printf("\tBytes Y: %" PRIu64 "\n",
1115 stats.n_bytes[RTE_MTR_RED]);
1116 if (stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
1117 printf("\tPkts DROPPED: %" PRIu64 "\n",
1118 stats.n_pkts_dropped);
1119 if (stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
1120 printf("\tBytes DROPPED: %" PRIu64 "\n",
1121 stats.n_bytes_dropped);
1124 cmdline_parse_inst_t cmd_show_port_meter_stats = {
1125 .f = cmd_show_port_meter_stats_parsed,
1127 .help_str = "Show port meter stats",
1129 (void *)&cmd_show_port_meter_stats_show,
1130 (void *)&cmd_show_port_meter_stats_port,
1131 (void *)&cmd_show_port_meter_stats_meter,
1132 (void *)&cmd_show_port_meter_stats_stats,
1133 (void *)&cmd_show_port_meter_stats_port_id,
1134 (void *)&cmd_show_port_meter_stats_mtr_id,
1135 (void *)&cmd_show_port_meter_stats_clear,