#include <vppinfra/types.h>
#include <ioam/lib-e2e/e2e_util.h>
#include <ioam/lib-trace/trace_util.h>
+#include <ioam/lib-trace/trace_config.h>
+#include <vppinfra/lock.h>
#define IOAM_FLOW_TEMPLATE_ID 260
#define IOAM_TRACE_MAX_NODES 10
u16 ingress_if;
u16 egress_if;
u32 node_id;
+ u32 state_up;
} ioam_path_map_t;
/** @brief Analysed iOAM trace data.
*/
typedef struct ioam_analyser_data_t_
{
+ CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
+
u8 is_free;
u8 pad[3];
struct ioam_analyser_data_t_ *chached_data_list;
/** Lock to since we use this to export the data in other thread. */
- volatile u32 *writer_lock;
+ clib_spinlock_t writer_lock;
} ioam_analyser_data_t;
always_inline f64
-ip6_ioam_analyse_calc_delay (ioam_trace_hdr_t * trace, u16 trace_len)
+ip6_ioam_analyse_calc_delay (ioam_trace_hdr_t * trace, u16 trace_len,
+ u8 oneway)
{
- u16 size_of_traceopt_per_node, size_of_all_traceopts;
+ u16 size_of_all_traceopts;
+ u8 size_of_traceopt_per_node;
u8 num_nodes;
- u32 *start_elt, *end_elt;
+ u32 *start_elt, *end_elt, *uturn_elt;;
u32 start_time, end_time;
+ u8 done = 0;
size_of_traceopt_per_node = fetch_trace_data_size (trace->ioam_trace_type);
+ // Unknown trace type
+ if (size_of_traceopt_per_node == 0)
+ return 0;
size_of_all_traceopts = trace_len; /*ioam_trace_type,data_list_elts_left */
num_nodes = (u8) (size_of_all_traceopts / size_of_traceopt_per_node);
+ if ((num_nodes == 0) || (num_nodes <= trace->data_list_elts_left))
+ return 0;
num_nodes -= trace->data_list_elts_left;
start_elt = trace->elts;
end_elt =
trace->elts +
- (size_of_traceopt_per_node * (num_nodes - 1) / sizeof (u32));
+ (u32) ((size_of_traceopt_per_node / sizeof (u32)) * (num_nodes - 1));
+
+ if (oneway && (trace->ioam_trace_type & BIT_TTL_NODEID))
+ {
+ done = 0;
+ do
+ {
+ uturn_elt = start_elt - size_of_traceopt_per_node / sizeof (u32);
+ if ((clib_net_to_host_u32 (*start_elt) >> 24) <=
+ (clib_net_to_host_u32 (*uturn_elt) >> 24))
+ done = 1;
+ }
+ while (!done && (start_elt = uturn_elt) != end_elt);
+ }
if (trace->ioam_trace_type & BIT_TTL_NODEID)
{
start_elt++;
start_elt++;
end_elt++;
}
-
start_time = clib_net_to_host_u32 (*start_elt);
end_time = clib_net_to_host_u32 (*end_elt);
return (f64) (end_time - start_time);
}
+always_inline void
+ip6_ioam_analyse_set_paths_down (ioam_analyser_data_t * data)
+{
+ ioam_analyse_trace_data *trace_data;
+ ioam_analyse_trace_record *trace_record;
+ ioam_path_map_t *path;
+ u8 k, i;
+
+ clib_spinlock_lock (&data->writer_lock);
+
+ trace_data = &data->trace_data;
+
+ for (i = 0; i < IOAM_MAX_PATHS_PER_FLOW; i++)
+ {
+ trace_record = trace_data->path_data + i;
+
+ if (trace_record->is_free)
+ continue;
+
+ path = trace_record->path;
+
+ for (k = 0; k < trace_record->num_nodes; k++)
+ path[k].state_up = 0;
+ }
+ clib_spinlock_unlock (&data->writer_lock);
+}
+
+always_inline void
+ip6_ioam_analyse_hbh_trace_loopback (ioam_analyser_data_t * data,
+ ioam_trace_hdr_t * trace, u16 trace_len)
+{
+ ioam_analyse_trace_data *trace_data;
+ ioam_analyse_trace_record *trace_record;
+ ioam_path_map_t *path;
+ u8 i, j, k, num_nodes, max_nodes;
+ u8 *ptr;
+ u32 nodeid;
+ u16 ingress_if, egress_if;
+ u16 size_of_traceopt_per_node;
+ u16 size_of_all_traceopts;
+
+ clib_spinlock_lock (&data->writer_lock);
+
+ trace_data = &data->trace_data;
+
+ size_of_traceopt_per_node = fetch_trace_data_size (trace->ioam_trace_type);
+ if (0 == size_of_traceopt_per_node)
+ goto end;
+
+ size_of_all_traceopts = trace_len;
+
+ ptr = (u8 *) trace->elts;
+ max_nodes = (u8) (size_of_all_traceopts / size_of_traceopt_per_node);
+ num_nodes = max_nodes - trace->data_list_elts_left;
+
+ for (i = 0; i < IOAM_MAX_PATHS_PER_FLOW; i++)
+ {
+ trace_record = trace_data->path_data + i;
+ path = trace_record->path;
+
+ if (trace_record->is_free)
+ continue;
+
+ for (j = max_nodes, k = 0; k < num_nodes; j--, k++)
+ {
+ ptr =
+ (u8 *) ((u8 *) trace->elts +
+ (size_of_traceopt_per_node * (j - 1)));
+
+ nodeid = clib_net_to_host_u32 (*((u32 *) ptr)) & 0x00ffffff;
+ ptr += 4;
+
+ if (nodeid != path[k].node_id)
+ goto end;
+
+ if ((trace->ioam_trace_type == TRACE_TYPE_IF_TS_APP) ||
+ (trace->ioam_trace_type == TRACE_TYPE_IF))
+ {
+ ingress_if = clib_net_to_host_u16 (*((u16 *) ptr));
+ ptr += 2;
+ egress_if = clib_net_to_host_u16 (*((u16 *) ptr));
+ if ((ingress_if != path[k].ingress_if) ||
+ (egress_if != path[k].egress_if))
+ {
+ goto end;
+ }
+ }
+ /* Found Match - set path hop state to up */
+ path[k].state_up = 1;
+ }
+ }
+end:
+ clib_spinlock_unlock (&data->writer_lock);
+}
+
always_inline int
ip6_ioam_analyse_hbh_trace (ioam_analyser_data_t * data,
ioam_trace_hdr_t * trace, u16 pak_len,
ioam_path_map_t *path = NULL;
ioam_analyse_trace_record *trace_record;
- while (__sync_lock_test_and_set (data->writer_lock, 1))
- ;
+ clib_spinlock_lock (&data->writer_lock);
trace_data = &data->trace_data;
size_of_traceopt_per_node = fetch_trace_data_size (trace->ioam_trace_type);
+ // Unknown trace type
+ if (size_of_traceopt_per_node == 0)
+ goto DONE;
size_of_all_traceopts = trace_len;
ptr = (u8 *) trace->elts;
}
found_match:
+ /* Set path state to UP */
+ for (k = 0; k < num_nodes; k++)
+ path[k].state_up = 1;
+
trace_record->pkt_counter++;
trace_record->bytes_counter += pak_len;
-
if (trace->ioam_trace_type & BIT_TIMESTAMP)
{
/* Calculate time delay */
- u32 delay = (u32) ip6_ioam_analyse_calc_delay (trace, trace_len);
+ u32 delay = (u32) ip6_ioam_analyse_calc_delay (trace, trace_len, 0);
if (delay < trace_record->min_delay)
trace_record->min_delay = delay;
else if (delay > trace_record->max_delay)
trace_record->mean_delay =
(u32) ((sum + delay) / (data->seqno_data.rx_packets + 1));
}
-
- *(data->writer_lock) = 0;
+DONE:
+ clib_spinlock_unlock (&data->writer_lock);
return 0;
}
ip6_ioam_analyse_hbh_e2e (ioam_analyser_data_t * data,
ioam_e2e_packet_t * e2e, u16 len)
{
- while (__sync_lock_test_and_set (data->writer_lock, 1))
- ;
+ clib_spinlock_lock (&data->writer_lock);
ioam_analyze_seqno (&data->seqno_data,
(u64) clib_net_to_host_u32 (e2e->e2e_data));
- *(data->writer_lock) = 0;
+ clib_spinlock_unlock (&data->writer_lock);
+
return 0;
}
for (i = 0; i < num_of_elts; i++)
{
- s = format (s, "node_id: 0x%x, ingress_if: 0x%x, egress_if:0x%x\n",
- pm->node_id, pm->ingress_if, pm->egress_if);
+ s =
+ format (s,
+ "node_id: 0x%x, ingress_if: 0x%x, egress_if:0x%x, state:%s\n",
+ pm->node_id, pm->ingress_if, pm->egress_if,
+ pm->state_up ? "UP" : "DOWN");
pm++;
}
* get extended in future to maintain history of data */
vec_validate_aligned (data->chached_data_list, 0, CLIB_CACHE_LINE_BYTES);
- data->writer_lock = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
- CLIB_CACHE_LINE_BYTES);
- *(data->writer_lock) = 0;
+ clib_spinlock_init (&data->writer_lock);
trace_data = &(data->trace_data);
for (j = 0; j < IOAM_MAX_PATHS_PER_FLOW; j++)