Initial commit of vpp code.
[vpp.git] / vnet / vnet / lisp-gpe / lisp_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_lisp_gpe_h
16 #define included_vnet_lisp_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/lisp-gpe/lisp_gpe_packet.h>
25 #include <vnet/ip/ip4_packet.h>
26 #include <vnet/ip/udp.h>
27
28 typedef CLIB_PACKED (struct {
29   ip4_header_t ip4;             /* 20 bytes */
30   udp_header_t udp;             /* 8 bytes */
31   lisp_gpe_header_t lisp;       /* 8 bytes */
32 }) ip4_udp_lisp_gpe_header_t;
33
34 typedef CLIB_PACKED(struct {
35   /* 
36    * Key fields: ip src, LISP iid, ??? $$$$$$$$$ correct answer ???
37    * all fields in NET byte order
38    */
39   union {
40     struct {
41       u32 src;
42       u32 iid;
43     };
44     u64 as_u64[1];
45   };
46 }) lisp_gpe_tunnel_key_t;
47
48 typedef struct {
49   /* Rewrite string. $$$$ embed vnet_rewrite header */
50   u8 * rewrite;
51
52   /* decap next index */
53   u32 decap_next_index;
54
55   /* tunnel src and dst addresses */
56   ip4_address_t src;
57   ip4_address_t dst;
58
59   /* FIB indices */
60   u32 encap_fib_index;          /* tunnel partner lookup here */
61   u32 decap_fib_index;          /* inner IP lookup here */
62
63   /* vnet intfc hw/sw_if_index */
64   u32 hw_if_index;
65   u32 sw_if_index;
66
67   /* LISP header fields in HOST byte order */
68   u8 flags;
69   u8 ver_res;
70   u8 res;
71   u8 next_protocol;
72   u32 iid;
73 } lisp_gpe_tunnel_t;
74
75 #define foreach_lisp_gpe_input_next             \
76 _(DROP, "error-drop")                           \
77 _(IP4_INPUT, "ip4-input")                       \
78 _(IP6_INPUT, "ip6-input")                       \
79 _(ETHERNET_INPUT, "ethernet-input")             \
80 _(LISP_GPE_ENCAP, "lisp-gpe-encap")
81
82 typedef enum {
83 #define _(s,n) LISP_GPE_INPUT_NEXT_##s,
84   foreach_lisp_gpe_input_next
85 #undef _
86   LISP_GPE_INPUT_N_NEXT,
87 } lisp_gpe_input_next_t;
88
89 typedef enum {
90 #define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n,
91 #include <vnet/lisp-gpe/lisp_gpe_error.def>
92 #undef lisp_gpe_error
93   LISP_GPE_N_ERROR,
94 } lisp_gpe_input_error_t;
95
96 typedef struct {
97   /* vector of encap tunnel instances */
98   lisp_gpe_tunnel_t *tunnels;
99
100   /* lookup tunnel by key */
101   uword * lisp_gpe_tunnel_by_key;
102
103   /* Free vlib hw_if_indices */
104   u32 * free_lisp_gpe_tunnel_hw_if_indices;
105
106   /* convenience */
107   vlib_main_t * vlib_main;
108   vnet_main_t * vnet_main;
109 } lisp_gpe_main_t;
110
111 lisp_gpe_main_t lisp_gpe_main;
112
113 vlib_node_registration_t lisp_gpe_input_node;
114 vlib_node_registration_t lisp_gpe_encap_node;
115
116 u8 * format_lisp_gpe_encap_trace (u8 * s, va_list * args);
117 u8 * format_lisp_gpe_header_with_length (u8 * s, va_list * args);
118
119 typedef struct {
120   u8 is_add;
121   ip4_address_t src, dst;
122   u32 encap_fib_index;
123   u32 decap_fib_index;
124   u32 decap_next_index;
125   u8 flags;
126   u8 ver_res;
127   u8 res;
128   u8 next_protocol;
129   u32 iid;                      /* host byte order */
130 } vnet_lisp_gpe_add_del_tunnel_args_t;
131
132 int vnet_lisp_gpe_add_del_tunnel 
133 (vnet_lisp_gpe_add_del_tunnel_args_t *a, u32 * sw_if_indexp);
134
135 u8 * format_lisp_gpe_header_with_length (u8 * s, va_list * args);
136
137 #endif /* included_vnet_lisp_gpe_h */