VPP-39 - refactoring of NSH into own folder
[vpp.git] / vnet / vnet / nsh-gre / nsh_gre.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_gre_h
16 #define included_vnet_nsh_gre_h
17
18 #include <vnet/vnet.h>
19 #include <vnet/gre/gre.h>
20 #include <vnet/nsh/nsh_packet.h>
21 #include <vnet/ip/ip4_packet.h>
22
23 typedef CLIB_PACKED (struct {
24   ip4_header_t ip4;             /* 20 bytes */
25   gre_header_t gre;             /* 4 bytes */
26   nsh_header_t nsh;             /* 28 bytes */
27 }) ip4_gre_and_nsh_header_t;
28
29 typedef struct {
30   /* Rewrite string. $$$$ embed vnet_rewrite header */
31   u8 * rewrite;
32
33   /* tunnel src and dst addresses */
34   ip4_address_t src;
35   ip4_address_t dst;
36
37   /* FIB indices */
38   u32 encap_fib_index;          /* tunnel partner lookup here */
39   u32 decap_fib_index;          /* inner IP lookup here */
40
41   /* when decapsulating, send pkts here */
42   u32 decap_next_index;
43
44   /* vnet intfc hw/sw_if_index */
45   u32 hw_if_index;
46   u32 sw_if_index;
47
48   /* NSH header fields in HOST byte order */
49   nsh_header_t nsh_hdr;
50
51 } nsh_gre_tunnel_t;
52
53 #define foreach_nsh_gre_input_next              \
54   _ (DROP, "error-drop")                        \
55   _ (IP4_INPUT, "ip4-input")                    \
56   _ (IP6_INPUT, "ip6-input")                    \
57   _ (ETHERNET_INPUT, "ethernet-input")
58
59 typedef enum {
60 #define _(s,n) NSH_GRE_INPUT_NEXT_##s,
61   foreach_nsh_gre_input_next
62 #undef _
63   NSH_GRE_INPUT_N_NEXT,
64 } nsh_gre_input_next_t;
65
66 typedef enum {
67 #define nsh_gre_error(n,s) NSH_GRE_ERROR_##n,
68 #include <vnet/nsh/nsh_error.def>
69 #undef nsh_gre_error
70   NSH_GRE_N_ERROR,
71 } nsh_gre_input_error_t;
72
73 typedef struct {
74   /* vector of encap tunnel instances */
75   nsh_gre_tunnel_t *tunnels;
76
77   /* lookup tunnel by tunnel partner src address */
78   uword * nsh_gre_tunnel_by_src_address;
79
80   /* Free vlib hw_if_indices */
81   u32 * free_nsh_gre_tunnel_hw_if_indices;
82
83   /* show device instance by real device instance */
84   u32 * dev_inst_by_real;
85
86   /* convenience */
87   vlib_main_t * vlib_main;
88   vnet_main_t * vnet_main;
89 } nsh_gre_main_t;
90
91 nsh_gre_main_t nsh_gre_main;
92
93 extern vlib_node_registration_t nsh_gre_input_node;
94 extern vlib_node_registration_t nsh_gre_encap_node;
95
96 u8 * format_nsh_gre_encap_trace (u8 * s, va_list * args);
97
98 typedef struct {
99   u8 is_add;
100   ip4_address_t src, dst;
101   u32 encap_fib_index;
102   u32 decap_fib_index;
103   u32 decap_next_index;
104   nsh_header_t nsh_hdr;
105 } vnet_nsh_gre_add_del_tunnel_args_t;
106
107 int vnet_nsh_gre_add_del_tunnel (vnet_nsh_gre_add_del_tunnel_args_t *a, 
108                                  u32 * sw_if_indexp);
109
110 #endif /* included_vnet_nsh_gre_h */