From 7749a3a92219143434b0ea08a28324ff5e9aafb3 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 30 Jun 2023 10:51:01 +0200 Subject: [PATCH] No not pass super-node UUID to Node::parse() any longer Signed-off-by: Steffen Vogel --- include/villas/node.h | 2 +- include/villas/node.hpp | 17 ++-- include/villas/node_compat.hpp | 6 +- include/villas/nodes/api.hpp | 4 +- include/villas/nodes/example.hpp | 4 +- include/villas/nodes/exec.hpp | 6 +- include/villas/nodes/fpga.hpp | 2 +- include/villas/nodes/go.hpp | 2 +- include/villas/nodes/iec60870.hpp | 4 +- include/villas/nodes/iec61850_goose.hpp | 4 +- include/villas/nodes/loopback.hpp | 2 +- include/villas/nodes/loopback_internal.hpp | 2 +- include/villas/nodes/signal.hpp | 4 +- include/villas/nodes/webrtc.hpp | 8 +- lib/node.cpp | 92 ++++++++-------------- lib/node_capi.cpp | 8 +- lib/node_compat.cpp | 12 +-- lib/nodes/api.cpp | 8 +- lib/nodes/example.cpp | 6 +- lib/nodes/exec.cpp | 4 +- lib/nodes/fpga.cpp | 2 +- lib/nodes/iec60870.cpp | 8 +- lib/nodes/iec61850_goose.cpp | 8 +- lib/nodes/loopback.cpp | 4 +- lib/nodes/loopback_internal.cpp | 6 +- lib/nodes/signal.cpp | 8 +- lib/nodes/webrtc.cpp | 8 +- lib/super_node.cpp | 38 +++++---- 28 files changed, 136 insertions(+), 143 deletions(-) diff --git a/include/villas/node.h b/include/villas/node.h index 96d737a79..02b6650fb 100644 --- a/include/villas/node.h +++ b/include/villas/node.h @@ -16,7 +16,7 @@ typedef void *vnode; typedef void *vsample; -vnode * node_new(const char *json_str, const char *sn_uuid_str); +vnode * node_new(const char *id_str, const char *json_str); int node_prepare(vnode *n); diff --git a/include/villas/node.hpp b/include/villas/node.hpp index afecf46c0..5c0842d8d 100644 --- a/include/villas/node.hpp +++ b/include/villas/node.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -107,7 +108,7 @@ protected: public: /** Initialize node with default values */ - Node(const std::string &name = ""); + Node(const uuid_t &id = {}, const std::string &name = ""); /** Destroy node by freeing dynamically allocated memory. */ virtual @@ -124,7 +125,7 @@ public: * @retval <0 Error. Something went wrong. */ virtual - int parse(json_t *json, const uuid_t sn_uuid); + int parse(json_t *json); /** Validate node configuration. */ virtual @@ -351,6 +352,8 @@ protected: n->logger = getLogger(); n->factory = this; + n->name_long = fmt::format(CLR_RED("{}") "(" CLR_YEL("{}") ")", n->name_short, getName()); + instances.push_back(n); } @@ -376,13 +379,13 @@ public: } virtual - Node * make() = 0; + Node * make(const uuid_t &id = {}, const std::string &nme = "") = 0; static - Node * make(json_t *json, uuid_t uuid); + Node * make(json_t *json, const uuid_t &id, const std::string &name = ""); static - Node * make(const std::string &type); + Node * make(const std::string &type, const uuid_t &id = {}, const std::string &name = ""); virtual std::string getType() const @@ -438,9 +441,9 @@ class NodePlugin : public NodeFactory { public: virtual - Node * make() + Node * make(const uuid_t &id = {}, const std::string &nme = "") { - T* n = new T(); + T* n = new T(id, nme); init(n); diff --git a/include/villas/node_compat.hpp b/include/villas/node_compat.hpp index c24ff5e2b..b1d40c78f 100644 --- a/include/villas/node_compat.hpp +++ b/include/villas/node_compat.hpp @@ -43,7 +43,7 @@ public: NodeCompat *node; json_t *cfg; - NodeCompat(struct NodeCompatType *vt); + NodeCompat(struct NodeCompatType *vt, const uuid_t &id, const std::string &name); NodeCompat(const NodeCompat& n); NodeCompat& operator=(const NodeCompat& other); @@ -71,7 +71,7 @@ public: * @retval <0 Error. Something went wrong. */ virtual - int parse(json_t *json, const uuid_t sn_uuid); + int parse(json_t *json); /** Returns a string with a textual represenation of this node. */ virtual @@ -170,7 +170,7 @@ public: { } virtual - Node * make(); + Node * make(const uuid_t &id = {}, const std::string &name = ""); /// Get plugin name virtual diff --git a/include/villas/nodes/api.hpp b/include/villas/nodes/api.hpp index 075f03b2b..ecbf75682 100644 --- a/include/villas/nodes/api.hpp +++ b/include/villas/nodes/api.hpp @@ -22,7 +22,7 @@ struct Sample; class APINode : public Node { public: - APINode(const std::string &name = ""); + APINode(const uuid_t &id = {}, const std::string &name = ""); struct Direction { Sample *sample; @@ -42,7 +42,7 @@ public: protected: virtual - int parse(json_t *json, const uuid_t sn_uuid); + int parse(json_t *json); virtual int _read(struct Sample *smps[], unsigned cnt); diff --git a/include/villas/nodes/example.hpp b/include/villas/nodes/example.hpp index 4454104fa..005bb2b24 100644 --- a/include/villas/nodes/example.hpp +++ b/include/villas/nodes/example.hpp @@ -42,7 +42,7 @@ protected: int _write(struct Sample *smps[], unsigned cnt); public: - ExampleNode(const std::string &name = ""); + ExampleNode(const uuid_t &id = {}, const std::string &name = ""); /* All of the following virtual-declared functions are optional. * Have a look at node.hpp/node.cpp for the default behaviour. @@ -55,7 +55,7 @@ public: int prepare(); virtual - int parse(json_t *json, const uuid_t sn_uuid); + int parse(json_t *json); /** Validate node configuration. */ virtual diff --git a/include/villas/nodes/exec.hpp b/include/villas/nodes/exec.hpp index e7cb83c3b..af8a07c88 100644 --- a/include/villas/nodes/exec.hpp +++ b/include/villas/nodes/exec.hpp @@ -42,8 +42,8 @@ protected: int _write(struct Sample * smps[], unsigned cnt); public: - ExecNode(const std::string &name = "") : - Node(name), + ExecNode(const uuid_t &id = {}, const std::string &name = "") : + Node(id, name), stream_in(nullptr), stream_out(nullptr), flush(true), @@ -66,7 +66,7 @@ public: int prepare(); virtual - int parse(json_t *json, const uuid_t sn_uuid); + int parse(json_t *json); virtual std::vector getPollFDs(); diff --git a/include/villas/nodes/fpga.hpp b/include/villas/nodes/fpga.hpp index b523a2261..97c6c52ff 100644 --- a/include/villas/nodes/fpga.hpp +++ b/include/villas/nodes/fpga.hpp @@ -57,7 +57,7 @@ public: ~FpgaNode(); virtual - int parse(json_t *json, const uuid_t sn_uuid); + int parse(json_t *json); virtual const std::string & getDetails(); diff --git a/include/villas/nodes/go.hpp b/include/villas/nodes/go.hpp index b0cdebe8f..a9d8e6195 100644 --- a/include/villas/nodes/go.hpp +++ b/include/villas/nodes/go.hpp @@ -42,7 +42,7 @@ public: ~GoNode(); virtual - int parse(json_t *json, const uuid_t sn_uuid); + int parse(json_t *json); virtual std::vector getPollFDs(); diff --git a/include/villas/nodes/iec60870.hpp b/include/villas/nodes/iec60870.hpp index 6f4384131..f245c29da 100644 --- a/include/villas/nodes/iec60870.hpp +++ b/include/villas/nodes/iec60870.hpp @@ -171,13 +171,13 @@ protected: int _write(struct Sample *smps[], unsigned cnt) override; public: - SlaveNode(const std::string &name = ""); + SlaveNode(const uuid_t &id = {}, const std::string &name = ""); virtual ~SlaveNode() override; virtual - int parse(json_t *json, const uuid_t sn_uuid) override; + int parse(json_t *json) override; virtual int start() override; diff --git a/include/villas/nodes/iec61850_goose.hpp b/include/villas/nodes/iec61850_goose.hpp index 2c97eea49..4f60fb99e 100644 --- a/include/villas/nodes/iec61850_goose.hpp +++ b/include/villas/nodes/iec61850_goose.hpp @@ -233,7 +233,7 @@ protected: int _write(struct Sample *smps[], unsigned cnt) override; public: - GooseNode(const std::string &name = ""); + GooseNode(const uuid_t &id = {}, const std::string &name = ""); virtual ~GooseNode() override; @@ -242,7 +242,7 @@ public: std::vector getPollFDs() override; virtual - int parse(json_t *json, const uuid_t sn_uuid) override; + int parse(json_t *json) override; virtual int prepare() override; diff --git a/include/villas/nodes/loopback.hpp b/include/villas/nodes/loopback.hpp index 9322b11ce..2395b8aad 100644 --- a/include/villas/nodes/loopback.hpp +++ b/include/villas/nodes/loopback.hpp @@ -29,7 +29,7 @@ protected: int _read(struct Sample * smps[], unsigned cnt); public: - LoopbackNode(const std::string &name = ""); + LoopbackNode(const uuid_t &id = {}, const std::string &name = ""); virtual ~LoopbackNode(); diff --git a/include/villas/nodes/loopback_internal.hpp b/include/villas/nodes/loopback_internal.hpp index d270801d4..cecf511c7 100644 --- a/include/villas/nodes/loopback_internal.hpp +++ b/include/villas/nodes/loopback_internal.hpp @@ -47,7 +47,7 @@ public: using NodeFactory::NodeFactory; virtual - Node * make() + Node * make(const uuid_t &id = {}, const std::string &name = "") { return nullptr; } diff --git a/include/villas/nodes/signal.hpp b/include/villas/nodes/signal.hpp index f1c437157..222be861a 100644 --- a/include/villas/nodes/signal.hpp +++ b/include/villas/nodes/signal.hpp @@ -82,13 +82,13 @@ protected: int _read(struct Sample *smps[], unsigned cnt); public: - SignalNode(const std::string &name = ""); + SignalNode(const uuid_t &id = {}, const std::string &name = ""); virtual const std::string & getDetails(); virtual - int parse(json_t *json, const uuid_t sn_uuid); + int parse(json_t *json); virtual int start(); diff --git a/include/villas/nodes/webrtc.hpp b/include/villas/nodes/webrtc.hpp index 5fb306418..8f33b411f 100644 --- a/include/villas/nodes/webrtc.hpp +++ b/include/villas/nodes/webrtc.hpp @@ -48,7 +48,7 @@ protected: int _write(struct Sample *smps[], unsigned cnt); public: - WebRTCNode(const std::string &name = ""); + WebRTCNode(const uuid_t &id = {}, const std::string &name = ""); virtual ~WebRTCNode(); @@ -57,7 +57,7 @@ public: int prepare(); virtual - int parse(json_t *json, const uuid_t sn_uuid); + int parse(json_t *json); virtual int check(); @@ -82,9 +82,9 @@ public: using NodeFactory::NodeFactory; virtual - Node * make() + Node * make(const uuid_t &id = {}, const std::string &nme = "") { - auto *n = new WebRTCNode(); + auto *n = new WebRTCNode(id, nme); init(n); diff --git a/lib/node.cpp b/lib/node.cpp index 530210a24..c1a1d7429 100644 --- a/lib/node.cpp +++ b/lib/node.cpp @@ -41,7 +41,7 @@ using namespace villas; using namespace villas::node; using namespace villas::utils; -Node::Node(const std::string &n) : +Node::Node(const uuid_t &id, const std::string &name) : logger(logging.get("node")), sequence_init(0), sequence(0), @@ -57,14 +57,23 @@ Node::Node(const std::string &n) : state(State::INITIALIZED), enabled(true), config(nullptr), - name_short(n), - name_long(), + name_short(name), affinity(-1), /* all cores */ factory(nullptr) { - uuid_clear(uuid); + if (uuid_is_null(id)) { + uuid_generate_random(uuid); + } else { + uuid_copy(uuid, id); + } - name_long = fmt::format(CLR_RED("{}"), n); + if (!name_short.empty()) { + name_long = fmt::format(CLR_RED("{}"), name_short); + } + else if (name_short.empty()) { + name_short = ""; + name_long = CLR_RED(""); + } } Node::~Node() @@ -94,7 +103,7 @@ int Node::prepare() return 0; } -int Node::parse(json_t *json, const uuid_t sn_uuid) +int Node::parse(json_t *json) { assert(state == State::INITIALIZED || state == State::PARSED || @@ -105,12 +114,7 @@ int Node::parse(json_t *json, const uuid_t sn_uuid) json_error_t err; 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, s?: i }", - "name", &name_str, - "uuid", &uuid_str, + ret = json_unpack_ex(json, &err, 0, "{ s?: b, s?: i }", "enabled", &en, "initial_sequenceno", &init_seq ); @@ -120,9 +124,6 @@ int Node::parse(json_t *json, const uuid_t sn_uuid) if (init_seq >= 0) sequence_init = init_seq; - if (name_str) - logger = logging.get(fmt::format("node:{}", name_str)); - #ifdef __linux__ ret = json_unpack_ex(json, &err, 0, "{ s?: { s?: o, s?: i } }", "out", @@ -135,24 +136,6 @@ int Node::parse(json_t *json, const uuid_t sn_uuid) enabled = en; - if (name_str) { - name_short = std::string(name_str); - name_long = fmt::format(CLR_RED("{}") "(" CLR_YEL("{}") ")", name_str, factory->getName()); - } - else if (name_short.empty()) { - name_short = ""; - name_long = CLR_RED(""); - } - - if (uuid_str) { - ret = uuid_parse(uuid_str, 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::generateFromJson(uuid, json, sn_uuid); - if (json_netem) { #ifdef WITH_NETEM int enabled = 1; @@ -184,7 +167,6 @@ int Node::parse(json_t *json, const uuid_t sn_uuid) /* Skip if direction is unused */ if (!json_dir) { json_dir = json_pack("{ s: b }", "enabled", 0); - // json_object_set_new(json, dirs[j].str, json_dir); } /* Copy missing fields from main node config to direction config */ @@ -492,45 +474,39 @@ void Node::swapSignals() { SWAP(in.signals, out.signals); } -Node * NodeFactory::make(json_t *json, uuid_t uuid) +Node * NodeFactory::make(json_t *json, const uuid_t &id, const std::string &name) { int ret; std::string type; Node *n; - if (json_is_string(json)) { - type = json_string_value(json); + if (json_is_object(json)) + throw ConfigError(json, "node-config-node", "Node configuration must be an object"); - return NodeFactory::make(type); + json_t *json_type = json_object_get(json, "type"); + + type = json_string_value(json_type); + + n = NodeFactory::make(type, id, name); + if (!n) + return nullptr; + + ret = n->parse(json); + if (ret) { + delete n; + return nullptr; } - else if (json_is_object(json)) { - json_t *json_type = json_object_get(json, "type"); - type = json_string_value(json_type); - - n = NodeFactory::make(type); - if (!n) - return nullptr; - - ret = n->parse(json, uuid); - if (ret) { - delete n; - return nullptr; - } - - return n; - } - else - throw ConfigError(json, "node-config-node", "Invalid node config"); + return n; } -Node * NodeFactory::make(const std::string &type) +Node * NodeFactory::make(const std::string &type, const uuid_t &id, const std::string &name) { NodeFactory *nf = plugin::registry->lookup(type); if (!nf) throw RuntimeError("Unknown node-type: {}", type); - return nf->make(); + return nf->make(id, name); } int NodeFactory::start(SuperNode *sn) diff --git a/lib/node_capi.cpp b/lib/node_capi.cpp index 342be2104..38f280482 100644 --- a/lib/node_capi.cpp +++ b/lib/node_capi.cpp @@ -16,13 +16,13 @@ extern "C" { using namespace villas; using namespace villas::node; -vnode * node_new(const char *json_str, const char *sn_uuid_str) +vnode * node_new(const char *id_str, const char *json_str) { json_error_t err; - uuid_t sn_uuid; - uuid_parse(sn_uuid_str, sn_uuid); + uuid_t id; + uuid_parse(id_str, id); auto *json = json_loads(json_str, 0, &err); - return (vnode *) NodeFactory::make(json, sn_uuid); + return (vnode *) NodeFactory::make(json, id); } int node_prepare(vnode *n) diff --git a/lib/node_compat.cpp b/lib/node_compat.cpp index 369458c17..d4719bc33 100644 --- a/lib/node_compat.cpp +++ b/lib/node_compat.cpp @@ -12,8 +12,8 @@ using namespace villas; using namespace villas::node; -NodeCompat::NodeCompat(struct NodeCompatType *vt) : - Node(), +NodeCompat::NodeCompat(struct NodeCompatType *vt, const uuid_t &id, const std::string &name) : + Node(id, name), _vt(vt) { _vd = new char[_vt->size]; @@ -89,9 +89,9 @@ int NodeCompat::prepare() return Node::prepare(); } -int NodeCompat::parse(json_t *json, const uuid_t sn_uuid) +int NodeCompat::parse(json_t *json) { - int ret = Node::parse(json, sn_uuid); + int ret = Node::parse(json); if (ret) return ret; @@ -270,9 +270,9 @@ const std::string & NodeCompat::getDetails() return _details; } -Node * NodeCompatFactory::make() +Node * NodeCompatFactory::make(const uuid_t &id, const std::string &name) { - auto *n = new NodeCompat(_vt); + auto *n = new NodeCompat(_vt, id, name); init(n); diff --git a/lib/nodes/api.cpp b/lib/nodes/api.cpp index cc4408870..3c2dcd379 100644 --- a/lib/nodes/api.cpp +++ b/lib/nodes/api.cpp @@ -16,8 +16,8 @@ using namespace villas; using namespace villas::node; using namespace villas::node::api::universal; -APINode::APINode(const std::string &name) : - Node(name), +APINode::APINode(const uuid_t &id, const std::string &name) : + Node(id, name), read(), write() { @@ -94,9 +94,9 @@ int APINode::_write(struct Sample *smps[], unsigned cnt) return 1; } -int APINode::parse(json_t *json, const uuid_t sn_uuid) +int APINode::parse(json_t *json) { - int ret = Node::parse(json, sn_uuid); + int ret = Node::parse(json); if (ret) return ret; diff --git a/lib/nodes/example.cpp b/lib/nodes/example.cpp index 4a4268a94..ad421e701 100644 --- a/lib/nodes/example.cpp +++ b/lib/nodes/example.cpp @@ -20,8 +20,8 @@ using namespace villas; using namespace villas::node; using namespace villas::utils; -ExampleNode::ExampleNode(const std::string &name) : - Node(name), +ExampleNode::ExampleNode(const uuid_t &id, const std::string &name) : + Node(id, name), setting1(72), setting2("something"), state1(0) @@ -40,7 +40,7 @@ int ExampleNode::prepare() return 0; } -int ExampleNode::parse(json_t *json, const uuid_t sn_uuid) +int ExampleNode::parse(json_t *json) { /* TODO: Add implementation here. The following is just an example */ diff --git a/lib/nodes/exec.cpp b/lib/nodes/exec.cpp index d5f11541b..15a33423d 100644 --- a/lib/nodes/exec.cpp +++ b/lib/nodes/exec.cpp @@ -27,9 +27,9 @@ ExecNode::~ExecNode() fclose(stream_out); } -int ExecNode::parse(json_t *json, const uuid_t sn_uuid) +int ExecNode::parse(json_t *json) { - int ret = Node::parse(json, sn_uuid); + int ret = Node::parse(json); if (ret) return ret; diff --git a/lib/nodes/fpga.cpp b/lib/nodes/fpga.cpp index 327b61e66..b83e7ce84 100644 --- a/lib/nodes/fpga.cpp +++ b/lib/nodes/fpga.cpp @@ -52,7 +52,7 @@ FpgaNode::FpgaNode(const std::string &name) : FpgaNode::~FpgaNode() { } -int FpgaNode::parse(json_t *json, const uuid_t sn_uuid) +int FpgaNode::parse(json_t *json) { int ret = Node::parse(json); if (ret) diff --git a/lib/nodes/iec60870.cpp b/lib/nodes/iec60870.cpp index 321e3b237..8c71ab4f2 100644 --- a/lib/nodes/iec60870.cpp +++ b/lib/nodes/iec60870.cpp @@ -630,8 +630,8 @@ int SlaveNode::_write(Sample *samples[], unsigned sample_count) return sample_count; } -SlaveNode::SlaveNode(const std::string &name) : - Node(name) +SlaveNode::SlaveNode(const uuid_t &id, const std::string &name) : + Node(id, name) { server.state = SlaveNode::Server::NONE; @@ -662,9 +662,9 @@ SlaveNode::~SlaveNode() destroySlave(); } -int SlaveNode::parse(json_t *json, const uuid_t sn_uuid) +int SlaveNode::parse(json_t *json) { - int ret = Node::parse(json, sn_uuid); + int ret = Node::parse(json); if (ret) return ret; diff --git a/lib/nodes/iec61850_goose.cpp b/lib/nodes/iec61850_goose.cpp index 6209064e3..40c01efec 100644 --- a/lib/nodes/iec61850_goose.cpp +++ b/lib/nodes/iec61850_goose.cpp @@ -572,8 +572,8 @@ int GooseNode::_write(Sample *samples[], unsigned sample_count) return sample_count; } -GooseNode::GooseNode(const std::string &name) : - Node(name) +GooseNode::GooseNode(const uuid_t &id, const std::string &name) : + Node(id, name) { input.state = Input::NONE; @@ -601,12 +601,12 @@ GooseNode::~GooseNode() err = pool_destroy(&input.pool); } -int GooseNode::parse(json_t *json, const uuid_t sn_uuid) +int GooseNode::parse(json_t *json) { int ret; json_error_t err; - ret = Node::parse(json, sn_uuid); + ret = Node::parse(json); if (ret) return ret; diff --git a/lib/nodes/loopback.cpp b/lib/nodes/loopback.cpp index e1467e31b..004d8b42d 100644 --- a/lib/nodes/loopback.cpp +++ b/lib/nodes/loopback.cpp @@ -18,8 +18,8 @@ using namespace villas; using namespace villas::node; using namespace villas::utils; -LoopbackNode::LoopbackNode(const std::string &name) : - Node(name), +LoopbackNode::LoopbackNode(const uuid_t &id, const std::string &name) : + Node(id, name), queuelen(DEFAULT_QUEUE_LENGTH), mode(QueueSignalledMode::AUTO) { diff --git a/lib/nodes/loopback_internal.cpp b/lib/nodes/loopback_internal.cpp index 04c261b29..6b78cb12f 100644 --- a/lib/nodes/loopback_internal.cpp +++ b/lib/nodes/loopback_internal.cpp @@ -20,14 +20,18 @@ using namespace villas::node; static InternalLoopbackNodeFactory nf; InternalLoopbackNode::InternalLoopbackNode(Node *src, unsigned id, unsigned ql) : - Node(fmt::format("{}.lo{}", src->getNameShort(), id)), queuelen(ql), source(src) { + auto name = fmt::format("{}.lo{}", src->getNameShort(), id); + + uuid_t uuid; int ret = uuid::generateFromString(uuid, fmt::format("lo{}", id), src->getUuid()); if (ret) throw RuntimeError("Failed to initialize UUID"); + Node(uuid, name); + factory = &nf; name_long = fmt::format(CLR_RED("{}") "(" CLR_YEL("{}") ")", name_short, nf.getName()); diff --git a/lib/nodes/signal.cpp b/lib/nodes/signal.cpp index 0464f067e..c2a9400d1 100644 --- a/lib/nodes/signal.cpp +++ b/lib/nodes/signal.cpp @@ -188,8 +188,8 @@ Signal::Ptr SignalNodeSignal::toSignal(Signal::Ptr tpl) const return sig; } -SignalNode::SignalNode(const std::string &name) : - Node(name), +SignalNode::SignalNode(const uuid_t &id, const std::string &name) : + Node(id, name), task(CLOCK_MONOTONIC), rt(1), rate(10), @@ -215,9 +215,9 @@ int SignalNode::prepare() return Node::prepare(); } -int SignalNode::parse(json_t *json, const uuid_t sn_uuid) +int SignalNode::parse(json_t *json) { - int r = -1, m = -1, ret = Node::parse(json, sn_uuid); + int r = -1, m = -1, ret = Node::parse(json); if (ret) return ret; diff --git a/lib/nodes/webrtc.cpp b/lib/nodes/webrtc.cpp index e35934ce0..ceed5edc1 100644 --- a/lib/nodes/webrtc.cpp +++ b/lib/nodes/webrtc.cpp @@ -23,8 +23,8 @@ using namespace villas::utils; static villas::node::Web *web; -WebRTCNode::WebRTCNode(const std::string &name) : - Node(name), +WebRTCNode::WebRTCNode(const uuid_t &id, const std::string &name) : + Node(id, name), server("https://villas.k8s.eonerc.rwth-aachen.de/ws/signaling"), wait_seconds(0), format(nullptr), @@ -42,9 +42,9 @@ WebRTCNode::~WebRTCNode() ; } -int WebRTCNode::parse(json_t *json, const uuid_t sn_uuid) +int WebRTCNode::parse(json_t *json) { - int ret = Node::parse(json, sn_uuid); + int ret = Node::parse(json); if (ret) return ret; diff --git a/lib/super_node.cpp b/lib/super_node.cpp index 605ac468c..9a946ca4b 100644 --- a/lib/super_node.cpp +++ b/lib/super_node.cpp @@ -128,34 +128,44 @@ void SuperNode::parse(json_t *root) if (!json_is_object(json_nodes)) throw ConfigError(json_nodes, "node-config-nodes", "Setting 'nodes' must be a group with node name => group mappings."); - const char *name; + const char *node_name; json_t *json_node; - json_object_foreach(json_nodes, name, json_node) { - const char *type; + json_object_foreach(json_nodes, node_name, json_node) { + uuid_t node_uuid; + const char *node_type; + const char *node_uuid_str = nullptr; - ret = Node::isValidName(name); + ret = Node::isValidName(node_name); if (!ret) - throw RuntimeError("Invalid name for node: {}", name); + throw RuntimeError("Invalid name for node: {}", node_name); - ret = json_unpack_ex(json_node, &err, 0, "{ s: s }", "type", &type); + ret = json_unpack_ex(json_node, &err, 0, "{ s: s, s?: s }", + "type", &node_type, + "uuid", &node_uuid_str + ); if (ret) - throw ConfigError(root, err, "node-config-node-type", "Failed to parse type of node '{}'", name); + throw ConfigError(root, err, "node-config-node-type", "Failed to parse type of node '{}'", node_name); - json_object_set_new(json_node, "name", json_string(name)); + if (node_uuid_str) { + ret = uuid_parse(uuid_str, uuid); + if (ret) + throw ConfigError(json_node, "node-config-node-uuid", "Failed to parse UUID: {}", uuid_str); + } + else + // Generate UUID from node name and super-node UUID + uuid::generateFromString(node_uuid, node_name, uuid); - auto *n = NodeFactory::make(type); + auto *n = NodeFactory::make(node_type, node_uuid, node_name); if (!n) throw MemoryAllocationError(); - ret = n->parse(json_node, uuid); + ret = n->parse(json_node); if (ret) { - auto config_id = fmt::format("node-config-node-{}", type); + auto config_id = fmt::format("node-config-node-{}", node_type); - throw ConfigError(json_node, config_id, "Failed to parse configuration of node '{}'", name); + throw ConfigError(json_node, config_id, "Failed to parse configuration of node '{}'", node_name); } - json_object_del(json_node, "name"); - nodes.push_back(n); } }