FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
graph_cli.c
Go to the documentation of this file.
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 #include <linux/if.h>
20 
21 #include <vnet/vnet.h>
22 #include <vnet/plugin/plugin.h>
23 
24 #include <vlibapi/api.h>
25 #include <vlibmemory/api.h>
26 #include <vpp/app/version.h>
27 #include <vnet/format_fns.h>
28 
29 #include <tracedump/graph.h>
30 #include <tracedump/graph.api_enum.h>
31 #include <tracedump/graph.api_types.h>
32 
33 static void graph_node_print (vlib_main_t *vm, vlib_node_t *n, bool want_arcs)
34 {
35  vlib_cli_output (vm, "Node (%4d): %v, Flags: 0x%x\n",
36  n->index, n->name, n->flags);
37  if (!want_arcs)
38  return;
39 
40  int i;
41  int n_arcs = vec_len (n->next_nodes);
42  for (i = 0; i < n_arcs; ++i)
43  {
44  vlib_cli_output (vm, " next: %d\n", n->next_nodes[i]);
45  }
46 }
47 
48 
49 static int
50 node_cmp (void *a1, void *a2)
51 {
52  vlib_node_t **n1 = a1;
53  vlib_node_t **n2 = a2;
54 
55  return vec_cmp (n1[0]->name, n2[0]->name);
56 }
57 
58 static clib_error_t *
60  unformat_input_t * input, vlib_cli_command_t * cmd)
61 {
63  vlib_node_t *n;
64  u32 index;
65  u8 *name;
66  u32 flags;
67  bool want_arcs;
68 
69  index = ~0;
70  name = 0;
71  flags = 0;
72  want_arcs = false;
73  n = 0;
74 
76  {
77  if (unformat (input, "node %d", &index))
78  n = vlib_get_node (vm, index);
79  else if (unformat (input, "node %v", &name))
81 
82  else if (unformat (input, "want_arcs"))
83  want_arcs = true;
84 
85  else if (unformat (input, "trace_supported"))
87  else if (unformat (input, "input"))
89  else if (unformat (input, "drop"))
91  else if (unformat (input, "output"))
93  else if (unformat (input, "punt"))
95  else if (unformat (input, "handoff"))
97  else if (unformat (input, "no_free"))
99  else if (unformat (input, "polling"))
101  else if (unformat (input, "interrupt"))
103 
104  else
105  return clib_error_return (0, "unknown input '%U'",
106  format_unformat_error, input);
107  }
108 
109  /*
110  * Just one node requested? Ignore flags.
111  */
112  if (n) {
113  graph_node_print (vm, n, want_arcs);
114  return 0;
115  }
116 
117  vlib_node_t **nodes = vec_dup (nm->nodes);
118  uword i;
119 
121 
122  for (i = 0; i < vec_len (nodes); ++i)
123  {
124  if (flags == 0 || (flags & nodes[i]->flags))
125  {
126  graph_node_print (vm, nodes[i], want_arcs);
127  }
128  }
129 
130  vec_free (nodes);
131 
132  return 0;
133 }
134 
135 /* *INDENT-OFF* */
137  .path = "show graph",
138  .short_help = "show graph [node <index>|<name>] [want_arcs] [input|trace_supported] [drop] [output] [punt] [handoff] [no_free] [polling] [interrupt]",
139  .function = graph_node_show_cmd,
140 };
141 /* *INDENT-ON* */
142 
143 
144 /*
145  * Local Variables:
146  * eval: (c-set-style "gnu")
147  * End:
148  */
api.h
graph_node_show_cmd
static clib_error_t * graph_node_show_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: graph_cli.c:59
name
string name[64]
Definition: fib.api:25
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
graph_node_show_command
static vlib_cli_command_t graph_node_show_command
(constructor) VLIB_CLI_COMMAND (graph_node_show_command)
Definition: graph_cli.c:136
vlib_node_t::flags
u16 flags
Definition: node.h:278
vlib_main_t::node_main
vlib_node_main_t node_main
Definition: main.h:173
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
NODE_FLAG_TRACE_SUPPORTED
@ NODE_FLAG_TRACE_SUPPORTED
Definition: graph.api:31
unformat_input_t
struct _unformat_input_t unformat_input_t
vec_cmp
#define vec_cmp(v1, v2)
Compare two vectors (only applicable to vectors of signed numbers).
Definition: vec.h:1033
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
vlib_node_t::index
u32 index
Definition: node.h:269
graph.h
vec_dup
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:444
graph_node_print
static void graph_node_print(vlib_main_t *vm, vlib_node_t *n, bool want_arcs)
Definition: graph_cli.c:33
NODE_FLAG_IS_OUTPUT
@ NODE_FLAG_IS_OUTPUT
Definition: graph.api:24
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
uword
u64 uword
Definition: types.h:112
vlib_get_node
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
Definition: node_funcs.h:86
NODE_FLAG_SWITCH_FROM_POLLING_TO_INTERRUPT_MODE
@ NODE_FLAG_SWITCH_FROM_POLLING_TO_INTERRUPT_MODE
Definition: graph.api:30
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
plugin.h
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
index
u32 index
Definition: flow_types.api:221
vlib_get_node_by_name
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
NODE_FLAG_IS_PUNT
@ NODE_FLAG_IS_PUNT
Definition: graph.api:26
format_fns.h
node_cmp
static int node_cmp(void *a1, void *a2)
Definition: graph_cli.c:50
u32
unsigned int u32
Definition: types.h:88
NODE_FLAG_IS_HANDOFF
@ NODE_FLAG_IS_HANDOFF
Definition: graph.api:27
NODE_FLAG_IS_DROP
@ NODE_FLAG_IS_DROP
Definition: graph.api:25
nm
nat44_ei_main_t * nm
Definition: nat44_ei_hairpinning.c:413
vec_sort_with_function
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:1097
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
NODE_FLAG_FRAME_NO_FREE_AFTER_DISPATCH
@ NODE_FLAG_FRAME_NO_FREE_AFTER_DISPATCH
Definition: graph.api:23
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
i
int i
Definition: flowhash_template.h:376
vlib_node_t::next_nodes
u32 * next_nodes
Definition: node.h:325
vlib_node_main_t
Definition: node.h:665
vnet.h
NODE_FLAG_SWITCH_FROM_INTERRUPT_TO_POLLING_MODE
@ NODE_FLAG_SWITCH_FROM_INTERRUPT_TO_POLLING_MODE
Definition: graph.api:29
vlib_cli_command_t
Definition: cli.h:92
vlib_node_t::name
u8 * name
Definition: node.h:253
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105