diff --git a/src/mpExperience.py b/src/mpExperience.py index c688087..a014924 100644 --- a/src/mpExperience.py +++ b/src/mpExperience.py @@ -6,6 +6,7 @@ class MpExperience: NC = "nc" NONE = "none" HTTPS = "https" + EPLOAD = "epload" def __init__(self, xpParam, mpTopo, mpConfig): self.xpParam = xpParam diff --git a/src/mpExperienceEpload.py b/src/mpExperienceEpload.py new file mode 100644 index 0000000..d9841d8 --- /dev/null +++ b/src/mpExperienceEpload.py @@ -0,0 +1,92 @@ +from mpExperience import MpExperience +from mpParamXp import MpParamXp +from mpPvAt import MpPvAt +import os + +class MpExperienceEpload(MpExperience): + SERVER_LOG = "http_server.log" + EPLOAD_LOG = "epload.log" + NODE_BIN = "/usr/local/nodejs/bin/node" + EPLOAD_EMULATOR="/home/mininet/epload/epload/emulator/run.js" + PING_OUTPUT = "ping.log" + + def __init__(self, xpParamFile, mpTopo, mpConfig): + MpExperience.__init__(self, xpParamFile, mpTopo, mpConfig) + self.loadParam() + self.ping() + MpExperience.classicRun(self) + + def ping(self): + self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ + MpExperienceEpload.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 + \ + " >> " + MpExperienceEpload.PING_OUTPUT + print(s) + return s + + def loadParam(self): + self.epload_test_dir = self.xpParam.getParam(MpParamXp.EPLOADTESTDIR) + + def prepare(self): + MpExperience.prepare(self) + self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ + MpExperienceEpload.EPLOAD_LOG ) + self.mpTopo.commandTo(self.mpConfig.server, "rm " + \ + MpExperienceEpload.SERVER_LOG ) + + def getHTTPServerCmd(self): + s = "python -m SimpleHTTPServer 8123 &>" + MpExperienceEpload.SERVER_LOG + " &" + print(s) + return s + + def getKillHTTPCmd(self): + s = "ps aux | grep SimpleHTTP | head -1 | tr -s ' ' | cut -d ' ' -f 2 | xargs kill" + print(s) + return s + + def getEploadClientCmd(self): + s = MpExperienceEpload.NODE_BIN + " " + MpExperienceEpload.EPLOAD_EMULATOR + \ + " http " + \ + self.epload_test_dir + " &>" + MpExperienceEpload.EPLOAD_LOG + print(s) + return s + + def getSubHostCmd(self): + s = "for f in `ls " + self.epload_test_dir + "/*`; do " + \ + " sed -i 's/@host@/" + self.mpConfig.getServerIP() + "/' " + \ + "$f; done" + print(s) + return s + + def getSubBackHostCmd(self): + s = "for f in `ls " + self.epload_test_dir + "/*`; do " + \ + " sed -i 's/" + self.mpConfig.getServerIP() + "/@host@/' " + \ + "$f; done" + print(s) + return s + + def clean(self): + MpExperience.clean(self) + + def run(self): + cmd = self.getHTTPServerCmd() + self.mpTopo.commandTo(self.mpConfig.server, cmd) + self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") + + cmd = self.getSubHostCmd() + self.mpTopo.commandTo(self.mpConfig.client, cmd) + cmd = self.getEploadClientCmd() + self.mpTopo.commandTo(self.mpConfig.client, cmd) + cmd = self.getSubBackHostCmd() + self.mpTopo.commandTo(self.mpConfig.client, cmd) + + self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") + cmd = self.getKillHTTPCmd() + self.mpTopo.commandTo(self.mpConfig.server, cmd) diff --git a/src/mpParamXp.py b/src/mpParamXp.py index ffd9d74..6f640d9 100644 --- a/src/mpParamXp.py +++ b/src/mpParamXp.py @@ -28,6 +28,7 @@ class MpParamXp(MpParam): CHANGEPVAT = "changePvAt" HTTPSFILE = "file" # file to wget, if random : we create a file with random data called random. HTTPSRANDOMSIZE = "file_size" # if file is set to random, define the size of the random file + EPLOADTESTDIR = "epload_test_dir" # global sysctl @@ -70,6 +71,7 @@ class MpParamXp(MpParam): defaultValue[CHANGEPV] = "no" defaultValue[HTTPSFILE] = "random" defaultValue[HTTPSRANDOMSIZE] = "1024" + defaultValue[EPLOADTESTDIR] = "/bla/bla/bla" def __init__(self, paramFile): MpParam.__init__(self, paramFile) diff --git a/src/mpXpRunner.py b/src/mpXpRunner.py index 2f3f820..7ca38bf 100644 --- a/src/mpXpRunner.py +++ b/src/mpXpRunner.py @@ -9,6 +9,7 @@ from mpExperiencePing import MpExperiencePing from mpExperienceNCPV import MpExperienceNCPV from mpExperienceNC import MpExperienceNC from mpExperienceHTTPS import MpExperienceHTTPS +from mpExperienceEpload import MpExperienceEpload from mpExperienceNone import MpExperienceNone from mpExperience import MpExperience from mpECMPSingleInterfaceTopo import MpECMPSingleInterfaceTopo @@ -79,6 +80,9 @@ class MpXpRunner: elif xp == MpExperience.HTTPS: MpExperienceHTTPS(self.xpParam, self.mpTopo, self.mpTopoConfig) + elif xp == MpExperience.EPLOAD: + MpExperienceEpload(self.xpParam, self.mpTopo, + self.mpTopoConfig) else: print("Unfound xp type..." + xp)