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