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