2020-06-24 15:18:40 +00:00
|
|
|
from core.experience import Experience, ExperienceParameter
|
|
|
|
import os
|
|
|
|
|
2020-06-25 14:57:27 +00:00
|
|
|
|
|
|
|
class NetperfParameter(ExperienceParameter):
|
|
|
|
TESTLEN = "netperfTestlen"
|
|
|
|
TESTNAME = "netperfTestname"
|
|
|
|
REQRES_SIZE = "netperfReqresSize"
|
|
|
|
|
|
|
|
def __init__(self, experience_parameter_filename):
|
|
|
|
super(NetperfParameter, self).__init__(experience_parameter_filename)
|
|
|
|
self.default_parameters.update({
|
|
|
|
NetperfParameter.TESTLEN: "10",
|
|
|
|
NetperfParameter.TESTNAME: "TCP_RR",
|
|
|
|
NetperfParameter.REQRES_SIZE: "2K,256",
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2020-06-24 15:18:40 +00:00
|
|
|
class Netperf(Experience):
|
|
|
|
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-25 12:56:47 +00:00
|
|
|
def __init__(self, experience_parameter_filename, topo, topo_config):
|
|
|
|
super(Netperf, self).__init__(experience_parameter_filename, topo, topo_config)
|
|
|
|
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-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 15:18:40 +00:00
|
|
|
|
|
|
|
def pingCommand(self, fromIP, toIP, n=5):
|
|
|
|
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-25 14:57:27 +00:00
|
|
|
self.testlen = self.experience_parameter.get(NetperfParameter.TESTLEN)
|
|
|
|
self.testname = self.experience_parameter.get(NetperfParameter.TESTNAME)
|
|
|
|
self.reqres_size = self.experience_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")
|