be447024cb9e1b8dc46beec13f2b62f40f4b4018
[vpp.git] / src / vnet / lisp-gpe / lisp_gpe.h
1 /*
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:
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  */
15 /**
16  * @file
17  * @brief LISP-GPE definitions.
18  */
19
20 #ifndef included_vnet_lisp_gpe_h
21 #define included_vnet_lisp_gpe_h
22
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>
36
37 /** IP4-UDP-LISP encap header */
38 /* *INDENT-OFF* */
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;
44 /* *INDENT-ON* */
45
46 /** IP6-UDP-LISP encap header */
47 /* *INDENT-OFF* */
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;
53 /* *INDENT-ON* */
54
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")
60
61 /** Enum of possible next nodes post LISP-GPE decap */
62 typedef enum
63 {
64 #define _(s,n) LISP_GPE_INPUT_NEXT_##s,
65   foreach_lisp_gpe_ip_input_next
66 #undef _
67     LISP_GPE_INPUT_N_NEXT,
68 } lisp_gpe_input_next_t;
69
70 /* Arc to nsh-input added only if nsh-input exists */
71 #define LISP_GPE_INPUT_NEXT_NSH_INPUT 4
72
73 typedef enum
74 {
75 #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,
79 } lisp_gpe_error_t;
80
81 typedef struct tunnel_lookup
82 {
83   /** Lookup lisp-gpe interfaces by dp table (eg. vrf/bridge index) */
84   uword *hw_if_index_by_dp_table;
85
86   /** lookup decap tunnel termination sw_if_index by vni and vice versa */
87   uword *sw_if_index_by_vni;
88
89   // FIXME - Need this?
90   uword *vni_by_sw_if_index;
91 } tunnel_lookup_t;
92
93 typedef struct
94 {
95   u32 fwd_entry_index;
96   u32 tunnel_index;
97 } lisp_stats_key_t;
98
99 typedef struct
100 {
101   u32 pkt_count;
102   u32 bytes;
103 } lisp_stats_t;
104
105 typedef struct
106 {
107   u32 vni;
108   dp_address_t deid;
109   dp_address_t seid;
110   ip_address_t loc_rloc;
111   ip_address_t rmt_rloc;
112
113   lisp_stats_t stats;
114 } lisp_api_stats_t;
115
116 typedef enum gpe_encap_mode_e
117 {
118   GPE_ENCAP_LISP,
119   GPE_ENCAP_VXLAN,
120   GPE_ENCAP_COUNT
121 } gpe_encap_mode_t;
122
123 /** LISP-GPE global state*/
124 typedef struct lisp_gpe_main
125 {
126   /**
127    * @brief DB of all forwarding entries. The Key is:{l-EID,r-EID,vni}
128    * where the EID encodes L2 or L3
129    */
130   uword *lisp_gpe_fwd_entries;
131
132   /**
133    * @brief A Pool of all LISP forwarding entries
134    */
135   struct lisp_gpe_fwd_entry_t_ *lisp_fwd_entry_pool;
136
137   /** Free vlib hw_if_indices */
138   u32 *free_tunnel_hw_if_indices;
139
140   u8 is_en;
141
142   /* L3 data structures
143    * ================== */
144   tunnel_lookup_t l3_ifaces;
145
146   /* L2 data structures
147    * ================== */
148
149   /** L2 LISP FIB */
150     BVT (clib_bihash) l2_fib;
151
152   tunnel_lookup_t l2_ifaces;
153
154   /** Load-balance for a miss in the table */
155   dpo_id_t l2_lb_cp_lkup;
156
157   /* NSH data structures
158    * ================== */
159
160     BVT (clib_bihash) nsh_fib;
161
162   tunnel_lookup_t nsh_ifaces;
163
164   const dpo_id_t *nsh_cp_lkup;
165
166   gpe_encap_mode_t encap_mode;
167
168   lisp_stats_t *lisp_stats_pool;
169   uword *lisp_stats_index_by_key;
170
171   /** convenience */
172   vlib_main_t *vlib_main;
173   vnet_main_t *vnet_main;
174   ip4_main_t *im4;
175   ip6_main_t *im6;
176   ip_lookup_main_t *lm4;
177   ip_lookup_main_t *lm6;
178 } lisp_gpe_main_t;
179
180 /** LISP-GPE global state*/
181 lisp_gpe_main_t lisp_gpe_main;
182
183 always_inline lisp_gpe_main_t *
184 vnet_lisp_gpe_get_main ()
185 {
186   return &lisp_gpe_main;
187 }
188
189
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;
193
194 u8 *format_lisp_gpe_header_with_length (u8 * s, va_list * args);
195
196 /** Read LISP-GPE status */
197 u8 vnet_lisp_gpe_enable_disable_status (void);
198
199 u32
200 lisp_gpe_l3_iface_find_or_create (lisp_gpe_main_t * lgm,
201                                   u32 overlay_table_id, u32 vni);
202
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);
208
209
210 typedef struct
211 {
212   u8 is_en;
213 } vnet_lisp_gpe_enable_disable_args_t;
214
215 clib_error_t
216   * vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a);
217
218 typedef enum
219 {
220   NO_ACTION,
221   FORWARD_NATIVE,
222   SEND_MAP_REQUEST,
223   DROP
224 } negative_fwd_actions_e;
225
226 /** */
227 typedef struct
228 {
229   u8 is_add;
230
231   /** type of mapping */
232   u8 is_negative;
233
234   /** action for negative mappings */
235   negative_fwd_actions_e action;
236
237   /** local eid */
238   gid_address_t lcl_eid;
239
240   /** remote eid */
241   gid_address_t rmt_eid;
242
243   /** vector of locator pairs */
244   locator_pair_t *locator_pairs;
245
246   /** FIB index to lookup remote locator at encap */
247   u32 encap_fib_index;
248
249   /** FIB index to lookup inner IP at decap */
250   u32 decap_fib_index;
251
252   /* TODO remove */
253   u32 decap_next_index;
254
255   /** VNI/tenant id in HOST byte order */
256   u32 vni;
257
258   /** vrf or bd where fwd entry should be inserted */
259   union
260   {
261     /** table (vrf) id */
262     u32 table_id;
263
264     /** bridge domain id */
265     u16 bd_id;
266
267     /** generic access */
268     u32 dp_table;
269   };
270 } vnet_lisp_gpe_add_del_fwd_entry_args_t;
271
272 typedef struct
273 {
274   u32 fwd_entry_index;
275   u32 dp_table;
276   u32 vni;
277   dp_address_t leid;
278   dp_address_t reid;
279 } lisp_api_gpe_fwd_entry_t;
280
281 #define foreach_lgpe_ip4_lookup_next    \
282   _(DROP, "error-drop")                 \
283   _(LISP_CP_LOOKUP, "lisp-cp-lookup")
284
285 typedef enum lgpe_ip4_lookup_next
286 {
287 #define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym,
288   foreach_lgpe_ip4_lookup_next
289 #undef _
290     LGPE_IP4_LOOKUP_N_NEXT,
291 } lgpe_ip4_lookup_next_t;
292
293 #define foreach_lgpe_ip6_lookup_next    \
294   _(DROP, "error-drop")                 \
295   _(LISP_CP_LOOKUP, "lisp-cp-lookup")
296
297 typedef enum lgpe_ip6_lookup_next
298 {
299 #define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym,
300   foreach_lgpe_ip6_lookup_next
301 #undef _
302     LGPE_IP6_LOOKUP_N_NEXT,
303 } lgpe_ip6_lookup_next_t;
304
305 u8 *format_vnet_lisp_gpe_status (u8 * s, va_list * args);
306
307 lisp_api_gpe_fwd_entry_t *vnet_lisp_gpe_fwd_entries_get_by_vni (u32 vni);
308 gpe_encap_mode_t vnet_gpe_get_encap_mode (void);
309 int vnet_gpe_set_encap_mode (gpe_encap_mode_t mode);
310
311 u8 vnet_lisp_stats_enable_disable_state (void);
312 vnet_api_error_t vnet_lisp_stats_enable_disable (u8 enable);
313 lisp_api_stats_t *vnet_lisp_get_stats (void);
314 void vnet_lisp_flush_stats (void);
315
316 #endif /* included_vnet_lisp_gpe_h */
317
318 /*
319  * fd.io coding-style-patch-verification: ON
320  *
321  * Local Variables:
322  * eval: (c-set-style "gnu")
323  * End:
324  */