]>
Commit | Line | Data |
---|---|---|
4d7b695d SM |
1 | /* |
2 | * Copyright (C) 2020 NetDEF, Inc. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of the GNU General Public License as published by the Free | |
6 | * Software Foundation; either version 2 of the License, or (at your option) | |
7 | * any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along | |
15 | * with this program; see the file COPYING; if not, write to the Free Software | |
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | */ | |
18 | ||
19 | #ifndef _FRR_PATHD_H_ | |
20 | #define _FRR_PATHD_H_ | |
21 | ||
c7479286 | 22 | #include "lib/memory.h" |
4d7b695d SM |
23 | #include "lib/mpls.h" |
24 | #include "lib/ipaddr.h" | |
25 | #include "lib/srte.h" | |
26 | #include "lib/hook.h" | |
27 | ||
c7479286 DL |
28 | DECLARE_MGROUP(PATHD); |
29 | ||
4d7b695d SM |
30 | enum srte_protocol_origin { |
31 | SRTE_ORIGIN_UNDEFINED = 0, | |
32 | SRTE_ORIGIN_PCEP = 1, | |
33 | SRTE_ORIGIN_BGP = 2, | |
34 | SRTE_ORIGIN_LOCAL = 3, | |
35 | }; | |
36 | ||
37 | enum srte_policy_status { | |
38 | SRTE_POLICY_STATUS_UNKNOWN = 0, | |
39 | SRTE_POLICY_STATUS_DOWN = 1, | |
40 | SRTE_POLICY_STATUS_UP = 2, | |
41 | SRTE_POLICY_STATUS_GOING_DOWN = 3, | |
42 | SRTE_POLICY_STATUS_GOING_UP = 4 | |
43 | }; | |
44 | ||
45 | enum srte_candidate_type { | |
46 | SRTE_CANDIDATE_TYPE_UNDEFINED = 0, | |
47 | SRTE_CANDIDATE_TYPE_EXPLICIT = 1, | |
48 | SRTE_CANDIDATE_TYPE_DYNAMIC = 2, | |
49 | }; | |
50 | ||
51 | enum srte_candidate_metric_type { | |
52 | /* IGP metric */ | |
53 | SRTE_CANDIDATE_METRIC_TYPE_IGP = 1, | |
54 | /* TE metric */ | |
55 | SRTE_CANDIDATE_METRIC_TYPE_TE = 2, | |
56 | /* Hop Counts */ | |
57 | SRTE_CANDIDATE_METRIC_TYPE_HC = 3, | |
58 | /* Aggregate bandwidth consumption */ | |
59 | SRTE_CANDIDATE_METRIC_TYPE_ABC = 4, | |
60 | /* Load of the most loaded link */ | |
61 | SRTE_CANDIDATE_METRIC_TYPE_LMLL = 5, | |
62 | /* Cumulative IGP cost */ | |
63 | SRTE_CANDIDATE_METRIC_TYPE_CIGP = 6, | |
64 | /* Cumulative TE cost */ | |
65 | SRTE_CANDIDATE_METRIC_TYPE_CTE = 7, | |
66 | /* P2MP IGP metric */ | |
67 | SRTE_CANDIDATE_METRIC_TYPE_PIGP = 8, | |
68 | /* P2MP TE metric */ | |
69 | SRTE_CANDIDATE_METRIC_TYPE_PTE = 9, | |
70 | /* P2MP hop count metric */ | |
71 | SRTE_CANDIDATE_METRIC_TYPE_PHC = 10, | |
72 | /* Segment-ID (SID) Depth */ | |
73 | SRTE_CANDIDATE_METRIC_TYPE_MSD = 11, | |
74 | /* Path Delay metric */ | |
75 | SRTE_CANDIDATE_METRIC_TYPE_PD = 12, | |
76 | /* Path Delay Variation metric */ | |
77 | SRTE_CANDIDATE_METRIC_TYPE_PDV = 13, | |
78 | /* Path Loss metric */ | |
79 | SRTE_CANDIDATE_METRIC_TYPE_PL = 14, | |
80 | /* P2MP Path Delay metric */ | |
81 | SRTE_CANDIDATE_METRIC_TYPE_PPD = 15, | |
82 | /* P2MP Path Delay variation metric */ | |
83 | SRTE_CANDIDATE_METRIC_TYPE_PPDV = 16, | |
84 | /* P2MP Path Loss metric */ | |
85 | SRTE_CANDIDATE_METRIC_TYPE_PPL = 17, | |
86 | /* Number of adaptations on a path */ | |
87 | SRTE_CANDIDATE_METRIC_TYPE_NAP = 18, | |
88 | /* Number of layers on a path */ | |
89 | SRTE_CANDIDATE_METRIC_TYPE_NLP = 19, | |
90 | /* Domain Count metric */ | |
91 | SRTE_CANDIDATE_METRIC_TYPE_DC = 20, | |
92 | /* Border Node Count metric */ | |
93 | SRTE_CANDIDATE_METRIC_TYPE_BNC = 21, | |
94 | }; | |
95 | #define MAX_METRIC_TYPE 21 | |
96 | ||
97 | enum srte_segment_nai_type { | |
98 | SRTE_SEGMENT_NAI_TYPE_NONE = 0, | |
99 | SRTE_SEGMENT_NAI_TYPE_IPV4_NODE = 1, | |
100 | SRTE_SEGMENT_NAI_TYPE_IPV6_NODE = 2, | |
101 | SRTE_SEGMENT_NAI_TYPE_IPV4_ADJACENCY = 3, | |
102 | SRTE_SEGMENT_NAI_TYPE_IPV6_ADJACENCY = 4, | |
103 | SRTE_SEGMENT_NAI_TYPE_IPV4_UNNUMBERED_ADJACENCY = 5 | |
104 | }; | |
105 | ||
106 | enum objfun_type { | |
107 | OBJFUN_UNDEFINED = 0, | |
108 | /* Minimum Cost Path [RFC5541] */ | |
109 | OBJFUN_MCP = 1, | |
110 | /* Minimum Load Path [RFC5541] */ | |
111 | OBJFUN_MLP = 2, | |
112 | /* Maximum residual Bandwidth Path [RFC5541] */ | |
113 | OBJFUN_MBP = 3, | |
114 | /* Minimize aggregate Bandwidth Consumption [RFC5541] */ | |
115 | OBJFUN_MBC = 4, | |
116 | /* Minimize the Load of the most loaded Link [RFC5541] */ | |
117 | OBJFUN_MLL = 5, | |
118 | /* Minimize the Cumulative Cost of a set of paths [RFC5541] */ | |
119 | OBJFUN_MCC = 6, | |
120 | /* Shortest Path Tree [RFC8306] */ | |
121 | OBJFUN_SPT = 7, | |
122 | /* Minimum Cost Tree [RFC8306] */ | |
123 | OBJFUN_MCT = 8, | |
124 | /* Minimum Packet Loss Path [RFC8233] */ | |
125 | OBJFUN_MPLP = 9, | |
126 | /* Maximum Under-Utilized Path [RFC8233] */ | |
127 | OBJFUN_MUP = 10, | |
128 | /* Maximum Reserved Under-Utilized Path [RFC8233] */ | |
129 | OBJFUN_MRUP = 11, | |
130 | /* Minimize the number of Transit Domains [RFC8685] */ | |
131 | OBJFUN_MTD = 12, | |
132 | /* Minimize the number of Border Nodes [RFC8685] */ | |
133 | OBJFUN_MBN = 13, | |
134 | /* Minimize the number of Common Transit Domains [RFC8685] */ | |
135 | OBJFUN_MCTD = 14, | |
136 | /* Minimize the number of Shared Links [RFC8800] */ | |
137 | OBJFUN_MSL = 15, | |
138 | /* Minimize the number of Shared SRLGs [RFC8800] */ | |
139 | OBJFUN_MSS = 16, | |
140 | /* Minimize the number of Shared Nodes [RFC8800] */ | |
141 | OBJFUN_MSN = 17, | |
142 | }; | |
143 | #define MAX_OBJFUN_TYPE 17 | |
144 | ||
145 | enum affinity_filter_type { | |
146 | AFFINITY_FILTER_UNDEFINED = 0, | |
147 | AFFINITY_FILTER_EXCLUDE_ANY = 1, | |
148 | AFFINITY_FILTER_INCLUDE_ANY = 2, | |
149 | AFFINITY_FILTER_INCLUDE_ALL = 3, | |
150 | }; | |
151 | #define MAX_AFFINITY_FILTER_TYPE 3 | |
152 | ||
153 | struct srte_segment_list; | |
154 | ||
155 | struct srte_segment_entry { | |
156 | RB_ENTRY(srte_segment_entry) entry; | |
157 | ||
158 | /* The segment list the entry belong to */ | |
159 | struct srte_segment_list *segment_list; | |
160 | ||
161 | /* Index of the Label. */ | |
162 | uint32_t index; | |
163 | ||
164 | /* Label Value. */ | |
165 | mpls_label_t sid_value; | |
166 | ||
167 | /* NAI Type */ | |
168 | enum srte_segment_nai_type nai_type; | |
169 | /* NAI local address when nai type is not NONE */ | |
170 | struct ipaddr nai_local_addr; | |
171 | /* NAI local interface when nai type is not IPv4 unnumbered adjacency */ | |
172 | uint32_t nai_local_iface; | |
173 | /* NAI local interface when nai type is IPv4 or IPv6 adjacency */ | |
174 | struct ipaddr nai_remote_addr; | |
175 | /* NAI remote interface when nai type is not IPv4 unnumbered adjacency | |
176 | */ | |
177 | uint32_t nai_remote_iface; | |
178 | }; | |
179 | RB_HEAD(srte_segment_entry_head, srte_segment_entry); | |
180 | RB_PROTOTYPE(srte_segment_entry_head, srte_segment_entry, entry, | |
181 | srte_segment_entry_compare) | |
182 | ||
183 | struct srte_segment_list { | |
184 | RB_ENTRY(srte_segment_list) entry; | |
185 | ||
186 | /* Name of the Segment List. */ | |
187 | char name[64]; | |
188 | ||
189 | /* The Protocol-Origin. */ | |
190 | enum srte_protocol_origin protocol_origin; | |
191 | ||
192 | /* The Originator */ | |
193 | char originator[64]; | |
194 | ||
195 | /* Nexthops. */ | |
196 | struct srte_segment_entry_head segments; | |
197 | ||
198 | /* Status flags. */ | |
199 | uint16_t flags; | |
200 | #define F_SEGMENT_LIST_NEW 0x0002 | |
201 | #define F_SEGMENT_LIST_MODIFIED 0x0004 | |
202 | #define F_SEGMENT_LIST_DELETED 0x0008 | |
203 | }; | |
204 | RB_HEAD(srte_segment_list_head, srte_segment_list); | |
205 | RB_PROTOTYPE(srte_segment_list_head, srte_segment_list, entry, | |
206 | srte_segment_list_compare) | |
207 | ||
208 | struct srte_metric { | |
209 | uint16_t flags; | |
210 | #define F_METRIC_IS_DEFINED 0x0001 | |
211 | #define F_METRIC_IS_REQUIRED 0x0002 | |
212 | #define F_METRIC_IS_BOUND 0x0004 | |
213 | #define F_METRIC_IS_COMPUTED 0x0008 | |
214 | float value; | |
215 | }; | |
216 | ||
217 | /* Runtime information about the candidate path */ | |
218 | struct srte_lsp { | |
219 | /* Backpointer to the Candidate Path. */ | |
220 | struct srte_candidate *candidate; | |
221 | ||
222 | /* The associated Segment List. */ | |
223 | struct srte_segment_list *segment_list; | |
224 | ||
225 | /* The Protocol-Origin. */ | |
226 | enum srte_protocol_origin protocol_origin; | |
227 | ||
228 | /* The Originator */ | |
229 | char originator[64]; | |
230 | ||
231 | /* The Discriminator */ | |
232 | uint32_t discriminator; | |
233 | ||
234 | /* Flags. */ | |
235 | uint32_t flags; | |
236 | ||
237 | /* Metrics LSP Values */ | |
238 | struct srte_metric metrics[MAX_METRIC_TYPE]; | |
239 | ||
240 | /* Bandwidth Configured Value */ | |
241 | float bandwidth; | |
242 | ||
243 | /* The objective function in used */ | |
244 | enum objfun_type objfun; | |
245 | }; | |
246 | ||
247 | /* Configured candidate path */ | |
248 | struct srte_candidate { | |
249 | RB_ENTRY(srte_candidate) entry; | |
250 | ||
251 | /* Backpointer to SR Policy */ | |
252 | struct srte_policy *policy; | |
253 | ||
254 | /* The LSP associated with this candidate path. */ | |
255 | struct srte_lsp *lsp; | |
256 | ||
257 | /* Administrative preference. */ | |
258 | uint32_t preference; | |
259 | ||
260 | /* Symbolic Name. */ | |
261 | char name[64]; | |
262 | ||
263 | /* The associated Segment List. */ | |
264 | struct srte_segment_list *segment_list; | |
265 | ||
266 | /* The Protocol-Origin. */ | |
267 | enum srte_protocol_origin protocol_origin; | |
268 | ||
269 | /* The Originator */ | |
270 | char originator[64]; | |
271 | ||
272 | /* The Discriminator */ | |
273 | uint32_t discriminator; | |
274 | ||
275 | /* The Type (explicit or dynamic) */ | |
276 | enum srte_candidate_type type; | |
277 | ||
278 | /* Flags. */ | |
279 | uint32_t flags; | |
280 | #define F_CANDIDATE_BEST 0x0001 | |
281 | #define F_CANDIDATE_NEW 0x0002 | |
282 | #define F_CANDIDATE_MODIFIED 0x0004 | |
283 | #define F_CANDIDATE_DELETED 0x0008 | |
284 | #define F_CANDIDATE_HAS_BANDWIDTH 0x0100 | |
285 | #define F_CANDIDATE_REQUIRED_BANDWIDTH 0x0200 | |
286 | #define F_CANDIDATE_HAS_OBJFUN 0x0400 | |
287 | #define F_CANDIDATE_REQUIRED_OBJFUN 0x0800 | |
288 | #define F_CANDIDATE_HAS_EXCLUDE_ANY 0x1000 | |
289 | #define F_CANDIDATE_HAS_INCLUDE_ANY 0x2000 | |
290 | #define F_CANDIDATE_HAS_INCLUDE_ALL 0x4000 | |
291 | ||
292 | /* Metrics Configured Values */ | |
293 | struct srte_metric metrics[MAX_METRIC_TYPE]; | |
294 | ||
295 | /* Bandwidth Configured Value */ | |
296 | float bandwidth; | |
297 | ||
298 | /* Configured objective functions */ | |
299 | enum objfun_type objfun; | |
300 | ||
301 | /* Path constraints attribute filters */ | |
302 | uint32_t affinity_filters[MAX_AFFINITY_FILTER_TYPE]; | |
303 | ||
304 | /* Hooks delaying timer */ | |
305 | struct thread *hook_timer; | |
306 | }; | |
307 | ||
308 | RB_HEAD(srte_candidate_head, srte_candidate); | |
309 | RB_PROTOTYPE(srte_candidate_head, srte_candidate, entry, srte_candidate_compare) | |
310 | ||
311 | struct srte_policy { | |
312 | RB_ENTRY(srte_policy) entry; | |
313 | ||
314 | /* Color */ | |
315 | uint32_t color; | |
316 | ||
317 | /* Endpoint */ | |
318 | struct ipaddr endpoint; | |
319 | ||
320 | /* Name */ | |
321 | char name[64]; | |
322 | ||
323 | /* Binding SID */ | |
324 | mpls_label_t binding_sid; | |
325 | ||
326 | /* Operational Status of the policy */ | |
327 | enum srte_policy_status status; | |
328 | ||
329 | /* Best candidate path. */ | |
330 | struct srte_candidate *best_candidate; | |
331 | ||
332 | /* Candidate Paths */ | |
333 | struct srte_candidate_head candidate_paths; | |
334 | /* Status flags. */ | |
335 | uint16_t flags; | |
336 | #define F_POLICY_NEW 0x0002 | |
337 | #define F_POLICY_MODIFIED 0x0004 | |
338 | #define F_POLICY_DELETED 0x0008 | |
339 | }; | |
340 | RB_HEAD(srte_policy_head, srte_policy); | |
341 | RB_PROTOTYPE(srte_policy_head, srte_policy, entry, srte_policy_compare) | |
342 | ||
343 | DECLARE_HOOK(pathd_candidate_created, (struct srte_candidate * candidate), | |
8451921b | 344 | (candidate)); |
4d7b695d | 345 | DECLARE_HOOK(pathd_candidate_updated, (struct srte_candidate * candidate), |
8451921b | 346 | (candidate)); |
4d7b695d | 347 | DECLARE_HOOK(pathd_candidate_removed, (struct srte_candidate * candidate), |
8451921b | 348 | (candidate)); |
4d7b695d SM |
349 | |
350 | extern struct srte_segment_list_head srte_segment_lists; | |
351 | extern struct srte_policy_head srte_policies; | |
352 | extern struct zebra_privs_t pathd_privs; | |
353 | ||
354 | /* master thread, defined in path_main.c */ | |
355 | extern struct thread_master *master; | |
356 | ||
357 | /* pathd.c */ | |
358 | struct srte_segment_list *srte_segment_list_add(const char *name); | |
359 | void srte_segment_list_del(struct srte_segment_list *segment_list); | |
360 | struct srte_segment_list *srte_segment_list_find(const char *name); | |
361 | struct srte_segment_entry * | |
362 | srte_segment_entry_add(struct srte_segment_list *segment_list, uint32_t index); | |
363 | void srte_segment_entry_del(struct srte_segment_entry *segment); | |
364 | void srte_segment_entry_set_nai(struct srte_segment_entry *segment, | |
365 | enum srte_segment_nai_type type, | |
366 | struct ipaddr *local_ip, uint32_t local_iface, | |
367 | struct ipaddr *remote_ip, | |
368 | uint32_t remote_iface); | |
369 | struct srte_policy *srte_policy_add(uint32_t color, struct ipaddr *endpoint); | |
370 | void srte_policy_del(struct srte_policy *policy); | |
371 | struct srte_policy *srte_policy_find(uint32_t color, struct ipaddr *endpoint); | |
372 | void srte_policy_update_binding_sid(struct srte_policy *policy, | |
373 | uint32_t binding_sid); | |
374 | void srte_apply_changes(void); | |
375 | void srte_policy_apply_changes(struct srte_policy *policy); | |
376 | struct srte_candidate *srte_candidate_add(struct srte_policy *policy, | |
377 | uint32_t preference); | |
378 | void srte_candidate_del(struct srte_candidate *candidate); | |
379 | void srte_candidate_set_bandwidth(struct srte_candidate *candidate, | |
380 | float bandwidth, bool required); | |
381 | void srte_candidate_unset_bandwidth(struct srte_candidate *candidate); | |
382 | void srte_candidate_set_metric(struct srte_candidate *candidate, | |
383 | enum srte_candidate_metric_type type, | |
384 | float value, bool required, bool is_cound, | |
385 | bool is_computed); | |
386 | void srte_candidate_unset_metric(struct srte_candidate *candidate, | |
387 | enum srte_candidate_metric_type type); | |
388 | void srte_candidate_set_objfun(struct srte_candidate *candidate, bool required, | |
389 | enum objfun_type type); | |
390 | void srte_candidate_unset_objfun(struct srte_candidate *candidate); | |
391 | void srte_candidate_set_affinity_filter(struct srte_candidate *candidate, | |
392 | enum affinity_filter_type type, | |
393 | uint32_t filter); | |
394 | void srte_candidate_unset_affinity_filter(struct srte_candidate *candidate, | |
395 | enum affinity_filter_type type); | |
396 | void srte_lsp_set_bandwidth(struct srte_lsp *lsp, float bandwidth, | |
397 | bool required); | |
398 | void srte_lsp_unset_bandwidth(struct srte_lsp *lsp); | |
399 | void srte_lsp_set_metric(struct srte_lsp *lsp, | |
400 | enum srte_candidate_metric_type type, float value, | |
401 | bool required, bool is_cound, bool is_computed); | |
402 | void srte_lsp_unset_metric(struct srte_lsp *lsp, | |
403 | enum srte_candidate_metric_type type); | |
404 | struct srte_candidate *srte_candidate_find(struct srte_policy *policy, | |
405 | uint32_t preference); | |
406 | struct srte_segment_entry * | |
407 | srte_segment_entry_find(struct srte_segment_list *segment_list, uint32_t index); | |
408 | void srte_candidate_status_update(struct srte_candidate *candidate, int status); | |
409 | void srte_candidate_unset_segment_list(const char *originator, bool force); | |
410 | const char *srte_origin2str(enum srte_protocol_origin origin); | |
411 | ||
412 | /* path_cli.c */ | |
413 | void path_cli_init(void); | |
414 | ||
415 | #endif /* _FRR_PATHD_H_ */ |