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