blob: d0bdf5b909777d16873b4edb98c809044ef440a7 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15/*
16 * node_cli.c: node CLI
17 *
18 * Copyright (c) 2008 Eliot Dresselhaus
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39
Benoît Ganne362456a2019-01-21 17:41:25 +010040#include <sys/types.h>
41#include <sys/stat.h>
42#include <fcntl.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070043#include <vlib/vlib.h>
44#include <vlib/threads.h>
Damjan Marion8973b072022-03-01 15:51:18 +010045#include <vlib/stats/stats.h>
Arthur de Kerhor156158f2021-02-18 03:09:42 -080046#include <math.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070047
Matus Fabiand2dc3df2015-12-14 10:31:33 -050048static int
Dave Barach9b8ffd92016-07-08 08:13:45 -040049node_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050050{
Dave Barach9b8ffd92016-07-08 08:13:45 -040051 vlib_node_t **n1 = a1;
52 vlib_node_t **n2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050053
54 return vec_cmp (n1[0]->name, n2[0]->name);
55}
56
Ed Warnickecb9cada2015-12-08 15:45:58 -070057static clib_error_t *
58show_node_graph (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -040059 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -070060{
Dave Barach9b8ffd92016-07-08 08:13:45 -040061 vlib_node_main_t *nm = &vm->node_main;
62 vlib_node_t *n;
Ed Warnickecb9cada2015-12-08 15:45:58 -070063 u32 node_index;
64
65 vlib_cli_output (vm, "%U\n", format_vlib_node_graph, nm, 0);
66
67 if (unformat (input, "%U", unformat_vlib_node, vm, &node_index))
68 {
69 n = vlib_get_node (vm, node_index);
70 vlib_cli_output (vm, "%U\n", format_vlib_node_graph, nm, n);
71 }
72 else
73 {
Dave Barach9b8ffd92016-07-08 08:13:45 -040074 vlib_node_t **nodes = vec_dup (nm->nodes);
Ed Warnickecb9cada2015-12-08 15:45:58 -070075 uword i;
76
Matus Fabiand2dc3df2015-12-14 10:31:33 -050077 vec_sort_with_function (nodes, node_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070078
79 for (i = 0; i < vec_len (nodes); i++)
80 vlib_cli_output (vm, "%U\n\n", format_vlib_node_graph, nm, nodes[i]);
81
82 vec_free (nodes);
83 }
84
85 return 0;
86}
87
88VLIB_CLI_COMMAND (show_node_graph_command, static) = {
89 .path = "show vlib graph",
90 .short_help = "Show packet processing node graph",
91 .function = show_node_graph,
92};
93
Benoît Ganne362456a2019-01-21 17:41:25 +010094static clib_error_t *
95show_node_graphviz (vlib_main_t * vm,
96 unformat_input_t * input, vlib_cli_command_t * cmd)
97{
98 clib_error_t *error = 0;
99 vlib_node_main_t *nm = &vm->node_main;
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800100 vlib_node_t **nodes = nm->nodes;
Benoît Ganne362456a2019-01-21 17:41:25 +0100101 u8 *chroot_filename = 0;
102 int fd;
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800103 uword *active = 0;
104 u32 i, j;
105 unformat_input_t _line_input, *line_input = &_line_input;
106 u8 filter = 0, calls_filter = 0, vectors_filter = 0, both = 0;
Benoît Ganne362456a2019-01-21 17:41:25 +0100107
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800108 fd = -1;
109 /* Get a line of input. */
110 if (unformat_user (input, unformat_line_input, line_input))
Benoît Ganne362456a2019-01-21 17:41:25 +0100111 {
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800112 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
113 {
114 if (unformat (line_input, "filter"))
115 filter = 1;
116 else if (unformat (line_input, "calls") && filter)
117 calls_filter = 1;
118 else if (unformat (line_input, "vectors") && filter)
119 vectors_filter = 1;
120 else if (unformat (line_input, "file %U", unformat_vlib_tmpfile,
121 &chroot_filename))
122 {
123 fd = open ((char *) chroot_filename,
124 O_CREAT | O_TRUNC | O_WRONLY, 0664);
125 }
126 else
127 return clib_error_return (0, "unknown input `%U'",
128 format_unformat_error, input);
129 }
130 unformat_free (line_input);
Benoît Ganne362456a2019-01-21 17:41:25 +0100131 }
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800132
133 /*both is set to true if calls_filter and vectors_filter are, or neither */
134 both = filter & (!(calls_filter ^ vectors_filter));
Benoît Ganne362456a2019-01-21 17:41:25 +0100135
136#define format__(vm__, fd__, ...) \
137 if ((fd) < 0) \
138 { \
139 vlib_cli_output((vm__), ## __VA_ARGS__); \
140 } \
141 else \
142 { \
143 fdformat((fd__), ## __VA_ARGS__); \
144 }
145
146 format__ (vm, fd, "%s", "digraph {\n");
147
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800148 clib_bitmap_alloc (active, vec_len (nodes));
149 clib_bitmap_set_region (active, 0, 1, vec_len (nodes));
150 if (filter)
Benoît Ganne362456a2019-01-21 17:41:25 +0100151 {
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800152 /*Adding the legend to the dot file*/
153 format__ (vm, fd, "%s",
154 " rankdir=\"LR\"\n nodesep=2\n subgraph cluster_legend {\n "
155 " label=\"Legend\"\n style=\"solid\"\n labelloc = b\n "
156 " subgraph cluster_colors {\n label=\"Packets/Call\"\n "
157 " style=\"solid\"\n labelloc = b\n");
158 format__ (vm, fd, "%s",
159 " 0 [label=\"No packet\", fixedsize=true shape=circle "
160 "width=2 fontsize=17]\n"
161 " 1 [label=\"1-32\", fillcolor=1 style=filled "
162 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
163 "fontsize=17]\n"
164 " 2 [label=\"33-64\", fillcolor=2 style=filled "
165 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
166 "fontsize=17]\n"
167 " 3 [label=\"65-96\", fillcolor=3 style=filled "
168 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
169 "fontsize=17]\n"
170 " 4 [label=\"97-128\", fillcolor=4 style=filled "
171 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
172 "fontsize=17]\n"
173 " 5 [label=\"129-160\", fillcolor=5 style=filled "
174 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
175 "fontsize=17]\n"
176 " 6 [label=\"161-192\", fillcolor=6 style=filled "
177 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
178 "fontsize=17]\n"
179 " 7 [label=\"193-224\", fillcolor=7 style=filled "
180 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
181 "fontsize=17]\n"
182 " 8 [label=\"224+\", fillcolor=8 style=filled "
183 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
184 "fontsize=17]\n");
185 format__ (vm, fd, "%s",
186 " 0 -> 1 -> 2 -> 3 -> 4 [style=\"invis\",weight =100]\n "
187 " 5 -> 6 -> 7 -> 8 [style=\"invis\",weight =100]\n }\n "
188 " subgraph cluster_size {\n label=\"Cycles/Packet\"\n "
189 " style=\"solid\"\n labelloc = b\n");
190 format__ (
191 vm, fd, "%s",
192 " a[label=\"0\",fixedsize=true shape=circle width=1] \n"
193 " b[label=\"10\",fixedsize=true shape=circle width=2 "
194 "fontsize=17]\n"
195 " c[label=\"100\",fixedsize=true shape=circle width=3 "
196 "fontsize=20]\n"
197 " d[label=\"1000\",fixedsize=true shape=circle width=4 "
198 "fontsize=23]\n"
199 " a -> b -> c -> d [style=\"invis\",weight =100]\n }\n }\n");
200
201 vlib_worker_thread_barrier_sync (vm);
202 for (j = 0; j < vec_len (nm->nodes); j++)
Benoît Ganne362456a2019-01-21 17:41:25 +0100203 {
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800204 vlib_node_t *n;
205 n = nm->nodes[j];
206 vlib_node_sync_stats (vm, n);
207 }
Benoît Ganne362456a2019-01-21 17:41:25 +0100208
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800209 /* Updating the stats for multithreaded use cases.
210 * We need to dup the nodes to sum the stats from all threads.*/
211 nodes = vec_dup (nm->nodes);
Damjan Marion6ffb7c62021-03-26 13:06:13 +0100212 for (i = 1; i < vlib_get_n_threads (); i++)
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800213 {
214 vlib_node_main_t *nm_clone;
215 vlib_main_t *vm_clone;
216 vlib_node_runtime_t *rt;
217 vlib_node_t *n;
Benoît Ganne362456a2019-01-21 17:41:25 +0100218
Damjan Marion6ffb7c62021-03-26 13:06:13 +0100219 vm_clone = vlib_get_main_by_index (i);
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800220 nm_clone = &vm_clone->node_main;
221
222 for (j = 0; j < vec_len (nm_clone->nodes); j++)
223 {
224 n = nm_clone->nodes[j];
225
226 rt = vlib_node_get_runtime (vm_clone, n->index);
227 /* Sync the stats directly in the duplicated node.*/
228 vlib_node_runtime_sync_stats_node (nodes[j], rt, 0, 0, 0);
229 }
230 }
231 vlib_worker_thread_barrier_release (vm);
232
233 for (i = 0; i < vec_len (nodes); i++)
234 {
235 u64 p, c, l;
236 c = nodes[i]->stats_total.calls - nodes[i]->stats_last_clear.calls;
237 p =
238 nodes[i]->stats_total.vectors - nodes[i]->stats_last_clear.vectors;
239 l = nodes[i]->stats_total.clocks - nodes[i]->stats_last_clear.clocks;
240
241 if ((both && c > 0 && p > 0) || (calls_filter && c > 0) ||
242 (vectors_filter && p > 0))
243 {
244 format__ (vm, fd, " \"%v\" [shape=circle", nodes[i]->name);
245 /*Changing the size and the font of nodes that receive packets*/
246 if (p > 0)
247 {
248 f64 x = (f64) l / (f64) p;
249 f64 size_ratio = (1 + log10 (x + 1));
250 format__ (vm, fd, " width=%.2f fontsize=%.2f fixedsize=true",
251 size_ratio, 11 + 3 * size_ratio);
252 /*Coloring nodes that are indeed called*/
253 if (c > 0)
254 {
255 u64 color = ((p - 1) / (32 * c)) + 1;
256 color = clib_min (color, 8);
257 format__ (
258 vm, fd,
259 " fillcolor=%u style=filled colorscheme=ylorrd8",
260 color);
261 }
262 }
263 format__ (vm, fd, "]\n");
264 }
265 else
266 {
267 clib_bitmap_set (active, i, 0);
268 }
Benoît Ganne362456a2019-01-21 17:41:25 +0100269 }
270 }
271
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800272 clib_bitmap_foreach (i, active)
273 {
274 for (j = 0; j < vec_len (nodes[i]->next_nodes); j++)
275 {
276 if (nodes[i]->next_nodes[j] == VLIB_INVALID_NODE_INDEX)
277 continue;
278
279 if (!filter || clib_bitmap_get (active, nodes[i]->next_nodes[j]))
280 {
281 format__ (vm, fd, " \"%v\" -> \"%v\"\n", nodes[i]->name,
282 nodes[nodes[i]->next_nodes[j]]->name);
283 }
284 }
285 }
286
287 format__ (vm, fd, "}\n");
Benoît Ganne362456a2019-01-21 17:41:25 +0100288
289 if (fd >= 0)
290 {
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800291 /*Dumping all the nodes saturates dot capacities to render a directed
292 * graph. In this case, prefer using he fdp command to generate an
293 * undirected graph. */
294 const char *soft = filter ? "dot" : "fdp";
295 vlib_cli_output (
296 vm, "vlib graph dumped into `%s'. Run eg. `%s -Tsvg -O %s'.",
297 chroot_filename, soft, chroot_filename);
Benoît Ganne362456a2019-01-21 17:41:25 +0100298 }
299
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800300 clib_bitmap_free (active);
Benoît Ganne362456a2019-01-21 17:41:25 +0100301 vec_free (chroot_filename);
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800302 if (filter)
303 vec_free (nodes);
Benoît Ganne362456a2019-01-21 17:41:25 +0100304 if (fd >= 0)
305 close (fd);
306 return error;
307}
308
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800309/*?
310 * Dump dot files data to draw a graph of all the nodes.
311 * If the argument 'filter' is provided, only the active nodes (since the last
Nathan Skrzypczakecd6b1a2021-09-29 15:35:31 +0200312 * "clear run" command) are selected and they are scaled and colored according
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800313 * to their utilization. You can choose to filter nodes that are called,
314 * nodes that receive vectors or both (default).
315 * The 'file' option allows to save data in a temp file.
316 *
317 * @cliexpar
318 * @clistart
319 * show vlib graphviz
320 * show vlib graphviz filter file tmpfile
321 * show vlib graphviz filter calls file tmpfile
322 * @cliend
323 * @cliexcmd{show vlib graphviz [filter][calls][vectors][file <filename>]}
324?*/
Benoît Ganne362456a2019-01-21 17:41:25 +0100325VLIB_CLI_COMMAND (show_node_graphviz_command, static) = {
326 .path = "show vlib graphviz",
327 .short_help = "Dump packet processing node graph as a graphviz dotfile",
328 .function = show_node_graphviz,
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800329 .is_mp_safe = 1,
Benoît Ganne362456a2019-01-21 17:41:25 +0100330};
Benoît Ganne362456a2019-01-21 17:41:25 +0100331
Dave Barach9b8ffd92016-07-08 08:13:45 -0400332static u8 *
Damjan Marion69abe442018-08-27 22:43:23 +0200333format_vlib_node_state (u8 * s, va_list * va)
334{
335 vlib_main_t *vm = va_arg (*va, vlib_main_t *);
336 vlib_node_t *n = va_arg (*va, vlib_node_t *);
337 char *state;
338
339 state = "active";
340 if (n->type == VLIB_NODE_TYPE_PROCESS)
341 {
342 vlib_process_t *p = vlib_get_process_from_node (vm, n);
343
344 switch (p->flags & (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK
345 | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT))
346 {
347 default:
348 if (!(p->flags & VLIB_PROCESS_IS_RUNNING))
349 state = "done";
350 break;
351
352 case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK:
353 state = "time wait";
354 break;
355
356 case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT:
357 state = "event wait";
358 break;
359
360 case (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK):
361 state =
362 "any wait";
363 break;
364 }
365 }
366 else if (n->type != VLIB_NODE_TYPE_INTERNAL)
367 {
368 state = "polling";
369 if (n->state == VLIB_NODE_STATE_DISABLED)
370 state = "disabled";
371 else if (n->state == VLIB_NODE_STATE_INTERRUPT)
372 state = "interrupt wait";
373 }
374
375 return format (s, "%s", state);
376}
377
378static u8 *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400379format_vlib_node_stats (u8 * s, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700380{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400381 vlib_main_t *vm = va_arg (*va, vlib_main_t *);
382 vlib_node_t *n = va_arg (*va, vlib_node_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700383 int max = va_arg (*va, int);
384 f64 v;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400385 u8 *ns;
386 u8 *misc_info = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700387 u64 c, p, l, d;
388 f64 x;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400389 f64 maxc, maxcn;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700390 u32 maxn;
Christophe Fontained3c008d2017-10-02 18:10:54 +0200391 u32 indent;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700392
Dave Barach9b8ffd92016-07-08 08:13:45 -0400393 if (!n)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700394 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400395 if (max)
Dave Barach4d1a8662018-09-10 12:31:15 -0400396 s = format (s,
397 "%=30s%=17s%=16s%=16s%=16s%=16s",
398 "Name", "Max Node Clocks", "Vectors at Max",
399 "Max Clocks", "Avg Clocks", "Avg Vectors/Call");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700400 else
Dave Barach4d1a8662018-09-10 12:31:15 -0400401 s = format (s,
402 "%=30s%=12s%=16s%=16s%=16s%=16s%=16s",
403 "Name", "State", "Calls", "Vectors", "Suspends",
404 "Clocks", "Vectors/Call");
Dave Barach4d1a8662018-09-10 12:31:15 -0400405 return s;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700406 }
407
408 indent = format_get_indent (s);
409
410 l = n->stats_total.clocks - n->stats_last_clear.clocks;
411 c = n->stats_total.calls - n->stats_last_clear.calls;
412 p = n->stats_total.vectors - n->stats_last_clear.vectors;
413 d = n->stats_total.suspends - n->stats_last_clear.suspends;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400414 maxc = (f64) n->stats_total.max_clock;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700415 maxn = n->stats_total.max_clock_n;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400416 if (n->stats_total.max_clock_n)
417 maxcn = (f64) n->stats_total.max_clock / (f64) maxn;
418 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700419 maxcn = 0.0;
420
421 /* Clocks per packet, per call or per suspend. */
422 x = 0;
423 if (p > 0)
424 x = (f64) l / (f64) p;
425 else if (c > 0)
426 x = (f64) l / (f64) c;
427 else if (d > 0)
428 x = (f64) l / (f64) d;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400429
Ed Warnickecb9cada2015-12-08 15:45:58 -0700430 if (c > 0)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400431 v = (double) p / (double) c;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700432 else
433 v = 0;
434
Ed Warnickecb9cada2015-12-08 15:45:58 -0700435 if (n->type == VLIB_NODE_TYPE_PROCESS)
436 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400437 vlib_process_t *p = vlib_get_process_from_node (vm, n);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700438
439 /* Show processes with events pending. This helps spot bugs where events are not
Dave Barach9b8ffd92016-07-08 08:13:45 -0400440 being handled. */
441 if (!clib_bitmap_is_zero (p->non_empty_event_type_bitmap))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700442 misc_info = format (misc_info, "events pending, ");
Dave Barach9b8ffd92016-07-08 08:13:45 -0400443 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700444 ns = n->name;
445
446 if (max)
447 s = format (s, "%-30v%=17.2e%=16d%=16.2e%=16.2e%=16.2e",
Dave Barach9b8ffd92016-07-08 08:13:45 -0400448 ns, maxc, maxn, maxcn, x, v);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700449 else
Damjan Marion69abe442018-08-27 22:43:23 +0200450 s = format (s, "%-30v%=12U%16Ld%16Ld%16Ld%16.2e%16.2f", ns,
451 format_vlib_node_state, vm, n, c, p, d, x, v);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700452
453 if (ns != n->name)
454 vec_free (ns);
455
456 if (misc_info)
457 {
458 s = format (s, "\n%U%v", format_white_space, indent + 4, misc_info);
459 vec_free (misc_info);
460 }
461
462 return s;
463}
464
465static clib_error_t *
466show_node_runtime (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400467 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700468{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400469 vlib_node_main_t *nm = &vm->node_main;
470 vlib_node_t *n;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700471 f64 time_now;
472 u32 node_index;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400473 vlib_node_t ***node_dups = 0;
Dave Baracha8df85c2019-10-01 13:34:23 -0400474 f64 *internal_node_vector_rates = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700475
476 time_now = vlib_time_now (vm);
477
478 if (unformat (input, "%U", unformat_vlib_node, vm, &node_index))
479 {
480 n = vlib_get_node (vm, node_index);
481 vlib_node_sync_stats (vm, n);
482 vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, 0, 0);
483 vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, n, 0);
484 }
485 else
486 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400487 vlib_node_t **nodes;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700488 uword i, j;
489 f64 dt;
490 u64 n_input, n_output, n_drop, n_punt;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700491 u64 n_clocks, l, v, c, d;
492 int brief = 1;
Dave Barachac78f8a2019-10-04 09:59:00 -0400493 int summary = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700494 int max = 0;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400495 vlib_main_t **stat_vms = 0, *stat_vm;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700496
497 /* Suppress nodes with zero calls since last clear */
498 if (unformat (input, "brief") || unformat (input, "b"))
Dave Barach9b8ffd92016-07-08 08:13:45 -0400499 brief = 1;
500 if (unformat (input, "verbose") || unformat (input, "v"))
501 brief = 0;
502 if (unformat (input, "max") || unformat (input, "m"))
503 max = 1;
Dave Barachac78f8a2019-10-04 09:59:00 -0400504 if (unformat (input, "summary") || unformat (input, "sum")
505 || unformat (input, "su"))
506 summary = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700507
Damjan Marion6ffb7c62021-03-26 13:06:13 +0100508 for (i = 0; i < vlib_get_n_threads (); i++)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400509 {
Damjan Marion6ffb7c62021-03-26 13:06:13 +0100510 stat_vm = vlib_get_main_by_index (i);
Dave Barach80f54e22017-03-08 19:08:56 -0500511 if (stat_vm)
512 vec_add1 (stat_vms, stat_vm);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400513 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700514
Dave Barach9b8ffd92016-07-08 08:13:45 -0400515 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -0700516 * Barrier sync across stats scraping.
517 * Otherwise, the counts will be grossly inaccurate.
518 */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400519 vlib_worker_thread_barrier_sync (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700520
521 for (j = 0; j < vec_len (stat_vms); j++)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400522 {
523 stat_vm = stat_vms[j];
524 nm = &stat_vm->node_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700525
Dave Barach9b8ffd92016-07-08 08:13:45 -0400526 for (i = 0; i < vec_len (nm->nodes); i++)
527 {
528 n = nm->nodes[i];
529 vlib_node_sync_stats (stat_vm, n);
530 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700531
Dave Barach9b8ffd92016-07-08 08:13:45 -0400532 nodes = vec_dup (nm->nodes);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700533
Dave Barach9b8ffd92016-07-08 08:13:45 -0400534 vec_add1 (node_dups, nodes);
Dave Baracha8df85c2019-10-01 13:34:23 -0400535 vec_add1 (internal_node_vector_rates,
536 vlib_internal_node_vector_rate (stat_vm));
Dave Barach9b8ffd92016-07-08 08:13:45 -0400537 }
538 vlib_worker_thread_barrier_release (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700539
540
541 for (j = 0; j < vec_len (stat_vms); j++)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400542 {
543 stat_vm = stat_vms[j];
544 nodes = node_dups[j];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700545
Dave Barach9b8ffd92016-07-08 08:13:45 -0400546 vec_sort_with_function (nodes, node_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700547
Dave Barach9b8ffd92016-07-08 08:13:45 -0400548 n_input = n_output = n_drop = n_punt = n_clocks = 0;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400549 for (i = 0; i < vec_len (nodes); i++)
550 {
551 n = nodes[i];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700552
Dave Barach9b8ffd92016-07-08 08:13:45 -0400553 l = n->stats_total.clocks - n->stats_last_clear.clocks;
554 n_clocks += l;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700555
Dave Barach9b8ffd92016-07-08 08:13:45 -0400556 v = n->stats_total.vectors - n->stats_last_clear.vectors;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700557
Dave Barach9b8ffd92016-07-08 08:13:45 -0400558 switch (n->type)
559 {
560 default:
561 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700562
Dave Barach9b8ffd92016-07-08 08:13:45 -0400563 case VLIB_NODE_TYPE_INTERNAL:
564 n_output += (n->flags & VLIB_NODE_FLAG_IS_OUTPUT) ? v : 0;
565 n_drop += (n->flags & VLIB_NODE_FLAG_IS_DROP) ? v : 0;
566 n_punt += (n->flags & VLIB_NODE_FLAG_IS_PUNT) ? v : 0;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400567 if (n->flags & VLIB_NODE_FLAG_IS_HANDOFF)
568 n_input += v;
569 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700570
Dave Barach9b8ffd92016-07-08 08:13:45 -0400571 case VLIB_NODE_TYPE_INPUT:
572 n_input += v;
573 break;
574 }
575 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700576
Damjan Marion6ffb7c62021-03-26 13:06:13 +0100577 if (vlib_get_n_threads () > 1)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400578 {
579 vlib_worker_thread_t *w = vlib_worker_threads + j;
580 if (j > 0)
581 vlib_cli_output (vm, "---------------");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700582
Mohsin Kazmi5d64c782018-09-11 20:27:09 +0200583 if (w->cpu_id > -1)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400584 vlib_cli_output (vm, "Thread %d %s (lcore %u)", j, w->name,
Mohsin Kazmi5d64c782018-09-11 20:27:09 +0200585 w->cpu_id);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400586 else
587 vlib_cli_output (vm, "Thread %d %s", j, w->name);
588 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700589
Dave Barach9b8ffd92016-07-08 08:13:45 -0400590 dt = time_now - nm->time_last_runtime_stats_clear;
Damjan Marion8973b072022-03-01 15:51:18 +0100591 vlib_cli_output (
592 vm,
593 "Time %.1f, %f sec internal node vector rate %.2f loops/sec %.2f\n"
594 " vector rates in %.4e, out %.4e, drop %.4e, punt %.4e",
595 dt, vlib_stats_get_segment_update_rate (),
596 internal_node_vector_rates[j], stat_vm->loops_per_second,
597 (f64) n_input / dt, (f64) n_output / dt, (f64) n_drop / dt,
598 (f64) n_punt / dt);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700599
Dave Barachac78f8a2019-10-04 09:59:00 -0400600 if (summary == 0)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400601 {
Dave Barachac78f8a2019-10-04 09:59:00 -0400602 vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm,
603 0, max);
604 for (i = 0; i < vec_len (nodes); i++)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400605 {
Dave Barachac78f8a2019-10-04 09:59:00 -0400606 c =
607 nodes[i]->stats_total.calls -
608 nodes[i]->stats_last_clear.calls;
609 d =
610 nodes[i]->stats_total.suspends -
611 nodes[i]->stats_last_clear.suspends;
612 if (c || d || !brief)
613 {
614 vlib_cli_output (vm, "%U", format_vlib_node_stats,
615 stat_vm, nodes[i], max);
616 }
Dave Barach9b8ffd92016-07-08 08:13:45 -0400617 }
618 }
619 vec_free (nodes);
620 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700621 vec_free (stat_vms);
622 vec_free (node_dups);
Dave Baracha8df85c2019-10-01 13:34:23 -0400623 vec_free (internal_node_vector_rates);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700624 }
625
626 return 0;
627}
628
629VLIB_CLI_COMMAND (show_node_runtime_command, static) = {
630 .path = "show runtime",
631 .short_help = "Show packet processing runtime",
632 .function = show_node_runtime,
633 .is_mp_safe = 1,
634};
635
636static clib_error_t *
637clear_node_runtime (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400638 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700639{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400640 vlib_node_main_t *nm;
641 vlib_node_t *n;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700642 int i, j;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400643 vlib_main_t **stat_vms = 0, *stat_vm;
644 vlib_node_runtime_t *r;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700645
Damjan Marion6ffb7c62021-03-26 13:06:13 +0100646 for (i = 0; i < vlib_get_n_threads (); i++)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700647 {
Damjan Marion6ffb7c62021-03-26 13:06:13 +0100648 stat_vm = vlib_get_main_by_index (i);
Dave Barach80f54e22017-03-08 19:08:56 -0500649 if (stat_vm)
650 vec_add1 (stat_vms, stat_vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700651 }
Dave Barach9b8ffd92016-07-08 08:13:45 -0400652
653 vlib_worker_thread_barrier_sync (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700654
655 for (j = 0; j < vec_len (stat_vms); j++)
656 {
657 stat_vm = stat_vms[j];
658 nm = &stat_vm->node_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700659
Dave Barach9b8ffd92016-07-08 08:13:45 -0400660 for (i = 0; i < vec_len (nm->nodes); i++)
661 {
662 n = nm->nodes[i];
663 vlib_node_sync_stats (stat_vm, n);
664 n->stats_last_clear = n->stats_total;
665
666 r = vlib_node_get_runtime (stat_vm, n->index);
667 r->max_clock = 0;
668 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700669 /* Note: input/output rates computed using vlib_global_main */
670 nm->time_last_runtime_stats_clear = vlib_time_now (vm);
671 }
672
Damjan Marion8973b072022-03-01 15:51:18 +0100673 vlib_stats_set_timestamp (STAT_COUNTER_LAST_STATS_CLEAR,
674 vm->node_main.time_last_runtime_stats_clear);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400675 vlib_worker_thread_barrier_release (vm);
676
Ed Warnickecb9cada2015-12-08 15:45:58 -0700677 vec_free (stat_vms);
678
679 return 0;
680}
681
682VLIB_CLI_COMMAND (clear_node_runtime_command, static) = {
683 .path = "clear runtime",
684 .short_help = "Clear packet processing runtime statistics",
685 .function = clear_node_runtime,
686};
687
Damjan Marion69abe442018-08-27 22:43:23 +0200688static clib_error_t *
689show_node (vlib_main_t * vm, unformat_input_t * input,
690 vlib_cli_command_t * cmd)
691{
692 unformat_input_t _line_input, *line_input = &_line_input;
Paul Vinciguerra98afc712018-09-25 10:02:07 -0700693 clib_error_t *error = 0;
Damjan Marion69abe442018-08-27 22:43:23 +0200694 vlib_node_main_t *nm = &vm->node_main;
695 vlib_node_t *n;
696 u8 *s = 0, *s2 = 0;
Florin Coras178ecc02020-03-12 23:26:11 +0000697 u32 i, node_index = ~0, verbose = 0;
Damjan Marion69abe442018-08-27 22:43:23 +0200698 char *type_str;
Paul Vinciguerra98afc712018-09-25 10:02:07 -0700699 u8 valid_node_name = 0;
Florin Coras178ecc02020-03-12 23:26:11 +0000700 u64 cl, ca, v;
Damjan Marion69abe442018-08-27 22:43:23 +0200701
702 if (!unformat_user (input, unformat_line_input, line_input))
703 return 0;
704
705 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
706 {
Paul Vinciguerra98afc712018-09-25 10:02:07 -0700707 if (unformat (line_input, "index %u", &node_index))
Damjan Marion69abe442018-08-27 22:43:23 +0200708 ;
Florin Coras178ecc02020-03-12 23:26:11 +0000709 else if (unformat (line_input, "verbose"))
710 verbose = 1;
Damjan Marion69abe442018-08-27 22:43:23 +0200711 else
Paul Vinciguerra98afc712018-09-25 10:02:07 -0700712 if (unformat (line_input, "%U", unformat_vlib_node, vm, &node_index))
713 valid_node_name = 1;
714 else if (!valid_node_name)
715 error = clib_error_return (0, "unknown node name: '%U'",
716 format_unformat_error, line_input);
717 else
718 error = clib_error_return (0, "unknown input '%U'",
719 format_unformat_error, line_input);
Filip Tehlarbe0ffbc2019-07-09 13:52:26 +0000720
721 if (error)
722 break;
Damjan Marion69abe442018-08-27 22:43:23 +0200723 }
Paul Vinciguerra98afc712018-09-25 10:02:07 -0700724
Damjan Marion69abe442018-08-27 22:43:23 +0200725 unformat_free (line_input);
726
Paul Vinciguerra98afc712018-09-25 10:02:07 -0700727 if (error)
728 return error;
729
Damjan Marion69abe442018-08-27 22:43:23 +0200730 if (node_index >= vec_len (vm->node_main.nodes))
731 return clib_error_return (0, "please specify valid node");
732
733 n = vlib_get_node (vm, node_index);
734 vlib_node_sync_stats (vm, n);
735
736 switch (n->type)
737 {
738 case VLIB_NODE_TYPE_INTERNAL:
739 type_str = "internal";
740 break;
741 case VLIB_NODE_TYPE_INPUT:
742 type_str = "input";
743 break;
744 case VLIB_NODE_TYPE_PRE_INPUT:
745 type_str = "pre-input";
746 break;
747 case VLIB_NODE_TYPE_PROCESS:
748 type_str = "process";
749 break;
750 default:
751 type_str = "unknown";
752 }
753
754 if (n->sibling_of)
755 s = format (s, ", sibling-of %s", n->sibling_of);
756
Benoît Ganne62d9fda2019-12-16 15:49:47 +0100757 vlib_cli_output (vm, "node %v, type %s, state %U, index %d%v\n",
Damjan Marion69abe442018-08-27 22:43:23 +0200758 n->name, type_str, format_vlib_node_state, vm, n,
759 n->index, s);
760 vec_reset_length (s);
761
762 if (n->node_fn_registrations)
763 {
764 vlib_node_fn_registration_t *fnr = n->node_fn_registrations;
Damjan Mariona31698b2021-03-10 14:35:28 +0100765 vlib_node_fn_variant_t *v;
Damjan Marion69abe442018-08-27 22:43:23 +0200766 while (fnr)
767 {
Damjan Mariona31698b2021-03-10 14:35:28 +0100768 v = vec_elt_at_index (vm->node_main.variants, fnr->march_variant);
Damjan Marion69abe442018-08-27 22:43:23 +0200769 if (vec_len (s) == 0)
Damjan Mariona31698b2021-03-10 14:35:28 +0100770 s = format (s, "\n %-15s %=8s %6s %s", "Name", "Priority",
771 "Active", "Description");
772 s = format (s, "\n %-15s %8d %=6s %s", v->suffix, v->priority,
773 fnr->function == n->function ? "yes" : "", v->desc);
Damjan Marion69abe442018-08-27 22:43:23 +0200774 fnr = fnr->next_registration;
775 }
776 }
777 else
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700778 s = format (s, "\n default only");
Damjan Marion69abe442018-08-27 22:43:23 +0200779 vlib_cli_output (vm, " node function variants:%v\n", s);
780 vec_reset_length (s);
781
782 for (i = 0; i < vec_len (n->next_nodes); i++)
783 {
784 vlib_node_t *pn;
785 if (n->next_nodes[i] == VLIB_INVALID_NODE_INDEX)
786 continue;
787
788 pn = vec_elt (nm->nodes, n->next_nodes[i]);
789
790 if (vec_len (s) == 0)
791 s = format (s, "\n %10s %10s %=30s %8s",
792 "next-index", "node-index", "Node", "Vectors");
793
Florin Coras178ecc02020-03-12 23:26:11 +0000794 s = format (s, "\n %=10u %=10u %=30v %=8llu", i, n->next_nodes[i],
Damjan Marion69abe442018-08-27 22:43:23 +0200795 pn->name, vec_elt (n->n_vectors_by_next_node, i));
796 }
797
798 if (vec_len (s) == 0)
799 s = format (s, "\n none");
800 vlib_cli_output (vm, "\n next nodes:%v\n", s);
801 vec_reset_length (s);
802
803 if (n->type == VLIB_NODE_TYPE_INTERNAL)
804 {
805 int j = 0;
Damjan Marionf0ca1e82020-12-13 23:26:56 +0100806 clib_bitmap_foreach (i, n->prev_node_bitmap) {
Damjan Marion69abe442018-08-27 22:43:23 +0200807 vlib_node_t *pn = vlib_get_node (vm, i);
808 if (j++ % 3 == 0)
809 s = format (s, "\n ");
810 s2 = format (s2, "%v (%u)", pn->name, i);
811 s = format (s, "%-35v", s2);
812 vec_reset_length (s2);
Damjan Marionf0ca1e82020-12-13 23:26:56 +0100813 }
Damjan Marion69abe442018-08-27 22:43:23 +0200814
815 if (vec_len (s) == 0)
816 s = format (s, "\n none");
817 vlib_cli_output (vm, "\n known previous nodes:%v\n", s);
818 vec_reset_length (s);
Florin Coras178ecc02020-03-12 23:26:11 +0000819 vec_free (s2);
Damjan Marion69abe442018-08-27 22:43:23 +0200820 }
821
Florin Coras178ecc02020-03-12 23:26:11 +0000822 if (!verbose)
823 goto done;
824
825 s = format (s, "\n%8s %=12s %=12s %=12s %=12s %=12s\n", "Thread", "Calls",
826 "Clocks", "Vectors", "Max Clock", "Max Vectors");
Damjan Marion6ffb7c62021-03-26 13:06:13 +0100827 for (i = 0; i < vlib_get_n_threads (); i++)
Florin Coras178ecc02020-03-12 23:26:11 +0000828 {
Damjan Marion6ffb7c62021-03-26 13:06:13 +0100829 n = vlib_get_node (vlib_get_main_by_index (i), node_index);
830 vlib_node_sync_stats (vlib_get_main_by_index (i), n);
Florin Coras178ecc02020-03-12 23:26:11 +0000831
832 cl = n->stats_total.clocks - n->stats_last_clear.clocks;
833 ca = n->stats_total.calls - n->stats_last_clear.calls;
834 v = n->stats_total.vectors - n->stats_last_clear.vectors;
835
836 s = format (s, "%=8u %=12lu %=12lu %=12lu %=12u %=12u\n", i, ca, cl, v,
837 n->stats_total.max_clock, n->stats_total.max_clock_n);
838 }
839
840 vlib_cli_output (vm, "%v", s);
841
842done:
843
Damjan Marion69abe442018-08-27 22:43:23 +0200844 vec_free (s);
Damjan Marion69abe442018-08-27 22:43:23 +0200845 return 0;
846}
847
Damjan Marion69abe442018-08-27 22:43:23 +0200848VLIB_CLI_COMMAND (show_node_command, static) = {
849 .path = "show node",
850 .short_help = "show node [index] <node-name | node-index>",
851 .function = show_node,
852};
853
854static clib_error_t *
855set_node_fn(vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
856{
857 unformat_input_t _line_input, *line_input = &_line_input;
Damjan Mariona31698b2021-03-10 14:35:28 +0100858 u32 node_index, march_variant;
Damjan Marion69abe442018-08-27 22:43:23 +0200859 vlib_node_t *n;
860 clib_error_t *err = 0;
Damjan Marion69abe442018-08-27 22:43:23 +0200861
862 if (!unformat_user (input, unformat_line_input, line_input))
863 return 0;
864
865 if (!unformat (line_input, "%U", unformat_vlib_node, vm, &node_index))
866 {
867 err = clib_error_return (0, "please specify valid node name");
868 goto done;
869 }
870
Damjan Mariona31698b2021-03-10 14:35:28 +0100871 if (!unformat (line_input, "%U", unformat_vlib_node_variant, &march_variant))
Damjan Marion69abe442018-08-27 22:43:23 +0200872 {
Damjan Mariona31698b2021-03-10 14:35:28 +0100873 err = clib_error_return (0, "please specify node function variant");
Damjan Marion69abe442018-08-27 22:43:23 +0200874 goto done;
875 }
876
877 n = vlib_get_node (vm, node_index);
878
879 if (n->node_fn_registrations == 0)
880 {
Damjan Mariona31698b2021-03-10 14:35:28 +0100881 err = clib_error_return (0, "node doesn't have function variants");
Damjan Marion69abe442018-08-27 22:43:23 +0200882 goto done;
883 }
884
Damjan Mariona31698b2021-03-10 14:35:28 +0100885 if (vlib_node_set_march_variant (vm, node_index, march_variant))
Damjan Marion69abe442018-08-27 22:43:23 +0200886 {
Damjan Mariona31698b2021-03-10 14:35:28 +0100887 vlib_node_fn_variant_t *v;
888 v = vec_elt_at_index (vm->node_main.variants, march_variant);
889 err = clib_error_return (0, "node function variant '%s' not found",
890 v->suffix);
891 goto done;
Damjan Marion69abe442018-08-27 22:43:23 +0200892 }
893
Damjan Marion69abe442018-08-27 22:43:23 +0200894
895done:
Damjan Marion69abe442018-08-27 22:43:23 +0200896 unformat_free (line_input);
897 return err;
898}
899
Damjan Marion69abe442018-08-27 22:43:23 +0200900VLIB_CLI_COMMAND (set_node_fn_command, static) = {
901 .path = "set node function",
902 .short_help = "set node function <node-name> <variant-name>",
903 .function = set_node_fn,
904};
Damjan Marion69abe442018-08-27 22:43:23 +0200905
Ed Warnickecb9cada2015-12-08 15:45:58 -0700906/* Dummy function to get us linked in. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400907void
908vlib_node_cli_reference (void)
909{
910}
911
912/*
913 * fd.io coding-style-patch-verification: ON
914 *
915 * Local Variables:
916 * eval: (c-set-style "gnu")
917 * End:
918 */