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 /* pool of ethernet tunnel instances */
98 mpls_eth_tunnel_t *eth_tunnels;
99 u32 * free_eth_sw_if_indices;
101 /* Encap side: map (fib, dst_address) to mpls label stack */
102 mpls_encap_t * encaps;
103 uword * mpls_encap_by_fib_and_dest;
105 /* mpls-o-e policy tunnel next index for ip4/ip6-classify */
106 u32 ip4_classify_mpls_policy_encap_next_index;
107 u32 ip6_classify_mpls_policy_encap_next_index;
109 /* Feature arc indices */
110 u8 input_feature_arc_index;
111 u8 output_feature_arc_index;
113 /* IP4 enabled count by software interface */
114 u8 * mpls_enabled_by_sw_if_index;
117 vlib_main_t * vlib_main;
118 vnet_main_t * vnet_main;
121 extern mpls_main_t mpls_main;
123 extern clib_error_t * mpls_feature_init(vlib_main_t * vm);
125 format_function_t format_mpls_protocol;
126 format_function_t format_mpls_eth_header_with_length;
127 format_function_t format_mpls_encap_index;
129 format_function_t format_mpls_eos_bit;
130 format_function_t format_mpls_unicast_header_net_byte_order;
131 format_function_t format_mpls_unicast_label;
132 format_function_t format_mpls_header;
134 extern vlib_node_registration_t mpls_input_node;
135 extern vlib_node_registration_t mpls_policy_encap_node;
136 extern vlib_node_registration_t mpls_output_node;
137 extern vlib_node_registration_t mpls_midchain_node;
139 /* Parse mpls protocol as 0xXXXX or protocol name.
140 In either host or network byte order. */
141 unformat_function_t unformat_mpls_protocol_host_byte_order;
142 unformat_function_t unformat_mpls_protocol_net_byte_order;
143 unformat_function_t unformat_mpls_label_net_byte_order;
144 unformat_function_t unformat_mpls_unicast_label;
146 /* Parse mpls header. */
147 unformat_function_t unformat_mpls_header;
148 unformat_function_t unformat_pg_mpls_header;
150 void mpls_sw_interface_enable_disable (mpls_main_t * mm,
154 u8 mpls_sw_interface_is_enabled (u32 sw_if_index);
157 mpls_encap_by_fib_and_dest (mpls_main_t * mm, u32 rx_fib, u32 dst_address);
159 int vnet_mpls_ethernet_add_del_tunnel (u8 *dst,
160 ip4_address_t *intfc,
164 u32 * tunnel_sw_if_index,
168 int mpls_fib_reset_labels (u32 fib_id);
170 int vnet_mpls_add_del_encap (ip4_address_t *dest, u32 fib_id,
171 u32 *labels_host_byte_order,
172 u32 policy_tunnel_index,
173 int no_dst_hash, u32 * indexp, int is_add);
175 int vnet_mpls_policy_tunnel_add_rewrite (mpls_main_t * mm,
177 u32 policy_tunnel_index);
179 #define foreach_mpls_input_next \
180 _(DROP, "error-drop") \
181 _(LOOKUP, "mpls-lookup")
184 #define _(s,n) MPLS_INPUT_NEXT_##s,
185 foreach_mpls_input_next
190 #define foreach_mpls_lookup_next \
191 _(DROP, "error-drop") \
192 _(IP4_INPUT, "ip4-input") \
193 _(L2_OUTPUT, "l2-output")
197 #define _(s,n) MPLS_LOOKUP_NEXT_##s,
198 foreach_mpls_lookup_next
201 } mpls_lookup_next_t;
203 #define foreach_mpls_output_next \
204 _(DROP, "error-drop")
207 #define _(s,n) MPLS_OUTPUT_NEXT_##s,
208 foreach_mpls_output_next
211 } mpls_output_next_t;
216 /* Tunnel-id / index in tunnel vector */
219 /* output interface */
222 /* mpls encap index */
223 u32 mpls_encap_index;
229 } mpls_eth_tx_trace_t;
231 u8 * format_mpls_eth_tx_trace (u8 * s, va_list * args);
242 mpls_dest_cmp(void * a1, void * a2);
245 mpls_fib_index_cmp(void * a1, void * a2);
248 mpls_label_cmp(void * a1, void * a2);
250 #endif /* included_vnet_mpls_h */