summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSteffen Vogel <post@steffenvogel.de>2017-12-20 11:09:08 +0100
committerSteffen Vogel <post@steffenvogel.de>2017-12-20 11:09:08 +0100
commitb590366ffbc759505dabe438bea18ce0c3bce515 (patch)
treefa961679d4a165f32d6b42582a2097fdcb31827a /lib
parent165611034621b0eda1a4747ea382600fed436437 (diff)
downloadlibnl-b590366ffbc759505dabe438bea18ce0c3bce515.tar.gz
route: add separate function to set netem qdisc delay distribution
A new function rtnl_netem_set_delay_distribution_data() has been added to allow the user to pass the delay distribution directly without loading it from a file. In conjunction with the maketable code (see iproute2 / NISTnet) this can be used to generate and load custom delay distributions on the fly.
Diffstat (limited to 'lib')
-rw-r--r--lib/route/qdisc/netem.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/lib/route/qdisc/netem.c b/lib/route/qdisc/netem.c
index c4ba2a1f..0df5b017 100644
--- a/lib/route/qdisc/netem.c
+++ b/lib/route/qdisc/netem.c
@@ -867,17 +867,36 @@ int rtnl_netem_get_delay_distribution(struct rtnl_qdisc *qdisc, int16_t **dist_p
}
/**
- * Set the delay distribution. Latency/jitter must be set before applying.
+ * Set the delay distribution data. Latency/jitter must be set before applying.
* @arg qdisc Netem qdisc.
- * @arg dist_type The name of the distribution (type, file, path/file).
* @return 0 on success, error code on failure.
*/
-int rtnl_netem_set_delay_distribution(struct rtnl_qdisc *qdisc, const char *dist_type) {
+int rtnl_netem_set_delay_distribution_data(struct rtnl_qdisc *qdisc, int16_t *data, size_t len) {
struct rtnl_netem *netem;
if (!(netem = rtnl_tc_data(TC_CAST(qdisc))))
BUG();
+ if (len > MAXDIST)
+ return -NLE_INVAL;
+
+ netem->qnm_dist.dist_data = (int16_t *) calloc(len, sizeof(int16_t));
+
+ memcpy(netem->qnm_dist.dist_data, data, len * sizeof(int16_t));
+
+ netem->qnm_dist.dist_size = len;
+ netem->qnm_mask |= SCH_NETEM_ATTR_DIST;
+
+ return 0;
+}
+
+/**
+ * Load the delay distribution from a file. Latency/jitter must be set before applying.
+ * @arg qdisc Netem qdisc.
+ * @arg dist_type The name of the distribution (type, file, path/file).
+ * @return 0 on success, error code on failure.
+ */
+int rtnl_netem_set_delay_distribution(struct rtnl_qdisc *qdisc, const char *dist_type) {
FILE *f;
int n = 0;
size_t i;
@@ -909,7 +928,7 @@ int rtnl_netem_set_delay_distribution(struct rtnl_qdisc *qdisc, const char *dist
if (f == NULL)
return -nl_syserr2nlerr(errno);
- netem->qnm_dist.dist_data = (int16_t *) calloc (MAXDIST, sizeof(int16_t));
+ int16_t * data = (int16_t *) calloc (MAXDIST, sizeof(int16_t));
line = (char *) calloc (sizeof(char), len + 1);
@@ -928,17 +947,14 @@ int rtnl_netem_set_delay_distribution(struct rtnl_qdisc *qdisc, const char *dist
fclose(f);
return -NLE_INVAL;
}
- netem->qnm_dist.dist_data[n++] = x;
+ data[n++] = x;
}
}
free(line);
-
- netem->qnm_dist.dist_size = n;
- netem->qnm_mask |= SCH_NETEM_ATTR_DIST;
-
fclose(f);
- return 0;
+
+ return rtnl_netem_set_delay_distribution_data(qdisc, data, n);
}
/** @} */