FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
trajectory.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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 /** \file
17  * Buffer trace trajectory utilities
18  */
19 
20 #include <vnet/vnet.h>
21 
22 /**
23  * Dump a trajectory trace, reasonably easy to call from gdb
24  */
25 void
27 {
28 #if VLIB_BUFFER_TRACE_TRAJECTORY > 0
29  vlib_node_main_t *vnm = &vm->node_main;
30  vlib_buffer_t *b;
31  u16 *trace;
32  u8 i;
33 
34  b = vlib_get_buffer (vm, bi);
35 
36  trace = vnet_buffer2 (b)->trajectory_trace;
37 
38  fformat (stderr, "Context trace for bi %d b 0x%llx, visited %d\n",
39  bi, b, vec_len (trace));
40 
41  for (i = 0; i < vec_len (trace); i++)
42  {
43  u32 node_index;
44 
45  node_index = trace[i];
46 
47  if (node_index >= vec_len (vnm->nodes))
48  {
49  fformat (stderr, "Skip bogus node index %d\n", node_index);
50  continue;
51  }
52 
53  fformat (stderr, "%v (%d)\n", vnm->nodes[node_index]->name, node_index);
54  }
55 #else
56  fformat (stderr, "in vlib/buffers.h, "
57  "#define VLIB_BUFFER_TRACE_TRAJECTORY 1\n");
58 
59 #endif
60 }
61 
62 #if VLIB_BUFFER_TRACE_TRAJECTORY > 0
63 
64 void
65 init_trajectory_trace (vlib_buffer_t * b)
66 {
67  if (!clib_mem_is_vec (vnet_buffer2 (b)->trajectory_trace))
68  {
69  vnet_buffer2 (b)->trajectory_trace = 0;
70  vec_validate (vnet_buffer2 (b)->trajectory_trace, 7);
71  }
72  _vec_len (vnet_buffer2 (b)->trajectory_trace) = 0;
73 }
74 
75 void
76 add_trajectory_trace (vlib_buffer_t * b, u32 node_index)
77 {
78  vec_add1 (vnet_buffer2 (b)->trajectory_trace, (u16) node_index);
79 }
80 
81 static clib_error_t *
82 trajectory_trace_init (vlib_main_t * vm)
83 {
84  vlib_buffer_trace_trajectory_cb = add_trajectory_trace;
85  vlib_buffer_trace_trajectory_init_cb = init_trajectory_trace;
86  return 0;
87 }
88 
89 VLIB_INIT_FUNCTION (trajectory_trace_init);
90 
91 #endif
92 
93 /*
94  * fd.io coding-style-patch-verification: ON
95  *
96  * Local Variables:
97  * eval: (c-set-style "gnu")
98  * End:
99  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
Definition: vlib_api_cli.c:889
#define vnet_buffer2(b)
Definition: buffer.h:424
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
int i
unsigned char u8
Definition: types.h:56
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
vlib_node_t ** nodes
Definition: node.h:699
unsigned int u32
Definition: types.h:88
unsigned short u16
Definition: types.h:57
word fformat(FILE *f, char *fmt,...)
Definition: format.c:462
u8 * name
Definition: node.h:264
void vnet_dump_trajectory_trace(vlib_main_t *vm, u32 bi)
Dump a trajectory trace, reasonably easy to call from gdb.
Definition: trajectory.c:26
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vlib_node_main_t node_main
Definition: main.h:158
VLIB buffer representation.
Definition: buffer.h:102
static void add_trajectory_trace(vlib_buffer_t *b, u32 node_index)
Definition: main.c:964
static uword clib_mem_is_vec(void *v)
Predicate function, says whether the supplied vector is a clib heap object.
Definition: vec.h:206
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85