]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_sr.h
Merge pull request #6390 from opensourcerouting/bfd-cp-fix
[mirror_frr.git] / isisd / isis_sr.h
1 /*
2 * This is an implementation of Segment Routing for IS-IS as per RFC 8667
3 *
4 * Copyright (C) 2019 Orange http://www.orange.com
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
56
57 /* Segment Routing Data Base (SRDB) RB-Tree structure */
58 PREDECL_RBTREE_UNIQ(srdb_node)
59 PREDECL_RBTREE_UNIQ(srdb_node_prefix)
60 PREDECL_RBTREE_UNIQ(srdb_area_prefix)
61 PREDECL_RBTREE_UNIQ(srdb_prefix_cfg)
62
63 /* Segment Routing Adjacency-SID type. */
64 enum sr_adj_type {
65 ISIS_SR_ADJ_NORMAL = 0,
66 ISIS_SR_LAN_BACKUP,
67 };
68
69 /* Segment Routing Adjacency. */
70 struct sr_adjacency {
71 /* Adjacency type. */
72 enum sr_adj_type type;
73
74 /* Adjacency-SID nexthop information. */
75 struct {
76 int family;
77 union g_addr address;
78 mpls_label_t label;
79 } nexthop;
80
81 /* (LAN-)Adjacency-SID Sub-TLV. */
82 union {
83 struct isis_adj_sid *adj_sid;
84 struct isis_lan_adj_sid *ladj_sid;
85 } u;
86
87 /* Back pointer to IS-IS adjacency. */
88 struct isis_adjacency *adj;
89 };
90
91 /* Segment Routing Prefix-SID type. */
92 enum sr_prefix_type {
93 ISIS_SR_PREFIX_LOCAL = 0,
94 ISIS_SR_PREFIX_REMOTE,
95 };
96
97 /* Segment Routing Nexthop Information. */
98 struct sr_nexthop_info {
99 mpls_label_t label;
100 time_t uptime;
101 };
102
103 /* State of Object (SR-Node and SR-Prefix) stored in SRDB */
104 enum srdb_state {
105 SRDB_STATE_VALIDATED = 0,
106 SRDB_STATE_NEW,
107 SRDB_STATE_MODIFIED,
108 SRDB_STATE_UNCHANGED
109 };
110
111 /* Segment Routing Prefix-SID. */
112 struct sr_prefix {
113 /* SRDB RB-tree entries. */
114 struct srdb_node_prefix_item node_entry;
115 struct srdb_area_prefix_item area_entry;
116
117 /* IP prefix. */
118 struct prefix prefix;
119
120 /* SID value, algorithm and flags subTLVs. */
121 struct isis_prefix_sid sid;
122
123 /* Input label value. */
124 mpls_label_t input_label;
125
126 /* Prefix-SID type. */
127 enum sr_prefix_type type;
128 union {
129 struct {
130 /* Information about this local Prefix-SID. */
131 struct sr_nexthop_info info;
132 } local;
133 struct {
134 /* Route associated to this remote Prefix-SID. */
135 struct isis_route_info *rinfo;
136 } remote;
137 } u;
138
139 /* Backpointer to Segment Routing node. */
140 struct sr_node *srn;
141
142 /* SR-Prefix State used while the LSPDB is being parsed. */
143 enum srdb_state state;
144 };
145
146 /* Segment Routing node. */
147 struct sr_node {
148 /* SRDB RB-tree entry. */
149 struct srdb_node_item entry;
150
151 /* IS-IS level: ISIS_LEVEL1 or ISIS_LEVEL2. */
152 int level;
153
154 /* IS-IS node identifier. */
155 uint8_t sysid[ISIS_SYS_ID_LEN];
156
157 /* Segment Routing node capabilities (SRGB, SR Algorithms) subTLVs. */
158 struct isis_router_cap cap;
159
160 /* List of Prefix-SIDs advertised by this node. */
161 struct srdb_node_prefix_head prefix_sids;
162
163 /* Backpointer to IS-IS area. */
164 struct isis_area *area;
165
166 /* SR-Node State used while the LSPDB is being parsed. */
167 enum srdb_state state;
168 };
169
170 /* SID type. NOTE: these values must be in sync with the YANG module. */
171 enum sr_sid_value_type {
172 SR_SID_VALUE_TYPE_INDEX = 0,
173 SR_SID_VALUE_TYPE_ABSOLUTE = 1,
174 };
175
176 #define IS_SID_VALUE(flag) CHECK_FLAG(flag, ISIS_PREFIX_SID_VALUE)
177
178 /* Last Hop Behavior. NOTE: these values must be in sync with the YANG module */
179 enum sr_last_hop_behavior {
180 SR_LAST_HOP_BEHAVIOR_EXP_NULL = 0,
181 SR_LAST_HOP_BEHAVIOR_NO_PHP = 1,
182 SR_LAST_HOP_BEHAVIOR_PHP = 2,
183 };
184
185 /* Segment Routing Prefix-SID configuration. */
186 struct sr_prefix_cfg {
187 /* SRDB RB-tree entry. */
188 struct srdb_prefix_cfg_item entry;
189
190 /* IP prefix. */
191 struct prefix prefix;
192
193 /* SID value. */
194 uint32_t sid;
195
196 /* SID value type. */
197 enum sr_sid_value_type sid_type;
198
199 /* SID last hop behavior. */
200 enum sr_last_hop_behavior last_hop_behavior;
201
202 /* Does this Prefix-SID refer to a loopback address (Node-SID)? */
203 bool node_sid;
204
205 /* Backpointer to IS-IS area. */
206 struct isis_area *area;
207 };
208
209 /* Per-area IS-IS Segment Routing Data Base (SRDB). */
210 struct isis_sr_db {
211 /* Global Operational status of Segment Routing. */
212 bool enabled;
213
214 /* List of local Adjacency-SIDs. */
215 struct list *adj_sids;
216
217 /* Segment Routing Node information per IS-IS level. */
218 struct srdb_node_head sr_nodes[ISIS_LEVELS];
219
220 /* Segment Routing Prefix-SIDs per IS-IS level. */
221 struct srdb_area_prefix_head prefix_sids[ISIS_LEVELS];
222
223 /* Area Segment Routing configuration. */
224 struct {
225 /* Administrative status of Segment Routing. */
226 bool enabled;
227
228 /* Segment Routing Global Block lower & upper bound. */
229 uint32_t srgb_lower_bound;
230 uint32_t srgb_upper_bound;
231
232 /* Maximum SID Depth supported by the node. */
233 uint8_t msd;
234
235 /* Prefix-SID mappings. */
236 struct srdb_prefix_cfg_head prefix_sids;
237 } config;
238 };
239
240 /* Prototypes. */
241 extern int isis_sr_cfg_srgb_update(struct isis_area *area, uint32_t lower_bound,
242 uint32_t upper_bound);
243 extern struct sr_prefix_cfg *
244 isis_sr_cfg_prefix_add(struct isis_area *area, const struct prefix *prefix);
245 extern void isis_sr_cfg_prefix_del(struct sr_prefix_cfg *pcfg);
246 extern struct sr_prefix_cfg *
247 isis_sr_cfg_prefix_find(struct isis_area *area, union prefixconstptr prefix);
248 extern void isis_sr_prefix_cfg2subtlv(const struct sr_prefix_cfg *pcfg,
249 bool external,
250 struct isis_prefix_sid *psid);
251 extern void isis_sr_nexthop_update(struct sr_nexthop_info *srnh,
252 mpls_label_t label);
253 extern void isis_sr_nexthop_reset(struct sr_nexthop_info *srnh);
254 extern void isis_area_verify_sr(struct isis_area *area);
255 extern int isis_sr_start(struct isis_area *area);
256 extern void isis_sr_stop(struct isis_area *area);
257 extern void isis_sr_area_init(struct isis_area *area);
258 extern void isis_sr_area_term(struct isis_area *area);
259 extern void isis_sr_init(void);
260 extern void isis_sr_term(void);
261
262 #endif /* _FRR_ISIS_SR_H */