From 9e3e2b358becd31a47ff7838ad8b5ed80847ccbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Thu, 26 Dec 2019 16:56:59 +0000 Subject: [PATCH] Use the full 8bits range for loss MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- mud.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/mud.c b/mud.c index aed69e2..0cd2bcd 100644 --- a/mud.c +++ b/mud.c @@ -86,9 +86,7 @@ #define MUD_TIME_TOLERANCE ( 10 * MUD_ONE_MIN) #define MUD_TC (192) // CS6 - -#define MUD_LOSS_LIMIT (20) -#define MUD_LOSS_COUNT (1000) +#define MUD_LOSS_LIMIT (25) #define MUD_CTRL_SIZE (CMSG_SPACE(MUD_PKTINFO_SIZE) + \ CMSG_SPACE(sizeof(struct in6_pktinfo)) + \ @@ -747,12 +745,12 @@ mud_set_tc(struct mud *mud, int tc) int mud_set_loss_limit(struct mud *mud, unsigned loss) { - if (loss > 100) { + if (loss > 100U) { errno = EINVAL; return -1; } - mud->loss_limit = loss; + mud->loss_limit = loss * 255U / 100U; return 0; } @@ -1215,9 +1213,9 @@ mud_update_window(struct mud *mud, struct mud_path *path, uint64_t now, uint64_t tx_acc = path->msg.tx.acc + tx_pkt; uint64_t rx_acc = path->msg.rx.acc + rx_pkt; - if (tx_acc > MUD_LOSS_COUNT) { + if (tx_acc > 10 * MUD_LOSS_LIMIT) { if (tx_acc >= rx_acc) { - uint64_t loss = (tx_acc - rx_acc) * 100 / tx_acc; + uint64_t loss = (tx_acc - rx_acc) * 255U / tx_acc; path->tx.loss = (6 * path->tx.loss + 2 * loss) / 8; } path->msg.tx.acc = 0;