]> git.proxmox.com Git - mirror_frr.git/blame - pathd/pathd.h
*: Convert struct thread_master to struct event_master and it's ilk
[mirror_frr.git] / pathd / pathd.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
4d7b695d
SM
2/*
3 * Copyright (C) 2020 NetDEF, Inc.
4d7b695d
SM
4 */
5
6#ifndef _FRR_PATHD_H_
7#define _FRR_PATHD_H_
8
c7479286 9#include "lib/memory.h"
4d7b695d
SM
10#include "lib/mpls.h"
11#include "lib/ipaddr.h"
12#include "lib/srte.h"
13#include "lib/hook.h"
f2b9485d
JG
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))
4d7b695d 21
c7479286
DL
22DECLARE_MGROUP(PATHD);
23
ac9103aa
IR
24DECLARE_HOOK(pathd_srte_config_write, (struct vty *vty), (vty));
25
4d7b695d
SM
26enum 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
116f9b45
PG
33extern struct debug path_policy_debug;
34
35#define PATH_POLICY_DEBUG_BASIC 0x01
36
4d7b695d
SM
37enum 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
45enum srte_candidate_type {
46 SRTE_CANDIDATE_TYPE_UNDEFINED = 0,
47 SRTE_CANDIDATE_TYPE_EXPLICIT = 1,
48 SRTE_CANDIDATE_TYPE_DYNAMIC = 2,
49};
50
51enum 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
97enum 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,
f2b9485d
JG
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
4d7b695d
SM
109};
110
111enum 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
150enum 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
158struct srte_segment_list;
159
160struct 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;
f2b9485d
JG
183 /* Support draft-ietf-spring-segment-routing-policy sl types queries*/
184 uint8_t nai_local_prefix_len;
185 uint8_t nai_algorithm;
4d7b695d
SM
186};
187RB_HEAD(srte_segment_entry_head, srte_segment_entry);
188RB_PROTOTYPE(srte_segment_entry_head, srte_segment_entry, entry,
189 srte_segment_entry_compare)
190
191struct 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
f2b9485d 211#define F_SEGMENT_LIST_SID_CONFLICT 0x0010
4d7b695d
SM
212};
213RB_HEAD(srte_segment_list_head, srte_segment_list);
214RB_PROTOTYPE(srte_segment_list_head, srte_segment_list, entry,
215 srte_segment_list_compare)
216
217struct 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 */
227struct 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 */
257struct 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 */
e6685141 314 struct event *hook_timer;
4d7b695d
SM
315};
316
317RB_HEAD(srte_candidate_head, srte_candidate);
318RB_PROTOTYPE(srte_candidate_head, srte_candidate, entry, srte_candidate_compare)
319
c1657d26
PG
320#define ENDPOINT_STR_LENGTH IPADDR_STRING_SIZE
321
4d7b695d
SM
322struct 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
ab7fe289
JG
337 /* The Protocol-Origin. */
338 enum srte_protocol_origin protocol_origin;
339
340 /* The Originator */
341 char originator[64];
342
4d7b695d
SM
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
ab7fe289
JG
356 /* SRP id for PcInitiated support */
357 int srp_id;
4d7b695d
SM
358};
359RB_HEAD(srte_policy_head, srte_policy);
360RB_PROTOTYPE(srte_policy_head, srte_policy, entry, srte_policy_compare)
361
362DECLARE_HOOK(pathd_candidate_created, (struct srte_candidate * candidate),
8451921b 363 (candidate));
4d7b695d 364DECLARE_HOOK(pathd_candidate_updated, (struct srte_candidate * candidate),
8451921b 365 (candidate));
4d7b695d 366DECLARE_HOOK(pathd_candidate_removed, (struct srte_candidate * candidate),
8451921b 367 (candidate));
4d7b695d
SM
368
369extern struct srte_segment_list_head srte_segment_lists;
370extern struct srte_policy_head srte_policies;
371extern struct zebra_privs_t pathd_privs;
372
373/* master thread, defined in path_main.c */
2453d15d 374extern struct event_master *master;
4d7b695d
SM
375
376/* pathd.c */
377struct srte_segment_list *srte_segment_list_add(const char *name);
378void srte_segment_list_del(struct srte_segment_list *segment_list);
379struct srte_segment_list *srte_segment_list_find(const char *name);
380struct srte_segment_entry *
381srte_segment_entry_add(struct srte_segment_list *segment_list, uint32_t index);
382void srte_segment_entry_del(struct srte_segment_entry *segment);
f2b9485d
JG
383int 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);
388void srte_segment_set_local_modification(struct srte_segment_list *s_list,
389 struct srte_segment_entry *s_entry,
390 uint32_t ted_sid);
ab7fe289
JG
391struct srte_policy *srte_policy_add(uint32_t color, struct ipaddr *endpoint,
392 enum srte_protocol_origin origin,
393 const char *originator);
4d7b695d
SM
394void srte_policy_del(struct srte_policy *policy);
395struct srte_policy *srte_policy_find(uint32_t color, struct ipaddr *endpoint);
f2b9485d 396int srte_policy_update_ted_sid(void);
4d7b695d
SM
397void srte_policy_update_binding_sid(struct srte_policy *policy,
398 uint32_t binding_sid);
399void srte_apply_changes(void);
75c69d15 400void srte_clean_zebra(void);
4d7b695d
SM
401void srte_policy_apply_changes(struct srte_policy *policy);
402struct srte_candidate *srte_candidate_add(struct srte_policy *policy,
ab7fe289
JG
403 uint32_t preference,
404 enum srte_protocol_origin origin,
405 const char *originator);
4d7b695d
SM
406void srte_candidate_del(struct srte_candidate *candidate);
407void srte_candidate_set_bandwidth(struct srte_candidate *candidate,
408 float bandwidth, bool required);
409void srte_candidate_unset_bandwidth(struct srte_candidate *candidate);
410void 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);
414void srte_candidate_unset_metric(struct srte_candidate *candidate,
415 enum srte_candidate_metric_type type);
416void srte_candidate_set_objfun(struct srte_candidate *candidate, bool required,
417 enum objfun_type type);
418void srte_candidate_unset_objfun(struct srte_candidate *candidate);
419void srte_candidate_set_affinity_filter(struct srte_candidate *candidate,
420 enum affinity_filter_type type,
421 uint32_t filter);
422void srte_candidate_unset_affinity_filter(struct srte_candidate *candidate,
423 enum affinity_filter_type type);
424void srte_lsp_set_bandwidth(struct srte_lsp *lsp, float bandwidth,
425 bool required);
426void srte_lsp_unset_bandwidth(struct srte_lsp *lsp);
427void 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);
430void srte_lsp_unset_metric(struct srte_lsp *lsp,
431 enum srte_candidate_metric_type type);
432struct srte_candidate *srte_candidate_find(struct srte_policy *policy,
433 uint32_t preference);
434struct srte_segment_entry *
435srte_segment_entry_find(struct srte_segment_list *segment_list, uint32_t index);
436void srte_candidate_status_update(struct srte_candidate *candidate, int status);
437void srte_candidate_unset_segment_list(const char *originator, bool force);
438const char *srte_origin2str(enum srte_protocol_origin origin);
75c69d15 439void pathd_shutdown(void);
116f9b45 440void path_policy_show_debugging(struct vty *vty);
4d7b695d
SM
441
442/* path_cli.c */
443void path_cli_init(void);
444
f2b9485d
JG
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 */
455int32_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 */
467int32_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 */
479int32_t srte_ted_do_query_type_f(struct srte_segment_entry *entry,
480 struct ipaddr *local, struct ipaddr *remote);
4d7b695d 481#endif /* _FRR_PATHD_H_ */