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));
89 if (dscp_table == NULL)
93 if (strcmp(token, "G") == 0 ||
94 strcmp(token, "g") == 0)
95 dscp_table[i++] = RTE_MTR_GREEN;
96 else if (strcmp(token, "Y") == 0 ||
97 strcmp(token, "y") == 0)
98 dscp_table[i++] = RTE_MTR_YELLOW;
99 else if (strcmp(token, "R") == 0 ||
100 strcmp(token, "r") == 0)
101 dscp_table[i++] = RTE_MTR_RED;
106 if (i == MAX_DSCP_TABLE_ENTRIES)
109 token = strtok_r(str, PARSE_DELIMITER, &str);
119 parse_meter_color_str(char *c_str, uint32_t *use_prev_meter_color,
120 enum rte_mtr_color *dscp_table)
123 uint64_t previous_mtr_color = 0;
126 /* First token: use previous meter color */
127 token = strtok_r(c_str, PARSE_DELIMITER, &c_str);
131 ret = parse_uint(&previous_mtr_color, token);
135 /* Check if previous meter color to be used */
136 if (previous_mtr_color) {
137 *use_prev_meter_color = previous_mtr_color;
141 /* Parse dscp table entries */
142 ret = parse_dscp_table_entries(c_str, dscp_table);
150 string_to_policer_action(char *s)
152 if ((strcmp(s, "G") == 0) || (strcmp(s, "g") == 0))
153 return MTR_POLICER_ACTION_COLOR_GREEN;
155 if ((strcmp(s, "Y") == 0) || (strcmp(s, "y") == 0))
156 return MTR_POLICER_ACTION_COLOR_YELLOW;
158 if ((strcmp(s, "R") == 0) || (strcmp(s, "r") == 0))
159 return MTR_POLICER_ACTION_COLOR_RED;
161 if ((strcmp(s, "D") == 0) || (strcmp(s, "d") == 0))
162 return MTR_POLICER_ACTION_DROP;
168 parse_policer_action_string(char *p_str, uint32_t action_mask,
169 enum rte_mtr_policer_action actions[])
172 int count = __builtin_popcount(action_mask);
173 int g_color = 0, y_color = 0, action, i;
175 for (i = 0; i < count; i++) {
176 token = strtok_r(p_str, PARSE_DELIMITER, &p_str);
180 action = string_to_policer_action(token);
184 if (g_color == 0 && (action_mask & 0x1)) {
185 actions[RTE_MTR_GREEN] = action;
187 } else if (y_color == 0 && (action_mask & 0x2)) {
188 actions[RTE_MTR_YELLOW] = action;
191 actions[RTE_MTR_RED] = action;
197 parse_multi_token_string(char *t_str, uint16_t *port_id,
198 uint32_t *mtr_id, enum rte_mtr_color *dscp_table)
204 /* First token: port id */
205 token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
209 ret = parse_uint(&val, token);
210 if (ret != 0 || val > UINT16_MAX)
215 /* Second token: meter id */
216 token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
220 ret = parse_uint(&val, token);
221 if (ret != 0 || val > UINT32_MAX)
226 ret = parse_dscp_table_entries(t_str, dscp_table);
233 /* *** Show Port Meter Capabilities *** */
234 struct cmd_show_port_meter_cap_result {
235 cmdline_fixed_string_t show;
236 cmdline_fixed_string_t port;
237 cmdline_fixed_string_t meter;
238 cmdline_fixed_string_t cap;
242 cmdline_parse_token_string_t cmd_show_port_meter_cap_show =
243 TOKEN_STRING_INITIALIZER(
244 struct cmd_show_port_meter_cap_result, show, "show");
245 cmdline_parse_token_string_t cmd_show_port_meter_cap_port =
246 TOKEN_STRING_INITIALIZER(
247 struct cmd_show_port_meter_cap_result, port, "port");
248 cmdline_parse_token_string_t cmd_show_port_meter_cap_meter =
249 TOKEN_STRING_INITIALIZER(
250 struct cmd_show_port_meter_cap_result, meter, "meter");
251 cmdline_parse_token_string_t cmd_show_port_meter_cap_cap =
252 TOKEN_STRING_INITIALIZER(
253 struct cmd_show_port_meter_cap_result, cap, "cap");
254 cmdline_parse_token_num_t cmd_show_port_meter_cap_port_id =
255 TOKEN_NUM_INITIALIZER(
256 struct cmd_show_port_meter_cap_result, port_id, UINT16);
258 static void cmd_show_port_meter_cap_parsed(void *parsed_result,
259 __attribute__((unused)) struct cmdline *cl,
260 __attribute__((unused)) void *data)
262 struct cmd_show_port_meter_cap_result *res = parsed_result;
263 struct rte_mtr_capabilities cap;
264 struct rte_mtr_error error;
265 uint16_t port_id = res->port_id;
268 if (port_id_is_invalid(port_id, ENABLED_WARN))
271 memset(&cap, 0, sizeof(struct rte_mtr_capabilities));
272 ret = rte_mtr_capabilities_get(port_id, &cap, &error);
274 print_err_msg(&error);
278 printf("\n**** Port Meter Object Capabilities ****\n\n");
279 printf("cap.n_max %" PRIu32 "\n", cap.n_max);
280 printf("cap.n_shared_max %" PRIu32 "\n", cap.n_shared_max);
281 printf("cap.identical %" PRId32 "\n", cap.identical);
282 printf("cap.shared_identical %" PRId32 "\n",
283 cap.shared_identical);
284 printf("cap.shared_n_flows_per_mtr_max %" PRIu32 "\n",
285 cap.shared_n_flows_per_mtr_max);
286 printf("cap.chaining_n_mtrs_per_flow_max %" PRIu32 "\n",
287 cap.chaining_n_mtrs_per_flow_max);
288 printf("cap.chaining_use_prev_mtr_color_supported %" PRId32 "\n",
289 cap.chaining_use_prev_mtr_color_supported);
290 printf("cap.chaining_use_prev_mtr_color_enforced %" PRId32 "\n",
291 cap.chaining_use_prev_mtr_color_enforced);
292 printf("cap.meter_srtcm_rfc2697_n_max %" PRIu32 "\n",
293 cap.meter_srtcm_rfc2697_n_max);
294 printf("cap.meter_trtcm_rfc2698_n_max %" PRIu32 "\n",
295 cap.meter_trtcm_rfc2698_n_max);
296 printf("cap.meter_trtcm_rfc4115_n_max %" PRIu32 "\n",
297 cap.meter_trtcm_rfc4115_n_max);
298 printf("cap.meter_rate_max %" PRIu64 "\n", cap.meter_rate_max);
299 printf("cap.color_aware_srtcm_rfc2697_supported %" PRId32 "\n",
300 cap.color_aware_srtcm_rfc2697_supported);
301 printf("cap.color_aware_trtcm_rfc2698_supported %" PRId32 "\n",
302 cap.color_aware_trtcm_rfc2698_supported);
303 printf("cap.color_aware_trtcm_rfc4115_supported %" PRId32 "\n",
304 cap.color_aware_trtcm_rfc4115_supported);
305 printf("cap.policer_action_recolor_supported %" PRId32 "\n",
306 cap.policer_action_recolor_supported);
307 printf("cap.policer_action_drop_supported %" PRId32 "\n",
308 cap.policer_action_drop_supported);
309 printf("cap.stats_mask %" PRIx64 "\n", cap.stats_mask);
312 cmdline_parse_inst_t cmd_show_port_meter_cap = {
313 .f = cmd_show_port_meter_cap_parsed,
315 .help_str = "Show port meter cap",
317 (void *)&cmd_show_port_meter_cap_show,
318 (void *)&cmd_show_port_meter_cap_port,
319 (void *)&cmd_show_port_meter_cap_meter,
320 (void *)&cmd_show_port_meter_cap_cap,
321 (void *)&cmd_show_port_meter_cap_port_id,
326 /* *** Add Port Meter Profile srtcm_rfc2697 *** */
327 struct cmd_add_port_meter_profile_srtcm_result {
328 cmdline_fixed_string_t add;
329 cmdline_fixed_string_t port;
330 cmdline_fixed_string_t meter;
331 cmdline_fixed_string_t profile;
332 cmdline_fixed_string_t srtcm_rfc2697;
340 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_add =
341 TOKEN_STRING_INITIALIZER(
342 struct cmd_add_port_meter_profile_srtcm_result, add, "add");
343 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_port =
344 TOKEN_STRING_INITIALIZER(
345 struct cmd_add_port_meter_profile_srtcm_result,
347 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_meter =
348 TOKEN_STRING_INITIALIZER(
349 struct cmd_add_port_meter_profile_srtcm_result,
351 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_profile =
352 TOKEN_STRING_INITIALIZER(
353 struct cmd_add_port_meter_profile_srtcm_result,
355 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_srtcm_rfc2697 =
356 TOKEN_STRING_INITIALIZER(
357 struct cmd_add_port_meter_profile_srtcm_result,
358 srtcm_rfc2697, "srtcm_rfc2697");
359 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_port_id =
360 TOKEN_NUM_INITIALIZER(
361 struct cmd_add_port_meter_profile_srtcm_result,
363 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_profile_id =
364 TOKEN_NUM_INITIALIZER(
365 struct cmd_add_port_meter_profile_srtcm_result,
367 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cir =
368 TOKEN_NUM_INITIALIZER(
369 struct cmd_add_port_meter_profile_srtcm_result,
371 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cbs =
372 TOKEN_NUM_INITIALIZER(
373 struct cmd_add_port_meter_profile_srtcm_result,
375 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_ebs =
376 TOKEN_NUM_INITIALIZER(
377 struct cmd_add_port_meter_profile_srtcm_result,
380 static void cmd_add_port_meter_profile_srtcm_parsed(void *parsed_result,
381 __attribute__((unused)) struct cmdline *cl,
382 __attribute__((unused)) void *data)
384 struct cmd_add_port_meter_profile_srtcm_result *res = parsed_result;
385 struct rte_mtr_meter_profile mp;
386 struct rte_mtr_error error;
387 uint32_t profile_id = res->profile_id;
388 uint16_t port_id = res->port_id;
391 if (port_id_is_invalid(port_id, ENABLED_WARN))
394 /* Private shaper profile params */
395 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
396 mp.alg = RTE_MTR_SRTCM_RFC2697;
397 mp.srtcm_rfc2697.cir = res->cir;
398 mp.srtcm_rfc2697.cbs = res->cbs;
399 mp.srtcm_rfc2697.ebs = res->ebs;
401 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
403 print_err_msg(&error);
408 cmdline_parse_inst_t cmd_add_port_meter_profile_srtcm = {
409 .f = cmd_add_port_meter_profile_srtcm_parsed,
411 .help_str = "Add port meter profile srtcm (rfc2697)",
413 (void *)&cmd_add_port_meter_profile_srtcm_add,
414 (void *)&cmd_add_port_meter_profile_srtcm_port,
415 (void *)&cmd_add_port_meter_profile_srtcm_meter,
416 (void *)&cmd_add_port_meter_profile_srtcm_profile,
417 (void *)&cmd_add_port_meter_profile_srtcm_srtcm_rfc2697,
418 (void *)&cmd_add_port_meter_profile_srtcm_port_id,
419 (void *)&cmd_add_port_meter_profile_srtcm_profile_id,
420 (void *)&cmd_add_port_meter_profile_srtcm_cir,
421 (void *)&cmd_add_port_meter_profile_srtcm_cbs,
422 (void *)&cmd_add_port_meter_profile_srtcm_ebs,
427 /* *** Add Port Meter Profile trtcm_rfc2698 *** */
428 struct cmd_add_port_meter_profile_trtcm_result {
429 cmdline_fixed_string_t add;
430 cmdline_fixed_string_t port;
431 cmdline_fixed_string_t meter;
432 cmdline_fixed_string_t profile;
433 cmdline_fixed_string_t trtcm_rfc2698;
442 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_add =
443 TOKEN_STRING_INITIALIZER(
444 struct cmd_add_port_meter_profile_trtcm_result, add, "add");
445 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_port =
446 TOKEN_STRING_INITIALIZER(
447 struct cmd_add_port_meter_profile_trtcm_result,
449 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_meter =
450 TOKEN_STRING_INITIALIZER(
451 struct cmd_add_port_meter_profile_trtcm_result,
453 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_profile =
454 TOKEN_STRING_INITIALIZER(
455 struct cmd_add_port_meter_profile_trtcm_result,
457 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_trtcm_rfc2698 =
458 TOKEN_STRING_INITIALIZER(
459 struct cmd_add_port_meter_profile_trtcm_result,
460 trtcm_rfc2698, "trtcm_rfc2698");
461 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_port_id =
462 TOKEN_NUM_INITIALIZER(
463 struct cmd_add_port_meter_profile_trtcm_result,
465 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_profile_id =
466 TOKEN_NUM_INITIALIZER(
467 struct cmd_add_port_meter_profile_trtcm_result,
469 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cir =
470 TOKEN_NUM_INITIALIZER(
471 struct cmd_add_port_meter_profile_trtcm_result,
473 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pir =
474 TOKEN_NUM_INITIALIZER(
475 struct cmd_add_port_meter_profile_trtcm_result,
477 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cbs =
478 TOKEN_NUM_INITIALIZER(
479 struct cmd_add_port_meter_profile_trtcm_result,
481 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pbs =
482 TOKEN_NUM_INITIALIZER(
483 struct cmd_add_port_meter_profile_trtcm_result,
486 static void cmd_add_port_meter_profile_trtcm_parsed(void *parsed_result,
487 __attribute__((unused)) struct cmdline *cl,
488 __attribute__((unused)) void *data)
490 struct cmd_add_port_meter_profile_trtcm_result *res = parsed_result;
491 struct rte_mtr_meter_profile mp;
492 struct rte_mtr_error error;
493 uint32_t profile_id = res->profile_id;
494 uint16_t port_id = res->port_id;
497 if (port_id_is_invalid(port_id, ENABLED_WARN))
500 /* Private shaper profile params */
501 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
502 mp.alg = RTE_MTR_TRTCM_RFC2698;
503 mp.trtcm_rfc2698.cir = res->cir;
504 mp.trtcm_rfc2698.pir = res->pir;
505 mp.trtcm_rfc2698.cbs = res->cbs;
506 mp.trtcm_rfc2698.pbs = res->pbs;
508 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
510 print_err_msg(&error);
515 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm = {
516 .f = cmd_add_port_meter_profile_trtcm_parsed,
518 .help_str = "Add port meter profile trtcm (rfc2698)",
520 (void *)&cmd_add_port_meter_profile_trtcm_add,
521 (void *)&cmd_add_port_meter_profile_trtcm_port,
522 (void *)&cmd_add_port_meter_profile_trtcm_meter,
523 (void *)&cmd_add_port_meter_profile_trtcm_profile,
524 (void *)&cmd_add_port_meter_profile_trtcm_trtcm_rfc2698,
525 (void *)&cmd_add_port_meter_profile_trtcm_port_id,
526 (void *)&cmd_add_port_meter_profile_trtcm_profile_id,
527 (void *)&cmd_add_port_meter_profile_trtcm_cir,
528 (void *)&cmd_add_port_meter_profile_trtcm_pir,
529 (void *)&cmd_add_port_meter_profile_trtcm_cbs,
530 (void *)&cmd_add_port_meter_profile_trtcm_pbs,
535 /* *** Add Port Meter Profile trtcm_rfc4115 *** */
536 struct cmd_add_port_meter_profile_trtcm_rfc4115_result {
537 cmdline_fixed_string_t add;
538 cmdline_fixed_string_t port;
539 cmdline_fixed_string_t meter;
540 cmdline_fixed_string_t profile;
541 cmdline_fixed_string_t trtcm_rfc4115;
550 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_add =
551 TOKEN_STRING_INITIALIZER(
552 struct cmd_add_port_meter_profile_trtcm_rfc4115_result, add,
554 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_port =
555 TOKEN_STRING_INITIALIZER(
556 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
558 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_meter =
559 TOKEN_STRING_INITIALIZER(
560 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
562 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_profile =
563 TOKEN_STRING_INITIALIZER(
564 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
566 cmdline_parse_token_string_t
567 cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115 =
568 TOKEN_STRING_INITIALIZER(
569 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
570 trtcm_rfc4115, "trtcm_rfc4115");
571 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_port_id =
572 TOKEN_NUM_INITIALIZER(
573 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
575 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_profile_id =
576 TOKEN_NUM_INITIALIZER(
577 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
579 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cir =
580 TOKEN_NUM_INITIALIZER(
581 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
583 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_eir =
584 TOKEN_NUM_INITIALIZER(
585 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
587 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cbs =
588 TOKEN_NUM_INITIALIZER(
589 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
591 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_ebs =
592 TOKEN_NUM_INITIALIZER(
593 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
596 static void cmd_add_port_meter_profile_trtcm_rfc4115_parsed(
598 __attribute__((unused)) struct cmdline *cl,
599 __attribute__((unused)) void *data)
601 struct cmd_add_port_meter_profile_trtcm_rfc4115_result *res =
603 struct rte_mtr_meter_profile mp;
604 struct rte_mtr_error error;
605 uint32_t profile_id = res->profile_id;
606 uint16_t port_id = res->port_id;
609 if (port_id_is_invalid(port_id, ENABLED_WARN))
612 /* Private shaper profile params */
613 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
614 mp.alg = RTE_MTR_TRTCM_RFC4115;
615 mp.trtcm_rfc4115.cir = res->cir;
616 mp.trtcm_rfc4115.eir = res->eir;
617 mp.trtcm_rfc4115.cbs = res->cbs;
618 mp.trtcm_rfc4115.ebs = res->ebs;
620 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
622 print_err_msg(&error);
627 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm_rfc4115 = {
628 .f = cmd_add_port_meter_profile_trtcm_rfc4115_parsed,
630 .help_str = "Add port meter profile trtcm (rfc4115)",
632 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_add,
633 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port,
634 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_meter,
635 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile,
636 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115,
637 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port_id,
638 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile_id,
639 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cir,
640 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_eir,
641 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cbs,
642 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_ebs,
647 /* *** Delete Port Meter Profile *** */
648 struct cmd_del_port_meter_profile_result {
649 cmdline_fixed_string_t del;
650 cmdline_fixed_string_t port;
651 cmdline_fixed_string_t meter;
652 cmdline_fixed_string_t profile;
657 cmdline_parse_token_string_t cmd_del_port_meter_profile_del =
658 TOKEN_STRING_INITIALIZER(
659 struct cmd_del_port_meter_profile_result, del, "del");
660 cmdline_parse_token_string_t cmd_del_port_meter_profile_port =
661 TOKEN_STRING_INITIALIZER(
662 struct cmd_del_port_meter_profile_result,
664 cmdline_parse_token_string_t cmd_del_port_meter_profile_meter =
665 TOKEN_STRING_INITIALIZER(
666 struct cmd_del_port_meter_profile_result,
668 cmdline_parse_token_string_t cmd_del_port_meter_profile_profile =
669 TOKEN_STRING_INITIALIZER(
670 struct cmd_del_port_meter_profile_result,
672 cmdline_parse_token_num_t cmd_del_port_meter_profile_port_id =
673 TOKEN_NUM_INITIALIZER(
674 struct cmd_del_port_meter_profile_result,
676 cmdline_parse_token_num_t cmd_del_port_meter_profile_profile_id =
677 TOKEN_NUM_INITIALIZER(
678 struct cmd_del_port_meter_profile_result,
681 static void cmd_del_port_meter_profile_parsed(void *parsed_result,
682 __attribute__((unused)) struct cmdline *cl,
683 __attribute__((unused)) void *data)
685 struct cmd_del_port_meter_profile_result *res = parsed_result;
686 struct rte_mtr_error error;
687 uint32_t profile_id = res->profile_id;
688 uint16_t port_id = res->port_id;
691 if (port_id_is_invalid(port_id, ENABLED_WARN))
694 /* Delete meter profile */
695 ret = rte_mtr_meter_profile_delete(port_id, profile_id, &error);
697 print_err_msg(&error);
702 cmdline_parse_inst_t cmd_del_port_meter_profile = {
703 .f = cmd_del_port_meter_profile_parsed,
705 .help_str = "Delete port meter profile",
707 (void *)&cmd_del_port_meter_profile_del,
708 (void *)&cmd_del_port_meter_profile_port,
709 (void *)&cmd_del_port_meter_profile_meter,
710 (void *)&cmd_del_port_meter_profile_profile,
711 (void *)&cmd_del_port_meter_profile_port_id,
712 (void *)&cmd_del_port_meter_profile_profile_id,
717 /* *** Create Port Meter Object *** */
718 struct cmd_create_port_meter_result {
719 cmdline_fixed_string_t create;
720 cmdline_fixed_string_t port;
721 cmdline_fixed_string_t meter;
725 cmdline_fixed_string_t meter_enable;
726 cmdline_fixed_string_t g_action;
727 cmdline_fixed_string_t y_action;
728 cmdline_fixed_string_t r_action;
729 uint64_t statistics_mask;
731 cmdline_multi_string_t meter_input_color;
734 cmdline_parse_token_string_t cmd_create_port_meter_create =
735 TOKEN_STRING_INITIALIZER(
736 struct cmd_create_port_meter_result, create, "create");
737 cmdline_parse_token_string_t cmd_create_port_meter_port =
738 TOKEN_STRING_INITIALIZER(
739 struct cmd_create_port_meter_result, port, "port");
740 cmdline_parse_token_string_t cmd_create_port_meter_meter =
741 TOKEN_STRING_INITIALIZER(
742 struct cmd_create_port_meter_result, meter, "meter");
743 cmdline_parse_token_num_t cmd_create_port_meter_port_id =
744 TOKEN_NUM_INITIALIZER(
745 struct cmd_create_port_meter_result, port_id, UINT16);
746 cmdline_parse_token_num_t cmd_create_port_meter_mtr_id =
747 TOKEN_NUM_INITIALIZER(
748 struct cmd_create_port_meter_result, mtr_id, UINT32);
749 cmdline_parse_token_num_t cmd_create_port_meter_profile_id =
750 TOKEN_NUM_INITIALIZER(
751 struct cmd_create_port_meter_result, profile_id, UINT32);
752 cmdline_parse_token_string_t cmd_create_port_meter_meter_enable =
753 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
754 meter_enable, "yes#no");
755 cmdline_parse_token_string_t cmd_create_port_meter_g_action =
756 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
757 g_action, "R#Y#G#D#r#y#g#d");
758 cmdline_parse_token_string_t cmd_create_port_meter_y_action =
759 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
760 y_action, "R#Y#G#D#r#y#g#d");
761 cmdline_parse_token_string_t cmd_create_port_meter_r_action =
762 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
763 r_action, "R#Y#G#D#r#y#g#d");
764 cmdline_parse_token_num_t cmd_create_port_meter_statistics_mask =
765 TOKEN_NUM_INITIALIZER(struct cmd_create_port_meter_result,
766 statistics_mask, UINT64);
767 cmdline_parse_token_num_t cmd_create_port_meter_shared =
768 TOKEN_NUM_INITIALIZER(struct cmd_create_port_meter_result,
770 cmdline_parse_token_string_t cmd_create_port_meter_input_color =
771 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
772 meter_input_color, TOKEN_STRING_MULTI);
774 static void cmd_create_port_meter_parsed(void *parsed_result,
775 __attribute__((unused)) struct cmdline *cl,
776 __attribute__((unused)) void *data)
778 struct cmd_create_port_meter_result *res = parsed_result;
779 struct rte_mtr_error error;
780 struct rte_mtr_params params;
781 uint32_t mtr_id = res->mtr_id;
782 uint32_t shared = res->shared;
783 uint32_t use_prev_meter_color = 0;
784 uint16_t port_id = res->port_id;
785 enum rte_mtr_color *dscp_table = NULL;
786 char *c_str = res->meter_input_color;
789 if (port_id_is_invalid(port_id, ENABLED_WARN))
793 memset(¶ms, 0, sizeof(struct rte_mtr_params));
794 params.meter_profile_id = res->profile_id;
796 /* Parse meter input color string params */
797 ret = parse_meter_color_str(c_str, &use_prev_meter_color, dscp_table);
799 printf(" Meter input color params string parse error\n");
803 params.use_prev_mtr_color = use_prev_meter_color;
804 params.dscp_table = dscp_table;
806 if (strcmp(res->meter_enable, "yes") == 0)
807 params.meter_enable = 1;
809 params.meter_enable = 0;
811 params.action[RTE_MTR_GREEN] =
812 string_to_policer_action(res->g_action);
813 params.action[RTE_MTR_YELLOW] =
814 string_to_policer_action(res->y_action);
815 params.action[RTE_MTR_RED] =
816 string_to_policer_action(res->r_action);
817 params.stats_mask = res->statistics_mask;
819 ret = rte_mtr_create(port_id, mtr_id, ¶ms, shared, &error);
822 print_err_msg(&error);
827 cmdline_parse_inst_t cmd_create_port_meter = {
828 .f = cmd_create_port_meter_parsed,
830 .help_str = "Create port meter",
832 (void *)&cmd_create_port_meter_create,
833 (void *)&cmd_create_port_meter_port,
834 (void *)&cmd_create_port_meter_meter,
835 (void *)&cmd_create_port_meter_port_id,
836 (void *)&cmd_create_port_meter_mtr_id,
837 (void *)&cmd_create_port_meter_profile_id,
838 (void *)&cmd_create_port_meter_meter_enable,
839 (void *)&cmd_create_port_meter_g_action,
840 (void *)&cmd_create_port_meter_y_action,
841 (void *)&cmd_create_port_meter_r_action,
842 (void *)&cmd_create_port_meter_statistics_mask,
843 (void *)&cmd_create_port_meter_shared,
844 (void *)&cmd_create_port_meter_input_color,
849 /* *** Enable Meter of MTR Object *** */
850 struct cmd_enable_port_meter_result {
851 cmdline_fixed_string_t enable;
852 cmdline_fixed_string_t port;
853 cmdline_fixed_string_t meter;
858 cmdline_parse_token_string_t cmd_enable_port_meter_enable =
859 TOKEN_STRING_INITIALIZER(
860 struct cmd_enable_port_meter_result, enable, "enable");
861 cmdline_parse_token_string_t cmd_enable_port_meter_port =
862 TOKEN_STRING_INITIALIZER(
863 struct cmd_enable_port_meter_result, port, "port");
864 cmdline_parse_token_string_t cmd_enable_port_meter_meter =
865 TOKEN_STRING_INITIALIZER(
866 struct cmd_enable_port_meter_result, meter, "meter");
867 cmdline_parse_token_num_t cmd_enable_port_meter_port_id =
868 TOKEN_NUM_INITIALIZER(
869 struct cmd_enable_port_meter_result, port_id, UINT16);
870 cmdline_parse_token_num_t cmd_enable_port_meter_mtr_id =
871 TOKEN_NUM_INITIALIZER(
872 struct cmd_enable_port_meter_result, mtr_id, UINT32);
874 static void cmd_enable_port_meter_parsed(void *parsed_result,
875 __attribute__((unused)) struct cmdline *cl,
876 __attribute__((unused)) void *data)
878 struct cmd_enable_port_meter_result *res = parsed_result;
879 struct rte_mtr_error error;
880 uint32_t mtr_id = res->mtr_id;
881 uint16_t port_id = res->port_id;
885 if (port_id_is_invalid(port_id, ENABLED_WARN))
889 ret = rte_mtr_meter_enable(port_id, mtr_id, &error);
891 print_err_msg(&error);
896 cmdline_parse_inst_t cmd_enable_port_meter = {
897 .f = cmd_enable_port_meter_parsed,
899 .help_str = "Enable port meter",
901 (void *)&cmd_enable_port_meter_enable,
902 (void *)&cmd_enable_port_meter_port,
903 (void *)&cmd_enable_port_meter_meter,
904 (void *)&cmd_enable_port_meter_port_id,
905 (void *)&cmd_enable_port_meter_mtr_id,
910 /* *** Disable Meter of MTR Object *** */
911 struct cmd_disable_port_meter_result {
912 cmdline_fixed_string_t disable;
913 cmdline_fixed_string_t port;
914 cmdline_fixed_string_t meter;
919 cmdline_parse_token_string_t cmd_disable_port_meter_disable =
920 TOKEN_STRING_INITIALIZER(
921 struct cmd_disable_port_meter_result, disable, "disable");
922 cmdline_parse_token_string_t cmd_disable_port_meter_port =
923 TOKEN_STRING_INITIALIZER(
924 struct cmd_disable_port_meter_result, port, "port");
925 cmdline_parse_token_string_t cmd_disable_port_meter_meter =
926 TOKEN_STRING_INITIALIZER(
927 struct cmd_disable_port_meter_result, meter, "meter");
928 cmdline_parse_token_num_t cmd_disable_port_meter_port_id =
929 TOKEN_NUM_INITIALIZER(
930 struct cmd_disable_port_meter_result, port_id, UINT16);
931 cmdline_parse_token_num_t cmd_disable_port_meter_mtr_id =
932 TOKEN_NUM_INITIALIZER(
933 struct cmd_disable_port_meter_result, mtr_id, UINT32);
935 static void cmd_disable_port_meter_parsed(void *parsed_result,
936 __attribute__((unused)) struct cmdline *cl,
937 __attribute__((unused)) void *data)
939 struct cmd_disable_port_meter_result *res = parsed_result;
940 struct rte_mtr_error error;
941 uint32_t mtr_id = res->mtr_id;
942 uint16_t port_id = res->port_id;
946 if (port_id_is_invalid(port_id, ENABLED_WARN))
950 ret = rte_mtr_meter_disable(port_id, mtr_id, &error);
952 print_err_msg(&error);
957 cmdline_parse_inst_t cmd_disable_port_meter = {
958 .f = cmd_disable_port_meter_parsed,
960 .help_str = "Disable port meter",
962 (void *)&cmd_disable_port_meter_disable,
963 (void *)&cmd_disable_port_meter_port,
964 (void *)&cmd_disable_port_meter_meter,
965 (void *)&cmd_disable_port_meter_port_id,
966 (void *)&cmd_disable_port_meter_mtr_id,
971 /* *** Delete Port Meter Object *** */
972 struct cmd_del_port_meter_result {
973 cmdline_fixed_string_t del;
974 cmdline_fixed_string_t port;
975 cmdline_fixed_string_t meter;
980 cmdline_parse_token_string_t cmd_del_port_meter_del =
981 TOKEN_STRING_INITIALIZER(
982 struct cmd_del_port_meter_result, del, "del");
983 cmdline_parse_token_string_t cmd_del_port_meter_port =
984 TOKEN_STRING_INITIALIZER(
985 struct cmd_del_port_meter_result, port, "port");
986 cmdline_parse_token_string_t cmd_del_port_meter_meter =
987 TOKEN_STRING_INITIALIZER(
988 struct cmd_del_port_meter_result, meter, "meter");
989 cmdline_parse_token_num_t cmd_del_port_meter_port_id =
990 TOKEN_NUM_INITIALIZER(
991 struct cmd_del_port_meter_result, port_id, UINT16);
992 cmdline_parse_token_num_t cmd_del_port_meter_mtr_id =
993 TOKEN_NUM_INITIALIZER(
994 struct cmd_del_port_meter_result, mtr_id, UINT32);
996 static void cmd_del_port_meter_parsed(void *parsed_result,
997 __attribute__((unused)) struct cmdline *cl,
998 __attribute__((unused)) void *data)
1000 struct cmd_del_port_meter_result *res = parsed_result;
1001 struct rte_mtr_error error;
1002 uint32_t mtr_id = res->mtr_id;
1003 uint16_t port_id = res->port_id;
1007 if (port_id_is_invalid(port_id, ENABLED_WARN))
1011 ret = rte_mtr_destroy(port_id, mtr_id, &error);
1013 print_err_msg(&error);
1018 cmdline_parse_inst_t cmd_del_port_meter = {
1019 .f = cmd_del_port_meter_parsed,
1021 .help_str = "Delete port meter",
1023 (void *)&cmd_del_port_meter_del,
1024 (void *)&cmd_del_port_meter_port,
1025 (void *)&cmd_del_port_meter_meter,
1026 (void *)&cmd_del_port_meter_port_id,
1027 (void *)&cmd_del_port_meter_mtr_id,
1032 /* *** Set Port Meter Profile *** */
1033 struct cmd_set_port_meter_profile_result {
1034 cmdline_fixed_string_t set;
1035 cmdline_fixed_string_t port;
1036 cmdline_fixed_string_t meter;
1037 cmdline_fixed_string_t profile;
1040 uint32_t profile_id;
1043 cmdline_parse_token_string_t cmd_set_port_meter_profile_set =
1044 TOKEN_STRING_INITIALIZER(
1045 struct cmd_set_port_meter_profile_result, set, "set");
1046 cmdline_parse_token_string_t cmd_set_port_meter_profile_port =
1047 TOKEN_STRING_INITIALIZER(
1048 struct cmd_set_port_meter_profile_result, port, "port");
1049 cmdline_parse_token_string_t cmd_set_port_meter_profile_meter =
1050 TOKEN_STRING_INITIALIZER(
1051 struct cmd_set_port_meter_profile_result, meter, "meter");
1052 cmdline_parse_token_string_t cmd_set_port_meter_profile_profile =
1053 TOKEN_STRING_INITIALIZER(
1054 struct cmd_set_port_meter_profile_result, profile, "profile");
1055 cmdline_parse_token_num_t cmd_set_port_meter_profile_port_id =
1056 TOKEN_NUM_INITIALIZER(
1057 struct cmd_set_port_meter_profile_result, port_id, UINT16);
1058 cmdline_parse_token_num_t cmd_set_port_meter_profile_mtr_id =
1059 TOKEN_NUM_INITIALIZER(
1060 struct cmd_set_port_meter_profile_result, mtr_id, UINT32);
1061 cmdline_parse_token_num_t cmd_set_port_meter_profile_profile_id =
1062 TOKEN_NUM_INITIALIZER(
1063 struct cmd_set_port_meter_profile_result, profile_id, UINT32);
1065 static void cmd_set_port_meter_profile_parsed(void *parsed_result,
1066 __attribute__((unused)) struct cmdline *cl,
1067 __attribute__((unused)) void *data)
1069 struct cmd_set_port_meter_profile_result *res = parsed_result;
1070 struct rte_mtr_error error;
1071 uint32_t mtr_id = res->mtr_id;
1072 uint32_t profile_id = res->profile_id;
1073 uint16_t port_id = res->port_id;
1077 if (port_id_is_invalid(port_id, ENABLED_WARN))
1080 /* Set meter profile */
1081 ret = rte_mtr_meter_profile_update(port_id, mtr_id,
1082 profile_id, &error);
1084 print_err_msg(&error);
1089 cmdline_parse_inst_t cmd_set_port_meter_profile = {
1090 .f = cmd_set_port_meter_profile_parsed,
1092 .help_str = "Set port meter profile",
1094 (void *)&cmd_set_port_meter_profile_set,
1095 (void *)&cmd_set_port_meter_profile_port,
1096 (void *)&cmd_set_port_meter_profile_meter,
1097 (void *)&cmd_set_port_meter_profile_profile,
1098 (void *)&cmd_set_port_meter_profile_port_id,
1099 (void *)&cmd_set_port_meter_profile_mtr_id,
1100 (void *)&cmd_set_port_meter_profile_profile_id,
1105 /* *** Set Port Meter DSCP Table *** */
1106 struct cmd_set_port_meter_dscp_table_result {
1107 cmdline_fixed_string_t set;
1108 cmdline_fixed_string_t port;
1109 cmdline_fixed_string_t meter;
1110 cmdline_fixed_string_t dscp_table;
1111 cmdline_multi_string_t token_string;
1114 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_set =
1115 TOKEN_STRING_INITIALIZER(
1116 struct cmd_set_port_meter_dscp_table_result, set, "set");
1117 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_port =
1118 TOKEN_STRING_INITIALIZER(
1119 struct cmd_set_port_meter_dscp_table_result, port, "port");
1120 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_meter =
1121 TOKEN_STRING_INITIALIZER(
1122 struct cmd_set_port_meter_dscp_table_result, meter, "meter");
1123 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_dscp_table =
1124 TOKEN_STRING_INITIALIZER(
1125 struct cmd_set_port_meter_dscp_table_result,
1126 dscp_table, "dscp table");
1127 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_token_string =
1128 TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_dscp_table_result,
1129 token_string, TOKEN_STRING_MULTI);
1131 static void cmd_set_port_meter_dscp_table_parsed(void *parsed_result,
1132 __attribute__((unused)) struct cmdline *cl,
1133 __attribute__((unused)) void *data)
1135 struct cmd_set_port_meter_dscp_table_result *res = parsed_result;
1136 struct rte_mtr_error error;
1137 enum rte_mtr_color *dscp_table = NULL;
1138 char *t_str = res->token_string;
1139 uint32_t mtr_id = 0;
1144 ret = parse_multi_token_string(t_str, &port_id, &mtr_id, dscp_table);
1146 printf(" Multi token string parse error\n");
1150 if (port_id_is_invalid(port_id, ENABLED_WARN))
1153 /* Update Meter DSCP Table*/
1154 ret = rte_mtr_meter_dscp_table_update(port_id, mtr_id,
1155 dscp_table, &error);
1157 print_err_msg(&error);
1163 cmdline_parse_inst_t cmd_set_port_meter_dscp_table = {
1164 .f = cmd_set_port_meter_dscp_table_parsed,
1166 .help_str = "Update port meter dscp table",
1168 (void *)&cmd_set_port_meter_dscp_table_set,
1169 (void *)&cmd_set_port_meter_dscp_table_port,
1170 (void *)&cmd_set_port_meter_dscp_table_meter,
1171 (void *)&cmd_set_port_meter_dscp_table_dscp_table,
1172 (void *)&cmd_set_port_meter_dscp_table_token_string,
1177 /* *** Set Port Meter Policer Action *** */
1178 struct cmd_set_port_meter_policer_action_result {
1179 cmdline_fixed_string_t set;
1180 cmdline_fixed_string_t port;
1181 cmdline_fixed_string_t meter;
1182 cmdline_fixed_string_t policer;
1183 cmdline_fixed_string_t action;
1186 uint32_t action_mask;
1187 cmdline_multi_string_t policer_action;
1190 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_set =
1191 TOKEN_STRING_INITIALIZER(
1192 struct cmd_set_port_meter_policer_action_result, set, "set");
1193 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_port =
1194 TOKEN_STRING_INITIALIZER(
1195 struct cmd_set_port_meter_policer_action_result, port, "port");
1196 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_meter =
1197 TOKEN_STRING_INITIALIZER(
1198 struct cmd_set_port_meter_policer_action_result, meter,
1200 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_policer =
1201 TOKEN_STRING_INITIALIZER(
1202 struct cmd_set_port_meter_policer_action_result, policer,
1204 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_action =
1205 TOKEN_STRING_INITIALIZER(
1206 struct cmd_set_port_meter_policer_action_result, action,
1208 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_port_id =
1209 TOKEN_NUM_INITIALIZER(
1210 struct cmd_set_port_meter_policer_action_result, port_id,
1212 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_mtr_id =
1213 TOKEN_NUM_INITIALIZER(
1214 struct cmd_set_port_meter_policer_action_result, mtr_id,
1216 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_action_mask =
1217 TOKEN_NUM_INITIALIZER(
1218 struct cmd_set_port_meter_policer_action_result, action_mask,
1220 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_policer_action =
1221 TOKEN_STRING_INITIALIZER(
1222 struct cmd_set_port_meter_policer_action_result,
1223 policer_action, TOKEN_STRING_MULTI);
1225 static void cmd_set_port_meter_policer_action_parsed(void *parsed_result,
1226 __attribute__((unused)) struct cmdline *cl,
1227 __attribute__((unused)) void *data)
1229 struct cmd_set_port_meter_policer_action_result *res = parsed_result;
1230 enum rte_mtr_policer_action *actions;
1231 struct rte_mtr_error error;
1232 uint32_t mtr_id = res->mtr_id;
1233 uint32_t action_mask = res->action_mask;
1234 uint16_t port_id = res->port_id;
1235 char *p_str = res->policer_action;
1238 if (port_id_is_invalid(port_id, ENABLED_WARN))
1241 /* Check: action mask */
1242 if (action_mask == 0 || (action_mask & (~0x7UL))) {
1243 printf(" Policer action mask not correct (error)\n");
1247 /* Allocate memory for policer actions */
1248 actions = (enum rte_mtr_policer_action *)malloc(RTE_MTR_COLORS *
1249 sizeof(enum rte_mtr_policer_action));
1250 if (actions == NULL) {
1251 printf("Memory for policer actions not allocated (error)\n");
1254 /* Parse policer action string */
1255 ret = parse_policer_action_string(p_str, action_mask, actions);
1257 printf(" Policer action string parse error\n");
1262 ret = rte_mtr_policer_actions_update(port_id, mtr_id,
1263 action_mask, actions, &error);
1265 print_err_msg(&error);
1272 cmdline_parse_inst_t cmd_set_port_meter_policer_action = {
1273 .f = cmd_set_port_meter_policer_action_parsed,
1275 .help_str = "Set port meter policer action",
1277 (void *)&cmd_set_port_meter_policer_action_set,
1278 (void *)&cmd_set_port_meter_policer_action_port,
1279 (void *)&cmd_set_port_meter_policer_action_meter,
1280 (void *)&cmd_set_port_meter_policer_action_policer,
1281 (void *)&cmd_set_port_meter_policer_action_action,
1282 (void *)&cmd_set_port_meter_policer_action_port_id,
1283 (void *)&cmd_set_port_meter_policer_action_mtr_id,
1284 (void *)&cmd_set_port_meter_policer_action_action_mask,
1285 (void *)&cmd_set_port_meter_policer_action_policer_action,
1290 /* *** Set Port Meter Stats Mask *** */
1291 struct cmd_set_port_meter_stats_mask_result {
1292 cmdline_fixed_string_t set;
1293 cmdline_fixed_string_t port;
1294 cmdline_fixed_string_t meter;
1295 cmdline_fixed_string_t stats;
1296 cmdline_fixed_string_t mask;
1299 uint64_t stats_mask;
1302 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_set =
1303 TOKEN_STRING_INITIALIZER(
1304 struct cmd_set_port_meter_stats_mask_result, set, "set");
1305 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_port =
1306 TOKEN_STRING_INITIALIZER(
1307 struct cmd_set_port_meter_stats_mask_result, port, "port");
1308 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_meter =
1309 TOKEN_STRING_INITIALIZER(
1310 struct cmd_set_port_meter_stats_mask_result, meter, "meter");
1311 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_stats =
1312 TOKEN_STRING_INITIALIZER(
1313 struct cmd_set_port_meter_stats_mask_result, stats, "stats");
1314 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_mask =
1315 TOKEN_STRING_INITIALIZER(
1316 struct cmd_set_port_meter_stats_mask_result, mask, "mask");
1317 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_port_id =
1318 TOKEN_NUM_INITIALIZER(
1319 struct cmd_set_port_meter_stats_mask_result, port_id, UINT16);
1320 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_mtr_id =
1321 TOKEN_NUM_INITIALIZER(
1322 struct cmd_set_port_meter_stats_mask_result, mtr_id, UINT32);
1323 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_stats_mask =
1324 TOKEN_NUM_INITIALIZER(
1325 struct cmd_set_port_meter_stats_mask_result, stats_mask,
1328 static void cmd_set_port_meter_stats_mask_parsed(void *parsed_result,
1329 __attribute__((unused)) struct cmdline *cl,
1330 __attribute__((unused)) void *data)
1332 struct cmd_set_port_meter_stats_mask_result *res = parsed_result;
1333 struct rte_mtr_error error;
1334 uint64_t stats_mask = res->stats_mask;
1335 uint32_t mtr_id = res->mtr_id;
1336 uint16_t port_id = res->port_id;
1339 if (port_id_is_invalid(port_id, ENABLED_WARN))
1342 ret = rte_mtr_stats_update(port_id, mtr_id, stats_mask, &error);
1344 print_err_msg(&error);
1349 cmdline_parse_inst_t cmd_set_port_meter_stats_mask = {
1350 .f = cmd_set_port_meter_stats_mask_parsed,
1352 .help_str = "Set port meter stats mask",
1354 (void *)&cmd_set_port_meter_stats_mask_set,
1355 (void *)&cmd_set_port_meter_stats_mask_port,
1356 (void *)&cmd_set_port_meter_stats_mask_meter,
1357 (void *)&cmd_set_port_meter_stats_mask_stats,
1358 (void *)&cmd_set_port_meter_stats_mask_mask,
1359 (void *)&cmd_set_port_meter_stats_mask_port_id,
1360 (void *)&cmd_set_port_meter_stats_mask_mtr_id,
1361 (void *)&cmd_set_port_meter_stats_mask_stats_mask,
1366 /* *** Show Port Meter Stats *** */
1367 struct cmd_show_port_meter_stats_result {
1368 cmdline_fixed_string_t show;
1369 cmdline_fixed_string_t port;
1370 cmdline_fixed_string_t meter;
1371 cmdline_fixed_string_t stats;
1374 cmdline_fixed_string_t clear;
1377 cmdline_parse_token_string_t cmd_show_port_meter_stats_show =
1378 TOKEN_STRING_INITIALIZER(
1379 struct cmd_show_port_meter_stats_result, show, "show");
1380 cmdline_parse_token_string_t cmd_show_port_meter_stats_port =
1381 TOKEN_STRING_INITIALIZER(
1382 struct cmd_show_port_meter_stats_result, port, "port");
1383 cmdline_parse_token_string_t cmd_show_port_meter_stats_meter =
1384 TOKEN_STRING_INITIALIZER(
1385 struct cmd_show_port_meter_stats_result, meter, "meter");
1386 cmdline_parse_token_string_t cmd_show_port_meter_stats_stats =
1387 TOKEN_STRING_INITIALIZER(
1388 struct cmd_show_port_meter_stats_result, stats, "stats");
1389 cmdline_parse_token_num_t cmd_show_port_meter_stats_port_id =
1390 TOKEN_NUM_INITIALIZER(
1391 struct cmd_show_port_meter_stats_result, port_id, UINT16);
1392 cmdline_parse_token_num_t cmd_show_port_meter_stats_mtr_id =
1393 TOKEN_NUM_INITIALIZER(
1394 struct cmd_show_port_meter_stats_result, mtr_id, UINT32);
1395 cmdline_parse_token_string_t cmd_show_port_meter_stats_clear =
1396 TOKEN_STRING_INITIALIZER(
1397 struct cmd_show_port_meter_stats_result, clear, "yes#no");
1399 static void cmd_show_port_meter_stats_parsed(void *parsed_result,
1400 __attribute__((unused)) struct cmdline *cl,
1401 __attribute__((unused)) void *data)
1403 struct cmd_show_port_meter_stats_result *res = parsed_result;
1404 struct rte_mtr_stats stats;
1405 uint64_t stats_mask = 0;
1406 struct rte_mtr_error error;
1407 uint32_t mtr_id = res->mtr_id;
1409 uint16_t port_id = res->port_id;
1412 if (port_id_is_invalid(port_id, ENABLED_WARN))
1415 if (strcmp(res->clear, "yes") == 0)
1418 memset(&stats, 0, sizeof(struct rte_mtr_stats));
1419 ret = rte_mtr_stats_read(port_id, mtr_id, &stats,
1420 &stats_mask, clear, &error);
1422 print_err_msg(&error);
1427 if (stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
1428 printf("\tPkts G: %" PRIu64 "\n",
1429 stats.n_pkts[RTE_MTR_GREEN]);
1430 if (stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
1431 printf("\tBytes G: %" PRIu64 "\n",
1432 stats.n_bytes[RTE_MTR_GREEN]);
1433 if (stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
1434 printf("\tPkts Y: %" PRIu64 "\n",
1435 stats.n_pkts[RTE_MTR_YELLOW]);
1436 if (stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
1437 printf("\tBytes Y: %" PRIu64 "\n",
1438 stats.n_bytes[RTE_MTR_YELLOW]);
1439 if (stats_mask & RTE_MTR_STATS_N_PKTS_RED)
1440 printf("\tPkts R: %" PRIu64 "\n",
1441 stats.n_pkts[RTE_MTR_RED]);
1442 if (stats_mask & RTE_MTR_STATS_N_BYTES_RED)
1443 printf("\tBytes Y: %" PRIu64 "\n",
1444 stats.n_bytes[RTE_MTR_RED]);
1445 if (stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
1446 printf("\tPkts DROPPED: %" PRIu64 "\n",
1447 stats.n_pkts_dropped);
1448 if (stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
1449 printf("\tBytes DROPPED: %" PRIu64 "\n",
1450 stats.n_bytes_dropped);
1453 cmdline_parse_inst_t cmd_show_port_meter_stats = {
1454 .f = cmd_show_port_meter_stats_parsed,
1456 .help_str = "Show port meter stats",
1458 (void *)&cmd_show_port_meter_stats_show,
1459 (void *)&cmd_show_port_meter_stats_port,
1460 (void *)&cmd_show_port_meter_stats_meter,
1461 (void *)&cmd_show_port_meter_stats_stats,
1462 (void *)&cmd_show_port_meter_stats_port_id,
1463 (void *)&cmd_show_port_meter_stats_mtr_id,
1464 (void *)&cmd_show_port_meter_stats_clear,