build: archive make install-ext-deps build logs in ci
[vpp.git] / src / plugins / ioam / lib-trace / trace_util.h
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;
44   u8 trace_type;
45   u8 num_elts;
46   /* Configured node-id */
47   u32 node_id;
48   u32 app_data;
49   u32 trace_tsp;
50 } trace_profile;
51
52 typedef struct
53 {
54   /* Name of the default profile list in use */
55   trace_profile profile;
56
57   /* API message ID base */
58   u16 msg_id_base;
59
60   /* convenience */
61   vlib_main_t *vlib_main;
62   vnet_main_t *vnet_main;
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 typedef CLIB_PACKED (struct
79 {
80   u8 ioam_trace_type;
81   u8 data_list_elts_left;
82   u32 elts[0]; /* Variable type. So keep it generic */
83 }) ioam_trace_hdr_t;
84
85
86
87 #define    BIT_TTL_NODEID       (1<<0)
88 #define    BIT_ING_INTERFACE    (1<<1)
89 #define    BIT_EGR_INTERFACE    (1<<2)
90 #define    BIT_TIMESTAMP        (1<<3)
91 #define    BIT_APPDATA          (1<<4)
92 #define    BIT_LOOPBACK         (1<<5)
93 #define    BIT_LOOPBACK_REPLY   (1<<6)
94 #define    TRACE_TYPE_MASK      0x7F    /* Mask of all above bits */
95
96 #define    TRACE_TYPE_IF_TS_APP_LOOP    0x3F
97
98 /*
99      0x00011111  iOAM-trace-type is 0x00011111 then the format of node
100         data is:
101
102           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
103          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
104          |   Hop_Lim     |              node_id                          |
105          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
106          |     ingress_if_id             |         egress_if_id          |
107          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
108          +                           timestamp                           +
109          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
110          |                            app_data                           |
111          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
112
113 */
114 #define   TRACE_TYPE_IF_TS_APP   0x1f
115 typedef struct
116 {
117   u32 ttl_node_id;
118   u16 ingress_if;
119   u16 egress_if;
120   u32 timestamp;
121   u32 app_data;
122 } ioam_trace_if_ts_app_t;
123
124 /*
125      0x00000111  iOAM-trace-type is 0x00000111 then the format is:
126
127           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
128          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
129          |   Hop_Lim     |              node_id                          |
130          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
131          |     ingress_if_id             |         egress_if_id          |
132          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
133
134 */
135
136 #define   TRACE_TYPE_IF   0x03
137 typedef struct
138 {
139   u32 ttl_node_id;
140   u16 ingress_if;
141   u16 egress_if;
142 } ioam_trace_if_t;
143
144 /*
145      0x00001001  iOAM-trace-type is 0x00001001 then the format is:
146
147           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
148          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
149          |   Hop_Lim     |              node_id                          |
150          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
151          +                           timestamp                           +
152          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
153
154 */
155
156 #define   TRACE_TYPE_TS   0x09
157 typedef struct
158 {
159   u32 ttl_node_id;
160   u32 timestamp;
161 } ioam_trace_ts_t;
162
163 /*
164      0x00010001  iOAM-trace-type is 0x00010001 then the format is:
165
166
167           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
168          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
169          |   Hop_Lim     |              node_id                          |
170          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
171          |                            app_data                           |
172          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
173
174 */
175
176
177 #define   TRACE_TYPE_APP   0x11
178 typedef struct
179 {
180   u32 ttl_node_id;
181   u32 app_data;
182 } ioam_trace_app_t;
183
184 /*
185
186      0x00011001  iOAM-trace-type is 0x00011001 then the format is:
187
188           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
189          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
190          |   Hop_Lim     |              node_id                          |
191          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
192          +                           timestamp                           +
193          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
194          |                            app_data                           |
195          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
196 */
197
198 #define   TRACE_TYPE_TS_APP   0x19
199 typedef struct
200 {
201   u32 ttl_node_id;
202   u32 timestamp;
203   u32 app_data;
204 } ioam_trace_ts_app_t;
205
206 static inline u8
207 fetch_trace_data_size (u16 trace_type)
208 {
209   u8 trace_data_size = 0;
210
211   if ((trace_type & TRACE_TYPE_IF_TS_APP) == TRACE_TYPE_IF_TS_APP)
212     trace_data_size = sizeof (ioam_trace_if_ts_app_t);
213   else if ((trace_type & TRACE_TYPE_IF) == TRACE_TYPE_IF)
214     trace_data_size = sizeof (ioam_trace_if_t);
215   else if ((trace_type & TRACE_TYPE_TS) == TRACE_TYPE_TS)
216     trace_data_size = sizeof (ioam_trace_ts_t);
217   else if ((trace_type & TRACE_TYPE_APP) == TRACE_TYPE_APP)
218     trace_data_size = sizeof (ioam_trace_app_t);
219   else if ((trace_type & TRACE_TYPE_TS_APP) == TRACE_TYPE_TS_APP)
220     trace_data_size = sizeof (ioam_trace_ts_app_t);
221
222   return trace_data_size;
223 }
224
225 always_inline void
226 ioam_trace_set_bit (ioam_trace_hdr_t * trace_hdr, u8 trace_bit)
227 {
228   trace_hdr->ioam_trace_type |= trace_bit;
229 }
230
231 always_inline void
232 ioam_trace_reset_bit (ioam_trace_hdr_t * trace_hdr, u8 trace_bit)
233 {
234   trace_hdr->ioam_trace_type &= (~trace_bit);
235 }
236
237 int ioam_trace_get_sizeof_handler (u32 * result);
238 int ip6_trace_profile_setup (void);
239 int ip6_trace_profile_cleanup (void);
240
241 #define TSP_SECONDS              0
242 #define TSP_MILLISECONDS         1
243 #define TSP_MICROSECONDS         2
244 #define TSP_NANOSECONDS          3
245
246 #endif
247
248 /*
249  * fd.io coding-style-patch-verification: ON
250  *
251  * Local Variables:
252  * eval: (c-set-style "gnu")
253  * End:
254  */