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