Skip to content

Commit 5c71f2b

Browse files
committed
IPFIX output: many code improvements, added documentation
1 parent 866dfaf commit 5c71f2b

File tree

6 files changed

+324
-212
lines changed

6 files changed

+324
-212
lines changed
Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
IPFIX (output plugin)
22
=====================
33

4-
The plugin outputs incoming IPFIX Data to an IPFIX File or a series of IPFIX Files.
5-
6-
An IPFIX File is a serialized stream of IPFIX Messages. Simply put, the plugin stores all valid packets received by the collector into one or more IPFIX Files. Although this is not an optimal way to store flows, it can be quite useful for testing purposes - capture flow records into IPFIX File(s) and replay them using ipfixsend2 tool.
7-
8-
After a new file is started, all the (options) templates seen in the (options) template sets of an ODID that are still available are written to the file once the first IPFIX Message corresponding to the ODID arrives with at least one successfully parsed data record. This is necessary so each file can be used individually independent of the (options) template sets from previous files.
4+
The plugin writes incoming IPFIX Messages to an IPFIX File or a series of IPFIX
5+
Files.
96

7+
An IPFIX File is a serialized stream of IPFIX Messages. Simply put, the plugin
8+
stores all valid packets received by the collector into one or more IPFIX Files.
9+
Although this is not an optimal way to store flows, it can be quite useful
10+
for testing purposes - capture flow records into IPFIX File(s) and replay them
11+
using ``ipfixsend2`` tool.
1012

1113
Limitations
1214
-----------
13-
As there is no session information in raw IPFIX Data, we can't distinguish messages from multiple sessions using the same ODID. For this reason, the same ODID can only be used by one session at a time, and all messages from other sessions using the ODID that's already in use are ignored and a warning message is printed. All ODIDs used by a session are released once the session closes and they can be used by another session.
1415

16+
In a situation when multiple exporters are using the same ODID at a time, the
17+
file format can store flow records only from one of the conflicting exporters
18+
with the given ODID.
19+
20+
This is due to fact that the IPFIX Data Records (i.e. flow records) are
21+
formatted based on so called (Options) Template definitions (i.e. descriptions
22+
of flow record structures), which are unique for combination of a Transport
23+
Session (e.g. connection to a flow exporter) and an ODID. As there is no session
24+
information in raw IPFIX Messages, we can't distinguish Messages from multiple
25+
sessions using the same ODID. For this reason, each ODID can be used only by
26+
one session at a time, and all messages from other sessions using the
27+
same ODID that's already in use are ignored and a warning message is shown.
28+
Once a Transport Session is closed, ODIDs used by the session are released
29+
and can be later reused by another session.
1530

1631
Example configuration
1732
---------------------
@@ -22,9 +37,9 @@ Example configuration
2237
<name>IPFIX output</name>
2338
<plugin>ipfix</plugin>
2439
<params>
25-
<filename>/tmp/ipfix/%d-%m-%y/%H:%M:%S.ipfix</filename>
40+
<filename>/tmp/ipfix/%Y%m%d%H%M%S.ipfix</filename>
2641
<useLocalTime>false</useLocalTime>
27-
<windowSize>60</windowSize>
42+
<windowSize>300</windowSize>
2843
<alignWindows>true</alignWindows>
2944
<skipUnknownDataSets>true</skipUnknownDataSets>
3045
<splitOnExportTime>false</splitOnExportTime>
@@ -35,19 +50,42 @@ Parameters
3550
----------
3651

3752
:``filename``:
38-
The output filename, allows the use of strftime format values to add the export time into the file path.
53+
Specifies an absolute path of output files. The path should contain format
54+
specifier for day, month, etc. For example "/tmp/ipfix/%Y%m%d%H%M%S.ipfix".
55+
See ``strftime``\ (3) for more information.
3956

4057
:``useLocalTime``:
41-
Specifies whether the time values in filenames should be in local time instead of UTC. [default: false]
58+
Specifies whether the time values in filenames should be in local time
59+
instead of UTC. [default: false]
4260

4361
:``windowSize``:
44-
The number of seconds before a new file is created. The value of 0 means the file will never split. [default: 0]
62+
Specifies the time interval in seconds to rotate files. If the value
63+
is "0", all flow will be stored into a single file. [default: 0]
4564

4665
:``alignWindows``:
47-
Specifies whether the file should only be split on multiples of windowSize. [default: true]
66+
Align file rotation with next N minute interval (true/false). [default: true]
4867

4968
:``skipUnknownDataSets``:
50-
Specifies whether data sets with missing template should be left out from the output file. Sequence numbers and message lengths will be adjusted accordingly. [default: false]
69+
Specifies whether Data Sets with unknown (Options) Template should be left
70+
out from the output file. Sequence numbers and message lengths will be
71+
adjusted accordingly. [default: false]
5172

