Skip to content

Commit 804fd14

Browse files
committed
ipfixprobe - refactor OutputPlugin
1 parent ea2cc3c commit 804fd14

File tree

4 files changed

+82
-76
lines changed

4 files changed

+82
-76
lines changed

include/ipfixprobe/output.hpp

Lines changed: 0 additions & 74 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* @file
3+
* @brief Generic interface of output plugin
4+
* @author Pavel Siska <[email protected]>
5+
* @author Vaclav Bartos <[email protected]>
6+
* @author Jiri Havranek <[email protected]>
7+
* @date 2025
8+
*
9+
* Copyright (c) 2025 CESNET
10+
*
11+
* SPDX-License-Identifier: BSD-3-Clause
12+
*/
13+
14+
#pragma once
15+
16+
#include "api.hpp"
17+
#include "flowifc.hpp"
18+
#include "plugin.hpp"
19+
#include "process.hpp"
20+
21+
#include <cstdint>
22+
#include <string>
23+
#include <vector>
24+
25+
namespace ipxp {
26+
27+
#define DEFAULT_EXPORTER_ID 1
28+
29+
/**
30+
* \brief Base class for flow exporters.
31+
*/
32+
class IPXP_API OutputPlugin : public Plugin {
33+
public:
34+
typedef std::vector<std::pair<std::string, ProcessPlugin*>> Plugins;
35+
uint64_t m_flows_seen; /**< Number of flows received to export. */
36+
uint64_t m_flows_dropped; /**< Number of flows that could not be exported. */
37+
38+
OutputPlugin()
39+
: m_flows_seen(0)
40+
, m_flows_dropped(0)
41+
{
42+
}
43+
virtual ~OutputPlugin() {}
44+
45+
virtual void init(const char* params, Plugins& plugins) = 0;
46+
47+
enum class Result { EXPORTED = 0, DROPPED };
48+
/**
49+
* \brief Send flow record to output interface.
50+
* \param [in] flow Flow to send.
51+
* \return 0 on success
52+
*/
53+
virtual int export_flow(const Flow& flow) = 0;
54+
55+
/**
56+
* \brief Force exporter to flush flows to collector.
57+
*/
58+
virtual void flush() {}
59+
};
60+
61+
/**
62+
* @brief Factory template for creating plugins.
63+
*
64+
* This template allows dynamic creation of plugin instances based on the specified
65+
* base class and constructor argument types.
66+
*
67+
* @tparam Base The base class for the plugin.
68+
* @tparam Args The argument types required for the plugin constructor.
69+
*/
70+
template<typename Base, typename... Args>
71+
class IPXP_API PluginFactory;
72+
73+
/**
74+
* @brief Type alias for the OutputPlugin factory.
75+
*
76+
* Provides a factory for creating OutputPlugin instances using a string-based constructor.
77+
*/
78+
using OutputPluginFactory = PluginFactory<OutputPlugin, const std::string&>;
79+
80+
} // namespace ipxp

src/core/ipfixprobe.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include <appFs.hpp>
4343
#include <ipfixprobe/inputPlugin.hpp>
4444
#include <ipfixprobe/options.hpp>
45-
#include <ipfixprobe/output.hpp>
45+
#include <ipfixprobe/outputPlugin.hpp>
4646
#include <ipfixprobe/packet.hpp>
4747
#include <ipfixprobe/plugin.hpp>
4848
#include <ipfixprobe/process.hpp>

src/core/workers.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include <future>
3636

3737
#include <ipfixprobe/inputPlugin.hpp>
38-
#include <ipfixprobe/output.hpp>
38+
#include <ipfixprobe/outputPlugin.hpp>
3939
#include <ipfixprobe/packet.hpp>
4040
#include <ipfixprobe/process.hpp>
4141
#include <ipfixprobe/ring.h>

0 commit comments

Comments
 (0)