Skip to content

Commit f5a4168

Browse files
Zainullin DamirZainullin Damir
authored andcommitted
++
1 parent 0c4bc43 commit f5a4168

File tree

41 files changed

+545
-291
lines changed

Some content is hidden

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

41 files changed

+545
-291
lines changed

include/ipfixprobe/processPlugin/fieldGroup.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace ipxp {
5252
* DirectionalPair is used for fields that have a forward and a reverse component.
5353
* Typical example: `packets` (forward) and `packets_rev` (reverse).
5454
*
55-
* Behavior depends on flow orientation:
55+
* Behavior depends on flow view:
5656
*
5757
* | Flow Type | Forward Field | Reverse Field |
5858
* |------------------|---------------------|---------------------|
@@ -67,7 +67,7 @@ namespace ipxp {
6767
*
6868
* BiflowPair is used for fields that conceptually belong to two sides of a bidirectional flow.
6969
* Typical example: `src_port` (A) and `dst_port` (B).
70-
* Behavior depends on flow orientation:
70+
* Behavior depends on flow view:
7171
*
7272
* | Flow Type | A Field | B Field |
7373
* |------------------|-----------------|-----------------|
@@ -328,7 +328,7 @@ class FieldGroup {
328328
std::move(accessorB));
329329
}
330330

331-
__builtin_unreachable();
331+
throw std::logic_error("Unreachable code in addPairFieldsGeneric");
332332
}
333333

334334
std::string m_groupName;

include/ipfixprobe/processPlugin/fieldGroupTypeTraits.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
22
* @file
33
* @author Pavel Siska <[email protected]>
4-
* @brief Type traits and helpers for FieldSchema, including scalar/vector detection and
4+
* @brief Type traits and helpers for FieldGroup, including scalar/vector detection and
55
* element type extraction.
66
*
7-
* This header defines compile-time utilities used by FieldSchema to:
7+
* This header defines compile-time utilities used by FieldGroup to:
88
* - Determine if an accessor is scalar or vector.
99
* - Extract element type from std::span or scalar type.
1010
*
11-
* @note These helpers are intended primarily for use within FieldSchema.
11+
* @note These helpers are intended primarily for use within FieldGroup.
1212
*
1313
* @copyright Copyright (c) 2025 CESNET, z.s.p.o.
1414
*/

include/ipfixprobe/processPlugin/fieldManager.hpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @brief FieldManager manages registration and organization of FlowRecord fields.
55
*
66
* FieldManager is responsible for:
7-
* - Creating FieldSchema instances for different logical groups
7+
* - Creating FieldGroup instances for different logical groups
88
* - Registering scalar and directional fields
99
* - Keeping track of biflow and uniflow fields
1010
* - Providing access to field descriptors for introspection and validation
@@ -29,7 +29,7 @@
2929

