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;
193 parse_multi_token_string(char *t_str, uint16_t *port_id,
194 uint32_t *mtr_id, enum rte_mtr_color *dscp_table)
200 /* First token: port id */
201 token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
205 ret = parse_uint(&val, token);
206 if (ret != 0 || val > UINT16_MAX)
211 /* Second token: meter id */
212 token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
216 ret = parse_uint(&val, token);
217 if (ret != 0 || val > UINT32_MAX)
222 ret = parse_dscp_table_entries(t_str, dscp_table);
229 /* *** Show Port Meter Capabilities *** */
230 struct cmd_show_port_meter_cap_result {
231 cmdline_fixed_string_t show;
232 cmdline_fixed_string_t port;
233 cmdline_fixed_string_t meter;
234 cmdline_fixed_string_t cap;
238 cmdline_parse_token_string_t cmd_show_port_meter_cap_show =
239 TOKEN_STRING_INITIALIZER(
240 struct cmd_show_port_meter_cap_result, show, "show");
241 cmdline_parse_token_string_t cmd_show_port_meter_cap_port =
242 TOKEN_STRING_INITIALIZER(
243 struct cmd_show_port_meter_cap_result, port, "port");
244 cmdline_parse_token_string_t cmd_show_port_meter_cap_meter =
245 TOKEN_STRING_INITIALIZER(
246 struct cmd_show_port_meter_cap_result, meter, "meter");
247 cmdline_parse_token_string_t cmd_show_port_meter_cap_cap =
248 TOKEN_STRING_INITIALIZER(
249 struct cmd_show_port_meter_cap_result, cap, "cap");
250 cmdline_parse_token_num_t cmd_show_port_meter_cap_port_id =
251 TOKEN_NUM_INITIALIZER(
252 struct cmd_show_port_meter_cap_result, port_id, UINT16);
254 static void cmd_show_port_meter_cap_parsed(void *parsed_result,
255 __attribute__((unused)) struct cmdline *cl,
256 __attribute__((unused)) void *data)
258 struct cmd_show_port_meter_cap_result *res = parsed_result;
259 struct rte_mtr_capabilities cap;
260 struct rte_mtr_error error;
261 uint16_t port_id = res->port_id;
264 if (port_id_is_invalid(port_id, ENABLED_WARN))
267 memset(&cap, 0, sizeof(struct rte_mtr_capabilities));
268 ret = rte_mtr_capabilities_get(port_id, &cap, &error);
270 print_err_msg(&error);
274 printf("\n**** Port Meter Object Capabilities ****\n\n");
275 printf("cap.n_max %" PRIu32 "\n", cap.n_max);
276 printf("cap.n_shared_max %" PRIu32 "\n", cap.n_shared_max);
277 printf("cap.identical %" PRId32 "\n", cap.identical);
278 printf("cap.shared_identical %" PRId32 "\n",
279 cap.shared_identical);
280 printf("cap.shared_n_flows_per_mtr_max %" PRIu32 "\n",
281 cap.shared_n_flows_per_mtr_max);
282 printf("cap.chaining_n_mtrs_per_flow_max %" PRIu32 "\n",
283 cap.chaining_n_mtrs_per_flow_max);
284 printf("cap.chaining_use_prev_mtr_color_supported %" PRId32 "\n",
285 cap.chaining_use_prev_mtr_color_supported);
286 printf("cap.chaining_use_prev_mtr_color_enforced %" PRId32 "\n",
287 cap.chaining_use_prev_mtr_color_enforced);
288 printf("cap.meter_srtcm_rfc2697_n_max %" PRIu32 "\n",
289 cap.meter_srtcm_rfc2697_n_max);
290 printf("cap.meter_trtcm_rfc2698_n_max %" PRIu32 "\n",
291 cap.meter_trtcm_rfc2698_n_max);
292 printf("cap.meter_trtcm_rfc4115_n_max %" PRIu32 "\n",
293 cap.meter_trtcm_rfc4115_n_max);
294 printf("cap.meter_rate_max %" PRIu64 "\n", cap.meter_rate_max);
295 printf("cap.color_aware_srtcm_rfc2697_supported %" PRId32 "\n",
296 cap.color_aware_srtcm_rfc2697_supported);
297 printf("cap.color_aware_trtcm_rfc2698_supported %" PRId32 "\n",
298 cap.color_aware_trtcm_rfc2698_supported);
299 printf("cap.color_aware_trtcm_rfc4115_supported %" PRId32 "\n",
300 cap.color_aware_trtcm_rfc4115_supported);
301 printf("cap.policer_action_recolor_supported %" PRId32 "\n",
302 cap.policer_action_recolor_supported);
303 printf("cap.policer_action_drop_supported %" PRId32 "\n",
304 cap.policer_action_drop_supported);
305 printf("cap.stats_mask %" PRIx64 "\n", cap.stats_mask);
308 cmdline_parse_inst_t cmd_show_port_meter_cap = {
309 .f = cmd_show_port_meter_cap_parsed,
311 .help_str = "Show port meter cap",
313 (void *)&cmd_show_port_meter_cap_show,
314 (void *)&cmd_show_port_meter_cap_port,
315 (void *)&cmd_show_port_meter_cap_meter,
316 (void *)&cmd_show_port_meter_cap_cap,
317 (void *)&cmd_show_port_meter_cap_port_id,
322 /* *** Add Port Meter Profile srtcm_rfc2697 *** */
323 struct cmd_add_port_meter_profile_srtcm_result {
324 cmdline_fixed_string_t add;
325 cmdline_fixed_string_t port;
326 cmdline_fixed_string_t meter;
327 cmdline_fixed_string_t profile;
328 cmdline_fixed_string_t srtcm_rfc2697;
336 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_add =
337 TOKEN_STRING_INITIALIZER(
338 struct cmd_add_port_meter_profile_srtcm_result, add, "add");
339 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_port =
340 TOKEN_STRING_INITIALIZER(
341 struct cmd_add_port_meter_profile_srtcm_result,
343 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_meter =
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_profile =
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_srtcm_rfc2697 =
352 TOKEN_STRING_INITIALIZER(
353 struct cmd_add_port_meter_profile_srtcm_result,
354 srtcm_rfc2697, "srtcm_rfc2697");
355 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_port_id =
356 TOKEN_NUM_INITIALIZER(
357 struct cmd_add_port_meter_profile_srtcm_result,
359 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_profile_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_cir =
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_cbs =
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_ebs =
372 TOKEN_NUM_INITIALIZER(
373 struct cmd_add_port_meter_profile_srtcm_result,
376 static void cmd_add_port_meter_profile_srtcm_parsed(void *parsed_result,
377 __attribute__((unused)) struct cmdline *cl,
378 __attribute__((unused)) void *data)
380 struct cmd_add_port_meter_profile_srtcm_result *res = parsed_result;
381 struct rte_mtr_meter_profile mp;
382 struct rte_mtr_error error;
383 uint32_t profile_id = res->profile_id;
384 uint16_t port_id = res->port_id;
387 if (port_id_is_invalid(port_id, ENABLED_WARN))
390 /* Private shaper profile params */
391 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
392 mp.alg = RTE_MTR_SRTCM_RFC2697;
393 mp.srtcm_rfc2697.cir = res->cir;
394 mp.srtcm_rfc2697.cbs = res->cbs;
395 mp.srtcm_rfc2697.ebs = res->ebs;
397 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
399 print_err_msg(&error);
404 cmdline_parse_inst_t cmd_add_port_meter_profile_srtcm = {
405 .f = cmd_add_port_meter_profile_srtcm_parsed,
407 .help_str = "Add port meter profile srtcm (rfc2697)",
409 (void *)&cmd_add_port_meter_profile_srtcm_add,
410 (void *)&cmd_add_port_meter_profile_srtcm_port,
411 (void *)&cmd_add_port_meter_profile_srtcm_meter,
412 (void *)&cmd_add_port_meter_profile_srtcm_profile,
413 (void *)&cmd_add_port_meter_profile_srtcm_port_id,
414 (void *)&cmd_add_port_meter_profile_srtcm_profile_id,
415 (void *)&cmd_add_port_meter_profile_srtcm_srtcm_rfc2697,
416 (void *)&cmd_add_port_meter_profile_srtcm_cir,
417 (void *)&cmd_add_port_meter_profile_srtcm_cbs,
418 (void *)&cmd_add_port_meter_profile_srtcm_ebs,
423 /* *** Add Port Meter Profile trtcm_rfc2698 *** */
424 struct cmd_add_port_meter_profile_trtcm_result {
425 cmdline_fixed_string_t add;
426 cmdline_fixed_string_t port;
427 cmdline_fixed_string_t meter;
428 cmdline_fixed_string_t profile;
429 cmdline_fixed_string_t trtcm_rfc2698;
438 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_add =
439 TOKEN_STRING_INITIALIZER(
440 struct cmd_add_port_meter_profile_trtcm_result, add, "add");
441 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_port =
442 TOKEN_STRING_INITIALIZER(
443 struct cmd_add_port_meter_profile_trtcm_result,
445 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_meter =
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_profile =
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_trtcm_rfc2698 =
454 TOKEN_STRING_INITIALIZER(
455 struct cmd_add_port_meter_profile_trtcm_result,
456 trtcm_rfc2698, "trtcm_rfc2698");
457 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_port_id =
458 TOKEN_NUM_INITIALIZER(
459 struct cmd_add_port_meter_profile_trtcm_result,
461 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_profile_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_cir =
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_pir =
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_cbs =
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_pbs =
478 TOKEN_NUM_INITIALIZER(
479 struct cmd_add_port_meter_profile_trtcm_result,
482 static void cmd_add_port_meter_profile_trtcm_parsed(void *parsed_result,
483 __attribute__((unused)) struct cmdline *cl,
484 __attribute__((unused)) void *data)
486 struct cmd_add_port_meter_profile_trtcm_result *res = parsed_result;
487 struct rte_mtr_meter_profile mp;
488 struct rte_mtr_error error;
489 uint32_t profile_id = res->profile_id;
490 uint16_t port_id = res->port_id;
493 if (port_id_is_invalid(port_id, ENABLED_WARN))
496 /* Private shaper profile params */
497 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
498 mp.alg = RTE_MTR_TRTCM_RFC2698;
499 mp.trtcm_rfc2698.cir = res->cir;
500 mp.trtcm_rfc2698.pir = res->pir;
501 mp.trtcm_rfc2698.cbs = res->cbs;
502 mp.trtcm_rfc2698.pbs = res->pbs;
504 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
506 print_err_msg(&error);
511 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm = {
512 .f = cmd_add_port_meter_profile_trtcm_parsed,
514 .help_str = "Add port meter profile trtcm (rfc2698)",
516 (void *)&cmd_add_port_meter_profile_trtcm_add,
517 (void *)&cmd_add_port_meter_profile_trtcm_port,
518 (void *)&cmd_add_port_meter_profile_trtcm_meter,
519 (void *)&cmd_add_port_meter_profile_trtcm_profile,
520 (void *)&cmd_add_port_meter_profile_trtcm_port_id,
521 (void *)&cmd_add_port_meter_profile_trtcm_profile_id,
522 (void *)&cmd_add_port_meter_profile_trtcm_trtcm_rfc2698,
523 (void *)&cmd_add_port_meter_profile_trtcm_cir,
524 (void *)&cmd_add_port_meter_profile_trtcm_pir,
525 (void *)&cmd_add_port_meter_profile_trtcm_cbs,
526 (void *)&cmd_add_port_meter_profile_trtcm_pbs,
531 /* *** Add Port Meter Profile trtcm_rfc4115 *** */
532 struct cmd_add_port_meter_profile_trtcm_rfc4115_result {
533 cmdline_fixed_string_t add;
534 cmdline_fixed_string_t port;
535 cmdline_fixed_string_t meter;
536 cmdline_fixed_string_t profile;
537 cmdline_fixed_string_t trtcm_rfc4115;
546 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_add =
547 TOKEN_STRING_INITIALIZER(
548 struct cmd_add_port_meter_profile_trtcm_rfc4115_result, add,
550 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_port =
551 TOKEN_STRING_INITIALIZER(
552 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
554 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_meter =
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_profile =
559 TOKEN_STRING_INITIALIZER(
560 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
562 cmdline_parse_token_string_t
563 cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115 =
564 TOKEN_STRING_INITIALIZER(
565 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
566 trtcm_rfc4115, "trtcm_rfc4115");
567 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_port_id =
568 TOKEN_NUM_INITIALIZER(
569 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
571 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_profile_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_cir =
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_eir =
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_cbs =
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_ebs =
588 TOKEN_NUM_INITIALIZER(
589 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
592 static void cmd_add_port_meter_profile_trtcm_rfc4115_parsed(
594 __attribute__((unused)) struct cmdline *cl,
595 __attribute__((unused)) void *data)
597 struct cmd_add_port_meter_profile_trtcm_rfc4115_result *res =
599 struct rte_mtr_meter_profile mp;
600 struct rte_mtr_error error;
601 uint32_t profile_id = res->profile_id;
602 uint16_t port_id = res->port_id;
605 if (port_id_is_invalid(port_id, ENABLED_WARN))
608 /* Private shaper profile params */
609 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
610 mp.alg = RTE_MTR_TRTCM_RFC4115;
611 mp.trtcm_rfc4115.cir = res->cir;
612 mp.trtcm_rfc4115.eir = res->eir;
613 mp.trtcm_rfc4115.cbs = res->cbs;
614 mp.trtcm_rfc4115.ebs = res->ebs;
616 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
618 print_err_msg(&error);
623 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm_rfc4115 = {
624 .f = cmd_add_port_meter_profile_trtcm_rfc4115_parsed,
626 .help_str = "Add port meter profile trtcm (rfc4115)",
628 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_add,
629 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port,
630 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_meter,
631 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile,
632 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port_id,
633 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile_id,
634 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115,
635 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cir,
636 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_eir,
637 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cbs,
638 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_ebs,
643 /* *** Delete Port Meter Profile *** */
644 struct cmd_del_port_meter_profile_result {
645 cmdline_fixed_string_t del;
646 cmdline_fixed_string_t port;
647 cmdline_fixed_string_t meter;
648 cmdline_fixed_string_t profile;
653 cmdline_parse_token_string_t cmd_del_port_meter_profile_del =
654 TOKEN_STRING_INITIALIZER(
655 struct cmd_del_port_meter_profile_result, del, "del");
656 cmdline_parse_token_string_t cmd_del_port_meter_profile_port =
657 TOKEN_STRING_INITIALIZER(
658 struct cmd_del_port_meter_profile_result,
660 cmdline_parse_token_string_t cmd_del_port_meter_profile_meter =
661 TOKEN_STRING_INITIALIZER(
662 struct cmd_del_port_meter_profile_result,
664 cmdline_parse_token_string_t cmd_del_port_meter_profile_profile =
665 TOKEN_STRING_INITIALIZER(
666 struct cmd_del_port_meter_profile_result,
668 cmdline_parse_token_num_t cmd_del_port_meter_profile_port_id =
669 TOKEN_NUM_INITIALIZER(
670 struct cmd_del_port_meter_profile_result,
672 cmdline_parse_token_num_t cmd_del_port_meter_profile_profile_id =
673 TOKEN_NUM_INITIALIZER(
674 struct cmd_del_port_meter_profile_result,
677 static void cmd_del_port_meter_profile_parsed(void *parsed_result,
678 __attribute__((unused)) struct cmdline *cl,
679 __attribute__((unused)) void *data)
681 struct cmd_del_port_meter_profile_result *res = parsed_result;
682 struct rte_mtr_error error;
683 uint32_t profile_id = res->profile_id;
684 uint16_t port_id = res->port_id;
687 if (port_id_is_invalid(port_id, ENABLED_WARN))
690 /* Delete meter profile */
691 ret = rte_mtr_meter_profile_delete(port_id, profile_id, &error);
693 print_err_msg(&error);
698 cmdline_parse_inst_t cmd_del_port_meter_profile = {
699 .f = cmd_del_port_meter_profile_parsed,
701 .help_str = "Delete port meter profile",
703 (void *)&cmd_del_port_meter_profile_del,
704 (void *)&cmd_del_port_meter_profile_port,
705 (void *)&cmd_del_port_meter_profile_meter,
706 (void *)&cmd_del_port_meter_profile_profile,
707 (void *)&cmd_del_port_meter_profile_port_id,
708 (void *)&cmd_del_port_meter_profile_profile_id,
713 /* *** Create Port Meter Object *** */
714 struct cmd_create_port_meter_result {
715 cmdline_fixed_string_t create;
716 cmdline_fixed_string_t port;
717 cmdline_fixed_string_t meter;
721 cmdline_fixed_string_t meter_enable;
722 cmdline_fixed_string_t g_action;
723 cmdline_fixed_string_t y_action;
724 cmdline_fixed_string_t r_action;
725 uint64_t statistics_mask;
727 cmdline_multi_string_t meter_input_color;
730 cmdline_parse_token_string_t cmd_create_port_meter_create =
731 TOKEN_STRING_INITIALIZER(
732 struct cmd_create_port_meter_result, create, "create");
733 cmdline_parse_token_string_t cmd_create_port_meter_port =
734 TOKEN_STRING_INITIALIZER(
735 struct cmd_create_port_meter_result, port, "port");
736 cmdline_parse_token_string_t cmd_create_port_meter_meter =
737 TOKEN_STRING_INITIALIZER(
738 struct cmd_create_port_meter_result, meter, "meter");
739 cmdline_parse_token_num_t cmd_create_port_meter_port_id =
740 TOKEN_NUM_INITIALIZER(
741 struct cmd_create_port_meter_result, port_id, UINT16);
742 cmdline_parse_token_num_t cmd_create_port_meter_mtr_id =
743 TOKEN_NUM_INITIALIZER(
744 struct cmd_create_port_meter_result, mtr_id, UINT32);
745 cmdline_parse_token_num_t cmd_create_port_meter_profile_id =
746 TOKEN_NUM_INITIALIZER(
747 struct cmd_create_port_meter_result, profile_id, UINT32);
748 cmdline_parse_token_string_t cmd_create_port_meter_meter_enable =
749 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
750 meter_enable, "yes#no");
751 cmdline_parse_token_string_t cmd_create_port_meter_g_action =
752 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
753 g_action, "R#Y#G#D#r#y#g#d");
754 cmdline_parse_token_string_t cmd_create_port_meter_y_action =
755 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
756 y_action, "R#Y#G#D#r#y#g#d");
757 cmdline_parse_token_string_t cmd_create_port_meter_r_action =
758 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
759 r_action, "R#Y#G#D#r#y#g#d");
760 cmdline_parse_token_num_t cmd_create_port_meter_statistics_mask =
761 TOKEN_NUM_INITIALIZER(struct cmd_create_port_meter_result,
762 statistics_mask, UINT64);
763 cmdline_parse_token_num_t cmd_create_port_meter_shared =
764 TOKEN_NUM_INITIALIZER(struct cmd_create_port_meter_result,
766 cmdline_parse_token_string_t cmd_create_port_meter_input_color =
767 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
768 meter_input_color, TOKEN_STRING_MULTI);
770 static void cmd_create_port_meter_parsed(void *parsed_result,
771 __attribute__((unused)) struct cmdline *cl,
772 __attribute__((unused)) void *data)
774 struct cmd_create_port_meter_result *res = parsed_result;
775 struct rte_mtr_error error;
776 struct rte_mtr_params params;
777 uint32_t mtr_id = res->mtr_id;
778 uint32_t shared = res->shared;
779 uint32_t use_prev_meter_color = 0;
780 uint16_t port_id = res->port_id;
781 enum rte_mtr_color *dscp_table = NULL;
782 char *c_str = res->meter_input_color;
785 if (port_id_is_invalid(port_id, ENABLED_WARN))
789 memset(¶ms, 0, sizeof(struct rte_mtr_params));
790 params.meter_profile_id = res->profile_id;
792 /* Parse meter input color string params */
793 ret = parse_meter_color_str(c_str, &use_prev_meter_color, dscp_table);
795 printf(" Meter input color params string parse error\n");
799 params.use_prev_mtr_color = use_prev_meter_color;
800 params.dscp_table = dscp_table;
802 if (strcmp(res->meter_enable, "yes") == 0)
803 params.meter_enable = 1;
805 params.meter_enable = 0;
807 params.action[RTE_MTR_GREEN] =
808 string_to_policer_action(res->g_action);
809 params.action[RTE_MTR_YELLOW] =
810 string_to_policer_action(res->y_action);
811 params.action[RTE_MTR_RED] =
812 string_to_policer_action(res->r_action);
813 params.stats_mask = res->statistics_mask;
815 ret = rte_mtr_create(port_id, mtr_id, ¶ms, shared, &error);
818 print_err_msg(&error);
823 cmdline_parse_inst_t cmd_create_port_meter = {
824 .f = cmd_create_port_meter_parsed,
826 .help_str = "Create port meter",
828 (void *)&cmd_create_port_meter_create,
829 (void *)&cmd_create_port_meter_port,
830 (void *)&cmd_create_port_meter_meter,
831 (void *)&cmd_create_port_meter_port_id,
832 (void *)&cmd_create_port_meter_mtr_id,
833 (void *)&cmd_create_port_meter_profile_id,
834 (void *)&cmd_create_port_meter_meter_enable,
835 (void *)&cmd_create_port_meter_g_action,
836 (void *)&cmd_create_port_meter_y_action,
837 (void *)&cmd_create_port_meter_r_action,
838 (void *)&cmd_create_port_meter_statistics_mask,
839 (void *)&cmd_create_port_meter_shared,
840 (void *)&cmd_create_port_meter_input_color,
845 /* *** Enable Meter of MTR Object *** */
846 struct cmd_enable_port_meter_result {
847 cmdline_fixed_string_t enable;
848 cmdline_fixed_string_t port;
849 cmdline_fixed_string_t meter;
854 cmdline_parse_token_string_t cmd_enable_port_meter_enable =
855 TOKEN_STRING_INITIALIZER(
856 struct cmd_enable_port_meter_result, enable, "enable");
857 cmdline_parse_token_string_t cmd_enable_port_meter_port =
858 TOKEN_STRING_INITIALIZER(
859 struct cmd_enable_port_meter_result, port, "port");
860 cmdline_parse_token_string_t cmd_enable_port_meter_meter =
861 TOKEN_STRING_INITIALIZER(
862 struct cmd_enable_port_meter_result, meter, "meter");
863 cmdline_parse_token_num_t cmd_enable_port_meter_port_id =
864 TOKEN_NUM_INITIALIZER(
865 struct cmd_enable_port_meter_result, port_id, UINT16);
866 cmdline_parse_token_num_t cmd_enable_port_meter_mtr_id =
867 TOKEN_NUM_INITIALIZER(
868 struct cmd_enable_port_meter_result, mtr_id, UINT32);
870 static void cmd_enable_port_meter_parsed(void *parsed_result,
871 __attribute__((unused)) struct cmdline *cl,
872 __attribute__((unused)) void *data)
874 struct cmd_enable_port_meter_result *res = parsed_result;
875 struct rte_mtr_error error;
876 uint32_t mtr_id = res->mtr_id;
877 uint16_t port_id = res->port_id;
881 if (port_id_is_invalid(port_id, ENABLED_WARN))
885 ret = rte_mtr_meter_enable(port_id, mtr_id, &error);
887 print_err_msg(&error);
892 cmdline_parse_inst_t cmd_enable_port_meter = {
893 .f = cmd_enable_port_meter_parsed,
895 .help_str = "Enable port meter",
897 (void *)&cmd_enable_port_meter_enable,
898 (void *)&cmd_enable_port_meter_port,
899 (void *)&cmd_enable_port_meter_meter,
900 (void *)&cmd_enable_port_meter_port_id,
901 (void *)&cmd_enable_port_meter_mtr_id,
906 /* *** Disable Meter of MTR Object *** */
907 struct cmd_disable_port_meter_result {
908 cmdline_fixed_string_t disable;
909 cmdline_fixed_string_t port;
910 cmdline_fixed_string_t meter;
915 cmdline_parse_token_string_t cmd_disable_port_meter_disable =
916 TOKEN_STRING_INITIALIZER(
917 struct cmd_disable_port_meter_result, disable, "disable");
918 cmdline_parse_token_string_t cmd_disable_port_meter_port =
919 TOKEN_STRING_INITIALIZER(
920 struct cmd_disable_port_meter_result, port, "port");
921 cmdline_parse_token_string_t cmd_disable_port_meter_meter =
922 TOKEN_STRING_INITIALIZER(
923 struct cmd_disable_port_meter_result, meter, "meter");
924 cmdline_parse_token_num_t cmd_disable_port_meter_port_id =
925 TOKEN_NUM_INITIALIZER(
926 struct cmd_disable_port_meter_result, port_id, UINT16);
927 cmdline_parse_token_num_t cmd_disable_port_meter_mtr_id =
928 TOKEN_NUM_INITIALIZER(
929 struct cmd_disable_port_meter_result, mtr_id, UINT32);
931 static void cmd_disable_port_meter_parsed(void *parsed_result,
932 __attribute__((unused)) struct cmdline *cl,
933 __attribute__((unused)) void *data)
935 struct cmd_disable_port_meter_result *res = parsed_result;
936 struct rte_mtr_error error;
937 uint32_t mtr_id = res->mtr_id;
938 uint16_t port_id = res->port_id;
942 if (port_id_is_invalid(port_id, ENABLED_WARN))
946 ret = rte_mtr_meter_disable(port_id, mtr_id, &error);
948 print_err_msg(&error);
953 cmdline_parse_inst_t cmd_disable_port_meter = {
954 .f = cmd_disable_port_meter_parsed,
956 .help_str = "Disable port meter",
958 (void *)&cmd_disable_port_meter_disable,
959 (void *)&cmd_disable_port_meter_port,
960 (void *)&cmd_disable_port_meter_meter,
961 (void *)&cmd_disable_port_meter_port_id,
962 (void *)&cmd_disable_port_meter_mtr_id,
967 /* *** Delete Port Meter Object *** */
968 struct cmd_del_port_meter_result {
969 cmdline_fixed_string_t del;
970 cmdline_fixed_string_t port;
971 cmdline_fixed_string_t meter;
976 cmdline_parse_token_string_t cmd_del_port_meter_del =
977 TOKEN_STRING_INITIALIZER(
978 struct cmd_del_port_meter_result, del, "del");
979 cmdline_parse_token_string_t cmd_del_port_meter_port =
980 TOKEN_STRING_INITIALIZER(
981 struct cmd_del_port_meter_result, port, "port");
982 cmdline_parse_token_string_t cmd_del_port_meter_meter =
983 TOKEN_STRING_INITIALIZER(
984 struct cmd_del_port_meter_result, meter, "meter");
985 cmdline_parse_token_num_t cmd_del_port_meter_port_id =
986 TOKEN_NUM_INITIALIZER(
987 struct cmd_del_port_meter_result, port_id, UINT16);
988 cmdline_parse_token_num_t cmd_del_port_meter_mtr_id =
989 TOKEN_NUM_INITIALIZER(
990 struct cmd_del_port_meter_result, mtr_id, UINT32);
992 static void cmd_del_port_meter_parsed(void *parsed_result,
993 __attribute__((unused)) struct cmdline *cl,
994 __attribute__((unused)) void *data)
996 struct cmd_del_port_meter_result *res = parsed_result;
997 struct rte_mtr_error error;
998 uint32_t mtr_id = res->mtr_id;
999 uint16_t port_id = res->port_id;
1003 if (port_id_is_invalid(port_id, ENABLED_WARN))
1007 ret = rte_mtr_destroy(port_id, mtr_id, &error);
1009 print_err_msg(&error);
1014 cmdline_parse_inst_t cmd_del_port_meter = {
1015 .f = cmd_del_port_meter_parsed,
1017 .help_str = "Delete port meter",
1019 (void *)&cmd_del_port_meter_del,
1020 (void *)&cmd_del_port_meter_port,
1021 (void *)&cmd_del_port_meter_meter,
1022 (void *)&cmd_del_port_meter_port_id,
1023 (void *)&cmd_del_port_meter_mtr_id,
1028 /* *** Set Port Meter Profile *** */
1029 struct cmd_set_port_meter_profile_result {
1030 cmdline_fixed_string_t set;
1031 cmdline_fixed_string_t port;
1032 cmdline_fixed_string_t meter;
1033 cmdline_fixed_string_t profile;
1036 uint32_t profile_id;
1039 cmdline_parse_token_string_t cmd_set_port_meter_profile_set =
1040 TOKEN_STRING_INITIALIZER(
1041 struct cmd_set_port_meter_profile_result, set, "set");
1042 cmdline_parse_token_string_t cmd_set_port_meter_profile_port =
1043 TOKEN_STRING_INITIALIZER(
1044 struct cmd_set_port_meter_profile_result, port, "port");
1045 cmdline_parse_token_string_t cmd_set_port_meter_profile_meter =
1046 TOKEN_STRING_INITIALIZER(
1047 struct cmd_set_port_meter_profile_result, meter, "meter");
1048 cmdline_parse_token_string_t cmd_set_port_meter_profile_profile =
1049 TOKEN_STRING_INITIALIZER(
1050 struct cmd_set_port_meter_profile_result, profile, "profile");
1051 cmdline_parse_token_num_t cmd_set_port_meter_profile_port_id =
1052 TOKEN_NUM_INITIALIZER(
1053 struct cmd_set_port_meter_profile_result, port_id, UINT16);
1054 cmdline_parse_token_num_t cmd_set_port_meter_profile_mtr_id =
1055 TOKEN_NUM_INITIALIZER(
1056 struct cmd_set_port_meter_profile_result, mtr_id, UINT32);
1057 cmdline_parse_token_num_t cmd_set_port_meter_profile_profile_id =
1058 TOKEN_NUM_INITIALIZER(
1059 struct cmd_set_port_meter_profile_result, profile_id, UINT32);
1061 static void cmd_set_port_meter_profile_parsed(void *parsed_result,
1062 __attribute__((unused)) struct cmdline *cl,
1063 __attribute__((unused)) void *data)
1065 struct cmd_set_port_meter_profile_result *res = parsed_result;
1066 struct rte_mtr_error error;
1067 uint32_t mtr_id = res->mtr_id;
1068 uint32_t profile_id = res->profile_id;
1069 uint16_t port_id = res->port_id;
1073 if (port_id_is_invalid(port_id, ENABLED_WARN))
1076 /* Set meter profile */
1077 ret = rte_mtr_meter_profile_update(port_id, mtr_id,
1078 profile_id, &error);
1080 print_err_msg(&error);
1085 cmdline_parse_inst_t cmd_set_port_meter_profile = {
1086 .f = cmd_set_port_meter_profile_parsed,
1088 .help_str = "Set port meter profile",
1090 (void *)&cmd_set_port_meter_profile_set,
1091 (void *)&cmd_set_port_meter_profile_port,
1092 (void *)&cmd_set_port_meter_profile_meter,
1093 (void *)&cmd_set_port_meter_profile_profile,
1094 (void *)&cmd_set_port_meter_profile_port_id,
1095 (void *)&cmd_set_port_meter_profile_mtr_id,
1096 (void *)&cmd_set_port_meter_profile_profile_id,
1101 /* *** Set Port Meter DSCP Table *** */
1102 struct cmd_set_port_meter_dscp_table_result {
1103 cmdline_fixed_string_t set;
1104 cmdline_fixed_string_t port;
1105 cmdline_fixed_string_t meter;
1106 cmdline_fixed_string_t dscp_table;
1107 cmdline_multi_string_t token_string;
1110 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_set =
1111 TOKEN_STRING_INITIALIZER(
1112 struct cmd_set_port_meter_dscp_table_result, set, "set");
1113 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_port =
1114 TOKEN_STRING_INITIALIZER(
1115 struct cmd_set_port_meter_dscp_table_result, port, "port");
1116 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_meter =
1117 TOKEN_STRING_INITIALIZER(
1118 struct cmd_set_port_meter_dscp_table_result, meter, "meter");
1119 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_dscp_table =
1120 TOKEN_STRING_INITIALIZER(
1121 struct cmd_set_port_meter_dscp_table_result,
1122 dscp_table, "dscp table");
1123 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_token_string =
1124 TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_dscp_table_result,
1125 token_string, TOKEN_STRING_MULTI);
1127 static void cmd_set_port_meter_dscp_table_parsed(void *parsed_result,
1128 __attribute__((unused)) struct cmdline *cl,
1129 __attribute__((unused)) void *data)
1131 struct cmd_set_port_meter_dscp_table_result *res = parsed_result;
1132 struct rte_mtr_error error;
1133 enum rte_mtr_color *dscp_table = NULL;
1134 char *t_str = res->token_string;
1135 uint32_t mtr_id = 0;
1140 ret = parse_multi_token_string(t_str, &port_id, &mtr_id, dscp_table);
1142 printf(" Multi token string parse error\n");
1146 if (port_id_is_invalid(port_id, ENABLED_WARN))
1149 /* Update Meter DSCP Table*/
1150 ret = rte_mtr_meter_dscp_table_update(port_id, mtr_id,
1151 dscp_table, &error);
1153 print_err_msg(&error);
1159 cmdline_parse_inst_t cmd_set_port_meter_dscp_table = {
1160 .f = cmd_set_port_meter_dscp_table_parsed,
1162 .help_str = "Update port meter dscp table",
1164 (void *)&cmd_set_port_meter_dscp_table_set,
1165 (void *)&cmd_set_port_meter_dscp_table_port,
1166 (void *)&cmd_set_port_meter_dscp_table_meter,
1167 (void *)&cmd_set_port_meter_dscp_table_dscp_table,
1168 (void *)&cmd_set_port_meter_dscp_table_token_string,
1173 /* *** Set Port Meter Policer Action *** */
1174 struct cmd_set_port_meter_policer_action_result {
1175 cmdline_fixed_string_t set;
1176 cmdline_fixed_string_t port;
1177 cmdline_fixed_string_t meter;
1178 cmdline_fixed_string_t policer;
1179 cmdline_fixed_string_t action;
1182 uint32_t action_mask;
1183 cmdline_multi_string_t policer_action;
1186 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_set =
1187 TOKEN_STRING_INITIALIZER(
1188 struct cmd_set_port_meter_policer_action_result, set, "set");
1189 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_port =
1190 TOKEN_STRING_INITIALIZER(
1191 struct cmd_set_port_meter_policer_action_result, port, "port");
1192 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_meter =
1193 TOKEN_STRING_INITIALIZER(
1194 struct cmd_set_port_meter_policer_action_result, meter,
1196 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_policer =
1197 TOKEN_STRING_INITIALIZER(
1198 struct cmd_set_port_meter_policer_action_result, policer,
1200 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_action =
1201 TOKEN_STRING_INITIALIZER(
1202 struct cmd_set_port_meter_policer_action_result, action,
1204 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_port_id =
1205 TOKEN_NUM_INITIALIZER(
1206 struct cmd_set_port_meter_policer_action_result, port_id,
1208 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_mtr_id =
1209 TOKEN_NUM_INITIALIZER(
1210 struct cmd_set_port_meter_policer_action_result, mtr_id,
1212 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_action_mask =
1213 TOKEN_NUM_INITIALIZER(
1214 struct cmd_set_port_meter_policer_action_result, action_mask,
1216 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_policer_action =
1217 TOKEN_STRING_INITIALIZER(
1218 struct cmd_set_port_meter_policer_action_result,
1219 policer_action, TOKEN_STRING_MULTI);
1221 static void cmd_set_port_meter_policer_action_parsed(void *parsed_result,
1222 __attribute__((unused)) struct cmdline *cl,
1223 __attribute__((unused)) void *data)
1225 struct cmd_set_port_meter_policer_action_result *res = parsed_result;
1226 enum rte_mtr_policer_action *actions;
1227 struct rte_mtr_error error;
1228 uint32_t mtr_id = res->mtr_id;
1229 uint32_t action_mask = res->action_mask;
1230 uint16_t port_id = res->port_id;
1231 char *p_str = res->policer_action;
1234 if (port_id_is_invalid(port_id, ENABLED_WARN))
1237 /* Check: action mask */
1238 if (action_mask == 0 || (action_mask & (~0x7UL))) {
1239 printf(" Policer action mask not correct (error)\n");
1243 /* Allocate memory for policer actions */
1244 actions = (enum rte_mtr_policer_action *)malloc(RTE_MTR_COLORS *
1245 sizeof(enum rte_mtr_policer_action));
1246 if (actions == NULL) {
1247 printf("Memory for policer actions not allocated (error)\n");
1250 /* Parse policer action string */
1251 ret = parse_policer_action_string(p_str, action_mask, actions);
1253 printf(" Policer action string parse error\n");
1258 ret = rte_mtr_policer_actions_update(port_id, mtr_id,
1259 action_mask, actions, &error);
1261 print_err_msg(&error);
1268 cmdline_parse_inst_t cmd_set_port_meter_policer_action = {
1269 .f = cmd_set_port_meter_policer_action_parsed,
1271 .help_str = "Set port meter policer action",
1273 (void *)&cmd_set_port_meter_policer_action_set,
1274 (void *)&cmd_set_port_meter_policer_action_port,
1275 (void *)&cmd_set_port_meter_policer_action_meter,
1276 (void *)&cmd_set_port_meter_policer_action_policer,
1277 (void *)&cmd_set_port_meter_policer_action_action,
1278 (void *)&cmd_set_port_meter_policer_action_port_id,
1279 (void *)&cmd_set_port_meter_policer_action_mtr_id,
1280 (void *)&cmd_set_port_meter_policer_action_action_mask,
1281 (void *)&cmd_set_port_meter_policer_action_policer_action,
1286 /* *** Set Port Meter Stats Mask *** */
1287 struct cmd_set_port_meter_stats_mask_result {
1288 cmdline_fixed_string_t set;
1289 cmdline_fixed_string_t port;
1290 cmdline_fixed_string_t meter;
1291 cmdline_fixed_string_t stats;
1292 cmdline_fixed_string_t mask;
1295 uint64_t stats_mask;
1298 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_set =
1299 TOKEN_STRING_INITIALIZER(
1300 struct cmd_set_port_meter_stats_mask_result, set, "set");
1301 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_port =
1302 TOKEN_STRING_INITIALIZER(
1303 struct cmd_set_port_meter_stats_mask_result, port, "port");
1304 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_meter =
1305 TOKEN_STRING_INITIALIZER(
1306 struct cmd_set_port_meter_stats_mask_result, meter, "meter");
1307 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_stats =
1308 TOKEN_STRING_INITIALIZER(
1309 struct cmd_set_port_meter_stats_mask_result, stats, "stats");
1310 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_mask =
1311 TOKEN_STRING_INITIALIZER(
1312 struct cmd_set_port_meter_stats_mask_result, mask, "mask");
1313 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_port_id =
1314 TOKEN_NUM_INITIALIZER(
1315 struct cmd_set_port_meter_stats_mask_result, port_id, UINT16);
1316 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_mtr_id =
1317 TOKEN_NUM_INITIALIZER(
1318 struct cmd_set_port_meter_stats_mask_result, mtr_id, UINT32);
1319 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_stats_mask =
1320 TOKEN_NUM_INITIALIZER(
1321 struct cmd_set_port_meter_stats_mask_result, stats_mask,
1324 static void cmd_set_port_meter_stats_mask_parsed(void *parsed_result,
1325 __attribute__((unused)) struct cmdline *cl,
1326 __attribute__((unused)) void *data)
1328 struct cmd_set_port_meter_stats_mask_result *res = parsed_result;
1329 struct rte_mtr_error error;
1330 uint64_t stats_mask = res->stats_mask;
1331 uint32_t mtr_id = res->mtr_id;
1332 uint16_t port_id = res->port_id;
1335 if (port_id_is_invalid(port_id, ENABLED_WARN))
1338 ret = rte_mtr_stats_update(port_id, mtr_id, stats_mask, &error);
1340 print_err_msg(&error);
1345 cmdline_parse_inst_t cmd_set_port_meter_stats_mask = {
1346 .f = cmd_set_port_meter_stats_mask_parsed,
1348 .help_str = "Set port meter stats mask",
1350 (void *)&cmd_set_port_meter_stats_mask_set,
1351 (void *)&cmd_set_port_meter_stats_mask_port,
1352 (void *)&cmd_set_port_meter_stats_mask_meter,
1353 (void *)&cmd_set_port_meter_stats_mask_stats,
1354 (void *)&cmd_set_port_meter_stats_mask_mask,
1355 (void *)&cmd_set_port_meter_stats_mask_port_id,
1356 (void *)&cmd_set_port_meter_stats_mask_mtr_id,
1357 (void *)&cmd_set_port_meter_stats_mask_stats_mask,
1362 /* *** Show Port Meter Stats *** */
1363 struct cmd_show_port_meter_stats_result {
1364 cmdline_fixed_string_t show;
1365 cmdline_fixed_string_t port;
1366 cmdline_fixed_string_t meter;
1367 cmdline_fixed_string_t stats;
1370 cmdline_fixed_string_t clear;
1373 cmdline_parse_token_string_t cmd_show_port_meter_stats_show =
1374 TOKEN_STRING_INITIALIZER(
1375 struct cmd_show_port_meter_stats_result, show, "show");
1376 cmdline_parse_token_string_t cmd_show_port_meter_stats_port =
1377 TOKEN_STRING_INITIALIZER(
1378 struct cmd_show_port_meter_stats_result, port, "port");
1379 cmdline_parse_token_string_t cmd_show_port_meter_stats_meter =
1380 TOKEN_STRING_INITIALIZER(
1381 struct cmd_show_port_meter_stats_result, meter, "meter");
1382 cmdline_parse_token_string_t cmd_show_port_meter_stats_stats =
1383 TOKEN_STRING_INITIALIZER(
1384 struct cmd_show_port_meter_stats_result, stats, "stats");
1385 cmdline_parse_token_num_t cmd_show_port_meter_stats_port_id =
1386 TOKEN_NUM_INITIALIZER(
1387 struct cmd_show_port_meter_stats_result, port_id, UINT16);
1388 cmdline_parse_token_num_t cmd_show_port_meter_stats_mtr_id =
1389 TOKEN_NUM_INITIALIZER(
1390 struct cmd_show_port_meter_stats_result, mtr_id, UINT32);
1391 cmdline_parse_token_string_t cmd_show_port_meter_stats_clear =
1392 TOKEN_STRING_INITIALIZER(
1393 struct cmd_show_port_meter_stats_result, clear, "yes#no");
1395 static void cmd_show_port_meter_stats_parsed(void *parsed_result,
1396 __attribute__((unused)) struct cmdline *cl,
1397 __attribute__((unused)) void *data)
1399 struct cmd_show_port_meter_stats_result *res = parsed_result;
1400 struct rte_mtr_stats stats;
1401 uint64_t stats_mask = 0;
1402 struct rte_mtr_error error;
1403 uint32_t mtr_id = res->mtr_id;
1405 uint16_t port_id = res->port_id;
1408 if (port_id_is_invalid(port_id, ENABLED_WARN))
1411 if (strcmp(res->clear, "yes") == 0)
1414 memset(&stats, 0, sizeof(struct rte_mtr_stats));
1415 ret = rte_mtr_stats_read(port_id, mtr_id, &stats,
1416 &stats_mask, clear, &error);
1418 print_err_msg(&error);
1423 if (stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
1424 printf("\tPkts G: %" PRIu64 "\n",
1425 stats.n_pkts[RTE_MTR_GREEN]);
1426 if (stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
1427 printf("\tBytes G: %" PRIu64 "\n",
1428 stats.n_bytes[RTE_MTR_GREEN]);
1429 if (stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
1430 printf("\tPkts Y: %" PRIu64 "\n",
1431 stats.n_pkts[RTE_MTR_YELLOW]);
1432 if (stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
1433 printf("\tBytes Y: %" PRIu64 "\n",
1434 stats.n_bytes[RTE_MTR_YELLOW]);
1435 if (stats_mask & RTE_MTR_STATS_N_PKTS_RED)
1436 printf("\tPkts R: %" PRIu64 "\n",
1437 stats.n_pkts[RTE_MTR_RED]);
1438 if (stats_mask & RTE_MTR_STATS_N_BYTES_RED)
1439 printf("\tBytes Y: %" PRIu64 "\n",
1440 stats.n_bytes[RTE_MTR_RED]);
1441 if (stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
1442 printf("\tPkts DROPPED: %" PRIu64 "\n",
1443 stats.n_pkts_dropped);
1444 if (stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
1445 printf("\tBytes DROPPED: %" PRIu64 "\n",
1446 stats.n_bytes_dropped);
1449 cmdline_parse_inst_t cmd_show_port_meter_stats = {
1450 .f = cmd_show_port_meter_stats_parsed,
1452 .help_str = "Show port meter stats",
1454 (void *)&cmd_show_port_meter_stats_show,
1455 (void *)&cmd_show_port_meter_stats_port,
1456 (void *)&cmd_show_port_meter_stats_meter,
1457 (void *)&cmd_show_port_meter_stats_stats,
1458 (void *)&cmd_show_port_meter_stats_port_id,
1459 (void *)&cmd_show_port_meter_stats_mtr_id,
1460 (void *)&cmd_show_port_meter_stats_clear,