Skip to content

Commit 66a57bf

Browse files
authored
Merge pull request #222 from Zadamsa/update-process-plugins-events
Enhance process plugins: Allow skipping flows marked as uninteresting Updated process plugins to enable skipping flows that are flagged as not interesting. This optimization improves efficiency by bypassing unnecessary processing for certain flows
2 parents ebb8d77 + 107401e commit 66a57bf

Some content is hidden

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

65 files changed

+516
-372
lines changed

include/ipfixprobe/flowifc.hpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <arpa/inet.h>
5050
#include "ipaddr.hpp"
5151
#include <string>
52+
#include <bitset>
5253

5354
namespace ipxp {
5455

@@ -247,7 +248,24 @@ struct Record {
247248
* \brief Flow record struct constaining basic flow record data and extension headers.
248249
*/
249250
struct Flow : public Record {
250-
uint64_t flow_hash;
251+
static inline const int MAXIMAL_PROCESS_PLUGIN_COUNT = 64;
252+
/**
253+
* \brief Plugins status struct describes flow information required by process plugins.
254+
*/
255+
struct PluginsStatus {
256+
// get_no_data[i] == true -> i-th process plugin requires no flow data
257+
// get_no_data[i] == false && get_all_data[i] == true -> i-th process plugin requires all
258+
// available flow data
259+
// get_no_data[i] == false && get_all_data[i] == false -> i-th process plugin requires
260+
// only metadata
261+
std::bitset<MAXIMAL_PROCESS_PLUGIN_COUNT> get_all_data;
262+
std::bitset<MAXIMAL_PROCESS_PLUGIN_COUNT> get_no_data;
263+
};
264+
265+
uint64_t flow_hash;
266+
PluginsStatus plugins_status; /**< Statuses of the process plugins for this flow, used to check
267+
if the flow process plugins requires all available data, only
268+
metadata or nothing of this. */
251269

252270
struct timeval time_first;
253271
struct timeval time_last;

include/ipfixprobe/process.hpp

Lines changed: 85 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -38,85 +38,103 @@
3838
#include "flowifc.hpp"
3939

4040
namespace ipxp {
41-
42-
/**
43-
* \brief Tell storage plugin to flush (immediately export) current flow.
44-
* Behavior when called from post_create, pre_update and post_update: flush current Flow and erase FlowRecord.
45-
*/
46-
#define FLOW_FLUSH 0x1
47-
48-
/**
49-
* \brief Tell storage plugin to flush (immediately export) current flow.
50-
* Behavior when called from post_create: flush current Flow and erase FlowRecord.
51-
* Behavior when called from pre_update and post_update: flush current Flow, erase FlowRecord and call post_create on packet.
52-
*/
53-
#define FLOW_FLUSH_WITH_REINSERT 0x3
54-
5541
/**
5642
* \brief Class template for flow cache plugins.
5743
*/
5844
class ProcessPlugin : public Plugin
5945
{
6046
public:
61-
ProcessPlugin() {}
62-
virtual ~ProcessPlugin() {}
63-
virtual ProcessPlugin *copy() = 0;
47+
enum FlowAction : int {
48+
/**
49+
* \brief Tell storage plugin that process plugin requires all incoming data for given flow.
50+
*/
51+
GET_ALL_DATA = 0,
52+
/**
53+
* \brief Tell storage plugin that process plugin requires only metadata.
54+
* Used to offload the cache when all process plugin return GET_METADATA.
55+
*/
56+
GET_METADATA = 0x2,
57+
/**
58+
* \brief Tell storage plugin that process plugin has ended up its work and doesn't require
59+
* any new data. Used to offload the cache when all process plugin return NO_PROCESS.
60+
*/
61+
NO_PROCESS = 0x4,
62+
/**
63+
* \brief Tell storage plugin to flush (immediately export) current flow.
64+
* Behavior when called from post_create, pre_update and post_update: flush current Flow and
65+
* erase FlowRecord.
66+
*/
67+
FLUSH = 0x1,
68+
69+
/**
70+
* \brief Tell storage plugin to flush (immediately export) current flow.
71+
* Behavior when called from post_create: flush current Flow and erase FlowRecord.
72+
* Behavior when called from pre_update and post_update: flush current Flow, erase
73+
* FlowRecord and call post_create on packet.
74+
*/
75+
FLUSH_WITH_REINSERT = 0x7
76+
};
77+
78+
ProcessPlugin() {}
79+
virtual ~ProcessPlugin() {}
80+
virtual ProcessPlugin* copy() = 0;
81+
82+
virtual RecordExt *get_ext() const
83+
{
84+
return nullptr;
85+
}
6486

65-
virtual RecordExt *get_ext() const
66-
{
67-
return nullptr;
68-
}
87+
/**
88+
* \brief Called before a new flow record is created.
89+
* \param [in] pkt Parsed packet.
90+
* \return 0 on success or FLOW_FLUSH option.
91+
*/
92+
virtual FlowAction pre_create(Packet& pkt)
93+
{
94+
return FlowAction::GET_ALL_DATA;
95+
}
6996

70-
/**
71-
* \brief Called before a new flow record is created.
72-
* \param [in] pkt Parsed packet.
73-
* \return 0 on success or FLOW_FLUSH option.
74-
*/
75-
virtual int pre_create(Packet &pkt)
76-
{
77-
return 0;
78-
}
97+
/**
98+
* \brief Called after a new flow record is created.
99+
* \param [in,out] rec Reference to flow record.
100+
* \param [in] pkt Parsed packet.
101+
* \return 0 on success or FLOW_FLUSH option.
102+
*/
103+
virtual FlowAction post_create(Flow& rec, const Packet& pkt)
104+
{
105+
return FlowAction::GET_ALL_DATA;
106+
}
79107

80-
/**
81-
* \brief Called after a new flow record is created.
82-
* \param [in,out] rec Reference to flow record.
83-
* \param [in] pkt Parsed packet.
84-
* \return 0 on success or FLOW_FLUSH option.
85-
*/
86-
virtual int post_create(Flow &rec, const Packet &pkt)
87-
{
88-
return 0;
89-
}
108+
/**
109+
* \brief Called before an existing record is update.
110+
* \param [in,out] rec Reference to flow record.
111+
* \param [in,out] pkt Parsed packet.
112+
* \return 0 on success or FLOW_FLUSH option.
113+
*/
114+
virtual FlowAction pre_update(Flow& rec, Packet& pkt)
115+
{
116+
return FlowAction::GET_ALL_DATA;
117+
}
90118

91-
/**
92-
* \brief Called before an existing record is update.
93-
* \param [in,out] rec Reference to flow record.
94-
* \param [in,out] pkt Parsed packet.
95-
* \return 0 on success or FLOW_FLUSH option.
96-
*/
97-
virtual int pre_update(Flow &rec, Packet &pkt)
98-
{
99-
return 0;
100-
}
119+
/**
120+
* \brief Called after an existing record is updated.
121+
* \param [in,out] rec Reference to flow record.
122+
* \param [in,out] pkt Parsed packet.
123+
* \return 0 on success or FLOW_FLUSH option.
124+
*/
125+
virtual FlowAction post_update(Flow& rec, const Packet& pkt)
126+
{
127+
return FlowAction::GET_ALL_DATA;
128+
}
101129

102-
/**
103-
* \brief Called after an existing record is updated.
104-
* \param [in,out] rec Reference to flow record.
105-
* \param [in,out] pkt Parsed packet.
106-
* \return 0 on success or FLOW_FLUSH option.
107-
*/
108-
virtual int post_update(Flow &rec, const Packet &pkt)
109-
{
110-
return 0;
111-
}
130+
/**
131+
* \brief Called before a flow record is exported from the cache.
132+
* \param [in,out] rec Reference to flow record.
133+
*/
134+
virtual void pre_export(Flow& rec)
135+
{
112136

113-
/**
114-
* \brief Called before a flow record is exported from the cache.
115-
* \param [in,out] rec Reference to flow record.
116-
*/
117-
virtual void pre_export(Flow &rec)
118-
{
119-
}
137+
}
120138
};
121139

122140
}

0 commit comments

Comments
 (0)