hs-test: cache docker build in local filesystem
[vpp.git] / src / plugins / ioam / analyse / ip6 / ip6_ioam_analyse.h
1 /*
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:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15
16 #ifndef PLUGINS_IOAM_PLUGIN_IOAM_ANALYSE_IP6_IOAM_ANALYSE_NODE_H_
17 #define PLUGINS_IOAM_PLUGIN_IOAM_ANALYSE_IP6_IOAM_ANALYSE_NODE_H_
18
19 #include <ioam/analyse/ioam_analyse.h>
20 #include <vnet/ip/ip6_hop_by_hop.h>
21 #include <ioam/encap/ip6_ioam_trace.h>
22
23 /** @brief IP6-iOAM analyser main structure.
24     @note cache aligned.
25 */
26 typedef struct
27 {
28   /** Array of function pointer to analyse each hop-by-hop option. */
29   int (*analyse_hbh_handler[MAX_IP6_HBH_OPTION]) (u32 flow_id,
30                                                   ip6_hop_by_hop_option_t *
31                                                   opt, u16 len);
32
33   /** This contains the aggregated data from the time VPP started analysing. */
34   ioam_analyser_data_t *aggregated_data;
35
36 } ip6_ioam_analyser_main_t;
37
38 extern ip6_ioam_analyser_main_t ioam_analyser_main;
39
40 extern vlib_node_registration_t analyse_node_local;
41 extern vlib_node_registration_t analyse_node_remote;
42
43 void ip6_ioam_analyse_register_handlers (void);
44
45 void ip6_ioam_analyse_unregister_handlers (void);
46
47 clib_error_t *ip6_ioam_analyse_init (vlib_main_t * vm);
48
49 inline static ioam_analyser_data_t *
50 ioam_analyse_get_data_from_flow_id (u32 flow_id)
51 {
52   if (flow_id >= vec_len (ioam_analyser_main.aggregated_data))
53     return NULL;
54
55   if (ioam_analyser_main.aggregated_data[flow_id].is_free)
56     ioam_analyser_main.aggregated_data[flow_id].is_free = 0;
57
58   return (ioam_analyser_main.aggregated_data + flow_id);
59 }
60
61 always_inline void *
62 ip6_ioam_find_hbh_option (ip6_hop_by_hop_header_t * hbh0, u8 option)
63 {
64   ip6_hop_by_hop_option_t *opt0, *limit0;
65   u8 type0;
66
67   opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
68   limit0 =
69     (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 + ((hbh0->length + 1) << 3));
70
71   while (opt0 < limit0)
72     {
73       type0 = opt0->type;
74       if (type0 == option)
75         return ((void *) opt0);
76
77       if (0 == type0)
78         {
79           opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
80           continue;
81         }
82       opt0 = (ip6_hop_by_hop_option_t *)
83         (((u8 *) opt0) + opt0->length + sizeof (ip6_hop_by_hop_option_t));
84     }
85
86   return NULL;
87 }
88
89 always_inline int
90 ip6_ioam_analyse_compare_path_delay (ip6_hop_by_hop_header_t * hbh0,
91                                      ip6_hop_by_hop_header_t * hbh1,
92                                      bool oneway)
93 {
94   ioam_trace_option_t *trace0 = NULL, *trace1 = NULL;
95   f64 delay0, delay1;
96
97   trace0 =
98     ip6_ioam_find_hbh_option (hbh0, HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST);
99   trace1 =
100     ip6_ioam_find_hbh_option (hbh1, HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST);
101
102   if (PREDICT_FALSE ((trace0 == NULL) && (trace1 == NULL)))
103     return 0;
104
105   if (PREDICT_FALSE (trace1 == NULL))
106     return 1;
107
108   if (PREDICT_FALSE (trace0 == NULL))
109     return -1;
110
111   delay0 = ip6_ioam_analyse_calc_delay (&trace0->trace_hdr,
112                                         trace0->hdr.length - 2, oneway);
113   delay1 = ip6_ioam_analyse_calc_delay (&trace1->trace_hdr,
114                                         trace1->hdr.length - 2, oneway);
115
116   return (delay0 - delay1);
117 }
118
119 #endif /* PLUGINS_IOAM_PLUGIN_IOAM_ANALYSE_IP6_IOAM_ANALYSE_NODE_H_ */
120
121 /*
122  * fd.io coding-style-patch-verification: ON
123  *
124  * Local Variables:
125  * eval: (c-set-style "gnu")
126  * End:
127  */