2020-06-24 08:36:26 +00:00
|
|
|
from core.experience import Experience, ExperienceParameter
|
2015-02-27 10:16:01 +00:00
|
|
|
from mpPvAt import MpPvAt
|
|
|
|
|
|
|
|
"""
|
2020-06-24 08:36:26 +00:00
|
|
|
Should be the mother of ExperienceNCPV, shame on me, should rewrite
|
|
|
|
ExperienceNCPV as daughter class of this one.
|
2015-02-27 10:16:01 +00:00
|
|
|
"""
|
|
|
|
|
2020-06-24 08:36:26 +00:00
|
|
|
class ExperienceNC(Experience):
|
2015-02-27 10:16:01 +00:00
|
|
|
SERVER_NC_LOG = "netcat_server"
|
|
|
|
CLIENT_NC_LOG = "netcat_client"
|
|
|
|
NC_BIN = "netcat"
|
|
|
|
|
|
|
|
def __init__(self, xpParamFile, mpTopo, mpConfig):
|
2020-06-24 08:36:26 +00:00
|
|
|
Experience.__init__(self, xpParamFile, mpTopo, mpConfig)
|
2015-02-27 10:16:01 +00:00
|
|
|
self.loadParam()
|
2020-06-24 08:36:26 +00:00
|
|
|
Experience.classicRun(self)
|
2015-02-27 10:16:01 +00:00
|
|
|
|
|
|
|
def loadParam(self):
|
2020-06-24 08:36:26 +00:00
|
|
|
self.ddibs = self.xpParam.getParam(ExperienceParameter.DDIBS)
|
|
|
|
self.ddobs = self.xpParam.getParam(ExperienceParameter.DDOBS)
|
|
|
|
self.ddcount = self.xpParam.getParam(ExperienceParameter.DDCOUNT)
|
|
|
|
self.ncServerPort = self.xpParam.getParam(ExperienceParameter.NCSERVERPORT)
|
2015-02-27 10:16:01 +00:00
|
|
|
self.ncClientPort = []
|
|
|
|
for k in sorted(self.xpParam.paramDic):
|
2020-06-24 08:36:26 +00:00
|
|
|
if k.startswith(ExperienceParameter.NCCLIENTPORT):
|
2015-02-27 10:16:01 +00:00
|
|
|
port = self.xpParam.paramDic[k]
|
|
|
|
self.ncClientPort.append(port)
|
|
|
|
if len(self.ncClientPort) == 0:
|
2020-06-24 08:36:26 +00:00
|
|
|
d = self.xpParam.getParam(ExperienceParameter.NCCLIENTPORT)
|
2015-02-27 10:16:01 +00:00
|
|
|
self.ncClientPort.append(d)
|
|
|
|
|
|
|
|
def prepare(self):
|
2020-06-24 08:36:26 +00:00
|
|
|
Experience.prepare(self)
|
2015-02-27 10:16:01 +00:00
|
|
|
self.mpTopo.commandTo(self.mpConfig.client, "rm " + \
|
2020-06-24 08:36:26 +00:00
|
|
|
ExperienceNC.CLIENT_NC_LOG )
|
2015-02-27 10:16:01 +00:00
|
|
|
self.mpTopo.commandTo(self.mpConfig.server, "rm " + \
|
2020-06-24 08:36:26 +00:00
|
|
|
ExperienceNC.SERVER_NC_LOG )
|
2015-02-27 10:16:01 +00:00
|
|
|
|
|
|
|
def getNCServerCmd(self, id):
|
|
|
|
s = "dd if=/dev/urandom ibs=" + self.ddibs + \
|
|
|
|
" obs=" + self.ddobs + \
|
|
|
|
" count=" + self.ddcount + \
|
|
|
|
" | " + \
|
2020-06-24 08:36:26 +00:00
|
|
|
ExperienceNC.NC_BIN + \
|
2015-02-27 10:16:01 +00:00
|
|
|
" -l " + self.ncServerPort + \
|
2020-06-24 08:36:26 +00:00
|
|
|
" &>" + ExperienceNC.SERVER_NC_LOG + \
|
2015-02-27 10:16:01 +00:00
|
|
|
"_" + str(id) + ".log"
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def getNCClientCmd(self, id):
|
2020-06-24 08:36:26 +00:00
|
|
|
s = ExperienceNC.NC_BIN + " " + \
|
2015-02-27 10:16:01 +00:00
|
|
|
" -p " + self.ncClientPort[id] + " " + \
|
|
|
|
self.mpConfig.getServerIP() + " " + \
|
|
|
|
self.ncServerPort + " " + \
|
2020-06-24 08:36:26 +00:00
|
|
|
"&>" + ExperienceNC.CLIENT_NC_LOG + \
|
2015-02-27 10:40:52 +00:00
|
|
|
"_" + str(id) + ".log"
|
2015-02-27 10:16:01 +00:00
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def clean(self):
|
2020-06-24 08:36:26 +00:00
|
|
|
Experience.clean(self)
|
2015-02-27 10:16:01 +00:00
|
|
|
#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")
|
|
|
|
|