Skip to content

Commit c50faae

Browse files
authored
Merge pull request #21 from CESNET/hutak-extensions
Data Record extensions
2 parents f5313d3 + fbabc78 commit c50faae

File tree

16 files changed

+940
-15
lines changed

16 files changed

+940
-15
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ endif()
1414

1515
# Versions and other informations
1616
set(IPFIXCOL_VERSION_MAJOR 2)
17-
set(IPFIXCOL_VERSION_MINOR 1)
17+
set(IPFIXCOL_VERSION_MINOR 2)
1818
set(IPFIXCOL_VERSION_PATCH 0)
1919
set(IPFIXCOL_VERSION
2020
${IPFIXCOL_VERSION_MAJOR}.${IPFIXCOL_VERSION_MINOR}.${IPFIXCOL_VERSION_PATCH})

include/ipfixcol2/message_ipfix.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ extern "C" {
5151

5252
#include <ipfixcol2/api.h>
5353
#include "session.h"
54-
#include "plugins.h"
5554

5655
/**
5756
* \defgroup ipxMsgIPFIX IPFIX message
@@ -99,12 +98,17 @@ struct ipx_ipfix_set {
9998
* \brief Data record (record + extensions)
10099
*/
101100
struct ipx_ipfix_record {
102-
/** Data record information */
101+
/** Data record information */
103102
struct fds_drec rec;
104-
/** Start of reserved space for registered extensions (filled by plugins) */
103+
104+
/** Bit mask of filled extensions (set by producers) */
105+
uint64_t ext_mask;
106+
/** Start of reserved space for registered extensions (filled by producers) */
105107
uint8_t ext[1];
106108
};
107109

110+
#include "plugins.h"
111+
108112
/**
109113
* \brief Create an empty wrapper around IPFIX (or NetFlow) Message
110114
*

include/ipfixcol2/plugins.h

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* \file include/ipfixcol2/plugins.h
33
* \author Lukas Hutak <[email protected]>
44
* \brief IPFIXcol plugin interface and functions (header file)
5-
* \date 2018
5+
* \date 2018-2020
66
*/
77

8-
/* Copyright (C) 2018 CESNET, z.s.p.o.
8+
/* Copyright (C) 2018-2020 CESNET, z.s.p.o.
99
*
1010
* Redistribution and use in source and binary forms, with or without
1111
* modification, are permitted provided that the following conditions
@@ -49,12 +49,13 @@ extern "C" {
4949
/** Internal plugin context */
5050
typedef struct ipx_ctx ipx_ctx_t;
5151
/** Internal data structure that represents IPFIXcol record extension */
52-
typedef struct ipx_ctx_rext ipx_ctx_rext_t;
52+
typedef struct ipx_ctx_ext ipx_ctx_ext_t;
5353

5454
#include <ipfixcol2/api.h>
5555
#include <ipfixcol2/verbose.h>
5656
#include <ipfixcol2/session.h>
5757
#include <ipfixcol2/message.h>
58+
#include <ipfixcol2/message_ipfix.h>
5859

5960
/**
6061
* \defgroup pluginAPI Plugin API
@@ -396,6 +397,101 @@ ipx_ctx_subscribe(ipx_ctx_t *ctx, const ipx_msg_mask_t *mask_new, ipx_msg_mask_t
396397
IPX_API const fds_iemgr_t *
397398
ipx_ctx_iemgr_get(ipx_ctx_t *ctx);
398399

400+
/**
401+
* \brief Register an extension of Data Records (Intermediate plugins ONLY!)
402+
*
403+
* Reserve space for metadata that will be part of each Data Record. The purpose of extension
404+
* it is to add non-flow information which can be useful during record processing. For example,
405+
* one plugin can add some labels and one or more plugins further in the pipeline can use them
406+
* later.
407+
*
408+
* Structure or data type of the extension is up to the producer. Nevertheless, the producer and
409+
* all consumers must use the same. The producer is also RESPONSIBLE for filling content of the
410+
* extension to EACH Data Record in the IPFIX Message! After filling the extension, function
411+
* ipx_ctx_ext_set_filled() must be called to mark the extension memory as filled. Otherwise,
412+
* consumers are not able get its content.
413+
*
414+
* One plugin instance can register multiple extensions.
415+
* \warning
416+
* This function can be called only during ipx_plugin_init() of Intermediate plugins.
417+
* \note
418+
* Only single plugin instance at time can produce extension with the given combination
419+
* of the \p type and the \p name.
420+
* \param[in] ctx Plugin context
421+
* \param[in] type Identification of the extension type (e.g. "profiles-v1")
422+
* \param[in] name Identification of the extension name (e.g. "main_profiles")
423+
* \param[in] size Non-zero size of memory required for the extension (in bytes)
424+
* \param[out] ext Internal description of the extension
425+
*
426+
* \return #IPX_OK on success
427+
* \return #IPX_ERR_ARG if the \p type or \p name are not valid (i.e. empty or NULL) or \p size
428+
* is zero.
429+
* \return #IPX_ERR_DENIED if the plugin doesn't have permission to register extension
430+
* \return #IPX_ERR_EXISTS if the extension or dependency has been already registered by this plugin
431+
* \return #IPX_ERR_NOMEM if a memory allocation failure has occurred
432+
*/
433+
IPX_API int
434+
ipx_ctx_ext_producer(ipx_ctx_t *ctx, const char *type, const char *name, size_t size,
435+
ipx_ctx_ext_t **ext);
436+
437+
/**
438+
* @brief Add dependency on an extension of Data Records (Intermediate and Output plugins ONLY!)
439+
*
440+
* Register dependency on an extension. This will make sure that the required extension is
441+
* available for EACH Data Record during ipx_plugin_process() and that there is a particular
442+
* producer earlier in the processing pipeline.
443+
*
444+
* One plugin instance can register multiple dependencies.
445+
*
446+
* \warning
447+
* This function can be called only during ipx_plugin_init() of Intermediate and Output plugins.
448+
* \note
449+
* If the function has succeeded, it doesn't mean that there is particular extension producer.
450+
* Since dependencies are resolved later during configuration of the collector, startup
451+
* process will be interrupted if all requirements are not met.
452+
* \note
453+
* The plugin instance CANNOT add dependency on an extension which it is producing.
454+
*
455+
* \param[in] ctx Plugin context
456+
* \param[in] type Identification of the extension type (e.g. "profiles-v1")
457+
* \param[in] name Identification of the extension name (e.g. "main_profiles")
458+
* \param[out] ext Internal description of the extension
459+
*
460+
* \return #IPX_OK on success (see notes)
461+
* \return #IPX_ERR_ARG if the \p type or \p name are not valid (i.e. empty or NULL)
462+
* \return #IPX_ERR_DENIED if the plugin doesn't have permission to register dependency
463+
* \return #IPX_ERR_EXISTS if the dependency or extension has been already registered by this plugin
464+
* \return #IPX_ERR_NOMEM if a memory allocation failure has occurred
465+
*/
466+
IPX_API int
467+
ipx_ctx_ext_consumer(ipx_ctx_t *ctx, const char *type, const char *name, ipx_ctx_ext_t **ext);
468+
469+
/**
470+
* \brief Get an extension
471+
*
472+
* In case of a producer of the extension, it always returns #IPX_OK and fills the pointer and
473+
* size. If the producer decides to fill the extension, it also must call ipx_ctx_ext_set_filled().
474+
* Otherwise, consumers will not be able to get its content.
475+
*
476+
* \param[in] ext Internal description of the extension
477+
* \param[in] drec Data Record with extensions
478+
* \param[out] data Pointer to extension data
479+
* \param[out] size Size of the extensions (bytes)
480+
* \return #IPX_OK on success
481+
* \return #IPX_ERR_NOTFOUND if the extension hasn't been filled by its producer
482+
*/
483+
IPX_API int
484+
ipx_ctx_ext_get(ipx_ctx_ext_t *ext, struct ipx_ipfix_record *drec, void **data, size_t *size);
485+
486+
/**
487+
* \brief Set the extension of a Data Record as filled (ONLY for the producer of the extension)
488+
*
489+
* \param[in] ext Internal description of the extension
490+
* \param[in] drec Data Record with extensions
491+
*/
492+
IPX_API void
493+
ipx_ctx_ext_set_filled(ipx_ctx_ext_t *ext, struct ipx_ipfix_record *drec);
494+
399495
/**
400496
* @}
401497
* @}

pkg/deb/templates/changelog

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
ipfixcol2 (2.1.0-1) unstable; urgency=low
1+
ipfixcol2 (2.2.0-1) unstable; urgency=low
22

33
* Initial release.
44

5-
-- Lukas Hutak <[email protected]> Thu, 25 Oct 2018 10:17:56 +0200
5+
-- Lukas Hutak <[email protected]> Sun, 23 Feb 2020 14:42:00 +0100

src/core/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ set(CORE_SOURCE
44
configurator/config_file.hpp
55
configurator/configurator.cpp
66
configurator/configurator.hpp
7+
configurator/extensions.cpp
8+
configurator/extensions.hpp
79
configurator/instance.hpp
810
configurator/instance_input.cpp
911
configurator/instance_input.hpp
@@ -28,6 +30,8 @@ set(CORE_SOURCE
2830
api.c
2931
context.c
3032
context.h
33+
extension.c
34+
extension.h
3135
fpipe.c
3236
fpipe.h
3337
message_base.c

src/core/configurator/configurator.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <signal.h>
4747

4848
#include "configurator.hpp"
49+
#include "extensions.hpp"
4950

5051
extern "C" {
5152
#include "../message_terminate.h"
@@ -249,16 +250,40 @@ ipx_configurator::start(const ipx_config_model &model)
249250

250251
IPX_DEBUG(comp_str, "All instances have been successfully initialized.", '\0');
251252

252-
// Phase 4. Start threads of all plugins
253+
// Phase 4. Register and resolved Data Record extensions and dependencies
254+
ipx_cfg_extensions ext_mgr;
255+
size_t pos = 0; // Position of an instance in the collector pipeline
256+
257+
for (auto &input : inputs) {
258+
input->extensions_register(&ext_mgr, pos);
259+
}
260+
261+
pos++;
262+
for (auto &inter : inters) {
263+
inter->extensions_register(&ext_mgr, pos);
264+
pos++;
265+
}
266+
267+
for (auto &output : outputs) {
268+
output->extensions_register(&ext_mgr, pos);
269+
}
270+
271+
ext_mgr.resolve();
272+
ext_mgr.list_extensions();
273+
274+
// Phase 5. Start threads of all plugins and update definitions of extensions
253275
for (auto &output : outputs) {
276+
output->extensions_resolve(&ext_mgr);
254277
output->start();
255278
}
256279

257280
for (auto &inter : inters) {
281+
inter->extensions_resolve(&ext_mgr);
258282
inter->start();
259283
}
260284

261285
for (auto &input : inputs) {
286+
input->extensions_resolve(&ext_mgr);
262287
input->start();
263288
}
264289

0 commit comments

Comments
 (0)