2015-01-06 14:47:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MpLinkCharacteristics:
|
2015-01-20 11:23:57 +00:00
|
|
|
|
|
|
|
tcNetemParent = "5:1"
|
|
|
|
tcNetemHandle = "10:"
|
|
|
|
|
2015-12-08 15:50:49 +00:00
|
|
|
def __init__(self, id, delay, queueSize, bandwidth, loss, back_up=False):
|
2015-01-06 14:47:15 +00:00
|
|
|
self.id = id
|
|
|
|
self.delay = delay
|
|
|
|
self.queueSize = queueSize
|
|
|
|
self.bandwidth = bandwidth
|
2015-12-08 15:50:49 +00:00
|
|
|
self.loss = loss
|
2015-01-20 10:04:36 +00:00
|
|
|
self.netemAt = []
|
2015-05-18 14:54:18 +00:00
|
|
|
self.back_up = back_up
|
2015-01-20 10:04:36 +00:00
|
|
|
|
|
|
|
def addNetemAt(self, n):
|
|
|
|
if len(self.netemAt) == 0:
|
2015-01-20 11:23:57 +00:00
|
|
|
n.delta = n.at
|
2015-01-20 10:04:36 +00:00
|
|
|
self.netemAt.append(n)
|
|
|
|
else:
|
|
|
|
if n.at > self.netemAt[-1].at:
|
|
|
|
n.delta = n.at - self.netemAt[-1].at
|
|
|
|
self.netemAt.append(n)
|
|
|
|
else:
|
|
|
|
print("Do not take into account " + n.__str__() + \
|
|
|
|
"because ooo !")
|
|
|
|
pass
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-01-20 11:23:57 +00:00
|
|
|
def buildNetemCmd(self, ifname):
|
2015-01-20 10:04:36 +00:00
|
|
|
cmd = ""
|
|
|
|
for n in self.netemAt:
|
|
|
|
cmd = cmd + "sleep " + str(n.delta)
|
|
|
|
cmd = cmd + " && "
|
2015-02-26 16:43:45 +00:00
|
|
|
cmd = cmd + " tc qdisc change dev " + ifname + " "
|
2015-01-20 11:23:57 +00:00
|
|
|
cmd = cmd + " parent " + MpLinkCharacteristics.tcNetemParent
|
|
|
|
cmd = cmd + " handle " + MpLinkCharacteristics.tcNetemHandle
|
2016-04-19 08:15:16 +00:00
|
|
|
cmd = cmd + " netem " + n.cmd + " delay " + self.delay
|
2016-04-18 13:16:44 +00:00
|
|
|
cmd = cmd + " rate " + self.bandwidth + "mbit && "
|
2015-01-20 10:04:36 +00:00
|
|
|
cmd = cmd + " true &"
|
2015-01-16 02:59:52 +00:00
|
|
|
return cmd
|
2015-01-20 10:04:36 +00:00
|
|
|
|
2015-01-07 13:44:44 +00:00
|
|
|
def asDict(self):
|
|
|
|
d = {}
|
2015-01-16 02:59:52 +00:00
|
|
|
d['bw'] = float(self.bandwidth)
|
2015-01-07 13:52:43 +00:00
|
|
|
d['delay'] = self.delay + "ms"
|
2015-12-08 15:50:49 +00:00
|
|
|
d['loss'] = float(self.loss)
|
2015-01-07 13:52:43 +00:00
|
|
|
d['max_queue_size'] = int(self.queueSize)
|
2015-01-07 13:44:44 +00:00
|
|
|
return d
|
2015-01-06 14:47:15 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
s = "Link id : " + str(self.id) + "\n"
|
|
|
|
s = s + "\tDelay : " + str(self.delay) + "\n"
|
|
|
|
s = s + "\tQueue Size : " + str(self.queueSize) + "\n"
|
2015-01-20 10:04:36 +00:00
|
|
|
s = s + "\tBandwidth : " + str(self.bandwidth) + "\n"
|
2015-12-08 15:50:49 +00:00
|
|
|
s = s + "\tLoss : " + str(self.loss) + "\n"
|
2015-05-18 14:54:18 +00:00
|
|
|
s = s + "\tBack up : " + str(self.back_up) + "\n"
|
2015-01-20 10:04:36 +00:00
|
|
|
for l in self.netemAt:
|
|
|
|
s = s + "\t" + l.__str__() + "\n"
|
2015-01-06 14:47:15 +00:00
|
|
|
return s
|