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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @brief Segment Routing data structures definitions
22 #ifndef included_vnet_srv6_h
23 #define included_vnet_srv6_h
25 #include <vnet/vnet.h>
26 #include <vnet/srv6/sr_packet.h>
27 #include <vnet/ip/ip6_packet.h>
28 #include <vnet/ethernet/ethernet.h>
33 #define IPv6_DEFAULT_HEADER_LENGTH 40
34 #define IPv6_DEFAULT_HOP_LIMIT 64
35 #define IPv6_DEFAULT_MAX_MASK_WIDTH 128
37 #define SR_BEHAVIOR_END 1
38 #define SR_BEHAVIOR_X 2
39 #define SR_BEHAVIOR_T 3
40 #define SR_BEHAVIOR_D_FIRST 4 /* Unused. Separator in between regular and D */
41 #define SR_BEHAVIOR_DX2 5
42 #define SR_BEHAVIOR_DX6 6
43 #define SR_BEHAVIOR_DX4 7
44 #define SR_BEHAVIOR_DT6 8
45 #define SR_BEHAVIOR_DT4 9
46 #define SR_BEHAVIOR_END_UN_PERF 10
47 #define SR_BEHAVIOR_END_UN 11
48 #define SR_BEHAVIOR_LAST 12 /* Must always be the last one */
51 #define SR_STEER_IPV4 4
52 #define SR_STEER_IPV6 6
54 #define SR_FUNCTION_SIZE 4
55 #define SR_ARGUMENT_SIZE 4
57 #define SR_SEGMENT_LIST_WEIGHT_DEFAULT 1
63 } __attribute__ ((packed)) ip6srv_combo_header_t;
66 * @brief SR Segment List (SID list)
70 ip6_address_t *segments; /**< SIDs (key) */
72 u32 weight; /**< SID list weight (wECMP / UCMP) */
74 u8 *rewrite; /**< Precomputed rewrite header */
75 u8 *rewrite_bsid; /**< Precomputed rewrite header for bindingSID */
78 u32 egress_fib_table; /**< Egress FIB table for encap packet */
80 dpo_id_t bsid_dpo; /**< DPO for Encaps/Insert for BSID */
81 dpo_id_t ip6_dpo; /**< DPO for Encaps/Insert IPv6 */
82 dpo_id_t ip4_dpo; /**< DPO for Encaps IPv6 */
89 #define SR_POLICY_TYPE_DEFAULT 0
90 #define SR_POLICY_TYPE_SPRAY 1
91 #define SR_POLICY_TYPE_TEF 2
97 u32 *segments_lists; /**< SID lists indexes (vector) */
99 ip6_address_t bsid; /**< BindingSID (key) */
101 u8 type; /**< Type (default is 0) */
102 /* SR Policy specific DPO */
103 /* IF Type = DEFAULT Then Load-Balancer DPO among SID lists */
104 /* IF Type = SPRAY then Spray DPO with all SID lists */
105 dpo_id_t bsid_dpo; /**< SR Policy specific DPO - BSID */
106 dpo_id_t ip4_dpo; /**< SR Policy specific DPO - IPv6 */
107 dpo_id_t ip6_dpo; /**< SR Policy specific DPO - IPv4 */
109 u32 fib_table; /**< FIB table */
111 u8 is_encap; /**< Mode (0 is SRH insert, 1 Encaps) */
113 ip6_address_t encap_src;
119 typedef int (sr_p_plugin_callback_t) (ip6_sr_policy_t * sr);
126 ip6_address_t localsid; /**< LocalSID IPv6 address */
128 u16 localsid_prefix_len;
130 char end_psp; /**< Combined with End.PSP? */
132 u8 behavior; /**< Behavior associated to this localsid */
136 u32 sw_if_index; /**< xconnect only */
137 u32 vrf_index; /**< vrf only */
140 u32 fib_table; /**< FIB table where localsid is registered */
142 u32 vlan_index; /**< VLAN tag (not an index) */
144 ip46_address_t next_hop; /**< Next_hop for xconnect usage only */
146 u32 nh_adj; /**< Next_adj for xconnect usage only */
148 ip6_address_t usid_block;
149 ip6_address_t usid_block_mask;
157 void *plugin_mem; /**< Memory to be used by the plugin callback functions */
160 typedef int (sr_plugin_callback_t) (ip6_sr_localsid_t * localsid);
163 * @brief SR LocalSID behavior registration
167 u16 sr_localsid_function_number; /**< SR LocalSID plugin function (>SR_BEHAVIOR_LAST) */
169 u8 *function_name; /**< Function name. (key). */
171 u8 *keyword_str; /**< Behavior keyword (i.e. End.X) */
173 u8 *def_str; /**< Behavior definition (i.e. Endpoint with cross-connect) */
175 u8 *params_str; /**< Behavior parameters (i.e. <oif> <IP46next_hop>) */
179 dpo_type_t dpo; /**< DPO type registration */
181 format_function_t *ls_format; /**< LocalSID format function */
183 unformat_function_t *ls_unformat; /**< LocalSID unformat function */
185 sr_plugin_callback_t *creation; /**< Function within plugin that will be called after localsid creation*/
187 sr_plugin_callback_t *removal; /**< Function within plugin that will be called before localsid removal */
188 } sr_localsid_fn_registration_t;
191 * @brief SR Policy behavior registration
195 u16 sr_policy_function_number; /**< SR Policy plugin function */
197 u8 *function_name; /**< Function name. (key). */
199 u8 *keyword_str; /**< Behavior keyword (i.e. End.X) */
201 u8 *def_str; /**< Behavior definition (i.e. Endpoint with cross-connect) */
203 u8 *params_str; /**< Behavior parameters (i.e. <oif> <IP46next_hop>) */
207 dpo_type_t dpo; /**< DPO type registration */
209 format_function_t *ls_format; /**< LocalSID format function */
211 unformat_function_t *ls_unformat; /**< LocalSID unformat function */
213 sr_p_plugin_callback_t *creation; /**< Function within plugin that will be called after localsid creation*/
215 sr_p_plugin_callback_t *removal; /**< Function within plugin that will be called before localsid removal */
216 } sr_policy_fn_registration_t;
219 * @brief Steering db key
221 * L3 is IPv4/IPv6 + mask
222 * L2 is sf_if_index + vlan
230 ip46_address_t prefix; /**< IP address of the prefix */
231 u32 mask_width; /**< Mask width of the prefix */
232 u32 fib_table; /**< VRF of the prefix */
236 u32 sw_if_index; /**< Incoming software interface */
239 u8 traffic_type; /**< Traffic type (IPv4, IPv6, L2) */
245 sr_steering_key_t classify; /**< Traffic classification */
246 u32 sr_policy; /**< SR Policy index */
247 } ip6_sr_steering_policy_t;
251 ip6_address_t address;
257 * @brief Segment Routing main datastructure
261 /* L2-input -> SR rewrite next index */
262 u32 l2_sr_policy_rewrite_index;
265 ip6_sr_sl_t *sid_lists;
268 ip6_sr_policy_t *sr_policies;
270 /* Hash table mapping BindingSID to SRv6 policy */
271 mhash_t sr_policies_index_hash;
273 /* Pool of SR localsid instances */
274 ip6_sr_localsid_t *localsids;
276 /* Hash table mapping LOC:FUNC to SR LocalSID instance */
277 mhash_t sr_localsids_index_hash;
279 /* Pool of SR steer policies instances */
280 ip6_sr_steering_policy_t *steer_policies;
282 /* Hash table mapping steering rules to SR steer instance */
283 mhash_t sr_steer_policies_hash;
285 /* L2 steering ifaces - sr_policies */
286 u32 *sw_iface_sr_policies;
289 dpo_type_t sr_pr_spray_dpo_type;
291 /* Plugin functions */
292 sr_localsid_fn_registration_t *plugin_functions;
294 /* Find plugin function by name */
295 uword *plugin_functions_by_key;
297 /* Plugin functions for Policy */
298 sr_policy_fn_registration_t *policy_plugin_functions;
300 /* Find plugin function by name */
301 uword *policy_plugin_functions_by_key;
304 vlib_combined_counter_main_t sr_ls_valid_counters;
305 vlib_combined_counter_main_t sr_ls_invalid_counters;
307 /* SR Policies FIBs */
312 vlib_main_t *vlib_main;
313 vnet_main_t *vnet_main;
317 extern ip6_sr_main_t sr_main;
319 extern vlib_node_registration_t sr_policy_rewrite_encaps_node;
320 extern vlib_node_registration_t sr_policy_rewrite_insert_node;
321 extern vlib_node_registration_t sr_localsid_node;
322 extern vlib_node_registration_t sr_localsid_d_node;
324 extern void sr_dpo_lock (dpo_id_t * dpo);
325 extern void sr_dpo_unlock (dpo_id_t * dpo);
328 sr_localsid_register_function (vlib_main_t * vm, u8 * fn_name,
329 u8 * keyword_str, u8 * def_str,
330 u8 * params_str, u8 prefix_length,
332 format_function_t * ls_format,
333 unformat_function_t * ls_unformat,
334 sr_plugin_callback_t * creation_fn,
335 sr_plugin_callback_t * removal_fn);
338 sr_policy_register_function (vlib_main_t * vm, u8 * fn_name,
339 u8 * keyword_str, u8 * def_str,
340 u8 * params_str, u8 prefix_length,
342 format_function_t * ls_format,
343 unformat_function_t * ls_unformat,
344 sr_p_plugin_callback_t * creation_fn,
345 sr_p_plugin_callback_t * removal_fn);
347 extern int sr_policy_add (ip6_address_t *bsid, ip6_address_t *segments,
348 ip6_address_t *encap_src, u32 weight, u8 type,
349 u32 fib_table, u8 is_encap, u16 plugin,
351 extern int sr_policy_mod (ip6_address_t *bsid, u32 index, u32 fib_table,
352 u8 operation, ip6_address_t *segments,
353 ip6_address_t *encap_src, u32 sl_index, u32 weight);
354 extern int sr_policy_del (ip6_address_t * bsid, u32 index);
357 sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
358 u16 localsid_prefix_len, char end_psp, u8 behavior,
359 u32 sw_if_index, u32 vlan_index, u32 fib_table,
360 ip46_address_t * nh_addr, int usid_len, void *ls_plugin_mem);
363 sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
364 u32 table_id, ip46_address_t * prefix, u32 mask_width,
365 u32 sw_if_index, u8 traffic_type);
367 extern void sr_set_source (ip6_address_t * address);
368 extern ip6_address_t *sr_get_encaps_source ();
370 extern void sr_set_hop_limit (u8 hop_limit);
371 extern u8 sr_get_hop_limit (void);
374 * @brief SR rewrite string computation for SRH insertion (inline)
376 * @param sl is a vector of IPv6 addresses composing the Segment List
378 * @return precomputed rewrite string for SRH insertion
381 ip6_sr_compute_rewrite_string_insert (ip6_address_t * sl)
383 ip6_sr_header_t *srh;
384 ip6_address_t *addrp, *this_address;
385 u32 header_length = 0;
389 header_length += sizeof (ip6_sr_header_t);
390 header_length += (vec_len (sl) + 1) * sizeof (ip6_address_t);
392 vec_validate (rs, header_length - 1);
394 srh = (ip6_sr_header_t *) rs;
395 srh->type = ROUTING_HEADER_TYPE_SR;
396 srh->segments_left = vec_len (sl);
397 srh->last_entry = vec_len (sl);
398 srh->length = ((sizeof (ip6_sr_header_t) +
399 ((vec_len (sl) + 1) * sizeof (ip6_address_t))) / 8) - 1;
402 addrp = srh->segments + vec_len (sl);
403 vec_foreach (this_address, sl)
405 clib_memcpy_fast (addrp->as_u8, this_address->as_u8,
406 sizeof (ip6_address_t));
412 #endif /* included_vnet_sr_h */
415 * fd.io coding-style-patch-verification: ON
418 * eval: (c-set-style "gnu")