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