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