LCOV - code coverage report
Current view: top level - app/test-pmd - cmdline_mtr.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 431 0.0 %
Date: 2025-02-01 18:54:23 Functions: 0 28 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2017 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdlib.h>
       6                 :            : 
       7                 :            : #include <cmdline_parse.h>
       8                 :            : #include <cmdline_parse_num.h>
       9                 :            : #include <cmdline_parse_string.h>
      10                 :            : 
      11                 :            : #include <rte_ethdev.h>
      12                 :            : #include <rte_flow.h>
      13                 :            : #include <rte_mtr.h>
      14                 :            : 
      15                 :            : #include "testpmd.h"
      16                 :            : #include "cmdline_mtr.h"
      17                 :            : 
      18                 :            : #define PARSE_DELIMITER                         " \f\n\r\t\v"
      19                 :            : #define MAX_VLAN_TABLE_ENTRIES          16
      20                 :            : #define MAX_DSCP_TABLE_ENTRIES          64
      21                 :            : 
      22                 :            : /** Display Meter Error Message */
      23                 :            : static void
      24                 :          0 : print_err_msg(struct rte_mtr_error *error)
      25                 :            : {
      26                 :            :         static const char *const errstrlist[] = {
      27                 :            :                 [RTE_MTR_ERROR_TYPE_NONE] = "no error",
      28                 :            :                 [RTE_MTR_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
      29                 :            :                 [RTE_MTR_ERROR_TYPE_METER_PROFILE_ID] = "meter profile id",
      30                 :            :                 [RTE_MTR_ERROR_TYPE_METER_PROFILE] = "meter profile null",
      31                 :            :                 [RTE_MTR_ERROR_TYPE_MTR_ID] = "meter id",
      32                 :            :                 [RTE_MTR_ERROR_TYPE_MTR_PARAMS] = "meter params null",
      33                 :            :                 [RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN]
      34                 :            :                         = "policer action(green)",
      35                 :            :                 [RTE_MTR_ERROR_TYPE_POLICER_ACTION_YELLOW]
      36                 :            :                         = "policer action(yellow)",
      37                 :            :                 [RTE_MTR_ERROR_TYPE_POLICER_ACTION_RED]
      38                 :            :                         = "policer action(red)",
      39                 :            :                 [RTE_MTR_ERROR_TYPE_STATS_MASK] = "stats mask",
      40                 :            :                 [RTE_MTR_ERROR_TYPE_STATS] = "stats",
      41                 :            :                 [RTE_MTR_ERROR_TYPE_SHARED]
      42                 :            :                         = "shared meter",
      43                 :            :                 [RTE_MTR_ERROR_TYPE_METER_POLICY_ID] = "meter policy id",
      44                 :            :                 [RTE_MTR_ERROR_TYPE_METER_POLICY] = "meter policy null",
      45                 :            :         };
      46                 :            : 
      47                 :            :         const char *errstr;
      48                 :            :         char buf[64];
      49                 :            : 
      50                 :          0 :         if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
      51                 :          0 :                 !errstrlist[error->type])
      52                 :            :                 errstr = "unknown type";
      53                 :            :         else
      54                 :            :                 errstr = errstrlist[error->type];
      55                 :            : 
      56                 :          0 :         if (error->cause)
      57                 :            :                 snprintf(buf, sizeof(buf), "cause: %p, ", error->cause);
      58                 :            : 
      59                 :          0 :         fprintf(stderr, "%s: %s%s (error %d)\n",
      60                 :          0 :                 errstr, error->cause ? buf : "",
      61                 :          0 :                 error->message ? error->message : "(no stated reason)",
      62                 :          0 :                 error->type);
      63                 :          0 : }
      64                 :            : 
      65                 :            : void
      66                 :          0 : print_mtr_err_msg(struct rte_mtr_error *error)
      67                 :            : {
      68                 :          0 :         print_err_msg(error);
      69                 :          0 : }
      70                 :            : 
      71                 :            : static int
      72                 :          0 : parse_uint(uint64_t *value, const char *str)
      73                 :            : {
      74                 :          0 :         char *next = NULL;
      75                 :            :         uint64_t n;
      76                 :            : 
      77                 :          0 :         errno = 0;
      78                 :            :         /* Parse number string */
      79                 :          0 :         n = strtol(str, &next, 10);
      80                 :          0 :         if (errno != 0 || str == next || *next != '\0')
      81                 :            :                 return -1;
      82                 :            : 
      83                 :          0 :         *value = n;
      84                 :            : 
      85                 :          0 :         return 0;
      86                 :            : }
      87                 :            : 
      88                 :            : static int
      89                 :          0 : parse_input_color_table_entries(char *str, enum rte_color **dscp_table,
      90                 :            :         enum rte_color **vlan_table)
      91                 :            : {
      92                 :            :         enum rte_color *vlan, *dscp;
      93                 :            :         char *token;
      94                 :            :         int i = 0;
      95                 :            : 
      96                 :          0 :         token = strtok_r(str, PARSE_DELIMITER, &str);
      97                 :          0 :         if (token == NULL)
      98                 :            :                 return 0;
      99                 :            : 
     100                 :            :         /* Allocate memory for dscp table */
     101                 :          0 :         dscp = (enum rte_color *)malloc(MAX_DSCP_TABLE_ENTRIES *
     102                 :            :                 sizeof(enum rte_color));
     103                 :          0 :         if (dscp == NULL)
     104                 :            :                 return -1;
     105                 :            : 
     106                 :            :         while (1) {
     107                 :          0 :                 if (strcasecmp(token, "G") == 0)
     108                 :          0 :                         dscp[i++] = RTE_COLOR_GREEN;
     109                 :          0 :                 else if (strcasecmp(token, "Y") == 0)
     110                 :          0 :                         dscp[i++] = RTE_COLOR_YELLOW;
     111                 :          0 :                 else if (strcasecmp(token, "R") == 0)
     112                 :          0 :                         dscp[i++] = RTE_COLOR_RED;
     113                 :            :                 else {
     114                 :          0 :                         free(dscp);
     115                 :          0 :                         return -1;
     116                 :            :                 }
     117                 :          0 :                 if (i == MAX_DSCP_TABLE_ENTRIES)
     118                 :            :                         break;
     119                 :            : 
     120                 :          0 :                 token = strtok_r(str, PARSE_DELIMITER, &str);
     121                 :          0 :                 if (token == NULL) {
     122                 :          0 :                         free(dscp);
     123                 :          0 :                         return -1;
     124                 :            :                 }
     125                 :            :         }
     126                 :            : 
     127                 :          0 :         *dscp_table = dscp;
     128                 :            : 
     129                 :          0 :         token = strtok_r(str, PARSE_DELIMITER, &str);
     130                 :          0 :         if (token == NULL)
     131                 :            :                 return 0;
     132                 :            : 
     133                 :            :         /* Allocate memory for vlan table */
     134                 :          0 :         vlan = (enum rte_color *)malloc(MAX_VLAN_TABLE_ENTRIES *
     135                 :            :                 sizeof(enum rte_color));
     136                 :          0 :         if (vlan == NULL) {
     137                 :          0 :                 free(*dscp_table);
     138                 :          0 :                 return -1;
     139                 :            :         }
     140                 :            : 
     141                 :            :         i = 0;
     142                 :            :         while (1) {
     143                 :          0 :                 if (strcasecmp(token, "G") == 0)
     144                 :          0 :                         vlan[i++] = RTE_COLOR_GREEN;
     145                 :          0 :                 else if (strcasecmp(token, "Y") == 0)
     146                 :          0 :                         vlan[i++] = RTE_COLOR_YELLOW;
     147                 :          0 :                 else if (strcasecmp(token, "R") == 0)
     148                 :          0 :                         vlan[i++] = RTE_COLOR_RED;
     149                 :            :                 else {
     150                 :          0 :                         free(vlan);
     151                 :          0 :                         free(*dscp_table);
     152                 :          0 :                         return -1;
     153                 :            :                 }
     154                 :          0 :                 if (i == MAX_VLAN_TABLE_ENTRIES)
     155                 :            :                         break;
     156                 :            : 
     157                 :          0 :                 token = strtok_r(str, PARSE_DELIMITER, &str);
     158                 :          0 :                 if (token == NULL) {
     159                 :          0 :                         free(vlan);
     160                 :          0 :                         free(*dscp_table);
     161                 :          0 :                         return -1;
     162                 :            :                 }
     163                 :            :         }
     164                 :            : 
     165                 :          0 :         *vlan_table = vlan;
     166                 :          0 :         return 0;
     167                 :            : }
     168                 :            : 
     169                 :            : static int
     170                 :          0 : parse_vlan_table_entries(char *str, enum rte_color **vlan_table)
     171                 :            : {
     172                 :            :         char *token;
     173                 :            :         int i = 0;
     174                 :            : 
     175                 :          0 :         token = strtok_r(str, PARSE_DELIMITER, &str);
     176                 :          0 :         if (token == NULL)
     177                 :            :                 return 0;
     178                 :            : 
     179                 :            :         /* Allocate memory for vlan table */
     180                 :          0 :         *vlan_table = (enum rte_color *)malloc(MAX_VLAN_TABLE_ENTRIES *
     181                 :            :                 sizeof(enum rte_color));
     182                 :          0 :         if (*vlan_table == NULL)
     183                 :            :                 return -1;
     184                 :            : 
     185                 :            :         while (1) {
     186                 :          0 :                 if (strcasecmp(token, "G") == 0)
     187                 :          0 :                         (*vlan_table)[i++] = RTE_COLOR_GREEN;
     188                 :          0 :                 else if (strcasecmp(token, "Y") == 0)
     189                 :          0 :                         (*vlan_table)[i++] = RTE_COLOR_YELLOW;
     190                 :          0 :                 else if (strcasecmp(token, "R") == 0)
     191                 :          0 :                         (*vlan_table)[i++] = RTE_COLOR_RED;
     192                 :            :                 else {
     193                 :          0 :                         free(*vlan_table);
     194                 :          0 :                         return -1;
     195                 :            :                 }
     196                 :          0 :                 if (i == MAX_VLAN_TABLE_ENTRIES)
     197                 :            :                         break;
     198                 :            : 
     199                 :          0 :                 token = strtok_r(str, PARSE_DELIMITER, &str);
     200                 :          0 :                 if (token == NULL) {
     201                 :          0 :                         free(*vlan_table);
     202                 :          0 :                         return -1;
     203                 :            :                 }
     204                 :            :         }
     205                 :            :         return 0;
     206                 :            : }
     207                 :            : 
     208                 :            : static int
     209                 :          0 : parse_dscp_table_entries(char *str, enum rte_color **dscp_table)
     210                 :            : {
     211                 :            :         char *token;
     212                 :            :         int i = 0;
     213                 :            : 
     214                 :          0 :         token = strtok_r(str, PARSE_DELIMITER, &str);
     215                 :          0 :         if (token == NULL)
     216                 :            :                 return 0;
     217                 :            : 
     218                 :            :         /* Allocate memory for dscp table */
     219                 :          0 :         *dscp_table = (enum rte_color *)malloc(MAX_DSCP_TABLE_ENTRIES *
     220                 :            :                 sizeof(enum rte_color));
     221                 :          0 :         if (*dscp_table == NULL)
     222                 :            :                 return -1;
     223                 :            : 
     224                 :            :         while (1) {
     225                 :          0 :                 if (strcmp(token, "G") == 0 ||
     226                 :          0 :                         strcmp(token, "g") == 0)
     227                 :          0 :                         (*dscp_table)[i++] = RTE_COLOR_GREEN;
     228                 :          0 :                 else if (strcmp(token, "Y") == 0 ||
     229                 :          0 :                         strcmp(token, "y") == 0)
     230                 :          0 :                         (*dscp_table)[i++] = RTE_COLOR_YELLOW;
     231                 :          0 :                 else if (strcmp(token, "R") == 0 ||
     232                 :          0 :                         strcmp(token, "r") == 0)
     233                 :          0 :                         (*dscp_table)[i++] = RTE_COLOR_RED;
     234                 :            :                 else {
     235                 :          0 :                         free(*dscp_table);
     236                 :          0 :                         return -1;
     237                 :            :                 }
     238                 :          0 :                 if (i == MAX_DSCP_TABLE_ENTRIES)
     239                 :            :                         break;
     240                 :            : 
     241                 :          0 :                 token = strtok_r(str, PARSE_DELIMITER, &str);
     242                 :          0 :                 if (token == NULL) {
     243                 :          0 :                         free(*dscp_table);
     244                 :          0 :                         return -1;
     245                 :            :                 }
     246                 :            :         }
     247                 :            :         return 0;
     248                 :            : }
     249                 :            : 
     250                 :            : static int
     251                 :          0 : parse_default_input_color_str(char *str, uint64_t *def_inp_color)
     252                 :            : {
     253                 :            :         char *token;
     254                 :            : 
     255                 :          0 :         token = strtok_r(str, PARSE_DELIMITER, &str);
     256                 :          0 :         if (token == NULL)
     257                 :            :                 return 0;
     258                 :            : 
     259                 :          0 :         if (strcasecmp(token, "G") == 0)
     260                 :          0 :                 *def_inp_color = RTE_COLOR_GREEN;
     261                 :          0 :         else if (strcasecmp(token, "Y") == 0)
     262                 :          0 :                 *def_inp_color = RTE_COLOR_YELLOW;
     263                 :          0 :         else if (strcasecmp(token, "R") == 0)
     264                 :          0 :                 *def_inp_color = RTE_COLOR_RED;
     265                 :            :         else
     266                 :            :                 return -1;
     267                 :            : 
     268                 :            :         return 0;
     269                 :            : }
     270                 :            : 
     271                 :            : static int
     272                 :          0 : parse_meter_color_str(char *c_str, uint32_t *use_prev_meter_color,
     273                 :            :         enum rte_color **vlan_table, enum rte_color **dscp_table)
     274                 :            : {
     275                 :            :         char *token;
     276                 :          0 :         uint64_t previous_mtr_color = 0;
     277                 :            :         int ret;
     278                 :            : 
     279                 :            :         /* First token: use previous meter color */
     280                 :          0 :         token = strtok_r(c_str, PARSE_DELIMITER, &c_str);
     281                 :          0 :         if (token ==  NULL)
     282                 :            :                 return -1;
     283                 :            : 
     284                 :          0 :         ret = parse_uint(&previous_mtr_color, token);
     285                 :          0 :         if (ret != 0)
     286                 :            :                 return -1;
     287                 :            : 
     288                 :            :         /* Check if previous meter color to be used */
     289                 :          0 :         if (previous_mtr_color) {
     290                 :          0 :                 *use_prev_meter_color = previous_mtr_color;
     291                 :          0 :                 return 0;
     292                 :            :         }
     293                 :            : 
     294                 :          0 :         ret = parse_input_color_table_entries(c_str, dscp_table, vlan_table);
     295                 :          0 :         if (ret != 0)
     296                 :          0 :                 return -1;
     297                 :            : 
     298                 :            :         return 0;
     299                 :            : }
     300                 :            : 
     301                 :            : static int
     302                 :          0 : parse_multi_token_string(char *t_str, uint16_t *port_id, uint32_t *mtr_id,
     303                 :            :         enum rte_mtr_color_in_protocol *proto, enum rte_color **dscp_table)
     304                 :            : {
     305                 :            :         char *token;
     306                 :            :         uint64_t val;
     307                 :            :         int ret;
     308                 :            : 
     309                 :            :         /* First token: port id */
     310                 :          0 :         token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
     311                 :          0 :         if (token ==  NULL)
     312                 :            :                 return -1;
     313                 :            : 
     314                 :          0 :         ret = parse_uint(&val, token);
     315                 :          0 :         if (ret != 0 || val > UINT16_MAX)
     316                 :            :                 return -1;
     317                 :            : 
     318                 :          0 :         *port_id = val;
     319                 :            : 
     320                 :            :         /* Second token: meter id */
     321                 :          0 :         token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
     322                 :          0 :         if (token == NULL)
     323                 :            :                 return 0;
     324                 :            : 
     325                 :          0 :         ret = parse_uint(&val, token);
     326                 :          0 :         if (ret != 0 || val > UINT32_MAX)
     327                 :            :                 return -1;
     328                 :            : 
     329                 :          0 :         *mtr_id = val;
     330                 :            : 
     331                 :            :         /* Third token: protocol  */
     332                 :          0 :         token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
     333                 :          0 :         if (token == NULL)
     334                 :            :                 return 0;
     335                 :            : 
     336                 :          0 :         if (strcmp(token, "outer_ip") == 0)
     337                 :          0 :                 *proto = RTE_MTR_COLOR_IN_PROTO_OUTER_IP;
     338                 :          0 :         else if (strcmp(token, "inner_ip") == 0)
     339                 :          0 :                 *proto = RTE_MTR_COLOR_IN_PROTO_INNER_IP;
     340                 :            : 
     341                 :          0 :         ret = parse_dscp_table_entries(t_str, dscp_table);
     342                 :          0 :         if (ret != 0)
     343                 :          0 :                 return -1;
     344                 :            : 
     345                 :            :         return 0;
     346                 :            : }
     347                 :            : 
     348                 :            : static int
     349                 :          0 : parse_multi_token_vlan_str(char *t_str, uint16_t *port_id, uint32_t *mtr_id,
     350                 :            :         enum rte_mtr_color_in_protocol *proto, enum rte_color **vlan_table)
     351                 :            : {
     352                 :            :         uint64_t val;
     353                 :            :         char *token;
     354                 :            :         int ret;
     355                 :            : 
     356                 :            :         /* First token: port id */
     357                 :          0 :         token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
     358                 :          0 :         if (token ==  NULL)
     359                 :            :                 return -1;
     360                 :            : 
     361                 :          0 :         ret = parse_uint(&val, token);
     362                 :          0 :         if (ret != 0 || val > UINT16_MAX)
     363                 :            :                 return -1;
     364                 :            : 
     365                 :          0 :         *port_id = val;
     366                 :            : 
     367                 :            :         /* Second token: meter id */
     368                 :          0 :         token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
     369                 :          0 :         if (token == NULL)
     370                 :            :                 return 0;
     371                 :            : 
     372                 :          0 :         ret = parse_uint(&val, token);
     373                 :          0 :         if (ret != 0 || val > UINT32_MAX)
     374                 :            :                 return -1;
     375                 :            : 
     376                 :          0 :         *mtr_id = val;
     377                 :            : 
     378                 :            :         /* Third token: protocol  */
     379                 :          0 :         token = strtok_r(t_str, PARSE_DELIMITER, &t_str);
     380                 :          0 :         if (token == NULL)
     381                 :            :                 return 0;
     382                 :            : 
     383                 :          0 :         if (strcmp(token, "outer_vlan") == 0)
     384                 :          0 :                 *proto = RTE_MTR_COLOR_IN_PROTO_OUTER_VLAN;
     385                 :          0 :         else if (strcmp(token, "inner_vlan") == 0)
     386                 :          0 :                 *proto = RTE_MTR_COLOR_IN_PROTO_INNER_VLAN;
     387                 :            : 
     388                 :          0 :         ret = parse_vlan_table_entries(t_str, vlan_table);
     389                 :          0 :         if (ret != 0)
     390                 :          0 :                 return -1;
     391                 :            : 
     392                 :            :         return 0;
     393                 :            : }
     394                 :            : 
     395                 :            : /* *** Show Port Meter Capabilities *** */
     396                 :            : struct cmd_show_port_meter_cap_result {
     397                 :            :         cmdline_fixed_string_t show;
     398                 :            :         cmdline_fixed_string_t port;
     399                 :            :         cmdline_fixed_string_t meter;
     400                 :            :         cmdline_fixed_string_t cap;
     401                 :            :         uint16_t port_id;
     402                 :            : };
     403                 :            : 
     404                 :            : static cmdline_parse_token_string_t cmd_show_port_meter_cap_show =
     405                 :            :         TOKEN_STRING_INITIALIZER(
     406                 :            :                 struct cmd_show_port_meter_cap_result, show, "show");
     407                 :            : static cmdline_parse_token_string_t cmd_show_port_meter_cap_port =
     408                 :            :         TOKEN_STRING_INITIALIZER(
     409                 :            :                 struct cmd_show_port_meter_cap_result, port, "port");
     410                 :            : static cmdline_parse_token_string_t cmd_show_port_meter_cap_meter =
     411                 :            :         TOKEN_STRING_INITIALIZER(
     412                 :            :                 struct cmd_show_port_meter_cap_result, meter, "meter");
     413                 :            : static cmdline_parse_token_string_t cmd_show_port_meter_cap_cap =
     414                 :            :         TOKEN_STRING_INITIALIZER(
     415                 :            :                 struct cmd_show_port_meter_cap_result, cap, "cap");
     416                 :            : static cmdline_parse_token_num_t cmd_show_port_meter_cap_port_id =
     417                 :            :         TOKEN_NUM_INITIALIZER(
     418                 :            :                 struct cmd_show_port_meter_cap_result, port_id, RTE_UINT16);
     419                 :            : 
     420                 :          0 : static void cmd_show_port_meter_cap_parsed(void *parsed_result,
     421                 :            :         __rte_unused struct cmdline *cl,
     422                 :            :         __rte_unused void *data)
     423                 :            : {
     424                 :            :         struct cmd_show_port_meter_cap_result *res = parsed_result;
     425                 :            :         struct rte_mtr_capabilities cap;
     426                 :            :         struct rte_mtr_error error;
     427                 :          0 :         uint16_t port_id = res->port_id;
     428                 :            :         int ret;
     429                 :            : 
     430                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
     431                 :          0 :                 return;
     432                 :            : 
     433                 :            :         memset(&cap, 0, sizeof(struct rte_mtr_capabilities));
     434                 :          0 :         ret = rte_mtr_capabilities_get(port_id, &cap, &error);
     435                 :          0 :         if (ret) {
     436                 :          0 :                 print_err_msg(&error);
     437                 :          0 :                 return;
     438                 :            :         }
     439                 :            : 
     440                 :            :         printf("\n****   Port Meter Object Capabilities ****\n\n");
     441                 :          0 :         printf("cap.n_max %" PRIu32 "\n", cap.n_max);
     442                 :          0 :         printf("cap.n_shared_max %" PRIu32 "\n", cap.n_shared_max);
     443                 :          0 :         printf("cap.identical %" PRId32 "\n", cap.identical);
     444                 :          0 :         printf("cap.shared_identical %" PRId32 "\n",
     445                 :            :                 cap.shared_identical);
     446                 :          0 :         printf("cap.shared_n_flows_per_mtr_max %" PRIu32 "\n",
     447                 :            :                 cap.shared_n_flows_per_mtr_max);
     448                 :          0 :         printf("cap.chaining_n_mtrs_per_flow_max %" PRIu32 "\n",
     449                 :            :                 cap.chaining_n_mtrs_per_flow_max);
     450                 :          0 :         printf("cap.chaining_use_prev_mtr_color_supported %" PRId32 "\n",
     451                 :            :                 cap.chaining_use_prev_mtr_color_supported);
     452                 :          0 :         printf("cap.chaining_use_prev_mtr_color_enforced %" PRId32 "\n",
     453                 :            :                 cap.chaining_use_prev_mtr_color_enforced);
     454                 :          0 :         printf("cap.meter_srtcm_rfc2697_n_max %" PRIu32 "\n",
     455                 :            :                 cap.meter_srtcm_rfc2697_n_max);
     456                 :          0 :         printf("cap.meter_trtcm_rfc2698_n_max %" PRIu32 "\n",
     457                 :            :                 cap.meter_trtcm_rfc2698_n_max);
     458                 :          0 :         printf("cap.meter_trtcm_rfc4115_n_max %" PRIu32 "\n",
     459                 :            :                 cap.meter_trtcm_rfc4115_n_max);
     460                 :          0 :         printf("cap.meter_rate_max %" PRIu64 "\n", cap.meter_rate_max);
     461                 :          0 :         printf("cap.color_aware_srtcm_rfc2697_supported %" PRId32 "\n",
     462                 :            :                 cap.color_aware_srtcm_rfc2697_supported);
     463                 :          0 :         printf("cap.color_aware_trtcm_rfc2698_supported %" PRId32 "\n",
     464                 :            :                 cap.color_aware_trtcm_rfc2698_supported);
     465                 :          0 :         printf("cap.color_aware_trtcm_rfc4115_supported %" PRId32 "\n",
     466                 :            :                 cap.color_aware_trtcm_rfc4115_supported);
     467                 :          0 :         printf("cap.srtcm_rfc2697_byte_mode_supported %" PRId32 "\n",
     468                 :            :                 cap.srtcm_rfc2697_byte_mode_supported);
     469                 :          0 :         printf("cap.srtcm_rfc2697_packet_mode_supported %" PRId32 "\n",
     470                 :            :                 cap.srtcm_rfc2697_packet_mode_supported);
     471                 :          0 :         printf("cap.trtcm_rfc2698_byte_mode_supported %" PRId32 "\n",
     472                 :            :                 cap.trtcm_rfc2698_byte_mode_supported);
     473                 :          0 :         printf("cap.trtcm_rfc2698_packet_mode_supported %" PRId32 "\n",
     474                 :            :                 cap.trtcm_rfc2698_packet_mode_supported);
     475                 :          0 :         printf("cap.trtcm_rfc4115_byte_mode_supported %" PRId32 "\n",
     476                 :            :                 cap.trtcm_rfc4115_byte_mode_supported);
     477                 :          0 :         printf("cap.trtcm_rfc4115_packet_mode_supported %" PRId32 "\n",
     478                 :            :                 cap.trtcm_rfc4115_packet_mode_supported);
     479                 :          0 :         printf("cap.stats_mask %" PRIx64 "\n", cap.stats_mask);
     480                 :          0 :         printf("cap.input_color_proto_mask 0x%" PRIx64 "\n",
     481                 :            :                 cap.input_color_proto_mask);
     482                 :          0 :         printf("cap.separate_input_color_table_per_port %" PRId32 "\n",
     483                 :            :                 cap.separate_input_color_table_per_port);
     484                 :            : }
     485                 :            : 
     486                 :            : cmdline_parse_inst_t cmd_show_port_meter_cap = {
     487                 :            :         .f = cmd_show_port_meter_cap_parsed,
     488                 :            :         .data = NULL,
     489                 :            :         .help_str = "show port meter cap <port_id>",
     490                 :            :         .tokens = {
     491                 :            :                 (void *)&cmd_show_port_meter_cap_show,
     492                 :            :                 (void *)&cmd_show_port_meter_cap_port,
     493                 :            :                 (void *)&cmd_show_port_meter_cap_meter,
     494                 :            :                 (void *)&cmd_show_port_meter_cap_cap,
     495                 :            :                 (void *)&cmd_show_port_meter_cap_port_id,
     496                 :            :                 NULL,
     497                 :            :         },
     498                 :            : };
     499                 :            : 
     500                 :            : /* *** Add Port Meter Profile srtcm_rfc2697 *** */
     501                 :            : struct cmd_add_port_meter_profile_srtcm_result {
     502                 :            :         cmdline_fixed_string_t add;
     503                 :            :         cmdline_fixed_string_t port;
     504                 :            :         cmdline_fixed_string_t meter;
     505                 :            :         cmdline_fixed_string_t profile;
     506                 :            :         cmdline_fixed_string_t srtcm_rfc2697;
     507                 :            :         uint16_t port_id;
     508                 :            :         uint32_t profile_id;
     509                 :            :         uint64_t cir;
     510                 :            :         uint64_t cbs;
     511                 :            :         uint64_t ebs;
     512                 :            :         int packet_mode;
     513                 :            : };
     514                 :            : 
     515                 :            : static cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_add =
     516                 :            :         TOKEN_STRING_INITIALIZER(
     517                 :            :                 struct cmd_add_port_meter_profile_srtcm_result, add, "add");
     518                 :            : static cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_port =
     519                 :            :         TOKEN_STRING_INITIALIZER(
     520                 :            :                 struct cmd_add_port_meter_profile_srtcm_result,
     521                 :            :                         port, "port");
     522                 :            : static cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_meter =
     523                 :            :         TOKEN_STRING_INITIALIZER(
     524                 :            :                 struct cmd_add_port_meter_profile_srtcm_result,
     525                 :            :                         meter, "meter");
     526                 :            : static cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_profile =
     527                 :            :         TOKEN_STRING_INITIALIZER(
     528                 :            :                 struct cmd_add_port_meter_profile_srtcm_result,
     529                 :            :                         profile, "profile");
     530                 :            : static cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_srtcm_rfc2697 =
     531                 :            :         TOKEN_STRING_INITIALIZER(
     532                 :            :                 struct cmd_add_port_meter_profile_srtcm_result,
     533                 :            :                         srtcm_rfc2697, "srtcm_rfc2697");
     534                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_port_id =
     535                 :            :         TOKEN_NUM_INITIALIZER(
     536                 :            :                 struct cmd_add_port_meter_profile_srtcm_result,
     537                 :            :                         port_id, RTE_UINT16);
     538                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_profile_id =
     539                 :            :         TOKEN_NUM_INITIALIZER(
     540                 :            :                 struct cmd_add_port_meter_profile_srtcm_result,
     541                 :            :                         profile_id, RTE_UINT32);
     542                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cir =
     543                 :            :         TOKEN_NUM_INITIALIZER(
     544                 :            :                 struct cmd_add_port_meter_profile_srtcm_result,
     545                 :            :                         cir, RTE_UINT64);
     546                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cbs =
     547                 :            :         TOKEN_NUM_INITIALIZER(
     548                 :            :                 struct cmd_add_port_meter_profile_srtcm_result,
     549                 :            :                         cbs, RTE_UINT64);
     550                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_ebs =
     551                 :            :         TOKEN_NUM_INITIALIZER(
     552                 :            :                 struct cmd_add_port_meter_profile_srtcm_result,
     553                 :            :                         ebs, RTE_UINT64);
     554                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_packet_mode =
     555                 :            :         TOKEN_NUM_INITIALIZER(
     556                 :            :                 struct cmd_add_port_meter_profile_srtcm_result,
     557                 :            :                         packet_mode, RTE_UINT32);
     558                 :            : 
     559                 :          0 : static void cmd_add_port_meter_profile_srtcm_parsed(void *parsed_result,
     560                 :            :         __rte_unused struct cmdline *cl,
     561                 :            :         __rte_unused void *data)
     562                 :            : {
     563                 :            :         struct cmd_add_port_meter_profile_srtcm_result *res = parsed_result;
     564                 :            :         struct rte_mtr_meter_profile mp;
     565                 :            :         struct rte_mtr_error error;
     566                 :          0 :         uint32_t profile_id = res->profile_id;
     567                 :          0 :         uint16_t port_id = res->port_id;
     568                 :            :         int ret;
     569                 :            : 
     570                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
     571                 :          0 :                 return;
     572                 :            : 
     573                 :            :         /* Private shaper profile params */
     574                 :            :         memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
     575                 :          0 :         mp.alg = RTE_MTR_SRTCM_RFC2697;
     576                 :          0 :         mp.srtcm_rfc2697.cir = res->cir;
     577                 :          0 :         mp.srtcm_rfc2697.cbs = res->cbs;
     578                 :          0 :         mp.srtcm_rfc2697.ebs = res->ebs;
     579                 :          0 :         mp.packet_mode = res->packet_mode;
     580                 :            : 
     581                 :          0 :         ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
     582                 :          0 :         if (ret != 0) {
     583                 :          0 :                 print_err_msg(&error);
     584                 :          0 :                 return;
     585                 :            :         }
     586                 :            : }
     587                 :            : 
     588                 :            : cmdline_parse_inst_t cmd_add_port_meter_profile_srtcm = {
     589                 :            :         .f = cmd_add_port_meter_profile_srtcm_parsed,
     590                 :            :         .data = NULL,
     591                 :            :         .help_str = "add port meter profile srtcm_rfc2697 <port_id> <profile_id> <cir> <cbs> <ebs> <packet_mode>",
     592                 :            :         .tokens = {
     593                 :            :                 (void *)&cmd_add_port_meter_profile_srtcm_add,
     594                 :            :                 (void *)&cmd_add_port_meter_profile_srtcm_port,
     595                 :            :                 (void *)&cmd_add_port_meter_profile_srtcm_meter,
     596                 :            :                 (void *)&cmd_add_port_meter_profile_srtcm_profile,
     597                 :            :                 (void *)&cmd_add_port_meter_profile_srtcm_srtcm_rfc2697,
     598                 :            :                 (void *)&cmd_add_port_meter_profile_srtcm_port_id,
     599                 :            :                 (void *)&cmd_add_port_meter_profile_srtcm_profile_id,
     600                 :            :                 (void *)&cmd_add_port_meter_profile_srtcm_cir,
     601                 :            :                 (void *)&cmd_add_port_meter_profile_srtcm_cbs,
     602                 :            :                 (void *)&cmd_add_port_meter_profile_srtcm_ebs,
     603                 :            :                 (void *)&cmd_add_port_meter_profile_srtcm_packet_mode,
     604                 :            :                 NULL,
     605                 :            :         },
     606                 :            : };
     607                 :            : 
     608                 :            : /* *** Add Port Meter Profile trtcm_rfc2698 *** */
     609                 :            : struct cmd_add_port_meter_profile_trtcm_result {
     610                 :            :         cmdline_fixed_string_t add;
     611                 :            :         cmdline_fixed_string_t port;
     612                 :            :         cmdline_fixed_string_t meter;
     613                 :            :         cmdline_fixed_string_t profile;
     614                 :            :         cmdline_fixed_string_t trtcm_rfc2698;
     615                 :            :         uint16_t port_id;
     616                 :            :         uint32_t profile_id;
     617                 :            :         uint64_t cir;
     618                 :            :         uint64_t pir;
     619                 :            :         uint64_t cbs;
     620                 :            :         uint64_t pbs;
     621                 :            :         int packet_mode;
     622                 :            : };
     623                 :            : 
     624                 :            : static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_add =
     625                 :            :         TOKEN_STRING_INITIALIZER(
     626                 :            :                 struct cmd_add_port_meter_profile_trtcm_result, add, "add");
     627                 :            : static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_port =
     628                 :            :         TOKEN_STRING_INITIALIZER(
     629                 :            :                 struct cmd_add_port_meter_profile_trtcm_result,
     630                 :            :                         port, "port");
     631                 :            : static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_meter =
     632                 :            :         TOKEN_STRING_INITIALIZER(
     633                 :            :                 struct cmd_add_port_meter_profile_trtcm_result,
     634                 :            :                         meter, "meter");
     635                 :            : static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_profile =
     636                 :            :         TOKEN_STRING_INITIALIZER(
     637                 :            :                 struct cmd_add_port_meter_profile_trtcm_result,
     638                 :            :                         profile, "profile");
     639                 :            : static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_trtcm_rfc2698 =
     640                 :            :         TOKEN_STRING_INITIALIZER(
     641                 :            :                 struct cmd_add_port_meter_profile_trtcm_result,
     642                 :            :                         trtcm_rfc2698, "trtcm_rfc2698");
     643                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_port_id =
     644                 :            :         TOKEN_NUM_INITIALIZER(
     645                 :            :                 struct cmd_add_port_meter_profile_trtcm_result,
     646                 :            :                         port_id, RTE_UINT16);
     647                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_profile_id =
     648                 :            :         TOKEN_NUM_INITIALIZER(
     649                 :            :                 struct cmd_add_port_meter_profile_trtcm_result,
     650                 :            :                         profile_id, RTE_UINT32);
     651                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cir =
     652                 :            :         TOKEN_NUM_INITIALIZER(
     653                 :            :                 struct cmd_add_port_meter_profile_trtcm_result,
     654                 :            :                         cir, RTE_UINT64);
     655                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pir =
     656                 :            :         TOKEN_NUM_INITIALIZER(
     657                 :            :                 struct cmd_add_port_meter_profile_trtcm_result,
     658                 :            :                         pir, RTE_UINT64);
     659                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cbs =
     660                 :            :         TOKEN_NUM_INITIALIZER(
     661                 :            :                 struct cmd_add_port_meter_profile_trtcm_result,
     662                 :            :                         cbs, RTE_UINT64);
     663                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pbs =
     664                 :            :         TOKEN_NUM_INITIALIZER(
     665                 :            :                 struct cmd_add_port_meter_profile_trtcm_result,
     666                 :            :                         pbs, RTE_UINT64);
     667                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_packet_mode =
     668                 :            :         TOKEN_NUM_INITIALIZER(
     669                 :            :                 struct cmd_add_port_meter_profile_trtcm_result,
     670                 :            :                         packet_mode, RTE_UINT32);
     671                 :            : 
     672                 :          0 : static void cmd_add_port_meter_profile_trtcm_parsed(void *parsed_result,
     673                 :            :         __rte_unused struct cmdline *cl,
     674                 :            :         __rte_unused void *data)
     675                 :            : {
     676                 :            :         struct cmd_add_port_meter_profile_trtcm_result *res = parsed_result;
     677                 :            :         struct rte_mtr_meter_profile mp;
     678                 :            :         struct rte_mtr_error error;
     679                 :          0 :         uint32_t profile_id = res->profile_id;
     680                 :          0 :         uint16_t port_id = res->port_id;
     681                 :            :         int ret;
     682                 :            : 
     683                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
     684                 :          0 :                 return;
     685                 :            : 
     686                 :            :         /* Private shaper profile params */
     687                 :            :         memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
     688                 :          0 :         mp.alg = RTE_MTR_TRTCM_RFC2698;
     689                 :          0 :         mp.trtcm_rfc2698.cir = res->cir;
     690                 :          0 :         mp.trtcm_rfc2698.pir = res->pir;
     691                 :          0 :         mp.trtcm_rfc2698.cbs = res->cbs;
     692                 :          0 :         mp.trtcm_rfc2698.pbs = res->pbs;
     693                 :          0 :         mp.packet_mode = res->packet_mode;
     694                 :            : 
     695                 :          0 :         ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
     696                 :          0 :         if (ret != 0) {
     697                 :          0 :                 print_err_msg(&error);
     698                 :          0 :                 return;
     699                 :            :         }
     700                 :            : }
     701                 :            : 
     702                 :            : cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm = {
     703                 :            :         .f = cmd_add_port_meter_profile_trtcm_parsed,
     704                 :            :         .data = NULL,
     705                 :            :         .help_str = "add port meter profile trtcm_rfc2698 <port_id> <profile_id> <cir> <pir> <cbs> <pbs> <packet_mode>",
     706                 :            :         .tokens = {
     707                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_add,
     708                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_port,
     709                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_meter,
     710                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_profile,
     711                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_trtcm_rfc2698,
     712                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_port_id,
     713                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_profile_id,
     714                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_cir,
     715                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_pir,
     716                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_cbs,
     717                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_pbs,
     718                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_packet_mode,
     719                 :            :                 NULL,
     720                 :            :         },
     721                 :            : };
     722                 :            : 
     723                 :            : /* *** Add Port Meter Profile trtcm_rfc4115 *** */
     724                 :            : struct cmd_add_port_meter_profile_trtcm_rfc4115_result {
     725                 :            :         cmdline_fixed_string_t add;
     726                 :            :         cmdline_fixed_string_t port;
     727                 :            :         cmdline_fixed_string_t meter;
     728                 :            :         cmdline_fixed_string_t profile;
     729                 :            :         cmdline_fixed_string_t trtcm_rfc4115;
     730                 :            :         uint16_t port_id;
     731                 :            :         uint32_t profile_id;
     732                 :            :         uint64_t cir;
     733                 :            :         uint64_t eir;
     734                 :            :         uint64_t cbs;
     735                 :            :         uint64_t ebs;
     736                 :            :         int packet_mode;
     737                 :            : };
     738                 :            : 
     739                 :            : static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_add =
     740                 :            :         TOKEN_STRING_INITIALIZER(
     741                 :            :                 struct cmd_add_port_meter_profile_trtcm_rfc4115_result, add,
     742                 :            :                 "add");
     743                 :            : static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_port =
     744                 :            :         TOKEN_STRING_INITIALIZER(
     745                 :            :                 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
     746                 :            :                         port, "port");
     747                 :            : static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_meter =
     748                 :            :         TOKEN_STRING_INITIALIZER(
     749                 :            :                 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
     750                 :            :                         meter, "meter");
     751                 :            : static cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_profile =
     752                 :            :         TOKEN_STRING_INITIALIZER(
     753                 :            :                 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
     754                 :            :                         profile, "profile");
     755                 :            : static cmdline_parse_token_string_t
     756                 :            :         cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115 =
     757                 :            :         TOKEN_STRING_INITIALIZER(
     758                 :            :                 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
     759                 :            :                         trtcm_rfc4115, "trtcm_rfc4115");
     760                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_port_id =
     761                 :            :         TOKEN_NUM_INITIALIZER(
     762                 :            :                 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
     763                 :            :                         port_id, RTE_UINT16);
     764                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_profile_id =
     765                 :            :         TOKEN_NUM_INITIALIZER(
     766                 :            :                 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
     767                 :            :                         profile_id, RTE_UINT32);
     768                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cir =
     769                 :            :         TOKEN_NUM_INITIALIZER(
     770                 :            :                 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
     771                 :            :                         cir, RTE_UINT64);
     772                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_eir =
     773                 :            :         TOKEN_NUM_INITIALIZER(
     774                 :            :                 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
     775                 :            :                         eir, RTE_UINT64);
     776                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cbs =
     777                 :            :         TOKEN_NUM_INITIALIZER(
     778                 :            :                 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
     779                 :            :                         cbs, RTE_UINT64);
     780                 :            : static cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_ebs =
     781                 :            :         TOKEN_NUM_INITIALIZER(
     782                 :            :                 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
     783                 :            :                         ebs, RTE_UINT64);
     784                 :            : static cmdline_parse_token_num_t
     785                 :            :         cmd_add_port_meter_profile_trtcm_rfc4115_packet_mode =
     786                 :            :         TOKEN_NUM_INITIALIZER(
     787                 :            :                 struct cmd_add_port_meter_profile_trtcm_rfc4115_result,
     788                 :            :                         packet_mode, RTE_UINT32);
     789                 :            : 
     790                 :          0 : static void cmd_add_port_meter_profile_trtcm_rfc4115_parsed(
     791                 :            :         void *parsed_result,
     792                 :            :         __rte_unused struct cmdline *cl,
     793                 :            :         __rte_unused void *data)
     794                 :            : {
     795                 :            :         struct cmd_add_port_meter_profile_trtcm_rfc4115_result *res =
     796                 :            :                 parsed_result;
     797                 :            :         struct rte_mtr_meter_profile mp;
     798                 :            :         struct rte_mtr_error error;
     799                 :          0 :         uint32_t profile_id = res->profile_id;
     800                 :          0 :         uint16_t port_id = res->port_id;
     801                 :            :         int ret;
     802                 :            : 
     803                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
     804                 :          0 :                 return;
     805                 :            : 
     806                 :            :         /* Private shaper profile params */
     807                 :            :         memset(&mp, 0, sizeof(struct rte_mtr_meter_profile));
     808                 :          0 :         mp.alg = RTE_MTR_TRTCM_RFC4115;
     809                 :          0 :         mp.trtcm_rfc4115.cir = res->cir;
     810                 :          0 :         mp.trtcm_rfc4115.eir = res->eir;
     811                 :          0 :         mp.trtcm_rfc4115.cbs = res->cbs;
     812                 :          0 :         mp.trtcm_rfc4115.ebs = res->ebs;
     813                 :          0 :         mp.packet_mode = res->packet_mode;
     814                 :            : 
     815                 :          0 :         ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error);
     816                 :          0 :         if (ret != 0) {
     817                 :          0 :                 print_err_msg(&error);
     818                 :          0 :                 return;
     819                 :            :         }
     820                 :            : }
     821                 :            : 
     822                 :            : cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm_rfc4115 = {
     823                 :            :         .f = cmd_add_port_meter_profile_trtcm_rfc4115_parsed,
     824                 :            :         .data = NULL,
     825                 :            :         .help_str = "add port meter profile trtcm_rfc4115 <port_id> <profile_id> <cir> <eir> <cbs> <ebs> <packet_mode>",
     826                 :            :         .tokens = {
     827                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_add,
     828                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port,
     829                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_meter,
     830                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile,
     831                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115,
     832                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port_id,
     833                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile_id,
     834                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cir,
     835                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_eir,
     836                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cbs,
     837                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_ebs,
     838                 :            :                 (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_packet_mode,
     839                 :            :                 NULL,
     840                 :            :         },
     841                 :            : };
     842                 :            : 
     843                 :            : /* *** Delete Port Meter Profile *** */
     844                 :            : struct cmd_del_port_meter_profile_result {
     845                 :            :         cmdline_fixed_string_t del;
     846                 :            :         cmdline_fixed_string_t port;
     847                 :            :         cmdline_fixed_string_t meter;
     848                 :            :         cmdline_fixed_string_t profile;
     849                 :            :         uint16_t port_id;
     850                 :            :         uint32_t profile_id;
     851                 :            : };
     852                 :            : 
     853                 :            : static cmdline_parse_token_string_t cmd_del_port_meter_profile_del =
     854                 :            :         TOKEN_STRING_INITIALIZER(
     855                 :            :                 struct cmd_del_port_meter_profile_result, del, "del");
     856                 :            : static cmdline_parse_token_string_t cmd_del_port_meter_profile_port =
     857                 :            :         TOKEN_STRING_INITIALIZER(
     858                 :            :                 struct cmd_del_port_meter_profile_result,
     859                 :            :                         port, "port");
     860                 :            : static cmdline_parse_token_string_t cmd_del_port_meter_profile_meter =
     861                 :            :         TOKEN_STRING_INITIALIZER(
     862                 :            :                 struct cmd_del_port_meter_profile_result,
     863                 :            :                         meter, "meter");
     864                 :            : static cmdline_parse_token_string_t cmd_del_port_meter_profile_profile =
     865                 :            :         TOKEN_STRING_INITIALIZER(
     866                 :            :                 struct cmd_del_port_meter_profile_result,
     867                 :            :                         profile, "profile");
     868                 :            : static cmdline_parse_token_num_t cmd_del_port_meter_profile_port_id =
     869                 :            :         TOKEN_NUM_INITIALIZER(
     870                 :            :                 struct cmd_del_port_meter_profile_result,
     871                 :            :                         port_id, RTE_UINT16);
     872                 :            : static cmdline_parse_token_num_t cmd_del_port_meter_profile_profile_id =
     873                 :            :         TOKEN_NUM_INITIALIZER(
     874                 :            :                 struct cmd_del_port_meter_profile_result,
     875                 :            :                         profile_id, RTE_UINT32);
     876                 :            : 
     877                 :          0 : static void cmd_del_port_meter_profile_parsed(void *parsed_result,
     878                 :            :         __rte_unused struct cmdline *cl,
     879                 :            :         __rte_unused void *data)
     880                 :            : {
     881                 :            :         struct cmd_del_port_meter_profile_result *res = parsed_result;
     882                 :            :         struct rte_mtr_error error;
     883                 :          0 :         uint32_t profile_id = res->profile_id;
     884                 :          0 :         uint16_t port_id = res->port_id;
     885                 :            :         int ret;
     886                 :            : 
     887                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
     888                 :          0 :                 return;
     889                 :            : 
     890                 :            :         /* Delete meter profile */
     891                 :          0 :         ret = rte_mtr_meter_profile_delete(port_id, profile_id, &error);
     892                 :          0 :         if (ret != 0) {
     893                 :          0 :                 print_err_msg(&error);
     894                 :          0 :                 return;
     895                 :            :         }
     896                 :            : }
     897                 :            : 
     898                 :            : cmdline_parse_inst_t cmd_del_port_meter_profile = {
     899                 :            :         .f = cmd_del_port_meter_profile_parsed,
     900                 :            :         .data = NULL,
     901                 :            :         .help_str = "del port meter profile <port_id> <profile_id>",
     902                 :            :         .tokens = {
     903                 :            :                 (void *)&cmd_del_port_meter_profile_del,
     904                 :            :                 (void *)&cmd_del_port_meter_profile_port,
     905                 :            :                 (void *)&cmd_del_port_meter_profile_meter,
     906                 :            :                 (void *)&cmd_del_port_meter_profile_profile,
     907                 :            :                 (void *)&cmd_del_port_meter_profile_port_id,
     908                 :            :                 (void *)&cmd_del_port_meter_profile_profile_id,
     909                 :            :                 NULL,
     910                 :            :         },
     911                 :            : };
     912                 :            : 
     913                 :            : /* *** Create Port Meter Object *** */
     914                 :            : struct cmd_create_port_meter_result {
     915                 :            :         cmdline_fixed_string_t create;
     916                 :            :         cmdline_fixed_string_t port;
     917                 :            :         cmdline_fixed_string_t meter;
     918                 :            :         uint16_t port_id;
     919                 :            :         uint32_t mtr_id;
     920                 :            :         uint32_t profile_id;
     921                 :            :         uint32_t policy_id;
     922                 :            :         cmdline_fixed_string_t meter_enable;
     923                 :            :         cmdline_fixed_string_t g_action;
     924                 :            :         cmdline_fixed_string_t y_action;
     925                 :            :         cmdline_fixed_string_t r_action;
     926                 :            :         uint64_t statistics_mask;
     927                 :            :         uint32_t shared;
     928                 :            :         cmdline_fixed_string_t default_input_color;
     929                 :            :         cmdline_multi_string_t meter_input_color;
     930                 :            : };
     931                 :            : 
     932                 :            : static cmdline_parse_token_string_t cmd_create_port_meter_create =
     933                 :            :         TOKEN_STRING_INITIALIZER(
     934                 :            :                 struct cmd_create_port_meter_result, create, "create");
     935                 :            : static cmdline_parse_token_string_t cmd_create_port_meter_port =
     936                 :            :         TOKEN_STRING_INITIALIZER(
     937                 :            :                 struct cmd_create_port_meter_result, port, "port");
     938                 :            : static cmdline_parse_token_string_t cmd_create_port_meter_meter =
     939                 :            :         TOKEN_STRING_INITIALIZER(
     940                 :            :                 struct cmd_create_port_meter_result, meter, "meter");
     941                 :            : static cmdline_parse_token_num_t cmd_create_port_meter_port_id =
     942                 :            :         TOKEN_NUM_INITIALIZER(
     943                 :            :                 struct cmd_create_port_meter_result, port_id, RTE_UINT16);
     944                 :            : static cmdline_parse_token_num_t cmd_create_port_meter_mtr_id =
     945                 :            :         TOKEN_NUM_INITIALIZER(
     946                 :            :                 struct cmd_create_port_meter_result, mtr_id, RTE_UINT32);
     947                 :            : static cmdline_parse_token_num_t cmd_create_port_meter_profile_id =
     948                 :            :         TOKEN_NUM_INITIALIZER(
     949                 :            :                 struct cmd_create_port_meter_result, profile_id, RTE_UINT32);
     950                 :            : static cmdline_parse_token_num_t cmd_create_port_meter_policy_id =
     951                 :            :         TOKEN_NUM_INITIALIZER(
     952                 :            :                 struct cmd_create_port_meter_result, policy_id, RTE_UINT32);
     953                 :            : static cmdline_parse_token_string_t cmd_create_port_meter_meter_enable =
     954                 :            :         TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
     955                 :            :                 meter_enable, "yes#no");
     956                 :            : static cmdline_parse_token_num_t cmd_create_port_meter_statistics_mask =
     957                 :            :         TOKEN_NUM_INITIALIZER(struct cmd_create_port_meter_result,
     958                 :            :                 statistics_mask, RTE_UINT64);
     959                 :            : static cmdline_parse_token_num_t cmd_create_port_meter_shared =
     960                 :            :         TOKEN_NUM_INITIALIZER(struct cmd_create_port_meter_result,
     961                 :            :                 shared, RTE_UINT32);
     962                 :            : static cmdline_parse_token_string_t cmd_create_port_meter_default_input_color =
     963                 :            :         TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
     964                 :            :                 default_input_color, "R#Y#G#r#y#g");
     965                 :            : static cmdline_parse_token_string_t cmd_create_port_meter_input_color =
     966                 :            :         TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result,
     967                 :            :                 meter_input_color, TOKEN_STRING_MULTI);
     968                 :            : 
     969                 :          0 : static void cmd_create_port_meter_parsed(void *parsed_result,
     970                 :            :         __rte_unused struct cmdline *cl,
     971                 :            :         __rte_unused void *data)
     972                 :            : {
     973                 :            :         struct cmd_create_port_meter_result *res = parsed_result;
     974                 :            :         struct rte_mtr_error error;
     975                 :            :         struct rte_mtr_params params;
     976                 :          0 :         uint32_t mtr_id = res->mtr_id;
     977                 :          0 :         uint32_t shared = res->shared;
     978                 :          0 :         uint32_t use_prev_meter_color = 0;
     979                 :          0 :         uint16_t port_id = res->port_id;
     980                 :          0 :         uint64_t def_inp_color = 0;
     981                 :          0 :         enum rte_color *dscp_table = NULL;
     982                 :          0 :         enum rte_color *vlan_table = NULL;
     983                 :          0 :         char *def_color_str = res->default_input_color;
     984                 :          0 :         char *c_str = res->meter_input_color;
     985                 :            :         int ret;
     986                 :            : 
     987                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
     988                 :          0 :                 return;
     989                 :            : 
     990                 :            :         /* Meter params */
     991                 :            :         memset(&params, 0, sizeof(struct rte_mtr_params));
     992                 :          0 :         params.meter_profile_id = res->profile_id;
     993                 :          0 :         params.meter_policy_id = res->policy_id;
     994                 :            : 
     995                 :            :         /* Parse meter default input color string params */
     996                 :          0 :         ret = parse_default_input_color_str(def_color_str, &def_inp_color);
     997                 :          0 :         if (ret) {
     998                 :          0 :                 fprintf(stderr,
     999                 :            :                         " Meter default input color is invalid\n");
    1000                 :          0 :                 return;
    1001                 :            :         }
    1002                 :            : 
    1003                 :            :         /* Parse meter input color string params */
    1004                 :          0 :         ret = parse_meter_color_str(c_str, &use_prev_meter_color, &vlan_table,
    1005                 :            :                 &dscp_table);
    1006                 :          0 :         if (ret) {
    1007                 :          0 :                 fprintf(stderr,
    1008                 :            :                         " Meter input color params string parse error\n");
    1009                 :          0 :                 return;
    1010                 :            :         }
    1011                 :            : 
    1012                 :          0 :         params.use_prev_mtr_color = use_prev_meter_color;
    1013                 :          0 :         params.vlan_table = vlan_table;
    1014                 :          0 :         params.dscp_table = dscp_table;
    1015                 :          0 :         params.default_input_color = def_inp_color;
    1016                 :            : 
    1017                 :          0 :         if (strcmp(res->meter_enable, "yes") == 0)
    1018                 :          0 :                 params.meter_enable = 1;
    1019                 :            :         else
    1020                 :          0 :                 params.meter_enable = 0;
    1021                 :            : 
    1022                 :          0 :         params.stats_mask = res->statistics_mask;
    1023                 :            : 
    1024                 :          0 :         ret = rte_mtr_create(port_id, mtr_id, &params, shared, &error);
    1025                 :          0 :         if (ret != 0) {
    1026                 :          0 :                 free(vlan_table);
    1027                 :          0 :                 free(dscp_table);
    1028                 :          0 :                 print_err_msg(&error);
    1029                 :          0 :                 return;
    1030                 :            :         }
    1031                 :            : }
    1032                 :            : 
    1033                 :            : cmdline_parse_inst_t cmd_create_port_meter = {
    1034                 :            :         .f = cmd_create_port_meter_parsed,
    1035                 :            :         .data = NULL,
    1036                 :            :         .help_str = "create port meter <port_id> <mtr_id> <profile_id> <policy_id> "
    1037                 :            :                 "<meter_enable>(yes|no) <stats_mask> <shared> "
    1038                 :            :                 "<default_input_color>(g|y|r) <use_pre_meter_color> "
    1039                 :            :                 "[<dscp_tbl_entry0> <dscp_tbl_entry1> ...<dscp_tbl_entry63>] "
    1040                 :            :                 "[<vlan_tbl_entry0> <vlan_tbl_entry1> ... <vlan_tbl_entry15>]",
    1041                 :            :         .tokens = {
    1042                 :            :                 (void *)&cmd_create_port_meter_create,
    1043                 :            :                 (void *)&cmd_create_port_meter_port,
    1044                 :            :                 (void *)&cmd_create_port_meter_meter,
    1045                 :            :                 (void *)&cmd_create_port_meter_port_id,
    1046                 :            :                 (void *)&cmd_create_port_meter_mtr_id,
    1047                 :            :                 (void *)&cmd_create_port_meter_profile_id,
    1048                 :            :                 (void *)&cmd_create_port_meter_policy_id,
    1049                 :            :                 (void *)&cmd_create_port_meter_meter_enable,
    1050                 :            :                 (void *)&cmd_create_port_meter_statistics_mask,
    1051                 :            :                 (void *)&cmd_create_port_meter_shared,
    1052                 :            :                 (void *)&cmd_create_port_meter_default_input_color,
    1053                 :            :                 (void *)&cmd_create_port_meter_input_color,
    1054                 :            :                 NULL,
    1055                 :            :         },
    1056                 :            : };
    1057                 :            : 
    1058                 :            : /* *** Enable Meter of MTR Object  *** */
    1059                 :            : struct cmd_enable_port_meter_result {
    1060                 :            :         cmdline_fixed_string_t enable;
    1061                 :            :         cmdline_fixed_string_t port;
    1062                 :            :         cmdline_fixed_string_t meter;
    1063                 :            :         uint16_t port_id;
    1064                 :            :         uint32_t mtr_id;
    1065                 :            : };
    1066                 :            : 
    1067                 :            : static cmdline_parse_token_string_t cmd_enable_port_meter_enable =
    1068                 :            :         TOKEN_STRING_INITIALIZER(
    1069                 :            :                 struct cmd_enable_port_meter_result, enable, "enable");
    1070                 :            : static cmdline_parse_token_string_t cmd_enable_port_meter_port =
    1071                 :            :         TOKEN_STRING_INITIALIZER(
    1072                 :            :                 struct cmd_enable_port_meter_result, port, "port");
    1073                 :            : static cmdline_parse_token_string_t cmd_enable_port_meter_meter =
    1074                 :            :         TOKEN_STRING_INITIALIZER(
    1075                 :            :                 struct cmd_enable_port_meter_result, meter, "meter");
    1076                 :            : static cmdline_parse_token_num_t cmd_enable_port_meter_port_id =
    1077                 :            :         TOKEN_NUM_INITIALIZER(
    1078                 :            :                 struct cmd_enable_port_meter_result, port_id, RTE_UINT16);
    1079                 :            : static cmdline_parse_token_num_t cmd_enable_port_meter_mtr_id =
    1080                 :            :         TOKEN_NUM_INITIALIZER(
    1081                 :            :                 struct cmd_enable_port_meter_result, mtr_id, RTE_UINT32);
    1082                 :            : 
    1083                 :          0 : static void cmd_enable_port_meter_parsed(void *parsed_result,
    1084                 :            :         __rte_unused struct cmdline *cl,
    1085                 :            :         __rte_unused void *data)
    1086                 :            : {
    1087                 :            :         struct cmd_enable_port_meter_result *res = parsed_result;
    1088                 :            :         struct rte_mtr_error error;
    1089                 :          0 :         uint32_t mtr_id = res->mtr_id;
    1090                 :          0 :         uint16_t port_id = res->port_id;
    1091                 :            : 
    1092                 :            :         int ret;
    1093                 :            : 
    1094                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
    1095                 :          0 :                 return;
    1096                 :            : 
    1097                 :            :         /* Enable Meter */
    1098                 :          0 :         ret = rte_mtr_meter_enable(port_id, mtr_id, &error);
    1099                 :          0 :         if (ret != 0) {
    1100                 :          0 :                 print_err_msg(&error);
    1101                 :          0 :                 return;
    1102                 :            :         }
    1103                 :            : }
    1104                 :            : 
    1105                 :            : cmdline_parse_inst_t cmd_enable_port_meter = {
    1106                 :            :         .f = cmd_enable_port_meter_parsed,
    1107                 :            :         .data = NULL,
    1108                 :            :         .help_str = "enable port meter <port_id> <mtr_id>",
    1109                 :            :         .tokens = {
    1110                 :            :                 (void *)&cmd_enable_port_meter_enable,
    1111                 :            :                 (void *)&cmd_enable_port_meter_port,
    1112                 :            :                 (void *)&cmd_enable_port_meter_meter,
    1113                 :            :                 (void *)&cmd_enable_port_meter_port_id,
    1114                 :            :                 (void *)&cmd_enable_port_meter_mtr_id,
    1115                 :            :                 NULL,
    1116                 :            :         },
    1117                 :            : };
    1118                 :            : 
    1119                 :            : /* *** Disable Meter of MTR Object  *** */
    1120                 :            : struct cmd_disable_port_meter_result {
    1121                 :            :         cmdline_fixed_string_t disable;
    1122                 :            :         cmdline_fixed_string_t port;
    1123                 :            :         cmdline_fixed_string_t meter;
    1124                 :            :         uint16_t port_id;
    1125                 :            :         uint32_t mtr_id;
    1126                 :            : };
    1127                 :            : 
    1128                 :            : static cmdline_parse_token_string_t cmd_disable_port_meter_disable =
    1129                 :            :         TOKEN_STRING_INITIALIZER(
    1130                 :            :                 struct cmd_disable_port_meter_result, disable, "disable");
    1131                 :            : static cmdline_parse_token_string_t cmd_disable_port_meter_port =
    1132                 :            :         TOKEN_STRING_INITIALIZER(
    1133                 :            :                 struct cmd_disable_port_meter_result, port, "port");
    1134                 :            : static cmdline_parse_token_string_t cmd_disable_port_meter_meter =
    1135                 :            :         TOKEN_STRING_INITIALIZER(
    1136                 :            :                 struct cmd_disable_port_meter_result, meter, "meter");
    1137                 :            : static cmdline_parse_token_num_t cmd_disable_port_meter_port_id =
    1138                 :            :         TOKEN_NUM_INITIALIZER(
    1139                 :            :                 struct cmd_disable_port_meter_result, port_id, RTE_UINT16);
    1140                 :            : static cmdline_parse_token_num_t cmd_disable_port_meter_mtr_id =
    1141                 :            :         TOKEN_NUM_INITIALIZER(
    1142                 :            :                 struct cmd_disable_port_meter_result, mtr_id, RTE_UINT32);
    1143                 :            : 
    1144                 :          0 : static void cmd_disable_port_meter_parsed(void *parsed_result,
    1145                 :            :         __rte_unused struct cmdline *cl,
    1146                 :            :         __rte_unused void *data)
    1147                 :            : {
    1148                 :            :         struct cmd_disable_port_meter_result *res = parsed_result;
    1149                 :            :         struct rte_mtr_error error;
    1150                 :          0 :         uint32_t mtr_id = res->mtr_id;
    1151                 :          0 :         uint16_t port_id = res->port_id;
    1152                 :            : 
    1153                 :            :         int ret;
    1154                 :            : 
    1155                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
    1156                 :          0 :                 return;
    1157                 :            : 
    1158                 :            :         /* Disable Meter */
    1159                 :          0 :         ret = rte_mtr_meter_disable(port_id, mtr_id, &error);
    1160                 :          0 :         if (ret != 0) {
    1161                 :          0 :                 print_err_msg(&error);
    1162                 :          0 :                 return;
    1163                 :            :         }
    1164                 :            : }
    1165                 :            : 
    1166                 :            : cmdline_parse_inst_t cmd_disable_port_meter = {
    1167                 :            :         .f = cmd_disable_port_meter_parsed,
    1168                 :            :         .data = NULL,
    1169                 :            :         .help_str = "disable port meter <port_id> <mtr_id>",
    1170                 :            :         .tokens = {
    1171                 :            :                 (void *)&cmd_disable_port_meter_disable,
    1172                 :            :                 (void *)&cmd_disable_port_meter_port,
    1173                 :            :                 (void *)&cmd_disable_port_meter_meter,
    1174                 :            :                 (void *)&cmd_disable_port_meter_port_id,
    1175                 :            :                 (void *)&cmd_disable_port_meter_mtr_id,
    1176                 :            :                 NULL,
    1177                 :            :         },
    1178                 :            : };
    1179                 :            : 
    1180                 :            : /* *** Delete Port Meter Policy Object *** */
    1181                 :            : struct cmd_del_port_meter_policy_result {
    1182                 :            :         cmdline_fixed_string_t del;
    1183                 :            :         cmdline_fixed_string_t port;
    1184                 :            :         cmdline_fixed_string_t meter;
    1185                 :            :         cmdline_fixed_string_t policy;
    1186                 :            :         uint16_t port_id;
    1187                 :            :         uint32_t policy_id;
    1188                 :            : };
    1189                 :            : 
    1190                 :            : static cmdline_parse_token_string_t cmd_del_port_meter_policy_del =
    1191                 :            :         TOKEN_STRING_INITIALIZER(
    1192                 :            :                 struct cmd_del_port_meter_policy_result, del, "del");
    1193                 :            : static cmdline_parse_token_string_t cmd_del_port_meter_policy_port =
    1194                 :            :         TOKEN_STRING_INITIALIZER(
    1195                 :            :                 struct cmd_del_port_meter_policy_result, port, "port");
    1196                 :            : static cmdline_parse_token_string_t cmd_del_port_meter_policy_meter =
    1197                 :            :         TOKEN_STRING_INITIALIZER(
    1198                 :            :                 struct cmd_del_port_meter_policy_result, meter, "meter");
    1199                 :            : static cmdline_parse_token_string_t cmd_del_port_meter_policy_policy =
    1200                 :            :         TOKEN_STRING_INITIALIZER(
    1201                 :            :                 struct cmd_del_port_meter_policy_result, policy, "policy");
    1202                 :            : static cmdline_parse_token_num_t cmd_del_port_meter_policy_port_id =
    1203                 :            :         TOKEN_NUM_INITIALIZER(
    1204                 :            :                 struct cmd_del_port_meter_policy_result, port_id, RTE_UINT16);
    1205                 :            : static cmdline_parse_token_num_t cmd_del_port_meter_policy_policy_id =
    1206                 :            :         TOKEN_NUM_INITIALIZER(
    1207                 :            :                 struct cmd_del_port_meter_policy_result, policy_id, RTE_UINT32);
    1208                 :            : 
    1209                 :          0 : static void cmd_del_port_meter_policy_parsed(void *parsed_result,
    1210                 :            :         __rte_unused struct cmdline *cl,
    1211                 :            :         __rte_unused void *data)
    1212                 :            : {
    1213                 :            :         struct cmd_del_port_meter_policy_result *res = parsed_result;
    1214                 :            :         struct rte_mtr_error error;
    1215                 :          0 :         uint32_t policy_id = res->policy_id;
    1216                 :          0 :         uint16_t port_id = res->port_id;
    1217                 :            :         int ret;
    1218                 :            : 
    1219                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
    1220                 :          0 :                 return;
    1221                 :            : 
    1222                 :            :         /* Delete Meter Policy*/
    1223                 :          0 :         ret = rte_mtr_meter_policy_delete(port_id, policy_id, &error);
    1224                 :          0 :         if (ret != 0) {
    1225                 :          0 :                 print_err_msg(&error);
    1226                 :          0 :                 return;
    1227                 :            :         }
    1228                 :            : }
    1229                 :            : 
    1230                 :            : cmdline_parse_inst_t cmd_del_port_meter_policy = {
    1231                 :            :         .f = cmd_del_port_meter_policy_parsed,
    1232                 :            :         .data = NULL,
    1233                 :            :         .help_str = "Delete port meter policy",
    1234                 :            :         .tokens = {
    1235                 :            :                 (void *)&cmd_del_port_meter_policy_del,
    1236                 :            :                 (void *)&cmd_del_port_meter_policy_port,
    1237                 :            :                 (void *)&cmd_del_port_meter_policy_meter,
    1238                 :            :                 (void *)&cmd_del_port_meter_policy_policy,
    1239                 :            :                 (void *)&cmd_del_port_meter_policy_port_id,
    1240                 :            :                 (void *)&cmd_del_port_meter_policy_policy_id,
    1241                 :            :                 NULL,
    1242                 :            :         },
    1243                 :            : };
    1244                 :            : 
    1245                 :            : /* *** Delete Port Meter Object *** */
    1246                 :            : struct cmd_del_port_meter_result {
    1247                 :            :         cmdline_fixed_string_t del;
    1248                 :            :         cmdline_fixed_string_t port;
    1249                 :            :         cmdline_fixed_string_t meter;
    1250                 :            :         uint16_t port_id;
    1251                 :            :         uint32_t mtr_id;
    1252                 :            : };
    1253                 :            : 
    1254                 :            : static cmdline_parse_token_string_t cmd_del_port_meter_del =
    1255                 :            :         TOKEN_STRING_INITIALIZER(
    1256                 :            :                 struct cmd_del_port_meter_result, del, "del");
    1257                 :            : static cmdline_parse_token_string_t cmd_del_port_meter_port =
    1258                 :            :         TOKEN_STRING_INITIALIZER(
    1259                 :            :                 struct cmd_del_port_meter_result, port, "port");
    1260                 :            : static cmdline_parse_token_string_t cmd_del_port_meter_meter =
    1261                 :            :         TOKEN_STRING_INITIALIZER(
    1262                 :            :                 struct cmd_del_port_meter_result, meter, "meter");
    1263                 :            : static cmdline_parse_token_num_t cmd_del_port_meter_port_id =
    1264                 :            :         TOKEN_NUM_INITIALIZER(
    1265                 :            :                 struct cmd_del_port_meter_result, port_id, RTE_UINT16);
    1266                 :            : static cmdline_parse_token_num_t cmd_del_port_meter_mtr_id =
    1267                 :            :         TOKEN_NUM_INITIALIZER(
    1268                 :            :                 struct cmd_del_port_meter_result, mtr_id, RTE_UINT32);
    1269                 :            : 
    1270                 :          0 : static void cmd_del_port_meter_parsed(void *parsed_result,
    1271                 :            :         __rte_unused struct cmdline *cl,
    1272                 :            :         __rte_unused void *data)
    1273                 :            : {
    1274                 :            :         struct cmd_del_port_meter_result *res = parsed_result;
    1275                 :            :         struct rte_mtr_error error;
    1276                 :          0 :         uint32_t mtr_id = res->mtr_id;
    1277                 :          0 :         uint16_t port_id = res->port_id;
    1278                 :            : 
    1279                 :            :         int ret;
    1280                 :            : 
    1281                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
    1282                 :          0 :                 return;
    1283                 :            : 
    1284                 :            :         /* Destroy Meter */
    1285                 :          0 :         ret = rte_mtr_destroy(port_id, mtr_id, &error);
    1286                 :          0 :         if (ret != 0) {
    1287                 :          0 :                 print_err_msg(&error);
    1288                 :          0 :                 return;
    1289                 :            :         }
    1290                 :            : }
    1291                 :            : 
    1292                 :            : cmdline_parse_inst_t cmd_del_port_meter = {
    1293                 :            :         .f = cmd_del_port_meter_parsed,
    1294                 :            :         .data = NULL,
    1295                 :            :         .help_str = "del port meter <port_id> <mtr_id>",
    1296                 :            :         .tokens = {
    1297                 :            :                 (void *)&cmd_del_port_meter_del,
    1298                 :            :                 (void *)&cmd_del_port_meter_port,
    1299                 :            :                 (void *)&cmd_del_port_meter_meter,
    1300                 :            :                 (void *)&cmd_del_port_meter_port_id,
    1301                 :            :                 (void *)&cmd_del_port_meter_mtr_id,
    1302                 :            :                 NULL,
    1303                 :            :         },
    1304                 :            : };
    1305                 :            : 
    1306                 :            : /* *** Set Port Meter Profile *** */
    1307                 :            : struct cmd_set_port_meter_profile_result {
    1308                 :            :         cmdline_fixed_string_t set;
    1309                 :            :         cmdline_fixed_string_t port;
    1310                 :            :         cmdline_fixed_string_t meter;
    1311                 :            :         cmdline_fixed_string_t profile;
    1312                 :            :         uint16_t port_id;
    1313                 :            :         uint32_t mtr_id;
    1314                 :            :         uint32_t profile_id;
    1315                 :            : };
    1316                 :            : 
    1317                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_profile_set =
    1318                 :            :         TOKEN_STRING_INITIALIZER(
    1319                 :            :                 struct cmd_set_port_meter_profile_result, set, "set");
    1320                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_profile_port =
    1321                 :            :         TOKEN_STRING_INITIALIZER(
    1322                 :            :                 struct cmd_set_port_meter_profile_result, port, "port");
    1323                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_profile_meter =
    1324                 :            :         TOKEN_STRING_INITIALIZER(
    1325                 :            :                 struct cmd_set_port_meter_profile_result, meter, "meter");
    1326                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_profile_profile =
    1327                 :            :         TOKEN_STRING_INITIALIZER(
    1328                 :            :                 struct cmd_set_port_meter_profile_result, profile, "profile");
    1329                 :            : static cmdline_parse_token_num_t cmd_set_port_meter_profile_port_id =
    1330                 :            :         TOKEN_NUM_INITIALIZER(
    1331                 :            :                 struct cmd_set_port_meter_profile_result, port_id,
    1332                 :            :                 RTE_UINT16);
    1333                 :            : static cmdline_parse_token_num_t cmd_set_port_meter_profile_mtr_id =
    1334                 :            :         TOKEN_NUM_INITIALIZER(
    1335                 :            :                 struct cmd_set_port_meter_profile_result, mtr_id,
    1336                 :            :                 RTE_UINT32);
    1337                 :            : static cmdline_parse_token_num_t cmd_set_port_meter_profile_profile_id =
    1338                 :            :         TOKEN_NUM_INITIALIZER(
    1339                 :            :                 struct cmd_set_port_meter_profile_result, profile_id,
    1340                 :            :                 RTE_UINT32);
    1341                 :            : 
    1342                 :          0 : static void cmd_set_port_meter_profile_parsed(void *parsed_result,
    1343                 :            :         __rte_unused struct cmdline *cl,
    1344                 :            :         __rte_unused void *data)
    1345                 :            : {
    1346                 :            :         struct cmd_set_port_meter_profile_result *res = parsed_result;
    1347                 :            :         struct rte_mtr_error error;
    1348                 :          0 :         uint32_t mtr_id = res->mtr_id;
    1349                 :          0 :         uint32_t profile_id = res->profile_id;
    1350                 :          0 :         uint16_t port_id = res->port_id;
    1351                 :            : 
    1352                 :            :         int ret;
    1353                 :            : 
    1354                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
    1355                 :          0 :                 return;
    1356                 :            : 
    1357                 :            :         /* Set meter profile */
    1358                 :          0 :         ret = rte_mtr_meter_profile_update(port_id, mtr_id,
    1359                 :            :                 profile_id, &error);
    1360                 :          0 :         if (ret != 0) {
    1361                 :          0 :                 print_err_msg(&error);
    1362                 :          0 :                 return;
    1363                 :            :         }
    1364                 :            : }
    1365                 :            : 
    1366                 :            : cmdline_parse_inst_t cmd_set_port_meter_profile = {
    1367                 :            :         .f = cmd_set_port_meter_profile_parsed,
    1368                 :            :         .data = NULL,
    1369                 :            :         .help_str = "set port meter profile <port_id> <mtr_id> <profile_id>",
    1370                 :            :         .tokens = {
    1371                 :            :                 (void *)&cmd_set_port_meter_profile_set,
    1372                 :            :                 (void *)&cmd_set_port_meter_profile_port,
    1373                 :            :                 (void *)&cmd_set_port_meter_profile_meter,
    1374                 :            :                 (void *)&cmd_set_port_meter_profile_profile,
    1375                 :            :                 (void *)&cmd_set_port_meter_profile_port_id,
    1376                 :            :                 (void *)&cmd_set_port_meter_profile_mtr_id,
    1377                 :            :                 (void *)&cmd_set_port_meter_profile_profile_id,
    1378                 :            :                 NULL,
    1379                 :            :         },
    1380                 :            : };
    1381                 :            : 
    1382                 :            : /* *** Set Port Meter DSCP Table *** */
    1383                 :            : struct cmd_set_port_meter_dscp_table_result {
    1384                 :            :         cmdline_fixed_string_t set;
    1385                 :            :         cmdline_fixed_string_t port;
    1386                 :            :         cmdline_fixed_string_t meter;
    1387                 :            :         cmdline_fixed_string_t dscp_table;
    1388                 :            :         cmdline_multi_string_t token_string;
    1389                 :            : };
    1390                 :            : 
    1391                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_set =
    1392                 :            :         TOKEN_STRING_INITIALIZER(
    1393                 :            :                 struct cmd_set_port_meter_dscp_table_result, set, "set");
    1394                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_port =
    1395                 :            :         TOKEN_STRING_INITIALIZER(
    1396                 :            :                 struct cmd_set_port_meter_dscp_table_result, port, "port");
    1397                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_meter =
    1398                 :            :         TOKEN_STRING_INITIALIZER(
    1399                 :            :                 struct cmd_set_port_meter_dscp_table_result, meter, "meter");
    1400                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_dscp_table =
    1401                 :            :         TOKEN_STRING_INITIALIZER(
    1402                 :            :                 struct cmd_set_port_meter_dscp_table_result,
    1403                 :            :                 dscp_table, "dscp table");
    1404                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_dscp_table_token_string =
    1405                 :            :         TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_dscp_table_result,
    1406                 :            :                 token_string, TOKEN_STRING_MULTI);
    1407                 :            : 
    1408                 :          0 : static void cmd_set_port_meter_dscp_table_parsed(void *parsed_result,
    1409                 :            :         __rte_unused struct cmdline *cl,
    1410                 :            :         __rte_unused void *data)
    1411                 :            : {
    1412                 :            :         struct cmd_set_port_meter_dscp_table_result *res = parsed_result;
    1413                 :          0 :         enum rte_mtr_color_in_protocol proto = 0;
    1414                 :            :         struct rte_mtr_error error;
    1415                 :          0 :         enum rte_color *dscp_table = NULL;
    1416                 :          0 :         char *t_str = res->token_string;
    1417                 :          0 :         uint32_t mtr_id = 0;
    1418                 :            :         uint16_t port_id;
    1419                 :            :         int ret;
    1420                 :            : 
    1421                 :            :         /* Parse string */
    1422                 :          0 :         ret = parse_multi_token_string(t_str, &port_id, &mtr_id, &proto,
    1423                 :            :                                        &dscp_table);
    1424                 :          0 :         if (ret) {
    1425                 :          0 :                 fprintf(stderr, " Multi token string parse error\n");
    1426                 :          0 :                 return;
    1427                 :            :         }
    1428                 :            : 
    1429                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
    1430                 :          0 :                 goto free_table;
    1431                 :            : 
    1432                 :            :         /* Update Meter DSCP Table*/
    1433                 :          0 :         ret = rte_mtr_meter_dscp_table_update(port_id, mtr_id, proto,
    1434                 :            :                 dscp_table, &error);
    1435                 :          0 :         if (ret != 0)
    1436                 :          0 :                 print_err_msg(&error);
    1437                 :            : 
    1438                 :          0 : free_table:
    1439                 :          0 :         free(dscp_table);
    1440                 :            : }
    1441                 :            : 
    1442                 :            : cmdline_parse_inst_t cmd_set_port_meter_dscp_table = {
    1443                 :            :         .f = cmd_set_port_meter_dscp_table_parsed,
    1444                 :            :         .data = NULL,
    1445                 :            :         .help_str = "set port meter dscp table <port_id> <mtr_id> <proto> "
    1446                 :            :                 "[<dscp_tbl_entry0> <dscp_tbl_entry1> ... <dscp_tbl_entry63>]",
    1447                 :            :         .tokens = {
    1448                 :            :                 (void *)&cmd_set_port_meter_dscp_table_set,
    1449                 :            :                 (void *)&cmd_set_port_meter_dscp_table_port,
    1450                 :            :                 (void *)&cmd_set_port_meter_dscp_table_meter,
    1451                 :            :                 (void *)&cmd_set_port_meter_dscp_table_dscp_table,
    1452                 :            :                 (void *)&cmd_set_port_meter_dscp_table_token_string,
    1453                 :            :                 NULL,
    1454                 :            :         },
    1455                 :            : };
    1456                 :            : 
    1457                 :            : /* *** Set Port Meter VLAN Table *** */
    1458                 :            : struct cmd_set_port_meter_vlan_table_result {
    1459                 :            :         cmdline_fixed_string_t set;
    1460                 :            :         cmdline_fixed_string_t port;
    1461                 :            :         cmdline_fixed_string_t meter;
    1462                 :            :         cmdline_fixed_string_t vlan_table;
    1463                 :            :         cmdline_multi_string_t token_string;
    1464                 :            : };
    1465                 :            : 
    1466                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_vlan_table_set =
    1467                 :            :         TOKEN_STRING_INITIALIZER(
    1468                 :            :                 struct cmd_set_port_meter_vlan_table_result, set, "set");
    1469                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_vlan_table_port =
    1470                 :            :         TOKEN_STRING_INITIALIZER(
    1471                 :            :                 struct cmd_set_port_meter_vlan_table_result, port, "port");
    1472                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_vlan_table_meter =
    1473                 :            :         TOKEN_STRING_INITIALIZER(
    1474                 :            :                 struct cmd_set_port_meter_vlan_table_result, meter, "meter");
    1475                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_vlan_table_vlan_table =
    1476                 :            :         TOKEN_STRING_INITIALIZER(
    1477                 :            :                 struct cmd_set_port_meter_vlan_table_result,
    1478                 :            :                 vlan_table, "vlan table");
    1479                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_vlan_table_token_string =
    1480                 :            :         TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_vlan_table_result,
    1481                 :            :                 token_string, TOKEN_STRING_MULTI);
    1482                 :            : 
    1483                 :          0 : static void cmd_set_port_meter_vlan_table_parsed(void *parsed_result,
    1484                 :            :         __rte_unused struct cmdline *cl,
    1485                 :            :         __rte_unused void *data)
    1486                 :            : {
    1487                 :            :         struct cmd_set_port_meter_vlan_table_result *res = parsed_result;
    1488                 :          0 :         enum rte_mtr_color_in_protocol proto = 0;
    1489                 :            :         struct rte_mtr_error error;
    1490                 :          0 :         enum rte_color *vlan_table = NULL;
    1491                 :          0 :         char *t_str = res->token_string;
    1492                 :          0 :         uint32_t mtr_id = 0;
    1493                 :            :         uint16_t port_id;
    1494                 :            :         int ret;
    1495                 :            : 
    1496                 :            :         /* Parse string */
    1497                 :          0 :         ret = parse_multi_token_vlan_str(t_str, &port_id, &mtr_id, &proto,
    1498                 :            :                                          &vlan_table);
    1499                 :          0 :         if (ret) {
    1500                 :          0 :                 fprintf(stderr, " Multi token string parse error\n");
    1501                 :          0 :                 return;
    1502                 :            :         }
    1503                 :            : 
    1504                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
    1505                 :          0 :                 goto free_table;
    1506                 :            : 
    1507                 :            :         /* Update Meter VLAN Table*/
    1508                 :          0 :         ret = rte_mtr_meter_vlan_table_update(port_id, mtr_id, proto,
    1509                 :            :                 vlan_table, &error);
    1510                 :          0 :         if (ret != 0)
    1511                 :          0 :                 print_err_msg(&error);
    1512                 :            : 
    1513                 :          0 : free_table:
    1514                 :          0 :         free(vlan_table);
    1515                 :            : }
    1516                 :            : 
    1517                 :            : cmdline_parse_inst_t cmd_set_port_meter_vlan_table = {
    1518                 :            :         .f = cmd_set_port_meter_vlan_table_parsed,
    1519                 :            :         .data = NULL,
    1520                 :            :         .help_str = "set port meter vlan table <port_id> <mtr_id> <proto> "
    1521                 :            :                 "[<vlan_tbl_entry0> <vlan_tbl_entry1> ... <vlan_tbl_entry15>]",
    1522                 :            :         .tokens = {
    1523                 :            :                 (void *)&cmd_set_port_meter_vlan_table_set,
    1524                 :            :                 (void *)&cmd_set_port_meter_vlan_table_port,
    1525                 :            :                 (void *)&cmd_set_port_meter_vlan_table_meter,
    1526                 :            :                 (void *)&cmd_set_port_meter_vlan_table_vlan_table,
    1527                 :            :                 (void *)&cmd_set_port_meter_vlan_table_token_string,
    1528                 :            :                 NULL,
    1529                 :            :         },
    1530                 :            : };
    1531                 :            : 
    1532                 :            : /* *** Set Port Meter input protocol *** */
    1533                 :            : struct cmd_set_port_meter_in_proto_result {
    1534                 :            :         cmdline_fixed_string_t set;
    1535                 :            :         cmdline_fixed_string_t port;
    1536                 :            :         cmdline_fixed_string_t meter;
    1537                 :            :         cmdline_fixed_string_t protocol;
    1538                 :            :         cmdline_fixed_string_t proto;
    1539                 :            :         uint32_t prio;
    1540                 :            :         uint32_t mtr_id;
    1541                 :            :         uint16_t port_id;
    1542                 :            : };
    1543                 :            : 
    1544                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_in_proto_set =
    1545                 :            :         TOKEN_STRING_INITIALIZER(
    1546                 :            :                 struct cmd_set_port_meter_in_proto_result, set, "set");
    1547                 :            : 
    1548                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_in_proto_port =
    1549                 :            :         TOKEN_STRING_INITIALIZER(
    1550                 :            :                 struct cmd_set_port_meter_in_proto_result, port, "port");
    1551                 :            : 
    1552                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_in_proto_meter =
    1553                 :            :         TOKEN_STRING_INITIALIZER(
    1554                 :            :                 struct cmd_set_port_meter_in_proto_result, meter, "meter");
    1555                 :            : 
    1556                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_in_proto_protocol =
    1557                 :            :         TOKEN_STRING_INITIALIZER(
    1558                 :            :                 struct cmd_set_port_meter_in_proto_result, protocol, "proto");
    1559                 :            : 
    1560                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_in_proto_proto =
    1561                 :            :         TOKEN_STRING_INITIALIZER(
    1562                 :            :                 struct cmd_set_port_meter_in_proto_result, proto,
    1563                 :            :                 "outer_vlan#inner_vlan#outer_ip#inner_ip");
    1564                 :            : 
    1565                 :            : static cmdline_parse_token_num_t cmd_set_port_meter_in_proto_prio =
    1566                 :            :         TOKEN_NUM_INITIALIZER(
    1567                 :            :                 struct cmd_set_port_meter_in_proto_result, prio, RTE_UINT32);
    1568                 :            : 
    1569                 :            : static cmdline_parse_token_num_t cmd_set_port_meter_in_proto_port_id =
    1570                 :            :         TOKEN_NUM_INITIALIZER(
    1571                 :            :                 struct cmd_set_port_meter_in_proto_result, port_id, RTE_UINT16);
    1572                 :            : 
    1573                 :            : static cmdline_parse_token_num_t cmd_set_port_meter_in_proto_mtr_id =
    1574                 :            :         TOKEN_NUM_INITIALIZER(
    1575                 :            :                 struct cmd_set_port_meter_in_proto_result, mtr_id, RTE_UINT32);
    1576                 :            : 
    1577                 :          0 : static void cmd_set_port_meter_in_proto_parsed(void *parsed_result,
    1578                 :            :         __rte_unused struct cmdline *cl,
    1579                 :            :         __rte_unused void *data)
    1580                 :            : {
    1581                 :            :         struct cmd_set_port_meter_in_proto_result *res = parsed_result;
    1582                 :            :         enum rte_mtr_color_in_protocol proto;
    1583                 :            :         struct rte_mtr_error error;
    1584                 :            :         int ret;
    1585                 :            : 
    1586                 :          0 :         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
    1587                 :          0 :                 return;
    1588                 :            : 
    1589                 :          0 :         if (strcmp(res->proto, "outer_vlan") == 0)
    1590                 :            :                 proto = RTE_MTR_COLOR_IN_PROTO_OUTER_VLAN;
    1591                 :          0 :         else if (strcmp(res->proto, "inner_vlan") == 0)
    1592                 :            :                 proto = RTE_MTR_COLOR_IN_PROTO_INNER_VLAN;
    1593                 :          0 :         else if (strcmp(res->proto, "outer_ip") == 0)
    1594                 :            :                 proto = RTE_MTR_COLOR_IN_PROTO_OUTER_IP;
    1595                 :          0 :         else if (strcmp(res->proto, "inner_ip") == 0)
    1596                 :            :                 proto = RTE_MTR_COLOR_IN_PROTO_INNER_IP;
    1597                 :            :         else {
    1598                 :            :                 printf("Invalid protocol\n");
    1599                 :          0 :                 return;
    1600                 :            :         }
    1601                 :            : 
    1602                 :            :         /* Update Meter input proto and priority */
    1603                 :          0 :         ret = rte_mtr_color_in_protocol_set(res->port_id, res->mtr_id,
    1604                 :            :                 proto, res->prio, &error);
    1605                 :          0 :         if (ret != 0)
    1606                 :          0 :                 print_err_msg(&error);
    1607                 :            : }
    1608                 :            : 
    1609                 :            : cmdline_parse_inst_t cmd_set_port_meter_in_proto = {
    1610                 :            :         .f = cmd_set_port_meter_in_proto_parsed,
    1611                 :            :         .data = NULL,
    1612                 :            :         .help_str = "set port meter proto <port_id> <mtr_id> <proto> "
    1613                 :            :                 "<prio>",
    1614                 :            :         .tokens = {
    1615                 :            :                 (void *)&cmd_set_port_meter_in_proto_set,
    1616                 :            :                 (void *)&cmd_set_port_meter_in_proto_port,
    1617                 :            :                 (void *)&cmd_set_port_meter_in_proto_meter,
    1618                 :            :                 (void *)&cmd_set_port_meter_in_proto_protocol,
    1619                 :            :                 (void *)&cmd_set_port_meter_in_proto_port_id,
    1620                 :            :                 (void *)&cmd_set_port_meter_in_proto_mtr_id,
    1621                 :            :                 (void *)&cmd_set_port_meter_in_proto_proto,
    1622                 :            :                 (void *)&cmd_set_port_meter_in_proto_prio,
    1623                 :            :                 NULL,
    1624                 :            :         },
    1625                 :            : };
    1626                 :            : 
    1627                 :            : /* *** Get Port Meter input protocol *** */
    1628                 :            : struct cmd_get_port_meter_in_proto_result {
    1629                 :            :         cmdline_fixed_string_t get;
    1630                 :            :         cmdline_fixed_string_t port;
    1631                 :            :         cmdline_fixed_string_t meter;
    1632                 :            :         cmdline_fixed_string_t protocol;
    1633                 :            :         uint32_t mtr_id;
    1634                 :            :         uint16_t port_id;
    1635                 :            : };
    1636                 :            : 
    1637                 :            : static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_get =
    1638                 :            :         TOKEN_STRING_INITIALIZER(
    1639                 :            :                 struct cmd_get_port_meter_in_proto_result, get, "get");
    1640                 :            : 
    1641                 :            : static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_port =
    1642                 :            :         TOKEN_STRING_INITIALIZER(
    1643                 :            :                 struct cmd_get_port_meter_in_proto_result, port, "port");
    1644                 :            : 
    1645                 :            : static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_meter =
    1646                 :            :         TOKEN_STRING_INITIALIZER(
    1647                 :            :                 struct cmd_get_port_meter_in_proto_result, meter, "meter");
    1648                 :            : 
    1649                 :            : static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_protocol =
    1650                 :            :         TOKEN_STRING_INITIALIZER(
    1651                 :            :                 struct cmd_get_port_meter_in_proto_result, protocol, "proto");
    1652                 :            : 
    1653                 :            : static cmdline_parse_token_num_t cmd_get_port_meter_in_proto_port_id =
    1654                 :            :         TOKEN_NUM_INITIALIZER(
    1655                 :            :                 struct cmd_get_port_meter_in_proto_result, port_id, RTE_UINT16);
    1656                 :            : 
    1657                 :            : static cmdline_parse_token_num_t cmd_get_port_meter_in_proto_mtr_id =
    1658                 :            :         TOKEN_NUM_INITIALIZER(
    1659                 :            :                 struct cmd_get_port_meter_in_proto_result, mtr_id, RTE_UINT32);
    1660                 :            : 
    1661                 :          0 : static void cmd_get_port_meter_in_proto_parsed(void *parsed_result,
    1662                 :            :         __rte_unused struct cmdline *cl,
    1663                 :            :         __rte_unused void *data)
    1664                 :            : {
    1665                 :            :         struct cmd_set_port_meter_in_proto_result *res = parsed_result;
    1666                 :            :         struct rte_mtr_error error;
    1667                 :          0 :         uint64_t proto_mask = 0;
    1668                 :            :         int ret;
    1669                 :            : 
    1670                 :          0 :         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
    1671                 :          0 :                 return;
    1672                 :            : 
    1673                 :            :         /* Update Meter input proto and priority */
    1674                 :          0 :         ret = rte_mtr_color_in_protocol_get(res->port_id, res->mtr_id,
    1675                 :            :                 &proto_mask, &error);
    1676                 :          0 :         if (ret != 0)
    1677                 :          0 :                 print_err_msg(&error);
    1678                 :            : 
    1679                 :            :         printf("Enabled protocols:\n");
    1680                 :          0 :         if (proto_mask & RTE_MTR_COLOR_IN_PROTO_OUTER_VLAN)
    1681                 :            :                 printf("\touter_vlan\n");
    1682                 :          0 :         if (proto_mask & RTE_MTR_COLOR_IN_PROTO_INNER_VLAN)
    1683                 :            :                 printf("\tinner_vlan\n");
    1684                 :          0 :         if (proto_mask & RTE_MTR_COLOR_IN_PROTO_OUTER_IP)
    1685                 :            :                 printf("\touter_ip\n");
    1686                 :          0 :         if (proto_mask & RTE_MTR_COLOR_IN_PROTO_INNER_IP)
    1687                 :            :                 printf("\tinner_ip\n");
    1688                 :            : }
    1689                 :            : 
    1690                 :            : cmdline_parse_inst_t cmd_get_port_meter_in_proto = {
    1691                 :            :         .f = cmd_get_port_meter_in_proto_parsed,
    1692                 :            :         .data = NULL,
    1693                 :            :         .help_str = "get port meter proto <port_id> <mtr_id>",
    1694                 :            :         .tokens = {
    1695                 :            :                 (void *)&cmd_get_port_meter_in_proto_get,
    1696                 :            :                 (void *)&cmd_get_port_meter_in_proto_port,
    1697                 :            :                 (void *)&cmd_get_port_meter_in_proto_meter,
    1698                 :            :                 (void *)&cmd_get_port_meter_in_proto_protocol,
    1699                 :            :                 (void *)&cmd_get_port_meter_in_proto_port_id,
    1700                 :            :                 (void *)&cmd_get_port_meter_in_proto_mtr_id,
    1701                 :            :                 NULL,
    1702                 :            :         },
    1703                 :            : };
    1704                 :            : 
    1705                 :            : /* *** Get Port Meter input protocol priority *** */
    1706                 :            : struct cmd_get_port_meter_in_proto_prio_result {
    1707                 :            :         cmdline_fixed_string_t get;
    1708                 :            :         cmdline_fixed_string_t port;
    1709                 :            :         cmdline_fixed_string_t meter;
    1710                 :            :         cmdline_fixed_string_t protocol;
    1711                 :            :         cmdline_fixed_string_t proto;
    1712                 :            :         uint32_t mtr_id;
    1713                 :            :         uint16_t port_id;
    1714                 :            : };
    1715                 :            : 
    1716                 :            : static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_prio_get =
    1717                 :            :         TOKEN_STRING_INITIALIZER(
    1718                 :            :                 struct cmd_get_port_meter_in_proto_prio_result, get, "get");
    1719                 :            : 
    1720                 :            : static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_prio_port =
    1721                 :            :         TOKEN_STRING_INITIALIZER(
    1722                 :            :                 struct cmd_get_port_meter_in_proto_prio_result, port, "port");
    1723                 :            : 
    1724                 :            : static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_prio_meter =
    1725                 :            :         TOKEN_STRING_INITIALIZER(
    1726                 :            :                 struct cmd_get_port_meter_in_proto_prio_result, meter, "meter");
    1727                 :            : 
    1728                 :            : static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_prio_protocol =
    1729                 :            :         TOKEN_STRING_INITIALIZER(
    1730                 :            :                 struct cmd_get_port_meter_in_proto_prio_result, protocol,
    1731                 :            :                 "proto_prio");
    1732                 :            : 
    1733                 :            : static cmdline_parse_token_string_t cmd_get_port_meter_in_proto_prio_proto =
    1734                 :            :         TOKEN_STRING_INITIALIZER(
    1735                 :            :                 struct cmd_get_port_meter_in_proto_prio_result, proto,
    1736                 :            :                 "outer_vlan#inner_vlan#outer_ip#inner_ip");
    1737                 :            : 
    1738                 :            : static cmdline_parse_token_num_t cmd_get_port_meter_in_proto_prio_port_id =
    1739                 :            :         TOKEN_NUM_INITIALIZER(
    1740                 :            :                 struct cmd_get_port_meter_in_proto_prio_result, port_id,
    1741                 :            :                 RTE_UINT16);
    1742                 :            : 
    1743                 :            : static cmdline_parse_token_num_t cmd_get_port_meter_in_proto_prio_mtr_id =
    1744                 :            :         TOKEN_NUM_INITIALIZER(
    1745                 :            :                 struct cmd_get_port_meter_in_proto_prio_result, mtr_id,
    1746                 :            :                 RTE_UINT32);
    1747                 :            : 
    1748                 :          0 : static void cmd_get_port_meter_in_proto_prio_parsed(void *parsed_result,
    1749                 :            :         __rte_unused struct cmdline *cl,
    1750                 :            :         __rte_unused void *data)
    1751                 :            : {
    1752                 :            :         struct cmd_get_port_meter_in_proto_prio_result *res = parsed_result;
    1753                 :            :         enum rte_mtr_color_in_protocol proto;
    1754                 :            :         struct rte_mtr_error error;
    1755                 :          0 :         uint32_t prio = 0;
    1756                 :            :         int ret;
    1757                 :            : 
    1758                 :          0 :         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
    1759                 :          0 :                 return;
    1760                 :            : 
    1761                 :          0 :         if (strcmp(res->proto, "outer_vlan") == 0)
    1762                 :            :                 proto = RTE_MTR_COLOR_IN_PROTO_OUTER_VLAN;
    1763                 :          0 :         else if (strcmp(res->proto, "inner_vlan") == 0)
    1764                 :            :                 proto = RTE_MTR_COLOR_IN_PROTO_INNER_VLAN;
    1765                 :          0 :         else if (strcmp(res->proto, "outer_ip") == 0)
    1766                 :            :                 proto = RTE_MTR_COLOR_IN_PROTO_OUTER_IP;
    1767                 :          0 :         else if (strcmp(res->proto, "inner_ip") == 0)
    1768                 :            :                 proto = RTE_MTR_COLOR_IN_PROTO_INNER_IP;
    1769                 :            :         else {
    1770                 :            :                 printf("Invalid protocol\n");
    1771                 :          0 :                 return;
    1772                 :            :         }
    1773                 :            : 
    1774                 :            :         /* Get Meter input proto and priority */
    1775                 :          0 :         ret = rte_mtr_color_in_protocol_priority_get(res->port_id, res->mtr_id,
    1776                 :            :                 proto, &prio, &error);
    1777                 :          0 :         if (ret != 0)
    1778                 :          0 :                 print_err_msg(&error);
    1779                 :            : }
    1780                 :            : 
    1781                 :            : cmdline_parse_inst_t cmd_get_port_meter_in_proto_prio = {
    1782                 :            :         .f = cmd_get_port_meter_in_proto_prio_parsed,
    1783                 :            :         .data = NULL,
    1784                 :            :         .help_str = "get port meter proto_prio <port_id> <mtr_id> <proto>",
    1785                 :            :         .tokens = {
    1786                 :            :                 (void *)&cmd_get_port_meter_in_proto_prio_get,
    1787                 :            :                 (void *)&cmd_get_port_meter_in_proto_prio_port,
    1788                 :            :                 (void *)&cmd_get_port_meter_in_proto_prio_meter,
    1789                 :            :                 (void *)&cmd_get_port_meter_in_proto_prio_protocol,
    1790                 :            :                 (void *)&cmd_get_port_meter_in_proto_prio_port_id,
    1791                 :            :                 (void *)&cmd_get_port_meter_in_proto_prio_mtr_id,
    1792                 :            :                 (void *)&cmd_get_port_meter_in_proto_prio_proto,
    1793                 :            :                 NULL,
    1794                 :            :         },
    1795                 :            : };
    1796                 :            : 
    1797                 :            : /* *** Set Port Meter Stats Mask *** */
    1798                 :            : struct cmd_set_port_meter_stats_mask_result {
    1799                 :            :         cmdline_fixed_string_t set;
    1800                 :            :         cmdline_fixed_string_t port;
    1801                 :            :         cmdline_fixed_string_t meter;
    1802                 :            :         cmdline_fixed_string_t stats;
    1803                 :            :         cmdline_fixed_string_t mask;
    1804                 :            :         uint16_t port_id;
    1805                 :            :         uint32_t mtr_id;
    1806                 :            :         uint64_t stats_mask;
    1807                 :            : };
    1808                 :            : 
    1809                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_set =
    1810                 :            :         TOKEN_STRING_INITIALIZER(
    1811                 :            :                 struct cmd_set_port_meter_stats_mask_result, set, "set");
    1812                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_port =
    1813                 :            :         TOKEN_STRING_INITIALIZER(
    1814                 :            :                 struct cmd_set_port_meter_stats_mask_result, port, "port");
    1815                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_meter =
    1816                 :            :         TOKEN_STRING_INITIALIZER(
    1817                 :            :                 struct cmd_set_port_meter_stats_mask_result, meter, "meter");
    1818                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_stats =
    1819                 :            :         TOKEN_STRING_INITIALIZER(
    1820                 :            :                 struct cmd_set_port_meter_stats_mask_result, stats, "stats");
    1821                 :            : static cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_mask =
    1822                 :            :         TOKEN_STRING_INITIALIZER(
    1823                 :            :                 struct cmd_set_port_meter_stats_mask_result, mask, "mask");
    1824                 :            : static cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_port_id =
    1825                 :            :         TOKEN_NUM_INITIALIZER(
    1826                 :            :                 struct cmd_set_port_meter_stats_mask_result, port_id,
    1827                 :            :                 RTE_UINT16);
    1828                 :            : static cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_mtr_id =
    1829                 :            :         TOKEN_NUM_INITIALIZER(
    1830                 :            :                 struct cmd_set_port_meter_stats_mask_result, mtr_id,
    1831                 :            :                 RTE_UINT32);
    1832                 :            : static cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_stats_mask =
    1833                 :            :         TOKEN_NUM_INITIALIZER(
    1834                 :            :                 struct cmd_set_port_meter_stats_mask_result, stats_mask,
    1835                 :            :                 RTE_UINT64);
    1836                 :            : 
    1837                 :          0 : static void cmd_set_port_meter_stats_mask_parsed(void *parsed_result,
    1838                 :            :         __rte_unused struct cmdline *cl,
    1839                 :            :         __rte_unused void *data)
    1840                 :            : {
    1841                 :            :         struct cmd_set_port_meter_stats_mask_result *res = parsed_result;
    1842                 :            :         struct rte_mtr_error error;
    1843                 :          0 :         uint64_t stats_mask = res->stats_mask;
    1844                 :          0 :         uint32_t mtr_id = res->mtr_id;
    1845                 :          0 :         uint16_t port_id = res->port_id;
    1846                 :            :         int ret;
    1847                 :            : 
    1848                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
    1849                 :          0 :                 return;
    1850                 :            : 
    1851                 :          0 :         ret = rte_mtr_stats_update(port_id, mtr_id, stats_mask, &error);
    1852                 :          0 :         if (ret != 0) {
    1853                 :          0 :                 print_err_msg(&error);
    1854                 :          0 :                 return;
    1855                 :            :         }
    1856                 :            : }
    1857                 :            : 
    1858                 :            : cmdline_parse_inst_t cmd_set_port_meter_stats_mask = {
    1859                 :            :         .f = cmd_set_port_meter_stats_mask_parsed,
    1860                 :            :         .data = NULL,
    1861                 :            :         .help_str = "set port meter stats mask <port_id> <mtr_id> <stats_mask>",
    1862                 :            :         .tokens = {
    1863                 :            :                 (void *)&cmd_set_port_meter_stats_mask_set,
    1864                 :            :                 (void *)&cmd_set_port_meter_stats_mask_port,
    1865                 :            :                 (void *)&cmd_set_port_meter_stats_mask_meter,
    1866                 :            :                 (void *)&cmd_set_port_meter_stats_mask_stats,
    1867                 :            :                 (void *)&cmd_set_port_meter_stats_mask_mask,
    1868                 :            :                 (void *)&cmd_set_port_meter_stats_mask_port_id,
    1869                 :            :                 (void *)&cmd_set_port_meter_stats_mask_mtr_id,
    1870                 :            :                 (void *)&cmd_set_port_meter_stats_mask_stats_mask,
    1871                 :            :                 NULL,
    1872                 :            :         },
    1873                 :            : };
    1874                 :            : 
    1875                 :            : /* *** Show Port Meter Stats *** */
    1876                 :            : struct cmd_show_port_meter_stats_result {
    1877                 :            :         cmdline_fixed_string_t show;
    1878                 :            :         cmdline_fixed_string_t port;
    1879                 :            :         cmdline_fixed_string_t meter;
    1880                 :            :         cmdline_fixed_string_t stats;
    1881                 :            :         uint16_t port_id;
    1882                 :            :         uint32_t mtr_id;
    1883                 :            :         cmdline_fixed_string_t clear;
    1884                 :            : };
    1885                 :            : 
    1886                 :            : static cmdline_parse_token_string_t cmd_show_port_meter_stats_show =
    1887                 :            :         TOKEN_STRING_INITIALIZER(
    1888                 :            :                 struct cmd_show_port_meter_stats_result, show, "show");
    1889                 :            : static cmdline_parse_token_string_t cmd_show_port_meter_stats_port =
    1890                 :            :         TOKEN_STRING_INITIALIZER(
    1891                 :            :                 struct cmd_show_port_meter_stats_result, port, "port");
    1892                 :            : static cmdline_parse_token_string_t cmd_show_port_meter_stats_meter =
    1893                 :            :         TOKEN_STRING_INITIALIZER(
    1894                 :            :                 struct cmd_show_port_meter_stats_result, meter, "meter");
    1895                 :            : static cmdline_parse_token_string_t cmd_show_port_meter_stats_stats =
    1896                 :            :         TOKEN_STRING_INITIALIZER(
    1897                 :            :                 struct cmd_show_port_meter_stats_result, stats, "stats");
    1898                 :            : static cmdline_parse_token_num_t cmd_show_port_meter_stats_port_id =
    1899                 :            :         TOKEN_NUM_INITIALIZER(
    1900                 :            :                 struct cmd_show_port_meter_stats_result, port_id, RTE_UINT16);
    1901                 :            : static cmdline_parse_token_num_t cmd_show_port_meter_stats_mtr_id =
    1902                 :            :         TOKEN_NUM_INITIALIZER(
    1903                 :            :                 struct cmd_show_port_meter_stats_result, mtr_id, RTE_UINT32);
    1904                 :            : static cmdline_parse_token_string_t cmd_show_port_meter_stats_clear =
    1905                 :            :         TOKEN_STRING_INITIALIZER(
    1906                 :            :                 struct cmd_show_port_meter_stats_result, clear, "yes#no");
    1907                 :            : 
    1908                 :          0 : static void cmd_show_port_meter_stats_parsed(void *parsed_result,
    1909                 :            :         __rte_unused struct cmdline *cl,
    1910                 :            :         __rte_unused void *data)
    1911                 :            : {
    1912                 :            :         struct cmd_show_port_meter_stats_result *res = parsed_result;
    1913                 :            :         struct rte_mtr_stats stats;
    1914                 :          0 :         uint64_t stats_mask = 0;
    1915                 :            :         struct rte_mtr_error error;
    1916                 :          0 :         uint32_t mtr_id = res->mtr_id;
    1917                 :            :         uint32_t clear = 0;
    1918                 :          0 :         uint16_t port_id = res->port_id;
    1919                 :            :         int ret;
    1920                 :            : 
    1921                 :          0 :         if (port_id_is_invalid(port_id, ENABLED_WARN))
    1922                 :          0 :                 return;
    1923                 :            : 
    1924                 :          0 :         if (strcmp(res->clear, "yes") == 0)
    1925                 :            :                 clear = 1;
    1926                 :            : 
    1927                 :            :         memset(&stats, 0, sizeof(struct rte_mtr_stats));
    1928                 :          0 :         ret = rte_mtr_stats_read(port_id, mtr_id, &stats,
    1929                 :            :                 &stats_mask, clear, &error);
    1930                 :          0 :         if (ret != 0) {
    1931                 :          0 :                 print_err_msg(&error);
    1932                 :          0 :                 return;
    1933                 :            :         }
    1934                 :            : 
    1935                 :            :         /* Display stats */
    1936                 :          0 :         if (stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
    1937                 :          0 :                 printf("\tPkts G: %" PRIu64 "\n",
    1938                 :            :                         stats.n_pkts[RTE_COLOR_GREEN]);
    1939                 :          0 :         if (stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
    1940                 :          0 :                 printf("\tBytes G: %" PRIu64 "\n",
    1941                 :            :                         stats.n_bytes[RTE_COLOR_GREEN]);
    1942                 :          0 :         if (stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
    1943                 :          0 :                 printf("\tPkts Y: %" PRIu64 "\n",
    1944                 :            :                         stats.n_pkts[RTE_COLOR_YELLOW]);
    1945                 :          0 :         if (stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
    1946                 :          0 :                 printf("\tBytes Y: %" PRIu64 "\n",
    1947                 :            :                         stats.n_bytes[RTE_COLOR_YELLOW]);
    1948                 :          0 :         if (stats_mask & RTE_MTR_STATS_N_PKTS_RED)
    1949                 :          0 :                 printf("\tPkts R: %" PRIu64 "\n",
    1950                 :            :                         stats.n_pkts[RTE_COLOR_RED]);
    1951                 :          0 :         if (stats_mask & RTE_MTR_STATS_N_BYTES_RED)
    1952                 :          0 :                 printf("\tBytes R: %" PRIu64 "\n",
    1953                 :            :                         stats.n_bytes[RTE_COLOR_RED]);
    1954                 :          0 :         if (stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
    1955                 :          0 :                 printf("\tPkts DROPPED: %" PRIu64 "\n",
    1956                 :            :                         stats.n_pkts_dropped);
    1957                 :          0 :         if (stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
    1958                 :          0 :                 printf("\tBytes DROPPED: %" PRIu64 "\n",
    1959                 :            :                         stats.n_bytes_dropped);
    1960                 :            : }
    1961                 :            : 
    1962                 :            : cmdline_parse_inst_t cmd_show_port_meter_stats = {
    1963                 :            :         .f = cmd_show_port_meter_stats_parsed,
    1964                 :            :         .data = NULL,
    1965                 :            :         .help_str = "show port meter stats <port_id> <mtr_id> <clear>(yes|no)",
    1966                 :            :         .tokens = {
    1967                 :            :                 (void *)&cmd_show_port_meter_stats_show,
    1968                 :            :                 (void *)&cmd_show_port_meter_stats_port,
    1969                 :            :                 (void *)&cmd_show_port_meter_stats_meter,
    1970                 :            :                 (void *)&cmd_show_port_meter_stats_stats,
    1971                 :            :                 (void *)&cmd_show_port_meter_stats_port_id,
    1972                 :            :                 (void *)&cmd_show_port_meter_stats_mtr_id,
    1973                 :            :                 (void *)&cmd_show_port_meter_stats_clear,
    1974                 :            :                 NULL,
    1975                 :            :         },
    1976                 :            : };

Generated by: LCOV version 1.14