]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
efba0985 SM |
2 | /* |
3 | * Copyright (C) 2020 NetDEF, Inc. | |
efba0985 SM |
4 | */ |
5 | ||
6 | #ifndef _PATH_PCEP_H_ | |
7 | #define _PATH_PCEP_H_ | |
8 | ||
9 | #include <stdbool.h> | |
10 | #include <debug.h> | |
11 | #include <netinet/tcp.h> | |
c7479286 | 12 | #include "memory.h" |
74971473 JG |
13 | #include "pceplib/pcep_utils_logging.h" |
14 | #include "pceplib/pcep_pcc_api.h" | |
efba0985 SM |
15 | #include "mpls.h" |
16 | #include "pathd/pathd.h" | |
c7479286 DL |
17 | |
18 | DECLARE_MTYPE(PCEP); | |
efba0985 SM |
19 | |
20 | #define PCEP_DEFAULT_PORT 4189 | |
21 | #define MAX_PCC 32 | |
22 | #define MAX_PCE 32 | |
23 | #define MAX_TAG_SIZE 50 | |
24 | #define PCEP_DEBUG_MODE_BASIC 0x01 | |
25 | #define PCEP_DEBUG_MODE_PATH 0x02 | |
26 | #define PCEP_DEBUG_MODE_PCEP 0x04 | |
27 | #define PCEP_DEBUG_MODE_PCEPLIB 0x08 | |
28 | #define PCEP_DEBUG(fmt, ...) \ | |
29 | do { \ | |
30 | if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC)) \ | |
31 | DEBUGD(&pcep_g->dbg, "pcep: " fmt, ##__VA_ARGS__); \ | |
32 | } while (0) | |
33 | #define PCEP_DEBUG_PATH(fmt, ...) \ | |
34 | do { \ | |
35 | if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PATH)) \ | |
36 | DEBUGD(&pcep_g->dbg, "pcep: " fmt, ##__VA_ARGS__); \ | |
37 | } while (0) | |
38 | #define PCEP_DEBUG_PCEP(fmt, ...) \ | |
39 | do { \ | |
40 | if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEP)) \ | |
41 | DEBUGD(&pcep_g->dbg, "pcep: " fmt, ##__VA_ARGS__); \ | |
42 | } while (0) | |
43 | #define PCEP_DEBUG_PCEPLIB(priority, fmt, ...) \ | |
44 | do { \ | |
45 | switch (priority) { \ | |
46 | case LOG_DEBUG: \ | |
47 | if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, \ | |
48 | PCEP_DEBUG_MODE_PCEPLIB)) \ | |
49 | DEBUGD(&pcep_g->dbg, "pcep: " fmt, \ | |
50 | ##__VA_ARGS__); \ | |
51 | break; \ | |
52 | case LOG_INFO: \ | |
53 | if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, \ | |
54 | PCEP_DEBUG_MODE_PCEPLIB)) \ | |
55 | DEBUGI(&pcep_g->dbg, "pcep: " fmt, \ | |
56 | ##__VA_ARGS__); \ | |
57 | break; \ | |
58 | case LOG_NOTICE: \ | |
59 | if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, \ | |
60 | PCEP_DEBUG_MODE_PCEPLIB)) \ | |
61 | DEBUGN(&pcep_g->dbg, "pcep: " fmt, \ | |
62 | ##__VA_ARGS__); \ | |
63 | break; \ | |
64 | case LOG_WARNING: \ | |
65 | case LOG_ERR: \ | |
66 | default: \ | |
67 | zlog(priority, "pcep: " fmt, ##__VA_ARGS__); \ | |
68 | break; \ | |
69 | } \ | |
70 | } while (0) | |
71 | ||
72 | struct pcep_config_group_opts { | |
73 | char name[64]; | |
2a034138 | 74 | char tcp_md5_auth[PCEP_MD5SIG_MAXKEYLEN]; |
efba0985 SM |
75 | struct ipaddr source_ip; |
76 | short source_port; | |
77 | bool draft07; | |
78 | bool pce_initiated; | |
79 | int keep_alive_seconds; | |
80 | int min_keep_alive_seconds; | |
81 | int max_keep_alive_seconds; | |
82 | int dead_timer_seconds; | |
83 | int min_dead_timer_seconds; | |
84 | int max_dead_timer_seconds; | |
85 | int pcep_request_time_seconds; | |
86 | int session_timeout_inteval_seconds; | |
87 | int delegation_timeout_seconds; | |
88 | }; | |
89 | ||
90 | struct pce_opts { | |
91 | struct ipaddr addr; | |
92 | short port; | |
93 | char pce_name[64]; | |
94 | struct pcep_config_group_opts config_opts; | |
95 | uint8_t precedence; /* Multi-PCE precedence */ | |
96 | }; | |
97 | ||
98 | struct pcc_opts { | |
99 | struct ipaddr addr; | |
100 | short port; | |
101 | short msd; | |
102 | }; | |
103 | ||
104 | /* Encapsulate the pce_opts with needed CLI information */ | |
105 | struct pce_opts_cli { | |
106 | struct pce_opts pce_opts; | |
107 | char config_group_name[64]; | |
108 | /* These are the values configured in the pcc-peer sub-commands. | |
109 | * These need to be stored for later merging. Notice, it could | |
110 | * be that not all of them are set. */ | |
111 | struct pcep_config_group_opts pce_config_group_opts; | |
112 | /* The pce_opts->config_opts will be a merge of the default values, | |
113 | * optional config_group values (which overwrite default values), | |
114 | * and any values configured in the pce sub-commands (which overwrite | |
115 | * both default and config_group values). This flag indicates of the | |
116 | * values need to be merged or not. */ | |
117 | bool merged; | |
118 | }; | |
119 | ||
120 | struct lsp_nb_key { | |
121 | uint32_t color; | |
122 | struct ipaddr endpoint; | |
123 | uint32_t preference; | |
124 | }; | |
125 | ||
126 | struct sid_mpls { | |
127 | mpls_label_t label; | |
128 | uint8_t traffic_class; | |
129 | bool is_bottom; | |
130 | uint8_t ttl; | |
131 | }; | |
132 | ||
133 | struct pcep_caps { | |
134 | bool is_stateful; | |
135 | /* If we know the objective functions supported by the PCE. | |
136 | * If we don't know, it doesn't mean the PCE doesn't support any */ | |
137 | bool supported_ofs_are_known; | |
138 | /* Defined if we know which objective funtions are supported by the PCE. | |
139 | * One bit per objective function, the bit index being equal to | |
140 | * enum pcep_objfun_type values: bit 0 is not used, bit 1 is | |
141 | * PCEP_OBJFUN_MCP, up to bit 17 that is PCEP_OBJFUN_MSN */ | |
142 | uint32_t supported_ofs; | |
143 | }; | |
144 | ||
145 | union sid { | |
146 | uint32_t value; | |
147 | struct sid_mpls mpls; | |
148 | }; | |
149 | ||
150 | struct nai { | |
151 | /* NAI type */ | |
152 | enum pcep_sr_subobj_nai type; | |
153 | /* Local IP address*/ | |
154 | struct ipaddr local_addr; | |
155 | /* Local interface identifier if the NAI is an unnumbered adjacency */ | |
156 | uint32_t local_iface; | |
157 | /* Remote address if the NAI is an adjacency */ | |
158 | struct ipaddr remote_addr; | |
159 | /* Remote interface identifier if the NAI is an unnumbered adjacency */ | |
160 | uint32_t remote_iface; | |
161 | }; | |
162 | ||
163 | struct path_hop { | |
164 | /* Pointer to the next hop in the path */ | |
165 | struct path_hop *next; | |
166 | /* Indicateif this ia a loose or strict hop */ | |
167 | bool is_loose; | |
168 | /* Indicate if there is an SID for the hop */ | |
169 | bool has_sid; | |
170 | /* Indicate if the hop as a MPLS label */ | |
171 | bool is_mpls; | |
172 | /* Indicate if the MPLS label has extra attributes (TTL, class..)*/ | |
173 | bool has_attribs; | |
174 | /* Hop's SID if available */ | |
175 | union sid sid; | |
176 | /* Indicate if there is a NAI for this hop */ | |
177 | bool has_nai; | |
178 | /* NAI if available */ | |
179 | struct nai nai; | |
180 | }; | |
181 | ||
182 | struct path_metric { | |
183 | /* Pointer to the next metric */ | |
184 | struct path_metric *next; | |
185 | /* The metric type */ | |
186 | enum pcep_metric_types type; | |
187 | /* If the metric should be enforced */ | |
188 | bool enforce; | |
189 | /* If the metric value is bound (a maximum) */ | |
190 | bool is_bound; | |
191 | /* If the metric value is computed */ | |
192 | bool is_computed; | |
193 | /* The metric value */ | |
194 | float value; | |
195 | }; | |
196 | ||
197 | struct path { | |
198 | /* Both the nbkey and the plspid are keys comming from the PCC, | |
199 | but the PCE is only using the plspid. The missing key is looked up by | |
200 | the PCC so we always have both */ | |
201 | ||
202 | /* The northbound key identifying this path */ | |
203 | struct lsp_nb_key nbkey; | |
204 | /* The generated unique PLSP identifier for this path. | |
205 | See draft-ietf-pce-stateful-pce */ | |
206 | uint32_t plsp_id; | |
207 | ||
208 | /* The transport address the path is comming from, PCE or PCC*/ | |
209 | struct ipaddr sender; | |
210 | /* The pcc protocol address, must be the same family as the endpoint */ | |
211 | struct ipaddr pcc_addr; | |
212 | ||
213 | /* The identifier of the PCC the path is for/from. If 0 it is undefined, | |
214 | meaning it hasn't be set yet or is for all the PCC */ | |
215 | int pcc_id; | |
216 | ||
217 | /* The origin of the path creation */ | |
218 | enum srte_protocol_origin create_origin; | |
219 | /* The origin of the path modification */ | |
220 | enum srte_protocol_origin update_origin; | |
221 | /* The identifier of the entity that originated the path */ | |
222 | const char *originator; | |
223 | /* The type of the path, for PCE initiated or updated path it is always | |
224 | SRTE_CANDIDATE_TYPE_DYNAMIC */ | |
225 | enum srte_candidate_type type; | |
226 | ||
227 | /* The following data comes from either the PCC or the PCE if available | |
228 | */ | |
229 | ||
230 | /* Path's binding SID */ | |
231 | mpls_label_t binding_sid; | |
232 | /* The name of the path */ | |
233 | const char *name; | |
234 | /* The request identifier from the PCE, when getting a path from the | |
235 | PCE. See draft-ietf-pce-stateful-pce */ | |
236 | uint32_t srp_id; | |
237 | /* The request identifier from the PCC , when getting a path from the | |
238 | PCE after a computation request. See rfc5440, section-7.4 */ | |
239 | uint32_t req_id; | |
240 | /* The operational status of the path */ | |
241 | enum pcep_lsp_operational_status status; | |
242 | /* If true, the receiver (PCC) must remove the path. | |
243 | See draft-ietf-pce-pce-initiated-lsp */ | |
244 | bool do_remove; | |
245 | /* Indicate the given path was removed by the PCC. | |
246 | See draft-ietf-pce-stateful-pce, section-7.3, flag R */ | |
247 | bool was_removed; | |
248 | /* Indicate the path is part of the synchronization process. | |
249 | See draft-ietf-pce-stateful-pce, section-7.3, flag S */ | |
250 | bool is_synching; | |
251 | /* Indicate if the path bandwidth requirment is defined */ | |
252 | bool has_bandwidth; | |
253 | /* Indicate if the bandwidth requirment should be enforced */ | |
254 | bool enforce_bandwidth; | |
255 | /* Path required bandwidth if defined */ | |
256 | float bandwidth; | |
257 | /* Specify the list of hop defining the path */ | |
258 | struct path_hop *first_hop; | |
259 | /* Specify the list of metrics */ | |
260 | struct path_metric *first_metric; | |
261 | /* Indicate if the path has a PCC-defined objective function */ | |
262 | bool has_pcc_objfun; | |
263 | /* Indicate the PCC-defined objective function is required */ | |
264 | bool enforce_pcc_objfun; | |
265 | /* PCC-defined Objective Function */ | |
266 | enum objfun_type pcc_objfun; | |
267 | /* Indicate if the path has a PCE-defined objective function */ | |
268 | bool has_pce_objfun; | |
269 | /* PCE-defined Objective Function */ | |
270 | enum objfun_type pce_objfun; | |
271 | /* Indicate if some affinity filters are defined */ | |
272 | bool has_affinity_filters; | |
273 | /* Affinity attribute filters indexed by enum affinity_filter_type - 1 | |
274 | */ | |
275 | uint32_t affinity_filters[MAX_AFFINITY_FILTER_TYPE]; | |
276 | ||
277 | /* The following data need to be specialized for a given PCE */ | |
278 | ||
279 | /* Indicate the path is delegated to the PCE. | |
280 | See draft-ietf-pce-stateful-pce, section-7.3, flag D */ | |
281 | bool is_delegated; | |
282 | /* Indicate if the PCE wants the path to get active. | |
283 | See draft-ietf-pce-stateful-pce, section-7.3, flag A */ | |
284 | bool go_active; | |
285 | /* Indicate the given path was created by the PCE, | |
286 | See draft-ietf-pce-pce-initiated-lsp, section-5.3.1, flag C */ | |
287 | bool was_created; | |
288 | ||
289 | /* The following data is defined for comnputation replies */ | |
290 | ||
291 | /* Indicate that no path could be computed */ | |
292 | bool no_path; | |
293 | }; | |
294 | ||
295 | struct pcep_glob { | |
296 | struct debug dbg; | |
297 | struct thread_master *master; | |
298 | struct frr_pthread *fpt; | |
299 | uint8_t num_pce_opts_cli; | |
300 | struct pce_opts_cli *pce_opts_cli[MAX_PCE]; | |
301 | uint8_t num_config_group_opts; | |
302 | struct pcep_config_group_opts *config_group_opts[MAX_PCE]; | |
303 | }; | |
304 | ||
305 | extern struct pcep_glob *pcep_g; | |
306 | ||
ab7fe289 JG |
307 | struct pcep_error { |
308 | struct path *path; | |
309 | int error_type; | |
310 | int error_value; | |
311 | /* Rfc 8281 PcInitiated error on bad values */ | |
312 | #define ERROR_19_1 1 | |
313 | #define ERROR_19_3 2 | |
314 | #define ERROR_19_9 3 | |
315 | }; | |
316 | ||
efba0985 SM |
317 | /* Path Helper Functions */ |
318 | struct path *pcep_new_path(void); | |
319 | struct path_hop *pcep_new_hop(void); | |
320 | struct path_metric *pcep_new_metric(void); | |
321 | struct path *pcep_copy_path(struct path *path); | |
322 | void pcep_free_path(struct path *path); | |
323 | ||
324 | ||
325 | #endif // _PATH_PCEP_H_ |