2020-06-24 15:18:40 +00:00
|
|
|
from core.experience import Experience, ExperienceParameter
|
|
|
|
import os
|
|
|
|
|
|
|
|
class IPerf(Experience):
|
|
|
|
NAME = "iperf"
|
|
|
|
|
|
|
|
IPERF_LOG = "iperf.log"
|
|
|
|
SERVER_LOG = "server.log"
|
|
|
|
IPERF_BIN = "iperf3"
|
|
|
|
PING_OUTPUT = "ping.log"
|
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
def __init__(self, experience_parameter, topo, topo_config):
|
|
|
|
super(IPerf, self).__init__(experience_parameter, topo, topo_config)
|
2020-06-24 15:18:40 +00:00
|
|
|
self.loadParam()
|
|
|
|
self.ping()
|
2020-06-25 08:53:56 +00:00
|
|
|
super(IPerf, self).classic_run()
|
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
|
|
|
IPerf.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 + \
|
|
|
|
" >> " + IPerf.PING_OUTPUT
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def loadParam(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
self.time = self.experience_parameter.get(ExperienceParameter.IPERFTIME)
|
|
|
|
self.parallel = self.experience_parameter.get(ExperienceParameter.IPERFPARALLEL)
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
def prepare(self):
|
|
|
|
super(IPerf, 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
|
|
|
IPerf.IPERF_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
|
|
|
IPerf.SERVER_LOG)
|
|
|
|
|
|
|
|
def getClientCmd(self):
|
2020-06-25 08:53:56 +00:00
|
|
|
s = IPerf.IPERF_BIN + " -c " + self.topo_config.getServerIP() + \
|
2020-06-24 15:18:40 +00:00
|
|
|
" -t " + self.time + " -P " + self.parallel + " &>" + IPerf.IPERF_LOG
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def getServerCmd(self):
|
|
|
|
s = "sudo " + IPerf.IPERF_BIN + " -s &>" + \
|
|
|
|
IPerf.SERVER_LOG + "&"
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
super(IPerf, self).clean()
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
cmd = self.getServerCmd()
|
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-24 15:18:40 +00:00
|
|
|
cmd = self.getClientCmd()
|
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")
|