mininet-sample/mpExperienceIperf.py

73 lines
2.1 KiB
Python
Raw Normal View History

2016-06-01 09:00:51 +00:00
from mpExperience import MpExperience
from mpParamXp import MpParamXp
from mpPvAt import MpPvAt
import os
class MpExperienceIperf(MpExperience):
IPERF_LOG = "iperf.log"
SERVER_LOG = "server.log"
2016-06-03 14:39:16 +00:00
IPERF_BIN = "iperf3"
2016-06-01 09:00:51 +00:00
PING_OUTPUT = "ping.log"
def __init__(self, xpParamFile, mpTopo, mpConfig):
MpExperience.__init__(self, xpParamFile, mpTopo, mpConfig)
self.loadParam()
self.ping()
MpExperience.classicRun(self)
def ping(self):
self.mpTopo.commandTo(self.mpConfig.client, "rm " + \
MpExperienceIperf.PING_OUTPUT)
count = self.xpParam.getParam(MpParamXp.PINGCOUNT)
for i in range(0, self.mpConfig.getClientInterfaceCount()):
cmd = self.pingCommand(self.mpConfig.getClientIP(i),
self.mpConfig.getServerIP(), n = count)
self.mpTopo.commandTo(self.mpConfig.client, cmd)
def pingCommand(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + MpExperienceIperf.PING_OUTPUT
print(s)
return s
def loadParam(self):
"""
todo : param LD_PRELOAD ??
"""
self.time = self.xpParam.getParam(MpParamXp.IPERFTIME)
self.parallel = self.xpParam.getParam(MpParamXp.IPERFPARALLEL)
2016-06-01 09:00:51 +00:00
def prepare(self):
MpExperience.prepare(self)
self.mpTopo.commandTo(self.mpConfig.client, "rm " +
MpExperienceIperf.IPERF_LOG)
self.mpTopo.commandTo(self.mpConfig.server, "rm " +
MpExperienceIperf.SERVER_LOG)
def getClientCmd(self):
s = MpExperienceIperf.IPERF_BIN + " -c " + self.mpConfig.getServerIP() + \
" -t " + self.time + " -P " + self.parallel + " &>" + MpExperienceIperf.IPERF_LOG
2016-06-01 09:00:51 +00:00
print(s)
return s
def getServerCmd(self):
2016-06-03 15:27:55 +00:00
s = "sudo " + MpExperienceIperf.IPERF_BIN + " -s &>" + \
2016-06-01 09:00:51 +00:00
MpExperienceIperf.SERVER_LOG + "&"
print(s)
return s
def clean(self):
MpExperience.clean(self)
#todo use cst
#self.mpTopo.commandTo(self.mpConfig.server, "killall netcat")
def run(self):
cmd = self.getServerCmd()
self.mpTopo.commandTo(self.mpConfig.server, cmd)
self.mpTopo.commandTo(self.mpConfig.client, "sleep 2")
cmd = self.getClientCmd()
self.mpTopo.commandTo(self.mpConfig.client, cmd)
self.mpTopo.commandTo(self.mpConfig.client, "sleep 2")