]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_sr.h
Merge pull request #8628 from idryzhov/isis-vrf-redist
[mirror_frr.git] / ospfd / ospf_sr.h
1 /*
2 * This is an implementation of Segment Routing
3 * as per RFC 8665 - OSPF Extensions for Segment Routing
4 * and RFC 8476 - Signaling Maximum SID Depth (MSD) Using OSPF
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 *
11 * Copyright (C) 2016 - 2020 Orange Labs http://www.orange.com
12 *
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.
17 *
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.
22 *
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
26 */
27
28 #ifndef _FRR_OSPF_SR_H
29 #define _FRR_OSPF_SR_H
30
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
41 #define OSPF_SR_DEFAULT_METRIC 1
42
43 /* Segment Routing TLVs as per RFC 8665 */
44
45 /* Segment ID could be a Label (3 bytes) or an Index (4 bytes) */
46 #define SID_LABEL 3
47 #define SID_LABEL_SIZE(U) (U - 1)
48 #define SID_INDEX 4
49 #define SID_INDEX_SIZE(U) (U)
50
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
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
62 /* SID/Label Sub TLV - section 2.1 */
63 #define SUBTLV_SID_LABEL 1
64 #define SUBTLV_SID_LABEL_SIZE 4
65 struct subtlv_sid_label {
66 /* Length is 3 (20 rightmost bits MPLS label) or 4 (32 bits SID) */
67 struct tlv_header header;
68 uint32_t value;
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 */
85 uint8_t value[ALGORITHM_COUNT];
86 };
87
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
91 #define RI_SR_TLV_LABEL_RANGE_SIZE 12
92 struct ri_sr_tlv_sid_label_range {
93 struct tlv_header header;
94 /* Only 24 upper most bits are significant */
95 #define SID_RANGE_LABEL_LENGTH 3
96 uint32_t size;
97 /* A SID/Label sub-TLV will follow. */
98 struct subtlv_sid_label lower;
99 };
100
101 /* RI Node/MSD TLV as per RFC 8476 */
102 #define RI_SR_TLV_NODE_MSD 12
103 #define RI_SR_TLV_NODE_MSD_SIZE 4
104 struct ri_sr_tlv_node_msd {
105 struct tlv_header header;
106 uint8_t subtype; /* always = 1 */
107 uint8_t value;
108 uint16_t padding;
109 };
110
111 /*
112 * Following section defines Segment Routing TLV (tag, length, value)
113 * structures, used in Extended Prefix/Link Opaque LSA.
114 */
115
116 /* Adj-SID and LAN-Ajd-SID subtlvs' flags */
117 #define EXT_SUBTLV_LINK_ADJ_SID_BFLG 0x80
118 #define EXT_SUBTLV_LINK_ADJ_SID_VFLG 0x40
119 #define EXT_SUBTLV_LINK_ADJ_SID_LFLG 0x20
120 #define EXT_SUBTLV_LINK_ADJ_SID_SFLG 0x10
121
122 /* Prefix SID subtlv Flags */
123 #define EXT_SUBTLV_PREFIX_SID_NPFLG 0x40
124 #define EXT_SUBTLV_PREFIX_SID_MFLG 0x20
125 #define EXT_SUBTLV_PREFIX_SID_EFLG 0x10
126 #define EXT_SUBTLV_PREFIX_SID_VFLG 0x08
127 #define EXT_SUBTLV_PREFIX_SID_LFLG 0x04
128
129 /* SID/Label Binding subtlv Flags */
130 #define EXT_SUBTLV_SID_BINDING_MFLG 0x80
131
132 /* Extended Prefix Range TLV - section 4 */
133 #define EXT_TLV_PREF_RANGE 2
134 #define EXT_SUBTLV_PREFIX_RANGE_SIZE 12
135 struct ext_tlv_prefix_range {
136 struct tlv_header header;
137 uint8_t pref_length;
138 uint8_t af;
139 uint16_t range_size;
140 uint8_t flags;
141 uint8_t reserved[3];
142 struct in_addr address;
143 };
144
145 /* Prefix SID Sub-TLV - section 5 */
146 #define EXT_SUBTLV_PREFIX_SID 2
147 #define EXT_SUBTLV_PREFIX_SID_SIZE 8
148 struct ext_subtlv_prefix_sid {
149 struct tlv_header header;
150 uint8_t flags;
151 uint8_t reserved;
152 uint8_t mtid;
153 uint8_t algorithm;
154 uint32_t value;
155 };
156
157 /* Adj-SID Sub-TLV - section 6.1 */
158 #define EXT_SUBTLV_ADJ_SID 2
159 #define EXT_SUBTLV_ADJ_SID_SIZE 8
160 struct ext_subtlv_adj_sid {
161 struct tlv_header header;
162 uint8_t flags;
163 uint8_t reserved;
164 uint8_t mtid;
165 uint8_t weight;
166 uint32_t value;
167 };
168
169 /* LAN Adj-SID Sub-TLV - section 6.2 */
170 #define EXT_SUBTLV_LAN_ADJ_SID 3
171 #define EXT_SUBTLV_LAN_ADJ_SID_SIZE 12
172 struct ext_subtlv_lan_adj_sid {
173 struct tlv_header header;
174 uint8_t flags;
175 uint8_t reserved;
176 uint8_t mtid;
177 uint8_t weight;
178 struct in_addr neighbor_id;
179 uint32_t value;
180 };
181
182 /*
183 * Following section define structure used to manage Segment Routing
184 * information and TLVs / SubTLVs
185 */
186 /* Default min and size of SR Global Block label range */
187 #define DEFAULT_SRGB_LABEL 16000
188 #define DEFAULT_SRGB_SIZE 8000
189
190 /* Default min and size of SR Local Block label range */
191 #define DEFAULT_SRLB_LABEL 15000
192 #define DEFAULT_SRLB_SIZE 1000
193
194 /* Structure aggregating SR Range Block info retrieved from an lsa */
195 struct sr_block {
196 uint32_t range_size;
197 uint32_t lower_bound;
198 };
199
200 /* Segment Routing Global Block allocation */
201 struct sr_global_block {
202 bool reserved;
203 uint32_t start;
204 uint32_t size;
205 };
206
207 /* Segment Routing Local Block allocation */
208 struct sr_local_block {
209 bool reserved;
210 uint32_t start;
211 uint32_t end;
212 uint32_t current;
213 uint32_t max_block;
214 uint64_t *used_mark;
215 };
216 #define SRLB_BLOCK_SIZE 64
217
218 /* SID type to make difference between loopback interfaces and others */
219 enum sid_type { PREF_SID, LOCAL_SID, ADJ_SID, LAN_ADJ_SID };
220
221 /* Status of Segment Routing: Off (Disable), On (Enable), (Up) Started */
222 enum sr_status { SR_OFF, SR_ON, SR_UP, SR_DOWN };
223
224 /* Structure aggregating all OSPF Segment Routing information for the node */
225 struct ospf_sr_db {
226 /* Status of Segment Routing */
227 enum sr_status status;
228
229 /* Flooding Scope: Area = 10 or AS = 11 */
230 uint8_t scope;
231
232 /* FRR SR node */
233 struct sr_node *self;
234
235 /* List of neighbour SR nodes */
236 struct hash *neighbors;
237
238 /* Local SR info announced in Router Info LSA */
239
240 /* Algorithms supported by the node */
241 uint8_t algo[ALGORITHM_COUNT];
242 /*
243 * Segment Routing Global Block i.e. label range
244 * Only one range supported in this code
245 */
246 struct sr_global_block srgb;
247
248 /* Segment Routing Local Block */
249 struct sr_local_block srlb;
250
251 /* Maximum SID Depth supported by the node */
252 uint8_t msd;
253
254 /* Thread timer to start Label Manager */
255 struct thread *t_start_lm;
256 };
257
258 /* Structure aggregating all received SR info from LSAs by node */
259 struct sr_node {
260 struct in_addr adv_router; /* used to identify sender of LSA */
261 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
262 uint32_t instance;
263
264 uint8_t algo[ALGORITHM_COUNT]; /* Algorithms supported by the node */
265 struct sr_block srgb; /* Segment Routing Global Block */
266 struct sr_block srlb; /* Segment Routing Local Block */
267 uint8_t msd; /* Maximum SID Depth */
268
269 /* List of Prefix & Link advertise by this node */
270 struct list *ext_prefix; /* For Node SID */
271 struct list *ext_link; /* For Adjacency SID */
272
273 /* Pointer to FRR SR-Node or NULL if it is not a neighbor */
274 struct sr_node *neighbor;
275 };
276
277 /* Segment Routing - NHLFE info: support IPv4 Only */
278 struct sr_nhlfe {
279 struct in_addr nexthop;
280 ifindex_t ifindex;
281 mpls_label_t label_in;
282 mpls_label_t label_out;
283 };
284
285 /* Structure aggregating all Segment Routing Link information */
286 /* Link are generally advertised by pair: primary + backup */
287 struct sr_link {
288 struct in_addr adv_router; /* used to identify sender of LSA */
289 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
290 uint32_t instance;
291
292 /* Addressed (remote) router id */
293 struct in_addr remote_id;
294
295 /* Interface address */
296 struct in_addr itf_addr;
297
298 /* Flags to manage this link parameters. */
299 uint8_t flags[2];
300
301 /* Segment Routing ID */
302 uint32_t sid[2];
303 enum sid_type type;
304
305 /* SR NHLFE (Primary + Backup) for this link */
306 struct sr_nhlfe nhlfe[2];
307
308 /* Back pointer to SR Node which advertise this Link */
309 struct sr_node *srn;
310 };
311
312 /* Structure aggregating all Segment Routing Prefix information */
313 struct sr_prefix {
314 struct in_addr adv_router; /* used to identify sender of LSA */
315 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
316 uint32_t instance;
317
318 /* Prefix itself */
319 struct prefix_ipv4 prefv4;
320
321 /* Flags to manage this prefix parameters. */
322 uint8_t flags;
323
324 /* Segment Routing ID */
325 uint32_t sid;
326 enum sid_type type;
327
328 /* Incoming label for this prefix */
329 mpls_label_t label_in;
330
331 /* Back pointer to OSPF Route for remote prefix */
332 struct ospf_route *route;
333
334 /* NHLFE for local prefix */
335 struct sr_nhlfe nhlfe;
336
337 /* Back pointer to SR Node which advertise this Prefix */
338 struct sr_node *srn;
339 };
340
341 /* Prototypes definition */
342 /* Segment Routing initialisation functions */
343 extern int ospf_sr_init(void);
344 extern void ospf_sr_term(void);
345 extern void ospf_sr_finish(void);
346 /* Segment Routing label allocation functions */
347 extern mpls_label_t ospf_sr_local_block_request_label(void);
348 extern int ospf_sr_local_block_release_label(mpls_label_t label);
349 /* Segment Routing LSA update & delete functions */
350 extern void ospf_sr_ri_lsa_update(struct ospf_lsa *lsa);
351 extern void ospf_sr_ri_lsa_delete(struct ospf_lsa *lsa);
352 extern void ospf_sr_ext_link_lsa_update(struct ospf_lsa *lsa);
353 extern void ospf_sr_ext_link_lsa_delete(struct ospf_lsa *lsa);
354 extern void ospf_sr_ext_prefix_lsa_update(struct ospf_lsa *lsa);
355 extern void ospf_sr_ext_prefix_lsa_delete(struct ospf_lsa *lsa);
356 /* Segment Routing Extending Link management */
357 struct ext_itf;
358 extern void ospf_sr_ext_itf_add(struct ext_itf *exti);
359 extern void ospf_sr_ext_itf_delete(struct ext_itf *exti);
360 /* Segment Routing configuration functions */
361 extern void ospf_sr_config_write_router(struct vty *vty);
362 extern void ospf_sr_update_local_prefix(struct interface *ifp,
363 struct prefix *p);
364 /* Segment Routing re-routing function */
365 extern void ospf_sr_update_task(struct ospf *ospf);
366
367 /* Support for TI-LFA */
368 extern mpls_label_t ospf_sr_get_prefix_sid_by_id(struct in_addr *id);
369 extern mpls_label_t ospf_sr_get_adj_sid_by_id(struct in_addr *root_id,
370 struct in_addr *neighbor_id);
371 extern struct sr_node *ospf_sr_node_create(struct in_addr *rid);
372
373 #endif /* _FRR_OSPF_SR_H */