1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * This is an implementation of Segment Routing for IS-IS as per RFC 8667
5 * Copyright (C) 2019 Orange http://www.orange.com
7 * Author: Olivier Dugeon <olivier.dugeon@orange.com>
8 * Contributor: Renato Westphal <renato@opensourcerouting.org> for NetDEF
11 #ifndef _FRR_ISIS_SR_H
12 #define _FRR_ISIS_SR_H
14 #include "lib/linklist.h"
16 #include "lib/nexthop.h"
17 #include "lib/typesafe.h"
19 #include "isisd/isis_tlvs.h"
22 * Segment Routing information is transported through the following Sub-TLVs:
24 * Sub-TLV Name Value TLVs
25 * ---------------------------------------------------------------------
28 * Prefix Segment Identifier 3 135, 235, 236 and 237
30 * Adjacency Segment Identifier 31 22, 23, 141, 222 and 223
31 * LAN Adjacency Segment Identifier 32 22, 23, 141, 222 and 223
33 * Segment Routing Capability 2 242
34 * Segment Routing Algorithm 19 242
35 * Node Maximum Stack Depth (MSD) 23 242
37 * Sub-TLV definitions, serialization and de-serialization are defined
41 #define SRGB_LOWER_BOUND 16000
42 #define SRGB_UPPER_BOUND 23999
43 #define SRLB_LOWER_BOUND 15000
44 #define SRLB_UPPER_BOUND 15999
46 /* Segment Routing Data Base (SRDB) RB-Tree structure */
47 PREDECL_RBTREE_UNIQ(srdb_prefix_cfg
);
50 * Segment Routing Prefix-SID information.
52 * This structure is intended to be embedded inside other structures that
53 * might or might not contain Prefix-SID information.
55 struct isis_sr_psid_info
{
56 /* Prefix-SID Sub-TLV information. */
57 struct isis_prefix_sid sid
;
59 /* Resolved input/output label. */
62 /* Indicates whether the Prefix-SID is present or not. */
66 /* Segment Routing Local Block allocation */
67 struct sr_local_block
{
75 #define SRLB_BLOCK_SIZE 64
77 /* Segment Routing Adjacency-SID type. */
79 ISIS_SR_ADJ_NORMAL
= 0,
83 /* Segment Routing Adjacency. */
86 enum sr_adj_type type
;
88 /* Adjacency-SID input label. */
89 mpls_label_t input_label
;
91 /* Adjacency-SID nexthop information. */
97 /* Adjacency-SID TI-LFA backup nexthops. */
98 struct list
*backup_nexthops
;
100 /* (LAN-)Adjacency-SID Sub-TLV. */
102 struct isis_adj_sid
*adj_sid
;
103 struct isis_lan_adj_sid
*ladj_sid
;
106 /* Back pointer to IS-IS adjacency. */
107 struct isis_adjacency
*adj
;
110 /* SID type. NOTE: these values must be in sync with the YANG module. */
111 enum sr_sid_value_type
{
112 SR_SID_VALUE_TYPE_INDEX
= 0,
113 SR_SID_VALUE_TYPE_ABSOLUTE
= 1,
116 #define IS_SID_VALUE(flag) CHECK_FLAG(flag, ISIS_PREFIX_SID_VALUE)
118 /* Last Hop Behavior. NOTE: these values must be in sync with the YANG module */
119 enum sr_last_hop_behavior
{
120 SR_LAST_HOP_BEHAVIOR_EXP_NULL
= 0,
121 SR_LAST_HOP_BEHAVIOR_NO_PHP
= 1,
122 SR_LAST_HOP_BEHAVIOR_PHP
= 2,
125 /* Segment Routing Prefix-SID configuration. */
126 struct sr_prefix_cfg
{
127 /* SRDB RB-tree entry. */
128 struct srdb_prefix_cfg_item entry
;
131 struct prefix prefix
;
136 /* SID value type. */
137 enum sr_sid_value_type sid_type
;
139 /* SID last hop behavior. */
140 enum sr_last_hop_behavior last_hop_behavior
;
142 /* Indicates whether the node flag must be explicitly unset. */
145 /* Does this Prefix-SID refer to a loopback address (Node-SID)? */
148 /* Backpointer to IS-IS area. */
149 struct isis_area
*area
;
152 /* Per-area IS-IS Segment Routing Data Base (SRDB). */
154 /* Global Operational status of Segment Routing. */
157 /* Thread timer to start Label Manager */
158 struct thread
*t_start_lm
;
160 /* List of local Adjacency-SIDs. */
161 struct list
*adj_sids
;
163 /* Management of SRLB & SRGB allocation */
164 struct sr_local_block srlb
;
167 /* Area Segment Routing configuration. */
169 /* Administrative status of Segment Routing. */
172 /* Segment Routing Global Block lower & upper bound. */
173 uint32_t srgb_lower_bound
;
174 uint32_t srgb_upper_bound
;
176 /* Segment Routing Local Block lower & upper bound. */
177 uint32_t srlb_lower_bound
;
178 uint32_t srlb_upper_bound
;
180 /* Maximum SID Depth supported by the node. */
183 /* Prefix-SID mappings. */
184 struct srdb_prefix_cfg_head prefix_sids
;
189 extern struct isis_sr_block
*isis_sr_find_srgb(struct lspdb_head
*lspdb
,
190 const uint8_t *sysid
);
191 extern mpls_label_t
sr_prefix_in_label(struct isis_area
*area
,
192 struct isis_prefix_sid
*psid
,
194 extern mpls_label_t
sr_prefix_out_label(struct lspdb_head
*lspdb
, int family
,
195 struct isis_prefix_sid
*psid
,
196 const uint8_t *nh_sysid
, bool last_hop
);
197 extern int isis_sr_cfg_srgb_update(struct isis_area
*area
, uint32_t lower_bound
,
198 uint32_t upper_bound
);
199 extern int isis_sr_cfg_srlb_update(struct isis_area
*area
, uint32_t lower_bound
,
200 uint32_t upper_bound
);
201 extern struct sr_prefix_cfg
*
202 isis_sr_cfg_prefix_add(struct isis_area
*area
, const struct prefix
*prefix
);
203 extern void isis_sr_cfg_prefix_del(struct sr_prefix_cfg
*pcfg
);
204 extern struct sr_prefix_cfg
*
205 isis_sr_cfg_prefix_find(struct isis_area
*area
, union prefixconstptr prefix
);
206 extern void isis_sr_prefix_cfg2subtlv(const struct sr_prefix_cfg
*pcfg
,
208 struct isis_prefix_sid
*psid
);
209 extern void sr_adj_sid_add_single(struct isis_adjacency
*adj
, int family
,
210 bool backup
, struct list
*nexthops
);
211 extern struct sr_adjacency
*isis_sr_adj_sid_find(struct isis_adjacency
*adj
,
213 enum sr_adj_type type
);
214 extern void isis_area_delete_backup_adj_sids(struct isis_area
*area
, int level
);
215 extern char *sr_op2str(char *buf
, size_t size
, mpls_label_t label_in
,
216 mpls_label_t label_out
);
217 extern int isis_sr_start(struct isis_area
*area
);
218 extern void isis_sr_stop(struct isis_area
*area
);
219 extern void isis_sr_area_init(struct isis_area
*area
);
220 extern void isis_sr_area_term(struct isis_area
*area
);
221 extern void isis_sr_init(void);
222 extern void isis_sr_term(void);
224 #endif /* _FRR_ISIS_SR_H */