FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
trace_util.h
Go to the documentation of this file.
1 /*
2  * trace_util.h -- Trace Profile Utility header
3  *
4  * Copyright (c) 2016 Cisco 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 
18 #ifndef include_vnet_trace_util_h
19 #define include_vnet_trace_util_h
20 
21 #define debug_ioam debug_ioam_fn
22 
23 
24 /**
25  * Usage:
26  *
27  * On any node that participates in iOAM Trace.
28  *
29  * Step 1: Initialize this library by calling trace_init()
30  * Step 2: Setup a trace profile that contains all the parameters needed to compute cumulative:
31  * Call these functions:
32  * trace_profile_find
33  * trace_profile_create
34  * Step 2a: On initial node enable the profile to be used:
35  * trace_profile_set_active / trace_profile_get_active will return the profile
36  * Step 4: TBD
37  * trace_validate
38  *
39  */
40 
41 typedef struct trace_profile_
42 {
43  u8 valid:1;
46  /* Configured node-id */
51 
52 typedef struct
53 {
54  /* Name of the default profile list in use */
56 
57  /* API message ID base */
59 
60  /* convenience */
63 } trace_main_t;
64 
65 
66 /*
67  * Initialize Trace profile
68  */
69 int trace_util_init (void);
70 
71 
72 /* setup and clean up profile */
73 int trace_profile_create (trace_profile * profile, u8 trace_type, u8 num_elts,
74  u32 trace_tsp, u32 node_id, u32 app_data);
75 
76 void clear_trace_profiles (void);
77 
78 /* *INDENT-OFF* */
79 typedef CLIB_PACKED (struct
80 {
81  u8 ioam_trace_type;
82  u8 data_list_elts_left;
83  u32 elts[0]; /* Variable type. So keep it generic */
84 }) ioam_trace_hdr_t;
85 /* *INDENT-ON* */
86 
87 
88 
89 #define BIT_TTL_NODEID (1<<0)
90 #define BIT_ING_INTERFACE (1<<1)
91 #define BIT_EGR_INTERFACE (1<<2)
92 #define BIT_TIMESTAMP (1<<3)
93 #define BIT_APPDATA (1<<4)
94 #define BIT_LOOPBACK (1<<5)
95 #define BIT_LOOPBACK_REPLY (1<<6)
96 #define TRACE_TYPE_MASK 0x7F /* Mask of all above bits */
97 
98 #define TRACE_TYPE_IF_TS_APP_LOOP 0x3F
99 
100 /*
101  0x00011111 iOAM-trace-type is 0x00011111 then the format of node
102  data is:
103 
104  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
105  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
106  | Hop_Lim | node_id |
107  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
108  | ingress_if_id | egress_if_id |
109  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
110  + timestamp +
111  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
112  | app_data |
113  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
114 
115 */
116 #define TRACE_TYPE_IF_TS_APP 0x1f
117 typedef struct
118 {
125 
126 /*
127  0x00000111 iOAM-trace-type is 0x00000111 then the format is:
128 
129  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
130  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
131  | Hop_Lim | node_id |
132  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
133  | ingress_if_id | egress_if_id |
134  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
135 
136 */
137 
138 #define TRACE_TYPE_IF 0x03
139 typedef struct
140 {
145 
146 /*
147  0x00001001 iOAM-trace-type is 0x00001001 then the format is:
148 
149  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
150  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
151  | Hop_Lim | node_id |
152  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
153  + timestamp +
154  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
155 
156 */
157 
158 #define TRACE_TYPE_TS 0x09
159 typedef struct
160 {
164 
165 /*
166  0x00010001 iOAM-trace-type is 0x00010001 then the format is:
167 
168 
169  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
170  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
171  | Hop_Lim | node_id |
172  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
173  | app_data |
174  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
175 
176 */
177 
178 
179 #define TRACE_TYPE_APP 0x11
180 typedef struct
181 {
185 
186 /*
187 
188  0x00011001 iOAM-trace-type is 0x00011001 then the format is:
189 
190  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
191  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
192  | Hop_Lim | node_id |
193  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
194  + timestamp +
195  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
196  | app_data |
197  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
198 */
199 
200 #define TRACE_TYPE_TS_APP 0x19
201 typedef struct
202 {
207 
208 static inline u8
210 {
211  u8 trace_data_size = 0;
212 
213  if ((trace_type & TRACE_TYPE_IF_TS_APP) == TRACE_TYPE_IF_TS_APP)
214  trace_data_size = sizeof (ioam_trace_if_ts_app_t);
215  else if ((trace_type & TRACE_TYPE_IF) == TRACE_TYPE_IF)
216  trace_data_size = sizeof (ioam_trace_if_t);
217  else if ((trace_type & TRACE_TYPE_TS) == TRACE_TYPE_TS)
218  trace_data_size = sizeof (ioam_trace_ts_t);
219  else if ((trace_type & TRACE_TYPE_APP) == TRACE_TYPE_APP)
220  trace_data_size = sizeof (ioam_trace_app_t);
221  else if ((trace_type & TRACE_TYPE_TS_APP) == TRACE_TYPE_TS_APP)
222  trace_data_size = sizeof (ioam_trace_ts_app_t);
223 
224  return trace_data_size;
225 }
226 
227 always_inline void
228 ioam_trace_set_bit (ioam_trace_hdr_t * trace_hdr, u8 trace_bit)
229 {
230  trace_hdr->ioam_trace_type |= trace_bit;
231 }
232 
233 always_inline void
234 ioam_trace_reset_bit (ioam_trace_hdr_t * trace_hdr, u8 trace_bit)
235 {
236  trace_hdr->ioam_trace_type &= (~trace_bit);
237 }
238 
239 int ioam_trace_get_sizeof_handler (u32 * result);
240 int ip6_trace_profile_setup (void);
241 int ip6_trace_profile_cleanup (void);
242 
243 #define TSP_SECONDS 0
244 #define TSP_MILLISECONDS 1
245 #define TSP_MICROSECONDS 2
246 #define TSP_NANOSECONDS 3
247 
248 #endif
249 
250 /*
251  * fd.io coding-style-patch-verification: ON
252  *
253  * Local Variables:
254  * eval: (c-set-style "gnu")
255  * End:
256  */
ioam_trace_ts_t::timestamp
u32 timestamp
Definition: trace_util.h:162
ip6_trace_profile_setup
int ip6_trace_profile_setup(void)
Definition: ip6_ioam_trace.c:467
TRACE_TYPE_TS_APP
#define TRACE_TYPE_TS_APP
Definition: trace_util.h:200
clear_trace_profiles
void clear_trace_profiles(void)
Definition: trace_util.c:96
ioam_trace_if_t
Definition: trace_util.h:139
TRACE_TYPE_IF
#define TRACE_TYPE_IF
Definition: trace_util.h:138
ioam_trace_if_ts_app_t
Definition: trace_util.h:117
u16
unsigned short u16
Definition: types.h:57
trace_profile_::num_elts
u8 num_elts
Definition: trace_util.h:45
TRACE_TYPE_APP
#define TRACE_TYPE_APP
Definition: trace_util.h:179
ioam_trace_if_ts_app_t::ttl_node_id
u32 ttl_node_id
Definition: trace_util.h:119
trace_profile_::trace_tsp
u32 trace_tsp
Definition: trace_util.h:49
trace_profile_::node_id
u32 node_id
Definition: trace_util.h:47
trace_profile_
Usage:
Definition: trace_util.h:41
ioam_trace_get_sizeof_handler
int ioam_trace_get_sizeof_handler(u32 *result)
trace_main_t::vnet_main
vnet_main_t * vnet_main
Definition: trace_util.h:62
ioam_trace_if_t::ingress_if
u16 ingress_if
Definition: trace_util.h:142
ioam_trace_ts_t::ttl_node_id
u32 ttl_node_id
Definition: trace_util.h:161
ioam_trace_app_t::ttl_node_id
u32 ttl_node_id
Definition: trace_util.h:182
ioam_trace_ts_app_t::timestamp
u32 timestamp
Definition: trace_util.h:204
trace_profile
struct trace_profile_ trace_profile
Usage:
trace_main_t::profile
trace_profile profile
Definition: trace_util.h:55
trace_profile_create
int trace_profile_create(trace_profile *profile, u8 trace_type, u8 num_elts, u32 trace_tsp, u32 node_id, u32 app_data)
Definition: trace_util.c:57
ioam_trace_ts_app_t::ttl_node_id
u32 ttl_node_id
Definition: trace_util.h:203
ip6_trace_profile_cleanup
int ip6_trace_profile_cleanup(void)
Definition: ip6_ioam_trace.c:455
ioam_trace_app_t::app_data
u32 app_data
Definition: trace_util.h:183
trace_profile_::app_data
u32 app_data
Definition: trace_util.h:48
vnet_main_t
Definition: vnet.h:76
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
ioam_trace_ts_app_t
Definition: trace_util.h:201
u32
unsigned int u32
Definition: types.h:88
trace_main_t::vlib_main
vlib_main_t * vlib_main
Definition: trace_util.h:61
ioam_trace_if_ts_app_t::egress_if
u16 egress_if
Definition: trace_util.h:121
CLIB_PACKED
typedef CLIB_PACKED(struct { u8 ioam_trace_type;u8 data_list_elts_left;u32 elts[0];}) ioam_trace_hdr_t
ioam_trace_if_ts_app_t::ingress_if
u16 ingress_if
Definition: trace_util.h:120
TRACE_TYPE_IF_TS_APP
#define TRACE_TYPE_IF_TS_APP
Definition: trace_util.h:116
trace_main_t::msg_id_base
u16 msg_id_base
Definition: trace_util.h:58
vlib_main_t
Definition: main.h:102
trace_profile_::valid
u8 valid
Definition: trace_util.h:43
ioam_trace_if_t::ttl_node_id
u32 ttl_node_id
Definition: trace_util.h:141
trace_util_init
int trace_util_init(void)
Definition: trace_util.c:47
ioam_trace_app_t
Definition: trace_util.h:180
u8
unsigned char u8
Definition: types.h:56
trace_profile_::trace_type
u8 trace_type
Definition: trace_util.h:44
ioam_trace_set_bit
static void ioam_trace_set_bit(ioam_trace_hdr_t *trace_hdr, u8 trace_bit)
Definition: trace_util.h:228
ioam_trace_if_ts_app_t::timestamp
u32 timestamp
Definition: trace_util.h:122
ioam_trace_if_ts_app_t::app_data
u32 app_data
Definition: trace_util.h:123
TRACE_TYPE_TS
#define TRACE_TYPE_TS
Definition: trace_util.h:158
trace_main_t
Definition: trace_util.h:52
fetch_trace_data_size
static u8 fetch_trace_data_size(u16 trace_type)
Definition: trace_util.h:209
ioam_trace_if_t::egress_if
u16 egress_if
Definition: trace_util.h:143
ioam_trace_reset_bit
static void ioam_trace_reset_bit(ioam_trace_hdr_t *trace_hdr, u8 trace_bit)
Definition: trace_util.h:234
ioam_trace_ts_app_t::app_data
u32 app_data
Definition: trace_util.h:205
ioam_trace_ts_t
Definition: trace_util.h:159