2020-06-25 12:56:47 +00:00
|
|
|
from core.experience import RandomFileExperience, RandomFileParameter, ExperienceParameter
|
2020-06-24 15:18:40 +00:00
|
|
|
import os
|
|
|
|
|
2020-06-25 12:56:47 +00:00
|
|
|
class SendFile(RandomFileExperience):
|
2020-06-24 15:18:40 +00:00
|
|
|
NAME = "sendfile"
|
|
|
|
|
|
|
|
SERVER_LOG = "sendfile_server.log"
|
|
|
|
CLIENT_LOG = "sendfile_client.log"
|
|
|
|
WGET_BIN = "./client"
|
|
|
|
PING_OUTPUT = "ping.log"
|
|
|
|
|
2020-06-25 12:56:47 +00:00
|
|
|
def __init__(self, experience_parameter_filename, topo, topo_config):
|
|
|
|
# Just rely on RandomFileExperience
|
|
|
|
super(SendFile, self).__init__(experience_parameter_filename, topo, topo_config)
|
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
|
|
|
SendFile.PING_OUTPUT )
|
2020-06-25 15:01:58 +00:00
|
|
|
count = self.experience_parameter.get(ExperienceParameter.PING_COUNT)
|
2020-06-25 08:53:56 +00:00
|
|
|
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 + \
|
|
|
|
" >> " + SendFile.PING_OUTPUT
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
2020-06-25 12:56:47 +00:00
|
|
|
def load_parameters(self):
|
|
|
|
super(SendFile, self).load_parameters()
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
def prepare(self):
|
|
|
|
super(SendFile, 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
|
|
|
SendFile.CLIENT_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
|
|
|
SendFile.SERVER_LOG )
|
|
|
|
|
|
|
|
def getSendFileServerCmd(self):
|
|
|
|
s = "./server &>" + SendFile.SERVER_LOG + "&"
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def getSendFileClientCmd(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
s = SendFile.WGET_BIN + " " + self.topo_config.getServerIP() + " &>" + SendFile.CLIENT_LOG
|
2020-06-24 15:18:40 +00:00
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
super(SendFile, self).clean()
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
cmd = self.getSendFileServerCmd()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.server, 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 0.1")
|
2020-06-24 15:18:40 +00:00
|
|
|
cmd = self.getSendFileClientCmd()
|
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")
|