2014-06-05 09:35:32 +00:00
|
|
|
/** Message paths
|
2014-06-05 09:34:29 +00:00
|
|
|
*
|
2014-06-28 06:40:52 +00:00
|
|
|
* @file
|
2015-06-02 21:53:04 +02:00
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2020-01-20 17:17:00 +01:00
|
|
|
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
|
2017-04-27 12:56:43 +02:00
|
|
|
* @license GNU General Public License (version 3)
|
|
|
|
*
|
|
|
|
* VILLASnode
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
2017-05-05 19:24:16 +00:00
|
|
|
*
|
2017-04-27 12:56:43 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2017-05-05 19:24:16 +00:00
|
|
|
*
|
2017-04-27 12:56:43 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-03-05 10:06:32 -04:00
|
|
|
*********************************************************************************/
|
|
|
|
|
2015-09-19 18:48:00 +02:00
|
|
|
/** A path connects one input node to multiple output nodes (1-to-n).
|
|
|
|
*
|
|
|
|
* @addtogroup path Path
|
|
|
|
* @{
|
2017-03-05 10:06:32 -04:00
|
|
|
*/
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
#pragma once
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2019-04-23 13:03:58 +02:00
|
|
|
#include <bitset>
|
|
|
|
|
2020-08-17 17:01:36 +02:00
|
|
|
#include <uuid/uuid.h>
|
2014-06-05 09:34:29 +00:00
|
|
|
#include <pthread.h>
|
2017-08-03 00:19:27 +02:00
|
|
|
#include <jansson.h>
|
2021-07-07 10:39:35 +02:00
|
|
|
#include <spdlog/fmt/ostr.h>
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2018-06-29 09:06:04 +02:00
|
|
|
#include <villas/list.h>
|
|
|
|
#include <villas/queue.h>
|
|
|
|
#include <villas/pool.h>
|
2020-03-04 12:41:55 +01:00
|
|
|
#include <villas/common.hpp>
|
2018-06-29 09:06:04 +02:00
|
|
|
#include <villas/mapping.h>
|
2020-03-04 13:06:28 +01:00
|
|
|
#include <villas/task.hpp>
|
2021-06-21 16:12:47 -04:00
|
|
|
#include <villas/node_list.hpp>
|
2021-07-07 10:39:35 +02:00
|
|
|
#include <villas/colors.hpp>
|
|
|
|
#include <villas/path_destination.h>
|
|
|
|
#include <villas/path_source.h>
|
|
|
|
#include <villas/node.h>
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2019-04-23 13:03:58 +02:00
|
|
|
#include <villas/log.hpp>
|
2018-06-28 13:42:50 +02:00
|
|
|
|
2016-11-20 12:59:37 -05:00
|
|
|
/* Forward declarations */
|
2020-08-25 21:00:52 +02:00
|
|
|
struct vnode;
|
2016-11-20 12:59:37 -05:00
|
|
|
|
2017-10-16 23:07:42 +02:00
|
|
|
/** The register mode determines under which condition the path is triggered. */
|
2019-06-23 16:13:23 +02:00
|
|
|
enum class PathMode {
|
|
|
|
ANY, /**< The path is triggered whenever one of the sources receives samples. */
|
|
|
|
ALL /**< The path is triggered only after all sources have received at least 1 sample. */
|
2017-10-16 23:07:42 +02:00
|
|
|
};
|
|
|
|
|
2016-11-07 22:17:45 -05:00
|
|
|
/** The datastructure for a path. */
|
2020-06-08 02:25:07 +02:00
|
|
|
struct vpath {
|
2019-06-23 16:13:23 +02:00
|
|
|
enum State state; /**< Path state. */
|
2017-10-16 23:07:42 +02:00
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
enum PathMode mode; /**< Determines when this path is triggered. */
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2020-08-17 17:01:36 +02:00
|
|
|
uuid_t uuid;
|
|
|
|
|
2017-08-30 23:53:35 +02:00
|
|
|
struct {
|
|
|
|
int nfds;
|
|
|
|
struct pollfd *pfds;
|
|
|
|
} reader;
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2017-08-30 23:53:35 +02:00
|
|
|
struct pool pool;
|
|
|
|
struct sample *last_sample;
|
2017-10-16 23:07:42 +02:00
|
|
|
int last_sequence;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2020-06-08 02:25:07 +02:00
|
|
|
struct vlist sources; /**< List of all incoming nodes (struct vpath_source). */
|
|
|
|
struct vlist destinations; /**< List of all outgoing nodes (struct vpath_destination). */
|
2019-06-11 18:34:23 +02:00
|
|
|
struct vlist mappings; /**< List of all input mappings (struct mapping_entry). */
|
2019-01-07 10:28:55 +01:00
|
|
|
struct vlist hooks; /**< List of processing hooks (struct hook). */
|
|
|
|
struct vlist signals; /**< List of signals which this path creates (struct signal). */
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2020-03-04 13:06:28 +01:00
|
|
|
struct Task timeout;
|
2017-10-16 23:07:42 +02:00
|
|
|
|
2018-06-29 08:37:14 +02:00
|
|
|
double rate; /**< A timeout for */
|
2021-05-10 00:12:30 +02:00
|
|
|
int enabled; /**< Is this path enabled? */
|
|
|
|
int muxed; /**< Is this path muxed? */
|
2020-09-13 08:36:48 +02:00
|
|
|
int affinity; /**< Thread affinity. */
|
2018-06-29 08:37:14 +02:00
|
|
|
int poll; /**< Weather or not to use poll(2). */
|
2020-08-17 17:01:36 +02:00
|
|
|
int reverse; /**< This path has a matching reverse path. */
|
2018-06-29 08:37:14 +02:00
|
|
|
int builtin; /**< This path should use built-in hooks by default. */
|
2020-08-17 17:01:36 +02:00
|
|
|
int original_sequence_no; /**< Use original source sequence number when multiplexing */
|
|
|
|
unsigned queuelen; /**< The queue length for each path_destination::queue */
|
2014-06-25 17:50:30 +00:00
|
|
|
|
2018-06-29 08:37:14 +02:00
|
|
|
pthread_t tid; /**< The thread id for this path. */
|
2021-02-16 14:15:14 +01:00
|
|
|
json_t *config; /**< A JSON object containing the configuration of the path. */
|
2019-04-07 15:44:00 +02:00
|
|
|
|
2019-04-07 16:16:58 +02:00
|
|
|
villas::Logger logger;
|
|
|
|
|
2020-09-10 17:36:08 +02:00
|
|
|
std::list<struct vnode *> mask_list;
|
|
|
|
|
2019-04-23 10:55:23 +02:00
|
|
|
std::bitset<MAX_SAMPLE_LENGTH> mask; /**< A mask of path_sources which are enabled for poll(). */
|
2020-08-17 17:01:36 +02:00
|
|
|
std::bitset<MAX_SAMPLE_LENGTH> received; /**< A mask of path_sources for which we already received samples. */
|
2021-07-07 10:39:35 +02:00
|
|
|
|
|
|
|
/** Custom formatter for spdlog */
|
|
|
|
template<typename OStream>
|
|
|
|
friend OStream &operator<<(OStream &os, const struct vpath &p)
|
|
|
|
{
|
|
|
|
os << "[";
|
|
|
|
|
|
|
|
for (size_t i = 0; i < vlist_length(&p.sources); i++) {
|
|
|
|
struct vpath_source *ps = (struct vpath_source *) vlist_at(&p.sources, i);
|
|
|
|
|
|
|
|
os << " " << node_name_short(ps->node);
|
|
|
|
}
|
|
|
|
|
|
|
|
os << " ] " CLR_MAG("=>") " [";
|
|
|
|
|
|
|
|
for (size_t i = 0; i < vlist_length(&p.destinations); i++) {
|
|
|
|
struct vpath_destination *pd = (struct vpath_destination *) vlist_at(&p.destinations, i);
|
|
|
|
|
|
|
|
os << " " << node_name_short(pd->node);
|
|
|
|
}
|
|
|
|
|
|
|
|
os << " ]";
|
|
|
|
|
|
|
|
return os;
|
|
|
|
}
|
2014-06-05 09:34:29 +00:00
|
|
|
};
|
|
|
|
|
2016-10-20 21:16:01 -04:00
|
|
|
/** Initialize internal data structures. */
|
2020-09-10 11:11:42 +02:00
|
|
|
int path_init(struct vpath *p) __attribute__ ((warn_unused_result));
|
2017-03-12 17:01:24 -03:00
|
|
|
|
2021-06-21 16:12:47 -04:00
|
|
|
int path_prepare(struct vpath *p, villas::node::NodeList &nodes);
|
2017-03-05 10:06:32 -04:00
|
|
|
|
|
|
|
/** Check if path configuration is proper. */
|
2020-09-10 17:36:08 +02:00
|
|
|
void path_check(struct vpath *p);
|
2015-03-21 15:23:57 +01:00
|
|
|
|
2014-06-05 09:35:32 +00:00
|
|
|
/** Start a path.
|
|
|
|
*
|
|
|
|
* Start a new pthread for receiving/sending messages over this path.
|
2014-06-05 09:34:29 +00:00
|
|
|
*
|
2015-03-21 15:31:42 +01:00
|
|
|
* @param p A pointer to the path structure.
|
2014-12-05 12:26:47 +01:00
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
2014-06-05 09:34:29 +00:00
|
|
|
*/
|
2020-06-08 02:25:07 +02:00
|
|
|
int path_start(struct vpath *p);
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2014-06-05 09:35:32 +00:00
|
|
|
/** Stop a path.
|
2014-06-05 09:34:29 +00:00
|
|
|
*
|
2015-03-21 15:31:42 +01:00
|
|
|
* @param p A pointer to the path structure.
|
2014-12-05 12:26:47 +01:00
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
2014-06-05 09:34:29 +00:00
|
|
|
*/
|
2020-06-08 02:25:07 +02:00
|
|
|
int path_stop(struct vpath *p);
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2017-03-12 17:01:24 -03:00
|
|
|
/** Destroy path by freeing dynamically allocated memory.
|
|
|
|
*
|
|
|
|
* @param i A pointer to the path structure.
|
|
|
|
*/
|
2020-09-10 11:11:42 +02:00
|
|
|
int path_destroy(struct vpath *p) __attribute__ ((warn_unused_result));
|
2017-03-12 17:01:24 -03:00
|
|
|
|
2020-07-01 17:02:22 +02:00
|
|
|
/** Get a list of signals which is emitted by the path. */
|
2021-07-01 22:26:44 +02:00
|
|
|
struct vlist * path_output_signals(struct vpath *p);
|
|
|
|
|
|
|
|
unsigned path_output_signals_max_cnt(struct vpath *p);
|
2020-07-01 17:02:22 +02:00
|
|
|
|
2016-11-07 22:17:45 -05:00
|
|
|
/** Reverse a path */
|
2020-06-08 02:25:07 +02:00
|
|
|
int path_reverse(struct vpath *p, struct vpath *r);
|
2016-11-07 22:17:45 -05:00
|
|
|
|
2016-11-20 12:59:37 -05:00
|
|
|
/** Parse a single path and add it to the global configuration.
|
|
|
|
*
|
2021-02-16 14:15:14 +01:00
|
|
|
* @param json A JSON object containing the configuration of the path.
|
2016-11-20 12:59:37 -05:00
|
|
|
* @param p Pointer to the allocated memory for this path
|
|
|
|
* @param nodes A linked list of all existing nodes
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2021-06-21 16:12:47 -04:00
|
|
|
int path_parse(struct vpath *p, json_t *json, villas::node::NodeList &nodes, const uuid_t sn_uuid);
|
2016-11-20 12:59:37 -05:00
|
|
|
|
2021-06-21 16:12:47 -04:00
|
|
|
void path_parse_mask(struct vpath *p, json_t *json_mask, villas::node::NodeList &nodes);
|
2020-08-28 09:42:46 +02:00
|
|
|
|
2020-06-08 02:25:07 +02:00
|
|
|
bool path_is_simple(const struct vpath *p);
|
2019-02-24 11:10:44 +01:00
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
bool path_is_muxed(const struct vpath *p);
|
|
|
|
|
2020-06-08 02:25:07 +02:00
|
|
|
bool path_is_enabled(const struct vpath *p);
|
2019-02-24 11:10:44 +01:00
|
|
|
|
2020-06-08 02:25:07 +02:00
|
|
|
bool path_is_reversed(const struct vpath *p);
|
2019-02-12 17:54:35 +01:00
|
|
|
|
2020-08-25 20:24:18 +02:00
|
|
|
json_t * path_to_json(struct vpath *p);
|
|
|
|
|
2018-06-29 08:37:14 +02:00
|
|
|
/** @} */
|