Skip to content

Commit c52a883

Browse files
Zainullin DamirZainullin Damir
authored andcommitted
++
1 parent b0afbc5 commit c52a883

File tree

13 files changed

+290
-122
lines changed

13 files changed

+290
-122
lines changed

include/ipfixprobe/outputPlugin/outputPlugin.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ class IPXP_API OutputPlugin {
3131

3232
virtual ~OutputPlugin() = default;
3333

34+
constexpr static std::size_t DEFAULT_EXPORTER_ID = 1;
3435
protected:
36+
3537
const FieldManager& m_fieldManager;
3638
const std::vector<ProcessPluginEntry>& m_plugins;
3739
std::size_t m_dropped = 0;
40+
std::size_t m_seen = 0;
3841
};
3942

4043
template<typename Base, typename... Args>

include/ipfixprobe/pluginFactory/pluginFactory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace ipxp {
3636
* @tparam Args The types of arguments that will be passed to the plugin constructors.
3737
*/
3838
template<typename Base, typename... Args>
39-
class IPXP_API PluginFactory {
39+
class PluginFactory {
4040
public:
4141
/**
4242
* @brief Retrieves the singleton instance of `PluginFactory`.

include/ipfixprobe/processPlugin/flowRecord.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class FlowRecord {
6363
Timestamp timeLastUpdate;
6464

6565
FlowKey flowKey;
66+
DirectionalField<MACAddress> macAddress;
6667

6768
DirectionalField<DirectionalData> directionalData;
6869

@@ -113,19 +114,19 @@ class FlowRecord {
113114
m_flow.dst_tcp_flags = 0;*/
114115
}
115116

116-
inline __attribute__((always_inline)) bool is_empty() const
117+
constexpr bool isEmpty() const noexcept
117118
{
118119
return hash == 0;
119120
}
120121

121-
inline __attribute__((always_inline)) bool belongs(uint64_t value) const
122+
/*constexpr bool belongs(uint64_t value) const noexcept
122123
{
123124
return hash == value;
124-
}
125+
}*/
125126

126-
void create(const Packet& packet, uint64_t hash)
127+
void createFrom(const Packet& packet)
127128
{
128-
/*m_flow.src_packets = 1;
129+
m_flow.directionalData[Direction::Forward].packets = 1;
129130

130131
m_hash = hash;
131132

include/ipfixprobe/processPlugin/macAddress.hpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
#pragma once
22

33
#include <iostream>
4+
#include <array>
5+
#include <span>
6+
#include <cstddef>
7+
#include <cstdint>
48

59
namespace ipxp {
610

7-
struct MACAddress {};
11+
struct MACAddress {
12+
std::array<std::byte, 6> address;
13+
14+
constexpr MACAddress() noexcept
15+
: address{}
16+
{
17+
}
18+
19+
constexpr MACAddress(std::span<const std::byte, 6> address) noexcept
20+
: address{}
21+
{
22+
std::ranges::copy(address, this->address.begin());
23+
}
24+
};
825

926
inline std::ostream& operator<<(std::ostream& os, const MACAddress& mac)
1027
{

include/ipfixprobe/processPlugin/processPluginManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class ProcessPluginManager {
142142
}
143143
}
144144

145-
void exportFlowRecord(FlowRecord & flowRecord)
145+
void exportFlowRecord(FlowRecord& flowRecord)
146146
{
147147
for (std::size_t pluginID = 0; pluginID < m_processPlugins.size(); pluginID++) {
148148
const auto& pluginEntry = m_processPlugins[pluginID];

include/ipfixprobe/processPlugin/timestamp.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ struct Timestamp {
3232
return ns / 1'000'000'000;
3333
}
3434

35+
constexpr timeval toTimeval() const noexcept
36+
{
37+
// TODO use chrono
38+
timeval tv;
39+
tv.tv_sec = static_cast<time_t>(ns / 1'000'000'000);
40+
tv.tv_usec = static_cast<suseconds_t>((ns % 1'000'000'000) / 1'000);
41+
return tv;
42+
}
43+
3544
constexpr bool operator<(const Timestamp& other) const noexcept
3645
{
3746
return ns < other.ns;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#define RECONNECT_TIMEOUT 60
4545
#define TEMPLATE_REFRESH_TIME 600
4646
#define TEMPLATE_REFRESH_PACKETS 0
47-
#define DEFAULT_EXPORTER_ID 1
4847

4948
namespace ipxp {
5049

@@ -69,7 +68,7 @@ class IpfixOptParser : public OptionsParser {
6968
, m_mtu(DEFAULT_MTU)
7069
, m_udp(false)
7170
, m_non_blocking_tcp(false)
72-
, m_id(DEFAULT_EXPORTER_ID)
71+
, m_id(OutputPlugin::DEFAULT_EXPORTER_ID)
7372
, m_dir(0)
7473
, m_template_refresh_time(TEMPLATE_REFRESH_TIME)
7574
, m_verbose(false)

src/plugins/output/text/src/textOutputPlugin.cpp

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,25 @@ printVectorVariant(const FieldDescriptor& field, const VectorValueGetter& varian
4949

5050
void TextOutputPlugin::processRecord(FlowRecordUniquePtr& flowRecord)
5151
{
52-
auto outputFields = m_fieldManager.getBiflowFields();
53-
auto fn = [&](ProcessPlugin* processPlugin) {
54-
// const void* pluginExportData = processPlugin->getExportData();
55-
const void* pluginExportData = flowRecord->getPluginContext(0);
56-
57-
for (const auto& outputField : outputFields) {
58-
if (!outputField.isInRecord(*flowRecord.get())) {
59-
continue;
60-
}
61-
62-
const auto& getter = outputField.getValueGetter();
63-
64-
std::visit(
65-
[&](const auto& variant) {
66-
using GetterT = std::decay_t<decltype(variant)>;
67-
if constexpr (std::is_same_v<GetterT, ScalarValueGetter>) {
68-
printScalarVariant(outputField, variant, pluginExportData);
69-
} else if constexpr (std::is_same_v<GetterT, VectorValueGetter>) {
70-
printVectorVariant(outputField, variant, pluginExportData);
71-
}
72-
},
73-
getter);
52+
std::ranges::for_each(m_fieldManager.getBiflowFields(), [&](const FieldDescriptor& fieldDescriptor) {
53+
if (!fieldDescriptor.isInRecord(*flowRecord.get())) {
54+
return;
7455
}
75-
};
7656

77-
for (const auto& pluginEntry : m_plugins) {
78-
std::cout << "Processing " << pluginEntry.name << "\n";
79-
fn(reinterpret_cast<ProcessPlugin*>(pluginEntry.plugin.get()));
80-
}
57+
const void* pluginExportData = flowRecord->getPluginContext(fieldDescriptor.getBitIndex());
58+
59+
const auto& getter = fieldDescriptor.getValueGetter();
60+
std::visit(
61+
[&](const auto& variant) {
62+
using GetterT = std::decay_t<decltype(variant)>;
63+
if constexpr (std::is_same_v<GetterT, ScalarValueGetter>) {
64+
printScalarVariant(fieldDescriptor, variant, pluginExportData);
65+
} else if constexpr (std::is_same_v<GetterT, VectorValueGetter>) {
66+
printVectorVariant(fieldDescriptor, variant, pluginExportData);
67+
}
68+
},
69+
getter);
70+
});
8171
}
8272

8373
} // namespace ipxp

src/plugins/output/text/src/textOutputPlugin.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ class TextOutputPlugin : public OutputPlugin {
1010
TextOutputPlugin(const std::string& params, const FieldManager& manager, const std::vector<ProcessPluginEntry>& plugins)
1111
: OutputPlugin(manager, plugins)
1212
{
13-
// TODO parse params
14-
(void)params;
1513
}
1614

1715
void processRecord(FlowRecordUniquePtr& flowRecord) override;
18-
16+
1917
};
2018

2119
} // namespace ipxp

src/plugins/output/unirec/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ set_target_properties(ipfixprobe-output-unirec PROPERTIES
1212

1313
target_include_directories(ipfixprobe-output-unirec PRIVATE
1414
${CMAKE_SOURCE_DIR}/include/
15+
${CMAKE_SOURCE_DIR}/include/ipfixprobe/outputPlugin
16+
${CMAKE_SOURCE_DIR}/include/ipfixprobe/processPlugin
1517
)
1618

1719
target_link_libraries(ipfixprobe-output-unirec PRIVATE

0 commit comments

Comments
 (0)