Skip to content

Commit b0afbc5

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

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+660
-470
lines changed

include/ipfixprobe/flowifc.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ struct Record {
233233
virtual ~Record() { remove_extensions(); }
234234
};
235235

236-
#define FLOW_END_INACTIVE 0x01
237-
#define FLOW_END_ACTIVE 0x02
238-
#define FLOW_END_EOF 0x03
239-
#define FLOW_END_FORCED 0x04
240-
#define FLOW_END_NO_RES 0x05
236+
//#define FLOW_END_INACTIVE 0x01
237+
//#define FLOW_END_ACTIVE 0x02
238+
//#define FLOW_END_EOF 0x03
239+
//#define FLOW_END_FORCED 0x04
240+
//#define FLOW_END_NO_RES 0x05
241241

242242
/**
243243
* \brief Flow record struct constaining basic flow record data and extension headers.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#pragma once
2+
3+
#include "fieldManager.hpp"
4+
#include "flowRecord.hpp"
5+
#include "processPluginEntry.hpp"
6+
#include "../api.hpp"
7+
8+
#include <vector>
9+
#include <string>
10+
#include <cstddef>
11+
#include <cstdint>
12+
13+
//#include "../pluginFactory/pluginFactory.hpp"
14+
15+
namespace ipxp {
16+
17+
class IPXP_API OutputPlugin {
18+
public:
19+
OutputPlugin(const FieldManager& fieldManager, const std::vector<ProcessPluginEntry>& plugins)
20+
: m_fieldManager(fieldManager)
21+
, m_plugins(plugins)
22+
{
23+
}
24+
25+
virtual void processRecord(FlowRecordUniquePtr& flowRecord) = 0;
26+
27+
std::size_t getDroppedCount() const noexcept
28+
{
29+
return m_dropped;
30+
}
31+
32+
virtual ~OutputPlugin() = default;
33+
34+
protected:
35+
const FieldManager& m_fieldManager;
36+
const std::vector<ProcessPluginEntry>& m_plugins;
37+
std::size_t m_dropped = 0;
38+
};
39+
40+
template<typename Base, typename... Args>
41+
class IPXP_API PluginFactory;
42+
43+
/**
44+
* @brief Type alias for the OutputPlugin factory.
45+
*
46+
* Provides a factory for creating OutputPlugin instances using a string-based constructor.
47+
*/
48+
using OutputPluginFactory = PluginFactory<OutputPlugin, const std::string&, const FieldManager&, const std::vector<ProcessPluginEntry>&>;
49+
50+
} // namespace ipxp

