Skip to content

Commit b71e916

Browse files
committed
Merge branch 'fds-output-selection' into 'devel'
FDS Output: Add support for selecting only a subset of fields to be saved See merge request monitoring/ipfixcol2!17
2 parents 9e8f903 + 689f6c9 commit b71e916

File tree

6 files changed

+338
-32
lines changed

6 files changed

+338
-32
lines changed

src/plugins/output/fds/README.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ Example configuration
2828
<timeWindow>300</timeWindow>
2929
<align>yes</align>
3030
</dumpInterval>
31+
<outputSelection>
32+
<element>iana:octetDeltaCount</element>
33+
<element>iana@reverse:octetDeltaCount@reverse</element>
34+
<element>iana:packetDeltaCount</element>
35+
<element>iana@reverse:packetDeltaCount@reverse</element>
36+
<element>iana:destinationIPv4Address</element>
37+
<element>iana:destinationIPv6Address</element>
38+
<element>iana:sourceIPv4Address</element>
39+
<element>iana:sourceIPv6Address</element>
40+
<element>iana:destinationTransportPort</element>
41+
<element>iana:sourceTransportPort</element>
42+
<element>iana:protocolIdentifier</element>
43+
<element>cesnet:quicSNI</element>
44+
<element>cesnet:TLSSNI</element>
45+
</outputSelection>
3146
</params>
3247
</output>
3348
@@ -62,6 +77,20 @@ Parameters
6277
and window size is 5 minutes long, files will be created at 0, 5, 10, etc.
6378
[values: yes/no, default: yes]
6479

80+
:``outputSelection``:
81+
Select only a subset of fields that will be saved in output. A list of IPFIX
82+
elements is provided. Any fields of an element that are not a part of this list
83+
will be skipped and not included in the resulting FDS output file.
84+
Note that when
85+
[default: all fields]
86+
87+
:``element``:
88+
The identifier of the IPFIX element in the form of ``SCOPE_NAME:ELEMENT_NAME``,
89+
for example ``iana:sourceIPv4Address``. ``SCOPE_NAME:`` prefix can be omitted in
90+
case of "iana:".
91+
Note: Reverse elements use the following naming pattern
92+
``iana@reverse:sourceIPv4Address@reverse``
93+
6594
:``asyncIO``:
6695
Allows to use asynchronous I/O for writing to the file. Usually when parts
6796
of the file are being written, the process is blocked on synchronous I/O

src/plugins/output/fds/src/Config.cpp

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* \file src/plugins/output/fds/src/Config.cpp
33
* \author Lukas Hutak <[email protected]>
4+
* \author Michal Sedlak <[email protected]>
45
* \brief Parser of XML configuration (source file)
56
* \date 2019
67
*
@@ -21,6 +22,11 @@
2122
* <align>...</align> <!-- optional -->
2223
* </dumpInterval>
2324
* <asyncIO>...</asyncIO> <!-- optional -->
25+
* <outputSelection> <!-- optional -->
26+
* <element>...</element>
27+
* <element>...</element>
28+
* ...
29+
* </outputSelection>
2430
* </params>
2531
*/
2632

@@ -30,9 +36,12 @@ enum params_xml_nodes {
3036
NODE_COMPRESS,
3137
NODE_DUMP,
3238
NODE_ASYNCIO,
39+
NODE_SELECTION,
3340

3441
DUMP_WINDOW,
35-
DUMP_ALIGN
42+
DUMP_ALIGN,
43+
44+
SELECTION_ELEMENT,
3645
};
3746

3847
/// Definition of the \<dumpInterval\> node
@@ -42,17 +51,24 @@ static const struct fds_xml_args args_dump[] = {
4251
FDS_OPTS_END
4352
};
4453

