2015-01-06 14:47:15 +00:00
|
|
|
from mpLinkCharacteristics import MpLinkCharacteristics
|
2015-01-08 18:52:45 +00:00
|
|
|
from mpParam import MpParam
|
2015-01-20 10:04:36 +00:00
|
|
|
from mpNetemAt import MpNetemAt
|
2015-01-06 14:47:15 +00:00
|
|
|
|
2015-01-08 18:52:45 +00:00
|
|
|
class MpParamTopo(MpParam):
|
2015-01-07 13:44:44 +00:00
|
|
|
LSUBNET = "leftSubnet"
|
|
|
|
RSUBNET = "rightSubnet"
|
2015-01-20 10:04:36 +00:00
|
|
|
netemAt = "netemAt_"
|
|
|
|
changeNetem = "changeNetem"
|
2015-01-07 13:44:44 +00:00
|
|
|
defaultValue = {}
|
|
|
|
defaultValue[LSUBNET] = "10.1."
|
|
|
|
defaultValue[RSUBNET] = "10.2."
|
2015-01-20 10:04:36 +00:00
|
|
|
defaultValue[changeNetem] = "false"
|
2015-01-07 13:44:44 +00:00
|
|
|
|
2015-01-06 14:47:15 +00:00
|
|
|
def __init__(self, paramFile):
|
2015-01-08 18:52:45 +00:00
|
|
|
MpParam.__init__(self, paramFile)
|
2015-01-06 14:47:15 +00:00
|
|
|
self.linkCharacteristics = []
|
|
|
|
self.loadLinkCharacteristics()
|
2015-01-20 10:04:36 +00:00
|
|
|
self.loadNetemAt()
|
|
|
|
print(self.__str__())
|
|
|
|
|
|
|
|
def loadNetemAt(self):
|
|
|
|
if not self.getParam(MpParamTopo.changeNetem) == "yes":
|
|
|
|
return
|
|
|
|
for k in sorted(self.paramDic):
|
|
|
|
if k.startswith(MpParamTopo.netemAt):
|
|
|
|
i = int(k[len(MpParamTopo.netemAt):])
|
|
|
|
val = self.paramDic[k]
|
|
|
|
if not isinstance(val, list):
|
2015-01-20 18:49:34 +00:00
|
|
|
tmp = val
|
|
|
|
val = []
|
|
|
|
val.append(tmp)
|
2015-01-20 10:04:36 +00:00
|
|
|
self.loadNetemAtList(i, val)
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-01-20 10:04:36 +00:00
|
|
|
def loadNetemAtList(self, id, nlist):
|
|
|
|
for n in nlist:
|
|
|
|
tab = n.split(",")
|
|
|
|
if len(tab)==2:
|
|
|
|
o = MpNetemAt(float(tab[0]), tab[1])
|
|
|
|
if id < len(self.linkCharacteristics):
|
|
|
|
self.linkCharacteristics[id].addNetemAt(o)
|
|
|
|
else:
|
|
|
|
print("Error can't set netem for link " + str(id))
|
|
|
|
else:
|
|
|
|
print("Netem wrong line : " + n)
|
|
|
|
print(self.linkCharacteristics[id].netemAt)
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-01-06 14:47:15 +00:00
|
|
|
def loadLinkCharacteristics(self):
|
2015-02-26 16:43:45 +00:00
|
|
|
i = 0
|
2015-01-07 15:00:15 +00:00
|
|
|
for k in sorted(self.paramDic):
|
2015-01-06 14:47:15 +00:00
|
|
|
if k.startswith("path"):
|
|
|
|
tab = self.paramDic[k].split(",")
|
2015-05-18 14:54:18 +00:00
|
|
|
bup = False
|
2015-12-08 15:50:49 +00:00
|
|
|
loss = "0.0"
|
|
|
|
if len(tab) == 5:
|
|
|
|
loss = tab[3]
|
|
|
|
bup = tab[4] == 'True'
|
2015-05-18 14:54:18 +00:00
|
|
|
if len(tab) == 4:
|
2015-12-08 15:50:49 +00:00
|
|
|
try:
|
|
|
|
loss = float(tab[3])
|
|
|
|
loss = tab[3]
|
|
|
|
except ValueError:
|
|
|
|
bup = tab[3] == 'True'
|
|
|
|
if len(tab) == 3 or len(tab) == 4 or len(tab) == 5:
|
2015-01-06 14:47:15 +00:00
|
|
|
path = MpLinkCharacteristics(i,tab[0],
|
2015-12-08 15:50:49 +00:00
|
|
|
tab[1], tab[2], loss, bup)
|
2015-01-06 14:47:15 +00:00
|
|
|
self.linkCharacteristics.append(path)
|
2015-01-12 11:26:54 +00:00
|
|
|
i = i + 1
|
2015-01-06 14:47:15 +00:00
|
|
|
else:
|
|
|
|
print("Ignored path :")
|
|
|
|
print(self.paramDic[k])
|
|
|
|
|
|
|
|
def getParam(self, key):
|
2015-01-08 18:52:45 +00:00
|
|
|
val = MpParam.getParam(self, key)
|
|
|
|
if val is None:
|
|
|
|
if key in MpParamTopo.defaultValue:
|
2015-01-20 10:04:36 +00:00
|
|
|
return MpParamTopo.defaultValue[key]
|
2015-01-08 18:52:45 +00:00
|
|
|
else:
|
|
|
|
raise Exception("Param not found " + key)
|
2015-01-06 14:47:15 +00:00
|
|
|
else:
|
2015-01-08 18:52:45 +00:00
|
|
|
return val
|
2015-01-06 14:47:15 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2015-01-08 18:52:45 +00:00
|
|
|
s = MpParam.__str__(self)
|
2015-01-06 14:47:15 +00:00
|
|
|
s = s + "\n"
|
|
|
|
for p in self.linkCharacteristics[:-1]:
|
|
|
|
s = s + p.__str__() + "\n"
|
|
|
|
s = s + self.linkCharacteristics[-1].__str__()
|
|
|
|
return s
|