From 3b0cca73e3cd5469755629730d82bc70796e16a5 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 21 Jan 2019 13:10:55 +0100 Subject: [PATCH] rtp: added initial implementation for AIMD --- etc/rtp.conf | 7 +++++++ include/villas/nodes/rtp.h | 3 +++ lib/nodes/rtp.c | 32 ++++++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/etc/rtp.conf b/etc/rtp.conf index e259d7f31..1c111d58e 100644 --- a/etc/rtp.conf +++ b/etc/rtp.conf @@ -2,6 +2,8 @@ nodes = { rtp_node = { type = "rtp" + rate = 10000, + rtcp = { enabled = true, @@ -9,6 +11,11 @@ nodes = { throttle_mode = "decimate" } + aimd = { + a = 10, + b = 0.5 + } + in = { address = "0.0.0.0:12000", signals = { diff --git a/include/villas/nodes/rtp.h b/include/villas/nodes/rtp.h index f7f634a5f..be2cade7a 100644 --- a/include/villas/nodes/rtp.h +++ b/include/villas/nodes/rtp.h @@ -77,7 +77,10 @@ struct rtp { } rtcp; struct { + double a; + double b; + double last_rate; } aimd; /** AIMD state */ struct queue_signalled recv_queue; diff --git a/lib/nodes/rtp.c b/lib/nodes/rtp.c index 6c9ae89c2..28610edd8 100644 --- a/lib/nodes/rtp.c +++ b/lib/nodes/rtp.c @@ -68,11 +68,17 @@ static int rtp_set_rate(struct node *n, double rate) static int rtp_aimd(struct node *n, double loss_frac) { + struct rtp *r = (struct rtp *) n->_vd; + int ret; double rate; - /** @todo: Implement AIMD */ - rate = 1; + if (loss_frac < 1e-3) + rate = r->aimd.last_rate + r->aimd.a; + else + rate = r->aimd.last_rate * r->aimd.b; + + r->aimd.last_rate = rate; ret = rtp_set_rate(n, rate); if (ret) @@ -107,12 +113,18 @@ int rtp_parse(struct node *n, json_t *cfg) uint16_t port; json_error_t err; - json_t *json_rtcp = NULL; + json_t *json_rtcp = NULL, *json_aimd = NULL; - ret = json_unpack_ex(cfg, &err, 0, "{ s?: s, s?: o, s: { s: s }, s: { s: s } }", + /* Default values */ + r->aimd.a = 10; + r->aimd.b = 0.5; + r->aimd.last_rate = 1; + + ret = json_unpack_ex(cfg, &err, 0, "{ s?: s, s?: o, s?: o, s: { s: s }, s: { s: s } }", "format", &format, "rate", &r->rate, "rtcp", &json_rtcp, + "aimd", &json_aimd, "out", "address", &remote, "in", @@ -121,6 +133,16 @@ int rtp_parse(struct node *n, json_t *cfg) if (ret) jerror(&err, "Failed to parse configuration of node %s", node_name(n)); + /* AIMD */ + if (json_aimd) { + ret = json_unpack_ex(json_rtcp, &err, 0, "{ s?: f, s?: f }", + "a", &r->aimd.a, + "b", &r->aimd.b + ); + if (ret) + jerror(&err, "Failed to parse configuration of node %s", node_name(n)); + } + /* RTCP */ if (json_rtcp) { const char *mode = "aimd"; @@ -131,6 +153,8 @@ int rtp_parse(struct node *n, json_t *cfg) "mode", &mode, "throttle_mode", &throttle_mode ); + if (ret) + jerror(&err, "Failed to parse configuration of node %s", node_name(n)); /* RTCP Mode */ if (!strcmp(mode, "aimd"))