mininet-sample/mpExperienceEpload.py

92 lines
2.8 KiB
Python
Raw Normal View History

2020-06-24 08:36:26 +00:00
from core.experience import Experience, ExperienceParameter
from mpPvAt import MpPvAt
import os
2020-06-24 08:36:26 +00:00
class ExperienceEpload(Experience):
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):
2020-06-24 08:36:26 +00:00
Experience.__init__(self, xpParamFile, mpTopo, mpConfig)
self.loadParam()
self.ping()
2020-06-24 08:36:26 +00:00
Experience.classicRun(self)
def ping(self):
self.mpTopo.commandTo(self.mpConfig.client, "rm " + \
2020-06-24 08:36:26 +00:00
ExperienceEpload.PING_OUTPUT )
count = self.xpParam.getParam(ExperienceParameter.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 + \
2020-06-24 08:36:26 +00:00
" >> " + ExperienceEpload.PING_OUTPUT
print(s)
return s
def loadParam(self):
2020-06-24 08:36:26 +00:00
self.epload_test_dir = self.xpParam.getParam(ExperienceParameter.EPLOADTESTDIR)
def prepare(self):
2020-06-24 08:36:26 +00:00
Experience.prepare(self)
self.mpTopo.commandTo(self.mpConfig.client, "rm " + \
2020-06-24 08:36:26 +00:00
ExperienceEpload.EPLOAD_LOG )
self.mpTopo.commandTo(self.mpConfig.server, "rm " + \
2020-06-24 08:36:26 +00:00
ExperienceEpload.SERVER_LOG )
def getHTTPServerCmd(self):
2020-06-24 08:36:26 +00:00
s = "/etc/init.d/apache2 restart &>" + ExperienceEpload.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):
2020-06-24 08:36:26 +00:00
s = ExperienceEpload.NODE_BIN + " " + ExperienceEpload.EPLOAD_EMULATOR + \
" http " + \
2020-06-24 08:36:26 +00:00
self.epload_test_dir + " &>" + ExperienceEpload.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):
2020-06-24 08:36:26 +00:00
Experience.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)