1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2020 NetDEF, Inc.
9 #include "lib/memory.h"
11 #include "lib/ipaddr.h"
14 #include "lib/prefix.h"
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))
22 DECLARE_MGROUP(PATHD
);
24 DECLARE_HOOK(pathd_srte_config_write
, (struct vty
*vty
), (vty
));
26 enum srte_protocol_origin
{
27 SRTE_ORIGIN_UNDEFINED
= 0,
30 SRTE_ORIGIN_LOCAL
= 3,
33 extern struct debug path_policy_debug
;
35 #define PATH_POLICY_DEBUG_BASIC 0x01
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
45 enum srte_candidate_type
{
46 SRTE_CANDIDATE_TYPE_UNDEFINED
= 0,
47 SRTE_CANDIDATE_TYPE_EXPLICIT
= 1,
48 SRTE_CANDIDATE_TYPE_DYNAMIC
= 2,
51 enum srte_candidate_metric_type
{
53 SRTE_CANDIDATE_METRIC_TYPE_IGP
= 1,
55 SRTE_CANDIDATE_METRIC_TYPE_TE
= 2,
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,
67 SRTE_CANDIDATE_METRIC_TYPE_PIGP
= 8,
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,
95 #define MAX_METRIC_TYPE 21
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
112 OBJFUN_UNDEFINED
= 0,
113 /* Minimum Cost Path [RFC5541] */
115 /* Minimum Load Path [RFC5541] */
117 /* Maximum residual Bandwidth Path [RFC5541] */
119 /* Minimize aggregate Bandwidth Consumption [RFC5541] */
121 /* Minimize the Load of the most loaded Link [RFC5541] */
123 /* Minimize the Cumulative Cost of a set of paths [RFC5541] */
125 /* Shortest Path Tree [RFC8306] */
127 /* Minimum Cost Tree [RFC8306] */
129 /* Minimum Packet Loss Path [RFC8233] */
131 /* Maximum Under-Utilized Path [RFC8233] */
133 /* Maximum Reserved Under-Utilized Path [RFC8233] */
135 /* Minimize the number of Transit Domains [RFC8685] */
137 /* Minimize the number of Border Nodes [RFC8685] */
139 /* Minimize the number of Common Transit Domains [RFC8685] */
141 /* Minimize the number of Shared Links [RFC8800] */
143 /* Minimize the number of Shared SRLGs [RFC8800] */
145 /* Minimize the number of Shared Nodes [RFC8800] */
148 #define MAX_OBJFUN_TYPE 17
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,
156 #define MAX_AFFINITY_FILTER_TYPE 3
158 struct srte_segment_list
;
160 struct srte_segment_entry
{
161 RB_ENTRY(srte_segment_entry
) entry
;
163 /* The segment list the entry belong to */
164 struct srte_segment_list
*segment_list
;
166 /* Index of the Label. */
170 mpls_label_t sid_value
;
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
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
;
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
)
191 struct srte_segment_list
{
192 RB_ENTRY(srte_segment_list
) entry
;
194 /* Name of the Segment List. */
197 /* The Protocol-Origin. */
198 enum srte_protocol_origin protocol_origin
;
204 struct srte_segment_entry_head segments
;
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
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
)
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
226 /* Runtime information about the candidate path */
228 /* Backpointer to the Candidate Path. */
229 struct srte_candidate
*candidate
;
231 /* The associated Segment List. */
232 struct srte_segment_list
*segment_list
;
234 /* The Protocol-Origin. */
235 enum srte_protocol_origin protocol_origin
;
240 /* The Discriminator */
241 uint32_t discriminator
;
246 /* Metrics LSP Values */
247 struct srte_metric metrics
[MAX_METRIC_TYPE
];
249 /* Bandwidth Configured Value */
252 /* The objective function in used */
253 enum objfun_type objfun
;
256 /* Configured candidate path */
257 struct srte_candidate
{
258 RB_ENTRY(srte_candidate
) entry
;
260 /* Backpointer to SR Policy */
261 struct srte_policy
*policy
;
263 /* The LSP associated with this candidate path. */
264 struct srte_lsp
*lsp
;
266 /* Administrative preference. */
272 /* The associated Segment List. */
273 struct srte_segment_list
*segment_list
;
275 /* The Protocol-Origin. */
276 enum srte_protocol_origin protocol_origin
;
281 /* The Discriminator */
282 uint32_t discriminator
;
284 /* The Type (explicit or dynamic) */
285 enum srte_candidate_type type
;
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
301 /* Metrics Configured Values */
302 struct srte_metric metrics
[MAX_METRIC_TYPE
];
304 /* Bandwidth Configured Value */
307 /* Configured objective functions */
308 enum objfun_type objfun
;
310 /* Path constraints attribute filters */
311 uint32_t affinity_filters
[MAX_AFFINITY_FILTER_TYPE
];
313 /* Hooks delaying timer */
314 struct event
*hook_timer
;
317 RB_HEAD(srte_candidate_head
, srte_candidate
);
318 RB_PROTOTYPE(srte_candidate_head
, srte_candidate
, entry
, srte_candidate_compare
)
320 #define ENDPOINT_STR_LENGTH IPADDR_STRING_SIZE
323 RB_ENTRY(srte_policy
) entry
;
329 struct ipaddr endpoint
;
335 mpls_label_t binding_sid
;
337 /* The Protocol-Origin. */
338 enum srte_protocol_origin protocol_origin
;
343 /* Operational Status of the policy */
344 enum srte_policy_status status
;
346 /* Best candidate path. */
347 struct srte_candidate
*best_candidate
;
349 /* Candidate Paths */
350 struct srte_candidate_head candidate_paths
;
353 #define F_POLICY_NEW 0x0002
354 #define F_POLICY_MODIFIED 0x0004
355 #define F_POLICY_DELETED 0x0008
356 /* SRP id for PcInitiated support */
359 RB_HEAD(srte_policy_head
, srte_policy
);
360 RB_PROTOTYPE(srte_policy_head
, srte_policy
, entry
, srte_policy_compare
)
362 DECLARE_HOOK(pathd_candidate_created
, (struct srte_candidate
* candidate
),
364 DECLARE_HOOK(pathd_candidate_updated
, (struct srte_candidate
* candidate
),
366 DECLARE_HOOK(pathd_candidate_removed
, (struct srte_candidate
* candidate
),
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
;
373 /* master thread, defined in path_main.c */
374 extern struct event_loop
*master
;
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
,
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
,
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
,
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
,
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
,
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
);
443 void path_cli_init(void);
447 * Search for sid based in prefix and algorithm
449 * @param Prefix The prefix to use
450 * @param algo Algorithm we want to query for
451 * @param ted_sid Sid to query
455 int32_t srte_ted_do_query_type_c(struct srte_segment_entry
*entry
,
456 struct prefix
*prefix_cli
, uint32_t algo
);
459 * Search for sid based in prefix and interface id
461 * @param Prefix The prefix to use
462 * @param local_iface The id of interface
463 * @param ted_sid Sid to query
467 int32_t srte_ted_do_query_type_e(struct srte_segment_entry
*entry
,
468 struct prefix
*prefix_cli
,
469 uint32_t local_iface
);
471 * Search for sid based in local and remote ip
473 * @param entry entry to update
474 * @param local Local addr for query
475 * @param remote Local addr for query
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_ */