From c2436d574a52eb13e7443b494a85beb1b5e573c3 Mon Sep 17 00:00:00 2001 From: Quentin De Coninck Date: Sat, 4 Jun 2016 14:15:57 +0200 Subject: [PATCH] mpLinkCharacteristics: use tbf + mpExperienceIperf: pkill fix --- src/mpExperienceIperf.py | 1 - src/mpLinkCharacteristics.py | 28 ++++++++++++++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/mpExperienceIperf.py b/src/mpExperienceIperf.py index 1044853..890a7ce 100644 --- a/src/mpExperienceIperf.py +++ b/src/mpExperienceIperf.py @@ -68,5 +68,4 @@ class MpExperienceIperf(MpExperience): self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") cmd = self.getClientCmd() self.mpTopo.commandTo(self.mpConfig.client, cmd) - self.mpTopo.commandTo(self.mpConfig.server, "pkill -9 -f iperf") self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") diff --git a/src/mpLinkCharacteristics.py b/src/mpLinkCharacteristics.py index 5b23071..27fdee2 100644 --- a/src/mpLinkCharacteristics.py +++ b/src/mpLinkCharacteristics.py @@ -1,4 +1,4 @@ - +import math class MpLinkCharacteristics: @@ -7,12 +7,19 @@ class MpLinkCharacteristics: tcHtbClassid = "10" tcNetemHandle = "1:10" + def bandwidthDelayProductDividedByMTU(self): + rtt = 2 * float(self.delay) + """ Since bandwidth is in Mbps and rtt in ms """ + bandwidthDelayProduct = (float(self.bandwidth) * 125000.0) * (rtt / 1000.0) + return int(math.ceil(bandwidthDelayProduct * 1.0 / 1500.0)) + def __init__(self, id, delay, queueSize, bandwidth, loss, back_up=False): self.id = id self.delay = delay self.queueSize = queueSize self.bandwidth = bandwidth self.loss = loss + self.queuingDelay = str(int(1000.0 * int(queueSize) / self.bandwidthDelayProductDividedByMTU())) self.netemAt = [] self.back_up = back_up @@ -33,20 +40,13 @@ class MpLinkCharacteristics: cmd = "" for n in self.netemAt: cmd = cmd + "sleep " + str(n.delta) - cmd = cmd + " && (( tc qdisc del dev " + ifname + " root " - cmd = cmd + " && tc qdisc add dev " + ifname + " root handle 1: htb default 10 direct_qlen " + self.queueSize + " && tc class add dev " + ifname + " " - cmd = cmd + " parent 1:1 " - cmd = cmd + " classid " + MpLinkCharacteristics.tcHtbClassid - cmd = cmd + " htb rate " + self.bandwidth + "mbit" - cmd = cmd + " burst " + str(int(self.queueSize) * 1500) + ") || " - cmd = cmd + " tc class change dev " + ifname + " " - cmd = cmd + " parent " + MpLinkCharacteristics.tcNetemParent - cmd = cmd + " classid " + MpLinkCharacteristics.tcHtbClassid - cmd = cmd + " htb rate " + self.bandwidth + "mbit" - cmd = cmd + " burst " + str(int(self.queueSize) * 1500) + ") && " + cmd = cmd + " && tc qdisc del dev " + ifname + " root " + cmd = cmd + " && tc qdisc add dev " + ifname + " root handle 1:0 tbf rate " + self.bandwidth + cmd = cmd + "mbit burst " + str(int(self.queueSize) * 1500) + " latency " + self.queuingDelay + cmd = cmd + "ms && " cmd = cmd + " tc qdisc add dev " + ifname + " " - cmd = cmd + " parent " + MpLinkCharacteristics.tcNetemHandle - cmd = cmd + " netem " + n.cmd + " delay " + self.delay + "ms limit " + self.queueSize + " && " + cmd = cmd + " parent 1:0 handle 10: " + cmd = cmd + " netem " + n.cmd + " delay " + self.delay + "ms && " cmd = cmd + " true &" return cmd