2 * Copyright (c) 2016 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.
15 #ifndef __included_ip6_hop_by_hop_ioam_h__
16 #define __included_ip6_hop_by_hop_ioam_h__
18 #include <vnet/ip/ip6_hop_by_hop_packet.h>
19 #include <vnet/ip/ip.h>
22 #define MAX_IP6_HBH_OPTION 256
24 /* To determine whether a node is decap MS bit is set */
25 #define IOAM_DECAP_BIT 0x80000000
27 #define IOAM_DEAP_ENABLED(opaque_data) (opaque_data & IOAM_DECAP_BIT)
29 #define IOAM_SET_DECAP(opaque_data) \
30 (opaque_data |= IOAM_DECAP_BIT)
32 #define IOAM_MASK_DECAP_BIT(x) (x & ~IOAM_DECAP_BIT)
35 * Stores the run time flow data of hbh options
39 u32 ctx[MAX_IP6_HBH_OPTION];
45 /* The current rewrite we're using */
48 /* Trace data processing callback */
49 void *ioam_end_of_path_cb;
50 /* Configuration data */
53 #define IOAM_HBYH_ADD 0
54 #define IOAM_HBYH_MOD 1
55 #define IOAM_HBYH_POP 2
57 /* time scale transform. Joy. */
68 /* Per Packet Counter option */
71 /* Enabling analyis of iOAM data on decap node */
72 u8 has_analyse_option;
74 /* Array of function pointers to ADD and POP HBH option handling routines */
75 u8 options_size[MAX_IP6_HBH_OPTION];
76 int (*add_options[MAX_IP6_HBH_OPTION]) (u8 * rewrite_string,
78 int (*pop_options[MAX_IP6_HBH_OPTION]) (vlib_buffer_t * b,
80 ip6_hop_by_hop_option_t * opt);
81 int (*get_sizeof_options[MAX_IP6_HBH_OPTION]) (u32 * rewrite_size);
82 int (*config_handler[MAX_IP6_HBH_OPTION]) (void *data, u8 disable);
84 /* Array of function pointers to handle hbh options being used with classifier */
85 u32 (*flow_handler[MAX_IP6_HBH_OPTION]) (u32 flow_ctx, u8 add);
89 vlib_main_t *vlib_main;
90 vnet_main_t *vnet_main;
91 } ip6_hop_by_hop_ioam_main_t;
93 extern ip6_hop_by_hop_ioam_main_t ip6_hop_by_hop_ioam_main;
95 extern clib_error_t *ip6_ioam_enable (int has_trace_option,
98 int has_analyse_option);
100 extern int ip6_ioam_set_destination (ip6_address_t * addr, u32 mask_width,
101 u32 vrf_id, int is_add, int is_pop,
104 extern clib_error_t *clear_ioam_rewrite_fn (void);
107 is_zero_ip4_address (ip4_address_t * a)
109 return (a->as_u32 == 0);
113 copy_ip6_address (ip6_address_t * dst, ip6_address_t * src)
115 dst->as_u64[0] = src->as_u64[0];
116 dst->as_u64[1] = src->as_u64[1];
120 set_zero_ip6_address (ip6_address_t * a)
127 cmp_ip6_address (ip6_address_t * a1, ip6_address_t * a2)
129 return ((a1->as_u64[0] == a2->as_u64[0])
130 && (a1->as_u64[1] == a2->as_u64[1]));
134 is_zero_ip6_address (ip6_address_t * a)
136 return ((a->as_u64[0] == 0) && (a->as_u64[1] == 0));
139 int ip6_hbh_add_register_option (u8 option,
141 int rewrite_options (u8 * rewrite_string,
143 int ip6_hbh_add_unregister_option (u8 option);
145 int ip6_hbh_pop_register_option (u8 option,
146 int options (vlib_buffer_t * b,
148 ip6_hop_by_hop_option_t * opt));
149 int ip6_hbh_pop_unregister_option (u8 option);
152 ip6_hbh_get_sizeof_register_option (u8 option,
153 int get_sizeof_hdr_options (u32 *
157 ip6_ioam_set_rewrite (u8 ** rwp, int has_trace_option,
158 int has_pot_option, int has_seq_no);
161 ip6_hbh_config_handler_register (u8 option,
162 int config_handler (void *data, u8 disable));
164 int ip6_hbh_config_handler_unregister (u8 option);
166 int ip6_hbh_flow_handler_register (u8 option,
167 u32 ioam_flow_handler (u32 flow_ctx,
170 int ip6_hbh_flow_handler_unregister (u8 option);
172 u8 *get_flow_name_from_flow_ctx (u32 flow_ctx);
174 static inline flow_data_t *
177 flow_data_t *flow = NULL;
178 ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
180 if (pool_is_free_index (hm->flows, index))
183 flow = pool_elt_at_index (hm->flows, index);
188 get_flow_data_from_flow_ctx (u32 flow_ctx, u8 option)
190 flow_data_t *flow = NULL;
191 ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
194 index = IOAM_MASK_DECAP_BIT (flow_ctx);
195 //flow = pool_elt_at_index (hm->flows, index);
196 flow = &hm->flows[index];
197 return (flow->ctx[option]);
201 is_seqno_enabled (void)
203 return (ip6_hop_by_hop_ioam_main.has_seqno_option);
206 int ip6_trace_profile_setup ();
209 ioam_flow_add (u8 encap, u8 * flow_name)
211 ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
212 flow_data_t *flow = 0;
216 pool_get (hm->flows, flow);
217 clib_memset (flow, 0, sizeof (flow_data_t));
219 index = flow - hm->flows;
220 strncpy ((char *) flow->flow_name, (char *) flow_name, 31);
223 IOAM_SET_DECAP (index);
225 for (i = 0; i < 255; i++)
227 if (hm->flow_handler[i])
228 flow->ctx[i] = hm->flow_handler[i] (index, 1);
233 always_inline ip6_hop_by_hop_option_t *
234 ip6_hbh_get_option (ip6_hop_by_hop_header_t * hbh0, u8 option_to_search)
236 ip6_hop_by_hop_option_t *opt0, *limit0;
242 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
243 limit0 = (ip6_hop_by_hop_option_t *)
244 ((u8 *) hbh0 + ((hbh0->length + 1) << 3));
246 /* Scan the set of h-b-h options, process ones that we understand */
247 while (opt0 < limit0)
253 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
258 if (type0 == option_to_search)
263 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
264 sizeof (ip6_hop_by_hop_option_t));
269 #endif /* __included_ip6_hop_by_hop_ioam_h__ */
272 * fd.io coding-style-patch-verification: ON
275 * eval: (c-set-style "gnu")