]>
Commit | Line | Data |
---|---|---|
26f6acaf | 1 | /* |
f2333421 | 2 | * This is an implementation of Segment Routing for IS-IS as per RFC 8667 |
26f6acaf | 3 | * |
f2333421 | 4 | * Copyright (C) 2019 Orange http://www.orange.com |
26f6acaf RW |
5 | * |
6 | * Author: Olivier Dugeon <olivier.dugeon@orange.com> | |
7 | * Contributor: Renato Westphal <renato@opensourcerouting.org> for NetDEF | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify it | |
10 | * under the terms of the GNU General Public License as published by the Free | |
11 | * Software Foundation; either version 2 of the License, or (at your option) | |
12 | * any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
17 | * more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; see the file COPYING; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
22 | */ | |
23 | ||
24 | #ifndef _FRR_ISIS_SR_H | |
25 | #define _FRR_ISIS_SR_H | |
26 | ||
27 | #include "lib/linklist.h" | |
28 | #include "lib/mpls.h" | |
29 | #include "lib/nexthop.h" | |
30 | #include "lib/typesafe.h" | |
31 | ||
32 | #include "isisd/isis_tlvs.h" | |
33 | ||
34 | /* | |
35 | * Segment Routing information is transported through the following Sub-TLVs: | |
36 | * | |
37 | * Sub-TLV Name Value TLVs | |
38 | * --------------------------------------------------------------------- | |
39 | * SID Label 1 | |
40 | * | |
41 | * Prefix Segment Identifier 3 135, 235, 236 and 237 | |
42 | * | |
43 | * Adjacency Segment Identifier 31 22, 23, 141, 222 and 223 | |
44 | * LAN Adjacency Segment Identifier 32 22, 23, 141, 222 and 223 | |
45 | * | |
46 | * Segment Routing Capability 2 242 | |
47 | * Segment Routing Algorithm 19 242 | |
48 | * Node Maximum Stack Depth (MSD) 23 242 | |
49 | * | |
50 | * Sub-TLV definitions, serialization and de-serialization are defined | |
51 | * in isis_tlvs.[c,h]. | |
52 | */ | |
53 | ||
54 | #define SRGB_LOWER_BOUND 16000 | |
55 | #define SRGB_UPPER_BOUND 23999 | |
d8391312 OD |
56 | #define SRLB_LOWER_BOUND 15000 |
57 | #define SRLB_UPPER_BOUND 15999 | |
26f6acaf | 58 | |
f2333421 | 59 | /* Segment Routing Data Base (SRDB) RB-Tree structure */ |
cab10e86 OD |
60 | PREDECL_RBTREE_UNIQ(srdb_node) |
61 | PREDECL_RBTREE_UNIQ(srdb_node_prefix) | |
62 | PREDECL_RBTREE_UNIQ(srdb_area_prefix) | |
63 | PREDECL_RBTREE_UNIQ(srdb_prefix_cfg) | |
26f6acaf | 64 | |
d8391312 OD |
65 | /* Segment Routing Local Block allocation */ |
66 | struct sr_local_block { | |
58fbcdf2 | 67 | bool active; |
d8391312 OD |
68 | uint32_t start; |
69 | uint32_t end; | |
70 | uint32_t current; | |
71 | uint32_t max_block; | |
72 | uint64_t *used_mark; | |
73 | }; | |
74 | #define SRLB_BLOCK_SIZE 64 | |
75 | ||
f2333421 | 76 | /* Segment Routing Adjacency-SID type. */ |
26f6acaf RW |
77 | enum sr_adj_type { |
78 | ISIS_SR_ADJ_NORMAL = 0, | |
79 | ISIS_SR_LAN_BACKUP, | |
80 | }; | |
81 | ||
f2333421 | 82 | /* Segment Routing Adjacency. */ |
26f6acaf RW |
83 | struct sr_adjacency { |
84 | /* Adjacency type. */ | |
85 | enum sr_adj_type type; | |
86 | ||
f2333421 | 87 | /* Adjacency-SID nexthop information. */ |
26f6acaf RW |
88 | struct { |
89 | int family; | |
90 | union g_addr address; | |
91 | mpls_label_t label; | |
92 | } nexthop; | |
93 | ||
f2333421 | 94 | /* (LAN-)Adjacency-SID Sub-TLV. */ |
26f6acaf RW |
95 | union { |
96 | struct isis_adj_sid *adj_sid; | |
97 | struct isis_lan_adj_sid *ladj_sid; | |
98 | } u; | |
99 | ||
100 | /* Back pointer to IS-IS adjacency. */ | |
101 | struct isis_adjacency *adj; | |
102 | }; | |
103 | ||
f2333421 | 104 | /* Segment Routing Prefix-SID type. */ |
26f6acaf RW |
105 | enum sr_prefix_type { |
106 | ISIS_SR_PREFIX_LOCAL = 0, | |
107 | ISIS_SR_PREFIX_REMOTE, | |
108 | }; | |
109 | ||
f2333421 | 110 | /* Segment Routing Nexthop Information. */ |
26f6acaf RW |
111 | struct sr_nexthop_info { |
112 | mpls_label_t label; | |
113 | time_t uptime; | |
114 | }; | |
115 | ||
cab10e86 OD |
116 | /* State of Object (SR-Node and SR-Prefix) stored in SRDB */ |
117 | enum srdb_state { | |
118 | SRDB_STATE_VALIDATED = 0, | |
119 | SRDB_STATE_NEW, | |
120 | SRDB_STATE_MODIFIED, | |
121 | SRDB_STATE_UNCHANGED | |
122 | }; | |
123 | ||
f2333421 | 124 | /* Segment Routing Prefix-SID. */ |
26f6acaf | 125 | struct sr_prefix { |
f2333421 | 126 | /* SRDB RB-tree entries. */ |
cab10e86 OD |
127 | struct srdb_node_prefix_item node_entry; |
128 | struct srdb_area_prefix_item area_entry; | |
26f6acaf RW |
129 | |
130 | /* IP prefix. */ | |
131 | struct prefix prefix; | |
132 | ||
f2333421 | 133 | /* SID value, algorithm and flags subTLVs. */ |
26f6acaf RW |
134 | struct isis_prefix_sid sid; |
135 | ||
b1d80d43 OD |
136 | /* Input label value. */ |
137 | mpls_label_t input_label; | |
26f6acaf RW |
138 | |
139 | /* Prefix-SID type. */ | |
140 | enum sr_prefix_type type; | |
141 | union { | |
142 | struct { | |
143 | /* Information about this local Prefix-SID. */ | |
144 | struct sr_nexthop_info info; | |
145 | } local; | |
146 | struct { | |
147 | /* Route associated to this remote Prefix-SID. */ | |
148 | struct isis_route_info *rinfo; | |
149 | } remote; | |
150 | } u; | |
151 | ||
f2333421 | 152 | /* Backpointer to Segment Routing node. */ |
26f6acaf RW |
153 | struct sr_node *srn; |
154 | ||
cab10e86 OD |
155 | /* SR-Prefix State used while the LSPDB is being parsed. */ |
156 | enum srdb_state state; | |
26f6acaf RW |
157 | }; |
158 | ||
f2333421 | 159 | /* Segment Routing node. */ |
26f6acaf | 160 | struct sr_node { |
f2333421 | 161 | /* SRDB RB-tree entry. */ |
cab10e86 | 162 | struct srdb_node_item entry; |
26f6acaf RW |
163 | |
164 | /* IS-IS level: ISIS_LEVEL1 or ISIS_LEVEL2. */ | |
165 | int level; | |
166 | ||
167 | /* IS-IS node identifier. */ | |
168 | uint8_t sysid[ISIS_SYS_ID_LEN]; | |
169 | ||
f2333421 | 170 | /* Segment Routing node capabilities (SRGB, SR Algorithms) subTLVs. */ |
26f6acaf RW |
171 | struct isis_router_cap cap; |
172 | ||
173 | /* List of Prefix-SIDs advertised by this node. */ | |
cab10e86 | 174 | struct srdb_node_prefix_head prefix_sids; |
26f6acaf RW |
175 | |
176 | /* Backpointer to IS-IS area. */ | |
177 | struct isis_area *area; | |
178 | ||
cab10e86 OD |
179 | /* SR-Node State used while the LSPDB is being parsed. */ |
180 | enum srdb_state state; | |
26f6acaf RW |
181 | }; |
182 | ||
f2333421 | 183 | /* SID type. NOTE: these values must be in sync with the YANG module. */ |
26f6acaf RW |
184 | enum sr_sid_value_type { |
185 | SR_SID_VALUE_TYPE_INDEX = 0, | |
186 | SR_SID_VALUE_TYPE_ABSOLUTE = 1, | |
187 | }; | |
188 | ||
b407c77a OD |
189 | #define IS_SID_VALUE(flag) CHECK_FLAG(flag, ISIS_PREFIX_SID_VALUE) |
190 | ||
f2333421 | 191 | /* Last Hop Behavior. NOTE: these values must be in sync with the YANG module */ |
26f6acaf RW |
192 | enum sr_last_hop_behavior { |
193 | SR_LAST_HOP_BEHAVIOR_EXP_NULL = 0, | |
194 | SR_LAST_HOP_BEHAVIOR_NO_PHP = 1, | |
195 | SR_LAST_HOP_BEHAVIOR_PHP = 2, | |
196 | }; | |
197 | ||
f2333421 | 198 | /* Segment Routing Prefix-SID configuration. */ |
26f6acaf | 199 | struct sr_prefix_cfg { |
f2333421 | 200 | /* SRDB RB-tree entry. */ |
cab10e86 | 201 | struct srdb_prefix_cfg_item entry; |
26f6acaf RW |
202 | |
203 | /* IP prefix. */ | |
204 | struct prefix prefix; | |
205 | ||
206 | /* SID value. */ | |
207 | uint32_t sid; | |
208 | ||
209 | /* SID value type. */ | |
210 | enum sr_sid_value_type sid_type; | |
211 | ||
212 | /* SID last hop behavior. */ | |
213 | enum sr_last_hop_behavior last_hop_behavior; | |
214 | ||
215 | /* Does this Prefix-SID refer to a loopback address (Node-SID)? */ | |
216 | bool node_sid; | |
217 | ||
218 | /* Backpointer to IS-IS area. */ | |
219 | struct isis_area *area; | |
220 | }; | |
221 | ||
f2333421 | 222 | /* Per-area IS-IS Segment Routing Data Base (SRDB). */ |
26f6acaf | 223 | struct isis_sr_db { |
f2333421 | 224 | /* Global Operational status of Segment Routing. */ |
26f6acaf RW |
225 | bool enabled; |
226 | ||
58fbcdf2 OD |
227 | /* Thread timer to start Label Manager */ |
228 | struct thread *t_start_lm; | |
229 | ||
f2333421 | 230 | /* List of local Adjacency-SIDs. */ |
26f6acaf RW |
231 | struct list *adj_sids; |
232 | ||
f2333421 | 233 | /* Segment Routing Node information per IS-IS level. */ |
cab10e86 | 234 | struct srdb_node_head sr_nodes[ISIS_LEVELS]; |
26f6acaf | 235 | |
f2333421 | 236 | /* Segment Routing Prefix-SIDs per IS-IS level. */ |
cab10e86 | 237 | struct srdb_area_prefix_head prefix_sids[ISIS_LEVELS]; |
26f6acaf | 238 | |
58fbcdf2 | 239 | /* Management of SRLB & SRGB allocation */ |
d8391312 | 240 | struct sr_local_block srlb; |
58fbcdf2 | 241 | bool srgb_active; |
d8391312 | 242 | |
f2333421 | 243 | /* Area Segment Routing configuration. */ |
26f6acaf RW |
244 | struct { |
245 | /* Administrative status of Segment Routing. */ | |
246 | bool enabled; | |
247 | ||
248 | /* Segment Routing Global Block lower & upper bound. */ | |
249 | uint32_t srgb_lower_bound; | |
250 | uint32_t srgb_upper_bound; | |
251 | ||
d8391312 OD |
252 | /* Segment Routing Local Block lower & upper bound. */ |
253 | uint32_t srlb_lower_bound; | |
254 | uint32_t srlb_upper_bound; | |
255 | ||
26f6acaf RW |
256 | /* Maximum SID Depth supported by the node. */ |
257 | uint8_t msd; | |
258 | ||
259 | /* Prefix-SID mappings. */ | |
cab10e86 | 260 | struct srdb_prefix_cfg_head prefix_sids; |
26f6acaf RW |
261 | } config; |
262 | }; | |
263 | ||
264 | /* Prototypes. */ | |
265 | extern int isis_sr_cfg_srgb_update(struct isis_area *area, uint32_t lower_bound, | |
266 | uint32_t upper_bound); | |
d8391312 OD |
267 | extern int isis_sr_cfg_srlb_update(struct isis_area *area, uint32_t lower_bound, |
268 | uint32_t upper_bound); | |
26f6acaf RW |
269 | extern struct sr_prefix_cfg * |
270 | isis_sr_cfg_prefix_add(struct isis_area *area, const struct prefix *prefix); | |
271 | extern void isis_sr_cfg_prefix_del(struct sr_prefix_cfg *pcfg); | |
272 | extern struct sr_prefix_cfg * | |
273 | isis_sr_cfg_prefix_find(struct isis_area *area, union prefixconstptr prefix); | |
274 | extern void isis_sr_prefix_cfg2subtlv(const struct sr_prefix_cfg *pcfg, | |
275 | bool external, | |
276 | struct isis_prefix_sid *psid); | |
277 | extern void isis_sr_nexthop_update(struct sr_nexthop_info *srnh, | |
278 | mpls_label_t label); | |
279 | extern void isis_sr_nexthop_reset(struct sr_nexthop_info *srnh); | |
280 | extern void isis_area_verify_sr(struct isis_area *area); | |
281 | extern int isis_sr_start(struct isis_area *area); | |
282 | extern void isis_sr_stop(struct isis_area *area); | |
283 | extern void isis_sr_area_init(struct isis_area *area); | |
284 | extern void isis_sr_area_term(struct isis_area *area); | |
285 | extern void isis_sr_init(void); | |
286 | extern void isis_sr_term(void); | |
287 | ||
288 | #endif /* _FRR_ISIS_SR_H */ |