54+
/// Definition of the \<outputSelection\> node
55+
static const struct fds_xml_args args_selection[] = {
56+
FDS_OPTS_ELEM(SELECTION_ELEMENT, "element", FDS_OPTS_T_STRING, FDS_OPTS_P_MULTI),
57+
FDS_OPTS_END
58+
};
59+
4560
/// Definition of the \<params\> node
4661
static const struct fds_xml_args args_params[] = {
4762
FDS_OPTS_ROOT("params"),
48-
FDS_OPTS_ELEM(NODE_STORAGE, "storagePath", FDS_OPTS_T_STRING, 0),
49-
FDS_OPTS_ELEM(NODE_COMPRESS, "compression", FDS_OPTS_T_STRING, FDS_OPTS_P_OPT),
50-
FDS_OPTS_NESTED(NODE_DUMP, "dumpInterval", args_dump, FDS_OPTS_P_OPT),
51-
FDS_OPTS_ELEM(NODE_ASYNCIO, "asyncIO", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
63+
FDS_OPTS_ELEM(NODE_STORAGE, "storagePath", FDS_OPTS_T_STRING, 0),
64+
FDS_OPTS_ELEM(NODE_COMPRESS, "compression", FDS_OPTS_T_STRING, FDS_OPTS_P_OPT),
65+
FDS_OPTS_NESTED(NODE_DUMP, "dumpInterval", args_dump, FDS_OPTS_P_OPT),
66+
FDS_OPTS_ELEM(NODE_ASYNCIO, "asyncIO", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
67+
FDS_OPTS_NESTED(NODE_SELECTION, "outputSelection", args_selection, FDS_OPTS_P_OPT),
5268
FDS_OPTS_END
5369
};
5470

55-
Config::Config(const char *params)
71+
Config::Config(const char *params, const fds_iemgr_t *iemgr)
5672
{
5773
set_default();
5874

@@ -74,7 +90,7 @@ Config::Config(const char *params)
7490

7591
// Parse parameters and check configuration
7692
try {
77-
parse_root(params_ctx);
93+
parse_root(params_ctx, iemgr);
7894
validate();
7995
} catch (std::exception &ex) {
8096
throw std::runtime_error("Failed to parse the configuration: " + std::string(ex.what()));
@@ -93,6 +109,9 @@ Config::set_default()
93109

94110
m_window.align = true;
95111
m_window.size = WINDOW_SIZE;
112+
113+
m_selection_used = false;
114+
m_selection.clear();
96115
}
97116

98117
/**
@@ -114,10 +133,11 @@ Config::validate()
114133
/**
115134
* @brief Process \<params\> node
116135
* @param[in] ctx XML context to process
136+
* @param[in] iemgr Information elements manager
117137
* @throw runtime_error if the parser fails
118138
*/
119139
void
120-
Config::parse_root(fds_xml_ctx_t *ctx)
140+
Config::parse_root(fds_xml_ctx_t *ctx, const fds_iemgr_t *iemgr)
121141
{
122142
const struct fds_xml_cont *content;
123143
while (fds_xml_next(ctx, &content) != FDS_EOC) {
@@ -151,6 +171,11 @@ Config::parse_root(fds_xml_ctx_t *ctx)
151171
assert(content->type == FDS_OPTS_T_CONTEXT);
152172
parse_dump(content->ptr_ctx);
153173
break;
174+
case NODE_SELECTION:
175+
// Output selection
176+
assert(content->type == FDS_OPTS_T_CONTEXT);
177+
parse_selection(content->ptr_ctx, iemgr);
178+
break;
154179
default:
155180
// Internal error
156181
throw std::runtime_error("Unknown XML node");
@@ -187,4 +212,38 @@ Config::parse_dump(fds_xml_ctx_t *ctx)
187212
throw std::runtime_error("Unknown XML node");
188213
}
189214
}
190-
}
215+
}
216+
217+
/**
218+
* @brief Auxiliary function for parsing \<outputSelection\> options
219+
* @param[in] ctx XML context to process
220+
* @param[in] iemgr Information elements manager
221+
* @throw runtime_error if the parser fails
222+
*/
223+
void
224+
Config::parse_selection(fds_xml_ctx_t *ctx, const fds_iemgr_t* iemgr)
225+
{
226+
m_selection_used = true;
227+
228+
const struct fds_xml_cont *content;
229+
while(fds_xml_next(ctx, &content) != FDS_EOC) {
230+
switch (content->id) {
231+
case SELECTION_ELEMENT: {
232+
// IPFIX element to select
233+
assert(content->type == FDS_OPTS_T_STRING);
234+
235+
const fds_iemgr_elem* ie = fds_iemgr_elem_find_name(iemgr, content->ptr_string);
236+
if (!ie) {
237+
throw std::runtime_error("Element \"" + std::string(content->ptr_string) + "\" not found!");
238+
}
239+
element elem;
240+
elem.pen = ie->scope->pen;
241+
elem.id = ie->id;
242+
m_selection.push_back(elem);
243+
} break;
244+
default:
245+
// Internal error
246+
throw std::runtime_error("Unknown XML node");
247+
}
248+
}
249+
}

src/plugins/output/fds/src/Config.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* \file src/plugins/output/fds/src/Config.hpp
33
* \author Lukas Hutak <[email protected]>
4+
* \author Michal Sedlak <[email protected]>
45
* \brief Parser of XML configuration (header file)
56
* \date 2019
67
*
@@ -12,6 +13,7 @@
1213
#define IPFIXCOL2_FDS_CONFIG_HPP
1314

1415
#include <string>
16+
#include <vector>
1517
#include <libfds.h>
1618

1719
/**
@@ -22,9 +24,10 @@ class Config {
2224
/**
2325
* @brief Parse configuration of the plugin
2426
* @param[in] params XML parameters to parse
27+
* @param[in] iemgr Information elements manager
2528
* @throw runtime_exception on error
2629
*/
27-
Config(const char *params);
30+
Config(const char *params, const fds_iemgr_t *iemgr);
2831
~Config() = default;
2932

3033
enum class calg {
@@ -45,6 +48,13 @@ class Config {
4548
uint32_t size; ///< Time window size
4649
} m_window; ///< Window alignment
4750

51+
struct element {
52+
uint32_t pen;
53+
uint16_t id;
54+
};
55+
bool m_selection_used;
56+
std::vector<element> m_selection;
57+
4858
private:
4959
/// Default window size
5060
static const uint32_t WINDOW_SIZE = 300U;
@@ -55,9 +65,11 @@ class Config {
5565
validate();
5666

5767
void
58-
parse_root(fds_xml_ctx_t *ctx);
68+
parse_root(fds_xml_ctx_t *ctx, const fds_iemgr_t *iemgr);
5969
void
6070
parse_dump(fds_xml_ctx_t *ctx);
71+
void
72+
parse_selection(fds_xml_ctx_t *ctx, const fds_iemgr_t *iemgr);
6173
};
6274

6375

0 commit comments

Comments
 (0)