VPP-307: Documentation for vnet/vnet/vxlan-gpe
[vpp.git] / vnet / vnet / vxlan-gpe / vxlan_gpe.h
1 /*
2  * Copyright (c) 2015 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 VXLAN GPE definitions
18  *
19 */
20 #ifndef included_vnet_vxlan_gpe_h
21 #define included_vnet_vxlan_gpe_h
22
23 #include <vppinfra/error.h>
24 #include <vppinfra/hash.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/vxlan-gpe/vxlan_gpe_packet.h>
30 #include <vnet/ip/ip4_packet.h>
31 #include <vnet/ip/ip6_packet.h>
32 #include <vnet/ip/udp.h>
33
34 /**
35  * @brief VXLAN GPE header struct
36  *
37  */
38 typedef CLIB_PACKED (struct {
39   /** 20 bytes */
40   ip4_header_t ip4;
41   /** 8 bytes */
42   udp_header_t udp;
43   /** 8 bytes */
44   vxlan_gpe_header_t vxlan;
45 }) ip4_vxlan_gpe_header_t;
46
47 typedef CLIB_PACKED (struct {
48   /** 40 bytes */
49   ip6_header_t ip6;
50   /** 8 bytes */
51   udp_header_t udp;
52   /** 8 bytes */
53   vxlan_gpe_header_t vxlan;
54 }) ip6_vxlan_gpe_header_t;
55
56 /**
57  * @brief Key struct for IPv4 VXLAN GPE tunnel.
58  * Key fields: local remote, vni
59  * all fields in NET byte order
60  * VNI shifted 8 bits
61  */
62 typedef CLIB_PACKED(struct {
63   union {
64     struct {
65       u32 local;
66       u32 remote;
67
68       u32 vni;
69       u32 pad;
70     };
71     u64 as_u64[2];
72   };
73 }) vxlan4_gpe_tunnel_key_t;
74
75 /**
76  * @brief Key struct for IPv6 VXLAN GPE tunnel.
77  * Key fields: local remote, vni
78  * all fields in NET byte order
79  * VNI shifted 8 bits
80  */
81 typedef CLIB_PACKED(struct {
82   ip6_address_t local;
83   ip6_address_t remote;
84   u32 vni;
85 }) vxlan6_gpe_tunnel_key_t;
86
87 /**
88  * @brief Struct for VXLAN GPE tunnel
89  */
90 typedef struct {
91   /** Rewrite string. $$$$ embed vnet_rewrite header */
92   u8 * rewrite;
93
94   /** encapsulated protocol */
95   u8 protocol;
96
97   /** tunnel local address */
98   ip46_address_t local;
99   /** tunnel remote address */
100   ip46_address_t remote;
101
102   /** FIB indices - tunnel partner lookup here */
103   u32 encap_fib_index;
104   /** FIB indices - inner IP packet lookup here */
105   u32 decap_fib_index;
106
107   /** VXLAN GPE VNI in HOST byte order, shifted left 8 bits */
108   u32 vni;
109
110   /** vnet intfc hw_if_index */
111   u32 hw_if_index;
112   /** vnet intfc sw_if_index */
113   u32 sw_if_index;
114
115   /** flags */
116   u32 flags;
117 } vxlan_gpe_tunnel_t;
118
119 /** Flags for vxlan_gpe_tunnel_t */
120 #define VXLAN_GPE_TUNNEL_IS_IPV4        1
121
122 /** next nodes for VXLAN GPE input */
123 #define foreach_vxlan_gpe_input_next        \
124 _(DROP, "error-drop")                           \
125 _(IP4_INPUT, "ip4-input")                       \
126 _(IP6_INPUT, "ip6-input")                       \
127 _(ETHERNET_INPUT, "ethernet-input")
128
129 /** struct for next nodes for VXLAN GPE input */
130 typedef enum {
131 #define _(s,n) VXLAN_GPE_INPUT_NEXT_##s,
132   foreach_vxlan_gpe_input_next
133 #undef _
134   VXLAN_GPE_INPUT_N_NEXT,
135 } vxlan_gpe_input_next_t;
136
137 /** struct for VXLAN GPE errors */
138 typedef enum {
139 #define vxlan_gpe_error(n,s) VXLAN_GPE_ERROR_##n,
140 #include <vnet/vxlan-gpe/vxlan_gpe_error.def>
141 #undef vxlan_gpe_error
142   VXLAN_GPE_N_ERROR,
143 } vxlan_gpe_input_error_t;
144
145 /** Struct for VXLAN GPE node state */
146 typedef struct {
147   /** vector of encap tunnel instances */
148   vxlan_gpe_tunnel_t *tunnels;
149
150   /** lookup IPv4 VXLAN GPE tunnel by key */
151   uword * vxlan4_gpe_tunnel_by_key;
152   /** lookup IPv6 VXLAN GPE tunnel by key */
153   uword * vxlan6_gpe_tunnel_by_key;
154
155   /** Free vlib hw_if_indices */
156   u32 * free_vxlan_gpe_tunnel_hw_if_indices;
157
158   /** Mapping from sw_if_index to tunnel index */
159   u32 * tunnel_index_by_sw_if_index;
160
161   /** State convenience vlib_main_t */
162   vlib_main_t * vlib_main;
163   /** State convenience vnet_main_t */
164   vnet_main_t * vnet_main;
165 } vxlan_gpe_main_t;
166
167 vxlan_gpe_main_t vxlan_gpe_main;
168
169 extern vlib_node_registration_t vxlan_gpe_encap_node;
170 extern vlib_node_registration_t vxlan4_gpe_input_node;
171 extern vlib_node_registration_t vxlan6_gpe_input_node;
172
173 u8 * format_vxlan_gpe_encap_trace (u8 * s, va_list * args);
174
175 /** Struct for VXLAN GPE add/del args */
176 typedef struct {
177   u8 is_add;
178   u8 is_ip6;
179   ip46_address_t local, remote;
180   u8 protocol;
181   u32 encap_fib_index;
182   u32 decap_fib_index;
183   u32 vni;
184 } vnet_vxlan_gpe_add_del_tunnel_args_t;
185
186
187 int vnet_vxlan_gpe_add_del_tunnel
188 (vnet_vxlan_gpe_add_del_tunnel_args_t *a, u32 * sw_if_indexp);
189
190
191
192
193
194 #endif /* included_vnet_vxlan_gpe_h */