Skip to content

Commit a98ff16

Browse files
committed
FDS Output: introduce <outputSelection> configuration node
1 parent 7a2283a commit a98ff16

File tree

3 files changed

+85
-12
lines changed

3 files changed

+85
-12
lines changed

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

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ ipx_plugin_init(ipx_ctx_t *ctx, const char *params)
7474
return IPX_ERR_DENIED;
7575
}
7676

77+
const fds_iemgr_t *iemgr = ipx_ctx_iemgr_get(ctx);
78+
7779
try {
7880
// Parse configuration, try to create a storage and time window
7981
std::unique_ptr<Instance> instance(new Instance);
80-
instance->config_ptr.reset(new Config(params));
82+
instance->config_ptr.reset(new Config(params, iemgr));
8183
instance->storage_ptr.reset(new Storage(ctx, *instance->config_ptr));
8284
window_check(*instance);
8385
// Everything seems OK

0 commit comments

Comments
 (0)