1174a1631SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2174a1631SBruce Richardson * Copyright(c) 2017 Intel Corporation
330ffb4e6SCristian Dumitrescu */
430ffb4e6SCristian Dumitrescu
51bcb7ba9SDavid Marchand #include <stdlib.h>
61bcb7ba9SDavid Marchand
730ffb4e6SCristian Dumitrescu #include <cmdline_parse.h>
830ffb4e6SCristian Dumitrescu #include <cmdline_parse_num.h>
930ffb4e6SCristian Dumitrescu #include <cmdline_parse_string.h>
1030ffb4e6SCristian Dumitrescu
1130ffb4e6SCristian Dumitrescu #include <rte_ethdev.h>
1230ffb4e6SCristian Dumitrescu #include <rte_flow.h>
1330ffb4e6SCristian Dumitrescu #include <rte_mtr.h>
1430ffb4e6SCristian Dumitrescu
1530ffb4e6SCristian Dumitrescu #include "testpmd.h"
1630ffb4e6SCristian Dumitrescu #include "cmdline_mtr.h"
1730ffb4e6SCristian Dumitrescu
18e63b5016SJasvinder Singh #define PARSE_DELIMITER " \f\n\r\t\v"
199f5488e3SSunil Kumar Kori #define MAX_VLAN_TABLE_ENTRIES 16
20e63b5016SJasvinder Singh #define MAX_DSCP_TABLE_ENTRIES 64
21e63b5016SJasvinder Singh
2230ffb4e6SCristian Dumitrescu /** Display Meter Error Message */
2330ffb4e6SCristian Dumitrescu static void
print_err_msg(struct rte_mtr_error * error)2430ffb4e6SCristian Dumitrescu print_err_msg(struct rte_mtr_error *error)
2530ffb4e6SCristian Dumitrescu {
2630ffb4e6SCristian Dumitrescu static const char *const errstrlist[] = {
2730ffb4e6SCristian Dumitrescu [RTE_MTR_ERROR_TYPE_NONE] = "no error",
2830ffb4e6SCristian Dumitrescu [RTE_MTR_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
2930ffb4e6SCristian Dumitrescu [RTE_MTR_ERROR_TYPE_METER_PROFILE_ID] = "meter profile id",
3030ffb4e6SCristian Dumitrescu [RTE_MTR_ERROR_TYPE_METER_PROFILE] = "meter profile null",
3130ffb4e6SCristian Dumitrescu [RTE_MTR_ERROR_TYPE_MTR_ID] = "meter id",
3230ffb4e6SCristian Dumitrescu [RTE_MTR_ERROR_TYPE_MTR_PARAMS] = "meter params null",
3330ffb4e6SCristian Dumitrescu [RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN]
3430ffb4e6SCristian Dumitrescu = "policer action(green)",
3530ffb4e6SCristian Dumitrescu [RTE_MTR_ERROR_TYPE_POLICER_ACTION_YELLOW]
3630ffb4e6SCristian Dumitrescu = "policer action(yellow)",
3730ffb4e6SCristian Dumitrescu [RTE_MTR_ERROR_TYPE_POLICER_ACTION_RED]
3830ffb4e6SCristian Dumitrescu = "policer action(red)",
3930ffb4e6SCristian Dumitrescu [RTE_MTR_ERROR_TYPE_STATS_MASK] = "stats mask",
4030ffb4e6SCristian Dumitrescu [RTE_MTR_ERROR_TYPE_STATS] = "stats",
4130ffb4e6SCristian Dumitrescu [RTE_MTR_ERROR_TYPE_SHARED]
4230ffb4e6SCristian Dumitrescu = "shared meter",
43f29fa2c5SHaifei Luo [RTE_MTR_ERROR_TYPE_METER_POLICY_ID] = "meter policy id",
44f29fa2c5SHaifei Luo [RTE_MTR_ERROR_TYPE_METER_POLICY] = "meter policy null",
4530ffb4e6SCristian Dumitrescu };
4630ffb4e6SCristian Dumitrescu
4730ffb4e6SCristian Dumitrescu const char *errstr;
4830ffb4e6SCristian Dumitrescu char buf[64];
4930ffb4e6SCristian Dumitrescu
5030ffb4e6SCristian Dumitrescu if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
5130ffb4e6SCristian Dumitrescu !errstrlist[error->type])
5230ffb4e6SCristian Dumitrescu errstr = "unknown type";
5330ffb4e6SCristian Dumitrescu else
5430ffb4e6SCristian Dumitrescu errstr = errstrlist[error->type];
5530ffb4e6SCristian Dumitrescu
5630ffb4e6SCristian Dumitrescu if (error->cause)
5730ffb4e6SCristian Dumitrescu snprintf(buf, sizeof(buf), "cause: %p, ", error->cause);
5830ffb4e6SCristian Dumitrescu
5961a3b0e5SAndrew Rybchenko fprintf(stderr, "%s: %s%s (error %d)\n",
6061a3b0e5SAndrew Rybchenko errstr, error->cause ? buf : "",
6130ffb4e6SCristian Dumitrescu error->message ? error->message : "(no stated reason)",
6230ffb4e6SCristian Dumitrescu error->type);
6330ffb4e6SCristian Dumitrescu }
6430ffb4e6SCristian Dumitrescu
65f29fa2c5SHaifei Luo void
print_mtr_err_msg(struct rte_mtr_error * error)66f29fa2c5SHaifei Luo print_mtr_err_msg(struct rte_mtr_error *error)
67f29fa2c5SHaifei Luo {
68f29fa2c5SHaifei Luo print_err_msg(error);
69f29fa2c5SHaifei Luo }
70f29fa2c5SHaifei Luo
7130ffb4e6SCristian Dumitrescu static int
parse_uint(uint64_t * value,const char * str)72e63b5016SJasvinder Singh parse_uint(uint64_t *value, const char *str)
73e63b5016SJasvinder Singh {
74e63b5016SJasvinder Singh char *next = NULL;
75e63b5016SJasvinder Singh uint64_t n;
76e63b5016SJasvinder Singh
77e63b5016SJasvinder Singh errno = 0;
78e63b5016SJasvinder Singh /* Parse number string */
79e63b5016SJasvinder Singh n = strtol(str, &next, 10);
80e63b5016SJasvinder Singh if (errno != 0 || str == next || *next != '\0')
81e63b5016SJasvinder Singh return -1;
82e63b5016SJasvinder Singh
83e63b5016SJasvinder Singh *value = n;
84e63b5016SJasvinder Singh
85e63b5016SJasvinder Singh return 0;
86e63b5016SJasvinder Singh }
87e63b5016SJasvinder Singh
88e63b5016SJasvinder Singh static int
parse_input_color_table_entries(char * str,enum rte_color ** dscp_table,enum rte_color ** vlan_table)899f5488e3SSunil Kumar Kori parse_input_color_table_entries(char *str, enum rte_color **dscp_table,
909f5488e3SSunil Kumar Kori enum rte_color **vlan_table)
919f5488e3SSunil Kumar Kori {
929f5488e3SSunil Kumar Kori enum rte_color *vlan, *dscp;
939f5488e3SSunil Kumar Kori char *token;
949f5488e3SSunil Kumar Kori int i = 0;
959f5488e3SSunil Kumar Kori
969f5488e3SSunil Kumar Kori token = strtok_r(str, PARSE_DELIMITER, &str);
979f5488e3SSunil Kumar Kori if (token == NULL)
989f5488e3SSunil Kumar Kori return 0;
999f5488e3SSunil Kumar Kori
1009f5488e3SSunil Kumar Kori /* Allocate memory for dscp table */
1019f5488e3SSunil Kumar Kori dscp = (enum rte_color *)malloc(MAX_DSCP_TABLE_ENTRIES *
1029f5488e3SSunil Kumar Kori sizeof(enum rte_color));
1039f5488e3SSunil Kumar Kori if (dscp == NULL)
1049f5488e3SSunil Kumar Kori return -1;
1059f5488e3SSunil Kumar Kori
1069f5488e3SSunil Kumar Kori while (1) {
1079f5488e3SSunil Kumar Kori if (strcasecmp(token, "G") == 0)
1089f5488e3SSunil Kumar Kori dscp[i++] = RTE_COLOR_GREEN;
1099f5488e3SSunil Kumar Kori else if (strcasecmp(token, "Y") == 0)
1109f5488e3SSunil Kumar Kori dscp[i++] = RTE_COLOR_YELLOW;
1119f5488e3SSunil Kumar Kori else if (strcasecmp(token, "R") == 0)
1129f5488e3SSunil Kumar Kori dscp[i++] = RTE_COLOR_RED;
1139f5488e3SSunil Kumar Kori else {
1149f5488e3SSunil Kumar Kori free(dscp);
1159f5488e3SSunil Kumar Kori return -1;
1169f5488e3SSunil Kumar Kori }
1179f5488e3SSunil Kumar Kori if (i == MAX_DSCP_TABLE_ENTRIES)
1189f5488e3SSunil Kumar Kori break;
1199f5488e3SSunil Kumar Kori
1209f5488e3SSunil Kumar Kori token = strtok_r(str, PARSE_DELIMITER, &str);
1219f5488e3SSunil Kumar Kori if (token == NULL) {
1229f5488e3SSunil Kumar Kori free(dscp);
1239f5488e3SSunil Kumar Kori return -1;
1249f5488e3SSunil Kumar Kori }
1259f5488e3SSunil Kumar Kori }
1269f5488e3SSunil Kumar Kori
1279f5488e3SSunil Kumar Kori *dscp_table = dscp;
1289f5488e3SSunil Kumar Kori
1299f5488e3SSunil Kumar Kori token = strtok_r(str, PARSE_DELIMITER, &str);
1309f5488e3SSunil Kumar Kori if (token == NULL)
1319f5488e3SSunil Kumar Kori return 0;
1329f5488e3SSunil Kumar Kori
1339f5488e3SSunil Kumar Kori /* Allocate memory for vlan table */
1349f5488e3SSunil Kumar Kori vlan = (enum rte_color *)malloc(MAX_VLAN_TABLE_ENTRIES *
1359f5488e3SSunil Kumar Kori sizeof(enum rte_color));
136e1673ddeSJasvinder Singh if (vlan == NULL) {
137e1673ddeSJasvinder Singh free(*dscp_table);
1389f5488e3SSunil Kumar Kori return -1;
139e1673ddeSJasvinder Singh }
1409f5488e3SSunil Kumar Kori
1419f5488e3SSunil Kumar Kori i = 0;
1429f5488e3SSunil Kumar Kori while (1) {
1439f5488e3SSunil Kumar Kori if (strcasecmp(token, "G") == 0)
1449f5488e3SSunil Kumar Kori vlan[i++] = RTE_COLOR_GREEN;
1459f5488e3SSunil Kumar Kori else if (strcasecmp(token, "Y") == 0)
1469f5488e3SSunil Kumar Kori vlan[i++] = RTE_COLOR_YELLOW;
1479f5488e3SSunil Kumar Kori else if (strcasecmp(token, "R") == 0)
1489f5488e3SSunil Kumar Kori vlan[i++] = RTE_COLOR_RED;
1499f5488e3SSunil Kumar Kori else {
1509f5488e3SSunil Kumar Kori free(vlan);
151e1673ddeSJasvinder Singh free(*dscp_table);
1529f5488e3SSunil Kumar Kori return -1;
1539f5488e3SSunil Kumar Kori }
1549f5488e3SSunil Kumar Kori if (i == MAX_VLAN_TABLE_ENTRIES)
1559f5488e3SSunil Kumar Kori break;
1569f5488e3SSunil Kumar Kori
1579f5488e3SSunil Kumar Kori token = strtok_r(str, PARSE_DELIMITER, &str);
1589f5488e3SSunil Kumar Kori if (token == NULL) {
1599f5488e3SSunil Kumar Kori free(vlan);
160e1673ddeSJasvinder Singh free(*dscp_table);
1619f5488e3SSunil Kumar Kori return -1;
1629f5488e3SSunil Kumar Kori }
1639f5488e3SSunil Kumar Kori }
1649f5488e3SSunil Kumar Kori
1659f5488e3SSunil Kumar Kori *vlan_table = vlan;
1669f5488e3SSunil Kumar Kori return 0;
1679f5488e3SSunil Kumar Kori }
1689f5488e3SSunil Kumar Kori
1699f5488e3SSunil Kumar Kori static int
parse_vlan_table_entries(char * str,enum rte_color ** vlan_table)1709f5488e3SSunil Kumar Kori parse_vlan_table_entries(char *str, enum rte_color **vlan_table)
1719f5488e3SSunil Kumar Kori {
1729f5488e3SSunil Kumar Kori char *token;
1739f5488e3SSunil Kumar Kori int i = 0;
1749f5488e3SSunil Kumar Kori
1759f5488e3SSunil Kumar Kori token = strtok_r(str, PARSE_DELIMITER, &str);
1769f5488e3SSunil Kumar Kori if (token == NULL)
1779f5488e3SSunil Kumar Kori return 0;
1789f5488e3SSunil Kumar Kori
1799f5488e3SSunil Kumar Kori /* Allocate memory for vlan table */
1809f5488e3SSunil Kumar Kori *vlan_table = (enum rte_color *)malloc(MAX_VLAN_TABLE_ENTRIES *
1819f5488e3SSunil Kumar Kori sizeof(enum rte_color));
1829f5488e3SSunil Kumar Kori if (*vlan_table == NULL)
1839f5488e3SSunil Kumar Kori return -1;
1849f5488e3SSunil Kumar Kori
1859f5488e3SSunil Kumar Kori while (1) {
1869f5488e3SSunil Kumar Kori if (strcasecmp(token, "G") == 0)
1879f5488e3SSunil Kumar Kori (*vlan_table)[i++] = RTE_COLOR_GREEN;
1889f5488e3SSunil Kumar Kori else if (strcasecmp(token, "Y") == 0)
1899f5488e3SSunil Kumar Kori (*vlan_table)[i++] = RTE_COLOR_YELLOW;
1909f5488e3SSunil Kumar Kori else if (strcasecmp(token, "R") == 0)
1919f5488e3SSunil Kumar Kori (*vlan_table)[i++] = RTE_COLOR_RED;
1929f5488e3SSunil Kumar Kori else {
1939f5488e3SSunil Kumar Kori free(*vlan_table);
1949f5488e3SSunil Kumar Kori return -1;
1959f5488e3SSunil Kumar Kori }
1969f5488e3SSunil Kumar Kori if (i == MAX_VLAN_TABLE_ENTRIES)
1979f5488e3SSunil Kumar Kori break;
1989f5488e3SSunil Kumar Kori
1999f5488e3SSunil Kumar Kori token = strtok_r(str, PARSE_DELIMITER, &str);
2009f5488e3SSunil Kumar Kori if (token == NULL) {
2019f5488e3SSunil Kumar Kori free(*vlan_table);
2029f5488e3SSunil Kumar Kori return -1;
2039f5488e3SSunil Kumar Kori }
2049f5488e3SSunil Kumar Kori }
2059f5488e3SSunil Kumar Kori return 0;
2069f5488e3SSunil Kumar Kori }
2079f5488e3SSunil Kumar Kori
2089f5488e3SSunil Kumar Kori static int
parse_dscp_table_entries(char * str,enum rte_color ** dscp_table)209c1656328SJasvinder Singh parse_dscp_table_entries(char *str, enum rte_color **dscp_table)
210e63b5016SJasvinder Singh {
211e63b5016SJasvinder Singh char *token;
212e63b5016SJasvinder Singh int i = 0;
213e63b5016SJasvinder Singh
214e63b5016SJasvinder Singh token = strtok_r(str, PARSE_DELIMITER, &str);
215e63b5016SJasvinder Singh if (token == NULL)
216e63b5016SJasvinder Singh return 0;
217e63b5016SJasvinder Singh
218e63b5016SJasvinder Singh /* Allocate memory for dscp table */
219c1656328SJasvinder Singh *dscp_table = (enum rte_color *)malloc(MAX_DSCP_TABLE_ENTRIES *
220c1656328SJasvinder Singh sizeof(enum rte_color));
221459463aeSJasvinder Singh if (*dscp_table == NULL)
2220c36b7c4SJasvinder Singh return -1;
223e63b5016SJasvinder Singh
224e63b5016SJasvinder Singh while (1) {
225e63b5016SJasvinder Singh if (strcmp(token, "G") == 0 ||
226e63b5016SJasvinder Singh strcmp(token, "g") == 0)
227b314a4a6SSunil Kumar Kori (*dscp_table)[i++] = RTE_COLOR_GREEN;
228e63b5016SJasvinder Singh else if (strcmp(token, "Y") == 0 ||
229e63b5016SJasvinder Singh strcmp(token, "y") == 0)
230b314a4a6SSunil Kumar Kori (*dscp_table)[i++] = RTE_COLOR_YELLOW;
231e63b5016SJasvinder Singh else if (strcmp(token, "R") == 0 ||
232e63b5016SJasvinder Singh strcmp(token, "r") == 0)
233b314a4a6SSunil Kumar Kori (*dscp_table)[i++] = RTE_COLOR_RED;
234e63b5016SJasvinder Singh else {
235459463aeSJasvinder Singh free(*dscp_table);
236e63b5016SJasvinder Singh return -1;
237e63b5016SJasvinder Singh }
238e63b5016SJasvinder Singh if (i == MAX_DSCP_TABLE_ENTRIES)
239e63b5016SJasvinder Singh break;
240e63b5016SJasvinder Singh
241e63b5016SJasvinder Singh token = strtok_r(str, PARSE_DELIMITER, &str);
2420c36b7c4SJasvinder Singh if (token == NULL) {
243459463aeSJasvinder Singh free(*dscp_table);
244e63b5016SJasvinder Singh return -1;
245e63b5016SJasvinder Singh }
2460c36b7c4SJasvinder Singh }
247e63b5016SJasvinder Singh return 0;
248e63b5016SJasvinder Singh }
249e63b5016SJasvinder Singh
250e63b5016SJasvinder Singh static int
parse_default_input_color_str(char * str,uint64_t * def_inp_color)2519f5488e3SSunil Kumar Kori parse_default_input_color_str(char *str, uint64_t *def_inp_color)
2529f5488e3SSunil Kumar Kori {
2539f5488e3SSunil Kumar Kori char *token;
2549f5488e3SSunil Kumar Kori
2559f5488e3SSunil Kumar Kori token = strtok_r(str, PARSE_DELIMITER, &str);
2569f5488e3SSunil Kumar Kori if (token == NULL)
2579f5488e3SSunil Kumar Kori return 0;
2589f5488e3SSunil Kumar Kori
2599f5488e3SSunil Kumar Kori if (strcasecmp(token, "G") == 0)
2609f5488e3SSunil Kumar Kori *def_inp_color = RTE_COLOR_GREEN;
2619f5488e3SSunil Kumar Kori else if (strcasecmp(token, "Y") == 0)
2629f5488e3SSunil Kumar Kori *def_inp_color = RTE_COLOR_YELLOW;
2639f5488e3SSunil Kumar Kori else if (strcasecmp(token, "R") == 0)
2649f5488e3SSunil Kumar Kori *def_inp_color = RTE_COLOR_RED;
2659f5488e3SSunil Kumar Kori else
2669f5488e3SSunil Kumar Kori return -1;
2679f5488e3SSunil Kumar Kori
2689f5488e3SSunil Kumar Kori return 0;
2699f5488e3SSunil Kumar Kori }
2709f5488e3SSunil Kumar Kori
2719f5488e3SSunil Kumar Kori static int
parse_meter_color_str(char * c_str,uint32_t * use_prev_meter_color,enum rte_color ** vlan_table,enum rte_color ** dscp_table)272e63b5016SJasvinder Singh parse_meter_color_str(char *c_str, uint32_t *use_prev_meter_color,
2739f5488e3SSunil Kumar Kori enum rte_color **vlan_table, enum rte_color **dscp_table)
274e63b5016SJasvinder Singh {
275e63b5016SJasvinder Singh char *token;
276e63b5016SJasvinder Singh uint64_t previous_mtr_color = 0;
277e63b5016SJasvinder Singh int ret;
278e63b5016SJasvinder Singh
279e63b5016SJasvinder Singh /* First token: use previous meter color */
280e63b5016SJasvinder Singh token = strtok_r(c_str, PARSE_DELIMITER, &c_str);
281e63b5016SJasvinder Singh if (token == NULL)
282e63b5016SJasvinder Singh return -1;
283e63b5016SJasvinder Singh
284e63b5016SJasvinder Singh ret = parse_uint(&previous_mtr_color, token);
285e63b5016SJasvinder Singh if (ret != 0)
286e63b5016SJasvinder Singh return -1;
287e63b5016SJasvinder Singh
288e63b5016SJasvinder Singh /* Check if previous meter color to be used */
289e63b5016SJasvinder Singh if (previous_mtr_color) {
290e63b5016SJasvinder Singh *use_prev_meter_color = previous_mtr_color;
291e63b5016SJasvinder Singh return 0;
292e63b5016SJasvinder Singh }
293e63b5016SJasvinder Singh
2949f5488e3SSunil Kumar Kori ret = parse_input_color_table_entries(c_str, dscp_table, vlan_table);
295e63b5016SJasvinder Singh if (ret != 0)
296e63b5016SJasvinder Singh return -1;
297e63b5016SJasvinder Singh
298e63b5016SJasvinder Singh return 0;
299e63b5016SJasvinder Singh }
300e63b5016SJasvinder Singh
301e63b5016SJasvinder Singh static int
parse_multi_token_string(char * t_str,uint16_t * port_id,uint32_t * mtr_id,enum rte_mtr_color_in_protocol * proto,enum rte_color ** dscp_table)302*204daeeaSSunil Kumar Kori parse_multi_token_string(char *t_str, uint16_t *port_id, uint32_t *mtr_id,
303*204daeeaSSunil Kumar Kori enum rte_mtr_color_in_protocol *proto, enum rte_color **dscp_table)
304281eeb8aSJasvinder Singh {
305281eeb8aSJasvinder Singh char *token;
306281eeb8aSJasvinder Singh uint64_t val;
307281eeb8aSJasvinder Singh int ret;
308281eeb8aSJasvinder Singh
309281eeb8aSJasvinder Singh /* First token: port id */
310281eeb8aSJasvinder Singh token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
311281eeb8aSJasvinder Singh if (token == NULL)
312281eeb8aSJasvinder Singh return -1;
313281eeb8aSJasvinder Singh
314281eeb8aSJasvinder Singh ret = parse_uint(&val, token);
315281eeb8aSJasvinder Singh if (ret != 0 || val > UINT16_MAX)
316281eeb8aSJasvinder Singh return -1;
317281eeb8aSJasvinder Singh
318281eeb8aSJasvinder Singh *port_id = val;
319281eeb8aSJasvinder Singh
320281eeb8aSJasvinder Singh /* Second token: meter id */
321281eeb8aSJasvinder Singh token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
322281eeb8aSJasvinder Singh if (token == NULL)
323281eeb8aSJasvinder Singh return 0;
324281eeb8aSJasvinder Singh
325281eeb8aSJasvinder Singh ret = parse_uint(&val, token);
326281eeb8aSJasvinder Singh if (ret != 0 || val > UINT32_MAX)
327281eeb8aSJasvinder Singh return -1;
328281eeb8aSJasvinder Singh
329281eeb8aSJasvinder Singh *mtr_id = val;
330281eeb8aSJasvinder Singh
331*204daeeaSSunil Kumar Kori /* Third token: protocol */
332*204daeeaSSunil Kumar Kori token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
333*204daeeaSSunil Kumar Kori if (token == NULL)
334*204daeeaSSunil Kumar Kori return 0;
335*204daeeaSSunil Kumar Kori
336*204daeeaSSunil Kumar Kori if (strcmp(token, "outer_ip") == 0)
337*204daeeaSSunil Kumar Kori *proto = RTE_MTR_COLOR_IN_PROTO_OUTER_IP;
338*204daeeaSSunil Kumar Kori else if (strcmp(token, "inner_ip") == 0)
339*204daeeaSSunil Kumar Kori *proto = RTE_MTR_COLOR_IN_PROTO_INNER_IP;
340*204daeeaSSunil Kumar Kori
341281eeb8aSJasvinder Singh ret = parse_dscp_table_entries(t_str, dscp_table);
342281eeb8aSJasvinder Singh if (ret != 0)
343281eeb8aSJasvinder Singh return -1;
344281eeb8aSJasvinder Singh
345281eeb8aSJasvinder Singh return 0;
346281eeb8aSJasvinder Singh }
347281eeb8aSJasvinder Singh
3489f5488e3SSunil Kumar Kori static int
parse_multi_token_vlan_str(char * t_str,uint16_t * port_id,uint32_t * mtr_id,enum rte_mtr_color_in_protocol * proto,enum rte_color ** vlan_table)3499f5488e3SSunil Kumar Kori parse_multi_token_vlan_str(char *t_str, uint16_t *port_id, uint32_t *mtr_id,
350*204daeeaSSunil Kumar Kori enum rte_mtr_color_in_protocol *proto, enum rte_color **vlan_table)
3519f5488e3SSunil Kumar Kori {
3529f5488e3SSunil Kumar Kori uint64_t val;
3539f5488e3SSunil Kumar Kori char *token;
3549f5488e3SSunil Kumar Kori int ret;
3559f5488e3SSunil Kumar Kori
3569f5488e3SSunil Kumar Kori /* First token: port id */
3579f5488e3SSunil Kumar Kori token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
3589f5488e3SSunil Kumar Kori if (token == NULL)
3599f5488e3SSunil Kumar Kori return -1;
3609f5488e3SSunil Kumar Kori
3619f5488e3SSunil Kumar Kori ret = parse_uint(&val, token);
3629f5488e3SSunil Kumar Kori if (ret != 0 || val > UINT16_MAX)
3639f5488e3SSunil Kumar Kori return -1;
3649f5488e3SSunil Kumar Kori
3659f5488e3SSunil Kumar Kori *port_id = val;
3669f5488e3SSunil Kumar Kori
3679f5488e3SSunil Kumar Kori /* Second token: meter id */
3689f5488e3SSunil Kumar Kori token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
3699f5488e3SSunil Kumar Kori if (token == NULL)
3709f5488e3SSunil Kumar Kori return 0;
3719f5488e3SSunil Kumar Kori
3729f5488e3SSunil Kumar Kori ret = parse_uint(&val, token);
3739f5488e3SSunil Kumar Kori if (ret != 0 || val > UINT32_MAX)
3749f5488e3SSunil Kumar Kori return -1;
3759f5488e3SSunil Kumar Kori
3769f5488e3SSunil Kumar Kori *mtr_id = val;
3779f5488e3SSunil Kumar Kori
378*204daeeaSSunil Kumar Kori /* Third token: protocol */
379*204daeeaSSunil Kumar Kori token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
380*204daeeaSSunil Kumar Kori if (token == NULL)
381*204daeeaSSunil Kumar Kori return 0;
382*204daeeaSSunil Kumar Kori
383*204daeeaSSunil Kumar Kori if (strcmp(token, "outer_vlan") == 0)
384*204daeeaSSunil Kumar Kori *proto = RTE_MTR_COLOR_IN_PROTO_OUTER_VLAN;
385*204daeeaSSunil Kumar Kori else if (strcmp(token, "inner_vlan") == 0)
386*204daeeaSSunil Kumar Kori *proto = RTE_MTR_COLOR_IN_PROTO_INNER_VLAN;
387*204daeeaSSunil Kumar Kori
3889f5488e3SSunil Kumar Kori ret = parse_vlan_table_entries(t_str, vlan_table);
3899f5488e3SSunil Kumar Kori if (ret != 0)
3909f5488e3SSunil Kumar Kori return -1;
3919f5488e3SSunil Kumar Kori
3929f5488e3SSunil Kumar Kori return 0;
3939f5488e3SSunil Kumar Kori }
3949f5488e3SSunil Kumar Kori
395281eeb8aSJasvinder Singh /* *** Show Port Meter Capabilities *** */
396281eeb8aSJasvinder Singh struct cmd_show_port_meter_cap_result {
397281eeb8aSJasvinder Singh cmdline_fixed_string_t show;
398281eeb8aSJasvinder Singh cmdline_fixed_string_t port;
399281eeb8aSJasvinder Singh cmdline_fixed_string_t meter;
400281eeb8aSJasvinder Singh cmdline_fixed_string_t cap;
401281eeb8aSJasvinder Singh uint16_t port_id;
402281eeb8aSJasvinder Singh };
403281eeb8aSJasvinder Singh
404ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_show_port_meter_cap_show =
405281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(
406281eeb8aSJasvinder Singh struct cmd_show_port_meter_cap_result, show, "show");
407ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_show_port_meter_cap_port =
408281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(
409281eeb8aSJasvinder Singh struct cmd_show_port_meter_cap_result, port, "port");
410ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_show_port_meter_cap_meter =
411281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(
412281eeb8aSJasvinder Singh struct cmd_show_port_meter_cap_result, meter, "meter");
413ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_show_port_meter_cap_cap =
414281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(
415281eeb8aSJasvinder Singh struct cmd_show_port_meter_cap_result, cap, "cap");
416ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_show_port_meter_cap_port_id =
417281eeb8aSJasvinder Singh TOKEN_NUM_INITIALIZER(
418c2341bb6SDmitry Kozlyuk struct cmd_show_port_meter_cap_result, port_id, RTE_UINT16);
419281eeb8aSJasvinder Singh
cmd_show_port_meter_cap_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)420281eeb8aSJasvinder Singh static void cmd_show_port_meter_cap_parsed(void *parsed_result,
421f2fc83b4SThomas Monjalon __rte_unused struct cmdline *cl,
422f2fc83b4SThomas Monjalon __rte_unused void *data)
423281eeb8aSJasvinder Singh {
424281eeb8aSJasvinder Singh struct cmd_show_port_meter_cap_result *res = parsed_result;
425281eeb8aSJasvinder Singh struct rte_mtr_capabilities cap;
426281eeb8aSJasvinder Singh struct rte_mtr_error error;
427281eeb8aSJasvinder Singh uint16_t port_id = res->port_id;
428281eeb8aSJasvinder Singh int ret;
429281eeb8aSJasvinder Singh
430281eeb8aSJasvinder Singh if (port_id_is_invalid(port_id, ENABLED_WARN))
431281eeb8aSJasvinder Singh return;
432281eeb8aSJasvinder Singh
433281eeb8aSJasvinder Singh memset(&cap, 0, sizeof(struct rte_mtr_capabilities));
434281eeb8aSJasvinder Singh ret = rte_mtr_capabilities_get(port_id, &cap, &error);
435281eeb8aSJasvinder Singh if (ret) {
436281eeb8aSJasvinder Singh print_err_msg(&error);
437281eeb8aSJasvinder Singh return;
438281eeb8aSJasvinder Singh }
439281eeb8aSJasvinder Singh
440281eeb8aSJasvinder Singh printf("\n**** Port Meter Object Capabilities ****\n\n");
441281eeb8aSJasvinder Singh printf("cap.n_max %" PRIu32 "\n", cap.n_max);
442281eeb8aSJasvinder Singh printf("cap.n_shared_max %" PRIu32 "\n", cap.n_shared_max);
443281eeb8aSJasvinder Singh printf("cap.identical %" PRId32 "\n", cap.identical);
444281eeb8aSJasvinder Singh printf("cap.shared_identical %" PRId32 "\n",
445281eeb8aSJasvinder Singh cap.shared_identical);
446281eeb8aSJasvinder Singh printf("cap.shared_n_flows_per_mtr_max %" PRIu32 "\n",
447281eeb8aSJasvinder Singh cap.shared_n_flows_per_mtr_max);
448281eeb8aSJasvinder Singh printf("cap.chaining_n_mtrs_per_flow_max %" PRIu32 "\n",
449281eeb8aSJasvinder Singh cap.chaining_n_mtrs_per_flow_max);
450281eeb8aSJasvinder Singh printf("cap.chaining_use_prev_mtr_color_supported %" PRId32 "\n",
451281eeb8aSJasvinder Singh cap.chaining_use_prev_mtr_color_supported);
452281eeb8aSJasvinder Singh printf("cap.chaining_use_prev_mtr_color_enforced %" PRId32 "\n",
453281eeb8aSJasvinder Singh cap.chaining_use_prev_mtr_color_enforced);
454281eeb8aSJasvinder Singh printf("cap.meter_srtcm_rfc2697_n_max %" PRIu32 "\n",
455281eeb8aSJasvinder Singh cap.meter_srtcm_rfc2697_n_max);
456281eeb8aSJasvinder Singh printf("cap.meter_trtcm_rfc2698_n_max %" PRIu32 "\n",
457281eeb8aSJasvinder Singh cap.meter_trtcm_rfc2698_n_max);
458281eeb8aSJasvinder Singh printf("cap.meter_trtcm_rfc4115_n_max %" PRIu32 "\n",
459281eeb8aSJasvinder Singh cap.meter_trtcm_rfc4115_n_max);
460281eeb8aSJasvinder Singh printf("cap.meter_rate_max %" PRIu64 "\n", cap.meter_rate_max);
461281eeb8aSJasvinder Singh printf("cap.color_aware_srtcm_rfc2697_supported %" PRId32 "\n",
462281eeb8aSJasvinder Singh cap.color_aware_srtcm_rfc2697_supported);
463281eeb8aSJasvinder Singh printf("cap.color_aware_trtcm_rfc2698_supported %" PRId32 "\n",
464281eeb8aSJasvinder Singh cap.color_aware_trtcm_rfc2698_supported);
465281eeb8aSJasvinder Singh printf("cap.color_aware_trtcm_rfc4115_supported %" PRId32 "\n",
466281eeb8aSJasvinder Singh cap.color_aware_trtcm_rfc4115_supported);
467c5a3860fSLi Zhang printf("cap.srtcm_rfc2697_byte_mode_supported %" PRId32 "\n",
468c5a3860fSLi Zhang cap.srtcm_rfc2697_byte_mode_supported);
469c5a3860fSLi Zhang printf("cap.srtcm_rfc2697_packet_mode_supported %" PRId32 "\n",
470c5a3860fSLi Zhang cap.srtcm_rfc2697_packet_mode_supported);
471c5a3860fSLi Zhang printf("cap.trtcm_rfc2698_byte_mode_supported %" PRId32 "\n",
472c5a3860fSLi Zhang cap.trtcm_rfc2698_byte_mode_supported);
473c5a3860fSLi Zhang printf("cap.trtcm_rfc2698_packet_mode_supported %" PRId32 "\n",
474c5a3860fSLi Zhang cap.trtcm_rfc2698_packet_mode_supported);
475c5a3860fSLi Zhang printf("cap.trtcm_rfc4115_byte_mode_supported %" PRId32 "\n",
476c5a3860fSLi Zhang cap.trtcm_rfc4115_byte_mode_supported);
477c5a3860fSLi Zhang printf("cap.trtcm_rfc4115_packet_mode_supported %" PRId32 "\n",
478c5a3860fSLi Zhang cap.trtcm_rfc4115_packet_mode_supported);
479281eeb8aSJasvinder Singh printf("cap.stats_mask %" PRIx64 "\n", cap.stats_mask);
4809f5488e3SSunil Kumar Kori printf("cap.input_color_proto_mask 0x%" PRIx64 "\n",
4819f5488e3SSunil Kumar Kori cap.input_color_proto_mask);
4829f5488e3SSunil Kumar Kori printf("cap.separate_input_color_table_per_port %" PRId32 "\n",
4839f5488e3SSunil Kumar Kori cap.separate_input_color_table_per_port);
484281eeb8aSJasvinder Singh }
485281eeb8aSJasvinder Singh
486281eeb8aSJasvinder Singh cmdline_parse_inst_t cmd_show_port_meter_cap = {
487281eeb8aSJasvinder Singh .f = cmd_show_port_meter_cap_parsed,
488281eeb8aSJasvinder Singh .data = NULL,
489618f0f4aSFerruh Yigit .help_str = "show port meter cap <port_id>",
490281eeb8aSJasvinder Singh .tokens = {
491281eeb8aSJasvinder Singh (void *)&cmd_show_port_meter_cap_show,
492281eeb8aSJasvinder Singh (void *)&cmd_show_port_meter_cap_port,
493281eeb8aSJasvinder Singh (void *)&cmd_show_port_meter_cap_meter,
494281eeb8aSJasvinder Singh (void *)&cmd_show_port_meter_cap_cap,
495281eeb8aSJasvinder Singh (void *)&cmd_show_port_meter_cap_port_id,
496281eeb8aSJasvinder Singh NULL,
497281eeb8aSJasvinder Singh },
498281eeb8aSJasvinder Singh };
499281eeb8aSJasvinder Singh
50030ffb4e6SCristian Dumitrescu /* *** Add Port Meter Profile srtcm_rfc2697 *** */
50130ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_srtcm_result {
50230ffb4e6SCristian Dumitrescu cmdline_fixed_string_t add;
50330ffb4e6SCristian Dumitrescu cmdline_fixed_string_t port;
50430ffb4e6SCristian Dumitrescu cmdline_fixed_string_t meter;
50530ffb4e6SCristian Dumitrescu cmdline_fixed_string_t profile;
50630ffb4e6SCristian Dumitrescu cmdline_fixed_string_t srtcm_rfc2697;
50730ffb4e6SCristian Dumitrescu uint16_t port_id;
50830ffb4e6SCristian Dumitrescu uint32_t profile_id;
50930ffb4e6SCristian Dumitrescu uint64_t cir;
51030ffb4e6SCristian Dumitrescu uint64_t cbs;
51130ffb4e6SCristian Dumitrescu uint64_t ebs;
512c5a3860fSLi Zhang int packet_mode;
51330ffb4e6SCristian Dumitrescu };
51430ffb4e6SCristian Dumitrescu
515ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_add =
51630ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
51730ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_srtcm_result, add, "add");
518ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_port =
51930ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
52030ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_srtcm_result,
52130ffb4e6SCristian Dumitrescu port, "port");
522ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_meter =
52330ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
52430ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_srtcm_result,
52530ffb4e6SCristian Dumitrescu meter, "meter");
526ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_profile =
52730ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
52830ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_srtcm_result,
52930ffb4e6SCristian Dumitrescu profile, "profile");
530ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_srtcm_rfc2697 =
53130ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
53230ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_srtcm_result,
53330ffb4e6SCristian Dumitrescu srtcm_rfc2697, "srtcm_rfc2697");
534ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_port_id =
53530ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
53630ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_srtcm_result,
537c2341bb6SDmitry Kozlyuk port_id, RTE_UINT16);
538ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_profile_id =
53930ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
54030ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_srtcm_result,
541c2341bb6SDmitry Kozlyuk profile_id, RTE_UINT32);
542ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cir =
54330ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
54430ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_srtcm_result,
545c2341bb6SDmitry Kozlyuk cir, RTE_UINT64);
546ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cbs =
54730ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
54830ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_srtcm_result,
549c2341bb6SDmitry Kozlyuk cbs, RTE_UINT64);
550ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_ebs =
55130ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
55230ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_srtcm_result,
553c2341bb6SDmitry Kozlyuk ebs, RTE_UINT64);
554ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_packet_mode =
555c5a3860fSLi Zhang TOKEN_NUM_INITIALIZER(
556c5a3860fSLi Zhang struct cmd_add_port_meter_profile_srtcm_result,
557c5a3860fSLi Zhang packet_mode, RTE_UINT32);
55830ffb4e6SCristian Dumitrescu
cmd_add_port_meter_profile_srtcm_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)55930ffb4e6SCristian Dumitrescu static void cmd_add_port_meter_profile_srtcm_parsed(void *parsed_result,
560f2fc83b4SThomas Monjalon __rte_unused struct cmdline *cl,
561f2fc83b4SThomas Monjalon __rte_unused void *data)
56230ffb4e6SCristian Dumitrescu {
56330ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_srtcm_result *res = parsed_result;
56430ffb4e6SCristian Dumitrescu struct rte_mtr_meter_profile mp;
56530ffb4e6SCristian Dumitrescu struct rte_mtr_error error;
56630ffb4e6SCristian Dumitrescu uint32_t profile_id = res->profile_id;
56730ffb4e6SCristian Dumitrescu uint16_t port_id = res->port_id;
56830ffb4e6SCristian Dumitrescu int ret;
56930ffb4e6SCristian Dumitrescu
57030ffb4e6SCristian Dumitrescu if (port_id_is_invalid(port_id, ENABLED_WARN))
57130ffb4e6SCristian Dumitrescu return;
57230ffb4e6SCristian Dumitrescu
57330ffb4e6SCristian Dumitrescu /* Private shaper profile params */
57430ffb4e6SCristian Dumitrescu memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
575e63b5016SJasvinder Singh mp.alg = RTE_MTR_SRTCM_RFC2697;
57630ffb4e6SCristian Dumitrescu mp.srtcm_rfc2697.cir = res->cir;
57730ffb4e6SCristian Dumitrescu mp.srtcm_rfc2697.cbs = res->cbs;
57830ffb4e6SCristian Dumitrescu mp.srtcm_rfc2697.ebs = res->ebs;
579c5a3860fSLi Zhang mp.packet_mode = res->packet_mode;
58030ffb4e6SCristian Dumitrescu
58130ffb4e6SCristian Dumitrescu ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
58230ffb4e6SCristian Dumitrescu if (ret != 0) {
58330ffb4e6SCristian Dumitrescu print_err_msg(&error);
58430ffb4e6SCristian Dumitrescu return;
58530ffb4e6SCristian Dumitrescu }
58630ffb4e6SCristian Dumitrescu }
58730ffb4e6SCristian Dumitrescu
58830ffb4e6SCristian Dumitrescu cmdline_parse_inst_t cmd_add_port_meter_profile_srtcm = {
58930ffb4e6SCristian Dumitrescu .f = cmd_add_port_meter_profile_srtcm_parsed,
59030ffb4e6SCristian Dumitrescu .data = NULL,
591c5a3860fSLi Zhang .help_str = "add port meter profile srtcm_rfc2697 <port_id> <profile_id> <cir> <cbs> <ebs> <packet_mode>",
59230ffb4e6SCristian Dumitrescu .tokens = {
59330ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_srtcm_add,
59430ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_srtcm_port,
59530ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_srtcm_meter,
59630ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_srtcm_profile,
597a0f367ebSJasvinder Singh (void *)&cmd_add_port_meter_profile_srtcm_srtcm_rfc2697,
59830ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_srtcm_port_id,
59930ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_srtcm_profile_id,
60030ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_srtcm_cir,
60130ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_srtcm_cbs,
60230ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_srtcm_ebs,
603c5a3860fSLi Zhang (void *)&cmd_add_port_meter_profile_srtcm_packet_mode,
60430ffb4e6SCristian Dumitrescu NULL,
60530ffb4e6SCristian Dumitrescu },
60630ffb4e6SCristian Dumitrescu };
60730ffb4e6SCristian Dumitrescu
60830ffb4e6SCristian Dumitrescu /* *** Add Port Meter Profile trtcm_rfc2698 *** */
60930ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_result {
61030ffb4e6SCristian Dumitrescu cmdline_fixed_string_t add;
61130ffb4e6SCristian Dumitrescu cmdline_fixed_string_t port;
61230ffb4e6SCristian Dumitrescu cmdline_fixed_string_t meter;
61330ffb4e6SCristian Dumitrescu cmdline_fixed_string_t profile;
61430ffb4e6SCristian Dumitrescu cmdline_fixed_string_t trtcm_rfc2698;
61530ffb4e6SCristian Dumitrescu uint16_t port_id;
61630ffb4e6SCristian Dumitrescu uint32_t profile_id;
61730ffb4e6SCristian Dumitrescu uint64_t cir;
61830ffb4e6SCristian Dumitrescu uint64_t pir;
61930ffb4e6SCristian Dumitrescu uint64_t cbs;
62030ffb4e6SCristian Dumitrescu uint64_t pbs;
621c5a3860fSLi Zhang int packet_mode;
62230ffb4e6SCristian Dumitrescu };
62330ffb4e6SCristian Dumitrescu
624ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_add =
62530ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
62630ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_result, add, "add");
627ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_port =
62830ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
62930ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_result,
63030ffb4e6SCristian Dumitrescu port, "port");
631ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_meter =
63230ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
63330ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_result,
63430ffb4e6SCristian Dumitrescu meter, "meter");
635ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_profile =
63630ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
63730ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_result,
63830ffb4e6SCristian Dumitrescu profile, "profile");
639ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_trtcm_rfc2698 =
64030ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
64130ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_result,
64230ffb4e6SCristian Dumitrescu trtcm_rfc2698, "trtcm_rfc2698");
643ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_port_id =
64430ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
64530ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_result,
646c2341bb6SDmitry Kozlyuk port_id, RTE_UINT16);
647ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_profile_id =
64830ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
64930ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_result,
650c2341bb6SDmitry Kozlyuk profile_id, RTE_UINT32);
651ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cir =
65230ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
65330ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_result,
654c2341bb6SDmitry Kozlyuk cir, RTE_UINT64);
655ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pir =
65630ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
65730ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_result,
658c2341bb6SDmitry Kozlyuk pir, RTE_UINT64);
659ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cbs =
66030ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
66130ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_result,
662c2341bb6SDmitry Kozlyuk cbs, RTE_UINT64);
663ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pbs =
66430ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
66530ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_result,
666c2341bb6SDmitry Kozlyuk pbs, RTE_UINT64);
667ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_packet_mode =
668c5a3860fSLi Zhang TOKEN_NUM_INITIALIZER(
669c5a3860fSLi Zhang struct cmd_add_port_meter_profile_trtcm_result,
670c5a3860fSLi Zhang packet_mode, RTE_UINT32);
67130ffb4e6SCristian Dumitrescu
cmd_add_port_meter_profile_trtcm_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)67230ffb4e6SCristian Dumitrescu static void cmd_add_port_meter_profile_trtcm_parsed(void *parsed_result,
673f2fc83b4SThomas Monjalon __rte_unused struct cmdline *cl,
674f2fc83b4SThomas Monjalon __rte_unused void *data)
67530ffb4e6SCristian Dumitrescu {
67630ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_result *res = parsed_result;
67730ffb4e6SCristian Dumitrescu struct rte_mtr_meter_profile mp;
67830ffb4e6SCristian Dumitrescu struct rte_mtr_error error;
67930ffb4e6SCristian Dumitrescu uint32_t profile_id = res->profile_id;
68030ffb4e6SCristian Dumitrescu uint16_t port_id = res->port_id;
68130ffb4e6SCristian Dumitrescu int ret;
68230ffb4e6SCristian Dumitrescu
68330ffb4e6SCristian Dumitrescu if (port_id_is_invalid(port_id, ENABLED_WARN))
68430ffb4e6SCristian Dumitrescu return;
68530ffb4e6SCristian Dumitrescu
68630ffb4e6SCristian Dumitrescu /* Private shaper profile params */
68730ffb4e6SCristian Dumitrescu memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
688e63b5016SJasvinder Singh mp.alg = RTE_MTR_TRTCM_RFC2698;
68930ffb4e6SCristian Dumitrescu mp.trtcm_rfc2698.cir = res->cir;
69030ffb4e6SCristian Dumitrescu mp.trtcm_rfc2698.pir = res->pir;
69130ffb4e6SCristian Dumitrescu mp.trtcm_rfc2698.cbs = res->cbs;
69230ffb4e6SCristian Dumitrescu mp.trtcm_rfc2698.pbs = res->pbs;
693c5a3860fSLi Zhang mp.packet_mode = res->packet_mode;
69430ffb4e6SCristian Dumitrescu
69530ffb4e6SCristian Dumitrescu ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
69630ffb4e6SCristian Dumitrescu if (ret != 0) {
69730ffb4e6SCristian Dumitrescu print_err_msg(&error);
69830ffb4e6SCristian Dumitrescu return;
69930ffb4e6SCristian Dumitrescu }
70030ffb4e6SCristian Dumitrescu }
70130ffb4e6SCristian Dumitrescu
70230ffb4e6SCristian Dumitrescu cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm = {
70330ffb4e6SCristian Dumitrescu .f = cmd_add_port_meter_profile_trtcm_parsed,
70430ffb4e6SCristian Dumitrescu .data = NULL,
705c5a3860fSLi Zhang .help_str = "add port meter profile trtcm_rfc2698 <port_id> <profile_id> <cir> <pir> <cbs> <pbs> <packet_mode>",
70630ffb4e6SCristian Dumitrescu .tokens = {
70730ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_add,
70830ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_port,
70930ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_meter,
71030ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_profile,
711a0f367ebSJasvinder Singh (void *)&cmd_add_port_meter_profile_trtcm_trtcm_rfc2698,
71230ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_port_id,
71330ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_profile_id,
71430ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_cir,
71530ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_pir,
71630ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_cbs,
71730ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_pbs,
718c5a3860fSLi Zhang (void *)&cmd_add_port_meter_profile_trtcm_packet_mode,
71930ffb4e6SCristian Dumitrescu NULL,
72030ffb4e6SCristian Dumitrescu },
72130ffb4e6SCristian Dumitrescu };
72230ffb4e6SCristian Dumitrescu
72330ffb4e6SCristian Dumitrescu /* *** Add Port Meter Profile trtcm_rfc4115 *** */
72430ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_rfc4115_result {
72530ffb4e6SCristian Dumitrescu cmdline_fixed_string_t add;
72630ffb4e6SCristian Dumitrescu cmdline_fixed_string_t port;
72730ffb4e6SCristian Dumitrescu cmdline_fixed_string_t meter;
72830ffb4e6SCristian Dumitrescu cmdline_fixed_string_t profile;
72930ffb4e6SCristian Dumitrescu cmdline_fixed_string_t trtcm_rfc4115;
73030ffb4e6SCristian Dumitrescu uint16_t port_id;
73130ffb4e6SCristian Dumitrescu uint32_t profile_id;
73230ffb4e6SCristian Dumitrescu uint64_t cir;
73330ffb4e6SCristian Dumitrescu uint64_t eir;
73430ffb4e6SCristian Dumitrescu uint64_t cbs;
73530ffb4e6SCristian Dumitrescu uint64_t ebs;
736c5a3860fSLi Zhang int packet_mode;
73730ffb4e6SCristian Dumitrescu };
73830ffb4e6SCristian Dumitrescu
739ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_add =
74030ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
74130ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_rfc4115_result, add,
74230ffb4e6SCristian Dumitrescu "add");
743ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_port =
74430ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
74530ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
74630ffb4e6SCristian Dumitrescu port, "port");
747ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_meter =
74830ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
74930ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
75030ffb4e6SCristian Dumitrescu meter, "meter");
751ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_profile =
75230ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
75330ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
75430ffb4e6SCristian Dumitrescu profile, "profile");
755ea0774ffSDavid Marchand static cmdline_parse_token_string_t
75630ffb4e6SCristian Dumitrescu cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115 =
75730ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
75830ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
75930ffb4e6SCristian Dumitrescu trtcm_rfc4115, "trtcm_rfc4115");
760ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_port_id =
76130ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
76230ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
763c2341bb6SDmitry Kozlyuk port_id, RTE_UINT16);
764ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_profile_id =
76530ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
76630ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
767c2341bb6SDmitry Kozlyuk profile_id, RTE_UINT32);
768ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cir =
76930ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
77030ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
771c2341bb6SDmitry Kozlyuk cir, RTE_UINT64);
772ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_eir =
77330ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
77430ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
775c2341bb6SDmitry Kozlyuk eir, RTE_UINT64);
776ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cbs =
77730ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
77830ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
779c2341bb6SDmitry Kozlyuk cbs, RTE_UINT64);
780ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_ebs =
78130ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
78230ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
783c2341bb6SDmitry Kozlyuk ebs, RTE_UINT64);
784ea0774ffSDavid Marchand static cmdline_parse_token_num_t
785c5a3860fSLi Zhang cmd_add_port_meter_profile_trtcm_rfc4115_packet_mode =
786c5a3860fSLi Zhang TOKEN_NUM_INITIALIZER(
787c5a3860fSLi Zhang struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
788c5a3860fSLi Zhang packet_mode, RTE_UINT32);
78930ffb4e6SCristian Dumitrescu
cmd_add_port_meter_profile_trtcm_rfc4115_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)79030ffb4e6SCristian Dumitrescu static void cmd_add_port_meter_profile_trtcm_rfc4115_parsed(
79130ffb4e6SCristian Dumitrescu void *parsed_result,
792f2fc83b4SThomas Monjalon __rte_unused struct cmdline *cl,
793f2fc83b4SThomas Monjalon __rte_unused void *data)
79430ffb4e6SCristian Dumitrescu {
79530ffb4e6SCristian Dumitrescu struct cmd_add_port_meter_profile_trtcm_rfc4115_result *res =
79630ffb4e6SCristian Dumitrescu parsed_result;
79730ffb4e6SCristian Dumitrescu struct rte_mtr_meter_profile mp;
79830ffb4e6SCristian Dumitrescu struct rte_mtr_error error;
79930ffb4e6SCristian Dumitrescu uint32_t profile_id = res->profile_id;
80030ffb4e6SCristian Dumitrescu uint16_t port_id = res->port_id;
80130ffb4e6SCristian Dumitrescu int ret;
80230ffb4e6SCristian Dumitrescu
80330ffb4e6SCristian Dumitrescu if (port_id_is_invalid(port_id, ENABLED_WARN))
80430ffb4e6SCristian Dumitrescu return;
80530ffb4e6SCristian Dumitrescu
80630ffb4e6SCristian Dumitrescu /* Private shaper profile params */
80730ffb4e6SCristian Dumitrescu memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
808e63b5016SJasvinder Singh mp.alg = RTE_MTR_TRTCM_RFC4115;
80930ffb4e6SCristian Dumitrescu mp.trtcm_rfc4115.cir = res->cir;
81030ffb4e6SCristian Dumitrescu mp.trtcm_rfc4115.eir = res->eir;
81130ffb4e6SCristian Dumitrescu mp.trtcm_rfc4115.cbs = res->cbs;
81230ffb4e6SCristian Dumitrescu mp.trtcm_rfc4115.ebs = res->ebs;
813c5a3860fSLi Zhang mp.packet_mode = res->packet_mode;
81430ffb4e6SCristian Dumitrescu
81530ffb4e6SCristian Dumitrescu ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
81630ffb4e6SCristian Dumitrescu if (ret != 0) {
81730ffb4e6SCristian Dumitrescu print_err_msg(&error);
81830ffb4e6SCristian Dumitrescu return;
81930ffb4e6SCristian Dumitrescu }
82030ffb4e6SCristian Dumitrescu }
82130ffb4e6SCristian Dumitrescu
82230ffb4e6SCristian Dumitrescu cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm_rfc4115 = {
82330ffb4e6SCristian Dumitrescu .f = cmd_add_port_meter_profile_trtcm_rfc4115_parsed,
82430ffb4e6SCristian Dumitrescu .data = NULL,
825c5a3860fSLi Zhang .help_str = "add port meter profile trtcm_rfc4115 <port_id> <profile_id> <cir> <eir> <cbs> <ebs> <packet_mode>",
82630ffb4e6SCristian Dumitrescu .tokens = {
82730ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_add,
82830ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port,
82930ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_meter,
83030ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile,
831a0f367ebSJasvinder Singh (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115,
83230ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port_id,
83330ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile_id,
83430ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cir,
83530ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_eir,
83630ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cbs,
83730ffb4e6SCristian Dumitrescu (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_ebs,
838c5a3860fSLi Zhang (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_packet_mode,
83930ffb4e6SCristian Dumitrescu NULL,
84030ffb4e6SCristian Dumitrescu },
84130ffb4e6SCristian Dumitrescu };
84230ffb4e6SCristian Dumitrescu
84330ffb4e6SCristian Dumitrescu /* *** Delete Port Meter Profile *** */
84430ffb4e6SCristian Dumitrescu struct cmd_del_port_meter_profile_result {
84530ffb4e6SCristian Dumitrescu cmdline_fixed_string_t del;
84630ffb4e6SCristian Dumitrescu cmdline_fixed_string_t port;
84730ffb4e6SCristian Dumitrescu cmdline_fixed_string_t meter;
84830ffb4e6SCristian Dumitrescu cmdline_fixed_string_t profile;
84930ffb4e6SCristian Dumitrescu uint16_t port_id;
85030ffb4e6SCristian Dumitrescu uint32_t profile_id;
85130ffb4e6SCristian Dumitrescu };
85230ffb4e6SCristian Dumitrescu
853ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_del_port_meter_profile_del =
85430ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
85530ffb4e6SCristian Dumitrescu struct cmd_del_port_meter_profile_result, del, "del");
856ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_del_port_meter_profile_port =
85730ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
85830ffb4e6SCristian Dumitrescu struct cmd_del_port_meter_profile_result,
85930ffb4e6SCristian Dumitrescu port, "port");
860ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_del_port_meter_profile_meter =
86130ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
86230ffb4e6SCristian Dumitrescu struct cmd_del_port_meter_profile_result,
86330ffb4e6SCristian Dumitrescu meter, "meter");
864ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_del_port_meter_profile_profile =
86530ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
86630ffb4e6SCristian Dumitrescu struct cmd_del_port_meter_profile_result,
86730ffb4e6SCristian Dumitrescu profile, "profile");
868ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_del_port_meter_profile_port_id =
86930ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
87030ffb4e6SCristian Dumitrescu struct cmd_del_port_meter_profile_result,
871c2341bb6SDmitry Kozlyuk port_id, RTE_UINT16);
872ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_del_port_meter_profile_profile_id =
87330ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
87430ffb4e6SCristian Dumitrescu struct cmd_del_port_meter_profile_result,
875c2341bb6SDmitry Kozlyuk profile_id, RTE_UINT32);
87630ffb4e6SCristian Dumitrescu
cmd_del_port_meter_profile_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)87730ffb4e6SCristian Dumitrescu static void cmd_del_port_meter_profile_parsed(void *parsed_result,
878f2fc83b4SThomas Monjalon __rte_unused struct cmdline *cl,
879f2fc83b4SThomas Monjalon __rte_unused void *data)
88030ffb4e6SCristian Dumitrescu {
88130ffb4e6SCristian Dumitrescu struct cmd_del_port_meter_profile_result *res = parsed_result;
88230ffb4e6SCristian Dumitrescu struct rte_mtr_error error;
88330ffb4e6SCristian Dumitrescu uint32_t profile_id = res->profile_id;
88430ffb4e6SCristian Dumitrescu uint16_t port_id = res->port_id;
88530ffb4e6SCristian Dumitrescu int ret;
88630ffb4e6SCristian Dumitrescu
88730ffb4e6SCristian Dumitrescu if (port_id_is_invalid(port_id, ENABLED_WARN))
88830ffb4e6SCristian Dumitrescu return;
88930ffb4e6SCristian Dumitrescu
89030ffb4e6SCristian Dumitrescu /* Delete meter profile */
89130ffb4e6SCristian Dumitrescu ret = rte_mtr_meter_profile_delete(port_id, profile_id, &error);
89230ffb4e6SCristian Dumitrescu if (ret != 0) {
89330ffb4e6SCristian Dumitrescu print_err_msg(&error);
89430ffb4e6SCristian Dumitrescu return;
89530ffb4e6SCristian Dumitrescu }
89630ffb4e6SCristian Dumitrescu }
89730ffb4e6SCristian Dumitrescu
89830ffb4e6SCristian Dumitrescu cmdline_parse_inst_t cmd_del_port_meter_profile = {
89930ffb4e6SCristian Dumitrescu .f = cmd_del_port_meter_profile_parsed,
90030ffb4e6SCristian Dumitrescu .data = NULL,
901618f0f4aSFerruh Yigit .help_str = "del port meter profile <port_id> <profile_id>",
90230ffb4e6SCristian Dumitrescu .tokens = {
90330ffb4e6SCristian Dumitrescu (void *)&cmd_del_port_meter_profile_del,
90430ffb4e6SCristian Dumitrescu (void *)&cmd_del_port_meter_profile_port,
90530ffb4e6SCristian Dumitrescu (void *)&cmd_del_port_meter_profile_meter,
90630ffb4e6SCristian Dumitrescu (void *)&cmd_del_port_meter_profile_profile,
90730ffb4e6SCristian Dumitrescu (void *)&cmd_del_port_meter_profile_port_id,
90830ffb4e6SCristian Dumitrescu (void *)&cmd_del_port_meter_profile_profile_id,
90930ffb4e6SCristian Dumitrescu NULL,
91030ffb4e6SCristian Dumitrescu },
91130ffb4e6SCristian Dumitrescu };
91230ffb4e6SCristian Dumitrescu
91330ffb4e6SCristian Dumitrescu /* *** Create Port Meter Object *** */
914e63b5016SJasvinder Singh struct cmd_create_port_meter_result {
915e63b5016SJasvinder Singh cmdline_fixed_string_t create;
91630ffb4e6SCristian Dumitrescu cmdline_fixed_string_t port;
91730ffb4e6SCristian Dumitrescu cmdline_fixed_string_t meter;
91830ffb4e6SCristian Dumitrescu uint16_t port_id;
91930ffb4e6SCristian Dumitrescu uint32_t mtr_id;
92030ffb4e6SCristian Dumitrescu uint32_t profile_id;
921f29fa2c5SHaifei Luo uint32_t policy_id;
922e63b5016SJasvinder Singh cmdline_fixed_string_t meter_enable;
92330ffb4e6SCristian Dumitrescu cmdline_fixed_string_t g_action;
92430ffb4e6SCristian Dumitrescu cmdline_fixed_string_t y_action;
92530ffb4e6SCristian Dumitrescu cmdline_fixed_string_t r_action;
92630ffb4e6SCristian Dumitrescu uint64_t statistics_mask;
92730ffb4e6SCristian Dumitrescu uint32_t shared;
9289f5488e3SSunil Kumar Kori cmdline_fixed_string_t default_input_color;
929e63b5016SJasvinder Singh cmdline_multi_string_t meter_input_color;
93030ffb4e6SCristian Dumitrescu };
93130ffb4e6SCristian Dumitrescu
932ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_create_port_meter_create =
93330ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
934e63b5016SJasvinder Singh struct cmd_create_port_meter_result, create, "create");
935ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_create_port_meter_port =
93630ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
937e63b5016SJasvinder Singh struct cmd_create_port_meter_result, port, "port");
938ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_create_port_meter_meter =
93930ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
940e63b5016SJasvinder Singh struct cmd_create_port_meter_result, meter, "meter");
941ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_create_port_meter_port_id =
94230ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
943c2341bb6SDmitry Kozlyuk struct cmd_create_port_meter_result, port_id, RTE_UINT16);
944ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_create_port_meter_mtr_id =
94530ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
946c2341bb6SDmitry Kozlyuk struct cmd_create_port_meter_result, mtr_id, RTE_UINT32);
947ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_create_port_meter_profile_id =
94830ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
949c2341bb6SDmitry Kozlyuk struct cmd_create_port_meter_result, profile_id, RTE_UINT32);
950ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_create_port_meter_policy_id =
951f29fa2c5SHaifei Luo TOKEN_NUM_INITIALIZER(
952f29fa2c5SHaifei Luo struct cmd_create_port_meter_result, policy_id, RTE_UINT32);
953ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_create_port_meter_meter_enable =
954e63b5016SJasvinder Singh TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
955e63b5016SJasvinder Singh meter_enable, "yes#no");
956ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_create_port_meter_statistics_mask =
957e63b5016SJasvinder Singh TOKEN_NUM_INITIALIZER(struct cmd_create_port_meter_result,
958c2341bb6SDmitry Kozlyuk statistics_mask, RTE_UINT64);
959ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_create_port_meter_shared =
960e63b5016SJasvinder Singh TOKEN_NUM_INITIALIZER(struct cmd_create_port_meter_result,
961c2341bb6SDmitry Kozlyuk shared, RTE_UINT32);
9629f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_create_port_meter_default_input_color =
9639f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
9649f5488e3SSunil Kumar Kori default_input_color, "R#Y#G#r#y#g");
965ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_create_port_meter_input_color =
966e63b5016SJasvinder Singh TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
967e63b5016SJasvinder Singh meter_input_color, TOKEN_STRING_MULTI);
96830ffb4e6SCristian Dumitrescu
cmd_create_port_meter_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)969e63b5016SJasvinder Singh static void cmd_create_port_meter_parsed(void *parsed_result,
970f2fc83b4SThomas Monjalon __rte_unused struct cmdline *cl,
971f2fc83b4SThomas Monjalon __rte_unused void *data)
97230ffb4e6SCristian Dumitrescu {
973e63b5016SJasvinder Singh struct cmd_create_port_meter_result *res = parsed_result;
97430ffb4e6SCristian Dumitrescu struct rte_mtr_error error;
97530ffb4e6SCristian Dumitrescu struct rte_mtr_params params;
97630ffb4e6SCristian Dumitrescu uint32_t mtr_id = res->mtr_id;
97730ffb4e6SCristian Dumitrescu uint32_t shared = res->shared;
978e63b5016SJasvinder Singh uint32_t use_prev_meter_color = 0;
97930ffb4e6SCristian Dumitrescu uint16_t port_id = res->port_id;
9809f5488e3SSunil Kumar Kori uint64_t def_inp_color = 0;
981c1656328SJasvinder Singh enum rte_color *dscp_table = NULL;
9829f5488e3SSunil Kumar Kori enum rte_color *vlan_table = NULL;
9839f5488e3SSunil Kumar Kori char *def_color_str = res->default_input_color;
984e63b5016SJasvinder Singh char *c_str = res->meter_input_color;
98530ffb4e6SCristian Dumitrescu int ret;
98630ffb4e6SCristian Dumitrescu
98730ffb4e6SCristian Dumitrescu if (port_id_is_invalid(port_id, ENABLED_WARN))
98830ffb4e6SCristian Dumitrescu return;
98930ffb4e6SCristian Dumitrescu
99030ffb4e6SCristian Dumitrescu /* Meter params */
99130ffb4e6SCristian Dumitrescu memset(¶ms, 0, sizeof(struct rte_mtr_params));
99230ffb4e6SCristian Dumitrescu params.meter_profile_id = res->profile_id;
993f29fa2c5SHaifei Luo params.meter_policy_id = res->policy_id;
9949f5488e3SSunil Kumar Kori
9959f5488e3SSunil Kumar Kori /* Parse meter default input color string params */
9969f5488e3SSunil Kumar Kori ret = parse_default_input_color_str(def_color_str, &def_inp_color);
9979f5488e3SSunil Kumar Kori if (ret) {
9989f5488e3SSunil Kumar Kori fprintf(stderr,
9999f5488e3SSunil Kumar Kori " Meter default input color is invalid\n");
10009f5488e3SSunil Kumar Kori return;
10019f5488e3SSunil Kumar Kori }
10029f5488e3SSunil Kumar Kori
1003e63b5016SJasvinder Singh /* Parse meter input color string params */
10049f5488e3SSunil Kumar Kori ret = parse_meter_color_str(c_str, &use_prev_meter_color, &vlan_table,
10059f5488e3SSunil Kumar Kori &dscp_table);
1006e63b5016SJasvinder Singh if (ret) {
100761a3b0e5SAndrew Rybchenko fprintf(stderr,
100861a3b0e5SAndrew Rybchenko " Meter input color params string parse error\n");
1009e63b5016SJasvinder Singh return;
1010e63b5016SJasvinder Singh }
1011e63b5016SJasvinder Singh
1012e63b5016SJasvinder Singh params.use_prev_mtr_color = use_prev_meter_color;
10139f5488e3SSunil Kumar Kori params.vlan_table = vlan_table;
1014e63b5016SJasvinder Singh params.dscp_table = dscp_table;
10159f5488e3SSunil Kumar Kori params.default_input_color = def_inp_color;
1016e63b5016SJasvinder Singh
1017e63b5016SJasvinder Singh if (strcmp(res->meter_enable, "yes") == 0)
101830ffb4e6SCristian Dumitrescu params.meter_enable = 1;
1019e63b5016SJasvinder Singh else
1020e63b5016SJasvinder Singh params.meter_enable = 0;
10219f5488e3SSunil Kumar Kori
102230ffb4e6SCristian Dumitrescu params.stats_mask = res->statistics_mask;
102330ffb4e6SCristian Dumitrescu
102430ffb4e6SCristian Dumitrescu ret = rte_mtr_create(port_id, mtr_id, ¶ms, shared, &error);
102530ffb4e6SCristian Dumitrescu if (ret != 0) {
10269f5488e3SSunil Kumar Kori free(vlan_table);
1027e63b5016SJasvinder Singh free(dscp_table);
102830ffb4e6SCristian Dumitrescu print_err_msg(&error);
102930ffb4e6SCristian Dumitrescu return;
103030ffb4e6SCristian Dumitrescu }
103130ffb4e6SCristian Dumitrescu }
103230ffb4e6SCristian Dumitrescu
1033e63b5016SJasvinder Singh cmdline_parse_inst_t cmd_create_port_meter = {
1034e63b5016SJasvinder Singh .f = cmd_create_port_meter_parsed,
103530ffb4e6SCristian Dumitrescu .data = NULL,
1036dfffd090SJin Liu .help_str = "create port meter <port_id> <mtr_id> <profile_id> <policy_id> "
10379f5488e3SSunil Kumar Kori "<meter_enable>(yes|no) <stats_mask> <shared> "
10389f5488e3SSunil Kumar Kori "<default_input_color>(g|y|r) <use_pre_meter_color> "
10399f5488e3SSunil Kumar Kori "[<dscp_tbl_entry0> <dscp_tbl_entry1> ...<dscp_tbl_entry63>] "
10409f5488e3SSunil Kumar Kori "[<vlan_tbl_entry0> <vlan_tbl_entry1> ... <vlan_tbl_entry15>]",
104130ffb4e6SCristian Dumitrescu .tokens = {
1042e63b5016SJasvinder Singh (void *)&cmd_create_port_meter_create,
1043e63b5016SJasvinder Singh (void *)&cmd_create_port_meter_port,
1044e63b5016SJasvinder Singh (void *)&cmd_create_port_meter_meter,
1045e63b5016SJasvinder Singh (void *)&cmd_create_port_meter_port_id,
1046e63b5016SJasvinder Singh (void *)&cmd_create_port_meter_mtr_id,
1047e63b5016SJasvinder Singh (void *)&cmd_create_port_meter_profile_id,
1048f29fa2c5SHaifei Luo (void *)&cmd_create_port_meter_policy_id,
1049e63b5016SJasvinder Singh (void *)&cmd_create_port_meter_meter_enable,
1050e63b5016SJasvinder Singh (void *)&cmd_create_port_meter_statistics_mask,
1051e63b5016SJasvinder Singh (void *)&cmd_create_port_meter_shared,
10529f5488e3SSunil Kumar Kori (void *)&cmd_create_port_meter_default_input_color,
1053e63b5016SJasvinder Singh (void *)&cmd_create_port_meter_input_color,
105430ffb4e6SCristian Dumitrescu NULL,
105530ffb4e6SCristian Dumitrescu },
105630ffb4e6SCristian Dumitrescu };
105730ffb4e6SCristian Dumitrescu
1058281eeb8aSJasvinder Singh /* *** Enable Meter of MTR Object *** */
1059281eeb8aSJasvinder Singh struct cmd_enable_port_meter_result {
1060281eeb8aSJasvinder Singh cmdline_fixed_string_t enable;
1061281eeb8aSJasvinder Singh cmdline_fixed_string_t port;
1062281eeb8aSJasvinder Singh cmdline_fixed_string_t meter;
1063281eeb8aSJasvinder Singh uint16_t port_id;
1064281eeb8aSJasvinder Singh uint32_t mtr_id;
1065281eeb8aSJasvinder Singh };
1066281eeb8aSJasvinder Singh
1067ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_enable_port_meter_enable =
1068281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(
1069281eeb8aSJasvinder Singh struct cmd_enable_port_meter_result, enable, "enable");
1070ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_enable_port_meter_port =
1071281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(
1072281eeb8aSJasvinder Singh struct cmd_enable_port_meter_result, port, "port");
1073ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_enable_port_meter_meter =
1074281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(
1075281eeb8aSJasvinder Singh struct cmd_enable_port_meter_result, meter, "meter");
1076ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_enable_port_meter_port_id =
1077281eeb8aSJasvinder Singh TOKEN_NUM_INITIALIZER(
1078c2341bb6SDmitry Kozlyuk struct cmd_enable_port_meter_result, port_id, RTE_UINT16);
1079ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_enable_port_meter_mtr_id =
1080281eeb8aSJasvinder Singh TOKEN_NUM_INITIALIZER(
1081c2341bb6SDmitry Kozlyuk struct cmd_enable_port_meter_result, mtr_id, RTE_UINT32);
1082281eeb8aSJasvinder Singh
cmd_enable_port_meter_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)1083281eeb8aSJasvinder Singh static void cmd_enable_port_meter_parsed(void *parsed_result,
1084f2fc83b4SThomas Monjalon __rte_unused struct cmdline *cl,
1085f2fc83b4SThomas Monjalon __rte_unused void *data)
1086281eeb8aSJasvinder Singh {
1087281eeb8aSJasvinder Singh struct cmd_enable_port_meter_result *res = parsed_result;
1088281eeb8aSJasvinder Singh struct rte_mtr_error error;
1089281eeb8aSJasvinder Singh uint32_t mtr_id = res->mtr_id;
1090281eeb8aSJasvinder Singh uint16_t port_id = res->port_id;
1091281eeb8aSJasvinder Singh
1092281eeb8aSJasvinder Singh int ret;
1093281eeb8aSJasvinder Singh
1094281eeb8aSJasvinder Singh if (port_id_is_invalid(port_id, ENABLED_WARN))
1095281eeb8aSJasvinder Singh return;
1096281eeb8aSJasvinder Singh
1097281eeb8aSJasvinder Singh /* Enable Meter */
1098281eeb8aSJasvinder Singh ret = rte_mtr_meter_enable(port_id, mtr_id, &error);
1099281eeb8aSJasvinder Singh if (ret != 0) {
1100281eeb8aSJasvinder Singh print_err_msg(&error);
1101281eeb8aSJasvinder Singh return;
1102281eeb8aSJasvinder Singh }
1103281eeb8aSJasvinder Singh }
1104281eeb8aSJasvinder Singh
1105281eeb8aSJasvinder Singh cmdline_parse_inst_t cmd_enable_port_meter = {
1106281eeb8aSJasvinder Singh .f = cmd_enable_port_meter_parsed,
1107281eeb8aSJasvinder Singh .data = NULL,
1108618f0f4aSFerruh Yigit .help_str = "enable port meter <port_id> <mtr_id>",
1109281eeb8aSJasvinder Singh .tokens = {
1110281eeb8aSJasvinder Singh (void *)&cmd_enable_port_meter_enable,
1111281eeb8aSJasvinder Singh (void *)&cmd_enable_port_meter_port,
1112281eeb8aSJasvinder Singh (void *)&cmd_enable_port_meter_meter,
1113281eeb8aSJasvinder Singh (void *)&cmd_enable_port_meter_port_id,
1114281eeb8aSJasvinder Singh (void *)&cmd_enable_port_meter_mtr_id,
1115281eeb8aSJasvinder Singh NULL,
1116281eeb8aSJasvinder Singh },
1117281eeb8aSJasvinder Singh };
1118281eeb8aSJasvinder Singh
1119281eeb8aSJasvinder Singh /* *** Disable Meter of MTR Object *** */
1120281eeb8aSJasvinder Singh struct cmd_disable_port_meter_result {
1121281eeb8aSJasvinder Singh cmdline_fixed_string_t disable;
1122281eeb8aSJasvinder Singh cmdline_fixed_string_t port;
1123281eeb8aSJasvinder Singh cmdline_fixed_string_t meter;
1124281eeb8aSJasvinder Singh uint16_t port_id;
1125281eeb8aSJasvinder Singh uint32_t mtr_id;
1126281eeb8aSJasvinder Singh };
1127281eeb8aSJasvinder Singh
1128ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_disable_port_meter_disable =
1129281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(
1130281eeb8aSJasvinder Singh struct cmd_disable_port_meter_result, disable, "disable");
1131ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_disable_port_meter_port =
1132281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(
1133281eeb8aSJasvinder Singh struct cmd_disable_port_meter_result, port, "port");
1134ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_disable_port_meter_meter =
1135281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(
1136281eeb8aSJasvinder Singh struct cmd_disable_port_meter_result, meter, "meter");
1137ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_disable_port_meter_port_id =
1138281eeb8aSJasvinder Singh TOKEN_NUM_INITIALIZER(
1139c2341bb6SDmitry Kozlyuk struct cmd_disable_port_meter_result, port_id, RTE_UINT16);
1140ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_disable_port_meter_mtr_id =
1141281eeb8aSJasvinder Singh TOKEN_NUM_INITIALIZER(
1142c2341bb6SDmitry Kozlyuk struct cmd_disable_port_meter_result, mtr_id, RTE_UINT32);
1143281eeb8aSJasvinder Singh
cmd_disable_port_meter_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)1144281eeb8aSJasvinder Singh static void cmd_disable_port_meter_parsed(void *parsed_result,
1145f2fc83b4SThomas Monjalon __rte_unused struct cmdline *cl,
1146f2fc83b4SThomas Monjalon __rte_unused void *data)
1147281eeb8aSJasvinder Singh {
1148281eeb8aSJasvinder Singh struct cmd_disable_port_meter_result *res = parsed_result;
1149281eeb8aSJasvinder Singh struct rte_mtr_error error;
1150281eeb8aSJasvinder Singh uint32_t mtr_id = res->mtr_id;
1151281eeb8aSJasvinder Singh uint16_t port_id = res->port_id;
1152281eeb8aSJasvinder Singh
1153281eeb8aSJasvinder Singh int ret;
1154281eeb8aSJasvinder Singh
1155281eeb8aSJasvinder Singh if (port_id_is_invalid(port_id, ENABLED_WARN))
1156281eeb8aSJasvinder Singh return;
1157281eeb8aSJasvinder Singh
1158281eeb8aSJasvinder Singh /* Disable Meter */
1159281eeb8aSJasvinder Singh ret = rte_mtr_meter_disable(port_id, mtr_id, &error);
1160281eeb8aSJasvinder Singh if (ret != 0) {
1161281eeb8aSJasvinder Singh print_err_msg(&error);
1162281eeb8aSJasvinder Singh return;
1163281eeb8aSJasvinder Singh }
1164281eeb8aSJasvinder Singh }
1165281eeb8aSJasvinder Singh
1166281eeb8aSJasvinder Singh cmdline_parse_inst_t cmd_disable_port_meter = {
1167281eeb8aSJasvinder Singh .f = cmd_disable_port_meter_parsed,
1168281eeb8aSJasvinder Singh .data = NULL,
1169618f0f4aSFerruh Yigit .help_str = "disable port meter <port_id> <mtr_id>",
1170281eeb8aSJasvinder Singh .tokens = {
1171281eeb8aSJasvinder Singh (void *)&cmd_disable_port_meter_disable,
1172281eeb8aSJasvinder Singh (void *)&cmd_disable_port_meter_port,
1173281eeb8aSJasvinder Singh (void *)&cmd_disable_port_meter_meter,
1174281eeb8aSJasvinder Singh (void *)&cmd_disable_port_meter_port_id,
1175281eeb8aSJasvinder Singh (void *)&cmd_disable_port_meter_mtr_id,
1176281eeb8aSJasvinder Singh NULL,
1177281eeb8aSJasvinder Singh },
1178281eeb8aSJasvinder Singh };
1179281eeb8aSJasvinder Singh
1180f29fa2c5SHaifei Luo /* *** Delete Port Meter Policy Object *** */
1181f29fa2c5SHaifei Luo struct cmd_del_port_meter_policy_result {
1182f29fa2c5SHaifei Luo cmdline_fixed_string_t del;
1183f29fa2c5SHaifei Luo cmdline_fixed_string_t port;
1184f29fa2c5SHaifei Luo cmdline_fixed_string_t meter;
1185f29fa2c5SHaifei Luo cmdline_fixed_string_t policy;
1186f29fa2c5SHaifei Luo uint16_t port_id;
1187f29fa2c5SHaifei Luo uint32_t policy_id;
1188f29fa2c5SHaifei Luo };
1189f29fa2c5SHaifei Luo
1190ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_del_port_meter_policy_del =
1191f29fa2c5SHaifei Luo TOKEN_STRING_INITIALIZER(
1192f29fa2c5SHaifei Luo struct cmd_del_port_meter_policy_result, del, "del");
1193ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_del_port_meter_policy_port =
1194f29fa2c5SHaifei Luo TOKEN_STRING_INITIALIZER(
1195f29fa2c5SHaifei Luo struct cmd_del_port_meter_policy_result, port, "port");
1196ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_del_port_meter_policy_meter =
1197f29fa2c5SHaifei Luo TOKEN_STRING_INITIALIZER(
1198f29fa2c5SHaifei Luo struct cmd_del_port_meter_policy_result, meter, "meter");
1199ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_del_port_meter_policy_policy =
1200f29fa2c5SHaifei Luo TOKEN_STRING_INITIALIZER(
1201f29fa2c5SHaifei Luo struct cmd_del_port_meter_policy_result, policy, "policy");
1202ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_del_port_meter_policy_port_id =
1203f29fa2c5SHaifei Luo TOKEN_NUM_INITIALIZER(
1204f29fa2c5SHaifei Luo struct cmd_del_port_meter_policy_result, port_id, RTE_UINT16);
1205ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_del_port_meter_policy_policy_id =
1206f29fa2c5SHaifei Luo TOKEN_NUM_INITIALIZER(
1207f29fa2c5SHaifei Luo struct cmd_del_port_meter_policy_result, policy_id, RTE_UINT32);
1208f29fa2c5SHaifei Luo
cmd_del_port_meter_policy_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)1209f29fa2c5SHaifei Luo static void cmd_del_port_meter_policy_parsed(void *parsed_result,
1210f29fa2c5SHaifei Luo __rte_unused struct cmdline *cl,
1211f29fa2c5SHaifei Luo __rte_unused void *data)
1212f29fa2c5SHaifei Luo {
1213f29fa2c5SHaifei Luo struct cmd_del_port_meter_policy_result *res = parsed_result;
1214f29fa2c5SHaifei Luo struct rte_mtr_error error;
1215f29fa2c5SHaifei Luo uint32_t policy_id = res->policy_id;
1216f29fa2c5SHaifei Luo uint16_t port_id = res->port_id;
1217f29fa2c5SHaifei Luo int ret;
1218f29fa2c5SHaifei Luo
1219f29fa2c5SHaifei Luo if (port_id_is_invalid(port_id, ENABLED_WARN))
1220f29fa2c5SHaifei Luo return;
1221f29fa2c5SHaifei Luo
1222f29fa2c5SHaifei Luo /* Delete Meter Policy*/
1223f29fa2c5SHaifei Luo ret = rte_mtr_meter_policy_delete(port_id, policy_id, &error);
1224f29fa2c5SHaifei Luo if (ret != 0) {
1225f29fa2c5SHaifei Luo print_err_msg(&error);
1226f29fa2c5SHaifei Luo return;
1227f29fa2c5SHaifei Luo }
1228f29fa2c5SHaifei Luo }
1229f29fa2c5SHaifei Luo
1230f29fa2c5SHaifei Luo cmdline_parse_inst_t cmd_del_port_meter_policy = {
1231f29fa2c5SHaifei Luo .f = cmd_del_port_meter_policy_parsed,
1232f29fa2c5SHaifei Luo .data = NULL,
1233f29fa2c5SHaifei Luo .help_str = "Delete port meter policy",
1234f29fa2c5SHaifei Luo .tokens = {
1235f29fa2c5SHaifei Luo (void *)&cmd_del_port_meter_policy_del,
1236f29fa2c5SHaifei Luo (void *)&cmd_del_port_meter_policy_port,
1237f29fa2c5SHaifei Luo (void *)&cmd_del_port_meter_policy_meter,
1238f29fa2c5SHaifei Luo (void *)&cmd_del_port_meter_policy_policy,
1239f29fa2c5SHaifei Luo (void *)&cmd_del_port_meter_policy_port_id,
1240f29fa2c5SHaifei Luo (void *)&cmd_del_port_meter_policy_policy_id,
1241f29fa2c5SHaifei Luo NULL,
1242f29fa2c5SHaifei Luo },
1243f29fa2c5SHaifei Luo };
1244f29fa2c5SHaifei Luo
124530ffb4e6SCristian Dumitrescu /* *** Delete Port Meter Object *** */
124630ffb4e6SCristian Dumitrescu struct cmd_del_port_meter_result {
124730ffb4e6SCristian Dumitrescu cmdline_fixed_string_t del;
124830ffb4e6SCristian Dumitrescu cmdline_fixed_string_t port;
124930ffb4e6SCristian Dumitrescu cmdline_fixed_string_t meter;
125030ffb4e6SCristian Dumitrescu uint16_t port_id;
125130ffb4e6SCristian Dumitrescu uint32_t mtr_id;
125230ffb4e6SCristian Dumitrescu };
125330ffb4e6SCristian Dumitrescu
1254ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_del_port_meter_del =
125530ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
125630ffb4e6SCristian Dumitrescu struct cmd_del_port_meter_result, del, "del");
1257ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_del_port_meter_port =
125830ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
125930ffb4e6SCristian Dumitrescu struct cmd_del_port_meter_result, port, "port");
1260ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_del_port_meter_meter =
126130ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
126230ffb4e6SCristian Dumitrescu struct cmd_del_port_meter_result, meter, "meter");
1263ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_del_port_meter_port_id =
126430ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
1265c2341bb6SDmitry Kozlyuk struct cmd_del_port_meter_result, port_id, RTE_UINT16);
1266ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_del_port_meter_mtr_id =
126730ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
1268c2341bb6SDmitry Kozlyuk struct cmd_del_port_meter_result, mtr_id, RTE_UINT32);
126930ffb4e6SCristian Dumitrescu
cmd_del_port_meter_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)127030ffb4e6SCristian Dumitrescu static void cmd_del_port_meter_parsed(void *parsed_result,
1271f2fc83b4SThomas Monjalon __rte_unused struct cmdline *cl,
1272f2fc83b4SThomas Monjalon __rte_unused void *data)
127330ffb4e6SCristian Dumitrescu {
127430ffb4e6SCristian Dumitrescu struct cmd_del_port_meter_result *res = parsed_result;
127530ffb4e6SCristian Dumitrescu struct rte_mtr_error error;
127630ffb4e6SCristian Dumitrescu uint32_t mtr_id = res->mtr_id;
127730ffb4e6SCristian Dumitrescu uint16_t port_id = res->port_id;
127830ffb4e6SCristian Dumitrescu
127930ffb4e6SCristian Dumitrescu int ret;
128030ffb4e6SCristian Dumitrescu
128130ffb4e6SCristian Dumitrescu if (port_id_is_invalid(port_id, ENABLED_WARN))
128230ffb4e6SCristian Dumitrescu return;
128330ffb4e6SCristian Dumitrescu
128430ffb4e6SCristian Dumitrescu /* Destroy Meter */
128530ffb4e6SCristian Dumitrescu ret = rte_mtr_destroy(port_id, mtr_id, &error);
128630ffb4e6SCristian Dumitrescu if (ret != 0) {
128730ffb4e6SCristian Dumitrescu print_err_msg(&error);
128830ffb4e6SCristian Dumitrescu return;
128930ffb4e6SCristian Dumitrescu }
129030ffb4e6SCristian Dumitrescu }
129130ffb4e6SCristian Dumitrescu
129230ffb4e6SCristian Dumitrescu cmdline_parse_inst_t cmd_del_port_meter = {
129330ffb4e6SCristian Dumitrescu .f = cmd_del_port_meter_parsed,
129430ffb4e6SCristian Dumitrescu .data = NULL,
1295618f0f4aSFerruh Yigit .help_str = "del port meter <port_id> <mtr_id>",
129630ffb4e6SCristian Dumitrescu .tokens = {
129730ffb4e6SCristian Dumitrescu (void *)&cmd_del_port_meter_del,
129830ffb4e6SCristian Dumitrescu (void *)&cmd_del_port_meter_port,
129930ffb4e6SCristian Dumitrescu (void *)&cmd_del_port_meter_meter,
130030ffb4e6SCristian Dumitrescu (void *)&cmd_del_port_meter_port_id,
130130ffb4e6SCristian Dumitrescu (void *)&cmd_del_port_meter_mtr_id,
130230ffb4e6SCristian Dumitrescu NULL,
130330ffb4e6SCristian Dumitrescu },
130430ffb4e6SCristian Dumitrescu };
130530ffb4e6SCristian Dumitrescu
130630ffb4e6SCristian Dumitrescu /* *** Set Port Meter Profile *** */
130730ffb4e6SCristian Dumitrescu struct cmd_set_port_meter_profile_result {
130830ffb4e6SCristian Dumitrescu cmdline_fixed_string_t set;
130930ffb4e6SCristian Dumitrescu cmdline_fixed_string_t port;
131030ffb4e6SCristian Dumitrescu cmdline_fixed_string_t meter;
131130ffb4e6SCristian Dumitrescu cmdline_fixed_string_t profile;
131230ffb4e6SCristian Dumitrescu uint16_t port_id;
131330ffb4e6SCristian Dumitrescu uint32_t mtr_id;
131430ffb4e6SCristian Dumitrescu uint32_t profile_id;
131530ffb4e6SCristian Dumitrescu };
131630ffb4e6SCristian Dumitrescu
1317ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_set_port_meter_profile_set =
131830ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
131930ffb4e6SCristian Dumitrescu struct cmd_set_port_meter_profile_result, set, "set");
1320ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_set_port_meter_profile_port =
132130ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
132230ffb4e6SCristian Dumitrescu struct cmd_set_port_meter_profile_result, port, "port");
1323ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_set_port_meter_profile_meter =
132430ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
132530ffb4e6SCristian Dumitrescu struct cmd_set_port_meter_profile_result, meter, "meter");
1326ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_set_port_meter_profile_profile =
132730ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
132830ffb4e6SCristian Dumitrescu struct cmd_set_port_meter_profile_result, profile, "profile");
1329ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_set_port_meter_profile_port_id =
133030ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
1331c2341bb6SDmitry Kozlyuk struct cmd_set_port_meter_profile_result, port_id,
1332c2341bb6SDmitry Kozlyuk RTE_UINT16);
1333ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_set_port_meter_profile_mtr_id =
133430ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
1335c2341bb6SDmitry Kozlyuk struct cmd_set_port_meter_profile_result, mtr_id,
1336c2341bb6SDmitry Kozlyuk RTE_UINT32);
1337ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_set_port_meter_profile_profile_id =
133830ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
1339c2341bb6SDmitry Kozlyuk struct cmd_set_port_meter_profile_result, profile_id,
1340c2341bb6SDmitry Kozlyuk RTE_UINT32);
134130ffb4e6SCristian Dumitrescu
cmd_set_port_meter_profile_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)134230ffb4e6SCristian Dumitrescu static void cmd_set_port_meter_profile_parsed(void *parsed_result,
1343f2fc83b4SThomas Monjalon __rte_unused struct cmdline *cl,
1344f2fc83b4SThomas Monjalon __rte_unused void *data)
134530ffb4e6SCristian Dumitrescu {
134630ffb4e6SCristian Dumitrescu struct cmd_set_port_meter_profile_result *res = parsed_result;
134730ffb4e6SCristian Dumitrescu struct rte_mtr_error error;
134830ffb4e6SCristian Dumitrescu uint32_t mtr_id = res->mtr_id;
134930ffb4e6SCristian Dumitrescu uint32_t profile_id = res->profile_id;
135030ffb4e6SCristian Dumitrescu uint16_t port_id = res->port_id;
135130ffb4e6SCristian Dumitrescu
135230ffb4e6SCristian Dumitrescu int ret;
135330ffb4e6SCristian Dumitrescu
135430ffb4e6SCristian Dumitrescu if (port_id_is_invalid(port_id, ENABLED_WARN))
135530ffb4e6SCristian Dumitrescu return;
135630ffb4e6SCristian Dumitrescu
135730ffb4e6SCristian Dumitrescu /* Set meter profile */
135830ffb4e6SCristian Dumitrescu ret = rte_mtr_meter_profile_update(port_id, mtr_id,
135930ffb4e6SCristian Dumitrescu profile_id, &error);
136030ffb4e6SCristian Dumitrescu if (ret != 0) {
136130ffb4e6SCristian Dumitrescu print_err_msg(&error);
136230ffb4e6SCristian Dumitrescu return;
136330ffb4e6SCristian Dumitrescu }
136430ffb4e6SCristian Dumitrescu }
136530ffb4e6SCristian Dumitrescu
136630ffb4e6SCristian Dumitrescu cmdline_parse_inst_t cmd_set_port_meter_profile = {
136730ffb4e6SCristian Dumitrescu .f = cmd_set_port_meter_profile_parsed,
136830ffb4e6SCristian Dumitrescu .data = NULL,
1369618f0f4aSFerruh Yigit .help_str = "set port meter profile <port_id> <mtr_id> <profile_id>",
137030ffb4e6SCristian Dumitrescu .tokens = {
137130ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_profile_set,
137230ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_profile_port,
137330ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_profile_meter,
137430ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_profile_profile,
137530ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_profile_port_id,
137630ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_profile_mtr_id,
137730ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_profile_profile_id,
137830ffb4e6SCristian Dumitrescu NULL,
137930ffb4e6SCristian Dumitrescu },
138030ffb4e6SCristian Dumitrescu };
138130ffb4e6SCristian Dumitrescu
1382281eeb8aSJasvinder Singh /* *** Set Port Meter DSCP Table *** */
1383281eeb8aSJasvinder Singh struct cmd_set_port_meter_dscp_table_result {
1384281eeb8aSJasvinder Singh cmdline_fixed_string_t set;
1385281eeb8aSJasvinder Singh cmdline_fixed_string_t port;
1386281eeb8aSJasvinder Singh cmdline_fixed_string_t meter;
1387281eeb8aSJasvinder Singh cmdline_fixed_string_t dscp_table;
1388281eeb8aSJasvinder Singh cmdline_multi_string_t token_string;
1389281eeb8aSJasvinder Singh };
1390281eeb8aSJasvinder Singh
1391ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_set =
1392281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(
1393281eeb8aSJasvinder Singh struct cmd_set_port_meter_dscp_table_result, set, "set");
1394ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_port =
1395281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(
1396281eeb8aSJasvinder Singh struct cmd_set_port_meter_dscp_table_result, port, "port");
1397ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_meter =
1398281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(
1399281eeb8aSJasvinder Singh struct cmd_set_port_meter_dscp_table_result, meter, "meter");
1400ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_dscp_table =
1401281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(
1402281eeb8aSJasvinder Singh struct cmd_set_port_meter_dscp_table_result,
1403281eeb8aSJasvinder Singh dscp_table, "dscp table");
1404ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_token_string =
1405281eeb8aSJasvinder Singh TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_dscp_table_result,
1406281eeb8aSJasvinder Singh token_string, TOKEN_STRING_MULTI);
1407281eeb8aSJasvinder Singh
cmd_set_port_meter_dscp_table_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)1408281eeb8aSJasvinder Singh static void cmd_set_port_meter_dscp_table_parsed(void *parsed_result,
1409f2fc83b4SThomas Monjalon __rte_unused struct cmdline *cl,
1410f2fc83b4SThomas Monjalon __rte_unused void *data)
1411281eeb8aSJasvinder Singh {
1412281eeb8aSJasvinder Singh struct cmd_set_port_meter_dscp_table_result *res = parsed_result;
1413*204daeeaSSunil Kumar Kori enum rte_mtr_color_in_protocol proto = 0;
1414281eeb8aSJasvinder Singh struct rte_mtr_error error;
1415c1656328SJasvinder Singh enum rte_color *dscp_table = NULL;
1416281eeb8aSJasvinder Singh char *t_str = res->token_string;
1417281eeb8aSJasvinder Singh uint32_t mtr_id = 0;
1418281eeb8aSJasvinder Singh uint16_t port_id;
1419281eeb8aSJasvinder Singh int ret;
1420281eeb8aSJasvinder Singh
1421281eeb8aSJasvinder Singh /* Parse string */
1422*204daeeaSSunil Kumar Kori ret = parse_multi_token_string(t_str, &port_id, &mtr_id, &proto,
1423*204daeeaSSunil Kumar Kori &dscp_table);
1424281eeb8aSJasvinder Singh if (ret) {
142561a3b0e5SAndrew Rybchenko fprintf(stderr, " Multi token string parse error\n");
1426281eeb8aSJasvinder Singh return;
1427281eeb8aSJasvinder Singh }
1428281eeb8aSJasvinder Singh
1429281eeb8aSJasvinder Singh if (port_id_is_invalid(port_id, ENABLED_WARN))
14305fe5678dSJasvinder Singh goto free_table;
1431281eeb8aSJasvinder Singh
1432281eeb8aSJasvinder Singh /* Update Meter DSCP Table*/
1433*204daeeaSSunil Kumar Kori ret = rte_mtr_meter_dscp_table_update(port_id, mtr_id, proto,
1434281eeb8aSJasvinder Singh dscp_table, &error);
14355fe5678dSJasvinder Singh if (ret != 0)
1436281eeb8aSJasvinder Singh print_err_msg(&error);
14375fe5678dSJasvinder Singh
14385fe5678dSJasvinder Singh free_table:
1439281eeb8aSJasvinder Singh free(dscp_table);
1440281eeb8aSJasvinder Singh }
1441281eeb8aSJasvinder Singh
1442281eeb8aSJasvinder Singh cmdline_parse_inst_t cmd_set_port_meter_dscp_table = {
1443281eeb8aSJasvinder Singh .f = cmd_set_port_meter_dscp_table_parsed,
1444281eeb8aSJasvinder Singh .data = NULL,
1445*204daeeaSSunil Kumar Kori .help_str = "set port meter dscp table <port_id> <mtr_id> <proto> "
1446618f0f4aSFerruh Yigit "[<dscp_tbl_entry0> <dscp_tbl_entry1> ... <dscp_tbl_entry63>]",
1447281eeb8aSJasvinder Singh .tokens = {
1448281eeb8aSJasvinder Singh (void *)&cmd_set_port_meter_dscp_table_set,
1449281eeb8aSJasvinder Singh (void *)&cmd_set_port_meter_dscp_table_port,
1450281eeb8aSJasvinder Singh (void *)&cmd_set_port_meter_dscp_table_meter,
1451281eeb8aSJasvinder Singh (void *)&cmd_set_port_meter_dscp_table_dscp_table,
1452281eeb8aSJasvinder Singh (void *)&cmd_set_port_meter_dscp_table_token_string,
1453281eeb8aSJasvinder Singh NULL,
1454281eeb8aSJasvinder Singh },
1455281eeb8aSJasvinder Singh };
1456281eeb8aSJasvinder Singh
14579f5488e3SSunil Kumar Kori /* *** Set Port Meter VLAN Table *** */
14589f5488e3SSunil Kumar Kori struct cmd_set_port_meter_vlan_table_result {
14599f5488e3SSunil Kumar Kori cmdline_fixed_string_t set;
14609f5488e3SSunil Kumar Kori cmdline_fixed_string_t port;
14619f5488e3SSunil Kumar Kori cmdline_fixed_string_t meter;
14629f5488e3SSunil Kumar Kori cmdline_fixed_string_t vlan_table;
14639f5488e3SSunil Kumar Kori cmdline_multi_string_t token_string;
14649f5488e3SSunil Kumar Kori };
14659f5488e3SSunil Kumar Kori
14669f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_set_port_meter_vlan_table_set =
14679f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
14689f5488e3SSunil Kumar Kori struct cmd_set_port_meter_vlan_table_result, set, "set");
14699f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_set_port_meter_vlan_table_port =
14709f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
14719f5488e3SSunil Kumar Kori struct cmd_set_port_meter_vlan_table_result, port, "port");
14729f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_set_port_meter_vlan_table_meter =
14739f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
14749f5488e3SSunil Kumar Kori struct cmd_set_port_meter_vlan_table_result, meter, "meter");
14759f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_set_port_meter_vlan_table_vlan_table =
14769f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
14779f5488e3SSunil Kumar Kori struct cmd_set_port_meter_vlan_table_result,
14789f5488e3SSunil Kumar Kori vlan_table, "vlan table");
14799f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_set_port_meter_vlan_table_token_string =
14809f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_vlan_table_result,
14819f5488e3SSunil Kumar Kori token_string, TOKEN_STRING_MULTI);
14829f5488e3SSunil Kumar Kori
cmd_set_port_meter_vlan_table_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)14839f5488e3SSunil Kumar Kori static void cmd_set_port_meter_vlan_table_parsed(void *parsed_result,
14849f5488e3SSunil Kumar Kori __rte_unused struct cmdline *cl,
14859f5488e3SSunil Kumar Kori __rte_unused void *data)
14869f5488e3SSunil Kumar Kori {
14879f5488e3SSunil Kumar Kori struct cmd_set_port_meter_vlan_table_result *res = parsed_result;
1488*204daeeaSSunil Kumar Kori enum rte_mtr_color_in_protocol proto = 0;
14899f5488e3SSunil Kumar Kori struct rte_mtr_error error;
14909f5488e3SSunil Kumar Kori enum rte_color *vlan_table = NULL;
14919f5488e3SSunil Kumar Kori char *t_str = res->token_string;
14929f5488e3SSunil Kumar Kori uint32_t mtr_id = 0;
14939f5488e3SSunil Kumar Kori uint16_t port_id;
14949f5488e3SSunil Kumar Kori int ret;
14959f5488e3SSunil Kumar Kori
14969f5488e3SSunil Kumar Kori /* Parse string */
1497*204daeeaSSunil Kumar Kori ret = parse_multi_token_vlan_str(t_str, &port_id, &mtr_id, &proto,
1498*204daeeaSSunil Kumar Kori &vlan_table);
14999f5488e3SSunil Kumar Kori if (ret) {
15009f5488e3SSunil Kumar Kori fprintf(stderr, " Multi token string parse error\n");
15019f5488e3SSunil Kumar Kori return;
15029f5488e3SSunil Kumar Kori }
15039f5488e3SSunil Kumar Kori
15049f5488e3SSunil Kumar Kori if (port_id_is_invalid(port_id, ENABLED_WARN))
15059f5488e3SSunil Kumar Kori goto free_table;
15069f5488e3SSunil Kumar Kori
15079f5488e3SSunil Kumar Kori /* Update Meter VLAN Table*/
1508*204daeeaSSunil Kumar Kori ret = rte_mtr_meter_vlan_table_update(port_id, mtr_id, proto,
15099f5488e3SSunil Kumar Kori vlan_table, &error);
15109f5488e3SSunil Kumar Kori if (ret != 0)
15119f5488e3SSunil Kumar Kori print_err_msg(&error);
15129f5488e3SSunil Kumar Kori
15139f5488e3SSunil Kumar Kori free_table:
15149f5488e3SSunil Kumar Kori free(vlan_table);
15159f5488e3SSunil Kumar Kori }
15169f5488e3SSunil Kumar Kori
15179f5488e3SSunil Kumar Kori cmdline_parse_inst_t cmd_set_port_meter_vlan_table = {
15189f5488e3SSunil Kumar Kori .f = cmd_set_port_meter_vlan_table_parsed,
15199f5488e3SSunil Kumar Kori .data = NULL,
1520*204daeeaSSunil Kumar Kori .help_str = "set port meter vlan table <port_id> <mtr_id> <proto> "
15219f5488e3SSunil Kumar Kori "[<vlan_tbl_entry0> <vlan_tbl_entry1> ... <vlan_tbl_entry15>]",
15229f5488e3SSunil Kumar Kori .tokens = {
15239f5488e3SSunil Kumar Kori (void *)&cmd_set_port_meter_vlan_table_set,
15249f5488e3SSunil Kumar Kori (void *)&cmd_set_port_meter_vlan_table_port,
15259f5488e3SSunil Kumar Kori (void *)&cmd_set_port_meter_vlan_table_meter,
15269f5488e3SSunil Kumar Kori (void *)&cmd_set_port_meter_vlan_table_vlan_table,
15279f5488e3SSunil Kumar Kori (void *)&cmd_set_port_meter_vlan_table_token_string,
15289f5488e3SSunil Kumar Kori NULL,
15299f5488e3SSunil Kumar Kori },
15309f5488e3SSunil Kumar Kori };
15319f5488e3SSunil Kumar Kori
15329f5488e3SSunil Kumar Kori /* *** Set Port Meter input protocol *** */
15339f5488e3SSunil Kumar Kori struct cmd_set_port_meter_in_proto_result {
15349f5488e3SSunil Kumar Kori cmdline_fixed_string_t set;
15359f5488e3SSunil Kumar Kori cmdline_fixed_string_t port;
15369f5488e3SSunil Kumar Kori cmdline_fixed_string_t meter;
15379f5488e3SSunil Kumar Kori cmdline_fixed_string_t protocol;
15389f5488e3SSunil Kumar Kori cmdline_fixed_string_t proto;
15399f5488e3SSunil Kumar Kori uint32_t prio;
15409f5488e3SSunil Kumar Kori uint32_t mtr_id;
15419f5488e3SSunil Kumar Kori uint16_t port_id;
15429f5488e3SSunil Kumar Kori };
15439f5488e3SSunil Kumar Kori
15449f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_set_port_meter_in_proto_set =
15459f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
15469f5488e3SSunil Kumar Kori struct cmd_set_port_meter_in_proto_result, set, "set");
15479f5488e3SSunil Kumar Kori
15489f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_set_port_meter_in_proto_port =
15499f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
15509f5488e3SSunil Kumar Kori struct cmd_set_port_meter_in_proto_result, port, "port");
15519f5488e3SSunil Kumar Kori
15529f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_set_port_meter_in_proto_meter =
15539f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
15549f5488e3SSunil Kumar Kori struct cmd_set_port_meter_in_proto_result, meter, "meter");
15559f5488e3SSunil Kumar Kori
15569f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_set_port_meter_in_proto_protocol =
15579f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
15589f5488e3SSunil Kumar Kori struct cmd_set_port_meter_in_proto_result, protocol, "proto");
15599f5488e3SSunil Kumar Kori
15609f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_set_port_meter_in_proto_proto =
15619f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
15629f5488e3SSunil Kumar Kori struct cmd_set_port_meter_in_proto_result, proto,
15639f5488e3SSunil Kumar Kori "outer_vlan#inner_vlan#outer_ip#inner_ip");
15649f5488e3SSunil Kumar Kori
15659f5488e3SSunil Kumar Kori static cmdline_parse_token_num_t cmd_set_port_meter_in_proto_prio =
15669f5488e3SSunil Kumar Kori TOKEN_NUM_INITIALIZER(
15679f5488e3SSunil Kumar Kori struct cmd_set_port_meter_in_proto_result, prio, RTE_UINT32);
15689f5488e3SSunil Kumar Kori
15699f5488e3SSunil Kumar Kori static cmdline_parse_token_num_t cmd_set_port_meter_in_proto_port_id =
15709f5488e3SSunil Kumar Kori TOKEN_NUM_INITIALIZER(
15719f5488e3SSunil Kumar Kori struct cmd_set_port_meter_in_proto_result, port_id, RTE_UINT16);
15729f5488e3SSunil Kumar Kori
15739f5488e3SSunil Kumar Kori static cmdline_parse_token_num_t cmd_set_port_meter_in_proto_mtr_id =
15749f5488e3SSunil Kumar Kori TOKEN_NUM_INITIALIZER(
15759f5488e3SSunil Kumar Kori struct cmd_set_port_meter_in_proto_result, mtr_id, RTE_UINT32);
15769f5488e3SSunil Kumar Kori
cmd_set_port_meter_in_proto_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)15779f5488e3SSunil Kumar Kori static void cmd_set_port_meter_in_proto_parsed(void *parsed_result,
15789f5488e3SSunil Kumar Kori __rte_unused struct cmdline *cl,
15799f5488e3SSunil Kumar Kori __rte_unused void *data)
15809f5488e3SSunil Kumar Kori {
15819f5488e3SSunil Kumar Kori struct cmd_set_port_meter_in_proto_result *res = parsed_result;
15829f5488e3SSunil Kumar Kori enum rte_mtr_color_in_protocol proto;
15839f5488e3SSunil Kumar Kori struct rte_mtr_error error;
15849f5488e3SSunil Kumar Kori int ret;
15859f5488e3SSunil Kumar Kori
15869f5488e3SSunil Kumar Kori if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15879f5488e3SSunil Kumar Kori return;
15889f5488e3SSunil Kumar Kori
15899f5488e3SSunil Kumar Kori if (strcmp(res->proto, "outer_vlan") == 0)
15909f5488e3SSunil Kumar Kori proto = RTE_MTR_COLOR_IN_PROTO_OUTER_VLAN;
15919f5488e3SSunil Kumar Kori else if (strcmp(res->proto, "inner_vlan") == 0)
15929f5488e3SSunil Kumar Kori proto = RTE_MTR_COLOR_IN_PROTO_INNER_VLAN;
15939f5488e3SSunil Kumar Kori else if (strcmp(res->proto, "outer_ip") == 0)
15949f5488e3SSunil Kumar Kori proto = RTE_MTR_COLOR_IN_PROTO_OUTER_IP;
15959f5488e3SSunil Kumar Kori else if (strcmp(res->proto, "inner_ip") == 0)
15969f5488e3SSunil Kumar Kori proto = RTE_MTR_COLOR_IN_PROTO_INNER_IP;
15979f5488e3SSunil Kumar Kori else {
15989f5488e3SSunil Kumar Kori printf("Invalid protocol\n");
15999f5488e3SSunil Kumar Kori return;
16009f5488e3SSunil Kumar Kori }
16019f5488e3SSunil Kumar Kori
16029f5488e3SSunil Kumar Kori /* Update Meter input proto and priority */
16039f5488e3SSunil Kumar Kori ret = rte_mtr_color_in_protocol_set(res->port_id, res->mtr_id,
16049f5488e3SSunil Kumar Kori proto, res->prio, &error);
16059f5488e3SSunil Kumar Kori if (ret != 0)
16069f5488e3SSunil Kumar Kori print_err_msg(&error);
16079f5488e3SSunil Kumar Kori }
16089f5488e3SSunil Kumar Kori
16099f5488e3SSunil Kumar Kori cmdline_parse_inst_t cmd_set_port_meter_in_proto = {
16109f5488e3SSunil Kumar Kori .f = cmd_set_port_meter_in_proto_parsed,
16119f5488e3SSunil Kumar Kori .data = NULL,
16129f5488e3SSunil Kumar Kori .help_str = "set port meter proto <port_id> <mtr_id> <proto> "
16139f5488e3SSunil Kumar Kori "<prio>",
16149f5488e3SSunil Kumar Kori .tokens = {
16159f5488e3SSunil Kumar Kori (void *)&cmd_set_port_meter_in_proto_set,
16169f5488e3SSunil Kumar Kori (void *)&cmd_set_port_meter_in_proto_port,
16179f5488e3SSunil Kumar Kori (void *)&cmd_set_port_meter_in_proto_meter,
16189f5488e3SSunil Kumar Kori (void *)&cmd_set_port_meter_in_proto_protocol,
16199f5488e3SSunil Kumar Kori (void *)&cmd_set_port_meter_in_proto_port_id,
16209f5488e3SSunil Kumar Kori (void *)&cmd_set_port_meter_in_proto_mtr_id,
16219f5488e3SSunil Kumar Kori (void *)&cmd_set_port_meter_in_proto_proto,
16229f5488e3SSunil Kumar Kori (void *)&cmd_set_port_meter_in_proto_prio,
16239f5488e3SSunil Kumar Kori NULL,
16249f5488e3SSunil Kumar Kori },
16259f5488e3SSunil Kumar Kori };
16269f5488e3SSunil Kumar Kori
16279f5488e3SSunil Kumar Kori /* *** Get Port Meter input protocol *** */
16289f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_result {
16299f5488e3SSunil Kumar Kori cmdline_fixed_string_t get;
16309f5488e3SSunil Kumar Kori cmdline_fixed_string_t port;
16319f5488e3SSunil Kumar Kori cmdline_fixed_string_t meter;
16329f5488e3SSunil Kumar Kori cmdline_fixed_string_t protocol;
16339f5488e3SSunil Kumar Kori uint32_t mtr_id;
16349f5488e3SSunil Kumar Kori uint16_t port_id;
16359f5488e3SSunil Kumar Kori };
16369f5488e3SSunil Kumar Kori
16379f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_get =
16389f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
16399f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_result, get, "get");
16409f5488e3SSunil Kumar Kori
16419f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_port =
16429f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
16439f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_result, port, "port");
16449f5488e3SSunil Kumar Kori
16459f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_meter =
16469f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
16479f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_result, meter, "meter");
16489f5488e3SSunil Kumar Kori
16499f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_protocol =
16509f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
16519f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_result, protocol, "proto");
16529f5488e3SSunil Kumar Kori
16539f5488e3SSunil Kumar Kori static cmdline_parse_token_num_t cmd_get_port_meter_in_proto_port_id =
16549f5488e3SSunil Kumar Kori TOKEN_NUM_INITIALIZER(
16559f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_result, port_id, RTE_UINT16);
16569f5488e3SSunil Kumar Kori
16579f5488e3SSunil Kumar Kori static cmdline_parse_token_num_t cmd_get_port_meter_in_proto_mtr_id =
16589f5488e3SSunil Kumar Kori TOKEN_NUM_INITIALIZER(
16599f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_result, mtr_id, RTE_UINT32);
16609f5488e3SSunil Kumar Kori
cmd_get_port_meter_in_proto_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)16619f5488e3SSunil Kumar Kori static void cmd_get_port_meter_in_proto_parsed(void *parsed_result,
16629f5488e3SSunil Kumar Kori __rte_unused struct cmdline *cl,
16639f5488e3SSunil Kumar Kori __rte_unused void *data)
16649f5488e3SSunil Kumar Kori {
16659f5488e3SSunil Kumar Kori struct cmd_set_port_meter_in_proto_result *res = parsed_result;
16669f5488e3SSunil Kumar Kori struct rte_mtr_error error;
16679f5488e3SSunil Kumar Kori uint64_t proto_mask = 0;
16689f5488e3SSunil Kumar Kori int ret;
16699f5488e3SSunil Kumar Kori
16709f5488e3SSunil Kumar Kori if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16719f5488e3SSunil Kumar Kori return;
16729f5488e3SSunil Kumar Kori
16739f5488e3SSunil Kumar Kori /* Update Meter input proto and priority */
16749f5488e3SSunil Kumar Kori ret = rte_mtr_color_in_protocol_get(res->port_id, res->mtr_id,
16759f5488e3SSunil Kumar Kori &proto_mask, &error);
16769f5488e3SSunil Kumar Kori if (ret != 0)
16779f5488e3SSunil Kumar Kori print_err_msg(&error);
16789f5488e3SSunil Kumar Kori
16799f5488e3SSunil Kumar Kori printf("Enabled protocols:\n");
16809f5488e3SSunil Kumar Kori if (proto_mask & RTE_MTR_COLOR_IN_PROTO_OUTER_VLAN)
16819f5488e3SSunil Kumar Kori printf("\touter_vlan\n");
16829f5488e3SSunil Kumar Kori if (proto_mask & RTE_MTR_COLOR_IN_PROTO_INNER_VLAN)
16839f5488e3SSunil Kumar Kori printf("\tinner_vlan\n");
16849f5488e3SSunil Kumar Kori if (proto_mask & RTE_MTR_COLOR_IN_PROTO_OUTER_IP)
16859f5488e3SSunil Kumar Kori printf("\touter_ip\n");
16869f5488e3SSunil Kumar Kori if (proto_mask & RTE_MTR_COLOR_IN_PROTO_INNER_IP)
16879f5488e3SSunil Kumar Kori printf("\tinner_ip\n");
16889f5488e3SSunil Kumar Kori }
16899f5488e3SSunil Kumar Kori
16909f5488e3SSunil Kumar Kori cmdline_parse_inst_t cmd_get_port_meter_in_proto = {
16919f5488e3SSunil Kumar Kori .f = cmd_get_port_meter_in_proto_parsed,
16929f5488e3SSunil Kumar Kori .data = NULL,
16939f5488e3SSunil Kumar Kori .help_str = "get port meter proto <port_id> <mtr_id>",
16949f5488e3SSunil Kumar Kori .tokens = {
16959f5488e3SSunil Kumar Kori (void *)&cmd_get_port_meter_in_proto_get,
16969f5488e3SSunil Kumar Kori (void *)&cmd_get_port_meter_in_proto_port,
16979f5488e3SSunil Kumar Kori (void *)&cmd_get_port_meter_in_proto_meter,
16989f5488e3SSunil Kumar Kori (void *)&cmd_get_port_meter_in_proto_protocol,
16999f5488e3SSunil Kumar Kori (void *)&cmd_get_port_meter_in_proto_port_id,
17009f5488e3SSunil Kumar Kori (void *)&cmd_get_port_meter_in_proto_mtr_id,
17019f5488e3SSunil Kumar Kori NULL,
17029f5488e3SSunil Kumar Kori },
17039f5488e3SSunil Kumar Kori };
17049f5488e3SSunil Kumar Kori
17059f5488e3SSunil Kumar Kori /* *** Get Port Meter input protocol priority *** */
17069f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_prio_result {
17079f5488e3SSunil Kumar Kori cmdline_fixed_string_t get;
17089f5488e3SSunil Kumar Kori cmdline_fixed_string_t port;
17099f5488e3SSunil Kumar Kori cmdline_fixed_string_t meter;
17109f5488e3SSunil Kumar Kori cmdline_fixed_string_t protocol;
17119f5488e3SSunil Kumar Kori cmdline_fixed_string_t proto;
17129f5488e3SSunil Kumar Kori uint32_t mtr_id;
17139f5488e3SSunil Kumar Kori uint16_t port_id;
17149f5488e3SSunil Kumar Kori };
17159f5488e3SSunil Kumar Kori
17169f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_prio_get =
17179f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
17189f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_prio_result, get, "get");
17199f5488e3SSunil Kumar Kori
17209f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_prio_port =
17219f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
17229f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_prio_result, port, "port");
17239f5488e3SSunil Kumar Kori
17249f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_prio_meter =
17259f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
17269f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_prio_result, meter, "meter");
17279f5488e3SSunil Kumar Kori
17289f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_prio_protocol =
17299f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
17309f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_prio_result, protocol,
17319f5488e3SSunil Kumar Kori "proto_prio");
17329f5488e3SSunil Kumar Kori
17339f5488e3SSunil Kumar Kori static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_prio_proto =
17349f5488e3SSunil Kumar Kori TOKEN_STRING_INITIALIZER(
17359f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_prio_result, proto,
17369f5488e3SSunil Kumar Kori "outer_vlan#inner_vlan#outer_ip#inner_ip");
17379f5488e3SSunil Kumar Kori
17389f5488e3SSunil Kumar Kori static cmdline_parse_token_num_t cmd_get_port_meter_in_proto_prio_port_id =
17399f5488e3SSunil Kumar Kori TOKEN_NUM_INITIALIZER(
17409f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_prio_result, port_id,
17419f5488e3SSunil Kumar Kori RTE_UINT16);
17429f5488e3SSunil Kumar Kori
17439f5488e3SSunil Kumar Kori static cmdline_parse_token_num_t cmd_get_port_meter_in_proto_prio_mtr_id =
17449f5488e3SSunil Kumar Kori TOKEN_NUM_INITIALIZER(
17459f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_prio_result, mtr_id,
17469f5488e3SSunil Kumar Kori RTE_UINT32);
17479f5488e3SSunil Kumar Kori
cmd_get_port_meter_in_proto_prio_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)17489f5488e3SSunil Kumar Kori static void cmd_get_port_meter_in_proto_prio_parsed(void *parsed_result,
17499f5488e3SSunil Kumar Kori __rte_unused struct cmdline *cl,
17509f5488e3SSunil Kumar Kori __rte_unused void *data)
17519f5488e3SSunil Kumar Kori {
17529f5488e3SSunil Kumar Kori struct cmd_get_port_meter_in_proto_prio_result *res = parsed_result;
17539f5488e3SSunil Kumar Kori enum rte_mtr_color_in_protocol proto;
17549f5488e3SSunil Kumar Kori struct rte_mtr_error error;
17559f5488e3SSunil Kumar Kori uint32_t prio = 0;
17569f5488e3SSunil Kumar Kori int ret;
17579f5488e3SSunil Kumar Kori
17589f5488e3SSunil Kumar Kori if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17599f5488e3SSunil Kumar Kori return;
17609f5488e3SSunil Kumar Kori
17619f5488e3SSunil Kumar Kori if (strcmp(res->proto, "outer_vlan") == 0)
17629f5488e3SSunil Kumar Kori proto = RTE_MTR_COLOR_IN_PROTO_OUTER_VLAN;
17639f5488e3SSunil Kumar Kori else if (strcmp(res->proto, "inner_vlan") == 0)
17649f5488e3SSunil Kumar Kori proto = RTE_MTR_COLOR_IN_PROTO_INNER_VLAN;
17659f5488e3SSunil Kumar Kori else if (strcmp(res->proto, "outer_ip") == 0)
17669f5488e3SSunil Kumar Kori proto = RTE_MTR_COLOR_IN_PROTO_OUTER_IP;
17679f5488e3SSunil Kumar Kori else if (strcmp(res->proto, "inner_ip") == 0)
17689f5488e3SSunil Kumar Kori proto = RTE_MTR_COLOR_IN_PROTO_INNER_IP;
17699f5488e3SSunil Kumar Kori else {
17709f5488e3SSunil Kumar Kori printf("Invalid protocol\n");
17719f5488e3SSunil Kumar Kori return;
17729f5488e3SSunil Kumar Kori }
17739f5488e3SSunil Kumar Kori
17749f5488e3SSunil Kumar Kori /* Get Meter input proto and priority */
17759f5488e3SSunil Kumar Kori ret = rte_mtr_color_in_protocol_priority_get(res->port_id, res->mtr_id,
17769f5488e3SSunil Kumar Kori proto, &prio, &error);
17779f5488e3SSunil Kumar Kori if (ret != 0)
17789f5488e3SSunil Kumar Kori print_err_msg(&error);
17799f5488e3SSunil Kumar Kori }
17809f5488e3SSunil Kumar Kori
17819f5488e3SSunil Kumar Kori cmdline_parse_inst_t cmd_get_port_meter_in_proto_prio = {
17829f5488e3SSunil Kumar Kori .f = cmd_get_port_meter_in_proto_prio_parsed,
17839f5488e3SSunil Kumar Kori .data = NULL,
17849f5488e3SSunil Kumar Kori .help_str = "get port meter proto_prio <port_id> <mtr_id> <proto>",
17859f5488e3SSunil Kumar Kori .tokens = {
17869f5488e3SSunil Kumar Kori (void *)&cmd_get_port_meter_in_proto_prio_get,
17879f5488e3SSunil Kumar Kori (void *)&cmd_get_port_meter_in_proto_prio_port,
17889f5488e3SSunil Kumar Kori (void *)&cmd_get_port_meter_in_proto_prio_meter,
17899f5488e3SSunil Kumar Kori (void *)&cmd_get_port_meter_in_proto_prio_protocol,
17909f5488e3SSunil Kumar Kori (void *)&cmd_get_port_meter_in_proto_prio_port_id,
17919f5488e3SSunil Kumar Kori (void *)&cmd_get_port_meter_in_proto_prio_mtr_id,
17929f5488e3SSunil Kumar Kori (void *)&cmd_get_port_meter_in_proto_prio_proto,
17939f5488e3SSunil Kumar Kori NULL,
17949f5488e3SSunil Kumar Kori },
17959f5488e3SSunil Kumar Kori };
17969f5488e3SSunil Kumar Kori
179730ffb4e6SCristian Dumitrescu /* *** Set Port Meter Stats Mask *** */
179830ffb4e6SCristian Dumitrescu struct cmd_set_port_meter_stats_mask_result {
179930ffb4e6SCristian Dumitrescu cmdline_fixed_string_t set;
180030ffb4e6SCristian Dumitrescu cmdline_fixed_string_t port;
180130ffb4e6SCristian Dumitrescu cmdline_fixed_string_t meter;
180230ffb4e6SCristian Dumitrescu cmdline_fixed_string_t stats;
180330ffb4e6SCristian Dumitrescu cmdline_fixed_string_t mask;
180430ffb4e6SCristian Dumitrescu uint16_t port_id;
180530ffb4e6SCristian Dumitrescu uint32_t mtr_id;
180630ffb4e6SCristian Dumitrescu uint64_t stats_mask;
180730ffb4e6SCristian Dumitrescu };
180830ffb4e6SCristian Dumitrescu
1809ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_set =
181030ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
181130ffb4e6SCristian Dumitrescu struct cmd_set_port_meter_stats_mask_result, set, "set");
1812ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_port =
181330ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
181430ffb4e6SCristian Dumitrescu struct cmd_set_port_meter_stats_mask_result, port, "port");
1815ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_meter =
181630ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
181730ffb4e6SCristian Dumitrescu struct cmd_set_port_meter_stats_mask_result, meter, "meter");
1818ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_stats =
181930ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
182030ffb4e6SCristian Dumitrescu struct cmd_set_port_meter_stats_mask_result, stats, "stats");
1821ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_mask =
182230ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
182330ffb4e6SCristian Dumitrescu struct cmd_set_port_meter_stats_mask_result, mask, "mask");
1824ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_port_id =
182530ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
1826c2341bb6SDmitry Kozlyuk struct cmd_set_port_meter_stats_mask_result, port_id,
1827c2341bb6SDmitry Kozlyuk RTE_UINT16);
1828ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_mtr_id =
182930ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
1830c2341bb6SDmitry Kozlyuk struct cmd_set_port_meter_stats_mask_result, mtr_id,
1831c2341bb6SDmitry Kozlyuk RTE_UINT32);
1832ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_stats_mask =
183330ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
183430ffb4e6SCristian Dumitrescu struct cmd_set_port_meter_stats_mask_result, stats_mask,
1835c2341bb6SDmitry Kozlyuk RTE_UINT64);
183630ffb4e6SCristian Dumitrescu
cmd_set_port_meter_stats_mask_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)183730ffb4e6SCristian Dumitrescu static void cmd_set_port_meter_stats_mask_parsed(void *parsed_result,
1838f2fc83b4SThomas Monjalon __rte_unused struct cmdline *cl,
1839f2fc83b4SThomas Monjalon __rte_unused void *data)
184030ffb4e6SCristian Dumitrescu {
184130ffb4e6SCristian Dumitrescu struct cmd_set_port_meter_stats_mask_result *res = parsed_result;
184230ffb4e6SCristian Dumitrescu struct rte_mtr_error error;
184330ffb4e6SCristian Dumitrescu uint64_t stats_mask = res->stats_mask;
184430ffb4e6SCristian Dumitrescu uint32_t mtr_id = res->mtr_id;
184530ffb4e6SCristian Dumitrescu uint16_t port_id = res->port_id;
184630ffb4e6SCristian Dumitrescu int ret;
184730ffb4e6SCristian Dumitrescu
184830ffb4e6SCristian Dumitrescu if (port_id_is_invalid(port_id, ENABLED_WARN))
184930ffb4e6SCristian Dumitrescu return;
185030ffb4e6SCristian Dumitrescu
185130ffb4e6SCristian Dumitrescu ret = rte_mtr_stats_update(port_id, mtr_id, stats_mask, &error);
185230ffb4e6SCristian Dumitrescu if (ret != 0) {
185330ffb4e6SCristian Dumitrescu print_err_msg(&error);
185430ffb4e6SCristian Dumitrescu return;
185530ffb4e6SCristian Dumitrescu }
185630ffb4e6SCristian Dumitrescu }
185730ffb4e6SCristian Dumitrescu
185830ffb4e6SCristian Dumitrescu cmdline_parse_inst_t cmd_set_port_meter_stats_mask = {
185930ffb4e6SCristian Dumitrescu .f = cmd_set_port_meter_stats_mask_parsed,
186030ffb4e6SCristian Dumitrescu .data = NULL,
1861618f0f4aSFerruh Yigit .help_str = "set port meter stats mask <port_id> <mtr_id> <stats_mask>",
186230ffb4e6SCristian Dumitrescu .tokens = {
186330ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_stats_mask_set,
186430ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_stats_mask_port,
186530ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_stats_mask_meter,
186630ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_stats_mask_stats,
186730ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_stats_mask_mask,
186830ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_stats_mask_port_id,
186930ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_stats_mask_mtr_id,
187030ffb4e6SCristian Dumitrescu (void *)&cmd_set_port_meter_stats_mask_stats_mask,
187130ffb4e6SCristian Dumitrescu NULL,
187230ffb4e6SCristian Dumitrescu },
187330ffb4e6SCristian Dumitrescu };
187430ffb4e6SCristian Dumitrescu
187530ffb4e6SCristian Dumitrescu /* *** Show Port Meter Stats *** */
187630ffb4e6SCristian Dumitrescu struct cmd_show_port_meter_stats_result {
187730ffb4e6SCristian Dumitrescu cmdline_fixed_string_t show;
187830ffb4e6SCristian Dumitrescu cmdline_fixed_string_t port;
187930ffb4e6SCristian Dumitrescu cmdline_fixed_string_t meter;
188030ffb4e6SCristian Dumitrescu cmdline_fixed_string_t stats;
188130ffb4e6SCristian Dumitrescu uint16_t port_id;
188230ffb4e6SCristian Dumitrescu uint32_t mtr_id;
1883e63b5016SJasvinder Singh cmdline_fixed_string_t clear;
188430ffb4e6SCristian Dumitrescu };
188530ffb4e6SCristian Dumitrescu
1886ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_show_port_meter_stats_show =
188730ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
188830ffb4e6SCristian Dumitrescu struct cmd_show_port_meter_stats_result, show, "show");
1889ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_show_port_meter_stats_port =
189030ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
189130ffb4e6SCristian Dumitrescu struct cmd_show_port_meter_stats_result, port, "port");
1892ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_show_port_meter_stats_meter =
189330ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
189430ffb4e6SCristian Dumitrescu struct cmd_show_port_meter_stats_result, meter, "meter");
1895ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_show_port_meter_stats_stats =
189630ffb4e6SCristian Dumitrescu TOKEN_STRING_INITIALIZER(
189730ffb4e6SCristian Dumitrescu struct cmd_show_port_meter_stats_result, stats, "stats");
1898ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_show_port_meter_stats_port_id =
189930ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
1900c2341bb6SDmitry Kozlyuk struct cmd_show_port_meter_stats_result, port_id, RTE_UINT16);
1901ea0774ffSDavid Marchand static cmdline_parse_token_num_t cmd_show_port_meter_stats_mtr_id =
190230ffb4e6SCristian Dumitrescu TOKEN_NUM_INITIALIZER(
1903c2341bb6SDmitry Kozlyuk struct cmd_show_port_meter_stats_result, mtr_id, RTE_UINT32);
1904ea0774ffSDavid Marchand static cmdline_parse_token_string_t cmd_show_port_meter_stats_clear =
1905e63b5016SJasvinder Singh TOKEN_STRING_INITIALIZER(
1906e63b5016SJasvinder Singh struct cmd_show_port_meter_stats_result, clear, "yes#no");
190730ffb4e6SCristian Dumitrescu
cmd_show_port_meter_stats_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)190830ffb4e6SCristian Dumitrescu static void cmd_show_port_meter_stats_parsed(void *parsed_result,
1909f2fc83b4SThomas Monjalon __rte_unused struct cmdline *cl,
1910f2fc83b4SThomas Monjalon __rte_unused void *data)
191130ffb4e6SCristian Dumitrescu {
191230ffb4e6SCristian Dumitrescu struct cmd_show_port_meter_stats_result *res = parsed_result;
191330ffb4e6SCristian Dumitrescu struct rte_mtr_stats stats;
191430ffb4e6SCristian Dumitrescu uint64_t stats_mask = 0;
191530ffb4e6SCristian Dumitrescu struct rte_mtr_error error;
191630ffb4e6SCristian Dumitrescu uint32_t mtr_id = res->mtr_id;
1917e63b5016SJasvinder Singh uint32_t clear = 0;
191830ffb4e6SCristian Dumitrescu uint16_t port_id = res->port_id;
191930ffb4e6SCristian Dumitrescu int ret;
192030ffb4e6SCristian Dumitrescu
192130ffb4e6SCristian Dumitrescu if (port_id_is_invalid(port_id, ENABLED_WARN))
192230ffb4e6SCristian Dumitrescu return;
192330ffb4e6SCristian Dumitrescu
1924e63b5016SJasvinder Singh if (strcmp(res->clear, "yes") == 0)
1925e63b5016SJasvinder Singh clear = 1;
1926e63b5016SJasvinder Singh
192730ffb4e6SCristian Dumitrescu memset(&stats, 0, sizeof(struct rte_mtr_stats));
192830ffb4e6SCristian Dumitrescu ret = rte_mtr_stats_read(port_id, mtr_id, &stats,
192930ffb4e6SCristian Dumitrescu &stats_mask, clear, &error);
193030ffb4e6SCristian Dumitrescu if (ret != 0) {
193130ffb4e6SCristian Dumitrescu print_err_msg(&error);
193230ffb4e6SCristian Dumitrescu return;
193330ffb4e6SCristian Dumitrescu }
193430ffb4e6SCristian Dumitrescu
193530ffb4e6SCristian Dumitrescu /* Display stats */
193630ffb4e6SCristian Dumitrescu if (stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
193730ffb4e6SCristian Dumitrescu printf("\tPkts G: %" PRIu64 "\n",
1938c1656328SJasvinder Singh stats.n_pkts[RTE_COLOR_GREEN]);
193930ffb4e6SCristian Dumitrescu if (stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
194030ffb4e6SCristian Dumitrescu printf("\tBytes G: %" PRIu64 "\n",
1941c1656328SJasvinder Singh stats.n_bytes[RTE_COLOR_GREEN]);
194230ffb4e6SCristian Dumitrescu if (stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
194330ffb4e6SCristian Dumitrescu printf("\tPkts Y: %" PRIu64 "\n",
1944c1656328SJasvinder Singh stats.n_pkts[RTE_COLOR_YELLOW]);
194530ffb4e6SCristian Dumitrescu if (stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
194630ffb4e6SCristian Dumitrescu printf("\tBytes Y: %" PRIu64 "\n",
1947c1656328SJasvinder Singh stats.n_bytes[RTE_COLOR_YELLOW]);
194830ffb4e6SCristian Dumitrescu if (stats_mask & RTE_MTR_STATS_N_PKTS_RED)
194930ffb4e6SCristian Dumitrescu printf("\tPkts R: %" PRIu64 "\n",
1950c1656328SJasvinder Singh stats.n_pkts[RTE_COLOR_RED]);
195130ffb4e6SCristian Dumitrescu if (stats_mask & RTE_MTR_STATS_N_BYTES_RED)
1952930a030dSLeah Tekoa printf("\tBytes R: %" PRIu64 "\n",
1953c1656328SJasvinder Singh stats.n_bytes[RTE_COLOR_RED]);
195430ffb4e6SCristian Dumitrescu if (stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
195530ffb4e6SCristian Dumitrescu printf("\tPkts DROPPED: %" PRIu64 "\n",
195630ffb4e6SCristian Dumitrescu stats.n_pkts_dropped);
195730ffb4e6SCristian Dumitrescu if (stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
195830ffb4e6SCristian Dumitrescu printf("\tBytes DROPPED: %" PRIu64 "\n",
195930ffb4e6SCristian Dumitrescu stats.n_bytes_dropped);
196030ffb4e6SCristian Dumitrescu }
196130ffb4e6SCristian Dumitrescu
196230ffb4e6SCristian Dumitrescu cmdline_parse_inst_t cmd_show_port_meter_stats = {
196330ffb4e6SCristian Dumitrescu .f = cmd_show_port_meter_stats_parsed,
196430ffb4e6SCristian Dumitrescu .data = NULL,
1965618f0f4aSFerruh Yigit .help_str = "show port meter stats <port_id> <mtr_id> <clear>(yes|no)",
196630ffb4e6SCristian Dumitrescu .tokens = {
196730ffb4e6SCristian Dumitrescu (void *)&cmd_show_port_meter_stats_show,
196830ffb4e6SCristian Dumitrescu (void *)&cmd_show_port_meter_stats_port,
196930ffb4e6SCristian Dumitrescu (void *)&cmd_show_port_meter_stats_meter,
197030ffb4e6SCristian Dumitrescu (void *)&cmd_show_port_meter_stats_stats,
197130ffb4e6SCristian Dumitrescu (void *)&cmd_show_port_meter_stats_port_id,
197230ffb4e6SCristian Dumitrescu (void *)&cmd_show_port_meter_stats_mtr_id,
197330ffb4e6SCristian Dumitrescu (void *)&cmd_show_port_meter_stats_clear,
197430ffb4e6SCristian Dumitrescu NULL,
197530ffb4e6SCristian Dumitrescu },
197630ffb4e6SCristian Dumitrescu };
1977