Initial commit of vpp code.
[vpp.git] / vnet / vnet / vxlan / vxlan.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 #ifndef included_vnet_vxlan_h
16 #define included_vnet_vxlan_h
17
18 #include <vppinfra/error.h>
19 #include <vppinfra/hash.h>
20 #include <vnet/vnet.h>
21 #include <vnet/ip/ip.h>
22 #include <vnet/l2/l2_input.h>
23 #include <vnet/l2/l2_bd.h>
24 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/vxlan/vxlan_packet.h>
26 #include <vnet/ip/ip4_packet.h>
27 #include <vnet/ip/udp.h>
28
29 typedef CLIB_PACKED (struct {
30   ip4_header_t ip4;            /* 20 bytes */
31   udp_header_t udp;            /* 8 bytes */
32   vxlan_header_t vxlan;        /* 8 bytes */
33 }) ip4_vxlan_header_t;
34
35 typedef CLIB_PACKED(struct {
36   /* 
37    * Key fields: ip src and vxlan vni on incoming VXLAN packet
38    * all fields in NET byte order
39    */
40   union {
41     struct {
42       u32 src;
43       u32 vni;                 /* shifted left 8 bits */
44     };
45     u64 as_u64;
46   };
47 }) vxlan_tunnel_key_t;
48
49 typedef struct {
50   /* Rewrite string. $$$$ embed vnet_rewrite header */
51   u8 * rewrite;
52
53   /* decap next index */
54   u32 decap_next_index;
55
56   /* tunnel src and dst addresses */
57   ip4_address_t src;
58   ip4_address_t dst;
59
60   /* vxlan VNI in HOST byte order */
61   u32 vni;
62
63   /* L3 FIB index and L2 BD ID */
64   u16 encap_fib_index;          /* tunnel partner IP lookup here */
65
66   /* vnet intfc hw/sw_if_index */
67   u16 hw_if_index;
68   u32 sw_if_index;
69 } vxlan_tunnel_t;
70
71 #define foreach_vxlan_input_next        \
72 _(DROP, "error-drop")                   \
73 _(L2_INPUT, "l2-input")                 \
74 _(IP4_INPUT, "ip4-input")               \
75 _(IP6_INPUT, "ip6-input")
76
77 typedef enum {
78 #define _(s,n) VXLAN_INPUT_NEXT_##s,
79   foreach_vxlan_input_next
80 #undef _
81   VXLAN_INPUT_N_NEXT,
82 } vxlan_input_next_t;
83
84 typedef enum {
85 #define vxlan_error(n,s) VXLAN_ERROR_##n,
86 #include <vnet/vxlan/vxlan_error.def>
87 #undef vxlan_error
88   VXLAN_N_ERROR,
89 } vxlan_input_error_t;
90
91 typedef struct {
92   /* vector of encap tunnel instances */
93   vxlan_tunnel_t *tunnels;
94
95   /* lookup tunnel by key */
96   uword * vxlan_tunnel_by_key;
97
98   /* Free vlib hw_if_indices */
99   u32 * free_vxlan_tunnel_hw_if_indices;
100
101   /* Dummy rewrite for deleted vxlan_tunnels with hw_if_indices as above */
102   u64 dummy_str [sizeof(ip4_vxlan_header_t)/sizeof(u64) + 2];
103 #define vxlan_dummy_rewrite ((u8 *) &vxlan_main.dummy_str[1])
104
105   /* convenience */
106   vlib_main_t * vlib_main;
107   vnet_main_t * vnet_main;
108 } vxlan_main_t;
109
110 vxlan_main_t vxlan_main;
111
112 vlib_node_registration_t vxlan_input_node;
113 vlib_node_registration_t vxlan_encap_node;
114
115 u8 * format_vxlan_encap_trace (u8 * s, va_list * args);
116
117 typedef struct {
118   u8 is_add;
119   ip4_address_t src, dst;
120   u32 encap_fib_index;
121   u32 decap_next_index;
122   u32 vni;
123 } vnet_vxlan_add_del_tunnel_args_t;
124
125 int vnet_vxlan_add_del_tunnel 
126 (vnet_vxlan_add_del_tunnel_args_t *a, u32 * sw_if_indexp);
127
128 #endif /* included_vnet_vxlan_h */