]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_sr.h
ospfd: remove unused enum case for state of SR ..
[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
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
bc298f5d 64#define SUBTLV_SID_LABEL_SIZE 4
cf9b9f77
OD
65struct 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
78struct 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
8db278b5 91#define RI_SR_TLV_LABEL_RANGE_SIZE 12
cf9b9f77
OD
92struct 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
93f0a26e 96 uint32_t size;
cf9b9f77
OD
97 /* A SID/Label sub-TLV will follow. */
98 struct subtlv_sid_label lower;
99};
100
6f751f14 101/* RI Node/MSD TLV as per RFC 8476 */
cf9b9f77 102#define RI_SR_TLV_NODE_MSD 12
8db278b5 103#define RI_SR_TLV_NODE_MSD_SIZE 4
cf9b9f77
OD
104struct ri_sr_tlv_node_msd {
105 struct tlv_header header;
93f0a26e
OD
106 uint8_t subtype; /* always = 1 */
107 uint8_t value;
108 uint16_t padding;
cf9b9f77
OD
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
135struct ext_tlv_prefix_range {
136 struct tlv_header header;
93f0a26e
OD
137 uint8_t pref_length;
138 uint8_t af;
139 uint16_t range_size;
140 uint8_t flags;
141 uint8_t reserved[3];
cf9b9f77
OD
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
148struct ext_subtlv_prefix_sid {
149 struct tlv_header header;
93f0a26e
OD
150 uint8_t flags;
151 uint8_t reserved;
152 uint8_t mtid;
153 uint8_t algorithm;
154 uint32_t value;
cf9b9f77
OD
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
160struct ext_subtlv_adj_sid {
161 struct tlv_header header;
93f0a26e
OD
162 uint8_t flags;
163 uint8_t reserved;
164 uint8_t mtid;
165 uint8_t weight;
166 uint32_t value;
cf9b9f77
OD
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
172struct ext_subtlv_lan_adj_sid {
173 struct tlv_header header;
93f0a26e
OD
174 uint8_t flags;
175 uint8_t reserved;
176 uint8_t mtid;
177 uint8_t weight;
cf9b9f77 178 struct in_addr neighbor_id;
93f0a26e 179 uint32_t value;
cf9b9f77
OD
180};
181
182/*
183 * Following section define structure used to manage Segment Routing
184 * information and TLVs / SubTLVs
185 */
6f751f14
OD
186/* Default min and size of SR Global Block label range */
187#define DEFAULT_SRGB_LABEL 16000
188#define DEFAULT_SRGB_SIZE 8000
6443a4be 189#define DEFAULT_SRGB_END (DEFAULT_SRGB_LABEL + DEFAULT_SRGB_SIZE - 1)
6f751f14
OD
190
191/* Default min and size of SR Local Block label range */
192#define DEFAULT_SRLB_LABEL 15000
193#define DEFAULT_SRLB_SIZE 1000
6443a4be 194#define DEFAULT_SRLB_END (DEFAULT_SRLB_LABEL + DEFAULT_SRLB_SIZE - 1)
cf9b9f77 195
6f751f14
OD
196/* Structure aggregating SR Range Block info retrieved from an lsa */
197struct sr_block {
93f0a26e
OD
198 uint32_t range_size;
199 uint32_t lower_bound;
cf9b9f77
OD
200};
201
6f751f14
OD
202/* Segment Routing Global Block allocation */
203struct sr_global_block {
204 bool reserved;
205 uint32_t start;
206 uint32_t size;
207};
208
209/* Segment Routing Local Block allocation */
210struct sr_local_block {
211 bool reserved;
212 uint32_t start;
213 uint32_t end;
214 uint32_t current;
215 uint32_t max_block;
216 uint64_t *used_mark;
217};
218#define SRLB_BLOCK_SIZE 64
219
cf9b9f77 220/* SID type to make difference between loopback interfaces and others */
b37eb79c 221enum sid_type { PREF_SID, LOCAL_SID, ADJ_SID, LAN_ADJ_SID };
cf9b9f77 222
d81b8e0e 223/* Status of Segment Routing: Off (Disable), On (Enable), (Up) Started */
2110d03e 224enum sr_status { SR_OFF, SR_ON, SR_UP };
d81b8e0e 225
cf9b9f77
OD
226/* Structure aggregating all OSPF Segment Routing information for the node */
227struct ospf_sr_db {
d81b8e0e
OD
228 /* Status of Segment Routing */
229 enum sr_status status;
cf9b9f77 230
cf9b9f77 231 /* Flooding Scope: Area = 10 or AS = 11 */
93f0a26e 232 uint8_t scope;
cf9b9f77
OD
233
234 /* FRR SR node */
235 struct sr_node *self;
236
237 /* List of neighbour SR nodes */
238 struct hash *neighbors;
239
cf9b9f77
OD
240 /* Local SR info announced in Router Info LSA */
241
242 /* Algorithms supported by the node */
93f0a26e 243 uint8_t algo[ALGORITHM_COUNT];
cf9b9f77
OD
244 /*
245 * Segment Routing Global Block i.e. label range
246 * Only one range supported in this code
247 */
6f751f14 248 struct sr_global_block srgb;
d81b8e0e 249
6f751f14
OD
250 /* Segment Routing Local Block */
251 struct sr_local_block srlb;
d81b8e0e 252
cf9b9f77 253 /* Maximum SID Depth supported by the node */
93f0a26e 254 uint8_t msd;
6f751f14
OD
255
256 /* Thread timer to start Label Manager */
257 struct thread *t_start_lm;
cf9b9f77
OD
258};
259
260/* Structure aggregating all received SR info from LSAs by node */
261struct sr_node {
262 struct in_addr adv_router; /* used to identify sender of LSA */
263 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
93f0a26e 264 uint32_t instance;
cf9b9f77 265
93f0a26e 266 uint8_t algo[ALGORITHM_COUNT]; /* Algorithms supported by the node */
6f751f14
OD
267 struct sr_block srgb; /* Segment Routing Global Block */
268 struct sr_block srlb; /* Segment Routing Local Block */
269 uint8_t msd; /* Maximum SID Depth */
cf9b9f77
OD
270
271 /* List of Prefix & Link advertise by this node */
272 struct list *ext_prefix; /* For Node SID */
edb368e9 273 struct list *ext_link; /* For Adjacency SID */
cf9b9f77
OD
274
275 /* Pointer to FRR SR-Node or NULL if it is not a neighbor */
276 struct sr_node *neighbor;
277};
278
cf9b9f77
OD
279/* Segment Routing - NHLFE info: support IPv4 Only */
280struct sr_nhlfe {
cf9b9f77
OD
281 struct in_addr nexthop;
282 ifindex_t ifindex;
283 mpls_label_t label_in;
284 mpls_label_t label_out;
285};
286
287/* Structure aggregating all Segment Routing Link information */
288/* Link are generally advertised by pair: primary + backup */
289struct sr_link {
290 struct in_addr adv_router; /* used to identify sender of LSA */
291 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
93f0a26e 292 uint32_t instance;
cf9b9f77 293
cc1725bd
G
294 /* Addressed (remote) router id */
295 struct in_addr remote_id;
296
b37eb79c
OD
297 /* Interface address */
298 struct in_addr itf_addr;
299
cf9b9f77 300 /* Flags to manage this link parameters. */
7743f2f8 301 uint8_t flags[2];
cf9b9f77
OD
302
303 /* Segment Routing ID */
93f0a26e 304 uint32_t sid[2];
cf9b9f77
OD
305 enum sid_type type;
306
b37eb79c 307 /* SR NHLFE (Primary + Backup) for this link */
cf9b9f77
OD
308 struct sr_nhlfe nhlfe[2];
309
310 /* Back pointer to SR Node which advertise this Link */
311 struct sr_node *srn;
312};
313
314/* Structure aggregating all Segment Routing Prefix information */
315struct sr_prefix {
316 struct in_addr adv_router; /* used to identify sender of LSA */
317 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
93f0a26e 318 uint32_t instance;
cf9b9f77 319
b37eb79c
OD
320 /* Prefix itself */
321 struct prefix_ipv4 prefv4;
322
cf9b9f77 323 /* Flags to manage this prefix parameters. */
7743f2f8 324 uint8_t flags;
cf9b9f77
OD
325
326 /* Segment Routing ID */
93f0a26e 327 uint32_t sid;
cf9b9f77
OD
328 enum sid_type type;
329
b37eb79c
OD
330 /* Incoming label for this prefix */
331 mpls_label_t label_in;
332
333 /* Back pointer to OSPF Route for remote prefix */
b61264a8 334 struct ospf_route *route;
b37eb79c
OD
335
336 /* NHLFE for local prefix */
cf9b9f77
OD
337 struct sr_nhlfe nhlfe;
338
339 /* Back pointer to SR Node which advertise this Prefix */
340 struct sr_node *srn;
cf9b9f77
OD
341};
342
343/* Prototypes definition */
344/* Segment Routing initialisation functions */
345extern int ospf_sr_init(void);
346extern void ospf_sr_term(void);
bcf4475e 347extern void ospf_sr_finish(void);
6f751f14
OD
348/* Segment Routing label allocation functions */
349extern mpls_label_t ospf_sr_local_block_request_label(void);
350extern int ospf_sr_local_block_release_label(mpls_label_t label);
cf9b9f77
OD
351/* Segment Routing LSA update & delete functions */
352extern void ospf_sr_ri_lsa_update(struct ospf_lsa *lsa);
353extern void ospf_sr_ri_lsa_delete(struct ospf_lsa *lsa);
7743f2f8
OD
354extern void ospf_sr_ext_link_lsa_update(struct ospf_lsa *lsa);
355extern void ospf_sr_ext_link_lsa_delete(struct ospf_lsa *lsa);
356extern void ospf_sr_ext_prefix_lsa_update(struct ospf_lsa *lsa);
357extern void ospf_sr_ext_prefix_lsa_delete(struct ospf_lsa *lsa);
21baf89a
OD
358/* Segment Routing Extending Link management */
359struct ext_itf;
360extern void ospf_sr_ext_itf_add(struct ext_itf *exti);
361extern void ospf_sr_ext_itf_delete(struct ext_itf *exti);
cf9b9f77 362/* Segment Routing configuration functions */
7743f2f8 363extern void ospf_sr_config_write_router(struct vty *vty);
b61264a8
OD
364extern void ospf_sr_update_local_prefix(struct interface *ifp,
365 struct prefix *p);
cf9b9f77 366/* Segment Routing re-routing function */
b37eb79c 367extern void ospf_sr_update_task(struct ospf *ospf);
7fd0729f
G
368
369/* Support for TI-LFA */
370extern mpls_label_t ospf_sr_get_prefix_sid_by_id(struct in_addr *id);
cc1725bd
G
371extern mpls_label_t ospf_sr_get_adj_sid_by_id(struct in_addr *root_id,
372 struct in_addr *neighbor_id);
7fd0729f
G
373extern struct sr_node *ospf_sr_node_create(struct in_addr *rid);
374
cf9b9f77 375#endif /* _FRR_OSPF_SR_H */