Skip to content

Commit c75373c

Browse files
committed
Merge branch 'devel' into 'master'
merge devel See merge request monitoring/ipfixcol2!23
2 parents 32fab99 + 1416946 commit c75373c

File tree

137 files changed

+10926
-1988
lines changed

Some content is hidden

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

137 files changed

+10926
-1988
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ cmake-build-release/
1010
# JetBrains files
1111
.idea/
1212

13+
# Clangd cache files
14+
.cache/
15+
1316
# Prerequisites
1417
*.d
1518

include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set(SUB_HEADERS
1414
ipfixcol2/message_garbage.h
1515
ipfixcol2/message_ipfix.h
1616
ipfixcol2/message_session.h
17+
ipfixcol2/message_periodic.h
1718
ipfixcol2/plugins.h
1819
ipfixcol2/session.h
1920
ipfixcol2/utils.h

include/ipfixcol2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include <ipfixcol2/message_garbage.h>
6161
#include <ipfixcol2/message_session.h>
6262
#include <ipfixcol2/message_ipfix.h>
63+
#include <ipfixcol2/message_periodic.h>
6364

6465
#include <ipfixcol2/plugins.h>
6566
#include <ipfixcol2/session.h>

include/ipfixcol2/message.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ enum ipx_msg_type {
7777
IPX_MSG_TERMINATE = (1 << 3),
7878
// An internal configuration message (only for internal usage)
7979
//IPX_MSG_CONFIG = (1 << 4)
80+
/** A periodic message */
81+
IPX_MSG_PERIODIC = (1 << 5)
8082
};
8183

8284
/** The data type of the base message */
@@ -107,6 +109,7 @@ ipx_msg_destroy(ipx_msg_t *msg);
107109
#include <ipfixcol2/message_ipfix.h>
108110
#include <ipfixcol2/message_garbage.h>
109111
#include <ipfixcol2/message_session.h>
112+
#include <ipfixcol2/message_periodic.h>
110113

111114
/**
112115
* \brief Cast from a base message to a session message
@@ -147,6 +150,19 @@ ipx_msg_base2ipfix(ipx_msg_t *msg)
147150
return (ipx_msg_ipfix_t *) msg;
148151
}
149152

153+
/**
154+
* \brief Cast base message to periodic message
155+
*
156+
* \param[in] msg Pointer to the base message
157+
* \return A pointer to a periodic message
158+
*/
159+
static inline ipx_msg_periodic_t *
160+
ipx_msg_base2periodic(ipx_msg_t *msg)
161+
{
162+
assert(ipx_msg_get_type(msg) == IPX_MSG_PERIODIC);
163+
return (ipx_msg_periodic_t *) msg;
164+
}
165+
150166
/**@}*/
151167

152168
#ifdef __cplusplus

include/ipfixcol2/message_ipfix.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ ipx_msg_ipfix_add_set_ref(struct ipx_msg_ipfix *msg);
225225
IPX_API struct ipx_ipfix_record *
226226
ipx_msg_ipfix_add_drec_ref(struct ipx_msg_ipfix **msg_ref);
227227

228+
/**
229+
* \brief Set the raw size of an IPFIX message.
230+
*
231+
* \param[in] msg IPFIX Message wrapper.
232+
* \param[in] new_raw_size The new raw_size value.
233+
*/
234+
IPX_API void
235+
ipx_msg_ipfix_set_raw_size(ipx_msg_ipfix_t *msg, uint16_t new_raw_size);
236+
228237
/**@}*/
229238
#ifdef __cplusplus
230239
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* @file
3+
* @author Adrian Duriska <[email protected]>
4+
* @brief Periodic message
5+
*
6+
* Copyright: (C) 2024 CESNET, z.s.p.o.
7+
* SPDX-License-Identifier: BSD-3-Clause
8+
*/
9+
10+
#ifndef IPX_MESSAGE_PERIODIC_H
11+
#define IPX_MESSAGE_PERIODIC_H
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
#include <ipfixcol2/message.h>
18+
19+
typedef struct ipx_msg_periodic ipx_msg_periodic_t;
20+
21+
/**
22+
* \brief Cast periodic message to base message
23+
*
24+
* \param[in] msg Pointer to the periodic message
25+
* \return A pointer to a base message
26+
*/
27+
static inline ipx_msg_t *
28+
ipx_msg_periodic2base(ipx_msg_periodic_t *msg)
29+
{
30+
return (ipx_msg_t *) msg;
31+
}
32+
33+
/**
34+
* \brief Get sequence number of periodic message
35+
*
36+
* \param[in] msg Pointer to the periodic message
37+
* \return Periodic messages sequence number
38+
*/
39+
IPX_API uint64_t
40+
ipx_msg_periodic_get_seq_num(ipx_msg_periodic_t *msg);
41+
42+
/**
43+
* \brief Get created time of periodic message
44+
*
45+
* \param[in] msg Pointer to the periodic message
46+
* \return Periodic messages created time
47+
*/
48+
IPX_API struct timespec
49+
ipx_msg_periodic_get_created(ipx_msg_periodic_t *msg);
50+
51+
/**
52+
* \brief Get last intermediate plugin processed time of periodic message
53+
*
54+
* \param[in] msg Pointer to the periodic message
55+
* \return Periodic messages last intermediate plugin processed time
56+
*/
57+
IPX_API struct timespec
58+
ipx_msg_periodic_get_last_processed(ipx_msg_periodic_t *msg);
59+
60+
#ifdef __cplusplus
61+
}
62+
#endif
63+
#endif

