mininet-sample/experiments/send_file.py

62 lines
2.2 KiB
Python
Raw Normal View History

2020-06-26 06:52:56 +00:00
from core.experiment import RandomFileExperiment, RandomFileParameter, ExperimentParameter
import os
2020-06-26 06:52:56 +00:00
class SendFile(RandomFileExperiment):
NAME = "sendfile"
SERVER_LOG = "sendfile_server.log"
CLIENT_LOG = "sendfile_client.log"
WGET_BIN = "./client"
PING_OUTPUT = "ping.log"
2020-06-26 06:52:56 +00:00
def __init__(self, experiment_parameter_filename, topo, topo_config):
# Just rely on RandomFileExperiment
super(SendFile, self).__init__(experiment_parameter_filename, topo, topo_config)
def ping(self):
self.topo.command_to(self.topo_config.client, "rm " + \
SendFile.PING_OUTPUT )
2020-06-26 06:52:56 +00:00
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
2020-06-26 09:17:00 +00:00
for i in range(0, self.topo_config.client_interface_count()):
cmd = self.pingCommand(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd)
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()
def prepare(self):
super(SendFile, self).prepare()
self.topo.command_to(self.topo_config.client, "rm " + \
SendFile.CLIENT_LOG )
self.topo.command_to(self.topo_config.server, "rm " + \
SendFile.SERVER_LOG )
def getSendFileServerCmd(self):
s = "./server &>" + SendFile.SERVER_LOG + "&"
print(s)
return s
def getSendFileClientCmd(self):
s = SendFile.WGET_BIN + " " + self.topo_config.getServerIP() + " &>" + SendFile.CLIENT_LOG
print(s)
return s
def clean(self):
super(SendFile, self).clean()
def run(self):
cmd = self.getSendFileServerCmd()
self.topo.command_to(self.topo_config.server, cmd)
self.topo.command_to(self.topo_config.client, "sleep 0.1")
cmd = self.getSendFileClientCmd()
self.topo.command_to(self.topo_config.client, cmd)
self.topo.command_to(self.topo_config.client, "sleep 2")