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
36 /** @brief Analysed iOAM trace data.
41 /** No of nodes in path. */
44 /** Data contained in trace - NodeId, TTL, Ingress & Egress Link, Timestamp. */
47 /** Flag to indicate whether node is allocated. */
52 /** Actual PATH flow has taken. */
53 ioam_path_map_t path[IOAM_TRACE_MAX_NODES];
55 /** Num of pkts in the flow going over path. */
58 /** Num of bytes in the flow going over path. */
61 /** Minumum Dealay for the flow. */
64 /** Maximum Dealay for the flow. */
67 /** Average Dealay for the flow. */
71 } ioam_analyse_trace_record;
75 ioam_analyse_trace_record path_data[IOAM_MAX_PATHS_PER_FLOW];
76 } ioam_analyse_trace_data;
78 /** @brief Analysed iOAM pot data.
83 /** Number of packets validated (passes through the service chain)
84 within the timestamps. */
85 u32 sfc_validated_count;
87 /** Number of packets invalidated (failed through the service chain)
88 within the timestamps. */
89 u32 sfc_invalidated_count;
90 } ioam_analyse_pot_data;
92 /** @brief Analysed iOAM data.
95 typedef struct ioam_analyser_data_t_
100 /** Num of pkts sent for this flow. */
103 /** Num of pkts matching this flow. */
106 /** Num of bytes matching this flow. */
109 /** Analysed iOAM trace data. */
110 ioam_analyse_trace_data trace_data;
112 /** Analysed iOAM pot data. */
113 ioam_analyse_pot_data pot_data;
115 /** Analysed iOAM seqno data. */
116 seqno_rx_info seqno_data;
118 /** Cache of previously analysed data, useful for export. */
119 struct ioam_analyser_data_t_ *chached_data_list;
121 /** Lock to since we use this to export the data in other thread. */
122 volatile u32 *writer_lock;
123 } ioam_analyser_data_t;
126 ip6_ioam_analyse_calc_delay (ioam_trace_hdr_t * trace, u16 trace_len)
128 u16 size_of_traceopt_per_node, size_of_all_traceopts;
130 u32 *start_elt, *end_elt;
131 u32 start_time, end_time;
133 size_of_traceopt_per_node = fetch_trace_data_size (trace->ioam_trace_type);
134 size_of_all_traceopts = trace_len; /*ioam_trace_type,data_list_elts_left */
136 num_nodes = (u8) (size_of_all_traceopts / size_of_traceopt_per_node);
138 num_nodes -= trace->data_list_elts_left;
140 start_elt = trace->elts;
143 (size_of_traceopt_per_node * (num_nodes - 1) / sizeof (u32));
145 if (trace->ioam_trace_type & BIT_TTL_NODEID)
150 if (trace->ioam_trace_type & BIT_ING_INTERFACE)
156 start_time = clib_net_to_host_u32 (*start_elt);
157 end_time = clib_net_to_host_u32 (*end_elt);
159 return (f64) (end_time - start_time);
163 ip6_ioam_analyse_hbh_trace (ioam_analyser_data_t * data,
164 ioam_trace_hdr_t * trace, u16 pak_len,
167 ioam_analyse_trace_data *trace_data;
168 u16 size_of_traceopt_per_node;
169 u16 size_of_all_traceopts;
170 u8 i, j, k, num_nodes, max_nodes;
173 u16 ingress_if, egress_if;
174 ioam_path_map_t *path = NULL;
175 ioam_analyse_trace_record *trace_record;
177 while (__sync_lock_test_and_set (data->writer_lock, 1))
180 trace_data = &data->trace_data;
182 size_of_traceopt_per_node = fetch_trace_data_size (trace->ioam_trace_type);
183 size_of_all_traceopts = trace_len;
185 ptr = (u8 *) trace->elts;
186 max_nodes = (u8) (size_of_all_traceopts / size_of_traceopt_per_node);
187 num_nodes = max_nodes - trace->data_list_elts_left;
189 for (i = 0; i < IOAM_MAX_PATHS_PER_FLOW; i++)
191 trace_record = trace_data->path_data + i;
193 if (trace_record->is_free ||
194 (num_nodes != trace_record->num_nodes) ||
195 (trace->ioam_trace_type != trace_record->trace_type))
198 path = trace_record->path;
200 for (j = max_nodes, k = 0; k < num_nodes; j--, k++)
203 (u8 *) ((u8 *) trace->elts +
204 (size_of_traceopt_per_node * (j - 1)));
206 nodeid = clib_net_to_host_u32 (*((u32 *) ptr)) & 0x00ffffff;
209 if (nodeid != path[k].node_id)
212 if ((trace->ioam_trace_type == TRACE_TYPE_IF_TS_APP) ||
213 (trace->ioam_trace_type == TRACE_TYPE_IF))
215 ingress_if = clib_net_to_host_u16 (*((u16 *) ptr));
217 egress_if = clib_net_to_host_u16 (*((u16 *) ptr));
218 if ((ingress_if != path[k].ingress_if) ||
219 (egress_if != path[k].egress_if))
232 for (i = 0; i < IOAM_MAX_PATHS_PER_FLOW; i++)
234 trace_record = trace_data->path_data + i;
235 if (trace_record->is_free)
237 trace_record->is_free = 0;
238 trace_record->num_nodes = num_nodes;
239 trace_record->trace_type = trace->ioam_trace_type;
240 path = trace_data->path_data[i].path;
241 trace_record->pkt_counter = 0;
242 trace_record->bytes_counter = 0;
243 trace_record->min_delay = 0xFFFFFFFF;
244 trace_record->max_delay = 0;
245 trace_record->mean_delay = 0;
250 for (j = max_nodes, k = 0; k < num_nodes; j--, k++)
253 (u8 *) ((u8 *) trace->elts + (size_of_traceopt_per_node * (j - 1)));
255 path[k].node_id = clib_net_to_host_u32 (*((u32 *) ptr)) & 0x00ffffff;
258 if ((trace->ioam_trace_type == TRACE_TYPE_IF_TS_APP) ||
259 (trace->ioam_trace_type == TRACE_TYPE_IF))
261 path[k].ingress_if = clib_net_to_host_u16 (*((u16 *) ptr));
263 path[k].egress_if = clib_net_to_host_u16 (*((u16 *) ptr));
268 trace_record->pkt_counter++;
269 trace_record->bytes_counter += pak_len;
271 if (trace->ioam_trace_type & BIT_TIMESTAMP)
273 /* Calculate time delay */
274 u32 delay = (u32) ip6_ioam_analyse_calc_delay (trace, trace_len);
275 if (delay < trace_record->min_delay)
276 trace_record->min_delay = delay;
277 else if (delay > trace_record->max_delay)
278 trace_record->max_delay = delay;
280 u64 sum = (trace_record->mean_delay * data->seqno_data.rx_packets);
281 trace_record->mean_delay =
282 (u32) ((sum + delay) / (data->seqno_data.rx_packets + 1));
285 *(data->writer_lock) = 0;
290 ip6_ioam_analyse_hbh_e2e (ioam_analyser_data_t * data,
291 ioam_e2e_packet_t * e2e, u16 len)
293 while (__sync_lock_test_and_set (data->writer_lock, 1))
296 ioam_analyze_seqno (&data->seqno_data,
297 (u64) clib_net_to_host_u32 (e2e->e2e_data));
299 *(data->writer_lock) = 0;
304 format_path_map (u8 * s, va_list * args)
306 ioam_path_map_t *pm = va_arg (*args, ioam_path_map_t *);
307 u32 num_of_elts = va_arg (*args, u32);
310 for (i = 0; i < num_of_elts; i++)
312 s = format (s, "node_id: 0x%x, ingress_if: 0x%x, egress_if:0x%x\n",
313 pm->node_id, pm->ingress_if, pm->egress_if);
321 print_analyse_flow (u8 * s, ioam_analyser_data_t * record)
324 ioam_analyse_trace_record *trace_record;
326 s = format (s, "pkt_sent : %u\n", record->pkt_sent);
327 s = format (s, "pkt_counter : %u\n", record->pkt_counter);
328 s = format (s, "bytes_counter : %u\n", record->bytes_counter);
330 s = format (s, "Trace data: \n");
332 for (j = 0; j < IOAM_MAX_PATHS_PER_FLOW; j++)
334 trace_record = record->trace_data.path_data + j;
335 if (trace_record->is_free)
338 s = format (s, "path_map:\n%U", format_path_map,
339 trace_record->path, trace_record->num_nodes);
340 s = format (s, "pkt_counter: %u\n", trace_record->pkt_counter);
341 s = format (s, "bytes_counter: %u\n", trace_record->bytes_counter);
343 s = format (s, "min_delay: %u\n", trace_record->min_delay);
344 s = format (s, "max_delay: %u\n", trace_record->max_delay);
345 s = format (s, "mean_delay: %u\n", trace_record->mean_delay);
348 s = format (s, "\nPOT data: \n");
349 s = format (s, "sfc_validated_count : %u\n",
350 record->pot_data.sfc_validated_count);
351 s = format (s, "sfc_invalidated_count : %u\n",
352 record->pot_data.sfc_invalidated_count);
354 s = format (s, "\nSeqno Data:\n");
357 "Lost Packets : %lu\n"
358 "Duplicate Packets : %lu\n"
359 "Reordered Packets : %lu\n",
360 record->seqno_data.rx_packets,
361 record->seqno_data.lost_packets,
362 record->seqno_data.dup_packets,
363 record->seqno_data.reordered_packets);
365 s = format (s, "\n");
370 ioam_analyse_init_data (ioam_analyser_data_t * data)
373 ioam_analyse_trace_data *trace_data;
377 /* We maintain data corresponding to last IP-Fix export, this may
378 * get extended in future to maintain history of data */
379 vec_validate_aligned (data->chached_data_list, 0, CLIB_CACHE_LINE_BYTES);
381 data->writer_lock = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
382 CLIB_CACHE_LINE_BYTES);
383 *(data->writer_lock) = 0;
385 trace_data = &(data->trace_data);
386 for (j = 0; j < IOAM_MAX_PATHS_PER_FLOW; j++)
387 trace_data->path_data[j].is_free = 1;
390 #endif /* PLUGINS_IOAM_PLUGIN_IOAM_ANALYSE_IOAM_ANALYSE_H_ */
393 * fd.io coding-style-patch-verification: ON
396 * eval: (c-set-style "gnu")