From 88372ca1cdc8da9b5a26a3ba5719046ad5334e14 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 20 Dec 2017 14:56:12 +0100 Subject: [PATCH 1/4] netem: bugfix for loading correlation --- lib/kernel/tc_netem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kernel/tc_netem.c b/lib/kernel/tc_netem.c index 288a600cd..03220a24d 100644 --- a/lib/kernel/tc_netem.c +++ b/lib/kernel/tc_netem.c @@ -76,7 +76,7 @@ int tc_netem_parse(struct rtnl_qdisc **netem, json_t *cfg) if (json_delay_correlation) { val = json_integer_value(json_delay_correlation); - if (!json_is_real(json_delay_correlation)) + if (!json_is_integer(json_delay_correlation) || val < 0 || val > 100) error("Setting 'correlation' must be a positive integer within the range [ 0, 100 ]"); rtnl_netem_set_delay_correlation(ne, val); From 7ea7dad766f065857107a7bd127e42023b985a62 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 20 Dec 2017 14:56:37 +0100 Subject: [PATCH 2/4] added option for skipping built-in hooks --- include/villas/path.h | 1 + lib/path.c | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/include/villas/path.h b/include/villas/path.h index eb5d99969..c9d09b78f 100644 --- a/include/villas/path.h +++ b/include/villas/path.h @@ -91,6 +91,7 @@ struct path { double rate; /**< A timeout for */ int enabled; /**< Is this path enabled. */ int reverse; /**< This path as a matching reverse path. */ + int no_builtin; /**< This path should not use built-in hooks by default. */ int queuelen; /**< The queue length for each path_destination::queue */ int samplelen; /**< Will be calculated based on path::sources.mappings */ diff --git a/lib/path.c b/lib/path.c index f1b85c67d..20096b4aa 100644 --- a/lib/path.c +++ b/lib/path.c @@ -258,22 +258,24 @@ int path_init(struct path *p) p->queuelen = DEFAULT_QUEUELEN; /* Add internal hooks if they are not already in the list */ - for (size_t i = 0; i < list_length(&plugins); i++) { - struct plugin *q = (struct plugin *) list_at(&plugins, i); + if (!p->no_builtin) { + for (size_t i = 0; i < list_length(&plugins); i++) { + struct plugin *q = (struct plugin *) list_at(&plugins, i); - if (q->type != PLUGIN_TYPE_HOOK) - continue; + if (q->type != PLUGIN_TYPE_HOOK) + continue; - struct hook_type *vt = &q->hook; + struct hook_type *vt = &q->hook; - if ((vt->flags & HOOK_PATH) && (vt->flags & HOOK_BUILTIN)) { - struct hook *h = (struct hook *) alloc(sizeof(struct hook)); + if ((vt->flags & HOOK_PATH) && (vt->flags & HOOK_BUILTIN)) { + struct hook *h = (struct hook *) alloc(sizeof(struct hook)); - ret = hook_init(h, vt, p, NULL); - if (ret) - return ret; + ret = hook_init(h, vt, p, NULL); + if (ret) + return ret; - list_push(&p->hooks, h); + list_push(&p->hooks, h); + } } } @@ -390,12 +392,13 @@ int path_parse(struct path *p, json_t *cfg, struct list *nodes) list_init(&sources); list_init(&destinations); - ret = json_unpack_ex(cfg, &err, 0, "{ s: o, s?: o, s?: o, s?: b, s?: b, s?: i, s?: s, s?: F, s?: o }", + ret = json_unpack_ex(cfg, &err, 0, "{ s: o, s?: o, s?: o, s?: b, s?: b, s?: b, s?: i, s?: s, s?: F, s?: o }", "in", &json_in, "out", &json_out, "hooks", &json_hooks, "reverse", &p->reverse, "enabled", &p->enabled, + "no_builtin", &p->no_builtin, "queuelen", &p->queuelen, "mode", &mode, "rate", &p->rate, From 05d37fabda803470d5d201aa1b0a00362c56fc20 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 20 Dec 2017 20:49:46 +0100 Subject: [PATCH 3/4] netem: fix parsing of correlation and probability settings --- lib/kernel/tc_netem.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/kernel/tc_netem.c b/lib/kernel/tc_netem.c index 03220a24d..7c0b30c39 100644 --- a/lib/kernel/tc_netem.c +++ b/lib/kernel/tc_netem.c @@ -23,6 +23,7 @@ *********************************************************************************/ #include +#include #include @@ -33,6 +34,7 @@ #include "kernel/kernel.h" #include "utils.h" +static const double max_percent_value = 0xffffffff; int tc_netem_parse(struct rtnl_qdisc **netem, json_t *cfg) { @@ -74,11 +76,14 @@ int tc_netem_parse(struct rtnl_qdisc **netem, json_t *cfg) } if (json_delay_correlation) { - val = json_integer_value(json_delay_correlation); + double dval = json_number_value(json_delay_correlation); - if (!json_is_integer(json_delay_correlation) || val < 0 || val > 100) + if (!json_is_number(json_delay_correlation) || dval < 0 || dval > 100) error("Setting 'correlation' must be a positive integer within the range [ 0, 100 ]"); + unsigned *pval = (unsigned *) &val; + *pval = (unsigned) rint((dval / 100.) * max_percent_value); + rtnl_netem_set_delay_correlation(ne, val); } else @@ -114,29 +119,38 @@ int tc_netem_parse(struct rtnl_qdisc **netem, json_t *cfg) } if (json_loss) { - val = json_integer_value(json_loss); + double dval = json_number_value(json_loss); - if (!json_is_integer(json_loss) || val < 0 || val > 100) + if (!json_is_number(json_loss) || dval < 0 || dval > 100) error("Setting 'loss' must be a positive integer within the range [ 0, 100 ]"); + unsigned *pval = (unsigned *) &val; + *pval = (unsigned) rint((dval / 100.) * max_percent_value); + rtnl_netem_set_loss(ne, val); } if (json_duplicate) { - val = json_integer_value(json_duplicate); + double dval = json_number_value(json_duplicate); - if (!json_is_integer(json_duplicate) || val < 0 || val > 100) + if (!json_is_number(json_duplicate) || dval < 0 || dval > 100) error("Setting 'duplicate' must be a positive integer within the range [ 0, 100 ]"); + unsigned *pval = (unsigned *) &val; + *pval = (unsigned) rint((dval / 100.) * max_percent_value); + rtnl_netem_set_duplicate(ne, val); } if (json_corruption) { - val = json_integer_value(json_corruption); + double dval = json_number_value(json_corruption); - if (!json_is_integer(json_corruption) || val < 0 || val > 100) + if (!json_is_number(json_corruption) || dval < 0 || dval > 100) error("Setting 'corruption' must be a positive integer within the range [ 0, 100 ]"); + unsigned *pval = (unsigned *) &val; + *pval = (unsigned) rint((dval / 100.) * max_percent_value); + rtnl_netem_set_corruption_probability(ne, val); } From 759fb0072e64c6299b6ba45ead17540eda0acf8a Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 20 Dec 2017 20:50:24 +0100 Subject: [PATCH 4/4] node: add new option to skip loading of default hooks --- include/villas/node.h | 1 + lib/node.c | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/villas/node.h b/include/villas/node.h index 07c44694e..54ce70e81 100644 --- a/include/villas/node.h +++ b/include/villas/node.h @@ -47,6 +47,7 @@ struct node char *_name; /**< Singleton: A string used to print to screen. */ char *_name_long; /**< Singleton: A string used to print to screen. */ + int no_builtin; int vectorize; /**< Number of messages to send / recv at once (scatter / gather) */ int affinity; /**< CPU Affinity of this node */ int samplelen; /**< The maximum number of values this node can receive. */ diff --git a/lib/node.c b/lib/node.c index 2d68c1837..e529eadd4 100644 --- a/lib/node.c +++ b/lib/node.c @@ -50,6 +50,7 @@ int node_init(struct node *n, struct node_type *vt) /* Default values */ n->vectorize = 1; + n->no_builtin = 0; n->samplelen = DEFAULT_SAMPLELEN; list_push(&vt->instances, n); @@ -57,22 +58,24 @@ int node_init(struct node *n, struct node_type *vt) list_init(&n->hooks); /* Add internal hooks if they are not already in the list */ - for (size_t i = 0; i < list_length(&plugins); i++) { - struct plugin *q = (struct plugin *) list_at(&plugins, i); + if (!n->no_builtin) { + for (size_t i = 0; i < list_length(&plugins); i++) { + struct plugin *q = (struct plugin *) list_at(&plugins, i); - if (q->type != PLUGIN_TYPE_HOOK) - continue; + if (q->type != PLUGIN_TYPE_HOOK) + continue; - struct hook_type *vt = &q->hook; + struct hook_type *vt = &q->hook; - if ((vt->flags & HOOK_NODE) && (vt->flags & HOOK_BUILTIN)) { - struct hook *h = (struct hook *) alloc(sizeof(struct hook)); + if ((vt->flags & HOOK_NODE) && (vt->flags & HOOK_BUILTIN)) { + struct hook *h = (struct hook *) alloc(sizeof(struct hook)); - ret = hook_init(h, vt, NULL, n); - if (ret) - return ret; + ret = hook_init(h, vt, NULL, n); + if (ret) + return ret; - list_push(&n->hooks, h); + list_push(&n->hooks, h); + } } } @@ -101,11 +104,12 @@ int node_parse(struct node *n, json_t *cfg, const char *name) n->name = strdup(name); - ret = json_unpack_ex(cfg, &err, 0, "{ s: s, s?: i, s?: i, s?: o }", + ret = json_unpack_ex(cfg, &err, 0, "{ s: s, s?: i, s?: i, s?: o, s?: b }", "type", &type, "vectorize", &n->vectorize, "samplelen", &n->samplelen, - "hooks", &json_hooks + "hooks", &json_hooks, + "no_builtin", &n->no_builtin ); if (ret) jerror(&err, "Failed to parse node '%s'", node_name(n));