2020-06-26 06:52:56 +00:00
|
|
|
from .nc import NC, NCParameter, ExperimentParameter
|
2020-06-25 12:56:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NCPVParameter(NCParameter):
|
|
|
|
RATE_LIMIT= "pvRateLimit"
|
|
|
|
G = "pvG" #patched version of pv
|
|
|
|
Z = "pvZ"
|
|
|
|
CHANGE_PV = "changePv"
|
|
|
|
CHANGE_PV_AT = "changePvAt"
|
|
|
|
|
2020-06-26 06:52:56 +00:00
|
|
|
def __init__(self, experiment_parameter_filename):
|
|
|
|
super(NCPVParameter, self).__init__(experiment_parameter_filename)
|
2020-06-25 12:56:47 +00:00
|
|
|
self.default_parameters.update({
|
|
|
|
NCPVParameter.RATE_LIMIT: "400k",
|
|
|
|
NCPVParameter.G: "10000",
|
|
|
|
NCPVParameter.Z: "10000",
|
|
|
|
NCPVParameter.CHANGE_PV: "no",
|
|
|
|
})
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MpPvAt(object):
|
|
|
|
def __init__(self, at, cmd):
|
|
|
|
self.at = at
|
|
|
|
self.cmd = cmd
|
|
|
|
self.delta = 0
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Pv... at " + str(self.at) + "(" + str(self.delta) + \
|
|
|
|
") will be " + self.cmd
|
|
|
|
|
|
|
|
|
2020-06-25 12:56:47 +00:00
|
|
|
class NCPV(NC):
|
2020-06-24 15:18:40 +00:00
|
|
|
"""
|
|
|
|
NC PV : NetCat and Pipe Viewer
|
|
|
|
"""
|
|
|
|
NAME = "ncpv"
|
2020-06-25 12:56:47 +00:00
|
|
|
PARAMETER_CLASS = NCPVParameter
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
SERVER_NC_LOG = "netcat_server"
|
|
|
|
CLIENT_NC_LOG = "netcat_client"
|
|
|
|
NC_BIN = "/usr/local/bin/nc"
|
|
|
|
PV_BIN = "/usr/local/bin/pv"
|
|
|
|
PING_OUTPUT = "ping.log"
|
|
|
|
|
2020-06-26 06:52:56 +00:00
|
|
|
def __init__(self, experiment_parameter_filename, topo, topo_config):
|
|
|
|
super(NCPV, self).__init__(experiment_parameter_filename, topo, topo_config)
|
2020-06-25 12:56:47 +00:00
|
|
|
self.load_parameters()
|
2020-06-24 15:18:40 +00:00
|
|
|
self.ping()
|
|
|
|
|
|
|
|
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
|
|
|
NCPV.PING_OUTPUT )
|
2020-06-26 06:52:56 +00:00
|
|
|
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
|
2020-06-26 09:17:00 +00:00
|
|
|
for i in range(0, self.topo_config.client_interface_count()):
|
2020-06-29 14:23:39 +00:00
|
|
|
cmd = self.ping_command(self.topo_config.get_client_ip(i),
|
|
|
|
self.topo_config.get_server_ip(), n = count)
|
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-29 07:51:55 +00:00
|
|
|
def ping_command(self, fromIP, toIP, n=5):
|
2020-06-24 15:18:40 +00:00
|
|
|
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
|
|
|
|
" >> " + NCPV.PING_OUTPUT
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
2020-06-25 12:56:47 +00:00
|
|
|
def load_parameters(self):
|
|
|
|
super(NCPV, self).load_parameters()
|
2020-06-26 06:52:56 +00:00
|
|
|
self.pvg = self.experiment_parameter.get(ExperimentParameter.PVG)
|
|
|
|
self.pvz = self.experiment_parameter.get(ExperimentParameter.PVZ)
|
|
|
|
self.pvRateLimit = self.experiment_parameter.get(ExperimentParameter.PVRATELIMIT)
|
2020-06-24 15:18:40 +00:00
|
|
|
self.loadPvAt()
|
|
|
|
|
|
|
|
def loadPvAt(self):
|
|
|
|
self.changePvAt = []
|
2020-06-26 06:52:56 +00:00
|
|
|
self.changePv = self.experiment_parameter.get(ExperimentParameter.CHANGEPV)
|
2020-06-24 15:18:40 +00:00
|
|
|
if self.changePv != "yes":
|
|
|
|
print("Don't change pv rate...")
|
|
|
|
return
|
2020-06-26 06:52:56 +00:00
|
|
|
changePvAt = self.experiment_parameter.get(ExperimentParameter.CHANGEPVAT)
|
2020-06-24 15:18:40 +00:00
|
|
|
if not isinstance(changePvAt, list):
|
|
|
|
changePvAt = [changePvAt]
|
|
|
|
for p in changePvAt:
|
|
|
|
tab = p.split(",")
|
|
|
|
if len(tab)==2:
|
|
|
|
o = MpPvAt(float(tab[0]), tab[1])
|
|
|
|
self.addPvAt(o)
|
|
|
|
else:
|
|
|
|
print("pv wrong line : " + p)
|
|
|
|
|
|
|
|
def addPvAt(self, p):
|
|
|
|
if len(self.changePvAt) == 0 :
|
|
|
|
p.delta = p.at
|
|
|
|
else:
|
|
|
|
if p.at > self.changePvAt[-1].at:
|
|
|
|
p.delta = p.at - self.changePvAt[-1].at
|
|
|
|
else:
|
|
|
|
print("Do not take into account " + p.__str__() + \
|
|
|
|
"because ooo !")
|
|
|
|
return
|
|
|
|
|
|
|
|
self.changePvAt.append(p)
|
|
|
|
|
|
|
|
def getPvChangeCmd(self):
|
|
|
|
cmd = ""
|
|
|
|
for p in self.changePvAt:
|
|
|
|
cmd = cmd + "sleep " + str(p.delta)
|
|
|
|
cmd = cmd + " && "
|
|
|
|
cmd = cmd + NCPV.PV_BIN + " -R " + self.pvPid
|
|
|
|
cmd = cmd + " " + p.cmd + " && "
|
|
|
|
cmd = cmd + " true &"
|
|
|
|
return cmd
|
|
|
|
|
|
|
|
def prepare(self):
|
|
|
|
super(NCPV, self).prepare()
|
|
|
|
|
|
|
|
def getNCServerCmd(self, id):
|
2020-06-25 12:56:47 +00:00
|
|
|
s = NC.NC_BIN + " -d " + \
|
2020-06-24 15:18:40 +00:00
|
|
|
" -l " + self.ncServerPort + \
|
2020-06-25 12:56:47 +00:00
|
|
|
" 1>/dev/null 2>" + NC.SERVER_NC_LOG + \
|
2020-06-24 15:18:40 +00:00
|
|
|
"_" + str(id) + ".log &"
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def getNCClientCmd(self, id):
|
|
|
|
s = "dd if=/dev/urandom ibs=" + self.ddibs + \
|
|
|
|
" obs=" + self.ddobs + \
|
|
|
|
" count=" + self.ddcount + \
|
2020-06-25 12:56:47 +00:00
|
|
|
" | " + NC.PV_BIN + \
|
2020-06-24 15:18:40 +00:00
|
|
|
" -g " + self.pvg + " -z " + self.pvz + \
|
|
|
|
" -q --rate-limit " + self.pvRateLimit + \
|
2020-06-25 12:56:47 +00:00
|
|
|
" | " + NC.NC_BIN + " " + \
|
2020-06-24 15:18:40 +00:00
|
|
|
" -p " + self.ncClientPort[id] + " " + \
|
2020-06-29 14:23:39 +00:00
|
|
|
self.topo_config.get_server_ip() + " " + \
|
2020-06-24 15:18:40 +00:00
|
|
|
self.ncServerPort + " " + \
|
|
|
|
"&>" + NCPV.CLIENT_NC_LOG + \
|
|
|
|
"_" + str(id) + ".log"
|
|
|
|
print(s)
|
|
|
|
return s
|
2020-06-25 12:56:47 +00:00
|
|
|
|
2020-06-24 15:18:40 +00:00
|
|
|
def getPvPidCmd(self):
|
|
|
|
s = "pgrep -n pv"
|
|
|
|
return s
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
super(NCPV, self).clean()
|
|
|
|
|
|
|
|
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.command_to(self.topo_config.server, cmd)
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
cmd = self.getNCClientCmd(i)
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo_config.client.sendCmd(cmd)
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
cmd = self.getPvPidCmd()
|
|
|
|
self.pvPid = None
|
|
|
|
while self.pvPid == None or self.pvPid == "":
|
2020-06-25 08:53:56 +00:00
|
|
|
self.pvPid = self.topo.command_to(self.topo_config.server, cmd)[:-1]
|
2020-06-24 15:18:40 +00:00
|
|
|
print("guessing pv pid ... :" + str(self.pvPid))
|
|
|
|
|
|
|
|
cmd = self.getPvChangeCmd()
|
|
|
|
print(cmd)
|
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_config.client.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
|
|
|
|