]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_sr.h
Merge pull request #5468 from qlyoung/bgpd-remove-bgp-attr-dup
[mirror_frr.git] / ospfd / ospf_sr.h
CommitLineData
cf9b9f77
OD
1/*
2 * This is an implementation of Segment Routing
3 * as per draft draft-ietf-ospf-segment-routing-extensions-24
4 *
5 * Module name: Segment Routing header definitions
6 *
7 * Author: Olivier Dugeon <olivier.dugeon@orange.com>
8 * Author: Anselme Sawadogo <anselmesawadogo@gmail.com>
9 *
7743f2f8 10 * Copyright (C) 2016 - 2018 Orange Labs http://www.orange.com
cf9b9f77 11 *
7743f2f8
OD
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
cf9b9f77 16 *
7743f2f8
OD
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 * more details.
cf9b9f77 21 *
7743f2f8
OD
22 * You should have received a copy of the GNU General Public License along
23 * with this program; see the file COPYING; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
cf9b9f77
OD
25 */
26
27#ifndef _FRR_OSPF_SR_H
28#define _FRR_OSPF_SR_H
29
cf9b9f77
OD
30/* macros and constants for segment routing */
31#define SET_RANGE_SIZE_MASK 0xffffff00
32#define GET_RANGE_SIZE_MASK 0x00ffffff
33#define SET_LABEL_MASK 0xffffff00
34#define GET_LABEL_MASK 0x00ffffff
35#define SET_RANGE_SIZE(range_size) ((range_size << 8) & SET_RANGE_SIZE_MASK)
36#define GET_RANGE_SIZE(range_size) ((range_size >> 8) & GET_RANGE_SIZE_MASK)
37#define SET_LABEL(label) ((label << 8) & SET_LABEL_MASK)
38#define GET_LABEL(label) ((label >> 8) & GET_LABEL_MASK)
39
7743f2f8
OD
40/* Label range for Adj-SID attribution purpose. Start just right after SRGB */
41#define ADJ_SID_MIN MPLS_DEFAULT_MAX_SRGB_LABEL
42#define ADJ_SID_MAX (MPLS_DEFAULT_MAX_SRGB_LABEL + 1000)
cf9b9f77
OD
43
44#define OSPF_SR_DEFAULT_METRIC 1
45
46/* Segment Routing TLVs as per draft-ietf-ospf-segment-routing-extensions-19 */
47
48/* Segment ID could be a Label (3 bytes) or an Index (4 bytes) */
cf9b9f77 49#define SID_LABEL 3
d922605d 50#define SID_LABEL_SIZE(U) (U - 1)
cf9b9f77 51#define SID_INDEX 4
d922605d 52#define SID_INDEX_SIZE(U) (U)
cf9b9f77
OD
53
54/* SID/Label Sub TLV - section 2.1 */
55#define SUBTLV_SID_LABEL 1
56#define SUBTLV_SID_LABEL_SIZE 8
57struct subtlv_sid_label {
58 /* Length is 3 (20 rightmost bits MPLS label) or 4 (32 bits SID) */
59 struct tlv_header header;
93f0a26e 60 uint32_t value;
cf9b9f77
OD
61};
62
63/*
64 * Following section defines Segment Routing TLV (tag, length, value)
65 * structures, used in Router Information Opaque LSA.
66 */
67
68/* RI SR-Algorithm TLV - section 3.1 */
69#define RI_SR_TLV_SR_ALGORITHM 8
70struct ri_sr_tlv_sr_algorithm {
71 struct tlv_header header;
72#define SR_ALGORITHM_SPF 0
73#define SR_ALGORITHM_STRICT_SPF 1
74#define SR_ALGORITHM_UNSET 255
75#define ALGORITHM_COUNT 4
76 /* Only 4 algorithms supported in this code */
93f0a26e 77 uint8_t value[ALGORITHM_COUNT];
cf9b9f77
OD
78};
79
80/* RI SID/Label Range TLV - section 3.2 */
81#define RI_SR_TLV_SID_LABEL_RANGE 9
82struct ri_sr_tlv_sid_label_range {
83 struct tlv_header header;
84/* Only 24 upper most bits are significant */
85#define SID_RANGE_LABEL_LENGTH 3
93f0a26e 86 uint32_t size;
cf9b9f77
OD
87 /* A SID/Label sub-TLV will follow. */
88 struct subtlv_sid_label lower;
89};
90
91/* RI Node/MSD TLV as per draft-ietf-ospf-segment-routing-msd-05 */
92#define RI_SR_TLV_NODE_MSD 12
93struct ri_sr_tlv_node_msd {
94 struct tlv_header header;
93f0a26e
OD
95 uint8_t subtype; /* always = 1 */
96 uint8_t value;
97 uint16_t padding;
cf9b9f77
OD
98};
99
100/*
101 * Following section defines Segment Routing TLV (tag, length, value)
102 * structures, used in Extended Prefix/Link Opaque LSA.
103 */
104
105/* Adj-SID and LAN-Ajd-SID subtlvs' flags */
106#define EXT_SUBTLV_LINK_ADJ_SID_BFLG 0x80
107#define EXT_SUBTLV_LINK_ADJ_SID_VFLG 0x40
108#define EXT_SUBTLV_LINK_ADJ_SID_LFLG 0x20
109#define EXT_SUBTLV_LINK_ADJ_SID_SFLG 0x10
110
111/* Prefix SID subtlv Flags */
112#define EXT_SUBTLV_PREFIX_SID_NPFLG 0x40
113#define EXT_SUBTLV_PREFIX_SID_MFLG 0x20
114#define EXT_SUBTLV_PREFIX_SID_EFLG 0x10
115#define EXT_SUBTLV_PREFIX_SID_VFLG 0x08
116#define EXT_SUBTLV_PREFIX_SID_LFLG 0x04
117
118/* SID/Label Binding subtlv Flags */
119#define EXT_SUBTLV_SID_BINDING_MFLG 0x80
120
121/* Extended Prefix Range TLV - section 4 */
122#define EXT_TLV_PREF_RANGE 2
123#define EXT_SUBTLV_PREFIX_RANGE_SIZE 12
124struct ext_tlv_prefix_range {
125 struct tlv_header header;
93f0a26e
OD
126 uint8_t pref_length;
127 uint8_t af;
128 uint16_t range_size;
129 uint8_t flags;
130 uint8_t reserved[3];
cf9b9f77
OD
131 struct in_addr address;
132};
133
134/* Prefix SID Sub-TLV - section 5 */
135#define EXT_SUBTLV_PREFIX_SID 2
136#define EXT_SUBTLV_PREFIX_SID_SIZE 8
137struct ext_subtlv_prefix_sid {
138 struct tlv_header header;
93f0a26e
OD
139 uint8_t flags;
140 uint8_t reserved;
141 uint8_t mtid;
142 uint8_t algorithm;
143 uint32_t value;
cf9b9f77
OD
144};
145
146/* Adj-SID Sub-TLV - section 6.1 */
147#define EXT_SUBTLV_ADJ_SID 2
148#define EXT_SUBTLV_ADJ_SID_SIZE 8
149struct ext_subtlv_adj_sid {
150 struct tlv_header header;
93f0a26e
OD
151 uint8_t flags;
152 uint8_t reserved;
153 uint8_t mtid;
154 uint8_t weight;
155 uint32_t value;
cf9b9f77
OD
156};
157
158/* LAN Adj-SID Sub-TLV - section 6.2 */
159#define EXT_SUBTLV_LAN_ADJ_SID 3
160#define EXT_SUBTLV_LAN_ADJ_SID_SIZE 12
161struct ext_subtlv_lan_adj_sid {
162 struct tlv_header header;
93f0a26e
OD
163 uint8_t flags;
164 uint8_t reserved;
165 uint8_t mtid;
166 uint8_t weight;
cf9b9f77 167 struct in_addr neighbor_id;
93f0a26e 168 uint32_t value;
cf9b9f77
OD
169};
170
171/*
172 * Following section define structure used to manage Segment Routing
173 * information and TLVs / SubTLVs
174 */
175
176/* Structure aggregating SRGB info retrieved from an lsa */
177struct sr_srgb {
93f0a26e
OD
178 uint32_t range_size;
179 uint32_t lower_bound;
cf9b9f77
OD
180};
181
182/* SID type to make difference between loopback interfaces and others */
183enum sid_type { PREF_SID, ADJ_SID, LAN_ADJ_SID };
184
185/* Structure aggregating all OSPF Segment Routing information for the node */
186struct ospf_sr_db {
187 /* Status of Segment Routing: enable or disable */
188 bool enabled;
189
190 /* Ongoing Update following an OSPF SPF */
191 bool update;
192
193 /* Flooding Scope: Area = 10 or AS = 11 */
93f0a26e 194 uint8_t scope;
cf9b9f77
OD
195
196 /* FRR SR node */
197 struct sr_node *self;
198
199 /* List of neighbour SR nodes */
200 struct hash *neighbors;
201
202 /* List of SR prefix */
203 struct route_table *prefix;
204
205 /* Local SR info announced in Router Info LSA */
206
207 /* Algorithms supported by the node */
93f0a26e 208 uint8_t algo[ALGORITHM_COUNT];
cf9b9f77
OD
209 /*
210 * Segment Routing Global Block i.e. label range
211 * Only one range supported in this code
212 */
213 struct sr_srgb srgb;
214 /* Maximum SID Depth supported by the node */
93f0a26e 215 uint8_t msd;
cf9b9f77
OD
216};
217
218/* Structure aggregating all received SR info from LSAs by node */
219struct sr_node {
220 struct in_addr adv_router; /* used to identify sender of LSA */
221 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
93f0a26e 222 uint32_t instance;
cf9b9f77 223
93f0a26e 224 uint8_t algo[ALGORITHM_COUNT]; /* Algorithms supported by the node */
cf9b9f77
OD
225 /* Segment Routing Global Block i.e. label range */
226 struct sr_srgb srgb;
93f0a26e 227 uint8_t msd; /* Maximum SID Depth */
cf9b9f77
OD
228
229 /* List of Prefix & Link advertise by this node */
230 struct list *ext_prefix; /* For Node SID */
231 struct list *ext_link; /* For Adj and LAN SID */
232
233 /* Pointer to FRR SR-Node or NULL if it is not a neighbor */
234 struct sr_node *neighbor;
235};
236
237
238/* Segment Routing - NHLFE info: support IPv4 Only */
239struct sr_nhlfe {
240 struct prefix_ipv4 prefv4;
241 struct in_addr nexthop;
242 ifindex_t ifindex;
243 mpls_label_t label_in;
244 mpls_label_t label_out;
245};
246
247/* Structure aggregating all Segment Routing Link information */
248/* Link are generally advertised by pair: primary + backup */
249struct sr_link {
250 struct in_addr adv_router; /* used to identify sender of LSA */
251 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
93f0a26e 252 uint32_t instance;
cf9b9f77
OD
253
254 /* Flags to manage this link parameters. */
7743f2f8 255 uint8_t flags[2];
cf9b9f77
OD
256
257 /* Segment Routing ID */
93f0a26e 258 uint32_t sid[2];
cf9b9f77
OD
259 enum sid_type type;
260
261 /* SR NHLFE for this link */
262 struct sr_nhlfe nhlfe[2];
263
264 /* Back pointer to SR Node which advertise this Link */
265 struct sr_node *srn;
266};
267
268/* Structure aggregating all Segment Routing Prefix information */
269struct sr_prefix {
270 struct in_addr adv_router; /* used to identify sender of LSA */
271 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
93f0a26e 272 uint32_t instance;
cf9b9f77
OD
273
274 /* Flags to manage this prefix parameters. */
7743f2f8 275 uint8_t flags;
cf9b9f77
OD
276
277 /* Segment Routing ID */
93f0a26e 278 uint32_t sid;
cf9b9f77
OD
279 enum sid_type type;
280
281 /* SR NHLFE for this prefix */
282 struct sr_nhlfe nhlfe;
283
284 /* Back pointer to SR Node which advertise this Prefix */
285 struct sr_node *srn;
286
7743f2f8
OD
287 /*
288 * Pointer to SR Node which is the next hop for this Prefix
289 * or NULL if next hop is the destination of the prefix
290 */
cf9b9f77
OD
291 struct sr_node *nexthop;
292};
293
294/* Prototypes definition */
295/* Segment Routing initialisation functions */
296extern int ospf_sr_init(void);
297extern void ospf_sr_term(void);
bcf4475e 298extern void ospf_sr_finish(void);
cf9b9f77
OD
299/* Segment Routing LSA update & delete functions */
300extern void ospf_sr_ri_lsa_update(struct ospf_lsa *lsa);
301extern void ospf_sr_ri_lsa_delete(struct ospf_lsa *lsa);
7743f2f8
OD
302extern void ospf_sr_ext_link_lsa_update(struct ospf_lsa *lsa);
303extern void ospf_sr_ext_link_lsa_delete(struct ospf_lsa *lsa);
304extern void ospf_sr_ext_prefix_lsa_update(struct ospf_lsa *lsa);
305extern void ospf_sr_ext_prefix_lsa_delete(struct ospf_lsa *lsa);
cf9b9f77 306/* Segment Routing configuration functions */
93f0a26e 307extern uint32_t get_ext_link_label_value(void);
7743f2f8
OD
308extern void ospf_sr_config_write_router(struct vty *vty);
309extern void ospf_sr_update_prefix(struct interface *ifp, struct prefix *p);
cf9b9f77 310/* Segment Routing re-routing function */
7743f2f8 311extern void ospf_sr_update_timer_add(struct ospf *ospf);
cf9b9f77 312#endif /* _FRR_OSPF_SR_H */