2020-06-26 06:52:56 +00:00
|
|
|
from core.experiment import Experiment, ExperimentParameter
|
2020-06-24 15:18:40 +00:00
|
|
|
import os
|
|
|
|
|
2020-06-25 14:57:27 +00:00
|
|
|
|
2020-06-26 06:52:56 +00:00
|
|
|
class NetperfParameter(ExperimentParameter):
|
2020-06-25 14:57:27 +00:00
|
|
|
TESTLEN = "netperfTestlen"
|
|
|
|
TESTNAME = "netperfTestname"
|
|
|
|
REQRES_SIZE = "netperfReqresSize"
|
|
|
|
|
2020-06-26 06:52:56 +00:00
|
|
|
def __init__(self, experiment_parameter_filename):
|
|
|
|
super(NetperfParameter, self).__init__(experiment_parameter_filename)
|
2020-06-25 14:57:27 +00:00
|
|
|
self.default_parameters.update({
|
|
|
|
NetperfParameter.TESTLEN: "10",
|
|
|
|
NetperfParameter.TESTNAME: "TCP_RR",
|
|
|
|
NetperfParameter.REQRES_SIZE: "2K,256",
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2020-06-26 06:52:56 +00:00
|
|
|
class Netperf(Experiment):
|
2020-06-24 15:18:40 +00:00
|
|
|
NAME = "netperf"
|
2020-06-25 14:57:27 +00:00
|
|
|
PARAMETER_CLASS = NetperfParameter
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
NETPERF_LOG = "netperf.log"
|
|
|
|
NETSERVER_LOG = "netserver.log"
|
|
|
|
NETPERF_BIN = "netperf"
|
|
|
|
NETSERVER_BIN = "netserver"
|
|
|
|
PING_OUTPUT = "ping.log"
|
|
|
|
|
2020-06-26 06:52:56 +00:00
|
|
|
def __init__(self, experiment_parameter_filename, topo, topo_config):
|
|
|
|
super(Netperf, 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()
|
|
|
|
|
|
|
|
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
|
|
|
Netperf.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()):
|
2020-06-29 07:51:55 +00:00
|
|
|
cmd = self.ping_command(self.topo_config.getClientIP(i),
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo_config.getServerIP(), n = count)
|
|
|
|
self.topo.command_to(self.topo_config.client, cmd)
|
2020-06-24 15:18:40 +00:00
|
|
|
|
2020-06-29 07:51:55 +00:00
|
|
|
def ping_command(self, fromIP, toIP, n=5):
|
2020-06-24 15:18:40 +00:00
|
|
|
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
|
|
|
|
" >> " + Netperf.PING_OUTPUT
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
2020-06-25 12:56:47 +00:00
|
|
|
def load_parameters(self):
|
2020-06-26 06:52:56 +00:00
|
|
|
self.testlen = self.experiment_parameter.get(NetperfParameter.TESTLEN)
|
|
|
|
self.testname = self.experiment_parameter.get(NetperfParameter.TESTNAME)
|
|
|
|
self.reqres_size = self.experiment_parameter.get(NetperfParameter.REQRES_SIZE)
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
def prepare(self):
|
|
|
|
super(Netperf, 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
|
|
|
Netperf.NETPERF_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
|
|
|
Netperf.NETSERVER_LOG)
|
|
|
|
|
2020-06-25 14:57:27 +00:00
|
|
|
def get_client_cmd(self):
|
|
|
|
s = "{} -H {} -l {} -t {} -- -r {} &> {}".format(Netperf.NETPERF_BIN,
|
|
|
|
self.topo_config.getServerIP(), self.testlen, self.testname, self.reqres_size,
|
|
|
|
Netperf.NETPERF_LOG)
|
2020-06-24 15:18:40 +00:00
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
2020-06-25 14:57:27 +00:00
|
|
|
def get_server_cmd(self):
|
|
|
|
s = "sudo {} &> {} &".format(Netperf.NETSERVER_BIN, Netperf.NETSERVER_LOG)
|
2020-06-24 15:18:40 +00:00
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
super(Netperf, self).clean()
|
|
|
|
|
|
|
|
def run(self):
|
2020-06-25 14:57:27 +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-06-25 14:57:27 +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")
|