diff --git a/src/conf/topo/0_para_2 b/src/conf/topo/0_para_2 index b5f67c6..1b0d913 100644 --- a/src/conf/topo/0_para_2 +++ b/src/conf/topo/0_para_2 @@ -1,6 +1,6 @@ desc:Simple configuration with two para link -leftSubnet:xxx -rightSubnet:yyy +leftSubnet:10.0. +rightSubnet:10.1. midSubnet:zzz #path_x:delay,queueSize(may be calc),bw error diff --git a/src/conf/xp/1_ping b/src/conf/xp/1_ping new file mode 100644 index 0000000..d0fceed --- /dev/null +++ b/src/conf/xp/1_ping @@ -0,0 +1,2 @@ +xpType:ping +pingCount:10 diff --git a/src/mpConfig.py b/src/mpConfig.py index 1888324..05002f3 100644 --- a/src/mpConfig.py +++ b/src/mpConfig.py @@ -6,6 +6,9 @@ class MpConfig: self.topo = topo self.param = param + def getClientInterfaceCount(self): + raise Exception("To be implemented") + def interfaceUpCommand(self, interfaceName, ip, subnet): s = "ifconfig " + interfaceName + " " + ip + " netmask " + \ subnet diff --git a/src/mpExperience.py b/src/mpExperience.py new file mode 100644 index 0000000..75ce308 --- /dev/null +++ b/src/mpExperience.py @@ -0,0 +1,30 @@ +from mpParamXp import MpParamXp + +class MpExperience: + PING = "ping" + def __init__(self, xpParam, mpTopo, mpConfig): + self.xpParam = xpParam + self.mpTopo = mpTopo + self.mpConfig = mpConfig + print(self.xpParam) + + def classicRun(self): + self.prepare() + self.run() + self.clean() + + def prepare(self): + self.runTcpDump() + pass + + def run(self): + pass + + def clean(self): + pass + + def runTcpDump(self): + if self.xpParam.getParam(MpParamXp.CLIENTPCAP) == "yes": + print("todo : run client dump") + if self.xpParam.getParam(MpParamXp.SERVERPCAP) == "yes": + print("todo : run server dump") diff --git a/src/mpExperiencePing.py b/src/mpExperiencePing.py new file mode 100644 index 0000000..b86c4b5 --- /dev/null +++ b/src/mpExperiencePing.py @@ -0,0 +1,30 @@ +from mpExperience import MpExperience +from mpParamXp import MpParamXp + +class MpExperiencePing(MpExperience): + + PING_OUTPUT = "ping.log" + + def __init__(self, xpParamFile, mpTopo, mpConfig): + MpExperience.__init__(self, xpParamFile, mpTopo, mpConfig) + MpExperience.classicRun(self) + def prepapre(self): + MpExperience.prepare(self) + + def clean(self): + MpExperience.clean(self) + + def run(self): + self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ + MpExperiencePing.PING_OUTPUT ) + count = self.xpParam.getParam(MpParamXp.PINGCOUNT) + for i in range(0, self.mpConfig.getClientInterfaceCount()): + cmd = self.pingCommand(self.mpConfig.getClientIP(i), + self.mpConfig.getServerIP(), n = count) + self.mpTopo.commandTo(self.mpConfig.client, cmd) + + def pingCommand(self, fromIP, toIP, n=5): + s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ + " >> " + MpExperiencePing.PING_OUTPUT + print(s) + return s diff --git a/src/mpMultiInterfaceConfig.py b/src/mpMultiInterfaceConfig.py index 7c05f03..4cb89e8 100644 --- a/src/mpMultiInterfaceConfig.py +++ b/src/mpMultiInterfaceConfig.py @@ -86,6 +86,9 @@ class MpMultiInterfaceConfig(MpConfig): serverIP = rSubnet + "0.1" return serverIP + def getClientInterfaceCount(self): + return len(self.topo.switch) + def getRouterInterfaceServer(self): return self.getRouterInterfaceSwitch(len(self.topo.switch)) @@ -98,11 +101,3 @@ class MpMultiInterfaceConfig(MpConfig): def getServerInterface(self): return MpTopo.serverName + "-eth0" - def pingAllFromClient(self, n = 5): - i = 0 - self.topo.commandTo(self.client, "rm " + MpConfig.PING_OUTPUT) - for l in self.topo.switch: - cmd = self.pingCommand(self.getClientIP(i), - self.getServerIP(), n) - self.topo.commandTo(self.client, cmd) - i = i + 1 diff --git a/src/mpMultiInterfaceTopo.py b/src/mpMultiInterfaceTopo.py index c11b73d..3643b5a 100644 --- a/src/mpMultiInterfaceTopo.py +++ b/src/mpMultiInterfaceTopo.py @@ -17,7 +17,7 @@ class MpMultiInterfaceTopo(MpTopo): def addOneSwitchPerLink(self, link): return self.addSwitch(MpMultiInterfaceTopo.switchNamePrefix + str(link.id)) - + def __str__(self): s = "Simple multiple interface topolgy \n" i = 0 diff --git a/src/mpParam.py b/src/mpParam.py new file mode 100644 index 0000000..6b5dcdd --- /dev/null +++ b/src/mpParam.py @@ -0,0 +1,35 @@ + +class MpParam: + def __init__(self, paramFile): + self.paramDic = {} + print("Create the param Object") + if paramFile is None: + print("default param...") + else: + self.loadParamFile(paramFile) + + 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 getParam(self, key): + if key in self.paramDic: + return self.paramDic[key] + return None + + def __str__(self): + s = self.paramDic.__str__() + return s diff --git a/src/mpParamTopo.py b/src/mpParamTopo.py index 120d880..55143f7 100644 --- a/src/mpParamTopo.py +++ b/src/mpParamTopo.py @@ -1,7 +1,7 @@ from mpLinkCharacteristics import MpLinkCharacteristics +from mpParam import MpParam - -class MpParamTopo: +class MpParamTopo(MpParam): LSUBNET = "leftSubnet" RSUBNET = "rightSubnet" defaultValue = {} @@ -9,29 +9,10 @@ class MpParamTopo: defaultValue[RSUBNET] = "10.2." def __init__(self, paramFile): - self.paramDic = {} + MpParam.__init__(self, paramFile) 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 sorted(self.paramDic): @@ -47,15 +28,17 @@ class MpParamTopo: print(self.paramDic[k]) def getParam(self, key): - if key in self.paramDic: - return self.paramDic[key] - elif key in MpParamTopo.defaultValue: - return MpParamTopo[key] + val = MpParam.getParam(self, key) + if val is None: + if key in MpParamTopo.defaultValue: + return MpParamTopo[key] + else: + raise Exception("Param not found " + key) else: - raise Exception("Param not found " + key) + return val def __str__(self): - s = self.paramDic.__str__() + s = MpParam.__str__(self) s = s + "\n" for p in self.linkCharacteristics[:-1]: s = s + p.__str__() + "\n" diff --git a/src/mpParamXp.py b/src/mpParamXp.py new file mode 100644 index 0000000..fdf9f52 --- /dev/null +++ b/src/mpParamXp.py @@ -0,0 +1,34 @@ +from mpParam import MpParam + +class MpParamXp(MpParam): + + RMEM = "rmem" + CLIENTPCAP = "clientPcap" + SERVERPCAP = "serverPcap" + XPTYPE = "xpType" + PINGCOUNT = "pingCount" + + defaultValue = {} + + defaultValue[RMEM] = "x y z" + defaultValue[CLIENTPCAP] = "no" + defaultValue[SERVERPCAP] = "no" + defaultValue[XPTYPE] = "ping" + defaultValue[PINGCOUNT] = "5" + + def __init__(self, paramFile): + MpParam.__init__(self, paramFile) + + def getParam(self, key): + val = MpParam.getParam(self, key) + if val is None: + if key in MpParamXp.defaultValue: + return MpParamXp.defaultValue[key] + else: + raise Exception("Param not found " + key) + else: + return val + + def __str__(self): + s = MpParam.__str__(self) + return s diff --git a/src/mpTopo.py b/src/mpTopo.py index 3581ff3..4c56ba3 100644 --- a/src/mpTopo.py +++ b/src/mpTopo.py @@ -10,7 +10,7 @@ class MpTopo: """Simple MpTopo""" def __init__(self, topoBuilder, topoParam): self.topoBuilder = topoBuilder - self.topoParam = topoParam + self.topoParam = topoParam def commandTo(self, who, cmd): self.topoBuilder.commandTo(who, cmd) diff --git a/src/mpXpRunner.py b/src/mpXpRunner.py index c3f0423..4ffb207 100644 --- a/src/mpXpRunner.py +++ b/src/mpXpRunner.py @@ -1,19 +1,26 @@ from mpTopo import MpTopo from mpParamTopo import MpParamTopo +from mpParamXp import MpParamXp from mpMultiInterfaceTopo import MpMultiInterfaceTopo from mpMultiInterfaceConfig import MpMultiInterfaceConfig from mpMininetBuilder import MpMininetBuilder +from mpExperiencePing import MpExperiencePing +from mpExperience import MpExperience class MpXpRunner: def __init__(self, builderType, topoParamFile, xpParamFile): + self.defParamXp(xpParamFile) self.topoParam = MpParamTopo(topoParamFile) self.defBuilder(builderType) self.defTopo() self.defConfig() self.startTopo() - self.runXp(xpParamFile) + self.runXp() self.stopTopo() + def defParamXp(self, xpParamFile): + self.xpParam = MpParamXp(xpParamFile) + def defBuilder(self, builderType): if builderType == MpTopo.mininetBuilder: self.topoBuilder = MpMininetBuilder() @@ -37,12 +44,13 @@ class MpXpRunner: self.mpTopo.startNetwork() self.mpTopoConfig.configureNetwork() - def runXp(self, xpParamFile): - if xpParamFile is None: - self.mpTopoConfig.pingAllFromClient() - self.mpTopo.getCLI() + def runXp(self): + xp = self.xpParam.getParam(MpParamXp.XPTYPE) + if xp == MpExperience.PING: + MpExperiencePing(self.xpParam, self.mpTopo, + self.mpTopoConfig) else: - raise Exception("TODO") + print("Unfound xp type..." + xp) def stopTopo(self): self.mpTopo.stopNetwork()