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 - 2018 Orange Labs http://www.orange.com
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)
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
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
27 #ifndef _FRR_OSPF_SR_H
28 #define _FRR_OSPF_SR_H
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)
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)
44 #define OSPF_SR_DEFAULT_METRIC 1
46 /* Segment Routing TLVs as per draft-ietf-ospf-segment-routing-extensions-19 */
48 /* Segment ID could be a Label (3 bytes) or an Index (4 bytes) */
50 #define SID_LABEL_SIZE(U) (U - 1)
52 #define SID_INDEX_SIZE(U) (U)
54 /* SID/Label Sub TLV - section 2.1 */
55 #define SUBTLV_SID_LABEL 1
56 #define SUBTLV_SID_LABEL_SIZE 8
57 struct subtlv_sid_label
{
58 /* Length is 3 (20 rightmost bits MPLS label) or 4 (32 bits SID) */
59 struct tlv_header header
;
64 * Following section defines Segment Routing TLV (tag, length, value)
65 * structures, used in Router Information Opaque LSA.
68 /* RI SR-Algorithm TLV - section 3.1 */
69 #define RI_SR_TLV_SR_ALGORITHM 8
70 struct 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 */
77 uint8_t value
[ALGORITHM_COUNT
];
80 /* RI SID/Label Range TLV - section 3.2 */
81 #define RI_SR_TLV_SID_LABEL_RANGE 9
82 struct 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
87 /* A SID/Label sub-TLV will follow. */
88 struct subtlv_sid_label lower
;
91 /* RI Node/MSD TLV as per draft-ietf-ospf-segment-routing-msd-05 */
92 #define RI_SR_TLV_NODE_MSD 12
93 struct ri_sr_tlv_node_msd
{
94 struct tlv_header header
;
95 uint8_t subtype
; /* always = 1 */
101 * Following section defines Segment Routing TLV (tag, length, value)
102 * structures, used in Extended Prefix/Link Opaque LSA.
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
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
118 /* SID/Label Binding subtlv Flags */
119 #define EXT_SUBTLV_SID_BINDING_MFLG 0x80
121 /* Extended Prefix Range TLV - section 4 */
122 #define EXT_TLV_PREF_RANGE 2
123 #define EXT_SUBTLV_PREFIX_RANGE_SIZE 12
124 struct ext_tlv_prefix_range
{
125 struct tlv_header header
;
131 struct in_addr address
;
134 /* Prefix SID Sub-TLV - section 5 */
135 #define EXT_SUBTLV_PREFIX_SID 2
136 #define EXT_SUBTLV_PREFIX_SID_SIZE 8
137 struct ext_subtlv_prefix_sid
{
138 struct tlv_header header
;
146 /* Adj-SID Sub-TLV - section 6.1 */
147 #define EXT_SUBTLV_ADJ_SID 2
148 #define EXT_SUBTLV_ADJ_SID_SIZE 8
149 struct ext_subtlv_adj_sid
{
150 struct tlv_header header
;
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
161 struct ext_subtlv_lan_adj_sid
{
162 struct tlv_header header
;
167 struct in_addr neighbor_id
;
172 * Following section define structure used to manage Segment Routing
173 * information and TLVs / SubTLVs
176 /* Structure aggregating SRGB info retrieved from an lsa */
179 uint32_t lower_bound
;
182 /* SID type to make difference between loopback interfaces and others */
183 enum sid_type
{ PREF_SID
, ADJ_SID
, LAN_ADJ_SID
};
185 /* Structure aggregating all OSPF Segment Routing information for the node */
187 /* Status of Segment Routing: enable or disable */
190 /* Ongoing Update following an OSPF SPF */
193 /* Flooding Scope: Area = 10 or AS = 11 */
197 struct sr_node
*self
;
199 /* List of neighbour SR nodes */
200 struct hash
*neighbors
;
202 /* List of SR prefix */
203 struct route_table
*prefix
;
205 /* Local SR info announced in Router Info LSA */
207 /* Algorithms supported by the node */
208 uint8_t algo
[ALGORITHM_COUNT
];
210 * Segment Routing Global Block i.e. label range
211 * Only one range supported in this code
214 /* Maximum SID Depth supported by the node */
218 /* Structure aggregating all received SR info from LSAs by 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 */
224 uint8_t algo
[ALGORITHM_COUNT
]; /* Algorithms supported by the node */
225 /* Segment Routing Global Block i.e. label range */
227 uint8_t msd
; /* Maximum SID Depth */
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 */
233 /* Pointer to FRR SR-Node or NULL if it is not a neighbor */
234 struct sr_node
*neighbor
;
238 /* Segment Routing - NHLFE info: support IPv4 Only */
240 struct prefix_ipv4 prefv4
;
241 struct in_addr nexthop
;
243 mpls_label_t label_in
;
244 mpls_label_t label_out
;
247 /* Structure aggregating all Segment Routing Link information */
248 /* Link are generally advertised by pair: primary + backup */
250 struct in_addr adv_router
; /* used to identify sender of LSA */
251 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
254 /* Flags to manage this link parameters. */
257 /* Segment Routing ID */
261 /* SR NHLFE for this link */
262 struct sr_nhlfe nhlfe
[2];
264 /* Back pointer to SR Node which advertise this Link */
268 /* Structure aggregating all Segment Routing Prefix information */
270 struct in_addr adv_router
; /* used to identify sender of LSA */
271 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
274 /* Flags to manage this prefix parameters. */
277 /* Segment Routing ID */
281 /* SR NHLFE for this prefix */
282 struct sr_nhlfe nhlfe
;
284 /* Back pointer to SR Node which advertise this Prefix */
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
291 struct sr_node
*nexthop
;
294 /* Prototypes definition */
295 /* Segment Routing initialisation functions */
296 extern int ospf_sr_init(void);
297 extern void ospf_sr_term(void);
298 extern void ospf_sr_finish(void);
299 /* Segment Routing LSA update & delete functions */
300 extern void ospf_sr_ri_lsa_update(struct ospf_lsa
*lsa
);
301 extern void ospf_sr_ri_lsa_delete(struct ospf_lsa
*lsa
);
302 extern void ospf_sr_ext_link_lsa_update(struct ospf_lsa
*lsa
);
303 extern void ospf_sr_ext_link_lsa_delete(struct ospf_lsa
*lsa
);
304 extern void ospf_sr_ext_prefix_lsa_update(struct ospf_lsa
*lsa
);
305 extern void ospf_sr_ext_prefix_lsa_delete(struct ospf_lsa
*lsa
);
306 /* Segment Routing configuration functions */
307 extern uint32_t get_ext_link_label_value(void);
308 extern void ospf_sr_config_write_router(struct vty
*vty
);
309 extern void ospf_sr_update_prefix(struct interface
*ifp
, struct prefix
*p
);
310 /* Segment Routing re-routing function */
311 extern void ospf_sr_update_timer_add(struct ospf
*ospf
);
312 #endif /* _FRR_OSPF_SR_H */