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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef included_vnet_mpls_h
16 #define included_vnet_mpls_h
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>
27 #define mpls_error(n,s) MPLS_ERROR_##n,
28 #include <vnet/mpls/error.def>
34 * No protocol info, MPLS labels don't have a next-header field
35 * presumably the label field tells all...
39 ip4_address_t intfc_address;
51 mpls_unicast_header_t *labels;
52 /* only for policy tunnels */
54 u32 output_next_index;
57 #define MPLS_FIB_DEFAULT_TABLE_ID 0
60 * Type exposure is to allow the DP fast/inlined access
62 #define MPLS_FIB_KEY_SIZE 21
63 #define MPLS_FIB_DB_SIZE (1 << (MPLS_FIB_KEY_SIZE-1))
65 typedef struct mpls_fib_t_
68 * A hash table of entries. 21 bit key
69 * Hash table for reduced memory footprint
74 * The load-balance indeices keyed by 21 bit label+eos bit.
75 * A flat array for maximum lookup performace.
77 index_t mf_lbs[MPLS_FIB_DB_SIZE];
81 * @brief Definition of a callback for receiving MPLS interface state change
84 typedef void (*mpls_interface_state_change_callback_t)(u32 sw_if_index,
88 /* MPLS FIB index for each software interface */
89 u32 *fib_index_by_sw_if_index;
91 /** A pool of all the MPLS FIBs */
92 struct fib_table_t_ *fibs;
94 /** A hash table to lookup the mpls_fib by table ID */
95 uword *fib_index_by_table_id;
97 /* rx/tx interface/feature configuration. */
98 ip_config_main_t feature_config_mains[VNET_N_IP_FEAT];
100 /* Built-in unicast feature path indices, see vnet_feature_arc_init(...) */
101 u32 mpls_rx_feature_lookup;
102 u32 mpls_rx_feature_not_enabled;
103 u32 mpls_tx_feature_interface_output;
105 /* pool of ethernet tunnel instances */
106 mpls_eth_tunnel_t *eth_tunnels;
107 u32 * free_eth_sw_if_indices;
109 /* Encap side: map (fib, dst_address) to mpls label stack */
110 mpls_encap_t * encaps;
111 uword * mpls_encap_by_fib_and_dest;
113 /* mpls-o-e policy tunnel next index for ip4/ip6-classify */
114 u32 ip4_classify_mpls_policy_encap_next_index;
115 u32 ip6_classify_mpls_policy_encap_next_index;
117 /* feature path configuration lists */
118 vnet_feature_registration_t * next_feature[VNET_N_IP_FEAT];
120 /* Save feature results for show command */
121 char **feature_nodes[VNET_N_IP_FEAT];
123 /* IP4 enabled count by software interface */
124 u8 * mpls_enabled_by_sw_if_index;
127 vlib_main_t * vlib_main;
128 vnet_main_t * vnet_main;
131 extern mpls_main_t mpls_main;
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) \
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; \
143 __VA_ARGS__ vnet_feature_registration_t uc_##x
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) \
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; \
155 __VA_ARGS__ vnet_feature_registration_t tx_##x
157 extern clib_error_t * mpls_feature_init(vlib_main_t * vm);
159 format_function_t format_mpls_protocol;
160 format_function_t format_mpls_eth_header_with_length;
161 format_function_t format_mpls_encap_index;
163 format_function_t format_mpls_eos_bit;
164 format_function_t format_mpls_unicast_header_net_byte_order;
165 format_function_t format_mpls_unicast_label;
166 format_function_t format_mpls_header;
168 extern vlib_node_registration_t mpls_input_node;
169 extern vlib_node_registration_t mpls_policy_encap_node;
170 extern vlib_node_registration_t mpls_output_node;
171 extern vlib_node_registration_t mpls_midchain_node;
173 /* Parse mpls protocol as 0xXXXX or protocol name.
174 In either host or network byte order. */
175 unformat_function_t unformat_mpls_protocol_host_byte_order;
176 unformat_function_t unformat_mpls_protocol_net_byte_order;
177 unformat_function_t unformat_mpls_label_net_byte_order;
178 unformat_function_t unformat_mpls_unicast_label;
180 /* Parse mpls header. */
181 unformat_function_t unformat_mpls_header;
182 unformat_function_t unformat_pg_mpls_header;
184 void mpls_sw_interface_enable_disable (mpls_main_t * mm,
188 u8 mpls_sw_interface_is_enabled (u32 sw_if_index);
191 mpls_encap_by_fib_and_dest (mpls_main_t * mm, u32 rx_fib, u32 dst_address);
193 int vnet_mpls_ethernet_add_del_tunnel (u8 *dst,
194 ip4_address_t *intfc,
198 u32 * tunnel_sw_if_index,
202 int mpls_fib_reset_labels (u32 fib_id);
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);
209 int vnet_mpls_policy_tunnel_add_rewrite (mpls_main_t * mm,
211 u32 policy_tunnel_index);
213 #define foreach_mpls_input_next \
214 _(DROP, "error-drop") \
215 _(LOOKUP, "mpls-lookup")
218 #define _(s,n) MPLS_INPUT_NEXT_##s,
219 foreach_mpls_input_next
224 #define foreach_mpls_lookup_next \
225 _(DROP, "error-drop") \
226 _(IP4_INPUT, "ip4-input") \
227 _(L2_OUTPUT, "l2-output")
231 #define _(s,n) MPLS_LOOKUP_NEXT_##s,
232 foreach_mpls_lookup_next
235 } mpls_lookup_next_t;
237 #define foreach_mpls_output_next \
238 _(DROP, "error-drop")
241 #define _(s,n) MPLS_OUTPUT_NEXT_##s,
242 foreach_mpls_output_next
245 } mpls_output_next_t;
250 /* Tunnel-id / index in tunnel vector */
253 /* output interface */
256 /* mpls encap index */
257 u32 mpls_encap_index;
263 } mpls_eth_tx_trace_t;
265 u8 * format_mpls_eth_tx_trace (u8 * s, va_list * args);
276 mpls_dest_cmp(void * a1, void * a2);
279 mpls_fib_index_cmp(void * a1, void * a2);
282 mpls_label_cmp(void * a1, void * a2);
284 #endif /* included_vnet_mpls_h */