]> git.proxmox.com Git - mirror_frr.git/blame - pceplib/pcep_msg_encoding.h
*: auto-convert to SPDX License IDs
[mirror_frr.git] / pceplib / pcep_msg_encoding.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: LGPL-2.1-or-later
74971473
JG
2/*
3 * This file is part of the PCEPlib, a PCEP protocol library.
4 *
5 * Copyright (C) 2020 Volta Networks https://voltanet.io/
6 *
74971473
JG
7 * Author : Brady Johnson <brady@voltanet.io>
8 *
9 */
10
11
12/*
13 * Definitions for encoding and decoding PCEP messages, objects, and TLVs.
14 */
15
16#ifndef PCEP_ENCODING_H
17#define PCEP_ENCODING_H
18
19#include <stdbool.h>
20
21#include "pcep_msg_messages.h"
22#include "pcep_msg_objects.h"
23#include "pcep_msg_tlvs.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29struct pcep_versioning {
30 bool draft_ietf_pce_segment_routing_07; /* If false, use draft16 */
31 /* As more draft versions are incorporated, add appropriate attributes
32 */
33};
34
35#define MESSAGE_HEADER_LENGTH 4
36#define PCEP_MESSAGE_LENGTH 65535
37#define OBJECT_HEADER_LENGTH 4
38#define OBJECT_RO_SUBOBJ_HEADER_LENGTH 2
39#define TLV_HEADER_LENGTH 4
40#define LENGTH_1WORD sizeof(uint32_t)
41#define LENGTH_2WORDS sizeof(uint32_t) * 2
42#define LENGTH_3WORDS sizeof(uint32_t) * 3
43#define LENGTH_4WORDS sizeof(uint32_t) * 4
44#define LENGTH_5WORDS sizeof(uint32_t) * 5
45#define LENGTH_6WORDS sizeof(uint32_t) * 6
46#define LENGTH_7WORDS sizeof(uint32_t) * 7
47#define LENGTH_8WORDS sizeof(uint32_t) * 8
48#define LENGTH_9WORDS sizeof(uint32_t) * 9
49#define LENGTH_10WORDS sizeof(uint32_t) * 10
50#define LENGTH_11WORDS sizeof(uint32_t) * 11
51#define LENGTH_12WORDS sizeof(uint32_t) * 12
52#define LENGTH_13WORDS sizeof(uint32_t) * 13
53
54/* When iterating sub-objects or TLVs, limit to 10 in case corrupt data is
55 * received */
56#define MAX_ITERATIONS 10
57
58struct pcep_versioning *create_default_pcep_versioning(void);
59void destroy_pcep_versioning(struct pcep_versioning *versioning);
60
61/*
62 * Message encoding / decoding functions
63 */
64
65/* Called before sending messages to encode the message to a byte buffer in
66 * Network byte order. This function will also encode all the objects and their
67 * TLVs in the message. The result will be stored in the encoded_message field
68 * in the pcep_message. Implemented in pcep-messages-encoding.c */
69void pcep_encode_message(struct pcep_message *message,
70 struct pcep_versioning *versioning);
71
72/* Decode the message header and return the message length.
73 * Returns < 0 for invalid message headers. */
74int32_t pcep_decode_validate_msg_header(const uint8_t *msg_buf);
75
76/* Decode the entire message */
77struct pcep_message *pcep_decode_message(const uint8_t *message_buffer);
78
79
80/*
81 * Object encoding / decoding functions
82 */
83
84/* Implemented in pcep-objects-encoding.c
85 * Encode the object in struct pcep_object_header* into the uint8_t *buf,
86 * and return the encoded object_length. */
87uint16_t pcep_encode_object(struct pcep_object_header *object_hdr,
88 struct pcep_versioning *versioning, uint8_t *buf);
89
90/* Implemented in pcep-objects-encoding.c
91 * Decode the object, including the TLVs (if any) and return the object.
92 * Returns object on success, NULL otherwise. */
93struct pcep_object_header *pcep_decode_object(const uint8_t *msg_buf);
94
95/* Internal util functions implemented in pcep-objects-encoding.c */
96void encode_ipv6(struct in6_addr *src_ipv6, uint32_t *dst);
97void decode_ipv6(const uint32_t *src, struct in6_addr *dst_ipv6);
98uint16_t normalize_pcep_tlv_length(uint16_t length);
99bool pcep_object_has_tlvs(struct pcep_object_header *object_hdr);
100uint16_t pcep_object_get_length_by_hdr(struct pcep_object_header *object_hdr);
101uint16_t pcep_object_get_length(enum pcep_object_classes object_class,
102 enum pcep_object_types object_type);
103
104
105/*
106 * TLV encoding / decoding functions
107 */
108
109/* Implemented in pcep-tlv-encoding.c
110 * Encode the tlv in struct pcep_tlv_header* into the uint8_t *buf,
111 * and return the encoded tlv_length. */
112uint16_t pcep_encode_tlv(struct pcep_object_tlv_header *tlv_hdr,
113 struct pcep_versioning *versioning, uint8_t *buf);
114
115/* Decode the TLV in tlv_buf and return a pointer to the object */
116struct pcep_object_tlv_header *pcep_decode_tlv(const uint8_t *tlv_buf);
117
118
119/*
120 * utils mainly for testing purposes
121 */
122bool validate_message_objects(struct pcep_message *msg);
123
124#ifdef __cplusplus
125}
126#endif
127
128#endif