2020-06-24 14:11:54 +00:00
|
|
|
from core.experience import Experience, ExperienceParameter
|
|
|
|
import os
|
|
|
|
|
|
|
|
class AB(Experience):
|
|
|
|
NAME = "ab"
|
|
|
|
|
|
|
|
SERVER_LOG = "ab_server.log"
|
|
|
|
CLIENT_LOG = "ab_client.log"
|
|
|
|
AB_BIN = "ab"
|
|
|
|
PING_OUTPUT = "ping.log"
|
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
def __init__(self, experience_parameter, topo, topo_config):
|
|
|
|
super(AB, self).__init__(experience_parameter, topo, topo_config)
|
2020-06-24 14:11:54 +00:00
|
|
|
self.loadParam()
|
|
|
|
self.ping()
|
2020-06-25 08:53:56 +00:00
|
|
|
super(AB, self).classic_run()
|
2020-06-24 14:11:54 +00:00
|
|
|
|
|
|
|
def ping(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client,
|
2020-06-24 14:11:54 +00:00
|
|
|
"rm " + AB.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 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
|
|
|
|
|
|
|
|
def loadParam(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
self.file = self.experience_parameter.get(ExperienceParameter.HTTPFILE)
|
|
|
|
self.random_size = self.experience_parameter.get(ExperienceParameter.HTTPRANDOMSIZE)
|
|
|
|
self.concurrent_requests = self.experience_parameter.get(ExperienceParameter.ABCONCURRENTREQUESTS)
|
|
|
|
self.timelimit = self.experience_parameter.get(ExperienceParameter.ABTIMELIMIT)
|
2020-06-24 14:11:54 +00:00
|
|
|
|
|
|
|
def prepare(self):
|
|
|
|
Experience.prepare(self)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, "rm " + \
|
2020-06-24 14:11:54 +00:00
|
|
|
AB.CLIENT_LOG )
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.server, "rm " + \
|
2020-06-24 14:11:54 +00:00
|
|
|
AB.SERVER_LOG )
|
|
|
|
if self.file == "random":
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client,
|
2020-06-24 14:11:54 +00:00
|
|
|
"dd if=/dev/urandom of=random bs=1K count=" + \
|
|
|
|
self.random_size)
|
|
|
|
|
|
|
|
def getAbServerCmd(self):
|
|
|
|
s = "python " + os.path.dirname(os.path.abspath(__file__)) + \
|
|
|
|
"/utils/http_server.py &>" + AB.SERVER_LOG + "&"
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def getAbClientCmd(self):
|
|
|
|
s = AB.AB_BIN + " -c " + self.concurrent_requests + " -t " + \
|
2020-06-25 08:53:56 +00:00
|
|
|
self.timelimit + " http://" + self.topo_config.getServerIP() + "/" + self.file + \
|
2020-06-24 14:11:54 +00:00
|
|
|
" &>" + AB.CLIENT_LOG
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
Experience.clean(self)
|
|
|
|
if self.file == "random":
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, "rm random*")
|
2020-06-24 14:11:54 +00:00
|
|
|
#todo use cst
|
2020-06-25 08:53:56 +00:00
|
|
|
#self.topo.command_to(self.topo_config.server, "killall netcat")
|
2020-06-24 14:11:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
cmd = self.getAbServerCmd()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.server, cmd)
|
2020-06-24 14:11:54 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, "sleep 2")
|
2020-06-24 14:11:54 +00:00
|
|
|
cmd = self.getAbClientCmd()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, cmd)
|
|
|
|
self.topo.command_to(self.topo_config.client, "sleep 2")
|