tabulations to spaces

This commit is contained in:
Quentin De Coninck 2020-06-24 12:19:05 +02:00
parent dffae6d281
commit ac52cf7ddf

View File

@ -4,14 +4,14 @@ import math
class NetemAt(object): class NetemAt(object):
def __init__(self, at, cmd): def __init__(self, at, cmd):
self.at = at self.at = at
self.cmd = cmd self.cmd = cmd
self.delta = 0 self.delta = 0
def __str__(self): def __str__(self):
return "Netem... at " + str(self.at) + "(" + str(self.delta) + \ return "Netem... at " + str(self.at) + "(" + str(self.delta) + \
") will be " + self.cmd ") will be " + self.cmd
class LinkCharacteristics(object): class LinkCharacteristics(object):
@ -115,149 +115,149 @@ class LinkCharacteristics(object):
class TopoParameter(Parameter): class TopoParameter(Parameter):
LSUBNET = "leftSubnet" LSUBNET = "leftSubnet"
RSUBNET = "rightSubnet" RSUBNET = "rightSubnet"
netemAt = "netemAt_" netemAt = "netemAt_"
changeNetem = "changeNetem" changeNetem = "changeNetem"
defaultValue = {} defaultValue = {}
defaultValue[LSUBNET] = "10.1." defaultValue[LSUBNET] = "10.1."
defaultValue[RSUBNET] = "10.2." defaultValue[RSUBNET] = "10.2."
defaultValue[changeNetem] = "false" defaultValue[changeNetem] = "false"
def __init__(self, paramFile): def __init__(self, paramFile):
Parameter.__init__(self, paramFile) Parameter.__init__(self, paramFile)
self.linkCharacteristics = [] self.linkCharacteristics = []
self.loadLinkCharacteristics() self.loadLinkCharacteristics()
self.loadNetemAt() self.loadNetemAt()
print(self.__str__()) print(self.__str__())
def loadNetemAt(self): def loadNetemAt(self):
if not self.getParam(TopoParameter.changeNetem) == "yes": if not self.getParam(TopoParameter.changeNetem) == "yes":
return return
for k in sorted(self.paramDic): for k in sorted(self.paramDic):
if k.startswith(TopoParameter.netemAt): if k.startswith(TopoParameter.netemAt):
i = int(k[len(TopoParameter.netemAt):]) i = int(k[len(TopoParameter.netemAt):])
val = self.paramDic[k] val = self.paramDic[k]
if not isinstance(val, list): if not isinstance(val, list):
tmp = val tmp = val
val = [] val = []
val.append(tmp) val.append(tmp)
self.loadNetemAtList(i, val) self.loadNetemAtList(i, val)
def loadNetemAtList(self, id, nlist): def loadNetemAtList(self, id, nlist):
for n in nlist: for n in nlist:
tab = n.split(",") tab = n.split(",")
if len(tab)==2: if len(tab)==2:
o = NetemAt(float(tab[0]), tab[1]) o = NetemAt(float(tab[0]), tab[1])
if id < len(self.linkCharacteristics): if id < len(self.linkCharacteristics):
self.linkCharacteristics[id].addNetemAt(o) self.linkCharacteristics[id].addNetemAt(o)
else: else:
print("Error can't set netem for link " + str(id)) print("Error can't set netem for link " + str(id))
else: else:
print("Netem wrong line : " + n) print("Netem wrong line : " + n)
print(self.linkCharacteristics[id].netemAt) print(self.linkCharacteristics[id].netemAt)
def loadLinkCharacteristics(self): def loadLinkCharacteristics(self):
i = 0 i = 0
for k in sorted(self.paramDic): for k in sorted(self.paramDic):
if k.startswith("path"): if k.startswith("path"):
tab = self.paramDic[k].split(",") tab = self.paramDic[k].split(",")
bup = False bup = False
loss = "0.0" loss = "0.0"
if len(tab) == 5: if len(tab) == 5:
loss = tab[3] loss = tab[3]
bup = tab[4] == 'True' bup = tab[4] == 'True'
if len(tab) == 4: if len(tab) == 4:
try: try:
loss = float(tab[3]) loss = float(tab[3])
loss = tab[3] loss = tab[3]
except ValueError: except ValueError:
bup = tab[3] == 'True' bup = tab[3] == 'True'
if len(tab) == 3 or len(tab) == 4 or len(tab) == 5: if len(tab) == 3 or len(tab) == 4 or len(tab) == 5:
path = LinkCharacteristics(i,tab[0], path = LinkCharacteristics(i,tab[0],
tab[1], tab[2], loss, bup) tab[1], tab[2], loss, bup)
self.linkCharacteristics.append(path) self.linkCharacteristics.append(path)
i = i + 1 i = i + 1
else: else:
print("Ignored path :") print("Ignored path :")
print(self.paramDic[k]) print(self.paramDic[k])
def getParam(self, key): def getParam(self, key):
val = Parameter.getParam(self, key) val = Parameter.getParam(self, key)
if val is None: if val is None:
if key in TopoParameter.defaultValue: if key in TopoParameter.defaultValue:
return TopoParameter.defaultValue[key] return TopoParameter.defaultValue[key]
else: else:
raise Exception("Param not found " + key) raise Exception("Param not found " + key)
else: else:
return val return val
def __str__(self): def __str__(self):
s = Parameter.__str__(self) s = Parameter.__str__(self)
s = s + "\n" s = s + "\n"
for p in self.linkCharacteristics[:-1]: for p in self.linkCharacteristics[:-1]:
s = s + p.__str__() + "\n" s = s + p.__str__() + "\n"
s = s + self.linkCharacteristics[-1].__str__() s = s + self.linkCharacteristics[-1].__str__()
return s return s
class Topo(object): class Topo(object):
mininetBuilder = "mininet" mininetBuilder = "mininet"
multiIfTopo = "MultiIf" multiIfTopo = "MultiIf"
ECMPLikeTopo = "ECMPLike" ECMPLikeTopo = "ECMPLike"
twoIfCongTopo = "twoIfCong" twoIfCongTopo = "twoIfCong"
multiIfCongTopo = "MultiIfCong" multiIfCongTopo = "MultiIfCong"
topoAttr = "topoType" topoAttr = "topoType"
switchNamePrefix = "s" switchNamePrefix = "s"
routerNamePrefix = "r" routerNamePrefix = "r"
clientName = "Client" clientName = "Client"
serverName = "Server" serverName = "Server"
routerName = "Router" routerName = "Router"
cmdLog = "command.log" cmdLog = "command.log"
"""Simple MpTopo""" """Simple MpTopo"""
def __init__(self, topoBuilder, topoParam): def __init__(self, topoBuilder, topoParam):
self.topoBuilder = topoBuilder self.topoBuilder = topoBuilder
self.topoParam = topoParam self.topoParam = topoParam
self.changeNetem = topoParam.getParam(TopoParameter.changeNetem) self.changeNetem = topoParam.getParam(TopoParameter.changeNetem)
self.logFile = open(Topo.cmdLog, 'w') self.logFile = open(Topo.cmdLog, 'w')
def getLinkCharacteristics(self): def getLinkCharacteristics(self):
return self.topoParam.linkCharacteristics return self.topoParam.linkCharacteristics
def commandTo(self, who, cmd): def commandTo(self, who, cmd):
self.logFile.write(who.__str__() + " : " + cmd + "\n") self.logFile.write(who.__str__() + " : " + cmd + "\n")
return self.topoBuilder.commandTo(who, cmd) return self.topoBuilder.commandTo(who, cmd)
def notNSCommand(self, cmd): def notNSCommand(self, cmd):
""" """
mainly use for not namespace sysctl. mainly use for not namespace sysctl.
""" """
self.logFile.write("Not_NS" + " : " + cmd + "\n") self.logFile.write("Not_NS" + " : " + cmd + "\n")
return self.topoBuilder.notNSCommand(cmd) return self.topoBuilder.notNSCommand(cmd)
def getHost(self, who): def getHost(self, who):
return self.topoBuilder.getHost(who) return self.topoBuilder.getHost(who)
def addHost(self, host): def addHost(self, host):
return self.topoBuilder.addHost(host) return self.topoBuilder.addHost(host)
def addSwitch(self, switch): def addSwitch(self, switch):
return self.topoBuilder.addSwitch(switch) return self.topoBuilder.addSwitch(switch)
def addLink(self, fromA, toB, **kwargs): def addLink(self, fromA, toB, **kwargs):
self.topoBuilder.addLink(fromA,toB,**kwargs) self.topoBuilder.addLink(fromA,toB,**kwargs)
def getCLI(self): def getCLI(self):
self.topoBuilder.getCLI() self.topoBuilder.getCLI()
def startNetwork(self): def startNetwork(self):
self.topoBuilder.startNetwork() self.topoBuilder.startNetwork()
def closeLogFile(self): def closeLogFile(self):
self.logFile.close() self.logFile.close()
def stopNetwork(self): def stopNetwork(self):
self.topoBuilder.stopNetwork() self.topoBuilder.stopNetwork()
class TopoConfig(object): class TopoConfig(object):