1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2020 NetDEF, Inc.
11 #include <netinet/tcp.h>
13 #include "pceplib/pcep_utils_logging.h"
14 #include "pceplib/pcep_pcc_api.h"
16 #include "pathd/pathd.h"
20 #define PCEP_DEFAULT_PORT 4189
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, ...) \
30 if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC)) \
31 DEBUGD(&pcep_g->dbg, "pcep: " fmt, ##__VA_ARGS__); \
33 #define PCEP_DEBUG_PATH(fmt, ...) \
35 if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PATH)) \
36 DEBUGD(&pcep_g->dbg, "pcep: " fmt, ##__VA_ARGS__); \
38 #define PCEP_DEBUG_PCEP(fmt, ...) \
40 if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEP)) \
41 DEBUGD(&pcep_g->dbg, "pcep: " fmt, ##__VA_ARGS__); \
43 #define PCEP_DEBUG_PCEPLIB(priority, fmt, ...) \
47 if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, \
48 PCEP_DEBUG_MODE_PCEPLIB)) \
49 DEBUGD(&pcep_g->dbg, "pcep: " fmt, \
53 if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, \
54 PCEP_DEBUG_MODE_PCEPLIB)) \
55 DEBUGI(&pcep_g->dbg, "pcep: " fmt, \
59 if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, \
60 PCEP_DEBUG_MODE_PCEPLIB)) \
61 DEBUGN(&pcep_g->dbg, "pcep: " fmt, \
67 zlog(priority, "pcep: " fmt, ##__VA_ARGS__); \
72 struct pcep_config_group_opts
{
74 char tcp_md5_auth
[PCEP_MD5SIG_MAXKEYLEN
];
75 struct ipaddr source_ip
;
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
;
94 struct pcep_config_group_opts config_opts
;
95 uint8_t precedence
; /* Multi-PCE precedence */
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. */
122 struct ipaddr endpoint
;
128 uint8_t traffic_class
;
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
;
147 struct sid_mpls mpls
;
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
;
164 /* Pointer to the next hop in the path */
165 struct path_hop
*next
;
166 /* Indicateif this ia a loose or strict hop */
168 /* Indicate if there is an SID for the hop */
170 /* Indicate if the hop as a MPLS label */
172 /* Indicate if the MPLS label has extra attributes (TTL, class..)*/
174 /* Hop's SID if available */
176 /* Indicate if there is a NAI for this hop */
178 /* NAI if available */
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 */
189 /* If the metric value is bound (a maximum) */
191 /* If the metric value is computed */
193 /* The metric value */
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 */
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 */
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
;
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 */
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
;
227 /* The following data comes from either the PCC or the PCE if available
230 /* Path's binding SID */
231 mpls_label_t binding_sid
;
232 /* The name of the path */
234 /* The request identifier from the PCE, when getting a path from the
235 PCE. See draft-ietf-pce-stateful-pce */
237 /* The request identifier from the PCC , when getting a path from the
238 PCE after a computation request. See rfc5440, section-7.4 */
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 */
245 /* Indicate the given path was removed by the PCC.
246 See draft-ietf-pce-stateful-pce, section-7.3, flag R */
248 /* Indicate the path is part of the synchronization process.
249 See draft-ietf-pce-stateful-pce, section-7.3, flag S */
251 /* Indicate if the path bandwidth requirment is defined */
253 /* Indicate if the bandwidth requirment should be enforced */
254 bool enforce_bandwidth
;
255 /* Path required bandwidth if defined */
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 */
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 */
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
275 uint32_t affinity_filters
[MAX_AFFINITY_FILTER_TYPE
];
277 /* The following data need to be specialized for a given PCE */
279 /* Indicate the path is delegated to the PCE.
280 See draft-ietf-pce-stateful-pce, section-7.3, flag D */
282 /* Indicate if the PCE wants the path to get active.
283 See draft-ietf-pce-stateful-pce, section-7.3, flag A */
285 /* Indicate the given path was created by the PCE,
286 See draft-ietf-pce-pce-initiated-lsp, section-5.3.1, flag C */
289 /* The following data is defined for comnputation replies */
291 /* Indicate that no path could be computed */
297 struct event_loop
*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
];
305 extern struct pcep_glob
*pcep_g
;
311 /* Rfc 8281 PcInitiated error on bad values */
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
);
325 #endif // _PATH_PCEP_H_