Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 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 | |
| 16 | #ifndef __MPLS_TUNNEL_H__ |
| 17 | #define __MPLS_TUNNEL_H__ |
| 18 | |
| 19 | #include <vnet/mpls/mpls.h> |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 20 | #include <vnet/fib/fib_path_ext.h> |
| 21 | |
| 22 | typedef enum mpls_tunnel_attribute_t_ |
| 23 | { |
| 24 | MPLS_TUNNEL_ATTRIBUTE_FIRST = 0, |
| 25 | /** |
| 26 | * @brief The tunnel has an underlying multicast LSP |
| 27 | */ |
| 28 | MPLS_TUNNEL_ATTRIBUTE_MCAST = MPLS_TUNNEL_ATTRIBUTE_FIRST, |
| 29 | MPLS_TUNNEL_ATTRIBUTE_LAST = MPLS_TUNNEL_ATTRIBUTE_MCAST, |
| 30 | } mpls_tunnel_attribute_t; |
| 31 | |
| 32 | #define MPLS_TUNNEL_ATTRIBUTES { \ |
| 33 | [MPLS_TUNNEL_ATTRIBUTE_MCAST] = "multicast", \ |
| 34 | } |
| 35 | #define FOR_EACH_MPLS_TUNNEL_ATTRIBUTE(_item) \ |
| 36 | for (_item = MPLS_TUNNEL_ATTRIBUTE_FIRST; \ |
Neale Ranns | 9f171f5 | 2017-04-11 08:56:53 -0700 | [diff] [blame] | 37 | _item <= MPLS_TUNNEL_ATTRIBUTE_LAST; \ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 38 | _item++) |
| 39 | |
| 40 | typedef enum mpls_tunnel_flag_t_ { |
| 41 | MPLS_TUNNEL_FLAG_NONE = 0, |
| 42 | MPLS_TUNNEL_FLAG_MCAST = (1 << MPLS_TUNNEL_ATTRIBUTE_MCAST), |
| 43 | } __attribute__ ((packed)) mpls_tunnel_flags_t; |
| 44 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * @brief A uni-directional MPLS tunnel |
| 48 | */ |
| 49 | typedef struct mpls_tunnel_t_ |
| 50 | { |
| 51 | /** |
| 52 | * @brief The tunnel hooks into the FIB control plane graph. |
| 53 | */ |
| 54 | fib_node_t mt_node; |
| 55 | |
| 56 | /** |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 57 | * @brief Tunnel flags |
| 58 | */ |
| 59 | mpls_tunnel_flags_t mt_flags; |
| 60 | |
| 61 | /** |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 62 | * @brief If the tunnel is an L2 tunnel, this is the link type ETHERNET |
| 63 | * adjacency |
| 64 | */ |
| 65 | adj_index_t mt_l2_adj; |
| 66 | |
| 67 | /** |
| 68 | * @brief on a L2 tunnel this is the VLIB arc from the L2-tx to the l2-midchain |
| 69 | */ |
| 70 | u32 mt_l2_tx_arc; |
| 71 | |
| 72 | /** |
| 73 | * @brief The path-list over which the tunnel's destination is reachable |
| 74 | */ |
| 75 | fib_node_index_t mt_path_list; |
| 76 | |
| 77 | /** |
| 78 | * @brief sibling index on the path-list so notifications are received. |
| 79 | */ |
| 80 | u32 mt_sibling_index; |
| 81 | |
| 82 | /** |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 83 | * A vector of path extensions o hold the label stack for each path |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 84 | */ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 85 | fib_path_ext_t *mt_path_exts; |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * @brief Flag to indicate the tunnel is only for L2 traffic, that is |
| 89 | * this tunnel belongs in a bridge domain. |
| 90 | */ |
| 91 | u8 mt_l2_only; |
| 92 | |
| 93 | /** |
| 94 | * @brief The HW interface index of the tunnel interfaces |
| 95 | */ |
| 96 | u32 mt_hw_if_index; |
| 97 | |
| 98 | /** |
| 99 | * @brief The SW interface index of the tunnel interfaces |
| 100 | */ |
| 101 | u32 mt_sw_if_index; |
| 102 | |
| 103 | } mpls_tunnel_t; |
| 104 | |
| 105 | /** |
| 106 | * @brief Create a new MPLS tunnel |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 107 | * @return the SW Interface index of the newly created tuneel |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 108 | */ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 109 | extern u32 vnet_mpls_tunnel_create (u8 l2_only, |
| 110 | u8 is_multicast); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 111 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 112 | /** |
| 113 | * @brief Add a path to an MPLS tunnel |
| 114 | */ |
| 115 | extern void vnet_mpls_tunnel_path_add (u32 sw_if_index, |
| 116 | fib_route_path_t *rpath); |
| 117 | |
| 118 | /** |
| 119 | * @brief remove a path from a tunnel. |
| 120 | * @return the number of remaining paths. 0 implies the tunnel can be deleted |
| 121 | */ |
| 122 | extern int vnet_mpls_tunnel_path_remove (u32 sw_if_index, |
| 123 | fib_route_path_t *rpath); |
| 124 | |
| 125 | /** |
| 126 | * @brief Delete an MPLS tunnel |
| 127 | */ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 128 | extern void vnet_mpls_tunnel_del (u32 sw_if_index); |
| 129 | |
| 130 | extern const mpls_tunnel_t *mpls_tunnel_get(u32 index); |
| 131 | |
| 132 | /** |
| 133 | * @brief Callback function invoked while walking MPLS tunnels |
| 134 | */ |
| 135 | typedef void (*mpls_tunnel_walk_cb_t)(u32 index, void *ctx); |
| 136 | |
| 137 | /** |
| 138 | * @brief Walk all the MPLS tunnels |
| 139 | */ |
| 140 | extern void mpls_tunnel_walk(mpls_tunnel_walk_cb_t cb, |
| 141 | void *ctx); |
| 142 | |
| 143 | #endif |