Move doxytags file to html output directory
[vpp.git] / vnet / vnet / mpls / mpls.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_mpls_gre_h
16 #define included_vnet_mpls_gre_h
17
18 #include <vnet/vnet.h>
19 #include <vnet/gre/gre.h>
20 #include <vnet/mpls/packet.h>
21 #include <vnet/mpls/mpls_types.h>
22 #include <vnet/ip/ip4_packet.h>
23 #include <vnet/ethernet/ethernet.h>
24 #include <vnet/fib/fib_node.h>
25 #include <vnet/adj/adj.h>
26
27 typedef CLIB_PACKED (struct {
28   ip4_header_t ip4;             /* 20 bytes */
29   gre_header_t gre;             /* 4 bytes */
30   mpls_unicast_header_t labels[0];   /* 4 bytes each */
31 }) ip4_gre_and_mpls_header_t;
32
33 extern vnet_hw_interface_class_t mpls_gre_hw_interface_class;
34
35 typedef enum {
36 #define mpls_error(n,s) MPLS_ERROR_##n,
37 #include <vnet/mpls/error.def>
38 #undef mpls_error
39   MPLS_N_ERROR,
40 } mpls_gre_error_t;
41
42 /* 
43  * No protocol info, MPLS labels don't have a next-header field 
44  * presumably the label field tells all...
45  */
46
47 typedef struct {
48   fib_node_t mgt_node;
49   ip4_address_t tunnel_src;
50   ip4_address_t tunnel_dst;
51   ip4_address_t intfc_address;
52   u32 mask_width;
53   u32 inner_fib_index;
54   u32 outer_fib_index;
55   u32 encap_index;
56   u32 hw_if_index;              /* L2 x-connect capable tunnel intfc */
57   u8 * rewrite_data;
58   u8 l2_only;
59   fib_node_index_t fei; /* FIB Entry index for the tunnel's destination */
60   adj_index_t adj_index; /* The midchain adj this tunnel creates */
61   u32 sibling_index;
62 } mpls_gre_tunnel_t;
63
64 typedef struct {
65   u8 tunnel_dst[6];
66   ip4_address_t intfc_address;
67   u32 tx_sw_if_index;
68   u32 inner_fib_index;
69   u32 mask_width;
70   u32 encap_index;
71   u32 hw_if_index;
72   u8 * rewrite_data;
73   u8 l2_only;
74   fib_node_index_t fei;
75 } mpls_eth_tunnel_t;
76
77 typedef struct {
78   mpls_unicast_header_t *labels;
79   /* only for policy tunnels */
80   u8 * rewrite;
81   u32 output_next_index;
82 } mpls_encap_t;
83
84 typedef struct {
85   u32 tx_fib_index;
86   u32 next_index;               /* e.g. ip4/6-input, l2-input */
87 } mpls_decap_t;
88
89 #define MPLS_FIB_DEFAULT_TABLE_ID 0
90
91 /**
92  * Type exposure is to allow the DP fast/inlined access
93  */
94 #define MPLS_FIB_KEY_SIZE 21
95 #define MPLS_FIB_DB_SIZE (1 << (MPLS_FIB_KEY_SIZE-1))
96
97 typedef struct mpls_fib_t_
98 {
99   /**
100    * A hash table of entries. 21 bit key
101    * Hash table for reduced memory footprint
102    */
103   uword * mf_entries; 
104
105   /**
106    * The load-balance indeices keyed by 21 bit label+eos bit.
107    * A flat array for maximum lookup performace.
108    */
109   index_t mf_lbs[MPLS_FIB_DB_SIZE];
110 } mpls_fib_t;
111
112 /**
113  * @brief Definition of a callback for receiving MPLS interface state change
114  * notifications
115  */
116 typedef void (*mpls_interface_state_change_callback_t)(u32 sw_if_index,
117                                                        u32 is_enable);
118
119 typedef struct {
120   /* MPLS FIB index for each software interface */
121   u32 *fib_index_by_sw_if_index;
122
123   /**  A pool of all the MPLS FIBs */
124   struct fib_table_t_ *fibs;
125
126   /** A hash table to lookup the mpls_fib by table ID */
127   uword *fib_index_by_table_id;
128
129   /* rx/tx interface/feature configuration. */
130   ip_config_main_t rx_config_mains, tx_config_main;
131
132   /* Built-in unicast feature path indices, see ip_feature_init_cast(...)  */
133   u32 mpls_rx_feature_lookup;
134   u32 mpls_rx_feature_not_enabled;
135
136   /* pool of gre tunnel instances */
137   mpls_gre_tunnel_t *gre_tunnels;
138   u32 * free_gre_sw_if_indices;
139
140   /* pool of ethernet tunnel instances */
141   mpls_eth_tunnel_t *eth_tunnels;
142   u32 * free_eth_sw_if_indices;
143
144   /* Encap side: map (fib, dst_address) to mpls label stack */
145   mpls_encap_t * encaps;
146   uword * mpls_encap_by_fib_and_dest;
147
148   /* Decap side: map rx label to FIB */
149   mpls_decap_t * decaps;
150   uword * mpls_decap_by_rx_fib_and_label;
151
152   /* mpls-o-e policy tunnel next index for ip4/ip6-classify */
153   u32 ip4_classify_mpls_policy_encap_next_index;
154   u32 ip6_classify_mpls_policy_encap_next_index;
155
156   /* feature path configuration lists */
157   vnet_ip_feature_registration_t * next_feature;
158
159   /* Save feature results for show command */
160   char **feature_nodes;
161
162   /* IP4 enabled count by software interface */
163   u8 * mpls_enabled_by_sw_if_index;
164
165   /* Functions to call when MPLS state on an interface changes. */
166   mpls_interface_state_change_callback_t * mpls_interface_state_change_callbacks;
167
168   /* convenience */
169   vlib_main_t * vlib_main;
170   vnet_main_t * vnet_main;
171 } mpls_main_t;
172
173 extern mpls_main_t mpls_main;
174
175 #define VNET_MPLS_FEATURE_INIT(x,...)                           \
176   __VA_ARGS__ vnet_ip_feature_registration_t uc_##x;            \
177 static void __vnet_add_feature_registration_uc_##x (void)       \
178   __attribute__((__constructor__)) ;                            \
179 static void __vnet_add_feature_registration_uc_##x (void)       \
180 {                                                               \
181   mpls_main_t * mm = &mpls_main;                                \
182   uc_##x.next = mm->next_feature;                               \
183   mm->next_feature = &uc_##x;                                   \
184 }                                                               \
185 __VA_ARGS__ vnet_ip_feature_registration_t uc_##x
186
187 extern clib_error_t * mpls_feature_init(vlib_main_t * vm);
188
189 format_function_t format_mpls_protocol;
190 format_function_t format_mpls_gre_header_with_length;
191 format_function_t format_mpls_eth_header_with_length;
192 format_function_t format_mpls_encap_index;
193
194 format_function_t format_mpls_eos_bit;
195 format_function_t format_mpls_unicast_header_net_byte_order;
196 format_function_t format_mpls_unicast_label;
197 format_function_t format_mpls_header;
198
199 extern vlib_node_registration_t mpls_input_node;
200 extern vlib_node_registration_t mpls_policy_encap_node;
201 extern vlib_node_registration_t mpls_output_node;
202 extern vlib_node_registration_t mpls_midchain_node;
203
204 extern vnet_device_class_t mpls_gre_device_class;
205
206 /* Parse mpls protocol as 0xXXXX or protocol name.
207    In either host or network byte order. */
208 unformat_function_t unformat_mpls_protocol_host_byte_order;
209 unformat_function_t unformat_mpls_protocol_net_byte_order;
210 unformat_function_t unformat_mpls_label_net_byte_order;
211 unformat_function_t unformat_mpls_gre_header;
212 unformat_function_t unformat_pg_mpls_gre_header;
213 unformat_function_t unformat_mpls_unicast_label;
214
215 /* Parse mpls header. */
216 unformat_function_t unformat_mpls_header;
217 unformat_function_t unformat_pg_mpls_header;
218
219 /* manually added to the interface output node in mpls.c */
220 #define MPLS_GRE_OUTPUT_NEXT_LOOKUP     1
221 #define MPLS_GRE_OUTPUT_NEXT_DROP       VNET_INTERFACE_TX_NEXT_DROP
222
223 void mpls_sw_interface_enable_disable (mpls_main_t * mm,
224                                        u32 sw_if_index,
225                                        u8 is_enable);
226
227 u8 mpls_sw_interface_is_enabled (u32 sw_if_index);
228
229 mpls_encap_t * 
230 mpls_encap_by_fib_and_dest (mpls_main_t * mm, u32 rx_fib, u32 dst_address);
231
232 int mpls_label_from_fib_id_and_dest (mpls_main_t *gm, u32 fib_id,
233                                      u32 dst_address, u32 *labelp);
234
235 int vnet_mpls_gre_add_del_tunnel (ip4_address_t *src,
236                                   ip4_address_t *dst,
237                                   ip4_address_t *intfc,
238                                   u32 mask_width,
239                                   u32 inner_fib_id, u32 outer_fib_id,
240                                   u32 * tunnel_intfc_sw_if_index,
241                                   u8 l2_only,
242                                   u8 is_add);
243
244 int vnet_mpls_ethernet_add_del_tunnel (u8 *dst,
245                                        ip4_address_t *intfc,
246                                        u32 mask_width,
247                                        u32 inner_fib_id, 
248                                        u32 tx_sw_if_index,
249                                        u32 * tunnel_sw_if_index,
250                                        u8 l2_only,
251                                        u8 is_add);
252
253 int vnet_mpls_gre_delete_fib_tunnels (u32 fib_id);
254
255 int mpls_fib_reset_labels (u32 fib_id);
256
257 int vnet_mpls_add_del_decap (u32 rx_fib_id, 
258                              u32 tx_fib_id,
259                              u32 label_host_byte_order, 
260                              int s_bit, int next_index, int is_add);
261
262 int vnet_mpls_add_del_encap (ip4_address_t *dest, u32 fib_id, 
263                              u32 *labels_host_byte_order,
264                              u32 policy_tunnel_index,
265                              int no_dst_hash, u32 * indexp, int is_add);
266
267 int vnet_mpls_policy_tunnel_add_rewrite (mpls_main_t * mm, 
268                                          mpls_encap_t * e, 
269                                          u32 policy_tunnel_index);
270
271 typedef struct {
272   u32 lookup_miss;
273
274   /* Tunnel-id / index in tunnel vector */
275   u32 tunnel_id;
276
277   /* mpls encap index */
278   u32 mpls_encap_index;
279
280   /* pkt length */
281   u32 length;
282
283   /* tunnel ip4 addresses */
284   ip4_address_t src;
285   ip4_address_t dst;
286 } mpls_gre_tx_trace_t;
287
288 u8 * format_mpls_gre_tx_trace (u8 * s, va_list * args);
289 u8 * format_mpls_gre_header (u8 * s, va_list * args);
290
291 #define foreach_mpls_input_next                 \
292 _(DROP, "error-drop")                           \
293 _(LOOKUP, "mpls-lookup")
294
295 typedef enum {
296 #define _(s,n) MPLS_INPUT_NEXT_##s,
297   foreach_mpls_input_next
298 #undef _
299   MPLS_INPUT_N_NEXT,
300 } mpls_input_next_t;
301
302 #define foreach_mpls_lookup_next                \
303 _(DROP, "error-drop")                           \
304 _(IP4_INPUT, "ip4-input")                       \
305 _(L2_OUTPUT, "l2-output")
306
307 // FIXME remove.
308 typedef enum {
309 #define _(s,n) MPLS_LOOKUP_NEXT_##s,
310   foreach_mpls_lookup_next
311 #undef _
312   MPLS_LOOKUP_N_NEXT,
313 } mpls_lookup_next_t;
314
315 #define foreach_mpls_output_next                \
316 _(DROP, "error-drop")                           
317
318 typedef enum {
319 #define _(s,n) MPLS_OUTPUT_NEXT_##s,
320   foreach_mpls_output_next
321 #undef _
322   MPLS_OUTPUT_N_NEXT,
323 } mpls_output_next_t;
324
325 typedef struct {
326   u32 lookup_miss;
327
328   /* Tunnel-id / index in tunnel vector */
329   u32 tunnel_id;
330
331   /* output interface */
332   u32 tx_sw_if_index;
333
334   /* mpls encap index */
335   u32 mpls_encap_index;
336
337   /* pkt length */
338   u32 length;
339
340   u8 dst[6];
341 } mpls_eth_tx_trace_t;
342
343 u8 * format_mpls_eth_tx_trace (u8 * s, va_list * args);
344
345 typedef struct {
346   u32 fib_index;
347   u32 entry_index;
348   u32 dest;
349   u32 s_bit;
350   u32 label;
351 } show_mpls_fib_t;
352
353 int
354 mpls_dest_cmp(void * a1, void * a2);
355
356 int
357 mpls_fib_index_cmp(void * a1, void * a2);
358
359 int
360 mpls_label_cmp(void * a1, void * a2);
361
362 #endif /* included_vnet_mpls_gre_h */