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 /* Macro to log debug message */
55 #define osr_debug(...) \
57 if (IS_DEBUG_OSPF_SR) \
58 zlog_debug(__VA_ARGS__); \
61 /* Macro to check if SR Prefix has no valid route */
62 #define IS_NO_ROUTE(srp) ((srp->route == NULL) || (srp->route->paths == NULL) \
63 || list_isempty(srp->route->paths))
65 /* SID/Label Sub TLV - section 2.1 */
66 #define SUBTLV_SID_LABEL 1
67 #define SUBTLV_SID_LABEL_SIZE 8
68 struct subtlv_sid_label
{
69 /* Length is 3 (20 rightmost bits MPLS label) or 4 (32 bits SID) */
70 struct tlv_header header
;
75 * Following section defines Segment Routing TLV (tag, length, value)
76 * structures, used in Router Information Opaque LSA.
79 /* RI SR-Algorithm TLV - section 3.1 */
80 #define RI_SR_TLV_SR_ALGORITHM 8
81 struct ri_sr_tlv_sr_algorithm
{
82 struct tlv_header header
;
83 #define SR_ALGORITHM_SPF 0
84 #define SR_ALGORITHM_STRICT_SPF 1
85 #define SR_ALGORITHM_UNSET 255
86 #define ALGORITHM_COUNT 4
87 /* Only 4 algorithms supported in this code */
88 uint8_t value
[ALGORITHM_COUNT
];
91 /* RI SID/Label Range TLV - section 3.2 */
92 #define RI_SR_TLV_SID_LABEL_RANGE 9
93 struct ri_sr_tlv_sid_label_range
{
94 struct tlv_header header
;
95 /* Only 24 upper most bits are significant */
96 #define SID_RANGE_LABEL_LENGTH 3
98 /* A SID/Label sub-TLV will follow. */
99 struct subtlv_sid_label lower
;
102 /* RI Node/MSD TLV as per draft-ietf-ospf-segment-routing-msd-05 */
103 #define RI_SR_TLV_NODE_MSD 12
104 struct ri_sr_tlv_node_msd
{
105 struct tlv_header header
;
106 uint8_t subtype
; /* always = 1 */
112 * Following section defines Segment Routing TLV (tag, length, value)
113 * structures, used in Extended Prefix/Link Opaque LSA.
116 /* Adj-SID and LAN-Ajd-SID subtlvs' flags */
117 #define EXT_SUBTLV_LINK_ADJ_SID_BFLG 0x80
118 #define EXT_SUBTLV_LINK_ADJ_SID_VFLG 0x40
119 #define EXT_SUBTLV_LINK_ADJ_SID_LFLG 0x20
120 #define EXT_SUBTLV_LINK_ADJ_SID_SFLG 0x10
122 /* Prefix SID subtlv Flags */
123 #define EXT_SUBTLV_PREFIX_SID_NPFLG 0x40
124 #define EXT_SUBTLV_PREFIX_SID_MFLG 0x20
125 #define EXT_SUBTLV_PREFIX_SID_EFLG 0x10
126 #define EXT_SUBTLV_PREFIX_SID_VFLG 0x08
127 #define EXT_SUBTLV_PREFIX_SID_LFLG 0x04
129 /* SID/Label Binding subtlv Flags */
130 #define EXT_SUBTLV_SID_BINDING_MFLG 0x80
132 /* Extended Prefix Range TLV - section 4 */
133 #define EXT_TLV_PREF_RANGE 2
134 #define EXT_SUBTLV_PREFIX_RANGE_SIZE 12
135 struct ext_tlv_prefix_range
{
136 struct tlv_header header
;
142 struct in_addr address
;
145 /* Prefix SID Sub-TLV - section 5 */
146 #define EXT_SUBTLV_PREFIX_SID 2
147 #define EXT_SUBTLV_PREFIX_SID_SIZE 8
148 struct ext_subtlv_prefix_sid
{
149 struct tlv_header header
;
157 /* Adj-SID Sub-TLV - section 6.1 */
158 #define EXT_SUBTLV_ADJ_SID 2
159 #define EXT_SUBTLV_ADJ_SID_SIZE 8
160 struct ext_subtlv_adj_sid
{
161 struct tlv_header header
;
169 /* LAN Adj-SID Sub-TLV - section 6.2 */
170 #define EXT_SUBTLV_LAN_ADJ_SID 3
171 #define EXT_SUBTLV_LAN_ADJ_SID_SIZE 12
172 struct ext_subtlv_lan_adj_sid
{
173 struct tlv_header header
;
178 struct in_addr neighbor_id
;
183 * Following section define structure used to manage Segment Routing
184 * information and TLVs / SubTLVs
187 /* Structure aggregating SRGB info retrieved from an lsa */
190 uint32_t lower_bound
;
193 /* SID type to make difference between loopback interfaces and others */
194 enum sid_type
{ PREF_SID
, LOCAL_SID
, ADJ_SID
, LAN_ADJ_SID
};
196 /* Structure aggregating all OSPF Segment Routing information for the node */
198 /* Status of Segment Routing: enable or disable */
201 /* Flooding Scope: Area = 10 or AS = 11 */
205 struct sr_node
*self
;
207 /* List of neighbour SR nodes */
208 struct hash
*neighbors
;
210 /* List of SR prefix */
211 struct route_table
*prefix
;
213 /* Local SR info announced in Router Info LSA */
215 /* Algorithms supported by the node */
216 uint8_t algo
[ALGORITHM_COUNT
];
218 * Segment Routing Global Block i.e. label range
219 * Only one range supported in this code
222 /* Maximum SID Depth supported by the node */
226 /* Structure aggregating all received SR info from LSAs by node */
228 struct in_addr adv_router
; /* used to identify sender of LSA */
229 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
232 uint8_t algo
[ALGORITHM_COUNT
]; /* Algorithms supported by the node */
233 /* Segment Routing Global Block i.e. label range */
235 uint8_t msd
; /* Maximum SID Depth */
237 /* List of Prefix & Link advertise by this node */
238 struct list
*ext_prefix
; /* For Node SID */
239 struct list
*ext_link
; /* For Adj and LAN SID */
241 /* Pointer to FRR SR-Node or NULL if it is not a neighbor */
242 struct sr_node
*neighbor
;
246 /* Segment Routing - NHLFE info: support IPv4 Only */
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 /* Interface address */
262 struct in_addr itf_addr
;
264 /* Flags to manage this link parameters. */
267 /* Segment Routing ID */
271 /* SR NHLFE (Primary + Backup) for this link */
272 struct sr_nhlfe nhlfe
[2];
274 /* Back pointer to SR Node which advertise this Link */
278 /* Structure aggregating all Segment Routing Prefix information */
280 struct in_addr adv_router
; /* used to identify sender of LSA */
281 /* 24-bit Opaque-ID field value according to RFC 7684 specification */
285 struct prefix_ipv4 prefv4
;
287 /* Flags to manage this prefix parameters. */
290 /* Segment Routing ID */
294 /* Incoming label for this prefix */
295 mpls_label_t label_in
;
297 /* Back pointer to OSPF Route for remote prefix */
298 struct ospf_route
*route
;
300 /* NHLFE for local prefix */
301 struct sr_nhlfe nhlfe
;
303 /* Back pointer to SR Node which advertise this Prefix */
307 /* Prototypes definition */
308 /* Segment Routing initialisation functions */
309 extern int ospf_sr_init(void);
310 extern void ospf_sr_term(void);
311 extern void ospf_sr_finish(void);
312 /* Segment Routing LSA update & delete functions */
313 extern void ospf_sr_ri_lsa_update(struct ospf_lsa
*lsa
);
314 extern void ospf_sr_ri_lsa_delete(struct ospf_lsa
*lsa
);
315 extern void ospf_sr_ext_link_lsa_update(struct ospf_lsa
*lsa
);
316 extern void ospf_sr_ext_link_lsa_delete(struct ospf_lsa
*lsa
);
317 extern void ospf_sr_ext_prefix_lsa_update(struct ospf_lsa
*lsa
);
318 extern void ospf_sr_ext_prefix_lsa_delete(struct ospf_lsa
*lsa
);
319 /* Segment Routing Extending Link management */
321 extern void ospf_sr_ext_itf_add(struct ext_itf
*exti
);
322 extern void ospf_sr_ext_itf_delete(struct ext_itf
*exti
);
323 /* Segment Routing configuration functions */
324 extern uint32_t get_ext_link_label_value(void);
325 extern void ospf_sr_config_write_router(struct vty
*vty
);
326 extern void ospf_sr_update_local_prefix(struct interface
*ifp
,
328 /* Segment Routing re-routing function */
329 extern void ospf_sr_update_task(struct ospf
*ospf
);
330 #endif /* _FRR_OSPF_SR_H */