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