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.
16 #ifndef included_vnet_lisp_gpe_h
17 #define included_vnet_lisp_gpe_h
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>
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;
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;
59 } lisp_gpe_tunnel_key_t;
61 typedef struct lisp_gpe_sub_tunnel
63 /* Rewrite string. $$$$ embed vnet_rewrite header */
66 u32 locator_pair_index;
69 } lisp_gpe_sub_tunnel_t;
71 typedef struct nomalized_sub_tunnel
75 } normalized_sub_tunnel_weights_t;
79 /* tunnel src and dst addresses */
80 locator_pair_t *locator_pairs;
82 /* locator-pairs with best priority become sub-tunnels */
83 lisp_gpe_sub_tunnel_t *sub_tunnels;
85 /* sub-tunnels load balancing vector: contains list of sub-tunnel
86 * indexes replicated according to weight */
89 /* number of entries in load balancing vector */
90 u32 sub_tunnels_lbv_count;
92 /* normalized sub tunnel weights */
93 normalized_sub_tunnel_weights_t *norm_sub_tunnel_weights;
95 /* decap next index */
99 ip_address_t src, dst;
102 u32 encap_fib_index; /* tunnel partner lookup here */
103 u32 decap_fib_index; /* inner IP lookup here */
105 /* vnet intfc hw/sw_if_index */
109 /* action for 'negative' tunnels */
112 /* LISP header fields in HOST byte order */
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")
128 #define _(s,n) LISP_GPE_INPUT_NEXT_##s,
129 foreach_lisp_gpe_ip_input_next
131 LISP_GPE_INPUT_N_NEXT,
132 } lisp_gpe_input_next_t;
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
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
145 typedef ip4_fib_t ip4_src_fib_t;
147 typedef struct ip6_src_fib
149 BVT (clib_bihash) ip6_lookup_table;
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];
157 /* ip6 lookup table config parameters */
158 u32 lookup_table_nbuckets;
159 uword lookup_table_size;
162 typedef struct tunnel_lookup
164 /* Lookup lisp-gpe interfaces by dp table (eg. vrf/bridge index) */
165 uword *hw_if_index_by_dp_table;
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;
172 typedef struct lisp_gpe_main
174 /* pool of encap tunnel instances */
175 lisp_gpe_tunnel_t *tunnels;
177 /* lookup tunnel by key */
178 mhash_t lisp_gpe_tunnel_by_key;
180 /* Free vlib hw_if_indices */
181 u32 *free_tunnel_hw_if_indices;
185 /* L3 data structures
186 * ================== */
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;
192 tunnel_lookup_t l3_ifaces;
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;
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;
202 /* L2 data structures
203 * ================== */
206 BVT (clib_bihash) l2_fib;
208 tunnel_lookup_t l2_ifaces;
211 vlib_main_t *vlib_main;
212 vnet_main_t *vnet_main;
215 ip_lookup_main_t *lm4;
216 ip_lookup_main_t *lm6;
219 lisp_gpe_main_t lisp_gpe_main;
221 always_inline lisp_gpe_main_t *
222 vnet_lisp_gpe_get_main ()
224 return &lisp_gpe_main;
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;
232 u8 *format_lisp_gpe_header_with_length (u8 * s, va_list * args);
249 u32 vni; /* host byte order */
250 } vnet_lisp_gpe_add_del_iface_args_t;
252 u8 vnet_lisp_gpe_enable_disable_status (void);
254 vnet_lisp_gpe_add_del_iface (vnet_lisp_gpe_add_del_iface_args_t * a,
260 } vnet_lisp_gpe_enable_disable_args_t;
263 * vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a);
269 /* type of mapping */
273 /* local and remote eids */
274 gid_address_t lcl_eid;
275 gid_address_t rmt_eid;
277 /* vector of locator pairs */
278 locator_pair_t *locator_pairs;
280 /* FIB indices to lookup remote locator at encap and inner IP at decap */
284 u32 decap_next_index; /* TODO is this really needed? */
286 /* VNI/tenant id in HOST byte order */
289 /* vrf or bd where fwd entry should be inserted */
298 } vnet_lisp_gpe_add_del_fwd_entry_args_t;
301 vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t * a,
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);
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);
312 #define foreach_lgpe_ip4_lookup_next \
313 _(DROP, "error-drop") \
314 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
316 typedef enum lgpe_ip4_lookup_next
318 #define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym,
319 foreach_lgpe_ip4_lookup_next
321 LGPE_IP4_LOOKUP_N_NEXT,
322 } lgpe_ip4_lookup_next_t;
324 #define foreach_lgpe_ip6_lookup_next \
325 _(DROP, "error-drop") \
326 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
328 typedef enum lgpe_ip6_lookup_next
330 #define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym,
331 foreach_lgpe_ip6_lookup_next
333 LGPE_IP6_LOOKUP_N_NEXT,
334 } lgpe_ip6_lookup_next_t;
336 u8 *format_vnet_lisp_gpe_status (u8 * s, va_list * args);
338 #define L2_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
339 #define L2_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20)
342 lisp_l2_fib_lookup (lisp_gpe_main_t * lgm, u16 bd_index, u8 src_mac[8],
345 #endif /* included_vnet_lisp_gpe_h */
348 * fd.io coding-style-patch-verification: ON
351 * eval: (c-set-style "gnu")