mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00
node: parse UUID from config or generate one based on config hash
This commit is contained in:
parent
a15850c87c
commit
6761ee21cc
3 changed files with 27 additions and 4 deletions
|
@ -31,6 +31,7 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
|
#include <uuid/uuid.h>
|
||||||
|
|
||||||
#include <villas/node_type.h>
|
#include <villas/node_type.h>
|
||||||
#include <villas/node_direction.h>
|
#include <villas/node_direction.h>
|
||||||
|
@ -64,6 +65,8 @@ struct node {
|
||||||
char *_name; /**< Singleton: A string used to print to screen. */
|
char *_name; /**< Singleton: A string used to print to screen. */
|
||||||
char *_name_long; /**< Singleton: A string used to print to screen. */
|
char *_name_long; /**< Singleton: A string used to print to screen. */
|
||||||
|
|
||||||
|
uuid_t uuid;
|
||||||
|
|
||||||
int affinity; /**< CPU Affinity of this node */
|
int affinity; /**< CPU Affinity of this node */
|
||||||
|
|
||||||
uint64_t sequence; /**< This is a counter of received samples, in case the node-type does not generate sequence numbers itself. */
|
uint64_t sequence; /**< This is a counter of received samples, in case the node-type does not generate sequence numbers itself. */
|
||||||
|
|
|
@ -30,6 +30,7 @@ list(APPEND INCLUDE_DIRS
|
||||||
|
|
||||||
set(LIBRARIES
|
set(LIBRARIES
|
||||||
PkgConfig::JANSSON
|
PkgConfig::JANSSON
|
||||||
|
PkgConfig::UUID
|
||||||
villas-common
|
villas-common
|
||||||
m
|
m
|
||||||
stdc++
|
stdc++
|
||||||
|
|
27
lib/node.cpp
27
lib/node.cpp
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <openssl/md5.h>
|
||||||
|
|
||||||
#include <villas/node/config.h>
|
#include <villas/node/config.h>
|
||||||
#include <villas/hook.hpp>
|
#include <villas/hook.hpp>
|
||||||
|
@ -120,12 +121,13 @@ int node_parse(struct node *n, json_t *json, const char *name)
|
||||||
json_error_t err;
|
json_error_t err;
|
||||||
json_t *json_netem = nullptr;
|
json_t *json_netem = nullptr;
|
||||||
|
|
||||||
const char *type;
|
const char *type, *uuid = nullptr;
|
||||||
|
|
||||||
n->name = strdup(name);
|
n->name = strdup(name);
|
||||||
|
|
||||||
ret = json_unpack_ex(json, &err, 0, "{ s: s, s?: b }",
|
ret = json_unpack_ex(json, &err, 0, "{ s: s, s?: s, s?: b }",
|
||||||
"type", &type,
|
"type", &type,
|
||||||
|
"uuid", &uuid,
|
||||||
"enabled", &n->enabled
|
"enabled", &n->enabled
|
||||||
);
|
);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
@ -146,6 +148,20 @@ int node_parse(struct node *n, json_t *json, const char *name)
|
||||||
|
|
||||||
n->_vt = nt;
|
n->_vt = nt;
|
||||||
|
|
||||||
|
if (uuid) {
|
||||||
|
ret = uuid_parse(uuid, n->uuid);
|
||||||
|
if (ret)
|
||||||
|
throw ConfigError(json, "node-config-node-uuid", "Failed to parse UUID: {}", uuid);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* Generate UUID from hashed config */
|
||||||
|
char *json_str = json_dumps(json, JSON_COMPACT | JSON_SORT_KEYS);
|
||||||
|
|
||||||
|
MD5((unsigned char*) json_str, strlen(json_str), (unsigned char*) &n->uuid);
|
||||||
|
|
||||||
|
free(json_str);
|
||||||
|
}
|
||||||
|
|
||||||
if (json_netem) {
|
if (json_netem) {
|
||||||
#ifdef WITH_NETEM
|
#ifdef WITH_NETEM
|
||||||
int enabled = 1;
|
int enabled = 1;
|
||||||
|
@ -496,8 +512,11 @@ char * node_name_long(struct node *n)
|
||||||
if (node_type(n)->print) {
|
if (node_type(n)->print) {
|
||||||
struct node_type *vt = node_type(n);
|
struct node_type *vt = node_type(n);
|
||||||
|
|
||||||
strcatf(&n->_name_long, "%s: #in.signals=%zu, #out.signals=%zu, #in.hooks=%zu, #out.hooks=%zu, in.vectorize=%d, out.vectorize=%d",
|
char uuid[37];
|
||||||
node_name(n),
|
uuid_unparse(n->uuid, uuid);
|
||||||
|
|
||||||
|
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.signals), vlist_length(&n->out.signals),
|
||||||
vlist_length(&n->in.hooks), vlist_length(&n->out.hooks),
|
vlist_length(&n->in.hooks), vlist_length(&n->out.hooks),
|
||||||
n->in.vectorize, n->out.vectorize
|
n->in.vectorize, n->out.vectorize
|
||||||
|
|
Loading…
Add table
Reference in a new issue