app/testpmd: check code of promiscuous mode switch
[dpdk.git] / app / test-pmd / cmdline_tm.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #include <cmdline_parse.h>
6 #include <cmdline_parse_num.h>
7 #include <cmdline_parse_string.h>
8
9 #include <rte_ethdev.h>
10 #include <rte_flow.h>
11 #include <rte_tm.h>
12
13 #include "testpmd.h"
14 #include "cmdline_tm.h"
15
16 #define PARSE_DELIMITER                         " \f\n\r\t\v"
17 #define MAX_NUM_SHARED_SHAPERS          256
18
19 #define skip_white_spaces(pos)                  \
20 ({                                              \
21         __typeof__(pos) _p = (pos);             \
22         for ( ; isspace(*_p); _p++)             \
23                 ;                               \
24         _p;                                     \
25 })
26
27 /** Display TM Error Message */
28 static void
29 print_err_msg(struct rte_tm_error *error)
30 {
31         static const char *const errstrlist[] = {
32                 [RTE_TM_ERROR_TYPE_NONE] = "no error",
33                 [RTE_TM_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
34                 [RTE_TM_ERROR_TYPE_CAPABILITIES]
35                         = "capability parameter null",
36                 [RTE_TM_ERROR_TYPE_LEVEL_ID] = "level id",
37                 [RTE_TM_ERROR_TYPE_WRED_PROFILE]
38                         = "wred profile null",
39                 [RTE_TM_ERROR_TYPE_WRED_PROFILE_GREEN] = "wred profile(green)",
40                 [RTE_TM_ERROR_TYPE_WRED_PROFILE_YELLOW]
41                         = "wred profile(yellow)",
42                 [RTE_TM_ERROR_TYPE_WRED_PROFILE_RED] = "wred profile(red)",
43                 [RTE_TM_ERROR_TYPE_WRED_PROFILE_ID] = "wred profile id",
44                 [RTE_TM_ERROR_TYPE_SHARED_WRED_CONTEXT_ID]
45                         = "shared wred context id",
46                 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE] = "shaper profile null",
47                 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_RATE]
48                         = "committed rate field (shaper profile)",
49                 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_SIZE]
50                         = "committed size field (shaper profile)",
51                 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_RATE]
52                         = "peak rate field (shaper profile)",
53                 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_SIZE]
54                         = "peak size field (shaper profile)",
55                 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PKT_ADJUST_LEN]
56                         = "packet adjust length field (shaper profile)",
57                 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID] = "shaper profile id",
58                 [RTE_TM_ERROR_TYPE_SHARED_SHAPER_ID] = "shared shaper id",
59                 [RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID] = "parent node id",
60                 [RTE_TM_ERROR_TYPE_NODE_PRIORITY] = "node priority",
61                 [RTE_TM_ERROR_TYPE_NODE_WEIGHT] = "node weight",
62                 [RTE_TM_ERROR_TYPE_NODE_PARAMS] = "node parameter null",
63                 [RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID]
64                         = "shaper profile id field (node params)",
65                 [RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_SHAPER_ID]
66                         = "shared shaper id field (node params)",
67                 [RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS]
68                         = "num shared shapers field (node params)",
69                 [RTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE]
70                         = "wfq weght mode field (node params)",
71                 [RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES]
72                         = "num strict priorities field (node params)",
73                 [RTE_TM_ERROR_TYPE_NODE_PARAMS_CMAN]
74                         = "congestion management mode field (node params)",
75                 [RTE_TM_ERROR_TYPE_NODE_PARAMS_WRED_PROFILE_ID] =
76                         "wred profile id field (node params)",
77                 [RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_WRED_CONTEXT_ID]
78                         = "shared wred context id field (node params)",
79                 [RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_WRED_CONTEXTS]
80                         = "num shared wred contexts field (node params)",
81                 [RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS]
82                         = "stats field (node params)",
83                 [RTE_TM_ERROR_TYPE_NODE_ID] = "node id",
84         };
85
86         const char *errstr;
87         char buf[64];
88
89         if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
90                 !errstrlist[error->type])
91                 errstr = "unknown type";
92         else
93                 errstr = errstrlist[error->type];
94
95         if (error->cause)
96                 snprintf(buf, sizeof(buf), "cause: %p, ", error->cause);
97
98         printf("%s: %s%s (error %d)\n", errstr, error->cause ? buf : "",
99                 error->message ? error->message : "(no stated reason)",
100                 error->type);
101 }
102
103 static int
104 read_uint64(uint64_t *value, const char *p)
105 {
106         char *next;
107         uint64_t val;
108
109         p = skip_white_spaces(p);
110         if (!isdigit(*p))
111                 return -EINVAL;
112
113         val = strtoul(p, &next, 10);
114         if (p == next)
115                 return -EINVAL;
116
117         p = next;
118         switch (*p) {
119         case 'T':
120                 val *= 1024ULL;
121                 /* fall through */
122         case 'G':
123                 val *= 1024ULL;
124                 /* fall through */
125         case 'M':
126                 val *= 1024ULL;
127                 /* fall through */
128         case 'k':
129         case 'K':
130                 val *= 1024ULL;
131                 p++;
132                 break;
133         }
134
135         p = skip_white_spaces(p);
136         if (*p != '\0')
137                 return -EINVAL;
138
139         *value = val;
140         return 0;
141 }
142
143 static int
144 read_uint32(uint32_t *value, const char *p)
145 {
146         uint64_t val = 0;
147         int ret = read_uint64(&val, p);
148
149         if (ret < 0)
150                 return ret;
151
152         if (val > UINT32_MAX)
153                 return -ERANGE;
154
155         *value = val;
156         return 0;
157 }
158
159 static int
160 parse_multi_ss_id_str(char *s_str, uint32_t *n_ssp, uint32_t shaper_id[])
161 {
162         uint32_t n_shared_shapers = 0, i = 0;
163         char *token;
164
165         /* First token: num of shared shapers */
166         token = strtok_r(s_str, PARSE_DELIMITER, &s_str);
167         if (token ==  NULL)
168                 return -1;
169
170         if (read_uint32(&n_shared_shapers, token))
171                 return -1;
172
173         /* Check: num of shared shaper */
174         if (n_shared_shapers >= MAX_NUM_SHARED_SHAPERS) {
175                 printf(" Number of shared shapers exceed the max (error)\n");
176                 return -1;
177         }
178
179         /* Parse shared shaper ids */
180         while (1) {
181                 token = strtok_r(s_str, PARSE_DELIMITER, &s_str);
182                 if ((token !=  NULL && n_shared_shapers == 0) ||
183                         (token == NULL && i < n_shared_shapers))
184                         return -1;
185
186                 if (token == NULL)
187                         break;
188
189                 if (read_uint32(&shaper_id[i], token))
190                         return -1;
191                 i++;
192         }
193         *n_ssp = n_shared_shapers;
194
195         return 0;
196 }
197 /* *** Port TM Capability *** */
198 struct cmd_show_port_tm_cap_result {
199         cmdline_fixed_string_t show;
200         cmdline_fixed_string_t port;
201         cmdline_fixed_string_t tm;
202         cmdline_fixed_string_t cap;
203         uint16_t port_id;
204 };
205
206 cmdline_parse_token_string_t cmd_show_port_tm_cap_show =
207         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result,
208                 show, "show");
209 cmdline_parse_token_string_t cmd_show_port_tm_cap_port =
210         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result,
211                 port, "port");
212 cmdline_parse_token_string_t cmd_show_port_tm_cap_tm =
213         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result,
214                 tm, "tm");
215 cmdline_parse_token_string_t cmd_show_port_tm_cap_cap =
216         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result,
217                 cap, "cap");
218 cmdline_parse_token_num_t cmd_show_port_tm_cap_port_id =
219         TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_cap_result,
220                  port_id, UINT16);
221
222 static void cmd_show_port_tm_cap_parsed(void *parsed_result,
223         __attribute__((unused)) struct cmdline *cl,
224         __attribute__((unused)) void *data)
225 {
226         struct cmd_show_port_tm_cap_result *res = parsed_result;
227         struct rte_tm_capabilities cap;
228         struct rte_tm_error error;
229         portid_t port_id = res->port_id;
230         uint32_t i;
231         int ret;
232
233         if (port_id_is_invalid(port_id, ENABLED_WARN))
234                 return;
235
236         memset(&cap, 0, sizeof(struct rte_tm_capabilities));
237         memset(&error, 0, sizeof(struct rte_tm_error));
238         ret = rte_tm_capabilities_get(port_id, &cap, &error);
239         if (ret) {
240                 print_err_msg(&error);
241                 return;
242         }
243
244         printf("\n****   Port TM Capabilities ****\n\n");
245         printf("cap.n_nodes_max %" PRIu32 "\n", cap.n_nodes_max);
246         printf("cap.n_levels_max %" PRIu32 "\n", cap.n_levels_max);
247         printf("cap.non_leaf_nodes_identical %" PRId32 "\n",
248                 cap.non_leaf_nodes_identical);
249         printf("cap.leaf_nodes_identical %" PRId32 "\n",
250                 cap.leaf_nodes_identical);
251         printf("cap.shaper_n_max %u\n", cap.shaper_n_max);
252         printf("cap.shaper_private_n_max %" PRIu32 "\n",
253                 cap.shaper_private_n_max);
254         printf("cap.shaper_private_dual_rate_n_max %" PRId32 "\n",
255                 cap.shaper_private_dual_rate_n_max);
256         printf("cap.shaper_private_rate_min %" PRIu64 "\n",
257                 cap.shaper_private_rate_min);
258         printf("cap.shaper_private_rate_max %" PRIu64 "\n",
259                 cap.shaper_private_rate_max);
260         printf("cap.shaper_shared_n_max %" PRIu32 "\n",
261                 cap.shaper_shared_n_max);
262         printf("cap.shaper_shared_n_nodes_per_shaper_max %" PRIu32 "\n",
263                 cap.shaper_shared_n_nodes_per_shaper_max);
264         printf("cap.shaper_shared_n_shapers_per_node_max %" PRIu32 "\n",
265                 cap.shaper_shared_n_shapers_per_node_max);
266         printf("cap.shaper_shared_dual_rate_n_max %" PRIu32 "\n",
267                 cap.shaper_shared_dual_rate_n_max);
268         printf("cap.shaper_shared_rate_min %" PRIu64 "\n",
269                 cap.shaper_shared_rate_min);
270         printf("cap.shaper_shared_rate_max %" PRIu64 "\n",
271                 cap.shaper_shared_rate_max);
272         printf("cap.shaper_pkt_length_adjust_min %" PRId32 "\n",
273                 cap.shaper_pkt_length_adjust_min);
274         printf("cap.shaper_pkt_length_adjust_max %" PRId32 "\n",
275                 cap.shaper_pkt_length_adjust_max);
276         printf("cap.sched_n_children_max %" PRIu32 "\n",
277                 cap.sched_n_children_max);
278         printf("cap.sched_sp_n_priorities_max %" PRIu32 "\n",
279                 cap.sched_sp_n_priorities_max);
280         printf("cap.sched_wfq_n_children_per_group_max %" PRIu32 "\n",
281                 cap.sched_wfq_n_children_per_group_max);
282         printf("cap.sched_wfq_n_groups_max %" PRIu32 "\n",
283                 cap.sched_wfq_n_groups_max);
284         printf("cap.sched_wfq_weight_max %" PRIu32 "\n",
285                 cap.sched_wfq_weight_max);
286         printf("cap.cman_head_drop_supported %" PRId32 "\n",
287                 cap.cman_head_drop_supported);
288         printf("cap.cman_wred_context_n_max %" PRIu32 "\n",
289                 cap.cman_wred_context_n_max);
290         printf("cap.cman_wred_context_private_n_max %" PRIu32 "\n",
291                 cap.cman_wred_context_private_n_max);
292         printf("cap.cman_wred_context_shared_n_max %" PRIu32 "\n",
293                 cap.cman_wred_context_shared_n_max);
294         printf("cap.cman_wred_context_shared_n_nodes_per_context_max %" PRIu32
295                 "\n", cap.cman_wred_context_shared_n_nodes_per_context_max);
296         printf("cap.cman_wred_context_shared_n_contexts_per_node_max %" PRIu32
297                 "\n", cap.cman_wred_context_shared_n_contexts_per_node_max);
298
299         for (i = 0; i < RTE_COLORS; i++) {
300                 printf("cap.mark_vlan_dei_supported %" PRId32 "\n",
301                         cap.mark_vlan_dei_supported[i]);
302                 printf("cap.mark_ip_ecn_tcp_supported %" PRId32 "\n",
303                         cap.mark_ip_ecn_tcp_supported[i]);
304                 printf("cap.mark_ip_ecn_sctp_supported %" PRId32 "\n",
305                         cap.mark_ip_ecn_sctp_supported[i]);
306                 printf("cap.mark_ip_dscp_supported %" PRId32 "\n",
307                         cap.mark_ip_dscp_supported[i]);
308         }
309
310         printf("cap.dynamic_update_mask %" PRIx64 "\n",
311                 cap.dynamic_update_mask);
312         printf("cap.stats_mask %" PRIx64 "\n", cap.stats_mask);
313 }
314
315 cmdline_parse_inst_t cmd_show_port_tm_cap = {
316         .f = cmd_show_port_tm_cap_parsed,
317         .data = NULL,
318         .help_str = "Show Port TM Capabilities",
319         .tokens = {
320                 (void *)&cmd_show_port_tm_cap_show,
321                 (void *)&cmd_show_port_tm_cap_port,
322                 (void *)&cmd_show_port_tm_cap_tm,
323                 (void *)&cmd_show_port_tm_cap_cap,
324                 (void *)&cmd_show_port_tm_cap_port_id,
325                 NULL,
326         },
327 };
328
329 /* *** Port TM Hierarchical Level Capability *** */
330 struct cmd_show_port_tm_level_cap_result {
331         cmdline_fixed_string_t show;
332         cmdline_fixed_string_t port;
333         cmdline_fixed_string_t tm;
334         cmdline_fixed_string_t level;
335         cmdline_fixed_string_t cap;
336         uint16_t port_id;
337         uint32_t level_id;
338 };
339
340 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_show =
341         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
342                 show, "show");
343 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_port =
344         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
345                 port, "port");
346 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_tm =
347         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
348                 tm, "tm");
349 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_level =
350         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
351                 level, "level");
352 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_cap =
353         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
354                 cap, "cap");
355 cmdline_parse_token_num_t cmd_show_port_tm_level_cap_port_id =
356         TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
357                  port_id, UINT16);
358 cmdline_parse_token_num_t cmd_show_port_tm_level_cap_level_id =
359         TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
360                  level_id, UINT32);
361
362
363 static void cmd_show_port_tm_level_cap_parsed(void *parsed_result,
364         __attribute__((unused)) struct cmdline *cl,
365         __attribute__((unused)) void *data)
366 {
367         struct cmd_show_port_tm_level_cap_result *res = parsed_result;
368         struct rte_tm_level_capabilities lcap;
369         struct rte_tm_error error;
370         portid_t port_id = res->port_id;
371         uint32_t level_id = res->level_id;
372         int ret;
373
374         if (port_id_is_invalid(port_id, ENABLED_WARN))
375                 return;
376
377         memset(&lcap, 0, sizeof(struct rte_tm_level_capabilities));
378         memset(&error, 0, sizeof(struct rte_tm_error));
379         ret = rte_tm_level_capabilities_get(port_id, level_id, &lcap, &error);
380         if (ret) {
381                 print_err_msg(&error);
382                 return;
383         }
384         printf("\n**   Port TM Hierarchy level %" PRIu32 " Capability **\n\n",
385                 level_id);
386
387         printf("cap.n_nodes_max %" PRIu32 "\n", lcap.n_nodes_max);
388         printf("cap.n_nodes_nonleaf_max %" PRIu32 "\n",
389                 lcap.n_nodes_nonleaf_max);
390         printf("cap.n_nodes_leaf_max %" PRIu32 "\n", lcap.n_nodes_leaf_max);
391         printf("cap.non_leaf_nodes_identical %" PRId32 "\n",
392                 lcap.non_leaf_nodes_identical);
393         printf("cap.leaf_nodes_identical %" PRId32 "\n",
394                 lcap.leaf_nodes_identical);
395         if (level_id <= 3) {
396                 printf("cap.nonleaf.shaper_private_supported %" PRId32 "\n",
397                         lcap.nonleaf.shaper_private_supported);
398                 printf("cap.nonleaf.shaper_private_dual_rate_supported %" PRId32
399                         "\n", lcap.nonleaf.shaper_private_dual_rate_supported);
400                 printf("cap.nonleaf.shaper_private_rate_min %" PRIu64 "\n",
401                         lcap.nonleaf.shaper_private_rate_min);
402                 printf("cap.nonleaf.shaper_private_rate_max %" PRIu64 "\n",
403                         lcap.nonleaf.shaper_private_rate_max);
404                 printf("cap.nonleaf.shaper_shared_n_max %" PRIu32 "\n",
405                         lcap.nonleaf.shaper_shared_n_max);
406                 printf("cap.nonleaf.sched_n_children_max %" PRIu32 "\n",
407                         lcap.nonleaf.sched_n_children_max);
408                 printf("cap.nonleaf.sched_sp_n_priorities_max %" PRIu32 "\n",
409                         lcap.nonleaf.sched_sp_n_priorities_max);
410                 printf("cap.nonleaf.sched_wfq_n_children_per_group_max %" PRIu32
411                         "\n", lcap.nonleaf.sched_wfq_n_children_per_group_max);
412                 printf("cap.nonleaf.sched_wfq_n_groups_max %" PRIu32 "\n",
413                         lcap.nonleaf.sched_wfq_n_groups_max);
414                 printf("cap.nonleaf.sched_wfq_weight_max %" PRIu32 "\n",
415                         lcap.nonleaf.sched_wfq_weight_max);
416                 printf("cap.nonleaf.stats_mask %" PRIx64 "\n",
417                         lcap.nonleaf.stats_mask);
418         } else {
419                 printf("cap.leaf.shaper_private_supported %" PRId32 "\n",
420                         lcap.leaf.shaper_private_supported);
421                 printf("cap.leaf.shaper_private_dual_rate_supported %" PRId32
422                         "\n", lcap.leaf.shaper_private_dual_rate_supported);
423                 printf("cap.leaf.shaper_private_rate_min %" PRIu64 "\n",
424                         lcap.leaf.shaper_private_rate_min);
425                 printf("cap.leaf.shaper_private_rate_max %" PRIu64 "\n",
426                         lcap.leaf.shaper_private_rate_max);
427                 printf("cap.leaf.shaper_shared_n_max %" PRIu32 "\n",
428                         lcap.leaf.shaper_shared_n_max);
429                 printf("cap.leaf.cman_head_drop_supported %" PRId32 "\n",
430                         lcap.leaf.cman_head_drop_supported);
431                 printf("cap.leaf.cman_wred_context_private_supported %" PRId32
432                         "\n", lcap.leaf.cman_wred_context_private_supported);
433                 printf("cap.leaf.cman_wred_context_shared_n_max %" PRIu32 "\n",
434                         lcap.leaf.cman_wred_context_shared_n_max);
435                 printf("cap.leaf.stats_mask %" PRIx64 "\n",
436                         lcap.leaf.stats_mask);
437         }
438 }
439
440 cmdline_parse_inst_t cmd_show_port_tm_level_cap = {
441         .f = cmd_show_port_tm_level_cap_parsed,
442         .data = NULL,
443         .help_str = "Show Port TM Hierarhical level Capabilities",
444         .tokens = {
445                 (void *)&cmd_show_port_tm_level_cap_show,
446                 (void *)&cmd_show_port_tm_level_cap_port,
447                 (void *)&cmd_show_port_tm_level_cap_tm,
448                 (void *)&cmd_show_port_tm_level_cap_level,
449                 (void *)&cmd_show_port_tm_level_cap_cap,
450                 (void *)&cmd_show_port_tm_level_cap_port_id,
451                 (void *)&cmd_show_port_tm_level_cap_level_id,
452                 NULL,
453         },
454 };
455
456 /* *** Port TM Hierarchy Node Capability *** */
457 struct cmd_show_port_tm_node_cap_result {
458         cmdline_fixed_string_t show;
459         cmdline_fixed_string_t port;
460         cmdline_fixed_string_t tm;
461         cmdline_fixed_string_t node;
462         cmdline_fixed_string_t cap;
463         uint16_t port_id;
464         uint32_t node_id;
465 };
466
467 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_show =
468         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
469                 show, "show");
470 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_port =
471         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
472                 port, "port");
473 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_tm =
474         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
475                 tm, "tm");
476 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_node =
477         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
478                 node, "node");
479 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_cap =
480         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
481                 cap, "cap");
482 cmdline_parse_token_num_t cmd_show_port_tm_node_cap_port_id =
483         TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
484                  port_id, UINT16);
485 cmdline_parse_token_num_t cmd_show_port_tm_node_cap_node_id =
486         TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
487                  node_id, UINT32);
488
489 static void cmd_show_port_tm_node_cap_parsed(void *parsed_result,
490         __attribute__((unused)) struct cmdline *cl,
491         __attribute__((unused)) void *data)
492 {
493         struct cmd_show_port_tm_node_cap_result *res = parsed_result;
494         struct rte_tm_node_capabilities ncap;
495         struct rte_tm_error error;
496         uint32_t node_id = res->node_id;
497         portid_t port_id = res->port_id;
498         int ret, is_leaf = 0;
499
500         if (port_id_is_invalid(port_id, ENABLED_WARN))
501                 return;
502
503         memset(&error, 0, sizeof(struct rte_tm_error));
504         /* Node id must be valid */
505         ret = rte_tm_node_type_get(port_id, node_id, &is_leaf, &error);
506         if (ret != 0) {
507                 print_err_msg(&error);
508                 return;
509         }
510
511         memset(&ncap, 0, sizeof(struct rte_tm_node_capabilities));
512         ret = rte_tm_node_capabilities_get(port_id, node_id, &ncap, &error);
513         if (ret != 0) {
514                 print_err_msg(&error);
515                 return;
516         }
517         printf("\n**   Port TM Hierarchy node %" PRIu32 " Capability **\n\n",
518                 node_id);
519         printf("cap.shaper_private_supported %" PRId32 "\n",
520                 ncap.shaper_private_supported);
521         printf("cap.shaper_private_dual_rate_supported %" PRId32 "\n",
522                 ncap.shaper_private_dual_rate_supported);
523         printf("cap.shaper_private_rate_min %" PRIu64 "\n",
524                 ncap.shaper_private_rate_min);
525         printf("cap.shaper_private_rate_max %" PRIu64 "\n",
526                 ncap.shaper_private_rate_max);
527         printf("cap.shaper_shared_n_max %" PRIu32 "\n",
528                 ncap.shaper_shared_n_max);
529         if (!is_leaf) {
530                 printf("cap.nonleaf.sched_n_children_max %" PRIu32 "\n",
531                         ncap.nonleaf.sched_n_children_max);
532                 printf("cap.nonleaf.sched_sp_n_priorities_max %" PRIu32 "\n",
533                         ncap.nonleaf.sched_sp_n_priorities_max);
534                 printf("cap.nonleaf.sched_wfq_n_children_per_group_max %" PRIu32
535                         "\n", ncap.nonleaf.sched_wfq_n_children_per_group_max);
536                 printf("cap.nonleaf.sched_wfq_n_groups_max %" PRIu32 "\n",
537                         ncap.nonleaf.sched_wfq_n_groups_max);
538                 printf("cap.nonleaf.sched_wfq_weight_max %" PRIu32 "\n",
539                         ncap.nonleaf.sched_wfq_weight_max);
540         } else {
541                 printf("cap.leaf.cman_head_drop_supported %" PRId32 "\n",
542                         ncap.leaf.cman_head_drop_supported);
543                 printf("cap.leaf.cman_wred_context_private_supported %" PRId32
544                         "\n", ncap.leaf.cman_wred_context_private_supported);
545                 printf("cap.leaf.cman_wred_context_shared_n_max %" PRIu32 "\n",
546                         ncap.leaf.cman_wred_context_shared_n_max);
547         }
548         printf("cap.stats_mask %" PRIx64 "\n", ncap.stats_mask);
549 }
550
551 cmdline_parse_inst_t cmd_show_port_tm_node_cap = {
552         .f = cmd_show_port_tm_node_cap_parsed,
553         .data = NULL,
554         .help_str = "Show Port TM Hierarchy node capabilities",
555         .tokens = {
556                 (void *)&cmd_show_port_tm_node_cap_show,
557                 (void *)&cmd_show_port_tm_node_cap_port,
558                 (void *)&cmd_show_port_tm_node_cap_tm,
559                 (void *)&cmd_show_port_tm_node_cap_node,
560                 (void *)&cmd_show_port_tm_node_cap_cap,
561                 (void *)&cmd_show_port_tm_node_cap_port_id,
562                 (void *)&cmd_show_port_tm_node_cap_node_id,
563                 NULL,
564         },
565 };
566
567 /* *** Show Port TM Node Statistics *** */
568 struct cmd_show_port_tm_node_stats_result {
569         cmdline_fixed_string_t show;
570         cmdline_fixed_string_t port;
571         cmdline_fixed_string_t tm;
572         cmdline_fixed_string_t node;
573         cmdline_fixed_string_t stats;
574         uint16_t port_id;
575         uint32_t node_id;
576         uint32_t clear;
577 };
578
579 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_show =
580         TOKEN_STRING_INITIALIZER(
581                 struct cmd_show_port_tm_node_stats_result, show, "show");
582 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_port =
583         TOKEN_STRING_INITIALIZER(
584                 struct cmd_show_port_tm_node_stats_result, port, "port");
585 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_tm =
586         TOKEN_STRING_INITIALIZER(
587                 struct cmd_show_port_tm_node_stats_result, tm, "tm");
588 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_node =
589         TOKEN_STRING_INITIALIZER(
590                 struct cmd_show_port_tm_node_stats_result, node, "node");
591 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_stats =
592         TOKEN_STRING_INITIALIZER(
593                 struct cmd_show_port_tm_node_stats_result, stats, "stats");
594 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_port_id =
595         TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_stats_result,
596                         port_id, UINT16);
597 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_node_id =
598         TOKEN_NUM_INITIALIZER(
599                 struct cmd_show_port_tm_node_stats_result,
600                         node_id, UINT32);
601 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_clear =
602         TOKEN_NUM_INITIALIZER(
603                 struct cmd_show_port_tm_node_stats_result, clear, UINT32);
604
605 static void cmd_show_port_tm_node_stats_parsed(void *parsed_result,
606         __attribute__((unused)) struct cmdline *cl,
607         __attribute__((unused)) void *data)
608 {
609         struct cmd_show_port_tm_node_stats_result *res = parsed_result;
610         struct rte_tm_node_stats stats;
611         struct rte_tm_error error;
612         uint64_t stats_mask = 0;
613         uint32_t node_id = res->node_id;
614         uint32_t clear = res->clear;
615         portid_t port_id = res->port_id;
616         int ret;
617
618         if (port_id_is_invalid(port_id, ENABLED_WARN))
619                 return;
620
621         memset(&error, 0, sizeof(struct rte_tm_error));
622         /* Port status */
623         if (!port_is_started(port_id)) {
624                 printf(" Port %u not started (error)\n", port_id);
625                 return;
626         }
627
628         memset(&stats, 0, sizeof(struct rte_tm_node_stats));
629         ret = rte_tm_node_stats_read(port_id, node_id, &stats,
630                         &stats_mask, clear, &error);
631         if (ret != 0) {
632                 print_err_msg(&error);
633                 return;
634         }
635
636         /* Display stats */
637         if (stats_mask & RTE_TM_STATS_N_PKTS)
638                 printf("\tPkts scheduled from node: %" PRIu64 "\n",
639                         stats.n_pkts);
640         if (stats_mask & RTE_TM_STATS_N_BYTES)
641                 printf("\tBytes scheduled from node: %" PRIu64 "\n",
642                         stats.n_bytes);
643         if (stats_mask & RTE_TM_STATS_N_PKTS_GREEN_DROPPED)
644                 printf("\tPkts dropped (green): %" PRIu64 "\n",
645                         stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN]);
646         if (stats_mask & RTE_TM_STATS_N_PKTS_YELLOW_DROPPED)
647                 printf("\tPkts dropped (yellow): %" PRIu64 "\n",
648                         stats.leaf.n_pkts_dropped[RTE_COLOR_YELLOW]);
649         if (stats_mask & RTE_TM_STATS_N_PKTS_RED_DROPPED)
650                 printf("\tPkts dropped (red): %" PRIu64 "\n",
651                         stats.leaf.n_pkts_dropped[RTE_COLOR_RED]);
652         if (stats_mask & RTE_TM_STATS_N_BYTES_GREEN_DROPPED)
653                 printf("\tBytes dropped (green): %" PRIu64 "\n",
654                         stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN]);
655         if (stats_mask & RTE_TM_STATS_N_BYTES_YELLOW_DROPPED)
656                 printf("\tBytes dropped (yellow): %" PRIu64 "\n",
657                         stats.leaf.n_bytes_dropped[RTE_COLOR_YELLOW]);
658         if (stats_mask & RTE_TM_STATS_N_BYTES_RED_DROPPED)
659                 printf("\tBytes dropped (red): %" PRIu64 "\n",
660                         stats.leaf.n_bytes_dropped[RTE_COLOR_RED]);
661         if (stats_mask & RTE_TM_STATS_N_PKTS_QUEUED)
662                 printf("\tPkts queued: %" PRIu64 "\n",
663                         stats.leaf.n_pkts_queued);
664         if (stats_mask & RTE_TM_STATS_N_BYTES_QUEUED)
665                 printf("\tBytes queued: %" PRIu64 "\n",
666                         stats.leaf.n_bytes_queued);
667 }
668
669 cmdline_parse_inst_t cmd_show_port_tm_node_stats = {
670         .f = cmd_show_port_tm_node_stats_parsed,
671         .data = NULL,
672         .help_str = "Show port tm node stats",
673         .tokens = {
674                 (void *)&cmd_show_port_tm_node_stats_show,
675                 (void *)&cmd_show_port_tm_node_stats_port,
676                 (void *)&cmd_show_port_tm_node_stats_tm,
677                 (void *)&cmd_show_port_tm_node_stats_node,
678                 (void *)&cmd_show_port_tm_node_stats_stats,
679                 (void *)&cmd_show_port_tm_node_stats_port_id,
680                 (void *)&cmd_show_port_tm_node_stats_node_id,
681                 (void *)&cmd_show_port_tm_node_stats_clear,
682                 NULL,
683         },
684 };
685
686 /* *** Show Port TM Node Type *** */
687 struct cmd_show_port_tm_node_type_result {
688         cmdline_fixed_string_t show;
689         cmdline_fixed_string_t port;
690         cmdline_fixed_string_t tm;
691         cmdline_fixed_string_t node;
692         cmdline_fixed_string_t type;
693         uint16_t port_id;
694         uint32_t node_id;
695 };
696
697 cmdline_parse_token_string_t cmd_show_port_tm_node_type_show =
698         TOKEN_STRING_INITIALIZER(
699                 struct cmd_show_port_tm_node_type_result, show, "show");
700 cmdline_parse_token_string_t cmd_show_port_tm_node_type_port =
701         TOKEN_STRING_INITIALIZER(
702                 struct cmd_show_port_tm_node_type_result, port, "port");
703 cmdline_parse_token_string_t cmd_show_port_tm_node_type_tm =
704         TOKEN_STRING_INITIALIZER(
705                 struct cmd_show_port_tm_node_type_result, tm, "tm");
706 cmdline_parse_token_string_t cmd_show_port_tm_node_type_node =
707         TOKEN_STRING_INITIALIZER(
708                 struct cmd_show_port_tm_node_type_result, node, "node");
709 cmdline_parse_token_string_t cmd_show_port_tm_node_type_type =
710         TOKEN_STRING_INITIALIZER(
711                 struct cmd_show_port_tm_node_type_result, type, "type");
712 cmdline_parse_token_num_t cmd_show_port_tm_node_type_port_id =
713         TOKEN_NUM_INITIALIZER(
714                 struct cmd_show_port_tm_node_type_result,
715                         port_id, UINT16);
716 cmdline_parse_token_num_t cmd_show_port_tm_node_type_node_id =
717         TOKEN_NUM_INITIALIZER(
718                 struct cmd_show_port_tm_node_type_result,
719                         node_id, UINT32);
720
721 static void cmd_show_port_tm_node_type_parsed(void *parsed_result,
722         __attribute__((unused)) struct cmdline *cl,
723         __attribute__((unused)) void *data)
724 {
725         struct cmd_show_port_tm_node_type_result *res = parsed_result;
726         struct rte_tm_error error;
727         uint32_t node_id = res->node_id;
728         portid_t port_id = res->port_id;
729         int ret, is_leaf = 0;
730
731         if (port_id_is_invalid(port_id, ENABLED_WARN))
732                 return;
733
734         memset(&error, 0, sizeof(struct rte_tm_error));
735         ret = rte_tm_node_type_get(port_id, node_id, &is_leaf, &error);
736         if (ret != 0) {
737                 print_err_msg(&error);
738                 return;
739         }
740
741         if (is_leaf == 1)
742                 printf("leaf node\n");
743         else
744                 printf("nonleaf node\n");
745
746 }
747
748 cmdline_parse_inst_t cmd_show_port_tm_node_type = {
749         .f = cmd_show_port_tm_node_type_parsed,
750         .data = NULL,
751         .help_str = "Show port tm node type",
752         .tokens = {
753                 (void *)&cmd_show_port_tm_node_type_show,
754                 (void *)&cmd_show_port_tm_node_type_port,
755                 (void *)&cmd_show_port_tm_node_type_tm,
756                 (void *)&cmd_show_port_tm_node_type_node,
757                 (void *)&cmd_show_port_tm_node_type_type,
758                 (void *)&cmd_show_port_tm_node_type_port_id,
759                 (void *)&cmd_show_port_tm_node_type_node_id,
760                 NULL,
761         },
762 };
763
764 /* *** Add Port TM Private Shaper Profile *** */
765 struct cmd_add_port_tm_node_shaper_profile_result {
766         cmdline_fixed_string_t add;
767         cmdline_fixed_string_t port;
768         cmdline_fixed_string_t tm;
769         cmdline_fixed_string_t node;
770         cmdline_fixed_string_t shaper;
771         cmdline_fixed_string_t profile;
772         uint16_t port_id;
773         uint32_t shaper_id;
774         uint64_t cmit_tb_rate;
775         uint64_t cmit_tb_size;
776         uint64_t peak_tb_rate;
777         uint64_t peak_tb_size;
778         uint32_t pktlen_adjust;
779 };
780
781 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_add =
782         TOKEN_STRING_INITIALIZER(
783                 struct cmd_add_port_tm_node_shaper_profile_result, add, "add");
784 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_port =
785         TOKEN_STRING_INITIALIZER(
786                 struct cmd_add_port_tm_node_shaper_profile_result,
787                         port, "port");
788 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_tm =
789         TOKEN_STRING_INITIALIZER(
790                 struct cmd_add_port_tm_node_shaper_profile_result,
791                         tm, "tm");
792 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_node =
793         TOKEN_STRING_INITIALIZER(
794                 struct cmd_add_port_tm_node_shaper_profile_result,
795                         node, "node");
796 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_shaper =
797         TOKEN_STRING_INITIALIZER(
798                 struct cmd_add_port_tm_node_shaper_profile_result,
799                         shaper, "shaper");
800 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_profile =
801         TOKEN_STRING_INITIALIZER(
802                 struct cmd_add_port_tm_node_shaper_profile_result,
803                         profile, "profile");
804 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_port_id =
805         TOKEN_NUM_INITIALIZER(
806                 struct cmd_add_port_tm_node_shaper_profile_result,
807                         port_id, UINT16);
808 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_shaper_id =
809         TOKEN_NUM_INITIALIZER(
810                 struct cmd_add_port_tm_node_shaper_profile_result,
811                         shaper_id, UINT32);
812 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_cmit_tb_rate =
813         TOKEN_NUM_INITIALIZER(
814                 struct cmd_add_port_tm_node_shaper_profile_result,
815                         cmit_tb_rate, UINT64);
816 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_cmit_tb_size =
817         TOKEN_NUM_INITIALIZER(
818                 struct cmd_add_port_tm_node_shaper_profile_result,
819                         cmit_tb_size, UINT64);
820 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_peak_tb_rate =
821         TOKEN_NUM_INITIALIZER(
822                 struct cmd_add_port_tm_node_shaper_profile_result,
823                         peak_tb_rate, UINT64);
824 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_peak_tb_size =
825         TOKEN_NUM_INITIALIZER(
826                 struct cmd_add_port_tm_node_shaper_profile_result,
827                         peak_tb_size, UINT64);
828 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_pktlen_adjust =
829         TOKEN_NUM_INITIALIZER(
830                 struct cmd_add_port_tm_node_shaper_profile_result,
831                         pktlen_adjust, UINT32);
832
833 static void cmd_add_port_tm_node_shaper_profile_parsed(void *parsed_result,
834         __attribute__((unused)) struct cmdline *cl,
835         __attribute__((unused)) void *data)
836 {
837         struct cmd_add_port_tm_node_shaper_profile_result *res = parsed_result;
838         struct rte_tm_shaper_params sp;
839         struct rte_tm_error error;
840         uint32_t shaper_id = res->shaper_id;
841         uint32_t pkt_len_adjust = res->pktlen_adjust;
842         portid_t port_id = res->port_id;
843         int ret;
844
845         if (port_id_is_invalid(port_id, ENABLED_WARN))
846                 return;
847
848         /* Private shaper profile params */
849         memset(&sp, 0, sizeof(struct rte_tm_shaper_params));
850         memset(&error, 0, sizeof(struct rte_tm_error));
851         sp.committed.rate = res->cmit_tb_rate;
852         sp.committed.size = res->cmit_tb_size;
853         sp.peak.rate = res->peak_tb_rate;
854         sp.peak.size = res->peak_tb_size;
855         sp.pkt_length_adjust = pkt_len_adjust;
856
857         ret = rte_tm_shaper_profile_add(port_id, shaper_id, &sp, &error);
858         if (ret != 0) {
859                 print_err_msg(&error);
860                 return;
861         }
862 }
863
864 cmdline_parse_inst_t cmd_add_port_tm_node_shaper_profile = {
865         .f = cmd_add_port_tm_node_shaper_profile_parsed,
866         .data = NULL,
867         .help_str = "Add port tm node private shaper profile",
868         .tokens = {
869                 (void *)&cmd_add_port_tm_node_shaper_profile_add,
870                 (void *)&cmd_add_port_tm_node_shaper_profile_port,
871                 (void *)&cmd_add_port_tm_node_shaper_profile_tm,
872                 (void *)&cmd_add_port_tm_node_shaper_profile_node,
873                 (void *)&cmd_add_port_tm_node_shaper_profile_shaper,
874                 (void *)&cmd_add_port_tm_node_shaper_profile_profile,
875                 (void *)&cmd_add_port_tm_node_shaper_profile_port_id,
876                 (void *)&cmd_add_port_tm_node_shaper_profile_shaper_id,
877                 (void *)&cmd_add_port_tm_node_shaper_profile_cmit_tb_rate,
878                 (void *)&cmd_add_port_tm_node_shaper_profile_cmit_tb_size,
879                 (void *)&cmd_add_port_tm_node_shaper_profile_peak_tb_rate,
880                 (void *)&cmd_add_port_tm_node_shaper_profile_peak_tb_size,
881                 (void *)&cmd_add_port_tm_node_shaper_profile_pktlen_adjust,
882                 NULL,
883         },
884 };
885
886 /* *** Delete Port TM Private Shaper Profile *** */
887 struct cmd_del_port_tm_node_shaper_profile_result {
888         cmdline_fixed_string_t del;
889         cmdline_fixed_string_t port;
890         cmdline_fixed_string_t tm;
891         cmdline_fixed_string_t node;
892         cmdline_fixed_string_t shaper;
893         cmdline_fixed_string_t profile;
894         uint16_t port_id;
895         uint32_t shaper_id;
896 };
897
898 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_del =
899         TOKEN_STRING_INITIALIZER(
900                 struct cmd_del_port_tm_node_shaper_profile_result, del, "del");
901 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_port =
902         TOKEN_STRING_INITIALIZER(
903                 struct cmd_del_port_tm_node_shaper_profile_result,
904                         port, "port");
905 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_tm =
906         TOKEN_STRING_INITIALIZER(
907                 struct cmd_del_port_tm_node_shaper_profile_result, tm, "tm");
908 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_node =
909         TOKEN_STRING_INITIALIZER(
910                 struct cmd_del_port_tm_node_shaper_profile_result,
911                         node, "node");
912 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_shaper =
913         TOKEN_STRING_INITIALIZER(
914                 struct cmd_del_port_tm_node_shaper_profile_result,
915                         shaper, "shaper");
916 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_profile =
917         TOKEN_STRING_INITIALIZER(
918                 struct cmd_del_port_tm_node_shaper_profile_result,
919                         profile, "profile");
920 cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_port_id =
921         TOKEN_NUM_INITIALIZER(
922                 struct cmd_del_port_tm_node_shaper_profile_result,
923                         port_id, UINT16);
924 cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_shaper_id =
925         TOKEN_NUM_INITIALIZER(
926                 struct cmd_del_port_tm_node_shaper_profile_result,
927                         shaper_id, UINT32);
928
929 static void cmd_del_port_tm_node_shaper_profile_parsed(void *parsed_result,
930         __attribute__((unused)) struct cmdline *cl,
931         __attribute__((unused)) void *data)
932 {
933         struct cmd_del_port_tm_node_shaper_profile_result *res = parsed_result;
934         struct rte_tm_error error;
935         uint32_t shaper_id = res->shaper_id;
936         portid_t port_id = res->port_id;
937         int ret;
938
939         if (port_id_is_invalid(port_id, ENABLED_WARN))
940                 return;
941
942         memset(&error, 0, sizeof(struct rte_tm_error));
943         ret = rte_tm_shaper_profile_delete(port_id, shaper_id, &error);
944         if (ret != 0) {
945                 print_err_msg(&error);
946                 return;
947         }
948 }
949
950 cmdline_parse_inst_t cmd_del_port_tm_node_shaper_profile = {
951         .f = cmd_del_port_tm_node_shaper_profile_parsed,
952         .data = NULL,
953         .help_str = "Delete port tm node private shaper profile",
954         .tokens = {
955                 (void *)&cmd_del_port_tm_node_shaper_profile_del,
956                 (void *)&cmd_del_port_tm_node_shaper_profile_port,
957                 (void *)&cmd_del_port_tm_node_shaper_profile_tm,
958                 (void *)&cmd_del_port_tm_node_shaper_profile_node,
959                 (void *)&cmd_del_port_tm_node_shaper_profile_shaper,
960                 (void *)&cmd_del_port_tm_node_shaper_profile_profile,
961                 (void *)&cmd_del_port_tm_node_shaper_profile_port_id,
962                 (void *)&cmd_del_port_tm_node_shaper_profile_shaper_id,
963                 NULL,
964         },
965 };
966
967 /* *** Add/Update Port TM shared Shaper *** */
968 struct cmd_add_port_tm_node_shared_shaper_result {
969         cmdline_fixed_string_t cmd_type;
970         cmdline_fixed_string_t port;
971         cmdline_fixed_string_t tm;
972         cmdline_fixed_string_t node;
973         cmdline_fixed_string_t shared;
974         cmdline_fixed_string_t shaper;
975         uint16_t port_id;
976         uint32_t shared_shaper_id;
977         uint32_t shaper_profile_id;
978 };
979
980 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_cmd_type =
981         TOKEN_STRING_INITIALIZER(
982                 struct cmd_add_port_tm_node_shared_shaper_result,
983                         cmd_type, "add#set");
984 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_port =
985         TOKEN_STRING_INITIALIZER(
986                 struct cmd_add_port_tm_node_shared_shaper_result, port, "port");
987 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_tm =
988         TOKEN_STRING_INITIALIZER(
989                 struct cmd_add_port_tm_node_shared_shaper_result, tm, "tm");
990 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_node =
991         TOKEN_STRING_INITIALIZER(
992                 struct cmd_add_port_tm_node_shared_shaper_result, node, "node");
993 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shared =
994         TOKEN_STRING_INITIALIZER(
995                 struct cmd_add_port_tm_node_shared_shaper_result,
996                         shared, "shared");
997 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shaper =
998         TOKEN_STRING_INITIALIZER(
999                 struct cmd_add_port_tm_node_shared_shaper_result,
1000                         shaper, "shaper");
1001 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_port_id =
1002         TOKEN_NUM_INITIALIZER(
1003                 struct cmd_add_port_tm_node_shared_shaper_result,
1004                         port_id, UINT16);
1005 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shared_shaper_id =
1006         TOKEN_NUM_INITIALIZER(
1007                 struct cmd_add_port_tm_node_shared_shaper_result,
1008                         shared_shaper_id, UINT32);
1009 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shaper_profile_id =
1010         TOKEN_NUM_INITIALIZER(
1011                 struct cmd_add_port_tm_node_shared_shaper_result,
1012                         shaper_profile_id, UINT32);
1013
1014 static void cmd_add_port_tm_node_shared_shaper_parsed(void *parsed_result,
1015         __attribute__((unused)) struct cmdline *cl,
1016         __attribute__((unused)) void *data)
1017 {
1018         struct cmd_add_port_tm_node_shared_shaper_result *res = parsed_result;
1019         struct rte_tm_error error;
1020         uint32_t shared_shaper_id = res->shared_shaper_id;
1021         uint32_t shaper_profile_id = res->shaper_profile_id;
1022         portid_t port_id = res->port_id;
1023         int ret;
1024
1025         if (port_id_is_invalid(port_id, ENABLED_WARN))
1026                 return;
1027
1028         memset(&error, 0, sizeof(struct rte_tm_error));
1029         /* Command type: add */
1030         if ((strcmp(res->cmd_type, "add") == 0) &&
1031                 (port_is_started(port_id))) {
1032                 printf(" Port %u not stopped (error)\n", port_id);
1033                 return;
1034         }
1035
1036         /* Command type: set (update) */
1037         if ((strcmp(res->cmd_type, "set") == 0) &&
1038                 (!port_is_started(port_id))) {
1039                 printf(" Port %u not started (error)\n", port_id);
1040                 return;
1041         }
1042
1043         ret = rte_tm_shared_shaper_add_update(port_id, shared_shaper_id,
1044                 shaper_profile_id, &error);
1045         if (ret != 0) {
1046                 print_err_msg(&error);
1047                 return;
1048         }
1049 }
1050
1051 cmdline_parse_inst_t cmd_add_port_tm_node_shared_shaper = {
1052         .f = cmd_add_port_tm_node_shared_shaper_parsed,
1053         .data = NULL,
1054         .help_str = "add/update port tm node shared shaper",
1055         .tokens = {
1056                 (void *)&cmd_add_port_tm_node_shared_shaper_cmd_type,
1057                 (void *)&cmd_add_port_tm_node_shared_shaper_port,
1058                 (void *)&cmd_add_port_tm_node_shared_shaper_tm,
1059                 (void *)&cmd_add_port_tm_node_shared_shaper_node,
1060                 (void *)&cmd_add_port_tm_node_shared_shaper_shared,
1061                 (void *)&cmd_add_port_tm_node_shared_shaper_shaper,
1062                 (void *)&cmd_add_port_tm_node_shared_shaper_port_id,
1063                 (void *)&cmd_add_port_tm_node_shared_shaper_shared_shaper_id,
1064                 (void *)&cmd_add_port_tm_node_shared_shaper_shaper_profile_id,
1065                 NULL,
1066         },
1067 };
1068
1069 /* *** Delete Port TM shared Shaper *** */
1070 struct cmd_del_port_tm_node_shared_shaper_result {
1071         cmdline_fixed_string_t del;
1072         cmdline_fixed_string_t port;
1073         cmdline_fixed_string_t tm;
1074         cmdline_fixed_string_t node;
1075         cmdline_fixed_string_t shared;
1076         cmdline_fixed_string_t shaper;
1077         uint16_t port_id;
1078         uint32_t shared_shaper_id;
1079 };
1080
1081 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_del =
1082         TOKEN_STRING_INITIALIZER(
1083                 struct cmd_del_port_tm_node_shared_shaper_result, del, "del");
1084 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_port =
1085         TOKEN_STRING_INITIALIZER(
1086                 struct cmd_del_port_tm_node_shared_shaper_result, port, "port");
1087 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_tm =
1088         TOKEN_STRING_INITIALIZER(
1089                 struct cmd_del_port_tm_node_shared_shaper_result, tm, "tm");
1090 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_node =
1091         TOKEN_STRING_INITIALIZER(
1092                 struct cmd_del_port_tm_node_shared_shaper_result, node, "node");
1093 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shared =
1094         TOKEN_STRING_INITIALIZER(
1095                 struct cmd_del_port_tm_node_shared_shaper_result,
1096                         shared, "shared");
1097 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shaper =
1098         TOKEN_STRING_INITIALIZER(
1099                 struct cmd_del_port_tm_node_shared_shaper_result,
1100                         shaper, "shaper");
1101 cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_port_id =
1102         TOKEN_NUM_INITIALIZER(
1103                 struct cmd_del_port_tm_node_shared_shaper_result,
1104                         port_id, UINT16);
1105 cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_shared_shaper_id =
1106         TOKEN_NUM_INITIALIZER(
1107                 struct cmd_del_port_tm_node_shared_shaper_result,
1108                         shared_shaper_id, UINT32);
1109
1110 static void cmd_del_port_tm_node_shared_shaper_parsed(void *parsed_result,
1111         __attribute__((unused)) struct cmdline *cl,
1112         __attribute__((unused)) void *data)
1113 {
1114         struct cmd_del_port_tm_node_shared_shaper_result *res = parsed_result;
1115         struct rte_tm_error error;
1116         uint32_t shared_shaper_id = res->shared_shaper_id;
1117         portid_t port_id = res->port_id;
1118         int ret;
1119
1120         if (port_id_is_invalid(port_id, ENABLED_WARN))
1121                 return;
1122
1123         memset(&error, 0, sizeof(struct rte_tm_error));
1124         ret = rte_tm_shared_shaper_delete(port_id, shared_shaper_id, &error);
1125         if (ret != 0) {
1126                 print_err_msg(&error);
1127                 return;
1128         }
1129 }
1130
1131 cmdline_parse_inst_t cmd_del_port_tm_node_shared_shaper = {
1132         .f = cmd_del_port_tm_node_shared_shaper_parsed,
1133         .data = NULL,
1134         .help_str = "delete port tm node shared shaper",
1135         .tokens = {
1136                 (void *)&cmd_del_port_tm_node_shared_shaper_del,
1137                 (void *)&cmd_del_port_tm_node_shared_shaper_port,
1138                 (void *)&cmd_del_port_tm_node_shared_shaper_tm,
1139                 (void *)&cmd_del_port_tm_node_shared_shaper_node,
1140                 (void *)&cmd_del_port_tm_node_shared_shaper_shared,
1141                 (void *)&cmd_del_port_tm_node_shared_shaper_shaper,
1142                 (void *)&cmd_del_port_tm_node_shared_shaper_port_id,
1143                 (void *)&cmd_del_port_tm_node_shared_shaper_shared_shaper_id,
1144                 NULL,
1145         },
1146 };
1147
1148 /* *** Add Port TM Node WRED Profile *** */
1149 struct cmd_add_port_tm_node_wred_profile_result {
1150         cmdline_fixed_string_t add;
1151         cmdline_fixed_string_t port;
1152         cmdline_fixed_string_t tm;
1153         cmdline_fixed_string_t node;
1154         cmdline_fixed_string_t wred;
1155         cmdline_fixed_string_t profile;
1156         uint16_t port_id;
1157         uint32_t wred_profile_id;
1158         cmdline_fixed_string_t color_g;
1159         uint64_t min_th_g;
1160         uint64_t max_th_g;
1161         uint16_t maxp_inv_g;
1162         uint16_t wq_log2_g;
1163         cmdline_fixed_string_t color_y;
1164         uint64_t min_th_y;
1165         uint64_t max_th_y;
1166         uint16_t maxp_inv_y;
1167         uint16_t wq_log2_y;
1168         cmdline_fixed_string_t color_r;
1169         uint64_t min_th_r;
1170         uint64_t max_th_r;
1171         uint16_t maxp_inv_r;
1172         uint16_t wq_log2_r;
1173 };
1174
1175 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_add =
1176         TOKEN_STRING_INITIALIZER(
1177                 struct cmd_add_port_tm_node_wred_profile_result, add, "add");
1178 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_port =
1179         TOKEN_STRING_INITIALIZER(
1180                 struct cmd_add_port_tm_node_wred_profile_result, port, "port");
1181 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_tm =
1182         TOKEN_STRING_INITIALIZER(
1183                 struct cmd_add_port_tm_node_wred_profile_result, tm, "tm");
1184 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_node =
1185         TOKEN_STRING_INITIALIZER(
1186                 struct cmd_add_port_tm_node_wred_profile_result, node, "node");
1187 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_wred =
1188         TOKEN_STRING_INITIALIZER(
1189                 struct cmd_add_port_tm_node_wred_profile_result, wred, "wred");
1190 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_profile =
1191         TOKEN_STRING_INITIALIZER(
1192                 struct cmd_add_port_tm_node_wred_profile_result,
1193                         profile, "profile");
1194 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_port_id =
1195         TOKEN_NUM_INITIALIZER(
1196                 struct cmd_add_port_tm_node_wred_profile_result,
1197                         port_id, UINT16);
1198 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wred_profile_id =
1199         TOKEN_NUM_INITIALIZER(
1200                 struct cmd_add_port_tm_node_wred_profile_result,
1201                         wred_profile_id, UINT32);
1202 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_g =
1203         TOKEN_STRING_INITIALIZER(
1204                 struct cmd_add_port_tm_node_wred_profile_result,
1205                         color_g, "G#g");
1206 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_g =
1207         TOKEN_NUM_INITIALIZER(
1208                 struct cmd_add_port_tm_node_wred_profile_result,
1209                         min_th_g, UINT64);
1210 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_g =
1211         TOKEN_NUM_INITIALIZER(
1212                 struct cmd_add_port_tm_node_wred_profile_result,
1213                         max_th_g, UINT64);
1214 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_g =
1215         TOKEN_NUM_INITIALIZER(
1216                 struct cmd_add_port_tm_node_wred_profile_result,
1217                         maxp_inv_g, UINT16);
1218 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_g =
1219         TOKEN_NUM_INITIALIZER(
1220                 struct cmd_add_port_tm_node_wred_profile_result,
1221                         wq_log2_g, UINT16);
1222 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_y =
1223         TOKEN_STRING_INITIALIZER(
1224                 struct cmd_add_port_tm_node_wred_profile_result,
1225                         color_y, "Y#y");
1226 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_y =
1227         TOKEN_NUM_INITIALIZER(
1228                 struct cmd_add_port_tm_node_wred_profile_result,
1229                         min_th_y, UINT64);
1230 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_y =
1231         TOKEN_NUM_INITIALIZER(
1232                 struct cmd_add_port_tm_node_wred_profile_result,
1233                         max_th_y, UINT64);
1234 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_y =
1235         TOKEN_NUM_INITIALIZER(
1236                 struct cmd_add_port_tm_node_wred_profile_result,
1237                         maxp_inv_y, UINT16);
1238 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_y =
1239         TOKEN_NUM_INITIALIZER(
1240                 struct cmd_add_port_tm_node_wred_profile_result,
1241                         wq_log2_y, UINT16);
1242 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_r =
1243         TOKEN_STRING_INITIALIZER(
1244                 struct cmd_add_port_tm_node_wred_profile_result,
1245                         color_r, "R#r");
1246 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_r =
1247         TOKEN_NUM_INITIALIZER(
1248                 struct cmd_add_port_tm_node_wred_profile_result,
1249                         min_th_r, UINT64);
1250 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_r =
1251         TOKEN_NUM_INITIALIZER(
1252                 struct cmd_add_port_tm_node_wred_profile_result,
1253                         max_th_r, UINT64);
1254 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_r =
1255         TOKEN_NUM_INITIALIZER(
1256                 struct cmd_add_port_tm_node_wred_profile_result,
1257                         maxp_inv_r, UINT16);
1258 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_r =
1259         TOKEN_NUM_INITIALIZER(
1260                 struct cmd_add_port_tm_node_wred_profile_result,
1261                         wq_log2_r, UINT16);
1262
1263
1264 static void cmd_add_port_tm_node_wred_profile_parsed(void *parsed_result,
1265         __attribute__((unused)) struct cmdline *cl,
1266         __attribute__((unused)) void *data)
1267 {
1268         struct cmd_add_port_tm_node_wred_profile_result *res = parsed_result;
1269         struct rte_tm_wred_params wp;
1270         enum rte_color color;
1271         struct rte_tm_error error;
1272         uint32_t wred_profile_id = res->wred_profile_id;
1273         portid_t port_id = res->port_id;
1274         int ret;
1275
1276         if (port_id_is_invalid(port_id, ENABLED_WARN))
1277                 return;
1278
1279         memset(&wp, 0, sizeof(struct rte_tm_wred_params));
1280         memset(&error, 0, sizeof(struct rte_tm_error));
1281
1282         /* WRED Params  (Green Color)*/
1283         color = RTE_COLOR_GREEN;
1284         wp.red_params[color].min_th = res->min_th_g;
1285         wp.red_params[color].max_th = res->max_th_g;
1286         wp.red_params[color].maxp_inv = res->maxp_inv_g;
1287         wp.red_params[color].wq_log2 = res->wq_log2_g;
1288
1289
1290         /* WRED Params  (Yellow Color)*/
1291         color = RTE_COLOR_YELLOW;
1292         wp.red_params[color].min_th = res->min_th_y;
1293         wp.red_params[color].max_th = res->max_th_y;
1294         wp.red_params[color].maxp_inv = res->maxp_inv_y;
1295         wp.red_params[color].wq_log2 = res->wq_log2_y;
1296
1297         /* WRED Params  (Red Color)*/
1298         color = RTE_COLOR_RED;
1299         wp.red_params[color].min_th = res->min_th_r;
1300         wp.red_params[color].max_th = res->max_th_r;
1301         wp.red_params[color].maxp_inv = res->maxp_inv_r;
1302         wp.red_params[color].wq_log2 = res->wq_log2_r;
1303
1304         ret = rte_tm_wred_profile_add(port_id, wred_profile_id, &wp, &error);
1305         if (ret != 0) {
1306                 print_err_msg(&error);
1307                 return;
1308         }
1309 }
1310
1311 cmdline_parse_inst_t cmd_add_port_tm_node_wred_profile = {
1312         .f = cmd_add_port_tm_node_wred_profile_parsed,
1313         .data = NULL,
1314         .help_str = "Add port tm node wred profile",
1315         .tokens = {
1316                 (void *)&cmd_add_port_tm_node_wred_profile_add,
1317                 (void *)&cmd_add_port_tm_node_wred_profile_port,
1318                 (void *)&cmd_add_port_tm_node_wred_profile_tm,
1319                 (void *)&cmd_add_port_tm_node_wred_profile_node,
1320                 (void *)&cmd_add_port_tm_node_wred_profile_wred,
1321                 (void *)&cmd_add_port_tm_node_wred_profile_profile,
1322                 (void *)&cmd_add_port_tm_node_wred_profile_port_id,
1323                 (void *)&cmd_add_port_tm_node_wred_profile_wred_profile_id,
1324                 (void *)&cmd_add_port_tm_node_wred_profile_color_g,
1325                 (void *)&cmd_add_port_tm_node_wred_profile_min_th_g,
1326                 (void *)&cmd_add_port_tm_node_wred_profile_max_th_g,
1327                 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_g,
1328                 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_g,
1329                 (void *)&cmd_add_port_tm_node_wred_profile_color_y,
1330                 (void *)&cmd_add_port_tm_node_wred_profile_min_th_y,
1331                 (void *)&cmd_add_port_tm_node_wred_profile_max_th_y,
1332                 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_y,
1333                 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_y,
1334                 (void *)&cmd_add_port_tm_node_wred_profile_color_r,
1335                 (void *)&cmd_add_port_tm_node_wred_profile_min_th_r,
1336                 (void *)&cmd_add_port_tm_node_wred_profile_max_th_r,
1337                 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_r,
1338                 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_r,
1339                 NULL,
1340         },
1341 };
1342
1343 /* *** Delete Port TM node WRED Profile *** */
1344 struct cmd_del_port_tm_node_wred_profile_result {
1345         cmdline_fixed_string_t del;
1346         cmdline_fixed_string_t port;
1347         cmdline_fixed_string_t tm;
1348         cmdline_fixed_string_t node;
1349         cmdline_fixed_string_t wred;
1350         cmdline_fixed_string_t profile;
1351         uint16_t port_id;
1352         uint32_t wred_profile_id;
1353 };
1354
1355 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_del =
1356         TOKEN_STRING_INITIALIZER(
1357                 struct cmd_del_port_tm_node_wred_profile_result, del, "del");
1358 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_port =
1359         TOKEN_STRING_INITIALIZER(
1360                 struct cmd_del_port_tm_node_wred_profile_result, port, "port");
1361 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_tm =
1362         TOKEN_STRING_INITIALIZER(
1363                 struct cmd_del_port_tm_node_wred_profile_result, tm, "tm");
1364 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_node =
1365         TOKEN_STRING_INITIALIZER(
1366                 struct cmd_del_port_tm_node_wred_profile_result, node, "node");
1367 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_wred =
1368         TOKEN_STRING_INITIALIZER(
1369                 struct cmd_del_port_tm_node_wred_profile_result, wred, "wred");
1370 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_profile =
1371         TOKEN_STRING_INITIALIZER(
1372                 struct cmd_del_port_tm_node_wred_profile_result,
1373                         profile, "profile");
1374 cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_port_id =
1375         TOKEN_NUM_INITIALIZER(
1376                 struct cmd_del_port_tm_node_wred_profile_result,
1377                         port_id, UINT16);
1378 cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_wred_profile_id =
1379         TOKEN_NUM_INITIALIZER(
1380                 struct cmd_del_port_tm_node_wred_profile_result,
1381                         wred_profile_id, UINT32);
1382
1383 static void cmd_del_port_tm_node_wred_profile_parsed(void *parsed_result,
1384         __attribute__((unused)) struct cmdline *cl,
1385         __attribute__((unused)) void *data)
1386 {
1387         struct cmd_del_port_tm_node_wred_profile_result *res = parsed_result;
1388         struct rte_tm_error error;
1389         uint32_t wred_profile_id = res->wred_profile_id;
1390         portid_t port_id = res->port_id;
1391         int ret;
1392
1393         if (port_id_is_invalid(port_id, ENABLED_WARN))
1394                 return;
1395
1396         memset(&error, 0, sizeof(struct rte_tm_error));
1397         ret = rte_tm_wred_profile_delete(port_id, wred_profile_id, &error);
1398         if (ret != 0) {
1399                 print_err_msg(&error);
1400                 return;
1401         }
1402 }
1403
1404 cmdline_parse_inst_t cmd_del_port_tm_node_wred_profile = {
1405         .f = cmd_del_port_tm_node_wred_profile_parsed,
1406         .data = NULL,
1407         .help_str = "Delete port tm node wred profile",
1408         .tokens = {
1409                 (void *)&cmd_del_port_tm_node_wred_profile_del,
1410                 (void *)&cmd_del_port_tm_node_wred_profile_port,
1411                 (void *)&cmd_del_port_tm_node_wred_profile_tm,
1412                 (void *)&cmd_del_port_tm_node_wred_profile_node,
1413                 (void *)&cmd_del_port_tm_node_wred_profile_wred,
1414                 (void *)&cmd_del_port_tm_node_wred_profile_profile,
1415                 (void *)&cmd_del_port_tm_node_wred_profile_port_id,
1416                 (void *)&cmd_del_port_tm_node_wred_profile_wred_profile_id,
1417                 NULL,
1418         },
1419 };
1420
1421 /* *** Update Port TM Node Shaper profile *** */
1422 struct cmd_set_port_tm_node_shaper_profile_result {
1423         cmdline_fixed_string_t set;
1424         cmdline_fixed_string_t port;
1425         cmdline_fixed_string_t tm;
1426         cmdline_fixed_string_t node;
1427         cmdline_fixed_string_t shaper;
1428         cmdline_fixed_string_t profile;
1429         uint16_t port_id;
1430         uint32_t node_id;
1431         uint32_t shaper_profile_id;
1432 };
1433
1434 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_set =
1435         TOKEN_STRING_INITIALIZER(
1436                 struct cmd_set_port_tm_node_shaper_profile_result, set, "set");
1437 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_port =
1438         TOKEN_STRING_INITIALIZER(
1439                 struct cmd_set_port_tm_node_shaper_profile_result,
1440                         port, "port");
1441 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_tm =
1442         TOKEN_STRING_INITIALIZER(
1443                 struct cmd_set_port_tm_node_shaper_profile_result, tm, "tm");
1444 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_node =
1445         TOKEN_STRING_INITIALIZER(
1446                 struct cmd_set_port_tm_node_shaper_profile_result,
1447                         node, "node");
1448 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_shaper =
1449         TOKEN_STRING_INITIALIZER(
1450                 struct cmd_set_port_tm_node_shaper_profile_result,
1451                         shaper, "shaper");
1452 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_profile =
1453         TOKEN_STRING_INITIALIZER(
1454                 struct cmd_set_port_tm_node_shaper_profile_result,
1455                         profile, "profile");
1456 cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_port_id =
1457         TOKEN_NUM_INITIALIZER(
1458                 struct cmd_set_port_tm_node_shaper_profile_result,
1459                         port_id, UINT16);
1460 cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_node_id =
1461         TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_shaper_profile_result,
1462                 node_id, UINT32);
1463 cmdline_parse_token_num_t
1464         cmd_set_port_tm_node_shaper_shaper_profile_profile_id =
1465                 TOKEN_NUM_INITIALIZER(
1466                         struct cmd_set_port_tm_node_shaper_profile_result,
1467                         shaper_profile_id, UINT32);
1468
1469 static void cmd_set_port_tm_node_shaper_profile_parsed(void *parsed_result,
1470         __attribute__((unused)) struct cmdline *cl,
1471         __attribute__((unused)) void *data)
1472 {
1473         struct cmd_set_port_tm_node_shaper_profile_result *res = parsed_result;
1474         struct rte_tm_error error;
1475         uint32_t node_id = res->node_id;
1476         uint32_t shaper_profile_id = res->shaper_profile_id;
1477         portid_t port_id = res->port_id;
1478         int ret;
1479
1480         if (port_id_is_invalid(port_id, ENABLED_WARN))
1481                 return;
1482
1483         memset(&error, 0, sizeof(struct rte_tm_error));
1484         /* Port status */
1485         if (!port_is_started(port_id)) {
1486                 printf(" Port %u not started (error)\n", port_id);
1487                 return;
1488         }
1489
1490         ret = rte_tm_node_shaper_update(port_id, node_id,
1491                 shaper_profile_id, &error);
1492         if (ret != 0) {
1493                 print_err_msg(&error);
1494                 return;
1495         }
1496 }
1497
1498 cmdline_parse_inst_t cmd_set_port_tm_node_shaper_profile = {
1499         .f = cmd_set_port_tm_node_shaper_profile_parsed,
1500         .data = NULL,
1501         .help_str = "Set port tm node shaper profile",
1502         .tokens = {
1503                 (void *)&cmd_set_port_tm_node_shaper_profile_set,
1504                 (void *)&cmd_set_port_tm_node_shaper_profile_port,
1505                 (void *)&cmd_set_port_tm_node_shaper_profile_tm,
1506                 (void *)&cmd_set_port_tm_node_shaper_profile_node,
1507                 (void *)&cmd_set_port_tm_node_shaper_profile_shaper,
1508                 (void *)&cmd_set_port_tm_node_shaper_profile_profile,
1509                 (void *)&cmd_set_port_tm_node_shaper_profile_port_id,
1510                 (void *)&cmd_set_port_tm_node_shaper_profile_node_id,
1511                 (void *)&cmd_set_port_tm_node_shaper_shaper_profile_profile_id,
1512                 NULL,
1513         },
1514 };
1515
1516 /* *** Add Port TM nonleaf node *** */
1517 struct cmd_add_port_tm_nonleaf_node_result {
1518         cmdline_fixed_string_t add;
1519         cmdline_fixed_string_t port;
1520         cmdline_fixed_string_t tm;
1521         cmdline_fixed_string_t nonleaf;
1522         cmdline_fixed_string_t node;
1523         uint16_t port_id;
1524         uint32_t node_id;
1525         int32_t parent_node_id;
1526         uint32_t priority;
1527         uint32_t weight;
1528         uint32_t level_id;
1529         int32_t shaper_profile_id;
1530         uint32_t n_sp_priorities;
1531         uint64_t stats_mask;
1532         cmdline_multi_string_t multi_shared_shaper_id;
1533 };
1534
1535 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_add =
1536         TOKEN_STRING_INITIALIZER(
1537                 struct cmd_add_port_tm_nonleaf_node_result, add, "add");
1538 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_port =
1539         TOKEN_STRING_INITIALIZER(
1540                 struct cmd_add_port_tm_nonleaf_node_result, port, "port");
1541 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_tm =
1542         TOKEN_STRING_INITIALIZER(
1543                 struct cmd_add_port_tm_nonleaf_node_result, tm, "tm");
1544 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_nonleaf =
1545         TOKEN_STRING_INITIALIZER(
1546                 struct cmd_add_port_tm_nonleaf_node_result, nonleaf, "nonleaf");
1547 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_node =
1548         TOKEN_STRING_INITIALIZER(
1549                 struct cmd_add_port_tm_nonleaf_node_result, node, "node");
1550 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_port_id =
1551         TOKEN_NUM_INITIALIZER(
1552                 struct cmd_add_port_tm_nonleaf_node_result,
1553                  port_id, UINT16);
1554 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_node_id =
1555         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1556                  node_id, UINT32);
1557 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_parent_node_id =
1558         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1559                  parent_node_id, INT32);
1560 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_priority =
1561         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1562                  priority, UINT32);
1563 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_weight =
1564         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1565                  weight, UINT32);
1566 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_level_id =
1567         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1568                  level_id, UINT32);
1569 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_shaper_profile_id =
1570         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1571                  shaper_profile_id, INT32);
1572 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_n_sp_priorities =
1573         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1574                  n_sp_priorities, UINT32);
1575 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_stats_mask =
1576         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1577                  stats_mask, UINT64);
1578 cmdline_parse_token_string_t
1579         cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id =
1580         TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1581                  multi_shared_shaper_id, TOKEN_STRING_MULTI);
1582
1583 static void cmd_add_port_tm_nonleaf_node_parsed(void *parsed_result,
1584         __attribute__((unused)) struct cmdline *cl,
1585         __attribute__((unused)) void *data)
1586 {
1587         struct cmd_add_port_tm_nonleaf_node_result *res = parsed_result;
1588         struct rte_tm_error error;
1589         struct rte_tm_node_params np;
1590         uint32_t *shared_shaper_id;
1591         uint32_t parent_node_id, n_shared_shapers = 0;
1592         char *s_str = res->multi_shared_shaper_id;
1593         portid_t port_id = res->port_id;
1594         int ret;
1595
1596         if (port_id_is_invalid(port_id, ENABLED_WARN))
1597                 return;
1598
1599         memset(&np, 0, sizeof(struct rte_tm_node_params));
1600         memset(&error, 0, sizeof(struct rte_tm_error));
1601
1602         /* Node parameters */
1603         if (res->parent_node_id < 0)
1604                 parent_node_id = UINT32_MAX;
1605         else
1606                 parent_node_id = res->parent_node_id;
1607
1608         shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS *
1609                 sizeof(uint32_t));
1610         if (shared_shaper_id == NULL) {
1611                 printf(" Memory not allocated for shared shapers (error)\n");
1612                 return;
1613         }
1614
1615         /* Parse multi shared shaper id string */
1616         ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id);
1617         if (ret) {
1618                 printf(" Shared shapers params string parse error\n");
1619                 free(shared_shaper_id);
1620                 return;
1621         }
1622
1623         if (res->shaper_profile_id < 0)
1624                 np.shaper_profile_id = UINT32_MAX;
1625         else
1626                 np.shaper_profile_id = res->shaper_profile_id;
1627
1628         np.n_shared_shapers = n_shared_shapers;
1629         if (np.n_shared_shapers) {
1630                 np.shared_shaper_id = &shared_shaper_id[0];
1631         } else {
1632                 free(shared_shaper_id);
1633                 shared_shaper_id = NULL;
1634         }
1635
1636         np.nonleaf.n_sp_priorities = res->n_sp_priorities;
1637         np.stats_mask = res->stats_mask;
1638         np.nonleaf.wfq_weight_mode = NULL;
1639
1640         ret = rte_tm_node_add(port_id, res->node_id, parent_node_id,
1641                                 res->priority, res->weight, res->level_id,
1642                                 &np, &error);
1643         if (ret != 0) {
1644                 print_err_msg(&error);
1645                 free(shared_shaper_id);
1646                 return;
1647         }
1648 }
1649
1650 cmdline_parse_inst_t cmd_add_port_tm_nonleaf_node = {
1651         .f = cmd_add_port_tm_nonleaf_node_parsed,
1652         .data = NULL,
1653         .help_str = "Add port tm nonleaf node",
1654         .tokens = {
1655                 (void *)&cmd_add_port_tm_nonleaf_node_add,
1656                 (void *)&cmd_add_port_tm_nonleaf_node_port,
1657                 (void *)&cmd_add_port_tm_nonleaf_node_tm,
1658                 (void *)&cmd_add_port_tm_nonleaf_node_nonleaf,
1659                 (void *)&cmd_add_port_tm_nonleaf_node_node,
1660                 (void *)&cmd_add_port_tm_nonleaf_node_port_id,
1661                 (void *)&cmd_add_port_tm_nonleaf_node_node_id,
1662                 (void *)&cmd_add_port_tm_nonleaf_node_parent_node_id,
1663                 (void *)&cmd_add_port_tm_nonleaf_node_priority,
1664                 (void *)&cmd_add_port_tm_nonleaf_node_weight,
1665                 (void *)&cmd_add_port_tm_nonleaf_node_level_id,
1666                 (void *)&cmd_add_port_tm_nonleaf_node_shaper_profile_id,
1667                 (void *)&cmd_add_port_tm_nonleaf_node_n_sp_priorities,
1668                 (void *)&cmd_add_port_tm_nonleaf_node_stats_mask,
1669                 (void *)&cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id,
1670                 NULL,
1671         },
1672 };
1673
1674 /* *** Add Port TM leaf node *** */
1675 struct cmd_add_port_tm_leaf_node_result {
1676         cmdline_fixed_string_t add;
1677         cmdline_fixed_string_t port;
1678         cmdline_fixed_string_t tm;
1679         cmdline_fixed_string_t leaf;
1680         cmdline_fixed_string_t node;
1681         uint16_t port_id;
1682         uint32_t node_id;
1683         int32_t parent_node_id;
1684         uint32_t priority;
1685         uint32_t weight;
1686         uint32_t level_id;
1687         int32_t shaper_profile_id;
1688         uint32_t cman_mode;
1689         uint32_t wred_profile_id;
1690         uint64_t stats_mask;
1691         cmdline_multi_string_t multi_shared_shaper_id;
1692 };
1693
1694 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_add =
1695         TOKEN_STRING_INITIALIZER(
1696                 struct cmd_add_port_tm_leaf_node_result, add, "add");
1697 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_port =
1698         TOKEN_STRING_INITIALIZER(
1699                 struct cmd_add_port_tm_leaf_node_result, port, "port");
1700 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_tm =
1701         TOKEN_STRING_INITIALIZER(
1702                 struct cmd_add_port_tm_leaf_node_result, tm, "tm");
1703 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_nonleaf =
1704         TOKEN_STRING_INITIALIZER(
1705                 struct cmd_add_port_tm_leaf_node_result, leaf, "leaf");
1706 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_node =
1707         TOKEN_STRING_INITIALIZER(
1708                 struct cmd_add_port_tm_leaf_node_result, node, "node");
1709 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_port_id =
1710         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1711                  port_id, UINT16);
1712 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_node_id =
1713         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1714                  node_id, UINT32);
1715 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_parent_node_id =
1716         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1717                  parent_node_id, INT32);
1718 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_priority =
1719         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1720                  priority, UINT32);
1721 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_weight =
1722         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1723                  weight, UINT32);
1724 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_level_id =
1725         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1726                  level_id, UINT32);
1727 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_shaper_profile_id =
1728         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1729                  shaper_profile_id, INT32);
1730 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_cman_mode =
1731         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1732                  cman_mode, UINT32);
1733 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_wred_profile_id =
1734         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1735                  wred_profile_id, UINT32);
1736 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_stats_mask =
1737         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1738                  stats_mask, UINT64);
1739 cmdline_parse_token_string_t
1740         cmd_add_port_tm_leaf_node_multi_shared_shaper_id =
1741         TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1742                  multi_shared_shaper_id, TOKEN_STRING_MULTI);
1743
1744 static void cmd_add_port_tm_leaf_node_parsed(void *parsed_result,
1745         __attribute__((unused)) struct cmdline *cl,
1746         __attribute__((unused)) void *data)
1747 {
1748         struct cmd_add_port_tm_leaf_node_result *res = parsed_result;
1749         struct rte_tm_error error;
1750         struct rte_tm_node_params np;
1751         uint32_t *shared_shaper_id;
1752         uint32_t parent_node_id, n_shared_shapers = 0;
1753         portid_t port_id = res->port_id;
1754         char *s_str = res->multi_shared_shaper_id;
1755         int ret;
1756
1757         if (port_id_is_invalid(port_id, ENABLED_WARN))
1758                 return;
1759
1760         memset(&np, 0, sizeof(struct rte_tm_node_params));
1761         memset(&error, 0, sizeof(struct rte_tm_error));
1762
1763         /* Node parameters */
1764         if (res->parent_node_id < 0)
1765                 parent_node_id = UINT32_MAX;
1766         else
1767                 parent_node_id = res->parent_node_id;
1768
1769         shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS *
1770                 sizeof(uint32_t));
1771         if (shared_shaper_id == NULL) {
1772                 printf(" Memory not allocated for shared shapers (error)\n");
1773                 return;
1774         }
1775
1776         /* Parse multi shared shaper id string */
1777         ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id);
1778         if (ret) {
1779                 printf(" Shared shapers params string parse error\n");
1780                 free(shared_shaper_id);
1781                 return;
1782         }
1783
1784         if (res->shaper_profile_id < 0)
1785                 np.shaper_profile_id = UINT32_MAX;
1786         else
1787                 np.shaper_profile_id = res->shaper_profile_id;
1788
1789         np.n_shared_shapers = n_shared_shapers;
1790
1791         if (np.n_shared_shapers) {
1792                 np.shared_shaper_id = &shared_shaper_id[0];
1793         } else {
1794                 free(shared_shaper_id);
1795                 shared_shaper_id = NULL;
1796         }
1797
1798         np.leaf.cman = res->cman_mode;
1799         np.leaf.wred.wred_profile_id = res->wred_profile_id;
1800         np.stats_mask = res->stats_mask;
1801
1802         ret = rte_tm_node_add(port_id, res->node_id, parent_node_id,
1803                                 res->priority, res->weight, res->level_id,
1804                                 &np, &error);
1805         if (ret != 0) {
1806                 print_err_msg(&error);
1807                 free(shared_shaper_id);
1808                 return;
1809         }
1810 }
1811
1812 cmdline_parse_inst_t cmd_add_port_tm_leaf_node = {
1813         .f = cmd_add_port_tm_leaf_node_parsed,
1814         .data = NULL,
1815         .help_str = "Add port tm leaf node",
1816         .tokens = {
1817                 (void *)&cmd_add_port_tm_leaf_node_add,
1818                 (void *)&cmd_add_port_tm_leaf_node_port,
1819                 (void *)&cmd_add_port_tm_leaf_node_tm,
1820                 (void *)&cmd_add_port_tm_leaf_node_nonleaf,
1821                 (void *)&cmd_add_port_tm_leaf_node_node,
1822                 (void *)&cmd_add_port_tm_leaf_node_port_id,
1823                 (void *)&cmd_add_port_tm_leaf_node_node_id,
1824                 (void *)&cmd_add_port_tm_leaf_node_parent_node_id,
1825                 (void *)&cmd_add_port_tm_leaf_node_priority,
1826                 (void *)&cmd_add_port_tm_leaf_node_weight,
1827                 (void *)&cmd_add_port_tm_leaf_node_level_id,
1828                 (void *)&cmd_add_port_tm_leaf_node_shaper_profile_id,
1829                 (void *)&cmd_add_port_tm_leaf_node_cman_mode,
1830                 (void *)&cmd_add_port_tm_leaf_node_wred_profile_id,
1831                 (void *)&cmd_add_port_tm_leaf_node_stats_mask,
1832                 (void *)&cmd_add_port_tm_leaf_node_multi_shared_shaper_id,
1833                 NULL,
1834         },
1835 };
1836
1837 /* *** Delete Port TM Node *** */
1838 struct cmd_del_port_tm_node_result {
1839         cmdline_fixed_string_t del;
1840         cmdline_fixed_string_t port;
1841         cmdline_fixed_string_t tm;
1842         cmdline_fixed_string_t node;
1843         uint16_t port_id;
1844         uint32_t node_id;
1845 };
1846
1847 cmdline_parse_token_string_t cmd_del_port_tm_node_del =
1848         TOKEN_STRING_INITIALIZER(
1849                 struct cmd_del_port_tm_node_result, del, "del");
1850 cmdline_parse_token_string_t cmd_del_port_tm_node_port =
1851         TOKEN_STRING_INITIALIZER(
1852                 struct cmd_del_port_tm_node_result, port, "port");
1853 cmdline_parse_token_string_t cmd_del_port_tm_node_tm =
1854         TOKEN_STRING_INITIALIZER(
1855                 struct cmd_del_port_tm_node_result, tm, "tm");
1856 cmdline_parse_token_string_t cmd_del_port_tm_node_node =
1857         TOKEN_STRING_INITIALIZER(
1858                 struct cmd_del_port_tm_node_result, node, "node");
1859 cmdline_parse_token_num_t cmd_del_port_tm_node_port_id =
1860         TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result,
1861                  port_id, UINT16);
1862 cmdline_parse_token_num_t cmd_del_port_tm_node_node_id =
1863         TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result,
1864                 node_id, UINT32);
1865
1866 static void cmd_del_port_tm_node_parsed(void *parsed_result,
1867         __attribute__((unused)) struct cmdline *cl,
1868         __attribute__((unused)) void *data)
1869 {
1870         struct cmd_del_port_tm_node_result *res = parsed_result;
1871         struct rte_tm_error error;
1872         uint32_t node_id = res->node_id;
1873         portid_t port_id = res->port_id;
1874         int ret;
1875
1876         if (port_id_is_invalid(port_id, ENABLED_WARN))
1877                 return;
1878
1879         memset(&error, 0, sizeof(struct rte_tm_error));
1880         /* Port status */
1881         if (port_is_started(port_id)) {
1882                 printf(" Port %u not stopped (error)\n", port_id);
1883                 return;
1884         }
1885
1886         ret = rte_tm_node_delete(port_id, node_id, &error);
1887         if (ret != 0) {
1888                 print_err_msg(&error);
1889                 return;
1890         }
1891 }
1892
1893 cmdline_parse_inst_t cmd_del_port_tm_node = {
1894         .f = cmd_del_port_tm_node_parsed,
1895         .data = NULL,
1896         .help_str = "Delete port tm node",
1897         .tokens = {
1898                 (void *)&cmd_del_port_tm_node_del,
1899                 (void *)&cmd_del_port_tm_node_port,
1900                 (void *)&cmd_del_port_tm_node_tm,
1901                 (void *)&cmd_del_port_tm_node_node,
1902                 (void *)&cmd_del_port_tm_node_port_id,
1903                 (void *)&cmd_del_port_tm_node_node_id,
1904                 NULL,
1905         },
1906 };
1907
1908 /* *** Update Port TM Node Parent *** */
1909 struct cmd_set_port_tm_node_parent_result {
1910         cmdline_fixed_string_t set;
1911         cmdline_fixed_string_t port;
1912         cmdline_fixed_string_t tm;
1913         cmdline_fixed_string_t node;
1914         cmdline_fixed_string_t parent;
1915         uint16_t port_id;
1916         uint32_t node_id;
1917         uint32_t parent_id;
1918         uint32_t priority;
1919         uint32_t weight;
1920 };
1921
1922 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_set =
1923         TOKEN_STRING_INITIALIZER(
1924                 struct cmd_set_port_tm_node_parent_result, set, "set");
1925 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_port =
1926         TOKEN_STRING_INITIALIZER(
1927                 struct cmd_set_port_tm_node_parent_result, port, "port");
1928 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_tm =
1929         TOKEN_STRING_INITIALIZER(
1930                 struct cmd_set_port_tm_node_parent_result, tm, "tm");
1931 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_node =
1932         TOKEN_STRING_INITIALIZER(
1933                 struct cmd_set_port_tm_node_parent_result, node, "node");
1934 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_parent =
1935         TOKEN_STRING_INITIALIZER(
1936                 struct cmd_set_port_tm_node_parent_result, parent, "parent");
1937 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_port_id =
1938         TOKEN_NUM_INITIALIZER(
1939                 struct cmd_set_port_tm_node_parent_result, port_id, UINT16);
1940 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_node_id =
1941         TOKEN_NUM_INITIALIZER(
1942                 struct cmd_set_port_tm_node_parent_result, node_id, UINT32);
1943 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_parent_id =
1944         TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
1945                 parent_id, UINT32);
1946 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_priority =
1947         TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
1948                 priority, UINT32);
1949 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_weight =
1950         TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
1951                 weight, UINT32);
1952
1953 static void cmd_set_port_tm_node_parent_parsed(void *parsed_result,
1954         __attribute__((unused)) struct cmdline *cl,
1955         __attribute__((unused)) void *data)
1956 {
1957         struct cmd_set_port_tm_node_parent_result *res = parsed_result;
1958         struct rte_tm_error error;
1959         uint32_t node_id = res->node_id;
1960         uint32_t parent_id = res->parent_id;
1961         uint32_t priority = res->priority;
1962         uint32_t weight = res->weight;
1963         portid_t port_id = res->port_id;
1964         int ret;
1965
1966         if (port_id_is_invalid(port_id, ENABLED_WARN))
1967                 return;
1968
1969         memset(&error, 0, sizeof(struct rte_tm_error));
1970         /* Port status */
1971         if (!port_is_started(port_id)) {
1972                 printf(" Port %u not started (error)\n", port_id);
1973                 return;
1974         }
1975
1976         ret = rte_tm_node_parent_update(port_id, node_id,
1977                 parent_id, priority, weight, &error);
1978         if (ret != 0) {
1979                 print_err_msg(&error);
1980                 return;
1981         }
1982 }
1983
1984 cmdline_parse_inst_t cmd_set_port_tm_node_parent = {
1985         .f = cmd_set_port_tm_node_parent_parsed,
1986         .data = NULL,
1987         .help_str = "Set port tm node parent",
1988         .tokens = {
1989                 (void *)&cmd_set_port_tm_node_parent_set,
1990                 (void *)&cmd_set_port_tm_node_parent_port,
1991                 (void *)&cmd_set_port_tm_node_parent_tm,
1992                 (void *)&cmd_set_port_tm_node_parent_node,
1993                 (void *)&cmd_set_port_tm_node_parent_parent,
1994                 (void *)&cmd_set_port_tm_node_parent_port_id,
1995                 (void *)&cmd_set_port_tm_node_parent_node_id,
1996                 (void *)&cmd_set_port_tm_node_parent_parent_id,
1997                 (void *)&cmd_set_port_tm_node_parent_priority,
1998                 (void *)&cmd_set_port_tm_node_parent_weight,
1999                 NULL,
2000         },
2001 };
2002
2003 /* *** Suspend Port TM Node *** */
2004 struct cmd_suspend_port_tm_node_result {
2005         cmdline_fixed_string_t suspend;
2006         cmdline_fixed_string_t port;
2007         cmdline_fixed_string_t tm;
2008         cmdline_fixed_string_t node;
2009         uint16_t port_id;
2010         uint32_t node_id;
2011 };
2012
2013 cmdline_parse_token_string_t cmd_suspend_port_tm_node_suspend =
2014         TOKEN_STRING_INITIALIZER(
2015                 struct cmd_suspend_port_tm_node_result, suspend, "suspend");
2016 cmdline_parse_token_string_t cmd_suspend_port_tm_node_port =
2017         TOKEN_STRING_INITIALIZER(
2018                 struct cmd_suspend_port_tm_node_result, port, "port");
2019 cmdline_parse_token_string_t cmd_suspend_port_tm_node_tm =
2020         TOKEN_STRING_INITIALIZER(
2021                 struct cmd_suspend_port_tm_node_result, tm, "tm");
2022 cmdline_parse_token_string_t cmd_suspend_port_tm_node_node =
2023         TOKEN_STRING_INITIALIZER(
2024                 struct cmd_suspend_port_tm_node_result, node, "node");
2025 cmdline_parse_token_num_t cmd_suspend_port_tm_node_port_id =
2026         TOKEN_NUM_INITIALIZER(
2027                 struct cmd_suspend_port_tm_node_result, port_id, UINT16);
2028 cmdline_parse_token_num_t cmd_suspend_port_tm_node_node_id =
2029         TOKEN_NUM_INITIALIZER(
2030                 struct cmd_suspend_port_tm_node_result, node_id, UINT32);
2031
2032 static void cmd_suspend_port_tm_node_parsed(void *parsed_result,
2033         __attribute__((unused)) struct cmdline *cl,
2034         __attribute__((unused)) void *data)
2035 {
2036         struct cmd_suspend_port_tm_node_result *res = parsed_result;
2037         struct rte_tm_error error;
2038         uint32_t node_id = res->node_id;
2039         portid_t port_id = res->port_id;
2040         int ret;
2041
2042         if (port_id_is_invalid(port_id, ENABLED_WARN))
2043                 return;
2044
2045         memset(&error, 0, sizeof(struct rte_tm_error));
2046         ret = rte_tm_node_suspend(port_id, node_id, &error);
2047         if (ret != 0) {
2048                 print_err_msg(&error);
2049                 return;
2050         }
2051 }
2052
2053 cmdline_parse_inst_t cmd_suspend_port_tm_node = {
2054         .f = cmd_suspend_port_tm_node_parsed,
2055         .data = NULL,
2056         .help_str = "Suspend port tm node",
2057         .tokens = {
2058                 (void *)&cmd_suspend_port_tm_node_suspend,
2059                 (void *)&cmd_suspend_port_tm_node_port,
2060                 (void *)&cmd_suspend_port_tm_node_tm,
2061                 (void *)&cmd_suspend_port_tm_node_node,
2062                 (void *)&cmd_suspend_port_tm_node_port_id,
2063                 (void *)&cmd_suspend_port_tm_node_node_id,
2064                 NULL,
2065         },
2066 };
2067
2068 /* *** Resume Port TM Node *** */
2069 struct cmd_resume_port_tm_node_result {
2070         cmdline_fixed_string_t resume;
2071         cmdline_fixed_string_t port;
2072         cmdline_fixed_string_t tm;
2073         cmdline_fixed_string_t node;
2074         uint16_t port_id;
2075         uint32_t node_id;
2076 };
2077
2078 cmdline_parse_token_string_t cmd_resume_port_tm_node_resume =
2079         TOKEN_STRING_INITIALIZER(
2080                 struct cmd_resume_port_tm_node_result, resume, "resume");
2081 cmdline_parse_token_string_t cmd_resume_port_tm_node_port =
2082         TOKEN_STRING_INITIALIZER(
2083                 struct cmd_resume_port_tm_node_result, port, "port");
2084 cmdline_parse_token_string_t cmd_resume_port_tm_node_tm =
2085         TOKEN_STRING_INITIALIZER(
2086                 struct cmd_resume_port_tm_node_result, tm, "tm");
2087 cmdline_parse_token_string_t cmd_resume_port_tm_node_node =
2088         TOKEN_STRING_INITIALIZER(
2089                 struct cmd_resume_port_tm_node_result, node, "node");
2090 cmdline_parse_token_num_t cmd_resume_port_tm_node_port_id =
2091         TOKEN_NUM_INITIALIZER(
2092                 struct cmd_resume_port_tm_node_result, port_id, UINT16);
2093 cmdline_parse_token_num_t cmd_resume_port_tm_node_node_id =
2094         TOKEN_NUM_INITIALIZER(
2095                 struct cmd_resume_port_tm_node_result, node_id, UINT32);
2096
2097 static void cmd_resume_port_tm_node_parsed(void *parsed_result,
2098         __attribute__((unused)) struct cmdline *cl,
2099         __attribute__((unused)) void *data)
2100 {
2101         struct cmd_resume_port_tm_node_result *res = parsed_result;
2102         struct rte_tm_error error;
2103         uint32_t node_id = res->node_id;
2104         portid_t port_id = res->port_id;
2105         int ret;
2106
2107         if (port_id_is_invalid(port_id, ENABLED_WARN))
2108                 return;
2109
2110         memset(&error, 0, sizeof(struct rte_tm_error));
2111         ret = rte_tm_node_resume(port_id, node_id, &error);
2112         if (ret != 0) {
2113                 print_err_msg(&error);
2114                 return;
2115         }
2116 }
2117
2118 cmdline_parse_inst_t cmd_resume_port_tm_node = {
2119         .f = cmd_resume_port_tm_node_parsed,
2120         .data = NULL,
2121         .help_str = "Resume port tm node",
2122         .tokens = {
2123                 (void *)&cmd_resume_port_tm_node_resume,
2124                 (void *)&cmd_resume_port_tm_node_port,
2125                 (void *)&cmd_resume_port_tm_node_tm,
2126                 (void *)&cmd_resume_port_tm_node_node,
2127                 (void *)&cmd_resume_port_tm_node_port_id,
2128                 (void *)&cmd_resume_port_tm_node_node_id,
2129                 NULL,
2130         },
2131 };
2132
2133 /* *** Port TM Hierarchy Commit *** */
2134 struct cmd_port_tm_hierarchy_commit_result {
2135         cmdline_fixed_string_t port;
2136         cmdline_fixed_string_t tm;
2137         cmdline_fixed_string_t hierarchy;
2138         cmdline_fixed_string_t commit;
2139         uint16_t port_id;
2140         cmdline_fixed_string_t clean_on_fail;
2141 };
2142
2143 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_port =
2144         TOKEN_STRING_INITIALIZER(
2145                 struct cmd_port_tm_hierarchy_commit_result, port, "port");
2146 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_tm =
2147         TOKEN_STRING_INITIALIZER(
2148                 struct cmd_port_tm_hierarchy_commit_result, tm, "tm");
2149 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_hierarchy =
2150         TOKEN_STRING_INITIALIZER(
2151                 struct cmd_port_tm_hierarchy_commit_result,
2152                         hierarchy, "hierarchy");
2153 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_commit =
2154         TOKEN_STRING_INITIALIZER(
2155                 struct cmd_port_tm_hierarchy_commit_result, commit, "commit");
2156 cmdline_parse_token_num_t cmd_port_tm_hierarchy_commit_port_id =
2157         TOKEN_NUM_INITIALIZER(
2158                 struct cmd_port_tm_hierarchy_commit_result,
2159                         port_id, UINT16);
2160 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_clean_on_fail =
2161         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_hierarchy_commit_result,
2162                  clean_on_fail, "yes#no");
2163
2164 static void cmd_port_tm_hierarchy_commit_parsed(void *parsed_result,
2165         __attribute__((unused)) struct cmdline *cl,
2166         __attribute__((unused)) void *data)
2167 {
2168         struct cmd_port_tm_hierarchy_commit_result *res = parsed_result;
2169         struct rte_tm_error error;
2170         uint32_t clean_on_fail;
2171         portid_t port_id = res->port_id;
2172         int ret;
2173
2174         if (port_id_is_invalid(port_id, ENABLED_WARN))
2175                 return;
2176
2177         if (strcmp(res->clean_on_fail, "yes") == 0)
2178                 clean_on_fail = 1;
2179         else
2180                 clean_on_fail = 0;
2181
2182         memset(&error, 0, sizeof(struct rte_tm_error));
2183         ret = rte_tm_hierarchy_commit(port_id, clean_on_fail, &error);
2184         if (ret != 0) {
2185                 print_err_msg(&error);
2186                 return;
2187         }
2188 }
2189
2190 cmdline_parse_inst_t cmd_port_tm_hierarchy_commit = {
2191         .f = cmd_port_tm_hierarchy_commit_parsed,
2192         .data = NULL,
2193         .help_str = "Commit port tm hierarchy",
2194         .tokens = {
2195                 (void *)&cmd_port_tm_hierarchy_commit_port,
2196                 (void *)&cmd_port_tm_hierarchy_commit_tm,
2197                 (void *)&cmd_port_tm_hierarchy_commit_hierarchy,
2198                 (void *)&cmd_port_tm_hierarchy_commit_commit,
2199                 (void *)&cmd_port_tm_hierarchy_commit_port_id,
2200                 (void *)&cmd_port_tm_hierarchy_commit_clean_on_fail,
2201                 NULL,
2202         },
2203 };
2204
2205 /* *** Port TM Mark IP ECN *** */
2206 struct cmd_port_tm_mark_ip_ecn_result {
2207         cmdline_fixed_string_t set;
2208         cmdline_fixed_string_t port;
2209         cmdline_fixed_string_t tm;
2210         cmdline_fixed_string_t mark;
2211         cmdline_fixed_string_t ip_ecn;
2212         uint16_t port_id;
2213         uint16_t green;
2214         uint16_t yellow;
2215         uint16_t red;
2216 };
2217
2218 cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_set =
2219         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2220                                  set, "set");
2221
2222 cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_port =
2223         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2224                                  port, "port");
2225
2226 cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_tm =
2227         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result, tm,
2228                                  "tm");
2229
2230 cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_mark =
2231         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2232                                  mark, "mark");
2233
2234 cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_ip_ecn =
2235         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2236                                  ip_ecn, "ip_ecn");
2237 cmdline_parse_token_num_t cmd_port_tm_mark_ip_ecn_port_id =
2238         TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2239                               port_id, UINT16);
2240
2241 cmdline_parse_token_num_t cmd_port_tm_mark_ip_ecn_green =
2242         TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2243                               green, UINT16);
2244 cmdline_parse_token_num_t cmd_port_tm_mark_ip_ecn_yellow =
2245         TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2246                               yellow, UINT16);
2247 cmdline_parse_token_num_t cmd_port_tm_mark_ip_ecn_red =
2248         TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2249                                 red, UINT16);
2250
2251 static void cmd_port_tm_mark_ip_ecn_parsed(void *parsed_result,
2252         __attribute__((unused)) struct cmdline *cl,
2253         __attribute__((unused)) void *data)
2254 {
2255         struct cmd_port_tm_mark_ip_ecn_result *res = parsed_result;
2256         struct rte_tm_error error;
2257         portid_t port_id = res->port_id;
2258         int green = res->green;
2259         int yellow = res->yellow;
2260         int red = res->red;
2261         int ret;
2262         if (port_id_is_invalid(port_id, ENABLED_WARN))
2263                 return;
2264
2265         memset(&error, 0, sizeof(struct rte_tm_error));
2266         ret = rte_tm_mark_ip_ecn(port_id, green, yellow, red, &error);
2267         if (ret != 0) {
2268                 print_err_msg(&error);
2269                 return;
2270         }
2271 }
2272
2273 cmdline_parse_inst_t cmd_port_tm_mark_ip_ecn = {
2274         .f = cmd_port_tm_mark_ip_ecn_parsed,
2275         .data = NULL,
2276         .help_str = "set port tm mark ip_ecn <port> <green> <yellow> <red>",
2277         .tokens = {
2278                 (void *)&cmd_port_tm_mark_ip_ecn_set,
2279                 (void *)&cmd_port_tm_mark_ip_ecn_port,
2280                 (void *)&cmd_port_tm_mark_ip_ecn_tm,
2281                 (void *)&cmd_port_tm_mark_ip_ecn_mark,
2282                 (void *)&cmd_port_tm_mark_ip_ecn_ip_ecn,
2283                 (void *)&cmd_port_tm_mark_ip_ecn_port_id,
2284                 (void *)&cmd_port_tm_mark_ip_ecn_green,
2285                 (void *)&cmd_port_tm_mark_ip_ecn_yellow,
2286                 (void *)&cmd_port_tm_mark_ip_ecn_red,
2287                 NULL,
2288         },
2289 };
2290
2291
2292 /* *** Port TM Mark IP DSCP *** */
2293 struct cmd_port_tm_mark_ip_dscp_result {
2294         cmdline_fixed_string_t set;
2295         cmdline_fixed_string_t port;
2296         cmdline_fixed_string_t tm;
2297         cmdline_fixed_string_t mark;
2298         cmdline_fixed_string_t ip_dscp;
2299         uint16_t port_id;
2300         uint16_t green;
2301         uint16_t yellow;
2302         uint16_t red;
2303 };
2304
2305 cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_set =
2306         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2307                                  set, "set");
2308
2309 cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_port =
2310         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2311                                  port, "port");
2312
2313 cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_tm =
2314         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result, tm,
2315                                  "tm");
2316
2317 cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_mark =
2318         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2319                                  mark, "mark");
2320
2321 cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_ip_dscp =
2322         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2323                                  ip_dscp, "ip_dscp");
2324 cmdline_parse_token_num_t cmd_port_tm_mark_ip_dscp_port_id =
2325         TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2326                               port_id, UINT16);
2327
2328 cmdline_parse_token_num_t cmd_port_tm_mark_ip_dscp_green =
2329         TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2330                                 green, UINT16);
2331 cmdline_parse_token_num_t cmd_port_tm_mark_ip_dscp_yellow =
2332         TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2333                                 yellow, UINT16);
2334 cmdline_parse_token_num_t cmd_port_tm_mark_ip_dscp_red =
2335         TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2336                                 red, UINT16);
2337
2338 static void cmd_port_tm_mark_ip_dscp_parsed(void *parsed_result,
2339         __attribute__((unused)) struct cmdline *cl,
2340         __attribute__((unused)) void *data)
2341 {
2342         struct cmd_port_tm_mark_ip_dscp_result *res = parsed_result;
2343         struct rte_tm_error error;
2344         portid_t port_id = res->port_id;
2345         int green = res->green;
2346         int yellow = res->yellow;
2347         int red = res->red;
2348         int ret;
2349         if (port_id_is_invalid(port_id, ENABLED_WARN))
2350                 return;
2351
2352         memset(&error, 0, sizeof(struct rte_tm_error));
2353         ret = rte_tm_mark_ip_dscp(port_id, green, yellow, red, &error);
2354         if (ret != 0) {
2355                 print_err_msg(&error);
2356                 return;
2357         }
2358 }
2359
2360 cmdline_parse_inst_t cmd_port_tm_mark_ip_dscp = {
2361         .f = cmd_port_tm_mark_ip_dscp_parsed,
2362         .data = NULL,
2363         .help_str = "set port tm mark ip_dscp <port> <green> <yellow> <red>",
2364         .tokens = {
2365                 (void *)&cmd_port_tm_mark_ip_dscp_set,
2366                 (void *)&cmd_port_tm_mark_ip_dscp_port,
2367                 (void *)&cmd_port_tm_mark_ip_dscp_tm,
2368                 (void *)&cmd_port_tm_mark_ip_dscp_mark,
2369                 (void *)&cmd_port_tm_mark_ip_dscp_ip_dscp,
2370                 (void *)&cmd_port_tm_mark_ip_dscp_port_id,
2371                 (void *)&cmd_port_tm_mark_ip_dscp_green,
2372                 (void *)&cmd_port_tm_mark_ip_dscp_yellow,
2373                 (void *)&cmd_port_tm_mark_ip_dscp_red,
2374                 NULL,
2375         },
2376 };
2377
2378
2379 /* *** Port TM Mark VLAN_DEI *** */
2380 struct cmd_port_tm_mark_vlan_dei_result {
2381         cmdline_fixed_string_t set;
2382         cmdline_fixed_string_t port;
2383         cmdline_fixed_string_t tm;
2384         cmdline_fixed_string_t mark;
2385         cmdline_fixed_string_t vlan_dei;
2386         uint16_t port_id;
2387         uint16_t green;
2388         uint16_t yellow;
2389         uint16_t red;
2390 };
2391
2392 cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_set =
2393         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2394                                  set, "set");
2395
2396 cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_port =
2397         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2398                                  port, "port");
2399
2400 cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_tm =
2401         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result, tm,
2402                                  "tm");
2403
2404 cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_mark =
2405         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2406                                  mark, "mark");
2407
2408 cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_vlan_dei =
2409         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2410                                  vlan_dei, "vlan_dei");
2411 cmdline_parse_token_num_t cmd_port_tm_mark_vlan_dei_port_id =
2412         TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2413                               port_id, UINT16);
2414
2415 cmdline_parse_token_num_t cmd_port_tm_mark_vlan_dei_green =
2416         TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2417                                 green, UINT16);
2418 cmdline_parse_token_num_t cmd_port_tm_mark_vlan_dei_yellow =
2419         TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2420                                 yellow, UINT16);
2421 cmdline_parse_token_num_t cmd_port_tm_mark_vlan_dei_red =
2422         TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2423                                 red, UINT16);
2424
2425 static void cmd_port_tm_mark_vlan_dei_parsed(void *parsed_result,
2426         __attribute__((unused)) struct cmdline *cl,
2427         __attribute__((unused)) void *data)
2428 {
2429         struct cmd_port_tm_mark_vlan_dei_result *res = parsed_result;
2430         struct rte_tm_error error;
2431         portid_t port_id = res->port_id;
2432         int green = res->green;
2433         int yellow = res->yellow;
2434         int red = res->red;
2435         int ret;
2436         if (port_id_is_invalid(port_id, ENABLED_WARN))
2437                 return;
2438
2439         memset(&error, 0, sizeof(struct rte_tm_error));
2440         ret = rte_tm_mark_vlan_dei(port_id, green, yellow, red, &error);
2441         if (ret != 0) {
2442                 print_err_msg(&error);
2443                 return;
2444         }
2445 }
2446
2447 cmdline_parse_inst_t cmd_port_tm_mark_vlan_dei = {
2448         .f = cmd_port_tm_mark_vlan_dei_parsed,
2449         .data = NULL,
2450         .help_str = "set port tm mark vlan_dei <port> <green> <yellow> <red>",
2451         .tokens = {
2452                 (void *)&cmd_port_tm_mark_vlan_dei_set,
2453                 (void *)&cmd_port_tm_mark_vlan_dei_port,
2454                 (void *)&cmd_port_tm_mark_vlan_dei_tm,
2455                 (void *)&cmd_port_tm_mark_vlan_dei_mark,
2456                 (void *)&cmd_port_tm_mark_vlan_dei_vlan_dei,
2457                 (void *)&cmd_port_tm_mark_vlan_dei_port_id,
2458                 (void *)&cmd_port_tm_mark_vlan_dei_green,
2459                 (void *)&cmd_port_tm_mark_vlan_dei_yellow,
2460                 (void *)&cmd_port_tm_mark_vlan_dei_red,
2461                 NULL,
2462         },
2463 };