1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/lib/node.cpp

723 lines
15 KiB
C++
Raw Permalink Normal View History

/** Nodes.
*
* @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-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-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/>.
2015-06-02 21:53:04 +02:00
*********************************************************************************/
2020-08-25 20:24:46 +02:00
#include <regex>
#include <cstring>
#include <cctype>
#include <openssl/md5.h>
#include <villas/node/config.h>
2019-06-23 16:13:23 +02:00
#include <villas/hook.hpp>
2019-04-23 13:12:04 +02:00
#include <villas/hook_list.hpp>
2017-12-09 02:19:28 +08:00
#include <villas/sample.h>
#include <villas/node.h>
2020-07-01 17:02:22 +02:00
#include <villas/path.h>
#include <villas/utils.hpp>
2019-04-23 13:11:08 +02:00
#include <villas/colors.hpp>
2017-12-09 02:19:28 +08:00
#include <villas/plugin.h>
#include <villas/mapping.h>
#include <villas/timing.h>
2018-03-21 16:59:19 +01:00
#include <villas/signal.h>
#include <villas/memory.h>
2019-01-21 22:14:41 +01:00
#ifdef WITH_NETEM
#include <villas/kernel/if.hpp>
#include <villas/kernel/nl.hpp>
#include <villas/kernel/tc.hpp>
#include <villas/kernel/tc_netem.hpp>
2019-01-21 22:14:41 +01:00
#endif /* WITH_NETEM */
2019-06-23 13:35:42 +02:00
using namespace villas;
2019-06-04 16:55:38 +02:00
using namespace villas::utils;
2020-08-25 21:00:52 +02:00
int node_init(struct vnode *n, struct vnode_type *vt)
{
int ret;
n->_vt = vt;
n->_vd = new char[vt->size];
2020-01-25 17:39:06 +01:00
if (!n->_vd)
throw MemoryAllocationError();
2020-07-05 13:23:14 +01:00
memset(n->_vd, 0, vt->size);
2020-07-01 17:02:22 +02:00
using stats_ptr = std::shared_ptr<Stats>;
new (&n->stats) stats_ptr();
2021-02-16 14:15:14 +01:00
new (&n->logger) Logger();
n->logger = logging.get(fmt::format("node:{}", node_type_name(vt)));
2020-07-01 17:02:22 +02:00
uuid_clear(n->uuid);
2020-07-01 17:02:22 +02:00
n->output_path = nullptr;
2019-04-08 08:59:08 +02:00
n->name = nullptr;
n->_name = nullptr;
n->_name_long = nullptr;
n->enabled = true;
2020-07-04 17:15:54 +02:00
n->affinity = -1; /* all cores */
2019-02-15 09:46:26 +01:00
#ifdef __linux__
2019-02-15 09:42:33 +01:00
n->fwmark = -1;
2019-02-15 11:18:32 +01:00
#endif /* __linux__ */
2019-02-15 09:42:33 +01:00
#ifdef WITH_NETEM
2019-04-08 08:59:08 +02:00
n->tc_qdisc = nullptr;
n->tc_classifier = nullptr;
#endif /* WITH_NETEM */
2018-08-20 18:31:27 +02:00
/* Default values */
2019-06-23 16:13:23 +02:00
ret = node_direction_init(&n->in, NodeDir::IN, n);
if (ret)
return ret;
2019-06-23 16:13:23 +02:00
ret = node_direction_init(&n->out, NodeDir::OUT, n);
if (ret)
return ret;
ret = vlist_init(&n->sources);
if (ret)
return ret;
ret = vlist_init(&n->destinations);
if (ret)
return ret;
2018-09-25 20:29:05 +02:00
ret = vt->init ? vt->init(n) : 0;
if (ret)
return ret;
2019-06-23 16:13:23 +02:00
n->state = State::INITIALIZED;
2019-01-07 10:28:55 +01:00
vlist_push(&vt->instances, n);
return 0;
}
2020-08-25 21:00:52 +02:00
int node_prepare(struct vnode *n)
2018-08-20 18:31:27 +02:00
{
int ret;
2019-06-23 16:13:23 +02:00
assert(n->state == State::CHECKED);
2018-08-20 18:31:27 +02:00
2019-03-15 17:19:28 +01:00
ret = node_type(n)->prepare ? node_type(n)->prepare(n) : 0;
if (ret)
return ret;
2019-02-24 09:06:48 +01:00
ret = node_direction_prepare(&n->in, n);
2018-08-20 18:31:27 +02:00
if (ret)
return ret;
ret = node_direction_prepare(&n->out, n);
2018-08-20 18:31:27 +02:00
if (ret)
return ret;
2019-06-23 16:13:23 +02:00
n->state = State::PREPARED;
2019-02-24 11:13:28 +01:00
2018-08-20 18:31:27 +02:00
return 0;
}
int node_parse(struct vnode *n, json_t *json, const uuid_t sn_uuid)
2015-12-11 17:56:14 +01:00
{
int ret, enabled = n->enabled;
json_error_t err;
2019-04-08 08:59:08 +02:00
json_t *json_netem = nullptr;
const char *uuid_str = nullptr;
const char *name_str = nullptr;
ret = json_unpack_ex(json, &err, 0, "{ s?: s, s?: s, s?: b }",
"name", &name_str,
"uuid", &uuid_str,
"enabled", &enabled
2019-02-15 09:46:26 +01:00
);
if (ret)
2019-03-26 15:36:24 +01:00
return ret;
2019-02-15 09:46:26 +01:00
2021-02-16 14:15:14 +01:00
if (name_str)
n->logger = logging.get(fmt::format("node:{}", name_str));
2019-02-15 09:46:26 +01:00
#ifdef __linux__
2019-02-15 11:18:32 +01:00
ret = json_unpack_ex(json, &err, 0, "{ s?: { s?: o, s?: i } }",
"out",
2019-02-15 09:42:53 +01:00
"netem", &json_netem,
"fwmark", &n->fwmark
);
if (ret)
2019-03-26 15:36:24 +01:00
return ret;
2019-02-15 09:46:26 +01:00
#endif /* __linux__ */
2016-06-08 22:38:21 +02:00
n->enabled = enabled;
if (name_str)
n->name = strdup(name_str);
else
n->name = strdup("<none>");
if (uuid_str) {
ret = uuid_parse(uuid_str, n->uuid);
if (ret)
throw ConfigError(json, "node-config-node-uuid", "Failed to parse UUID: {}", uuid_str);
}
else
/* Generate UUID from hashed config including node name */
uuid_generate_from_json(n->uuid, json, sn_uuid);
if (json_netem) {
#ifdef WITH_NETEM
int enabled = 1;
ret = json_unpack_ex(json_netem, &err, 0, "{ s?: b }", "enabled", &enabled);
if (ret)
2019-03-26 15:36:24 +01:00
return ret;
if (enabled)
kernel::tc::netem_parse(&n->tc_qdisc, json_netem);
else
2019-04-08 08:59:08 +02:00
n->tc_qdisc = nullptr;
#endif /* WITH_NETEM */
}
2018-06-12 20:45:03 +02:00
struct {
const char *str;
2020-08-25 21:00:52 +02:00
struct vnode_direction *dir;
2018-06-12 20:45:03 +02:00
} dirs[] = {
{ "in", &n->in },
{ "out", &n->out }
};
2019-02-06 13:11:57 +01:00
const char *fields[] = { "signals", "builtin", "vectorize", "hooks" };
2018-06-12 20:45:03 +02:00
2019-04-07 15:13:40 +02:00
for (unsigned j = 0; j < ARRAY_LEN(dirs); j++) {
2018-08-20 18:31:27 +02:00
json_t *json_dir = json_object_get(json, dirs[j].str);
2018-06-12 20:45:03 +02:00
/* Skip if direction is unused */
if (!json_dir)
json_dir = json_pack("{ s: b }", "enabled", 0);
2018-06-12 20:45:03 +02:00
/* Copy missing fields from main node config to direction config */
2019-04-07 15:13:40 +02:00
for (unsigned i = 0; i < ARRAY_LEN(fields); i++) {
2018-06-12 20:45:03 +02:00
json_t *json_field_dir = json_object_get(json_dir, fields[i]);
json_t *json_field_node = json_object_get(json, fields[i]);
if (json_field_node && !json_field_dir)
json_object_set(json_dir, fields[i], json_field_node);
}
2018-06-12 20:45:03 +02:00
ret = node_direction_parse(dirs[j].dir, n, json_dir);
2018-03-21 16:59:19 +01:00
if (ret)
2019-03-26 15:36:24 +01:00
return ret;
2018-03-21 16:59:19 +01:00
}
2018-07-16 08:30:41 +02:00
ret = node_type(n)->parse ? node_type(n)->parse(n, json) : 0;
if (ret)
2019-03-26 15:36:24 +01:00
return ret;
2021-02-16 14:15:14 +01:00
n->config = json;
2019-06-23 16:13:23 +02:00
n->state = State::PARSED;
2016-06-08 22:38:21 +02:00
2019-03-26 15:36:24 +01:00
return 0;
}
2020-08-25 21:00:52 +02:00
int node_check(struct vnode *n)
2015-12-11 17:56:14 +01:00
{
int ret;
2019-06-23 16:13:23 +02:00
assert(n->state != State::DESTROYED);
ret = node_direction_check(&n->in, n);
if (ret)
return ret;
2015-10-09 13:04:52 +02:00
ret = node_direction_check(&n->out, n);
if (ret)
return ret;
2018-07-16 08:30:41 +02:00
ret = node_type(n)->check ? node_type(n)->check(n) : 0;
if (ret)
return ret;
2019-06-23 16:13:23 +02:00
n->state = State::CHECKED;
return 0;
}
2020-08-25 21:00:52 +02:00
int node_start(struct vnode *n)
2015-12-11 17:56:14 +01:00
{
2015-11-16 10:51:00 +01:00
int ret;
2019-06-23 16:13:23 +02:00
assert(n->state == State::PREPARED);
assert(node_type(n)->state == State::STARTED);
2014-12-05 12:39:52 +01:00
2021-02-16 14:15:14 +01:00
n->logger->info("Starting node");
2018-08-20 18:31:27 +02:00
ret = node_direction_start(&n->in, n);
if (ret)
return ret;
2018-08-20 18:31:27 +02:00
ret = node_direction_start(&n->out, n);
if (ret)
return ret;
2017-03-13 23:51:38 -03:00
2018-08-20 18:31:27 +02:00
ret = node_type(n)->start ? node_type(n)->start(n) : 0;
if (ret)
return ret;
#ifdef __linux__
/* Set fwmark for outgoing packets if netem is enabled for this node */
if (n->fwmark >= 0) {
int fds[16];
int num_sds = node_netem_fds(n, fds);
for (int i = 0; i < num_sds; i++) {
int fd = fds[i];
2019-02-15 09:42:33 +01:00
ret = setsockopt(fd, SOL_SOCKET, SO_MARK, &n->fwmark, sizeof(n->fwmark));
if (ret)
throw RuntimeError("Failed to set FW mark for outgoing packets");
else
2021-02-16 14:15:14 +01:00
n->logger->debug("Set FW mark for socket (sd={}) to {}", fd, n->fwmark);
}
}
#endif /* __linux__ */
2019-06-23 16:13:23 +02:00
n->state = State::STARTED;
2016-10-19 01:56:00 -04:00
n->sequence = 0;
return 0;
2014-12-05 12:39:52 +01:00
}
2020-08-25 21:00:52 +02:00
int node_stop(struct vnode *n)
2015-12-11 17:56:14 +01:00
{
2015-11-16 10:51:00 +01:00
int ret;
2019-06-23 16:13:23 +02:00
if (n->state != State::STOPPING && n->state != State::STARTED && n->state != State::CONNECTED && n->state != State::PENDING_CONNECT)
return 0;
2021-02-16 14:15:14 +01:00
n->logger->info("Stopping node");
2018-11-22 09:56:40 +02:00
ret = node_direction_stop(&n->in, n);
if (ret)
return ret;
2018-11-22 09:56:40 +02:00
ret = node_direction_stop(&n->out, n);
if (ret)
return ret;
ret = node_type(n)->stop ? node_type(n)->stop(n) : 0;
2015-11-16 10:51:00 +01:00
if (ret == 0)
2019-06-23 16:13:23 +02:00
n->state = State::STOPPED;
2015-11-16 10:51:00 +01:00
return ret;
}
2020-08-25 21:00:52 +02:00
int node_pause(struct vnode *n)
{
int ret;
2019-06-23 16:13:23 +02:00
if (n->state != State::STARTED)
return -1;
2021-02-16 14:15:14 +01:00
n->logger->info("Pausing node");
ret = node_type(n)->pause ? node_type(n)->pause(n) : 0;
if (ret == 0)
2019-06-23 16:13:23 +02:00
n->state = State::PAUSED;
return ret;
}
2020-08-25 21:00:52 +02:00
int node_resume(struct vnode *n)
{
int ret;
2019-06-23 16:13:23 +02:00
if (n->state != State::PAUSED)
return -1;
2021-02-16 14:15:14 +01:00
n->logger->info("Resuming node");
ret = node_type(n)->resume ? node_type(n)->resume(n) : 0;
if (ret == 0)
2019-06-23 16:13:23 +02:00
n->state = State::STARTED;
return ret;
}
2020-08-25 21:00:52 +02:00
int node_restart(struct vnode *n)
{
int ret;
2019-06-23 16:13:23 +02:00
if (n->state != State::STARTED)
return -1;
2021-02-16 14:15:14 +01:00
n->logger->info("Restarting node");
2019-02-24 11:14:44 +01:00
if (node_type(n)->restart)
ret = node_type(n)->restart(n);
else {
ret = node_type(n)->stop ? node_type(n)->stop(n) : 0;
if (ret)
return ret;
ret = node_type(n)->start ? node_type(n)->start(n) : 0;
if (ret)
return ret;
}
return 0;
}
2020-08-25 21:00:52 +02:00
int node_destroy(struct vnode *n)
{
int ret;
2019-06-23 16:13:23 +02:00
assert(n->state != State::DESTROYED && n->state != State::STARTED);
ret = node_direction_destroy(&n->in, n);
if (ret)
return ret;
ret = node_direction_destroy(&n->out, n);
if (ret)
return ret;
ret = vlist_destroy(&n->sources);
if (ret)
return ret;
ret = vlist_destroy(&n->destinations);
if (ret)
return ret;
2018-08-20 18:31:27 +02:00
if (node_type(n)->destroy) {
2018-07-16 08:30:41 +02:00
ret = (int) node_type(n)->destroy(n);
2018-08-20 18:31:27 +02:00
if (ret)
2018-07-09 12:55:36 +02:00
return ret;
}
vlist_remove_all(&node_type(n)->instances, n);
if (n->_vd)
delete[] (char *) n->_vd;
if (n->_name)
free(n->_name);
2017-04-24 18:59:45 +02:00
if (n->_name_long)
free(n->_name_long);
if (n->name)
free(n->name);
#ifdef WITH_NETEM
rtnl_qdisc_put(n->tc_qdisc);
rtnl_cls_put(n->tc_classifier);
#endif /* WITH_NETEM */
2020-07-01 17:02:22 +02:00
using stats_ptr = std::shared_ptr<Stats>;
n->stats.~stats_ptr();
2019-06-23 16:13:23 +02:00
n->state = State::DESTROYED;
return 0;
}
2020-08-25 21:00:52 +02:00
int node_read(struct vnode *n, struct sample *smps[], unsigned cnt, unsigned *release)
{
int toread, readd, nread = 0;
unsigned vect;
assert(node_type(n)->read);
2019-06-23 16:13:23 +02:00
if (n->state == State::PAUSED || n->state == State::PENDING_CONNECT)
2019-02-11 16:39:30 +01:00
return 0;
2019-06-23 16:13:23 +02:00
else if (n->state != State::STARTED && n->state != State::CONNECTED)
2019-02-11 16:39:30 +01:00
return -1;
vect = node_type(n)->vectorize;
if (!vect)
vect = cnt;
2017-09-02 14:20:38 +02:00
while (cnt - nread > 0) {
toread = MIN(cnt - nread, vect);
readd = node_type(n)->read(n, &smps[nread], toread, release);
if (readd < 0)
return readd;
nread += readd;
}
#ifdef WITH_HOOKS
/* Run read hooks */
int rread = hook_list_process(&n->in.hooks, smps, nread);
2021-02-22 23:16:53 +01:00
if (rread < 0)
return rread;
2018-05-23 02:25:27 +02:00
int skipped = nread - rread;
2021-02-22 23:16:53 +01:00
if (skipped > 0) {
if (n->stats != nullptr)
n->stats->update(Stats::Metric::SMPS_SKIPPED, skipped);
2021-02-16 14:15:14 +01:00
n->logger->debug("Received {} samples of which {} have been skipped", nread, skipped);
}
2021-02-22 23:16:53 +01:00
else
2021-02-16 14:15:14 +01:00
n->logger->debug( "Received {} samples", nread);
2018-05-23 02:25:27 +02:00
return rread;
#else
2021-02-16 14:15:14 +01:00
n->logger->debug("Received {} samples", nread);
2018-05-23 02:25:27 +02:00
return nread;
#endif /* WITH_HOOKS */
}
2020-08-25 21:00:52 +02:00
int node_write(struct vnode *n, struct sample *smps[], unsigned cnt, unsigned *release)
{
int tosend, sent, nsent = 0;
unsigned vect;
assert(node_type(n)->write);
2019-06-23 16:13:23 +02:00
if (n->state == State::PAUSED || n->state == State::PENDING_CONNECT)
2019-02-11 16:39:30 +01:00
return 0;
2019-06-23 16:13:23 +02:00
else if (n->state != State::STARTED && n->state != State::CONNECTED)
2019-02-11 16:39:30 +01:00
return -1;
#ifdef WITH_HOOKS
/* Run write hooks */
cnt = hook_list_process(&n->out.hooks, smps, cnt);
if (cnt <= 0)
return cnt;
#endif /* WITH_HOOKS */
vect = node_type(n)->vectorize;
if (!vect)
vect = cnt;
while (cnt - nsent > 0) {
tosend = MIN(cnt - nsent, vect);
sent = node_type(n)->write(n, &smps[nsent], tosend, release);
if (sent < 0)
return sent;
nsent += sent;
2021-02-16 14:15:14 +01:00
n->logger->debug("Sent {} samples", sent);
}
return nsent;
}
2020-08-25 21:00:52 +02:00
char * node_name(struct vnode *n)
{
if (!n->_name)
strcatf(&n->_name, CLR_RED("%s") "(" CLR_YEL("%s") ")", n->name, node_type_name(node_type(n)));
return n->_name;
}
2020-08-25 21:00:52 +02:00
char * node_name_long(struct vnode *n)
{
2015-12-11 18:19:35 +01:00
if (!n->_name_long) {
2020-07-04 17:15:54 +02:00
char uuid[37];
uuid_unparse(n->uuid, uuid);
2019-01-21 23:00:16 +01:00
2020-07-04 17:15:54 +02:00
strcatf(&n->_name_long, "%s: uuid=%s, #in.signals=%zu, #out.signals=%zu, #in.hooks=%zu, #out.hooks=%zu, in.vectorize=%d, out.vectorize=%d",
node_name(n), uuid,
vlist_length(&n->in.signals), vlist_length(&n->out.signals),
vlist_length(&n->in.hooks), vlist_length(&n->out.hooks),
n->in.vectorize, n->out.vectorize
);
2019-01-30 00:42:35 +01:00
#ifdef WITH_NETEM
2020-07-04 17:15:54 +02:00
strcatf(&n->_name_long, ", out.netem=%s", n->tc_qdisc ? "yes" : "no");
2019-01-30 00:42:35 +01:00
2020-07-04 17:15:54 +02:00
if (n->tc_qdisc)
strcatf(&n->_name_long, ", fwmark=%d", n->fwmark);
2019-01-30 00:42:35 +01:00
#endif /* WITH_NETEM */
2019-01-21 23:00:16 +01:00
2020-07-04 17:15:54 +02:00
if (n->output_path)
strcatf(&n->_name_long, ", output_path=%s", path_name(n->output_path));
if (node_type(n)->print) {
2020-08-25 21:00:52 +02:00
struct vnode_type *vt = node_type(n);
2020-07-04 17:15:54 +02:00
2019-01-21 23:00:16 +01:00
/* Append node-type specific details */
char *name_long = vt->print(n);
strcatf(&n->_name_long, ", %s", name_long);
2015-12-11 18:19:35 +01:00
free(name_long);
}
}
return n->_name_long;
}
2020-08-25 21:00:52 +02:00
const char * node_name_short(struct vnode *n)
{
return n->name;
}
2020-08-25 21:00:52 +02:00
int node_reverse(struct vnode *n)
{
2018-07-16 08:30:41 +02:00
return node_type(n)->reverse ? node_type(n)->reverse(n) : -1;
2015-03-21 15:29:00 +01:00
}
2020-08-25 21:00:52 +02:00
int node_poll_fds(struct vnode *n, int fds[])
{
return node_type(n)->poll_fds ? node_type(n)->poll_fds(n, fds) : -1;
}
2020-08-25 21:00:52 +02:00
int node_netem_fds(struct vnode *n, int fds[])
{
return node_type(n)->netem_fds ? node_type(n)->netem_fds(n, fds) : -1;
}
2020-08-25 21:00:52 +02:00
struct memory_type * node_memory_type(struct vnode *n)
{
return node_type(n)->memory_type ? node_type(n)->memory_type(n, memory_default) : memory_default;
}
2021-02-16 14:15:14 +01:00
int node_list_parse(struct vlist *list, json_t *json, struct vlist *all)
{
2020-08-25 21:00:52 +02:00
struct vnode *node;
const char *str;
2019-04-08 08:59:08 +02:00
char *allstr = nullptr;
size_t index;
json_t *elm;
2021-02-16 14:15:14 +01:00
auto logger = logging.get("node");
switch (json_typeof(json)) {
case JSON_STRING:
2021-02-16 14:15:14 +01:00
str = json_string_value(json);
2020-08-25 21:00:52 +02:00
node = vlist_lookup_name<struct vnode>(all, str);
if (!node)
goto invalid2;
2019-01-07 10:28:55 +01:00
vlist_push(list, node);
break;
case JSON_ARRAY:
2021-02-16 14:15:14 +01:00
json_array_foreach(json, index, elm) {
if (!json_is_string(elm))
goto invalid;
2020-08-25 21:00:52 +02:00
node = vlist_lookup_name<struct vnode>(all, json_string_value(elm));
if (!node)
goto invalid;
2019-01-07 10:28:55 +01:00
vlist_push(list, node);
}
break;
default:
goto invalid;
}
return 0;
invalid:
2021-02-16 14:15:14 +01:00
throw RuntimeError("The node list must be an a single or an array of strings referring to the keys of the 'nodes' section");
return -1;
invalid2:
2019-01-07 10:28:55 +01:00
for (size_t i = 0; i < vlist_length(all); i++) {
2020-08-25 21:00:52 +02:00
struct vnode *n = (struct vnode *) vlist_at(all, i);
strcatf(&allstr, " %s", node_name_short(n));
}
2021-02-16 14:15:14 +01:00
throw RuntimeError("Unknown node {}. Choose of one of: {}", str, allstr);
return 0;
2017-09-02 14:20:38 +02:00
}
2019-02-12 17:54:08 +01:00
bool node_is_valid_name(const char *name)
2019-02-12 17:54:08 +01:00
{
std::regex re(RE_NODE_NAME);
2019-02-12 17:54:08 +01:00
2020-08-25 20:24:46 +02:00
return std::regex_match(name, re);
}
2020-08-25 21:00:52 +02:00
bool node_is_enabled(const struct vnode *n)
2019-02-24 11:08:15 +01:00
{
return n->enabled;
}
2020-10-21 20:56:51 +02:00
struct vlist * node_input_signals(struct vnode *n)
2019-03-08 15:21:01 +01:00
{
2020-10-21 20:56:51 +02:00
return node_direction_get_signals(&n->in);
}
2019-03-08 15:21:01 +01:00
2020-10-21 20:56:51 +02:00
struct vlist * node_output_signals(struct vnode *n)
{
if (n->output_path)
return path_output_signals(n->output_path);
return nullptr;
2019-02-12 17:54:08 +01:00
}
2020-08-25 20:24:18 +02:00
2020-08-25 21:00:52 +02:00
json_t * node_to_json(struct vnode *n)
2020-08-25 20:24:18 +02:00
{
struct vlist *output_signals;
json_t *json_node;
json_t *json_signals_in = nullptr;
json_t *json_signals_out = nullptr;
char uuid[37];
uuid_unparse(n->uuid, uuid);
json_signals_in = signal_list_to_json(&n->in.signals);
output_signals = node_output_signals(n);
if (output_signals)
json_signals_out = signal_list_to_json(output_signals);
json_node = json_pack("{ s: s, s: s, s: s, s: i, s: { s: i, s: o? }, s: { s: i, s: o? } }",
"name", node_name_short(n),
"uuid", uuid,
"state", state_print(n->state),
"affinity", n->affinity,
"in",
"vectorize", n->in.vectorize,
"signals", json_signals_in,
"out",
"vectorize", n->out.vectorize,
"signals", json_signals_out
);
if (n->stats)
json_object_set_new(json_node, "stats", n->stats->toJson());
/* Add all additional fields of node here.
* This can be used for metadata */
2021-02-16 14:15:14 +01:00
json_object_update(json_node, n->config);
2020-08-25 20:24:18 +02:00
return json_node;
}