22 * \file src/core/configurator/configurator.hpp
33 * \author Lukas Hutak <[email protected] > 44 * \brief Main pipeline configurator (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
5252#include " instance_outmgr.hpp"
5353#include " instance_output.hpp"
5454#include " plugin_mgr.hpp"
55+ #include " controller.hpp"
5556
5657extern " C" {
5758#include < ipfixcol2.h>
5859#include " ../context.h"
5960}
6061
61- /* * Main configurator of the internal pipeline */
62+ // Main configurator of the internal pipeline
6263class ipx_configurator {
63- private:
64- /* * Size of ring buffers */
65- uint32_t ring_size;
66- /* * Directory with definitions of Information Elements */
67- std::string iemgr_dir;
68-
69- /* * Manager of Information Elements */
70- fds_iemgr_t *iemgr;
71- /* * Vector of running instances of input plugins */
72- std::vector<std::unique_ptr<ipx_instance_input> > running_inputs;
73- /* * Vector of running instances of intermediate plugins */
74- std::vector<std::unique_ptr<ipx_instance_intermediate> > running_inter;
75- /* * Vector of running instances of output plugins */
76- std::vector<std::unique_ptr<ipx_instance_output> > running_outputs;
77-
78- void model_check (const ipx_config_model &model);
79- fds_iemgr_t *iemgr_load (const std::string dir);
80- enum ipx_verb_level verbosity_str2level (const std::string &verb);
81-
8264public:
8365 /* * Minimal size of ring buffers between instances of plugins */
8466 static constexpr uint32_t RING_MIN_SIZE = 128 ;
@@ -94,37 +76,100 @@ class ipx_configurator {
9476 ipx_configurator (const ipx_configurator &) = delete ;
9577 ipx_configurator& operator =(const ipx_configurator &) = delete ;
9678
97- /* * Plugin manager */
79+ /* * Plugin manager (can be modified by a user i.e. add paths, change behaviour, etc) */
9880 ipx_plugin_mgr plugins;
9981
10082 /* *
101- * \brief Start the configuration with a new model
102- *
103- * Check if the model is valid (consists of at least one input and one output instance,
104- * etc.) and load definitions of Information Elements (i.e. iemgr_set_dir() must be defined).
105- * Then try to load all plugins, initialized them and, finally, start their execution threads.
106- *
107- * \param[in] model Configuration model (description of input/intermediate/output instances)
108- * \throw runtime_error in case of any error, e.g. failed to find plugins, failed to load
109- * definitions of Information Elements, failed to initialize an instance, etc.
83+ * @brief Define a path to the directory of Information Elements definitions
84+ * @param[in] path Path
11085 */
111- void start (const ipx_config_model &model);
112-
113- /* *
114- * \brief Stop and destroy all instances of all plugins
115- */
116- void stop ();
86+ void
87+ iemgr_set_dir (const std::string &path);
88+ /* *
89+ * @brief Define a size of ring buffers
90+ * @param[in] size Size
91+ */
92+ void
93+ set_buffer_size (uint32_t size);
11794
118- /* *
119- * \brief Define a path to the directory of Information Elements definitions
120- * \param[in] path Path
121- */
122- void iemgr_set_dir (const std::string &path);
12395 /* *
124- * \brief Define a size of ring buffers
125- * \param[in] size Size
96+ * @brief Run the collector based on a configuration from the controller
97+ *
98+ * @note
99+ * Return code depends on the way how the collector was terminated. For example, if the
100+ * termination was caused by invalid configuration of a plugin, memory allocation during
101+ * processing, etc. return code corresponds to EXIT_FAILURE value.
102+ * However, if the collector was terminated by a plugin, which informed the configurator
103+ * that there are no more flow data for processing, return value is EXIT_SUCCESS.
104+ *
105+ * @param[in] ctrl Configuration controller
106+ * @return Return code of the application
126107 */
127- void set_buffer_size (uint32_t size);
108+ int
109+ run (ipx_controller *ctrl);
110+
111+ private:
112+ // / State type
113+ enum class STATUS {
114+ RUNNING, // /< No configuration change in progress
115+ STOP_SLOW, // /< Stop stop in progress
116+ STOP_FAST, // /< Fast stop in progress
117+ } m_state; // /< Configuration state
118+
119+ /* * Size of ring buffers */
120+ uint32_t m_ring_size;
121+ /* * Directory with definitions of Information Elements */
122+ std::string m_iemgr_dir;
123+
124+ /* * Manager of Information Elements */
125+ fds_iemgr_t *m_iemgr;
126+ /* * Vector of running instances of input plugins */
127+ std::vector<std::unique_ptr<ipx_instance_input> > m_running_inputs;
128+ /* * Vector of running instances of intermediate plugins */
129+ std::vector<std::unique_ptr<ipx_instance_intermediate> > m_running_inter;
130+ /* * Vector of running instances of output plugins */
131+ std::vector<std::unique_ptr<ipx_instance_output> > m_running_outputs;
132+
133+ // Internal functions
134+ void
135+ model_check (const ipx_config_model &model);
136+ fds_iemgr_t *
137+ iemgr_load (const std::string dir);
138+ enum ipx_verb_level
139+ verbosity_str2level (const std::string &verb);
140+
141+ void
142+ startup (const ipx_config_model &model);
143+ void
144+ cleanup ();
145+
146+ bool
147+ termination_handle (const struct ipx_cpipe_req &req, ipx_controller *ctrl);
148+ void
149+ termination_send_msg ();
150+
151+ void
152+ termination_stop_all ();
153+ void
154+ termination_stop_partly (const ipx_ctx_t *ctx);
128155};
129156
130157#endif // IPFIXCOL_CONFIGURATOR_H
158+
159+ // /**
160+ // * \brief Start the configuration with a new model
161+ // *
162+ // * Check if the model is valid (consists of at least one input and one output instance,
163+ // * etc.) and load definitions of Information Elements (i.e. iemgr_set_dir() must be defined).
164+ // * Then try to load all plugins, initialized them and, finally, start their execution threads.
165+ // *
166+ // * \param[in] model Configuration model (description of input/intermediate/output instances)
167+ // * \throw runtime_error in case of any error, e.g. failed to find plugins, failed to load
168+ // * definitions of Information Elements, failed to initialize an instance, etc.
169+ // */
170+ // void start(const ipx_config_model &model);
171+ //
172+ // /**
173+ // * \brief Stop and destroy all instances of all plugins
174+ // */
175+ // void stop();
0 commit comments