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 | /** |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 26 | * @brief The tunnel is L2 only |
| 27 | */ |
| 28 | MPLS_TUNNEL_ATTRIBUTE_L2 = MPLS_TUNNEL_ATTRIBUTE_FIRST, |
| 29 | /** |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 30 | * @brief The tunnel has an underlying multicast LSP |
| 31 | */ |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 32 | MPLS_TUNNEL_ATTRIBUTE_MCAST, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 33 | MPLS_TUNNEL_ATTRIBUTE_LAST = MPLS_TUNNEL_ATTRIBUTE_MCAST, |
| 34 | } mpls_tunnel_attribute_t; |
| 35 | |
| 36 | #define MPLS_TUNNEL_ATTRIBUTES { \ |
| 37 | [MPLS_TUNNEL_ATTRIBUTE_MCAST] = "multicast", \ |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 38 | [MPLS_TUNNEL_ATTRIBUTE_L2] = "L2", \ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 39 | } |
| 40 | #define FOR_EACH_MPLS_TUNNEL_ATTRIBUTE(_item) \ |
| 41 | for (_item = MPLS_TUNNEL_ATTRIBUTE_FIRST; \ |
Neale Ranns | 9f171f5 | 2017-04-11 08:56:53 -0700 | [diff] [blame] | 42 | _item <= MPLS_TUNNEL_ATTRIBUTE_LAST; \ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 43 | _item++) |
| 44 | |
| 45 | typedef enum mpls_tunnel_flag_t_ { |
| 46 | MPLS_TUNNEL_FLAG_NONE = 0, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 47 | MPLS_TUNNEL_FLAG_L2 = (1 << MPLS_TUNNEL_ATTRIBUTE_L2), |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 48 | MPLS_TUNNEL_FLAG_MCAST = (1 << MPLS_TUNNEL_ATTRIBUTE_MCAST), |
| 49 | } __attribute__ ((packed)) mpls_tunnel_flags_t; |
| 50 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * @brief A uni-directional MPLS tunnel |
| 54 | */ |
| 55 | typedef struct mpls_tunnel_t_ |
| 56 | { |
| 57 | /** |
| 58 | * @brief The tunnel hooks into the FIB control plane graph. |
| 59 | */ |
| 60 | fib_node_t mt_node; |
| 61 | |
| 62 | /** |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 63 | * @brief Tunnel flags |
| 64 | */ |
| 65 | mpls_tunnel_flags_t mt_flags; |
| 66 | |
| 67 | /** |
IJsbrand Wijnands | 39ae0a0 | 2020-03-05 10:56:26 -0800 | [diff] [blame] | 68 | * @brief User defined name tag for this MPLS Tunnel. |
| 69 | */ |
| 70 | u8 mt_tag[64]; |
| 71 | |
| 72 | /** |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 73 | * @brief If the tunnel is an L2 tunnel, this is the link type ETHERNET |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 74 | * load-balance |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 75 | */ |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 76 | dpo_id_t mt_l2_lb; |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 77 | |
| 78 | /** |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 79 | * @brief The HW interface index of the tunnel interfaces |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 80 | */ |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 81 | u32 mt_hw_if_index; |
| 82 | |
| 83 | /** |
| 84 | * @brief The SW interface index of the tunnel interfaces |
| 85 | */ |
| 86 | u32 mt_sw_if_index; |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * @brief The path-list over which the tunnel's destination is reachable |
| 90 | */ |
| 91 | fib_node_index_t mt_path_list; |
| 92 | |
| 93 | /** |
| 94 | * @brief sibling index on the path-list so notifications are received. |
| 95 | */ |
| 96 | u32 mt_sibling_index; |
| 97 | |
| 98 | /** |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 99 | * 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] | 100 | */ |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 101 | fib_path_ext_list_t mt_path_exts; |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 102 | } mpls_tunnel_t; |
| 103 | |
| 104 | /** |
| 105 | * @brief Create a new MPLS tunnel |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 106 | * @return the SW Interface index of the newly created tuneel |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 107 | */ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 108 | extern u32 vnet_mpls_tunnel_create (u8 l2_only, |
IJsbrand Wijnands | 39ae0a0 | 2020-03-05 10:56:26 -0800 | [diff] [blame] | 109 | u8 is_multicast, |
| 110 | u8 *description); |
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 | /** |
Paul Vinciguerra | b5a575b | 2019-11-01 13:00:58 -0400 | [diff] [blame] | 126 | * @brief return the tunnel index from the sw_if_index |
Neale Ranns | f5fa5ae | 2018-09-26 05:07:25 -0700 | [diff] [blame] | 127 | */ |
| 128 | extern int vnet_mpls_tunnel_get_index (u32 sw_if_index); |
| 129 | |
| 130 | /** |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 131 | * @brief Delete an MPLS tunnel |
| 132 | */ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 133 | extern void vnet_mpls_tunnel_del (u32 sw_if_index); |
| 134 | |
| 135 | extern const mpls_tunnel_t *mpls_tunnel_get(u32 index); |
| 136 | |
| 137 | /** |
| 138 | * @brief Callback function invoked while walking MPLS tunnels |
| 139 | */ |
| 140 | typedef void (*mpls_tunnel_walk_cb_t)(u32 index, void *ctx); |
| 141 | |
| 142 | /** |
| 143 | * @brief Walk all the MPLS tunnels |
| 144 | */ |
| 145 | extern void mpls_tunnel_walk(mpls_tunnel_walk_cb_t cb, |
| 146 | void *ctx); |
| 147 | |
| 148 | #endif |