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