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 fprintf(stderr, "%s: %s%s (error %d)\n",
57 errstr, error->cause ? buf : "",
58 error->message ? error->message : "(no stated reason)",
63 print_mtr_err_msg(struct rte_mtr_error *error)
69 parse_uint(uint64_t *value, const char *str)
75 /* Parse number string */
76 n = strtol(str, &next, 10);
77 if (errno != 0 || str == next || *next != '\0')
86 parse_dscp_table_entries(char *str, enum rte_color **dscp_table)
91 token = strtok_r(str, PARSE_DELIMITER, &str);
95 /* Allocate memory for dscp table */
96 *dscp_table = (enum rte_color *)malloc(MAX_DSCP_TABLE_ENTRIES *
97 sizeof(enum rte_color));
98 if (*dscp_table == NULL)
102 if (strcmp(token, "G") == 0 ||
103 strcmp(token, "g") == 0)
104 (*dscp_table)[i++] = RTE_COLOR_GREEN;
105 else if (strcmp(token, "Y") == 0 ||
106 strcmp(token, "y") == 0)
107 (*dscp_table)[i++] = RTE_COLOR_YELLOW;
108 else if (strcmp(token, "R") == 0 ||
109 strcmp(token, "r") == 0)
110 (*dscp_table)[i++] = RTE_COLOR_RED;
115 if (i == MAX_DSCP_TABLE_ENTRIES)
118 token = strtok_r(str, PARSE_DELIMITER, &str);
128 parse_meter_color_str(char *c_str, uint32_t *use_prev_meter_color,
129 enum rte_color **dscp_table)
132 uint64_t previous_mtr_color = 0;
135 /* First token: use previous meter color */
136 token = strtok_r(c_str, PARSE_DELIMITER, &c_str);
140 ret = parse_uint(&previous_mtr_color, token);
144 /* Check if previous meter color to be used */
145 if (previous_mtr_color) {
146 *use_prev_meter_color = previous_mtr_color;
150 /* Parse dscp table entries */
151 ret = parse_dscp_table_entries(c_str, dscp_table);
159 parse_multi_token_string(char *t_str, uint16_t *port_id,
160 uint32_t *mtr_id, enum rte_color **dscp_table)
166 /* First token: port id */
167 token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
171 ret = parse_uint(&val, token);
172 if (ret != 0 || val > UINT16_MAX)
177 /* Second token: meter id */
178 token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
182 ret = parse_uint(&val, token);
183 if (ret != 0 || val > UINT32_MAX)
188 ret = parse_dscp_table_entries(t_str, dscp_table);
195 /* *** Show Port Meter Capabilities *** */
196 struct cmd_show_port_meter_cap_result {
197 cmdline_fixed_string_t show;
198 cmdline_fixed_string_t port;
199 cmdline_fixed_string_t meter;
200 cmdline_fixed_string_t cap;
204 cmdline_parse_token_string_t cmd_show_port_meter_cap_show =
205 TOKEN_STRING_INITIALIZER(
206 struct cmd_show_port_meter_cap_result, show, "show");
207 cmdline_parse_token_string_t cmd_show_port_meter_cap_port =
208 TOKEN_STRING_INITIALIZER(
209 struct cmd_show_port_meter_cap_result, port, "port");
210 cmdline_parse_token_string_t cmd_show_port_meter_cap_meter =
211 TOKEN_STRING_INITIALIZER(
212 struct cmd_show_port_meter_cap_result, meter, "meter");
213 cmdline_parse_token_string_t cmd_show_port_meter_cap_cap =
214 TOKEN_STRING_INITIALIZER(
215 struct cmd_show_port_meter_cap_result, cap, "cap");
216 cmdline_parse_token_num_t cmd_show_port_meter_cap_port_id =
217 TOKEN_NUM_INITIALIZER(
218 struct cmd_show_port_meter_cap_result, port_id, RTE_UINT16);
220 static void cmd_show_port_meter_cap_parsed(void *parsed_result,
221 __rte_unused struct cmdline *cl,
222 __rte_unused void *data)
224 struct cmd_show_port_meter_cap_result *res = parsed_result;
225 struct rte_mtr_capabilities cap;
226 struct rte_mtr_error error;
227 uint16_t port_id = res->port_id;
230 if (port_id_is_invalid(port_id, ENABLED_WARN))
233 memset(&cap, 0, sizeof(struct rte_mtr_capabilities));
234 ret = rte_mtr_capabilities_get(port_id, &cap, &error);
236 print_err_msg(&error);
240 printf("\n**** Port Meter Object Capabilities ****\n\n");
241 printf("cap.n_max %" PRIu32 "\n", cap.n_max);
242 printf("cap.n_shared_max %" PRIu32 "\n", cap.n_shared_max);
243 printf("cap.identical %" PRId32 "\n", cap.identical);
244 printf("cap.shared_identical %" PRId32 "\n",
245 cap.shared_identical);
246 printf("cap.shared_n_flows_per_mtr_max %" PRIu32 "\n",
247 cap.shared_n_flows_per_mtr_max);
248 printf("cap.chaining_n_mtrs_per_flow_max %" PRIu32 "\n",
249 cap.chaining_n_mtrs_per_flow_max);
250 printf("cap.chaining_use_prev_mtr_color_supported %" PRId32 "\n",
251 cap.chaining_use_prev_mtr_color_supported);
252 printf("cap.chaining_use_prev_mtr_color_enforced %" PRId32 "\n",
253 cap.chaining_use_prev_mtr_color_enforced);
254 printf("cap.meter_srtcm_rfc2697_n_max %" PRIu32 "\n",
255 cap.meter_srtcm_rfc2697_n_max);
256 printf("cap.meter_trtcm_rfc2698_n_max %" PRIu32 "\n",
257 cap.meter_trtcm_rfc2698_n_max);
258 printf("cap.meter_trtcm_rfc4115_n_max %" PRIu32 "\n",
259 cap.meter_trtcm_rfc4115_n_max);
260 printf("cap.meter_rate_max %" PRIu64 "\n", cap.meter_rate_max);
261 printf("cap.color_aware_srtcm_rfc2697_supported %" PRId32 "\n",
262 cap.color_aware_srtcm_rfc2697_supported);
263 printf("cap.color_aware_trtcm_rfc2698_supported %" PRId32 "\n",
264 cap.color_aware_trtcm_rfc2698_supported);
265 printf("cap.color_aware_trtcm_rfc4115_supported %" PRId32 "\n",
266 cap.color_aware_trtcm_rfc4115_supported);
267 printf("cap.srtcm_rfc2697_byte_mode_supported %" PRId32 "\n",
268 cap.srtcm_rfc2697_byte_mode_supported);
269 printf("cap.srtcm_rfc2697_packet_mode_supported %" PRId32 "\n",
270 cap.srtcm_rfc2697_packet_mode_supported);
271 printf("cap.trtcm_rfc2698_byte_mode_supported %" PRId32 "\n",
272 cap.trtcm_rfc2698_byte_mode_supported);
273 printf("cap.trtcm_rfc2698_packet_mode_supported %" PRId32 "\n",
274 cap.trtcm_rfc2698_packet_mode_supported);
275 printf("cap.trtcm_rfc4115_byte_mode_supported %" PRId32 "\n",
276 cap.trtcm_rfc4115_byte_mode_supported);
277 printf("cap.trtcm_rfc4115_packet_mode_supported %" PRId32 "\n",
278 cap.trtcm_rfc4115_packet_mode_supported);
279 printf("cap.stats_mask %" PRIx64 "\n", cap.stats_mask);
282 cmdline_parse_inst_t cmd_show_port_meter_cap = {
283 .f = cmd_show_port_meter_cap_parsed,
285 .help_str = "show port meter cap <port_id>",
287 (void *)&cmd_show_port_meter_cap_show,
288 (void *)&cmd_show_port_meter_cap_port,
289 (void *)&cmd_show_port_meter_cap_meter,
290 (void *)&cmd_show_port_meter_cap_cap,
291 (void *)&cmd_show_port_meter_cap_port_id,
296 /* *** Add Port Meter Profile srtcm_rfc2697 *** */
297 struct cmd_add_port_meter_profile_srtcm_result {
298 cmdline_fixed_string_t add;
299 cmdline_fixed_string_t port;
300 cmdline_fixed_string_t meter;
301 cmdline_fixed_string_t profile;
302 cmdline_fixed_string_t srtcm_rfc2697;
311 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_add =
312 TOKEN_STRING_INITIALIZER(
313 struct cmd_add_port_meter_profile_srtcm_result, add, "add");
314 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_port =
315 TOKEN_STRING_INITIALIZER(
316 struct cmd_add_port_meter_profile_srtcm_result,
318 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_meter =
319 TOKEN_STRING_INITIALIZER(
320 struct cmd_add_port_meter_profile_srtcm_result,
322 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_profile =
323 TOKEN_STRING_INITIALIZER(
324 struct cmd_add_port_meter_profile_srtcm_result,
326 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_srtcm_rfc2697 =
327 TOKEN_STRING_INITIALIZER(
328 struct cmd_add_port_meter_profile_srtcm_result,
329 srtcm_rfc2697, "srtcm_rfc2697");
330 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_port_id =
331 TOKEN_NUM_INITIALIZER(
332 struct cmd_add_port_meter_profile_srtcm_result,
333 port_id, RTE_UINT16);
334 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_profile_id =
335 TOKEN_NUM_INITIALIZER(
336 struct cmd_add_port_meter_profile_srtcm_result,
337 profile_id, RTE_UINT32);
338 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cir =
339 TOKEN_NUM_INITIALIZER(
340 struct cmd_add_port_meter_profile_srtcm_result,
342 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cbs =
343 TOKEN_NUM_INITIALIZER(
344 struct cmd_add_port_meter_profile_srtcm_result,
346 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_ebs =
347 TOKEN_NUM_INITIALIZER(
348 struct cmd_add_port_meter_profile_srtcm_result,
350 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_packet_mode =
351 TOKEN_NUM_INITIALIZER(
352 struct cmd_add_port_meter_profile_srtcm_result,
353 packet_mode, RTE_UINT32);
355 static void cmd_add_port_meter_profile_srtcm_parsed(void *parsed_result,
356 __rte_unused struct cmdline *cl,
357 __rte_unused void *data)
359 struct cmd_add_port_meter_profile_srtcm_result *res = parsed_result;
360 struct rte_mtr_meter_profile mp;
361 struct rte_mtr_error error;
362 uint32_t profile_id = res->profile_id;
363 uint16_t port_id = res->port_id;
366 if (port_id_is_invalid(port_id, ENABLED_WARN))
369 /* Private shaper profile params */
370 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
371 mp.alg = RTE_MTR_SRTCM_RFC2697;
372 mp.srtcm_rfc2697.cir = res->cir;
373 mp.srtcm_rfc2697.cbs = res->cbs;
374 mp.srtcm_rfc2697.ebs = res->ebs;
375 mp.packet_mode = res->packet_mode;
377 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
379 print_err_msg(&error);
384 cmdline_parse_inst_t cmd_add_port_meter_profile_srtcm = {
385 .f = cmd_add_port_meter_profile_srtcm_parsed,
387 .help_str = "add port meter profile srtcm_rfc2697 <port_id> <profile_id> <cir> <cbs> <ebs> <packet_mode>",
389 (void *)&cmd_add_port_meter_profile_srtcm_add,
390 (void *)&cmd_add_port_meter_profile_srtcm_port,
391 (void *)&cmd_add_port_meter_profile_srtcm_meter,
392 (void *)&cmd_add_port_meter_profile_srtcm_profile,
393 (void *)&cmd_add_port_meter_profile_srtcm_srtcm_rfc2697,
394 (void *)&cmd_add_port_meter_profile_srtcm_port_id,
395 (void *)&cmd_add_port_meter_profile_srtcm_profile_id,
396 (void *)&cmd_add_port_meter_profile_srtcm_cir,
397 (void *)&cmd_add_port_meter_profile_srtcm_cbs,
398 (void *)&cmd_add_port_meter_profile_srtcm_ebs,
399 (void *)&cmd_add_port_meter_profile_srtcm_packet_mode,
404 /* *** Add Port Meter Profile trtcm_rfc2698 *** */
405 struct cmd_add_port_meter_profile_trtcm_result {
406 cmdline_fixed_string_t add;
407 cmdline_fixed_string_t port;
408 cmdline_fixed_string_t meter;
409 cmdline_fixed_string_t profile;
410 cmdline_fixed_string_t trtcm_rfc2698;
420 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_add =
421 TOKEN_STRING_INITIALIZER(
422 struct cmd_add_port_meter_profile_trtcm_result, add, "add");
423 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_port =
424 TOKEN_STRING_INITIALIZER(
425 struct cmd_add_port_meter_profile_trtcm_result,
427 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_meter =
428 TOKEN_STRING_INITIALIZER(
429 struct cmd_add_port_meter_profile_trtcm_result,
431 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_profile =
432 TOKEN_STRING_INITIALIZER(
433 struct cmd_add_port_meter_profile_trtcm_result,
435 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_trtcm_rfc2698 =
436 TOKEN_STRING_INITIALIZER(
437 struct cmd_add_port_meter_profile_trtcm_result,
438 trtcm_rfc2698, "trtcm_rfc2698");
439 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_port_id =
440 TOKEN_NUM_INITIALIZER(
441 struct cmd_add_port_meter_profile_trtcm_result,
442 port_id, RTE_UINT16);
443 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_profile_id =
444 TOKEN_NUM_INITIALIZER(
445 struct cmd_add_port_meter_profile_trtcm_result,
446 profile_id, RTE_UINT32);
447 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cir =
448 TOKEN_NUM_INITIALIZER(
449 struct cmd_add_port_meter_profile_trtcm_result,
451 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pir =
452 TOKEN_NUM_INITIALIZER(
453 struct cmd_add_port_meter_profile_trtcm_result,
455 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cbs =
456 TOKEN_NUM_INITIALIZER(
457 struct cmd_add_port_meter_profile_trtcm_result,
459 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pbs =
460 TOKEN_NUM_INITIALIZER(
461 struct cmd_add_port_meter_profile_trtcm_result,
463 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_packet_mode =
464 TOKEN_NUM_INITIALIZER(
465 struct cmd_add_port_meter_profile_trtcm_result,
466 packet_mode, RTE_UINT32);
468 static void cmd_add_port_meter_profile_trtcm_parsed(void *parsed_result,
469 __rte_unused struct cmdline *cl,
470 __rte_unused void *data)
472 struct cmd_add_port_meter_profile_trtcm_result *res = parsed_result;
473 struct rte_mtr_meter_profile mp;
474 struct rte_mtr_error error;
475 uint32_t profile_id = res->profile_id;
476 uint16_t port_id = res->port_id;
479 if (port_id_is_invalid(port_id, ENABLED_WARN))
482 /* Private shaper profile params */
483 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
484 mp.alg = RTE_MTR_TRTCM_RFC2698;
485 mp.trtcm_rfc2698.cir = res->cir;
486 mp.trtcm_rfc2698.pir = res->pir;
487 mp.trtcm_rfc2698.cbs = res->cbs;
488 mp.trtcm_rfc2698.pbs = res->pbs;
489 mp.packet_mode = res->packet_mode;
491 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
493 print_err_msg(&error);
498 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm = {
499 .f = cmd_add_port_meter_profile_trtcm_parsed,
501 .help_str = "add port meter profile trtcm_rfc2698 <port_id> <profile_id> <cir> <pir> <cbs> <pbs> <packet_mode>",
503 (void *)&cmd_add_port_meter_profile_trtcm_add,
504 (void *)&cmd_add_port_meter_profile_trtcm_port,
505 (void *)&cmd_add_port_meter_profile_trtcm_meter,
506 (void *)&cmd_add_port_meter_profile_trtcm_profile,
507 (void *)&cmd_add_port_meter_profile_trtcm_trtcm_rfc2698,
508 (void *)&cmd_add_port_meter_profile_trtcm_port_id,
509 (void *)&cmd_add_port_meter_profile_trtcm_profile_id,
510 (void *)&cmd_add_port_meter_profile_trtcm_cir,
511 (void *)&cmd_add_port_meter_profile_trtcm_pir,
512 (void *)&cmd_add_port_meter_profile_trtcm_cbs,
513 (void *)&cmd_add_port_meter_profile_trtcm_pbs,
514 (void *)&cmd_add_port_meter_profile_trtcm_packet_mode,
519 /* *** Add Port Meter Profile trtcm_rfc4115 *** */
520 struct cmd_add_port_meter_profile_trtcm_rfc4115_result {
521 cmdline_fixed_string_t add;
522 cmdline_fixed_string_t port;
523 cmdline_fixed_string_t meter;
524 cmdline_fixed_string_t profile;
525 cmdline_fixed_string_t trtcm_rfc4115;
535 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_add =
536 TOKEN_STRING_INITIALIZER(
537 struct cmd_add_port_meter_profile_trtcm_rfc4115_result, add,
539 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_port =
540 TOKEN_STRING_INITIALIZER(
541 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
543 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_meter =
544 TOKEN_STRING_INITIALIZER(
545 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
547 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_profile =
548 TOKEN_STRING_INITIALIZER(
549 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
551 cmdline_parse_token_string_t
552 cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115 =
553 TOKEN_STRING_INITIALIZER(
554 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
555 trtcm_rfc4115, "trtcm_rfc4115");
556 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_port_id =
557 TOKEN_NUM_INITIALIZER(
558 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
559 port_id, RTE_UINT16);
560 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_profile_id =
561 TOKEN_NUM_INITIALIZER(
562 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
563 profile_id, RTE_UINT32);
564 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cir =
565 TOKEN_NUM_INITIALIZER(
566 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
568 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_eir =
569 TOKEN_NUM_INITIALIZER(
570 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
572 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cbs =
573 TOKEN_NUM_INITIALIZER(
574 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
576 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_ebs =
577 TOKEN_NUM_INITIALIZER(
578 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
580 cmdline_parse_token_num_t
581 cmd_add_port_meter_profile_trtcm_rfc4115_packet_mode =
582 TOKEN_NUM_INITIALIZER(
583 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
584 packet_mode, RTE_UINT32);
586 static void cmd_add_port_meter_profile_trtcm_rfc4115_parsed(
588 __rte_unused struct cmdline *cl,
589 __rte_unused void *data)
591 struct cmd_add_port_meter_profile_trtcm_rfc4115_result *res =
593 struct rte_mtr_meter_profile mp;
594 struct rte_mtr_error error;
595 uint32_t profile_id = res->profile_id;
596 uint16_t port_id = res->port_id;
599 if (port_id_is_invalid(port_id, ENABLED_WARN))
602 /* Private shaper profile params */
603 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
604 mp.alg = RTE_MTR_TRTCM_RFC4115;
605 mp.trtcm_rfc4115.cir = res->cir;
606 mp.trtcm_rfc4115.eir = res->eir;
607 mp.trtcm_rfc4115.cbs = res->cbs;
608 mp.trtcm_rfc4115.ebs = res->ebs;
609 mp.packet_mode = res->packet_mode;
611 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
613 print_err_msg(&error);
618 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm_rfc4115 = {
619 .f = cmd_add_port_meter_profile_trtcm_rfc4115_parsed,
621 .help_str = "add port meter profile trtcm_rfc4115 <port_id> <profile_id> <cir> <eir> <cbs> <ebs> <packet_mode>",
623 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_add,
624 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port,
625 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_meter,
626 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile,
627 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115,
628 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port_id,
629 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile_id,
630 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cir,
631 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_eir,
632 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cbs,
633 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_ebs,
634 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_packet_mode,
639 /* *** Delete Port Meter Profile *** */
640 struct cmd_del_port_meter_profile_result {
641 cmdline_fixed_string_t del;
642 cmdline_fixed_string_t port;
643 cmdline_fixed_string_t meter;
644 cmdline_fixed_string_t profile;
649 cmdline_parse_token_string_t cmd_del_port_meter_profile_del =
650 TOKEN_STRING_INITIALIZER(
651 struct cmd_del_port_meter_profile_result, del, "del");
652 cmdline_parse_token_string_t cmd_del_port_meter_profile_port =
653 TOKEN_STRING_INITIALIZER(
654 struct cmd_del_port_meter_profile_result,
656 cmdline_parse_token_string_t cmd_del_port_meter_profile_meter =
657 TOKEN_STRING_INITIALIZER(
658 struct cmd_del_port_meter_profile_result,
660 cmdline_parse_token_string_t cmd_del_port_meter_profile_profile =
661 TOKEN_STRING_INITIALIZER(
662 struct cmd_del_port_meter_profile_result,
664 cmdline_parse_token_num_t cmd_del_port_meter_profile_port_id =
665 TOKEN_NUM_INITIALIZER(
666 struct cmd_del_port_meter_profile_result,
667 port_id, RTE_UINT16);
668 cmdline_parse_token_num_t cmd_del_port_meter_profile_profile_id =
669 TOKEN_NUM_INITIALIZER(
670 struct cmd_del_port_meter_profile_result,
671 profile_id, RTE_UINT32);
673 static void cmd_del_port_meter_profile_parsed(void *parsed_result,
674 __rte_unused struct cmdline *cl,
675 __rte_unused void *data)
677 struct cmd_del_port_meter_profile_result *res = parsed_result;
678 struct rte_mtr_error error;
679 uint32_t profile_id = res->profile_id;
680 uint16_t port_id = res->port_id;
683 if (port_id_is_invalid(port_id, ENABLED_WARN))
686 /* Delete meter profile */
687 ret = rte_mtr_meter_profile_delete(port_id, profile_id, &error);
689 print_err_msg(&error);
694 cmdline_parse_inst_t cmd_del_port_meter_profile = {
695 .f = cmd_del_port_meter_profile_parsed,
697 .help_str = "del port meter profile <port_id> <profile_id>",
699 (void *)&cmd_del_port_meter_profile_del,
700 (void *)&cmd_del_port_meter_profile_port,
701 (void *)&cmd_del_port_meter_profile_meter,
702 (void *)&cmd_del_port_meter_profile_profile,
703 (void *)&cmd_del_port_meter_profile_port_id,
704 (void *)&cmd_del_port_meter_profile_profile_id,
709 /* *** Create Port Meter Object *** */
710 struct cmd_create_port_meter_result {
711 cmdline_fixed_string_t create;
712 cmdline_fixed_string_t port;
713 cmdline_fixed_string_t meter;
718 cmdline_fixed_string_t meter_enable;
719 cmdline_fixed_string_t g_action;
720 cmdline_fixed_string_t y_action;
721 cmdline_fixed_string_t r_action;
722 uint64_t statistics_mask;
724 cmdline_multi_string_t meter_input_color;
727 cmdline_parse_token_string_t cmd_create_port_meter_create =
728 TOKEN_STRING_INITIALIZER(
729 struct cmd_create_port_meter_result, create, "create");
730 cmdline_parse_token_string_t cmd_create_port_meter_port =
731 TOKEN_STRING_INITIALIZER(
732 struct cmd_create_port_meter_result, port, "port");
733 cmdline_parse_token_string_t cmd_create_port_meter_meter =
734 TOKEN_STRING_INITIALIZER(
735 struct cmd_create_port_meter_result, meter, "meter");
736 cmdline_parse_token_num_t cmd_create_port_meter_port_id =
737 TOKEN_NUM_INITIALIZER(
738 struct cmd_create_port_meter_result, port_id, RTE_UINT16);
739 cmdline_parse_token_num_t cmd_create_port_meter_mtr_id =
740 TOKEN_NUM_INITIALIZER(
741 struct cmd_create_port_meter_result, mtr_id, RTE_UINT32);
742 cmdline_parse_token_num_t cmd_create_port_meter_profile_id =
743 TOKEN_NUM_INITIALIZER(
744 struct cmd_create_port_meter_result, profile_id, RTE_UINT32);
745 cmdline_parse_token_num_t cmd_create_port_meter_policy_id =
746 TOKEN_NUM_INITIALIZER(
747 struct cmd_create_port_meter_result, policy_id, RTE_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, RTE_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 __rte_unused struct cmdline *cl,
772 __rte_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_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;
791 params.meter_policy_id = res->policy_id;
792 /* Parse meter input color string params */
793 ret = parse_meter_color_str(c_str, &use_prev_meter_color, &dscp_table);
796 " Meter input color params string parse error\n");
800 params.use_prev_mtr_color = use_prev_meter_color;
801 params.dscp_table = dscp_table;
803 if (strcmp(res->meter_enable, "yes") == 0)
804 params.meter_enable = 1;
806 params.meter_enable = 0;
807 params.stats_mask = res->statistics_mask;
809 ret = rte_mtr_create(port_id, mtr_id, ¶ms, shared, &error);
812 print_err_msg(&error);
817 cmdline_parse_inst_t cmd_create_port_meter = {
818 .f = cmd_create_port_meter_parsed,
820 .help_str = "create port meter <port_id> <mtr_id> <profile_id> <meter_enable>(yes|no) "
821 "<stats_mask> <shared> <use_pre_meter_color> "
822 "[<dscp_tbl_entry0> <dscp_tbl_entry1> ...<dscp_tbl_entry63>]",
824 (void *)&cmd_create_port_meter_create,
825 (void *)&cmd_create_port_meter_port,
826 (void *)&cmd_create_port_meter_meter,
827 (void *)&cmd_create_port_meter_port_id,
828 (void *)&cmd_create_port_meter_mtr_id,
829 (void *)&cmd_create_port_meter_profile_id,
830 (void *)&cmd_create_port_meter_policy_id,
831 (void *)&cmd_create_port_meter_meter_enable,
832 (void *)&cmd_create_port_meter_statistics_mask,
833 (void *)&cmd_create_port_meter_shared,
834 (void *)&cmd_create_port_meter_input_color,
839 /* *** Enable Meter of MTR Object *** */
840 struct cmd_enable_port_meter_result {
841 cmdline_fixed_string_t enable;
842 cmdline_fixed_string_t port;
843 cmdline_fixed_string_t meter;
848 cmdline_parse_token_string_t cmd_enable_port_meter_enable =
849 TOKEN_STRING_INITIALIZER(
850 struct cmd_enable_port_meter_result, enable, "enable");
851 cmdline_parse_token_string_t cmd_enable_port_meter_port =
852 TOKEN_STRING_INITIALIZER(
853 struct cmd_enable_port_meter_result, port, "port");
854 cmdline_parse_token_string_t cmd_enable_port_meter_meter =
855 TOKEN_STRING_INITIALIZER(
856 struct cmd_enable_port_meter_result, meter, "meter");
857 cmdline_parse_token_num_t cmd_enable_port_meter_port_id =
858 TOKEN_NUM_INITIALIZER(
859 struct cmd_enable_port_meter_result, port_id, RTE_UINT16);
860 cmdline_parse_token_num_t cmd_enable_port_meter_mtr_id =
861 TOKEN_NUM_INITIALIZER(
862 struct cmd_enable_port_meter_result, mtr_id, RTE_UINT32);
864 static void cmd_enable_port_meter_parsed(void *parsed_result,
865 __rte_unused struct cmdline *cl,
866 __rte_unused void *data)
868 struct cmd_enable_port_meter_result *res = parsed_result;
869 struct rte_mtr_error error;
870 uint32_t mtr_id = res->mtr_id;
871 uint16_t port_id = res->port_id;
875 if (port_id_is_invalid(port_id, ENABLED_WARN))
879 ret = rte_mtr_meter_enable(port_id, mtr_id, &error);
881 print_err_msg(&error);
886 cmdline_parse_inst_t cmd_enable_port_meter = {
887 .f = cmd_enable_port_meter_parsed,
889 .help_str = "enable port meter <port_id> <mtr_id>",
891 (void *)&cmd_enable_port_meter_enable,
892 (void *)&cmd_enable_port_meter_port,
893 (void *)&cmd_enable_port_meter_meter,
894 (void *)&cmd_enable_port_meter_port_id,
895 (void *)&cmd_enable_port_meter_mtr_id,
900 /* *** Disable Meter of MTR Object *** */
901 struct cmd_disable_port_meter_result {
902 cmdline_fixed_string_t disable;
903 cmdline_fixed_string_t port;
904 cmdline_fixed_string_t meter;
909 cmdline_parse_token_string_t cmd_disable_port_meter_disable =
910 TOKEN_STRING_INITIALIZER(
911 struct cmd_disable_port_meter_result, disable, "disable");
912 cmdline_parse_token_string_t cmd_disable_port_meter_port =
913 TOKEN_STRING_INITIALIZER(
914 struct cmd_disable_port_meter_result, port, "port");
915 cmdline_parse_token_string_t cmd_disable_port_meter_meter =
916 TOKEN_STRING_INITIALIZER(
917 struct cmd_disable_port_meter_result, meter, "meter");
918 cmdline_parse_token_num_t cmd_disable_port_meter_port_id =
919 TOKEN_NUM_INITIALIZER(
920 struct cmd_disable_port_meter_result, port_id, RTE_UINT16);
921 cmdline_parse_token_num_t cmd_disable_port_meter_mtr_id =
922 TOKEN_NUM_INITIALIZER(
923 struct cmd_disable_port_meter_result, mtr_id, RTE_UINT32);
925 static void cmd_disable_port_meter_parsed(void *parsed_result,
926 __rte_unused struct cmdline *cl,
927 __rte_unused void *data)
929 struct cmd_disable_port_meter_result *res = parsed_result;
930 struct rte_mtr_error error;
931 uint32_t mtr_id = res->mtr_id;
932 uint16_t port_id = res->port_id;
936 if (port_id_is_invalid(port_id, ENABLED_WARN))
940 ret = rte_mtr_meter_disable(port_id, mtr_id, &error);
942 print_err_msg(&error);
947 cmdline_parse_inst_t cmd_disable_port_meter = {
948 .f = cmd_disable_port_meter_parsed,
950 .help_str = "disable port meter <port_id> <mtr_id>",
952 (void *)&cmd_disable_port_meter_disable,
953 (void *)&cmd_disable_port_meter_port,
954 (void *)&cmd_disable_port_meter_meter,
955 (void *)&cmd_disable_port_meter_port_id,
956 (void *)&cmd_disable_port_meter_mtr_id,
961 /* *** Delete Port Meter Policy Object *** */
962 struct cmd_del_port_meter_policy_result {
963 cmdline_fixed_string_t del;
964 cmdline_fixed_string_t port;
965 cmdline_fixed_string_t meter;
966 cmdline_fixed_string_t policy;
971 cmdline_parse_token_string_t cmd_del_port_meter_policy_del =
972 TOKEN_STRING_INITIALIZER(
973 struct cmd_del_port_meter_policy_result, del, "del");
974 cmdline_parse_token_string_t cmd_del_port_meter_policy_port =
975 TOKEN_STRING_INITIALIZER(
976 struct cmd_del_port_meter_policy_result, port, "port");
977 cmdline_parse_token_string_t cmd_del_port_meter_policy_meter =
978 TOKEN_STRING_INITIALIZER(
979 struct cmd_del_port_meter_policy_result, meter, "meter");
980 cmdline_parse_token_string_t cmd_del_port_meter_policy_policy =
981 TOKEN_STRING_INITIALIZER(
982 struct cmd_del_port_meter_policy_result, policy, "policy");
983 cmdline_parse_token_num_t cmd_del_port_meter_policy_port_id =
984 TOKEN_NUM_INITIALIZER(
985 struct cmd_del_port_meter_policy_result, port_id, RTE_UINT16);
986 cmdline_parse_token_num_t cmd_del_port_meter_policy_policy_id =
987 TOKEN_NUM_INITIALIZER(
988 struct cmd_del_port_meter_policy_result, policy_id, RTE_UINT32);
990 static void cmd_del_port_meter_policy_parsed(void *parsed_result,
991 __rte_unused struct cmdline *cl,
992 __rte_unused void *data)
994 struct cmd_del_port_meter_policy_result *res = parsed_result;
995 struct rte_mtr_error error;
996 uint32_t policy_id = res->policy_id;
997 uint16_t port_id = res->port_id;
1000 if (port_id_is_invalid(port_id, ENABLED_WARN))
1003 /* Delete Meter Policy*/
1004 ret = rte_mtr_meter_policy_delete(port_id, policy_id, &error);
1006 print_err_msg(&error);
1011 cmdline_parse_inst_t cmd_del_port_meter_policy = {
1012 .f = cmd_del_port_meter_policy_parsed,
1014 .help_str = "Delete port meter policy",
1016 (void *)&cmd_del_port_meter_policy_del,
1017 (void *)&cmd_del_port_meter_policy_port,
1018 (void *)&cmd_del_port_meter_policy_meter,
1019 (void *)&cmd_del_port_meter_policy_policy,
1020 (void *)&cmd_del_port_meter_policy_port_id,
1021 (void *)&cmd_del_port_meter_policy_policy_id,
1026 /* *** Delete Port Meter Object *** */
1027 struct cmd_del_port_meter_result {
1028 cmdline_fixed_string_t del;
1029 cmdline_fixed_string_t port;
1030 cmdline_fixed_string_t meter;
1035 cmdline_parse_token_string_t cmd_del_port_meter_del =
1036 TOKEN_STRING_INITIALIZER(
1037 struct cmd_del_port_meter_result, del, "del");
1038 cmdline_parse_token_string_t cmd_del_port_meter_port =
1039 TOKEN_STRING_INITIALIZER(
1040 struct cmd_del_port_meter_result, port, "port");
1041 cmdline_parse_token_string_t cmd_del_port_meter_meter =
1042 TOKEN_STRING_INITIALIZER(
1043 struct cmd_del_port_meter_result, meter, "meter");
1044 cmdline_parse_token_num_t cmd_del_port_meter_port_id =
1045 TOKEN_NUM_INITIALIZER(
1046 struct cmd_del_port_meter_result, port_id, RTE_UINT16);
1047 cmdline_parse_token_num_t cmd_del_port_meter_mtr_id =
1048 TOKEN_NUM_INITIALIZER(
1049 struct cmd_del_port_meter_result, mtr_id, RTE_UINT32);
1051 static void cmd_del_port_meter_parsed(void *parsed_result,
1052 __rte_unused struct cmdline *cl,
1053 __rte_unused void *data)
1055 struct cmd_del_port_meter_result *res = parsed_result;
1056 struct rte_mtr_error error;
1057 uint32_t mtr_id = res->mtr_id;
1058 uint16_t port_id = res->port_id;
1062 if (port_id_is_invalid(port_id, ENABLED_WARN))
1066 ret = rte_mtr_destroy(port_id, mtr_id, &error);
1068 print_err_msg(&error);
1073 cmdline_parse_inst_t cmd_del_port_meter = {
1074 .f = cmd_del_port_meter_parsed,
1076 .help_str = "del port meter <port_id> <mtr_id>",
1078 (void *)&cmd_del_port_meter_del,
1079 (void *)&cmd_del_port_meter_port,
1080 (void *)&cmd_del_port_meter_meter,
1081 (void *)&cmd_del_port_meter_port_id,
1082 (void *)&cmd_del_port_meter_mtr_id,
1087 /* *** Set Port Meter Profile *** */
1088 struct cmd_set_port_meter_profile_result {
1089 cmdline_fixed_string_t set;
1090 cmdline_fixed_string_t port;
1091 cmdline_fixed_string_t meter;
1092 cmdline_fixed_string_t profile;
1095 uint32_t profile_id;
1098 cmdline_parse_token_string_t cmd_set_port_meter_profile_set =
1099 TOKEN_STRING_INITIALIZER(
1100 struct cmd_set_port_meter_profile_result, set, "set");
1101 cmdline_parse_token_string_t cmd_set_port_meter_profile_port =
1102 TOKEN_STRING_INITIALIZER(
1103 struct cmd_set_port_meter_profile_result, port, "port");
1104 cmdline_parse_token_string_t cmd_set_port_meter_profile_meter =
1105 TOKEN_STRING_INITIALIZER(
1106 struct cmd_set_port_meter_profile_result, meter, "meter");
1107 cmdline_parse_token_string_t cmd_set_port_meter_profile_profile =
1108 TOKEN_STRING_INITIALIZER(
1109 struct cmd_set_port_meter_profile_result, profile, "profile");
1110 cmdline_parse_token_num_t cmd_set_port_meter_profile_port_id =
1111 TOKEN_NUM_INITIALIZER(
1112 struct cmd_set_port_meter_profile_result, port_id,
1114 cmdline_parse_token_num_t cmd_set_port_meter_profile_mtr_id =
1115 TOKEN_NUM_INITIALIZER(
1116 struct cmd_set_port_meter_profile_result, mtr_id,
1118 cmdline_parse_token_num_t cmd_set_port_meter_profile_profile_id =
1119 TOKEN_NUM_INITIALIZER(
1120 struct cmd_set_port_meter_profile_result, profile_id,
1123 static void cmd_set_port_meter_profile_parsed(void *parsed_result,
1124 __rte_unused struct cmdline *cl,
1125 __rte_unused void *data)
1127 struct cmd_set_port_meter_profile_result *res = parsed_result;
1128 struct rte_mtr_error error;
1129 uint32_t mtr_id = res->mtr_id;
1130 uint32_t profile_id = res->profile_id;
1131 uint16_t port_id = res->port_id;
1135 if (port_id_is_invalid(port_id, ENABLED_WARN))
1138 /* Set meter profile */
1139 ret = rte_mtr_meter_profile_update(port_id, mtr_id,
1140 profile_id, &error);
1142 print_err_msg(&error);
1147 cmdline_parse_inst_t cmd_set_port_meter_profile = {
1148 .f = cmd_set_port_meter_profile_parsed,
1150 .help_str = "set port meter profile <port_id> <mtr_id> <profile_id>",
1152 (void *)&cmd_set_port_meter_profile_set,
1153 (void *)&cmd_set_port_meter_profile_port,
1154 (void *)&cmd_set_port_meter_profile_meter,
1155 (void *)&cmd_set_port_meter_profile_profile,
1156 (void *)&cmd_set_port_meter_profile_port_id,
1157 (void *)&cmd_set_port_meter_profile_mtr_id,
1158 (void *)&cmd_set_port_meter_profile_profile_id,
1163 /* *** Set Port Meter DSCP Table *** */
1164 struct cmd_set_port_meter_dscp_table_result {
1165 cmdline_fixed_string_t set;
1166 cmdline_fixed_string_t port;
1167 cmdline_fixed_string_t meter;
1168 cmdline_fixed_string_t dscp_table;
1169 cmdline_multi_string_t token_string;
1172 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_set =
1173 TOKEN_STRING_INITIALIZER(
1174 struct cmd_set_port_meter_dscp_table_result, set, "set");
1175 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_port =
1176 TOKEN_STRING_INITIALIZER(
1177 struct cmd_set_port_meter_dscp_table_result, port, "port");
1178 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_meter =
1179 TOKEN_STRING_INITIALIZER(
1180 struct cmd_set_port_meter_dscp_table_result, meter, "meter");
1181 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_dscp_table =
1182 TOKEN_STRING_INITIALIZER(
1183 struct cmd_set_port_meter_dscp_table_result,
1184 dscp_table, "dscp table");
1185 cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_token_string =
1186 TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_dscp_table_result,
1187 token_string, TOKEN_STRING_MULTI);
1189 static void cmd_set_port_meter_dscp_table_parsed(void *parsed_result,
1190 __rte_unused struct cmdline *cl,
1191 __rte_unused void *data)
1193 struct cmd_set_port_meter_dscp_table_result *res = parsed_result;
1194 struct rte_mtr_error error;
1195 enum rte_color *dscp_table = NULL;
1196 char *t_str = res->token_string;
1197 uint32_t mtr_id = 0;
1202 ret = parse_multi_token_string(t_str, &port_id, &mtr_id, &dscp_table);
1204 fprintf(stderr, " Multi token string parse error\n");
1208 if (port_id_is_invalid(port_id, ENABLED_WARN))
1211 /* Update Meter DSCP Table*/
1212 ret = rte_mtr_meter_dscp_table_update(port_id, mtr_id,
1213 dscp_table, &error);
1215 print_err_msg(&error);
1221 cmdline_parse_inst_t cmd_set_port_meter_dscp_table = {
1222 .f = cmd_set_port_meter_dscp_table_parsed,
1224 .help_str = "set port meter dscp table <port_id> <mtr_id> "
1225 "[<dscp_tbl_entry0> <dscp_tbl_entry1> ... <dscp_tbl_entry63>]",
1227 (void *)&cmd_set_port_meter_dscp_table_set,
1228 (void *)&cmd_set_port_meter_dscp_table_port,
1229 (void *)&cmd_set_port_meter_dscp_table_meter,
1230 (void *)&cmd_set_port_meter_dscp_table_dscp_table,
1231 (void *)&cmd_set_port_meter_dscp_table_token_string,
1236 /* *** Set Port Meter Stats Mask *** */
1237 struct cmd_set_port_meter_stats_mask_result {
1238 cmdline_fixed_string_t set;
1239 cmdline_fixed_string_t port;
1240 cmdline_fixed_string_t meter;
1241 cmdline_fixed_string_t stats;
1242 cmdline_fixed_string_t mask;
1245 uint64_t stats_mask;
1248 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_set =
1249 TOKEN_STRING_INITIALIZER(
1250 struct cmd_set_port_meter_stats_mask_result, set, "set");
1251 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_port =
1252 TOKEN_STRING_INITIALIZER(
1253 struct cmd_set_port_meter_stats_mask_result, port, "port");
1254 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_meter =
1255 TOKEN_STRING_INITIALIZER(
1256 struct cmd_set_port_meter_stats_mask_result, meter, "meter");
1257 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_stats =
1258 TOKEN_STRING_INITIALIZER(
1259 struct cmd_set_port_meter_stats_mask_result, stats, "stats");
1260 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_mask =
1261 TOKEN_STRING_INITIALIZER(
1262 struct cmd_set_port_meter_stats_mask_result, mask, "mask");
1263 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_port_id =
1264 TOKEN_NUM_INITIALIZER(
1265 struct cmd_set_port_meter_stats_mask_result, port_id,
1267 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_mtr_id =
1268 TOKEN_NUM_INITIALIZER(
1269 struct cmd_set_port_meter_stats_mask_result, mtr_id,
1271 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_stats_mask =
1272 TOKEN_NUM_INITIALIZER(
1273 struct cmd_set_port_meter_stats_mask_result, stats_mask,
1276 static void cmd_set_port_meter_stats_mask_parsed(void *parsed_result,
1277 __rte_unused struct cmdline *cl,
1278 __rte_unused void *data)
1280 struct cmd_set_port_meter_stats_mask_result *res = parsed_result;
1281 struct rte_mtr_error error;
1282 uint64_t stats_mask = res->stats_mask;
1283 uint32_t mtr_id = res->mtr_id;
1284 uint16_t port_id = res->port_id;
1287 if (port_id_is_invalid(port_id, ENABLED_WARN))
1290 ret = rte_mtr_stats_update(port_id, mtr_id, stats_mask, &error);
1292 print_err_msg(&error);
1297 cmdline_parse_inst_t cmd_set_port_meter_stats_mask = {
1298 .f = cmd_set_port_meter_stats_mask_parsed,
1300 .help_str = "set port meter stats mask <port_id> <mtr_id> <stats_mask>",
1302 (void *)&cmd_set_port_meter_stats_mask_set,
1303 (void *)&cmd_set_port_meter_stats_mask_port,
1304 (void *)&cmd_set_port_meter_stats_mask_meter,
1305 (void *)&cmd_set_port_meter_stats_mask_stats,
1306 (void *)&cmd_set_port_meter_stats_mask_mask,
1307 (void *)&cmd_set_port_meter_stats_mask_port_id,
1308 (void *)&cmd_set_port_meter_stats_mask_mtr_id,
1309 (void *)&cmd_set_port_meter_stats_mask_stats_mask,
1314 /* *** Show Port Meter Stats *** */
1315 struct cmd_show_port_meter_stats_result {
1316 cmdline_fixed_string_t show;
1317 cmdline_fixed_string_t port;
1318 cmdline_fixed_string_t meter;
1319 cmdline_fixed_string_t stats;
1322 cmdline_fixed_string_t clear;
1325 cmdline_parse_token_string_t cmd_show_port_meter_stats_show =
1326 TOKEN_STRING_INITIALIZER(
1327 struct cmd_show_port_meter_stats_result, show, "show");
1328 cmdline_parse_token_string_t cmd_show_port_meter_stats_port =
1329 TOKEN_STRING_INITIALIZER(
1330 struct cmd_show_port_meter_stats_result, port, "port");
1331 cmdline_parse_token_string_t cmd_show_port_meter_stats_meter =
1332 TOKEN_STRING_INITIALIZER(
1333 struct cmd_show_port_meter_stats_result, meter, "meter");
1334 cmdline_parse_token_string_t cmd_show_port_meter_stats_stats =
1335 TOKEN_STRING_INITIALIZER(
1336 struct cmd_show_port_meter_stats_result, stats, "stats");
1337 cmdline_parse_token_num_t cmd_show_port_meter_stats_port_id =
1338 TOKEN_NUM_INITIALIZER(
1339 struct cmd_show_port_meter_stats_result, port_id, RTE_UINT16);
1340 cmdline_parse_token_num_t cmd_show_port_meter_stats_mtr_id =
1341 TOKEN_NUM_INITIALIZER(
1342 struct cmd_show_port_meter_stats_result, mtr_id, RTE_UINT32);
1343 cmdline_parse_token_string_t cmd_show_port_meter_stats_clear =
1344 TOKEN_STRING_INITIALIZER(
1345 struct cmd_show_port_meter_stats_result, clear, "yes#no");
1347 static void cmd_show_port_meter_stats_parsed(void *parsed_result,
1348 __rte_unused struct cmdline *cl,
1349 __rte_unused void *data)
1351 struct cmd_show_port_meter_stats_result *res = parsed_result;
1352 struct rte_mtr_stats stats;
1353 uint64_t stats_mask = 0;
1354 struct rte_mtr_error error;
1355 uint32_t mtr_id = res->mtr_id;
1357 uint16_t port_id = res->port_id;
1360 if (port_id_is_invalid(port_id, ENABLED_WARN))
1363 if (strcmp(res->clear, "yes") == 0)
1366 memset(&stats, 0, sizeof(struct rte_mtr_stats));
1367 ret = rte_mtr_stats_read(port_id, mtr_id, &stats,
1368 &stats_mask, clear, &error);
1370 print_err_msg(&error);
1375 if (stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
1376 printf("\tPkts G: %" PRIu64 "\n",
1377 stats.n_pkts[RTE_COLOR_GREEN]);
1378 if (stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
1379 printf("\tBytes G: %" PRIu64 "\n",
1380 stats.n_bytes[RTE_COLOR_GREEN]);
1381 if (stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
1382 printf("\tPkts Y: %" PRIu64 "\n",
1383 stats.n_pkts[RTE_COLOR_YELLOW]);
1384 if (stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
1385 printf("\tBytes Y: %" PRIu64 "\n",
1386 stats.n_bytes[RTE_COLOR_YELLOW]);
1387 if (stats_mask & RTE_MTR_STATS_N_PKTS_RED)
1388 printf("\tPkts R: %" PRIu64 "\n",
1389 stats.n_pkts[RTE_COLOR_RED]);
1390 if (stats_mask & RTE_MTR_STATS_N_BYTES_RED)
1391 printf("\tBytes R: %" PRIu64 "\n",
1392 stats.n_bytes[RTE_COLOR_RED]);
1393 if (stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
1394 printf("\tPkts DROPPED: %" PRIu64 "\n",
1395 stats.n_pkts_dropped);
1396 if (stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
1397 printf("\tBytes DROPPED: %" PRIu64 "\n",
1398 stats.n_bytes_dropped);
1401 cmdline_parse_inst_t cmd_show_port_meter_stats = {
1402 .f = cmd_show_port_meter_stats_parsed,
1404 .help_str = "show port meter stats <port_id> <mtr_id> <clear>(yes|no)",
1406 (void *)&cmd_show_port_meter_stats_show,
1407 (void *)&cmd_show_port_meter_stats_port,
1408 (void *)&cmd_show_port_meter_stats_meter,
1409 (void *)&cmd_show_port_meter_stats_stats,
1410 (void *)&cmd_show_port_meter_stats_port_id,
1411 (void *)&cmd_show_port_meter_stats_mtr_id,
1412 (void *)&cmd_show_port_meter_stats_clear,