mininet-sample/experiments/ab.py

64 lines
2.2 KiB
Python
Raw Normal View History

2020-06-26 06:52:56 +00:00
from core.experiment import RandomFileExperiment, RandomFileParameter, ExperimentParameter
2020-06-24 14:11:54 +00:00
import os
2020-06-25 12:56:47 +00:00
class ABParameter(RandomFileParameter):
CONCURRENT_REQUESTS = "abConccurentRequests"
TIME_LIMIT = "abTimelimit"
2020-06-26 06:52:56 +00:00
def __init__(self, experiment_parameter_filename):
super(ABParameter, self).__init__(experiment_parameter_filename)
2020-06-25 12:56:47 +00:00
self.default_parameters.update({
ABParameter.CONCURRENT_REQUESTS: "50",
ABParameter.TIME_LIMIT: "20",
})
2020-06-26 06:52:56 +00:00
class AB(RandomFileExperiment):
2020-06-24 14:11:54 +00:00
NAME = "ab"
2020-06-25 12:56:47 +00:00
PARAMETER_CLASS = ABParameter
2020-06-24 14:11:54 +00:00
SERVER_LOG = "ab_server.log"
CLIENT_LOG = "ab_client.log"
AB_BIN = "ab"
PING_OUTPUT = "ping.log"
2020-06-26 06:52:56 +00:00
def __init__(self, experiment_parameter_filename, topo, topo_config):
super(AB, self).__init__(experiment_parameter_filename, topo, topo_config)
2020-06-24 14:11:54 +00:00
2020-06-25 12:56:47 +00:00
def load_parameters(self):
super(AB, self).load_parameters()
2020-06-26 06:52:56 +00:00
self.concurrent_requests = self.experiment_parameter.get(ABParameter.CONCURRENT_REQUESTS)
self.time_limit = self.experiment_parameter.get(ABParameter.TIME_LIMIT)
2020-06-24 14:11:54 +00:00
def prepare(self):
2020-06-25 12:56:47 +00:00
super(AB, self).prepare()
self.topo.command_to(self.topo_config.client, "rm " + \
2020-06-24 14:11:54 +00:00
AB.CLIENT_LOG )
self.topo.command_to(self.topo_config.server, "rm " + \
2020-06-24 14:11:54 +00:00
AB.SERVER_LOG )
2020-06-25 12:56:47 +00:00
def get_ab_server_cmd(self):
s = "python {}/../utils/http_server.py &> {} 2>&1 &".format(
os.path.dirname(os.path.abspath(__file__)), AB.SERVER_LOG)
2020-06-24 14:11:54 +00:00
print(s)
return s
2020-06-25 12:56:47 +00:00
def get_ab_client_cmd(self):
s = "{} -c {} -t {} http://{}/{} &> {}".format(AB.AB_BIN, self.concurrent_requests,
2020-06-29 14:23:39 +00:00
self.time_limit, self.topo_config.get_server_ip(), self.file, AB.CLIENT_LOG)
2020-06-24 14:11:54 +00:00
print(s)
return s
def clean(self):
2020-06-25 12:56:47 +00:00
super(AB, self).clean()
2020-06-24 14:11:54 +00:00
def run(self):
2020-06-25 12:56:47 +00:00
cmd = self.get_ab_server_cmd()
self.topo.command_to(self.topo_config.server, cmd)
2020-06-25 12:56:47 +00:00
print("Wait for the HTTP server to be up, this can take quite a while...")
self.topo.command_to(self.topo_config.client, "sleep 15")
cmd = self.get_ab_client_cmd()
self.topo.command_to(self.topo_config.client, cmd)
self.topo.command_to(self.topo_config.client, "sleep 2")