LISP GPE: initial CP commit and DP improvements
[vpp.git] / vnet / 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 #ifndef included_vnet_lisp_gpe_h
17 #define included_vnet_lisp_gpe_h
18
19 #include <vppinfra/error.h>
20 #include <vppinfra/mhash.h>
21 #include <vnet/vnet.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/l2/l2_input.h>
24 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/ip/ip4_packet.h>
26 #include <vnet/ip/udp.h>
27 #include <vnet/lisp-cp/lisp_types.h>
28 #include <vnet/lisp-gpe/lisp_gpe_packet.h>
29
30 #define IP_UDP_HDR_LEN (word) (sizeof(udp_header_t) + sizeof(ip4_header_t))
31
32 typedef CLIB_PACKED (struct {
33   ip4_header_t ip4;             /* 20 bytes */
34   udp_header_t udp;             /* 8 bytes */
35   lisp_gpe_header_t lisp;       /* 8 bytes */
36 }) ip4_udp_lisp_gpe_header_t;
37
38 typedef struct
39 {
40   union
41   {
42     struct
43       {
44         gid_address_t eid;
45         u32 dst_loc;
46         u32 iid;
47       };
48     u8 as_u8[6];
49   };
50 } lisp_gpe_tunnel_key_t;
51
52 typedef struct
53 {
54   /* Rewrite string. $$$$ embed vnet_rewrite header */
55   u8 * rewrite;
56
57   /* decap next index */
58   u32 decap_next_index;
59
60   /* tunnel src and dst addresses */
61   ip4_address_t src;
62   ip4_address_t dst;
63
64   /* FIB indices */
65   u32 encap_fib_index;          /* tunnel partner lookup here */
66   u32 decap_fib_index;          /* inner IP lookup here */
67
68   /* vnet intfc hw/sw_if_index */
69   u32 hw_if_index;
70   u32 sw_if_index;
71
72   /* LISP header fields in HOST byte order */
73   u8 flags;
74   u8 ver_res;
75   u8 res;
76   u8 next_protocol;
77   u32 iid;
78 } lisp_gpe_tunnel_t;
79
80 #define foreach_lisp_gpe_input_next             \
81 _(DROP, "error-drop")                           \
82 _(IP4_INPUT, "ip4-input")                       \
83 _(IP6_INPUT, "ip6-input")                       \
84 _(ETHERNET_INPUT, "ethernet-input")             \
85 _(LISP_GPE_ENCAP, "lisp-gpe-encap")
86
87 typedef enum {
88 #define _(s,n) LISP_GPE_INPUT_NEXT_##s,
89   foreach_lisp_gpe_input_next
90 #undef _
91   LISP_GPE_INPUT_N_NEXT,
92 } lisp_gpe_input_next_t;
93
94 typedef enum {
95 #define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n,
96 #include <vnet/lisp-gpe/lisp_gpe_error.def>
97 #undef lisp_gpe_error
98   LISP_GPE_N_ERROR,
99 } lisp_gpe_input_error_t;
100
101 /* As a first step, reuse v4 fib. The goal of the typedef is to shield
102  * consumers from future updates that may result in the lisp ip4 fib diverging
103  * from ip4 fib */
104 typedef ip4_fib_t lisp_ip4_fib_t;
105
106 typedef struct lisp_gpe_main
107 {
108   /* Pool of src fibs that are paired with dst fibs */
109   ip4_fib_t * src_fibs;
110
111   /* vector of encap tunnel instances */
112   lisp_gpe_tunnel_t * tunnels;
113
114   /* lookup tunnel by key */
115   mhash_t lisp_gpe_tunnel_by_key;
116
117   /* lookup tunnel by adjacency index */
118   uword * lisp_gpe_tunnel_by_adj_index;
119
120   /* Free vlib hw_if_indices */
121   u32 * free_lisp_gpe_tunnel_hw_if_indices;
122
123   u32 lisp_gpe_hw_if_index;
124
125   /* next node indexes that points ip4 lookup to lisp gpe lookup and lisp cp */
126   u32 ip4_lookup_next_lgpe_ip4_lookup;
127
128   /* convenience */
129   vlib_main_t * vlib_main;
130   vnet_main_t * vnet_main;
131   ip_lookup_main_t * lookup_main;
132   ip4_main_t * im4;
133 } lisp_gpe_main_t;
134
135 lisp_gpe_main_t lisp_gpe_main;
136
137 extern vlib_node_registration_t lgpe_ip4_lookup_node;
138 extern vlib_node_registration_t lisp_gpe_input_node;
139 extern vlib_node_registration_t lisp_gpe_encap_node;
140
141 u8 *
142 format_lisp_gpe_encap_trace (u8 * s, va_list * args);
143 u8 *
144 format_lisp_gpe_header_with_length (u8 * s, va_list * args);
145
146 typedef struct
147 {
148   u8 is_add;
149   ip4_address_t src, dst;
150   u32 encap_fib_index;
151   u32 decap_fib_index;
152   u32 decap_next_index;
153   u8 flags;
154   u8 ver_res;
155   u8 res;
156   u8 next_protocol;
157   u32 iid; /* host byte order */
158 } vnet_lisp_gpe_add_del_tunnel_args_t;
159
160 int
161 vnet_lisp_gpe_add_del_tunnel (vnet_lisp_gpe_add_del_tunnel_args_t *a,
162                               u32 * sw_if_indexp);
163
164 typedef struct
165 {
166   u8 is_add;
167 } vnet_lisp_gpe_add_del_iface_args_t;
168
169 void
170 vnet_lisp_gpe_add_del_iface (vnet_lisp_gpe_add_del_iface_args_t *a,
171                              u32 * hw_if_indexp);
172
173 typedef enum
174 {
175   NO_ACTION,
176   FORWARD_NATIVE,
177   SEND_MAP_REQUEST,
178   DROP
179 } negative_fwd_actions_e;
180
181 typedef struct
182 {
183   u8 is_add;
184   u8 is_negative;
185   negative_fwd_actions_e action;
186   gid_address_t seid; /* TODO convert to ip4, ip6, mac ? */
187   gid_address_t deid;
188   ip_address_t slocator;
189   ip_address_t dlocator;
190   u32 encap_fib_index;
191   u32 decap_fib_index;
192   u32 decap_next_index;
193   u8 flags;
194   u8 ver_res;
195   u8 res;
196   u8 next_protocol;
197   u32 iid; /* host byte order */
198 } vnet_lisp_gpe_add_del_fwd_entry_args_t;
199
200 int
201 vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t *a,
202                                  u32 * hw_if_indexp);
203
204 u8 *
205 format_lisp_gpe_header_with_length (u8 * s, va_list * args);
206
207 #endif /* included_vnet_lisp_gpe_h */