blob: acfaa37ed2f76bc36fc87168db5df304c159c208 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05302 * Copyright (c) 2016 Cisco and/or its affiliates.
Ed Warnickecb9cada2015-12-08 15:45:58 -07003 * 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 */
Ole Troan944f5482016-05-24 11:56:58 +020015#ifndef __included_ip6_hop_by_hop_ioam_h__
16#define __included_ip6_hop_by_hop_ioam_h__
Ed Warnickecb9cada2015-12-08 15:45:58 -070017
18#include <vnet/ip/ip6_hop_by_hop_packet.h>
Shwetha Bhandari05866a12016-05-04 08:12:57 +020019#include <vnet/ip/ip.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070020
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +053021
22#define MAX_IP6_HBH_OPTION 256
23
24/* To determine whether a node is decap MS bit is set */
25#define IOAM_DECAP_BIT 0x80000000
26
27#define IOAM_DEAP_ENABLED(opaque_data) (opaque_data & IOAM_DECAP_BIT)
28
29#define IOAM_SET_DECAP(opaque_data) \
30 (opaque_data |= IOAM_DECAP_BIT)
31
32#define IOAM_MASK_DECAP_BIT(x) (x & ~IOAM_DECAP_BIT)
33
34/*
35 * Stores the run time flow data of hbh options
36 */
Dave Barachd7cb1b52016-12-09 09:52:16 -050037typedef struct
38{
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +053039 u32 ctx[MAX_IP6_HBH_OPTION];
40 u8 flow_name[64];
41} flow_data_t;
42
Dave Barachd7cb1b52016-12-09 09:52:16 -050043typedef struct
44{
Ed Warnickecb9cada2015-12-08 15:45:58 -070045 /* The current rewrite we're using */
Dave Barachd7cb1b52016-12-09 09:52:16 -050046 u8 *rewrite;
Ed Warnickecb9cada2015-12-08 15:45:58 -070047
48 /* Trace data processing callback */
49 void *ioam_end_of_path_cb;
rangan4f810852016-03-18 03:31:17 +053050 /* Configuration data */
51 /* Adjacency */
52 ip6_address_t adj;
53#define IOAM_HBYH_ADD 0
54#define IOAM_HBYH_MOD 1
55#define IOAM_HBYH_POP 2
56 u8 ioam_flag;
57 /* time scale transform. Joy. */
58 u32 unix_time_0;
59 f64 vlib_time_0;
60
61
62 /* Trace option */
Vengada Govindan07d2f842016-08-25 10:34:34 -070063 u8 has_trace_option;
rangan4f810852016-03-18 03:31:17 +053064
Shwetha85b528e2016-06-15 16:34:16 +010065 /* Pot option */
66 u8 has_pot_option;
rangan4f810852016-03-18 03:31:17 +053067
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +053068 /* Per Packet Counter option */
69 u8 has_seqno_option;
70
71 /* Enabling analyis of iOAM data on decap node */
72 u8 has_analyse_option;
rangan4f810852016-03-18 03:31:17 +053073
Shwetha85b528e2016-06-15 16:34:16 +010074 /* Array of function pointers to ADD and POP HBH option handling routines */
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +053075 u8 options_size[MAX_IP6_HBH_OPTION];
Dave Barachd7cb1b52016-12-09 09:52:16 -050076 int (*add_options[MAX_IP6_HBH_OPTION]) (u8 * rewrite_string,
77 u8 * rewrite_size);
78 int (*pop_options[MAX_IP6_HBH_OPTION]) (vlib_buffer_t * b,
79 ip6_header_t * ip,
80 ip6_hop_by_hop_option_t * opt);
81 int (*get_sizeof_options[MAX_IP6_HBH_OPTION]) (u32 * rewrite_size);
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +053082 int (*config_handler[MAX_IP6_HBH_OPTION]) (void *data, u8 disable);
83
84 /* Array of function pointers to handle hbh options being used with classifier */
Dave Barachd7cb1b52016-12-09 09:52:16 -050085 u32 (*flow_handler[MAX_IP6_HBH_OPTION]) (u32 flow_ctx, u8 add);
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +053086 flow_data_t *flows;
87
Ed Warnickecb9cada2015-12-08 15:45:58 -070088 /* convenience */
Dave Barachd7cb1b52016-12-09 09:52:16 -050089 vlib_main_t *vlib_main;
90 vnet_main_t *vnet_main;
Ole Troan944f5482016-05-24 11:56:58 +020091} ip6_hop_by_hop_ioam_main_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070092
Ole Troan944f5482016-05-24 11:56:58 +020093extern ip6_hop_by_hop_ioam_main_t ip6_hop_by_hop_ioam_main;
rangan4f810852016-03-18 03:31:17 +053094
Dave Barachd7cb1b52016-12-09 09:52:16 -050095extern u8 *format_path_map (u8 * s, va_list * args);
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +053096
Dave Barachd7cb1b52016-12-09 09:52:16 -050097extern clib_error_t *ip6_ioam_enable (int has_trace_option,
98 int has_pot_option,
99 int has_seqno_option,
100 int has_analyse_option);
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +0530101
Dave Barachd7cb1b52016-12-09 09:52:16 -0500102extern int ip6_ioam_set_destination (ip6_address_t * addr, u32 mask_width,
103 u32 vrf_id, int is_add, int is_pop,
104 int is_none);
rangan4f810852016-03-18 03:31:17 +0530105
Dave Barachd7cb1b52016-12-09 09:52:16 -0500106extern clib_error_t *clear_ioam_rewrite_fn (void);
rangan4f810852016-03-18 03:31:17 +0530107
Dave Barachd7cb1b52016-12-09 09:52:16 -0500108static inline u8
109is_zero_ip4_address (ip4_address_t * a)
rangan4f810852016-03-18 03:31:17 +0530110{
111 return (a->as_u32 == 0);
112}
113
Dave Barachd7cb1b52016-12-09 09:52:16 -0500114static inline void
115copy_ip6_address (ip6_address_t * dst, ip6_address_t * src)
rangan4f810852016-03-18 03:31:17 +0530116{
117 dst->as_u64[0] = src->as_u64[0];
118 dst->as_u64[1] = src->as_u64[1];
119}
120
Dave Barachd7cb1b52016-12-09 09:52:16 -0500121static inline void
122set_zero_ip6_address (ip6_address_t * a)
rangan4f810852016-03-18 03:31:17 +0530123{
124 a->as_u64[0] = 0;
125 a->as_u64[1] = 0;
126}
127
Dave Barachd7cb1b52016-12-09 09:52:16 -0500128static inline u8
129cmp_ip6_address (ip6_address_t * a1, ip6_address_t * a2)
rangan4f810852016-03-18 03:31:17 +0530130{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500131 return ((a1->as_u64[0] == a2->as_u64[0])
132 && (a1->as_u64[1] == a2->as_u64[1]));
rangan4f810852016-03-18 03:31:17 +0530133}
Dave Barachd7cb1b52016-12-09 09:52:16 -0500134
135static inline u8
136is_zero_ip6_address (ip6_address_t * a)
rangan4f810852016-03-18 03:31:17 +0530137{
138 return ((a->as_u64[0] == 0) && (a->as_u64[1] == 0));
139}
140
Shwetha85b528e2016-06-15 16:34:16 +0100141int ip6_hbh_add_register_option (u8 option,
142 u8 size,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500143 int rewrite_options (u8 * rewrite_string,
144 u8 * size));
Shwetha85b528e2016-06-15 16:34:16 +0100145int ip6_hbh_add_unregister_option (u8 option);
146
147int ip6_hbh_pop_register_option (u8 option,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500148 int options (vlib_buffer_t * b,
149 ip6_header_t * ip,
150 ip6_hop_by_hop_option_t * opt));
Shwetha85b528e2016-06-15 16:34:16 +0100151int ip6_hbh_pop_unregister_option (u8 option);
152
Vengada Govindan07d2f842016-08-25 10:34:34 -0700153int
154ip6_hbh_get_sizeof_register_option (u8 option,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500155 int get_sizeof_hdr_options (u32 *
156 rewrite_size));
Shwetha85b528e2016-06-15 16:34:16 +0100157
Vengada Govindan07d2f842016-08-25 10:34:34 -0700158int
Dave Barachd7cb1b52016-12-09 09:52:16 -0500159ip6_ioam_set_rewrite (u8 ** rwp, int has_trace_option,
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +0530160 int has_pot_option, int has_seq_no);
161
162int
163ip6_hbh_config_handler_register (u8 option,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500164 int config_handler (void *data, u8 disable));
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +0530165
166int ip6_hbh_config_handler_unregister (u8 option);
167
Dave Barachd7cb1b52016-12-09 09:52:16 -0500168int ip6_hbh_flow_handler_register (u8 option,
169 u32 ioam_flow_handler (u32 flow_ctx,
170 u8 add));
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +0530171
Dave Barachd7cb1b52016-12-09 09:52:16 -0500172int ip6_hbh_flow_handler_unregister (u8 option);
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +0530173
Dave Barachd7cb1b52016-12-09 09:52:16 -0500174u8 *get_flow_name_from_flow_ctx (u32 flow_ctx);
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +0530175
Dave Barachd7cb1b52016-12-09 09:52:16 -0500176static inline flow_data_t *
177get_flow (u32 index)
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +0530178{
179 flow_data_t *flow = NULL;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500180 ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +0530181
182 if (pool_is_free_index (hm->flows, index))
183 return NULL;
184
185 flow = pool_elt_at_index (hm->flows, index);
186 return flow;
187}
188
Dave Barachd7cb1b52016-12-09 09:52:16 -0500189static inline u32
190get_flow_data_from_flow_ctx (u32 flow_ctx, u8 option)
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +0530191{
192 flow_data_t *flow = NULL;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500193 ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +0530194 u32 index;
195
Dave Barachd7cb1b52016-12-09 09:52:16 -0500196 index = IOAM_MASK_DECAP_BIT (flow_ctx);
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +0530197 //flow = pool_elt_at_index (hm->flows, index);
198 flow = &hm->flows[index];
199 return (flow->ctx[option]);
200}
201
Dave Barachd7cb1b52016-12-09 09:52:16 -0500202static inline u8
203is_seqno_enabled (void)
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +0530204{
205 return (ip6_hop_by_hop_ioam_main.has_seqno_option);
206}
207
Dave Barachd7cb1b52016-12-09 09:52:16 -0500208int ip6_trace_profile_setup ();
Ole Troan944f5482016-05-24 11:56:58 +0200209#endif /* __included_ip6_hop_by_hop_ioam_h__ */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500210
211/*
212 * fd.io coding-style-patch-verification: ON
213 *
214 * Local Variables:
215 * eval: (c-set-style "gnu")
216 * End:
217 */