2015-01-06 14:47:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MpLinkCharacteristics:
|
|
|
|
def __init__(self, id, delay, queueSize, bandwidth):
|
|
|
|
self.id = id
|
|
|
|
self.delay = delay
|
|
|
|
self.queueSize = queueSize
|
|
|
|
self.bandwidth = bandwidth
|
2015-01-20 10:04:36 +00:00
|
|
|
self.netemAt = []
|
|
|
|
|
|
|
|
def addNetemAt(self, n):
|
|
|
|
if len(self.netemAt) == 0:
|
|
|
|
n.delay = n.at
|
|
|
|
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-01-07 13:44:44 +00:00
|
|
|
|
2015-01-20 10:04:36 +00:00
|
|
|
def buildNetemCmd(self):
|
|
|
|
cmd = ""
|
|
|
|
for n in self.netemAt:
|
|
|
|
cmd = cmd + "sleep " + str(n.delta)
|
|
|
|
cmd = cmd + " && "
|
|
|
|
cmd = cmd + " echo " + n.cmd + " && "
|
|
|
|
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"
|
|
|
|
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"
|
|
|
|
for l in self.netemAt:
|
|
|
|
s = s + "\t" + l.__str__() + "\n"
|
2015-01-06 14:47:15 +00:00
|
|
|
return s
|
|
|
|
|