include/ipfixcol2/plugins.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ ipx_ctx_msg_pass(ipx_ctx_t *ctx, ipx_msg_t *msg);
381381
* types of messages:
382382
* - ::IPX_MSG_IPFIX (IPFIX Message)
383383
* - ::IPX_MSG_SESSION (Transport Session Message)
384+
* - ::IPX_MSG_PERIODIC (Periodic Message)
384385
*
385386
* If \p mask_new is non-NULL, the new subscription mask is installed from \p mask_new.
386387
* If \p mask_old is non-NULL, the previous mask is saved in \p mask_old.

src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ set(CORE_SOURCE
4141
message_garbage.c
4242
message_ipfix.c
4343
message_ipfix.h
44+
message_periodic.c
45+
message_periodic.h
4446
message_session.c
4547
message_terminate.c
4648
message_terminate.h

src/core/configurator/configurator.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@
4646
#include <cstdlib>
4747
#include <dlfcn.h>
4848
#include <signal.h>
49+
#include <sys/time.h>
4950

5051
#include "configurator.hpp"
5152
#include "extensions.hpp"
5253

5354
extern "C" {
5455
#include "../message_terminate.h"
56+
#include "../message_periodic.h"
5557
#include "../plugin_parser.h"
5658
#include "../plugin_output_mgr.h"
5759
#include "../verbose.h"
@@ -88,7 +90,7 @@ termination_handler(int sig)
8890
cnt++;
8991

9092
// Send a termination request to the configurator
91-
int rc = ipx_cpipe_send_term(NULL, request_type);
93+
int rc = ipx_cpipe_send(NULL, request_type);
9294
if (rc != IPX_OK) {
9395
static const char *msg = "ERROR: Signal handler: failed to send a termination request";
9496
write(STDOUT_FILENO, msg, strlen(msg));
@@ -568,6 +570,22 @@ ipx_configurator::termination_send_msg()
568570
m_term_sent = m_running_inputs.size();
569571
}
570572

573+
void
574+
ipx_configurator::periodic_send_msg(uint32_t *periodic_message_sequence)
575+
{
576+
for (auto &input : m_running_inputs) {
577+
ipx_msg_periodic_t *msg = ipx_msg_periodic_create(*periodic_message_sequence);
578+
if (!msg) {
579+
IPX_ERROR(comp_str, "Can't create periodic message!", '\0');
580+
termination_send_msg();
581+
return;
582+
}
583+
584+
ipx_fpipe_write(input->get_feedback(), ipx_msg_periodic2base(msg));
585+
}
586+
(*periodic_message_sequence)++;
587+
}
588+
571589
int
572590
ipx_configurator::run(ipx_controller *ctrl)
573591
{
@@ -595,6 +613,9 @@ ipx_configurator::run(ipx_controller *ctrl)
595613
// Collector is running -> process termination/reconfiguration requests
596614
m_state = STATUS::RUNNING;
597615
bool terminate = false;
616+
617+
uint32_t periodic_message_sequence = 0;
618+
598619
while (!terminate) {
599620
struct ipx_cpipe_req req;
600621
if (ipx_cpipe_receive(&req) != IPX_OK) {
@@ -609,6 +630,9 @@ ipx_configurator::run(ipx_controller *ctrl)
609630
case IPX_CPIPE_TYPE_TERM_DONE:
610631
terminate = termination_handle(req, ctrl);
611632
break;
633+
case IPX_CPIPE_TYPE_PERIODIC:
634+
periodic_send_msg(&periodic_message_sequence);
635+
break;
612636
default:
613637
IPX_ERROR(comp_str, "Ignoring unknown configuration request!", '\0');
614638
continue;

src/core/configurator/configurator.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ class ipx_configurator {
150150
void
151151
termination_send_msg();
152152

153+
void
154+
periodic_send_msg(uint32_t *periodic_message_sequence);
155+
153156
void
154157
termination_stop_all();
155158
void

0 commit comments

Comments
 (0)