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 parse_multi_token_string(char *t_str, uint16_t *port_id,
151 uint32_t *mtr_id, enum rte_color **dscp_table)
157 /* First token: port id */
158 token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
162 ret = parse_uint(&val, token);
163 if (ret != 0 || val > UINT16_MAX)
168 /* Second token: meter id */
169 token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
173 ret = parse_uint(&val, token);
174 if (ret != 0 || val > UINT32_MAX)
179 ret = parse_dscp_table_entries(t_str, dscp_table);
186 /* *** Show Port Meter Capabilities *** */
187 struct cmd_show_port_meter_cap_result {
188 cmdline_fixed_string_t show;
189 cmdline_fixed_string_t port;
190 cmdline_fixed_string_t meter;
191 cmdline_fixed_string_t cap;
195 cmdline_parse_token_string_t cmd_show_port_meter_cap_show =
196 TOKEN_STRING_INITIALIZER(
197 struct cmd_show_port_meter_cap_result, show, "show");
198 cmdline_parse_token_string_t cmd_show_port_meter_cap_port =
199 TOKEN_STRING_INITIALIZER(
200 struct cmd_show_port_meter_cap_result, port, "port");
201 cmdline_parse_token_string_t cmd_show_port_meter_cap_meter =
202 TOKEN_STRING_INITIALIZER(
203 struct cmd_show_port_meter_cap_result, meter, "meter");
204 cmdline_parse_token_string_t cmd_show_port_meter_cap_cap =
205 TOKEN_STRING_INITIALIZER(
206 struct cmd_show_port_meter_cap_result, cap, "cap");
207 cmdline_parse_token_num_t cmd_show_port_meter_cap_port_id =
208 TOKEN_NUM_INITIALIZER(
209 struct cmd_show_port_meter_cap_result, port_id, RTE_UINT16);
211 static void cmd_show_port_meter_cap_parsed(void *parsed_result,
212 __rte_unused struct cmdline *cl,
213 __rte_unused void *data)
215 struct cmd_show_port_meter_cap_result *res = parsed_result;
216 struct rte_mtr_capabilities cap;
217 struct rte_mtr_error error;
218 uint16_t port_id = res->port_id;
221 if (port_id_is_invalid(port_id, ENABLED_WARN))
224 memset(&cap, 0, sizeof(struct rte_mtr_capabilities));
225 ret = rte_mtr_capabilities_get(port_id, &cap, &error);
227 print_err_msg(&error);
231 printf("\n**** Port Meter Object Capabilities ****\n\n");
232 printf("cap.n_max %" PRIu32 "\n", cap.n_max);
233 printf("cap.n_shared_max %" PRIu32 "\n", cap.n_shared_max);
234 printf("cap.identical %" PRId32 "\n", cap.identical);
235 printf("cap.shared_identical %" PRId32 "\n",
236 cap.shared_identical);
237 printf("cap.shared_n_flows_per_mtr_max %" PRIu32 "\n",
238 cap.shared_n_flows_per_mtr_max);
239 printf("cap.chaining_n_mtrs_per_flow_max %" PRIu32 "\n",
240 cap.chaining_n_mtrs_per_flow_max);
241 printf("cap.chaining_use_prev_mtr_color_supported %" PRId32 "\n",
242 cap.chaining_use_prev_mtr_color_supported);
243 printf("cap.chaining_use_prev_mtr_color_enforced %" PRId32 "\n",
244 cap.chaining_use_prev_mtr_color_enforced);
245 printf("cap.meter_srtcm_rfc2697_n_max %" PRIu32 "\n",
246 cap.meter_srtcm_rfc2697_n_max);
247 printf("cap.meter_trtcm_rfc2698_n_max %" PRIu32 "\n",
248 cap.meter_trtcm_rfc2698_n_max);
249 printf("cap.meter_trtcm_rfc4115_n_max %" PRIu32 "\n",
250 cap.meter_trtcm_rfc4115_n_max);
251 printf("cap.meter_rate_max %" PRIu64 "\n", cap.meter_rate_max);
252 printf("cap.color_aware_srtcm_rfc2697_supported %" PRId32 "\n",
253 cap.color_aware_srtcm_rfc2697_supported);
254 printf("cap.color_aware_trtcm_rfc2698_supported %" PRId32 "\n",
255 cap.color_aware_trtcm_rfc2698_supported);
256 printf("cap.color_aware_trtcm_rfc4115_supported %" PRId32 "\n",
257 cap.color_aware_trtcm_rfc4115_supported);
258 printf("cap.srtcm_rfc2697_byte_mode_supported %" PRId32 "\n",
259 cap.srtcm_rfc2697_byte_mode_supported);
260 printf("cap.srtcm_rfc2697_packet_mode_supported %" PRId32 "\n",
261 cap.srtcm_rfc2697_packet_mode_supported);
262 printf("cap.trtcm_rfc2698_byte_mode_supported %" PRId32 "\n",
263 cap.trtcm_rfc2698_byte_mode_supported);
264 printf("cap.trtcm_rfc2698_packet_mode_supported %" PRId32 "\n",
265 cap.trtcm_rfc2698_packet_mode_supported);
266 printf("cap.trtcm_rfc4115_byte_mode_supported %" PRId32 "\n",
267 cap.trtcm_rfc4115_byte_mode_supported);
268 printf("cap.trtcm_rfc4115_packet_mode_supported %" PRId32 "\n",
269 cap.trtcm_rfc4115_packet_mode_supported);
270 printf("cap.stats_mask %" PRIx64 "\n", cap.stats_mask);
273 cmdline_parse_inst_t cmd_show_port_meter_cap = {
274 .f = cmd_show_port_meter_cap_parsed,
276 .help_str = "show port meter cap <port_id>",
278 (void *)&cmd_show_port_meter_cap_show,
279 (void *)&cmd_show_port_meter_cap_port,
280 (void *)&cmd_show_port_meter_cap_meter,
281 (void *)&cmd_show_port_meter_cap_cap,
282 (void *)&cmd_show_port_meter_cap_port_id,
287 /* *** Add Port Meter Profile srtcm_rfc2697 *** */
288 struct cmd_add_port_meter_profile_srtcm_result {
289 cmdline_fixed_string_t add;
290 cmdline_fixed_string_t port;
291 cmdline_fixed_string_t meter;
292 cmdline_fixed_string_t profile;
293 cmdline_fixed_string_t srtcm_rfc2697;
302 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_add =
303 TOKEN_STRING_INITIALIZER(
304 struct cmd_add_port_meter_profile_srtcm_result, add, "add");
305 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_port =
306 TOKEN_STRING_INITIALIZER(
307 struct cmd_add_port_meter_profile_srtcm_result,
309 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_meter =
310 TOKEN_STRING_INITIALIZER(
311 struct cmd_add_port_meter_profile_srtcm_result,
313 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_profile =
314 TOKEN_STRING_INITIALIZER(
315 struct cmd_add_port_meter_profile_srtcm_result,
317 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_srtcm_rfc2697 =
318 TOKEN_STRING_INITIALIZER(
319 struct cmd_add_port_meter_profile_srtcm_result,
320 srtcm_rfc2697, "srtcm_rfc2697");
321 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_port_id =
322 TOKEN_NUM_INITIALIZER(
323 struct cmd_add_port_meter_profile_srtcm_result,
324 port_id, RTE_UINT16);
325 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_profile_id =
326 TOKEN_NUM_INITIALIZER(
327 struct cmd_add_port_meter_profile_srtcm_result,
328 profile_id, RTE_UINT32);
329 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cir =
330 TOKEN_NUM_INITIALIZER(
331 struct cmd_add_port_meter_profile_srtcm_result,
333 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cbs =
334 TOKEN_NUM_INITIALIZER(
335 struct cmd_add_port_meter_profile_srtcm_result,
337 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_ebs =
338 TOKEN_NUM_INITIALIZER(
339 struct cmd_add_port_meter_profile_srtcm_result,
341 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_packet_mode =
342 TOKEN_NUM_INITIALIZER(
343 struct cmd_add_port_meter_profile_srtcm_result,
344 packet_mode, RTE_UINT32);
346 static void cmd_add_port_meter_profile_srtcm_parsed(void *parsed_result,
347 __rte_unused struct cmdline *cl,
348 __rte_unused void *data)
350 struct cmd_add_port_meter_profile_srtcm_result *res = parsed_result;
351 struct rte_mtr_meter_profile mp;
352 struct rte_mtr_error error;
353 uint32_t profile_id = res->profile_id;
354 uint16_t port_id = res->port_id;
357 if (port_id_is_invalid(port_id, ENABLED_WARN))
360 /* Private shaper profile params */
361 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
362 mp.alg = RTE_MTR_SRTCM_RFC2697;
363 mp.srtcm_rfc2697.cir = res->cir;
364 mp.srtcm_rfc2697.cbs = res->cbs;
365 mp.srtcm_rfc2697.ebs = res->ebs;
366 mp.packet_mode = res->packet_mode;
368 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
370 print_err_msg(&error);
375 cmdline_parse_inst_t cmd_add_port_meter_profile_srtcm = {
376 .f = cmd_add_port_meter_profile_srtcm_parsed,
378 .help_str = "add port meter profile srtcm_rfc2697 <port_id> <profile_id> <cir> <cbs> <ebs> <packet_mode>",
380 (void *)&cmd_add_port_meter_profile_srtcm_add,
381 (void *)&cmd_add_port_meter_profile_srtcm_port,
382 (void *)&cmd_add_port_meter_profile_srtcm_meter,
383 (void *)&cmd_add_port_meter_profile_srtcm_profile,
384 (void *)&cmd_add_port_meter_profile_srtcm_srtcm_rfc2697,
385 (void *)&cmd_add_port_meter_profile_srtcm_port_id,
386 (void *)&cmd_add_port_meter_profile_srtcm_profile_id,
387 (void *)&cmd_add_port_meter_profile_srtcm_cir,
388 (void *)&cmd_add_port_meter_profile_srtcm_cbs,
389 (void *)&cmd_add_port_meter_profile_srtcm_ebs,
390 (void *)&cmd_add_port_meter_profile_srtcm_packet_mode,
395 /* *** Add Port Meter Profile trtcm_rfc2698 *** */
396 struct cmd_add_port_meter_profile_trtcm_result {
397 cmdline_fixed_string_t add;
398 cmdline_fixed_string_t port;
399 cmdline_fixed_string_t meter;
400 cmdline_fixed_string_t profile;
401 cmdline_fixed_string_t trtcm_rfc2698;
411 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_add =
412 TOKEN_STRING_INITIALIZER(
413 struct cmd_add_port_meter_profile_trtcm_result, add, "add");
414 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_port =
415 TOKEN_STRING_INITIALIZER(
416 struct cmd_add_port_meter_profile_trtcm_result,
418 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_meter =
419 TOKEN_STRING_INITIALIZER(
420 struct cmd_add_port_meter_profile_trtcm_result,
422 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_profile =
423 TOKEN_STRING_INITIALIZER(
424 struct cmd_add_port_meter_profile_trtcm_result,
426 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_trtcm_rfc2698 =
427 TOKEN_STRING_INITIALIZER(
428 struct cmd_add_port_meter_profile_trtcm_result,
429 trtcm_rfc2698, "trtcm_rfc2698");
430 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_port_id =
431 TOKEN_NUM_INITIALIZER(
432 struct cmd_add_port_meter_profile_trtcm_result,
433 port_id, RTE_UINT16);
434 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_profile_id =
435 TOKEN_NUM_INITIALIZER(
436 struct cmd_add_port_meter_profile_trtcm_result,
437 profile_id, RTE_UINT32);
438 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cir =
439 TOKEN_NUM_INITIALIZER(
440 struct cmd_add_port_meter_profile_trtcm_result,
442 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pir =
443 TOKEN_NUM_INITIALIZER(
444 struct cmd_add_port_meter_profile_trtcm_result,
446 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cbs =
447 TOKEN_NUM_INITIALIZER(
448 struct cmd_add_port_meter_profile_trtcm_result,
450 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pbs =
451 TOKEN_NUM_INITIALIZER(
452 struct cmd_add_port_meter_profile_trtcm_result,
454 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_packet_mode =
455 TOKEN_NUM_INITIALIZER(
456 struct cmd_add_port_meter_profile_trtcm_result,
457 packet_mode, RTE_UINT32);
459 static void cmd_add_port_meter_profile_trtcm_parsed(void *parsed_result,
460 __rte_unused struct cmdline *cl,
461 __rte_unused void *data)
463 struct cmd_add_port_meter_profile_trtcm_result *res = parsed_result;
464 struct rte_mtr_meter_profile mp;
465 struct rte_mtr_error error;
466 uint32_t profile_id = res->profile_id;
467 uint16_t port_id = res->port_id;
470 if (port_id_is_invalid(port_id, ENABLED_WARN))
473 /* Private shaper profile params */
474 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
475 mp.alg = RTE_MTR_TRTCM_RFC2698;
476 mp.trtcm_rfc2698.cir = res->cir;
477 mp.trtcm_rfc2698.pir = res->pir;
478 mp.trtcm_rfc2698.cbs = res->cbs;
479 mp.trtcm_rfc2698.pbs = res->pbs;
480 mp.packet_mode = res->packet_mode;
482 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
484 print_err_msg(&error);
489 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm = {
490 .f = cmd_add_port_meter_profile_trtcm_parsed,
492 .help_str = "add port meter profile trtcm_rfc2698 <port_id> <profile_id> <cir> <pir> <cbs> <pbs> <packet_mode>",
494 (void *)&cmd_add_port_meter_profile_trtcm_add,
495 (void *)&cmd_add_port_meter_profile_trtcm_port,
496 (void *)&cmd_add_port_meter_profile_trtcm_meter,
497 (void *)&cmd_add_port_meter_profile_trtcm_profile,
498 (void *)&cmd_add_port_meter_profile_trtcm_trtcm_rfc2698,
499 (void *)&cmd_add_port_meter_profile_trtcm_port_id,
500 (void *)&cmd_add_port_meter_profile_trtcm_profile_id,
501 (void *)&cmd_add_port_meter_profile_trtcm_cir,
502 (void *)&cmd_add_port_meter_profile_trtcm_pir,
503 (void *)&cmd_add_port_meter_profile_trtcm_cbs,
504 (void *)&cmd_add_port_meter_profile_trtcm_pbs,
505 (void *)&cmd_add_port_meter_profile_trtcm_packet_mode,
510 /* *** Add Port Meter Profile trtcm_rfc4115 *** */
511 struct cmd_add_port_meter_profile_trtcm_rfc4115_result {
512 cmdline_fixed_string_t add;
513 cmdline_fixed_string_t port;
514 cmdline_fixed_string_t meter;
515 cmdline_fixed_string_t profile;
516 cmdline_fixed_string_t trtcm_rfc4115;
526 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_add =
527 TOKEN_STRING_INITIALIZER(
528 struct cmd_add_port_meter_profile_trtcm_rfc4115_result, add,
530 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_port =
531 TOKEN_STRING_INITIALIZER(
532 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
534 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_meter =
535 TOKEN_STRING_INITIALIZER(
536 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
538 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_profile =
539 TOKEN_STRING_INITIALIZER(
540 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
542 cmdline_parse_token_string_t
543 cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115 =
544 TOKEN_STRING_INITIALIZER(
545 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
546 trtcm_rfc4115, "trtcm_rfc4115");
547 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_port_id =
548 TOKEN_NUM_INITIALIZER(
549 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
550 port_id, RTE_UINT16);
551 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_profile_id =
552 TOKEN_NUM_INITIALIZER(
553 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
554 profile_id, RTE_UINT32);
555 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cir =
556 TOKEN_NUM_INITIALIZER(
557 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
559 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_eir =
560 TOKEN_NUM_INITIALIZER(
561 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
563 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cbs =
564 TOKEN_NUM_INITIALIZER(
565 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
567 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_ebs =
568 TOKEN_NUM_INITIALIZER(
569 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
571 cmdline_parse_token_num_t
572 cmd_add_port_meter_profile_trtcm_rfc4115_packet_mode =
573 TOKEN_NUM_INITIALIZER(
574 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
575 packet_mode, RTE_UINT32);
577 static void cmd_add_port_meter_profile_trtcm_rfc4115_parsed(
579 __rte_unused struct cmdline *cl,
580 __rte_unused void *data)
582 struct cmd_add_port_meter_profile_trtcm_rfc4115_result *res =
584 struct rte_mtr_meter_profile mp;
585 struct rte_mtr_error error;
586 uint32_t profile_id = res->profile_id;
587 uint16_t port_id = res->port_id;
590 if (port_id_is_invalid(port_id, ENABLED_WARN))
593 /* Private shaper profile params */
594 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
595 mp.alg = RTE_MTR_TRTCM_RFC4115;
596 mp.trtcm_rfc4115.cir = res->cir;
597 mp.trtcm_rfc4115.eir = res->eir;
598 mp.trtcm_rfc4115.cbs = res->cbs;
599 mp.trtcm_rfc4115.ebs = res->ebs;
600 mp.packet_mode = res->packet_mode;
602 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
604 print_err_msg(&error);
609 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm_rfc4115 = {
610 .f = cmd_add_port_meter_profile_trtcm_rfc4115_parsed,
612 .help_str = "add port meter profile trtcm_rfc4115 <port_id> <profile_id> <cir> <eir> <cbs> <ebs> <packet_mode>",
614 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_add,
615 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port,
616 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_meter,
617 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile,
618 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115,
619 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port_id,
620 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile_id,
621 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cir,
622 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_eir,
623 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cbs,
624 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_ebs,
625 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_packet_mode,
630 /* *** Delete Port Meter Profile *** */
631 struct cmd_del_port_meter_profile_result {
632 cmdline_fixed_string_t del;
633 cmdline_fixed_string_t port;
634 cmdline_fixed_string_t meter;
635 cmdline_fixed_string_t profile;
640 cmdline_parse_token_string_t cmd_del_port_meter_profile_del =
641 TOKEN_STRING_INITIALIZER(
642 struct cmd_del_port_meter_profile_result, del, "del");
643 cmdline_parse_token_string_t cmd_del_port_meter_profile_port =
644 TOKEN_STRING_INITIALIZER(
645 struct cmd_del_port_meter_profile_result,
647 cmdline_parse_token_string_t cmd_del_port_meter_profile_meter =
648 TOKEN_STRING_INITIALIZER(
649 struct cmd_del_port_meter_profile_result,
651 cmdline_parse_token_string_t cmd_del_port_meter_profile_profile =
652 TOKEN_STRING_INITIALIZER(
653 struct cmd_del_port_meter_profile_result,
655 cmdline_parse_token_num_t cmd_del_port_meter_profile_port_id =
656 TOKEN_NUM_INITIALIZER(
657 struct cmd_del_port_meter_profile_result,
658 port_id, RTE_UINT16);
659 cmdline_parse_token_num_t cmd_del_port_meter_profile_profile_id =
660 TOKEN_NUM_INITIALIZER(
661 struct cmd_del_port_meter_profile_result,
662 profile_id, RTE_UINT32);
664 static void cmd_del_port_meter_profile_parsed(void *parsed_result,
665 __rte_unused struct cmdline *cl,
666 __rte_unused void *data)
668 struct cmd_del_port_meter_profile_result *res = parsed_result;
669 struct rte_mtr_error error;
670 uint32_t profile_id = res->profile_id;
671 uint16_t port_id = res->port_id;
674 if (port_id_is_invalid(port_id, ENABLED_WARN))
677 /* Delete meter profile */
678 ret = rte_mtr_meter_profile_delete(port_id, profile_id, &error);
680 print_err_msg(&error);
685 cmdline_parse_inst_t cmd_del_port_meter_profile = {
686 .f = cmd_del_port_meter_profile_parsed,
688 .help_str = "del port meter profile <port_id> <profile_id>",
690 (void *)&cmd_del_port_meter_profile_del,
691 (void *)&cmd_del_port_meter_profile_port,
692 (void *)&cmd_del_port_meter_profile_meter,
693 (void *)&cmd_del_port_meter_profile_profile,
694 (void *)&cmd_del_port_meter_profile_port_id,
695 (void *)&cmd_del_port_meter_profile_profile_id,
700 /* *** Create Port Meter Object *** */
701 struct cmd_create_port_meter_result {
702 cmdline_fixed_string_t create;
703 cmdline_fixed_string_t port;
704 cmdline_fixed_string_t meter;
708 cmdline_fixed_string_t meter_enable;
709 cmdline_fixed_string_t g_action;
710 cmdline_fixed_string_t y_action;
711 cmdline_fixed_string_t r_action;
712 uint64_t statistics_mask;
714 cmdline_multi_string_t meter_input_color;
717 cmdline_parse_token_string_t cmd_create_port_meter_create =
718 TOKEN_STRING_INITIALIZER(
719 struct cmd_create_port_meter_result, create, "create");
720 cmdline_parse_token_string_t cmd_create_port_meter_port =
721 TOKEN_STRING_INITIALIZER(
722 struct cmd_create_port_meter_result, port, "port");
723 cmdline_parse_token_string_t cmd_create_port_meter_meter =
724 TOKEN_STRING_INITIALIZER(
725 struct cmd_create_port_meter_result, meter, "meter");
726 cmdline_parse_token_num_t cmd_create_port_meter_port_id =
727 TOKEN_NUM_INITIALIZER(
728 struct cmd_create_port_meter_result, port_id, RTE_UINT16);
729 cmdline_parse_token_num_t cmd_create_port_meter_mtr_id =
730 TOKEN_NUM_INITIALIZER(
731 struct cmd_create_port_meter_result, mtr_id, RTE_UINT32);
732 cmdline_parse_token_num_t cmd_create_port_meter_profile_id =
733 TOKEN_NUM_INITIALIZER(
734 struct cmd_create_port_meter_result, profile_id, RTE_UINT32);
735 cmdline_parse_token_string_t cmd_create_port_meter_meter_enable =
736 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
737 meter_enable, "yes#no");
738 cmdline_parse_token_string_t cmd_create_port_meter_g_action =
739 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
740 g_action, "R#Y#G#D#r#y#g#d");
741 cmdline_parse_token_string_t cmd_create_port_meter_y_action =
742 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
743 y_action, "R#Y#G#D#r#y#g#d");
744 cmdline_parse_token_string_t cmd_create_port_meter_r_action =
745 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
746 r_action, "R#Y#G#D#r#y#g#d");
747 cmdline_parse_token_num_t cmd_create_port_meter_statistics_mask =
748 TOKEN_NUM_INITIALIZER(struct cmd_create_port_meter_result,
749 statistics_mask, RTE_UINT64);
750 cmdline_parse_token_num_t cmd_create_port_meter_shared =
751 TOKEN_NUM_INITIALIZER(struct cmd_create_port_meter_result,
753 cmdline_parse_token_string_t cmd_create_port_meter_input_color =
754 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
755 meter_input_color, TOKEN_STRING_MULTI);
757 static void cmd_create_port_meter_parsed(void *parsed_result,
758 __rte_unused struct cmdline *cl,
759 __rte_unused void *data)
761 struct cmd_create_port_meter_result *res = parsed_result;
762 struct rte_mtr_error error;
763 struct rte_mtr_params params;
764 uint32_t mtr_id = res->mtr_id;
765 uint32_t shared = res->shared;
766 uint32_t use_prev_meter_color = 0;
767 uint16_t port_id = res->port_id;
768 enum rte_color *dscp_table = NULL;
769 char *c_str = res->meter_input_color;
772 if (port_id_is_invalid(port_id, ENABLED_WARN))
776 memset(¶ms, 0, sizeof(struct rte_mtr_params));
777 params.meter_profile_id = res->profile_id;
779 /* Parse meter input color string params */
780 ret = parse_meter_color_str(c_str, &use_prev_meter_color, &dscp_table);
782 printf(" Meter input color params string parse error\n");
786 params.use_prev_mtr_color = use_prev_meter_color;
787 params.dscp_table = dscp_table;
789 if (strcmp(res->meter_enable, "yes") == 0)
790 params.meter_enable = 1;
792 params.meter_enable = 0;
794 params.stats_mask = res->statistics_mask;
796 ret = rte_mtr_create(port_id, mtr_id, ¶ms, shared, &error);
799 print_err_msg(&error);
804 cmdline_parse_inst_t cmd_create_port_meter = {
805 .f = cmd_create_port_meter_parsed,
807 .help_str = "create port meter <port_id> <mtr_id> <profile_id> <meter_enable>(yes|no) "
808 "<g_action>(R|Y|G|D) <y_action>(R|Y|G|D) <r_action>(R|Y|G|D) "
809 "<stats_mask> <shared> <use_pre_meter_color> "
810 "[<dscp_tbl_entry0> <dscp_tbl_entry1> ...<dscp_tbl_entry63>]",
812 (void *)&cmd_create_port_meter_create,
813 (void *)&cmd_create_port_meter_port,
814 (void *)&cmd_create_port_meter_meter,
815 (void *)&cmd_create_port_meter_port_id,
816 (void *)&cmd_create_port_meter_mtr_id,
817 (void *)&cmd_create_port_meter_profile_id,
818 (void *)&cmd_create_port_meter_meter_enable,
819 (void *)&cmd_create_port_meter_g_action,
820 (void *)&cmd_create_port_meter_y_action,
821 (void *)&cmd_create_port_meter_r_action,
822 (void *)&cmd_create_port_meter_statistics_mask,
823 (void *)&cmd_create_port_meter_shared,
824 (void *)&cmd_create_port_meter_input_color,
829 /* *** Enable Meter of MTR Object *** */
830 struct cmd_enable_port_meter_result {
831 cmdline_fixed_string_t enable;
832 cmdline_fixed_string_t port;
833 cmdline_fixed_string_t meter;
838 cmdline_parse_token_string_t cmd_enable_port_meter_enable =
839 TOKEN_STRING_INITIALIZER(
840 struct cmd_enable_port_meter_result, enable, "enable");
841 cmdline_parse_token_string_t cmd_enable_port_meter_port =
842 TOKEN_STRING_INITIALIZER(
843 struct cmd_enable_port_meter_result, port, "port");
844 cmdline_parse_token_string_t cmd_enable_port_meter_meter =
845 TOKEN_STRING_INITIALIZER(
846 struct cmd_enable_port_meter_result, meter, "meter");
847 cmdline_parse_token_num_t cmd_enable_port_meter_port_id =
848 TOKEN_NUM_INITIALIZER(
849 struct cmd_enable_port_meter_result, port_id, RTE_UINT16);
850 cmdline_parse_token_num_t cmd_enable_port_meter_mtr_id =
851 TOKEN_NUM_INITIALIZER(
852 struct cmd_enable_port_meter_result, mtr_id, RTE_UINT32);
854 static void cmd_enable_port_meter_parsed(void *parsed_result,
855 __rte_unused struct cmdline *cl,
856 __rte_unused void *data)
858 struct cmd_enable_port_meter_result *res = parsed_result;
859 struct rte_mtr_error error;
860 uint32_t mtr_id = res->mtr_id;
861 uint16_t port_id = res->port_id;
865 if (port_id_is_invalid(port_id, ENABLED_WARN))
869 ret = rte_mtr_meter_enable(port_id, mtr_id, &error);
871 print_err_msg(&error);
876 cmdline_parse_inst_t cmd_enable_port_meter = {
877 .f = cmd_enable_port_meter_parsed,
879 .help_str = "enable port meter <port_id> <mtr_id>",
881 (void *)&cmd_enable_port_meter_enable,
882 (void *)&cmd_enable_port_meter_port,
883 (void *)&cmd_enable_port_meter_meter,
884 (void *)&cmd_enable_port_meter_port_id,
885 (void *)&cmd_enable_port_meter_mtr_id,
890 /* *** Disable Meter of MTR Object *** */
891 struct cmd_disable_port_meter_result {
892 cmdline_fixed_string_t disable;
893 cmdline_fixed_string_t port;
894 cmdline_fixed_string_t meter;
899 cmdline_parse_token_string_t cmd_disable_port_meter_disable =
900 TOKEN_STRING_INITIALIZER(
901 struct cmd_disable_port_meter_result, disable, "disable");
902 cmdline_parse_token_string_t cmd_disable_port_meter_port =
903 TOKEN_STRING_INITIALIZER(
904 struct cmd_disable_port_meter_result, port, "port");
905 cmdline_parse_token_string_t cmd_disable_port_meter_meter =
906 TOKEN_STRING_INITIALIZER(
907 struct cmd_disable_port_meter_result, meter, "meter");
908 cmdline_parse_token_num_t cmd_disable_port_meter_port_id =
909 TOKEN_NUM_INITIALIZER(
910 struct cmd_disable_port_meter_result, port_id, RTE_UINT16);
911 cmdline_parse_token_num_t cmd_disable_port_meter_mtr_id =
912 TOKEN_NUM_INITIALIZER(
913 struct cmd_disable_port_meter_result, mtr_id, RTE_UINT32);
915 static void cmd_disable_port_meter_parsed(void *parsed_result,
916 __rte_unused struct cmdline *cl,
917 __rte_unused void *data)
919 struct cmd_disable_port_meter_result *res = parsed_result;
920 struct rte_mtr_error error;
921 uint32_t mtr_id = res->mtr_id;
922 uint16_t port_id = res->port_id;
926 if (port_id_is_invalid(port_id, ENABLED_WARN))
930 ret = rte_mtr_meter_disable(port_id, mtr_id, &error);
932 print_err_msg(&error);
937 cmdline_parse_inst_t cmd_disable_port_meter = {
938 .f = cmd_disable_port_meter_parsed,
940 .help_str = "disable port meter <port_id> <mtr_id>",
942 (void *)&cmd_disable_port_meter_disable,
943 (void *)&cmd_disable_port_meter_port,
944 (void *)&cmd_disable_port_meter_meter,
945 (void *)&cmd_disable_port_meter_port_id,
946 (void *)&cmd_disable_port_meter_mtr_id,
951 /* *** Delete Port Meter Object *** */
952 struct cmd_del_port_meter_result {
953 cmdline_fixed_string_t del;
954 cmdline_fixed_string_t port;
955 cmdline_fixed_string_t meter;
960 cmdline_parse_token_string_t cmd_del_port_meter_del =
961 TOKEN_STRING_INITIALIZER(
962 struct cmd_del_port_meter_result, del, "del");
963 cmdline_parse_token_string_t cmd_del_port_meter_port =
964 TOKEN_STRING_INITIALIZER(
965 struct cmd_del_port_meter_result, port, "port");
966 cmdline_parse_token_string_t cmd_del_port_meter_meter =
967 TOKEN_STRING_INITIALIZER(
968 struct cmd_del_port_meter_result, meter, "meter");
969 cmdline_parse_token_num_t cmd_del_port_meter_port_id =
970 TOKEN_NUM_INITIALIZER(
971 struct cmd_del_port_meter_result, port_id, RTE_UINT16);
972 cmdline_parse_token_num_t cmd_del_port_meter_mtr_id =
973 TOKEN_NUM_INITIALIZER(
974 struct cmd_del_port_meter_result, mtr_id, RTE_UINT32);
976 static void cmd_del_port_meter_parsed(void *parsed_result,
977 __rte_unused struct cmdline *cl,
978 __rte_unused void *data)
980 struct cmd_del_port_meter_result *res = parsed_result;
981 struct rte_mtr_error error;
982 uint32_t mtr_id = res->mtr_id;
983 uint16_t port_id = res->port_id;
987 if (port_id_is_invalid(port_id, ENABLED_WARN))
991 ret = rte_mtr_destroy(port_id, mtr_id, &error);
993 print_err_msg(&error);
998 cmdline_parse_inst_t cmd_del_port_meter = {
999 .f = cmd_del_port_meter_parsed,
1001 .help_str = "del port meter <port_id> <mtr_id>",
1003 (void *)&cmd_del_port_meter_del,
1004 (void *)&cmd_del_port_meter_port,
1005 (void *)&cmd_del_port_meter_meter,
1006 (void *)&cmd_del_port_meter_port_id,
1007 (void *)&cmd_del_port_meter_mtr_id,
1012 /* *** Set Port Meter Profile *** */
1013 struct cmd_set_port_meter_profile_result {
1014 cmdline_fixed_string_t set;
1015 cmdline_fixed_string_t port;
1016 cmdline_fixed_string_t meter;
1017 cmdline_fixed_string_t profile;
1020 uint32_t profile_id;
1023 cmdline_parse_token_string_t cmd_set_port_meter_profile_set =
1024 TOKEN_STRING_INITIALIZER(
1025 struct cmd_set_port_meter_profile_result, set, "set");
1026 cmdline_parse_token_string_t cmd_set_port_meter_profile_port =
1027 TOKEN_STRING_INITIALIZER(
1028 struct cmd_set_port_meter_profile_result, port, "port");
1029 cmdline_parse_token_string_t cmd_set_port_meter_profile_meter =
1030 TOKEN_STRING_INITIALIZER(
1031 struct cmd_set_port_meter_profile_result, meter, "meter");
1032 cmdline_parse_token_string_t cmd_set_port_meter_profile_profile =
1033 TOKEN_STRING_INITIALIZER(
1034 struct cmd_set_port_meter_profile_result, profile, "profile");
1035 cmdline_parse_token_num_t cmd_set_port_meter_profile_port_id =
1036 TOKEN_NUM_INITIALIZER(
1037 struct cmd_set_port_meter_profile_result, port_id,
1039 cmdline_parse_token_num_t cmd_set_port_meter_profile_mtr_id =
1040 TOKEN_NUM_INITIALIZER(
1041 struct cmd_set_port_meter_profile_result, mtr_id,
1043 cmdline_parse_token_num_t cmd_set_port_meter_profile_profile_id =
1044 TOKEN_NUM_INITIALIZER(
1045 struct cmd_set_port_meter_profile_result, profile_id,
1048 static void cmd_set_port_meter_profile_parsed(void *parsed_result,
1049 __rte_unused struct cmdline *cl,
1050 __rte_unused void *data)
1052 struct cmd_set_port_meter_profile_result *res = parsed_result;
1053 struct rte_mtr_error error;
1054 uint32_t mtr_id = res->mtr_id;
1055 uint32_t profile_id = res->profile_id;
1056 uint16_t port_id = res->port_id;
1060 if (port_id_is_invalid(port_id, ENABLED_WARN))
1063 /* Set meter profile */
1064 ret = rte_mtr_meter_profile_update(port_id, mtr_id,
1065 profile_id, &error);
1067 print_err_msg(&error);
1072 cmdline_parse_inst_t cmd_set_port_meter_profile = {
1073 .f = cmd_set_port_meter_profile_parsed,
1075 .help_str = "set port meter profile <port_id> <mtr_id> <profile_id>",
1077 (void *)&cmd_set_port_meter_profile_set,
1078 (void *)&cmd_set_port_meter_profile_port,
1079 (void *)&cmd_set_port_meter_profile_meter,
1080 (void *)&cmd_set_port_meter_profile_profile,
1081 (void *)&cmd_set_port_meter_profile_port_id,
1082 (void *)&cmd_set_port_meter_profile_mtr_id,
1083 (void *)&cmd_set_port_meter_profile_profile_id,
1088 /* *** Set Port Meter DSCP Table *** */
1089 struct cmd_set_port_meter_dscp_table_result {
1090 cmdline_fixed_string_t set;
1091 cmdline_fixed_string_t port;
1092 cmdline_fixed_string_t meter;
1093 cmdline_fixed_string_t dscp_table;
1094 cmdline_multi_string_t token_string;
1097 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_set =
1098 TOKEN_STRING_INITIALIZER(
1099 struct cmd_set_port_meter_dscp_table_result, set, "set");
1100 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_port =
1101 TOKEN_STRING_INITIALIZER(
1102 struct cmd_set_port_meter_dscp_table_result, port, "port");
1103 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_meter =
1104 TOKEN_STRING_INITIALIZER(
1105 struct cmd_set_port_meter_dscp_table_result, meter, "meter");
1106 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_dscp_table =
1107 TOKEN_STRING_INITIALIZER(
1108 struct cmd_set_port_meter_dscp_table_result,
1109 dscp_table, "dscp table");
1110 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_token_string =
1111 TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_dscp_table_result,
1112 token_string, TOKEN_STRING_MULTI);
1114 static void cmd_set_port_meter_dscp_table_parsed(void *parsed_result,
1115 __rte_unused struct cmdline *cl,
1116 __rte_unused void *data)
1118 struct cmd_set_port_meter_dscp_table_result *res = parsed_result;
1119 struct rte_mtr_error error;
1120 enum rte_color *dscp_table = NULL;
1121 char *t_str = res->token_string;
1122 uint32_t mtr_id = 0;
1127 ret = parse_multi_token_string(t_str, &port_id, &mtr_id, &dscp_table);
1129 printf(" Multi token string parse error\n");
1133 if (port_id_is_invalid(port_id, ENABLED_WARN))
1136 /* Update Meter DSCP Table*/
1137 ret = rte_mtr_meter_dscp_table_update(port_id, mtr_id,
1138 dscp_table, &error);
1140 print_err_msg(&error);
1146 cmdline_parse_inst_t cmd_set_port_meter_dscp_table = {
1147 .f = cmd_set_port_meter_dscp_table_parsed,
1149 .help_str = "set port meter dscp table <port_id> <mtr_id> "
1150 "[<dscp_tbl_entry0> <dscp_tbl_entry1> ... <dscp_tbl_entry63>]",
1152 (void *)&cmd_set_port_meter_dscp_table_set,
1153 (void *)&cmd_set_port_meter_dscp_table_port,
1154 (void *)&cmd_set_port_meter_dscp_table_meter,
1155 (void *)&cmd_set_port_meter_dscp_table_dscp_table,
1156 (void *)&cmd_set_port_meter_dscp_table_token_string,
1161 /* *** Set Port Meter Stats Mask *** */
1162 struct cmd_set_port_meter_stats_mask_result {
1163 cmdline_fixed_string_t set;
1164 cmdline_fixed_string_t port;
1165 cmdline_fixed_string_t meter;
1166 cmdline_fixed_string_t stats;
1167 cmdline_fixed_string_t mask;
1170 uint64_t stats_mask;
1173 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_set =
1174 TOKEN_STRING_INITIALIZER(
1175 struct cmd_set_port_meter_stats_mask_result, set, "set");
1176 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_port =
1177 TOKEN_STRING_INITIALIZER(
1178 struct cmd_set_port_meter_stats_mask_result, port, "port");
1179 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_meter =
1180 TOKEN_STRING_INITIALIZER(
1181 struct cmd_set_port_meter_stats_mask_result, meter, "meter");
1182 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_stats =
1183 TOKEN_STRING_INITIALIZER(
1184 struct cmd_set_port_meter_stats_mask_result, stats, "stats");
1185 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_mask =
1186 TOKEN_STRING_INITIALIZER(
1187 struct cmd_set_port_meter_stats_mask_result, mask, "mask");
1188 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_port_id =
1189 TOKEN_NUM_INITIALIZER(
1190 struct cmd_set_port_meter_stats_mask_result, port_id,
1192 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_mtr_id =
1193 TOKEN_NUM_INITIALIZER(
1194 struct cmd_set_port_meter_stats_mask_result, mtr_id,
1196 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_stats_mask =
1197 TOKEN_NUM_INITIALIZER(
1198 struct cmd_set_port_meter_stats_mask_result, stats_mask,
1201 static void cmd_set_port_meter_stats_mask_parsed(void *parsed_result,
1202 __rte_unused struct cmdline *cl,
1203 __rte_unused void *data)
1205 struct cmd_set_port_meter_stats_mask_result *res = parsed_result;
1206 struct rte_mtr_error error;
1207 uint64_t stats_mask = res->stats_mask;
1208 uint32_t mtr_id = res->mtr_id;
1209 uint16_t port_id = res->port_id;
1212 if (port_id_is_invalid(port_id, ENABLED_WARN))
1215 ret = rte_mtr_stats_update(port_id, mtr_id, stats_mask, &error);
1217 print_err_msg(&error);
1222 cmdline_parse_inst_t cmd_set_port_meter_stats_mask = {
1223 .f = cmd_set_port_meter_stats_mask_parsed,
1225 .help_str = "set port meter stats mask <port_id> <mtr_id> <stats_mask>",
1227 (void *)&cmd_set_port_meter_stats_mask_set,
1228 (void *)&cmd_set_port_meter_stats_mask_port,
1229 (void *)&cmd_set_port_meter_stats_mask_meter,
1230 (void *)&cmd_set_port_meter_stats_mask_stats,
1231 (void *)&cmd_set_port_meter_stats_mask_mask,
1232 (void *)&cmd_set_port_meter_stats_mask_port_id,
1233 (void *)&cmd_set_port_meter_stats_mask_mtr_id,
1234 (void *)&cmd_set_port_meter_stats_mask_stats_mask,
1239 /* *** Show Port Meter Stats *** */
1240 struct cmd_show_port_meter_stats_result {
1241 cmdline_fixed_string_t show;
1242 cmdline_fixed_string_t port;
1243 cmdline_fixed_string_t meter;
1244 cmdline_fixed_string_t stats;
1247 cmdline_fixed_string_t clear;
1250 cmdline_parse_token_string_t cmd_show_port_meter_stats_show =
1251 TOKEN_STRING_INITIALIZER(
1252 struct cmd_show_port_meter_stats_result, show, "show");
1253 cmdline_parse_token_string_t cmd_show_port_meter_stats_port =
1254 TOKEN_STRING_INITIALIZER(
1255 struct cmd_show_port_meter_stats_result, port, "port");
1256 cmdline_parse_token_string_t cmd_show_port_meter_stats_meter =
1257 TOKEN_STRING_INITIALIZER(
1258 struct cmd_show_port_meter_stats_result, meter, "meter");
1259 cmdline_parse_token_string_t cmd_show_port_meter_stats_stats =
1260 TOKEN_STRING_INITIALIZER(
1261 struct cmd_show_port_meter_stats_result, stats, "stats");
1262 cmdline_parse_token_num_t cmd_show_port_meter_stats_port_id =
1263 TOKEN_NUM_INITIALIZER(
1264 struct cmd_show_port_meter_stats_result, port_id, RTE_UINT16);
1265 cmdline_parse_token_num_t cmd_show_port_meter_stats_mtr_id =
1266 TOKEN_NUM_INITIALIZER(
1267 struct cmd_show_port_meter_stats_result, mtr_id, RTE_UINT32);
1268 cmdline_parse_token_string_t cmd_show_port_meter_stats_clear =
1269 TOKEN_STRING_INITIALIZER(
1270 struct cmd_show_port_meter_stats_result, clear, "yes#no");
1272 static void cmd_show_port_meter_stats_parsed(void *parsed_result,
1273 __rte_unused struct cmdline *cl,
1274 __rte_unused void *data)
1276 struct cmd_show_port_meter_stats_result *res = parsed_result;
1277 struct rte_mtr_stats stats;
1278 uint64_t stats_mask = 0;
1279 struct rte_mtr_error error;
1280 uint32_t mtr_id = res->mtr_id;
1282 uint16_t port_id = res->port_id;
1285 if (port_id_is_invalid(port_id, ENABLED_WARN))
1288 if (strcmp(res->clear, "yes") == 0)
1291 memset(&stats, 0, sizeof(struct rte_mtr_stats));
1292 ret = rte_mtr_stats_read(port_id, mtr_id, &stats,
1293 &stats_mask, clear, &error);
1295 print_err_msg(&error);
1300 if (stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
1301 printf("\tPkts G: %" PRIu64 "\n",
1302 stats.n_pkts[RTE_COLOR_GREEN]);
1303 if (stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
1304 printf("\tBytes G: %" PRIu64 "\n",
1305 stats.n_bytes[RTE_COLOR_GREEN]);
1306 if (stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
1307 printf("\tPkts Y: %" PRIu64 "\n",
1308 stats.n_pkts[RTE_COLOR_YELLOW]);
1309 if (stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
1310 printf("\tBytes Y: %" PRIu64 "\n",
1311 stats.n_bytes[RTE_COLOR_YELLOW]);
1312 if (stats_mask & RTE_MTR_STATS_N_PKTS_RED)
1313 printf("\tPkts R: %" PRIu64 "\n",
1314 stats.n_pkts[RTE_COLOR_RED]);
1315 if (stats_mask & RTE_MTR_STATS_N_BYTES_RED)
1316 printf("\tBytes R: %" PRIu64 "\n",
1317 stats.n_bytes[RTE_COLOR_RED]);
1318 if (stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
1319 printf("\tPkts DROPPED: %" PRIu64 "\n",
1320 stats.n_pkts_dropped);
1321 if (stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
1322 printf("\tBytes DROPPED: %" PRIu64 "\n",
1323 stats.n_bytes_dropped);
1326 cmdline_parse_inst_t cmd_show_port_meter_stats = {
1327 .f = cmd_show_port_meter_stats_parsed,
1329 .help_str = "show port meter stats <port_id> <mtr_id> <clear>(yes|no)",
1331 (void *)&cmd_show_port_meter_stats_show,
1332 (void *)&cmd_show_port_meter_stats_port,
1333 (void *)&cmd_show_port_meter_stats_meter,
1334 (void *)&cmd_show_port_meter_stats_stats,
1335 (void *)&cmd_show_port_meter_stats_port_id,
1336 (void *)&cmd_show_port_meter_stats_mtr_id,
1337 (void *)&cmd_show_port_meter_stats_clear,