Skip to content

Commit

Permalink
TCP - implement the collector input plugin functions
Browse files Browse the repository at this point in the history
  • Loading branch information
BonnyAD9 committed Mar 28, 2024
1 parent e561e06 commit c7876f9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/plugins/input/tcp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_library(tcp-input MODULE
src/DecoderFactory.cpp
src/Acceptor.cpp
src/Plugin.cpp
src/IpxPlugin.cpp
)

install(
Expand Down
77 changes: 77 additions & 0 deletions src/plugins/input/tcp/src/IpxPlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* \file
* \author Jakub Antonín Štigler <[email protected]>
* \brief ipfixcol2 API for tcp input plugin
* \date 2024
*
* Copyright: (C) 2023 CESNET, z.s.p.o.
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <stdexcept> // exception

#include <ipfixcol2.h> // IPX_*, ipx_*

#include "Config.hpp" // Config
#include "Plugin.hpp" // Plugin

IPX_API struct ipx_plugin_info ipx_plugin_info = {
// Plugin identification name
"tcp",
// Brief description of the plugin
"Input plugins for IPFIX/NetFlow v5/v9 over Transmission Control Protocol.",
// Plugin type (input plugin)
IPX_PT_INPUT,
// Configuration flags (unused)
0,
// Plugin version string
"3.0.0",
// Minimal IPFIXcol version string
"2.0.0",
};

using namespace tcp_in;
using namespace std;

int ipx_plugin_init(ipx_ctx_t *ctx, const char *params) {
Plugin *plugin;

try {
Config conf(params);
plugin = new Plugin(ctx, conf);
} catch (exception &ex) {
IPX_CTX_ERROR(ctx, "%s", ex.what());
return IPX_ERR_DENIED;
}

ipx_ctx_private_set(ctx, plugin);
return IPX_OK;
}

int ipx_plugin_get(ipx_ctx_t *ctx, void *cfg) {
auto plugin = reinterpret_cast<Plugin *>(cfg);

try {
plugin->get();
} catch (exception &ex) {
IPX_CTX_ERROR(ctx, "%s", ex.what());
return IPX_ERR_DENIED;
}

return IPX_OK;
}

void ipx_plugin_session_close(ipx_ctx_t *ctx, void *cfg, const struct ipx_session *session) {
auto plugin = reinterpret_cast<Plugin *>(cfg);

try {
plugin->close_session(session);
} catch (exception &ex) {
IPX_CTX_ERROR(ctx, "%s", ex.what());
}
}

void ipx_plugin_destroy(ipx_ctx_t *ctx, void *cfg) {
(void)ctx;
delete reinterpret_cast<Plugin *>(cfg);
}

0 comments on commit c7876f9

Please sign in to comment.