2014-06-05 09:35:32 +00:00
|
|
|
|
/** Nodes
|
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/>.
|
2018-03-21 16:59:19 +01:00
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
2015-09-19 18:48:00 +02:00
|
|
|
|
* @addtogroup node Node
|
|
|
|
|
* @{
|
2018-03-21 16:59:19 +01: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
|
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <netinet/in.h>
|
2017-08-03 00:19:27 +02:00
|
|
|
|
#include <jansson.h>
|
2019-10-30 02:38:56 +01:00
|
|
|
|
#include <uuid/uuid.h>
|
2014-06-05 09:34:29 +00:00
|
|
|
|
|
2018-06-29 09:06:04 +02:00
|
|
|
|
#include <villas/node_type.h>
|
2019-02-24 11:07:07 +01:00
|
|
|
|
#include <villas/node_direction.h>
|
2018-06-29 09:06:04 +02:00
|
|
|
|
#include <villas/sample.h>
|
|
|
|
|
#include <villas/list.h>
|
|
|
|
|
#include <villas/queue.h>
|
2020-03-04 12:41:55 +01:00
|
|
|
|
#include <villas/common.hpp>
|
2019-06-26 20:18:02 +02:00
|
|
|
|
#include <villas/stats.hpp>
|
2014-06-25 01:53:48 +00:00
|
|
|
|
|
2019-01-21 22:14:41 +01:00
|
|
|
|
#if defined(LIBNL3_ROUTE_FOUND) && defined(__linux__)
|
|
|
|
|
#define WITH_NETEM
|
|
|
|
|
#endif /* LIBNL3_ROUTE_FOUND */
|
|
|
|
|
|
2019-01-21 15:50:18 +01:00
|
|
|
|
/* Forward declarations */
|
2019-01-21 22:14:41 +01:00
|
|
|
|
#ifdef WITH_NETEM
|
2019-01-21 15:50:18 +01:00
|
|
|
|
struct rtnl_qdisc;
|
|
|
|
|
struct rtnl_cls;
|
2019-01-21 22:14:41 +01:00
|
|
|
|
#endif /* WITH_NETEM */
|
2018-05-24 09:04:41 +02:00
|
|
|
|
|
2020-09-10 17:35:35 +02:00
|
|
|
|
#define RE_NODE_NAME "[a-z0-9_-]{2,32}"
|
2020-08-25 20:24:46 +02:00
|
|
|
|
|
2016-06-08 22:38:21 +02:00
|
|
|
|
/** The data structure for a node.
|
|
|
|
|
*
|
|
|
|
|
* Every entity which exchanges messages is represented by a node.
|
|
|
|
|
* Nodes can be remote machines and simulators or locally running processes.
|
|
|
|
|
*/
|
2020-08-25 21:00:52 +02:00
|
|
|
|
struct vnode {
|
2017-08-01 11:56:47 +02:00
|
|
|
|
char *name; /**< A short identifier of the node, only used for configuration and logging */
|
2020-09-10 11:19:51 +02:00
|
|
|
|
bool enabled;
|
2019-01-21 17:11:11 +01:00
|
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
|
enum State state;
|
2019-01-21 17:11:11 +01:00
|
|
|
|
|
2016-06-08 22:38:21 +02:00
|
|
|
|
char *_name; /**< Singleton: A string used to print to screen. */
|
|
|
|
|
char *_name_long; /**< Singleton: A string used to print to screen. */
|
|
|
|
|
|
2019-10-30 02:38:56 +01:00
|
|
|
|
uuid_t uuid;
|
|
|
|
|
|
2016-06-08 22:38:21 +02:00
|
|
|
|
int affinity; /**< CPU Affinity of this node */
|
2017-05-05 19:24:16 +00:00
|
|
|
|
|
2018-08-20 18:31:27 +02:00
|
|
|
|
uint64_t sequence; /**< This is a counter of received samples, in case the node-type does not generate sequence numbers itself. */
|
2017-09-02 14:27:58 +02:00
|
|
|
|
|
2020-07-01 17:02:22 +02:00
|
|
|
|
/** The path which uses this node as a destination.
|
|
|
|
|
* Usually every node should be used only by a single path as destination.
|
|
|
|
|
* Otherwise samples from different paths would be interleaved.
|
|
|
|
|
*/
|
|
|
|
|
struct vpath *output_path;
|
|
|
|
|
std::shared_ptr<villas::Stats> stats; /**< Statistic counters. This is a pointer to the statistic hooks private data. */
|
2017-09-02 14:27:58 +02:00
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
|
struct vnode_direction in, out;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
|
2019-02-15 09:46:26 +01:00
|
|
|
|
#ifdef __linux__
|
2019-02-15 09:42:33 +01:00
|
|
|
|
int fwmark; /**< Socket mark for netem, routing and filtering */
|
2019-01-21 15:50:18 +01:00
|
|
|
|
|
2019-02-15 09:46:26 +01:00
|
|
|
|
#ifdef WITH_NETEM
|
2019-01-21 15:50:18 +01:00
|
|
|
|
struct rtnl_qdisc *tc_qdisc; /**< libnl3: Network emulator queuing discipline */
|
|
|
|
|
struct rtnl_cls *tc_classifier; /**< libnl3: Firewall mark classifier */
|
2019-01-21 22:14:41 +01:00
|
|
|
|
#endif /* WITH_NETEM */
|
2019-02-15 09:46:26 +01:00
|
|
|
|
#endif /* __linux__ */
|
2019-01-21 15:50:18 +01:00
|
|
|
|
|
2020-09-10 11:20:35 +02:00
|
|
|
|
struct vlist sources; /**< A list of path sources which reference this node (struct vpath_sources). */
|
|
|
|
|
struct vlist destinations; /**< A list of path destinations which reference this node (struct vpath_destinations). */
|
2020-08-28 09:42:46 +02:00
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
|
struct vnode_type *_vt; /**< Virtual functions (C++ OOP style) */
|
|
|
|
|
void *_vd; /**< Virtual data (used by struct vnode::_vt functions) */
|
2017-08-03 00:19:27 +02:00
|
|
|
|
|
|
|
|
|
json_t *cfg; /**< A JSON object containing the configuration of the node. */
|
2016-06-08 22:38:21 +02:00
|
|
|
|
};
|
2015-12-11 12:35:32 +01:00
|
|
|
|
|
2018-08-17 12:40:03 +02:00
|
|
|
|
/** Initialize node with default values */
|
2020-09-10 11:11:42 +02:00
|
|
|
|
int node_init(struct vnode *n, struct vnode_type *vt) __attribute__ ((warn_unused_result));
|
2017-03-12 17:13:37 -03:00
|
|
|
|
|
2018-08-17 12:40:03 +02:00
|
|
|
|
/** Do initialization after parsing the configuration */
|
2020-08-25 21:00:52 +02:00
|
|
|
|
int node_prepare(struct vnode *n);
|
2018-08-17 12:40:03 +02:00
|
|
|
|
|
2017-07-13 01:55:06 +02:00
|
|
|
|
/** Parse settings of a node.
|
2014-06-05 09:34:56 +00:00
|
|
|
|
*
|
2017-08-03 00:19:27 +02:00
|
|
|
|
* @param cfg A JSON object containing the configuration of the node.
|
2017-03-12 17:13:37 -03:00
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
|
* @retval <0 Error. Something went wrong.
|
2015-11-23 16:42:43 +01:00
|
|
|
|
*/
|
2020-10-16 11:08:40 +02:00
|
|
|
|
int node_parse(struct vnode *n, json_t *cfg, const uuid_t sn_uuid);
|
2017-03-12 17:13:37 -03:00
|
|
|
|
|
2018-03-21 16:59:19 +01:00
|
|
|
|
/** Parse an array or single node and checks if they exist in the "nodes" section.
|
|
|
|
|
*
|
|
|
|
|
* Examples:
|
|
|
|
|
* out = [ "sintef", "scedu" ]
|
|
|
|
|
* out = "acs"
|
|
|
|
|
*
|
|
|
|
|
* @param cfg A JSON array or string. See examples above.
|
|
|
|
|
* @param nodes The nodes will be added to this list.
|
|
|
|
|
* @param all This list contains all valid nodes.
|
|
|
|
|
*/
|
2019-02-24 09:10:18 +01:00
|
|
|
|
int node_list_parse(struct vlist *list, json_t *cfg, struct vlist *all);
|
2018-03-21 16:59:19 +01:00
|
|
|
|
|
|
|
|
|
/** Parse the list of signal definitions. */
|
2019-01-07 10:28:55 +01:00
|
|
|
|
int node_parse_signals(struct vlist *list, json_t *cfg);
|
2018-03-21 16:59:19 +01:00
|
|
|
|
|
2017-03-12 17:13:37 -03:00
|
|
|
|
/** Validate node configuration. */
|
2020-08-25 21:00:52 +02:00
|
|
|
|
int node_check(struct vnode *n);
|
2015-11-23 16:42:43 +01:00
|
|
|
|
|
|
|
|
|
/** Start operation of a node.
|
|
|
|
|
*
|
2020-01-21 14:27:28 +01:00
|
|
|
|
* @see node_type::start
|
2014-06-05 09:34:56 +00:00
|
|
|
|
*/
|
2020-08-25 21:00:52 +02:00
|
|
|
|
int node_start(struct vnode *n);
|
2014-12-05 12:39:52 +01:00
|
|
|
|
|
2015-11-23 16:42:43 +01:00
|
|
|
|
/** Stops operation of a node.
|
|
|
|
|
*
|
2020-01-21 14:27:28 +01:00
|
|
|
|
* @see node_type::stop
|
2015-11-23 16:42:43 +01:00
|
|
|
|
*/
|
2020-08-25 21:00:52 +02:00
|
|
|
|
int node_stop(struct vnode *n);
|
2014-06-05 09:34:56 +00:00
|
|
|
|
|
2018-11-22 09:56:30 +02:00
|
|
|
|
/** Pauses operation of a node.
|
|
|
|
|
*
|
2020-01-21 14:27:28 +01:00
|
|
|
|
* @see node_type::stop
|
2018-11-22 09:56:30 +02:00
|
|
|
|
*/
|
2020-08-25 21:00:52 +02:00
|
|
|
|
int node_pause(struct vnode *n);
|
2018-11-22 09:56:30 +02:00
|
|
|
|
|
|
|
|
|
/** Resumes operation of a node.
|
|
|
|
|
*
|
2020-01-21 14:27:28 +01:00
|
|
|
|
* @see node_type::stop
|
2018-11-22 09:56:30 +02:00
|
|
|
|
*/
|
2020-08-25 21:00:52 +02:00
|
|
|
|
int node_resume(struct vnode *n);
|
2018-11-22 09:56:30 +02:00
|
|
|
|
|
|
|
|
|
/** Restarts operation of a node.
|
|
|
|
|
*
|
2020-01-21 14:27:28 +01:00
|
|
|
|
* @see node_type::stop
|
2018-11-22 09:56:30 +02:00
|
|
|
|
*/
|
2020-08-25 21:00:52 +02:00
|
|
|
|
int node_restart(struct vnode *n);
|
2018-11-22 09:56:30 +02:00
|
|
|
|
|
2017-03-12 17:13:37 -03:00
|
|
|
|
/** Destroy node by freeing dynamically allocated memory.
|
|
|
|
|
*
|
|
|
|
|
* @see node_type::destroy
|
|
|
|
|
*/
|
2020-09-10 11:11:42 +02:00
|
|
|
|
int node_destroy(struct vnode *n) __attribute__ ((warn_unused_result));
|
2017-03-12 17:13:37 -03:00
|
|
|
|
|
2015-12-13 00:46:22 +01:00
|
|
|
|
/** Return a pointer to a string which should be used to print this node.
|
2014-06-05 09:34:56 +00:00
|
|
|
|
*
|
2015-11-29 22:45:46 +01:00
|
|
|
|
* @see node::_name‚
|
|
|
|
|
* @param n A pointer to the node structure.
|
|
|
|
|
*/
|
2020-08-25 21:00:52 +02:00
|
|
|
|
const char * node_name_short(struct vnode *n);
|
2015-12-13 02:02:29 +01:00
|
|
|
|
|
|
|
|
|
/** Return a pointer to a string which should be used to print this node. */
|
2020-08-25 21:00:52 +02:00
|
|
|
|
char * node_name(struct vnode *n);
|
2015-11-29 22:45:46 +01:00
|
|
|
|
|
2015-12-13 00:46:22 +01:00
|
|
|
|
/** Return a pointer to a string which should be used to print this node.
|
2015-11-29 22:45:46 +01:00
|
|
|
|
*
|
|
|
|
|
* @see node::_name_short
|
2015-11-23 16:42:43 +01:00
|
|
|
|
* @see node_type::print
|
2015-11-29 22:45:46 +01:00
|
|
|
|
* @param n A pointer to the node structure.
|
2014-06-05 09:34:56 +00:00
|
|
|
|
*/
|
2020-08-25 21:00:52 +02:00
|
|
|
|
char * node_name_long(struct vnode *n);
|
2014-12-05 12:39:52 +01:00
|
|
|
|
|
2020-07-01 17:02:22 +02:00
|
|
|
|
/** Return a list of signals which are sent to this node.
|
|
|
|
|
*
|
|
|
|
|
* This list is derived from the path which uses the node as destination.
|
|
|
|
|
*/
|
2020-08-25 21:00:52 +02:00
|
|
|
|
struct vlist * node_output_signals(struct vnode *n);
|
2020-07-01 17:02:22 +02:00
|
|
|
|
|
2020-10-21 20:56:51 +02:00
|
|
|
|
struct vlist * node_input_signals(struct vnode *n);
|
|
|
|
|
|
2015-11-23 16:42:43 +01:00
|
|
|
|
/** Reverse local and remote socket address.
|
2015-03-21 15:23:57 +01:00
|
|
|
|
*
|
2015-11-23 16:42:43 +01:00
|
|
|
|
* @see node_type::reverse
|
2015-03-21 15:23:57 +01:00
|
|
|
|
*/
|
2020-08-25 21:00:52 +02:00
|
|
|
|
int node_reverse(struct vnode *n);
|
2015-03-18 16:18:10 +01:00
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
|
int node_read(struct vnode *n, struct sample *smps[], unsigned cnt, unsigned *release);
|
2016-06-08 22:38:21 +02:00
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
|
int node_write(struct vnode *n, struct sample *smps[], unsigned cnt, unsigned *release);
|
2016-06-08 22:38:21 +02:00
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
|
int node_poll_fds(struct vnode *n, int fds[]);
|
2017-08-30 00:22:58 +02:00
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
|
int node_netem_fds(struct vnode *n, int fds[]);
|
2019-01-21 15:50:18 +01:00
|
|
|
|
|
2019-02-24 11:06:24 +01:00
|
|
|
|
static inline
|
2020-08-25 21:00:52 +02:00
|
|
|
|
struct vnode_type * node_type(struct vnode *n)
|
2019-02-24 11:06:24 +01:00
|
|
|
|
{
|
|
|
|
|
return n->_vt;
|
|
|
|
|
}
|
2018-07-16 08:29:10 +02:00
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
|
struct memory_type * node_memory_type(struct vnode *n);
|
2018-06-29 17:32:07 +02:00
|
|
|
|
|
2019-02-24 11:10:44 +01:00
|
|
|
|
bool node_is_valid_name(const char *name);
|
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
|
bool node_is_enabled(const struct vnode *n);
|
2019-02-24 11:08:15 +01:00
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
|
json_t * node_to_json(struct vnode *);
|
2020-08-25 20:24:18 +02:00
|
|
|
|
|
2017-07-13 01:55:06 +02:00
|
|
|
|
/** @} */
|