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.
17 * @brief LISP-GPE definitions.
20 #ifndef included_vnet_lisp_gpe_h
21 #define included_vnet_lisp_gpe_h
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>
34 /** IP4-UDP-LISP encap header */
36 typedef CLIB_PACKED (struct {
37 ip4_header_t ip4; /* 20 bytes */
38 udp_header_t udp; /* 8 bytes */
39 lisp_gpe_header_t lisp; /* 8 bytes */
40 }) ip4_udp_lisp_gpe_header_t;
43 /** IP6-UDP-LISP encap header */
45 typedef CLIB_PACKED (struct {
46 ip6_header_t ip6; /* 40 bytes */
47 udp_header_t udp; /* 8 bytes */
48 lisp_gpe_header_t lisp; /* 8 bytes */
49 }) ip6_udp_lisp_gpe_header_t;
52 /** LISP-GPE tunnel key */
65 } lisp_gpe_tunnel_key_t;
67 typedef struct lisp_gpe_sub_tunnel
69 /** Rewrite string. $$$$ embed vnet_rewrite header */
72 u32 locator_pair_index;
75 } lisp_gpe_sub_tunnel_t;
77 typedef struct nomalized_sub_tunnel
81 } normalized_sub_tunnel_weights_t;
83 /** LISP-GPE tunnel structure */
86 /** tunnel src and dst addresses */
87 locator_pair_t *locator_pairs;
89 /** locator-pairs with best priority become sub-tunnels */
90 lisp_gpe_sub_tunnel_t *sub_tunnels;
92 /** sub-tunnels load balancing vector: contains list of sub-tunnel
93 * indexes replicated according to weight */
96 /** number of entries in load balancing vector */
97 u32 sub_tunnels_lbv_count;
99 /** normalized sub tunnel weights */
100 normalized_sub_tunnel_weights_t *norm_sub_tunnel_weights;
102 /** decap next index */
103 u32 decap_next_index;
106 ip_address_t src, dst;
109 u32 encap_fib_index; /* tunnel partner lookup here */
110 u32 decap_fib_index; /* inner IP lookup here */
112 /** vnet intfc hw/sw_if_index */
116 /** action for 'negative' tunnels */
119 /** LISP header fields in HOST byte order */
127 #define foreach_lisp_gpe_ip_input_next \
128 _(DROP, "error-drop") \
129 _(IP4_INPUT, "ip4-input") \
130 _(IP6_INPUT, "ip6-input") \
131 _(L2_INPUT, "l2-input")
133 /** Enum of possible next nodes post LISP-GPE decap */
136 #define _(s,n) LISP_GPE_INPUT_NEXT_##s,
137 foreach_lisp_gpe_ip_input_next
139 LISP_GPE_INPUT_N_NEXT,
140 } lisp_gpe_input_next_t;
144 #define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n,
145 #include <vnet/lisp-gpe/lisp_gpe_error.def>
146 #undef lisp_gpe_error
151 * As a first step, reuse v4 fib. The goal of the typedef is
152 * to shield consumers from future updates that may result in the lisp ip4 fib
153 * diverging from ip4 fib
155 typedef ip4_fib_t ip4_src_fib_t;
157 /** IP6 source FIB */
158 typedef struct ip6_src_fib
160 BVT (clib_bihash) ip6_lookup_table;
162 /** bitmap/vector of mask widths to search */
163 uword *non_empty_dst_address_length_bitmap;
164 u8 *prefix_lengths_in_search_order;
165 ip6_address_t fib_masks[129];
166 i32 dst_address_length_refcounts[129];
168 /** ip6 lookup table config parameters */
169 u32 lookup_table_nbuckets;
170 uword lookup_table_size;
173 /** Tunnel lookup structure for L2 and L3 tunnels */
174 typedef struct tunnel_lookup
176 /** Lookup lisp-gpe interfaces by dp table (eg. vrf/bridge index) */
177 uword *hw_if_index_by_dp_table;
179 /** lookup decap tunnel termination sw_if_index by vni and vice versa */
180 uword *sw_if_index_by_vni;
181 uword *vni_by_sw_if_index;
184 /** LISP-GPE global state*/
185 typedef struct lisp_gpe_main
187 /** pool of encap tunnel instances */
188 lisp_gpe_tunnel_t *tunnels;
190 /** lookup tunnel by key */
191 mhash_t lisp_gpe_tunnel_by_key;
193 /** Free vlib hw_if_indices */
194 u32 *free_tunnel_hw_if_indices;
198 /* L3 data structures
199 * ================== */
201 /** Pool of src fibs that are paired with dst fibs */
202 ip4_src_fib_t *ip4_src_fibs;
203 ip6_src_fib_t *ip6_src_fibs;
205 tunnel_lookup_t l3_ifaces;
207 /** Lookup lgpe_ipX_lookup_next by vrf */
208 uword *lgpe_ip4_lookup_next_index_by_table_id;
209 uword *lgpe_ip6_lookup_next_index_by_table_id;
211 /** next node indexes that point ip4/6 lookup to lisp gpe ip lookup */
212 u32 ip4_lookup_next_lgpe_ip4_lookup;
213 u32 ip6_lookup_next_lgpe_ip6_lookup;
215 /* L2 data structures
216 * ================== */
219 BVT (clib_bihash) l2_fib;
221 tunnel_lookup_t l2_ifaces;
224 vlib_main_t *vlib_main;
225 vnet_main_t *vnet_main;
228 ip_lookup_main_t *lm4;
229 ip_lookup_main_t *lm6;
232 /** LISP-GPE global state*/
233 lisp_gpe_main_t lisp_gpe_main;
235 always_inline lisp_gpe_main_t *
236 vnet_lisp_gpe_get_main ()
238 return &lisp_gpe_main;
241 extern vlib_node_registration_t lgpe_ip4_lookup_node;
242 extern vlib_node_registration_t lgpe_ip6_lookup_node;
243 extern vlib_node_registration_t lisp_gpe_ip4_input_node;
244 extern vlib_node_registration_t lisp_gpe_ip6_input_node;
246 u8 *format_lisp_gpe_header_with_length (u8 * s, va_list * args);
248 /** Arguments to add an L2/L3 LISP-GPE interface*/
260 /** generic access */
265 /** virtual network identifier in host byte order */
267 } vnet_lisp_gpe_add_del_iface_args_t;
269 /** Read LISP-GPE status */
270 u8 vnet_lisp_gpe_enable_disable_status (void);
272 /** Add/del LISP-GPE interface. */
274 vnet_lisp_gpe_add_del_iface (vnet_lisp_gpe_add_del_iface_args_t * a,
280 } vnet_lisp_gpe_enable_disable_args_t;
283 * vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a);
290 /** type of mapping */
293 /** action for negative mappings */
297 gid_address_t lcl_eid;
300 gid_address_t rmt_eid;
302 /** vector of locator pairs */
303 locator_pair_t *locator_pairs;
305 /** FIB index to lookup remote locator at encap */
308 /** FIB index to lookup inner IP at decap */
312 u32 decap_next_index;
314 /** VNI/tenant id in HOST byte order */
317 /** vrf or bd where fwd entry should be inserted */
320 /** table (vrf) id */
323 /** bridge domain id */
326 /** generic access */
329 } vnet_lisp_gpe_add_del_fwd_entry_args_t;
332 vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t * a,
336 ip_sd_fib_add_del_route (lisp_gpe_main_t * lgm, ip_prefix_t * dst_prefix,
337 ip_prefix_t * src_prefix, u32 table_id,
338 ip_adjacency_t * add_adj, u8 is_add);
340 ip_sd_fib_get_route (lisp_gpe_main_t * lgm, ip_prefix_t * dst_prefix,
341 ip_prefix_t * src_prefix, u32 table_id);
343 #define foreach_lgpe_ip4_lookup_next \
344 _(DROP, "error-drop") \
345 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
347 typedef enum lgpe_ip4_lookup_next
349 #define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym,
350 foreach_lgpe_ip4_lookup_next
352 LGPE_IP4_LOOKUP_N_NEXT,
353 } lgpe_ip4_lookup_next_t;
355 #define foreach_lgpe_ip6_lookup_next \
356 _(DROP, "error-drop") \
357 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
359 typedef enum lgpe_ip6_lookup_next
361 #define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym,
362 foreach_lgpe_ip6_lookup_next
364 LGPE_IP6_LOOKUP_N_NEXT,
365 } lgpe_ip6_lookup_next_t;
367 u8 *format_vnet_lisp_gpe_status (u8 * s, va_list * args);
369 #define L2_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
370 #define L2_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20)
373 lisp_l2_fib_lookup (lisp_gpe_main_t * lgm, u16 bd_index, u8 src_mac[8],
376 #endif /* included_vnet_lisp_gpe_h */
379 * fd.io coding-style-patch-verification: ON
382 * eval: (c-set-style "gnu")