FD.io VPP  v18.07-34-g55fbdb9
Vector Packet Processing
sr.h
Go to the documentation of this file.
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 data structures definitions
19  *
20  */
21 
22 #ifndef included_vnet_srv6_h
23 #define included_vnet_srv6_h
24 
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>
29 
30 #include <stdlib.h>
31 #include <string.h>
32 
33 #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_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_LAST 10 /* Must always be the last one */
47 
48 #define SR_STEER_L2 2
49 #define SR_STEER_IPV4 4
50 #define SR_STEER_IPV6 6
51 
52 #define SR_FUNCTION_SIZE 4
53 #define SR_ARGUMENT_SIZE 4
54 
55 #define SR_SEGMENT_LIST_WEIGHT_DEFAULT 1
56 
57 /**
58  * @brief SR Segment List (SID list)
59  */
60 typedef struct
61 {
62  ip6_address_t *segments; /**< SIDs (key) */
63 
64  u32 weight; /**< SID list weight (wECMP / UCMP) */
65 
66  u8 *rewrite; /**< Precomputed rewrite header */
67  u8 *rewrite_bsid; /**< Precomputed rewrite header for bindingSID */
68 
69  dpo_id_t bsid_dpo; /**< DPO for Encaps/Insert for BSID */
70  dpo_id_t ip6_dpo; /**< DPO for Encaps/Insert IPv6 */
71  dpo_id_t ip4_dpo; /**< DPO for Encaps IPv6 */
72 } ip6_sr_sl_t;
73 
74 /* SR policy types */
75 #define SR_POLICY_TYPE_DEFAULT 0
76 #define SR_POLICY_TYPE_SPRAY 1
77 /**
78  * @brief SR Policy
79  */
80 typedef struct
81 {
82  u32 *segments_lists; /**< SID lists indexes (vector) */
83 
84  ip6_address_t bsid; /**< BindingSID (key) */
85 
86  u8 type; /**< Type (default is 0) */
87  /* SR Policy specific DPO */
88  /* IF Type = DEFAULT Then Load Balancer DPO among SID lists */
89  /* IF Type = SPRAY then Spray DPO with all SID lists */
90  dpo_id_t bsid_dpo; /**< SR Policy specific DPO - BSID */
91  dpo_id_t ip4_dpo; /**< SR Policy specific DPO - IPv6 */
92  dpo_id_t ip6_dpo; /**< SR Policy specific DPO - IPv4 */
93 
94  u32 fib_table; /**< FIB table */
95 
96  u8 is_encap; /**< Mode (0 is SRH insert, 1 Encaps) */
98 
99 /**
100  * @brief SR LocalSID
101  */
102 typedef struct
103 {
104  ip6_address_t localsid; /**< LocalSID IPv6 address */
105 
106  char end_psp; /**< Combined with End.PSP? */
107 
108  u16 behavior; /**< Behavior associated to this localsid */
109 
110  union
111  {
112  u32 sw_if_index; /**< xconnect only */
113  u32 vrf_index; /**< vrf only */
114  };
115 
116  u32 fib_table; /**< FIB table where localsid is registered */
117 
118  u32 vlan_index; /**< VLAN tag (not an index) */
119 
120  ip46_address_t next_hop; /**< Next_hop for xconnect usage only */
121 
122  u32 nh_adj; /**< Next_adj for xconnect usage only */
123 
124  void *plugin_mem; /**< Memory to be used by the plugin callback functions */
126 
127 typedef int (sr_plugin_callback_t) (ip6_sr_localsid_t * localsid);
128 
129 /**
130  * @brief SR LocalSID behavior registration
131  */
132 typedef struct
133 {
134  u16 sr_localsid_function_number; /**< SR LocalSID plugin function (>SR_BEHAVIOR_LAST) */
135 
136  u8 *function_name; /**< Function name. (key). */
137 
138  u8 *keyword_str; /**< Behavior keyword (i.e. End.X) */
139 
140  u8 *def_str; /**< Behavior definition (i.e. Endpoint with cross-connect) */
141 
142  u8 *params_str; /**< Behavior parameters (i.e. <oif> <IP46next_hop>) */
143 
144  dpo_type_t dpo; /**< DPO type registration */
145 
146  format_function_t *ls_format; /**< LocalSID format function */
147 
148  unformat_function_t *ls_unformat; /**< LocalSID unformat function */
149 
150  sr_plugin_callback_t *creation; /**< Function within plugin that will be called after localsid creation*/
151 
152  sr_plugin_callback_t *removal; /**< Function within plugin that will be called before localsid removal */
154 
155 /**
156  * @brief Steering db key
157  *
158  * L3 is IPv4/IPv6 + mask
159  * L2 is sf_if_index + vlan
160  */
161 typedef struct
162 {
163  union
164  {
165  struct
166  {
167  ip46_address_t prefix; /**< IP address of the prefix */
168  u32 mask_width; /**< Mask width of the prefix */
169  u32 fib_table; /**< VRF of the prefix */
170  } l3;
171  struct
172  {
173  u32 sw_if_index; /**< Incoming software interface */
174  } l2;
175  };
176  u8 traffic_type; /**< Traffic type (IPv4, IPv6, L2) */
179 
180 typedef struct
181 {
182  sr_steering_key_t classify; /**< Traffic classification */
183  u32 sr_policy; /**< SR Policy index */
185 
186 /**
187  * @brief Segment Routing main datastructure
188  */
189 typedef struct
190 {
191  /* L2-input -> SR rewrite next index */
193 
194  /* SR SID lists */
196 
197  /* SRv6 policies */
199 
200  /* Hash table mapping BindingSID to SRv6 policy */
202 
203  /* Pool of SR localsid instances */
205 
206  /* Hash table mapping LOC:FUNC to SR LocalSID instance */
208 
209  /* Pool of SR steer policies instances */
211 
212  /* Hash table mapping steering rules to SR steer instance */
214 
215  /* L2 steering ifaces - sr_policies */
217 
218  /* Spray DPO */
220 
221  /* Plugin functions */
223 
224  /* Find plugin function by name */
226 
227  /* Counters */
230 
231  /* SR Policies FIBs */
234 
235  /* convenience */
238 } ip6_sr_main_t;
239 
240 extern ip6_sr_main_t sr_main;
241 
246 
247 extern void sr_dpo_lock (dpo_id_t * dpo);
248 extern void sr_dpo_unlock (dpo_id_t * dpo);
249 
250 extern int
252  u8 * keyword_str, u8 * def_str,
253  u8 * params_str, dpo_type_t * dpo,
254  format_function_t * ls_format,
255  unformat_function_t * ls_unformat,
256  sr_plugin_callback_t * creation_fn,
257  sr_plugin_callback_t * removal_fn);
258 
259 extern int
260 sr_policy_add (ip6_address_t * bsid, ip6_address_t * segments,
261  u32 weight, u8 behavior, u32 fib_table, u8 is_encap);
262 extern int
263 sr_policy_mod (ip6_address_t * bsid, u32 index, u32 fib_table,
264  u8 operation, ip6_address_t * segments, u32 sl_index,
265  u32 weight);
266 extern int sr_policy_del (ip6_address_t * bsid, u32 index);
267 
268 extern int
269 sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
270  char end_psp, u8 behavior, u32 sw_if_index,
271  u32 vlan_index, u32 fib_table, ip46_address_t * nh_addr,
272  void *ls_plugin_mem);
273 
274 extern int
275 sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
276  u32 table_id, ip46_address_t * prefix, u32 mask_width,
277  u32 sw_if_index, u8 traffic_type);
278 
279 extern void sr_set_source (ip6_address_t * address);
280 
281 /**
282  * @brief SR rewrite string computation for SRH insertion (inline)
283  *
284  * @param sl is a vector of IPv6 addresses composing the Segment List
285  *
286  * @return precomputed rewrite string for SRH insertion
287  */
288 static inline u8 *
290 {
291  ip6_sr_header_t *srh;
292  ip6_address_t *addrp, *this_address;
293  u32 header_length = 0;
294  u8 *rs = NULL;
295 
296  header_length = 0;
297  header_length += sizeof (ip6_sr_header_t);
298  header_length += (vec_len (sl) + 1) * sizeof (ip6_address_t);
299 
300  vec_validate (rs, header_length - 1);
301 
302  srh = (ip6_sr_header_t *) rs;
304  srh->segments_left = vec_len (sl);
305  srh->first_segment = vec_len (sl);
306  srh->length = ((sizeof (ip6_sr_header_t) +
307  ((vec_len (sl) + 1) * sizeof (ip6_address_t))) / 8) - 1;
308  srh->flags = 0x00;
309  srh->reserved = 0x0000;
310  addrp = srh->segments + vec_len (sl);
311  vec_foreach (this_address, sl)
312  {
313  clib_memcpy (addrp->as_u8, this_address->as_u8, sizeof (ip6_address_t));
314  addrp--;
315  }
316  return rs;
317 }
318 
319 
320 #endif /* included_vnet_sr_h */
321 
322 /*
323  * fd.io coding-style-patch-verification: ON
324  *
325  * Local Variables:
326  * eval: (c-set-style "gnu")
327  * End:
328  */
u8 * function_name
Function name.
Definition: sr.h:136
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:437
u32 sw_if_index
Incoming software interface.
Definition: sr.h:173
u8 type
Type (default is 0)
Definition: sr.h:86
Definition: mhash.h:46
u32 vlan_index
VLAN tag (not an index)
Definition: sr.h:118
uword( unformat_function_t)(unformat_input_t *input, va_list *args)
Definition: format.h:232
vlib_node_registration_t sr_policy_rewrite_encaps_node
(constructor) VLIB_REGISTER_NODE (sr_policy_rewrite_encaps_node)
typedef address
Definition: ip_types.api:35
u32 nh_adj
Next_adj for xconnect usage only.
Definition: sr.h:122
void sr_set_source(ip6_address_t *address)
int sr_cli_localsid(char is_del, ip6_address_t *localsid_addr, char end_psp, u8 behavior, u32 sw_if_index, u32 vlan_index, u32 fib_table, ip46_address_t *nh_addr, void *ls_plugin_mem)
SR localsid add/del.
Definition: sr_localsid.c:66
u32 mask_width
Mask width of the prefix.
Definition: sr.h:168
SR LocalSID.
Definition: sr.h:102
u32 fib_table
FIB table.
Definition: sr.h:94
u8 as_u8[16]
Definition: ip6_packet.h:48
int sr_steering_policy(int is_del, ip6_address_t *bsid, u32 sr_policy_index, u32 table_id, ip46_address_t *prefix, u32 mask_width, u32 sw_if_index, u8 traffic_type)
Steer traffic L2 and L3 traffic through a given SR policy.
Definition: sr_steering.c:60
unsigned char params_str[32]
#define NULL
Definition: clib.h:55
format_function_t * ls_format
LocalSID format function.
Definition: sr.h:146
dpo_id_t ip4_dpo
DPO for Encaps IPv6.
Definition: sr.h:71
ip6_address_t * segments
SIDs (key)
Definition: sr.h:62
u32 l2_sr_policy_rewrite_index
Definition: sr.h:192
u16 behavior
Behavior associated to this localsid.
Definition: sr.h:108
#define ROUTING_HEADER_TYPE_SR
Definition: sr_packet.h:116
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
unsigned char keyword_str[32]
vlib_combined_counter_main_t sr_ls_invalid_counters
Definition: sr.h:229
vlib_combined_counter_main_t sr_ls_valid_counters
Definition: sr.h:228
ip6_sr_steering_policy_t * steer_policies
Definition: sr.h:210
unsigned char u8
Definition: types.h:56
u8 * rewrite_bsid
Precomputed rewrite header for bindingSID.
Definition: sr.h:67
dpo_id_t ip6_dpo
DPO for Encaps/Insert IPv6.
Definition: sr.h:70
u32 * sw_iface_sr_policies
Definition: sr.h:216
enum dpo_type_t_ dpo_type_t
Common types of data-path objects New types can be dynamically added using dpo_register_new_type() ...
SR Segment List (SID list)
Definition: sr.h:60
unsigned int u32
Definition: types.h:88
u32 padding
Definition: vhost_user.h:110
int( sr_plugin_callback_t)(ip6_sr_localsid_t *localsid)
Definition: sr.h:127
vlib_node_registration_t sr_localsid_node
(constructor) VLIB_REGISTER_NODE (sr_localsid_node)
Definition: sr_localsid.c:1469
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:168
vlib_main_t * vlib_main
Definition: sr.h:236
unsigned short u16
Definition: types.h:57
SR LocalSID behavior registration.
Definition: sr.h:132
unsigned char def_str[64]
char end_psp
Combined with End.PSP?
Definition: sr.h:106
sr_steering_key_t classify
Traffic classification.
Definition: sr.h:182
u8 is_encap
Mode (0 is SRH insert, 1 Encaps)
Definition: sr.h:96
u32 sr_policy
SR Policy index.
Definition: sr.h:183
u32 weight
SID list weight (wECMP / UCMP)
Definition: sr.h:64
ip6_sr_localsid_t * localsids
Definition: sr.h:204
vnet_main_t * vnet_main
Definition: sr.h:237
vlib_main_t * vm
Definition: buffer.c:294
uint32_t mask_width(const boost::asio::ip::address &addr)
Get the prefix mask length of a host route from the boost address.
Definition: prefix.cpp:242
int sr_policy_del(ip6_address_t *bsid, u32 index)
Delete a SR policy.
int sr_policy_add(ip6_address_t *bsid, ip6_address_t *segments, u32 weight, u8 behavior, u32 fib_table, u8 is_encap)
Create a new SR policy.
u32 * segments_lists
SID lists indexes (vector)
Definition: sr.h:82
#define clib_memcpy(a, b, c)
Definition: string.h:75
unformat_function_t * ls_unformat
LocalSID unformat function.
Definition: sr.h:148
void sr_dpo_lock(dpo_id_t *dpo)
no-op lock function.
Definition: sr.c:38
dpo_id_t bsid_dpo
DPO for Encaps/Insert for BSID.
Definition: sr.h:69
dpo_type_t sr_pr_spray_dpo_type
Definition: sr.h:219
Steering db key.
Definition: sr.h:161
dpo_type_t dpo
DPO type registration.
Definition: sr.h:144
u8 * def_str
Behavior definition (i.e.
Definition: sr.h:140
void * plugin_mem
Memory to be used by the plugin callback functions.
Definition: sr.h:124
void sr_dpo_unlock(dpo_id_t *dpo)
no-op unlock function.
Definition: sr.c:47
u32 vrf_index
vrf only
Definition: sr.h:113
vlib_node_registration_t sr_localsid_d_node
(constructor) VLIB_REGISTER_NODE (sr_localsid_d_node)
Definition: sr_localsid.c:1164
u32 fib_table
FIB table where localsid is registered.
Definition: sr.h:116
mhash_t sr_policies_index_hash
Definition: sr.h:201
u16 sr_localsid_function_number
SR LocalSID plugin function (>SR_BEHAVIOR_LAST)
Definition: sr.h:134
struct _vlib_node_registration vlib_node_registration_t
vlib_node_registration_t sr_policy_rewrite_insert_node
(constructor) VLIB_REGISTER_NODE (sr_policy_rewrite_insert_node)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
ip6_sr_policy_t * sr_policies
Definition: sr.h:198
mhash_t sr_steer_policies_hash
Definition: sr.h:213
ip6_address_t segments[0]
Definition: sr_packet.h:148
SR Policy.
Definition: sr.h:80
sr_plugin_callback_t * creation
Function within plugin that will be called after localsid creation.
Definition: sr.h:150
u8 * rewrite
Precomputed rewrite header.
Definition: sr.h:66
u64 uword
Definition: types.h:112
dpo_id_t bsid_dpo
SR Policy specific DPO - BSID.
Definition: sr.h:90
A collection of combined counters.
Definition: counter.h:181
typedef prefix
Definition: ip_types.api:40
ip6_sr_sl_t * sid_lists
Definition: sr.h:195
Segment Routing main datastructure.
Definition: sr.h:189
dpo_id_t ip6_dpo
SR Policy specific DPO - IPv4.
Definition: sr.h:92
u32 fib_table
VRF of the prefix.
Definition: sr.h:169
int sr_localsid_register_function(vlib_main_t *vm, u8 *fn_name, u8 *keyword_str, u8 *def_str, u8 *params_str, dpo_type_t *dpo, format_function_t *ls_format, unformat_function_t *ls_unformat, sr_plugin_callback_t *creation_fn, sr_plugin_callback_t *removal_fn)
SR LocalSID plugin registry.
Definition: sr_localsid.c:1525
ip46_address_t prefix
IP address of the prefix.
Definition: sr.h:167
#define vec_foreach(var, vec)
Vector iterator.
u8 traffic_type
Traffic type (IPv4, IPv6, L2)
Definition: sr.h:176
u32 fib_table_ip4
Definition: sr.h:233
ip46_address_t next_hop
Next_hop for xconnect usage only.
Definition: sr.h:120
mhash_t sr_localsids_index_hash
Definition: sr.h:207
u8 * params_str
Behavior parameters (i.e.
Definition: sr.h:142
u32 sw_if_index
xconnect only
Definition: sr.h:112
sr_plugin_callback_t * removal
Function within plugin that will be called before localsid removal.
Definition: sr.h:152
dpo_id_t ip4_dpo
SR Policy specific DPO - IPv6.
Definition: sr.h:91
ip6_address_t localsid
LocalSID IPv6 address.
Definition: sr.h:104
u32 fib_table_ip6
Definition: sr.h:232
u8 * keyword_str
Behavior keyword (i.e.
Definition: sr.h:138
ip6_sr_main_t sr_main
Definition: sr.c:31
sr_localsid_fn_registration_t * plugin_functions
Definition: sr.h:222
int sr_policy_mod(ip6_address_t *bsid, u32 index, u32 fib_table, u8 operation, ip6_address_t *segments, u32 sl_index, u32 weight)
Modify an existing SR policy.
ip6_address_t bsid
BindingSID (key)
Definition: sr.h:84
uword * plugin_functions_by_key
Definition: sr.h:225
static u8 * ip6_sr_compute_rewrite_string_insert(ip6_address_t *sl)
SR rewrite string computation for SRH insertion (inline)
Definition: sr.h:289