FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
handoff_trace.c
Go to the documentation of this file.
1 /*
2  * handoff_trace.c - used to generate handoff trace records
3  *
4  * Copyright (c) 2019 Cisco Systems and/or its affiliates.
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 #include <vlib/vlib.h>
18 #include <vnet/vnet.h>
19 #include <vnet/pg/pg.h>
20 #include <vppinfra/error.h>
21 
22 typedef struct
23 {
27 
28 /* packet trace format function */
29 static u8 *
30 format_handoff_trace (u8 * s, va_list * args)
31 {
32  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
33  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
34  handoff_trace_t *t = va_arg (*args, handoff_trace_t *);
35 
36  s = format (s, "HANDED-OFF: from thread %d trace index %d",
38  return s;
39 }
40 
42 
43 #define foreach_handoff_trace_error \
44 _(BUGS, "Warning: packets sent to the handoff trace node!")
45 
46 typedef enum
47 {
48 #define _(sym,str) HANDOFF_TRACE_ERROR_##sym,
50 #undef _
53 
54 static char *handoff_trace_error_strings[] = {
55 #define _(sym,string) string,
57 #undef _
58 };
59 
60 static uword
63 {
65 
66  vlib_node_increment_counter (vm, node->node_index,
67  HANDOFF_TRACE_ERROR_BUGS, frame->n_vectors);
68 
69  return frame->n_vectors;
70 }
71 
72 typedef enum
73 {
77 
78 /* *INDENT-OFF* */
80 {
81  .name = "handoff_trace",
83  .function = handoff_trace_node_fn,
84  .vector_size = sizeof (u32),
85  .format_trace = format_handoff_trace,
87  .n_next_nodes = HANDOFF_TRACE_N_NEXT,
88 
89  /* edit / add dispositions here */
90  .next_nodes = {
91  [HANDOFF_TRACE_NEXT_DROP] = "error-drop",
92  },
93 
95  .error_strings = handoff_trace_error_strings,
96 };
97 /* *INDENT-ON* */
98 
99 int
101 {
102  u32 prev_thread = vlib_buffer_get_trace_thread (b);
103  u32 prev_trace_index = vlib_buffer_get_trace_index (b);
104  handoff_trace_t *t;
107 
108  if (PREDICT_FALSE
110  (vm, node, 0 /* fake next frame index */ , b, 1 /* follow chain */ )))
111  return 0;
112 
113  t = vlib_add_trace (vm, node, b, sizeof (*t));
114  t->prev_thread = prev_thread;
115  t->prev_trace_index = prev_trace_index;
116  return 1;
117 }
118 
119 
120 /* *INDENT-ON* */
121 
122 /*
123  * fd.io coding-style-patch-verification: ON
124  *
125  * Local Variables:
126  * eval: (c-set-style "gnu")
127  * End:
128  */
vlib.h
HANDOFF_TRACE_N_ERROR
@ HANDOFF_TRACE_N_ERROR
Definition: handoff_trace.c:51
foreach_handoff_trace_error
#define foreach_handoff_trace_error
Definition: handoff_trace.c:43
vlib_buffer_free
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: buffer_funcs.h:982
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
handoff_trace_t
Definition: handoff_trace.c:22
pg.h
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
handoff_trace_t::prev_thread
u32 prev_thread
Definition: handoff_trace.c:24
HANDOFF_TRACE_NEXT_DROP
@ HANDOFF_TRACE_NEXT_DROP
Definition: handoff_trace.c:74
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vlib_add_handoff_trace
int vlib_add_handoff_trace(vlib_main_t *vm, vlib_buffer_t *b)
Definition: handoff_trace.c:100
vlib_buffer_get_trace_thread
static u32 vlib_buffer_get_trace_thread(vlib_buffer_t *b)
Extract the thread id from a trace handle.
Definition: buffer.h:404
vlib_frame_t
Definition: node.h:372
handoff_trace_error_t
handoff_trace_error_t
Definition: handoff_trace.c:46
error.h
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
uword
u64 uword
Definition: types.h:112
handoff_trace_node_fn
static uword handoff_trace_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: handoff_trace.c:61
vlib_node_increment_counter
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1244
VLIB_NODE_FLAG_TRACE_SUPPORTED
#define VLIB_NODE_FLAG_TRACE_SUPPORTED
Definition: node.h:295
handoff_trace_t::prev_trace_index
u32 prev_trace_index
Definition: handoff_trace.c:25
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
handoff_trace_node
static vlib_node_registration_t handoff_trace_node
(constructor) VLIB_REGISTER_NODE (handoff_trace_node)
Definition: handoff_trace.c:41
tplaceholder_next_t
tplaceholder_next_t
Definition: handoff_trace.c:72
handoff_trace_error_strings
static char * handoff_trace_error_strings[]
Definition: handoff_trace.c:54
format
description fragment has unexpected format
Definition: map.api:433
u32
unsigned int u32
Definition: types.h:88
vlib_node_get_runtime
static vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Get node runtime by node index.
Definition: node_funcs.h:116
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
vnet.h
vlib_node_runtime_t
Definition: node.h:454
format_handoff_trace
static u8 * format_handoff_trace(u8 *s, va_list *args)
Definition: handoff_trace.c:30
vlib_trace_buffer
static __clib_warn_unused_result int vlib_trace_buffer(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, vlib_buffer_t *b, int follow_chain)
Definition: trace_funcs.h:153
vlib_buffer_get_trace_index
static u32 vlib_buffer_get_trace_index(vlib_buffer_t *b)
Extract the trace (pool) index from a trace handle.
Definition: buffer.h:416
HANDOFF_TRACE_N_NEXT
@ HANDOFF_TRACE_N_NEXT
Definition: handoff_trace.c:75
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169