New upstream version 18.05
[deb_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         ret = rte_tm_capabilities_get(port_id, &cap, &error);
238         if (ret) {
239                 print_err_msg(&error);
240                 return;
241         }
242
243         printf("\n****   Port TM Capabilities ****\n\n");
244         printf("cap.n_nodes_max %" PRIu32 "\n", cap.n_nodes_max);
245         printf("cap.n_levels_max %" PRIu32 "\n", cap.n_levels_max);
246         printf("cap.non_leaf_nodes_identical %" PRId32 "\n",
247                 cap.non_leaf_nodes_identical);
248         printf("cap.leaf_nodes_identical %" PRId32 "\n",
249                 cap.leaf_nodes_identical);
250         printf("cap.shaper_n_max %u\n", cap.shaper_n_max);
251         printf("cap.shaper_private_n_max %" PRIu32 "\n",
252                 cap.shaper_private_n_max);
253         printf("cap.shaper_private_dual_rate_n_max %" PRId32 "\n",
254                 cap.shaper_private_dual_rate_n_max);
255         printf("cap.shaper_private_rate_min %" PRIu64 "\n",
256                 cap.shaper_private_rate_min);
257         printf("cap.shaper_private_rate_max %" PRIu64 "\n",
258                 cap.shaper_private_rate_max);
259         printf("cap.shaper_shared_n_max %" PRIu32 "\n",
260                 cap.shaper_shared_n_max);
261         printf("cap.shaper_shared_n_nodes_per_shaper_max %" PRIu32 "\n",
262                 cap.shaper_shared_n_nodes_per_shaper_max);
263         printf("cap.shaper_shared_n_shapers_per_node_max %" PRIu32 "\n",
264                 cap.shaper_shared_n_shapers_per_node_max);
265         printf("cap.shaper_shared_dual_rate_n_max %" PRIu32 "\n",
266                 cap.shaper_shared_dual_rate_n_max);
267         printf("cap.shaper_shared_rate_min %" PRIu64 "\n",
268                 cap.shaper_shared_rate_min);
269         printf("cap.shaper_shared_rate_max %" PRIu64 "\n",
270                 cap.shaper_shared_rate_max);
271         printf("cap.shaper_pkt_length_adjust_min %" PRId32 "\n",
272                 cap.shaper_pkt_length_adjust_min);
273         printf("cap.shaper_pkt_length_adjust_max %" PRId32 "\n",
274                 cap.shaper_pkt_length_adjust_max);
275         printf("cap.sched_n_children_max %" PRIu32 "\n",
276                 cap.sched_n_children_max);
277         printf("cap.sched_sp_n_priorities_max %" PRIu32 "\n",
278                 cap.sched_sp_n_priorities_max);
279         printf("cap.sched_wfq_n_children_per_group_max %" PRIu32 "\n",
280                 cap.sched_wfq_n_children_per_group_max);
281         printf("cap.sched_wfq_n_groups_max %" PRIu32 "\n",
282                 cap.sched_wfq_n_groups_max);
283         printf("cap.sched_wfq_weight_max %" PRIu32 "\n",
284                 cap.sched_wfq_weight_max);
285         printf("cap.cman_head_drop_supported %" PRId32 "\n",
286                 cap.cman_head_drop_supported);
287         printf("cap.cman_wred_context_n_max %" PRIu32 "\n",
288                 cap.cman_wred_context_n_max);
289         printf("cap.cman_wred_context_private_n_max %" PRIu32 "\n",
290                 cap.cman_wred_context_private_n_max);
291         printf("cap.cman_wred_context_shared_n_max %" PRIu32 "\n",
292                 cap.cman_wred_context_shared_n_max);
293         printf("cap.cman_wred_context_shared_n_nodes_per_context_max %" PRIu32
294                 "\n", cap.cman_wred_context_shared_n_nodes_per_context_max);
295         printf("cap.cman_wred_context_shared_n_contexts_per_node_max %" PRIu32
296                 "\n", cap.cman_wred_context_shared_n_contexts_per_node_max);
297
298         for (i = 0; i < RTE_TM_COLORS; i++) {
299                 printf("cap.mark_vlan_dei_supported %" PRId32 "\n",
300                         cap.mark_vlan_dei_supported[i]);
301                 printf("cap.mark_ip_ecn_tcp_supported %" PRId32 "\n",
302                         cap.mark_ip_ecn_tcp_supported[i]);
303                 printf("cap.mark_ip_ecn_sctp_supported %" PRId32 "\n",
304                         cap.mark_ip_ecn_sctp_supported[i]);
305                 printf("cap.mark_ip_dscp_supported %" PRId32 "\n",
306                         cap.mark_ip_dscp_supported[i]);
307         }
308
309         printf("cap.dynamic_update_mask %" PRIx64 "\n",
310                 cap.dynamic_update_mask);
311         printf("cap.stats_mask %" PRIx64 "\n", cap.stats_mask);
312 }
313
314 cmdline_parse_inst_t cmd_show_port_tm_cap = {
315         .f = cmd_show_port_tm_cap_parsed,
316         .data = NULL,
317         .help_str = "Show Port TM Capabilities",
318         .tokens = {
319                 (void *)&cmd_show_port_tm_cap_show,
320                 (void *)&cmd_show_port_tm_cap_port,
321                 (void *)&cmd_show_port_tm_cap_tm,
322                 (void *)&cmd_show_port_tm_cap_cap,
323                 (void *)&cmd_show_port_tm_cap_port_id,
324                 NULL,
325         },
326 };
327
328 /* *** Port TM Hierarchical Level Capability *** */
329 struct cmd_show_port_tm_level_cap_result {
330         cmdline_fixed_string_t show;
331         cmdline_fixed_string_t port;
332         cmdline_fixed_string_t tm;
333         cmdline_fixed_string_t level;
334         cmdline_fixed_string_t cap;
335         uint16_t port_id;
336         uint32_t level_id;
337 };
338
339 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_show =
340         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
341                 show, "show");
342 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_port =
343         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
344                 port, "port");
345 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_tm =
346         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
347                 tm, "tm");
348 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_level =
349         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
350                 level, "level");
351 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_cap =
352         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
353                 cap, "cap");
354 cmdline_parse_token_num_t cmd_show_port_tm_level_cap_port_id =
355         TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
356                  port_id, UINT16);
357 cmdline_parse_token_num_t cmd_show_port_tm_level_cap_level_id =
358         TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
359                  level_id, UINT32);
360
361
362 static void cmd_show_port_tm_level_cap_parsed(void *parsed_result,
363         __attribute__((unused)) struct cmdline *cl,
364         __attribute__((unused)) void *data)
365 {
366         struct cmd_show_port_tm_level_cap_result *res = parsed_result;
367         struct rte_tm_level_capabilities lcap;
368         struct rte_tm_error error;
369         portid_t port_id = res->port_id;
370         uint32_t level_id = res->level_id;
371         int ret;
372
373         if (port_id_is_invalid(port_id, ENABLED_WARN))
374                 return;
375
376         memset(&lcap, 0, sizeof(struct rte_tm_level_capabilities));
377         ret = rte_tm_level_capabilities_get(port_id, level_id, &lcap, &error);
378         if (ret) {
379                 print_err_msg(&error);
380                 return;
381         }
382         printf("\n**   Port TM Hierarchy level %" PRIu32 " Capability **\n\n",
383                 level_id);
384
385         printf("cap.n_nodes_max %" PRIu32 "\n", lcap.n_nodes_max);
386         printf("cap.n_nodes_nonleaf_max %" PRIu32 "\n",
387                 lcap.n_nodes_nonleaf_max);
388         printf("cap.n_nodes_leaf_max %" PRIu32 "\n", lcap.n_nodes_leaf_max);
389         printf("cap.non_leaf_nodes_identical %" PRId32 "\n",
390                 lcap.non_leaf_nodes_identical);
391         printf("cap.leaf_nodes_identical %" PRId32 "\n",
392                 lcap.leaf_nodes_identical);
393         if (level_id <= 3) {
394                 printf("cap.nonleaf.shaper_private_supported %" PRId32 "\n",
395                         lcap.nonleaf.shaper_private_supported);
396                 printf("cap.nonleaf.shaper_private_dual_rate_supported %" PRId32
397                         "\n", lcap.nonleaf.shaper_private_dual_rate_supported);
398                 printf("cap.nonleaf.shaper_private_rate_min %" PRIu64 "\n",
399                         lcap.nonleaf.shaper_private_rate_min);
400                 printf("cap.nonleaf.shaper_private_rate_max %" PRIu64 "\n",
401                         lcap.nonleaf.shaper_private_rate_max);
402                 printf("cap.nonleaf.shaper_shared_n_max %" PRIu32 "\n",
403                         lcap.nonleaf.shaper_shared_n_max);
404                 printf("cap.nonleaf.sched_n_children_max %" PRIu32 "\n",
405                         lcap.nonleaf.sched_n_children_max);
406                 printf("cap.nonleaf.sched_sp_n_priorities_max %" PRIu32 "\n",
407                         lcap.nonleaf.sched_sp_n_priorities_max);
408                 printf("cap.nonleaf.sched_wfq_n_children_per_group_max %" PRIu32
409                         "\n", lcap.nonleaf.sched_wfq_n_children_per_group_max);
410                 printf("cap.nonleaf.sched_wfq_n_groups_max %" PRIu32 "\n",
411                         lcap.nonleaf.sched_wfq_n_groups_max);
412                 printf("cap.nonleaf.sched_wfq_weight_max %" PRIu32 "\n",
413                         lcap.nonleaf.sched_wfq_weight_max);
414                 printf("cap.nonleaf.stats_mask %" PRIx64 "\n",
415                         lcap.nonleaf.stats_mask);
416         } else {
417                 printf("cap.leaf.shaper_private_supported %" PRId32 "\n",
418                         lcap.leaf.shaper_private_supported);
419                 printf("cap.leaf.shaper_private_dual_rate_supported %" PRId32
420                         "\n", lcap.leaf.shaper_private_dual_rate_supported);
421                 printf("cap.leaf.shaper_private_rate_min %" PRIu64 "\n",
422                         lcap.leaf.shaper_private_rate_min);
423                 printf("cap.leaf.shaper_private_rate_max %" PRIu64 "\n",
424                         lcap.leaf.shaper_private_rate_max);
425                 printf("cap.leaf.shaper_shared_n_max %" PRIu32 "\n",
426                         lcap.leaf.shaper_shared_n_max);
427                 printf("cap.leaf.cman_head_drop_supported %" PRId32 "\n",
428                         lcap.leaf.cman_head_drop_supported);
429                 printf("cap.leaf.cman_wred_context_private_supported %" PRId32
430                         "\n", lcap.leaf.cman_wred_context_private_supported);
431                 printf("cap.leaf.cman_wred_context_shared_n_max %" PRIu32 "\n",
432                         lcap.leaf.cman_wred_context_shared_n_max);
433                 printf("cap.leaf.stats_mask %" PRIx64 "\n",
434                         lcap.leaf.stats_mask);
435         }
436 }
437
438 cmdline_parse_inst_t cmd_show_port_tm_level_cap = {
439         .f = cmd_show_port_tm_level_cap_parsed,
440         .data = NULL,
441         .help_str = "Show Port TM Hierarhical level Capabilities",
442         .tokens = {
443                 (void *)&cmd_show_port_tm_level_cap_show,
444                 (void *)&cmd_show_port_tm_level_cap_port,
445                 (void *)&cmd_show_port_tm_level_cap_tm,
446                 (void *)&cmd_show_port_tm_level_cap_level,
447                 (void *)&cmd_show_port_tm_level_cap_cap,
448                 (void *)&cmd_show_port_tm_level_cap_port_id,
449                 (void *)&cmd_show_port_tm_level_cap_level_id,
450                 NULL,
451         },
452 };
453
454 /* *** Port TM Hierarchy Node Capability *** */
455 struct cmd_show_port_tm_node_cap_result {
456         cmdline_fixed_string_t show;
457         cmdline_fixed_string_t port;
458         cmdline_fixed_string_t tm;
459         cmdline_fixed_string_t node;
460         cmdline_fixed_string_t cap;
461         uint16_t port_id;
462         uint32_t node_id;
463 };
464
465 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_show =
466         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
467                 show, "show");
468 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_port =
469         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
470                 port, "port");
471 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_tm =
472         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
473                 tm, "tm");
474 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_node =
475         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
476                 node, "node");
477 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_cap =
478         TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
479                 cap, "cap");
480 cmdline_parse_token_num_t cmd_show_port_tm_node_cap_port_id =
481         TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
482                  port_id, UINT16);
483 cmdline_parse_token_num_t cmd_show_port_tm_node_cap_node_id =
484         TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
485                  node_id, UINT32);
486
487 static void cmd_show_port_tm_node_cap_parsed(void *parsed_result,
488         __attribute__((unused)) struct cmdline *cl,
489         __attribute__((unused)) void *data)
490 {
491         struct cmd_show_port_tm_node_cap_result *res = parsed_result;
492         struct rte_tm_node_capabilities ncap;
493         struct rte_tm_error error;
494         uint32_t node_id = res->node_id;
495         portid_t port_id = res->port_id;
496         int ret, is_leaf = 0;
497
498         if (port_id_is_invalid(port_id, ENABLED_WARN))
499                 return;
500
501         /* Node id must be valid */
502         ret = rte_tm_node_type_get(port_id, node_id, &is_leaf, &error);
503         if (ret != 0) {
504                 print_err_msg(&error);
505                 return;
506         }
507
508         memset(&ncap, 0, sizeof(struct rte_tm_node_capabilities));
509         ret = rte_tm_node_capabilities_get(port_id, node_id, &ncap, &error);
510         if (ret != 0) {
511                 print_err_msg(&error);
512                 return;
513         }
514         printf("\n**   Port TM Hierarchy node %" PRIu32 " Capability **\n\n",
515                 node_id);
516         printf("cap.shaper_private_supported %" PRId32 "\n",
517                 ncap.shaper_private_supported);
518         printf("cap.shaper_private_dual_rate_supported %" PRId32 "\n",
519                 ncap.shaper_private_dual_rate_supported);
520         printf("cap.shaper_private_rate_min %" PRIu64 "\n",
521                 ncap.shaper_private_rate_min);
522         printf("cap.shaper_private_rate_max %" PRIu64 "\n",
523                 ncap.shaper_private_rate_max);
524         printf("cap.shaper_shared_n_max %" PRIu32 "\n",
525                 ncap.shaper_shared_n_max);
526         if (!is_leaf) {
527                 printf("cap.nonleaf.sched_n_children_max %" PRIu32 "\n",
528                         ncap.nonleaf.sched_n_children_max);
529                 printf("cap.nonleaf.sched_sp_n_priorities_max %" PRIu32 "\n",
530                         ncap.nonleaf.sched_sp_n_priorities_max);
531                 printf("cap.nonleaf.sched_wfq_n_children_per_group_max %" PRIu32
532                         "\n", ncap.nonleaf.sched_wfq_n_children_per_group_max);
533                 printf("cap.nonleaf.sched_wfq_n_groups_max %" PRIu32 "\n",
534                         ncap.nonleaf.sched_wfq_n_groups_max);
535                 printf("cap.nonleaf.sched_wfq_weight_max %" PRIu32 "\n",
536                         ncap.nonleaf.sched_wfq_weight_max);
537         } else {
538                 printf("cap.leaf.cman_head_drop_supported %" PRId32 "\n",
539                         ncap.leaf.cman_head_drop_supported);
540                 printf("cap.leaf.cman_wred_context_private_supported %" PRId32
541                         "\n", ncap.leaf.cman_wred_context_private_supported);
542                 printf("cap.leaf.cman_wred_context_shared_n_max %" PRIu32 "\n",
543                         ncap.leaf.cman_wred_context_shared_n_max);
544         }
545         printf("cap.stats_mask %" PRIx64 "\n", ncap.stats_mask);
546 }
547
548 cmdline_parse_inst_t cmd_show_port_tm_node_cap = {
549         .f = cmd_show_port_tm_node_cap_parsed,
550         .data = NULL,
551         .help_str = "Show Port TM Hierarchy node capabilities",
552         .tokens = {
553                 (void *)&cmd_show_port_tm_node_cap_show,
554                 (void *)&cmd_show_port_tm_node_cap_port,
555                 (void *)&cmd_show_port_tm_node_cap_tm,
556                 (void *)&cmd_show_port_tm_node_cap_node,
557                 (void *)&cmd_show_port_tm_node_cap_cap,
558                 (void *)&cmd_show_port_tm_node_cap_port_id,
559                 (void *)&cmd_show_port_tm_node_cap_node_id,
560                 NULL,
561         },
562 };
563
564 /* *** Show Port TM Node Statistics *** */
565 struct cmd_show_port_tm_node_stats_result {
566         cmdline_fixed_string_t show;
567         cmdline_fixed_string_t port;
568         cmdline_fixed_string_t tm;
569         cmdline_fixed_string_t node;
570         cmdline_fixed_string_t stats;
571         uint16_t port_id;
572         uint32_t node_id;
573         uint32_t clear;
574 };
575
576 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_show =
577         TOKEN_STRING_INITIALIZER(
578                 struct cmd_show_port_tm_node_stats_result, show, "show");
579 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_port =
580         TOKEN_STRING_INITIALIZER(
581                 struct cmd_show_port_tm_node_stats_result, port, "port");
582 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_tm =
583         TOKEN_STRING_INITIALIZER(
584                 struct cmd_show_port_tm_node_stats_result, tm, "tm");
585 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_node =
586         TOKEN_STRING_INITIALIZER(
587                 struct cmd_show_port_tm_node_stats_result, node, "node");
588 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_stats =
589         TOKEN_STRING_INITIALIZER(
590                 struct cmd_show_port_tm_node_stats_result, stats, "stats");
591 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_port_id =
592         TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_stats_result,
593                         port_id, UINT16);
594 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_node_id =
595         TOKEN_NUM_INITIALIZER(
596                 struct cmd_show_port_tm_node_stats_result,
597                         node_id, UINT32);
598 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_clear =
599         TOKEN_NUM_INITIALIZER(
600                 struct cmd_show_port_tm_node_stats_result, clear, UINT32);
601
602 static void cmd_show_port_tm_node_stats_parsed(void *parsed_result,
603         __attribute__((unused)) struct cmdline *cl,
604         __attribute__((unused)) void *data)
605 {
606         struct cmd_show_port_tm_node_stats_result *res = parsed_result;
607         struct rte_tm_node_stats stats;
608         struct rte_tm_error error;
609         uint64_t stats_mask = 0;
610         uint32_t node_id = res->node_id;
611         uint32_t clear = res->clear;
612         portid_t port_id = res->port_id;
613         int ret;
614
615         if (port_id_is_invalid(port_id, ENABLED_WARN))
616                 return;
617
618         /* Port status */
619         if (!port_is_started(port_id)) {
620                 printf(" Port %u not started (error)\n", port_id);
621                 return;
622         }
623
624         memset(&stats, 0, sizeof(struct rte_tm_node_stats));
625         ret = rte_tm_node_stats_read(port_id, node_id, &stats,
626                         &stats_mask, clear, &error);
627         if (ret != 0) {
628                 print_err_msg(&error);
629                 return;
630         }
631
632         /* Display stats */
633         if (stats_mask & RTE_TM_STATS_N_PKTS)
634                 printf("\tPkts scheduled from node: %" PRIu64 "\n",
635                         stats.n_pkts);
636         if (stats_mask & RTE_TM_STATS_N_BYTES)
637                 printf("\tBytes scheduled from node: %" PRIu64 "\n",
638                         stats.n_bytes);
639         if (stats_mask & RTE_TM_STATS_N_PKTS_GREEN_DROPPED)
640                 printf("\tPkts dropped (green): %" PRIu64 "\n",
641                         stats.leaf.n_pkts_dropped[RTE_TM_GREEN]);
642         if (stats_mask & RTE_TM_STATS_N_PKTS_YELLOW_DROPPED)
643                 printf("\tPkts dropped (yellow): %" PRIu64 "\n",
644                         stats.leaf.n_pkts_dropped[RTE_TM_YELLOW]);
645         if (stats_mask & RTE_TM_STATS_N_PKTS_RED_DROPPED)
646                 printf("\tPkts dropped (red): %" PRIu64 "\n",
647                         stats.leaf.n_pkts_dropped[RTE_TM_RED]);
648         if (stats_mask & RTE_TM_STATS_N_BYTES_GREEN_DROPPED)
649                 printf("\tBytes dropped (green): %" PRIu64 "\n",
650                         stats.leaf.n_bytes_dropped[RTE_TM_GREEN]);
651         if (stats_mask & RTE_TM_STATS_N_BYTES_YELLOW_DROPPED)
652                 printf("\tBytes dropped (yellow): %" PRIu64 "\n",
653                         stats.leaf.n_bytes_dropped[RTE_TM_YELLOW]);
654         if (stats_mask & RTE_TM_STATS_N_BYTES_RED_DROPPED)
655                 printf("\tBytes dropped (red): %" PRIu64 "\n",
656                         stats.leaf.n_bytes_dropped[RTE_TM_RED]);
657         if (stats_mask & RTE_TM_STATS_N_PKTS_QUEUED)
658                 printf("\tPkts queued: %" PRIu64 "\n",
659                         stats.leaf.n_pkts_queued);
660         if (stats_mask & RTE_TM_STATS_N_BYTES_QUEUED)
661                 printf("\tBytes queued: %" PRIu64 "\n",
662                         stats.leaf.n_bytes_queued);
663 }
664
665 cmdline_parse_inst_t cmd_show_port_tm_node_stats = {
666         .f = cmd_show_port_tm_node_stats_parsed,
667         .data = NULL,
668         .help_str = "Show port tm node stats",
669         .tokens = {
670                 (void *)&cmd_show_port_tm_node_stats_show,
671                 (void *)&cmd_show_port_tm_node_stats_port,
672                 (void *)&cmd_show_port_tm_node_stats_tm,
673                 (void *)&cmd_show_port_tm_node_stats_node,
674                 (void *)&cmd_show_port_tm_node_stats_stats,
675                 (void *)&cmd_show_port_tm_node_stats_port_id,
676                 (void *)&cmd_show_port_tm_node_stats_node_id,
677                 (void *)&cmd_show_port_tm_node_stats_clear,
678                 NULL,
679         },
680 };
681
682 /* *** Show Port TM Node Type *** */
683 struct cmd_show_port_tm_node_type_result {
684         cmdline_fixed_string_t show;
685         cmdline_fixed_string_t port;
686         cmdline_fixed_string_t tm;
687         cmdline_fixed_string_t node;
688         cmdline_fixed_string_t type;
689         uint16_t port_id;
690         uint32_t node_id;
691 };
692
693 cmdline_parse_token_string_t cmd_show_port_tm_node_type_show =
694         TOKEN_STRING_INITIALIZER(
695                 struct cmd_show_port_tm_node_type_result, show, "show");
696 cmdline_parse_token_string_t cmd_show_port_tm_node_type_port =
697         TOKEN_STRING_INITIALIZER(
698                 struct cmd_show_port_tm_node_type_result, port, "port");
699 cmdline_parse_token_string_t cmd_show_port_tm_node_type_tm =
700         TOKEN_STRING_INITIALIZER(
701                 struct cmd_show_port_tm_node_type_result, tm, "tm");
702 cmdline_parse_token_string_t cmd_show_port_tm_node_type_node =
703         TOKEN_STRING_INITIALIZER(
704                 struct cmd_show_port_tm_node_type_result, node, "node");
705 cmdline_parse_token_string_t cmd_show_port_tm_node_type_type =
706         TOKEN_STRING_INITIALIZER(
707                 struct cmd_show_port_tm_node_type_result, type, "type");
708 cmdline_parse_token_num_t cmd_show_port_tm_node_type_port_id =
709         TOKEN_NUM_INITIALIZER(
710                 struct cmd_show_port_tm_node_type_result,
711                         port_id, UINT16);
712 cmdline_parse_token_num_t cmd_show_port_tm_node_type_node_id =
713         TOKEN_NUM_INITIALIZER(
714                 struct cmd_show_port_tm_node_type_result,
715                         node_id, UINT32);
716
717 static void cmd_show_port_tm_node_type_parsed(void *parsed_result,
718         __attribute__((unused)) struct cmdline *cl,
719         __attribute__((unused)) void *data)
720 {
721         struct cmd_show_port_tm_node_type_result *res = parsed_result;
722         struct rte_tm_error error;
723         uint32_t node_id = res->node_id;
724         portid_t port_id = res->port_id;
725         int ret, is_leaf = 0;
726
727         if (port_id_is_invalid(port_id, ENABLED_WARN))
728                 return;
729
730         ret = rte_tm_node_type_get(port_id, node_id, &is_leaf, &error);
731         if (ret != 0) {
732                 print_err_msg(&error);
733                 return;
734         }
735
736         if (is_leaf == 1)
737                 printf("leaf node\n");
738         else
739                 printf("nonleaf node\n");
740
741 }
742
743 cmdline_parse_inst_t cmd_show_port_tm_node_type = {
744         .f = cmd_show_port_tm_node_type_parsed,
745         .data = NULL,
746         .help_str = "Show port tm node type",
747         .tokens = {
748                 (void *)&cmd_show_port_tm_node_type_show,
749                 (void *)&cmd_show_port_tm_node_type_port,
750                 (void *)&cmd_show_port_tm_node_type_tm,
751                 (void *)&cmd_show_port_tm_node_type_node,
752                 (void *)&cmd_show_port_tm_node_type_type,
753                 (void *)&cmd_show_port_tm_node_type_port_id,
754                 (void *)&cmd_show_port_tm_node_type_node_id,
755                 NULL,
756         },
757 };
758
759 /* *** Add Port TM Private Shaper Profile *** */
760 struct cmd_add_port_tm_node_shaper_profile_result {
761         cmdline_fixed_string_t add;
762         cmdline_fixed_string_t port;
763         cmdline_fixed_string_t tm;
764         cmdline_fixed_string_t node;
765         cmdline_fixed_string_t shaper;
766         cmdline_fixed_string_t profile;
767         uint16_t port_id;
768         uint32_t shaper_id;
769         uint64_t tb_rate;
770         uint64_t tb_size;
771         uint32_t pktlen_adjust;
772 };
773
774 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_add =
775         TOKEN_STRING_INITIALIZER(
776                 struct cmd_add_port_tm_node_shaper_profile_result, add, "add");
777 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_port =
778         TOKEN_STRING_INITIALIZER(
779                 struct cmd_add_port_tm_node_shaper_profile_result,
780                         port, "port");
781 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_tm =
782         TOKEN_STRING_INITIALIZER(
783                 struct cmd_add_port_tm_node_shaper_profile_result,
784                         tm, "tm");
785 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_node =
786         TOKEN_STRING_INITIALIZER(
787                 struct cmd_add_port_tm_node_shaper_profile_result,
788                         node, "node");
789 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_shaper =
790         TOKEN_STRING_INITIALIZER(
791                 struct cmd_add_port_tm_node_shaper_profile_result,
792                         shaper, "shaper");
793 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_profile =
794         TOKEN_STRING_INITIALIZER(
795                 struct cmd_add_port_tm_node_shaper_profile_result,
796                         profile, "profile");
797 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_port_id =
798         TOKEN_NUM_INITIALIZER(
799                 struct cmd_add_port_tm_node_shaper_profile_result,
800                         port_id, UINT16);
801 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_shaper_id =
802         TOKEN_NUM_INITIALIZER(
803                 struct cmd_add_port_tm_node_shaper_profile_result,
804                         shaper_id, UINT32);
805 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_tb_rate =
806         TOKEN_NUM_INITIALIZER(
807                 struct cmd_add_port_tm_node_shaper_profile_result,
808                         tb_rate, UINT64);
809 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_tb_size =
810         TOKEN_NUM_INITIALIZER(
811                 struct cmd_add_port_tm_node_shaper_profile_result,
812                         tb_size, UINT64);
813 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_pktlen_adjust =
814         TOKEN_NUM_INITIALIZER(
815                 struct cmd_add_port_tm_node_shaper_profile_result,
816                         pktlen_adjust, UINT32);
817
818 static void cmd_add_port_tm_node_shaper_profile_parsed(void *parsed_result,
819         __attribute__((unused)) struct cmdline *cl,
820         __attribute__((unused)) void *data)
821 {
822         struct cmd_add_port_tm_node_shaper_profile_result *res = parsed_result;
823         struct rte_tm_shaper_params sp;
824         struct rte_tm_error error;
825         uint32_t shaper_id = res->shaper_id;
826         uint32_t pkt_len_adjust = res->pktlen_adjust;
827         portid_t port_id = res->port_id;
828         int ret;
829
830         if (port_id_is_invalid(port_id, ENABLED_WARN))
831                 return;
832
833         /* Private shaper profile params */
834         memset(&sp, 0, sizeof(struct rte_tm_shaper_params));
835         sp.peak.rate = res->tb_rate;
836         sp.peak.size = res->tb_size;
837         sp.pkt_length_adjust = pkt_len_adjust;
838
839         ret = rte_tm_shaper_profile_add(port_id, shaper_id, &sp, &error);
840         if (ret != 0) {
841                 print_err_msg(&error);
842                 return;
843         }
844 }
845
846 cmdline_parse_inst_t cmd_add_port_tm_node_shaper_profile = {
847         .f = cmd_add_port_tm_node_shaper_profile_parsed,
848         .data = NULL,
849         .help_str = "Add port tm node private shaper profile",
850         .tokens = {
851                 (void *)&cmd_add_port_tm_node_shaper_profile_add,
852                 (void *)&cmd_add_port_tm_node_shaper_profile_port,
853                 (void *)&cmd_add_port_tm_node_shaper_profile_tm,
854                 (void *)&cmd_add_port_tm_node_shaper_profile_node,
855                 (void *)&cmd_add_port_tm_node_shaper_profile_shaper,
856                 (void *)&cmd_add_port_tm_node_shaper_profile_profile,
857                 (void *)&cmd_add_port_tm_node_shaper_profile_port_id,
858                 (void *)&cmd_add_port_tm_node_shaper_profile_shaper_id,
859                 (void *)&cmd_add_port_tm_node_shaper_profile_tb_rate,
860                 (void *)&cmd_add_port_tm_node_shaper_profile_tb_size,
861                 (void *)&cmd_add_port_tm_node_shaper_profile_pktlen_adjust,
862                 NULL,
863         },
864 };
865
866 /* *** Delete Port TM Private Shaper Profile *** */
867 struct cmd_del_port_tm_node_shaper_profile_result {
868         cmdline_fixed_string_t del;
869         cmdline_fixed_string_t port;
870         cmdline_fixed_string_t tm;
871         cmdline_fixed_string_t node;
872         cmdline_fixed_string_t shaper;
873         cmdline_fixed_string_t profile;
874         uint16_t port_id;
875         uint32_t shaper_id;
876 };
877
878 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_del =
879         TOKEN_STRING_INITIALIZER(
880                 struct cmd_del_port_tm_node_shaper_profile_result, del, "del");
881 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_port =
882         TOKEN_STRING_INITIALIZER(
883                 struct cmd_del_port_tm_node_shaper_profile_result,
884                         port, "port");
885 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_tm =
886         TOKEN_STRING_INITIALIZER(
887                 struct cmd_del_port_tm_node_shaper_profile_result, tm, "tm");
888 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_node =
889         TOKEN_STRING_INITIALIZER(
890                 struct cmd_del_port_tm_node_shaper_profile_result,
891                         node, "node");
892 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_shaper =
893         TOKEN_STRING_INITIALIZER(
894                 struct cmd_del_port_tm_node_shaper_profile_result,
895                         shaper, "shaper");
896 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_profile =
897         TOKEN_STRING_INITIALIZER(
898                 struct cmd_del_port_tm_node_shaper_profile_result,
899                         profile, "profile");
900 cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_port_id =
901         TOKEN_NUM_INITIALIZER(
902                 struct cmd_del_port_tm_node_shaper_profile_result,
903                         port_id, UINT16);
904 cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_shaper_id =
905         TOKEN_NUM_INITIALIZER(
906                 struct cmd_del_port_tm_node_shaper_profile_result,
907                         shaper_id, UINT32);
908
909 static void cmd_del_port_tm_node_shaper_profile_parsed(void *parsed_result,
910         __attribute__((unused)) struct cmdline *cl,
911         __attribute__((unused)) void *data)
912 {
913         struct cmd_del_port_tm_node_shaper_profile_result *res = parsed_result;
914         struct rte_tm_error error;
915         uint32_t shaper_id = res->shaper_id;
916         portid_t port_id = res->port_id;
917         int ret;
918
919         if (port_id_is_invalid(port_id, ENABLED_WARN))
920                 return;
921
922         ret = rte_tm_shaper_profile_delete(port_id, shaper_id, &error);
923         if (ret != 0) {
924                 print_err_msg(&error);
925                 return;
926         }
927 }
928
929 cmdline_parse_inst_t cmd_del_port_tm_node_shaper_profile = {
930         .f = cmd_del_port_tm_node_shaper_profile_parsed,
931         .data = NULL,
932         .help_str = "Delete port tm node private shaper profile",
933         .tokens = {
934                 (void *)&cmd_del_port_tm_node_shaper_profile_del,
935                 (void *)&cmd_del_port_tm_node_shaper_profile_port,
936                 (void *)&cmd_del_port_tm_node_shaper_profile_tm,
937                 (void *)&cmd_del_port_tm_node_shaper_profile_node,
938                 (void *)&cmd_del_port_tm_node_shaper_profile_shaper,
939                 (void *)&cmd_del_port_tm_node_shaper_profile_profile,
940                 (void *)&cmd_del_port_tm_node_shaper_profile_port_id,
941                 (void *)&cmd_del_port_tm_node_shaper_profile_shaper_id,
942                 NULL,
943         },
944 };
945
946 /* *** Add/Update Port TM shared Shaper *** */
947 struct cmd_add_port_tm_node_shared_shaper_result {
948         cmdline_fixed_string_t cmd_type;
949         cmdline_fixed_string_t port;
950         cmdline_fixed_string_t tm;
951         cmdline_fixed_string_t node;
952         cmdline_fixed_string_t shared;
953         cmdline_fixed_string_t shaper;
954         uint16_t port_id;
955         uint32_t shared_shaper_id;
956         uint32_t shaper_profile_id;
957 };
958
959 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_cmd_type =
960         TOKEN_STRING_INITIALIZER(
961                 struct cmd_add_port_tm_node_shared_shaper_result,
962                         cmd_type, "add#set");
963 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_port =
964         TOKEN_STRING_INITIALIZER(
965                 struct cmd_add_port_tm_node_shared_shaper_result, port, "port");
966 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_tm =
967         TOKEN_STRING_INITIALIZER(
968                 struct cmd_add_port_tm_node_shared_shaper_result, tm, "tm");
969 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_node =
970         TOKEN_STRING_INITIALIZER(
971                 struct cmd_add_port_tm_node_shared_shaper_result, node, "node");
972 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shared =
973         TOKEN_STRING_INITIALIZER(
974                 struct cmd_add_port_tm_node_shared_shaper_result,
975                         shared, "shared");
976 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shaper =
977         TOKEN_STRING_INITIALIZER(
978                 struct cmd_add_port_tm_node_shared_shaper_result,
979                         shaper, "shaper");
980 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_port_id =
981         TOKEN_NUM_INITIALIZER(
982                 struct cmd_add_port_tm_node_shared_shaper_result,
983                         port_id, UINT16);
984 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shared_shaper_id =
985         TOKEN_NUM_INITIALIZER(
986                 struct cmd_add_port_tm_node_shared_shaper_result,
987                         shared_shaper_id, UINT32);
988 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shaper_profile_id =
989         TOKEN_NUM_INITIALIZER(
990                 struct cmd_add_port_tm_node_shared_shaper_result,
991                         shaper_profile_id, UINT32);
992
993 static void cmd_add_port_tm_node_shared_shaper_parsed(void *parsed_result,
994         __attribute__((unused)) struct cmdline *cl,
995         __attribute__((unused)) void *data)
996 {
997         struct cmd_add_port_tm_node_shared_shaper_result *res = parsed_result;
998         struct rte_tm_error error;
999         uint32_t shared_shaper_id = res->shared_shaper_id;
1000         uint32_t shaper_profile_id = res->shaper_profile_id;
1001         portid_t port_id = res->port_id;
1002         int ret;
1003
1004         if (port_id_is_invalid(port_id, ENABLED_WARN))
1005                 return;
1006
1007         /* Command type: add */
1008         if ((strcmp(res->cmd_type, "add") == 0) &&
1009                 (port_is_started(port_id))) {
1010                 printf(" Port %u not stopped (error)\n", port_id);
1011                 return;
1012         }
1013
1014         /* Command type: set (update) */
1015         if ((strcmp(res->cmd_type, "set") == 0) &&
1016                 (!port_is_started(port_id))) {
1017                 printf(" Port %u not started (error)\n", port_id);
1018                 return;
1019         }
1020
1021         ret = rte_tm_shared_shaper_add_update(port_id, shared_shaper_id,
1022                 shaper_profile_id, &error);
1023         if (ret != 0) {
1024                 print_err_msg(&error);
1025                 return;
1026         }
1027 }
1028
1029 cmdline_parse_inst_t cmd_add_port_tm_node_shared_shaper = {
1030         .f = cmd_add_port_tm_node_shared_shaper_parsed,
1031         .data = NULL,
1032         .help_str = "add/update port tm node shared shaper",
1033         .tokens = {
1034                 (void *)&cmd_add_port_tm_node_shared_shaper_cmd_type,
1035                 (void *)&cmd_add_port_tm_node_shared_shaper_port,
1036                 (void *)&cmd_add_port_tm_node_shared_shaper_tm,
1037                 (void *)&cmd_add_port_tm_node_shared_shaper_node,
1038                 (void *)&cmd_add_port_tm_node_shared_shaper_shared,
1039                 (void *)&cmd_add_port_tm_node_shared_shaper_shaper,
1040                 (void *)&cmd_add_port_tm_node_shared_shaper_port_id,
1041                 (void *)&cmd_add_port_tm_node_shared_shaper_shared_shaper_id,
1042                 (void *)&cmd_add_port_tm_node_shared_shaper_shaper_profile_id,
1043                 NULL,
1044         },
1045 };
1046
1047 /* *** Delete Port TM shared Shaper *** */
1048 struct cmd_del_port_tm_node_shared_shaper_result {
1049         cmdline_fixed_string_t del;
1050         cmdline_fixed_string_t port;
1051         cmdline_fixed_string_t tm;
1052         cmdline_fixed_string_t node;
1053         cmdline_fixed_string_t shared;
1054         cmdline_fixed_string_t shaper;
1055         uint16_t port_id;
1056         uint32_t shared_shaper_id;
1057 };
1058
1059 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_del =
1060         TOKEN_STRING_INITIALIZER(
1061                 struct cmd_del_port_tm_node_shared_shaper_result, del, "del");
1062 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_port =
1063         TOKEN_STRING_INITIALIZER(
1064                 struct cmd_del_port_tm_node_shared_shaper_result, port, "port");
1065 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_tm =
1066         TOKEN_STRING_INITIALIZER(
1067                 struct cmd_del_port_tm_node_shared_shaper_result, tm, "tm");
1068 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_node =
1069         TOKEN_STRING_INITIALIZER(
1070                 struct cmd_del_port_tm_node_shared_shaper_result, node, "node");
1071 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shared =
1072         TOKEN_STRING_INITIALIZER(
1073                 struct cmd_del_port_tm_node_shared_shaper_result,
1074                         shared, "shared");
1075 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shaper =
1076         TOKEN_STRING_INITIALIZER(
1077                 struct cmd_del_port_tm_node_shared_shaper_result,
1078                         shaper, "shaper");
1079 cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_port_id =
1080         TOKEN_NUM_INITIALIZER(
1081                 struct cmd_del_port_tm_node_shared_shaper_result,
1082                         port_id, UINT16);
1083 cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_shared_shaper_id =
1084         TOKEN_NUM_INITIALIZER(
1085                 struct cmd_del_port_tm_node_shared_shaper_result,
1086                         shared_shaper_id, UINT32);
1087
1088 static void cmd_del_port_tm_node_shared_shaper_parsed(void *parsed_result,
1089         __attribute__((unused)) struct cmdline *cl,
1090         __attribute__((unused)) void *data)
1091 {
1092         struct cmd_del_port_tm_node_shared_shaper_result *res = parsed_result;
1093         struct rte_tm_error error;
1094         uint32_t shared_shaper_id = res->shared_shaper_id;
1095         portid_t port_id = res->port_id;
1096         int ret;
1097
1098         if (port_id_is_invalid(port_id, ENABLED_WARN))
1099                 return;
1100
1101         ret = rte_tm_shared_shaper_delete(port_id, shared_shaper_id, &error);
1102         if (ret != 0) {
1103                 print_err_msg(&error);
1104                 return;
1105         }
1106 }
1107
1108 cmdline_parse_inst_t cmd_del_port_tm_node_shared_shaper = {
1109         .f = cmd_del_port_tm_node_shared_shaper_parsed,
1110         .data = NULL,
1111         .help_str = "delete port tm node shared shaper",
1112         .tokens = {
1113                 (void *)&cmd_del_port_tm_node_shared_shaper_del,
1114                 (void *)&cmd_del_port_tm_node_shared_shaper_port,
1115                 (void *)&cmd_del_port_tm_node_shared_shaper_tm,
1116                 (void *)&cmd_del_port_tm_node_shared_shaper_node,
1117                 (void *)&cmd_del_port_tm_node_shared_shaper_shared,
1118                 (void *)&cmd_del_port_tm_node_shared_shaper_shaper,
1119                 (void *)&cmd_del_port_tm_node_shared_shaper_port_id,
1120                 (void *)&cmd_del_port_tm_node_shared_shaper_shared_shaper_id,
1121                 NULL,
1122         },
1123 };
1124
1125 /* *** Add Port TM Node WRED Profile *** */
1126 struct cmd_add_port_tm_node_wred_profile_result {
1127         cmdline_fixed_string_t add;
1128         cmdline_fixed_string_t port;
1129         cmdline_fixed_string_t tm;
1130         cmdline_fixed_string_t node;
1131         cmdline_fixed_string_t wred;
1132         cmdline_fixed_string_t profile;
1133         uint16_t port_id;
1134         uint32_t wred_profile_id;
1135         cmdline_fixed_string_t color_g;
1136         uint16_t min_th_g;
1137         uint16_t max_th_g;
1138         uint16_t maxp_inv_g;
1139         uint16_t wq_log2_g;
1140         cmdline_fixed_string_t color_y;
1141         uint16_t min_th_y;
1142         uint16_t max_th_y;
1143         uint16_t maxp_inv_y;
1144         uint16_t wq_log2_y;
1145         cmdline_fixed_string_t color_r;
1146         uint16_t min_th_r;
1147         uint16_t max_th_r;
1148         uint16_t maxp_inv_r;
1149         uint16_t wq_log2_r;
1150 };
1151
1152 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_add =
1153         TOKEN_STRING_INITIALIZER(
1154                 struct cmd_add_port_tm_node_wred_profile_result, add, "add");
1155 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_port =
1156         TOKEN_STRING_INITIALIZER(
1157                 struct cmd_add_port_tm_node_wred_profile_result, port, "port");
1158 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_tm =
1159         TOKEN_STRING_INITIALIZER(
1160                 struct cmd_add_port_tm_node_wred_profile_result, tm, "tm");
1161 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_node =
1162         TOKEN_STRING_INITIALIZER(
1163                 struct cmd_add_port_tm_node_wred_profile_result, node, "node");
1164 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_wred =
1165         TOKEN_STRING_INITIALIZER(
1166                 struct cmd_add_port_tm_node_wred_profile_result, wred, "wred");
1167 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_profile =
1168         TOKEN_STRING_INITIALIZER(
1169                 struct cmd_add_port_tm_node_wred_profile_result,
1170                         profile, "profile");
1171 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_port_id =
1172         TOKEN_NUM_INITIALIZER(
1173                 struct cmd_add_port_tm_node_wred_profile_result,
1174                         port_id, UINT16);
1175 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wred_profile_id =
1176         TOKEN_NUM_INITIALIZER(
1177                 struct cmd_add_port_tm_node_wred_profile_result,
1178                         wred_profile_id, UINT32);
1179 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_g =
1180         TOKEN_STRING_INITIALIZER(
1181                 struct cmd_add_port_tm_node_wred_profile_result,
1182                         color_g, "G#g");
1183 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_g =
1184         TOKEN_NUM_INITIALIZER(
1185                 struct cmd_add_port_tm_node_wred_profile_result,
1186                         min_th_g, UINT16);
1187 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_g =
1188         TOKEN_NUM_INITIALIZER(
1189                 struct cmd_add_port_tm_node_wred_profile_result,
1190                         max_th_g, UINT16);
1191 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_g =
1192         TOKEN_NUM_INITIALIZER(
1193                 struct cmd_add_port_tm_node_wred_profile_result,
1194                         maxp_inv_g, UINT16);
1195 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_g =
1196         TOKEN_NUM_INITIALIZER(
1197                 struct cmd_add_port_tm_node_wred_profile_result,
1198                         wq_log2_g, UINT16);
1199 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_y =
1200         TOKEN_STRING_INITIALIZER(
1201                 struct cmd_add_port_tm_node_wred_profile_result,
1202                         color_y, "Y#y");
1203 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_y =
1204         TOKEN_NUM_INITIALIZER(
1205                 struct cmd_add_port_tm_node_wred_profile_result,
1206                         min_th_y, UINT16);
1207 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_y =
1208         TOKEN_NUM_INITIALIZER(
1209                 struct cmd_add_port_tm_node_wred_profile_result,
1210                         max_th_y, UINT16);
1211 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_y =
1212         TOKEN_NUM_INITIALIZER(
1213                 struct cmd_add_port_tm_node_wred_profile_result,
1214                         maxp_inv_y, UINT16);
1215 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_y =
1216         TOKEN_NUM_INITIALIZER(
1217                 struct cmd_add_port_tm_node_wred_profile_result,
1218                         wq_log2_y, UINT16);
1219 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_r =
1220         TOKEN_STRING_INITIALIZER(
1221                 struct cmd_add_port_tm_node_wred_profile_result,
1222                         color_r, "R#r");
1223 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_r =
1224         TOKEN_NUM_INITIALIZER(
1225                 struct cmd_add_port_tm_node_wred_profile_result,
1226                         min_th_r, UINT16);
1227 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_r =
1228         TOKEN_NUM_INITIALIZER(
1229                 struct cmd_add_port_tm_node_wred_profile_result,
1230                         max_th_r, UINT16);
1231 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_r =
1232         TOKEN_NUM_INITIALIZER(
1233                 struct cmd_add_port_tm_node_wred_profile_result,
1234                         maxp_inv_r, UINT16);
1235 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_r =
1236         TOKEN_NUM_INITIALIZER(
1237                 struct cmd_add_port_tm_node_wred_profile_result,
1238                         wq_log2_r, UINT16);
1239
1240
1241 static void cmd_add_port_tm_node_wred_profile_parsed(void *parsed_result,
1242         __attribute__((unused)) struct cmdline *cl,
1243         __attribute__((unused)) void *data)
1244 {
1245         struct cmd_add_port_tm_node_wred_profile_result *res = parsed_result;
1246         struct rte_tm_wred_params wp;
1247         enum rte_tm_color color;
1248         struct rte_tm_error error;
1249         uint32_t wred_profile_id = res->wred_profile_id;
1250         portid_t port_id = res->port_id;
1251         int ret;
1252
1253         if (port_id_is_invalid(port_id, ENABLED_WARN))
1254                 return;
1255
1256         memset(&wp, 0, sizeof(struct rte_tm_wred_params));
1257
1258         /* WRED Params  (Green Color)*/
1259         color = RTE_TM_GREEN;
1260         wp.red_params[color].min_th = res->min_th_g;
1261         wp.red_params[color].max_th = res->max_th_g;
1262         wp.red_params[color].maxp_inv = res->maxp_inv_g;
1263         wp.red_params[color].wq_log2 = res->wq_log2_g;
1264
1265
1266         /* WRED Params  (Yellow Color)*/
1267         color = RTE_TM_YELLOW;
1268         wp.red_params[color].min_th = res->min_th_y;
1269         wp.red_params[color].max_th = res->max_th_y;
1270         wp.red_params[color].maxp_inv = res->maxp_inv_y;
1271         wp.red_params[color].wq_log2 = res->wq_log2_y;
1272
1273         /* WRED Params  (Red Color)*/
1274         color = RTE_TM_RED;
1275         wp.red_params[color].min_th = res->min_th_r;
1276         wp.red_params[color].max_th = res->max_th_r;
1277         wp.red_params[color].maxp_inv = res->maxp_inv_r;
1278         wp.red_params[color].wq_log2 = res->wq_log2_r;
1279
1280         ret = rte_tm_wred_profile_add(port_id, wred_profile_id, &wp, &error);
1281         if (ret != 0) {
1282                 print_err_msg(&error);
1283                 return;
1284         }
1285 }
1286
1287 cmdline_parse_inst_t cmd_add_port_tm_node_wred_profile = {
1288         .f = cmd_add_port_tm_node_wred_profile_parsed,
1289         .data = NULL,
1290         .help_str = "Add port tm node wred profile",
1291         .tokens = {
1292                 (void *)&cmd_add_port_tm_node_wred_profile_add,
1293                 (void *)&cmd_add_port_tm_node_wred_profile_port,
1294                 (void *)&cmd_add_port_tm_node_wred_profile_tm,
1295                 (void *)&cmd_add_port_tm_node_wred_profile_node,
1296                 (void *)&cmd_add_port_tm_node_wred_profile_wred,
1297                 (void *)&cmd_add_port_tm_node_wred_profile_profile,
1298                 (void *)&cmd_add_port_tm_node_wred_profile_port_id,
1299                 (void *)&cmd_add_port_tm_node_wred_profile_wred_profile_id,
1300                 (void *)&cmd_add_port_tm_node_wred_profile_color_g,
1301                 (void *)&cmd_add_port_tm_node_wred_profile_min_th_g,
1302                 (void *)&cmd_add_port_tm_node_wred_profile_max_th_g,
1303                 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_g,
1304                 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_g,
1305                 (void *)&cmd_add_port_tm_node_wred_profile_color_y,
1306                 (void *)&cmd_add_port_tm_node_wred_profile_min_th_y,
1307                 (void *)&cmd_add_port_tm_node_wred_profile_max_th_y,
1308                 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_y,
1309                 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_y,
1310                 (void *)&cmd_add_port_tm_node_wred_profile_color_r,
1311                 (void *)&cmd_add_port_tm_node_wred_profile_min_th_r,
1312                 (void *)&cmd_add_port_tm_node_wred_profile_max_th_r,
1313                 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_r,
1314                 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_r,
1315                 NULL,
1316         },
1317 };
1318
1319 /* *** Delete Port TM node WRED Profile *** */
1320 struct cmd_del_port_tm_node_wred_profile_result {
1321         cmdline_fixed_string_t del;
1322         cmdline_fixed_string_t port;
1323         cmdline_fixed_string_t tm;
1324         cmdline_fixed_string_t node;
1325         cmdline_fixed_string_t wred;
1326         cmdline_fixed_string_t profile;
1327         uint16_t port_id;
1328         uint32_t wred_profile_id;
1329 };
1330
1331 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_del =
1332         TOKEN_STRING_INITIALIZER(
1333                 struct cmd_del_port_tm_node_wred_profile_result, del, "del");
1334 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_port =
1335         TOKEN_STRING_INITIALIZER(
1336                 struct cmd_del_port_tm_node_wred_profile_result, port, "port");
1337 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_tm =
1338         TOKEN_STRING_INITIALIZER(
1339                 struct cmd_del_port_tm_node_wred_profile_result, tm, "tm");
1340 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_node =
1341         TOKEN_STRING_INITIALIZER(
1342                 struct cmd_del_port_tm_node_wred_profile_result, node, "node");
1343 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_wred =
1344         TOKEN_STRING_INITIALIZER(
1345                 struct cmd_del_port_tm_node_wred_profile_result, wred, "wred");
1346 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_profile =
1347         TOKEN_STRING_INITIALIZER(
1348                 struct cmd_del_port_tm_node_wred_profile_result,
1349                         profile, "profile");
1350 cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_port_id =
1351         TOKEN_NUM_INITIALIZER(
1352                 struct cmd_del_port_tm_node_wred_profile_result,
1353                         port_id, UINT16);
1354 cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_wred_profile_id =
1355         TOKEN_NUM_INITIALIZER(
1356                 struct cmd_del_port_tm_node_wred_profile_result,
1357                         wred_profile_id, UINT32);
1358
1359 static void cmd_del_port_tm_node_wred_profile_parsed(void *parsed_result,
1360         __attribute__((unused)) struct cmdline *cl,
1361         __attribute__((unused)) void *data)
1362 {
1363         struct cmd_del_port_tm_node_wred_profile_result *res = parsed_result;
1364         struct rte_tm_error error;
1365         uint32_t wred_profile_id = res->wred_profile_id;
1366         portid_t port_id = res->port_id;
1367         int ret;
1368
1369         if (port_id_is_invalid(port_id, ENABLED_WARN))
1370                 return;
1371
1372         ret = rte_tm_wred_profile_delete(port_id, wred_profile_id, &error);
1373         if (ret != 0) {
1374                 print_err_msg(&error);
1375                 return;
1376         }
1377 }
1378
1379 cmdline_parse_inst_t cmd_del_port_tm_node_wred_profile = {
1380         .f = cmd_del_port_tm_node_wred_profile_parsed,
1381         .data = NULL,
1382         .help_str = "Delete port tm node wred profile",
1383         .tokens = {
1384                 (void *)&cmd_del_port_tm_node_wred_profile_del,
1385                 (void *)&cmd_del_port_tm_node_wred_profile_port,
1386                 (void *)&cmd_del_port_tm_node_wred_profile_tm,
1387                 (void *)&cmd_del_port_tm_node_wred_profile_node,
1388                 (void *)&cmd_del_port_tm_node_wred_profile_wred,
1389                 (void *)&cmd_del_port_tm_node_wred_profile_profile,
1390                 (void *)&cmd_del_port_tm_node_wred_profile_port_id,
1391                 (void *)&cmd_del_port_tm_node_wred_profile_wred_profile_id,
1392                 NULL,
1393         },
1394 };
1395
1396 /* *** Update Port TM Node Shaper profile *** */
1397 struct cmd_set_port_tm_node_shaper_profile_result {
1398         cmdline_fixed_string_t set;
1399         cmdline_fixed_string_t port;
1400         cmdline_fixed_string_t tm;
1401         cmdline_fixed_string_t node;
1402         cmdline_fixed_string_t shaper;
1403         cmdline_fixed_string_t profile;
1404         uint16_t port_id;
1405         uint32_t node_id;
1406         uint32_t shaper_profile_id;
1407 };
1408
1409 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_set =
1410         TOKEN_STRING_INITIALIZER(
1411                 struct cmd_set_port_tm_node_shaper_profile_result, set, "set");
1412 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_port =
1413         TOKEN_STRING_INITIALIZER(
1414                 struct cmd_set_port_tm_node_shaper_profile_result,
1415                         port, "port");
1416 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_tm =
1417         TOKEN_STRING_INITIALIZER(
1418                 struct cmd_set_port_tm_node_shaper_profile_result, tm, "tm");
1419 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_node =
1420         TOKEN_STRING_INITIALIZER(
1421                 struct cmd_set_port_tm_node_shaper_profile_result,
1422                         node, "node");
1423 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_shaper =
1424         TOKEN_STRING_INITIALIZER(
1425                 struct cmd_set_port_tm_node_shaper_profile_result,
1426                         shaper, "shaper");
1427 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_profile =
1428         TOKEN_STRING_INITIALIZER(
1429                 struct cmd_set_port_tm_node_shaper_profile_result,
1430                         profile, "profile");
1431 cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_port_id =
1432         TOKEN_NUM_INITIALIZER(
1433                 struct cmd_set_port_tm_node_shaper_profile_result,
1434                         port_id, UINT16);
1435 cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_node_id =
1436         TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_shaper_profile_result,
1437                 node_id, UINT32);
1438 cmdline_parse_token_num_t
1439         cmd_set_port_tm_node_shaper_shaper_profile_profile_id =
1440                 TOKEN_NUM_INITIALIZER(
1441                         struct cmd_set_port_tm_node_shaper_profile_result,
1442                         shaper_profile_id, UINT32);
1443
1444 static void cmd_set_port_tm_node_shaper_profile_parsed(void *parsed_result,
1445         __attribute__((unused)) struct cmdline *cl,
1446         __attribute__((unused)) void *data)
1447 {
1448         struct cmd_set_port_tm_node_shaper_profile_result *res = parsed_result;
1449         struct rte_tm_error error;
1450         uint32_t node_id = res->node_id;
1451         uint32_t shaper_profile_id = res->shaper_profile_id;
1452         portid_t port_id = res->port_id;
1453         int ret;
1454
1455         if (port_id_is_invalid(port_id, ENABLED_WARN))
1456                 return;
1457
1458         /* Port status */
1459         if (!port_is_started(port_id)) {
1460                 printf(" Port %u not started (error)\n", port_id);
1461                 return;
1462         }
1463
1464         ret = rte_tm_node_shaper_update(port_id, node_id,
1465                 shaper_profile_id, &error);
1466         if (ret != 0) {
1467                 print_err_msg(&error);
1468                 return;
1469         }
1470 }
1471
1472 cmdline_parse_inst_t cmd_set_port_tm_node_shaper_profile = {
1473         .f = cmd_set_port_tm_node_shaper_profile_parsed,
1474         .data = NULL,
1475         .help_str = "Set port tm node shaper profile",
1476         .tokens = {
1477                 (void *)&cmd_set_port_tm_node_shaper_profile_set,
1478                 (void *)&cmd_set_port_tm_node_shaper_profile_port,
1479                 (void *)&cmd_set_port_tm_node_shaper_profile_tm,
1480                 (void *)&cmd_set_port_tm_node_shaper_profile_node,
1481                 (void *)&cmd_set_port_tm_node_shaper_profile_shaper,
1482                 (void *)&cmd_set_port_tm_node_shaper_profile_profile,
1483                 (void *)&cmd_set_port_tm_node_shaper_profile_port_id,
1484                 (void *)&cmd_set_port_tm_node_shaper_profile_node_id,
1485                 (void *)&cmd_set_port_tm_node_shaper_shaper_profile_profile_id,
1486                 NULL,
1487         },
1488 };
1489
1490 /* *** Add Port TM nonleaf node *** */
1491 struct cmd_add_port_tm_nonleaf_node_result {
1492         cmdline_fixed_string_t add;
1493         cmdline_fixed_string_t port;
1494         cmdline_fixed_string_t tm;
1495         cmdline_fixed_string_t nonleaf;
1496         cmdline_fixed_string_t node;
1497         uint16_t port_id;
1498         uint32_t node_id;
1499         int32_t parent_node_id;
1500         uint32_t priority;
1501         uint32_t weight;
1502         uint32_t level_id;
1503         int32_t shaper_profile_id;
1504         uint32_t n_sp_priorities;
1505         uint64_t stats_mask;
1506         cmdline_multi_string_t multi_shared_shaper_id;
1507 };
1508
1509 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_add =
1510         TOKEN_STRING_INITIALIZER(
1511                 struct cmd_add_port_tm_nonleaf_node_result, add, "add");
1512 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_port =
1513         TOKEN_STRING_INITIALIZER(
1514                 struct cmd_add_port_tm_nonleaf_node_result, port, "port");
1515 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_tm =
1516         TOKEN_STRING_INITIALIZER(
1517                 struct cmd_add_port_tm_nonleaf_node_result, tm, "tm");
1518 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_nonleaf =
1519         TOKEN_STRING_INITIALIZER(
1520                 struct cmd_add_port_tm_nonleaf_node_result, nonleaf, "nonleaf");
1521 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_node =
1522         TOKEN_STRING_INITIALIZER(
1523                 struct cmd_add_port_tm_nonleaf_node_result, node, "node");
1524 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_port_id =
1525         TOKEN_NUM_INITIALIZER(
1526                 struct cmd_add_port_tm_nonleaf_node_result,
1527                  port_id, UINT16);
1528 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_node_id =
1529         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1530                  node_id, UINT32);
1531 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_parent_node_id =
1532         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1533                  parent_node_id, INT32);
1534 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_priority =
1535         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1536                  priority, UINT32);
1537 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_weight =
1538         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1539                  weight, UINT32);
1540 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_level_id =
1541         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1542                  level_id, UINT32);
1543 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_shaper_profile_id =
1544         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1545                  shaper_profile_id, INT32);
1546 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_n_sp_priorities =
1547         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1548                  n_sp_priorities, UINT32);
1549 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_stats_mask =
1550         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1551                  stats_mask, UINT64);
1552 cmdline_parse_token_string_t
1553         cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id =
1554         TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1555                  multi_shared_shaper_id, TOKEN_STRING_MULTI);
1556
1557 static void cmd_add_port_tm_nonleaf_node_parsed(void *parsed_result,
1558         __attribute__((unused)) struct cmdline *cl,
1559         __attribute__((unused)) void *data)
1560 {
1561         struct cmd_add_port_tm_nonleaf_node_result *res = parsed_result;
1562         struct rte_tm_error error;
1563         struct rte_tm_node_params np;
1564         uint32_t *shared_shaper_id;
1565         uint32_t parent_node_id, n_shared_shapers = 0;
1566         char *s_str = res->multi_shared_shaper_id;
1567         portid_t port_id = res->port_id;
1568         int ret;
1569
1570         if (port_id_is_invalid(port_id, ENABLED_WARN))
1571                 return;
1572
1573         memset(&np, 0, sizeof(struct rte_tm_node_params));
1574
1575         /* Node parameters */
1576         if (res->parent_node_id < 0)
1577                 parent_node_id = UINT32_MAX;
1578         else
1579                 parent_node_id = res->parent_node_id;
1580
1581         shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS *
1582                 sizeof(uint32_t));
1583         if (shared_shaper_id == NULL) {
1584                 printf(" Memory not allocated for shared shapers (error)\n");
1585                 return;
1586         }
1587
1588         /* Parse multi shared shaper id string */
1589         ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id);
1590         if (ret) {
1591                 printf(" Shared shapers params string parse error\n");
1592                 free(shared_shaper_id);
1593                 return;
1594         }
1595
1596         if (res->shaper_profile_id < 0)
1597                 np.shaper_profile_id = UINT32_MAX;
1598         else
1599                 np.shaper_profile_id = res->shaper_profile_id;
1600
1601         np.n_shared_shapers = n_shared_shapers;
1602         if (np.n_shared_shapers)
1603                 np.shared_shaper_id = &shared_shaper_id[0];
1604         else
1605                 np.shared_shaper_id = NULL;
1606
1607         np.nonleaf.n_sp_priorities = res->n_sp_priorities;
1608         np.stats_mask = res->stats_mask;
1609         np.nonleaf.wfq_weight_mode = NULL;
1610
1611         ret = rte_tm_node_add(port_id, res->node_id, parent_node_id,
1612                                 res->priority, res->weight, res->level_id,
1613                                 &np, &error);
1614         if (ret != 0) {
1615                 print_err_msg(&error);
1616                 free(shared_shaper_id);
1617                 return;
1618         }
1619 }
1620
1621 cmdline_parse_inst_t cmd_add_port_tm_nonleaf_node = {
1622         .f = cmd_add_port_tm_nonleaf_node_parsed,
1623         .data = NULL,
1624         .help_str = "Add port tm nonleaf node",
1625         .tokens = {
1626                 (void *)&cmd_add_port_tm_nonleaf_node_add,
1627                 (void *)&cmd_add_port_tm_nonleaf_node_port,
1628                 (void *)&cmd_add_port_tm_nonleaf_node_tm,
1629                 (void *)&cmd_add_port_tm_nonleaf_node_nonleaf,
1630                 (void *)&cmd_add_port_tm_nonleaf_node_node,
1631                 (void *)&cmd_add_port_tm_nonleaf_node_port_id,
1632                 (void *)&cmd_add_port_tm_nonleaf_node_node_id,
1633                 (void *)&cmd_add_port_tm_nonleaf_node_parent_node_id,
1634                 (void *)&cmd_add_port_tm_nonleaf_node_priority,
1635                 (void *)&cmd_add_port_tm_nonleaf_node_weight,
1636                 (void *)&cmd_add_port_tm_nonleaf_node_level_id,
1637                 (void *)&cmd_add_port_tm_nonleaf_node_shaper_profile_id,
1638                 (void *)&cmd_add_port_tm_nonleaf_node_n_sp_priorities,
1639                 (void *)&cmd_add_port_tm_nonleaf_node_stats_mask,
1640                 (void *)&cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id,
1641                 NULL,
1642         },
1643 };
1644
1645 /* *** Add Port TM leaf node *** */
1646 struct cmd_add_port_tm_leaf_node_result {
1647         cmdline_fixed_string_t add;
1648         cmdline_fixed_string_t port;
1649         cmdline_fixed_string_t tm;
1650         cmdline_fixed_string_t leaf;
1651         cmdline_fixed_string_t node;
1652         uint16_t port_id;
1653         uint32_t node_id;
1654         int32_t parent_node_id;
1655         uint32_t priority;
1656         uint32_t weight;
1657         uint32_t level_id;
1658         int32_t shaper_profile_id;
1659         uint32_t cman_mode;
1660         uint32_t wred_profile_id;
1661         uint64_t stats_mask;
1662         cmdline_multi_string_t multi_shared_shaper_id;
1663 };
1664
1665 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_add =
1666         TOKEN_STRING_INITIALIZER(
1667                 struct cmd_add_port_tm_leaf_node_result, add, "add");
1668 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_port =
1669         TOKEN_STRING_INITIALIZER(
1670                 struct cmd_add_port_tm_leaf_node_result, port, "port");
1671 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_tm =
1672         TOKEN_STRING_INITIALIZER(
1673                 struct cmd_add_port_tm_leaf_node_result, tm, "tm");
1674 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_nonleaf =
1675         TOKEN_STRING_INITIALIZER(
1676                 struct cmd_add_port_tm_leaf_node_result, leaf, "leaf");
1677 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_node =
1678         TOKEN_STRING_INITIALIZER(
1679                 struct cmd_add_port_tm_leaf_node_result, node, "node");
1680 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_port_id =
1681         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1682                  port_id, UINT16);
1683 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_node_id =
1684         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1685                  node_id, UINT32);
1686 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_parent_node_id =
1687         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1688                  parent_node_id, INT32);
1689 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_priority =
1690         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1691                  priority, UINT32);
1692 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_weight =
1693         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1694                  weight, UINT32);
1695 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_level_id =
1696         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1697                  level_id, UINT32);
1698 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_shaper_profile_id =
1699         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1700                  shaper_profile_id, INT32);
1701 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_cman_mode =
1702         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1703                  cman_mode, UINT32);
1704 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_wred_profile_id =
1705         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1706                  wred_profile_id, UINT32);
1707 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_stats_mask =
1708         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1709                  stats_mask, UINT64);
1710 cmdline_parse_token_string_t
1711         cmd_add_port_tm_leaf_node_multi_shared_shaper_id =
1712         TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1713                  multi_shared_shaper_id, TOKEN_STRING_MULTI);
1714
1715 static void cmd_add_port_tm_leaf_node_parsed(void *parsed_result,
1716         __attribute__((unused)) struct cmdline *cl,
1717         __attribute__((unused)) void *data)
1718 {
1719         struct cmd_add_port_tm_leaf_node_result *res = parsed_result;
1720         struct rte_tm_error error;
1721         struct rte_tm_node_params np;
1722         uint32_t *shared_shaper_id;
1723         uint32_t parent_node_id, n_shared_shapers = 0;
1724         portid_t port_id = res->port_id;
1725         char *s_str = res->multi_shared_shaper_id;
1726         int ret;
1727
1728         if (port_id_is_invalid(port_id, ENABLED_WARN))
1729                 return;
1730
1731         memset(&np, 0, sizeof(struct rte_tm_node_params));
1732
1733         /* Node parameters */
1734         if (res->parent_node_id < 0)
1735                 parent_node_id = UINT32_MAX;
1736         else
1737                 parent_node_id = res->parent_node_id;
1738
1739         shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS *
1740                 sizeof(uint32_t));
1741         if (shared_shaper_id == NULL) {
1742                 printf(" Memory not allocated for shared shapers (error)\n");
1743                 return;
1744         }
1745
1746         /* Parse multi shared shaper id string */
1747         ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id);
1748         if (ret) {
1749                 printf(" Shared shapers params string parse error\n");
1750                 free(shared_shaper_id);
1751                 return;
1752         }
1753
1754         if (res->shaper_profile_id < 0)
1755                 np.shaper_profile_id = UINT32_MAX;
1756         else
1757                 np.shaper_profile_id = res->shaper_profile_id;
1758
1759         np.n_shared_shapers = n_shared_shapers;
1760
1761         if (np.n_shared_shapers)
1762                 np.shared_shaper_id = &shared_shaper_id[0];
1763         else
1764                 np.shared_shaper_id = NULL;
1765
1766         np.leaf.cman = res->cman_mode;
1767         np.leaf.wred.wred_profile_id = res->wred_profile_id;
1768         np.stats_mask = res->stats_mask;
1769
1770         ret = rte_tm_node_add(port_id, res->node_id, parent_node_id,
1771                                 res->priority, res->weight, res->level_id,
1772                                 &np, &error);
1773         if (ret != 0) {
1774                 print_err_msg(&error);
1775                 free(shared_shaper_id);
1776                 return;
1777         }
1778 }
1779
1780 cmdline_parse_inst_t cmd_add_port_tm_leaf_node = {
1781         .f = cmd_add_port_tm_leaf_node_parsed,
1782         .data = NULL,
1783         .help_str = "Add port tm leaf node",
1784         .tokens = {
1785                 (void *)&cmd_add_port_tm_leaf_node_add,
1786                 (void *)&cmd_add_port_tm_leaf_node_port,
1787                 (void *)&cmd_add_port_tm_leaf_node_tm,
1788                 (void *)&cmd_add_port_tm_leaf_node_nonleaf,
1789                 (void *)&cmd_add_port_tm_leaf_node_node,
1790                 (void *)&cmd_add_port_tm_leaf_node_port_id,
1791                 (void *)&cmd_add_port_tm_leaf_node_node_id,
1792                 (void *)&cmd_add_port_tm_leaf_node_parent_node_id,
1793                 (void *)&cmd_add_port_tm_leaf_node_priority,
1794                 (void *)&cmd_add_port_tm_leaf_node_weight,
1795                 (void *)&cmd_add_port_tm_leaf_node_level_id,
1796                 (void *)&cmd_add_port_tm_leaf_node_shaper_profile_id,
1797                 (void *)&cmd_add_port_tm_leaf_node_cman_mode,
1798                 (void *)&cmd_add_port_tm_leaf_node_wred_profile_id,
1799                 (void *)&cmd_add_port_tm_leaf_node_stats_mask,
1800                 (void *)&cmd_add_port_tm_leaf_node_multi_shared_shaper_id,
1801                 NULL,
1802         },
1803 };
1804
1805 /* *** Delete Port TM Node *** */
1806 struct cmd_del_port_tm_node_result {
1807         cmdline_fixed_string_t del;
1808         cmdline_fixed_string_t port;
1809         cmdline_fixed_string_t tm;
1810         cmdline_fixed_string_t node;
1811         uint16_t port_id;
1812         uint32_t node_id;
1813 };
1814
1815 cmdline_parse_token_string_t cmd_del_port_tm_node_del =
1816         TOKEN_STRING_INITIALIZER(
1817                 struct cmd_del_port_tm_node_result, del, "del");
1818 cmdline_parse_token_string_t cmd_del_port_tm_node_port =
1819         TOKEN_STRING_INITIALIZER(
1820                 struct cmd_del_port_tm_node_result, port, "port");
1821 cmdline_parse_token_string_t cmd_del_port_tm_node_tm =
1822         TOKEN_STRING_INITIALIZER(
1823                 struct cmd_del_port_tm_node_result, tm, "tm");
1824 cmdline_parse_token_string_t cmd_del_port_tm_node_node =
1825         TOKEN_STRING_INITIALIZER(
1826                 struct cmd_del_port_tm_node_result, node, "node");
1827 cmdline_parse_token_num_t cmd_del_port_tm_node_port_id =
1828         TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result,
1829                  port_id, UINT16);
1830 cmdline_parse_token_num_t cmd_del_port_tm_node_node_id =
1831         TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result,
1832                 node_id, UINT32);
1833
1834 static void cmd_del_port_tm_node_parsed(void *parsed_result,
1835         __attribute__((unused)) struct cmdline *cl,
1836         __attribute__((unused)) void *data)
1837 {
1838         struct cmd_del_port_tm_node_result *res = parsed_result;
1839         struct rte_tm_error error;
1840         uint32_t node_id = res->node_id;
1841         portid_t port_id = res->port_id;
1842         int ret;
1843
1844         if (port_id_is_invalid(port_id, ENABLED_WARN))
1845                 return;
1846
1847         /* Port status */
1848         if (port_is_started(port_id)) {
1849                 printf(" Port %u not stopped (error)\n", port_id);
1850                 return;
1851         }
1852
1853         ret = rte_tm_node_delete(port_id, node_id, &error);
1854         if (ret != 0) {
1855                 print_err_msg(&error);
1856                 return;
1857         }
1858 }
1859
1860 cmdline_parse_inst_t cmd_del_port_tm_node = {
1861         .f = cmd_del_port_tm_node_parsed,
1862         .data = NULL,
1863         .help_str = "Delete port tm node",
1864         .tokens = {
1865                 (void *)&cmd_del_port_tm_node_del,
1866                 (void *)&cmd_del_port_tm_node_port,
1867                 (void *)&cmd_del_port_tm_node_tm,
1868                 (void *)&cmd_del_port_tm_node_node,
1869                 (void *)&cmd_del_port_tm_node_port_id,
1870                 (void *)&cmd_del_port_tm_node_node_id,
1871                 NULL,
1872         },
1873 };
1874
1875 /* *** Update Port TM Node Parent *** */
1876 struct cmd_set_port_tm_node_parent_result {
1877         cmdline_fixed_string_t set;
1878         cmdline_fixed_string_t port;
1879         cmdline_fixed_string_t tm;
1880         cmdline_fixed_string_t node;
1881         cmdline_fixed_string_t parent;
1882         uint16_t port_id;
1883         uint32_t node_id;
1884         uint32_t parent_id;
1885         uint32_t priority;
1886         uint32_t weight;
1887 };
1888
1889 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_set =
1890         TOKEN_STRING_INITIALIZER(
1891                 struct cmd_set_port_tm_node_parent_result, set, "set");
1892 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_port =
1893         TOKEN_STRING_INITIALIZER(
1894                 struct cmd_set_port_tm_node_parent_result, port, "port");
1895 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_tm =
1896         TOKEN_STRING_INITIALIZER(
1897                 struct cmd_set_port_tm_node_parent_result, tm, "tm");
1898 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_node =
1899         TOKEN_STRING_INITIALIZER(
1900                 struct cmd_set_port_tm_node_parent_result, node, "node");
1901 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_parent =
1902         TOKEN_STRING_INITIALIZER(
1903                 struct cmd_set_port_tm_node_parent_result, parent, "parent");
1904 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_port_id =
1905         TOKEN_NUM_INITIALIZER(
1906                 struct cmd_set_port_tm_node_parent_result, port_id, UINT16);
1907 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_node_id =
1908         TOKEN_NUM_INITIALIZER(
1909                 struct cmd_set_port_tm_node_parent_result, node_id, UINT32);
1910 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_parent_id =
1911         TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
1912                 parent_id, UINT32);
1913 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_priority =
1914         TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
1915                 priority, UINT32);
1916 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_weight =
1917         TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
1918                 weight, UINT32);
1919
1920 static void cmd_set_port_tm_node_parent_parsed(void *parsed_result,
1921         __attribute__((unused)) struct cmdline *cl,
1922         __attribute__((unused)) void *data)
1923 {
1924         struct cmd_set_port_tm_node_parent_result *res = parsed_result;
1925         struct rte_tm_error error;
1926         uint32_t node_id = res->node_id;
1927         uint32_t parent_id = res->parent_id;
1928         uint32_t priority = res->priority;
1929         uint32_t weight = res->weight;
1930         portid_t port_id = res->port_id;
1931         int ret;
1932
1933         if (port_id_is_invalid(port_id, ENABLED_WARN))
1934                 return;
1935
1936         /* Port status */
1937         if (!port_is_started(port_id)) {
1938                 printf(" Port %u not started (error)\n", port_id);
1939                 return;
1940         }
1941
1942         ret = rte_tm_node_parent_update(port_id, node_id,
1943                 parent_id, priority, weight, &error);
1944         if (ret != 0) {
1945                 print_err_msg(&error);
1946                 return;
1947         }
1948 }
1949
1950 cmdline_parse_inst_t cmd_set_port_tm_node_parent = {
1951         .f = cmd_set_port_tm_node_parent_parsed,
1952         .data = NULL,
1953         .help_str = "Set port tm node parent",
1954         .tokens = {
1955                 (void *)&cmd_set_port_tm_node_parent_set,
1956                 (void *)&cmd_set_port_tm_node_parent_port,
1957                 (void *)&cmd_set_port_tm_node_parent_tm,
1958                 (void *)&cmd_set_port_tm_node_parent_node,
1959                 (void *)&cmd_set_port_tm_node_parent_parent,
1960                 (void *)&cmd_set_port_tm_node_parent_port_id,
1961                 (void *)&cmd_set_port_tm_node_parent_node_id,
1962                 (void *)&cmd_set_port_tm_node_parent_parent_id,
1963                 (void *)&cmd_set_port_tm_node_parent_priority,
1964                 (void *)&cmd_set_port_tm_node_parent_weight,
1965                 NULL,
1966         },
1967 };
1968
1969 /* *** Suspend Port TM Node *** */
1970 struct cmd_suspend_port_tm_node_result {
1971         cmdline_fixed_string_t suspend;
1972         cmdline_fixed_string_t port;
1973         cmdline_fixed_string_t tm;
1974         cmdline_fixed_string_t node;
1975         uint16_t port_id;
1976         uint32_t node_id;
1977 };
1978
1979 cmdline_parse_token_string_t cmd_suspend_port_tm_node_suspend =
1980         TOKEN_STRING_INITIALIZER(
1981                 struct cmd_suspend_port_tm_node_result, suspend, "suspend");
1982 cmdline_parse_token_string_t cmd_suspend_port_tm_node_port =
1983         TOKEN_STRING_INITIALIZER(
1984                 struct cmd_suspend_port_tm_node_result, port, "port");
1985 cmdline_parse_token_string_t cmd_suspend_port_tm_node_tm =
1986         TOKEN_STRING_INITIALIZER(
1987                 struct cmd_suspend_port_tm_node_result, tm, "tm");
1988 cmdline_parse_token_string_t cmd_suspend_port_tm_node_node =
1989         TOKEN_STRING_INITIALIZER(
1990                 struct cmd_suspend_port_tm_node_result, node, "node");
1991 cmdline_parse_token_num_t cmd_suspend_port_tm_node_port_id =
1992         TOKEN_NUM_INITIALIZER(
1993                 struct cmd_suspend_port_tm_node_result, port_id, UINT16);
1994 cmdline_parse_token_num_t cmd_suspend_port_tm_node_node_id =
1995         TOKEN_NUM_INITIALIZER(
1996                 struct cmd_suspend_port_tm_node_result, node_id, UINT32);
1997
1998 static void cmd_suspend_port_tm_node_parsed(void *parsed_result,
1999         __attribute__((unused)) struct cmdline *cl,
2000         __attribute__((unused)) void *data)
2001 {
2002         struct cmd_suspend_port_tm_node_result *res = parsed_result;
2003         struct rte_tm_error error;
2004         uint32_t node_id = res->node_id;
2005         portid_t port_id = res->port_id;
2006         int ret;
2007
2008         if (port_id_is_invalid(port_id, ENABLED_WARN))
2009                 return;
2010
2011         ret = rte_tm_node_suspend(port_id, node_id, &error);
2012         if (ret != 0) {
2013                 print_err_msg(&error);
2014                 return;
2015         }
2016 }
2017
2018 cmdline_parse_inst_t cmd_suspend_port_tm_node = {
2019         .f = cmd_suspend_port_tm_node_parsed,
2020         .data = NULL,
2021         .help_str = "Suspend port tm node",
2022         .tokens = {
2023                 (void *)&cmd_suspend_port_tm_node_suspend,
2024                 (void *)&cmd_suspend_port_tm_node_port,
2025                 (void *)&cmd_suspend_port_tm_node_tm,
2026                 (void *)&cmd_suspend_port_tm_node_node,
2027                 (void *)&cmd_suspend_port_tm_node_port_id,
2028                 (void *)&cmd_suspend_port_tm_node_node_id,
2029                 NULL,
2030         },
2031 };
2032
2033 /* *** Resume Port TM Node *** */
2034 struct cmd_resume_port_tm_node_result {
2035         cmdline_fixed_string_t resume;
2036         cmdline_fixed_string_t port;
2037         cmdline_fixed_string_t tm;
2038         cmdline_fixed_string_t node;
2039         uint16_t port_id;
2040         uint32_t node_id;
2041 };
2042
2043 cmdline_parse_token_string_t cmd_resume_port_tm_node_resume =
2044         TOKEN_STRING_INITIALIZER(
2045                 struct cmd_resume_port_tm_node_result, resume, "resume");
2046 cmdline_parse_token_string_t cmd_resume_port_tm_node_port =
2047         TOKEN_STRING_INITIALIZER(
2048                 struct cmd_resume_port_tm_node_result, port, "port");
2049 cmdline_parse_token_string_t cmd_resume_port_tm_node_tm =
2050         TOKEN_STRING_INITIALIZER(
2051                 struct cmd_resume_port_tm_node_result, tm, "tm");
2052 cmdline_parse_token_string_t cmd_resume_port_tm_node_node =
2053         TOKEN_STRING_INITIALIZER(
2054                 struct cmd_resume_port_tm_node_result, node, "node");
2055 cmdline_parse_token_num_t cmd_resume_port_tm_node_port_id =
2056         TOKEN_NUM_INITIALIZER(
2057                 struct cmd_resume_port_tm_node_result, port_id, UINT16);
2058 cmdline_parse_token_num_t cmd_resume_port_tm_node_node_id =
2059         TOKEN_NUM_INITIALIZER(
2060                 struct cmd_resume_port_tm_node_result, node_id, UINT32);
2061
2062 static void cmd_resume_port_tm_node_parsed(void *parsed_result,
2063         __attribute__((unused)) struct cmdline *cl,
2064         __attribute__((unused)) void *data)
2065 {
2066         struct cmd_resume_port_tm_node_result *res = parsed_result;
2067         struct rte_tm_error error;
2068         uint32_t node_id = res->node_id;
2069         portid_t port_id = res->port_id;
2070         int ret;
2071
2072         if (port_id_is_invalid(port_id, ENABLED_WARN))
2073                 return;
2074
2075         ret = rte_tm_node_resume(port_id, node_id, &error);
2076         if (ret != 0) {
2077                 print_err_msg(&error);
2078                 return;
2079         }
2080 }
2081
2082 cmdline_parse_inst_t cmd_resume_port_tm_node = {
2083         .f = cmd_resume_port_tm_node_parsed,
2084         .data = NULL,
2085         .help_str = "Resume port tm node",
2086         .tokens = {
2087                 (void *)&cmd_resume_port_tm_node_resume,
2088                 (void *)&cmd_resume_port_tm_node_port,
2089                 (void *)&cmd_resume_port_tm_node_tm,
2090                 (void *)&cmd_resume_port_tm_node_node,
2091                 (void *)&cmd_resume_port_tm_node_port_id,
2092                 (void *)&cmd_resume_port_tm_node_node_id,
2093                 NULL,
2094         },
2095 };
2096
2097 /* *** Port TM Hierarchy Commit *** */
2098 struct cmd_port_tm_hierarchy_commit_result {
2099         cmdline_fixed_string_t port;
2100         cmdline_fixed_string_t tm;
2101         cmdline_fixed_string_t hierarchy;
2102         cmdline_fixed_string_t commit;
2103         uint16_t port_id;
2104         cmdline_fixed_string_t clean_on_fail;
2105 };
2106
2107 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_port =
2108         TOKEN_STRING_INITIALIZER(
2109                 struct cmd_port_tm_hierarchy_commit_result, port, "port");
2110 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_tm =
2111         TOKEN_STRING_INITIALIZER(
2112                 struct cmd_port_tm_hierarchy_commit_result, tm, "tm");
2113 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_hierarchy =
2114         TOKEN_STRING_INITIALIZER(
2115                 struct cmd_port_tm_hierarchy_commit_result,
2116                         hierarchy, "hierarchy");
2117 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_commit =
2118         TOKEN_STRING_INITIALIZER(
2119                 struct cmd_port_tm_hierarchy_commit_result, commit, "commit");
2120 cmdline_parse_token_num_t cmd_port_tm_hierarchy_commit_port_id =
2121         TOKEN_NUM_INITIALIZER(
2122                 struct cmd_port_tm_hierarchy_commit_result,
2123                         port_id, UINT16);
2124 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_clean_on_fail =
2125         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_hierarchy_commit_result,
2126                  clean_on_fail, "yes#no");
2127
2128 static void cmd_port_tm_hierarchy_commit_parsed(void *parsed_result,
2129         __attribute__((unused)) struct cmdline *cl,
2130         __attribute__((unused)) void *data)
2131 {
2132         struct cmd_port_tm_hierarchy_commit_result *res = parsed_result;
2133         struct rte_tm_error error;
2134         uint32_t clean_on_fail;
2135         portid_t port_id = res->port_id;
2136         int ret;
2137
2138         if (port_id_is_invalid(port_id, ENABLED_WARN))
2139                 return;
2140
2141         if (strcmp(res->clean_on_fail, "yes") == 0)
2142                 clean_on_fail = 1;
2143         else
2144                 clean_on_fail = 0;
2145
2146         ret = rte_tm_hierarchy_commit(port_id, clean_on_fail, &error);
2147         if (ret != 0) {
2148                 print_err_msg(&error);
2149                 return;
2150         }
2151 }
2152
2153 cmdline_parse_inst_t cmd_port_tm_hierarchy_commit = {
2154         .f = cmd_port_tm_hierarchy_commit_parsed,
2155         .data = NULL,
2156         .help_str = "Set port tm node shaper profile",
2157         .tokens = {
2158                 (void *)&cmd_port_tm_hierarchy_commit_port,
2159                 (void *)&cmd_port_tm_hierarchy_commit_tm,
2160                 (void *)&cmd_port_tm_hierarchy_commit_hierarchy,
2161                 (void *)&cmd_port_tm_hierarchy_commit_commit,
2162                 (void *)&cmd_port_tm_hierarchy_commit_port_id,
2163                 (void *)&cmd_port_tm_hierarchy_commit_clean_on_fail,
2164                 NULL,
2165         },
2166 };