A Protocol Independent Hierarchical FIB (VPP-352)
[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  * @file
17  * @brief LISP-GPE definitions.
18  */
19
20 #ifndef included_vnet_lisp_gpe_h
21 #define included_vnet_lisp_gpe_h
22
23 #include <vppinfra/error.h>
24 #include <vppinfra/mhash.h>
25 #include <vnet/vnet.h>
26 #include <vnet/ip/ip.h>
27 #include <vnet/l2/l2_input.h>
28 #include <vnet/ethernet/ethernet.h>
29 #include <vnet/ip/ip4_packet.h>
30 #include <vnet/ip/udp.h>
31 #include <vnet/lisp-cp/lisp_types.h>
32 #include <vnet/lisp-gpe/lisp_gpe_packet.h>
33 #include <vnet/adj/adj_types.h>
34
35 /** IP4-UDP-LISP encap header */
36 /* *INDENT-OFF* */
37 typedef CLIB_PACKED (struct {
38   ip4_header_t ip4;             /* 20 bytes */
39   udp_header_t udp;             /* 8 bytes */
40   lisp_gpe_header_t lisp;       /* 8 bytes */
41 }) ip4_udp_lisp_gpe_header_t;
42 /* *INDENT-ON* */
43
44 /** IP6-UDP-LISP encap header */
45 /* *INDENT-OFF* */
46 typedef CLIB_PACKED (struct {
47   ip6_header_t ip6;             /* 40 bytes */
48   udp_header_t udp;             /* 8 bytes */
49   lisp_gpe_header_t lisp;       /* 8 bytes */
50 }) ip6_udp_lisp_gpe_header_t;
51 /* *INDENT-ON* */
52
53 /** LISP-GPE tunnel structure */
54 typedef struct
55 {
56   /** tunnel src and dst addresses */
57   locator_pair_t *locator_pairs;
58
59   /** locator-pairs with best priority become sub-tunnels */
60   u32 *sub_tunnels;
61
62   /** decap next index */
63   u32 decap_next_index;
64
65   /* TODO remove */
66   ip_address_t src, dst;
67
68   /** FIB indices */
69   u32 encap_fib_index;          /* tunnel partner lookup here */
70   u32 decap_fib_index;          /* inner IP lookup here */
71
72   /** index of the source address lookup FIB */
73   u32 src_fib_index;
74
75   /** vnet intfc hw/sw_if_index */
76   u32 hw_if_index;
77   u32 sw_if_index;
78
79   /** L2 path-list */
80   fib_node_index_t l2_path_list;
81
82   /** action for 'negative' tunnels */
83   u8 action;
84
85   /** LISP header fields in HOST byte order */
86   u8 flags;
87   u8 ver_res;
88   u8 res;
89   u8 next_protocol;
90   u32 vni;
91 } lisp_gpe_tunnel_t;
92
93 /**
94  * @brief A path on which to forward lisp traffic
95  */
96 typedef struct lisp_fwd_path_t_
97 {
98   /**
99    * The adjacency constructed for the locator pair
100    */
101   index_t lisp_adj;
102
103   /**
104    * Priority. Only the paths with the best priority will be installed in FIB
105    */
106   u8 priority;
107
108   /**
109    * [UE]CMP weigt for the path
110    */
111   u8 weight;
112
113 } lisp_fwd_path_t;
114
115 /**
116  * @brief A Forwarding entry can be 'normal' or 'negative'
117  * Negative implies we deliberately want to add a FIB entry for an EID
118  * that results in 'spcial' behaviour determined by an 'action'.
119  * @normal' means send it down some tunnels.
120  */
121 typedef enum lisp_fwd_entry_type_t_
122 {
123   LISP_FWD_ENTRY_TYPE_NORMAL,
124   LISP_FWD_ENTRY_TYPE_NEGATIVE,
125 } lisp_fwd_entry_type_t;
126
127 typedef enum
128 {
129   NO_ACTION,
130   FORWARD_NATIVE,
131   SEND_MAP_REQUEST,
132   DROP
133 } negative_fwd_actions_e;
134
135 /**
136  * LISP-GPE fwd entry key
137  */
138 typedef struct lisp_gpe_fwd_entry_key_t_
139 {
140   dp_address_t rmt;
141   dp_address_t lcl;
142   u32 vni;
143 } lisp_gpe_fwd_entry_key_t;
144
145 /**
146  * @brief A LISP Forwarding Entry
147  *
148  * A forwarding entry is from a locai EID to a remote EID over a set of rloc pairs
149  */
150 typedef struct lisp_fwd_entry_t_
151 {
152   /**
153    * The Entry's key: {lEID,r-EID,vni}
154    */
155   lisp_gpe_fwd_entry_key_t *key;
156
157   /**
158    * The VRF (in the case of L3) or Bridge-Domain (for L2) index
159    */
160   union
161   {
162     u32 eid_table_id;
163     u32 eid_bd_index;
164   };
165
166   /**
167    * The forwarding entry type
168    */
169   lisp_fwd_entry_type_t type;
170
171   union
172   {
173     /**
174      * @brief When the type is 'normal'
175      *        The RLOC pair that form the route's paths. i.e. where to send
176      *        packets for this route.
177      */
178     lisp_fwd_path_t *paths;
179
180     /**
181      * @brief When the type is negative. The action to take.
182      */
183     negative_fwd_actions_e action;
184   };
185
186   /**
187    * The FIB index for the overlay, i.e. the FIB in which the EIDs
188    * are present
189    */
190   u32 eid_fib_index;
191
192   /**
193    * The SRC-FIB index for created for anding source-route entries
194    */
195   u32 src_fib_index;
196 } lisp_fwd_entry_t;
197
198
199 #define foreach_lisp_gpe_ip_input_next          \
200 _(DROP, "error-drop")                           \
201 _(IP4_INPUT, "ip4-input")                       \
202 _(IP6_INPUT, "ip6-input")                       \
203 _(L2_INPUT, "l2-input")
204
205 /** Enum of possible next nodes post LISP-GPE decap */
206 typedef enum
207 {
208 #define _(s,n) LISP_GPE_INPUT_NEXT_##s,
209   foreach_lisp_gpe_ip_input_next
210 #undef _
211     LISP_GPE_INPUT_N_NEXT,
212 } lisp_gpe_input_next_t;
213
214 typedef enum
215 {
216 #define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n,
217 #include <vnet/lisp-gpe/lisp_gpe_error.def>
218 #undef lisp_gpe_error
219   LISP_GPE_N_ERROR,
220 } lisp_gpe_error_t;
221
222 typedef struct tunnel_lookup
223 {
224   /** Lookup lisp-gpe interfaces by dp table (eg. vrf/bridge index) */
225   uword *hw_if_index_by_dp_table;
226
227   /** lookup decap tunnel termination sw_if_index by vni and vice versa */
228   uword *sw_if_index_by_vni;
229
230   // FIXME - Need this?
231   uword *vni_by_sw_if_index;
232 } tunnel_lookup_t;
233
234 /** LISP-GPE global state*/
235 typedef struct lisp_gpe_main
236 {
237   /** pool of encap tunnel instances */
238   lisp_gpe_tunnel_t *tunnels;
239
240   /** Free vlib hw_if_indices */
241   u32 *free_tunnel_hw_if_indices;
242
243   u8 is_en;
244
245   /* L3 data structures
246    * ================== */
247   tunnel_lookup_t l3_ifaces;
248
249   /* L2 data structures
250    * ================== */
251
252   /** L2 LISP FIB */
253     BVT (clib_bihash) l2_fib;
254
255   tunnel_lookup_t l2_ifaces;
256
257   /** Load-balance for a miss in the table */
258   index_t l2_lb_miss;
259   index_t l2_lb_cp_lkup;
260
261   /** convenience */
262   vlib_main_t *vlib_main;
263   vnet_main_t *vnet_main;
264   ip4_main_t *im4;
265   ip6_main_t *im6;
266   ip_lookup_main_t *lm4;
267   ip_lookup_main_t *lm6;
268 } lisp_gpe_main_t;
269
270 /** LISP-GPE global state*/
271 lisp_gpe_main_t lisp_gpe_main;
272
273 always_inline lisp_gpe_main_t *
274 vnet_lisp_gpe_get_main ()
275 {
276   return &lisp_gpe_main;
277 }
278
279
280 extern vlib_node_registration_t lisp_gpe_ip4_input_node;
281 extern vlib_node_registration_t lisp_gpe_ip6_input_node;
282 extern vnet_hw_interface_class_t lisp_gpe_hw_class;
283
284 u8 *format_lisp_gpe_header_with_length (u8 * s, va_list * args);
285
286 /** Arguments to add an L2/L3 LISP-GPE interface*/
287 typedef struct
288 {
289   u8 is_add;
290   union
291   {
292     /** vrf */
293     u32 table_id;
294
295     /** bridge domain */
296     u16 bd_id;
297
298     /** generic access */
299     u32 dp_table;
300   };
301   u8 is_l2;
302
303   /** virtual network identifier in host byte order */
304   u32 vni;
305 } vnet_lisp_gpe_add_del_iface_args_t;
306
307 /** Read LISP-GPE status */
308 u8 vnet_lisp_gpe_enable_disable_status (void);
309
310 /** Add/del LISP-GPE interface. */
311 int
312 vnet_lisp_gpe_add_del_iface (vnet_lisp_gpe_add_del_iface_args_t * a,
313                              u32 * hw_if_indexp);
314
315 typedef struct
316 {
317   u8 is_en;
318 } vnet_lisp_gpe_enable_disable_args_t;
319
320 clib_error_t
321   * vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a);
322
323 /** */
324 typedef struct
325 {
326   u8 is_add;
327
328   /** type of mapping */
329   u8 is_negative;
330
331   /** action for negative mappings */
332   negative_fwd_actions_e action;
333
334   /** local eid */
335   gid_address_t lcl_eid;
336
337   /** remote eid */
338   gid_address_t rmt_eid;
339
340   /** vector of locator pairs */
341   locator_pair_t *locator_pairs;
342
343   /** FIB index to lookup remote locator at encap */
344   u32 encap_fib_index;
345
346   /** FIB index to lookup inner IP at decap */
347   u32 decap_fib_index;
348
349   /* TODO remove */
350   u32 decap_next_index;
351
352   /** VNI/tenant id in HOST byte order */
353   u32 vni;
354
355   /** vrf or bd where fwd entry should be inserted */
356   union
357   {
358     /** table (vrf) id */
359     u32 table_id;
360
361     /** bridge domain id */
362     u16 bd_id;
363
364     /** generic access */
365     u32 dp_table;
366   };
367 } vnet_lisp_gpe_add_del_fwd_entry_args_t;
368
369 int
370 vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t * a,
371                                  u32 * hw_if_indexp);
372
373 extern void
374 ip_src_fib_add_route (u32 src_fib_index,
375                       const ip_prefix_t * src_prefix,
376                       const lisp_fwd_path_t * paths);
377 extern void
378 ip_src_dst_fib_del_route (u32 src_fib_index,
379                           const ip_prefix_t * src_prefix,
380                           u32 dst_table_id, const ip_prefix_t * dst_prefix);
381 extern void
382 ip_src_fib_add_route_w_dpo (u32 src_fib_index,
383                             const ip_prefix_t * src_prefix,
384                             const dpo_id_t * src_dpo);
385 extern u32
386 ip_dst_fib_add_route (u32 dst_table_id, const ip_prefix_t * dst_prefix);
387
388 extern fib_route_path_t *lisp_gpe_mk_paths_for_sub_tunnels (lisp_gpe_tunnel_t
389                                                             * t);
390
391 #define foreach_lgpe_ip4_lookup_next    \
392   _(DROP, "error-drop")                 \
393   _(LISP_CP_LOOKUP, "lisp-cp-lookup")
394
395 typedef enum lgpe_ip4_lookup_next
396 {
397 #define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym,
398   foreach_lgpe_ip4_lookup_next
399 #undef _
400     LGPE_IP4_LOOKUP_N_NEXT,
401 } lgpe_ip4_lookup_next_t;
402
403 #define foreach_lgpe_ip6_lookup_next    \
404   _(DROP, "error-drop")                 \
405   _(LISP_CP_LOOKUP, "lisp-cp-lookup")
406
407 typedef enum lgpe_ip6_lookup_next
408 {
409 #define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym,
410   foreach_lgpe_ip6_lookup_next
411 #undef _
412     LGPE_IP6_LOOKUP_N_NEXT,
413 } lgpe_ip6_lookup_next_t;
414
415 u8 *format_vnet_lisp_gpe_status (u8 * s, va_list * args);
416
417 #define L2_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
418 #define L2_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20)
419
420 u32
421 lisp_l2_fib_lookup (lisp_gpe_main_t * lgm, u16 bd_index, u8 src_mac[8],
422                     u8 dst_mac[8]);
423
424 #endif /* included_vnet_lisp_gpe_h */
425
426 /*
427  * fd.io coding-style-patch-verification: ON
428  *
429  * Local Variables:
430  * eval: (c-set-style "gnu")
431  * End:
432  */