]> git.proxmox.com Git - mirror_frr.git/blob - pathd/pathd.h
Merge pull request #13060 from opensourcerouting/feature/allow_peering_with_127.0.0.1
[mirror_frr.git] / pathd / pathd.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2020 NetDEF, Inc.
4 */
5
6 #ifndef _FRR_PATHD_H_
7 #define _FRR_PATHD_H_
8
9 #include "lib/memory.h"
10 #include "lib/mpls.h"
11 #include "lib/ipaddr.h"
12 #include "lib/srte.h"
13 #include "lib/hook.h"
14 #include "lib/prefix.h"
15
16 #define PATH_SID_ERROR 1
17 #define PATH_SID_NO_ERROR 0
18 #define CHECK_SID(or, ts, es) \
19 ((or == SRTE_ORIGIN_PCEP && (ts == MPLS_LABEL_NONE || es != ts)) \
20 || (or == SRTE_ORIGIN_LOCAL && ts == MPLS_LABEL_NONE))
21
22 DECLARE_MGROUP(PATHD);
23
24 DECLARE_HOOK(pathd_srte_config_write, (struct vty *vty), (vty));
25
26 enum srte_protocol_origin {
27 SRTE_ORIGIN_UNDEFINED = 0,
28 SRTE_ORIGIN_PCEP = 1,
29 SRTE_ORIGIN_BGP = 2,
30 SRTE_ORIGIN_LOCAL = 3,
31 };
32
33 extern struct debug path_policy_debug;
34
35 #define PATH_POLICY_DEBUG_BASIC 0x01
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 SRTE_SEGMENT_NAI_TYPE_IPV6_ADJACENCY_LINK_LOCAL_ADDRESSES = 6,
105 SRTE_SEGMENT_NAI_TYPE_IPV4_LOCAL_IFACE = 7,
106 SRTE_SEGMENT_NAI_TYPE_IPV6_LOCAL_IFACE = 8,
107 SRTE_SEGMENT_NAI_TYPE_IPV4_ALGORITHM = 9,
108 SRTE_SEGMENT_NAI_TYPE_IPV6_ALGORITHM = 10
109 };
110
111 enum objfun_type {
112 OBJFUN_UNDEFINED = 0,
113 /* Minimum Cost Path [RFC5541] */
114 OBJFUN_MCP = 1,
115 /* Minimum Load Path [RFC5541] */
116 OBJFUN_MLP = 2,
117 /* Maximum residual Bandwidth Path [RFC5541] */
118 OBJFUN_MBP = 3,
119 /* Minimize aggregate Bandwidth Consumption [RFC5541] */
120 OBJFUN_MBC = 4,
121 /* Minimize the Load of the most loaded Link [RFC5541] */
122 OBJFUN_MLL = 5,
123 /* Minimize the Cumulative Cost of a set of paths [RFC5541] */
124 OBJFUN_MCC = 6,
125 /* Shortest Path Tree [RFC8306] */
126 OBJFUN_SPT = 7,
127 /* Minimum Cost Tree [RFC8306] */
128 OBJFUN_MCT = 8,
129 /* Minimum Packet Loss Path [RFC8233] */
130 OBJFUN_MPLP = 9,
131 /* Maximum Under-Utilized Path [RFC8233] */
132 OBJFUN_MUP = 10,
133 /* Maximum Reserved Under-Utilized Path [RFC8233] */
134 OBJFUN_MRUP = 11,
135 /* Minimize the number of Transit Domains [RFC8685] */
136 OBJFUN_MTD = 12,
137 /* Minimize the number of Border Nodes [RFC8685] */
138 OBJFUN_MBN = 13,
139 /* Minimize the number of Common Transit Domains [RFC8685] */
140 OBJFUN_MCTD = 14,
141 /* Minimize the number of Shared Links [RFC8800] */
142 OBJFUN_MSL = 15,
143 /* Minimize the number of Shared SRLGs [RFC8800] */
144 OBJFUN_MSS = 16,
145 /* Minimize the number of Shared Nodes [RFC8800] */
146 OBJFUN_MSN = 17,
147 };
148 #define MAX_OBJFUN_TYPE 17
149
150 enum affinity_filter_type {
151 AFFINITY_FILTER_UNDEFINED = 0,
152 AFFINITY_FILTER_EXCLUDE_ANY = 1,
153 AFFINITY_FILTER_INCLUDE_ANY = 2,
154 AFFINITY_FILTER_INCLUDE_ALL = 3,
155 };
156 #define MAX_AFFINITY_FILTER_TYPE 3
157
158 struct srte_segment_list;
159
160 struct srte_segment_entry {
161 RB_ENTRY(srte_segment_entry) entry;
162
163 /* The segment list the entry belong to */
164 struct srte_segment_list *segment_list;
165
166 /* Index of the Label. */
167 uint32_t index;
168
169 /* Label Value. */
170 mpls_label_t sid_value;
171
172 /* NAI Type */
173 enum srte_segment_nai_type nai_type;
174 /* NAI local address when nai type is not NONE */
175 struct ipaddr nai_local_addr;
176 /* NAI local interface when nai type is not IPv4 unnumbered adjacency */
177 uint32_t nai_local_iface;
178 /* NAI local interface when nai type is IPv4 or IPv6 adjacency */
179 struct ipaddr nai_remote_addr;
180 /* NAI remote interface when nai type is not IPv4 unnumbered adjacency
181 */
182 uint32_t nai_remote_iface;
183 /* Support draft-ietf-spring-segment-routing-policy sl types queries*/
184 uint8_t nai_local_prefix_len;
185 uint8_t nai_algorithm;
186 };
187 RB_HEAD(srte_segment_entry_head, srte_segment_entry);
188 RB_PROTOTYPE(srte_segment_entry_head, srte_segment_entry, entry,
189 srte_segment_entry_compare)
190
191 struct srte_segment_list {
192 RB_ENTRY(srte_segment_list) entry;
193
194 /* Name of the Segment List. */
195 char name[64];
196
197 /* The Protocol-Origin. */
198 enum srte_protocol_origin protocol_origin;
199
200 /* The Originator */
201 char originator[64];
202
203 /* Nexthops. */
204 struct srte_segment_entry_head segments;
205
206 /* Status flags. */
207 uint16_t flags;
208 #define F_SEGMENT_LIST_NEW 0x0002
209 #define F_SEGMENT_LIST_MODIFIED 0x0004
210 #define F_SEGMENT_LIST_DELETED 0x0008
211 #define F_SEGMENT_LIST_SID_CONFLICT 0x0010
212 };
213 RB_HEAD(srte_segment_list_head, srte_segment_list);
214 RB_PROTOTYPE(srte_segment_list_head, srte_segment_list, entry,
215 srte_segment_list_compare)
216
217 struct srte_metric {
218 uint16_t flags;
219 #define F_METRIC_IS_DEFINED 0x0001
220 #define F_METRIC_IS_REQUIRED 0x0002
221 #define F_METRIC_IS_BOUND 0x0004
222 #define F_METRIC_IS_COMPUTED 0x0008
223 float value;
224 };
225
226 /* Runtime information about the candidate path */
227 struct srte_lsp {
228 /* Backpointer to the Candidate Path. */
229 struct srte_candidate *candidate;
230
231 /* The associated Segment List. */
232 struct srte_segment_list *segment_list;
233
234 /* The Protocol-Origin. */
235 enum srte_protocol_origin protocol_origin;
236
237 /* The Originator */
238 char originator[64];
239
240 /* The Discriminator */
241 uint32_t discriminator;
242
243 /* Flags. */
244 uint32_t flags;
245
246 /* Metrics LSP Values */
247 struct srte_metric metrics[MAX_METRIC_TYPE];
248
249 /* Bandwidth Configured Value */
250 float bandwidth;
251
252 /* The objective function in used */
253 enum objfun_type objfun;
254 };
255
256 /* Configured candidate path */
257 struct srte_candidate {
258 RB_ENTRY(srte_candidate) entry;
259
260 /* Backpointer to SR Policy */
261 struct srte_policy *policy;
262
263 /* The LSP associated with this candidate path. */
264 struct srte_lsp *lsp;
265
266 /* Administrative preference. */
267 uint32_t preference;
268
269 /* Symbolic Name. */
270 char name[64];
271
272 /* The associated Segment List. */
273 struct srte_segment_list *segment_list;
274
275 /* The Protocol-Origin. */
276 enum srte_protocol_origin protocol_origin;
277
278 /* The Originator */
279 char originator[64];
280
281 /* The Discriminator */
282 uint32_t discriminator;
283
284 /* The Type (explicit or dynamic) */
285 enum srte_candidate_type type;
286
287 /* Flags. */
288 uint32_t flags;
289 #define F_CANDIDATE_BEST 0x0001
290 #define F_CANDIDATE_NEW 0x0002
291 #define F_CANDIDATE_MODIFIED 0x0004
292 #define F_CANDIDATE_DELETED 0x0008
293 #define F_CANDIDATE_HAS_BANDWIDTH 0x0100
294 #define F_CANDIDATE_REQUIRED_BANDWIDTH 0x0200
295 #define F_CANDIDATE_HAS_OBJFUN 0x0400
296 #define F_CANDIDATE_REQUIRED_OBJFUN 0x0800
297 #define F_CANDIDATE_HAS_EXCLUDE_ANY 0x1000
298 #define F_CANDIDATE_HAS_INCLUDE_ANY 0x2000
299 #define F_CANDIDATE_HAS_INCLUDE_ALL 0x4000
300
301 /* Metrics Configured Values */
302 struct srte_metric metrics[MAX_METRIC_TYPE];
303
304 /* Bandwidth Configured Value */
305 float bandwidth;
306
307 /* Configured objective functions */
308 enum objfun_type objfun;
309
310 /* Path constraints attribute filters */
311 uint32_t affinity_filters[MAX_AFFINITY_FILTER_TYPE];
312
313 /* Hooks delaying timer */
314 struct event *hook_timer;
315 };
316
317 RB_HEAD(srte_candidate_head, srte_candidate);
318 RB_PROTOTYPE(srte_candidate_head, srte_candidate, entry, srte_candidate_compare)
319
320 #define ENDPOINT_STR_LENGTH IPADDR_STRING_SIZE
321
322 struct srte_policy {
323 RB_ENTRY(srte_policy) entry;
324
325 /* Color */
326 uint32_t color;
327
328 /* Endpoint */
329 struct ipaddr endpoint;
330
331 /* Name */
332 char name[64];
333
334 /* Binding SID */
335 mpls_label_t binding_sid;
336
337 /* The Protocol-Origin. */
338 enum srte_protocol_origin protocol_origin;
339
340 /* The Originator */
341 char originator[64];
342
343 /* Operational Status of the policy */
344 enum srte_policy_status status;
345
346 /* Best candidate path. */
347 struct srte_candidate *best_candidate;
348
349 /* Candidate Paths */
350 struct srte_candidate_head candidate_paths;
351 /* Status flags. */
352 uint16_t flags;
353 #define F_POLICY_NEW 0x0002
354 #define F_POLICY_MODIFIED 0x0004
355 #define F_POLICY_DELETED 0x0008
356 /* SRP id for PcInitiated support */
357 int srp_id;
358 };
359 RB_HEAD(srte_policy_head, srte_policy);
360 RB_PROTOTYPE(srte_policy_head, srte_policy, entry, srte_policy_compare)
361
362 DECLARE_HOOK(pathd_candidate_created, (struct srte_candidate * candidate),
363 (candidate));
364 DECLARE_HOOK(pathd_candidate_updated, (struct srte_candidate * candidate),
365 (candidate));
366 DECLARE_HOOK(pathd_candidate_removed, (struct srte_candidate * candidate),
367 (candidate));
368
369 extern struct srte_segment_list_head srte_segment_lists;
370 extern struct srte_policy_head srte_policies;
371 extern struct zebra_privs_t pathd_privs;
372
373 /* master thread, defined in path_main.c */
374 extern struct event_loop *master;
375
376 /* pathd.c */
377 struct srte_segment_list *srte_segment_list_add(const char *name);
378 void srte_segment_list_del(struct srte_segment_list *segment_list);
379 struct srte_segment_list *srte_segment_list_find(const char *name);
380 struct srte_segment_entry *
381 srte_segment_entry_add(struct srte_segment_list *segment_list, uint32_t index);
382 void srte_segment_entry_del(struct srte_segment_entry *segment);
383 int srte_segment_entry_set_nai(struct srte_segment_entry *segment,
384 enum srte_segment_nai_type type,
385 struct ipaddr *local_ip, uint32_t local_iface,
386 struct ipaddr *remote_ip, uint32_t remote_iface,
387 uint8_t algo, uint8_t pref_len);
388 void srte_segment_set_local_modification(struct srte_segment_list *s_list,
389 struct srte_segment_entry *s_entry,
390 uint32_t ted_sid);
391 struct srte_policy *srte_policy_add(uint32_t color, struct ipaddr *endpoint,
392 enum srte_protocol_origin origin,
393 const char *originator);
394 void srte_policy_del(struct srte_policy *policy);
395 struct srte_policy *srte_policy_find(uint32_t color, struct ipaddr *endpoint);
396 int srte_policy_update_ted_sid(void);
397 void srte_policy_update_binding_sid(struct srte_policy *policy,
398 uint32_t binding_sid);
399 void srte_apply_changes(void);
400 void srte_clean_zebra(void);
401 void srte_policy_apply_changes(struct srte_policy *policy);
402 struct srte_candidate *srte_candidate_add(struct srte_policy *policy,
403 uint32_t preference,
404 enum srte_protocol_origin origin,
405 const char *originator);
406 void srte_candidate_del(struct srte_candidate *candidate);
407 void srte_candidate_set_bandwidth(struct srte_candidate *candidate,
408 float bandwidth, bool required);
409 void srte_candidate_unset_bandwidth(struct srte_candidate *candidate);
410 void srte_candidate_set_metric(struct srte_candidate *candidate,
411 enum srte_candidate_metric_type type,
412 float value, bool required, bool is_cound,
413 bool is_computed);
414 void srte_candidate_unset_metric(struct srte_candidate *candidate,
415 enum srte_candidate_metric_type type);
416 void srte_candidate_set_objfun(struct srte_candidate *candidate, bool required,
417 enum objfun_type type);
418 void srte_candidate_unset_objfun(struct srte_candidate *candidate);
419 void srte_candidate_set_affinity_filter(struct srte_candidate *candidate,
420 enum affinity_filter_type type,
421 uint32_t filter);
422 void srte_candidate_unset_affinity_filter(struct srte_candidate *candidate,
423 enum affinity_filter_type type);
424 void srte_lsp_set_bandwidth(struct srte_lsp *lsp, float bandwidth,
425 bool required);
426 void srte_lsp_unset_bandwidth(struct srte_lsp *lsp);
427 void srte_lsp_set_metric(struct srte_lsp *lsp,
428 enum srte_candidate_metric_type type, float value,
429 bool required, bool is_cound, bool is_computed);
430 void srte_lsp_unset_metric(struct srte_lsp *lsp,
431 enum srte_candidate_metric_type type);
432 struct srte_candidate *srte_candidate_find(struct srte_policy *policy,
433 uint32_t preference);
434 struct srte_segment_entry *
435 srte_segment_entry_find(struct srte_segment_list *segment_list, uint32_t index);
436 void srte_candidate_status_update(struct srte_candidate *candidate, int status);
437 void srte_candidate_unset_segment_list(const char *originator, bool force);
438 const char *srte_origin2str(enum srte_protocol_origin origin);
439 void pathd_shutdown(void);
440 void path_policy_show_debugging(struct vty *vty);
441
442 /* path_cli.c */
443 void path_cli_init(void);
444
445
446 /**
447 * Search for sid based in prefix and algorithm
448 *
449 * @param Prefix The prefix to use
450 * @param algo Algorithm we want to query for
451 * @param ted_sid Sid to query
452 *
453 * @return void
454 */
455 int32_t srte_ted_do_query_type_c(struct srte_segment_entry *entry,
456 struct prefix *prefix_cli, uint32_t algo);
457
458 /**
459 * Search for sid based in prefix and interface id
460 *
461 * @param Prefix The prefix to use
462 * @param local_iface The id of interface
463 * @param ted_sid Sid to query
464 *
465 * @return void
466 */
467 int32_t srte_ted_do_query_type_e(struct srte_segment_entry *entry,
468 struct prefix *prefix_cli,
469 uint32_t local_iface);
470 /**
471 * Search for sid based in local and remote ip
472 *
473 * @param entry entry to update
474 * @param local Local addr for query
475 * @param remote Local addr for query
476 *
477 * @return void
478 */
479 int32_t srte_ted_do_query_type_f(struct srte_segment_entry *entry,
480 struct ipaddr *local, struct ipaddr *remote);
481 #endif /* _FRR_PATHD_H_ */