4 * Copyright(c) 2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <cmdline_parse.h>
35 #include <cmdline_parse_num.h>
36 #include <cmdline_parse_string.h>
38 #include <rte_ethdev.h>
43 #include "cmdline_mtr.h"
45 /** Display Meter Error Message */
47 print_err_msg(struct rte_mtr_error *error)
49 static const char *const errstrlist[] = {
50 [RTE_MTR_ERROR_TYPE_NONE] = "no error",
51 [RTE_MTR_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
52 [RTE_MTR_ERROR_TYPE_METER_PROFILE_ID] = "meter profile id",
53 [RTE_MTR_ERROR_TYPE_METER_PROFILE] = "meter profile null",
54 [RTE_MTR_ERROR_TYPE_MTR_ID] = "meter id",
55 [RTE_MTR_ERROR_TYPE_MTR_PARAMS] = "meter params null",
56 [RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN]
57 = "policer action(green)",
58 [RTE_MTR_ERROR_TYPE_POLICER_ACTION_YELLOW]
59 = "policer action(yellow)",
60 [RTE_MTR_ERROR_TYPE_POLICER_ACTION_RED]
61 = "policer action(red)",
62 [RTE_MTR_ERROR_TYPE_STATS_MASK] = "stats mask",
63 [RTE_MTR_ERROR_TYPE_STATS] = "stats",
64 [RTE_MTR_ERROR_TYPE_SHARED]
71 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
72 !errstrlist[error->type])
73 errstr = "unknown type";
75 errstr = errstrlist[error->type];
78 snprintf(buf, sizeof(buf), "cause: %p, ", error->cause);
80 printf("%s: %s%s (error %d)\n", errstr, error->cause ? buf : "",
81 error->message ? error->message : "(no stated reason)",
86 string_to_policer_action(char *s)
88 if (strcmp(s, "G") == 0)
89 return MTR_POLICER_ACTION_COLOR_GREEN;
91 if (strcmp(s, "Y") == 0)
92 return MTR_POLICER_ACTION_COLOR_YELLOW;
94 if (strcmp(s, "R") == 0)
95 return MTR_POLICER_ACTION_COLOR_RED;
97 if (strcmp(s, "D") == 0)
98 return MTR_POLICER_ACTION_DROP;
103 /* *** Add Port Meter Profile srtcm_rfc2697 *** */
104 struct cmd_add_port_meter_profile_srtcm_result {
105 cmdline_fixed_string_t add;
106 cmdline_fixed_string_t port;
107 cmdline_fixed_string_t meter;
108 cmdline_fixed_string_t profile;
109 cmdline_fixed_string_t srtcm_rfc2697;
118 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_add =
119 TOKEN_STRING_INITIALIZER(
120 struct cmd_add_port_meter_profile_srtcm_result, add, "add");
121 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_port =
122 TOKEN_STRING_INITIALIZER(
123 struct cmd_add_port_meter_profile_srtcm_result,
125 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_meter =
126 TOKEN_STRING_INITIALIZER(
127 struct cmd_add_port_meter_profile_srtcm_result,
129 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_profile =
130 TOKEN_STRING_INITIALIZER(
131 struct cmd_add_port_meter_profile_srtcm_result,
133 cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_srtcm_rfc2697 =
134 TOKEN_STRING_INITIALIZER(
135 struct cmd_add_port_meter_profile_srtcm_result,
136 srtcm_rfc2697, "srtcm_rfc2697");
137 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_port_id =
138 TOKEN_NUM_INITIALIZER(
139 struct cmd_add_port_meter_profile_srtcm_result,
141 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_profile_id =
142 TOKEN_NUM_INITIALIZER(
143 struct cmd_add_port_meter_profile_srtcm_result,
145 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cir =
146 TOKEN_NUM_INITIALIZER(
147 struct cmd_add_port_meter_profile_srtcm_result,
149 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cbs =
150 TOKEN_NUM_INITIALIZER(
151 struct cmd_add_port_meter_profile_srtcm_result,
153 cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_ebs =
154 TOKEN_NUM_INITIALIZER(
155 struct cmd_add_port_meter_profile_srtcm_result,
158 static void cmd_add_port_meter_profile_srtcm_parsed(void *parsed_result,
159 __attribute__((unused)) struct cmdline *cl,
160 __attribute__((unused)) void *data)
162 struct cmd_add_port_meter_profile_srtcm_result *res = parsed_result;
163 struct rte_mtr_meter_profile mp;
164 struct rte_mtr_error error;
165 uint32_t profile_id = res->profile_id;
166 uint16_t port_id = res->port_id;
169 if (port_id_is_invalid(port_id, ENABLED_WARN))
172 /* Private shaper profile params */
173 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
175 mp.srtcm_rfc2697.cir = res->cir;
176 mp.srtcm_rfc2697.cbs = res->cbs;
177 mp.srtcm_rfc2697.ebs = res->ebs;
179 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
181 print_err_msg(&error);
186 cmdline_parse_inst_t cmd_add_port_meter_profile_srtcm = {
187 .f = cmd_add_port_meter_profile_srtcm_parsed,
189 .help_str = "Add port meter profile srtcm (rfc2697)",
191 (void *)&cmd_add_port_meter_profile_srtcm_add,
192 (void *)&cmd_add_port_meter_profile_srtcm_port,
193 (void *)&cmd_add_port_meter_profile_srtcm_meter,
194 (void *)&cmd_add_port_meter_profile_srtcm_profile,
195 (void *)&cmd_add_port_meter_profile_srtcm_port_id,
196 (void *)&cmd_add_port_meter_profile_srtcm_profile_id,
197 (void *)&cmd_add_port_meter_profile_srtcm_srtcm_rfc2697,
198 (void *)&cmd_add_port_meter_profile_srtcm_cir,
199 (void *)&cmd_add_port_meter_profile_srtcm_cbs,
200 (void *)&cmd_add_port_meter_profile_srtcm_ebs,
205 /* *** Add Port Meter Profile trtcm_rfc2698 *** */
206 struct cmd_add_port_meter_profile_trtcm_result {
207 cmdline_fixed_string_t add;
208 cmdline_fixed_string_t port;
209 cmdline_fixed_string_t meter;
210 cmdline_fixed_string_t profile;
211 cmdline_fixed_string_t trtcm_rfc2698;
220 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_add =
221 TOKEN_STRING_INITIALIZER(
222 struct cmd_add_port_meter_profile_trtcm_result, add, "add");
223 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_port =
224 TOKEN_STRING_INITIALIZER(
225 struct cmd_add_port_meter_profile_trtcm_result,
227 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_meter =
228 TOKEN_STRING_INITIALIZER(
229 struct cmd_add_port_meter_profile_trtcm_result,
231 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_profile =
232 TOKEN_STRING_INITIALIZER(
233 struct cmd_add_port_meter_profile_trtcm_result,
235 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_trtcm_rfc2698 =
236 TOKEN_STRING_INITIALIZER(
237 struct cmd_add_port_meter_profile_trtcm_result,
238 trtcm_rfc2698, "trtcm_rfc2698");
239 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_port_id =
240 TOKEN_NUM_INITIALIZER(
241 struct cmd_add_port_meter_profile_trtcm_result,
243 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_profile_id =
244 TOKEN_NUM_INITIALIZER(
245 struct cmd_add_port_meter_profile_trtcm_result,
247 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cir =
248 TOKEN_NUM_INITIALIZER(
249 struct cmd_add_port_meter_profile_trtcm_result,
251 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pir =
252 TOKEN_NUM_INITIALIZER(
253 struct cmd_add_port_meter_profile_trtcm_result,
255 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cbs =
256 TOKEN_NUM_INITIALIZER(
257 struct cmd_add_port_meter_profile_trtcm_result,
259 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pbs =
260 TOKEN_NUM_INITIALIZER(
261 struct cmd_add_port_meter_profile_trtcm_result,
264 static void cmd_add_port_meter_profile_trtcm_parsed(void *parsed_result,
265 __attribute__((unused)) struct cmdline *cl,
266 __attribute__((unused)) void *data)
268 struct cmd_add_port_meter_profile_trtcm_result *res = parsed_result;
269 struct rte_mtr_meter_profile mp;
270 struct rte_mtr_error error;
271 uint32_t profile_id = res->profile_id;
272 uint16_t port_id = res->port_id;
275 if (port_id_is_invalid(port_id, ENABLED_WARN))
278 /* Private shaper profile params */
279 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
281 mp.trtcm_rfc2698.cir = res->cir;
282 mp.trtcm_rfc2698.pir = res->pir;
283 mp.trtcm_rfc2698.cbs = res->cbs;
284 mp.trtcm_rfc2698.pbs = res->pbs;
286 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
288 print_err_msg(&error);
293 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm = {
294 .f = cmd_add_port_meter_profile_trtcm_parsed,
296 .help_str = "Add port meter profile trtcm (rfc2698)",
298 (void *)&cmd_add_port_meter_profile_trtcm_add,
299 (void *)&cmd_add_port_meter_profile_trtcm_port,
300 (void *)&cmd_add_port_meter_profile_trtcm_meter,
301 (void *)&cmd_add_port_meter_profile_trtcm_profile,
302 (void *)&cmd_add_port_meter_profile_trtcm_port_id,
303 (void *)&cmd_add_port_meter_profile_trtcm_profile_id,
304 (void *)&cmd_add_port_meter_profile_trtcm_trtcm_rfc2698,
305 (void *)&cmd_add_port_meter_profile_trtcm_cir,
306 (void *)&cmd_add_port_meter_profile_trtcm_pir,
307 (void *)&cmd_add_port_meter_profile_trtcm_cbs,
308 (void *)&cmd_add_port_meter_profile_trtcm_pbs,
313 /* *** Add Port Meter Profile trtcm_rfc4115 *** */
314 struct cmd_add_port_meter_profile_trtcm_rfc4115_result {
315 cmdline_fixed_string_t add;
316 cmdline_fixed_string_t port;
317 cmdline_fixed_string_t meter;
318 cmdline_fixed_string_t profile;
319 cmdline_fixed_string_t trtcm_rfc4115;
328 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_add =
329 TOKEN_STRING_INITIALIZER(
330 struct cmd_add_port_meter_profile_trtcm_rfc4115_result, add,
332 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_port =
333 TOKEN_STRING_INITIALIZER(
334 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
336 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_meter =
337 TOKEN_STRING_INITIALIZER(
338 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
340 cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_profile =
341 TOKEN_STRING_INITIALIZER(
342 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
344 cmdline_parse_token_string_t
345 cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115 =
346 TOKEN_STRING_INITIALIZER(
347 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
348 trtcm_rfc4115, "trtcm_rfc4115");
349 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_port_id =
350 TOKEN_NUM_INITIALIZER(
351 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
353 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_profile_id =
354 TOKEN_NUM_INITIALIZER(
355 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
357 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cir =
358 TOKEN_NUM_INITIALIZER(
359 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
361 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_eir =
362 TOKEN_NUM_INITIALIZER(
363 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
365 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cbs =
366 TOKEN_NUM_INITIALIZER(
367 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
369 cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_ebs =
370 TOKEN_NUM_INITIALIZER(
371 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
374 static void cmd_add_port_meter_profile_trtcm_rfc4115_parsed(
376 __attribute__((unused)) struct cmdline *cl,
377 __attribute__((unused)) void *data)
379 struct cmd_add_port_meter_profile_trtcm_rfc4115_result *res =
381 struct rte_mtr_meter_profile mp;
382 struct rte_mtr_error error;
383 uint32_t profile_id = res->profile_id;
384 uint16_t port_id = res->port_id;
387 if (port_id_is_invalid(port_id, ENABLED_WARN))
390 /* Private shaper profile params */
391 memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
393 mp.trtcm_rfc4115.cir = res->cir;
394 mp.trtcm_rfc4115.eir = res->eir;
395 mp.trtcm_rfc4115.cbs = res->cbs;
396 mp.trtcm_rfc4115.ebs = res->ebs;
398 ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
400 print_err_msg(&error);
405 cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm_rfc4115 = {
406 .f = cmd_add_port_meter_profile_trtcm_rfc4115_parsed,
408 .help_str = "Add port meter profile trtcm (rfc4115)",
410 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_add,
411 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port,
412 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_meter,
413 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile,
414 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port_id,
415 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile_id,
416 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115,
417 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cir,
418 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_eir,
419 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cbs,
420 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_ebs,
425 /* *** Delete Port Meter Profile *** */
426 struct cmd_del_port_meter_profile_result {
427 cmdline_fixed_string_t del;
428 cmdline_fixed_string_t port;
429 cmdline_fixed_string_t meter;
430 cmdline_fixed_string_t profile;
435 cmdline_parse_token_string_t cmd_del_port_meter_profile_del =
436 TOKEN_STRING_INITIALIZER(
437 struct cmd_del_port_meter_profile_result, del, "del");
438 cmdline_parse_token_string_t cmd_del_port_meter_profile_port =
439 TOKEN_STRING_INITIALIZER(
440 struct cmd_del_port_meter_profile_result,
442 cmdline_parse_token_string_t cmd_del_port_meter_profile_meter =
443 TOKEN_STRING_INITIALIZER(
444 struct cmd_del_port_meter_profile_result,
446 cmdline_parse_token_string_t cmd_del_port_meter_profile_profile =
447 TOKEN_STRING_INITIALIZER(
448 struct cmd_del_port_meter_profile_result,
450 cmdline_parse_token_num_t cmd_del_port_meter_profile_port_id =
451 TOKEN_NUM_INITIALIZER(
452 struct cmd_del_port_meter_profile_result,
454 cmdline_parse_token_num_t cmd_del_port_meter_profile_profile_id =
455 TOKEN_NUM_INITIALIZER(
456 struct cmd_del_port_meter_profile_result,
459 static void cmd_del_port_meter_profile_parsed(void *parsed_result,
460 __attribute__((unused)) struct cmdline *cl,
461 __attribute__((unused)) void *data)
463 struct cmd_del_port_meter_profile_result *res = parsed_result;
464 struct rte_mtr_error error;
465 uint32_t profile_id = res->profile_id;
466 uint16_t port_id = res->port_id;
469 if (port_id_is_invalid(port_id, ENABLED_WARN))
472 /* Delete meter profile */
473 ret = rte_mtr_meter_profile_delete(port_id, profile_id, &error);
475 print_err_msg(&error);
480 cmdline_parse_inst_t cmd_del_port_meter_profile = {
481 .f = cmd_del_port_meter_profile_parsed,
483 .help_str = "Delete port meter profile",
485 (void *)&cmd_del_port_meter_profile_del,
486 (void *)&cmd_del_port_meter_profile_port,
487 (void *)&cmd_del_port_meter_profile_meter,
488 (void *)&cmd_del_port_meter_profile_profile,
489 (void *)&cmd_del_port_meter_profile_port_id,
490 (void *)&cmd_del_port_meter_profile_profile_id,
495 /* *** Create Port Meter Object *** */
496 struct cmd_set_port_meter_result {
497 cmdline_fixed_string_t set;
498 cmdline_fixed_string_t port;
499 cmdline_fixed_string_t meter;
503 cmdline_fixed_string_t g_action;
504 cmdline_fixed_string_t y_action;
505 cmdline_fixed_string_t r_action;
506 uint64_t statistics_mask;
510 cmdline_parse_token_string_t cmd_set_port_meter_set =
511 TOKEN_STRING_INITIALIZER(
512 struct cmd_set_port_meter_result, set, "set");
513 cmdline_parse_token_string_t cmd_set_port_meter_port =
514 TOKEN_STRING_INITIALIZER(
515 struct cmd_set_port_meter_result, port, "port");
516 cmdline_parse_token_string_t cmd_set_port_meter_meter =
517 TOKEN_STRING_INITIALIZER(
518 struct cmd_set_port_meter_result, meter, "meter");
519 cmdline_parse_token_num_t cmd_set_port_meter_port_id =
520 TOKEN_NUM_INITIALIZER(
521 struct cmd_set_port_meter_result, port_id, UINT16);
522 cmdline_parse_token_num_t cmd_set_port_meter_mtr_id =
523 TOKEN_NUM_INITIALIZER(
524 struct cmd_set_port_meter_result, mtr_id, UINT32);
525 cmdline_parse_token_num_t cmd_set_port_meter_profile_id =
526 TOKEN_NUM_INITIALIZER(
527 struct cmd_set_port_meter_result, profile_id, UINT32);
528 cmdline_parse_token_string_t cmd_set_port_meter_g_action =
529 TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_result,
530 g_action, "R#Y#G#D");
531 cmdline_parse_token_string_t cmd_set_port_meter_y_action =
532 TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_result,
533 y_action, "R#Y#G#D");
534 cmdline_parse_token_string_t cmd_set_port_meter_r_action =
535 TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_result,
536 r_action, "R#Y#G#D");
537 cmdline_parse_token_num_t cmd_set_port_meter_statistics_mask =
538 TOKEN_NUM_INITIALIZER(struct cmd_set_port_meter_result,
539 statistics_mask, UINT64);
540 cmdline_parse_token_num_t cmd_set_port_meter_shared =
541 TOKEN_NUM_INITIALIZER(struct cmd_set_port_meter_result,
544 static void cmd_set_port_meter_parsed(void *parsed_result,
545 __attribute__((unused)) struct cmdline *cl,
546 __attribute__((unused)) void *data)
548 struct cmd_set_port_meter_result *res = parsed_result;
549 struct rte_mtr_error error;
550 struct rte_mtr_params params;
551 uint32_t mtr_id = res->mtr_id;
552 uint32_t shared = res->shared;
553 uint16_t port_id = res->port_id;
557 if (port_id_is_invalid(port_id, ENABLED_WARN))
561 memset(¶ms, 0, sizeof(struct rte_mtr_params));
562 params.meter_profile_id = res->profile_id;
563 params.use_prev_mtr_color = 1;
564 params.dscp_table = NULL;
565 params.meter_enable = 1;
566 params.action[RTE_MTR_GREEN] =
567 string_to_policer_action(res->g_action);
568 params.action[RTE_MTR_YELLOW] =
569 string_to_policer_action(res->y_action);
570 params.action[RTE_MTR_RED] =
571 string_to_policer_action(res->r_action);
572 params.stats_mask = res->statistics_mask;
574 ret = rte_mtr_create(port_id, mtr_id, ¶ms, shared, &error);
576 print_err_msg(&error);
581 cmdline_parse_inst_t cmd_set_port_meter = {
582 .f = cmd_set_port_meter_parsed,
584 .help_str = "Set port meter",
586 (void *)&cmd_set_port_meter_set,
587 (void *)&cmd_set_port_meter_port,
588 (void *)&cmd_set_port_meter_meter,
589 (void *)&cmd_set_port_meter_port_id,
590 (void *)&cmd_set_port_meter_mtr_id,
591 (void *)&cmd_set_port_meter_profile_id,
592 (void *)&cmd_set_port_meter_g_action,
593 (void *)&cmd_set_port_meter_y_action,
594 (void *)&cmd_set_port_meter_r_action,
595 (void *)&cmd_set_port_meter_statistics_mask,
596 (void *)&cmd_set_port_meter_shared,
601 /* *** Delete Port Meter Object *** */
602 struct cmd_del_port_meter_result {
603 cmdline_fixed_string_t del;
604 cmdline_fixed_string_t port;
605 cmdline_fixed_string_t meter;
610 cmdline_parse_token_string_t cmd_del_port_meter_del =
611 TOKEN_STRING_INITIALIZER(
612 struct cmd_del_port_meter_result, del, "del");
613 cmdline_parse_token_string_t cmd_del_port_meter_port =
614 TOKEN_STRING_INITIALIZER(
615 struct cmd_del_port_meter_result, port, "port");
616 cmdline_parse_token_string_t cmd_del_port_meter_meter =
617 TOKEN_STRING_INITIALIZER(
618 struct cmd_del_port_meter_result, meter, "meter");
619 cmdline_parse_token_num_t cmd_del_port_meter_port_id =
620 TOKEN_NUM_INITIALIZER(
621 struct cmd_del_port_meter_result, port_id, UINT16);
622 cmdline_parse_token_num_t cmd_del_port_meter_mtr_id =
623 TOKEN_NUM_INITIALIZER(
624 struct cmd_del_port_meter_result, mtr_id, UINT32);
626 static void cmd_del_port_meter_parsed(void *parsed_result,
627 __attribute__((unused)) struct cmdline *cl,
628 __attribute__((unused)) void *data)
630 struct cmd_del_port_meter_result *res = parsed_result;
631 struct rte_mtr_error error;
632 uint32_t mtr_id = res->mtr_id;
633 uint16_t port_id = res->port_id;
637 if (port_id_is_invalid(port_id, ENABLED_WARN))
641 ret = rte_mtr_destroy(port_id, mtr_id, &error);
643 print_err_msg(&error);
648 cmdline_parse_inst_t cmd_del_port_meter = {
649 .f = cmd_del_port_meter_parsed,
651 .help_str = "Delete port meter",
653 (void *)&cmd_del_port_meter_del,
654 (void *)&cmd_del_port_meter_port,
655 (void *)&cmd_del_port_meter_meter,
656 (void *)&cmd_del_port_meter_port_id,
657 (void *)&cmd_del_port_meter_mtr_id,
662 /* *** Set Port Meter Profile *** */
663 struct cmd_set_port_meter_profile_result {
664 cmdline_fixed_string_t set;
665 cmdline_fixed_string_t port;
666 cmdline_fixed_string_t meter;
667 cmdline_fixed_string_t profile;
673 cmdline_parse_token_string_t cmd_set_port_meter_profile_set =
674 TOKEN_STRING_INITIALIZER(
675 struct cmd_set_port_meter_profile_result, set, "set");
676 cmdline_parse_token_string_t cmd_set_port_meter_profile_port =
677 TOKEN_STRING_INITIALIZER(
678 struct cmd_set_port_meter_profile_result, port, "port");
679 cmdline_parse_token_string_t cmd_set_port_meter_profile_meter =
680 TOKEN_STRING_INITIALIZER(
681 struct cmd_set_port_meter_profile_result, meter, "meter");
682 cmdline_parse_token_string_t cmd_set_port_meter_profile_profile =
683 TOKEN_STRING_INITIALIZER(
684 struct cmd_set_port_meter_profile_result, profile, "profile");
685 cmdline_parse_token_num_t cmd_set_port_meter_profile_port_id =
686 TOKEN_NUM_INITIALIZER(
687 struct cmd_set_port_meter_profile_result, port_id, UINT16);
688 cmdline_parse_token_num_t cmd_set_port_meter_profile_mtr_id =
689 TOKEN_NUM_INITIALIZER(
690 struct cmd_set_port_meter_profile_result, mtr_id, UINT32);
691 cmdline_parse_token_num_t cmd_set_port_meter_profile_profile_id =
692 TOKEN_NUM_INITIALIZER(
693 struct cmd_set_port_meter_profile_result, profile_id, UINT32);
695 static void cmd_set_port_meter_profile_parsed(void *parsed_result,
696 __attribute__((unused)) struct cmdline *cl,
697 __attribute__((unused)) void *data)
699 struct cmd_set_port_meter_profile_result *res = parsed_result;
700 struct rte_mtr_error error;
701 uint32_t mtr_id = res->mtr_id;
702 uint32_t profile_id = res->profile_id;
703 uint16_t port_id = res->port_id;
707 if (port_id_is_invalid(port_id, ENABLED_WARN))
710 /* Set meter profile */
711 ret = rte_mtr_meter_profile_update(port_id, mtr_id,
714 print_err_msg(&error);
719 cmdline_parse_inst_t cmd_set_port_meter_profile = {
720 .f = cmd_set_port_meter_profile_parsed,
722 .help_str = "Set port meter profile",
724 (void *)&cmd_set_port_meter_profile_set,
725 (void *)&cmd_set_port_meter_profile_port,
726 (void *)&cmd_set_port_meter_profile_meter,
727 (void *)&cmd_set_port_meter_profile_profile,
728 (void *)&cmd_set_port_meter_profile_port_id,
729 (void *)&cmd_set_port_meter_profile_mtr_id,
730 (void *)&cmd_set_port_meter_profile_profile_id,
735 /* *** Set Port Meter Policer Action *** */
736 struct cmd_set_port_meter_policer_action_result {
737 cmdline_fixed_string_t set;
738 cmdline_fixed_string_t port;
739 cmdline_fixed_string_t meter;
740 cmdline_fixed_string_t policer;
741 cmdline_fixed_string_t action;
744 cmdline_fixed_string_t color;
745 cmdline_fixed_string_t policer_action;
748 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_set =
749 TOKEN_STRING_INITIALIZER(
750 struct cmd_set_port_meter_policer_action_result, set, "set");
751 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_port =
752 TOKEN_STRING_INITIALIZER(
753 struct cmd_set_port_meter_policer_action_result, port, "port");
754 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_meter =
755 TOKEN_STRING_INITIALIZER(
756 struct cmd_set_port_meter_policer_action_result, meter,
758 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_policer =
759 TOKEN_STRING_INITIALIZER(
760 struct cmd_set_port_meter_policer_action_result, policer,
762 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_action =
763 TOKEN_STRING_INITIALIZER(
764 struct cmd_set_port_meter_policer_action_result, action,
766 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_port_id =
767 TOKEN_NUM_INITIALIZER(
768 struct cmd_set_port_meter_policer_action_result, port_id,
770 cmdline_parse_token_num_t cmd_set_port_meter_policer_action_mtr_id =
771 TOKEN_NUM_INITIALIZER(
772 struct cmd_set_port_meter_policer_action_result, mtr_id,
774 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_color =
775 TOKEN_STRING_INITIALIZER(
776 struct cmd_set_port_meter_policer_action_result, color,
778 cmdline_parse_token_string_t cmd_set_port_meter_policer_action_policer_action =
779 TOKEN_STRING_INITIALIZER(
780 struct cmd_set_port_meter_policer_action_result,
781 policer_action, "G#Y#R#D");
783 static void cmd_set_port_meter_policer_action_parsed(void *parsed_result,
784 __attribute__((unused)) struct cmdline *cl,
785 __attribute__((unused)) void *data)
787 struct cmd_set_port_meter_policer_action_result *res = parsed_result;
788 enum rte_mtr_color color;
789 enum rte_mtr_policer_action action[RTE_MTR_COLORS];
790 struct rte_mtr_error error;
791 uint32_t mtr_id = res->mtr_id;
792 uint16_t port_id = res->port_id;
793 char *c = res->color;
794 char *a = res->policer_action;
797 if (port_id_is_invalid(port_id, ENABLED_WARN))
801 if (strcmp(c, "G") == 0)
802 color = RTE_MTR_GREEN;
803 else if (strcmp(c, "Y") == 0)
804 color = RTE_MTR_YELLOW;
805 else if (strcmp(c, "Y") == 0)
808 color = RTE_MTR_COLORS;
811 if (strcmp(a, "G") == 0)
812 action[color] = MTR_POLICER_ACTION_COLOR_GREEN;
813 else if (strcmp(a, "Y") == 0)
814 action[color] = MTR_POLICER_ACTION_COLOR_YELLOW;
815 else if (strcmp(a, "Y") == 0)
816 action[color] = MTR_POLICER_ACTION_COLOR_RED;
818 action[color] = MTR_POLICER_ACTION_DROP;
820 ret = rte_mtr_policer_actions_update(port_id, mtr_id,
821 1 << color, action, &error);
823 print_err_msg(&error);
828 cmdline_parse_inst_t cmd_set_port_meter_policer_action = {
829 .f = cmd_set_port_meter_policer_action_parsed,
831 .help_str = "Set port meter policer action",
833 (void *)&cmd_set_port_meter_policer_action_set,
834 (void *)&cmd_set_port_meter_policer_action_port,
835 (void *)&cmd_set_port_meter_policer_action_meter,
836 (void *)&cmd_set_port_meter_policer_action_policer,
837 (void *)&cmd_set_port_meter_policer_action_action,
838 (void *)&cmd_set_port_meter_policer_action_port_id,
839 (void *)&cmd_set_port_meter_policer_action_mtr_id,
840 (void *)&cmd_set_port_meter_policer_action_color,
841 (void *)&cmd_set_port_meter_policer_action_policer_action,
846 /* *** Set Port Meter Stats Mask *** */
847 struct cmd_set_port_meter_stats_mask_result {
848 cmdline_fixed_string_t set;
849 cmdline_fixed_string_t port;
850 cmdline_fixed_string_t meter;
851 cmdline_fixed_string_t stats;
852 cmdline_fixed_string_t mask;
858 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_set =
859 TOKEN_STRING_INITIALIZER(
860 struct cmd_set_port_meter_stats_mask_result, set, "set");
861 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_port =
862 TOKEN_STRING_INITIALIZER(
863 struct cmd_set_port_meter_stats_mask_result, port, "port");
864 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_meter =
865 TOKEN_STRING_INITIALIZER(
866 struct cmd_set_port_meter_stats_mask_result, meter, "meter");
867 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_stats =
868 TOKEN_STRING_INITIALIZER(
869 struct cmd_set_port_meter_stats_mask_result, stats, "stats");
870 cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_mask =
871 TOKEN_STRING_INITIALIZER(
872 struct cmd_set_port_meter_stats_mask_result, mask, "mask");
873 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_port_id =
874 TOKEN_NUM_INITIALIZER(
875 struct cmd_set_port_meter_stats_mask_result, port_id, UINT16);
876 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_mtr_id =
877 TOKEN_NUM_INITIALIZER(
878 struct cmd_set_port_meter_stats_mask_result, mtr_id, UINT32);
879 cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_stats_mask =
880 TOKEN_NUM_INITIALIZER(
881 struct cmd_set_port_meter_stats_mask_result, stats_mask,
884 static void cmd_set_port_meter_stats_mask_parsed(void *parsed_result,
885 __attribute__((unused)) struct cmdline *cl,
886 __attribute__((unused)) void *data)
888 struct cmd_set_port_meter_stats_mask_result *res = parsed_result;
889 struct rte_mtr_error error;
890 uint64_t stats_mask = res->stats_mask;
891 uint32_t mtr_id = res->mtr_id;
892 uint16_t port_id = res->port_id;
895 if (port_id_is_invalid(port_id, ENABLED_WARN))
898 ret = rte_mtr_stats_update(port_id, mtr_id, stats_mask, &error);
900 print_err_msg(&error);
905 cmdline_parse_inst_t cmd_set_port_meter_stats_mask = {
906 .f = cmd_set_port_meter_stats_mask_parsed,
908 .help_str = "Set port meter stats mask",
910 (void *)&cmd_set_port_meter_stats_mask_set,
911 (void *)&cmd_set_port_meter_stats_mask_port,
912 (void *)&cmd_set_port_meter_stats_mask_meter,
913 (void *)&cmd_set_port_meter_stats_mask_stats,
914 (void *)&cmd_set_port_meter_stats_mask_mask,
915 (void *)&cmd_set_port_meter_stats_mask_port_id,
916 (void *)&cmd_set_port_meter_stats_mask_mtr_id,
917 (void *)&cmd_set_port_meter_stats_mask_stats_mask,
922 /* *** Show Port Meter Stats *** */
923 struct cmd_show_port_meter_stats_result {
924 cmdline_fixed_string_t show;
925 cmdline_fixed_string_t port;
926 cmdline_fixed_string_t meter;
927 cmdline_fixed_string_t stats;
933 cmdline_parse_token_string_t cmd_show_port_meter_stats_show =
934 TOKEN_STRING_INITIALIZER(
935 struct cmd_show_port_meter_stats_result, show, "show");
936 cmdline_parse_token_string_t cmd_show_port_meter_stats_port =
937 TOKEN_STRING_INITIALIZER(
938 struct cmd_show_port_meter_stats_result, port, "port");
939 cmdline_parse_token_string_t cmd_show_port_meter_stats_meter =
940 TOKEN_STRING_INITIALIZER(
941 struct cmd_show_port_meter_stats_result, meter, "meter");
942 cmdline_parse_token_string_t cmd_show_port_meter_stats_stats =
943 TOKEN_STRING_INITIALIZER(
944 struct cmd_show_port_meter_stats_result, stats, "stats");
945 cmdline_parse_token_num_t cmd_show_port_meter_stats_port_id =
946 TOKEN_NUM_INITIALIZER(
947 struct cmd_show_port_meter_stats_result, port_id, UINT16);
948 cmdline_parse_token_num_t cmd_show_port_meter_stats_mtr_id =
949 TOKEN_NUM_INITIALIZER(
950 struct cmd_show_port_meter_stats_result, mtr_id, UINT32);
951 cmdline_parse_token_num_t cmd_show_port_meter_stats_clear =
952 TOKEN_NUM_INITIALIZER(
953 struct cmd_show_port_meter_stats_result, clear, UINT32);
955 static void cmd_show_port_meter_stats_parsed(void *parsed_result,
956 __attribute__((unused)) struct cmdline *cl,
957 __attribute__((unused)) void *data)
959 struct cmd_show_port_meter_stats_result *res = parsed_result;
960 struct rte_mtr_stats stats;
961 uint64_t stats_mask = 0;
962 struct rte_mtr_error error;
963 uint32_t mtr_id = res->mtr_id;
964 uint32_t clear = res->clear;
965 uint16_t port_id = res->port_id;
968 if (port_id_is_invalid(port_id, ENABLED_WARN))
971 memset(&stats, 0, sizeof(struct rte_mtr_stats));
972 ret = rte_mtr_stats_read(port_id, mtr_id, &stats,
973 &stats_mask, clear, &error);
975 print_err_msg(&error);
980 if (stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
981 printf("\tPkts G: %" PRIu64 "\n",
982 stats.n_pkts[RTE_MTR_GREEN]);
983 if (stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
984 printf("\tBytes G: %" PRIu64 "\n",
985 stats.n_bytes[RTE_MTR_GREEN]);
986 if (stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
987 printf("\tPkts Y: %" PRIu64 "\n",
988 stats.n_pkts[RTE_MTR_YELLOW]);
989 if (stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
990 printf("\tBytes Y: %" PRIu64 "\n",
991 stats.n_bytes[RTE_MTR_YELLOW]);
992 if (stats_mask & RTE_MTR_STATS_N_PKTS_RED)
993 printf("\tPkts R: %" PRIu64 "\n",
994 stats.n_pkts[RTE_MTR_RED]);
995 if (stats_mask & RTE_MTR_STATS_N_BYTES_RED)
996 printf("\tBytes Y: %" PRIu64 "\n",
997 stats.n_bytes[RTE_MTR_RED]);
998 if (stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
999 printf("\tPkts DROPPED: %" PRIu64 "\n",
1000 stats.n_pkts_dropped);
1001 if (stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
1002 printf("\tBytes DROPPED: %" PRIu64 "\n",
1003 stats.n_bytes_dropped);
1006 cmdline_parse_inst_t cmd_show_port_meter_stats = {
1007 .f = cmd_show_port_meter_stats_parsed,
1009 .help_str = "Show port meter stats",
1011 (void *)&cmd_show_port_meter_stats_show,
1012 (void *)&cmd_show_port_meter_stats_port,
1013 (void *)&cmd_show_port_meter_stats_meter,
1014 (void *)&cmd_show_port_meter_stats_stats,
1015 (void *)&cmd_show_port_meter_stats_port_id,
1016 (void *)&cmd_show_port_meter_stats_mtr_id,
1017 (void *)&cmd_show_port_meter_stats_clear,