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.
16 #ifndef __MPLS_TUNNEL_H__
17 #define __MPLS_TUNNEL_H__
19 #include <vnet/mpls/mpls.h>
20 #include <vnet/fib/fib_path_ext.h>
22 typedef enum mpls_tunnel_attribute_t_
24 MPLS_TUNNEL_ATTRIBUTE_FIRST = 0,
26 * @brief The tunnel is L2 only
28 MPLS_TUNNEL_ATTRIBUTE_L2 = MPLS_TUNNEL_ATTRIBUTE_FIRST,
30 * @brief The tunnel has an underlying multicast LSP
32 MPLS_TUNNEL_ATTRIBUTE_MCAST,
33 MPLS_TUNNEL_ATTRIBUTE_LAST = MPLS_TUNNEL_ATTRIBUTE_MCAST,
34 } mpls_tunnel_attribute_t;
36 #define MPLS_TUNNEL_ATTRIBUTES { \
37 [MPLS_TUNNEL_ATTRIBUTE_MCAST] = "multicast", \
38 [MPLS_TUNNEL_ATTRIBUTE_L2] = "L2", \
40 #define FOR_EACH_MPLS_TUNNEL_ATTRIBUTE(_item) \
41 for (_item = MPLS_TUNNEL_ATTRIBUTE_FIRST; \
42 _item <= MPLS_TUNNEL_ATTRIBUTE_LAST; \
45 typedef enum mpls_tunnel_flag_t_ {
46 MPLS_TUNNEL_FLAG_NONE = 0,
47 MPLS_TUNNEL_FLAG_L2 = (1 << MPLS_TUNNEL_ATTRIBUTE_L2),
48 MPLS_TUNNEL_FLAG_MCAST = (1 << MPLS_TUNNEL_ATTRIBUTE_MCAST),
49 } __attribute__ ((packed)) mpls_tunnel_flags_t;
53 * @brief A uni-directional MPLS tunnel
55 typedef struct mpls_tunnel_t_
58 * @brief The tunnel hooks into the FIB control plane graph.
65 mpls_tunnel_flags_t mt_flags;
68 * @brief If the tunnel is an L2 tunnel, this is the link type ETHERNET
74 * @brief The HW interface index of the tunnel interfaces
79 * @brief The SW interface index of the tunnel interfaces
84 * @brief The path-list over which the tunnel's destination is reachable
86 fib_node_index_t mt_path_list;
89 * @brief sibling index on the path-list so notifications are received.
94 * A vector of path extensions o hold the label stack for each path
96 fib_path_ext_list_t mt_path_exts;
100 * @brief Create a new MPLS tunnel
101 * @return the SW Interface index of the newly created tuneel
103 extern u32 vnet_mpls_tunnel_create (u8 l2_only,
107 * @brief Add a path to an MPLS tunnel
109 extern void vnet_mpls_tunnel_path_add (u32 sw_if_index,
110 fib_route_path_t *rpath);
113 * @brief remove a path from a tunnel.
114 * @return the number of remaining paths. 0 implies the tunnel can be deleted
116 extern int vnet_mpls_tunnel_path_remove (u32 sw_if_index,
117 fib_route_path_t *rpath);
120 * @vrief return the tunnel index from the sw_if_index
122 extern int vnet_mpls_tunnel_get_index (u32 sw_if_index);
125 * @brief Delete an MPLS tunnel
127 extern void vnet_mpls_tunnel_del (u32 sw_if_index);
129 extern const mpls_tunnel_t *mpls_tunnel_get(u32 index);
132 * @brief Callback function invoked while walking MPLS tunnels
134 typedef void (*mpls_tunnel_walk_cb_t)(u32 index, void *ctx);
137 * @brief Walk all the MPLS tunnels
139 extern void mpls_tunnel_walk(mpls_tunnel_walk_cb_t cb,