]>
Commit | Line | Data |
---|---|---|
cf9b9f77 OD |
1 | /* |
2 | * This is an implementation of Segment Routing | |
6f751f14 OD |
3 | * as per RFC 8665 - OSPF Extensions for Segment Routing |
4 | * and RFC 8476 - Signaling Maximum SID Depth (MSD) Using OSPF | |
cf9b9f77 OD |
5 | * |
6 | * Module name: Segment Routing header definitions | |
7 | * | |
8 | * Author: Olivier Dugeon <olivier.dugeon@orange.com> | |
9 | * Author: Anselme Sawadogo <anselmesawadogo@gmail.com> | |
10 | * | |
6f751f14 | 11 | * Copyright (C) 2016 - 2020 Orange Labs http://www.orange.com |
cf9b9f77 | 12 | * |
7743f2f8 OD |
13 | * This program is free software; you can redistribute it and/or modify it |
14 | * under the terms of the GNU General Public License as published by the Free | |
15 | * Software Foundation; either version 2 of the License, or (at your option) | |
16 | * any later version. | |
cf9b9f77 | 17 | * |
7743f2f8 OD |
18 | * This program is distributed in the hope that it will be useful, but WITHOUT |
19 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
20 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
21 | * more details. | |
cf9b9f77 | 22 | * |
7743f2f8 OD |
23 | * You should have received a copy of the GNU General Public License along |
24 | * with this program; see the file COPYING; if not, write to the Free Software | |
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
cf9b9f77 OD |
26 | */ |
27 | ||
28 | #ifndef _FRR_OSPF_SR_H | |
29 | #define _FRR_OSPF_SR_H | |
30 | ||
cf9b9f77 OD |
31 | /* macros and constants for segment routing */ |
32 | #define SET_RANGE_SIZE_MASK 0xffffff00 | |
33 | #define GET_RANGE_SIZE_MASK 0x00ffffff | |
34 | #define SET_LABEL_MASK 0xffffff00 | |
35 | #define GET_LABEL_MASK 0x00ffffff | |
36 | #define SET_RANGE_SIZE(range_size) ((range_size << 8) & SET_RANGE_SIZE_MASK) | |
37 | #define GET_RANGE_SIZE(range_size) ((range_size >> 8) & GET_RANGE_SIZE_MASK) | |
38 | #define SET_LABEL(label) ((label << 8) & SET_LABEL_MASK) | |
39 | #define GET_LABEL(label) ((label >> 8) & GET_LABEL_MASK) | |
40 | ||
cf9b9f77 OD |
41 | #define OSPF_SR_DEFAULT_METRIC 1 |
42 | ||
6f751f14 | 43 | /* Segment Routing TLVs as per RFC 8665 */ |
cf9b9f77 OD |
44 | |
45 | /* Segment ID could be a Label (3 bytes) or an Index (4 bytes) */ | |
cf9b9f77 | 46 | #define SID_LABEL 3 |
d922605d | 47 | #define SID_LABEL_SIZE(U) (U - 1) |
cf9b9f77 | 48 | #define SID_INDEX 4 |
d922605d | 49 | #define SID_INDEX_SIZE(U) (U) |
cf9b9f77 | 50 | |
b37eb79c OD |
51 | /* Macro to log debug message */ |
52 | #define osr_debug(...) \ | |
53 | do { \ | |
54 | if (IS_DEBUG_OSPF_SR) \ | |
55 | zlog_debug(__VA_ARGS__); \ | |
56 | } while (0) | |
57 | ||
43e7abb5 OD |
58 | /* Macro to check if SR Prefix has no valid route */ |
59 | #define IS_NO_ROUTE(srp) ((srp->route == NULL) || (srp->route->paths == NULL) \ | |
60 | || list_isempty(srp->route->paths)) | |
61 | ||
cf9b9f77 OD |
62 | /* SID/Label Sub TLV - section 2.1 */ |
63 | #define SUBTLV_SID_LABEL 1 | |
64 | #define SUBTLV_SID_LABEL_SIZE 8 | |
65 | struct subtlv_sid_label { | |
66 | /* Length is 3 (20 rightmost bits MPLS label) or 4 (32 bits SID) */ | |
67 | struct tlv_header header; | |
93f0a26e | 68 | uint32_t value; |
cf9b9f77 OD |
69 | }; |
70 | ||
71 | /* | |
72 | * Following section defines Segment Routing TLV (tag, length, value) | |
73 | * structures, used in Router Information Opaque LSA. | |
74 | */ | |
75 | ||
76 | /* RI SR-Algorithm TLV - section 3.1 */ | |
77 | #define RI_SR_TLV_SR_ALGORITHM 8 | |
78 | struct ri_sr_tlv_sr_algorithm { | |
79 | struct tlv_header header; | |
80 | #define SR_ALGORITHM_SPF 0 | |
81 | #define SR_ALGORITHM_STRICT_SPF 1 | |
82 | #define SR_ALGORITHM_UNSET 255 | |
83 | #define ALGORITHM_COUNT 4 | |
84 | /* Only 4 algorithms supported in this code */ | |
93f0a26e | 85 | uint8_t value[ALGORITHM_COUNT]; |
cf9b9f77 OD |
86 | }; |
87 | ||
6f751f14 OD |
88 | /* RI SID/Label Range TLV used for SRGB & SRLB - section 3.2 & 3.3 */ |
89 | #define RI_SR_TLV_SRGB_LABEL_RANGE 9 | |
90 | #define RI_SR_TLV_SRLB_LABEL_RANGE 14 | |
cf9b9f77 OD |
91 | struct ri_sr_tlv_sid_label_range { |
92 | struct tlv_header header; | |
93 | /* Only 24 upper most bits are significant */ | |
94 | #define SID_RANGE_LABEL_LENGTH 3 | |
93f0a26e | 95 | uint32_t size; |
cf9b9f77 OD |
96 | /* A SID/Label sub-TLV will follow. */ |
97 | struct subtlv_sid_label lower; | |
98 | }; | |
99 | ||
6f751f14 | 100 | /* RI Node/MSD TLV as per RFC 8476 */ |
cf9b9f77 OD |
101 | #define RI_SR_TLV_NODE_MSD 12 |
102 | struct ri_sr_tlv_node_msd { | |
103 | struct tlv_header header; | |
93f0a26e OD |
104 | uint8_t subtype; /* always = 1 */ |
105 | uint8_t value; | |
106 | uint16_t padding; | |
cf9b9f77 OD |
107 | }; |
108 | ||
109 | /* | |
110 | * Following section defines Segment Routing TLV (tag, length, value) | |
111 | * structures, used in Extended Prefix/Link Opaque LSA. | |
112 | */ | |
113 | ||
114 | /* Adj-SID and LAN-Ajd-SID subtlvs' flags */ | |
115 | #define EXT_SUBTLV_LINK_ADJ_SID_BFLG 0x80 | |
116 | #define EXT_SUBTLV_LINK_ADJ_SID_VFLG 0x40 | |
117 | #define EXT_SUBTLV_LINK_ADJ_SID_LFLG 0x20 | |
118 | #define EXT_SUBTLV_LINK_ADJ_SID_SFLG 0x10 | |
119 | ||
120 | /* Prefix SID subtlv Flags */ | |
121 | #define EXT_SUBTLV_PREFIX_SID_NPFLG 0x40 | |
122 | #define EXT_SUBTLV_PREFIX_SID_MFLG 0x20 | |
123 | #define EXT_SUBTLV_PREFIX_SID_EFLG 0x10 | |
124 | #define EXT_SUBTLV_PREFIX_SID_VFLG 0x08 | |
125 | #define EXT_SUBTLV_PREFIX_SID_LFLG 0x04 | |
126 | ||
127 | /* SID/Label Binding subtlv Flags */ | |
128 | #define EXT_SUBTLV_SID_BINDING_MFLG 0x80 | |
129 | ||
130 | /* Extended Prefix Range TLV - section 4 */ | |
131 | #define EXT_TLV_PREF_RANGE 2 | |
132 | #define EXT_SUBTLV_PREFIX_RANGE_SIZE 12 | |
133 | struct ext_tlv_prefix_range { | |
134 | struct tlv_header header; | |
93f0a26e OD |
135 | uint8_t pref_length; |
136 | uint8_t af; | |
137 | uint16_t range_size; | |
138 | uint8_t flags; | |
139 | uint8_t reserved[3]; | |
cf9b9f77 OD |
140 | struct in_addr address; |
141 | }; | |
142 | ||
143 | /* Prefix SID Sub-TLV - section 5 */ | |
144 | #define EXT_SUBTLV_PREFIX_SID 2 | |
145 | #define EXT_SUBTLV_PREFIX_SID_SIZE 8 | |
146 | struct ext_subtlv_prefix_sid { | |
147 | struct tlv_header header; | |
93f0a26e OD |
148 | uint8_t flags; |
149 | uint8_t reserved; | |
150 | uint8_t mtid; | |
151 | uint8_t algorithm; | |
152 | uint32_t value; | |
cf9b9f77 OD |
153 | }; |
154 | ||
155 | /* Adj-SID Sub-TLV - section 6.1 */ | |
156 | #define EXT_SUBTLV_ADJ_SID 2 | |
157 | #define EXT_SUBTLV_ADJ_SID_SIZE 8 | |
158 | struct ext_subtlv_adj_sid { | |
159 | struct tlv_header header; | |
93f0a26e OD |
160 | uint8_t flags; |
161 | uint8_t reserved; | |
162 | uint8_t mtid; | |
163 | uint8_t weight; | |
164 | uint32_t value; | |
cf9b9f77 OD |
165 | }; |
166 | ||
167 | /* LAN Adj-SID Sub-TLV - section 6.2 */ | |
168 | #define EXT_SUBTLV_LAN_ADJ_SID 3 | |
169 | #define EXT_SUBTLV_LAN_ADJ_SID_SIZE 12 | |
170 | struct ext_subtlv_lan_adj_sid { | |
171 | struct tlv_header header; | |
93f0a26e OD |
172 | uint8_t flags; |
173 | uint8_t reserved; | |
174 | uint8_t mtid; | |
175 | uint8_t weight; | |
cf9b9f77 | 176 | struct in_addr neighbor_id; |
93f0a26e | 177 | uint32_t value; |
cf9b9f77 OD |
178 | }; |
179 | ||
180 | /* | |
181 | * Following section define structure used to manage Segment Routing | |
182 | * information and TLVs / SubTLVs | |
183 | */ | |
6f751f14 OD |
184 | /* Default min and size of SR Global Block label range */ |
185 | #define DEFAULT_SRGB_LABEL 16000 | |
186 | #define DEFAULT_SRGB_SIZE 8000 | |
187 | ||
188 | /* Default min and size of SR Local Block label range */ | |
189 | #define DEFAULT_SRLB_LABEL 15000 | |
190 | #define DEFAULT_SRLB_SIZE 1000 | |
cf9b9f77 | 191 | |
6f751f14 OD |
192 | /* Structure aggregating SR Range Block info retrieved from an lsa */ |
193 | struct sr_block { | |
93f0a26e OD |
194 | uint32_t range_size; |
195 | uint32_t lower_bound; | |
cf9b9f77 OD |
196 | }; |
197 | ||
6f751f14 OD |
198 | /* Segment Routing Global Block allocation */ |
199 | struct sr_global_block { | |
200 | bool reserved; | |
201 | uint32_t start; | |
202 | uint32_t size; | |
203 | }; | |
204 | ||
205 | /* Segment Routing Local Block allocation */ | |
206 | struct sr_local_block { | |
207 | bool reserved; | |
208 | uint32_t start; | |
209 | uint32_t end; | |
210 | uint32_t current; | |
211 | uint32_t max_block; | |
212 | uint64_t *used_mark; | |
213 | }; | |
214 | #define SRLB_BLOCK_SIZE 64 | |
215 | ||
cf9b9f77 | 216 | /* SID type to make difference between loopback interfaces and others */ |
b37eb79c | 217 | enum sid_type { PREF_SID, LOCAL_SID, ADJ_SID, LAN_ADJ_SID }; |
cf9b9f77 | 218 | |
d81b8e0e OD |
219 | /* Status of Segment Routing: Off (Disable), On (Enable), (Up) Started */ |
220 | enum sr_status { SR_OFF, SR_ON, SR_UP, SR_DOWN }; | |
221 | ||
cf9b9f77 OD |
222 | /* Structure aggregating all OSPF Segment Routing information for the node */ |
223 | struct ospf_sr_db { | |
d81b8e0e OD |
224 | /* Status of Segment Routing */ |
225 | enum sr_status status; | |
cf9b9f77 | 226 | |
cf9b9f77 | 227 | /* Flooding Scope: Area = 10 or AS = 11 */ |
93f0a26e | 228 | uint8_t scope; |
cf9b9f77 OD |
229 | |
230 | /* FRR SR node */ | |
231 | struct sr_node *self; | |
232 | ||
233 | /* List of neighbour SR nodes */ | |
234 | struct hash *neighbors; | |
235 | ||
cf9b9f77 OD |
236 | /* Local SR info announced in Router Info LSA */ |
237 | ||
238 | /* Algorithms supported by the node */ | |
93f0a26e | 239 | uint8_t algo[ALGORITHM_COUNT]; |
cf9b9f77 OD |
240 | /* |
241 | * Segment Routing Global Block i.e. label range | |
242 | * Only one range supported in this code | |
243 | */ | |
6f751f14 | 244 | struct sr_global_block srgb; |
d81b8e0e | 245 | |
6f751f14 OD |
246 | /* Segment Routing Local Block */ |
247 | struct sr_local_block srlb; | |
d81b8e0e | 248 | |
cf9b9f77 | 249 | /* Maximum SID Depth supported by the node */ |
93f0a26e | 250 | uint8_t msd; |
6f751f14 OD |
251 | |
252 | /* Thread timer to start Label Manager */ | |
253 | struct thread *t_start_lm; | |
cf9b9f77 OD |
254 | }; |
255 | ||
256 | /* Structure aggregating all received SR info from LSAs by node */ | |
257 | struct sr_node { | |
258 | struct in_addr adv_router; /* used to identify sender of LSA */ | |
259 | /* 24-bit Opaque-ID field value according to RFC 7684 specification */ | |
93f0a26e | 260 | uint32_t instance; |
cf9b9f77 | 261 | |
93f0a26e | 262 | uint8_t algo[ALGORITHM_COUNT]; /* Algorithms supported by the node */ |
6f751f14 OD |
263 | struct sr_block srgb; /* Segment Routing Global Block */ |
264 | struct sr_block srlb; /* Segment Routing Local Block */ | |
265 | uint8_t msd; /* Maximum SID Depth */ | |
cf9b9f77 OD |
266 | |
267 | /* List of Prefix & Link advertise by this node */ | |
268 | struct list *ext_prefix; /* For Node SID */ | |
edb368e9 | 269 | struct list *ext_link; /* For Adjacency SID */ |
cf9b9f77 OD |
270 | |
271 | /* Pointer to FRR SR-Node or NULL if it is not a neighbor */ | |
272 | struct sr_node *neighbor; | |
273 | }; | |
274 | ||
cf9b9f77 OD |
275 | /* Segment Routing - NHLFE info: support IPv4 Only */ |
276 | struct sr_nhlfe { | |
cf9b9f77 OD |
277 | struct in_addr nexthop; |
278 | ifindex_t ifindex; | |
279 | mpls_label_t label_in; | |
280 | mpls_label_t label_out; | |
281 | }; | |
282 | ||
283 | /* Structure aggregating all Segment Routing Link information */ | |
284 | /* Link are generally advertised by pair: primary + backup */ | |
285 | struct sr_link { | |
286 | struct in_addr adv_router; /* used to identify sender of LSA */ | |
287 | /* 24-bit Opaque-ID field value according to RFC 7684 specification */ | |
93f0a26e | 288 | uint32_t instance; |
cf9b9f77 | 289 | |
cc1725bd G |
290 | /* Addressed (remote) router id */ |
291 | struct in_addr remote_id; | |
292 | ||
b37eb79c OD |
293 | /* Interface address */ |
294 | struct in_addr itf_addr; | |
295 | ||
cf9b9f77 | 296 | /* Flags to manage this link parameters. */ |
7743f2f8 | 297 | uint8_t flags[2]; |
cf9b9f77 OD |
298 | |
299 | /* Segment Routing ID */ | |
93f0a26e | 300 | uint32_t sid[2]; |
cf9b9f77 OD |
301 | enum sid_type type; |
302 | ||
b37eb79c | 303 | /* SR NHLFE (Primary + Backup) for this link */ |
cf9b9f77 OD |
304 | struct sr_nhlfe nhlfe[2]; |
305 | ||
306 | /* Back pointer to SR Node which advertise this Link */ | |
307 | struct sr_node *srn; | |
308 | }; | |
309 | ||
310 | /* Structure aggregating all Segment Routing Prefix information */ | |
311 | struct sr_prefix { | |
312 | struct in_addr adv_router; /* used to identify sender of LSA */ | |
313 | /* 24-bit Opaque-ID field value according to RFC 7684 specification */ | |
93f0a26e | 314 | uint32_t instance; |
cf9b9f77 | 315 | |
b37eb79c OD |
316 | /* Prefix itself */ |
317 | struct prefix_ipv4 prefv4; | |
318 | ||
cf9b9f77 | 319 | /* Flags to manage this prefix parameters. */ |
7743f2f8 | 320 | uint8_t flags; |
cf9b9f77 OD |
321 | |
322 | /* Segment Routing ID */ | |
93f0a26e | 323 | uint32_t sid; |
cf9b9f77 OD |
324 | enum sid_type type; |
325 | ||
b37eb79c OD |
326 | /* Incoming label for this prefix */ |
327 | mpls_label_t label_in; | |
328 | ||
329 | /* Back pointer to OSPF Route for remote prefix */ | |
b61264a8 | 330 | struct ospf_route *route; |
b37eb79c OD |
331 | |
332 | /* NHLFE for local prefix */ | |
cf9b9f77 OD |
333 | struct sr_nhlfe nhlfe; |
334 | ||
335 | /* Back pointer to SR Node which advertise this Prefix */ | |
336 | struct sr_node *srn; | |
cf9b9f77 OD |
337 | }; |
338 | ||
339 | /* Prototypes definition */ | |
340 | /* Segment Routing initialisation functions */ | |
341 | extern int ospf_sr_init(void); | |
342 | extern void ospf_sr_term(void); | |
bcf4475e | 343 | extern void ospf_sr_finish(void); |
6f751f14 OD |
344 | /* Segment Routing label allocation functions */ |
345 | extern mpls_label_t ospf_sr_local_block_request_label(void); | |
346 | extern int ospf_sr_local_block_release_label(mpls_label_t label); | |
cf9b9f77 OD |
347 | /* Segment Routing LSA update & delete functions */ |
348 | extern void ospf_sr_ri_lsa_update(struct ospf_lsa *lsa); | |
349 | extern void ospf_sr_ri_lsa_delete(struct ospf_lsa *lsa); | |
7743f2f8 OD |
350 | extern void ospf_sr_ext_link_lsa_update(struct ospf_lsa *lsa); |
351 | extern void ospf_sr_ext_link_lsa_delete(struct ospf_lsa *lsa); | |
352 | extern void ospf_sr_ext_prefix_lsa_update(struct ospf_lsa *lsa); | |
353 | extern void ospf_sr_ext_prefix_lsa_delete(struct ospf_lsa *lsa); | |
21baf89a OD |
354 | /* Segment Routing Extending Link management */ |
355 | struct ext_itf; | |
356 | extern void ospf_sr_ext_itf_add(struct ext_itf *exti); | |
357 | extern void ospf_sr_ext_itf_delete(struct ext_itf *exti); | |
cf9b9f77 | 358 | /* Segment Routing configuration functions */ |
7743f2f8 | 359 | extern void ospf_sr_config_write_router(struct vty *vty); |
b61264a8 OD |
360 | extern void ospf_sr_update_local_prefix(struct interface *ifp, |
361 | struct prefix *p); | |
cf9b9f77 | 362 | /* Segment Routing re-routing function */ |
b37eb79c | 363 | extern void ospf_sr_update_task(struct ospf *ospf); |
7fd0729f G |
364 | |
365 | /* Support for TI-LFA */ | |
366 | extern mpls_label_t ospf_sr_get_prefix_sid_by_id(struct in_addr *id); | |
cc1725bd G |
367 | extern mpls_label_t ospf_sr_get_adj_sid_by_id(struct in_addr *root_id, |
368 | struct in_addr *neighbor_id); | |
7fd0729f G |
369 | extern struct sr_node *ospf_sr_node_create(struct in_addr *rid); |
370 | ||
cf9b9f77 | 371 | #endif /* _FRR_OSPF_SR_H */ |