Skip to content

Commit d29572b

Browse files
committed
ipfixprobe - refactor InputPlugin
1 parent 98c9ecd commit d29572b

File tree

6 files changed

+134
-111
lines changed

6 files changed

+134
-111
lines changed

include/ipfixprobe/input.hpp

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

include/ipfixprobe/inputPlugin.hpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**
2+
* @file
3+
* @brief Base class and factory for packet input plugins
4+
* @author Pavel Siska <[email protected]>
5+
* @date 2025
6+
*
7+
* This file defines the base class for input plugins, responsible for processing
8+
* incoming packets, maintaining statistics, and integrating with the telemetry system.
9+
* It also includes a factory template for plugin creation.
10+
*
11+
* Copyright (c) 2025 CESNET
12+
*
13+
* SPDX-License-Identifier: BSD-3-Clause
14+
*/
15+
16+
#pragma once
17+
18+
#include "api.hpp"
19+
#include "packet.hpp"
20+
#include "parser-stats.hpp"
21+
#include "plugin.hpp"
22+
#include "telemetry-utils.hpp"
23+
24+
#include <cstdint>
25+
#include <memory>
26+
#include <string>
27+
28+
#include <telemetry.hpp>
29+
30+
namespace ipxp {
31+
32+
/**
33+
* \brief Base class for packet receivers.
34+
*
35+
* InputPlugin is an abstract base class for processing network packets.
36+
* It provides functionality for handling telemetry directories and maintains
37+
* statistics on processed packets.
38+
*/
39+
class IPXP_API InputPlugin
40+
: public TelemetryUtils
41+
, public Plugin {
42+
public:
43+
enum class Result {
44+
TIMEOUT = 0,
45+
PARSED,
46+
NOT_PARSED,
47+
END_OF_FILE,
48+
ERROR,
49+
};
50+
51+
virtual ~InputPlugin() = default;
52+
53+
/**
54+
* @brief Retrieves a block of packets.
55+
* @param packets Reference to a PacketBlock to store received packets.
56+
* @return The result of the packet retrieval operation.
57+
*/
58+
virtual Result get(PacketBlock& packets) = 0;
59+
60+
/**
61+
* @brief Sets the telemetry directories for this plugin.
62+
* @param plugin_dir Shared pointer to the plugin-specific telemetry directory.
63+
* @param queues_dir Shared pointer to the telemetry directory for queues.
64+
*/
65+
void set_telemetry_dirs(
66+
std::shared_ptr<telemetry::Directory> plugin_dir,
67+
std::shared_ptr<telemetry::Directory> queues_dir);
68+
69+
/// Number of packets seen by the plugin.
70+
uint64_t m_seen = 0;
71+
/// Number of packets successfully parsed.
72+
uint64_t m_parsed = 0;
73+
/// Number of packets dropped.
74+
uint64_t m_dropped = 0;
75+
76+
protected:
77+
/**
78+
* @brief Configures the telemetry directories.
79+
*
80+
* This method can be overridden by derived classes to perform additional
81+
* setup for telemetry directories.
82+
*
83+
* @param plugin_dir Shared pointer to the plugin-specific telemetry directory.
84+
* @param queues_dir Shared pointer to the telemetry directory for queues.
85+
*/
86+
virtual void configure_telemetry_dirs(
87+
std::shared_ptr<telemetry::Directory> plugin_dir,
88+
std::shared_ptr<telemetry::Directory> queues_dir)
89+
{
90+
(void) plugin_dir;
91+
(void) queues_dir;
92+
};
93+
94+
/// Statistics related to packet parsing.
95+
ParserStats m_parser_stats = {};
96+
97+
private:
98+
void create_parser_stats_telemetry(std::shared_ptr<telemetry::Directory> queues_dir);
99+
};
100+
101+
/**
102+
* @brief Factory template for creating plugins.
103+
*
104+
* This template allows dynamic creation of plugin instances based on the specified
105+
* base class and constructor argument types.
106+
*
107+
* @tparam Base The base class for the plugin.
108+
* @tparam Args The argument types required for the plugin constructor.
109+
*/
110+
template<typename Base, typename... Args>
111+
class IPXP_API PluginFactory;
112+
113+
/**
114+
* @brief Type alias for the InputPlugin factory.
115+
*
116+
* Provides a factory for creating InputPlugin instances using a string-based constructor.
117+
*/
118+
using InputPluginFactory = PluginFactory<InputPlugin, const std::string&>;
119+
120+
} // namespace ipxp

src/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ add_executable(ipfixprobe
1313
utils.cpp
1414
workers.cpp
1515
workers.hpp
16-
input.cpp
16+
inputPlugin.cpp
1717
)
1818

1919

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,22 @@
11
/**
2-
* \file
3-
* \brief
4-
* \author Pavel Siska <[email protected]>
5-
* \date 2024
6-
*/
7-
/*
8-
* Copyright (C) 2024 CESNET
2+
* @file
3+
* @brief Implementation of InputPlugin telemetry integration
4+
* @author Pavel Siska <[email protected]>
5+
* @date 2025
6+
*
7+
* This file contains the implementation of telemetry-related functions for
8+
* the InputPlugin class. It provides functionality to register parser statistics
9+
* in the telemetry system and manage telemetry directories.
910
*
10-
* LICENSE TERMS
11+
* Copyright (c) 2025 CESNET
1112
*
12-
* Redistribution and use in source and binary forms, with or without
13-
* modification, are permitted provided that the following conditions
14-
* are met:
15-
* 1. Redistributions of source code must retain the above copyright
16-
* notice, this list of conditions and the following disclaimer.
17-
* 2. Redistributions in binary form must reproduce the above copyright
18-
* notice, this list of conditions and the following disclaimer in
19-
* the documentation and/or other materials provided with the
20-
* distribution.
21-
* 3. Neither the name of the Company nor the names of its contributors
22-
* may be used to endorse or promote products derived from this
23-
* software without specific prior written permission.
13+
* SPDX-License-Identifier: BSD-3-Clause
2414
*/
2515

26-
#include <ipfixprobe/input.hpp>
16+
#include <ipfixprobe/inputPlugin.hpp>
2717

2818
namespace ipxp {
2919

30-
InputPlugin::InputPlugin()
31-
: m_seen(0)
32-
, m_parsed(0)
33-
, m_dropped(0)
34-
, m_parser_stats()
35-
{
36-
}
37-
3820
static telemetry::Content get_parser_stats_content(const ParserStats& parserStats)
3921
{
4022
telemetry::Dict dict;

src/core/ipfixprobe.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include <thread>
4141

4242
#include <appFs.hpp>
43-
#include <ipfixprobe/input.hpp>
43+
#include <ipfixprobe/inputPlugin.hpp>
4444
#include <ipfixprobe/options.hpp>
4545
#include <ipfixprobe/output.hpp>
4646
#include <ipfixprobe/packet.hpp>

src/core/workers.hpp

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

37-
#include <ipfixprobe/input.hpp>
37+
#include <ipfixprobe/inputPlugin.hpp>
3838
#include <ipfixprobe/output.hpp>
3939
#include <ipfixprobe/packet.hpp>
4040
#include <ipfixprobe/process.hpp>

0 commit comments

Comments
 (0)