VPP-261 Coding standards cleanup - vnet/vnet/lisp-gpe
[vpp.git] / vnet / vnet / lisp-gpe / lisp_gpe.h
1 /*
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:
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 included_vnet_lisp_gpe_h
17 #define included_vnet_lisp_gpe_h
18
19 #include <vppinfra/error.h>
20 #include <vppinfra/mhash.h>
21 #include <vnet/vnet.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/l2/l2_input.h>
24 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/ip/ip4_packet.h>
26 #include <vnet/ip/udp.h>
27 #include <vnet/lisp-cp/lisp_types.h>
28 #include <vnet/lisp-gpe/lisp_gpe_packet.h>
29
30 /* encap headers */
31 /* *INDENT-OFF* */
32 typedef CLIB_PACKED (struct {
33   ip4_header_t ip4;             /* 20 bytes */
34   udp_header_t udp;             /* 8 bytes */
35   lisp_gpe_header_t lisp;       /* 8 bytes */
36 }) ip4_udp_lisp_gpe_header_t;
37 /* *INDENT-ON* */
38
39 /* *INDENT-OFF* */
40 typedef CLIB_PACKED (struct {
41   ip6_header_t ip6;             /* 40 bytes */
42   udp_header_t udp;             /* 8 bytes */
43   lisp_gpe_header_t lisp;       /* 8 bytes */
44 }) ip6_udp_lisp_gpe_header_t;
45 /* *INDENT-ON* */
46
47 typedef struct
48 {
49   union
50   {
51     struct
52     {
53       dp_address_t rmt;
54       dp_address_t lcl;
55       u32 vni;
56     };
57     u8 as_u8[40];
58   };
59 } lisp_gpe_tunnel_key_t;
60
61 typedef struct lisp_gpe_sub_tunnel
62 {
63   /* Rewrite string. $$$$ embed vnet_rewrite header */
64   u8 *rewrite;
65   u32 parent_index;
66   u32 locator_pair_index;
67   u8 weight;
68   u8 is_ip4;
69 } lisp_gpe_sub_tunnel_t;
70
71 typedef struct nomalized_sub_tunnel
72 {
73   u32 sub_tunnel_index;
74   u8 weight;
75 } normalized_sub_tunnel_weights_t;
76
77 typedef struct
78 {
79   /* tunnel src and dst addresses */
80   locator_pair_t *locator_pairs;
81
82   /* locator-pairs with best priority become sub-tunnels */
83   lisp_gpe_sub_tunnel_t *sub_tunnels;
84
85   /* sub-tunnels load balancing vector: contains list of sub-tunnel
86    * indexes replicated according to weight */
87   u32 *sub_tunnels_lbv;
88
89   /* number of entries in load balancing vector */
90   u32 sub_tunnels_lbv_count;
91
92   /* normalized sub tunnel weights */
93   normalized_sub_tunnel_weights_t *norm_sub_tunnel_weights;
94
95   /* decap next index */
96   u32 decap_next_index;
97
98   /* TODO remove */
99   ip_address_t src, dst;
100
101   /* FIB indices */
102   u32 encap_fib_index;          /* tunnel partner lookup here */
103   u32 decap_fib_index;          /* inner IP lookup here */
104
105   /* vnet intfc hw/sw_if_index */
106   u32 hw_if_index;
107   u32 sw_if_index;
108
109   /* action for 'negative' tunnels */
110   u8 action;
111
112   /* LISP header fields in HOST byte order */
113   u8 flags;
114   u8 ver_res;
115   u8 res;
116   u8 next_protocol;
117   u32 vni;
118 } lisp_gpe_tunnel_t;
119
120 #define foreach_lisp_gpe_ip_input_next          \
121 _(DROP, "error-drop")                           \
122 _(IP4_INPUT, "ip4-input")                       \
123 _(IP6_INPUT, "ip6-input")                       \
124 _(L2_INPUT, "l2-input")
125
126 typedef enum
127 {
128 #define _(s,n) LISP_GPE_INPUT_NEXT_##s,
129   foreach_lisp_gpe_ip_input_next
130 #undef _
131     LISP_GPE_INPUT_N_NEXT,
132 } lisp_gpe_input_next_t;
133
134 typedef enum
135 {
136 #define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n,
137 #include <vnet/lisp-gpe/lisp_gpe_error.def>
138 #undef lisp_gpe_error
139   LISP_GPE_N_ERROR,
140 } lisp_gpe_error_t;
141
142 /* As a first step, reuse v4 fib. The goal of the typedef is to shield
143  * consumers from future updates that may result in the lisp ip4 fib diverging
144  * from ip4 fib */
145 typedef ip4_fib_t ip4_src_fib_t;
146
147 typedef struct ip6_src_fib
148 {
149   BVT (clib_bihash) ip6_lookup_table;
150
151   /* bitmap/vector of mask widths to search */
152   uword *non_empty_dst_address_length_bitmap;
153   u8 *prefix_lengths_in_search_order;
154   ip6_address_t fib_masks[129];
155   i32 dst_address_length_refcounts[129];
156
157   /* ip6 lookup table config parameters */
158   u32 lookup_table_nbuckets;
159   uword lookup_table_size;
160 } ip6_src_fib_t;
161
162 typedef struct tunnel_lookup
163 {
164   /* Lookup lisp-gpe interfaces by dp table (eg. vrf/bridge index) */
165   uword *hw_if_index_by_dp_table;
166
167   /* lookup decap tunnel termination sw_if_index by vni and vice versa */
168   uword *sw_if_index_by_vni;
169   uword *vni_by_sw_if_index;
170 } tunnel_lookup_t;
171
172 typedef struct lisp_gpe_main
173 {
174   /* pool of encap tunnel instances */
175   lisp_gpe_tunnel_t *tunnels;
176
177   /* lookup tunnel by key */
178   mhash_t lisp_gpe_tunnel_by_key;
179
180   /* Free vlib hw_if_indices */
181   u32 *free_tunnel_hw_if_indices;
182
183   u8 is_en;
184
185   /* L3 data structures
186    * ================== */
187
188   /* Pool of src fibs that are paired with dst fibs */
189   ip4_src_fib_t *ip4_src_fibs;
190   ip6_src_fib_t *ip6_src_fibs;
191
192   tunnel_lookup_t l3_ifaces;
193
194   /* Lookup lgpe_ipX_lookup_next by vrf */
195   uword *lgpe_ip4_lookup_next_index_by_table_id;
196   uword *lgpe_ip6_lookup_next_index_by_table_id;
197
198   /* next node indexes that point ip4/6 lookup to lisp gpe ip lookup */
199   u32 ip4_lookup_next_lgpe_ip4_lookup;
200   u32 ip6_lookup_next_lgpe_ip6_lookup;
201
202   /* L2 data structures
203    * ================== */
204
205   /* l2 lisp fib */
206     BVT (clib_bihash) l2_fib;
207
208   tunnel_lookup_t l2_ifaces;
209
210   /* convenience */
211   vlib_main_t *vlib_main;
212   vnet_main_t *vnet_main;
213   ip4_main_t *im4;
214   ip6_main_t *im6;
215   ip_lookup_main_t *lm4;
216   ip_lookup_main_t *lm6;
217 } lisp_gpe_main_t;
218
219 lisp_gpe_main_t lisp_gpe_main;
220
221 always_inline lisp_gpe_main_t *
222 vnet_lisp_gpe_get_main ()
223 {
224   return &lisp_gpe_main;
225 }
226
227 extern vlib_node_registration_t lgpe_ip4_lookup_node;
228 extern vlib_node_registration_t lgpe_ip6_lookup_node;
229 extern vlib_node_registration_t lisp_gpe_ip4_input_node;
230 extern vlib_node_registration_t lisp_gpe_ip6_input_node;
231
232 u8 *format_lisp_gpe_header_with_length (u8 * s, va_list * args);
233
234 typedef struct
235 {
236   u8 is_add;
237   union
238   {
239     /* vrf */
240     u32 table_id;
241
242     /* bridge domain */
243     u16 bd_id;
244
245     /* generic access */
246     u32 dp_table;
247   };
248   u8 is_l2;
249   u32 vni;                      /* host byte order */
250 } vnet_lisp_gpe_add_del_iface_args_t;
251
252 u8 vnet_lisp_gpe_enable_disable_status (void);
253 int
254 vnet_lisp_gpe_add_del_iface (vnet_lisp_gpe_add_del_iface_args_t * a,
255                              u32 * hw_if_indexp);
256
257 typedef struct
258 {
259   u8 is_en;
260 } vnet_lisp_gpe_enable_disable_args_t;
261
262 clib_error_t
263   * vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a);
264
265 typedef struct
266 {
267   u8 is_add;
268
269   /* type of mapping */
270   u8 is_negative;
271   u8 action;
272
273   /* local and remote eids */
274   gid_address_t lcl_eid;
275   gid_address_t rmt_eid;
276
277   /* vector of locator pairs */
278   locator_pair_t *locator_pairs;
279
280   /* FIB indices to lookup remote locator at encap and inner IP at decap */
281   u32 encap_fib_index;
282   u32 decap_fib_index;
283
284   u32 decap_next_index;         /* TODO is this really needed? */
285
286   /* VNI/tenant id in HOST byte order */
287   u32 vni;
288
289   /* vrf or bd where fwd entry should be inserted */
290   union
291   {
292     u32 table_id;
293     u16 bd_id;
294
295     /* generic access */
296     u32 dp_table;
297   };
298 } vnet_lisp_gpe_add_del_fwd_entry_args_t;
299
300 int
301 vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t * a,
302                                  u32 * hw_if_indexp);
303
304 int
305 ip_sd_fib_add_del_route (lisp_gpe_main_t * lgm, ip_prefix_t * dst_prefix,
306                          ip_prefix_t * src_prefix, u32 table_id,
307                          ip_adjacency_t * add_adj, u8 is_add);
308 u32
309 ip_sd_fib_get_route (lisp_gpe_main_t * lgm, ip_prefix_t * dst_prefix,
310                      ip_prefix_t * src_prefix, u32 table_id);
311
312 #define foreach_lgpe_ip4_lookup_next    \
313   _(DROP, "error-drop")                 \
314   _(LISP_CP_LOOKUP, "lisp-cp-lookup")
315
316 typedef enum lgpe_ip4_lookup_next
317 {
318 #define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym,
319   foreach_lgpe_ip4_lookup_next
320 #undef _
321     LGPE_IP4_LOOKUP_N_NEXT,
322 } lgpe_ip4_lookup_next_t;
323
324 #define foreach_lgpe_ip6_lookup_next     \
325   _(DROP, "error-drop")                 \
326   _(LISP_CP_LOOKUP, "lisp-cp-lookup")
327
328 typedef enum lgpe_ip6_lookup_next
329 {
330 #define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym,
331   foreach_lgpe_ip6_lookup_next
332 #undef _
333     LGPE_IP6_LOOKUP_N_NEXT,
334 } lgpe_ip6_lookup_next_t;
335
336 u8 *format_vnet_lisp_gpe_status (u8 * s, va_list * args);
337
338 #define L2_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
339 #define L2_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20)
340
341 u32
342 lisp_l2_fib_lookup (lisp_gpe_main_t * lgm, u16 bd_index, u8 src_mac[8],
343                     u8 dst_mac[8]);
344
345 #endif /* included_vnet_lisp_gpe_h */
346
347 /*
348  * fd.io coding-style-patch-verification: ON
349  *
350  * Local Variables:
351  * eval: (c-set-style "gnu")
352  * End:
353  */