1 /* Hey Emacs use -*- mode: C -*- */
3 * Copyright 2020 Rubicon Communications, LLC.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <sys/socket.h>
21 #include <vnet/vnet.h>
22 #include <vnet/plugin/plugin.h>
24 #include <vlibapi/api.h>
25 #include <vlibmemory/api.h>
26 #include <vpp/app/version.h>
27 #include <vnet/format_fns.h>
29 #include <tracedump/graph.h>
30 #include <tracedump/graph.api_enum.h>
31 #include <tracedump/graph.api_types.h>
33 static void graph_node_print (vlib_main_t *vm, vlib_node_t *n, bool want_arcs)
35 vlib_cli_output (vm, "Node (%4d): %v, Flags: 0x%x\n",
36 n->index, n->name, n->flags);
41 int n_arcs = vec_len (n->next_nodes);
42 for (i = 0; i < n_arcs; ++i)
44 vlib_cli_output (vm, " next: %d\n", n->next_nodes[i]);
50 node_cmp (void *a1, void *a2)
52 vlib_node_t **n1 = a1;
53 vlib_node_t **n2 = a2;
55 return vec_cmp (n1[0]->name, n2[0]->name);
59 graph_node_show_cmd (vlib_main_t * vm,
60 unformat_input_t * input, vlib_cli_command_t * cmd)
62 vlib_node_main_t *nm = &vm->node_main;
75 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
77 if (unformat (input, "node %d", &index))
78 n = vlib_get_node (vm, index);
79 else if (unformat (input, "node %s", &name))
80 n = vlib_get_node_by_name (vm, name);
82 else if (unformat (input, "want_arcs"))
85 else if (unformat (input, "trace_supported"))
86 flags |= NODE_FLAG_TRACE_SUPPORTED;
87 else if (unformat (input, "input"))
88 flags |= NODE_FLAG_TRACE_SUPPORTED;
89 else if (unformat (input, "drop"))
90 flags |= NODE_FLAG_IS_DROP;
91 else if (unformat (input, "output"))
92 flags |= NODE_FLAG_IS_OUTPUT;
93 else if (unformat (input, "punt"))
94 flags |= NODE_FLAG_IS_PUNT;
95 else if (unformat (input, "handoff"))
96 flags |= NODE_FLAG_IS_HANDOFF;
97 else if (unformat (input, "no_free"))
98 flags |= NODE_FLAG_FRAME_NO_FREE_AFTER_DISPATCH;
99 else if (unformat (input, "polling"))
100 flags |= NODE_FLAG_SWITCH_FROM_INTERRUPT_TO_POLLING_MODE;
101 else if (unformat (input, "interrupt"))
102 flags |= NODE_FLAG_SWITCH_FROM_POLLING_TO_INTERRUPT_MODE;
105 return clib_error_return (0, "unknown input '%U'",
106 format_unformat_error, input);
110 * Just one node requested? Ignore flags.
113 graph_node_print (vm, n, want_arcs);
117 vlib_node_t **nodes = vec_dup (nm->nodes);
120 vec_sort_with_function (nodes, node_cmp);
122 for (i = 0; i < vec_len (nodes); ++i)
124 if (flags == 0 || (flags & nodes[i]->flags))
126 graph_node_print (vm, nodes[i], want_arcs);
135 VLIB_CLI_COMMAND (graph_node_show_command, static) = {
136 .path = "show graph",
137 .short_help = "show graph [node <index>|<name>] [want_arcs] [input|trace_supported] [drop] [output] [punt] [handoff] [no_free] [polling] [interrupt]",
138 .function = graph_node_show_cmd,
144 * eval: (c-set-style "gnu")