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/udp/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 #include <vppinfra/bihash_24_8.h>
35 #include <vppinfra/bihash_template.h>
37 /** IP4-UDP-LISP encap header */
39 typedef CLIB_PACKED (struct {
40 ip4_header_t ip4; /* 20 bytes */
41 udp_header_t udp; /* 8 bytes */
42 lisp_gpe_header_t lisp; /* 8 bytes */
43 }) ip4_udp_lisp_gpe_header_t;
46 /** IP6-UDP-LISP encap header */
48 typedef CLIB_PACKED (struct {
49 ip6_header_t ip6; /* 40 bytes */
50 udp_header_t udp; /* 8 bytes */
51 lisp_gpe_header_t lisp; /* 8 bytes */
52 }) ip6_udp_lisp_gpe_header_t;
55 #define foreach_lisp_gpe_ip_input_next \
56 _(DROP, "error-drop") \
57 _(IP4_INPUT, "ip4-input") \
58 _(IP6_INPUT, "ip6-input") \
59 _(L2_INPUT, "l2-input")
61 /** Enum of possible next nodes post LISP-GPE decap */
64 #define _(s,n) LISP_GPE_INPUT_NEXT_##s,
65 foreach_lisp_gpe_ip_input_next
67 LISP_GPE_INPUT_N_NEXT,
68 } lisp_gpe_input_next_t;
70 /* Arc to nsh-input added only if nsh-input exists */
71 #define LISP_GPE_INPUT_NEXT_NSH_INPUT 4
75 #define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n,
76 #include <vnet/lisp-gpe/lisp_gpe_error.def>
81 typedef struct tunnel_lookup
83 /** Lookup lisp-gpe interfaces by dp table (eg. vrf/bridge index) */
84 uword *hw_if_index_by_dp_table;
86 /** lookup decap tunnel termination sw_if_index by vni and vice versa */
87 uword *sw_if_index_by_vni;
90 uword *vni_by_sw_if_index;
110 ip_address_t loc_rloc;
111 ip_address_t rmt_rloc;
116 typedef enum gpe_encap_mode_e
123 /** LISP-GPE global state*/
124 typedef struct lisp_gpe_main
127 * @brief DB of all forwarding entries. The Key is:{l-EID,r-EID,vni}
128 * where the EID encodes L2 or L3
130 uword *lisp_gpe_fwd_entries;
133 * @brief A Pool of all LISP forwarding entries
135 struct lisp_gpe_fwd_entry_t_ *lisp_fwd_entry_pool;
137 /** Free vlib hw_if_indices */
138 u32 *free_tunnel_hw_if_indices;
142 /* L3 data structures
143 * ================== */
144 tunnel_lookup_t l3_ifaces;
146 /* L2 data structures
147 * ================== */
150 BVT (clib_bihash) l2_fib;
152 tunnel_lookup_t l2_ifaces;
154 /** Load-balance for a miss in the table */
155 dpo_id_t l2_lb_cp_lkup;
157 /* NSH data structures
158 * ================== */
160 BVT (clib_bihash) nsh_fib;
162 tunnel_lookup_t nsh_ifaces;
164 const dpo_id_t *nsh_cp_lkup;
166 gpe_encap_mode_t encap_mode;
168 lisp_stats_t *lisp_stats_pool;
169 uword *lisp_stats_index_by_key;
172 vlib_main_t *vlib_main;
173 vnet_main_t *vnet_main;
176 ip_lookup_main_t *lm4;
177 ip_lookup_main_t *lm6;
180 /** LISP-GPE global state*/
181 lisp_gpe_main_t lisp_gpe_main;
183 always_inline lisp_gpe_main_t *
184 vnet_lisp_gpe_get_main ()
186 return &lisp_gpe_main;
190 extern vlib_node_registration_t lisp_gpe_ip4_input_node;
191 extern vlib_node_registration_t lisp_gpe_ip6_input_node;
192 extern vnet_hw_interface_class_t lisp_gpe_hw_class;
194 u8 *format_lisp_gpe_header_with_length (u8 * s, va_list * args);
196 /** Read LISP-GPE status */
197 u8 vnet_lisp_gpe_enable_disable_status (void);
200 lisp_gpe_l3_iface_find_or_create (lisp_gpe_main_t * lgm,
201 u32 overlay_table_id, u32 vni);
203 /** Add/del LISP-GPE interface. */
204 extern void lisp_gpe_del_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
205 extern u32 lisp_gpe_add_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
206 extern void lisp_gpe_del_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
207 extern u32 lisp_gpe_add_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
213 } vnet_lisp_gpe_enable_disable_args_t;
216 * vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a);
224 } negative_fwd_actions_e;
233 /** type of mapping */
236 /** action for negative mappings */
237 negative_fwd_actions_e action;
240 gid_address_t lcl_eid;
243 gid_address_t rmt_eid;
245 /** vector of locator pairs */
246 locator_pair_t *locator_pairs;
248 /** FIB index to lookup remote locator at encap */
251 /** FIB index to lookup inner IP at decap */
255 u32 decap_next_index;
257 /** VNI/tenant id in HOST byte order */
260 /** vrf or bd where fwd entry should be inserted */
263 /** table (vrf) id */
266 /** bridge domain id */
269 /** generic access */
272 } vnet_lisp_gpe_add_del_fwd_entry_args_t;
281 } lisp_api_gpe_fwd_entry_t;
283 #define foreach_lgpe_ip4_lookup_next \
284 _(DROP, "error-drop") \
285 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
287 typedef enum lgpe_ip4_lookup_next
289 #define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym,
290 foreach_lgpe_ip4_lookup_next
292 LGPE_IP4_LOOKUP_N_NEXT,
293 } lgpe_ip4_lookup_next_t;
295 #define foreach_lgpe_ip6_lookup_next \
296 _(DROP, "error-drop") \
297 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
299 typedef enum lgpe_ip6_lookup_next
301 #define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym,
302 foreach_lgpe_ip6_lookup_next
304 LGPE_IP6_LOOKUP_N_NEXT,
305 } lgpe_ip6_lookup_next_t;
307 u8 *format_vnet_lisp_gpe_status (u8 * s, va_list * args);
309 lisp_api_gpe_fwd_entry_t *vnet_lisp_gpe_fwd_entries_get_by_vni (u32 vni);
310 gpe_encap_mode_t vnet_gpe_get_encap_mode (void);
311 int vnet_gpe_set_encap_mode (gpe_encap_mode_t mode);
313 u8 vnet_lisp_stats_enable_disable_state (void);
314 vnet_api_error_t vnet_lisp_stats_enable_disable (u8 enable);
315 lisp_api_stats_t *vnet_lisp_get_stats (void);
316 void vnet_lisp_flush_stats (void);
318 #endif /* included_vnet_lisp_gpe_h */
321 * fd.io coding-style-patch-verification: ON
324 * eval: (c-set-style "gnu")