2 * This is an implementation of Segment Routing
3 * as per draft draft-ietf-ospf-segment-routing-extensions-24
5 * Module name: Segment Routing header definitions
7 * Author: Olivier Dugeon <olivier.dugeon@orange.com>
8 * Author: Anselme Sawadogo <anselmesawadogo@gmail.com>
10 * Copyright (C) 2016 - 2017 Orange Labs http://www.orange.com
12 * This file is part of FRR.
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
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.
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
30 #ifndef _FRR_OSPF_SR_H
31 #define _FRR_OSPF_SR_H
33 /* Default Route priority for OSPF Segment Routing */
34 #define OSPF_SR_PRIORITY_DEFAULT 10
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)
46 /* Label range for Adj-SID attribution purpose. See ospf_ext.c */
47 #define ADJ_SID_MIN 50000
48 #define ADJ_SID_MAX 51000
50 #define OSPF_SR_DEFAULT_METRIC 1
52 /* Segment Routing TLVs as per draft-ietf-ospf-segment-routing-extensions-19 */
54 /* Segment ID could be a Label (3 bytes) or an Index (4 bytes) */
55 #define SID_BASE_SIZE 4
57 #define SID_LABEL_SIZE (SID_BASE_SIZE + SID_LABEL)
59 #define SID_INDEX_SIZE (SID_BASE_SIZE + SID_INDEX)
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
;
71 * Following section defines Segment Routing TLV (tag, length, value)
72 * structures, used in Router Information Opaque LSA.
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
];
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
94 /* A SID/Label sub-TLV will follow. */
95 struct subtlv_sid_label lower
;
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 */
108 * Following section defines Segment Routing TLV (tag, length, value)
109 * structures, used in Extended Prefix/Link Opaque LSA.
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
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
125 /* SID/Label Binding subtlv Flags */
126 #define EXT_SUBTLV_SID_BINDING_MFLG 0x80
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
;
135 u_int16_t range_size
;
137 u_int8_t reserved
[3];
138 struct in_addr address
;
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
;
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
;
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
;
174 struct in_addr neighbor_id
;
179 * Following section define structure used to manage Segment Routing
180 * information and TLVs / SubTLVs
183 /* Structure aggregating SRGB info retrieved from an lsa */
185 u_int32_t range_size
;
186 u_int32_t lower_bound
;
189 /* SID type to make difference between loopback interfaces and others */
190 enum sid_type
{ PREF_SID
, ADJ_SID
, LAN_ADJ_SID
};
192 /* Structure aggregating all OSPF Segment Routing information for the node */
194 /* Status of Segment Routing: enable or disable */
197 /* Ongoing Update following an OSPF SPF */
200 /* Flooding Scope: Area = 10 or AS = 11 */
204 struct sr_node
*self
;
206 /* List of neighbour SR nodes */
207 struct hash
*neighbors
;
209 /* List of SR prefix */
210 struct route_table
*prefix
;
212 /* Local SR info announced in Router Info LSA */
214 /* Algorithms supported by the node */
215 u_int8_t algo
[ALGORITHM_COUNT
];
217 * Segment Routing Global Block i.e. label range
218 * Only one range supported in this code
221 /* Maximum SID Depth supported by the node */
225 /* Structure aggregating all received SR info from LSAs by 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 */
231 u_int8_t algo
[ALGORITHM_COUNT
]; /* Algorithms supported by the node */
232 /* Segment Routing Global Block i.e. label range */
234 u_int8_t msd
; /* Maximum SID Depth */
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 */
240 /* Pointer to FRR SR-Node or NULL if it is not a neighbor */
241 struct sr_node
*neighbor
;
245 /* Segment Routing - NHLFE info: support IPv4 Only */
247 struct prefix_ipv4 prefv4
;
248 struct in_addr nexthop
;
250 mpls_label_t label_in
;
251 mpls_label_t label_out
;
254 /* Structure aggregating all Segment Routing Link information */
255 /* Link are generally advertised by pair: primary + backup */
257 struct in_addr adv_router
; /* used to identify sender of LSA */
258 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
261 /* Flags to manage this link parameters. */
264 /* Segment Routing ID */
268 /* SR NHLFE for this link */
269 struct sr_nhlfe nhlfe
[2];
271 /* Back pointer to SR Node which advertise this Link */
275 /* Structure aggregating all Segment Routing Prefix information */
277 struct in_addr adv_router
; /* used to identify sender of LSA */
278 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
281 /* Flags to manage this prefix parameters. */
284 /* Segment Routing ID */
288 /* SR NHLFE for this prefix */
289 struct sr_nhlfe nhlfe
;
291 /* Back pointer to SR Node which advertise this Prefix */
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
;
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 */