5273
:``splitOnExportTime``:
53-
Specifies whether files should be split based on export time instead of system time. [default: false]
74+
Specifies whether files should be rotated based on IPFIX Export Time
75+
(i.e. timestamp from IPFIX Message header) instead of system time.
76+
Warning: If the plugin receives flow records from multiple exporters at time
77+
the rotation could be unsteady. [default: false]
78+
79+
Note
80+
----
81+
82+
After a new IPFIX File is created, all previously seen and still valid (Options)
83+
Templates of the each ODID are written to the file once the first IPFIX Message
84+
corresponding to the ODID arrives with at least one successfully parsed data record.
85+
This is necessary so each file can be used independently of the (Options) Template
86+
definitions from previous files.
87+
88+
``ipfixsend2`` tool doesn't support sequential reading of multiple IPFIX Files
89+
right now. However, there is a workaround - you can merge multiple IPFIX Files
90+
using cat tool e.g. ``cat file1.ipfix file2.ipfix > merge.ipfix`` and then use
91+
``ipfixsend2 -i merge.ipfix`` to send data.

src/plugins/output/ipfix/src/Config.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* \file src/plugins/output/ipfix/src/Config.cpp
33
* \author Michal Sedlak <[email protected]>
4-
* \brief Config for ipfix output plugin
4+
* \brief Config for IPFIX output plugin
55
* \date 2019
66
*/
77

@@ -44,6 +44,7 @@
4444
#include <stdexcept>
4545
#include <memory>
4646

47+
/// XML nodes
4748
enum params_xml_nodes {
4849
PARAM_FILENAME,
4950
PARAM_USE_LOCALTIME,
@@ -53,14 +54,15 @@ enum params_xml_nodes {
5354
PARAM_SPLIT_ON_EXPORT_TIME
5455
};
5556

57+
/// Description of XML document
5658
static const struct fds_xml_args args_params[] = {
5759
FDS_OPTS_ROOT("params"),
58-
FDS_OPTS_ELEM(PARAM_FILENAME, "filename", FDS_OPTS_T_STRING, 0),
60+
FDS_OPTS_ELEM(PARAM_FILENAME, "filename", FDS_OPTS_T_STRING, 0),
5961
FDS_OPTS_ELEM(PARAM_USE_LOCALTIME, "useLocalTime", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
60-
FDS_OPTS_ELEM(PARAM_WINDOW_SIZE, "windowSize", FDS_OPTS_T_UINT, FDS_OPTS_P_OPT),
62+
FDS_OPTS_ELEM(PARAM_WINDOW_SIZE, "windowSize", FDS_OPTS_T_UINT, FDS_OPTS_P_OPT),
6163
FDS_OPTS_ELEM(PARAM_ALIGN_WINDOWS, "alignWindows", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
6264
FDS_OPTS_ELEM(PARAM_SKIP_UNKNOWN_DATASETS, "skipUnknownDataSets", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
63-
FDS_OPTS_ELEM(PARAM_SPLIT_ON_EXPORT_TIME, "splitOnExportTime", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
65+
FDS_OPTS_ELEM(PARAM_SPLIT_ON_EXPORT_TIME, "splitOnExportTime", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
6466
FDS_OPTS_END
6567
};
6668

@@ -108,8 +110,8 @@ void Config::parse_params(fds_xml_ctx_t *params)
108110
}
109111
}
110112

111-
void
112-
Config::check_validity()
113+
void
114+
Config::check_validity()
113115
{
114116
if (filename.empty()) {
115117
throw std::invalid_argument("Filename cannot be empty!");

src/plugins/output/ipfix/src/Config.hpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,45 @@
4747
#include <ipfixcol2.h>
4848
#include <libfds.h>
4949

50+
/// Plugin configuration
5051
class Config {
51-
5252
private:
53+
/**
54+
* @brief Set default configuration parameters
55+
*/
5356
void set_defaults();
57+
/**
58+
* @brief Parse XML tree
59+
* @param[in] params XML tree
60+
* @throws invalid_argument if unexpected node is detected
61+
*/
5462
void parse_params(fds_xml_ctx_t *params);
63+
/**
64+
* @brief Check validity of configuration
65+
*/
5566
void check_validity();
5667

5768
public:
69+
/// Output file pattern
5870
std::string filename;
71+
/// Use local time instead of UTC time
5972
bool use_localtime;
73+
/// Time interval to rotate files (in seconds)
6074
uint64_t window_size;
75+
/// Rotate files on multiple of time interval
6176
bool align_windows;
77+
/// Skip Data Sets with undefined templates
6278
bool skip_unknown_datasets;
79+
/// Split on IPFIX Export Time instead on system time
6380
bool split_on_export_time;
6481

82+
/**
83+
* @brief Parse configuration of the IPFIX plugin
84+
* @param[in] params Plugin part of the configuration of the collector
85+
* @throws runtime_error on error or invalid configuration
86+
*/
6587
Config(const char *params);
88+
/// Configuration destructor
6689
~Config();
6790
};
6891

0 commit comments

Comments
 (0)