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