include/ipfixprobe/pluginFactory/pluginFactory.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class IPXP_API PluginFactory {
4343
*
4444
* @return A reference to the singleton `PluginFactory` instance.
4545
*/
46-
inline static PluginFactory& getInstance()
46+
static PluginFactory& getInstance()
4747
{
4848
static PluginFactory instance;
4949
return instance;
@@ -64,6 +64,8 @@ class IPXP_API PluginFactory {
6464
void registerPlugin(const PluginManifest& manifest)
6565
{
6666
static_assert(std::is_base_of<Base, Derived>::value, "Derived must be a subclass of Base");
67+
68+
std::cout << manifest.name << "=" << std::hex << std::size_t(this) << std::endl;
6769

6870
m_registeredPlugins[manifest] = createGenerators<Base, Derived, Args...>();
6971
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,6 @@ class IPXP_API PluginFactory;
174174
*
175175
* Provides a factory for creating ProcessPlugin instances using a string-based constructor.
176176
*/
177-
using ProcessPluginFactory = PluginFactory<ProcessPlugin, const std::string&, int>;
177+
//using ProcessPluginFactory = PluginFactory<ProcessPlugin, const std::string&, int>;
178178

179179
} // namespace ipxp
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* @file
3+
* @author Pavel Siska <[email protected]>
4+
* @brief Type traits and helpers for FieldSchema, including scalar/vector detection and
5+
* element type extraction.
6+
*
7+
* This header defines compile-time utilities used by FieldSchema to:
8+
* - Determine if an accessor is scalar or vector.
9+
* - Extract element type from std::span or scalar type.
10+
*
11+
* @note These helpers are intended primarily for use within FieldSchema.
12+
*
13+
* @copyright Copyright (c) 2025 CESNET, z.s.p.o.
14+
*/
15+
16+
#pragma once
17+
18+
#include "fieldAccessor.hpp"
19+
20+
#include <span>
21+
#include <type_traits>
22+
23+
namespace ipxp {
24+
25+
/**
26+
* @brief Extracts the element type from a type, removing const/volatile qualifiers.
27+
*
28+
* - If the given type is a `std::span<T, Extent>`, the element type is `T` without cv-qualifiers.
29+
* - Otherwise, the type itself (without cv-qualifiers) is returned.
30+
*
31+
* @tparam T Type to extract from.
32+
*/
33+
template<typename T>
34+
struct span_element_type {
35+
using type = std::remove_cv_t<T>;
36+
};
37+
38+
template<typename T, std::size_t Extent>
39+
struct span_element_type<std::span<T, Extent>> {
40+
using type = std::remove_cv_t<T>;
41+
};
42+
43+
/**
44+
* @brief Trait to detect whether a given accessor template is ScalarAccessor.
45+
*
46+
* Defaults to `false`; specialized for `ScalarAccessor<T>`.
47+
*
48+
* @tparam Accessor Accessor template (e.g., ScalarAccessor or VectorAccessor)
49+
* @tparam F Type argument to the accessor template
50+
*/
51+
template<template<typename> class Accessor, typename F>
52+
struct is_scalar_accessor : std::false_type {};
53+
54+
template<typename T>
55+
struct is_scalar_accessor<ScalarAccessor, T> : std::true_type {};
56+
57+
/**
58+
* @brief Trait to detect whether a given accessor template is VectorAccessor.
59+
*
60+
* Defaults to `false`; specialized for `VectorAccessor<T>`.
61+
*
62+
* @tparam Accessor Accessor template
63+
* @tparam F Type argument
64+
*/
65+
template<template<typename> class Accessor, typename F>
66+
struct is_vector_accessor : std::false_type {};
67+
68+
template<typename T>
69+
struct is_vector_accessor<VectorAccessor, T> : std::true_type {};
70+
71+
} // namespace ipxp

include/ipfixprobe/processPlugin/flowRecord.hpp

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "flowKey.hpp"
55
#include "directionalField.hpp"
66
#include "tcpFlags.hpp"
7+
#include "packet.hpp"
78

89
#include <array>
910
#include <bitset>
@@ -46,6 +47,14 @@ struct DirectionalData {
4647
TCPFlags tcpFlags = 0;
4748
};
4849

50+
enum class FlowEndReason : uint8_t {
51+
FLOW_END_INACTIVE = 0x01,
52+
FLOW_END_ACTIVE = 0x02,
53+
FLOW_END_EOF = 0x03,
54+
FLOW_END_FORCED = 0x04,
55+
FLOW_END_NO_RES = 0x05
56+
};
57+
4958
class FlowRecord {
5059
public:
5160
uint64_t hash;
@@ -57,14 +66,122 @@ class FlowRecord {
5766

5867
DirectionalField<DirectionalData> directionalData;
5968

69+
FlowEndReason endReason;
70+
6071
// Bitset of flow fields that were specified as present
6172
mutable FieldsBitset fieldsAvailable = {};
6273
// Bitset of successfully constructed plugins (constructor accepted packet)
6374
PluginsBitset pluginsConstructed = {};
6475
// Bitset of plugins that still wants to process packets of the flow
6576
PluginsBitset pluginsUpdate = {};
6677
// Bitset of plugins that are available for the flow
67-
const PluginsBitset pluginsAvailable;
78+
// TODO GET BACK CONST ?
79+
PluginsBitset pluginsAvailable;
80+
81+
void erase()
82+
{
83+
hash = 0;
84+
timeCreation = timeLastUpdate = {};
85+
flowKey = {};
86+
//directionalData = {};
87+
88+
/*memset(&m_flow.time_first, 0, sizeof(m_flow.time_first));
89+
memset(&m_flow.time_last, 0, sizeof(m_flow.time_last));
90+
m_flow.ip_version = 0;
91+
m_flow.ip_proto = 0;
92+
memset(&m_flow.src_ip, 0, sizeof(m_flow.src_ip));
93+
memset(&m_flow.dst_ip, 0, sizeof(m_flow.dst_ip));
94+
m_flow.src_port = 0;
95+
m_flow.dst_port = 0;
96+
m_flow.src_packets = 0;
97+
m_flow.dst_packets = 0;
98+
m_flow.src_bytes = 0;
99+
m_flow.dst_bytes = 0;
100+
m_flow.src_tcp_flags = 0;
101+
m_flow.dst_tcp_flags = 0;*/
102+
}
103+
104+
void reuse()
105+
{
106+
/*m_flow.remove_extensions();
107+
m_flow.time_first = m_flow.time_last;
108+
m_flow.src_packets = 0;
109+
m_flow.dst_packets = 0;
110+
m_flow.src_bytes = 0;
111+
m_flow.dst_bytes = 0;
112+
m_flow.src_tcp_flags = 0;
113+
m_flow.dst_tcp_flags = 0;*/
114+
}
115+
116+
inline __attribute__((always_inline)) bool is_empty() const
117+
{
118+
return hash == 0;
119+
}
120+
121+
inline __attribute__((always_inline)) bool belongs(uint64_t value) const
122+
{
123+
return hash == value;
124+
}
125+
126+
void create(const Packet& packet, uint64_t hash)
127+
{
128+
/*m_flow.src_packets = 1;
129+
130+
m_hash = hash;
131+
132+
m_flow.time_first = pkt.ts;
133+
m_flow.time_last = pkt.ts;
134+
m_flow.flow_hash = hash;
135+
136+
memcpy(m_flow.src_mac, pkt.src_mac, 6);
137+
memcpy(m_flow.dst_mac, pkt.dst_mac, 6);
138+
139+
if (pkt.ip_version == IP::v4) {
140+
m_flow.ip_version = pkt.ip_version;
141+
m_flow.ip_proto = pkt.ip_proto;
142+
m_flow.src_ip.v4 = pkt.src_ip.v4;
143+
m_flow.dst_ip.v4 = pkt.dst_ip.v4;
144+
m_flow.src_bytes = pkt.ip_len;
145+
} else if (pkt.ip_version == IP::v6) {
146+
m_flow.ip_version = pkt.ip_version;
147+
m_flow.ip_proto = pkt.ip_proto;
148+
memcpy(m_flow.src_ip.v6, pkt.src_ip.v6, 16);
149+
memcpy(m_flow.dst_ip.v6, pkt.dst_ip.v6, 16);
150+
m_flow.src_bytes = pkt.ip_len;
151+
}
152+
153+
if (pkt.ip_proto == IPPROTO_TCP) {
154+
m_flow.src_port = pkt.src_port;
155+
m_flow.dst_port = pkt.dst_port;
156+
m_flow.src_tcp_flags = pkt.tcp_flags;
157+
} else if (pkt.ip_proto == IPPROTO_UDP) {
158+
m_flow.src_port = pkt.src_port;
159+
m_flow.dst_port = pkt.dst_port;
160+
} else if (pkt.ip_proto == IPPROTO_ICMP || pkt.ip_proto == IPPROTO_ICMPV6) {
161+
m_flow.src_port = pkt.src_port;
162+
m_flow.dst_port = pkt.dst_port;
163+
}*/
164+
}
165+
166+
void update(const Packet& packet, bool src)
167+
{
168+
/*m_flow.time_last = pkt.ts;
169+
if (src) {
170+
m_flow.src_packets++;
171+
m_flow.src_bytes += pkt.ip_len;
172+
173+
if (pkt.ip_proto == IPPROTO_TCP) {
174+
m_flow.src_tcp_flags |= pkt.tcp_flags;
175+
}
176+
} else {
177+
m_flow.dst_packets++;
178+
m_flow.dst_bytes += pkt.ip_len;
179+
180+
if (pkt.ip_proto == IPPROTO_TCP) {
181+
m_flow.dst_tcp_flags |= pkt.tcp_flags;
182+
}
183+
}*/
184+
}
68185

69186
void* getPluginContext(std::size_t pluginIndex)
70187
{

include/ipfixprobe/processPlugin/flowRecordBuilder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "flowKey.hpp"
44
#include "flowRecord.hpp"
55
#include "ipAddress.hpp"
6-
#include "processPluginBuilder.hpp"
6+
//#include "processPluginBuilder.hpp"
77

88
#include <cstddef>
99
#include <memory>

include/ipfixprobe/processPlugin/outputPlugin.hpp

Lines changed: 0 additions & 25 deletions
This file was deleted.

include/ipfixprobe/processPlugin/processPlugin.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "packet.hpp"
2020
#include "fieldManager.hpp"
2121
#include "../api.hpp"
22-
#include "../pluginFactory/pluginFactory.hpp"
2322

2423
namespace ipxp {
2524

@@ -229,10 +228,23 @@ class IPXP_API ProcessPlugin {
229228
[[nodiscard]] virtual PluginDataMemoryLayout getDataMemoryLayout() const noexcept = 0;
230229
};
231230

232-
/*template<typename Base, typename... Args>
231+
/**
232+
* @brief Factory template for creating plugins.
233+
*
234+
* This template allows dynamic creation of plugin instances based on the specified
235+
* base class and constructor argument types.
236+
*
237+
* @tparam Base The base class for the plugin.
238+
* @tparam Args The argument types required for the plugin constructor.
239+
*/
240+
template<typename Base, typename... Args>
233241
class IPXP_API PluginFactory;
234242

243+
/**
244+
* @brief Type alias for the ProcessPlugin factory.
245+
*
246+
* Provides a factory for creating ProcessPlugin instances using a string-based constructor.
247+
*/
235248
using ProcessPluginFactory = PluginFactory<ProcessPlugin, const std::string&, FieldManager&>;
236-
*/
237249

238250
} // namespace ipxp

0 commit comments

Comments
 (0)