draft simple NC

Signed-off-by: Benjamin Hesmans <benjamin.hesmans@uclouvain.be>
This commit is contained in:
Benjamin Hesmans 2015-02-27 11:16:01 +01:00
parent ff8d8c5537
commit bb33748de3
3 changed files with 86 additions and 0 deletions

View File

@ -3,6 +3,7 @@ from mpParamXp import MpParamXp
class MpExperience: class MpExperience:
PING = "ping" PING = "ping"
NCPV = "ncpv" NCPV = "ncpv"
NC = "nc"
def __init__(self, xpParam, mpTopo, mpConfig): def __init__(self, xpParam, mpTopo, mpConfig):
self.xpParam = xpParam self.xpParam = xpParam
self.mpTopo = mpTopo self.mpTopo = mpTopo

80
src/mpExperienceNC.py Normal file
View File

@ -0,0 +1,80 @@
from mpExperience import MpExperience
from mpParamXp import MpParamXp
from mpPvAt import MpPvAt
"""
Should be the mother of MpExperienceNCPV, shame on me, should rewrite
MpExperienceNCPV as daughter class of this one.
"""
class MpExperienceNC(MpExperience):
SERVER_NC_LOG = "netcat_server"
CLIENT_NC_LOG = "netcat_client"
NC_BIN = "netcat"
def __init__(self, xpParamFile, mpTopo, mpConfig):
MpExperience.__init__(self, xpParamFile, mpTopo, mpConfig)
self.loadParam()
MpExperience.classicRun(self)
def loadParam(self):
self.ddibs = self.xpParam.getParam(MpParamXp.DDIBS)
self.ddobs = self.xpParam.getParam(MpParamXp.DDOBS)
self.ddcount = self.xpParam.getParam(MpParamXp.DDCOUNT)
self.ncServerPort = self.xpParam.getParam(MpParamXp.NCSERVERPORT)
self.ncClientPort = []
for k in sorted(self.xpParam.paramDic):
if k.startswith(MpParamXp.NCCLIENTPORT):
port = self.xpParam.paramDic[k]
self.ncClientPort.append(port)
if len(self.ncClientPort) == 0:
d = self.xpParam.getParam(MpParamXp.NCCLIENTPORT)
self.ncClientPort.append(d)
def prepare(self):
MpExperience.prepare(self)
self.mpTopo.commandTo(self.mpConfig.client, "rm " + \
MpExperienceNCPV.CLIENT_NC_LOG )
self.mpTopo.commandTo(self.mpConfig.server, "rm " + \
MpExperienceNCPV.SERVER_NC_LOG )
def getNCServerCmd(self, id):
s = "dd if=/dev/urandom ibs=" + self.ddibs + \
" obs=" + self.ddobs + \
" count=" + self.ddcount + \
" | " + \
MpExperienceNC.NC_BIN + \
" -l " + self.ncServerPort + \
" &>" + MpExperienceNC.SERVER_NC_LOG + \
"_" + str(id) + ".log"
print(s)
return s
def getNCClientCmd(self, id):
s = MpExperienceNCPV.NC_BIN + " " + \
" -p " + self.ncClientPort[id] + " " + \
self.mpConfig.getServerIP() + " " + \
self.ncServerPort + " " + \
"&>" + MpExperienceNC.CLIENT_NC_LOG + \
"_" + str(id) + ".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):
for i in range(0, len(self.ncClientPort)):
cmd = self.getNCServerCmd(i)
self.mpConfig.server.sendCmd(cmd)
cmd = self.getNCClientCmd(i)
self.mpTopo.commandTo(self.mpConfig.client, cmd)
self.mpConfig.server.waitOutput()
self.mpTopo.commandTo(self.mpConfig.client, "sleep 1")

View File

@ -7,6 +7,7 @@ from mpECMPSingleInterfaceConfig import MpECMPSingleInterfaceConfig
from mpMininetBuilder import MpMininetBuilder from mpMininetBuilder import MpMininetBuilder
from mpExperiencePing import MpExperiencePing from mpExperiencePing import MpExperiencePing
from mpExperienceNCPV import MpExperienceNCPV from mpExperienceNCPV import MpExperienceNCPV
from mpExperienceNC import MpExperienceNC
from mpExperience import MpExperience from mpExperience import MpExperience
from mpECMPSingleInterfaceTopo import MpECMPSingleInterfaceTopo from mpECMPSingleInterfaceTopo import MpECMPSingleInterfaceTopo
@ -69,6 +70,10 @@ class MpXpRunner:
MpExperienceNCPV(self.xpParam, self.mpTopo, MpExperienceNCPV(self.xpParam, self.mpTopo,
self.mpTopoConfig) self.mpTopoConfig)
self.mpTopo.getCLI() self.mpTopo.getCLI()
elif xp == MpExperience.NC:
MpExperienceNC(self.xpParam, self.mpTopo,
self.mpTopoConfig)
self.mpTopo.getCLI()
else: else:
print("Unfound xp type..." + xp) print("Unfound xp type..." + xp)