3030
namespace ipxp {
3131

32-
class FieldSchema;
32+
class FieldGroup;
3333

3434
/**
3535
* @class FieldManager
@@ -41,11 +41,11 @@ class FieldSchema;
4141
class FieldManager {
4242
public:
4343
/**
44-
* @brief Creates a FieldSchema for a given group name.
44+
* @brief Creates a FieldGroup for a given name.
4545
* @param groupName Logical group name (e.g., "dns", "http").
46-
* @return Newly created FieldSchema instance.
46+
* @return Newly created FieldGroup instance.
4747
*/
48-
[[nodiscard]] FieldSchema createFieldSchema(std::string_view groupName);
48+
[[nodiscard]] FieldGroup createFieldGroup(std::string_view groupName);
4949

5050
/** @brief Returns all biflow fields. */
5151
const std::vector<FieldDescriptor>& getBiflowFields() const;
@@ -60,8 +60,8 @@ class FieldManager {
6060
const std::vector<FieldDescriptor>& getUniflowReverseFields() const;
6161

6262
private:
63-
// registration of field can only be done by FieldSchema
64-
friend class FieldSchema;
63+
// registration of field can only be done by FieldGroup
64+
friend class FieldGroup;
6565

6666
[[nodiscard]] FieldHandler registerField(
6767
std::string_view groupName,
@@ -84,12 +84,19 @@ class FieldManager {
8484

8585
[[nodiscard]] std::size_t getNextBitIndex() noexcept { return m_fieldIndex++; }
8686

87+
void addField(
88+
std::vector<FieldDescriptor>& container,
89+
std::string_view group,
90+
std::string_view name,
91+
std::size_t bitIndex,
92+
GenericValueGetter getter);
93+
8794
std::vector<FieldDescriptor> m_biflowFields;
8895
std::vector<FieldDescriptor> m_reverseBiflowFields;
8996
std::vector<FieldDescriptor> m_uniflowForwardFields;
9097
std::vector<FieldDescriptor> m_uniflowReverseFields;
9198

92-
std::atomic<std::size_t> m_fieldIndex = 0;
99+
std::size_t m_fieldIndex = 0;
93100
};
94101

95102
} // namespace ipxp
File renamed without changes.

include/ipfixprobe/processPlugin/flowRecord.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,16 @@ class FlowRecord {
6969

7070
FlowEndReason endReason;
7171

72+
7273
// Bitset of flow fields that were specified as present
7374
mutable FieldsBitset fieldsAvailable = {};
7475
// Bitset of successfully constructed plugins (constructor accepted packet)
7576
PluginsBitset pluginsConstructed = {};
7677
// Bitset of plugins that still wants to process packets of the flow
7778
PluginsBitset pluginsUpdate = {};
7879
// Bitset of plugins that are available for the flow
79-
// TODO GET BACK CONST ?
80-
PluginsBitset pluginsAvailable;
80+
const PluginsBitset pluginsAvailable;
81+
8182

8283
void erase()
8384
{
@@ -194,6 +195,7 @@ class FlowRecord {
194195
// TODO PRIVATE
195196
FlowRecord(PluginsBitset pluginsAvailable = {})
196197
: pluginsAvailable(pluginsAvailable)
198+
, pluginsUpdate(pluginsAvailable)
197199
{
198200
}
199201

include/ipfixprobe/processPlugin/ipAddress.hpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ union IPAddress {
3636
std::memcpy(&u8, ipv6.data(), sizeof(u8));
3737
}
3838

39-
constexpr IPAddress(const ipaddr_t address) noexcept
39+
constexpr IPAddress(const ipaddr_t address, IP version) noexcept
40+
: IPAddress(address.v4)
4041
{
41-
// TODO
42-
(void)address;
42+
if (version == IP::v6) {
43+
std::memcpy(&u8, address.v6, 16);
44+
}
4345
}
4446

4547
constexpr IPAddress(const IPAddress& other) noexcept
@@ -59,6 +61,14 @@ union IPAddress {
5961
return !isIPv4();
6062
}
6163

64+
//constexpr bool operator==(const IPAddress&) const noexcept = default;
65+
66+
67+
constexpr auto operator<=>(const IPAddress& other) const noexcept
68+
{
69+
return u64 <=> other.u64;
70+
}
71+
6272
constexpr bool operator==(const IPAddress& other) const noexcept
6373
{
6474
return u8 == other.u8;
@@ -102,6 +112,11 @@ union IPAddress {
102112

103113
};
104114

115+
/*friend constexpr auto operator<=>(const IPAddress& lhs, const IPAddress& rhs) noexcept
116+
{
117+
return lhs.u64 <=> rhs.u64;
118+
}*/
119+
105120
inline std::ostream& operator<<(std::ostream& os, const IPAddress& ip)
106121
{
107122
return os << ip.toString();

include/ipfixprobe/processPlugin/processPlugin.hpp

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#pragma once
1616

1717
#include <cstdint>
18-
19-
#include "packet.hpp"
2018
#include "fieldManager.hpp"
2119
#include "../api.hpp"
2220

@@ -163,21 +161,28 @@ class IPXP_API ProcessPlugin {
163161
= 0;
164162

165163
/**
166-
* @brief Called to update plugin state for a constructed flow.
164+
* @brief Called before the main per-packet update.
165+
*
166+
* This method is invoked for each packet of a flow **before** the standard
167+
* update phase (`onUpdate()`) is executed. It allows the plugin to perform
168+
* early decisions or actions that must happen prior to flow statistics being
169+
* updated or other plugins being called.
170+
*
171+
* Typical use cases include:
172+
* - Requesting flow export and immediate re-insertion
173+
* (e.g., splitting a stream into multiple flows such as individual HTTP
174+
* requests or SIP sessions).
175+
* - Forcing a flow flush before normal packet processing.
167176
*
168-
* This method is called for each packet of a flow after the plugin has been constructed
169-
* (onInit returned ConstructionState::Constructed and RequiresUpdate). It allows the plugin
170-
* to process packets and update its internal state. If the plugin no longer requires updates,
171-
* it should return UpdateRequirement::NoUpdateNeeded. The method can also request actions such
172-
* as flushing or removing the plugin from the flow.
173177
*
174178
* @param flowContext Context containing references to the flow and packet.
175179
* @param pluginContext Pointer to plugin-specific context memory.
176180
* @return PluginUpdateResult describing update requirements and actions.
177181
*/
178182
[[nodiscard]] virtual PluginUpdateResult
179-
onUpdate(const FlowContext& flowContext, void* pluginContext)
183+
beforeUpdate(const FlowContext& flowContext, void* pluginContext)
180184
{
185+
// TODO
181186
(void) flowContext;
182187
(void) pluginContext;
183188
return {
@@ -186,6 +191,29 @@ class IPXP_API ProcessPlugin {
186191
};
187192
}
188193

194+
/**
195+
* @brief Called to update plugin state for a constructed flow.
196+
*
197+
* This method is called for each subsequent packet of a flow after the plugin has been
198+
* constructed. Importantly, onUpdate() is **not called for the same packet** that triggered
199+
* onInit(). Instead, the first invocation of onUpdate() happens with the *next* packet of the
200+
* flow. This ensures that initialization and the first update are clearly separated.
201+
*
202+
* The plugin can use this method to process packets and update its internal state. If the
203+
* plugin no longer requires updates, it should return UpdateRequirement::NoUpdateNeeded. The
204+
* method can also request actions such as flushing or removing the plugin from the flow.
205+
*
206+
* @param flowContext Context containing references to the flow and packet.
207+
* @param pluginContext Pointer to plugin-specific context memory.
208+
* @return PluginUpdateResult describing update requirements and actions.
209+
*/
210+
[[nodiscard]] virtual PluginUpdateResult
211+
onUpdate(const FlowContext& flowContext, void* pluginContext)
212+
{
213+
throw std::logic_error(
214+
"Unexpected call to Base::onUpdate(). Override this method in your plugin.");
215+
}
216+
189217
/**
190218
* @brief Called to export the flow record processed by the plugin.
191219
*

0 commit comments

Comments
 (0)