Pablo Camarillo | 4299882 | 2017-07-13 09:41:32 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. Licensed under the Apache |
| 3 | * License, Version 2.0 (the "License"); you may not use this file except in |
| 4 | * compliance with the License. You may obtain a copy of the License at: |
| 5 | * |
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | * |
| 8 | * Unless required by applicable law or agreed to in writing, software |
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 10 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 11 | * License for the specific language governing permissions and limitations |
| 12 | * under the License. |
| 13 | */ |
| 14 | |
| 15 | /** |
| 16 | * @file |
| 17 | * @brief Segment Routing MPLS data structures definitions |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #ifndef included_vnet_srmpls_h |
| 22 | #define included_vnet_srmpls_h |
| 23 | |
| 24 | #include <vnet/vnet.h> |
| 25 | #include <vnet/mpls/packet.h> |
| 26 | #include <vnet/fib/mpls_fib.h> |
| 27 | #include <vnet/ip/ip.h> |
| 28 | #include <vnet/ip/lookup.h> |
| 29 | #include <vnet/dpo/dpo.h> |
| 30 | #include <vnet/dpo/replicate_dpo.h> |
| 31 | |
| 32 | #include <stdlib.h> |
| 33 | #include <string.h> |
| 34 | |
| 35 | /* SR policy types */ |
| 36 | #define SR_POLICY_TYPE_DEFAULT 0 |
| 37 | #define SR_POLICY_TYPE_SPRAY 1 |
| 38 | |
| 39 | #define SR_SEGMENT_LIST_WEIGHT_DEFAULT 1 |
| 40 | |
| 41 | #define SR_STEER_IPV4 4 |
| 42 | #define SR_STEER_IPV6 6 |
| 43 | |
| 44 | #define SR_TE_CO_BITS_00 0 |
| 45 | #define SR_TE_CO_BITS_01 1 |
| 46 | #define SR_TE_CO_BITS_10 2 |
| 47 | #define SR_TE_CO_BITS_11 3 |
| 48 | |
| 49 | /** |
| 50 | * @brief SR Segment List (SID list) |
| 51 | */ |
| 52 | typedef struct |
| 53 | { |
| 54 | /* SIDs (key) */ |
| 55 | mpls_label_t *segments; |
| 56 | |
| 57 | /* SID list weight (wECMP / UCMP) */ |
| 58 | u32 weight; |
| 59 | |
| 60 | } mpls_sr_sl_t; |
| 61 | |
| 62 | typedef struct |
| 63 | { |
| 64 | u32 *segments_lists; /**< Pool of SID lists indexes */ |
| 65 | |
| 66 | mpls_label_t bsid; /**< BindingSID (key) */ |
| 67 | |
| 68 | u8 type; /**< Type (default is 0) */ |
| 69 | /* SR Policy specific DPO */ |
Nathan Skrzypczak | 2c77ae4 | 2021-09-29 15:36:51 +0200 | [diff] [blame] | 70 | /* IF Type = DEFAULT Then Load-Balancer DPO among SID lists */ |
Pablo Camarillo | 4299882 | 2017-07-13 09:41:32 +0200 | [diff] [blame] | 71 | /* IF Type = SPRAY then Spray DPO with all SID lists */ |
| 72 | |
| 73 | ip46_address_t endpoint; /**< Optional NH for SR TE */ |
| 74 | u8 endpoint_type; |
| 75 | u32 color; /**< Optional color for SR TE */ |
| 76 | } mpls_sr_policy_t; |
| 77 | |
| 78 | /** |
| 79 | * @brief Steering db key |
| 80 | * |
| 81 | * L3 is IPv4/IPv6 + mask |
| 82 | */ |
| 83 | typedef struct |
| 84 | { |
| 85 | ip46_address_t prefix; /**< IP address of the prefix */ |
| 86 | u32 mask_width; /**< Mask width of the prefix */ |
| 87 | u32 fib_table; /**< VRF of the prefix */ |
| 88 | u8 traffic_type; /**< Traffic type (IPv4, IPv6, L2) */ |
| 89 | u8 padding[3]; |
| 90 | } sr_mpls_steering_key_t; |
| 91 | |
| 92 | typedef struct |
| 93 | { |
| 94 | sr_mpls_steering_key_t classify; /**< Traffic classification */ |
| 95 | mpls_label_t bsid; /**< SR Policy index */ |
| 96 | ip46_address_t next_hop; /**< SR TE NH */ |
| 97 | char nh_type; |
| 98 | u32 *color; /**< Vector of SR TE colors */ |
| 99 | char co_bits; /**< Color-Only bits */ |
| 100 | mpls_label_t vpn_label; |
| 101 | } mpls_sr_steering_policy_t; |
| 102 | |
| 103 | /** |
| 104 | * @brief Segment Routing main datastructure |
| 105 | */ |
| 106 | typedef struct |
| 107 | { |
| 108 | /* SR SID lists */ |
| 109 | mpls_sr_sl_t *sid_lists; |
| 110 | |
| 111 | /* SR MPLS policies */ |
| 112 | mpls_sr_policy_t *sr_policies; |
| 113 | |
| 114 | /* Hash table mapping BindingSID to SR MPLS policy */ |
| 115 | uword *sr_policies_index_hash; |
| 116 | |
| 117 | /* Pool of SR steer policies instances */ |
| 118 | mpls_sr_steering_policy_t *steer_policies; |
| 119 | |
| 120 | /* MHash table mapping steering rules to SR steer instance */ |
| 121 | mhash_t sr_steer_policies_hash; |
| 122 | |
| 123 | /** SR TE **/ |
| 124 | /* Hash table mapping (Color->Endpoint->BSID) for SR policies */ |
| 125 | mhash_t sr_policies_c2e2eclabel_hash; |
| 126 | /* SR TE (internal) fib table (Endpoint, Color) */ |
| 127 | u32 fib_table_EC; |
| 128 | /* Pool of (Endpoint, Color) hidden labels */ |
| 129 | u32 *ec_labels; |
| 130 | |
| 131 | /* convenience */ |
| 132 | vlib_main_t *vlib_main; |
| 133 | vnet_main_t *vnet_main; |
| 134 | } mpls_sr_main_t; |
| 135 | |
| 136 | extern mpls_sr_main_t sr_mpls_main; |
| 137 | |
| 138 | extern int |
| 139 | sr_mpls_policy_add (mpls_label_t bsid, mpls_label_t * segments, |
| 140 | u8 behavior, u32 weight); |
| 141 | |
| 142 | extern int |
| 143 | sr_mpls_policy_mod (mpls_label_t bsid, u8 operation, |
| 144 | mpls_label_t * segments, u32 sl_index, u32 weight); |
| 145 | |
| 146 | extern int sr_mpls_policy_del (mpls_label_t bsid); |
| 147 | |
| 148 | extern int |
| 149 | sr_mpls_policy_assign_endpoint_color (mpls_label_t bsid, |
| 150 | ip46_address_t * endpoint, |
| 151 | u8 endpoint_type, u32 color); |
| 152 | |
| 153 | extern int |
| 154 | sr_mpls_steering_policy_add (mpls_label_t bsid, u32 table_id, |
| 155 | ip46_address_t * prefix, u32 mask_width, |
| 156 | u8 traffic_type, ip46_address_t * next_hop, |
| 157 | u8 nh_type, u32 color, char co_bits, |
| 158 | mpls_label_t vpn_label); |
| 159 | |
| 160 | extern int |
| 161 | sr_mpls_steering_policy_del (ip46_address_t * prefix, |
| 162 | u32 mask_width, u8 traffic_type, u32 table_id, |
| 163 | u32 color); |
| 164 | |
| 165 | extern u32 find_or_create_internal_label (ip46_address_t endpoint, u32 color); |
| 166 | |
| 167 | extern void internal_label_lock (ip46_address_t endpoint, u32 color); |
| 168 | |
| 169 | extern void internal_label_unlock (ip46_address_t endpoint, u32 color); |
| 170 | |
| 171 | #endif /* included_vnet_sr_mpls_h */ |
| 172 | |
| 173 | /* |
| 174 | * fd.io coding-style-patch-verification: ON |
| 175 | * |
| 176 | * Local Variables: eval: (c-set-style "gnu") End: |
| 177 | */ |