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]
40 [RTE_MTR_ERROR_TYPE_METER_POLICY_ID] = "meter policy id",
41 [RTE_MTR_ERROR_TYPE_METER_POLICY] = "meter policy null",
47 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
48 !errstrlist[error->type])
49 errstr = "unknown type";
51 errstr = errstrlist[error->type];
54 snprintf(buf, sizeof(buf), "cause: %p, ", error->cause);
56 printf("%s: %s%s (error %d)\n", errstr, error->cause ? buf : "",
57 error->message ? error->message : "(no stated reason)",
62 print_mtr_err_msg(struct rte_mtr_error *error)
68 parse_uint(uint64_t *value, const char *str)
74 /* Parse number string */
75 n = strtol(str, &next, 10);
76 if (errno != 0 || str == next || *next != '\0')
85 parse_dscp_table_entries(char *str, enum rte_color **dscp_table)
90 token = strtok_r(str, PARSE_DELIMITER, &str);
94 /* Allocate memory for dscp table */
95 *dscp_table = (enum rte_color *)malloc(MAX_DSCP_TABLE_ENTRIES *
96 sizeof(enum rte_color));
97 if (*dscp_table == NULL)
101 if (strcmp(token, "G") == 0 ||
102 strcmp(token, "g") == 0)
103 *dscp_table[i++] = RTE_COLOR_GREEN;
104 else if (strcmp(token, "Y") == 0 ||
105 strcmp(token, "y") == 0)
106 *dscp_table[i++] = RTE_COLOR_YELLOW;
107 else if (strcmp(token, "R") == 0 ||
108 strcmp(token, "r") == 0)
109 *dscp_table[i++] = RTE_COLOR_RED;
114 if (i == MAX_DSCP_TABLE_ENTRIES)
117 token = strtok_r(str, PARSE_DELIMITER, &str);
127 parse_meter_color_str(char *c_str, uint32_t *use_prev_meter_color,
128 enum rte_color **dscp_table)
131 uint64_t previous_mtr_color = 0;
134 /* First token: use previous meter color */
135 token = strtok_r(c_str, PARSE_DELIMITER, &c_str);
139 ret = parse_uint(&previous_mtr_color, token);
143 /* Check if previous meter color to be used */
144 if (previous_mtr_color) {
145 *use_prev_meter_color = previous_mtr_color;
149 /* Parse dscp table entries */
150 ret = parse_dscp_table_entries(c_str, dscp_table);
158 parse_multi_token_string(char *t_str, uint16_t *port_id,
159 uint32_t *mtr_id, enum rte_color **dscp_table)
165 /* First token: port id */
166 token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
170 ret = parse_uint(&val, token);
171 if (ret != 0 || val > UINT16_MAX)
176 /* Second token: meter id */
177 token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
181 ret = parse_uint(&val, token);
182 if (ret != 0 || val > UINT32_MAX)
187 ret = parse_dscp_table_entries(t_str, dscp_table);
194 /* *** Show Port Meter Capabilities *** */
195 struct cmd_show_port_meter_cap_result {
196 cmdline_fixed_string_t show;
197 cmdline_fixed_string_t port;
198 cmdline_fixed_string_t meter;
199 cmdline_fixed_string_t cap;
203 cmdline_parse_token_string_t cmd_show_port_meter_cap_show =
204 TOKEN_STRING_INITIALIZER(
205 struct cmd_show_port_meter_cap_result, show, "show");
206 cmdline_parse_token_string_t cmd_show_port_meter_cap_port =
207 TOKEN_STRING_INITIALIZER(
208 struct cmd_show_port_meter_cap_result, port, "port");
209 cmdline_parse_token_string_t cmd_show_port_meter_cap_meter =
210 TOKEN_STRING_INITIALIZER(
211 struct cmd_show_port_meter_cap_result, meter, "meter");
212 cmdline_parse_token_string_t cmd_show_port_meter_cap_cap =
213 TOKEN_STRING_INITIALIZER(
214 struct cmd_show_port_meter_cap_result, cap, "cap");
215 cmdline_parse_token_num_t cmd_show_port_meter_cap_port_id =
216 TOKEN_NUM_INITIALIZER(
217 struct cmd_show_port_meter_cap_result, port_id, RTE_UINT16);
219 static void cmd_show_port_meter_cap_parsed(void *parsed_result,
220 __rte_unused struct cmdline *cl,
221 __rte_unused void *data)
223 struct cmd_show_port_meter_cap_result *res = parsed_result;
224 struct rte_mtr_capabilities cap;
225 struct rte_mtr_error error;
226 uint16_t port_id = res->port_id;
229 if (port_id_is_invalid(port_id, ENABLED_WARN))
232 memset(&cap, 0, sizeof(struct rte_mtr_capabilities));
233 ret = rte_mtr_capabilities_get(port_id, &cap, &error);
235 print_err_msg(&error);
239 printf("\n**** Port Meter Object Capabilities ****\n\n");
240 printf("cap.n_max %" PRIu32 "\n", cap.n_max);
241 printf("cap.n_shared_max %" PRIu32 "\n", cap.n_shared_max);
242 printf("cap.identical %" PRId32 "\n", cap.identical);
243 printf("cap.shared_identical %" PRId32 "\n",
244 cap.shared_identical);
245 printf("cap.shared_n_flows_per_mtr_max %" PRIu32 "\n",
246 cap.shared_n_flows_per_mtr_max);
247 printf("cap.chaining_n_mtrs_per_flow_max %" PRIu32 "\n",
248 cap.chaining_n_mtrs_per_flow_max);
249 printf("cap.chaining_use_prev_mtr_color_supported %" PRId32 "\n",
250 cap.chaining_use_prev_mtr_color_supported);
251 printf("cap.chaining_use_prev_mtr_color_enforced %" PRId32 "\n",
252 cap.chaining_use_prev_mtr_color_enforced);
253 printf("cap.meter_srtcm_rfc2697_n_max %" PRIu32 "\n",
254 cap.meter_srtcm_rfc2697_n_max);
255 printf("cap.meter_trtcm_rfc2698_n_max %" PRIu32 "\n",
256 cap.meter_trtcm_rfc2698_n_max);
257 printf("cap.meter_trtcm_rfc4115_n_max %" PRIu32 "\n",
258 cap.meter_trtcm_rfc4115_n_max);
259 printf("cap.meter_rate_max %" PRIu64 "\n", cap.meter_rate_max);
260 printf("cap.color_aware_srtcm_rfc2697_supported %" PRId32 "\n",
261 cap.color_aware_srtcm_rfc2697_supported);
262 printf("cap.color_aware_trtcm_rfc2698_supported %" PRId32 "\n",
263 cap.color_aware_trtcm_rfc2698_supported);
264 printf("cap.color_aware_trtcm_rfc4115_supported %" PRId32 "\n",
265 cap.color_aware_trtcm_rfc4115_supported);
266 printf("cap.srtcm_rfc2697_byte_mode_supported %" PRId32 "\n",
267 cap.srtcm_rfc2697_byte_mode_supported);
268 printf("cap.srtcm_rfc2697_packet_mode_supported %" PRId32 "\n",
269 cap.srtcm_rfc2697_packet_mode_supported);
270 printf("cap.trtcm_rfc2698_byte_mode_supported %" PRId32 "\n",
271 cap.trtcm_rfc2698_byte_mode_supported);
272 printf("cap.trtcm_rfc2698_packet_mode_supported %" PRId32 "\n",
273 cap.trtcm_rfc2698_packet_mode_supported);
274 printf("cap.trtcm_rfc4115_byte_mode_supported %" PRId32 "\n",
275 cap.trtcm_rfc4115_byte_mode_supported);
276 printf("cap.trtcm_rfc4115_packet_mode_supported %" PRId32 "\n",
277 cap.trtcm_rfc4115_packet_mode_supported);
278 printf("cap.stats_mask %" PRIx64 "\n", cap.stats_mask);
281 cmdline_parse_inst_t cmd_show_port_meter_cap = {
282 .f = cmd_show_port_meter_cap_parsed,
284 .help_str = "show port meter cap <port_id>",
286 (void *)&cmd_show_port_meter_cap_show,
287 (void *)&cmd_show_port_meter_cap_port,
288 (void *)&cmd_show_port_meter_cap_meter,
289 (void *)&cmd_show_port_meter_cap_cap,
290 (void *)&cmd_show_port_meter_cap_port_id,
295 /* *** Add Port Meter Profile srtcm_rfc2697 *** */
296 struct cmd_add_port_meter_profile_srtcm_result {
297 cmdline_fixed_string_t add;
298 cmdline_fixed_string_t port;
299 cmdline_fixed_string_t meter;
300 cmdline_fixed_string_t profile;
301 cmdline_fixed_string_t srtcm_rfc2697;
310 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_add =
311 TOKEN_STRING_INITIALIZER(
312 struct cmd_add_port_meter_profile_srtcm_result, add, "add");
313 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_port =
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_meter =
318 TOKEN_STRING_INITIALIZER(
319 struct cmd_add_port_meter_profile_srtcm_result,
321 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_profile =
322 TOKEN_STRING_INITIALIZER(
323 struct cmd_add_port_meter_profile_srtcm_result,
325 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_srtcm_rfc2697 =
326 TOKEN_STRING_INITIALIZER(
327 struct cmd_add_port_meter_profile_srtcm_result,
328 srtcm_rfc2697, "srtcm_rfc2697");
329 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_port_id =
330 TOKEN_NUM_INITIALIZER(
331 struct cmd_add_port_meter_profile_srtcm_result,
332 port_id, RTE_UINT16);
333 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_profile_id =
334 TOKEN_NUM_INITIALIZER(
335 struct cmd_add_port_meter_profile_srtcm_result,
336 profile_id, RTE_UINT32);
337 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cir =
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_cbs =
342 TOKEN_NUM_INITIALIZER(
343 struct cmd_add_port_meter_profile_srtcm_result,
345 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_ebs =
346 TOKEN_NUM_INITIALIZER(
347 struct cmd_add_port_meter_profile_srtcm_result,
349 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_packet_mode =
350 TOKEN_NUM_INITIALIZER(
351 struct cmd_add_port_meter_profile_srtcm_result,
352 packet_mode, RTE_UINT32);
354 static void cmd_add_port_meter_profile_srtcm_parsed(void *parsed_result,
355 __rte_unused struct cmdline *cl,
356 __rte_unused void *data)
358 struct cmd_add_port_meter_profile_srtcm_result *res = parsed_result;
359 struct rte_mtr_meter_profile mp;
360 struct rte_mtr_error error;
361 uint32_t profile_id = res->profile_id;
362 uint16_t port_id = res->port_id;
365 if (port_id_is_invalid(port_id, ENABLED_WARN))
368 /* Private shaper profile params */
369 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
370 mp.alg = RTE_MTR_SRTCM_RFC2697;
371 mp.srtcm_rfc2697.cir = res->cir;
372 mp.srtcm_rfc2697.cbs = res->cbs;
373 mp.srtcm_rfc2697.ebs = res->ebs;
374 mp.packet_mode = res->packet_mode;
376 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
378 print_err_msg(&error);
383 cmdline_parse_inst_t cmd_add_port_meter_profile_srtcm = {
384 .f = cmd_add_port_meter_profile_srtcm_parsed,
386 .help_str = "add port meter profile srtcm_rfc2697 <port_id> <profile_id> <cir> <cbs> <ebs> <packet_mode>",
388 (void *)&cmd_add_port_meter_profile_srtcm_add,
389 (void *)&cmd_add_port_meter_profile_srtcm_port,
390 (void *)&cmd_add_port_meter_profile_srtcm_meter,
391 (void *)&cmd_add_port_meter_profile_srtcm_profile,
392 (void *)&cmd_add_port_meter_profile_srtcm_srtcm_rfc2697,
393 (void *)&cmd_add_port_meter_profile_srtcm_port_id,
394 (void *)&cmd_add_port_meter_profile_srtcm_profile_id,
395 (void *)&cmd_add_port_meter_profile_srtcm_cir,
396 (void *)&cmd_add_port_meter_profile_srtcm_cbs,
397 (void *)&cmd_add_port_meter_profile_srtcm_ebs,
398 (void *)&cmd_add_port_meter_profile_srtcm_packet_mode,
403 /* *** Add Port Meter Profile trtcm_rfc2698 *** */
404 struct cmd_add_port_meter_profile_trtcm_result {
405 cmdline_fixed_string_t add;
406 cmdline_fixed_string_t port;
407 cmdline_fixed_string_t meter;
408 cmdline_fixed_string_t profile;
409 cmdline_fixed_string_t trtcm_rfc2698;
419 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_add =
420 TOKEN_STRING_INITIALIZER(
421 struct cmd_add_port_meter_profile_trtcm_result, add, "add");
422 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_port =
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_meter =
427 TOKEN_STRING_INITIALIZER(
428 struct cmd_add_port_meter_profile_trtcm_result,
430 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_profile =
431 TOKEN_STRING_INITIALIZER(
432 struct cmd_add_port_meter_profile_trtcm_result,
434 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_trtcm_rfc2698 =
435 TOKEN_STRING_INITIALIZER(
436 struct cmd_add_port_meter_profile_trtcm_result,
437 trtcm_rfc2698, "trtcm_rfc2698");
438 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_port_id =
439 TOKEN_NUM_INITIALIZER(
440 struct cmd_add_port_meter_profile_trtcm_result,
441 port_id, RTE_UINT16);
442 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_profile_id =
443 TOKEN_NUM_INITIALIZER(
444 struct cmd_add_port_meter_profile_trtcm_result,
445 profile_id, RTE_UINT32);
446 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cir =
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_pir =
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_cbs =
455 TOKEN_NUM_INITIALIZER(
456 struct cmd_add_port_meter_profile_trtcm_result,
458 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pbs =
459 TOKEN_NUM_INITIALIZER(
460 struct cmd_add_port_meter_profile_trtcm_result,
462 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_packet_mode =
463 TOKEN_NUM_INITIALIZER(
464 struct cmd_add_port_meter_profile_trtcm_result,
465 packet_mode, RTE_UINT32);
467 static void cmd_add_port_meter_profile_trtcm_parsed(void *parsed_result,
468 __rte_unused struct cmdline *cl,
469 __rte_unused void *data)
471 struct cmd_add_port_meter_profile_trtcm_result *res = parsed_result;
472 struct rte_mtr_meter_profile mp;
473 struct rte_mtr_error error;
474 uint32_t profile_id = res->profile_id;
475 uint16_t port_id = res->port_id;
478 if (port_id_is_invalid(port_id, ENABLED_WARN))
481 /* Private shaper profile params */
482 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
483 mp.alg = RTE_MTR_TRTCM_RFC2698;
484 mp.trtcm_rfc2698.cir = res->cir;
485 mp.trtcm_rfc2698.pir = res->pir;
486 mp.trtcm_rfc2698.cbs = res->cbs;
487 mp.trtcm_rfc2698.pbs = res->pbs;
488 mp.packet_mode = res->packet_mode;
490 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
492 print_err_msg(&error);
497 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm = {
498 .f = cmd_add_port_meter_profile_trtcm_parsed,
500 .help_str = "add port meter profile trtcm_rfc2698 <port_id> <profile_id> <cir> <pir> <cbs> <pbs> <packet_mode>",
502 (void *)&cmd_add_port_meter_profile_trtcm_add,
503 (void *)&cmd_add_port_meter_profile_trtcm_port,
504 (void *)&cmd_add_port_meter_profile_trtcm_meter,
505 (void *)&cmd_add_port_meter_profile_trtcm_profile,
506 (void *)&cmd_add_port_meter_profile_trtcm_trtcm_rfc2698,
507 (void *)&cmd_add_port_meter_profile_trtcm_port_id,
508 (void *)&cmd_add_port_meter_profile_trtcm_profile_id,
509 (void *)&cmd_add_port_meter_profile_trtcm_cir,
510 (void *)&cmd_add_port_meter_profile_trtcm_pir,
511 (void *)&cmd_add_port_meter_profile_trtcm_cbs,
512 (void *)&cmd_add_port_meter_profile_trtcm_pbs,
513 (void *)&cmd_add_port_meter_profile_trtcm_packet_mode,
518 /* *** Add Port Meter Profile trtcm_rfc4115 *** */
519 struct cmd_add_port_meter_profile_trtcm_rfc4115_result {
520 cmdline_fixed_string_t add;
521 cmdline_fixed_string_t port;
522 cmdline_fixed_string_t meter;
523 cmdline_fixed_string_t profile;
524 cmdline_fixed_string_t trtcm_rfc4115;
534 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_add =
535 TOKEN_STRING_INITIALIZER(
536 struct cmd_add_port_meter_profile_trtcm_rfc4115_result, add,
538 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_port =
539 TOKEN_STRING_INITIALIZER(
540 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
542 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_meter =
543 TOKEN_STRING_INITIALIZER(
544 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
546 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_profile =
547 TOKEN_STRING_INITIALIZER(
548 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
550 cmdline_parse_token_string_t
551 cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115 =
552 TOKEN_STRING_INITIALIZER(
553 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
554 trtcm_rfc4115, "trtcm_rfc4115");
555 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_port_id =
556 TOKEN_NUM_INITIALIZER(
557 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
558 port_id, RTE_UINT16);
559 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_profile_id =
560 TOKEN_NUM_INITIALIZER(
561 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
562 profile_id, RTE_UINT32);
563 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cir =
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_eir =
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_cbs =
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_ebs =
576 TOKEN_NUM_INITIALIZER(
577 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
579 cmdline_parse_token_num_t
580 cmd_add_port_meter_profile_trtcm_rfc4115_packet_mode =
581 TOKEN_NUM_INITIALIZER(
582 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
583 packet_mode, RTE_UINT32);
585 static void cmd_add_port_meter_profile_trtcm_rfc4115_parsed(
587 __rte_unused struct cmdline *cl,
588 __rte_unused void *data)
590 struct cmd_add_port_meter_profile_trtcm_rfc4115_result *res =
592 struct rte_mtr_meter_profile mp;
593 struct rte_mtr_error error;
594 uint32_t profile_id = res->profile_id;
595 uint16_t port_id = res->port_id;
598 if (port_id_is_invalid(port_id, ENABLED_WARN))
601 /* Private shaper profile params */
602 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
603 mp.alg = RTE_MTR_TRTCM_RFC4115;
604 mp.trtcm_rfc4115.cir = res->cir;
605 mp.trtcm_rfc4115.eir = res->eir;
606 mp.trtcm_rfc4115.cbs = res->cbs;
607 mp.trtcm_rfc4115.ebs = res->ebs;
608 mp.packet_mode = res->packet_mode;
610 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
612 print_err_msg(&error);
617 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm_rfc4115 = {
618 .f = cmd_add_port_meter_profile_trtcm_rfc4115_parsed,
620 .help_str = "add port meter profile trtcm_rfc4115 <port_id> <profile_id> <cir> <eir> <cbs> <ebs> <packet_mode>",
622 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_add,
623 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port,
624 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_meter,
625 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile,
626 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115,
627 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port_id,
628 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile_id,
629 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cir,
630 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_eir,
631 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cbs,
632 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_ebs,
633 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_packet_mode,
638 /* *** Delete Port Meter Profile *** */
639 struct cmd_del_port_meter_profile_result {
640 cmdline_fixed_string_t del;
641 cmdline_fixed_string_t port;
642 cmdline_fixed_string_t meter;
643 cmdline_fixed_string_t profile;
648 cmdline_parse_token_string_t cmd_del_port_meter_profile_del =
649 TOKEN_STRING_INITIALIZER(
650 struct cmd_del_port_meter_profile_result, del, "del");
651 cmdline_parse_token_string_t cmd_del_port_meter_profile_port =
652 TOKEN_STRING_INITIALIZER(
653 struct cmd_del_port_meter_profile_result,
655 cmdline_parse_token_string_t cmd_del_port_meter_profile_meter =
656 TOKEN_STRING_INITIALIZER(
657 struct cmd_del_port_meter_profile_result,
659 cmdline_parse_token_string_t cmd_del_port_meter_profile_profile =
660 TOKEN_STRING_INITIALIZER(
661 struct cmd_del_port_meter_profile_result,
663 cmdline_parse_token_num_t cmd_del_port_meter_profile_port_id =
664 TOKEN_NUM_INITIALIZER(
665 struct cmd_del_port_meter_profile_result,
666 port_id, RTE_UINT16);
667 cmdline_parse_token_num_t cmd_del_port_meter_profile_profile_id =
668 TOKEN_NUM_INITIALIZER(
669 struct cmd_del_port_meter_profile_result,
670 profile_id, RTE_UINT32);
672 static void cmd_del_port_meter_profile_parsed(void *parsed_result,
673 __rte_unused struct cmdline *cl,
674 __rte_unused void *data)
676 struct cmd_del_port_meter_profile_result *res = parsed_result;
677 struct rte_mtr_error error;
678 uint32_t profile_id = res->profile_id;
679 uint16_t port_id = res->port_id;
682 if (port_id_is_invalid(port_id, ENABLED_WARN))
685 /* Delete meter profile */
686 ret = rte_mtr_meter_profile_delete(port_id, profile_id, &error);
688 print_err_msg(&error);
693 cmdline_parse_inst_t cmd_del_port_meter_profile = {
694 .f = cmd_del_port_meter_profile_parsed,
696 .help_str = "del port meter profile <port_id> <profile_id>",
698 (void *)&cmd_del_port_meter_profile_del,
699 (void *)&cmd_del_port_meter_profile_port,
700 (void *)&cmd_del_port_meter_profile_meter,
701 (void *)&cmd_del_port_meter_profile_profile,
702 (void *)&cmd_del_port_meter_profile_port_id,
703 (void *)&cmd_del_port_meter_profile_profile_id,
708 /* *** Create Port Meter Object *** */
709 struct cmd_create_port_meter_result {
710 cmdline_fixed_string_t create;
711 cmdline_fixed_string_t port;
712 cmdline_fixed_string_t meter;
717 cmdline_fixed_string_t meter_enable;
718 cmdline_fixed_string_t g_action;
719 cmdline_fixed_string_t y_action;
720 cmdline_fixed_string_t r_action;
721 uint64_t statistics_mask;
723 cmdline_multi_string_t meter_input_color;
726 cmdline_parse_token_string_t cmd_create_port_meter_create =
727 TOKEN_STRING_INITIALIZER(
728 struct cmd_create_port_meter_result, create, "create");
729 cmdline_parse_token_string_t cmd_create_port_meter_port =
730 TOKEN_STRING_INITIALIZER(
731 struct cmd_create_port_meter_result, port, "port");
732 cmdline_parse_token_string_t cmd_create_port_meter_meter =
733 TOKEN_STRING_INITIALIZER(
734 struct cmd_create_port_meter_result, meter, "meter");
735 cmdline_parse_token_num_t cmd_create_port_meter_port_id =
736 TOKEN_NUM_INITIALIZER(
737 struct cmd_create_port_meter_result, port_id, RTE_UINT16);
738 cmdline_parse_token_num_t cmd_create_port_meter_mtr_id =
739 TOKEN_NUM_INITIALIZER(
740 struct cmd_create_port_meter_result, mtr_id, RTE_UINT32);
741 cmdline_parse_token_num_t cmd_create_port_meter_profile_id =
742 TOKEN_NUM_INITIALIZER(
743 struct cmd_create_port_meter_result, profile_id, RTE_UINT32);
744 cmdline_parse_token_num_t cmd_create_port_meter_policy_id =
745 TOKEN_NUM_INITIALIZER(
746 struct cmd_create_port_meter_result, policy_id, RTE_UINT32);
747 cmdline_parse_token_string_t cmd_create_port_meter_meter_enable =
748 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
749 meter_enable, "yes#no");
750 cmdline_parse_token_string_t cmd_create_port_meter_g_action =
751 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
752 g_action, "R#Y#G#D#r#y#g#d");
753 cmdline_parse_token_string_t cmd_create_port_meter_y_action =
754 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
755 y_action, "R#Y#G#D#r#y#g#d");
756 cmdline_parse_token_string_t cmd_create_port_meter_r_action =
757 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
758 r_action, "R#Y#G#D#r#y#g#d");
759 cmdline_parse_token_num_t cmd_create_port_meter_statistics_mask =
760 TOKEN_NUM_INITIALIZER(struct cmd_create_port_meter_result,
761 statistics_mask, RTE_UINT64);
762 cmdline_parse_token_num_t cmd_create_port_meter_shared =
763 TOKEN_NUM_INITIALIZER(struct cmd_create_port_meter_result,
765 cmdline_parse_token_string_t cmd_create_port_meter_input_color =
766 TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
767 meter_input_color, TOKEN_STRING_MULTI);
769 static void cmd_create_port_meter_parsed(void *parsed_result,
770 __rte_unused struct cmdline *cl,
771 __rte_unused void *data)
773 struct cmd_create_port_meter_result *res = parsed_result;
774 struct rte_mtr_error error;
775 struct rte_mtr_params params;
776 uint32_t mtr_id = res->mtr_id;
777 uint32_t shared = res->shared;
778 uint32_t use_prev_meter_color = 0;
779 uint16_t port_id = res->port_id;
780 enum rte_color *dscp_table = NULL;
781 char *c_str = res->meter_input_color;
784 if (port_id_is_invalid(port_id, ENABLED_WARN))
788 memset(¶ms, 0, sizeof(struct rte_mtr_params));
789 params.meter_profile_id = res->profile_id;
790 params.meter_policy_id = res->policy_id;
791 /* Parse meter input color string params */
792 ret = parse_meter_color_str(c_str, &use_prev_meter_color, &dscp_table);
794 printf(" Meter input color params string parse error\n");
798 params.use_prev_mtr_color = use_prev_meter_color;
799 params.dscp_table = dscp_table;
801 if (strcmp(res->meter_enable, "yes") == 0)
802 params.meter_enable = 1;
804 params.meter_enable = 0;
805 params.stats_mask = res->statistics_mask;
807 ret = rte_mtr_create(port_id, mtr_id, ¶ms, shared, &error);
810 print_err_msg(&error);
815 cmdline_parse_inst_t cmd_create_port_meter = {
816 .f = cmd_create_port_meter_parsed,
818 .help_str = "create port meter <port_id> <mtr_id> <profile_id> <meter_enable>(yes|no) "
819 "<stats_mask> <shared> <use_pre_meter_color> "
820 "[<dscp_tbl_entry0> <dscp_tbl_entry1> ...<dscp_tbl_entry63>]",
822 (void *)&cmd_create_port_meter_create,
823 (void *)&cmd_create_port_meter_port,
824 (void *)&cmd_create_port_meter_meter,
825 (void *)&cmd_create_port_meter_port_id,
826 (void *)&cmd_create_port_meter_mtr_id,
827 (void *)&cmd_create_port_meter_profile_id,
828 (void *)&cmd_create_port_meter_policy_id,
829 (void *)&cmd_create_port_meter_meter_enable,
830 (void *)&cmd_create_port_meter_statistics_mask,
831 (void *)&cmd_create_port_meter_shared,
832 (void *)&cmd_create_port_meter_input_color,
837 /* *** Enable Meter of MTR Object *** */
838 struct cmd_enable_port_meter_result {
839 cmdline_fixed_string_t enable;
840 cmdline_fixed_string_t port;
841 cmdline_fixed_string_t meter;
846 cmdline_parse_token_string_t cmd_enable_port_meter_enable =
847 TOKEN_STRING_INITIALIZER(
848 struct cmd_enable_port_meter_result, enable, "enable");
849 cmdline_parse_token_string_t cmd_enable_port_meter_port =
850 TOKEN_STRING_INITIALIZER(
851 struct cmd_enable_port_meter_result, port, "port");
852 cmdline_parse_token_string_t cmd_enable_port_meter_meter =
853 TOKEN_STRING_INITIALIZER(
854 struct cmd_enable_port_meter_result, meter, "meter");
855 cmdline_parse_token_num_t cmd_enable_port_meter_port_id =
856 TOKEN_NUM_INITIALIZER(
857 struct cmd_enable_port_meter_result, port_id, RTE_UINT16);
858 cmdline_parse_token_num_t cmd_enable_port_meter_mtr_id =
859 TOKEN_NUM_INITIALIZER(
860 struct cmd_enable_port_meter_result, mtr_id, RTE_UINT32);
862 static void cmd_enable_port_meter_parsed(void *parsed_result,
863 __rte_unused struct cmdline *cl,
864 __rte_unused void *data)
866 struct cmd_enable_port_meter_result *res = parsed_result;
867 struct rte_mtr_error error;
868 uint32_t mtr_id = res->mtr_id;
869 uint16_t port_id = res->port_id;
873 if (port_id_is_invalid(port_id, ENABLED_WARN))
877 ret = rte_mtr_meter_enable(port_id, mtr_id, &error);
879 print_err_msg(&error);
884 cmdline_parse_inst_t cmd_enable_port_meter = {
885 .f = cmd_enable_port_meter_parsed,
887 .help_str = "enable port meter <port_id> <mtr_id>",
889 (void *)&cmd_enable_port_meter_enable,
890 (void *)&cmd_enable_port_meter_port,
891 (void *)&cmd_enable_port_meter_meter,
892 (void *)&cmd_enable_port_meter_port_id,
893 (void *)&cmd_enable_port_meter_mtr_id,
898 /* *** Disable Meter of MTR Object *** */
899 struct cmd_disable_port_meter_result {
900 cmdline_fixed_string_t disable;
901 cmdline_fixed_string_t port;
902 cmdline_fixed_string_t meter;
907 cmdline_parse_token_string_t cmd_disable_port_meter_disable =
908 TOKEN_STRING_INITIALIZER(
909 struct cmd_disable_port_meter_result, disable, "disable");
910 cmdline_parse_token_string_t cmd_disable_port_meter_port =
911 TOKEN_STRING_INITIALIZER(
912 struct cmd_disable_port_meter_result, port, "port");
913 cmdline_parse_token_string_t cmd_disable_port_meter_meter =
914 TOKEN_STRING_INITIALIZER(
915 struct cmd_disable_port_meter_result, meter, "meter");
916 cmdline_parse_token_num_t cmd_disable_port_meter_port_id =
917 TOKEN_NUM_INITIALIZER(
918 struct cmd_disable_port_meter_result, port_id, RTE_UINT16);
919 cmdline_parse_token_num_t cmd_disable_port_meter_mtr_id =
920 TOKEN_NUM_INITIALIZER(
921 struct cmd_disable_port_meter_result, mtr_id, RTE_UINT32);
923 static void cmd_disable_port_meter_parsed(void *parsed_result,
924 __rte_unused struct cmdline *cl,
925 __rte_unused void *data)
927 struct cmd_disable_port_meter_result *res = parsed_result;
928 struct rte_mtr_error error;
929 uint32_t mtr_id = res->mtr_id;
930 uint16_t port_id = res->port_id;
934 if (port_id_is_invalid(port_id, ENABLED_WARN))
938 ret = rte_mtr_meter_disable(port_id, mtr_id, &error);
940 print_err_msg(&error);
945 cmdline_parse_inst_t cmd_disable_port_meter = {
946 .f = cmd_disable_port_meter_parsed,
948 .help_str = "disable port meter <port_id> <mtr_id>",
950 (void *)&cmd_disable_port_meter_disable,
951 (void *)&cmd_disable_port_meter_port,
952 (void *)&cmd_disable_port_meter_meter,
953 (void *)&cmd_disable_port_meter_port_id,
954 (void *)&cmd_disable_port_meter_mtr_id,
959 /* *** Delete Port Meter Policy Object *** */
960 struct cmd_del_port_meter_policy_result {
961 cmdline_fixed_string_t del;
962 cmdline_fixed_string_t port;
963 cmdline_fixed_string_t meter;
964 cmdline_fixed_string_t policy;
969 cmdline_parse_token_string_t cmd_del_port_meter_policy_del =
970 TOKEN_STRING_INITIALIZER(
971 struct cmd_del_port_meter_policy_result, del, "del");
972 cmdline_parse_token_string_t cmd_del_port_meter_policy_port =
973 TOKEN_STRING_INITIALIZER(
974 struct cmd_del_port_meter_policy_result, port, "port");
975 cmdline_parse_token_string_t cmd_del_port_meter_policy_meter =
976 TOKEN_STRING_INITIALIZER(
977 struct cmd_del_port_meter_policy_result, meter, "meter");
978 cmdline_parse_token_string_t cmd_del_port_meter_policy_policy =
979 TOKEN_STRING_INITIALIZER(
980 struct cmd_del_port_meter_policy_result, policy, "policy");
981 cmdline_parse_token_num_t cmd_del_port_meter_policy_port_id =
982 TOKEN_NUM_INITIALIZER(
983 struct cmd_del_port_meter_policy_result, port_id, RTE_UINT16);
984 cmdline_parse_token_num_t cmd_del_port_meter_policy_policy_id =
985 TOKEN_NUM_INITIALIZER(
986 struct cmd_del_port_meter_policy_result, policy_id, RTE_UINT32);
988 static void cmd_del_port_meter_policy_parsed(void *parsed_result,
989 __rte_unused struct cmdline *cl,
990 __rte_unused void *data)
992 struct cmd_del_port_meter_policy_result *res = parsed_result;
993 struct rte_mtr_error error;
994 uint32_t policy_id = res->policy_id;
995 uint16_t port_id = res->port_id;
998 if (port_id_is_invalid(port_id, ENABLED_WARN))
1001 /* Delete Meter Policy*/
1002 ret = rte_mtr_meter_policy_delete(port_id, policy_id, &error);
1004 print_err_msg(&error);
1009 cmdline_parse_inst_t cmd_del_port_meter_policy = {
1010 .f = cmd_del_port_meter_policy_parsed,
1012 .help_str = "Delete port meter policy",
1014 (void *)&cmd_del_port_meter_policy_del,
1015 (void *)&cmd_del_port_meter_policy_port,
1016 (void *)&cmd_del_port_meter_policy_meter,
1017 (void *)&cmd_del_port_meter_policy_policy,
1018 (void *)&cmd_del_port_meter_policy_port_id,
1019 (void *)&cmd_del_port_meter_policy_policy_id,
1024 /* *** Delete Port Meter Object *** */
1025 struct cmd_del_port_meter_result {
1026 cmdline_fixed_string_t del;
1027 cmdline_fixed_string_t port;
1028 cmdline_fixed_string_t meter;
1033 cmdline_parse_token_string_t cmd_del_port_meter_del =
1034 TOKEN_STRING_INITIALIZER(
1035 struct cmd_del_port_meter_result, del, "del");
1036 cmdline_parse_token_string_t cmd_del_port_meter_port =
1037 TOKEN_STRING_INITIALIZER(
1038 struct cmd_del_port_meter_result, port, "port");
1039 cmdline_parse_token_string_t cmd_del_port_meter_meter =
1040 TOKEN_STRING_INITIALIZER(
1041 struct cmd_del_port_meter_result, meter, "meter");
1042 cmdline_parse_token_num_t cmd_del_port_meter_port_id =
1043 TOKEN_NUM_INITIALIZER(
1044 struct cmd_del_port_meter_result, port_id, RTE_UINT16);
1045 cmdline_parse_token_num_t cmd_del_port_meter_mtr_id =
1046 TOKEN_NUM_INITIALIZER(
1047 struct cmd_del_port_meter_result, mtr_id, RTE_UINT32);
1049 static void cmd_del_port_meter_parsed(void *parsed_result,
1050 __rte_unused struct cmdline *cl,
1051 __rte_unused void *data)
1053 struct cmd_del_port_meter_result *res = parsed_result;
1054 struct rte_mtr_error error;
1055 uint32_t mtr_id = res->mtr_id;
1056 uint16_t port_id = res->port_id;
1060 if (port_id_is_invalid(port_id, ENABLED_WARN))
1064 ret = rte_mtr_destroy(port_id, mtr_id, &error);
1066 print_err_msg(&error);
1071 cmdline_parse_inst_t cmd_del_port_meter = {
1072 .f = cmd_del_port_meter_parsed,
1074 .help_str = "del port meter <port_id> <mtr_id>",
1076 (void *)&cmd_del_port_meter_del,
1077 (void *)&cmd_del_port_meter_port,
1078 (void *)&cmd_del_port_meter_meter,
1079 (void *)&cmd_del_port_meter_port_id,
1080 (void *)&cmd_del_port_meter_mtr_id,
1085 /* *** Set Port Meter Profile *** */
1086 struct cmd_set_port_meter_profile_result {
1087 cmdline_fixed_string_t set;
1088 cmdline_fixed_string_t port;
1089 cmdline_fixed_string_t meter;
1090 cmdline_fixed_string_t profile;
1093 uint32_t profile_id;
1096 cmdline_parse_token_string_t cmd_set_port_meter_profile_set =
1097 TOKEN_STRING_INITIALIZER(
1098 struct cmd_set_port_meter_profile_result, set, "set");
1099 cmdline_parse_token_string_t cmd_set_port_meter_profile_port =
1100 TOKEN_STRING_INITIALIZER(
1101 struct cmd_set_port_meter_profile_result, port, "port");
1102 cmdline_parse_token_string_t cmd_set_port_meter_profile_meter =
1103 TOKEN_STRING_INITIALIZER(
1104 struct cmd_set_port_meter_profile_result, meter, "meter");
1105 cmdline_parse_token_string_t cmd_set_port_meter_profile_profile =
1106 TOKEN_STRING_INITIALIZER(
1107 struct cmd_set_port_meter_profile_result, profile, "profile");
1108 cmdline_parse_token_num_t cmd_set_port_meter_profile_port_id =
1109 TOKEN_NUM_INITIALIZER(
1110 struct cmd_set_port_meter_profile_result, port_id,
1112 cmdline_parse_token_num_t cmd_set_port_meter_profile_mtr_id =
1113 TOKEN_NUM_INITIALIZER(
1114 struct cmd_set_port_meter_profile_result, mtr_id,
1116 cmdline_parse_token_num_t cmd_set_port_meter_profile_profile_id =
1117 TOKEN_NUM_INITIALIZER(
1118 struct cmd_set_port_meter_profile_result, profile_id,
1121 static void cmd_set_port_meter_profile_parsed(void *parsed_result,
1122 __rte_unused struct cmdline *cl,
1123 __rte_unused void *data)
1125 struct cmd_set_port_meter_profile_result *res = parsed_result;
1126 struct rte_mtr_error error;
1127 uint32_t mtr_id = res->mtr_id;
1128 uint32_t profile_id = res->profile_id;
1129 uint16_t port_id = res->port_id;
1133 if (port_id_is_invalid(port_id, ENABLED_WARN))
1136 /* Set meter profile */
1137 ret = rte_mtr_meter_profile_update(port_id, mtr_id,
1138 profile_id, &error);
1140 print_err_msg(&error);
1145 cmdline_parse_inst_t cmd_set_port_meter_profile = {
1146 .f = cmd_set_port_meter_profile_parsed,
1148 .help_str = "set port meter profile <port_id> <mtr_id> <profile_id>",
1150 (void *)&cmd_set_port_meter_profile_set,
1151 (void *)&cmd_set_port_meter_profile_port,
1152 (void *)&cmd_set_port_meter_profile_meter,
1153 (void *)&cmd_set_port_meter_profile_profile,
1154 (void *)&cmd_set_port_meter_profile_port_id,
1155 (void *)&cmd_set_port_meter_profile_mtr_id,
1156 (void *)&cmd_set_port_meter_profile_profile_id,
1161 /* *** Set Port Meter DSCP Table *** */
1162 struct cmd_set_port_meter_dscp_table_result {
1163 cmdline_fixed_string_t set;
1164 cmdline_fixed_string_t port;
1165 cmdline_fixed_string_t meter;
1166 cmdline_fixed_string_t dscp_table;
1167 cmdline_multi_string_t token_string;
1170 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_set =
1171 TOKEN_STRING_INITIALIZER(
1172 struct cmd_set_port_meter_dscp_table_result, set, "set");
1173 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_port =
1174 TOKEN_STRING_INITIALIZER(
1175 struct cmd_set_port_meter_dscp_table_result, port, "port");
1176 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_meter =
1177 TOKEN_STRING_INITIALIZER(
1178 struct cmd_set_port_meter_dscp_table_result, meter, "meter");
1179 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_dscp_table =
1180 TOKEN_STRING_INITIALIZER(
1181 struct cmd_set_port_meter_dscp_table_result,
1182 dscp_table, "dscp table");
1183 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_token_string =
1184 TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_dscp_table_result,
1185 token_string, TOKEN_STRING_MULTI);
1187 static void cmd_set_port_meter_dscp_table_parsed(void *parsed_result,
1188 __rte_unused struct cmdline *cl,
1189 __rte_unused void *data)
1191 struct cmd_set_port_meter_dscp_table_result *res = parsed_result;
1192 struct rte_mtr_error error;
1193 enum rte_color *dscp_table = NULL;
1194 char *t_str = res->token_string;
1195 uint32_t mtr_id = 0;
1200 ret = parse_multi_token_string(t_str, &port_id, &mtr_id, &dscp_table);
1202 printf(" Multi token string parse error\n");
1206 if (port_id_is_invalid(port_id, ENABLED_WARN))
1209 /* Update Meter DSCP Table*/
1210 ret = rte_mtr_meter_dscp_table_update(port_id, mtr_id,
1211 dscp_table, &error);
1213 print_err_msg(&error);
1219 cmdline_parse_inst_t cmd_set_port_meter_dscp_table = {
1220 .f = cmd_set_port_meter_dscp_table_parsed,
1222 .help_str = "set port meter dscp table <port_id> <mtr_id> "
1223 "[<dscp_tbl_entry0> <dscp_tbl_entry1> ... <dscp_tbl_entry63>]",
1225 (void *)&cmd_set_port_meter_dscp_table_set,
1226 (void *)&cmd_set_port_meter_dscp_table_port,
1227 (void *)&cmd_set_port_meter_dscp_table_meter,
1228 (void *)&cmd_set_port_meter_dscp_table_dscp_table,
1229 (void *)&cmd_set_port_meter_dscp_table_token_string,
1234 /* *** Set Port Meter Stats Mask *** */
1235 struct cmd_set_port_meter_stats_mask_result {
1236 cmdline_fixed_string_t set;
1237 cmdline_fixed_string_t port;
1238 cmdline_fixed_string_t meter;
1239 cmdline_fixed_string_t stats;
1240 cmdline_fixed_string_t mask;
1243 uint64_t stats_mask;
1246 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_set =
1247 TOKEN_STRING_INITIALIZER(
1248 struct cmd_set_port_meter_stats_mask_result, set, "set");
1249 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_port =
1250 TOKEN_STRING_INITIALIZER(
1251 struct cmd_set_port_meter_stats_mask_result, port, "port");
1252 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_meter =
1253 TOKEN_STRING_INITIALIZER(
1254 struct cmd_set_port_meter_stats_mask_result, meter, "meter");
1255 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_stats =
1256 TOKEN_STRING_INITIALIZER(
1257 struct cmd_set_port_meter_stats_mask_result, stats, "stats");
1258 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_mask =
1259 TOKEN_STRING_INITIALIZER(
1260 struct cmd_set_port_meter_stats_mask_result, mask, "mask");
1261 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_port_id =
1262 TOKEN_NUM_INITIALIZER(
1263 struct cmd_set_port_meter_stats_mask_result, port_id,
1265 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_mtr_id =
1266 TOKEN_NUM_INITIALIZER(
1267 struct cmd_set_port_meter_stats_mask_result, mtr_id,
1269 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_stats_mask =
1270 TOKEN_NUM_INITIALIZER(
1271 struct cmd_set_port_meter_stats_mask_result, stats_mask,
1274 static void cmd_set_port_meter_stats_mask_parsed(void *parsed_result,
1275 __rte_unused struct cmdline *cl,
1276 __rte_unused void *data)
1278 struct cmd_set_port_meter_stats_mask_result *res = parsed_result;
1279 struct rte_mtr_error error;
1280 uint64_t stats_mask = res->stats_mask;
1281 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 ret = rte_mtr_stats_update(port_id, mtr_id, stats_mask, &error);
1290 print_err_msg(&error);
1295 cmdline_parse_inst_t cmd_set_port_meter_stats_mask = {
1296 .f = cmd_set_port_meter_stats_mask_parsed,
1298 .help_str = "set port meter stats mask <port_id> <mtr_id> <stats_mask>",
1300 (void *)&cmd_set_port_meter_stats_mask_set,
1301 (void *)&cmd_set_port_meter_stats_mask_port,
1302 (void *)&cmd_set_port_meter_stats_mask_meter,
1303 (void *)&cmd_set_port_meter_stats_mask_stats,
1304 (void *)&cmd_set_port_meter_stats_mask_mask,
1305 (void *)&cmd_set_port_meter_stats_mask_port_id,
1306 (void *)&cmd_set_port_meter_stats_mask_mtr_id,
1307 (void *)&cmd_set_port_meter_stats_mask_stats_mask,
1312 /* *** Show Port Meter Stats *** */
1313 struct cmd_show_port_meter_stats_result {
1314 cmdline_fixed_string_t show;
1315 cmdline_fixed_string_t port;
1316 cmdline_fixed_string_t meter;
1317 cmdline_fixed_string_t stats;
1320 cmdline_fixed_string_t clear;
1323 cmdline_parse_token_string_t cmd_show_port_meter_stats_show =
1324 TOKEN_STRING_INITIALIZER(
1325 struct cmd_show_port_meter_stats_result, show, "show");
1326 cmdline_parse_token_string_t cmd_show_port_meter_stats_port =
1327 TOKEN_STRING_INITIALIZER(
1328 struct cmd_show_port_meter_stats_result, port, "port");
1329 cmdline_parse_token_string_t cmd_show_port_meter_stats_meter =
1330 TOKEN_STRING_INITIALIZER(
1331 struct cmd_show_port_meter_stats_result, meter, "meter");
1332 cmdline_parse_token_string_t cmd_show_port_meter_stats_stats =
1333 TOKEN_STRING_INITIALIZER(
1334 struct cmd_show_port_meter_stats_result, stats, "stats");
1335 cmdline_parse_token_num_t cmd_show_port_meter_stats_port_id =
1336 TOKEN_NUM_INITIALIZER(
1337 struct cmd_show_port_meter_stats_result, port_id, RTE_UINT16);
1338 cmdline_parse_token_num_t cmd_show_port_meter_stats_mtr_id =
1339 TOKEN_NUM_INITIALIZER(
1340 struct cmd_show_port_meter_stats_result, mtr_id, RTE_UINT32);
1341 cmdline_parse_token_string_t cmd_show_port_meter_stats_clear =
1342 TOKEN_STRING_INITIALIZER(
1343 struct cmd_show_port_meter_stats_result, clear, "yes#no");
1345 static void cmd_show_port_meter_stats_parsed(void *parsed_result,
1346 __rte_unused struct cmdline *cl,
1347 __rte_unused void *data)
1349 struct cmd_show_port_meter_stats_result *res = parsed_result;
1350 struct rte_mtr_stats stats;
1351 uint64_t stats_mask = 0;
1352 struct rte_mtr_error error;
1353 uint32_t mtr_id = res->mtr_id;
1355 uint16_t port_id = res->port_id;
1358 if (port_id_is_invalid(port_id, ENABLED_WARN))
1361 if (strcmp(res->clear, "yes") == 0)
1364 memset(&stats, 0, sizeof(struct rte_mtr_stats));
1365 ret = rte_mtr_stats_read(port_id, mtr_id, &stats,
1366 &stats_mask, clear, &error);
1368 print_err_msg(&error);
1373 if (stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
1374 printf("\tPkts G: %" PRIu64 "\n",
1375 stats.n_pkts[RTE_COLOR_GREEN]);
1376 if (stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
1377 printf("\tBytes G: %" PRIu64 "\n",
1378 stats.n_bytes[RTE_COLOR_GREEN]);
1379 if (stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
1380 printf("\tPkts Y: %" PRIu64 "\n",
1381 stats.n_pkts[RTE_COLOR_YELLOW]);
1382 if (stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
1383 printf("\tBytes Y: %" PRIu64 "\n",
1384 stats.n_bytes[RTE_COLOR_YELLOW]);
1385 if (stats_mask & RTE_MTR_STATS_N_PKTS_RED)
1386 printf("\tPkts R: %" PRIu64 "\n",
1387 stats.n_pkts[RTE_COLOR_RED]);
1388 if (stats_mask & RTE_MTR_STATS_N_BYTES_RED)
1389 printf("\tBytes R: %" PRIu64 "\n",
1390 stats.n_bytes[RTE_COLOR_RED]);
1391 if (stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
1392 printf("\tPkts DROPPED: %" PRIu64 "\n",
1393 stats.n_pkts_dropped);
1394 if (stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
1395 printf("\tBytes DROPPED: %" PRIu64 "\n",
1396 stats.n_bytes_dropped);
1399 cmdline_parse_inst_t cmd_show_port_meter_stats = {
1400 .f = cmd_show_port_meter_stats_parsed,
1402 .help_str = "show port meter stats <port_id> <mtr_id> <clear>(yes|no)",
1404 (void *)&cmd_show_port_meter_stats_show,
1405 (void *)&cmd_show_port_meter_stats_port,
1406 (void *)&cmd_show_port_meter_stats_meter,
1407 (void *)&cmd_show_port_meter_stats_stats,
1408 (void *)&cmd_show_port_meter_stats_port_id,
1409 (void *)&cmd_show_port_meter_stats_mtr_id,
1410 (void *)&cmd_show_port_meter_stats_clear,