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