FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
node_format.c
Go to the documentation of this file.
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_format.c: node formatting
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 
40 #include <vlib/vlib.h>
41 
42 u8 *
43 format_vlib_node_graph (u8 * s, va_list * va)
44 {
45  vlib_node_main_t *nm = va_arg (*va, vlib_node_main_t *);
46  vlib_node_t *n = va_arg (*va, vlib_node_t *);
47  int i, j;
48  u32 indent;
49  typedef struct
50  {
51  u32 next_node;
52  u32 next_slot;
53  u32 prev_node;
54  } tmp_t;
55  tmp_t *tmps = 0;
56  tmp_t empty = {.next_node = ~0,.prev_node = ~0 };
57 
58  if (!n)
59  return format (s, "%=26s%=26s%=26s", "Name", "Next", "Previous");
60 
61  s = format (s, "%-26v", n->name);
62 
63  indent = format_get_indent (s);
64 
65  for (i = j = 0; i < vec_len (n->next_nodes); i++)
66  {
68  continue;
69  vec_validate_init_empty (tmps, j, empty);
70  tmps[j].next_node = n->next_nodes[i];
71  tmps[j].next_slot = i;
72  j++;
73  }
74 
75  j = 0;
76  /* *INDENT-OFF* */
78  vec_validate_init_empty (tmps, j, empty);
79  tmps[j].prev_node = i;
80  j++;
81  }
82  /* *INDENT-ON* */
83 
84  for (i = 0; i < vec_len (tmps); i++)
85  {
86  if (i > 0)
87  s = format (s, "\n%U", format_white_space, indent);
88 
89  if (tmps[i].next_node != ~0)
90  {
91  vlib_node_t *x;
92  u8 *t = 0;
93 
94  x = vec_elt (nm->nodes, tmps[i].next_node);
95  t = format (t, "%v [%d]", x->name, tmps[i].next_slot);
96  s = format (s, "%=26v", t);
97  vec_free (t);
98  }
99  else
100  s = format (s, "%26s", "");
101 
102  if (tmps[i].prev_node != ~0)
103  {
104  vlib_node_t *x;
105  x = vec_elt (nm->nodes, tmps[i].prev_node);
106  s = format (s, "%=26v", x->name);
107  }
108  }
109 
110  vec_free (tmps);
111 
112  return s;
113 }
114 
115 u8 *
116 format_vlib_node_and_next (u8 * s, va_list * va)
117 {
118  vlib_main_t *vm = va_arg (*va, vlib_main_t *);
119  vlib_node_t *n = va_arg (*va, vlib_node_t *);
120  u32 next_index = va_arg (*va, u32);
121  vlib_node_t *n_next;
122  u32 *ni;
123 
125  n_next = vlib_get_node (vm, ni[0]);
126  return format (s, "%v -> %v", n->name, n_next->name);
127 }
128 
129 u8 *
130 format_vlib_node_name (u8 * s, va_list * va)
131 {
132  vlib_main_t *vm = va_arg (*va, vlib_main_t *);
133  u32 node_index = va_arg (*va, u32);
135 
136  return format (s, "%v", n->name);
137 }
138 
139 u8 *
140 format_vlib_next_node_name (u8 * s, va_list * va)
141 {
142  vlib_main_t *vm = va_arg (*va, vlib_main_t *);
143  u32 node_index = va_arg (*va, u32);
144  u32 next_index = va_arg (*va, u32);
146  return format (s, "%v", next->name);
147 }
148 
149 /* Parse node name -> node index. */
150 uword
151 unformat_vlib_node (unformat_input_t * input, va_list * args)
152 {
153  vlib_main_t *vm = va_arg (*args, vlib_main_t *);
154  u32 *result = va_arg (*args, u32 *);
155 
157  vm->node_main.node_by_name, result);
158 }
159 
160 u8 *
161 format_vlib_time (u8 * s, va_list * va)
162 {
163  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
164  f64 time = va_arg (*va, f64);
165  return format (s, "%12.4f", time);
166 }
167 
168 u8 *
169 format_vlib_cpu_time (u8 * s, va_list * va)
170 {
171  vlib_main_t *vm = va_arg (*va, vlib_main_t *);
172  u64 cpu_time = va_arg (*va, u64);
173  f64 dt;
174 
175  dt =
176  (cpu_time -
178  return format (s, "%U", format_vlib_time, vm, dt);
179 }
180 
181 uword
183 {
185  u32 *march_variant = va_arg (*args, u32 *);
186  uword *p;
187  u8 *str = 0;
188 
189  if (unformat (input, "%s", &str) == 0)
190  return 0;
191 
193 
194  vec_free (str);
195 
196  if (p)
197  *march_variant = p[0];
198 
199  return p ? 1 : 0;
200 }
201 
202 /*
203  * fd.io coding-style-patch-verification: ON
204  *
205  * Local Variables:
206  * eval: (c-set-style "gnu")
207  * End:
208  */
vlib.h
vlib_node_main_t::node_by_name
uword * node_by_name
Definition: node.h:671
unformat_vlib_node
uword unformat_vlib_node(unformat_input_t *input, va_list *args)
Definition: node_format.c:151
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
format_vlib_next_node_name
u8 * format_vlib_next_node_name(u8 *s, va_list *va)
Definition: node_format.c:140
vlib_main_t::clib_time
clib_time_t clib_time
Definition: main.h:106
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
VLIB_INVALID_NODE_INDEX
#define VLIB_INVALID_NODE_INDEX
Definition: node.h:365
next
u16 * next
Definition: nat44_ei_out2in.c:718
vlib_main_t::node_main
vlib_node_main_t node_main
Definition: main.h:171
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
node_index
node node_index
Definition: interface_output.c:420
format_vlib_node_and_next
u8 * format_vlib_node_and_next(u8 *s, va_list *va)
Definition: node_format.c:116
unformat_input_t
struct _unformat_input_t unformat_input_t
clib_time_t::seconds_per_clock
f64 seconds_per_clock
Definition: time.h:58
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
vec_elt
#define vec_elt(v, i)
Get vector value at index i.
Definition: vec_bootstrap.h:210
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
format_vlib_cpu_time
u8 * format_vlib_cpu_time(u8 *s, va_list *va)
Definition: node_format.c:169
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
unformat_vlib_node_variant
uword unformat_vlib_node_variant(unformat_input_t *input, va_list *args)
Definition: node_format.c:182
uword
u64 uword
Definition: types.h:112
hash_get
#define hash_get(h, key)
Definition: hash.h:249
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
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
f64
double f64
Definition: types.h:142
clib_time_t::init_cpu_time
u64 init_cpu_time
Definition: time.h:61
vlib_node_main_t::node_fn_march_variant_by_suffix
uword * node_fn_march_variant_by_suffix
Definition: node.h:742
format_vlib_node_graph
u8 * format_vlib_node_graph(u8 *s, va_list *va)
Definition: node_format.c:43
vlib_get_next_node
static vlib_node_t * vlib_get_next_node(vlib_main_t *vm, u32 node_index, u32 next_index)
Get vlib node by graph arc (next) index.
Definition: node_funcs.h:99
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
u64
unsigned long u64
Definition: types.h:89
format
description fragment has unexpected format
Definition: map.api:433
format_get_indent
static u32 format_get_indent(u8 *s)
Definition: format.h:72
vlib_node_t::prev_node_bitmap
uword * prev_node_bitmap
Definition: node.h:342
vec_validate_init_empty
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header,...
Definition: vec.h:570
u32
unsigned int u32
Definition: types.h:88
format_vlib_time
u8 * format_vlib_time(u8 *s, va_list *va)
Definition: node_format.c:161
nm
nat44_ei_main_t * nm
Definition: nat44_ei_hairpinning.c:413
format_vlib_node_name
u8 * format_vlib_node_name(u8 *s, va_list *va)
Definition: node_format.c:130
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
u8
unsigned char u8
Definition: types.h:56
vlib_node_t::next_nodes
u32 * next_nodes
Definition: node.h:325
unformat_hash_vec_string
unformat_function_t unformat_hash_vec_string
Definition: hash.h:717
vlib_node_main_t
Definition: node.h:665
clib_bitmap_foreach
#define clib_bitmap_foreach(i, ai)
Macro to iterate across set bits in a bitmap.
Definition: bitmap.h:361
vlib_node_t::name
u8 * name
Definition: node.h:253
format_white_space
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129