mininet-sample/experiments/epload.py

88 lines
2.8 KiB
Python
Raw Permalink Normal View History

2020-06-26 06:52:56 +00:00
from core.experiment import Experiment, ExperimentParameter
import os
2020-06-26 06:52:56 +00:00
class EploadParameter(ExperimentParameter):
2020-06-25 12:56:47 +00:00
TEST_DIR = "test_dir"
2020-06-26 06:52:56 +00:00
def __init__(self, experiment_parameter_filename):
super(EploadParameter, self).__init__(experiment_parameter_filename)
2020-06-25 12:56:47 +00:00
self.default_parameters.update({
TEST_DIR: "/bla/bla/bla",
})
2020-06-26 06:52:56 +00:00
class Epload(Experiment):
NAME = "epload"
2020-06-25 12:56:47 +00:00
PARAMETER_CLASS = EploadParameter
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-26 06:52:56 +00:00
def __init__(self, experiment_parameter_filename, topo, topo_config):
super(Epload, self).__init__(experiment_parameter_filename, topo, topo_config)
2020-06-25 12:56:47 +00:00
self.load_parameters()
self.ping()
2020-06-25 12:56:47 +00:00
def load_parameters(self):
2020-06-26 06:52:56 +00:00
self.test_dir = self.experiment_parameter.get(EploadParameter.TEST_DIR)
def prepare(self):
super(Epload, self).prepare()
self.topo.command_to(self.topo_config.client, "rm " + \
Epload.EPLOAD_LOG )
self.topo.command_to(self.topo_config.server, "rm " + \
Epload.SERVER_LOG )
2020-07-01 14:02:54 +00:00
def get_http_server_cmd(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
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-29 14:23:39 +00:00
" sed -i 's/@host@/" + self.topo_config.get_server_ip() + "/' " + \
"$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-29 14:23:39 +00:00
" sed -i 's/" + self.topo_config.get_server_ip() + "/@host@/' " + \
"$f; done"
print(s)
return s
def clean(self):
super(Epload, self).clean()
def run(self):
2020-07-01 14:02:54 +00:00
cmd = self.get_http_server_cmd()
self.topo.command_to(self.topo_config.server, cmd)
self.topo.command_to(self.topo_config.client, "sleep 2")
cmd = self.getSubHostCmd()
self.topo.command_to(self.topo_config.client, cmd)
cmd = self.getEploadClientCmd()
self.topo.command_to(self.topo_config.client, cmd)
cmd = self.getSubBackHostCmd()
self.topo.command_to(self.topo_config.client, cmd)
self.topo.command_to(self.topo_config.client, "sleep 2")
cmd = self.getKillHTTPCmd()
self.topo.command_to(self.topo_config.server, cmd)