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 /** Display Meter Error Message */
18 print_err_msg(struct rte_mtr_error *error)
20 static const char *const errstrlist[] = {
21 [RTE_MTR_ERROR_TYPE_NONE] = "no error",
22 [RTE_MTR_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
23 [RTE_MTR_ERROR_TYPE_METER_PROFILE_ID] = "meter profile id",
24 [RTE_MTR_ERROR_TYPE_METER_PROFILE] = "meter profile null",
25 [RTE_MTR_ERROR_TYPE_MTR_ID] = "meter id",
26 [RTE_MTR_ERROR_TYPE_MTR_PARAMS] = "meter params null",
27 [RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN]
28 = "policer action(green)",
29 [RTE_MTR_ERROR_TYPE_POLICER_ACTION_YELLOW]
30 = "policer action(yellow)",
31 [RTE_MTR_ERROR_TYPE_POLICER_ACTION_RED]
32 = "policer action(red)",
33 [RTE_MTR_ERROR_TYPE_STATS_MASK] = "stats mask",
34 [RTE_MTR_ERROR_TYPE_STATS] = "stats",
35 [RTE_MTR_ERROR_TYPE_SHARED]
42 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
43 !errstrlist[error->type])
44 errstr = "unknown type";
46 errstr = errstrlist[error->type];
49 snprintf(buf, sizeof(buf), "cause: %p, ", error->cause);
51 printf("%s: %s%s (error %d)\n", errstr, error->cause ? buf : "",
52 error->message ? error->message : "(no stated reason)",
57 string_to_policer_action(char *s)
59 if (strcmp(s, "G") == 0)
60 return MTR_POLICER_ACTION_COLOR_GREEN;
62 if (strcmp(s, "Y") == 0)
63 return MTR_POLICER_ACTION_COLOR_YELLOW;
65 if (strcmp(s, "R") == 0)
66 return MTR_POLICER_ACTION_COLOR_RED;
68 if (strcmp(s, "D") == 0)
69 return MTR_POLICER_ACTION_DROP;
74 /* *** Add Port Meter Profile srtcm_rfc2697 *** */
75 struct cmd_add_port_meter_profile_srtcm_result {
76 cmdline_fixed_string_t add;
77 cmdline_fixed_string_t port;
78 cmdline_fixed_string_t meter;
79 cmdline_fixed_string_t profile;
80 cmdline_fixed_string_t srtcm_rfc2697;
89 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_add =
90 TOKEN_STRING_INITIALIZER(
91 struct cmd_add_port_meter_profile_srtcm_result, add, "add");
92 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_port =
93 TOKEN_STRING_INITIALIZER(
94 struct cmd_add_port_meter_profile_srtcm_result,
96 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_meter =
97 TOKEN_STRING_INITIALIZER(
98 struct cmd_add_port_meter_profile_srtcm_result,
100 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_profile =
101 TOKEN_STRING_INITIALIZER(
102 struct cmd_add_port_meter_profile_srtcm_result,
104 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_srtcm_rfc2697 =
105 TOKEN_STRING_INITIALIZER(
106 struct cmd_add_port_meter_profile_srtcm_result,
107 srtcm_rfc2697, "srtcm_rfc2697");
108 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_port_id =
109 TOKEN_NUM_INITIALIZER(
110 struct cmd_add_port_meter_profile_srtcm_result,
112 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_profile_id =
113 TOKEN_NUM_INITIALIZER(
114 struct cmd_add_port_meter_profile_srtcm_result,
116 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cir =
117 TOKEN_NUM_INITIALIZER(
118 struct cmd_add_port_meter_profile_srtcm_result,
120 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cbs =
121 TOKEN_NUM_INITIALIZER(
122 struct cmd_add_port_meter_profile_srtcm_result,
124 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_ebs =
125 TOKEN_NUM_INITIALIZER(
126 struct cmd_add_port_meter_profile_srtcm_result,
129 static void cmd_add_port_meter_profile_srtcm_parsed(void *parsed_result,
130 __attribute__((unused)) struct cmdline *cl,
131 __attribute__((unused)) void *data)
133 struct cmd_add_port_meter_profile_srtcm_result *res = parsed_result;
134 struct rte_mtr_meter_profile mp;
135 struct rte_mtr_error error;
136 uint32_t profile_id = res->profile_id;
137 uint16_t port_id = res->port_id;
140 if (port_id_is_invalid(port_id, ENABLED_WARN))
143 /* Private shaper profile params */
144 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
146 mp.srtcm_rfc2697.cir = res->cir;
147 mp.srtcm_rfc2697.cbs = res->cbs;
148 mp.srtcm_rfc2697.ebs = res->ebs;
150 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
152 print_err_msg(&error);
157 cmdline_parse_inst_t cmd_add_port_meter_profile_srtcm = {
158 .f = cmd_add_port_meter_profile_srtcm_parsed,
160 .help_str = "Add port meter profile srtcm (rfc2697)",
162 (void *)&cmd_add_port_meter_profile_srtcm_add,
163 (void *)&cmd_add_port_meter_profile_srtcm_port,
164 (void *)&cmd_add_port_meter_profile_srtcm_meter,
165 (void *)&cmd_add_port_meter_profile_srtcm_profile,
166 (void *)&cmd_add_port_meter_profile_srtcm_port_id,
167 (void *)&cmd_add_port_meter_profile_srtcm_profile_id,
168 (void *)&cmd_add_port_meter_profile_srtcm_srtcm_rfc2697,
169 (void *)&cmd_add_port_meter_profile_srtcm_cir,
170 (void *)&cmd_add_port_meter_profile_srtcm_cbs,
171 (void *)&cmd_add_port_meter_profile_srtcm_ebs,
176 /* *** Add Port Meter Profile trtcm_rfc2698 *** */
177 struct cmd_add_port_meter_profile_trtcm_result {
178 cmdline_fixed_string_t add;
179 cmdline_fixed_string_t port;
180 cmdline_fixed_string_t meter;
181 cmdline_fixed_string_t profile;
182 cmdline_fixed_string_t trtcm_rfc2698;
191 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_add =
192 TOKEN_STRING_INITIALIZER(
193 struct cmd_add_port_meter_profile_trtcm_result, add, "add");
194 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_port =
195 TOKEN_STRING_INITIALIZER(
196 struct cmd_add_port_meter_profile_trtcm_result,
198 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_meter =
199 TOKEN_STRING_INITIALIZER(
200 struct cmd_add_port_meter_profile_trtcm_result,
202 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_profile =
203 TOKEN_STRING_INITIALIZER(
204 struct cmd_add_port_meter_profile_trtcm_result,
206 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_trtcm_rfc2698 =
207 TOKEN_STRING_INITIALIZER(
208 struct cmd_add_port_meter_profile_trtcm_result,
209 trtcm_rfc2698, "trtcm_rfc2698");
210 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_port_id =
211 TOKEN_NUM_INITIALIZER(
212 struct cmd_add_port_meter_profile_trtcm_result,
214 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_profile_id =
215 TOKEN_NUM_INITIALIZER(
216 struct cmd_add_port_meter_profile_trtcm_result,
218 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cir =
219 TOKEN_NUM_INITIALIZER(
220 struct cmd_add_port_meter_profile_trtcm_result,
222 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pir =
223 TOKEN_NUM_INITIALIZER(
224 struct cmd_add_port_meter_profile_trtcm_result,
226 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cbs =
227 TOKEN_NUM_INITIALIZER(
228 struct cmd_add_port_meter_profile_trtcm_result,
230 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pbs =
231 TOKEN_NUM_INITIALIZER(
232 struct cmd_add_port_meter_profile_trtcm_result,
235 static void cmd_add_port_meter_profile_trtcm_parsed(void *parsed_result,
236 __attribute__((unused)) struct cmdline *cl,
237 __attribute__((unused)) void *data)
239 struct cmd_add_port_meter_profile_trtcm_result *res = parsed_result;
240 struct rte_mtr_meter_profile mp;
241 struct rte_mtr_error error;
242 uint32_t profile_id = res->profile_id;
243 uint16_t port_id = res->port_id;
246 if (port_id_is_invalid(port_id, ENABLED_WARN))
249 /* Private shaper profile params */
250 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
252 mp.trtcm_rfc2698.cir = res->cir;
253 mp.trtcm_rfc2698.pir = res->pir;
254 mp.trtcm_rfc2698.cbs = res->cbs;
255 mp.trtcm_rfc2698.pbs = res->pbs;
257 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
259 print_err_msg(&error);
264 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm = {
265 .f = cmd_add_port_meter_profile_trtcm_parsed,
267 .help_str = "Add port meter profile trtcm (rfc2698)",
269 (void *)&cmd_add_port_meter_profile_trtcm_add,
270 (void *)&cmd_add_port_meter_profile_trtcm_port,
271 (void *)&cmd_add_port_meter_profile_trtcm_meter,
272 (void *)&cmd_add_port_meter_profile_trtcm_profile,
273 (void *)&cmd_add_port_meter_profile_trtcm_port_id,
274 (void *)&cmd_add_port_meter_profile_trtcm_profile_id,
275 (void *)&cmd_add_port_meter_profile_trtcm_trtcm_rfc2698,
276 (void *)&cmd_add_port_meter_profile_trtcm_cir,
277 (void *)&cmd_add_port_meter_profile_trtcm_pir,
278 (void *)&cmd_add_port_meter_profile_trtcm_cbs,
279 (void *)&cmd_add_port_meter_profile_trtcm_pbs,
284 /* *** Add Port Meter Profile trtcm_rfc4115 *** */
285 struct cmd_add_port_meter_profile_trtcm_rfc4115_result {
286 cmdline_fixed_string_t add;
287 cmdline_fixed_string_t port;
288 cmdline_fixed_string_t meter;
289 cmdline_fixed_string_t profile;
290 cmdline_fixed_string_t trtcm_rfc4115;
299 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_add =
300 TOKEN_STRING_INITIALIZER(
301 struct cmd_add_port_meter_profile_trtcm_rfc4115_result, add,
303 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_port =
304 TOKEN_STRING_INITIALIZER(
305 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
307 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_meter =
308 TOKEN_STRING_INITIALIZER(
309 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
311 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_profile =
312 TOKEN_STRING_INITIALIZER(
313 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
315 cmdline_parse_token_string_t
316 cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115 =
317 TOKEN_STRING_INITIALIZER(
318 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
319 trtcm_rfc4115, "trtcm_rfc4115");
320 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_port_id =
321 TOKEN_NUM_INITIALIZER(
322 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
324 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_profile_id =
325 TOKEN_NUM_INITIALIZER(
326 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
328 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cir =
329 TOKEN_NUM_INITIALIZER(
330 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
332 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_eir =
333 TOKEN_NUM_INITIALIZER(
334 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
336 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cbs =
337 TOKEN_NUM_INITIALIZER(
338 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
340 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_ebs =
341 TOKEN_NUM_INITIALIZER(
342 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
345 static void cmd_add_port_meter_profile_trtcm_rfc4115_parsed(
347 __attribute__((unused)) struct cmdline *cl,
348 __attribute__((unused)) void *data)
350 struct cmd_add_port_meter_profile_trtcm_rfc4115_result *res =
352 struct rte_mtr_meter_profile mp;
353 struct rte_mtr_error error;
354 uint32_t profile_id = res->profile_id;
355 uint16_t port_id = res->port_id;
358 if (port_id_is_invalid(port_id, ENABLED_WARN))
361 /* Private shaper profile params */
362 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
364 mp.trtcm_rfc4115.cir = res->cir;
365 mp.trtcm_rfc4115.eir = res->eir;
366 mp.trtcm_rfc4115.cbs = res->cbs;
367 mp.trtcm_rfc4115.ebs = res->ebs;
369 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
371 print_err_msg(&error);
376 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm_rfc4115 = {
377 .f = cmd_add_port_meter_profile_trtcm_rfc4115_parsed,
379 .help_str = "Add port meter profile trtcm (rfc4115)",
381 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_add,
382 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port,
383 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_meter,
384 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile,
385 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port_id,
386 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile_id,
387 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115,
388 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cir,
389 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_eir,
390 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cbs,
391 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_ebs,
396 /* *** Delete Port Meter Profile *** */
397 struct cmd_del_port_meter_profile_result {
398 cmdline_fixed_string_t del;
399 cmdline_fixed_string_t port;
400 cmdline_fixed_string_t meter;
401 cmdline_fixed_string_t profile;
406 cmdline_parse_token_string_t cmd_del_port_meter_profile_del =
407 TOKEN_STRING_INITIALIZER(
408 struct cmd_del_port_meter_profile_result, del, "del");
409 cmdline_parse_token_string_t cmd_del_port_meter_profile_port =
410 TOKEN_STRING_INITIALIZER(
411 struct cmd_del_port_meter_profile_result,
413 cmdline_parse_token_string_t cmd_del_port_meter_profile_meter =
414 TOKEN_STRING_INITIALIZER(
415 struct cmd_del_port_meter_profile_result,
417 cmdline_parse_token_string_t cmd_del_port_meter_profile_profile =
418 TOKEN_STRING_INITIALIZER(
419 struct cmd_del_port_meter_profile_result,
421 cmdline_parse_token_num_t cmd_del_port_meter_profile_port_id =
422 TOKEN_NUM_INITIALIZER(
423 struct cmd_del_port_meter_profile_result,
425 cmdline_parse_token_num_t cmd_del_port_meter_profile_profile_id =
426 TOKEN_NUM_INITIALIZER(
427 struct cmd_del_port_meter_profile_result,
430 static void cmd_del_port_meter_profile_parsed(void *parsed_result,
431 __attribute__((unused)) struct cmdline *cl,
432 __attribute__((unused)) void *data)
434 struct cmd_del_port_meter_profile_result *res = parsed_result;
435 struct rte_mtr_error error;
436 uint32_t profile_id = res->profile_id;
437 uint16_t port_id = res->port_id;
440 if (port_id_is_invalid(port_id, ENABLED_WARN))
443 /* Delete meter profile */
444 ret = rte_mtr_meter_profile_delete(port_id, profile_id, &error);
446 print_err_msg(&error);
451 cmdline_parse_inst_t cmd_del_port_meter_profile = {
452 .f = cmd_del_port_meter_profile_parsed,
454 .help_str = "Delete port meter profile",
456 (void *)&cmd_del_port_meter_profile_del,
457 (void *)&cmd_del_port_meter_profile_port,
458 (void *)&cmd_del_port_meter_profile_meter,
459 (void *)&cmd_del_port_meter_profile_profile,
460 (void *)&cmd_del_port_meter_profile_port_id,
461 (void *)&cmd_del_port_meter_profile_profile_id,
466 /* *** Create Port Meter Object *** */
467 struct cmd_set_port_meter_result {
468 cmdline_fixed_string_t set;
469 cmdline_fixed_string_t port;
470 cmdline_fixed_string_t meter;
474 cmdline_fixed_string_t g_action;
475 cmdline_fixed_string_t y_action;
476 cmdline_fixed_string_t r_action;
477 uint64_t statistics_mask;
481 cmdline_parse_token_string_t cmd_set_port_meter_set =
482 TOKEN_STRING_INITIALIZER(
483 struct cmd_set_port_meter_result, set, "set");
484 cmdline_parse_token_string_t cmd_set_port_meter_port =
485 TOKEN_STRING_INITIALIZER(
486 struct cmd_set_port_meter_result, port, "port");
487 cmdline_parse_token_string_t cmd_set_port_meter_meter =
488 TOKEN_STRING_INITIALIZER(
489 struct cmd_set_port_meter_result, meter, "meter");
490 cmdline_parse_token_num_t cmd_set_port_meter_port_id =
491 TOKEN_NUM_INITIALIZER(
492 struct cmd_set_port_meter_result, port_id, UINT16);
493 cmdline_parse_token_num_t cmd_set_port_meter_mtr_id =
494 TOKEN_NUM_INITIALIZER(
495 struct cmd_set_port_meter_result, mtr_id, UINT32);
496 cmdline_parse_token_num_t cmd_set_port_meter_profile_id =
497 TOKEN_NUM_INITIALIZER(
498 struct cmd_set_port_meter_result, profile_id, UINT32);
499 cmdline_parse_token_string_t cmd_set_port_meter_g_action =
500 TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_result,
501 g_action, "R#Y#G#D");
502 cmdline_parse_token_string_t cmd_set_port_meter_y_action =
503 TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_result,
504 y_action, "R#Y#G#D");
505 cmdline_parse_token_string_t cmd_set_port_meter_r_action =
506 TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_result,
507 r_action, "R#Y#G#D");
508 cmdline_parse_token_num_t cmd_set_port_meter_statistics_mask =
509 TOKEN_NUM_INITIALIZER(struct cmd_set_port_meter_result,
510 statistics_mask, UINT64);
511 cmdline_parse_token_num_t cmd_set_port_meter_shared =
512 TOKEN_NUM_INITIALIZER(struct cmd_set_port_meter_result,
515 static void cmd_set_port_meter_parsed(void *parsed_result,
516 __attribute__((unused)) struct cmdline *cl,
517 __attribute__((unused)) void *data)
519 struct cmd_set_port_meter_result *res = parsed_result;
520 struct rte_mtr_error error;
521 struct rte_mtr_params params;
522 uint32_t mtr_id = res->mtr_id;
523 uint32_t shared = res->shared;
524 uint16_t port_id = res->port_id;
528 if (port_id_is_invalid(port_id, ENABLED_WARN))
532 memset(¶ms, 0, sizeof(struct rte_mtr_params));
533 params.meter_profile_id = res->profile_id;
534 params.use_prev_mtr_color = 1;
535 params.dscp_table = NULL;
536 params.meter_enable = 1;
537 params.action[RTE_MTR_GREEN] =
538 string_to_policer_action(res->g_action);
539 params.action[RTE_MTR_YELLOW] =
540 string_to_policer_action(res->y_action);
541 params.action[RTE_MTR_RED] =
542 string_to_policer_action(res->r_action);
543 params.stats_mask = res->statistics_mask;
545 ret = rte_mtr_create(port_id, mtr_id, ¶ms, shared, &error);
547 print_err_msg(&error);
552 cmdline_parse_inst_t cmd_set_port_meter = {
553 .f = cmd_set_port_meter_parsed,
555 .help_str = "Set port meter",
557 (void *)&cmd_set_port_meter_set,
558 (void *)&cmd_set_port_meter_port,
559 (void *)&cmd_set_port_meter_meter,
560 (void *)&cmd_set_port_meter_port_id,
561 (void *)&cmd_set_port_meter_mtr_id,
562 (void *)&cmd_set_port_meter_profile_id,
563 (void *)&cmd_set_port_meter_g_action,
564 (void *)&cmd_set_port_meter_y_action,
565 (void *)&cmd_set_port_meter_r_action,
566 (void *)&cmd_set_port_meter_statistics_mask,
567 (void *)&cmd_set_port_meter_shared,
572 /* *** Delete Port Meter Object *** */
573 struct cmd_del_port_meter_result {
574 cmdline_fixed_string_t del;
575 cmdline_fixed_string_t port;
576 cmdline_fixed_string_t meter;
581 cmdline_parse_token_string_t cmd_del_port_meter_del =
582 TOKEN_STRING_INITIALIZER(
583 struct cmd_del_port_meter_result, del, "del");
584 cmdline_parse_token_string_t cmd_del_port_meter_port =
585 TOKEN_STRING_INITIALIZER(
586 struct cmd_del_port_meter_result, port, "port");
587 cmdline_parse_token_string_t cmd_del_port_meter_meter =
588 TOKEN_STRING_INITIALIZER(
589 struct cmd_del_port_meter_result, meter, "meter");
590 cmdline_parse_token_num_t cmd_del_port_meter_port_id =
591 TOKEN_NUM_INITIALIZER(
592 struct cmd_del_port_meter_result, port_id, UINT16);
593 cmdline_parse_token_num_t cmd_del_port_meter_mtr_id =
594 TOKEN_NUM_INITIALIZER(
595 struct cmd_del_port_meter_result, mtr_id, UINT32);
597 static void cmd_del_port_meter_parsed(void *parsed_result,
598 __attribute__((unused)) struct cmdline *cl,
599 __attribute__((unused)) void *data)
601 struct cmd_del_port_meter_result *res = parsed_result;
602 struct rte_mtr_error error;
603 uint32_t mtr_id = res->mtr_id;
604 uint16_t port_id = res->port_id;
608 if (port_id_is_invalid(port_id, ENABLED_WARN))
612 ret = rte_mtr_destroy(port_id, mtr_id, &error);
614 print_err_msg(&error);
619 cmdline_parse_inst_t cmd_del_port_meter = {
620 .f = cmd_del_port_meter_parsed,
622 .help_str = "Delete port meter",
624 (void *)&cmd_del_port_meter_del,
625 (void *)&cmd_del_port_meter_port,
626 (void *)&cmd_del_port_meter_meter,
627 (void *)&cmd_del_port_meter_port_id,
628 (void *)&cmd_del_port_meter_mtr_id,
633 /* *** Set Port Meter Profile *** */
634 struct cmd_set_port_meter_profile_result {
635 cmdline_fixed_string_t set;
636 cmdline_fixed_string_t port;
637 cmdline_fixed_string_t meter;
638 cmdline_fixed_string_t profile;
644 cmdline_parse_token_string_t cmd_set_port_meter_profile_set =
645 TOKEN_STRING_INITIALIZER(
646 struct cmd_set_port_meter_profile_result, set, "set");
647 cmdline_parse_token_string_t cmd_set_port_meter_profile_port =
648 TOKEN_STRING_INITIALIZER(
649 struct cmd_set_port_meter_profile_result, port, "port");
650 cmdline_parse_token_string_t cmd_set_port_meter_profile_meter =
651 TOKEN_STRING_INITIALIZER(
652 struct cmd_set_port_meter_profile_result, meter, "meter");
653 cmdline_parse_token_string_t cmd_set_port_meter_profile_profile =
654 TOKEN_STRING_INITIALIZER(
655 struct cmd_set_port_meter_profile_result, profile, "profile");
656 cmdline_parse_token_num_t cmd_set_port_meter_profile_port_id =
657 TOKEN_NUM_INITIALIZER(
658 struct cmd_set_port_meter_profile_result, port_id, UINT16);
659 cmdline_parse_token_num_t cmd_set_port_meter_profile_mtr_id =
660 TOKEN_NUM_INITIALIZER(
661 struct cmd_set_port_meter_profile_result, mtr_id, UINT32);
662 cmdline_parse_token_num_t cmd_set_port_meter_profile_profile_id =
663 TOKEN_NUM_INITIALIZER(
664 struct cmd_set_port_meter_profile_result, profile_id, UINT32);
666 static void cmd_set_port_meter_profile_parsed(void *parsed_result,
667 __attribute__((unused)) struct cmdline *cl,
668 __attribute__((unused)) void *data)
670 struct cmd_set_port_meter_profile_result *res = parsed_result;
671 struct rte_mtr_error error;
672 uint32_t mtr_id = res->mtr_id;
673 uint32_t profile_id = res->profile_id;
674 uint16_t port_id = res->port_id;
678 if (port_id_is_invalid(port_id, ENABLED_WARN))
681 /* Set meter profile */
682 ret = rte_mtr_meter_profile_update(port_id, mtr_id,
685 print_err_msg(&error);
690 cmdline_parse_inst_t cmd_set_port_meter_profile = {
691 .f = cmd_set_port_meter_profile_parsed,
693 .help_str = "Set port meter profile",
695 (void *)&cmd_set_port_meter_profile_set,
696 (void *)&cmd_set_port_meter_profile_port,
697 (void *)&cmd_set_port_meter_profile_meter,
698 (void *)&cmd_set_port_meter_profile_profile,
699 (void *)&cmd_set_port_meter_profile_port_id,
700 (void *)&cmd_set_port_meter_profile_mtr_id,
701 (void *)&cmd_set_port_meter_profile_profile_id,
706 /* *** Set Port Meter Policer Action *** */
707 struct cmd_set_port_meter_policer_action_result {
708 cmdline_fixed_string_t set;
709 cmdline_fixed_string_t port;
710 cmdline_fixed_string_t meter;
711 cmdline_fixed_string_t policer;
712 cmdline_fixed_string_t action;
715 cmdline_fixed_string_t color;
716 cmdline_fixed_string_t policer_action;
719 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_set =
720 TOKEN_STRING_INITIALIZER(
721 struct cmd_set_port_meter_policer_action_result, set, "set");
722 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_port =
723 TOKEN_STRING_INITIALIZER(
724 struct cmd_set_port_meter_policer_action_result, port, "port");
725 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_meter =
726 TOKEN_STRING_INITIALIZER(
727 struct cmd_set_port_meter_policer_action_result, meter,
729 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_policer =
730 TOKEN_STRING_INITIALIZER(
731 struct cmd_set_port_meter_policer_action_result, policer,
733 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_action =
734 TOKEN_STRING_INITIALIZER(
735 struct cmd_set_port_meter_policer_action_result, action,
737 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_port_id =
738 TOKEN_NUM_INITIALIZER(
739 struct cmd_set_port_meter_policer_action_result, port_id,
741 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_mtr_id =
742 TOKEN_NUM_INITIALIZER(
743 struct cmd_set_port_meter_policer_action_result, mtr_id,
745 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_color =
746 TOKEN_STRING_INITIALIZER(
747 struct cmd_set_port_meter_policer_action_result, color,
749 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_policer_action =
750 TOKEN_STRING_INITIALIZER(
751 struct cmd_set_port_meter_policer_action_result,
752 policer_action, "G#Y#R#D");
754 static void cmd_set_port_meter_policer_action_parsed(void *parsed_result,
755 __attribute__((unused)) struct cmdline *cl,
756 __attribute__((unused)) void *data)
758 struct cmd_set_port_meter_policer_action_result *res = parsed_result;
759 enum rte_mtr_color color;
760 enum rte_mtr_policer_action action[RTE_MTR_COLORS];
761 struct rte_mtr_error error;
762 uint32_t mtr_id = res->mtr_id;
763 uint16_t port_id = res->port_id;
764 char *c = res->color;
765 char *a = res->policer_action;
768 if (port_id_is_invalid(port_id, ENABLED_WARN))
772 if (strcmp(c, "G") == 0)
773 color = RTE_MTR_GREEN;
774 else if (strcmp(c, "Y") == 0)
775 color = RTE_MTR_YELLOW;
780 if (strcmp(a, "G") == 0)
781 action[color] = MTR_POLICER_ACTION_COLOR_GREEN;
782 else if (strcmp(a, "Y") == 0)
783 action[color] = MTR_POLICER_ACTION_COLOR_YELLOW;
784 else if (strcmp(a, "R") == 0)
785 action[color] = MTR_POLICER_ACTION_COLOR_RED;
787 action[color] = MTR_POLICER_ACTION_DROP;
789 ret = rte_mtr_policer_actions_update(port_id, mtr_id,
790 1 << color, action, &error);
792 print_err_msg(&error);
797 cmdline_parse_inst_t cmd_set_port_meter_policer_action = {
798 .f = cmd_set_port_meter_policer_action_parsed,
800 .help_str = "Set port meter policer action",
802 (void *)&cmd_set_port_meter_policer_action_set,
803 (void *)&cmd_set_port_meter_policer_action_port,
804 (void *)&cmd_set_port_meter_policer_action_meter,
805 (void *)&cmd_set_port_meter_policer_action_policer,
806 (void *)&cmd_set_port_meter_policer_action_action,
807 (void *)&cmd_set_port_meter_policer_action_port_id,
808 (void *)&cmd_set_port_meter_policer_action_mtr_id,
809 (void *)&cmd_set_port_meter_policer_action_color,
810 (void *)&cmd_set_port_meter_policer_action_policer_action,
815 /* *** Set Port Meter Stats Mask *** */
816 struct cmd_set_port_meter_stats_mask_result {
817 cmdline_fixed_string_t set;
818 cmdline_fixed_string_t port;
819 cmdline_fixed_string_t meter;
820 cmdline_fixed_string_t stats;
821 cmdline_fixed_string_t mask;
827 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_set =
828 TOKEN_STRING_INITIALIZER(
829 struct cmd_set_port_meter_stats_mask_result, set, "set");
830 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_port =
831 TOKEN_STRING_INITIALIZER(
832 struct cmd_set_port_meter_stats_mask_result, port, "port");
833 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_meter =
834 TOKEN_STRING_INITIALIZER(
835 struct cmd_set_port_meter_stats_mask_result, meter, "meter");
836 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_stats =
837 TOKEN_STRING_INITIALIZER(
838 struct cmd_set_port_meter_stats_mask_result, stats, "stats");
839 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_mask =
840 TOKEN_STRING_INITIALIZER(
841 struct cmd_set_port_meter_stats_mask_result, mask, "mask");
842 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_port_id =
843 TOKEN_NUM_INITIALIZER(
844 struct cmd_set_port_meter_stats_mask_result, port_id, UINT16);
845 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_mtr_id =
846 TOKEN_NUM_INITIALIZER(
847 struct cmd_set_port_meter_stats_mask_result, mtr_id, UINT32);
848 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_stats_mask =
849 TOKEN_NUM_INITIALIZER(
850 struct cmd_set_port_meter_stats_mask_result, stats_mask,
853 static void cmd_set_port_meter_stats_mask_parsed(void *parsed_result,
854 __attribute__((unused)) struct cmdline *cl,
855 __attribute__((unused)) void *data)
857 struct cmd_set_port_meter_stats_mask_result *res = parsed_result;
858 struct rte_mtr_error error;
859 uint64_t stats_mask = res->stats_mask;
860 uint32_t mtr_id = res->mtr_id;
861 uint16_t port_id = res->port_id;
864 if (port_id_is_invalid(port_id, ENABLED_WARN))
867 ret = rte_mtr_stats_update(port_id, mtr_id, stats_mask, &error);
869 print_err_msg(&error);
874 cmdline_parse_inst_t cmd_set_port_meter_stats_mask = {
875 .f = cmd_set_port_meter_stats_mask_parsed,
877 .help_str = "Set port meter stats mask",
879 (void *)&cmd_set_port_meter_stats_mask_set,
880 (void *)&cmd_set_port_meter_stats_mask_port,
881 (void *)&cmd_set_port_meter_stats_mask_meter,
882 (void *)&cmd_set_port_meter_stats_mask_stats,
883 (void *)&cmd_set_port_meter_stats_mask_mask,
884 (void *)&cmd_set_port_meter_stats_mask_port_id,
885 (void *)&cmd_set_port_meter_stats_mask_mtr_id,
886 (void *)&cmd_set_port_meter_stats_mask_stats_mask,
891 /* *** Show Port Meter Stats *** */
892 struct cmd_show_port_meter_stats_result {
893 cmdline_fixed_string_t show;
894 cmdline_fixed_string_t port;
895 cmdline_fixed_string_t meter;
896 cmdline_fixed_string_t stats;
902 cmdline_parse_token_string_t cmd_show_port_meter_stats_show =
903 TOKEN_STRING_INITIALIZER(
904 struct cmd_show_port_meter_stats_result, show, "show");
905 cmdline_parse_token_string_t cmd_show_port_meter_stats_port =
906 TOKEN_STRING_INITIALIZER(
907 struct cmd_show_port_meter_stats_result, port, "port");
908 cmdline_parse_token_string_t cmd_show_port_meter_stats_meter =
909 TOKEN_STRING_INITIALIZER(
910 struct cmd_show_port_meter_stats_result, meter, "meter");
911 cmdline_parse_token_string_t cmd_show_port_meter_stats_stats =
912 TOKEN_STRING_INITIALIZER(
913 struct cmd_show_port_meter_stats_result, stats, "stats");
914 cmdline_parse_token_num_t cmd_show_port_meter_stats_port_id =
915 TOKEN_NUM_INITIALIZER(
916 struct cmd_show_port_meter_stats_result, port_id, UINT16);
917 cmdline_parse_token_num_t cmd_show_port_meter_stats_mtr_id =
918 TOKEN_NUM_INITIALIZER(
919 struct cmd_show_port_meter_stats_result, mtr_id, UINT32);
920 cmdline_parse_token_num_t cmd_show_port_meter_stats_clear =
921 TOKEN_NUM_INITIALIZER(
922 struct cmd_show_port_meter_stats_result, clear, UINT32);
924 static void cmd_show_port_meter_stats_parsed(void *parsed_result,
925 __attribute__((unused)) struct cmdline *cl,
926 __attribute__((unused)) void *data)
928 struct cmd_show_port_meter_stats_result *res = parsed_result;
929 struct rte_mtr_stats stats;
930 uint64_t stats_mask = 0;
931 struct rte_mtr_error error;
932 uint32_t mtr_id = res->mtr_id;
933 uint32_t clear = res->clear;
934 uint16_t port_id = res->port_id;
937 if (port_id_is_invalid(port_id, ENABLED_WARN))
940 memset(&stats, 0, sizeof(struct rte_mtr_stats));
941 ret = rte_mtr_stats_read(port_id, mtr_id, &stats,
942 &stats_mask, clear, &error);
944 print_err_msg(&error);
949 if (stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
950 printf("\tPkts G: %" PRIu64 "\n",
951 stats.n_pkts[RTE_MTR_GREEN]);
952 if (stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
953 printf("\tBytes G: %" PRIu64 "\n",
954 stats.n_bytes[RTE_MTR_GREEN]);
955 if (stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
956 printf("\tPkts Y: %" PRIu64 "\n",
957 stats.n_pkts[RTE_MTR_YELLOW]);
958 if (stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
959 printf("\tBytes Y: %" PRIu64 "\n",
960 stats.n_bytes[RTE_MTR_YELLOW]);
961 if (stats_mask & RTE_MTR_STATS_N_PKTS_RED)
962 printf("\tPkts R: %" PRIu64 "\n",
963 stats.n_pkts[RTE_MTR_RED]);
964 if (stats_mask & RTE_MTR_STATS_N_BYTES_RED)
965 printf("\tBytes Y: %" PRIu64 "\n",
966 stats.n_bytes[RTE_MTR_RED]);
967 if (stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
968 printf("\tPkts DROPPED: %" PRIu64 "\n",
969 stats.n_pkts_dropped);
970 if (stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
971 printf("\tBytes DROPPED: %" PRIu64 "\n",
972 stats.n_bytes_dropped);
975 cmdline_parse_inst_t cmd_show_port_meter_stats = {
976 .f = cmd_show_port_meter_stats_parsed,
978 .help_str = "Show port meter stats",
980 (void *)&cmd_show_port_meter_stats_show,
981 (void *)&cmd_show_port_meter_stats_port,
982 (void *)&cmd_show_port_meter_stats_meter,
983 (void *)&cmd_show_port_meter_stats_stats,
984 (void *)&cmd_show_port_meter_stats_port_id,
985 (void *)&cmd_show_port_meter_stats_mtr_id,
986 (void *)&cmd_show_port_meter_stats_clear,