2015-01-06 14:47:15 +00:00
|
|
|
from mpLinkCharacteristics import MpLinkCharacteristics
|
|
|
|
|
|
|
|
|
|
|
|
class MpParamTopo:
|
2015-01-07 13:44:44 +00:00
|
|
|
LSUBNET = "leftSubnet"
|
|
|
|
RSUBNET = "rightSubnet"
|
|
|
|
defaultValue = {}
|
|
|
|
defaultValue[LSUBNET] = "10.1."
|
|
|
|
defaultValue[RSUBNET] = "10.2."
|
|
|
|
|
2015-01-06 14:47:15 +00:00
|
|
|
def __init__(self, paramFile):
|
|
|
|
self.paramDic = {}
|
|
|
|
self.linkCharacteristics = []
|
|
|
|
print("Create the param Object")
|
|
|
|
self.loadParamFile(paramFile)
|
|
|
|
self.loadLinkCharacteristics()
|
|
|
|
|
|
|
|
def loadParamFile(self, paramFile):
|
|
|
|
f = open(paramFile)
|
|
|
|
i = 0
|
|
|
|
for l in f:
|
|
|
|
i = i + 1
|
|
|
|
if l.startswith("#"):
|
|
|
|
continue
|
|
|
|
|
|
|
|
tab = l.split(":")
|
|
|
|
if len(tab) == 2:
|
|
|
|
self.paramDic[tab[0]] = tab[1][:-1]
|
|
|
|
else:
|
|
|
|
print("Ignored Line " + str(i))
|
|
|
|
print(l),
|
|
|
|
print("In file " + paramFile)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
def loadLinkCharacteristics(self):
|
|
|
|
i = 0
|
|
|
|
for k in self.paramDic:
|
|
|
|
if k.startswith("path"):
|
|
|
|
tab = self.paramDic[k].split(",")
|
|
|
|
if len(tab) == 3:
|
|
|
|
i = i + 1
|
|
|
|
path = MpLinkCharacteristics(i,tab[0],
|
|
|
|
tab[1], tab[2])
|
|
|
|
self.linkCharacteristics.append(path)
|
|
|
|
else:
|
|
|
|
print("Ignored path :")
|
|
|
|
print(self.paramDic[k])
|
|
|
|
|
|
|
|
def getParam(self, key):
|
|
|
|
if key in self.paramDic:
|
|
|
|
return self.paramDic[key]
|
2015-01-07 13:44:44 +00:00
|
|
|
elif key in MpParamTopo.defaultValue:
|
|
|
|
return MpParamTopo[key]
|
2015-01-06 14:47:15 +00:00
|
|
|
else:
|
|
|
|
raise Exception("Param not found " + key)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
s = self.paramDic.__str__()
|
|
|
|
s = s + "\n"
|
|
|
|
for p in self.linkCharacteristics[:-1]:
|
|
|
|
s = s + p.__str__() + "\n"
|
|
|
|
s = s + self.linkCharacteristics[-1].__str__()
|
|
|
|
return s
|