New upstream version 17.11.4
[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 tb_rate;
799         uint64_t tb_size;
800         uint32_t pktlen_adjust;
801 };
802
803 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_add =
804         TOKEN_STRING_INITIALIZER(
805                 struct cmd_add_port_tm_node_shaper_profile_result, add, "add");
806 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_port =
807         TOKEN_STRING_INITIALIZER(
808                 struct cmd_add_port_tm_node_shaper_profile_result,
809                         port, "port");
810 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_tm =
811         TOKEN_STRING_INITIALIZER(
812                 struct cmd_add_port_tm_node_shaper_profile_result,
813                         tm, "tm");
814 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_node =
815         TOKEN_STRING_INITIALIZER(
816                 struct cmd_add_port_tm_node_shaper_profile_result,
817                         node, "node");
818 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_shaper =
819         TOKEN_STRING_INITIALIZER(
820                 struct cmd_add_port_tm_node_shaper_profile_result,
821                         shaper, "shaper");
822 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_profile =
823         TOKEN_STRING_INITIALIZER(
824                 struct cmd_add_port_tm_node_shaper_profile_result,
825                         profile, "profile");
826 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_port_id =
827         TOKEN_NUM_INITIALIZER(
828                 struct cmd_add_port_tm_node_shaper_profile_result,
829                         port_id, UINT16);
830 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_shaper_id =
831         TOKEN_NUM_INITIALIZER(
832                 struct cmd_add_port_tm_node_shaper_profile_result,
833                         shaper_id, UINT32);
834 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_tb_rate =
835         TOKEN_NUM_INITIALIZER(
836                 struct cmd_add_port_tm_node_shaper_profile_result,
837                         tb_rate, UINT64);
838 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_tb_size =
839         TOKEN_NUM_INITIALIZER(
840                 struct cmd_add_port_tm_node_shaper_profile_result,
841                         tb_size, UINT64);
842 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_pktlen_adjust =
843         TOKEN_NUM_INITIALIZER(
844                 struct cmd_add_port_tm_node_shaper_profile_result,
845                         pktlen_adjust, UINT32);
846
847 static void cmd_add_port_tm_node_shaper_profile_parsed(void *parsed_result,
848         __attribute__((unused)) struct cmdline *cl,
849         __attribute__((unused)) void *data)
850 {
851         struct cmd_add_port_tm_node_shaper_profile_result *res = parsed_result;
852         struct rte_tm_shaper_params sp;
853         struct rte_tm_error error;
854         uint32_t shaper_id = res->shaper_id;
855         uint32_t pkt_len_adjust = res->pktlen_adjust;
856         portid_t port_id = res->port_id;
857         int ret;
858
859         if (port_id_is_invalid(port_id, ENABLED_WARN))
860                 return;
861
862         /* Private shaper profile params */
863         memset(&sp, 0, sizeof(struct rte_tm_shaper_params));
864         sp.peak.rate = res->tb_rate;
865         sp.peak.size = res->tb_size;
866         sp.pkt_length_adjust = pkt_len_adjust;
867
868         ret = rte_tm_shaper_profile_add(port_id, shaper_id, &sp, &error);
869         if (ret != 0) {
870                 print_err_msg(&error);
871                 return;
872         }
873 }
874
875 cmdline_parse_inst_t cmd_add_port_tm_node_shaper_profile = {
876         .f = cmd_add_port_tm_node_shaper_profile_parsed,
877         .data = NULL,
878         .help_str = "Add port tm node private shaper profile",
879         .tokens = {
880                 (void *)&cmd_add_port_tm_node_shaper_profile_add,
881                 (void *)&cmd_add_port_tm_node_shaper_profile_port,
882                 (void *)&cmd_add_port_tm_node_shaper_profile_tm,
883                 (void *)&cmd_add_port_tm_node_shaper_profile_node,
884                 (void *)&cmd_add_port_tm_node_shaper_profile_shaper,
885                 (void *)&cmd_add_port_tm_node_shaper_profile_profile,
886                 (void *)&cmd_add_port_tm_node_shaper_profile_port_id,
887                 (void *)&cmd_add_port_tm_node_shaper_profile_shaper_id,
888                 (void *)&cmd_add_port_tm_node_shaper_profile_tb_rate,
889                 (void *)&cmd_add_port_tm_node_shaper_profile_tb_size,
890                 (void *)&cmd_add_port_tm_node_shaper_profile_pktlen_adjust,
891                 NULL,
892         },
893 };
894
895 /* *** Delete Port TM Private Shaper Profile *** */
896 struct cmd_del_port_tm_node_shaper_profile_result {
897         cmdline_fixed_string_t del;
898         cmdline_fixed_string_t port;
899         cmdline_fixed_string_t tm;
900         cmdline_fixed_string_t node;
901         cmdline_fixed_string_t shaper;
902         cmdline_fixed_string_t profile;
903         uint16_t port_id;
904         uint32_t shaper_id;
905 };
906
907 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_del =
908         TOKEN_STRING_INITIALIZER(
909                 struct cmd_del_port_tm_node_shaper_profile_result, del, "del");
910 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_port =
911         TOKEN_STRING_INITIALIZER(
912                 struct cmd_del_port_tm_node_shaper_profile_result,
913                         port, "port");
914 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_tm =
915         TOKEN_STRING_INITIALIZER(
916                 struct cmd_del_port_tm_node_shaper_profile_result, tm, "tm");
917 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_node =
918         TOKEN_STRING_INITIALIZER(
919                 struct cmd_del_port_tm_node_shaper_profile_result,
920                         node, "node");
921 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_shaper =
922         TOKEN_STRING_INITIALIZER(
923                 struct cmd_del_port_tm_node_shaper_profile_result,
924                         shaper, "shaper");
925 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_profile =
926         TOKEN_STRING_INITIALIZER(
927                 struct cmd_del_port_tm_node_shaper_profile_result,
928                         profile, "profile");
929 cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_port_id =
930         TOKEN_NUM_INITIALIZER(
931                 struct cmd_del_port_tm_node_shaper_profile_result,
932                         port_id, UINT16);
933 cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_shaper_id =
934         TOKEN_NUM_INITIALIZER(
935                 struct cmd_del_port_tm_node_shaper_profile_result,
936                         shaper_id, UINT32);
937
938 static void cmd_del_port_tm_node_shaper_profile_parsed(void *parsed_result,
939         __attribute__((unused)) struct cmdline *cl,
940         __attribute__((unused)) void *data)
941 {
942         struct cmd_del_port_tm_node_shaper_profile_result *res = parsed_result;
943         struct rte_tm_error error;
944         uint32_t shaper_id = res->shaper_id;
945         portid_t port_id = res->port_id;
946         int ret;
947
948         if (port_id_is_invalid(port_id, ENABLED_WARN))
949                 return;
950
951         ret = rte_tm_shaper_profile_delete(port_id, shaper_id, &error);
952         if (ret != 0) {
953                 print_err_msg(&error);
954                 return;
955         }
956 }
957
958 cmdline_parse_inst_t cmd_del_port_tm_node_shaper_profile = {
959         .f = cmd_del_port_tm_node_shaper_profile_parsed,
960         .data = NULL,
961         .help_str = "Delete port tm node private shaper profile",
962         .tokens = {
963                 (void *)&cmd_del_port_tm_node_shaper_profile_del,
964                 (void *)&cmd_del_port_tm_node_shaper_profile_port,
965                 (void *)&cmd_del_port_tm_node_shaper_profile_tm,
966                 (void *)&cmd_del_port_tm_node_shaper_profile_node,
967                 (void *)&cmd_del_port_tm_node_shaper_profile_shaper,
968                 (void *)&cmd_del_port_tm_node_shaper_profile_profile,
969                 (void *)&cmd_del_port_tm_node_shaper_profile_port_id,
970                 (void *)&cmd_del_port_tm_node_shaper_profile_shaper_id,
971                 NULL,
972         },
973 };
974
975 /* *** Add/Update Port TM shared Shaper *** */
976 struct cmd_add_port_tm_node_shared_shaper_result {
977         cmdline_fixed_string_t cmd_type;
978         cmdline_fixed_string_t port;
979         cmdline_fixed_string_t tm;
980         cmdline_fixed_string_t node;
981         cmdline_fixed_string_t shared;
982         cmdline_fixed_string_t shaper;
983         uint16_t port_id;
984         uint32_t shared_shaper_id;
985         uint32_t shaper_profile_id;
986 };
987
988 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_cmd_type =
989         TOKEN_STRING_INITIALIZER(
990                 struct cmd_add_port_tm_node_shared_shaper_result,
991                         cmd_type, "add#set");
992 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_port =
993         TOKEN_STRING_INITIALIZER(
994                 struct cmd_add_port_tm_node_shared_shaper_result, port, "port");
995 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_tm =
996         TOKEN_STRING_INITIALIZER(
997                 struct cmd_add_port_tm_node_shared_shaper_result, tm, "tm");
998 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_node =
999         TOKEN_STRING_INITIALIZER(
1000                 struct cmd_add_port_tm_node_shared_shaper_result, node, "node");
1001 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shared =
1002         TOKEN_STRING_INITIALIZER(
1003                 struct cmd_add_port_tm_node_shared_shaper_result,
1004                         shared, "shared");
1005 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shaper =
1006         TOKEN_STRING_INITIALIZER(
1007                 struct cmd_add_port_tm_node_shared_shaper_result,
1008                         shaper, "shaper");
1009 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_port_id =
1010         TOKEN_NUM_INITIALIZER(
1011                 struct cmd_add_port_tm_node_shared_shaper_result,
1012                         port_id, UINT16);
1013 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shared_shaper_id =
1014         TOKEN_NUM_INITIALIZER(
1015                 struct cmd_add_port_tm_node_shared_shaper_result,
1016                         shared_shaper_id, UINT32);
1017 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shaper_profile_id =
1018         TOKEN_NUM_INITIALIZER(
1019                 struct cmd_add_port_tm_node_shared_shaper_result,
1020                         shaper_profile_id, UINT32);
1021
1022 static void cmd_add_port_tm_node_shared_shaper_parsed(void *parsed_result,
1023         __attribute__((unused)) struct cmdline *cl,
1024         __attribute__((unused)) void *data)
1025 {
1026         struct cmd_add_port_tm_node_shared_shaper_result *res = parsed_result;
1027         struct rte_tm_error error;
1028         uint32_t shared_shaper_id = res->shared_shaper_id;
1029         uint32_t shaper_profile_id = res->shaper_profile_id;
1030         portid_t port_id = res->port_id;
1031         int ret;
1032
1033         if (port_id_is_invalid(port_id, ENABLED_WARN))
1034                 return;
1035
1036         /* Command type: add */
1037         if ((strcmp(res->cmd_type, "add") == 0) &&
1038                 (port_is_started(port_id))) {
1039                 printf(" Port %u not stopped (error)\n", port_id);
1040                 return;
1041         }
1042
1043         /* Command type: set (update) */
1044         if ((strcmp(res->cmd_type, "set") == 0) &&
1045                 (!port_is_started(port_id))) {
1046                 printf(" Port %u not started (error)\n", port_id);
1047                 return;
1048         }
1049
1050         ret = rte_tm_shared_shaper_add_update(port_id, shared_shaper_id,
1051                 shaper_profile_id, &error);
1052         if (ret != 0) {
1053                 print_err_msg(&error);
1054                 return;
1055         }
1056 }
1057
1058 cmdline_parse_inst_t cmd_add_port_tm_node_shared_shaper = {
1059         .f = cmd_add_port_tm_node_shared_shaper_parsed,
1060         .data = NULL,
1061         .help_str = "add/update port tm node shared shaper",
1062         .tokens = {
1063                 (void *)&cmd_add_port_tm_node_shared_shaper_cmd_type,
1064                 (void *)&cmd_add_port_tm_node_shared_shaper_port,
1065                 (void *)&cmd_add_port_tm_node_shared_shaper_tm,
1066                 (void *)&cmd_add_port_tm_node_shared_shaper_node,
1067                 (void *)&cmd_add_port_tm_node_shared_shaper_shared,
1068                 (void *)&cmd_add_port_tm_node_shared_shaper_shaper,
1069                 (void *)&cmd_add_port_tm_node_shared_shaper_port_id,
1070                 (void *)&cmd_add_port_tm_node_shared_shaper_shared_shaper_id,
1071                 (void *)&cmd_add_port_tm_node_shared_shaper_shaper_profile_id,
1072                 NULL,
1073         },
1074 };
1075
1076 /* *** Delete Port TM shared Shaper *** */
1077 struct cmd_del_port_tm_node_shared_shaper_result {
1078         cmdline_fixed_string_t del;
1079         cmdline_fixed_string_t port;
1080         cmdline_fixed_string_t tm;
1081         cmdline_fixed_string_t node;
1082         cmdline_fixed_string_t shared;
1083         cmdline_fixed_string_t shaper;
1084         uint16_t port_id;
1085         uint32_t shared_shaper_id;
1086 };
1087
1088 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_del =
1089         TOKEN_STRING_INITIALIZER(
1090                 struct cmd_del_port_tm_node_shared_shaper_result, del, "del");
1091 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_port =
1092         TOKEN_STRING_INITIALIZER(
1093                 struct cmd_del_port_tm_node_shared_shaper_result, port, "port");
1094 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_tm =
1095         TOKEN_STRING_INITIALIZER(
1096                 struct cmd_del_port_tm_node_shared_shaper_result, tm, "tm");
1097 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_node =
1098         TOKEN_STRING_INITIALIZER(
1099                 struct cmd_del_port_tm_node_shared_shaper_result, node, "node");
1100 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shared =
1101         TOKEN_STRING_INITIALIZER(
1102                 struct cmd_del_port_tm_node_shared_shaper_result,
1103                         shared, "shared");
1104 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shaper =
1105         TOKEN_STRING_INITIALIZER(
1106                 struct cmd_del_port_tm_node_shared_shaper_result,
1107                         shaper, "shaper");
1108 cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_port_id =
1109         TOKEN_NUM_INITIALIZER(
1110                 struct cmd_del_port_tm_node_shared_shaper_result,
1111                         port_id, UINT16);
1112 cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_shared_shaper_id =
1113         TOKEN_NUM_INITIALIZER(
1114                 struct cmd_del_port_tm_node_shared_shaper_result,
1115                         shared_shaper_id, UINT32);
1116
1117 static void cmd_del_port_tm_node_shared_shaper_parsed(void *parsed_result,
1118         __attribute__((unused)) struct cmdline *cl,
1119         __attribute__((unused)) void *data)
1120 {
1121         struct cmd_del_port_tm_node_shared_shaper_result *res = parsed_result;
1122         struct rte_tm_error error;
1123         uint32_t shared_shaper_id = res->shared_shaper_id;
1124         portid_t port_id = res->port_id;
1125         int ret;
1126
1127         if (port_id_is_invalid(port_id, ENABLED_WARN))
1128                 return;
1129
1130         ret = rte_tm_shared_shaper_delete(port_id, shared_shaper_id, &error);
1131         if (ret != 0) {
1132                 print_err_msg(&error);
1133                 return;
1134         }
1135 }
1136
1137 cmdline_parse_inst_t cmd_del_port_tm_node_shared_shaper = {
1138         .f = cmd_del_port_tm_node_shared_shaper_parsed,
1139         .data = NULL,
1140         .help_str = "delete port tm node shared shaper",
1141         .tokens = {
1142                 (void *)&cmd_del_port_tm_node_shared_shaper_del,
1143                 (void *)&cmd_del_port_tm_node_shared_shaper_port,
1144                 (void *)&cmd_del_port_tm_node_shared_shaper_tm,
1145                 (void *)&cmd_del_port_tm_node_shared_shaper_node,
1146                 (void *)&cmd_del_port_tm_node_shared_shaper_shared,
1147                 (void *)&cmd_del_port_tm_node_shared_shaper_shaper,
1148                 (void *)&cmd_del_port_tm_node_shared_shaper_port_id,
1149                 (void *)&cmd_del_port_tm_node_shared_shaper_shared_shaper_id,
1150                 NULL,
1151         },
1152 };
1153
1154 /* *** Add Port TM Node WRED Profile *** */
1155 struct cmd_add_port_tm_node_wred_profile_result {
1156         cmdline_fixed_string_t add;
1157         cmdline_fixed_string_t port;
1158         cmdline_fixed_string_t tm;
1159         cmdline_fixed_string_t node;
1160         cmdline_fixed_string_t wred;
1161         cmdline_fixed_string_t profile;
1162         uint16_t port_id;
1163         uint32_t wred_profile_id;
1164         cmdline_fixed_string_t color_g;
1165         uint16_t min_th_g;
1166         uint16_t max_th_g;
1167         uint16_t maxp_inv_g;
1168         uint16_t wq_log2_g;
1169         cmdline_fixed_string_t color_y;
1170         uint16_t min_th_y;
1171         uint16_t max_th_y;
1172         uint16_t maxp_inv_y;
1173         uint16_t wq_log2_y;
1174         cmdline_fixed_string_t color_r;
1175         uint16_t min_th_r;
1176         uint16_t max_th_r;
1177         uint16_t maxp_inv_r;
1178         uint16_t wq_log2_r;
1179 };
1180
1181 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_add =
1182         TOKEN_STRING_INITIALIZER(
1183                 struct cmd_add_port_tm_node_wred_profile_result, add, "add");
1184 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_port =
1185         TOKEN_STRING_INITIALIZER(
1186                 struct cmd_add_port_tm_node_wred_profile_result, port, "port");
1187 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_tm =
1188         TOKEN_STRING_INITIALIZER(
1189                 struct cmd_add_port_tm_node_wred_profile_result, tm, "tm");
1190 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_node =
1191         TOKEN_STRING_INITIALIZER(
1192                 struct cmd_add_port_tm_node_wred_profile_result, node, "node");
1193 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_wred =
1194         TOKEN_STRING_INITIALIZER(
1195                 struct cmd_add_port_tm_node_wred_profile_result, wred, "wred");
1196 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_profile =
1197         TOKEN_STRING_INITIALIZER(
1198                 struct cmd_add_port_tm_node_wred_profile_result,
1199                         profile, "profile");
1200 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_port_id =
1201         TOKEN_NUM_INITIALIZER(
1202                 struct cmd_add_port_tm_node_wred_profile_result,
1203                         port_id, UINT16);
1204 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wred_profile_id =
1205         TOKEN_NUM_INITIALIZER(
1206                 struct cmd_add_port_tm_node_wred_profile_result,
1207                         wred_profile_id, UINT32);
1208 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_g =
1209         TOKEN_STRING_INITIALIZER(
1210                 struct cmd_add_port_tm_node_wred_profile_result,
1211                         color_g, "G#g");
1212 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_g =
1213         TOKEN_NUM_INITIALIZER(
1214                 struct cmd_add_port_tm_node_wred_profile_result,
1215                         min_th_g, UINT16);
1216 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_g =
1217         TOKEN_NUM_INITIALIZER(
1218                 struct cmd_add_port_tm_node_wred_profile_result,
1219                         max_th_g, UINT16);
1220 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_g =
1221         TOKEN_NUM_INITIALIZER(
1222                 struct cmd_add_port_tm_node_wred_profile_result,
1223                         maxp_inv_g, UINT16);
1224 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_g =
1225         TOKEN_NUM_INITIALIZER(
1226                 struct cmd_add_port_tm_node_wred_profile_result,
1227                         wq_log2_g, UINT16);
1228 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_y =
1229         TOKEN_STRING_INITIALIZER(
1230                 struct cmd_add_port_tm_node_wred_profile_result,
1231                         color_y, "Y#y");
1232 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_y =
1233         TOKEN_NUM_INITIALIZER(
1234                 struct cmd_add_port_tm_node_wred_profile_result,
1235                         min_th_y, UINT16);
1236 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_y =
1237         TOKEN_NUM_INITIALIZER(
1238                 struct cmd_add_port_tm_node_wred_profile_result,
1239                         max_th_y, UINT16);
1240 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_y =
1241         TOKEN_NUM_INITIALIZER(
1242                 struct cmd_add_port_tm_node_wred_profile_result,
1243                         maxp_inv_y, UINT16);
1244 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_y =
1245         TOKEN_NUM_INITIALIZER(
1246                 struct cmd_add_port_tm_node_wred_profile_result,
1247                         wq_log2_y, UINT16);
1248 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_r =
1249         TOKEN_STRING_INITIALIZER(
1250                 struct cmd_add_port_tm_node_wred_profile_result,
1251                         color_r, "R#r");
1252 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_r =
1253         TOKEN_NUM_INITIALIZER(
1254                 struct cmd_add_port_tm_node_wred_profile_result,
1255                         min_th_r, UINT16);
1256 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_r =
1257         TOKEN_NUM_INITIALIZER(
1258                 struct cmd_add_port_tm_node_wred_profile_result,
1259                         max_th_r, UINT16);
1260 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_r =
1261         TOKEN_NUM_INITIALIZER(
1262                 struct cmd_add_port_tm_node_wred_profile_result,
1263                         maxp_inv_r, UINT16);
1264 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_r =
1265         TOKEN_NUM_INITIALIZER(
1266                 struct cmd_add_port_tm_node_wred_profile_result,
1267                         wq_log2_r, UINT16);
1268
1269
1270 static void cmd_add_port_tm_node_wred_profile_parsed(void *parsed_result,
1271         __attribute__((unused)) struct cmdline *cl,
1272         __attribute__((unused)) void *data)
1273 {
1274         struct cmd_add_port_tm_node_wred_profile_result *res = parsed_result;
1275         struct rte_tm_wred_params wp;
1276         enum rte_tm_color color;
1277         struct rte_tm_error error;
1278         uint32_t wred_profile_id = res->wred_profile_id;
1279         portid_t port_id = res->port_id;
1280         int ret;
1281
1282         if (port_id_is_invalid(port_id, ENABLED_WARN))
1283                 return;
1284
1285         memset(&wp, 0, sizeof(struct rte_tm_wred_params));
1286
1287         /* WRED Params  (Green Color)*/
1288         color = RTE_TM_GREEN;
1289         wp.red_params[color].min_th = res->min_th_g;
1290         wp.red_params[color].max_th = res->max_th_g;
1291         wp.red_params[color].maxp_inv = res->maxp_inv_g;
1292         wp.red_params[color].wq_log2 = res->wq_log2_g;
1293
1294
1295         /* WRED Params  (Yellow Color)*/
1296         color = RTE_TM_YELLOW;
1297         wp.red_params[color].min_th = res->min_th_y;
1298         wp.red_params[color].max_th = res->max_th_y;
1299         wp.red_params[color].maxp_inv = res->maxp_inv_y;
1300         wp.red_params[color].wq_log2 = res->wq_log2_y;
1301
1302         /* WRED Params  (Red Color)*/
1303         color = RTE_TM_RED;
1304         wp.red_params[color].min_th = res->min_th_r;
1305         wp.red_params[color].max_th = res->max_th_r;
1306         wp.red_params[color].maxp_inv = res->maxp_inv_r;
1307         wp.red_params[color].wq_log2 = res->wq_log2_r;
1308
1309         ret = rte_tm_wred_profile_add(port_id, wred_profile_id, &wp, &error);
1310         if (ret != 0) {
1311                 print_err_msg(&error);
1312                 return;
1313         }
1314 }
1315
1316 cmdline_parse_inst_t cmd_add_port_tm_node_wred_profile = {
1317         .f = cmd_add_port_tm_node_wred_profile_parsed,
1318         .data = NULL,
1319         .help_str = "Add port tm node wred profile",
1320         .tokens = {
1321                 (void *)&cmd_add_port_tm_node_wred_profile_add,
1322                 (void *)&cmd_add_port_tm_node_wred_profile_port,
1323                 (void *)&cmd_add_port_tm_node_wred_profile_tm,
1324                 (void *)&cmd_add_port_tm_node_wred_profile_node,
1325                 (void *)&cmd_add_port_tm_node_wred_profile_wred,
1326                 (void *)&cmd_add_port_tm_node_wred_profile_profile,
1327                 (void *)&cmd_add_port_tm_node_wred_profile_port_id,
1328                 (void *)&cmd_add_port_tm_node_wred_profile_wred_profile_id,
1329                 (void *)&cmd_add_port_tm_node_wred_profile_color_g,
1330                 (void *)&cmd_add_port_tm_node_wred_profile_min_th_g,
1331                 (void *)&cmd_add_port_tm_node_wred_profile_max_th_g,
1332                 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_g,
1333                 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_g,
1334                 (void *)&cmd_add_port_tm_node_wred_profile_color_y,
1335                 (void *)&cmd_add_port_tm_node_wred_profile_min_th_y,
1336                 (void *)&cmd_add_port_tm_node_wred_profile_max_th_y,
1337                 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_y,
1338                 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_y,
1339                 (void *)&cmd_add_port_tm_node_wred_profile_color_r,
1340                 (void *)&cmd_add_port_tm_node_wred_profile_min_th_r,
1341                 (void *)&cmd_add_port_tm_node_wred_profile_max_th_r,
1342                 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_r,
1343                 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_r,
1344                 NULL,
1345         },
1346 };
1347
1348 /* *** Delete Port TM node WRED Profile *** */
1349 struct cmd_del_port_tm_node_wred_profile_result {
1350         cmdline_fixed_string_t del;
1351         cmdline_fixed_string_t port;
1352         cmdline_fixed_string_t tm;
1353         cmdline_fixed_string_t node;
1354         cmdline_fixed_string_t wred;
1355         cmdline_fixed_string_t profile;
1356         uint16_t port_id;
1357         uint32_t wred_profile_id;
1358 };
1359
1360 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_del =
1361         TOKEN_STRING_INITIALIZER(
1362                 struct cmd_del_port_tm_node_wred_profile_result, del, "del");
1363 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_port =
1364         TOKEN_STRING_INITIALIZER(
1365                 struct cmd_del_port_tm_node_wred_profile_result, port, "port");
1366 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_tm =
1367         TOKEN_STRING_INITIALIZER(
1368                 struct cmd_del_port_tm_node_wred_profile_result, tm, "tm");
1369 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_node =
1370         TOKEN_STRING_INITIALIZER(
1371                 struct cmd_del_port_tm_node_wred_profile_result, node, "node");
1372 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_wred =
1373         TOKEN_STRING_INITIALIZER(
1374                 struct cmd_del_port_tm_node_wred_profile_result, wred, "wred");
1375 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_profile =
1376         TOKEN_STRING_INITIALIZER(
1377                 struct cmd_del_port_tm_node_wred_profile_result,
1378                         profile, "profile");
1379 cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_port_id =
1380         TOKEN_NUM_INITIALIZER(
1381                 struct cmd_del_port_tm_node_wred_profile_result,
1382                         port_id, UINT16);
1383 cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_wred_profile_id =
1384         TOKEN_NUM_INITIALIZER(
1385                 struct cmd_del_port_tm_node_wred_profile_result,
1386                         wred_profile_id, UINT32);
1387
1388 static void cmd_del_port_tm_node_wred_profile_parsed(void *parsed_result,
1389         __attribute__((unused)) struct cmdline *cl,
1390         __attribute__((unused)) void *data)
1391 {
1392         struct cmd_del_port_tm_node_wred_profile_result *res = parsed_result;
1393         struct rte_tm_error error;
1394         uint32_t wred_profile_id = res->wred_profile_id;
1395         portid_t port_id = res->port_id;
1396         int ret;
1397
1398         if (port_id_is_invalid(port_id, ENABLED_WARN))
1399                 return;
1400
1401         ret = rte_tm_wred_profile_delete(port_id, wred_profile_id, &error);
1402         if (ret != 0) {
1403                 print_err_msg(&error);
1404                 return;
1405         }
1406 }
1407
1408 cmdline_parse_inst_t cmd_del_port_tm_node_wred_profile = {
1409         .f = cmd_del_port_tm_node_wred_profile_parsed,
1410         .data = NULL,
1411         .help_str = "Delete port tm node wred profile",
1412         .tokens = {
1413                 (void *)&cmd_del_port_tm_node_wred_profile_del,
1414                 (void *)&cmd_del_port_tm_node_wred_profile_port,
1415                 (void *)&cmd_del_port_tm_node_wred_profile_tm,
1416                 (void *)&cmd_del_port_tm_node_wred_profile_node,
1417                 (void *)&cmd_del_port_tm_node_wred_profile_wred,
1418                 (void *)&cmd_del_port_tm_node_wred_profile_profile,
1419                 (void *)&cmd_del_port_tm_node_wred_profile_port_id,
1420                 (void *)&cmd_del_port_tm_node_wred_profile_wred_profile_id,
1421                 NULL,
1422         },
1423 };
1424
1425 /* *** Update Port TM Node Shaper profile *** */
1426 struct cmd_set_port_tm_node_shaper_profile_result {
1427         cmdline_fixed_string_t set;
1428         cmdline_fixed_string_t port;
1429         cmdline_fixed_string_t tm;
1430         cmdline_fixed_string_t node;
1431         cmdline_fixed_string_t shaper;
1432         cmdline_fixed_string_t profile;
1433         uint16_t port_id;
1434         uint32_t node_id;
1435         uint32_t shaper_profile_id;
1436 };
1437
1438 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_set =
1439         TOKEN_STRING_INITIALIZER(
1440                 struct cmd_set_port_tm_node_shaper_profile_result, set, "set");
1441 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_port =
1442         TOKEN_STRING_INITIALIZER(
1443                 struct cmd_set_port_tm_node_shaper_profile_result,
1444                         port, "port");
1445 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_tm =
1446         TOKEN_STRING_INITIALIZER(
1447                 struct cmd_set_port_tm_node_shaper_profile_result, tm, "tm");
1448 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_node =
1449         TOKEN_STRING_INITIALIZER(
1450                 struct cmd_set_port_tm_node_shaper_profile_result,
1451                         node, "node");
1452 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_shaper =
1453         TOKEN_STRING_INITIALIZER(
1454                 struct cmd_set_port_tm_node_shaper_profile_result,
1455                         shaper, "shaper");
1456 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_profile =
1457         TOKEN_STRING_INITIALIZER(
1458                 struct cmd_set_port_tm_node_shaper_profile_result,
1459                         profile, "profile");
1460 cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_port_id =
1461         TOKEN_NUM_INITIALIZER(
1462                 struct cmd_set_port_tm_node_shaper_profile_result,
1463                         port_id, UINT16);
1464 cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_node_id =
1465         TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_shaper_profile_result,
1466                 node_id, UINT32);
1467 cmdline_parse_token_num_t
1468         cmd_set_port_tm_node_shaper_shaper_profile_profile_id =
1469                 TOKEN_NUM_INITIALIZER(
1470                         struct cmd_set_port_tm_node_shaper_profile_result,
1471                         shaper_profile_id, UINT32);
1472
1473 static void cmd_set_port_tm_node_shaper_profile_parsed(void *parsed_result,
1474         __attribute__((unused)) struct cmdline *cl,
1475         __attribute__((unused)) void *data)
1476 {
1477         struct cmd_set_port_tm_node_shaper_profile_result *res = parsed_result;
1478         struct rte_tm_error error;
1479         uint32_t node_id = res->node_id;
1480         uint32_t shaper_profile_id = res->shaper_profile_id;
1481         portid_t port_id = res->port_id;
1482         int ret;
1483
1484         if (port_id_is_invalid(port_id, ENABLED_WARN))
1485                 return;
1486
1487         /* Port status */
1488         if (!port_is_started(port_id)) {
1489                 printf(" Port %u not started (error)\n", port_id);
1490                 return;
1491         }
1492
1493         ret = rte_tm_node_shaper_update(port_id, node_id,
1494                 shaper_profile_id, &error);
1495         if (ret != 0) {
1496                 print_err_msg(&error);
1497                 return;
1498         }
1499 }
1500
1501 cmdline_parse_inst_t cmd_set_port_tm_node_shaper_profile = {
1502         .f = cmd_set_port_tm_node_shaper_profile_parsed,
1503         .data = NULL,
1504         .help_str = "Set port tm node shaper profile",
1505         .tokens = {
1506                 (void *)&cmd_set_port_tm_node_shaper_profile_set,
1507                 (void *)&cmd_set_port_tm_node_shaper_profile_port,
1508                 (void *)&cmd_set_port_tm_node_shaper_profile_tm,
1509                 (void *)&cmd_set_port_tm_node_shaper_profile_node,
1510                 (void *)&cmd_set_port_tm_node_shaper_profile_shaper,
1511                 (void *)&cmd_set_port_tm_node_shaper_profile_profile,
1512                 (void *)&cmd_set_port_tm_node_shaper_profile_port_id,
1513                 (void *)&cmd_set_port_tm_node_shaper_profile_node_id,
1514                 (void *)&cmd_set_port_tm_node_shaper_shaper_profile_profile_id,
1515                 NULL,
1516         },
1517 };
1518
1519 /* *** Add Port TM nonleaf node *** */
1520 struct cmd_add_port_tm_nonleaf_node_result {
1521         cmdline_fixed_string_t add;
1522         cmdline_fixed_string_t port;
1523         cmdline_fixed_string_t tm;
1524         cmdline_fixed_string_t nonleaf;
1525         cmdline_fixed_string_t node;
1526         uint16_t port_id;
1527         uint32_t node_id;
1528         int32_t parent_node_id;
1529         uint32_t priority;
1530         uint32_t weight;
1531         uint32_t level_id;
1532         uint32_t shaper_profile_id;
1533         uint32_t n_sp_priorities;
1534         uint64_t stats_mask;
1535         cmdline_multi_string_t multi_shared_shaper_id;
1536 };
1537
1538 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_add =
1539         TOKEN_STRING_INITIALIZER(
1540                 struct cmd_add_port_tm_nonleaf_node_result, add, "add");
1541 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_port =
1542         TOKEN_STRING_INITIALIZER(
1543                 struct cmd_add_port_tm_nonleaf_node_result, port, "port");
1544 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_tm =
1545         TOKEN_STRING_INITIALIZER(
1546                 struct cmd_add_port_tm_nonleaf_node_result, tm, "tm");
1547 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_nonleaf =
1548         TOKEN_STRING_INITIALIZER(
1549                 struct cmd_add_port_tm_nonleaf_node_result, nonleaf, "nonleaf");
1550 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_node =
1551         TOKEN_STRING_INITIALIZER(
1552                 struct cmd_add_port_tm_nonleaf_node_result, node, "node");
1553 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_port_id =
1554         TOKEN_NUM_INITIALIZER(
1555                 struct cmd_add_port_tm_nonleaf_node_result,
1556                  port_id, UINT16);
1557 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_node_id =
1558         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1559                  node_id, UINT32);
1560 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_parent_node_id =
1561         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1562                  parent_node_id, INT32);
1563 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_priority =
1564         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1565                  priority, UINT32);
1566 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_weight =
1567         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1568                  weight, UINT32);
1569 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_level_id =
1570         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1571                  level_id, UINT32);
1572 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_shaper_profile_id =
1573         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1574                  shaper_profile_id, UINT32);
1575 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_n_sp_priorities =
1576         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1577                  n_sp_priorities, UINT32);
1578 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_stats_mask =
1579         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1580                  stats_mask, UINT64);
1581 cmdline_parse_token_string_t
1582         cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id =
1583         TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1584                  multi_shared_shaper_id, TOKEN_STRING_MULTI);
1585
1586 static void cmd_add_port_tm_nonleaf_node_parsed(void *parsed_result,
1587         __attribute__((unused)) struct cmdline *cl,
1588         __attribute__((unused)) void *data)
1589 {
1590         struct cmd_add_port_tm_nonleaf_node_result *res = parsed_result;
1591         struct rte_tm_error error;
1592         struct rte_tm_node_params np;
1593         uint32_t *shared_shaper_id;
1594         uint32_t parent_node_id, n_shared_shapers = 0;
1595         char *s_str = res->multi_shared_shaper_id;
1596         portid_t port_id = res->port_id;
1597         int ret;
1598
1599         if (port_id_is_invalid(port_id, ENABLED_WARN))
1600                 return;
1601
1602         memset(&np, 0, sizeof(struct rte_tm_node_params));
1603
1604         /* Node parameters */
1605         if (res->parent_node_id < 0)
1606                 parent_node_id = UINT32_MAX;
1607         else
1608                 parent_node_id = res->parent_node_id;
1609
1610         shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS *
1611                 sizeof(uint32_t));
1612         if (shared_shaper_id == NULL) {
1613                 printf(" Memory not allocated for shared shapers (error)\n");
1614                 return;
1615         }
1616
1617         /* Parse multi shared shaper id string */
1618         ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id);
1619         if (ret) {
1620                 printf(" Shared shapers params string parse error\n");
1621                 free(shared_shaper_id);
1622                 return;
1623         }
1624
1625         np.shaper_profile_id = res->shaper_profile_id;
1626         np.n_shared_shapers = n_shared_shapers;
1627         if (np.n_shared_shapers) {
1628                 np.shared_shaper_id = &shared_shaper_id[0];
1629         } else {
1630                 free(shared_shaper_id);
1631                 shared_shaper_id = NULL;
1632         }
1633
1634         np.nonleaf.n_sp_priorities = res->n_sp_priorities;
1635         np.stats_mask = res->stats_mask;
1636         np.nonleaf.wfq_weight_mode = NULL;
1637
1638         ret = rte_tm_node_add(port_id, res->node_id, parent_node_id,
1639                                 res->priority, res->weight, res->level_id,
1640                                 &np, &error);
1641         if (ret != 0) {
1642                 print_err_msg(&error);
1643                 free(shared_shaper_id);
1644                 return;
1645         }
1646 }
1647
1648 cmdline_parse_inst_t cmd_add_port_tm_nonleaf_node = {
1649         .f = cmd_add_port_tm_nonleaf_node_parsed,
1650         .data = NULL,
1651         .help_str = "Add port tm nonleaf node",
1652         .tokens = {
1653                 (void *)&cmd_add_port_tm_nonleaf_node_add,
1654                 (void *)&cmd_add_port_tm_nonleaf_node_port,
1655                 (void *)&cmd_add_port_tm_nonleaf_node_tm,
1656                 (void *)&cmd_add_port_tm_nonleaf_node_nonleaf,
1657                 (void *)&cmd_add_port_tm_nonleaf_node_node,
1658                 (void *)&cmd_add_port_tm_nonleaf_node_port_id,
1659                 (void *)&cmd_add_port_tm_nonleaf_node_node_id,
1660                 (void *)&cmd_add_port_tm_nonleaf_node_parent_node_id,
1661                 (void *)&cmd_add_port_tm_nonleaf_node_priority,
1662                 (void *)&cmd_add_port_tm_nonleaf_node_weight,
1663                 (void *)&cmd_add_port_tm_nonleaf_node_level_id,
1664                 (void *)&cmd_add_port_tm_nonleaf_node_shaper_profile_id,
1665                 (void *)&cmd_add_port_tm_nonleaf_node_n_sp_priorities,
1666                 (void *)&cmd_add_port_tm_nonleaf_node_stats_mask,
1667                 (void *)&cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id,
1668                 NULL,
1669         },
1670 };
1671
1672 /* *** Add Port TM leaf node *** */
1673 struct cmd_add_port_tm_leaf_node_result {
1674         cmdline_fixed_string_t add;
1675         cmdline_fixed_string_t port;
1676         cmdline_fixed_string_t tm;
1677         cmdline_fixed_string_t leaf;
1678         cmdline_fixed_string_t node;
1679         uint16_t port_id;
1680         uint32_t node_id;
1681         int32_t parent_node_id;
1682         uint32_t priority;
1683         uint32_t weight;
1684         uint32_t level_id;
1685         uint32_t shaper_profile_id;
1686         uint32_t cman_mode;
1687         uint32_t wred_profile_id;
1688         uint64_t stats_mask;
1689         cmdline_multi_string_t multi_shared_shaper_id;
1690 };
1691
1692 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_add =
1693         TOKEN_STRING_INITIALIZER(
1694                 struct cmd_add_port_tm_leaf_node_result, add, "add");
1695 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_port =
1696         TOKEN_STRING_INITIALIZER(
1697                 struct cmd_add_port_tm_leaf_node_result, port, "port");
1698 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_tm =
1699         TOKEN_STRING_INITIALIZER(
1700                 struct cmd_add_port_tm_leaf_node_result, tm, "tm");
1701 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_nonleaf =
1702         TOKEN_STRING_INITIALIZER(
1703                 struct cmd_add_port_tm_leaf_node_result, leaf, "leaf");
1704 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_node =
1705         TOKEN_STRING_INITIALIZER(
1706                 struct cmd_add_port_tm_leaf_node_result, node, "node");
1707 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_port_id =
1708         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1709                  port_id, UINT16);
1710 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_node_id =
1711         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1712                  node_id, UINT32);
1713 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_parent_node_id =
1714         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1715                  parent_node_id, INT32);
1716 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_priority =
1717         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1718                  priority, UINT32);
1719 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_weight =
1720         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1721                  weight, UINT32);
1722 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_level_id =
1723         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1724                  level_id, UINT32);
1725 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_shaper_profile_id =
1726         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1727                  shaper_profile_id, UINT32);
1728 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_cman_mode =
1729         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1730                  cman_mode, UINT32);
1731 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_wred_profile_id =
1732         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1733                  wred_profile_id, UINT32);
1734 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_stats_mask =
1735         TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1736                  stats_mask, UINT64);
1737 cmdline_parse_token_string_t
1738         cmd_add_port_tm_leaf_node_multi_shared_shaper_id =
1739         TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1740                  multi_shared_shaper_id, TOKEN_STRING_MULTI);
1741
1742 static void cmd_add_port_tm_leaf_node_parsed(void *parsed_result,
1743         __attribute__((unused)) struct cmdline *cl,
1744         __attribute__((unused)) void *data)
1745 {
1746         struct cmd_add_port_tm_leaf_node_result *res = parsed_result;
1747         struct rte_tm_error error;
1748         struct rte_tm_node_params np;
1749         uint32_t *shared_shaper_id;
1750         uint32_t parent_node_id, n_shared_shapers = 0;
1751         portid_t port_id = res->port_id;
1752         char *s_str = res->multi_shared_shaper_id;
1753         int ret;
1754
1755         if (port_id_is_invalid(port_id, ENABLED_WARN))
1756                 return;
1757
1758         memset(&np, 0, sizeof(struct rte_tm_node_params));
1759
1760         /* Node parameters */
1761         if (res->parent_node_id < 0)
1762                 parent_node_id = UINT32_MAX;
1763         else
1764                 parent_node_id = res->parent_node_id;
1765
1766         shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS *
1767                 sizeof(uint32_t));
1768         if (shared_shaper_id == NULL) {
1769                 printf(" Memory not allocated for shared shapers (error)\n");
1770                 return;
1771         }
1772
1773         /* Parse multi shared shaper id string */
1774         ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id);
1775         if (ret) {
1776                 printf(" Shared shapers params string parse error\n");
1777                 free(shared_shaper_id);
1778                 return;
1779         }
1780
1781         np.shaper_profile_id = res->shaper_profile_id;
1782         np.n_shared_shapers = n_shared_shapers;
1783
1784         if (np.n_shared_shapers) {
1785                 np.shared_shaper_id = &shared_shaper_id[0];
1786         } else {
1787                 free(shared_shaper_id);
1788                 shared_shaper_id = NULL;
1789         }
1790
1791         np.leaf.cman = res->cman_mode;
1792         np.leaf.wred.wred_profile_id = res->wred_profile_id;
1793         np.stats_mask = res->stats_mask;
1794
1795         ret = rte_tm_node_add(port_id, res->node_id, parent_node_id,
1796                                 res->priority, res->weight, res->level_id,
1797                                 &np, &error);
1798         if (ret != 0) {
1799                 print_err_msg(&error);
1800                 free(shared_shaper_id);
1801                 return;
1802         }
1803 }
1804
1805 cmdline_parse_inst_t cmd_add_port_tm_leaf_node = {
1806         .f = cmd_add_port_tm_leaf_node_parsed,
1807         .data = NULL,
1808         .help_str = "Add port tm leaf node",
1809         .tokens = {
1810                 (void *)&cmd_add_port_tm_leaf_node_add,
1811                 (void *)&cmd_add_port_tm_leaf_node_port,
1812                 (void *)&cmd_add_port_tm_leaf_node_tm,
1813                 (void *)&cmd_add_port_tm_leaf_node_nonleaf,
1814                 (void *)&cmd_add_port_tm_leaf_node_node,
1815                 (void *)&cmd_add_port_tm_leaf_node_port_id,
1816                 (void *)&cmd_add_port_tm_leaf_node_node_id,
1817                 (void *)&cmd_add_port_tm_leaf_node_parent_node_id,
1818                 (void *)&cmd_add_port_tm_leaf_node_priority,
1819                 (void *)&cmd_add_port_tm_leaf_node_weight,
1820                 (void *)&cmd_add_port_tm_leaf_node_level_id,
1821                 (void *)&cmd_add_port_tm_leaf_node_shaper_profile_id,
1822                 (void *)&cmd_add_port_tm_leaf_node_cman_mode,
1823                 (void *)&cmd_add_port_tm_leaf_node_wred_profile_id,
1824                 (void *)&cmd_add_port_tm_leaf_node_stats_mask,
1825                 (void *)&cmd_add_port_tm_leaf_node_multi_shared_shaper_id,
1826                 NULL,
1827         },
1828 };
1829
1830 /* *** Delete Port TM Node *** */
1831 struct cmd_del_port_tm_node_result {
1832         cmdline_fixed_string_t del;
1833         cmdline_fixed_string_t port;
1834         cmdline_fixed_string_t tm;
1835         cmdline_fixed_string_t node;
1836         uint16_t port_id;
1837         uint32_t node_id;
1838 };
1839
1840 cmdline_parse_token_string_t cmd_del_port_tm_node_del =
1841         TOKEN_STRING_INITIALIZER(
1842                 struct cmd_del_port_tm_node_result, del, "del");
1843 cmdline_parse_token_string_t cmd_del_port_tm_node_port =
1844         TOKEN_STRING_INITIALIZER(
1845                 struct cmd_del_port_tm_node_result, port, "port");
1846 cmdline_parse_token_string_t cmd_del_port_tm_node_tm =
1847         TOKEN_STRING_INITIALIZER(
1848                 struct cmd_del_port_tm_node_result, tm, "tm");
1849 cmdline_parse_token_string_t cmd_del_port_tm_node_node =
1850         TOKEN_STRING_INITIALIZER(
1851                 struct cmd_del_port_tm_node_result, node, "node");
1852 cmdline_parse_token_num_t cmd_del_port_tm_node_port_id =
1853         TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result,
1854                  port_id, UINT16);
1855 cmdline_parse_token_num_t cmd_del_port_tm_node_node_id =
1856         TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result,
1857                 node_id, UINT32);
1858
1859 static void cmd_del_port_tm_node_parsed(void *parsed_result,
1860         __attribute__((unused)) struct cmdline *cl,
1861         __attribute__((unused)) void *data)
1862 {
1863         struct cmd_del_port_tm_node_result *res = parsed_result;
1864         struct rte_tm_error error;
1865         uint32_t node_id = res->node_id;
1866         portid_t port_id = res->port_id;
1867         int ret;
1868
1869         if (port_id_is_invalid(port_id, ENABLED_WARN))
1870                 return;
1871
1872         /* Port status */
1873         if (port_is_started(port_id)) {
1874                 printf(" Port %u not stopped (error)\n", port_id);
1875                 return;
1876         }
1877
1878         ret = rte_tm_node_delete(port_id, node_id, &error);
1879         if (ret != 0) {
1880                 print_err_msg(&error);
1881                 return;
1882         }
1883 }
1884
1885 cmdline_parse_inst_t cmd_del_port_tm_node = {
1886         .f = cmd_del_port_tm_node_parsed,
1887         .data = NULL,
1888         .help_str = "Delete port tm node",
1889         .tokens = {
1890                 (void *)&cmd_del_port_tm_node_del,
1891                 (void *)&cmd_del_port_tm_node_port,
1892                 (void *)&cmd_del_port_tm_node_tm,
1893                 (void *)&cmd_del_port_tm_node_node,
1894                 (void *)&cmd_del_port_tm_node_port_id,
1895                 (void *)&cmd_del_port_tm_node_node_id,
1896                 NULL,
1897         },
1898 };
1899
1900 /* *** Update Port TM Node Parent *** */
1901 struct cmd_set_port_tm_node_parent_result {
1902         cmdline_fixed_string_t set;
1903         cmdline_fixed_string_t port;
1904         cmdline_fixed_string_t tm;
1905         cmdline_fixed_string_t node;
1906         cmdline_fixed_string_t parent;
1907         uint16_t port_id;
1908         uint32_t node_id;
1909         uint32_t parent_id;
1910         uint32_t priority;
1911         uint32_t weight;
1912 };
1913
1914 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_set =
1915         TOKEN_STRING_INITIALIZER(
1916                 struct cmd_set_port_tm_node_parent_result, set, "set");
1917 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_port =
1918         TOKEN_STRING_INITIALIZER(
1919                 struct cmd_set_port_tm_node_parent_result, port, "port");
1920 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_tm =
1921         TOKEN_STRING_INITIALIZER(
1922                 struct cmd_set_port_tm_node_parent_result, tm, "tm");
1923 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_node =
1924         TOKEN_STRING_INITIALIZER(
1925                 struct cmd_set_port_tm_node_parent_result, node, "node");
1926 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_parent =
1927         TOKEN_STRING_INITIALIZER(
1928                 struct cmd_set_port_tm_node_parent_result, parent, "parent");
1929 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_port_id =
1930         TOKEN_NUM_INITIALIZER(
1931                 struct cmd_set_port_tm_node_parent_result, port_id, UINT16);
1932 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_node_id =
1933         TOKEN_NUM_INITIALIZER(
1934                 struct cmd_set_port_tm_node_parent_result, node_id, UINT32);
1935 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_parent_id =
1936         TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
1937                 parent_id, UINT32);
1938 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_priority =
1939         TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
1940                 priority, UINT32);
1941 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_weight =
1942         TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
1943                 weight, UINT32);
1944
1945 static void cmd_set_port_tm_node_parent_parsed(void *parsed_result,
1946         __attribute__((unused)) struct cmdline *cl,
1947         __attribute__((unused)) void *data)
1948 {
1949         struct cmd_set_port_tm_node_parent_result *res = parsed_result;
1950         struct rte_tm_error error;
1951         uint32_t node_id = res->node_id;
1952         uint32_t parent_id = res->parent_id;
1953         uint32_t priority = res->priority;
1954         uint32_t weight = res->weight;
1955         portid_t port_id = res->port_id;
1956         int ret;
1957
1958         if (port_id_is_invalid(port_id, ENABLED_WARN))
1959                 return;
1960
1961         /* Port status */
1962         if (!port_is_started(port_id)) {
1963                 printf(" Port %u not started (error)\n", port_id);
1964                 return;
1965         }
1966
1967         ret = rte_tm_node_parent_update(port_id, node_id,
1968                 parent_id, priority, weight, &error);
1969         if (ret != 0) {
1970                 print_err_msg(&error);
1971                 return;
1972         }
1973 }
1974
1975 cmdline_parse_inst_t cmd_set_port_tm_node_parent = {
1976         .f = cmd_set_port_tm_node_parent_parsed,
1977         .data = NULL,
1978         .help_str = "Set port tm node parent",
1979         .tokens = {
1980                 (void *)&cmd_set_port_tm_node_parent_set,
1981                 (void *)&cmd_set_port_tm_node_parent_port,
1982                 (void *)&cmd_set_port_tm_node_parent_tm,
1983                 (void *)&cmd_set_port_tm_node_parent_node,
1984                 (void *)&cmd_set_port_tm_node_parent_parent,
1985                 (void *)&cmd_set_port_tm_node_parent_port_id,
1986                 (void *)&cmd_set_port_tm_node_parent_node_id,
1987                 (void *)&cmd_set_port_tm_node_parent_parent_id,
1988                 (void *)&cmd_set_port_tm_node_parent_priority,
1989                 (void *)&cmd_set_port_tm_node_parent_weight,
1990                 NULL,
1991         },
1992 };
1993
1994 /* *** Port TM Hierarchy Commit *** */
1995 struct cmd_port_tm_hierarchy_commit_result {
1996         cmdline_fixed_string_t port;
1997         cmdline_fixed_string_t tm;
1998         cmdline_fixed_string_t hierarchy;
1999         cmdline_fixed_string_t commit;
2000         uint16_t port_id;
2001         cmdline_fixed_string_t clean_on_fail;
2002 };
2003
2004 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_port =
2005         TOKEN_STRING_INITIALIZER(
2006                 struct cmd_port_tm_hierarchy_commit_result, port, "port");
2007 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_tm =
2008         TOKEN_STRING_INITIALIZER(
2009                 struct cmd_port_tm_hierarchy_commit_result, tm, "tm");
2010 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_hierarchy =
2011         TOKEN_STRING_INITIALIZER(
2012                 struct cmd_port_tm_hierarchy_commit_result,
2013                         hierarchy, "hierarchy");
2014 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_commit =
2015         TOKEN_STRING_INITIALIZER(
2016                 struct cmd_port_tm_hierarchy_commit_result, commit, "commit");
2017 cmdline_parse_token_num_t cmd_port_tm_hierarchy_commit_port_id =
2018         TOKEN_NUM_INITIALIZER(
2019                 struct cmd_port_tm_hierarchy_commit_result,
2020                         port_id, UINT16);
2021 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_clean_on_fail =
2022         TOKEN_STRING_INITIALIZER(struct cmd_port_tm_hierarchy_commit_result,
2023                  clean_on_fail, "yes#no");
2024
2025 static void cmd_port_tm_hierarchy_commit_parsed(void *parsed_result,
2026         __attribute__((unused)) struct cmdline *cl,
2027         __attribute__((unused)) void *data)
2028 {
2029         struct cmd_port_tm_hierarchy_commit_result *res = parsed_result;
2030         struct rte_tm_error error;
2031         uint32_t clean_on_fail;
2032         portid_t port_id = res->port_id;
2033         int ret;
2034
2035         if (port_id_is_invalid(port_id, ENABLED_WARN))
2036                 return;
2037
2038         if (strcmp(res->clean_on_fail, "yes") == 0)
2039                 clean_on_fail = 1;
2040         else
2041                 clean_on_fail = 0;
2042
2043         ret = rte_tm_hierarchy_commit(port_id, clean_on_fail, &error);
2044         if (ret != 0) {
2045                 print_err_msg(&error);
2046                 return;
2047         }
2048 }
2049
2050 cmdline_parse_inst_t cmd_port_tm_hierarchy_commit = {
2051         .f = cmd_port_tm_hierarchy_commit_parsed,
2052         .data = NULL,
2053         .help_str = "Set port tm node shaper profile",
2054         .tokens = {
2055                 (void *)&cmd_port_tm_hierarchy_commit_port,
2056                 (void *)&cmd_port_tm_hierarchy_commit_tm,
2057                 (void *)&cmd_port_tm_hierarchy_commit_hierarchy,
2058                 (void *)&cmd_port_tm_hierarchy_commit_commit,
2059                 (void *)&cmd_port_tm_hierarchy_commit_port_id,
2060                 (void *)&cmd_port_tm_hierarchy_commit_clean_on_fail,
2061                 NULL,
2062         },
2063 };