2020-06-24 15:18:40 +00:00
|
|
|
from core.experience import Experience, ExperienceParameter
|
|
|
|
import os
|
|
|
|
|
2020-06-25 12:56:47 +00:00
|
|
|
class EploadParameter(ExperienceParameter):
|
|
|
|
TEST_DIR = "test_dir"
|
|
|
|
|
|
|
|
def __init__(self, experience_parameter_filename):
|
|
|
|
super(EploadParameter, self).__init__(experience_parameter_filename)
|
|
|
|
self.default_parameters.update({
|
|
|
|
TEST_DIR: "/bla/bla/bla",
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2020-06-24 15:18:40 +00:00
|
|
|
class Epload(Experience):
|
|
|
|
NAME = "epload"
|
2020-06-25 12:56:47 +00:00
|
|
|
PARAMETER_CLASS = EploadParameter
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
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"
|
|
|
|
|
2020-06-25 12:56:47 +00:00
|
|
|
def __init__(self, experience_parameter_filename, topo, topo_config):
|
|
|
|
super(Epload, self).__init__(experience_parameter_filename, topo, topo_config)
|
|
|
|
self.load_parameters()
|
2020-06-24 15:18:40 +00:00
|
|
|
self.ping()
|
2020-06-25 08:53:56 +00:00
|
|
|
super(Epload, self).classic_run()
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
def ping(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, "rm " + \
|
2020-06-24 15:18:40 +00:00
|
|
|
Epload.PING_OUTPUT )
|
2020-06-25 08:53:56 +00:00
|
|
|
count = self.experience_parameter.get(ExperienceParameter.PINGCOUNT)
|
|
|
|
for i in range(0, self.topo_config.getClientInterfaceCount()):
|
|
|
|
cmd = self.pingCommand(self.topo_config.getClientIP(i),
|
|
|
|
self.topo_config.getServerIP(), n = count)
|
|
|
|
self.topo.command_to(self.topo_config.client, cmd)
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
def pingCommand(self, fromIP, toIP, n=5):
|
|
|
|
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
|
|
|
|
" >> " + Epload.PING_OUTPUT
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
2020-06-25 12:56:47 +00:00
|
|
|
def load_parameters(self):
|
|
|
|
self.test_dir = self.experience_parameter.get(EploadParameter.TEST_DIR)
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
def prepare(self):
|
|
|
|
super(Epload, self).prepare()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, "rm " + \
|
2020-06-24 15:18:40 +00:00
|
|
|
Epload.EPLOAD_LOG )
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.server, "rm " + \
|
2020-06-24 15:18:40 +00:00
|
|
|
Epload.SERVER_LOG )
|
|
|
|
|
|
|
|
def getHTTPServerCmd(self):
|
|
|
|
s = "/etc/init.d/apache2 restart &>" + Epload.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 = Epload.NODE_BIN + " " + Epload.EPLOAD_EMULATOR + \
|
|
|
|
" http " + \
|
2020-06-25 12:56:47 +00:00
|
|
|
self.test_dir + " &>" + Epload.EPLOAD_LOG
|
2020-06-24 15:18:40 +00:00
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def getSubHostCmd(self):
|
2020-06-25 12:56:47 +00:00
|
|
|
s = "for f in `ls " + self.test_dir + "/*`; do " + \
|
2020-06-25 08:53:56 +00:00
|
|
|
" sed -i 's/@host@/" + self.topo_config.getServerIP() + "/' " + \
|
2020-06-24 15:18:40 +00:00
|
|
|
"$f; done"
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def getSubBackHostCmd(self):
|
2020-06-25 12:56:47 +00:00
|
|
|
s = "for f in `ls " + self.test_dir + "/*`; do " + \
|
2020-06-25 08:53:56 +00:00
|
|
|
" sed -i 's/" + self.topo_config.getServerIP() + "/@host@/' " + \
|
2020-06-24 15:18:40 +00:00
|
|
|
"$f; done"
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
super(Epload, self).clean()
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
cmd = self.getHTTPServerCmd()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.server, cmd)
|
|
|
|
self.topo.command_to(self.topo_config.client, "sleep 2")
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
cmd = self.getSubHostCmd()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, cmd)
|
2020-06-24 15:18:40 +00:00
|
|
|
cmd = self.getEploadClientCmd()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, cmd)
|
2020-06-24 15:18:40 +00:00
|
|
|
cmd = self.getSubBackHostCmd()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, cmd)
|
2020-06-24 15:18:40 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, "sleep 2")
|
2020-06-24 15:18:40 +00:00
|
|
|
cmd = self.getKillHTTPCmd()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.server, cmd)
|