mininet-sample/experiences/ab.py

79 lines
2.9 KiB
Python
Raw Normal View History

2020-06-25 12:56:47 +00:00
from core.experience import RandomFileExperience, RandomFileParameter, ExperienceParameter
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"
def __init__(self, experience_parameter_filename):
super(ABParameter, self).__init__(experience_parameter_filename)
self.default_parameters.update({
ABParameter.CONCURRENT_REQUESTS: "50",
ABParameter.TIME_LIMIT: "20",
})
class AB(RandomFileExperience):
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-25 12:56:47 +00:00
def __init__(self, experience_parameter_filename, topo, topo_config):
super(AB, self).__init__(experience_parameter_filename, topo, topo_config)
2020-06-24 14:11:54 +00:00
def ping(self):
self.topo.command_to(self.topo_config.client,
2020-06-24 14:11:54 +00:00
"rm " + AB.PING_OUTPUT)
2020-06-25 15:01:58 +00:00
count = self.experience_parameter.get(ExperienceParameter.PING_COUNT)
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 14:11:54 +00:00
def pingCommand(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + AB.PING_OUTPUT
print(s)
return s
2020-06-25 12:56:47 +00:00
def load_parameters(self):
super(AB, self).load_parameters()
self.concurrent_requests = self.experience_parameter.get(ABParameter.CONCURRENT_REQUESTS)
self.time_limit = self.experience_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,
self.time_limit, self.topo_config.getServerIP(), 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")