FD.io VPP  v16.12-rc0-308-g931be3a
Vector Packet Processing
mpls.h
Go to the documentation of this file.
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_h
16 #define included_vnet_mpls_h
17 
18 #include <vnet/vnet.h>
19 #include <vnet/mpls/packet.h>
20 #include <vnet/mpls/mpls_types.h>
21 #include <vnet/ip/ip4_packet.h>
22 #include <vnet/ethernet/ethernet.h>
23 #include <vnet/fib/fib_node.h>
24 #include <vnet/adj/adj.h>
25 
26 typedef enum {
27 #define mpls_error(n,s) MPLS_ERROR_##n,
28 #include <vnet/mpls/error.def>
29 #undef mpls_error
30  MPLS_N_ERROR,
31 } mpls_error_t;
32 
33 /*
34  * No protocol info, MPLS labels don't have a next-header field
35  * presumably the label field tells all...
36  */
37 typedef struct {
38  u8 tunnel_dst[6];
46  u8 l2_only;
49 
50 typedef struct {
52  /* only for policy tunnels */
55 } mpls_encap_t;
56 
57 #define MPLS_FIB_DEFAULT_TABLE_ID 0
58 
59 /**
60  * Type exposure is to allow the DP fast/inlined access
61  */
62 #define MPLS_FIB_KEY_SIZE 21
63 #define MPLS_FIB_DB_SIZE (1 << (MPLS_FIB_KEY_SIZE-1))
64 
65 typedef struct mpls_fib_t_
66 {
67  /**
68  * A hash table of entries. 21 bit key
69  * Hash table for reduced memory footprint
70  */
72 
73  /**
74  * The load-balance indeices keyed by 21 bit label+eos bit.
75  * A flat array for maximum lookup performace.
76  */
78 } mpls_fib_t;
79 
80 /**
81  * @brief Definition of a callback for receiving MPLS interface state change
82  * notifications
83  */
84 typedef void (*mpls_interface_state_change_callback_t)(u32 sw_if_index,
85  u32 is_enable);
86 
87 typedef struct {
88  /* MPLS FIB index for each software interface */
90 
91  /** A pool of all the MPLS FIBs */
92  struct fib_table_t_ *fibs;
93 
94  /** A hash table to lookup the mpls_fib by table ID */
96 
97  /* rx/tx interface/feature configuration. */
99 
100  /* Built-in unicast feature path indices, see vnet_feature_arc_init(...) */
104 
105  /* pool of ethernet tunnel instances */
108 
109  /* Encap side: map (fib, dst_address) to mpls label stack */
112 
113  /* mpls-o-e policy tunnel next index for ip4/ip6-classify */
116 
117  /* feature path configuration lists */
119 
120  /* Save feature results for show command */
121  char **feature_nodes[VNET_N_IP_FEAT];
122 
123  /* IP4 enabled count by software interface */
125 
126  /* convenience */
129 } mpls_main_t;
130 
131 extern mpls_main_t mpls_main;
132 
133 #define VNET_MPLS_FEATURE_INIT(x,...) \
134  __VA_ARGS__ vnet_feature_registration_t uc_##x; \
135 static void __vnet_add_feature_registration_uc_##x (void) \
136  __attribute__((__constructor__)) ; \
137 static void __vnet_add_feature_registration_uc_##x (void) \
138 { \
139  mpls_main_t * mm = &mpls_main; \
140  uc_##x.next = mm->next_feature[VNET_IP_RX_UNICAST_FEAT]; \
141  mm->next_feature[VNET_IP_RX_UNICAST_FEAT] = &uc_##x; \
142 } \
143 __VA_ARGS__ vnet_feature_registration_t uc_##x
144 
145 #define VNET_MPLS_TX_FEATURE_INIT(x,...) \
146  __VA_ARGS__ vnet_feature_registration_t tx_##x; \
147 static void __vnet_add_feature_registration_tx_##x (void) \
148  __attribute__((__constructor__)) ; \
149 static void __vnet_add_feature_registration_tx_##x (void) \
150 { \
151  mpls_main_t * mm = &mpls_main; \
152  tx_##x.next = mm->next_feature[VNET_IP_TX_FEAT]; \
153  mm->next_feature[VNET_IP_TX_FEAT] = &tx_##x; \
154 } \
155 __VA_ARGS__ vnet_feature_registration_t tx_##x
156 
158 
162 
167 
172 
173 /* Parse mpls protocol as 0xXXXX or protocol name.
174  In either host or network byte order. */
179 
180 /* Parse mpls header. */
183 
185  u32 sw_if_index,
186  u8 is_enable);
187 
188 u8 mpls_sw_interface_is_enabled (u32 sw_if_index);
189 
190 mpls_encap_t *
191 mpls_encap_by_fib_and_dest (mpls_main_t * mm, u32 rx_fib, u32 dst_address);
192 
194  ip4_address_t *intfc,
195  u32 mask_width,
196  u32 inner_fib_id,
197  u32 tx_sw_if_index,
198  u32 * tunnel_sw_if_index,
199  u8 l2_only,
200  u8 is_add);
201 
202 int mpls_fib_reset_labels (u32 fib_id);
203 
204 int vnet_mpls_add_del_encap (ip4_address_t *dest, u32 fib_id,
205  u32 *labels_host_byte_order,
206  u32 policy_tunnel_index,
207  int no_dst_hash, u32 * indexp, int is_add);
208 
210  mpls_encap_t * e,
211  u32 policy_tunnel_index);
212 
213 #define foreach_mpls_input_next \
214 _(DROP, "error-drop") \
215 _(LOOKUP, "mpls-lookup")
216 
217 typedef enum {
218 #define _(s,n) MPLS_INPUT_NEXT_##s,
220 #undef _
223 
224 #define foreach_mpls_lookup_next \
225 _(DROP, "error-drop") \
226 _(IP4_INPUT, "ip4-input") \
227 _(L2_OUTPUT, "l2-output")
228 
229 // FIXME remove.
230 typedef enum {
231 #define _(s,n) MPLS_LOOKUP_NEXT_##s,
233 #undef _
236 
237 #define foreach_mpls_output_next \
238 _(DROP, "error-drop")
239 
240 typedef enum {
241 #define _(s,n) MPLS_OUTPUT_NEXT_##s,
243 #undef _
246 
247 typedef struct {
249 
250  /* Tunnel-id / index in tunnel vector */
252 
253  /* output interface */
255 
256  /* mpls encap index */
258 
259  /* pkt length */
261 
262  u8 dst[6];
264 
265 u8 * format_mpls_eth_tx_trace (u8 * s, va_list * args);
266 
267 typedef struct {
274 
275 int
276 mpls_dest_cmp(void * a1, void * a2);
277 
278 int
279 mpls_fib_index_cmp(void * a1, void * a2);
280 
281 int
282 mpls_label_cmp(void * a1, void * a2);
283 
284 #endif /* included_vnet_mpls_h */
struct mpls_fib_t_ mpls_fib_t
uword( unformat_function_t)(unformat_input_t *input, va_list *args)
Definition: format.h:231
u8 * format_mpls_eth_tx_trace(u8 *s, va_list *args)
Definition: mpls.c:124
format_function_t format_mpls_header
Definition: mpls.h:166
u32 mask_width
Definition: mpls.h:42
#define foreach_mpls_lookup_next
Definition: mpls.h:224
format_function_t format_mpls_eth_header_with_length
Definition: mpls.h:160
u32 mpls_rx_feature_not_enabled
Definition: mpls.h:102
int mpls_label_cmp(void *a1, void *a2)
Definition: mpls.c:413
void mpls_sw_interface_enable_disable(mpls_main_t *mm, u32 sw_if_index, u8 is_enable)
Definition: interface.c:275
u32 * fib_index_by_sw_if_index
Definition: mpls.h:89
u32 hw_if_index
Definition: mpls.h:44
format_function_t format_mpls_protocol
Definition: mpls.h:159
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
struct _vlib_node_registration vlib_node_registration_t
u32 mpls_tx_feature_interface_output
Definition: mpls.h:103
uword * mpls_encap_by_fib_and_dest
Definition: mpls.h:111
#define foreach_mpls_input_next
Definition: mpls.h:213
unformat_function_t unformat_mpls_unicast_label
Definition: mpls.h:178
u8 * mpls_enabled_by_sw_if_index
Definition: mpls.h:124
format_function_t format_mpls_unicast_header_net_byte_order
Definition: mpls.h:164
void(* mpls_interface_state_change_callback_t)(u32 sw_if_index, u32 is_enable)
Definition of a callback for receiving MPLS interface state change notifications. ...
Definition: mpls.h:84
vlib_node_registration_t mpls_midchain_node
(constructor) VLIB_REGISTER_NODE (mpls_midchain_node)
Definition: mpls_output.c:206
mpls_lookup_next_t
Definition: mpls.h:230
ip4_address_t intfc_address
Definition: mpls.h:39
format_function_t format_mpls_eos_bit
Definition: mpls.h:163
mpls_error_t
Definition: mpls.h:26
vlib_node_registration_t mpls_policy_encap_node
(constructor) VLIB_REGISTER_NODE (mpls_policy_encap_node)
Definition: policy_encap.c:136
u32 entry_index
Definition: mpls.h:269
int mpls_fib_reset_labels(u32 fib_id)
Definition: mpls.c:656
#define MPLS_FIB_DB_SIZE
Definition: mpls.h:63
vlib_node_registration_t mpls_input_node
(constructor) VLIB_REGISTER_NODE (mpls_input_node)
Definition: node.c:168
vnet_main_t * vnet_main
Definition: mpls.h:128
u32 tx_sw_if_index
Definition: mpls.h:40
u32 output_next_index
Definition: mpls.h:54
mpls_main_t mpls_main
Definition: mpls.c:25
struct fib_table_t_ * fibs
A pool of all the MPLS FIBs.
Definition: mpls.h:92
u32 * free_eth_sw_if_indices
Definition: mpls.h:107
fib_node_index_t fei
Definition: mpls.h:47
int mpls_fib_index_cmp(void *a1, void *a2)
Definition: mpls.c:404
unformat_function_t unformat_mpls_protocol_net_byte_order
Definition: mpls.h:176
u8 * rewrite
Definition: mpls.h:53
unformat_function_t unformat_mpls_header
Definition: mpls.h:181
unformat_function_t unformat_mpls_protocol_host_byte_order
Definition: mpls.h:175
unformat_function_t unformat_pg_mpls_header
Definition: mpls.h:182
mpls_output_next_t
Definition: mpls.h:240
u32 ip4_classify_mpls_policy_encap_next_index
Definition: mpls.h:114
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
u8 * rewrite_data
Definition: mpls.h:45
mpls_eth_tunnel_t * eth_tunnels
Definition: mpls.h:106
u32 mpls_encap_index
Definition: mpls.h:257
u32 fib_index
Definition: mpls.h:268
clib_error_t * mpls_feature_init(vlib_main_t *vm)
#define foreach_mpls_output_next
Definition: mpls.h:237
uword * mf_entries
A hash table of entries.
Definition: mpls.h:71
unsigned int u32
Definition: types.h:88
u32 ip6_classify_mpls_policy_encap_next_index
Definition: mpls.h:115
u8 mpls_sw_interface_is_enabled(u32 sw_if_index)
Definition: interface.c:264
int vnet_mpls_ethernet_add_del_tunnel(u8 *dst, ip4_address_t *intfc, u32 mask_width, u32 inner_fib_id, u32 tx_sw_if_index, u32 *tunnel_sw_if_index, u8 l2_only, u8 is_add)
Definition: interface.c:441
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
format_function_t format_mpls_unicast_label
Definition: mpls.h:165
u64 uword
Definition: types.h:112
mpls_input_next_t
Definition: mpls.h:217
unsigned char u8
Definition: types.h:56
u32 inner_fib_index
Definition: mpls.h:41
int vnet_mpls_add_del_encap(ip4_address_t *dest, u32 fib_id, u32 *labels_host_byte_order, u32 policy_tunnel_index, int no_dst_hash, u32 *indexp, int is_add)
Definition: mpls.c:196
u32 encap_index
Definition: mpls.h:43
vlib_main_t * vlib_main
Definition: mpls.h:127
int vnet_mpls_policy_tunnel_add_rewrite(mpls_main_t *mm, mpls_encap_t *e, u32 policy_tunnel_index)
Definition: interface.c:754
mpls_encap_t * mpls_encap_by_fib_and_dest(mpls_main_t *mm, u32 rx_fib, u32 dst_address)
Definition: mpls.c:180
unformat_function_t unformat_mpls_label_net_byte_order
Definition: mpls.h:177
format_function_t format_mpls_encap_index
Definition: mpls.h:161
u32 tx_sw_if_index
Definition: mpls.h:254
index_t mf_lbs[MPLS_FIB_DB_SIZE]
The load-balance indeices keyed by 21 bit label+eos bit.
Definition: mpls.h:77
uword * fib_index_by_table_id
A hash table to lookup the mpls_fib by table ID.
Definition: mpls.h:95
u32 mpls_rx_feature_lookup
Definition: mpls.h:101
vlib_node_registration_t mpls_output_node
(constructor) VLIB_REGISTER_NODE (mpls_output_node)
Definition: mpls_output.c:178
mpls_unicast_header_t * labels
Definition: mpls.h:51
mpls_encap_t * encaps
Definition: mpls.h:110
int mpls_dest_cmp(void *a1, void *a2)
Definition: mpls.c:395
A protocol Independent FIB table.
Definition: fib_table.h:29
struct _vnet_feature_registration vnet_feature_registration_t
feature registration object