Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [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 | /** |
| 17 | * @file |
| 18 | * @brief Segment Routing MPLS data structures definitions |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #ifndef included_vnet_srmpls_h |
| 23 | #define included_vnet_srmpls_h |
| 24 | |
| 25 | #include <vnet/vnet.h> |
| 26 | #include <vnet/mpls/packet.h> |
| 27 | #include <vnet/fib/mpls_fib.h> |
| 28 | #include <vnet/ip/ip.h> |
| 29 | #include <vnet/ip/lookup.h> |
| 30 | #include <vnet/dpo/dpo.h> |
| 31 | #include <vnet/dpo/replicate_dpo.h> |
| 32 | |
| 33 | #include <stdlib.h> |
| 34 | #include <string.h> |
| 35 | |
| 36 | /* SR policy types */ |
| 37 | #define SR_POLICY_TYPE_DEFAULT 0 |
| 38 | #define SR_POLICY_TYPE_SPRAY 1 |
| 39 | |
| 40 | #define SR_SEGMENT_LIST_WEIGHT_DEFAULT 1 |
| 41 | |
| 42 | #define SR_STEER_IPV4 4 |
| 43 | #define SR_STEER_IPV6 6 |
| 44 | |
| 45 | /** |
| 46 | * @brief SR Segment List (SID list) |
| 47 | */ |
| 48 | typedef struct |
| 49 | { |
| 50 | /** |
| 51 | * SIDs (key) |
| 52 | */ |
| 53 | mpls_label_t *segments; |
| 54 | |
| 55 | /** |
| 56 | * SID list weight (wECMP / UCMP) |
| 57 | */ |
| 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 */ |
| 70 | /* IF Type = DEFAULT Then Load Balancer DPO among SID lists */ |
| 71 | /* IF Type = SPRAY then Spray DPO with all SID lists */ |
| 72 | |
| 73 | } mpls_sr_policy_t; |
| 74 | |
| 75 | /** |
| 76 | * @brief Steering db key |
| 77 | * |
| 78 | * L3 is IPv4/IPv6 + mask |
| 79 | */ |
| 80 | typedef struct |
| 81 | { |
| 82 | ip46_address_t prefix; /**< IP address of the prefix */ |
| 83 | u32 mask_width; /**< Mask width of the prefix */ |
| 84 | u32 fib_table; /**< VRF of the prefix */ |
| 85 | u8 traffic_type; /**< Traffic type (IPv4, IPv6, L2) */ |
| 86 | u8 padding[3]; |
| 87 | } sr_mpls_steering_key_t; |
| 88 | |
| 89 | typedef struct |
| 90 | { |
| 91 | sr_mpls_steering_key_t classify; /**< Traffic classification */ |
| 92 | u32 sr_policy; /**< SR Policy index */ |
| 93 | } mpls_sr_steering_policy_t; |
| 94 | |
| 95 | /** |
| 96 | * @brief Segment Routing main datastructure |
| 97 | */ |
| 98 | typedef struct |
| 99 | { |
| 100 | /** |
| 101 | * SR SID lists |
| 102 | */ |
| 103 | mpls_sr_sl_t *sid_lists; |
| 104 | |
| 105 | /** |
| 106 | * SR MPLS policies |
| 107 | */ |
| 108 | mpls_sr_policy_t *sr_policies; |
| 109 | |
| 110 | /** |
| 111 | * Hash table mapping BindingSID to SR MPLS policy |
| 112 | */ |
| 113 | uword *sr_policies_index_hash; |
| 114 | |
| 115 | /** |
| 116 | * Pool of SR steer policies instances |
| 117 | */ |
| 118 | mpls_sr_steering_policy_t *steer_policies; |
| 119 | |
| 120 | /** |
| 121 | * MHash table mapping steering rules to SR steer instance |
| 122 | */ |
| 123 | mhash_t sr_steer_policies_hash; |
| 124 | |
| 125 | /** |
| 126 | * convenience |
| 127 | */ |
| 128 | vlib_main_t *vlib_main; |
| 129 | vnet_main_t *vnet_main; |
| 130 | } mpls_sr_main_t; |
| 131 | |
| 132 | extern mpls_sr_main_t sr_mpls_main; |
| 133 | |
| 134 | extern int |
| 135 | sr_mpls_policy_add (mpls_label_t bsid, mpls_label_t * segments, |
| 136 | u8 behavior, u32 weight); |
| 137 | |
| 138 | extern int |
| 139 | sr_mpls_policy_mod (mpls_label_t bsid, u32 index, u8 operation, |
| 140 | mpls_label_t * segments, u32 sl_index, u32 weight); |
| 141 | |
| 142 | extern int sr_mpls_policy_del (mpls_label_t bsid, u32 index); |
| 143 | |
| 144 | #endif /* included_vnet_sr_mpls_h */ |
| 145 | |
| 146 | /* |
| 147 | * fd.io coding-style-patch-verification: ON |
| 148 | * |
| 149 | * Local Variables: |
| 150 | * eval: (c-set-style "gnu") |
| 151 | * End: |
| 152 | */ |