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_color **dscp_table)
82 token = strtok_r(str, PARSE_DELIMITER, &str);
86 /* Allocate memory for dscp table */
87 *dscp_table = (enum rte_color *)malloc(MAX_DSCP_TABLE_ENTRIES *
88 sizeof(enum rte_color));
89 if (*dscp_table == NULL)
93 if (strcmp(token, "G") == 0 ||
94 strcmp(token, "g") == 0)
95 *dscp_table[i++] = RTE_COLOR_GREEN;
96 else if (strcmp(token, "Y") == 0 ||
97 strcmp(token, "y") == 0)
98 *dscp_table[i++] = RTE_COLOR_YELLOW;
99 else if (strcmp(token, "R") == 0 ||
100 strcmp(token, "r") == 0)
101 *dscp_table[i++] = RTE_COLOR_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_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_COLOR_GREEN] = action;
187 } else if (y_color == 0 && (action_mask & 0x2)) {
188 actions[RTE_COLOR_YELLOW] = action;
191 actions[RTE_COLOR_RED] = action;
197 parse_multi_token_string(char *t_str, uint16_t *port_id,
198 uint32_t *mtr_id, enum rte_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, RTE_UINT16);
258 static void cmd_show_port_meter_cap_parsed(void *parsed_result,
259 __rte_unused struct cmdline *cl,
260 __rte_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 <port_id>",
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,
362 port_id, RTE_UINT16);
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,
366 profile_id, RTE_UINT32);
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 __rte_unused struct cmdline *cl,
382 __rte_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 <port_id> <profile_id> <cir> <cbs> <ebs>",
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,
464 port_id, RTE_UINT16);
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,
468 profile_id, RTE_UINT32);
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 __rte_unused struct cmdline *cl,
488 __rte_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 <port_id> <profile_id> <cir> <pir> <cbs> <pbs>",
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,
574 port_id, RTE_UINT16);
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,
578 profile_id, RTE_UINT32);
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 __rte_unused struct cmdline *cl,
599 __rte_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 <port_id> <profile_id> <cir> <eir> <cbs> <ebs>",
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,
675 port_id, RTE_UINT16);
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,
679 profile_id, RTE_UINT32);
681 static void cmd_del_port_meter_profile_parsed(void *parsed_result,
682 __rte_unused struct cmdline *cl,
683 __rte_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 = "del port meter profile <port_id> <profile_id>",
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, RTE_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, RTE_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, RTE_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, RTE_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 __rte_unused struct cmdline *cl,
776 __rte_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_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_COLOR_GREEN] =
812 string_to_policer_action(res->g_action);
813 params.action[RTE_COLOR_YELLOW] =
814 string_to_policer_action(res->y_action);
815 params.action[RTE_COLOR_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 <port_id> <mtr_id> <profile_id> <meter_enable>(yes|no) "
831 "<g_action>(R|Y|G|D) <y_action>(R|Y|G|D) <r_action>(R|Y|G|D) "
832 "<stats_mask> <shared> <use_pre_meter_color> "
833 "[<dscp_tbl_entry0> <dscp_tbl_entry1> ...<dscp_tbl_entry63>]",
835 (void *)&cmd_create_port_meter_create,
836 (void *)&cmd_create_port_meter_port,
837 (void *)&cmd_create_port_meter_meter,
838 (void *)&cmd_create_port_meter_port_id,
839 (void *)&cmd_create_port_meter_mtr_id,
840 (void *)&cmd_create_port_meter_profile_id,
841 (void *)&cmd_create_port_meter_meter_enable,
842 (void *)&cmd_create_port_meter_g_action,
843 (void *)&cmd_create_port_meter_y_action,
844 (void *)&cmd_create_port_meter_r_action,
845 (void *)&cmd_create_port_meter_statistics_mask,
846 (void *)&cmd_create_port_meter_shared,
847 (void *)&cmd_create_port_meter_input_color,
852 /* *** Enable Meter of MTR Object *** */
853 struct cmd_enable_port_meter_result {
854 cmdline_fixed_string_t enable;
855 cmdline_fixed_string_t port;
856 cmdline_fixed_string_t meter;
861 cmdline_parse_token_string_t cmd_enable_port_meter_enable =
862 TOKEN_STRING_INITIALIZER(
863 struct cmd_enable_port_meter_result, enable, "enable");
864 cmdline_parse_token_string_t cmd_enable_port_meter_port =
865 TOKEN_STRING_INITIALIZER(
866 struct cmd_enable_port_meter_result, port, "port");
867 cmdline_parse_token_string_t cmd_enable_port_meter_meter =
868 TOKEN_STRING_INITIALIZER(
869 struct cmd_enable_port_meter_result, meter, "meter");
870 cmdline_parse_token_num_t cmd_enable_port_meter_port_id =
871 TOKEN_NUM_INITIALIZER(
872 struct cmd_enable_port_meter_result, port_id, RTE_UINT16);
873 cmdline_parse_token_num_t cmd_enable_port_meter_mtr_id =
874 TOKEN_NUM_INITIALIZER(
875 struct cmd_enable_port_meter_result, mtr_id, RTE_UINT32);
877 static void cmd_enable_port_meter_parsed(void *parsed_result,
878 __rte_unused struct cmdline *cl,
879 __rte_unused void *data)
881 struct cmd_enable_port_meter_result *res = parsed_result;
882 struct rte_mtr_error error;
883 uint32_t mtr_id = res->mtr_id;
884 uint16_t port_id = res->port_id;
888 if (port_id_is_invalid(port_id, ENABLED_WARN))
892 ret = rte_mtr_meter_enable(port_id, mtr_id, &error);
894 print_err_msg(&error);
899 cmdline_parse_inst_t cmd_enable_port_meter = {
900 .f = cmd_enable_port_meter_parsed,
902 .help_str = "enable port meter <port_id> <mtr_id>",
904 (void *)&cmd_enable_port_meter_enable,
905 (void *)&cmd_enable_port_meter_port,
906 (void *)&cmd_enable_port_meter_meter,
907 (void *)&cmd_enable_port_meter_port_id,
908 (void *)&cmd_enable_port_meter_mtr_id,
913 /* *** Disable Meter of MTR Object *** */
914 struct cmd_disable_port_meter_result {
915 cmdline_fixed_string_t disable;
916 cmdline_fixed_string_t port;
917 cmdline_fixed_string_t meter;
922 cmdline_parse_token_string_t cmd_disable_port_meter_disable =
923 TOKEN_STRING_INITIALIZER(
924 struct cmd_disable_port_meter_result, disable, "disable");
925 cmdline_parse_token_string_t cmd_disable_port_meter_port =
926 TOKEN_STRING_INITIALIZER(
927 struct cmd_disable_port_meter_result, port, "port");
928 cmdline_parse_token_string_t cmd_disable_port_meter_meter =
929 TOKEN_STRING_INITIALIZER(
930 struct cmd_disable_port_meter_result, meter, "meter");
931 cmdline_parse_token_num_t cmd_disable_port_meter_port_id =
932 TOKEN_NUM_INITIALIZER(
933 struct cmd_disable_port_meter_result, port_id, RTE_UINT16);
934 cmdline_parse_token_num_t cmd_disable_port_meter_mtr_id =
935 TOKEN_NUM_INITIALIZER(
936 struct cmd_disable_port_meter_result, mtr_id, RTE_UINT32);
938 static void cmd_disable_port_meter_parsed(void *parsed_result,
939 __rte_unused struct cmdline *cl,
940 __rte_unused void *data)
942 struct cmd_disable_port_meter_result *res = parsed_result;
943 struct rte_mtr_error error;
944 uint32_t mtr_id = res->mtr_id;
945 uint16_t port_id = res->port_id;
949 if (port_id_is_invalid(port_id, ENABLED_WARN))
953 ret = rte_mtr_meter_disable(port_id, mtr_id, &error);
955 print_err_msg(&error);
960 cmdline_parse_inst_t cmd_disable_port_meter = {
961 .f = cmd_disable_port_meter_parsed,
963 .help_str = "disable port meter <port_id> <mtr_id>",
965 (void *)&cmd_disable_port_meter_disable,
966 (void *)&cmd_disable_port_meter_port,
967 (void *)&cmd_disable_port_meter_meter,
968 (void *)&cmd_disable_port_meter_port_id,
969 (void *)&cmd_disable_port_meter_mtr_id,
974 /* *** Delete Port Meter Object *** */
975 struct cmd_del_port_meter_result {
976 cmdline_fixed_string_t del;
977 cmdline_fixed_string_t port;
978 cmdline_fixed_string_t meter;
983 cmdline_parse_token_string_t cmd_del_port_meter_del =
984 TOKEN_STRING_INITIALIZER(
985 struct cmd_del_port_meter_result, del, "del");
986 cmdline_parse_token_string_t cmd_del_port_meter_port =
987 TOKEN_STRING_INITIALIZER(
988 struct cmd_del_port_meter_result, port, "port");
989 cmdline_parse_token_string_t cmd_del_port_meter_meter =
990 TOKEN_STRING_INITIALIZER(
991 struct cmd_del_port_meter_result, meter, "meter");
992 cmdline_parse_token_num_t cmd_del_port_meter_port_id =
993 TOKEN_NUM_INITIALIZER(
994 struct cmd_del_port_meter_result, port_id, RTE_UINT16);
995 cmdline_parse_token_num_t cmd_del_port_meter_mtr_id =
996 TOKEN_NUM_INITIALIZER(
997 struct cmd_del_port_meter_result, mtr_id, RTE_UINT32);
999 static void cmd_del_port_meter_parsed(void *parsed_result,
1000 __rte_unused struct cmdline *cl,
1001 __rte_unused void *data)
1003 struct cmd_del_port_meter_result *res = parsed_result;
1004 struct rte_mtr_error error;
1005 uint32_t mtr_id = res->mtr_id;
1006 uint16_t port_id = res->port_id;
1010 if (port_id_is_invalid(port_id, ENABLED_WARN))
1014 ret = rte_mtr_destroy(port_id, mtr_id, &error);
1016 print_err_msg(&error);
1021 cmdline_parse_inst_t cmd_del_port_meter = {
1022 .f = cmd_del_port_meter_parsed,
1024 .help_str = "del port meter <port_id> <mtr_id>",
1026 (void *)&cmd_del_port_meter_del,
1027 (void *)&cmd_del_port_meter_port,
1028 (void *)&cmd_del_port_meter_meter,
1029 (void *)&cmd_del_port_meter_port_id,
1030 (void *)&cmd_del_port_meter_mtr_id,
1035 /* *** Set Port Meter Profile *** */
1036 struct cmd_set_port_meter_profile_result {
1037 cmdline_fixed_string_t set;
1038 cmdline_fixed_string_t port;
1039 cmdline_fixed_string_t meter;
1040 cmdline_fixed_string_t profile;
1043 uint32_t profile_id;
1046 cmdline_parse_token_string_t cmd_set_port_meter_profile_set =
1047 TOKEN_STRING_INITIALIZER(
1048 struct cmd_set_port_meter_profile_result, set, "set");
1049 cmdline_parse_token_string_t cmd_set_port_meter_profile_port =
1050 TOKEN_STRING_INITIALIZER(
1051 struct cmd_set_port_meter_profile_result, port, "port");
1052 cmdline_parse_token_string_t cmd_set_port_meter_profile_meter =
1053 TOKEN_STRING_INITIALIZER(
1054 struct cmd_set_port_meter_profile_result, meter, "meter");
1055 cmdline_parse_token_string_t cmd_set_port_meter_profile_profile =
1056 TOKEN_STRING_INITIALIZER(
1057 struct cmd_set_port_meter_profile_result, profile, "profile");
1058 cmdline_parse_token_num_t cmd_set_port_meter_profile_port_id =
1059 TOKEN_NUM_INITIALIZER(
1060 struct cmd_set_port_meter_profile_result, port_id,
1062 cmdline_parse_token_num_t cmd_set_port_meter_profile_mtr_id =
1063 TOKEN_NUM_INITIALIZER(
1064 struct cmd_set_port_meter_profile_result, mtr_id,
1066 cmdline_parse_token_num_t cmd_set_port_meter_profile_profile_id =
1067 TOKEN_NUM_INITIALIZER(
1068 struct cmd_set_port_meter_profile_result, profile_id,
1071 static void cmd_set_port_meter_profile_parsed(void *parsed_result,
1072 __rte_unused struct cmdline *cl,
1073 __rte_unused void *data)
1075 struct cmd_set_port_meter_profile_result *res = parsed_result;
1076 struct rte_mtr_error error;
1077 uint32_t mtr_id = res->mtr_id;
1078 uint32_t profile_id = res->profile_id;
1079 uint16_t port_id = res->port_id;
1083 if (port_id_is_invalid(port_id, ENABLED_WARN))
1086 /* Set meter profile */
1087 ret = rte_mtr_meter_profile_update(port_id, mtr_id,
1088 profile_id, &error);
1090 print_err_msg(&error);
1095 cmdline_parse_inst_t cmd_set_port_meter_profile = {
1096 .f = cmd_set_port_meter_profile_parsed,
1098 .help_str = "set port meter profile <port_id> <mtr_id> <profile_id>",
1100 (void *)&cmd_set_port_meter_profile_set,
1101 (void *)&cmd_set_port_meter_profile_port,
1102 (void *)&cmd_set_port_meter_profile_meter,
1103 (void *)&cmd_set_port_meter_profile_profile,
1104 (void *)&cmd_set_port_meter_profile_port_id,
1105 (void *)&cmd_set_port_meter_profile_mtr_id,
1106 (void *)&cmd_set_port_meter_profile_profile_id,
1111 /* *** Set Port Meter DSCP Table *** */
1112 struct cmd_set_port_meter_dscp_table_result {
1113 cmdline_fixed_string_t set;
1114 cmdline_fixed_string_t port;
1115 cmdline_fixed_string_t meter;
1116 cmdline_fixed_string_t dscp_table;
1117 cmdline_multi_string_t token_string;
1120 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_set =
1121 TOKEN_STRING_INITIALIZER(
1122 struct cmd_set_port_meter_dscp_table_result, set, "set");
1123 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_port =
1124 TOKEN_STRING_INITIALIZER(
1125 struct cmd_set_port_meter_dscp_table_result, port, "port");
1126 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_meter =
1127 TOKEN_STRING_INITIALIZER(
1128 struct cmd_set_port_meter_dscp_table_result, meter, "meter");
1129 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_dscp_table =
1130 TOKEN_STRING_INITIALIZER(
1131 struct cmd_set_port_meter_dscp_table_result,
1132 dscp_table, "dscp table");
1133 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_token_string =
1134 TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_dscp_table_result,
1135 token_string, TOKEN_STRING_MULTI);
1137 static void cmd_set_port_meter_dscp_table_parsed(void *parsed_result,
1138 __rte_unused struct cmdline *cl,
1139 __rte_unused void *data)
1141 struct cmd_set_port_meter_dscp_table_result *res = parsed_result;
1142 struct rte_mtr_error error;
1143 enum rte_color *dscp_table = NULL;
1144 char *t_str = res->token_string;
1145 uint32_t mtr_id = 0;
1150 ret = parse_multi_token_string(t_str, &port_id, &mtr_id, &dscp_table);
1152 printf(" Multi token string parse error\n");
1156 if (port_id_is_invalid(port_id, ENABLED_WARN))
1159 /* Update Meter DSCP Table*/
1160 ret = rte_mtr_meter_dscp_table_update(port_id, mtr_id,
1161 dscp_table, &error);
1163 print_err_msg(&error);
1169 cmdline_parse_inst_t cmd_set_port_meter_dscp_table = {
1170 .f = cmd_set_port_meter_dscp_table_parsed,
1172 .help_str = "set port meter dscp table <port_id> <mtr_id> "
1173 "[<dscp_tbl_entry0> <dscp_tbl_entry1> ... <dscp_tbl_entry63>]",
1175 (void *)&cmd_set_port_meter_dscp_table_set,
1176 (void *)&cmd_set_port_meter_dscp_table_port,
1177 (void *)&cmd_set_port_meter_dscp_table_meter,
1178 (void *)&cmd_set_port_meter_dscp_table_dscp_table,
1179 (void *)&cmd_set_port_meter_dscp_table_token_string,
1184 /* *** Set Port Meter Policer Action *** */
1185 struct cmd_set_port_meter_policer_action_result {
1186 cmdline_fixed_string_t set;
1187 cmdline_fixed_string_t port;
1188 cmdline_fixed_string_t meter;
1189 cmdline_fixed_string_t policer;
1190 cmdline_fixed_string_t action;
1193 uint32_t action_mask;
1194 cmdline_multi_string_t policer_action;
1197 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_set =
1198 TOKEN_STRING_INITIALIZER(
1199 struct cmd_set_port_meter_policer_action_result, set, "set");
1200 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_port =
1201 TOKEN_STRING_INITIALIZER(
1202 struct cmd_set_port_meter_policer_action_result, port, "port");
1203 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_meter =
1204 TOKEN_STRING_INITIALIZER(
1205 struct cmd_set_port_meter_policer_action_result, meter,
1207 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_policer =
1208 TOKEN_STRING_INITIALIZER(
1209 struct cmd_set_port_meter_policer_action_result, policer,
1211 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_action =
1212 TOKEN_STRING_INITIALIZER(
1213 struct cmd_set_port_meter_policer_action_result, action,
1215 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_port_id =
1216 TOKEN_NUM_INITIALIZER(
1217 struct cmd_set_port_meter_policer_action_result, port_id,
1219 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_mtr_id =
1220 TOKEN_NUM_INITIALIZER(
1221 struct cmd_set_port_meter_policer_action_result, mtr_id,
1223 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_action_mask =
1224 TOKEN_NUM_INITIALIZER(
1225 struct cmd_set_port_meter_policer_action_result, action_mask,
1227 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_policer_action =
1228 TOKEN_STRING_INITIALIZER(
1229 struct cmd_set_port_meter_policer_action_result,
1230 policer_action, TOKEN_STRING_MULTI);
1232 static void cmd_set_port_meter_policer_action_parsed(void *parsed_result,
1233 __rte_unused struct cmdline *cl,
1234 __rte_unused void *data)
1236 struct cmd_set_port_meter_policer_action_result *res = parsed_result;
1237 enum rte_mtr_policer_action *actions;
1238 struct rte_mtr_error error;
1239 uint32_t mtr_id = res->mtr_id;
1240 uint32_t action_mask = res->action_mask;
1241 uint16_t port_id = res->port_id;
1242 char *p_str = res->policer_action;
1245 if (port_id_is_invalid(port_id, ENABLED_WARN))
1248 /* Check: action mask */
1249 if (action_mask == 0 || (action_mask & (~0x7UL))) {
1250 printf(" Policer action mask not correct (error)\n");
1254 /* Allocate memory for policer actions */
1255 actions = (enum rte_mtr_policer_action *)malloc(RTE_COLORS *
1256 sizeof(enum rte_mtr_policer_action));
1257 if (actions == NULL) {
1258 printf("Memory for policer actions not allocated (error)\n");
1261 /* Parse policer action string */
1262 ret = parse_policer_action_string(p_str, action_mask, actions);
1264 printf(" Policer action string parse error\n");
1269 ret = rte_mtr_policer_actions_update(port_id, mtr_id,
1270 action_mask, actions, &error);
1273 print_err_msg(&error);
1280 cmdline_parse_inst_t cmd_set_port_meter_policer_action = {
1281 .f = cmd_set_port_meter_policer_action_parsed,
1283 .help_str = "set port meter policer action <port_id> <mtr_id> "
1284 "<action_mask> <action0> [<action1> <action2>]",
1286 (void *)&cmd_set_port_meter_policer_action_set,
1287 (void *)&cmd_set_port_meter_policer_action_port,
1288 (void *)&cmd_set_port_meter_policer_action_meter,
1289 (void *)&cmd_set_port_meter_policer_action_policer,
1290 (void *)&cmd_set_port_meter_policer_action_action,
1291 (void *)&cmd_set_port_meter_policer_action_port_id,
1292 (void *)&cmd_set_port_meter_policer_action_mtr_id,
1293 (void *)&cmd_set_port_meter_policer_action_action_mask,
1294 (void *)&cmd_set_port_meter_policer_action_policer_action,
1299 /* *** Set Port Meter Stats Mask *** */
1300 struct cmd_set_port_meter_stats_mask_result {
1301 cmdline_fixed_string_t set;
1302 cmdline_fixed_string_t port;
1303 cmdline_fixed_string_t meter;
1304 cmdline_fixed_string_t stats;
1305 cmdline_fixed_string_t mask;
1308 uint64_t stats_mask;
1311 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_set =
1312 TOKEN_STRING_INITIALIZER(
1313 struct cmd_set_port_meter_stats_mask_result, set, "set");
1314 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_port =
1315 TOKEN_STRING_INITIALIZER(
1316 struct cmd_set_port_meter_stats_mask_result, port, "port");
1317 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_meter =
1318 TOKEN_STRING_INITIALIZER(
1319 struct cmd_set_port_meter_stats_mask_result, meter, "meter");
1320 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_stats =
1321 TOKEN_STRING_INITIALIZER(
1322 struct cmd_set_port_meter_stats_mask_result, stats, "stats");
1323 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_mask =
1324 TOKEN_STRING_INITIALIZER(
1325 struct cmd_set_port_meter_stats_mask_result, mask, "mask");
1326 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_port_id =
1327 TOKEN_NUM_INITIALIZER(
1328 struct cmd_set_port_meter_stats_mask_result, port_id,
1330 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_mtr_id =
1331 TOKEN_NUM_INITIALIZER(
1332 struct cmd_set_port_meter_stats_mask_result, mtr_id,
1334 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_stats_mask =
1335 TOKEN_NUM_INITIALIZER(
1336 struct cmd_set_port_meter_stats_mask_result, stats_mask,
1339 static void cmd_set_port_meter_stats_mask_parsed(void *parsed_result,
1340 __rte_unused struct cmdline *cl,
1341 __rte_unused void *data)
1343 struct cmd_set_port_meter_stats_mask_result *res = parsed_result;
1344 struct rte_mtr_error error;
1345 uint64_t stats_mask = res->stats_mask;
1346 uint32_t mtr_id = res->mtr_id;
1347 uint16_t port_id = res->port_id;
1350 if (port_id_is_invalid(port_id, ENABLED_WARN))
1353 ret = rte_mtr_stats_update(port_id, mtr_id, stats_mask, &error);
1355 print_err_msg(&error);
1360 cmdline_parse_inst_t cmd_set_port_meter_stats_mask = {
1361 .f = cmd_set_port_meter_stats_mask_parsed,
1363 .help_str = "set port meter stats mask <port_id> <mtr_id> <stats_mask>",
1365 (void *)&cmd_set_port_meter_stats_mask_set,
1366 (void *)&cmd_set_port_meter_stats_mask_port,
1367 (void *)&cmd_set_port_meter_stats_mask_meter,
1368 (void *)&cmd_set_port_meter_stats_mask_stats,
1369 (void *)&cmd_set_port_meter_stats_mask_mask,
1370 (void *)&cmd_set_port_meter_stats_mask_port_id,
1371 (void *)&cmd_set_port_meter_stats_mask_mtr_id,
1372 (void *)&cmd_set_port_meter_stats_mask_stats_mask,
1377 /* *** Show Port Meter Stats *** */
1378 struct cmd_show_port_meter_stats_result {
1379 cmdline_fixed_string_t show;
1380 cmdline_fixed_string_t port;
1381 cmdline_fixed_string_t meter;
1382 cmdline_fixed_string_t stats;
1385 cmdline_fixed_string_t clear;
1388 cmdline_parse_token_string_t cmd_show_port_meter_stats_show =
1389 TOKEN_STRING_INITIALIZER(
1390 struct cmd_show_port_meter_stats_result, show, "show");
1391 cmdline_parse_token_string_t cmd_show_port_meter_stats_port =
1392 TOKEN_STRING_INITIALIZER(
1393 struct cmd_show_port_meter_stats_result, port, "port");
1394 cmdline_parse_token_string_t cmd_show_port_meter_stats_meter =
1395 TOKEN_STRING_INITIALIZER(
1396 struct cmd_show_port_meter_stats_result, meter, "meter");
1397 cmdline_parse_token_string_t cmd_show_port_meter_stats_stats =
1398 TOKEN_STRING_INITIALIZER(
1399 struct cmd_show_port_meter_stats_result, stats, "stats");
1400 cmdline_parse_token_num_t cmd_show_port_meter_stats_port_id =
1401 TOKEN_NUM_INITIALIZER(
1402 struct cmd_show_port_meter_stats_result, port_id, RTE_UINT16);
1403 cmdline_parse_token_num_t cmd_show_port_meter_stats_mtr_id =
1404 TOKEN_NUM_INITIALIZER(
1405 struct cmd_show_port_meter_stats_result, mtr_id, RTE_UINT32);
1406 cmdline_parse_token_string_t cmd_show_port_meter_stats_clear =
1407 TOKEN_STRING_INITIALIZER(
1408 struct cmd_show_port_meter_stats_result, clear, "yes#no");
1410 static void cmd_show_port_meter_stats_parsed(void *parsed_result,
1411 __rte_unused struct cmdline *cl,
1412 __rte_unused void *data)
1414 struct cmd_show_port_meter_stats_result *res = parsed_result;
1415 struct rte_mtr_stats stats;
1416 uint64_t stats_mask = 0;
1417 struct rte_mtr_error error;
1418 uint32_t mtr_id = res->mtr_id;
1420 uint16_t port_id = res->port_id;
1423 if (port_id_is_invalid(port_id, ENABLED_WARN))
1426 if (strcmp(res->clear, "yes") == 0)
1429 memset(&stats, 0, sizeof(struct rte_mtr_stats));
1430 ret = rte_mtr_stats_read(port_id, mtr_id, &stats,
1431 &stats_mask, clear, &error);
1433 print_err_msg(&error);
1438 if (stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
1439 printf("\tPkts G: %" PRIu64 "\n",
1440 stats.n_pkts[RTE_COLOR_GREEN]);
1441 if (stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
1442 printf("\tBytes G: %" PRIu64 "\n",
1443 stats.n_bytes[RTE_COLOR_GREEN]);
1444 if (stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
1445 printf("\tPkts Y: %" PRIu64 "\n",
1446 stats.n_pkts[RTE_COLOR_YELLOW]);
1447 if (stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
1448 printf("\tBytes Y: %" PRIu64 "\n",
1449 stats.n_bytes[RTE_COLOR_YELLOW]);
1450 if (stats_mask & RTE_MTR_STATS_N_PKTS_RED)
1451 printf("\tPkts R: %" PRIu64 "\n",
1452 stats.n_pkts[RTE_COLOR_RED]);
1453 if (stats_mask & RTE_MTR_STATS_N_BYTES_RED)
1454 printf("\tBytes R: %" PRIu64 "\n",
1455 stats.n_bytes[RTE_COLOR_RED]);
1456 if (stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
1457 printf("\tPkts DROPPED: %" PRIu64 "\n",
1458 stats.n_pkts_dropped);
1459 if (stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
1460 printf("\tBytes DROPPED: %" PRIu64 "\n",
1461 stats.n_bytes_dropped);
1464 cmdline_parse_inst_t cmd_show_port_meter_stats = {
1465 .f = cmd_show_port_meter_stats_parsed,
1467 .help_str = "show port meter stats <port_id> <mtr_id> <clear>(yes|no)",
1469 (void *)&cmd_show_port_meter_stats_show,
1470 (void *)&cmd_show_port_meter_stats_port,
1471 (void *)&cmd_show_port_meter_stats_meter,
1472 (void *)&cmd_show_port_meter_stats_stats,
1473 (void *)&cmd_show_port_meter_stats_port_id,
1474 (void *)&cmd_show_port_meter_stats_mtr_id,
1475 (void *)&cmd_show_port_meter_stats_clear,