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

netem: fix parsing of correlation and probability settings

This commit is contained in:
Steffen Vogel 2017-12-20 20:49:46 +01:00
parent 7ea7dad766
commit 05d37fabda

View file

@ -23,6 +23,7 @@
*********************************************************************************/
#include <jansson.h>
#include <math.h>
#include <netlink/route/qdisc/netem.h>
@ -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);
}