octeon: add clear counters for port and queues
[vpp.git] / src / plugins / tracedump / graph_cli.c
1 /* Hey Emacs use -*- mode: C -*- */
2 /*
3  * Copyright 2020 Rubicon Communications, LLC.
4  *
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:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 #include <sys/socket.h>
19 #ifdef __linux__
20 #include <linux/if.h>
21 #else
22 #include <net/if.h>
23 #endif /* __linux__ */
24
25 #include <vnet/vnet.h>
26 #include <vnet/plugin/plugin.h>
27
28 #include <vlibapi/api.h>
29 #include <vlibmemory/api.h>
30 #include <vpp/app/version.h>
31 #include <vnet/format_fns.h>
32
33 #include <tracedump/graph.h>
34 #include <tracedump/graph.api_enum.h>
35 #include <tracedump/graph.api_types.h>
36
37 static void graph_node_print (vlib_main_t *vm, vlib_node_t *n, bool want_arcs)
38 {
39   vlib_cli_output (vm, "Node (%4d): %v, Flags: 0x%x\n",
40                    n->index, n->name, n->flags);
41   if (!want_arcs)
42     return;
43
44   int i;
45   int n_arcs = vec_len (n->next_nodes);
46   for (i = 0; i < n_arcs; ++i)
47     {
48       vlib_cli_output (vm, "    next: %d\n", n->next_nodes[i]);
49     }
50 }
51
52
53 static int
54 node_cmp (void *a1, void *a2)
55 {
56   vlib_node_t **n1 = a1;
57   vlib_node_t **n2 = a2;
58
59   return vec_cmp (n1[0]->name, n2[0]->name);
60 }
61
62 static clib_error_t *
63 graph_node_show_cmd (vlib_main_t * vm,
64                      unformat_input_t * input, vlib_cli_command_t * cmd)
65 {
66   vlib_node_main_t *nm = &vm->node_main;
67   vlib_node_t *n;
68   u32 index;
69   u8 *name;
70   u32 flags;
71   bool want_arcs;
72
73   index = ~0;
74   name = 0;
75   flags = 0;
76   want_arcs = false;
77   n = 0;
78
79   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
80     {
81       if (unformat (input, "node %d", &index))
82         n = vlib_get_node (vm, index);
83       else if (unformat (input, "node %s", &name))
84         n = vlib_get_node_by_name (vm, name);
85
86       else if (unformat (input, "want_arcs"))
87         want_arcs = true;
88
89       else if (unformat (input, "trace_supported"))
90         flags |= NODE_FLAG_TRACE_SUPPORTED;
91       else if (unformat (input, "input"))
92         flags |= NODE_FLAG_TRACE_SUPPORTED;
93       else if (unformat (input, "drop"))
94         flags |= NODE_FLAG_IS_DROP;
95       else if (unformat (input, "output"))
96         flags |= NODE_FLAG_IS_OUTPUT;
97       else if (unformat (input, "punt"))
98         flags |= NODE_FLAG_IS_PUNT;
99       else if (unformat (input, "handoff"))
100         flags |= NODE_FLAG_IS_HANDOFF;
101       else if (unformat (input, "no_free"))
102         flags |= NODE_FLAG_FRAME_NO_FREE_AFTER_DISPATCH;
103       else if (unformat (input, "polling"))
104         flags |= NODE_FLAG_SWITCH_FROM_INTERRUPT_TO_POLLING_MODE;
105       else if (unformat (input, "interrupt"))
106         flags |= NODE_FLAG_SWITCH_FROM_POLLING_TO_INTERRUPT_MODE;
107
108       else
109         return clib_error_return (0, "unknown input '%U'",
110                                   format_unformat_error, input);
111     }
112
113   /*
114    * Just one node requested?  Ignore flags.
115    */
116   if (n) {
117     graph_node_print (vm, n, want_arcs);
118     return 0;
119   }
120
121   vlib_node_t **nodes = vec_dup (nm->nodes);
122   uword i;
123
124   vec_sort_with_function (nodes, node_cmp);
125
126   for (i = 0; i < vec_len (nodes); ++i)
127     {
128       if (flags == 0 || (flags & nodes[i]->flags))
129         {
130           graph_node_print (vm, nodes[i], want_arcs);
131         }
132     }
133
134   vec_free (nodes);
135
136   return 0;
137 }
138
139 VLIB_CLI_COMMAND (graph_node_show_command, static) = {
140   .path = "show graph",
141   .short_help = "show graph [node <index>|<name>] [want_arcs] [input|trace_supported] [drop] [output] [punt] [handoff] [no_free] [polling] [interrupt]",
142   .function = graph_node_show_cmd,
143 };
144
145
146 /*
147  * Local Variables:
148  * eval: (c-set-style "gnu")
149  * End:
150  */