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>
33 #include <vnet/adj/adj_types.h>
35 /** IP4-UDP-LISP encap header */
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;
44 /** IP6-UDP-LISP encap header */
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;
53 /** LISP-GPE tunnel structure */
56 /** tunnel src and dst addresses */
57 locator_pair_t *locator_pairs;
59 /** locator-pairs with best priority become sub-tunnels */
62 /** decap next index */
66 ip_address_t src, dst;
69 u32 encap_fib_index; /* tunnel partner lookup here */
70 u32 decap_fib_index; /* inner IP lookup here */
72 /** index of the source address lookup FIB */
75 /** vnet intfc hw/sw_if_index */
80 fib_node_index_t l2_path_list;
82 /** action for 'negative' tunnels */
85 /** LISP header fields in HOST byte order */
94 * @brief A path on which to forward lisp traffic
96 typedef struct lisp_fwd_path_t_
99 * The adjacency constructed for the locator pair
104 * Priority. Only the paths with the best priority will be installed in FIB
109 * [UE]CMP weigt for the path
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.
121 typedef enum lisp_fwd_entry_type_t_
123 LISP_FWD_ENTRY_TYPE_NORMAL,
124 LISP_FWD_ENTRY_TYPE_NEGATIVE,
125 } lisp_fwd_entry_type_t;
133 } negative_fwd_actions_e;
136 * LISP-GPE fwd entry key
138 typedef struct lisp_gpe_fwd_entry_key_t_
143 } lisp_gpe_fwd_entry_key_t;
146 * @brief A LISP Forwarding Entry
148 * A forwarding entry is from a locai EID to a remote EID over a set of rloc pairs
150 typedef struct lisp_fwd_entry_t_
153 * The Entry's key: {lEID,r-EID,vni}
155 lisp_gpe_fwd_entry_key_t *key;
158 * The VRF (in the case of L3) or Bridge-Domain (for L2) index
167 * The forwarding entry type
169 lisp_fwd_entry_type_t type;
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.
178 lisp_fwd_path_t *paths;
181 * @brief When the type is negative. The action to take.
183 negative_fwd_actions_e action;
187 * The FIB index for the overlay, i.e. the FIB in which the EIDs
193 * The SRC-FIB index for created for anding source-route entries
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")
205 /** Enum of possible next nodes post LISP-GPE decap */
208 #define _(s,n) LISP_GPE_INPUT_NEXT_##s,
209 foreach_lisp_gpe_ip_input_next
211 LISP_GPE_INPUT_N_NEXT,
212 } lisp_gpe_input_next_t;
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
222 typedef struct tunnel_lookup
224 /** Lookup lisp-gpe interfaces by dp table (eg. vrf/bridge index) */
225 uword *hw_if_index_by_dp_table;
227 /** lookup decap tunnel termination sw_if_index by vni and vice versa */
228 uword *sw_if_index_by_vni;
230 // FIXME - Need this?
231 uword *vni_by_sw_if_index;
234 /** LISP-GPE global state*/
235 typedef struct lisp_gpe_main
237 /** pool of encap tunnel instances */
238 lisp_gpe_tunnel_t *tunnels;
240 /** Free vlib hw_if_indices */
241 u32 *free_tunnel_hw_if_indices;
245 /* L3 data structures
246 * ================== */
247 tunnel_lookup_t l3_ifaces;
249 /* L2 data structures
250 * ================== */
253 BVT (clib_bihash) l2_fib;
255 tunnel_lookup_t l2_ifaces;
257 /** Load-balance for a miss in the table */
259 index_t l2_lb_cp_lkup;
262 vlib_main_t *vlib_main;
263 vnet_main_t *vnet_main;
266 ip_lookup_main_t *lm4;
267 ip_lookup_main_t *lm6;
270 /** LISP-GPE global state*/
271 lisp_gpe_main_t lisp_gpe_main;
273 always_inline lisp_gpe_main_t *
274 vnet_lisp_gpe_get_main ()
276 return &lisp_gpe_main;
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;
284 u8 *format_lisp_gpe_header_with_length (u8 * s, va_list * args);
286 /** Arguments to add an L2/L3 LISP-GPE interface*/
298 /** generic access */
303 /** virtual network identifier in host byte order */
305 } vnet_lisp_gpe_add_del_iface_args_t;
307 /** Read LISP-GPE status */
308 u8 vnet_lisp_gpe_enable_disable_status (void);
310 /** Add/del LISP-GPE interface. */
312 vnet_lisp_gpe_add_del_iface (vnet_lisp_gpe_add_del_iface_args_t * a,
318 } vnet_lisp_gpe_enable_disable_args_t;
321 * vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a);
328 /** type of mapping */
331 /** action for negative mappings */
332 negative_fwd_actions_e action;
335 gid_address_t lcl_eid;
338 gid_address_t rmt_eid;
340 /** vector of locator pairs */
341 locator_pair_t *locator_pairs;
343 /** FIB index to lookup remote locator at encap */
346 /** FIB index to lookup inner IP at decap */
350 u32 decap_next_index;
352 /** VNI/tenant id in HOST byte order */
355 /** vrf or bd where fwd entry should be inserted */
358 /** table (vrf) id */
361 /** bridge domain id */
364 /** generic access */
367 } vnet_lisp_gpe_add_del_fwd_entry_args_t;
370 vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t * a,
374 ip_src_fib_add_route (u32 src_fib_index,
375 const ip_prefix_t * src_prefix,
376 const lisp_fwd_path_t * paths);
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);
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);
386 ip_dst_fib_add_route (u32 dst_table_id, const ip_prefix_t * dst_prefix);
388 extern fib_route_path_t *lisp_gpe_mk_paths_for_sub_tunnels (lisp_gpe_tunnel_t
391 #define foreach_lgpe_ip4_lookup_next \
392 _(DROP, "error-drop") \
393 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
395 typedef enum lgpe_ip4_lookup_next
397 #define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym,
398 foreach_lgpe_ip4_lookup_next
400 LGPE_IP4_LOOKUP_N_NEXT,
401 } lgpe_ip4_lookup_next_t;
403 #define foreach_lgpe_ip6_lookup_next \
404 _(DROP, "error-drop") \
405 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
407 typedef enum lgpe_ip6_lookup_next
409 #define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym,
410 foreach_lgpe_ip6_lookup_next
412 LGPE_IP6_LOOKUP_N_NEXT,
413 } lgpe_ip6_lookup_next_t;
415 u8 *format_vnet_lisp_gpe_status (u8 * s, va_list * args);
417 #define L2_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
418 #define L2_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20)
421 lisp_l2_fib_lookup (lisp_gpe_main_t * lgm, u16 bd_index, u8 src_mac[8],
424 #endif /* included_vnet_lisp_gpe_h */
427 * fd.io coding-style-patch-verification: ON
430 * eval: (c-set-style "gnu")