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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef PLUGINS_IOAM_PLUGIN_IOAM_ANALYSE_IOAM_ANALYSE_H_
17 #define PLUGINS_IOAM_PLUGIN_IOAM_ANALYSE_IOAM_ANALYSE_H_
19 #include <vlib/vlib.h>
20 #include <vnet/vnet.h>
21 #include <vppinfra/types.h>
22 #include <ioam/lib-e2e/e2e_util.h>
23 #include <ioam/lib-trace/trace_util.h>
25 #define IOAM_FLOW_TEMPLATE_ID 260
26 #define IOAM_TRACE_MAX_NODES 10
27 #define IOAM_MAX_PATHS_PER_FLOW 10
37 /** @brief Analysed iOAM trace data.
42 /** No of nodes in path. */
45 /** Data contained in trace - NodeId, TTL, Ingress & Egress Link, Timestamp. */
48 /** Flag to indicate whether node is allocated. */
53 /** Actual PATH flow has taken. */
54 ioam_path_map_t path[IOAM_TRACE_MAX_NODES];
56 /** Num of pkts in the flow going over path. */
59 /** Num of bytes in the flow going over path. */
62 /** Minumum Dealay for the flow. */
65 /** Maximum Dealay for the flow. */
68 /** Average Dealay for the flow. */
72 } ioam_analyse_trace_record;
76 ioam_analyse_trace_record path_data[IOAM_MAX_PATHS_PER_FLOW];
77 } ioam_analyse_trace_data;
79 /** @brief Analysed iOAM pot data.
84 /** Number of packets validated (passes through the service chain)
85 within the timestamps. */
86 u32 sfc_validated_count;
88 /** Number of packets invalidated (failed through the service chain)
89 within the timestamps. */
90 u32 sfc_invalidated_count;
91 } ioam_analyse_pot_data;
93 /** @brief Analysed iOAM data.
96 typedef struct ioam_analyser_data_t_
101 /** Num of pkts sent for this flow. */
104 /** Num of pkts matching this flow. */
107 /** Num of bytes matching this flow. */
110 /** Analysed iOAM trace data. */
111 ioam_analyse_trace_data trace_data;
113 /** Analysed iOAM pot data. */
114 ioam_analyse_pot_data pot_data;
116 /** Analysed iOAM seqno data. */
117 seqno_rx_info seqno_data;
119 /** Cache of previously analysed data, useful for export. */
120 struct ioam_analyser_data_t_ *chached_data_list;
122 /** Lock to since we use this to export the data in other thread. */
123 volatile u32 *writer_lock;
124 } ioam_analyser_data_t;
127 ip6_ioam_analyse_calc_delay (ioam_trace_hdr_t * trace, u16 trace_len,
130 u16 size_of_traceopt_per_node, size_of_all_traceopts;
132 u32 *start_elt, *end_elt, *uturn_elt;;
133 u32 start_time, end_time;
136 size_of_traceopt_per_node = fetch_trace_data_size (trace->ioam_trace_type);
137 // Unknown trace type
138 if (size_of_traceopt_per_node == 0)
140 size_of_all_traceopts = trace_len; /*ioam_trace_type,data_list_elts_left */
142 num_nodes = (u8) (size_of_all_traceopts / size_of_traceopt_per_node);
144 num_nodes -= trace->data_list_elts_left;
146 start_elt = trace->elts;
149 (u32) (size_of_traceopt_per_node * (num_nodes - 1) / sizeof (u32));
151 if (oneway && (trace->ioam_trace_type & BIT_TTL_NODEID))
156 uturn_elt = start_elt - size_of_traceopt_per_node / sizeof (u32);
158 if ((clib_net_to_host_u32 (*start_elt) >> 24) <=
159 (clib_net_to_host_u32 (*uturn_elt) >> 24))
162 while (!done && (start_elt = uturn_elt) != end_elt);
164 if (trace->ioam_trace_type & BIT_TTL_NODEID)
169 if (trace->ioam_trace_type & BIT_ING_INTERFACE)
174 start_time = clib_net_to_host_u32 (*start_elt);
175 end_time = clib_net_to_host_u32 (*end_elt);
177 return (f64) (end_time - start_time);
181 ip6_ioam_analyse_set_paths_down (ioam_analyser_data_t * data)
183 ioam_analyse_trace_data *trace_data;
184 ioam_analyse_trace_record *trace_record;
185 ioam_path_map_t *path;
188 while (__sync_lock_test_and_set (data->writer_lock, 1))
191 trace_data = &data->trace_data;
193 for (i = 0; i < IOAM_MAX_PATHS_PER_FLOW; i++)
195 trace_record = trace_data->path_data + i;
197 if (trace_record->is_free)
200 path = trace_record->path;
202 for (k = 0; k < trace_record->num_nodes; k++)
203 path[k].state_up = 0;
205 *(data->writer_lock) = 0;
209 ip6_ioam_analyse_hbh_trace_loopback (ioam_analyser_data_t * data,
210 ioam_trace_hdr_t * trace, u16 trace_len)
212 ioam_analyse_trace_data *trace_data;
213 ioam_analyse_trace_record *trace_record;
214 ioam_path_map_t *path;
215 u8 i, j, k, num_nodes, max_nodes;
218 u16 ingress_if, egress_if;
219 u16 size_of_traceopt_per_node;
220 u16 size_of_all_traceopts;
222 while (__sync_lock_test_and_set (data->writer_lock, 1))
225 trace_data = &data->trace_data;
227 size_of_traceopt_per_node = fetch_trace_data_size (trace->ioam_trace_type);
228 size_of_all_traceopts = trace_len;
230 ptr = (u8 *) trace->elts;
231 max_nodes = (u8) (size_of_all_traceopts / size_of_traceopt_per_node);
232 num_nodes = max_nodes - trace->data_list_elts_left;
234 for (i = 0; i < IOAM_MAX_PATHS_PER_FLOW; i++)
236 trace_record = trace_data->path_data + i;
237 path = trace_record->path;
239 if (trace_record->is_free)
242 for (j = max_nodes, k = 0; k < num_nodes; j--, k++)
245 (u8 *) ((u8 *) trace->elts +
246 (size_of_traceopt_per_node * (j - 1)));
248 nodeid = clib_net_to_host_u32 (*((u32 *) ptr)) & 0x00ffffff;
251 if (nodeid != path[k].node_id)
254 if ((trace->ioam_trace_type == TRACE_TYPE_IF_TS_APP) ||
255 (trace->ioam_trace_type == TRACE_TYPE_IF))
257 ingress_if = clib_net_to_host_u16 (*((u16 *) ptr));
259 egress_if = clib_net_to_host_u16 (*((u16 *) ptr));
260 if ((ingress_if != path[k].ingress_if) ||
261 (egress_if != path[k].egress_if))
266 /* Found Match - set path hop state to up */
267 path[k].state_up = 1;
271 *(data->writer_lock) = 0;
275 ip6_ioam_analyse_hbh_trace (ioam_analyser_data_t * data,
276 ioam_trace_hdr_t * trace, u16 pak_len,
279 ioam_analyse_trace_data *trace_data;
280 u16 size_of_traceopt_per_node;
281 u16 size_of_all_traceopts;
282 u8 i, j, k, num_nodes, max_nodes;
285 u16 ingress_if, egress_if;
286 ioam_path_map_t *path = NULL;
287 ioam_analyse_trace_record *trace_record;
289 while (__sync_lock_test_and_set (data->writer_lock, 1))
292 trace_data = &data->trace_data;
294 size_of_traceopt_per_node = fetch_trace_data_size (trace->ioam_trace_type);
295 // Unknown trace type
296 if (size_of_traceopt_per_node == 0)
298 size_of_all_traceopts = trace_len;
300 ptr = (u8 *) trace->elts;
301 max_nodes = (u8) (size_of_all_traceopts / size_of_traceopt_per_node);
302 num_nodes = max_nodes - trace->data_list_elts_left;
304 for (i = 0; i < IOAM_MAX_PATHS_PER_FLOW; i++)
306 trace_record = trace_data->path_data + i;
308 if (trace_record->is_free ||
309 (num_nodes != trace_record->num_nodes) ||
310 (trace->ioam_trace_type != trace_record->trace_type))
313 path = trace_record->path;
315 for (j = max_nodes, k = 0; k < num_nodes; j--, k++)
318 (u8 *) ((u8 *) trace->elts +
319 (size_of_traceopt_per_node * (j - 1)));
321 nodeid = clib_net_to_host_u32 (*((u32 *) ptr)) & 0x00ffffff;
324 if (nodeid != path[k].node_id)
327 if ((trace->ioam_trace_type == TRACE_TYPE_IF_TS_APP) ||
328 (trace->ioam_trace_type == TRACE_TYPE_IF))
330 ingress_if = clib_net_to_host_u16 (*((u16 *) ptr));
332 egress_if = clib_net_to_host_u16 (*((u16 *) ptr));
333 if ((ingress_if != path[k].ingress_if) ||
334 (egress_if != path[k].egress_if))
347 for (i = 0; i < IOAM_MAX_PATHS_PER_FLOW; i++)
349 trace_record = trace_data->path_data + i;
350 if (trace_record->is_free)
352 trace_record->is_free = 0;
353 trace_record->num_nodes = num_nodes;
354 trace_record->trace_type = trace->ioam_trace_type;
355 path = trace_data->path_data[i].path;
356 trace_record->pkt_counter = 0;
357 trace_record->bytes_counter = 0;
358 trace_record->min_delay = 0xFFFFFFFF;
359 trace_record->max_delay = 0;
360 trace_record->mean_delay = 0;
365 for (j = max_nodes, k = 0; k < num_nodes; j--, k++)
368 (u8 *) ((u8 *) trace->elts + (size_of_traceopt_per_node * (j - 1)));
370 path[k].node_id = clib_net_to_host_u32 (*((u32 *) ptr)) & 0x00ffffff;
373 if ((trace->ioam_trace_type == TRACE_TYPE_IF_TS_APP) ||
374 (trace->ioam_trace_type == TRACE_TYPE_IF))
376 path[k].ingress_if = clib_net_to_host_u16 (*((u16 *) ptr));
378 path[k].egress_if = clib_net_to_host_u16 (*((u16 *) ptr));
383 /* Set path state to UP */
384 for (k = 0; k < num_nodes; k++)
385 path[k].state_up = 1;
387 trace_record->pkt_counter++;
388 trace_record->bytes_counter += pak_len;
389 if (trace->ioam_trace_type & BIT_TIMESTAMP)
391 /* Calculate time delay */
392 u32 delay = (u32) ip6_ioam_analyse_calc_delay (trace, trace_len, 0);
393 if (delay < trace_record->min_delay)
394 trace_record->min_delay = delay;
395 else if (delay > trace_record->max_delay)
396 trace_record->max_delay = delay;
398 u64 sum = (trace_record->mean_delay * data->seqno_data.rx_packets);
399 trace_record->mean_delay =
400 (u32) ((sum + delay) / (data->seqno_data.rx_packets + 1));
403 *(data->writer_lock) = 0;
408 ip6_ioam_analyse_hbh_e2e (ioam_analyser_data_t * data,
409 ioam_e2e_packet_t * e2e, u16 len)
411 while (__sync_lock_test_and_set (data->writer_lock, 1))
414 ioam_analyze_seqno (&data->seqno_data,
415 (u64) clib_net_to_host_u32 (e2e->e2e_data));
417 *(data->writer_lock) = 0;
422 format_path_map (u8 * s, va_list * args)
424 ioam_path_map_t *pm = va_arg (*args, ioam_path_map_t *);
425 u32 num_of_elts = va_arg (*args, u32);
428 for (i = 0; i < num_of_elts; i++)
432 "node_id: 0x%x, ingress_if: 0x%x, egress_if:0x%x, state:%s\n",
433 pm->node_id, pm->ingress_if, pm->egress_if,
434 pm->state_up ? "UP" : "DOWN");
442 print_analyse_flow (u8 * s, ioam_analyser_data_t * record)
445 ioam_analyse_trace_record *trace_record;
447 s = format (s, "pkt_sent : %u\n", record->pkt_sent);
448 s = format (s, "pkt_counter : %u\n", record->pkt_counter);
449 s = format (s, "bytes_counter : %u\n", record->bytes_counter);
451 s = format (s, "Trace data: \n");
453 for (j = 0; j < IOAM_MAX_PATHS_PER_FLOW; j++)
455 trace_record = record->trace_data.path_data + j;
456 if (trace_record->is_free)
459 s = format (s, "path_map:\n%U", format_path_map,
460 trace_record->path, trace_record->num_nodes);
461 s = format (s, "pkt_counter: %u\n", trace_record->pkt_counter);
462 s = format (s, "bytes_counter: %u\n", trace_record->bytes_counter);
464 s = format (s, "min_delay: %u\n", trace_record->min_delay);
465 s = format (s, "max_delay: %u\n", trace_record->max_delay);
466 s = format (s, "mean_delay: %u\n", trace_record->mean_delay);
469 s = format (s, "\nPOT data: \n");
470 s = format (s, "sfc_validated_count : %u\n",
471 record->pot_data.sfc_validated_count);
472 s = format (s, "sfc_invalidated_count : %u\n",
473 record->pot_data.sfc_invalidated_count);
475 s = format (s, "\nSeqno Data:\n");
478 "Lost Packets : %lu\n"
479 "Duplicate Packets : %lu\n"
480 "Reordered Packets : %lu\n",
481 record->seqno_data.rx_packets,
482 record->seqno_data.lost_packets,
483 record->seqno_data.dup_packets,
484 record->seqno_data.reordered_packets);
486 s = format (s, "\n");
491 ioam_analyse_init_data (ioam_analyser_data_t * data)
494 ioam_analyse_trace_data *trace_data;
498 /* We maintain data corresponding to last IP-Fix export, this may
499 * get extended in future to maintain history of data */
500 vec_validate_aligned (data->chached_data_list, 0, CLIB_CACHE_LINE_BYTES);
502 data->writer_lock = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
503 CLIB_CACHE_LINE_BYTES);
504 *(data->writer_lock) = 0;
506 trace_data = &(data->trace_data);
507 for (j = 0; j < IOAM_MAX_PATHS_PER_FLOW; j++)
508 trace_data->path_data[j].is_free = 1;
511 #endif /* PLUGINS_IOAM_PLUGIN_IOAM_ANALYSE_IOAM_ANALYSE_H_ */
514 * fd.io coding-style-patch-verification: ON
517 * eval: (c-set-style "gnu")