-
Notifications
You must be signed in to change notification settings - Fork 39
/
Builder.hpp
120 lines (110 loc) · 3.21 KB
/
Builder.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* \file src/plugins/input/fds/Builder.hpp
* \author Lukas Hutak <[email protected]>
* \brief IPFIX Message builder
* \date May 2020
*/
#ifndef FDS_BUILDER_HPP
#define FDS_BUILDER_HPP
#include <cstdlib>
#include <memory>
#include <libfds.h>
/// IPFIX Message builder
class Builder {
private:
/// Memory of IPFIX Message to generate (can be nullptr)
std::unique_ptr<uint8_t, decltype(&free)> m_msg = {nullptr, &free};
/// Allocated size (bytes)
uint16_t m_msg_alloc;
/// Filled size (bytes)
uint16_t m_msg_valid;
/// Currently edited Flow Set (zero == invalid)
uint16_t m_set_offset;
/// Set ID of the current Flow Set
uint16_t m_set_id;
/// Size of the current IPFIX Set
uint16_t m_set_size;
void
fset_new(uint16_t sid);
void
fset_close();
public:
/**
* @brief Create an IPFIX Message generator
*
* By default, ODID, Sequence Number, and Export Time are set to zeros.
* @param[in] size Maximal size of the message (allocation size)
*/
Builder(uint16_t size);
~Builder() = default;
Builder(Builder &&other) = default;
/**
* @brief Change maximal size of the message
*
* If the size is less than the size of the currently built message, the
* message is trimmed!
* @param[in] size Maximal size (i.e. allocation size)
*/
void
resize(uint16_t size);
/**
* @brief Test if the builder contains an IPFIX Message without content
*
* @note The builder is also considered as empty after release().
* @return True/false
*/
bool
empty();
/**
* @brief Release the generated IPFIX Message
* @warning After releasing, the class functions MUST NOT be used anymore!
* @return Pointer to the message (real size is part of the Message)
*/
uint8_t *
release();
/**
* @brief Set Export Time of the IPFIX Message
* @param[in] time Export Time
*/
void
set_etime(uint32_t time);
/**
* @brief Set Observation Domain ID (ODID) of the IPFIX Message
* @param[in] odid ODID
*/
void
set_odid(uint32_t odid);
/**
* @brief Set Sequence Number of the IPFIX Message
* @param[in] seq_num Sequence Number
*/
void
set_seqnum(uint32_t seq_num);
/**
* @brief Add an (Options) Template Record
* @param[in] tmplt IPFIX (Options) Template
* @return True, if the Template has been successfully added
* @return False, if the Message is already full
*/
bool
add_template(const struct fds_template *tmplt);
/**
* @brief Add a Data Record
* @param[in] rec IPFIX Data Record
* @return True, if the Record has been successfully added
* @return False, if the Message is already full
*/
bool
add_record(const struct fds_drec *rec);
/**
* @brief Add an All (Options) Template Withdrawals (only TCP, SCTP, and File sessions)
* @note
* After calling the function, all previous (Options) Templates are considered to
* be invalid.
* @return True, if the Withdrawals has been successfully added
* @return False, if the Message is already full
*/
bool
add_withdrawals();
};
#endif // FDS_BUILDER_HPP