]> git.proxmox.com Git - mirror_frr.git/blob - pceplib/pcep_msg_tlvs.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / pceplib / pcep_msg_tlvs.h
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3 * This file is part of the PCEPlib, a PCEP protocol library.
4 *
5 * Copyright (C) 2020 Volta Networks https://voltanet.io/
6 *
7 * Author : Brady Johnson <brady@voltanet.io>
8 */
9
10
11 /*
12 * This is a High Level PCEP message object TLV API.
13 */
14
15 #ifndef PCEP_TLVS_H_
16 #define PCEP_TLVS_H_
17
18 #include <arpa/inet.h>
19 #include <stdint.h>
20
21 #include "pcep.h"
22 #include "pcep_utils_double_linked_list.h"
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /*
29 * Regarding memory usage:
30 * When creating TLVs, any TLVs passed into messages or objects with these APIs
31 * will be free'd when the the enclosing pcep_message is free'd. That includes
32 * the double_linked_list's. So, just create the objects and TLVs, put them in
33 * their double_linked_list's, and everything will be managed internally. The
34 * enclosing message will be deleted by pcep_msg_free_message() or
35 * pcep_msg_free_message_list() which, * in turn will call one of:
36 * pcep_obj_free_object() and pcep_obj_free_tlv().
37 * For received messages, call pcep_msg_free_message() to free them.
38 */
39
40 /* These numbers can be found here:
41 * https://www.iana.org/assignments/pcep/pcep.xhtml */
42 enum pcep_object_tlv_types {
43 PCEP_OBJ_TLV_TYPE_NO_PATH_VECTOR = 1,
44 PCEP_OBJ_TLV_TYPE_OBJECTIVE_FUNCTION_LIST = 4, /* RFC 5541 */
45 PCEP_OBJ_TLV_TYPE_VENDOR_INFO = 7, /* RFC 7470 */
46 PCEP_OBJ_TLV_TYPE_STATEFUL_PCE_CAPABILITY = 16, /* RFC 8231 */
47 PCEP_OBJ_TLV_TYPE_SYMBOLIC_PATH_NAME = 17, /* RFC 8232 */
48 PCEP_OBJ_TLV_TYPE_IPV4_LSP_IDENTIFIERS = 18, /* RFC 8231 */
49 PCEP_OBJ_TLV_TYPE_IPV6_LSP_IDENTIFIERS = 19, /* RFC 8231 */
50 PCEP_OBJ_TLV_TYPE_LSP_ERROR_CODE = 20, /* RFC 8232 */
51 PCEP_OBJ_TLV_TYPE_RSVP_ERROR_SPEC = 21, /* RFC 8232 */
52 PCEP_OBJ_TLV_TYPE_LSP_DB_VERSION = 23, /* RFC 8232 */
53 PCEP_OBJ_TLV_TYPE_SPEAKER_ENTITY_ID = 24, /* RFC 8232 */
54 PCEP_OBJ_TLV_TYPE_SR_PCE_CAPABILITY =
55 26, /* draft-ietf-pce-segment-routing-16 */
56 PCEP_OBJ_TLV_TYPE_PATH_SETUP_TYPE = 28, /* RFC 8408 */
57 PCEP_OBJ_TLV_TYPE_PATH_SETUP_TYPE_CAPABILITY =
58 34, /* RFC 8408, draft-ietf-pce-segment-routing-16 */
59 PCEP_OBJ_TLV_TYPE_SRPOLICY_POL_ID =
60 60, /*TDB2 draft-barth-pce-segment-routing-policy-cp-04 */
61 PCEP_OBJ_TLV_TYPE_SRPOLICY_POL_NAME =
62 61, /*TDB3 draft-barth-pce-segment-routing-policy-cp-04 */
63 PCEP_OBJ_TLV_TYPE_SRPOLICY_CPATH_ID =
64 62, /*TDB4 draft-barth-pce-segment-routing-policy-cp-04 */
65 PCEP_OBJ_TLV_TYPE_SRPOLICY_CPATH_PREFERENCE =
66 63, /*TDB5 draft-barth-pce-segment-routing-policy-cp-04 */
67 PCEP_OBJ_TLV_TYPE_UNKNOWN = 128,
68 PCEP_OBJ_TYPE_CISCO_BSID = 65505,
69 /* Max IANA To write arbitrary data */
70 PCEP_OBJ_TLV_TYPE_ARBITRARY = 65533
71 };
72
73
74 struct pcep_object_tlv_header {
75 enum pcep_object_tlv_types type;
76 /* Pointer into encoded_message field from the pcep_message */
77 const uint8_t *encoded_tlv;
78 uint16_t encoded_tlv_length;
79 };
80
81 /* STATEFUL-PCE-CAPABILITY TLV, Used in Open Object. RFCs: 8231, 8232, 8281 */
82 #define TLV_STATEFUL_PCE_CAP_FLAG_U 0x01
83 #define TLV_STATEFUL_PCE_CAP_FLAG_S 0x02
84 #define TLV_STATEFUL_PCE_CAP_FLAG_I 0x04
85 #define TLV_STATEFUL_PCE_CAP_FLAG_T 0x08
86 #define TLV_STATEFUL_PCE_CAP_FLAG_D 0x10
87 #define TLV_STATEFUL_PCE_CAP_FLAG_F 0x20
88
89 struct pcep_object_tlv_stateful_pce_capability {
90 struct pcep_object_tlv_header header;
91 bool flag_u_lsp_update_capability; /* RFC 8231 */
92 bool flag_s_include_db_version; /* RFC 8232 */
93 bool flag_i_lsp_instantiation_capability; /* RFC 8281 */
94 bool flag_t_triggered_resync; /* RFC 8232 */
95 bool flag_d_delta_lsp_sync; /* RFC 8232 */
96 bool flag_f_triggered_initial_sync; /* RFC 8232 */
97 };
98
99 /* NOPATH-VECTOR TLV, Used in the Reply NoPath Object. */
100 struct pcep_object_tlv_nopath_vector {
101 struct pcep_object_tlv_header header;
102 uint32_t error_code;
103 };
104
105 /* STATEFUL-PCE-CAPABILITY TLV, Used in Open Object. RFCs: 8232 */
106 struct pcep_object_tlv_lsp_db_version {
107 struct pcep_object_tlv_header header;
108 uint64_t lsp_db_version;
109 };
110
111 /* Speaker Entity Identifier TLV, Used in Open Object. RFCs: 8232 */
112 struct pcep_object_tlv_speaker_entity_identifier {
113 struct pcep_object_tlv_header header;
114 double_linked_list *speaker_entity_id_list; /* list of uint32_t speaker
115 entity ids */
116 };
117
118 /* Ipv4 LSP Identifier TLV, Used in LSP Object. RFCs: 8231 */
119 struct pcep_object_tlv_ipv4_lsp_identifier {
120 struct pcep_object_tlv_header header;
121 struct in_addr ipv4_tunnel_sender;
122 uint16_t lsp_id;
123 uint16_t tunnel_id;
124 struct in_addr extended_tunnel_id;
125 struct in_addr ipv4_tunnel_endpoint;
126 };
127
128 /* Ipv6 LSP Identifier TLV, Used in LSP Object. RFCs: 8231 */
129 struct pcep_object_tlv_ipv6_lsp_identifier {
130 struct pcep_object_tlv_header header;
131 struct in6_addr ipv6_tunnel_sender;
132 uint16_t lsp_id;
133 uint16_t tunnel_id;
134 struct in6_addr extended_tunnel_id;
135 struct in6_addr ipv6_tunnel_endpoint;
136 };
137
138 /* Symbolic Path Name TLV, Used in LSP Object. RFCs: 8231 */
139 #define MAX_SYMBOLIC_PATH_NAME 256
140
141 struct pcep_object_tlv_symbolic_path_name {
142 struct pcep_object_tlv_header header;
143 uint16_t symbolic_path_name_length;
144 char symbolic_path_name[MAX_SYMBOLIC_PATH_NAME];
145 };
146
147 /* LSP Error Code TLV, Used in LSP Object. RFCs: 8231 */
148 enum pcep_tlv_lsp_error_codes {
149 PCEP_TLV_LSP_ERROR_CODE_UNKNOWN = 1,
150 PCEP_TLV_LSP_ERROR_CODE_LSP_LIMIT_REACHED = 2,
151 PCEP_TLV_LSP_ERROR_CODE_TOO_MANY_PENDING_LSP_UPDATES = 3,
152 PCEP_TLV_LSP_ERROR_CODE_UNACCEPTABLE_PARAMS = 4,
153 PCEP_TLV_LSP_ERROR_CODE_INTERNAL_ERROR = 5,
154 PCEP_TLV_LSP_ERROR_CODE_LSP_BROUGHT_DOWN = 6,
155 PCEP_TLV_LSP_ERROR_CODE_LSP_PREEMPTED = 7,
156 PCEP_TLV_LSP_ERROR_CODE_RSVP_SIGNALING_ERROR = 8,
157 };
158
159 struct pcep_object_tlv_lsp_error_code {
160 struct pcep_object_tlv_header header;
161 enum pcep_tlv_lsp_error_codes lsp_error_code;
162 };
163
164 /* Path Setup Type TLV, Used in RP and SRP Object. RFCs: 8408,
165 * draft-ietf-pce-segment-routing-16 */
166 #define SR_TE_PST 1
167
168 struct pcep_object_tlv_path_setup_type {
169 struct pcep_object_tlv_header header;
170 uint8_t path_setup_type;
171 };
172
173 /* Path Setup Type Capability TLV, Used in Open Object. RFCs: 8408,
174 * draft-ietf-pce-segment-routing-16 */
175 struct pcep_object_tlv_path_setup_type_capability {
176 struct pcep_object_tlv_header header;
177 double_linked_list *pst_list; /* list of uint8_t PSTs */
178 double_linked_list *sub_tlv_list; /* list of sub_tlvs */
179 };
180
181 /* SR PCE Capability sub-TLV, Used in Open Object. RFCs:
182 * draft-ietf-pce-segment-routing-16 */
183 #define TLV_SR_PCE_CAP_FLAG_X 0x01
184 #define TLV_SR_PCE_CAP_FLAG_N 0x02
185
186 struct pcep_object_tlv_sr_pce_capability {
187 struct pcep_object_tlv_header header;
188 bool flag_n;
189 bool flag_x;
190 uint8_t max_sid_depth;
191 };
192
193
194 /* RSVP Error Spec TLV, Used in LSP Object. RFCs: 8231, 2205 */
195 #define RSVP_ERROR_SPEC_IPV4_CTYPE 1
196 #define RSVP_ERROR_SPEC_IPV6_CTYPE 2
197 #define RSVP_ERROR_SPEC_CLASS_NUM 6
198
199 struct pcep_object_tlv_rsvp_error_spec {
200 struct pcep_object_tlv_header header;
201 uint8_t class_num;
202 uint8_t c_type;
203 uint8_t error_code;
204 uint16_t error_value;
205 /* Use the c_type to determine which union entry to use */
206 union error_spec_ip {
207 struct in_addr ipv4_error_node_address;
208 struct in6_addr ipv6_error_node_address;
209 } error_spec_ip;
210 };
211
212 /* SR Policy Identifier TLV Used in Association Object.
213 * draft-barth-pce-segment-routing-policy-cp-04*/
214 struct pcep_object_tlv_srpag_pol_id {
215 struct pcep_object_tlv_header header;
216 uint32_t color;
217 bool is_ipv4;
218 union end_point_ {
219 struct in_addr ipv4;
220 struct in6_addr ipv6;
221 } end_point;
222 };
223
224 /*draft-ietf-spring-segment-routing-policy-06*/
225 #define MAX_POLICY_NAME 256
226
227 /* SR Policy Name TLV Used in Association Object.
228 * draft-barth-pce-segment-routing-policy-cp-04*/
229 struct pcep_object_tlv_srpag_pol_name {
230 struct pcep_object_tlv_header header;
231 uint16_t name_length;
232 char name[MAX_POLICY_NAME];
233 };
234
235 /* SR Candidate Path Id TLV Used in Association Object.
236 * draft-barth-pce-segment-routing-policy-cp-04*/
237 struct pcep_object_tlv_srpag_cp_id {
238 struct pcep_object_tlv_header header;
239 uint8_t proto;
240 uint32_t orig_asn;
241 struct in6_addr orig_addres; /*With ipv4 embedded*/
242 uint32_t discriminator;
243 };
244
245 /* SR Candidate Preference TLV Used in Association Object.
246 * draft-barth-pce-segment-routing-policy-cp-04*/
247 struct pcep_object_tlv_srpag_cp_pref {
248 struct pcep_object_tlv_header header;
249 uint32_t preference;
250 };
251
252 struct pcep_object_tlv_vendor_info {
253 struct pcep_object_tlv_header header;
254 uint32_t enterprise_number;
255 uint32_t enterprise_specific_info;
256 };
257
258 /* arbitrary TLV 65535 */
259 #define MAX_ARBITRARY_SIZE 256
260 struct pcep_object_tlv_arbitrary {
261 struct pcep_object_tlv_header header;
262 enum pcep_object_tlv_types arbitraty_type;
263 uint16_t data_length;
264 char data[MAX_ARBITRARY_SIZE];
265 };
266
267 /* Objective Functions List RFC 5541
268 * At least the following 6 OF codes must be supported */
269 enum objective_function_codes {
270 PCEP_OF_CODE_MINIMUM_COST_PATH = 1, /* MCP */
271 PCEP_OF_CODE_MINIMUM_LOAD_PATH = 2, /* MLP */
272 PCEP_OF_CODE_MAXIMUM_BW_PATH = 3, /* MBP */
273 PCEP_OF_CODE_MINIMIZE_AGGR_BW_CONSUMPTION = 4, /* MBC */
274 PCEP_OF_CODE_MINIMIZE_MOST_LOADED_LINK = 5, /* MLL */
275 PCEP_OF_CODE_MINIMIZE_CUMULATIVE_COST_PATHS = 6, /* MCC */
276 };
277
278 struct pcep_object_tlv_of_list {
279 struct pcep_object_tlv_header header;
280 double_linked_list *of_list; /* list of uint16_t OF code points */
281 };
282
283 /*
284 * TLV creation functions
285 */
286
287 /*
288 * Open Object TLVs
289 */
290
291 struct pcep_object_tlv_stateful_pce_capability *
292 pcep_tlv_create_stateful_pce_capability(
293 bool flag_u_lsp_update_capability, bool flag_s_include_db_version,
294 bool flag_i_lsp_instantiation_capability, bool flag_t_triggered_resync,
295 bool flag_d_delta_lsp_sync, bool flag_f_triggered_initial_sync);
296 struct pcep_object_tlv_lsp_db_version *
297 pcep_tlv_create_lsp_db_version(uint64_t lsp_db_version);
298 struct pcep_object_tlv_speaker_entity_identifier *
299 pcep_tlv_create_speaker_entity_id(double_linked_list *speaker_entity_id_list);
300 struct pcep_object_tlv_path_setup_type *
301 pcep_tlv_create_path_setup_type(uint8_t pst);
302 struct pcep_object_tlv_path_setup_type_capability *
303 pcep_tlv_create_path_setup_type_capability(double_linked_list *pst_list,
304 double_linked_list *sub_tlv_list);
305 struct pcep_object_tlv_sr_pce_capability *
306 pcep_tlv_create_sr_pce_capability(bool flag_n, bool flag_x,
307 uint8_t max_sid_depth);
308 struct pcep_object_tlv_of_list *
309 pcep_tlv_create_of_list(double_linked_list *of_list);
310
311 /*
312 * LSP Object TLVs
313 */
314
315 struct pcep_object_tlv_ipv4_lsp_identifier *
316 pcep_tlv_create_ipv4_lsp_identifiers(struct in_addr *ipv4_tunnel_sender,
317 struct in_addr *ipv4_tunnel_endpoint,
318 uint16_t lsp_id, uint16_t tunnel_id,
319 struct in_addr *extended_tunnel_id);
320 struct pcep_object_tlv_ipv6_lsp_identifier *
321 pcep_tlv_create_ipv6_lsp_identifiers(struct in6_addr *ipv6_tunnel_sender,
322 struct in6_addr *extended_tunnel_id,
323 uint16_t lsp_id, uint16_t tunnel_id,
324 struct in6_addr *ipv6_tunnel_endpoint);
325 /* symbolic_path_name_length should NOT include the null terminator and cannot
326 * be zero */
327 struct pcep_object_tlv_symbolic_path_name *
328 pcep_tlv_create_symbolic_path_name(const char *symbolic_path_name,
329 uint16_t symbolic_path_name_length);
330 struct pcep_object_tlv_lsp_error_code *
331 pcep_tlv_create_lsp_error_code(enum pcep_tlv_lsp_error_codes lsp_error_code);
332 struct pcep_object_tlv_rsvp_error_spec *
333 pcep_tlv_create_rsvp_ipv4_error_spec(struct in_addr *error_node_ip,
334 uint8_t error_code, uint16_t error_value);
335 struct pcep_object_tlv_rsvp_error_spec *
336 pcep_tlv_create_rsvp_ipv6_error_spec(struct in6_addr *error_node_ip,
337 uint8_t error_code, uint16_t error_value);
338
339 struct pcep_object_tlv_nopath_vector *
340 pcep_tlv_create_nopath_vector(uint32_t error_code);
341 struct pcep_object_tlv_vendor_info *
342 pcep_tlv_create_vendor_info(uint32_t enterprise_number,
343 uint32_t enterprise_specific_info);
344
345 struct pcep_object_tlv_arbitrary *
346 pcep_tlv_create_tlv_arbitrary(const char *data, uint16_t data_length,
347 int tlv_id);
348 /*
349 * SRPAG (SR Association Group) TLVs
350 */
351
352 struct pcep_object_tlv_srpag_pol_id *
353 pcep_tlv_create_srpag_pol_id_ipv4(uint32_t color, struct in_addr *ipv4);
354 struct pcep_object_tlv_srpag_pol_id *
355 pcep_tlv_create_srpag_pol_id_ipv6(uint32_t color, struct in6_addr *ipv6);
356 struct pcep_object_tlv_srpag_pol_name *
357 pcep_tlv_create_srpag_pol_name(const char *pol_name, uint16_t pol_name_length);
358 struct pcep_object_tlv_srpag_cp_id *
359 pcep_tlv_create_srpag_cp_id(uint8_t proto_origin, uint32_t asn,
360 struct in6_addr *in6_addr_with_mapped_ipv4,
361 uint32_t discriminator);
362 struct pcep_object_tlv_srpag_cp_pref *
363 pcep_tlv_create_srpag_cp_pref(uint32_t pref);
364
365
366 #ifdef __cplusplus
367 }
368 #endif
369
370 #endif /* PCEP_TLVS_H_ */