blob: 5efeb4dd06a65d5d3c147336609d123a65ddcc32 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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 */
Pablo Camarillofb380952016-12-07 18:34:18 +010015
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070016/**
17 * @file
Pablo Camarillofb380952016-12-07 18:34:18 +010018 * @brief Segment Routing data structures definitions
19 *
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070020 */
Pablo Camarillofb380952016-12-07 18:34:18 +010021
Ed Warnickecb9cada2015-12-08 15:45:58 -070022#ifndef included_vnet_sr_h
23#define included_vnet_sr_h
24
25#include <vnet/vnet.h>
26#include <vnet/sr/sr_packet.h>
27#include <vnet/ip/ip6_packet.h>
Pablo Camarillofb380952016-12-07 18:34:18 +010028#include <vnet/ethernet/ethernet.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070029
Ed Warnickecb9cada2015-12-08 15:45:58 -070030#include <stdlib.h>
31#include <string.h>
32
Pablo Camarillofb380952016-12-07 18:34:18 +010033#define IPv6_DEFAULT_HEADER_LENGTH 40
34#define IPv6_DEFAULT_HOP_LIMIT 64
35#define IPv6_DEFAULT_MAX_MASK_WIDTH 128
36
37#define SR_BEHAVIOR_END 1
38#define SR_BEHAVIOR_X 2
39#define SR_BEHAVIOR_D_FIRST 3 /* Unused. Separator in between regular and D */
40#define SR_BEHAVIOR_DX2 4
41#define SR_BEHAVIOR_DX6 5
42#define SR_BEHAVIOR_DX4 6
43#define SR_BEHAVIOR_DT6 7
44#define SR_BEHAVIOR_DT4 8
45#define SR_BEHAVIOR_LAST 9 /* Must always be the last one */
46
47#define SR_STEER_L2 2
48#define SR_STEER_IPV4 4
49#define SR_STEER_IPV6 6
50
51#define SR_FUNCTION_SIZE 4
52#define SR_ARGUMENT_SIZE 4
53
54#define SR_SEGMENT_LIST_WEIGHT_DEFAULT 1
Ed Warnickecb9cada2015-12-08 15:45:58 -070055
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070056/**
Pablo Camarillofb380952016-12-07 18:34:18 +010057 * @brief SR Segment List (SID list)
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070058 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070059typedef struct
60{
Pablo Camarillofb380952016-12-07 18:34:18 +010061 ip6_address_t *segments; /**< SIDs (key) */
Ed Warnickecb9cada2015-12-08 15:45:58 -070062
Pablo Camarillofb380952016-12-07 18:34:18 +010063 u32 weight; /**< SID list weight (wECMP / UCMP) */
64
65 u8 *rewrite; /**< Precomputed rewrite header */
66 u8 *rewrite_bsid; /**< Precomputed rewrite header for bindingSID */
67
68 dpo_id_t bsid_dpo; /**< DPO for Encaps/Insert for BSID */
69 dpo_id_t ip6_dpo; /**< DPO for Encaps/Insert IPv6 */
70 dpo_id_t ip4_dpo; /**< DPO for Encaps IPv6 */
71} ip6_sr_sl_t;
72
73/* SR policy types */
74#define SR_POLICY_TYPE_DEFAULT 0
75#define SR_POLICY_TYPE_SPRAY 1
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070076/**
Pablo Camarillofb380952016-12-07 18:34:18 +010077 * @brief SR Policy
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070078 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070079typedef struct
80{
Pablo Camarillofb380952016-12-07 18:34:18 +010081 u32 *segments_lists; /**< SID lists indexes (vector) */
Ed Warnickecb9cada2015-12-08 15:45:58 -070082
Pablo Camarillofb380952016-12-07 18:34:18 +010083 ip6_address_t bsid; /**< BindingSID (key) */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070084
Pablo Camarillofb380952016-12-07 18:34:18 +010085 u8 type; /**< Type (default is 0) */
Pablo Camarillofb380952016-12-07 18:34:18 +010086 /* SR Policy specific DPO */
87 /* IF Type = DEFAULT Then Load Balancer DPO among SID lists */
88 /* IF Type = SPRAY then Spray DPO with all SID lists */
89 dpo_id_t bsid_dpo; /**< SR Policy specific DPO - BSID */
90 dpo_id_t ip4_dpo; /**< SR Policy specific DPO - IPv6 */
91 dpo_id_t ip6_dpo; /**< SR Policy specific DPO - IPv4 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070092
Pablo Camarillofb380952016-12-07 18:34:18 +010093 u32 fib_table; /**< FIB table */
Ed Warnickecb9cada2015-12-08 15:45:58 -070094
Pablo Camarillofb380952016-12-07 18:34:18 +010095 u8 is_encap; /**< Mode (0 is SRH insert, 1 Encaps) */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070096} ip6_sr_policy_t;
97
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070098/**
Pablo Camarillofb380952016-12-07 18:34:18 +010099 * @brief SR LocalSID
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700100 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700101typedef struct
102{
Pablo Camarillofb380952016-12-07 18:34:18 +0100103 ip6_address_t localsid; /**< LocalSID IPv6 address */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700104
Pablo Camarillofb380952016-12-07 18:34:18 +0100105 char end_psp; /**< Combined with End.PSP? */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700106
Pablo Camarillofb380952016-12-07 18:34:18 +0100107 u16 behavior; /**< Behavior associated to this localsid */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700108
Pablo Camarillofb380952016-12-07 18:34:18 +0100109 union
110 {
111 u32 sw_if_index; /**< xconnect only */
112 u32 vrf_index; /**< vrf only */
113 };
114
115 u32 fib_table; /**< FIB table where localsid is registered */
116
117 u32 vlan_index; /**< VLAN tag (not an index) */
118
119 ip46_address_t next_hop; /**< Next_hop for xconnect usage only */
120
121 u32 nh_adj; /**< Next_adj for xconnect usage only */
122
123 void *plugin_mem; /**< Memory to be used by the plugin callback functions */
124} ip6_sr_localsid_t;
125
126typedef int (sr_plugin_callback_t) (ip6_sr_localsid_t * localsid);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700127
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700128/**
Pablo Camarillofb380952016-12-07 18:34:18 +0100129 * @brief SR LocalSID behavior registration
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700130 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700131typedef struct
132{
Pablo Camarillofb380952016-12-07 18:34:18 +0100133 u16 sr_localsid_function_number; /**< SR LocalSID plugin function (>SR_BEHAVIOR_LAST) */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700134
Pablo Camarillofb380952016-12-07 18:34:18 +0100135 u8 *function_name; /**< Function name. (key). */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700136
Pablo Camarillofb380952016-12-07 18:34:18 +0100137 u8 *keyword_str; /**< Behavior keyword (i.e. End.X) */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700138
Pablo Camarillofb380952016-12-07 18:34:18 +0100139 u8 *def_str; /**< Behavior definition (i.e. Endpoint with cross-connect) */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700140
Pablo Camarillofb380952016-12-07 18:34:18 +0100141 u8 *params_str; /**< Behavior parameters (i.e. <oif> <IP46next_hop>) */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700142
Pablo Camarillofb380952016-12-07 18:34:18 +0100143 dpo_type_t dpo; /**< DPO type registration */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700144
Pablo Camarillofb380952016-12-07 18:34:18 +0100145 format_function_t *ls_format; /**< LocalSID format function */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700146
Pablo Camarillofb380952016-12-07 18:34:18 +0100147 unformat_function_t *ls_unformat; /**< LocalSID unformat function */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700148
Pablo Camarillofb380952016-12-07 18:34:18 +0100149 sr_plugin_callback_t *creation; /**< Function within plugin that will be called after localsid creation*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700150
Pablo Camarillofb380952016-12-07 18:34:18 +0100151 sr_plugin_callback_t *removal; /**< Function within plugin that will be called before localsid removal */
152} sr_localsid_fn_registration_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700153
Pablo Camarillofb380952016-12-07 18:34:18 +0100154/**
155 * @brief Steering db key
156 *
157 * L3 is IPv4/IPv6 + mask
158 * L2 is sf_if_index + vlan
159 */
160typedef struct
161{
162 union
163 {
164 struct
165 {
166 ip46_address_t prefix; /**< IP address of the prefix */
167 u32 mask_width; /**< Mask width of the prefix */
168 u32 fib_table; /**< VRF of the prefix */
169 } l3;
170 struct
171 {
172 u32 sw_if_index; /**< Incoming software interface */
173 } l2;
174 };
175 u8 traffic_type; /**< Traffic type (IPv4, IPv6, L2) */
176} sr_steering_key_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700177
Pablo Camarillofb380952016-12-07 18:34:18 +0100178typedef struct
179{
180 sr_steering_key_t classify; /**< Traffic classification */
181 u32 sr_policy; /**< SR Policy index */
182} ip6_sr_steering_policy_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700183
Pablo Camarillofb380952016-12-07 18:34:18 +0100184/**
185 * @brief Segment Routing main datastructure
186 */
187typedef struct
188{
189 /* ip6-lookup next index for imposition FIB entries */
190 u32 ip6_lookup_sr_next_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700191
Pablo Camarillofb380952016-12-07 18:34:18 +0100192 /* ip6-replicate next index for multicast tunnel */
193 u32 ip6_lookup_sr_spray_index;
194
195 /* IP4-lookup -> SR rewrite next index */
196 u32 ip4_lookup_sr_policy_rewrite_encaps_index;
197 u32 ip4_lookup_sr_policy_rewrite_insert_index;
198
199 /* IP6-lookup -> SR rewrite next index */
200 u32 ip6_lookup_sr_policy_rewrite_encaps_index;
201 u32 ip6_lookup_sr_policy_rewrite_insert_index;
202
203 /* L2-input -> SR rewrite next index */
204 u32 l2_sr_policy_rewrite_index;
205
206 /* IP6-lookup -> SR LocalSID (SR End processing) index */
207 u32 ip6_lookup_sr_localsid_index;
208
209 /* SR SID lists */
210 ip6_sr_sl_t *sid_lists;
211
212 /* SR policies */
213 ip6_sr_policy_t *sr_policies;
214
215 /* Find an SR policy by its BindingSID */
216 ip6_address_t *sr_policy_index_by_key;
217
218 /* Pool of SR localsid instances */
219 ip6_sr_localsid_t *localsids;
220
221 /* Find a SR localsid instance based on its functionID */
222 ip6_address_t *localsids_index_by_key;
223
224 /* Pool of SR steer policies instances */
225 ip6_sr_steering_policy_t *steer_policies;
226
227 /* Find a steer policy based on its classifier */
228 sr_steering_key_t *steer_policies_index_by_key;
229
230 /* L2 steering ifaces - sr_policies */
231 u32 *sw_iface_sr_policies;
232
233 /* Spray DPO */
234 dpo_type_t sr_pr_spray_dpo_type;
235
236 /* Plugin functions */
237 sr_localsid_fn_registration_t *plugin_functions;
238
239 /* Find plugin function by name */
240 uword *plugin_functions_by_key;
241
242 /* Counters */
243 vlib_combined_counter_main_t sr_ls_valid_counters;
244 vlib_combined_counter_main_t sr_ls_invalid_counters;
245
246 /* SR Policies FIBs */
247 u32 fib_table_ip6;
248 u32 fib_table_ip4;
249
250 /* convenience */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700251 vlib_main_t *vlib_main;
252 vnet_main_t *vnet_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700253} ip6_sr_main_t;
254
255ip6_sr_main_t sr_main;
256
Pablo Camarillofb380952016-12-07 18:34:18 +0100257extern vlib_node_registration_t sr_policy_rewrite_encaps_node;
258extern vlib_node_registration_t sr_policy_rewrite_insert_node;
259extern vlib_node_registration_t sr_localsid_node;
260extern vlib_node_registration_t sr_localsid_d_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700261
Pablo Camarillofb380952016-12-07 18:34:18 +0100262void sr_dpo_lock (dpo_id_t * dpo);
263void sr_dpo_unlock (dpo_id_t * dpo);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700264
Pablo Camarillofb380952016-12-07 18:34:18 +0100265int sr_localsid_register_function (vlib_main_t * vm, u8 * fn_name,
266 u8 * keyword_str, u8 * def_str,
267 u8 * params_str, dpo_type_t * dpo,
268 format_function_t * ls_format,
269 unformat_function_t * ls_unformat,
270 sr_plugin_callback_t * creation_fn,
271 sr_plugin_callback_t * removal_fn);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700272
Pablo Camarillofb380952016-12-07 18:34:18 +0100273int
274sr_policy_add (ip6_address_t * bsid, ip6_address_t * segments,
275 u32 weight, u8 behavior, u32 fib_table, u8 is_encap);
276int
277sr_policy_mod (ip6_address_t * bsid, u32 index, u32 fib_table,
278 u8 operation, ip6_address_t * segments, u32 sl_index,
279 u32 weight);
280int sr_policy_del (ip6_address_t * bsid, u32 index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700281
Pablo Camarillofb380952016-12-07 18:34:18 +0100282int sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
283 char end_psp, u8 behavior, u32 sw_if_index,
284 u32 vlan_index, u32 fib_table, ip46_address_t * nh_addr,
285 void *ls_plugin_mem);
286
287int
288sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
289 u32 table_id, ip46_address_t * prefix, u32 mask_width,
290 u32 sw_if_index, u8 traffic_type);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700291
Shwetha Bhandari78372a92017-01-18 12:43:54 +0530292/**
293 * @brief SR rewrite string computation for SRH insertion (inline)
294 *
295 * @param sl is a vector of IPv6 addresses composing the Segment List
296 *
297 * @return precomputed rewrite string for SRH insertion
298 */
299static inline u8 *
shwethabe146f132017-03-09 16:58:26 +0000300ip6_sr_compute_rewrite_string_insert (ip6_address_t * sl)
Shwetha Bhandari78372a92017-01-18 12:43:54 +0530301{
302 ip6_sr_header_t *srh;
303 ip6_address_t *addrp, *this_address;
304 u32 header_length = 0;
305 u8 *rs = NULL;
306
307 header_length = 0;
308 header_length += sizeof (ip6_sr_header_t);
309 header_length += (vec_len (sl) + 1) * sizeof (ip6_address_t);
310
311 vec_validate (rs, header_length - 1);
312
313 srh = (ip6_sr_header_t *) rs;
314 srh->type = ROUTING_HEADER_TYPE_SR;
315 srh->segments_left = vec_len (sl);
316 srh->first_segment = vec_len (sl);
317 srh->length = ((sizeof (ip6_sr_header_t) +
318 ((vec_len (sl) + 1) * sizeof (ip6_address_t))) / 8) - 1;
319 srh->flags = 0x00;
320 srh->reserved = 0x0000;
321 addrp = srh->segments + vec_len (sl);
322 vec_foreach (this_address, sl)
323 {
324 clib_memcpy (addrp->as_u8, this_address->as_u8, sizeof (ip6_address_t));
325 addrp--;
326 }
327 return rs;
328}
329
330
Ed Warnickecb9cada2015-12-08 15:45:58 -0700331#endif /* included_vnet_sr_h */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700332
333/*
334 * fd.io coding-style-patch-verification: ON
335 *
336 * Local Variables:
337 * eval: (c-set-style "gnu")
338 * End:
339 */