Skip to content

Commit 36cfef2

Browse files
sedmichaLukas955
authored andcommitted
IPFIX output plugin: First version
1 parent 0b6080a commit 36cfef2

File tree

10 files changed

+1137
-0
lines changed

10 files changed

+1137
-0
lines changed

src/plugins/output/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ add_subdirectory(fds)
44
add_subdirectory(json)
55
add_subdirectory(timecheck)
66
add_subdirectory(viewer)
7+
add_subdirectory(ipfix)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Create a linkable module
2+
add_library(ipfix MODULE
3+
src/IPFIXOutputPlugin.cpp
4+
src/IPFIXOutput.cpp
5+
src/IPFIXOutput.hpp
6+
src/Config.cpp
7+
src/Config.hpp
8+
)
9+
10+
install(
11+
TARGETS ipfix
12+
LIBRARY DESTINATION "${INSTALL_DIR_LIB}/ipfixcol2/"
13+
)
14+
15+
if (ENABLE_DOC_MANPAGE)
16+
# Build a manual page
17+
set(SRC_FILE "${CMAKE_CURRENT_SOURCE_DIR}/doc/ipfixcol2-ipfix.7.rst")
18+
set(DST_FILE "${CMAKE_CURRENT_BINARY_DIR}/ipfixcol2-ipfix.7")
19+
20+
add_custom_command(TARGET ipfix PRE_BUILD
21+
COMMAND ${RST2MAN_EXECUTABLE} --syntax-highlight=none ${SRC_FILE} ${DST_FILE}
22+
DEPENDS ${SRC_FILE}
23+
VERBATIM
24+
)
25+
26+
install(
27+
FILES "${DST_FILE}"
28+
DESTINATION "${INSTALL_DIR_MAN}/man7"
29+
)
30+
endif()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
IPFIX (output plugin)
2+
=====================
3+
4+
The plugin outputs incoming IPFIX data to a file or a series of files in the IPFIX format.
5+
6+
Example configuration
7+
---------------------
8+
9+
.. code-block:: xml
10+
11+
<output>
12+
<name>IPFIX output</name>
13+
<plugin>ipfix</plugin>
14+
<params>
15+
<filename>/tmp/ipfix/%d-%m-%y/%H:%M:%S.ipfix</filename>
16+
<useUtcForFilenameTime>false</useUtcForFilenameTime>
17+
<windowSize>60</windowSize>
18+
<alignWindows>true</alignWindows>
19+
<skipUnknownDataSets>true</skipUnknownDataSets>
20+
</params>
21+
</output>
22+
23+
Parameters
24+
----------
25+
26+
:``filename``:
27+
The output filename, allows the use of strftime format values to add the export time into the file path.
28+
29+
:``useUtcForFilenameTime``:
30+
Specifies whether the time values in filenames should be in local time or UTC. (optional, local time by default)
31+
32+
:``windowSize``:
33+
The number of seconds before a new file is created. The value of 0 means the file will never split. (optional, 0 by default)
34+
35+
:``alignWindows``:
36+
Specifies whether the file should only be split on multiples of windowSize. (optional, true by default)
37+
38+
:``skipUnknownDataSets``:
39+
Specifies whether data sets with missing template should be left out from the output file. Sequence numbers and message lengths will be adjusted accordingly. (optional, false by default)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
========================
2+
ipfixcol2-dummy-output
3+
========================
4+
5+
---------------------
6+
Dummy (output plugin)
7+
---------------------
8+
9+
:Author: Lukáš Huták ([email protected])
10+
:Author: Petr Velan ([email protected])
11+
:Date: 2018-09-20
12+
:Copyright: Copyright © 2018 CESNET, z.s.p.o.
13+
:Version: 2.0
14+
:Manual section: 7
15+
:Manual group: IPFIXcol collector
16+
17+
Description
18+
-----------
19+
20+
.. include:: ../README.rst
21+
:start-line: 3
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
========================
2+
ipfixcol2-dummy-output
3+
========================
4+
5+
---------------------
6+
Dummy (output plugin)
7+
---------------------
8+
9+
:Author: Michal Sedlák ([email protected])
10+
:Date: 2019-03-28
11+
:Copyright: Copyright © 2019 CESNET, z.s.p.o.
12+
:Version: 1.0
13+
:Manual section: 7
14+
:Manual group: IPFIXcol collector
15+
16+
Description
17+
-----------
18+
19+
.. include:: ../README.rst
20+
:start-line: 3
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/**
2+
* \file src/plugins/output/ipfix/src/Config.cpp
3+
* \author Michal Sedlak <[email protected]>
4+
* \brief Config for ipfix output plugin
5+
* \date 2019
6+
*/
7+
8+
/* Copyright (C) 2019 CESNET, z.s.p.o.
9+
*
10+
* Redistribution and use in source and binary forms, with or without
11+
* modification, are permitted provided that the following conditions
12+
* are met:
13+
* 1. Redistributions of source code must retain the above copyright
14+
* notice, this list of conditions and the following disclaimer.
15+
* 2. Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in
17+
* the documentation and/or other materials provided with the
18+
* distribution.
19+
* 3. Neither the name of the Company nor the names of its contributors
20+
* may be used to endorse or promote products derived from this
21+
* software without specific prior written permission.
22+
*
23+
* ALTERNATIVELY, provided that this notice is retained in full, this
24+
* product may be distributed under the terms of the GNU General Public
25+
* License (GPL) version 2 or later, in which case the provisions
26+
* of the GPL apply INSTEAD OF those given above.
27+
*
28+
* This software is provided ``as is'', and any express or implied
29+
* warranties, including, but not limited to, the implied warranties of
30+
* merchantability and fitness for a particular purpose are disclaimed.
31+
* In no event shall the company or contributors be liable for any
32+
* direct, indirect, incidental, special, exemplary, or consequential
33+
* damages (including, but not limited to, procurement of substitute
34+
* goods or services; loss of use, data, or profits; or business
35+
* interruption) however caused and on any theory of liability, whether
36+
* in contract, strict liability, or tort (including negligence or
37+
* otherwise) arising in any way out of the use of this software, even
38+
* if advised of the possibility of such damage.
39+
*
40+
*/
41+
42+
#include "Config.hpp"
43+
44+
#include <stdexcept>
45+
#include <memory>
46+
47+
enum params_xml_nodes {
48+
PARAM_FILENAME,
49+
PARAM_USE_UTC_FOR_FILENAME_TIME,
50+
PARAM_WINDOW_SIZE,
51+
PARAM_ALIGN_WINDOWS,
52+
PARAM_SKIP_UNKNOWN_DATASETS
53+
};
54+
55+
static const struct fds_xml_args args_params[] = {
56+
FDS_OPTS_ROOT("params"),
57+
FDS_OPTS_ELEM(PARAM_FILENAME, "filename", FDS_OPTS_T_STRING, 0),
58+
FDS_OPTS_ELEM(PARAM_USE_UTC_FOR_FILENAME_TIME, "useUtcForFilenameTime", FDS_OPTS_T_STRING, FDS_OPTS_P_OPT),
59+
FDS_OPTS_ELEM(PARAM_WINDOW_SIZE, "windowSize", FDS_OPTS_T_UINT, FDS_OPTS_P_OPT),
60+
FDS_OPTS_ELEM(PARAM_ALIGN_WINDOWS, "alignWindows", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
61+
FDS_OPTS_ELEM(PARAM_SKIP_UNKNOWN_DATASETS, "skipUnknownDataSets", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
62+
FDS_OPTS_END
63+
};
64+
65+
void Config::set_defaults() {
66+
filename = "";
67+
use_utc_for_filename_time = false;
68+
window_size = 0;
69+
align_windows = true;
70+
skip_unknown_datasets = false;
71+
}
72+
73+
void Config::parse_params(fds_xml_ctx_t *params)
74+
{
75+
const struct fds_xml_cont *content;
76+
while (fds_xml_next(params, &content) != FDS_EOC) {
77+
switch (content->id) {
78+
case PARAM_FILENAME:
79+
assert(content->type == FDS_OPTS_T_STRING);
80+
filename = std::string(content->ptr_string);
81+
break;
82+
case PARAM_USE_UTC_FOR_FILENAME_TIME:
83+
assert(content->type == FDS_OPTS_T_BOOL);
84+
use_utc_for_filename_time = content->val_bool;
85+
break;
86+
case PARAM_WINDOW_SIZE:
87+
assert(content->type == FDS_OPTS_T_UINT);
88+
window_size = content->val_uint;
89+
break;
90+
case PARAM_ALIGN_WINDOWS:
91+
assert(content->type == FDS_OPTS_T_BOOL);
92+
align_windows = content->val_bool;
93+
break;
94+
case PARAM_SKIP_UNKNOWN_DATASETS:
95+
assert(content->type == FDS_OPTS_T_BOOL);
96+
skip_unknown_datasets = content->val_bool;
97+
break;
98+
default:
99+
throw std::invalid_argument("Unexpected element within <params>!");
100+
}
101+
}
102+
}
103+
104+
void
105+
Config::check_validity()
106+
{
107+
if (filename.empty()) {
108+
throw std::invalid_argument("Filename cannot be empty!");
109+
}
110+
}
111+
112+
Config::Config(const char *params)
113+
{
114+
// Set default values
115+
set_defaults();
116+
117+
// Create XML parser
118+
std::unique_ptr<fds_xml_t, decltype(&fds_xml_destroy)> xml(fds_xml_create(), &fds_xml_destroy);
119+
if (!xml) {
120+
throw std::runtime_error("Failed to create an XML parser!");
121+
}
122+
123+
if (fds_xml_set_args(xml.get(), args_params) != FDS_OK) {
124+
std::string err = fds_xml_last_err(xml.get());
125+
throw std::runtime_error("Failed to parse the description of an XML document: " + err);
126+
}
127+
128+
fds_xml_ctx_t *params_ctx = fds_xml_parse_mem(xml.get(), params, true);
129+
if (!params_ctx) {
130+
std::string err = fds_xml_last_err(xml.get());
131+
throw std::runtime_error("Failed to parse the configuration: " + err);
132+
}
133+
134+
// Parse parameters and check configuration
135+
try {
136+
parse_params(params_ctx);
137+
check_validity();
138+
} catch (std::exception &ex) {
139+
throw std::runtime_error("Failed to parse the configuration: " + std::string(ex.what()));
140+
}
141+
}
142+
143+
Config::~Config()
144+
{
145+
// Nothing to do
146+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* \file src/plugins/output/ipfix/src/config.cpp
3+
* \author Michal Sedlak <[email protected]>
4+
* \brief Config for ipfix output plugin (header file)
5+
* \date 2019
6+
*/
7+
8+
/* Copyright (C) 2019 CESNET, z.s.p.o.
9+
*
10+
* Redistribution and use in source and binary forms, with or without
11+
* modification, are permitted provided that the following conditions
12+
* are met:
13+
* 1. Redistributions of source code must retain the above copyright
14+
* notice, this list of conditions and the following disclaimer.
15+
* 2. Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in
17+
* the documentation and/or other materials provided with the
18+
* distribution.
19+
* 3. Neither the name of the Company nor the names of its contributors
20+
* may be used to endorse or promote products derived from this
21+
* software without specific prior written permission.
22+
*
23+
* ALTERNATIVELY, provided that this notice is retained in full, this
24+
* product may be distributed under the terms of the GNU General Public
25+
* License (GPL) version 2 or later, in which case the provisions
26+
* of the GPL apply INSTEAD OF those given above.
27+
*
28+
* This software is provided ``as is'', and any express or implied
29+
* warranties, including, but not limited to, the implied warranties of
30+
* merchantability and fitness for a particular purpose are disclaimed.
31+
* In no event shall the company or contributors be liable for any
32+
* direct, indirect, incidental, special, exemplary, or consequential
33+
* damages (including, but not limited to, procurement of substitute
34+
* goods or services; loss of use, data, or profits; or business
35+
* interruption) however caused and on any theory of liability, whether
36+
* in contract, strict liability, or tort (including negligence or
37+
* otherwise) arising in any way out of the use of this software, even
38+
* if advised of the possibility of such damage.
39+
*
40+
*/
41+
42+
#ifndef CONFIG_HPP
43+
#define CONFIG_HPP
44+
45+
#include <string>
46+
47+
#include <ipfixcol2.h>
48+
#include <libfds.h>
49+
50+
class Config {
51+
52+
private:
53+
void set_defaults();
54+
void parse_params(fds_xml_ctx_t *params);
55+
void check_validity();
56+
57+
public:
58+
std::string filename;
59+
bool use_utc_for_filename_time;
60+
uint64_t window_size;
61+
bool align_windows;
62+
bool skip_unknown_datasets;
63+
64+
Config(const char *params);
65+
~Config();
66+
};
67+
68+
#endif // CONFIG_HPP

0 commit comments

Comments
 (0)