2020-06-24 15:18:40 +00:00
|
|
|
from core.experience import Experience, ExperienceParameter
|
|
|
|
|
|
|
|
"""
|
|
|
|
Should be the mother of ExperienceNCPV, shame on me, should rewrite
|
|
|
|
ExperienceNCPV as daughter class of this one.
|
|
|
|
"""
|
|
|
|
|
2020-06-25 12:56:47 +00:00
|
|
|
class NCParameter(ExperienceParameter):
|
|
|
|
DD_IBS = "ddIBS"
|
|
|
|
DD_OBS = "ddIBS"
|
|
|
|
DD_COUNT = "ddCount"
|
|
|
|
SERVER_PORT = "ncServerPort"
|
|
|
|
CLIENT_PORT = "ncClientPort"
|
|
|
|
|
|
|
|
def __init__(self, experience_parameter_filename):
|
|
|
|
super(NCParameter, self).__init__(experience_parameter_filename)
|
|
|
|
self.default_parameters.update({
|
|
|
|
NCParameter.DD_IBS: "1k",
|
|
|
|
NCParameter.DD_OBS: "1k",
|
|
|
|
NCParameter.DD_COUNT: "5000", #5k * 1k = 5m
|
|
|
|
NCParameter.SERVER_PORT: "33666",
|
|
|
|
NCParameter.CLIENT_PORT: "33555",
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2020-06-24 15:18:40 +00:00
|
|
|
class NC(Experience):
|
|
|
|
NAME = "nc"
|
2020-06-25 12:56:47 +00:00
|
|
|
PARAMETER_CLASS = NCParameter
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
SERVER_NC_LOG = "netcat_server"
|
|
|
|
CLIENT_NC_LOG = "netcat_client"
|
|
|
|
NC_BIN = "netcat"
|
|
|
|
|
2020-06-25 12:56:47 +00:00
|
|
|
def __init__(self, experience_parameter_filename, topo, topo_config):
|
|
|
|
super(NC, self).__init__(experience_parameter_filename, topo, topo_config)
|
|
|
|
self.load_parameters()
|
2020-06-25 08:53:56 +00:00
|
|
|
super(NC, self).classic_run()
|
2020-06-24 15:18:40 +00:00
|
|
|
|
2020-06-25 12:56:47 +00:00
|
|
|
def load_parameters(self):
|
|
|
|
self.ddibs = self.experience_parameter.get(NCParameter.DD_IBS)
|
|
|
|
self.ddobs = self.experience_parameter.get(NCParameter.DD_OBS)
|
|
|
|
self.ddcount = self.experience_parameter.get(NCParameter.DD_COUNT)
|
|
|
|
self.ncServerPort = self.experience_parameter.get(NCParameter.SERVER_PORT)
|
2020-06-24 15:18:40 +00:00
|
|
|
self.ncClientPort = []
|
2020-06-25 08:53:56 +00:00
|
|
|
for k in sorted(self.experience_parameter.paramDic):
|
2020-06-25 12:56:47 +00:00
|
|
|
if k.startswith(NCParameter.CLIENT_PORT):
|
2020-06-25 08:53:56 +00:00
|
|
|
port = self.experience_parameter.paramDic[k]
|
2020-06-24 15:18:40 +00:00
|
|
|
self.ncClientPort.append(port)
|
|
|
|
if len(self.ncClientPort) == 0:
|
2020-06-25 12:56:47 +00:00
|
|
|
d = self.experience_parameter.get(NCParameter.CLIENT_PORT)
|
2020-06-24 15:18:40 +00:00
|
|
|
self.ncClientPort.append(d)
|
|
|
|
|
|
|
|
def prepare(self):
|
|
|
|
super(NC, 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
|
|
|
NC.CLIENT_NC_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
|
|
|
NC.SERVER_NC_LOG )
|
|
|
|
|
|
|
|
def getNCServerCmd(self, id):
|
|
|
|
s = "dd if=/dev/urandom ibs=" + self.ddibs + \
|
|
|
|
" obs=" + self.ddobs + \
|
|
|
|
" count=" + self.ddcount + \
|
|
|
|
" | " + \
|
|
|
|
NC.NC_BIN + \
|
|
|
|
" -l " + self.ncServerPort + \
|
|
|
|
" &>" + NC.SERVER_NC_LOG + \
|
|
|
|
"_" + str(id) + ".log"
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def getNCClientCmd(self, id):
|
|
|
|
s = NC.NC_BIN + " " + \
|
|
|
|
" -p " + self.ncClientPort[id] + " " + \
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo_config.getServerIP() + " " + \
|
2020-06-24 15:18:40 +00:00
|
|
|
self.ncServerPort + " " + \
|
|
|
|
"&>" + NC.CLIENT_NC_LOG + \
|
|
|
|
"_" + str(id) + ".log"
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
super(NC, self).clean()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.server, "killall netcat")
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
for i in range(0, len(self.ncClientPort)):
|
|
|
|
cmd = self.getNCServerCmd(i)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo_config.server.sendCmd(cmd)
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
cmd = self.getNCClientCmd(i)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, cmd)
|
2020-06-24 15:18:40 +00:00
|
|
|
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo_config.server.waitOutput()
|
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 1")
|
2020-06-24 15:18:40 +00:00
|
|
|
|