Initial commit of vpp code.
[vpp.git] / vnet / vnet / nsh-vxlan-gpe / nsh_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 #ifndef included_vnet_nsh_vxlan_gpe_h
16 #define included_vnet_nsh_vxlan_gpe_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/ethernet/ethernet.h>
24 #include <vnet/gre/gre.h>
25 #include <vnet/nsh-gre/nsh_gre_packet.h>
26 #include <vnet/nsh-vxlan-gpe/vxlan_gpe_packet.h>
27 #include <vnet/ip/ip4_packet.h>
28 #include <vnet/ip/udp.h>
29
30 typedef CLIB_PACKED (struct {
31   ip4_header_t ip4;             /* 20 bytes */
32   udp_header_t udp;             /* 8 bytes */
33   vxlan_gpe_header_t vxlan;     /* 8 bytes */
34   nsh_header_t nsh;             /* 28 bytes */
35 }) ip4_vxlan_gpe_and_nsh_header_t;
36
37 typedef CLIB_PACKED(struct {
38   /* 
39    * Key fields: ip src, vxlan vni, nsh spi_si 
40    * all fields in NET byte order
41    */
42   union {
43     struct {
44       u32 src;
45       u32 vni;                      /* shifted 8 bits */
46       u32 spi_si;
47       u32 pad;
48     };
49     u64 as_u64[2];
50   };
51 }) nsh_vxlan_gpe_tunnel_key_t;
52
53 typedef struct {
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   /* vxlan VNI in HOST byte order, shifted left 8 bits */
69   u32 vni;
70
71   /* vnet intfc hw/sw_if_index */
72   u32 hw_if_index;
73   u32 sw_if_index;
74
75   /* NSH header fields in HOST byte order */
76   u8 ver_o_c;
77   u8 length;
78   u8 md_type;
79   u8 next_protocol;
80   u32 spi_si;
81     
82   /* Context headers, always present, in HOST byte order */
83   u32 c1, c2, c3, c4;
84   u32 * tlvs;
85 } nsh_vxlan_gpe_tunnel_t;
86
87 #define foreach_nsh_vxlan_gpe_input_next        \
88 _(DROP, "error-drop")                           \
89 _(IP4_INPUT, "ip4-input")                       \
90 _(IP6_INPUT, "ip6-input")                       \
91 _(ETHERNET_INPUT, "ethernet-input")             \
92 _(NSH_VXLAN_GPE_ENCAP, "nsh-vxlan-gpe-encap")
93
94 typedef enum {
95 #define _(s,n) NSH_VXLAN_GPE_INPUT_NEXT_##s,
96   foreach_nsh_vxlan_gpe_input_next
97 #undef _
98   NSH_VXLAN_GPE_INPUT_N_NEXT,
99 } nsh_vxlan_gpe_input_next_t;
100
101 typedef enum {
102 #define nsh_vxlan_gpe_error(n,s) NSH_VXLAN_GPE_ERROR_##n,
103 #include <vnet/nsh-vxlan-gpe/nsh_vxlan_gpe_error.def>
104 #undef nsh_vxlan_gpe_error
105   NSH_VXLAN_GPE_N_ERROR,
106 } nsh_vxlan_gpe_input_error_t;
107
108 typedef struct {
109   /* vector of encap tunnel instances */
110   nsh_vxlan_gpe_tunnel_t *tunnels;
111
112   /* lookup tunnel by key */
113   uword * nsh_vxlan_gpe_tunnel_by_key;
114
115   /* Free vlib hw_if_indices */
116   u32 * free_nsh_vxlan_gpe_tunnel_hw_if_indices;
117
118   /* show device instance by real device instance */
119   u32 * dev_inst_by_real;
120
121   /* convenience */
122   vlib_main_t * vlib_main;
123   vnet_main_t * vnet_main;
124 } nsh_vxlan_gpe_main_t;
125
126 nsh_vxlan_gpe_main_t nsh_vxlan_gpe_main;
127
128 vlib_node_registration_t nsh_vxlan_gpe_input_node;
129 vlib_node_registration_t nsh_vxlan_gpe_encap_node;
130
131 u8 * format_nsh_vxlan_gpe_encap_trace (u8 * s, va_list * args);
132
133 typedef struct {
134   u8 is_add;
135   ip4_address_t src, dst;
136   u32 encap_fib_index;
137   u32 decap_fib_index;
138   u32 decap_next_index;
139   u32 vni;
140   u8 ver_o_c;
141   u8 length;
142   u8 md_type;
143   u8 next_protocol;
144   u32 spi_si;
145   u32 c1, c2, c3, c4;
146   u32 * tlvs;
147 } vnet_nsh_vxlan_gpe_add_del_tunnel_args_t;
148
149 int vnet_nsh_vxlan_gpe_add_del_tunnel 
150 (vnet_nsh_vxlan_gpe_add_del_tunnel_args_t *a, u32 * sw_if_indexp);
151
152 #endif /* included_vnet_nsh_vxlan_gpe_h */