Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 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 Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 40 | #include <sys/types.h> |
| 41 | #include <sys/stat.h> |
| 42 | #include <fcntl.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 43 | #include <vlib/vlib.h> |
| 44 | #include <vlib/threads.h> |
| 45 | |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 46 | static int |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 47 | node_cmp (void *a1, void *a2) |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 48 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 49 | vlib_node_t **n1 = a1; |
| 50 | vlib_node_t **n2 = a2; |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 51 | |
| 52 | return vec_cmp (n1[0]->name, n2[0]->name); |
| 53 | } |
| 54 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 55 | static clib_error_t * |
| 56 | show_node_graph (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 57 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 58 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 59 | vlib_node_main_t *nm = &vm->node_main; |
| 60 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 61 | u32 node_index; |
| 62 | |
| 63 | vlib_cli_output (vm, "%U\n", format_vlib_node_graph, nm, 0); |
| 64 | |
| 65 | if (unformat (input, "%U", unformat_vlib_node, vm, &node_index)) |
| 66 | { |
| 67 | n = vlib_get_node (vm, node_index); |
| 68 | vlib_cli_output (vm, "%U\n", format_vlib_node_graph, nm, n); |
| 69 | } |
| 70 | else |
| 71 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 72 | vlib_node_t **nodes = vec_dup (nm->nodes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 73 | uword i; |
| 74 | |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 75 | vec_sort_with_function (nodes, node_cmp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 76 | |
| 77 | for (i = 0; i < vec_len (nodes); i++) |
| 78 | vlib_cli_output (vm, "%U\n\n", format_vlib_node_graph, nm, nodes[i]); |
| 79 | |
| 80 | vec_free (nodes); |
| 81 | } |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 86 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 87 | VLIB_CLI_COMMAND (show_node_graph_command, static) = { |
| 88 | .path = "show vlib graph", |
| 89 | .short_help = "Show packet processing node graph", |
| 90 | .function = show_node_graph, |
| 91 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 92 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 93 | |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 94 | static clib_error_t * |
| 95 | show_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; |
| 100 | u8 *chroot_filename = 0; |
| 101 | int fd; |
| 102 | vlib_node_t **nodes = 0; |
| 103 | uword i, j; |
| 104 | |
| 105 | if (!unformat_user (input, unformat_vlib_tmpfile, &chroot_filename)) |
| 106 | { |
| 107 | fd = -1; |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | fd = |
| 112 | open ((char *) chroot_filename, O_CREAT | O_TRUNC | O_WRONLY, 0664); |
| 113 | } |
| 114 | |
| 115 | #define format__(vm__, fd__, ...) \ |
| 116 | if ((fd) < 0) \ |
| 117 | { \ |
| 118 | vlib_cli_output((vm__), ## __VA_ARGS__); \ |
| 119 | } \ |
| 120 | else \ |
| 121 | { \ |
| 122 | fdformat((fd__), ## __VA_ARGS__); \ |
| 123 | } |
| 124 | |
| 125 | format__ (vm, fd, "%s", "digraph {\n"); |
| 126 | |
| 127 | nodes = vec_dup (nm->nodes); |
| 128 | vec_sort_with_function (nodes, node_cmp); |
| 129 | |
| 130 | for (i = 0; i < vec_len (nodes); i++) |
| 131 | { |
| 132 | for (j = 0; j < vec_len (nodes[i]->next_nodes); j++) |
| 133 | { |
| 134 | vlib_node_t *x; |
| 135 | |
| 136 | if (nodes[i]->next_nodes[j] == VLIB_INVALID_NODE_INDEX) |
| 137 | continue; |
| 138 | |
| 139 | x = vec_elt (nm->nodes, nodes[i]->next_nodes[j]); |
| 140 | format__ (vm, fd, " \"%v\" -> \"%v\"\n", nodes[i]->name, x->name); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | format__ (vm, fd, "%s", "}"); |
| 145 | |
| 146 | if (fd >= 0) |
| 147 | { |
| 148 | vlib_cli_output (vm, |
| 149 | "vlib graph dumped into `%s'. Run eg. `fdp -Tsvg -O %s'.", |
| 150 | chroot_filename, chroot_filename); |
| 151 | } |
| 152 | |
| 153 | vec_free (nodes); |
| 154 | vec_free (chroot_filename); |
| 155 | vec_free (nodes); |
| 156 | if (fd >= 0) |
| 157 | close (fd); |
| 158 | return error; |
| 159 | } |
| 160 | |
| 161 | /* *INDENT-OFF* */ |
| 162 | VLIB_CLI_COMMAND (show_node_graphviz_command, static) = { |
| 163 | .path = "show vlib graphviz", |
| 164 | .short_help = "Dump packet processing node graph as a graphviz dotfile", |
| 165 | .function = show_node_graphviz, |
| 166 | }; |
| 167 | /* *INDENT-ON* */ |
| 168 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 169 | static u8 * |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 170 | format_vlib_node_state (u8 * s, va_list * va) |
| 171 | { |
| 172 | vlib_main_t *vm = va_arg (*va, vlib_main_t *); |
| 173 | vlib_node_t *n = va_arg (*va, vlib_node_t *); |
| 174 | char *state; |
| 175 | |
| 176 | state = "active"; |
| 177 | if (n->type == VLIB_NODE_TYPE_PROCESS) |
| 178 | { |
| 179 | vlib_process_t *p = vlib_get_process_from_node (vm, n); |
| 180 | |
| 181 | switch (p->flags & (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK |
| 182 | | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT)) |
| 183 | { |
| 184 | default: |
| 185 | if (!(p->flags & VLIB_PROCESS_IS_RUNNING)) |
| 186 | state = "done"; |
| 187 | break; |
| 188 | |
| 189 | case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK: |
| 190 | state = "time wait"; |
| 191 | break; |
| 192 | |
| 193 | case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT: |
| 194 | state = "event wait"; |
| 195 | break; |
| 196 | |
| 197 | case (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK): |
| 198 | state = |
| 199 | "any wait"; |
| 200 | break; |
| 201 | } |
| 202 | } |
| 203 | else if (n->type != VLIB_NODE_TYPE_INTERNAL) |
| 204 | { |
| 205 | state = "polling"; |
| 206 | if (n->state == VLIB_NODE_STATE_DISABLED) |
| 207 | state = "disabled"; |
| 208 | else if (n->state == VLIB_NODE_STATE_INTERRUPT) |
| 209 | state = "interrupt wait"; |
| 210 | } |
| 211 | |
| 212 | return format (s, "%s", state); |
| 213 | } |
| 214 | |
| 215 | static u8 * |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 216 | format_vlib_node_stats (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 217 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 218 | vlib_main_t *vm = va_arg (*va, vlib_main_t *); |
| 219 | vlib_node_t *n = va_arg (*va, vlib_node_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 220 | int max = va_arg (*va, int); |
| 221 | f64 v; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 222 | u8 *ns; |
| 223 | u8 *misc_info = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 224 | u64 c, p, l, d; |
| 225 | f64 x; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 226 | f64 maxc, maxcn; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 227 | u32 maxn; |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 228 | u32 indent; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 229 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 230 | if (!n) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 231 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 232 | if (max) |
Dave Barach | 4d1a866 | 2018-09-10 12:31:15 -0400 | [diff] [blame] | 233 | s = format (s, |
| 234 | "%=30s%=17s%=16s%=16s%=16s%=16s", |
| 235 | "Name", "Max Node Clocks", "Vectors at Max", |
| 236 | "Max Clocks", "Avg Clocks", "Avg Vectors/Call"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 237 | else |
Dave Barach | 4d1a866 | 2018-09-10 12:31:15 -0400 | [diff] [blame] | 238 | s = format (s, |
| 239 | "%=30s%=12s%=16s%=16s%=16s%=16s%=16s", |
| 240 | "Name", "State", "Calls", "Vectors", "Suspends", |
| 241 | "Clocks", "Vectors/Call"); |
Dave Barach | 4d1a866 | 2018-09-10 12:31:15 -0400 | [diff] [blame] | 242 | return s; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | indent = format_get_indent (s); |
| 246 | |
| 247 | l = n->stats_total.clocks - n->stats_last_clear.clocks; |
| 248 | c = n->stats_total.calls - n->stats_last_clear.calls; |
| 249 | p = n->stats_total.vectors - n->stats_last_clear.vectors; |
| 250 | d = n->stats_total.suspends - n->stats_last_clear.suspends; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 251 | maxc = (f64) n->stats_total.max_clock; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 252 | maxn = n->stats_total.max_clock_n; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 253 | if (n->stats_total.max_clock_n) |
| 254 | maxcn = (f64) n->stats_total.max_clock / (f64) maxn; |
| 255 | else |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 256 | maxcn = 0.0; |
| 257 | |
| 258 | /* Clocks per packet, per call or per suspend. */ |
| 259 | x = 0; |
| 260 | if (p > 0) |
| 261 | x = (f64) l / (f64) p; |
| 262 | else if (c > 0) |
| 263 | x = (f64) l / (f64) c; |
| 264 | else if (d > 0) |
| 265 | x = (f64) l / (f64) d; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 266 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 267 | if (c > 0) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 268 | v = (double) p / (double) c; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 269 | else |
| 270 | v = 0; |
| 271 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 272 | if (n->type == VLIB_NODE_TYPE_PROCESS) |
| 273 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 274 | vlib_process_t *p = vlib_get_process_from_node (vm, n); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 275 | |
| 276 | /* Show processes with events pending. This helps spot bugs where events are not |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 277 | being handled. */ |
| 278 | if (!clib_bitmap_is_zero (p->non_empty_event_type_bitmap)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 279 | misc_info = format (misc_info, "events pending, "); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 280 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 281 | ns = n->name; |
| 282 | |
| 283 | if (max) |
| 284 | s = format (s, "%-30v%=17.2e%=16d%=16.2e%=16.2e%=16.2e", |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 285 | ns, maxc, maxn, maxcn, x, v); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 286 | else |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 287 | s = format (s, "%-30v%=12U%16Ld%16Ld%16Ld%16.2e%16.2f", ns, |
| 288 | format_vlib_node_state, vm, n, c, p, d, x, v); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 289 | |
| 290 | if (ns != n->name) |
| 291 | vec_free (ns); |
| 292 | |
| 293 | if (misc_info) |
| 294 | { |
| 295 | s = format (s, "\n%U%v", format_white_space, indent + 4, misc_info); |
| 296 | vec_free (misc_info); |
| 297 | } |
| 298 | |
| 299 | return s; |
| 300 | } |
| 301 | |
| 302 | static clib_error_t * |
| 303 | show_node_runtime (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 304 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 305 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 306 | vlib_node_main_t *nm = &vm->node_main; |
| 307 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 308 | f64 time_now; |
| 309 | u32 node_index; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 310 | vlib_node_t ***node_dups = 0; |
| 311 | f64 *vectors_per_main_loop = 0; |
| 312 | f64 *last_vector_length_per_node = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 313 | |
| 314 | time_now = vlib_time_now (vm); |
| 315 | |
| 316 | if (unformat (input, "%U", unformat_vlib_node, vm, &node_index)) |
| 317 | { |
| 318 | n = vlib_get_node (vm, node_index); |
| 319 | vlib_node_sync_stats (vm, n); |
| 320 | vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, 0, 0); |
| 321 | vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, n, 0); |
| 322 | } |
| 323 | else |
| 324 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 325 | vlib_node_t **nodes; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 326 | uword i, j; |
| 327 | f64 dt; |
| 328 | u64 n_input, n_output, n_drop, n_punt; |
| 329 | u64 n_internal_vectors, n_internal_calls; |
| 330 | u64 n_clocks, l, v, c, d; |
| 331 | int brief = 1; |
| 332 | int max = 0; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 333 | vlib_main_t **stat_vms = 0, *stat_vm; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 334 | |
| 335 | /* Suppress nodes with zero calls since last clear */ |
| 336 | if (unformat (input, "brief") || unformat (input, "b")) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 337 | brief = 1; |
| 338 | if (unformat (input, "verbose") || unformat (input, "v")) |
| 339 | brief = 0; |
| 340 | if (unformat (input, "max") || unformat (input, "m")) |
| 341 | max = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 342 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 343 | for (i = 0; i < vec_len (vlib_mains); i++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 344 | { |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 345 | stat_vm = vlib_mains[i]; |
| 346 | if (stat_vm) |
| 347 | vec_add1 (stat_vms, stat_vm); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 348 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 349 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 350 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 351 | * Barrier sync across stats scraping. |
| 352 | * Otherwise, the counts will be grossly inaccurate. |
| 353 | */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 354 | vlib_worker_thread_barrier_sync (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 355 | |
| 356 | for (j = 0; j < vec_len (stat_vms); j++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 357 | { |
| 358 | stat_vm = stat_vms[j]; |
| 359 | nm = &stat_vm->node_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 360 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 361 | for (i = 0; i < vec_len (nm->nodes); i++) |
| 362 | { |
| 363 | n = nm->nodes[i]; |
| 364 | vlib_node_sync_stats (stat_vm, n); |
| 365 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 366 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 367 | nodes = vec_dup (nm->nodes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 368 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 369 | vec_add1 (node_dups, nodes); |
| 370 | vec_add1 (vectors_per_main_loop, |
| 371 | vlib_last_vectors_per_main_loop_as_f64 (stat_vm)); |
| 372 | vec_add1 (last_vector_length_per_node, |
| 373 | vlib_last_vector_length_per_node (stat_vm)); |
| 374 | } |
| 375 | vlib_worker_thread_barrier_release (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 376 | |
| 377 | |
| 378 | for (j = 0; j < vec_len (stat_vms); j++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 379 | { |
| 380 | stat_vm = stat_vms[j]; |
| 381 | nodes = node_dups[j]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 382 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 383 | vec_sort_with_function (nodes, node_cmp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 384 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 385 | n_input = n_output = n_drop = n_punt = n_clocks = 0; |
| 386 | n_internal_vectors = n_internal_calls = 0; |
| 387 | for (i = 0; i < vec_len (nodes); i++) |
| 388 | { |
| 389 | n = nodes[i]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 390 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 391 | l = n->stats_total.clocks - n->stats_last_clear.clocks; |
| 392 | n_clocks += l; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 393 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 394 | v = n->stats_total.vectors - n->stats_last_clear.vectors; |
| 395 | c = n->stats_total.calls - n->stats_last_clear.calls; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 396 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 397 | switch (n->type) |
| 398 | { |
| 399 | default: |
| 400 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 401 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 402 | case VLIB_NODE_TYPE_INTERNAL: |
| 403 | n_output += (n->flags & VLIB_NODE_FLAG_IS_OUTPUT) ? v : 0; |
| 404 | n_drop += (n->flags & VLIB_NODE_FLAG_IS_DROP) ? v : 0; |
| 405 | n_punt += (n->flags & VLIB_NODE_FLAG_IS_PUNT) ? v : 0; |
| 406 | if (!(n->flags & VLIB_NODE_FLAG_IS_OUTPUT)) |
| 407 | { |
| 408 | n_internal_vectors += v; |
| 409 | n_internal_calls += c; |
| 410 | } |
| 411 | if (n->flags & VLIB_NODE_FLAG_IS_HANDOFF) |
| 412 | n_input += v; |
| 413 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 414 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 415 | case VLIB_NODE_TYPE_INPUT: |
| 416 | n_input += v; |
| 417 | break; |
| 418 | } |
| 419 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 420 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 421 | if (vec_len (vlib_mains) > 1) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 422 | { |
| 423 | vlib_worker_thread_t *w = vlib_worker_threads + j; |
| 424 | if (j > 0) |
| 425 | vlib_cli_output (vm, "---------------"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 426 | |
Mohsin Kazmi | 5d64c78 | 2018-09-11 20:27:09 +0200 | [diff] [blame] | 427 | if (w->cpu_id > -1) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 428 | vlib_cli_output (vm, "Thread %d %s (lcore %u)", j, w->name, |
Mohsin Kazmi | 5d64c78 | 2018-09-11 20:27:09 +0200 | [diff] [blame] | 429 | w->cpu_id); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 430 | else |
| 431 | vlib_cli_output (vm, "Thread %d %s", j, w->name); |
| 432 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 433 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 434 | dt = time_now - nm->time_last_runtime_stats_clear; |
| 435 | vlib_cli_output |
| 436 | (vm, |
| 437 | "Time %.1f, average vectors/node %.2f, last %d main loops %.2f per node %.2f" |
| 438 | "\n vector rates in %.4e, out %.4e, drop %.4e, punt %.4e", |
| 439 | dt, |
| 440 | (n_internal_calls > 0 |
| 441 | ? (f64) n_internal_vectors / (f64) n_internal_calls |
| 442 | : 0), |
| 443 | 1 << VLIB_LOG2_MAIN_LOOPS_PER_STATS_UPDATE, |
| 444 | vectors_per_main_loop[j], |
| 445 | last_vector_length_per_node[j], |
| 446 | (f64) n_input / dt, |
| 447 | (f64) n_output / dt, (f64) n_drop / dt, (f64) n_punt / dt); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 448 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 449 | vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm, 0, max); |
| 450 | for (i = 0; i < vec_len (nodes); i++) |
| 451 | { |
| 452 | c = |
| 453 | nodes[i]->stats_total.calls - |
| 454 | nodes[i]->stats_last_clear.calls; |
| 455 | d = |
| 456 | nodes[i]->stats_total.suspends - |
| 457 | nodes[i]->stats_last_clear.suspends; |
| 458 | if (c || d || !brief) |
| 459 | { |
| 460 | vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm, |
| 461 | nodes[i], max); |
| 462 | } |
| 463 | } |
| 464 | vec_free (nodes); |
| 465 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 466 | vec_free (stat_vms); |
| 467 | vec_free (node_dups); |
| 468 | vec_free (vectors_per_main_loop); |
| 469 | vec_free (last_vector_length_per_node); |
| 470 | } |
| 471 | |
| 472 | return 0; |
| 473 | } |
| 474 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 475 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 476 | VLIB_CLI_COMMAND (show_node_runtime_command, static) = { |
| 477 | .path = "show runtime", |
| 478 | .short_help = "Show packet processing runtime", |
| 479 | .function = show_node_runtime, |
| 480 | .is_mp_safe = 1, |
| 481 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 482 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 483 | |
| 484 | static clib_error_t * |
| 485 | clear_node_runtime (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 486 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 487 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 488 | vlib_node_main_t *nm; |
| 489 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 490 | int i, j; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 491 | vlib_main_t **stat_vms = 0, *stat_vm; |
| 492 | vlib_node_runtime_t *r; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 493 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 494 | for (i = 0; i < vec_len (vlib_mains); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 495 | { |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 496 | stat_vm = vlib_mains[i]; |
| 497 | if (stat_vm) |
| 498 | vec_add1 (stat_vms, stat_vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 499 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 500 | |
| 501 | vlib_worker_thread_barrier_sync (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 502 | |
| 503 | for (j = 0; j < vec_len (stat_vms); j++) |
| 504 | { |
| 505 | stat_vm = stat_vms[j]; |
| 506 | nm = &stat_vm->node_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 507 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 508 | for (i = 0; i < vec_len (nm->nodes); i++) |
| 509 | { |
| 510 | n = nm->nodes[i]; |
| 511 | vlib_node_sync_stats (stat_vm, n); |
| 512 | n->stats_last_clear = n->stats_total; |
| 513 | |
| 514 | r = vlib_node_get_runtime (stat_vm, n->index); |
| 515 | r->max_clock = 0; |
| 516 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 517 | /* Note: input/output rates computed using vlib_global_main */ |
| 518 | nm->time_last_runtime_stats_clear = vlib_time_now (vm); |
| 519 | } |
| 520 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 521 | vlib_worker_thread_barrier_release (vm); |
| 522 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 523 | vec_free (stat_vms); |
| 524 | |
| 525 | return 0; |
| 526 | } |
| 527 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 528 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 529 | VLIB_CLI_COMMAND (clear_node_runtime_command, static) = { |
| 530 | .path = "clear runtime", |
| 531 | .short_help = "Clear packet processing runtime statistics", |
| 532 | .function = clear_node_runtime, |
| 533 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 534 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 535 | |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 536 | static clib_error_t * |
| 537 | show_node (vlib_main_t * vm, unformat_input_t * input, |
| 538 | vlib_cli_command_t * cmd) |
| 539 | { |
| 540 | unformat_input_t _line_input, *line_input = &_line_input; |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame] | 541 | clib_error_t *error = 0; |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 542 | vlib_node_main_t *nm = &vm->node_main; |
| 543 | vlib_node_t *n; |
| 544 | u8 *s = 0, *s2 = 0; |
| 545 | u32 i, node_index = ~0; |
| 546 | char *type_str; |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame] | 547 | u8 valid_node_name = 0; |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 548 | |
| 549 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 550 | return 0; |
| 551 | |
| 552 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 553 | { |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame] | 554 | if (unformat (line_input, "index %u", &node_index)) |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 555 | ; |
| 556 | else |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame] | 557 | if (unformat (line_input, "%U", unformat_vlib_node, vm, &node_index)) |
| 558 | valid_node_name = 1; |
| 559 | else if (!valid_node_name) |
| 560 | error = clib_error_return (0, "unknown node name: '%U'", |
| 561 | format_unformat_error, line_input); |
| 562 | else |
| 563 | error = clib_error_return (0, "unknown input '%U'", |
| 564 | format_unformat_error, line_input); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 565 | } |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame] | 566 | |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 567 | unformat_free (line_input); |
| 568 | |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame] | 569 | if (error) |
| 570 | return error; |
| 571 | |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 572 | if (node_index >= vec_len (vm->node_main.nodes)) |
| 573 | return clib_error_return (0, "please specify valid node"); |
| 574 | |
| 575 | n = vlib_get_node (vm, node_index); |
| 576 | vlib_node_sync_stats (vm, n); |
| 577 | |
| 578 | switch (n->type) |
| 579 | { |
| 580 | case VLIB_NODE_TYPE_INTERNAL: |
| 581 | type_str = "internal"; |
| 582 | break; |
| 583 | case VLIB_NODE_TYPE_INPUT: |
| 584 | type_str = "input"; |
| 585 | break; |
| 586 | case VLIB_NODE_TYPE_PRE_INPUT: |
| 587 | type_str = "pre-input"; |
| 588 | break; |
| 589 | case VLIB_NODE_TYPE_PROCESS: |
| 590 | type_str = "process"; |
| 591 | break; |
| 592 | default: |
| 593 | type_str = "unknown"; |
| 594 | } |
| 595 | |
| 596 | if (n->sibling_of) |
| 597 | s = format (s, ", sibling-of %s", n->sibling_of); |
| 598 | |
| 599 | vlib_cli_output (vm, "node %s, type %s, state %U, index %d%v\n", |
| 600 | n->name, type_str, format_vlib_node_state, vm, n, |
| 601 | n->index, s); |
| 602 | vec_reset_length (s); |
| 603 | |
| 604 | if (n->node_fn_registrations) |
| 605 | { |
| 606 | vlib_node_fn_registration_t *fnr = n->node_fn_registrations; |
| 607 | while (fnr) |
| 608 | { |
| 609 | if (vec_len (s) == 0) |
| 610 | s = format (s, "\n %-15s %=8s %6s", |
| 611 | "Name", "Priority", "Active"); |
| 612 | s = format (s, "\n %-15s %=8u %=6s", fnr->name, fnr->priority, |
| 613 | fnr->function == n->function ? "yes" : ""); |
| 614 | fnr = fnr->next_registration; |
| 615 | } |
| 616 | } |
| 617 | else |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 618 | s = format (s, "\n default only"); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 619 | vlib_cli_output (vm, " node function variants:%v\n", s); |
| 620 | vec_reset_length (s); |
| 621 | |
| 622 | for (i = 0; i < vec_len (n->next_nodes); i++) |
| 623 | { |
| 624 | vlib_node_t *pn; |
| 625 | if (n->next_nodes[i] == VLIB_INVALID_NODE_INDEX) |
| 626 | continue; |
| 627 | |
| 628 | pn = vec_elt (nm->nodes, n->next_nodes[i]); |
| 629 | |
| 630 | if (vec_len (s) == 0) |
| 631 | s = format (s, "\n %10s %10s %=30s %8s", |
| 632 | "next-index", "node-index", "Node", "Vectors"); |
| 633 | |
| 634 | s = format (s, "\n %=10u %=10u %-30v %=8llu", i, n->next_nodes[i], |
| 635 | pn->name, vec_elt (n->n_vectors_by_next_node, i)); |
| 636 | } |
| 637 | |
| 638 | if (vec_len (s) == 0) |
| 639 | s = format (s, "\n none"); |
| 640 | vlib_cli_output (vm, "\n next nodes:%v\n", s); |
| 641 | vec_reset_length (s); |
| 642 | |
| 643 | if (n->type == VLIB_NODE_TYPE_INTERNAL) |
| 644 | { |
| 645 | int j = 0; |
| 646 | /* *INDENT-OFF* */ |
| 647 | clib_bitmap_foreach (i, n->prev_node_bitmap, ({ |
| 648 | vlib_node_t *pn = vlib_get_node (vm, i); |
| 649 | if (j++ % 3 == 0) |
| 650 | s = format (s, "\n "); |
| 651 | s2 = format (s2, "%v (%u)", pn->name, i); |
| 652 | s = format (s, "%-35v", s2); |
| 653 | vec_reset_length (s2); |
| 654 | })); |
| 655 | /* *INDENT-ON* */ |
| 656 | |
| 657 | if (vec_len (s) == 0) |
| 658 | s = format (s, "\n none"); |
| 659 | vlib_cli_output (vm, "\n known previous nodes:%v\n", s); |
| 660 | vec_reset_length (s); |
| 661 | } |
| 662 | |
| 663 | vec_free (s); |
| 664 | vec_free (s2); |
| 665 | return 0; |
| 666 | } |
| 667 | |
| 668 | /* *INDENT-OFF* */ |
| 669 | VLIB_CLI_COMMAND (show_node_command, static) = { |
| 670 | .path = "show node", |
| 671 | .short_help = "show node [index] <node-name | node-index>", |
| 672 | .function = show_node, |
| 673 | }; |
| 674 | |
| 675 | static clib_error_t * |
| 676 | set_node_fn(vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
| 677 | { |
| 678 | unformat_input_t _line_input, *line_input = &_line_input; |
| 679 | u32 node_index; |
| 680 | vlib_node_t *n; |
| 681 | clib_error_t *err = 0; |
| 682 | vlib_node_fn_registration_t *fnr; |
| 683 | u8 *variant = 0; |
| 684 | |
| 685 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 686 | return 0; |
| 687 | |
| 688 | if (!unformat (line_input, "%U", unformat_vlib_node, vm, &node_index)) |
| 689 | { |
| 690 | err = clib_error_return (0, "please specify valid node name"); |
| 691 | goto done; |
| 692 | } |
| 693 | |
| 694 | if (!unformat (line_input, "%s", &variant)) |
| 695 | { |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 696 | err = clib_error_return (0, "please specify node functional variant"); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 697 | goto done; |
| 698 | } |
| 699 | |
| 700 | n = vlib_get_node (vm, node_index); |
| 701 | |
| 702 | if (n->node_fn_registrations == 0) |
| 703 | { |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 704 | err = clib_error_return (0, "node doesn't have functional variants"); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 705 | goto done; |
| 706 | } |
| 707 | |
| 708 | fnr = n->node_fn_registrations; |
| 709 | vec_add1 (variant, 0); |
| 710 | |
| 711 | while (fnr) |
| 712 | { |
| 713 | if (!strncmp (fnr->name, (char *) variant, vec_len (variant) - 1)) |
| 714 | { |
| 715 | int i; |
| 716 | |
| 717 | n->function = fnr->function; |
| 718 | |
| 719 | for (i = 0; i < vec_len (vlib_mains); i++) |
| 720 | { |
| 721 | vlib_node_runtime_t *nrt; |
| 722 | nrt = vlib_node_get_runtime (vlib_mains[i], n->index); |
| 723 | nrt->function = fnr->function; |
| 724 | } |
| 725 | goto done; |
| 726 | } |
| 727 | fnr = fnr->next_registration; |
| 728 | } |
| 729 | |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 730 | err = clib_error_return (0, "node functional variant '%s' not found", variant); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 731 | |
| 732 | done: |
| 733 | vec_free (variant); |
| 734 | unformat_free (line_input); |
| 735 | return err; |
| 736 | } |
| 737 | |
| 738 | /* *INDENT-OFF* */ |
| 739 | VLIB_CLI_COMMAND (set_node_fn_command, static) = { |
| 740 | .path = "set node function", |
| 741 | .short_help = "set node function <node-name> <variant-name>", |
| 742 | .function = set_node_fn, |
| 743 | }; |
| 744 | /* *INDENT-ON* */ |
| 745 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 746 | /* Dummy function to get us linked in. */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 747 | void |
| 748 | vlib_node_cli_reference (void) |
| 749 | { |
| 750 | } |
| 751 | |
| 752 | /* |
| 753 | * fd.io coding-style-patch-verification: ON |
| 754 | * |
| 755 | * Local Variables: |
| 756 | * eval: (c-set-style "gnu") |
| 757 | * End: |
| 758 | */ |