blob: 5eafdd55ffc33af94768088ddc1c5ba648fcb49c [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
Florin Corase127a7e2016-02-18 22:20:01 +01002 * Copyright (c) 2016 Cisco and/or its affiliates.
Ed Warnickecb9cada2015-12-08 15:45:58 -07003 * 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 */
Florin Corasff0bf132016-09-05 19:30:35 +020015/**
16 * @file
17 * @brief LISP-GPE definitions.
18 */
Florin Corase127a7e2016-02-18 22:20:01 +010019
Ed Warnickecb9cada2015-12-08 15:45:58 -070020#ifndef included_vnet_lisp_gpe_h
21#define included_vnet_lisp_gpe_h
22
23#include <vppinfra/error.h>
Florin Corase127a7e2016-02-18 22:20:01 +010024#include <vppinfra/mhash.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070025#include <vnet/vnet.h>
26#include <vnet/ip/ip.h>
27#include <vnet/l2/l2_input.h>
28#include <vnet/ethernet/ethernet.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070029#include <vnet/ip/ip4_packet.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050030#include <vnet/udp/udp.h>
Florin Corase127a7e2016-02-18 22:20:01 +010031#include <vnet/lisp-cp/lisp_types.h>
32#include <vnet/lisp-gpe/lisp_gpe_packet.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010033#include <vnet/adj/adj_types.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050034#include <vppinfra/bihash_24_8.h>
35#include <vppinfra/bihash_template.h>
Florin Corase127a7e2016-02-18 22:20:01 +010036
Florin Corasff0bf132016-09-05 19:30:35 +020037/** IP4-UDP-LISP encap header */
Florin Coras220beac2016-08-16 23:04:00 +020038/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070039typedef 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;
Florin Coras220beac2016-08-16 23:04:00 +020044/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070045
Florin Corasff0bf132016-09-05 19:30:35 +020046/** IP6-UDP-LISP encap header */
Florin Coras220beac2016-08-16 23:04:00 +020047/* *INDENT-OFF* */
Florin Coras02655bd2016-04-26 00:17:24 +020048typedef 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;
Florin Coras220beac2016-08-16 23:04:00 +020053/* *INDENT-ON* */
Florin Coras02655bd2016-04-26 00:17:24 +020054
Florin Coras02655bd2016-04-26 00:17:24 +020055#define foreach_lisp_gpe_ip_input_next \
Ed Warnickecb9cada2015-12-08 15:45:58 -070056_(DROP, "error-drop") \
57_(IP4_INPUT, "ip4-input") \
58_(IP6_INPUT, "ip6-input") \
Florin Coras1a1adc72016-07-22 01:45:30 +020059_(L2_INPUT, "l2-input")
Ed Warnickecb9cada2015-12-08 15:45:58 -070060
Florin Corasff0bf132016-09-05 19:30:35 +020061/** Enum of possible next nodes post LISP-GPE decap */
Florin Coras220beac2016-08-16 23:04:00 +020062typedef enum
63{
Ed Warnickecb9cada2015-12-08 15:45:58 -070064#define _(s,n) LISP_GPE_INPUT_NEXT_##s,
Florin Coras02655bd2016-04-26 00:17:24 +020065 foreach_lisp_gpe_ip_input_next
Ed Warnickecb9cada2015-12-08 15:45:58 -070066#undef _
Florin Coras220beac2016-08-16 23:04:00 +020067 LISP_GPE_INPUT_N_NEXT,
Ed Warnickecb9cada2015-12-08 15:45:58 -070068} lisp_gpe_input_next_t;
69
Florin Coras263440e2017-02-22 23:38:08 -080070/* Arc to nsh-input added only if nsh-input exists */
71#define LISP_GPE_INPUT_NEXT_NSH_INPUT 4
72
Florin Coras220beac2016-08-16 23:04:00 +020073typedef enum
74{
Ed Warnickecb9cada2015-12-08 15:45:58 -070075#define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n,
76#include <vnet/lisp-gpe/lisp_gpe_error.def>
77#undef lisp_gpe_error
78 LISP_GPE_N_ERROR,
Florin Coras577c3552016-04-21 00:45:40 +020079} lisp_gpe_error_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070080
Florin Coras1a1adc72016-07-22 01:45:30 +020081typedef struct tunnel_lookup
82{
Florin Corasff0bf132016-09-05 19:30:35 +020083 /** Lookup lisp-gpe interfaces by dp table (eg. vrf/bridge index) */
Florin Coras220beac2016-08-16 23:04:00 +020084 uword *hw_if_index_by_dp_table;
Florin Coras1a1adc72016-07-22 01:45:30 +020085
Florin Corasff0bf132016-09-05 19:30:35 +020086 /** lookup decap tunnel termination sw_if_index by vni and vice versa */
Florin Coras220beac2016-08-16 23:04:00 +020087 uword *sw_if_index_by_vni;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010088
89 // FIXME - Need this?
Florin Coras220beac2016-08-16 23:04:00 +020090 uword *vni_by_sw_if_index;
Florin Coras1a1adc72016-07-22 01:45:30 +020091} tunnel_lookup_t;
92
Filip Tehlar4868ff62017-03-09 16:48:39 +010093typedef struct
94{
95 u32 fwd_entry_index;
96 u32 tunnel_index;
97} lisp_stats_key_t;
98
99typedef struct
100{
Filip Tehlar4868ff62017-03-09 16:48:39 +0100101 u32 vni;
102 dp_address_t deid;
103 dp_address_t seid;
104 ip_address_t loc_rloc;
105 ip_address_t rmt_rloc;
106
Filip Tehlar21511912017-04-07 10:41:42 +0200107 vlib_counter_t counters;
Filip Tehlar4868ff62017-03-09 16:48:39 +0100108} lisp_api_stats_t;
Filip Tehlar3e7b56932017-02-21 18:28:34 +0100109
110typedef enum gpe_encap_mode_e
111{
112 GPE_ENCAP_LISP,
113 GPE_ENCAP_VXLAN,
114 GPE_ENCAP_COUNT
115} gpe_encap_mode_t;
116
Florin Corasff0bf132016-09-05 19:30:35 +0200117/** LISP-GPE global state*/
Florin Corase127a7e2016-02-18 22:20:01 +0100118typedef struct lisp_gpe_main
119{
Neale Ranns5e575b12016-10-03 09:40:25 +0100120 /**
121 * @brief DB of all forwarding entries. The Key is:{l-EID,r-EID,vni}
122 * where the EID encodes L2 or L3
123 */
124 uword *lisp_gpe_fwd_entries;
125
126 /**
127 * @brief A Pool of all LISP forwarding entries
128 */
129 struct lisp_gpe_fwd_entry_t_ *lisp_fwd_entry_pool;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700130
Florin Corasff0bf132016-09-05 19:30:35 +0200131 /** Free vlib hw_if_indices */
Florin Coras220beac2016-08-16 23:04:00 +0200132 u32 *free_tunnel_hw_if_indices;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700133
Florin Coras1a1adc72016-07-22 01:45:30 +0200134 u8 is_en;
135
136 /* L3 data structures
137 * ================== */
Florin Coras1a1adc72016-07-22 01:45:30 +0200138 tunnel_lookup_t l3_ifaces;
Florin Coras577c3552016-04-21 00:45:40 +0200139
Florin Coras1a1adc72016-07-22 01:45:30 +0200140 /* L2 data structures
141 * ================== */
142
Florin Corasff0bf132016-09-05 19:30:35 +0200143 /** L2 LISP FIB */
Florin Coras220beac2016-08-16 23:04:00 +0200144 BVT (clib_bihash) l2_fib;
Florin Coras1a1adc72016-07-22 01:45:30 +0200145
146 tunnel_lookup_t l2_ifaces;
147
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100148 /** Load-balance for a miss in the table */
Neale Ranns5e575b12016-10-03 09:40:25 +0100149 dpo_id_t l2_lb_cp_lkup;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100150
Florin Corasce1b4c72017-01-26 14:25:34 -0800151 /* NSH data structures
152 * ================== */
153
154 BVT (clib_bihash) nsh_fib;
155
156 tunnel_lookup_t nsh_ifaces;
157
158 const dpo_id_t *nsh_cp_lkup;
159
Filip Tehlar3e7b56932017-02-21 18:28:34 +0100160 gpe_encap_mode_t encap_mode;
161
Filip Tehlar21511912017-04-07 10:41:42 +0200162 u8 *dummy_stats_pool;
Filip Tehlar4868ff62017-03-09 16:48:39 +0100163 uword *lisp_stats_index_by_key;
Filip Tehlar21511912017-04-07 10:41:42 +0200164 vlib_combined_counter_main_t counters;
Filip Tehlar4868ff62017-03-09 16:48:39 +0100165
Florin Corasa4e63e52017-06-07 21:50:57 -0700166 /** Native fwd data structures */
167 fib_route_path_t *native_fwd_rpath[2];
168 u32 *native_fwd_lfes[2];
169
Florin Corasff0bf132016-09-05 19:30:35 +0200170 /** convenience */
Florin Coras220beac2016-08-16 23:04:00 +0200171 vlib_main_t *vlib_main;
172 vnet_main_t *vnet_main;
173 ip4_main_t *im4;
174 ip6_main_t *im6;
175 ip_lookup_main_t *lm4;
176 ip_lookup_main_t *lm6;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700177} lisp_gpe_main_t;
178
Florin Corasff0bf132016-09-05 19:30:35 +0200179/** LISP-GPE global state*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700180lisp_gpe_main_t lisp_gpe_main;
181
Florin Coras1a1adc72016-07-22 01:45:30 +0200182always_inline lisp_gpe_main_t *
Florin Coras220beac2016-08-16 23:04:00 +0200183vnet_lisp_gpe_get_main ()
184{
Florin Coras1a1adc72016-07-22 01:45:30 +0200185 return &lisp_gpe_main;
186}
187
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100188
Florin Coras02655bd2016-04-26 00:17:24 +0200189extern vlib_node_registration_t lisp_gpe_ip4_input_node;
190extern vlib_node_registration_t lisp_gpe_ip6_input_node;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100191extern vnet_hw_interface_class_t lisp_gpe_hw_class;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700192
Florin Coras220beac2016-08-16 23:04:00 +0200193u8 *format_lisp_gpe_header_with_length (u8 * s, va_list * args);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700194
Florin Corasff0bf132016-09-05 19:30:35 +0200195/** Read LISP-GPE status */
Florin Coras220beac2016-08-16 23:04:00 +0200196u8 vnet_lisp_gpe_enable_disable_status (void);
Florin Corasff0bf132016-09-05 19:30:35 +0200197
Neale Ranns5e575b12016-10-03 09:40:25 +0100198u32
199lisp_gpe_l3_iface_find_or_create (lisp_gpe_main_t * lgm,
200 u32 overlay_table_id, u32 vni);
201
Florin Corasff0bf132016-09-05 19:30:35 +0200202/** Add/del LISP-GPE interface. */
Neale Ranns5e575b12016-10-03 09:40:25 +0100203extern void lisp_gpe_del_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
204extern u32 lisp_gpe_add_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
205extern void lisp_gpe_del_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
206extern u32 lisp_gpe_add_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
207
Florin Corase127a7e2016-02-18 22:20:01 +0100208
Florin Coras577c3552016-04-21 00:45:40 +0200209typedef struct
210{
211 u8 is_en;
212} vnet_lisp_gpe_enable_disable_args_t;
213
Florin Coras220beac2016-08-16 23:04:00 +0200214clib_error_t
215 * vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a);
Florin Coras577c3552016-04-21 00:45:40 +0200216
Neale Ranns5e575b12016-10-03 09:40:25 +0100217typedef enum
218{
219 NO_ACTION,
220 FORWARD_NATIVE,
221 SEND_MAP_REQUEST,
222 DROP
223} negative_fwd_actions_e;
224
Florin Corasff0bf132016-09-05 19:30:35 +0200225/** */
Florin Corase127a7e2016-02-18 22:20:01 +0100226typedef struct
227{
Filip Tehlar560274d2017-06-05 13:40:13 +0200228 /** forwarding entry index of */
229 u32 fwd_entry_index;
230
Filip Tehlared6b52b2017-03-22 09:02:33 +0100231 u8 is_src_dst;
232
Florin Corase127a7e2016-02-18 22:20:01 +0100233 u8 is_add;
Florin Corased09a052016-05-06 14:22:40 +0200234
Florin Corasff0bf132016-09-05 19:30:35 +0200235 /** type of mapping */
Florin Corase127a7e2016-02-18 22:20:01 +0100236 u8 is_negative;
Florin Corasff0bf132016-09-05 19:30:35 +0200237
238 /** action for negative mappings */
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100239 negative_fwd_actions_e action;
Florin Corased09a052016-05-06 14:22:40 +0200240
Florin Corasff0bf132016-09-05 19:30:35 +0200241 /** local eid */
Florin Coras1a1adc72016-07-22 01:45:30 +0200242 gid_address_t lcl_eid;
Florin Corasff0bf132016-09-05 19:30:35 +0200243
244 /** remote eid */
Florin Coras1a1adc72016-07-22 01:45:30 +0200245 gid_address_t rmt_eid;
Florin Corased09a052016-05-06 14:22:40 +0200246
Florin Corasff0bf132016-09-05 19:30:35 +0200247 /** vector of locator pairs */
Florin Coras220beac2016-08-16 23:04:00 +0200248 locator_pair_t *locator_pairs;
Florin Corased09a052016-05-06 14:22:40 +0200249
Florin Corasff0bf132016-09-05 19:30:35 +0200250 /** FIB index to lookup remote locator at encap */
Florin Corase127a7e2016-02-18 22:20:01 +0100251 u32 encap_fib_index;
Florin Corasff0bf132016-09-05 19:30:35 +0200252
253 /** FIB index to lookup inner IP at decap */
Florin Corase127a7e2016-02-18 22:20:01 +0100254 u32 decap_fib_index;
Florin Corased09a052016-05-06 14:22:40 +0200255
Florin Corasff0bf132016-09-05 19:30:35 +0200256 /* TODO remove */
257 u32 decap_next_index;
Florin Corased09a052016-05-06 14:22:40 +0200258
Florin Corasff0bf132016-09-05 19:30:35 +0200259 /** VNI/tenant id in HOST byte order */
Florin Corased09a052016-05-06 14:22:40 +0200260 u32 vni;
261
Florin Corasff0bf132016-09-05 19:30:35 +0200262 /** vrf or bd where fwd entry should be inserted */
Florin Coras1a1adc72016-07-22 01:45:30 +0200263 union
264 {
Florin Corasff0bf132016-09-05 19:30:35 +0200265 /** table (vrf) id */
Florin Coras1a1adc72016-07-22 01:45:30 +0200266 u32 table_id;
Florin Corasff0bf132016-09-05 19:30:35 +0200267
268 /** bridge domain id */
Florin Corasc14f31c2017-04-06 15:27:35 -0700269 u32 bd_id;
Florin Coras429e7952016-08-02 02:31:03 +0200270
Florin Corasff0bf132016-09-05 19:30:35 +0200271 /** generic access */
Florin Coras429e7952016-08-02 02:31:03 +0200272 u32 dp_table;
Florin Coras1a1adc72016-07-22 01:45:30 +0200273 };
Florin Corase127a7e2016-02-18 22:20:01 +0100274} vnet_lisp_gpe_add_del_fwd_entry_args_t;
275
Filip Tehlar5fae99c2017-01-18 12:57:37 +0100276typedef struct
277{
Florin Corasa4e63e52017-06-07 21:50:57 -0700278 fib_route_path_t rpath;
279 u8 is_add;
280} vnet_gpe_native_fwd_rpath_args_t;
281
282typedef struct
283{
Filip Tehlar5fae99c2017-01-18 12:57:37 +0100284 u32 fwd_entry_index;
285 u32 dp_table;
286 u32 vni;
Filip Tehlar0eb874e2017-05-18 14:23:32 +0200287 u8 action;
Filip Tehlar5fae99c2017-01-18 12:57:37 +0100288 dp_address_t leid;
289 dp_address_t reid;
290} lisp_api_gpe_fwd_entry_t;
291
Florin Coras02655bd2016-04-26 00:17:24 +0200292#define foreach_lgpe_ip4_lookup_next \
293 _(DROP, "error-drop") \
294 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
295
296typedef enum lgpe_ip4_lookup_next
297{
298#define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym,
299 foreach_lgpe_ip4_lookup_next
300#undef _
Florin Coras220beac2016-08-16 23:04:00 +0200301 LGPE_IP4_LOOKUP_N_NEXT,
Florin Coras02655bd2016-04-26 00:17:24 +0200302} lgpe_ip4_lookup_next_t;
303
Florin Corasff0bf132016-09-05 19:30:35 +0200304#define foreach_lgpe_ip6_lookup_next \
Florin Coras02655bd2016-04-26 00:17:24 +0200305 _(DROP, "error-drop") \
306 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
307
308typedef enum lgpe_ip6_lookup_next
309{
310#define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym,
311 foreach_lgpe_ip6_lookup_next
312#undef _
Florin Coras220beac2016-08-16 23:04:00 +0200313 LGPE_IP6_LOOKUP_N_NEXT,
Florin Coras02655bd2016-04-26 00:17:24 +0200314} lgpe_ip6_lookup_next_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700315
Florin Coras220beac2016-08-16 23:04:00 +0200316u8 *format_vnet_lisp_gpe_status (u8 * s, va_list * args);
Filip Tehlar46d4e362016-05-09 09:39:26 +0200317
Filip Tehlar5fae99c2017-01-18 12:57:37 +0100318lisp_api_gpe_fwd_entry_t *vnet_lisp_gpe_fwd_entries_get_by_vni (u32 vni);
Filip Tehlar3e7b56932017-02-21 18:28:34 +0100319gpe_encap_mode_t vnet_gpe_get_encap_mode (void);
320int vnet_gpe_set_encap_mode (gpe_encap_mode_t mode);
Filip Tehlar5fae99c2017-01-18 12:57:37 +0100321
Filip Tehlar4868ff62017-03-09 16:48:39 +0100322u8 vnet_lisp_stats_enable_disable_state (void);
323vnet_api_error_t vnet_lisp_stats_enable_disable (u8 enable);
324lisp_api_stats_t *vnet_lisp_get_stats (void);
Filip Tehlar21511912017-04-07 10:41:42 +0200325int vnet_lisp_flush_stats (void);
Florin Corasa4e63e52017-06-07 21:50:57 -0700326int vnet_gpe_add_del_native_fwd_rpath (vnet_gpe_native_fwd_rpath_args_t * a);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200327u32 vnet_lisp_gpe_add_nsh_iface (lisp_gpe_main_t * lgm);
328void vnet_lisp_gpe_del_nsh_iface (lisp_gpe_main_t * lgm);
329
Ed Warnickecb9cada2015-12-08 15:45:58 -0700330#endif /* included_vnet_lisp_gpe_h */
Florin Coras220beac2016-08-16 23:04:00 +0200331
332/*
333 * fd.io coding-style-patch-verification: ON
334 *
335 * Local Variables:
336 * eval: (c-set-style "gnu")
337 * End:
338 */