2020-06-26 06:52:56 +00:00
|
|
|
from core.experiment import Experiment, ExperimentParameter
|
2020-07-02 11:38:45 +00:00
|
|
|
import logging
|
2020-06-24 15:18:40 +00:00
|
|
|
import os
|
|
|
|
|
2020-07-02 11:38:45 +00:00
|
|
|
|
2020-06-26 06:52:56 +00:00
|
|
|
class IPerfParameter(ExperimentParameter):
|
2020-06-25 12:56:47 +00:00
|
|
|
TIME = "iperfTime"
|
|
|
|
PARALLEL = "iperfParallel"
|
|
|
|
|
2020-06-26 06:52:56 +00:00
|
|
|
def __init__(self, experiment_parameter_filename):
|
|
|
|
super(IPerfParameter, self).__init__(experiment_parameter_filename)
|
2020-06-25 12:56:47 +00:00
|
|
|
self.default_parameters.update({
|
|
|
|
IPerfParameter.TIME: "10",
|
|
|
|
IPerfParameter.PARALLEL: "1",
|
|
|
|
})
|
|
|
|
|
2020-06-26 06:52:56 +00:00
|
|
|
class IPerf(Experiment):
|
2020-06-24 15:18:40 +00:00
|
|
|
NAME = "iperf"
|
2020-06-25 12:56:47 +00:00
|
|
|
PARAMETER_CLASS = IPerfParameter
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
IPERF_LOG = "iperf.log"
|
|
|
|
SERVER_LOG = "server.log"
|
|
|
|
IPERF_BIN = "iperf3"
|
|
|
|
PING_OUTPUT = "ping.log"
|
|
|
|
|
2020-06-26 06:52:56 +00:00
|
|
|
def __init__(self, experiment_parameter_filename, topo, topo_config):
|
|
|
|
super(IPerf, self).__init__(experiment_parameter_filename, topo, topo_config)
|
2020-06-25 12:56:47 +00:00
|
|
|
self.load_parameters()
|
2020-06-24 15:18:40 +00:00
|
|
|
self.ping()
|
|
|
|
|
2020-06-25 12:56:47 +00:00
|
|
|
def load_parameters(self):
|
2020-06-26 06:52:56 +00:00
|
|
|
self.time = self.experiment_parameter.get(IPerfParameter.TIME)
|
|
|
|
self.parallel = self.experiment_parameter.get(IPerfParameter.PARALLEL)
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
def prepare(self):
|
|
|
|
super(IPerf, self).prepare()
|
2020-07-02 11:38:45 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, "rm {}".format(IPerf.IPERF_LOG))
|
|
|
|
self.topo.command_to(self.topo_config.server, "rm {}".format(IPerf.SERVER_LOG))
|
2020-06-24 15:18:40 +00:00
|
|
|
|
2020-07-02 11:38:45 +00:00
|
|
|
def get_client_cmd(self):
|
|
|
|
s = "{} -c {} -t {} -P {} &>{}".format(IPerf.IPERF_BIN,
|
|
|
|
self.topo_config.get_server_ip(), self.time, self.parallel, IPerf.IPERF_LOG)
|
|
|
|
logging.info(s)
|
2020-06-24 15:18:40 +00:00
|
|
|
return s
|
|
|
|
|
2020-07-02 11:38:45 +00:00
|
|
|
def get_server_cmd(self):
|
|
|
|
s = "{} -s &> {} &".format(IPerf.IPERF_BIN, IPerf.SERVER_LOG)
|
|
|
|
logging.info(s)
|
2020-06-24 15:18:40 +00:00
|
|
|
return s
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
super(IPerf, self).clean()
|
|
|
|
|
|
|
|
def run(self):
|
2020-07-02 11:38:45 +00:00
|
|
|
cmd = self.get_server_cmd()
|
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 2")
|
2020-07-02 11:38:45 +00:00
|
|
|
cmd = self.get_client_cmd()
|
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")
|