2020-06-26 06:52:56 +00:00
|
|
|
from core.experiment import Experiment, ExperimentParameter
|
2020-06-24 15:18:40 +00:00
|
|
|
import os
|
|
|
|
|
2020-06-25 13:56:14 +00:00
|
|
|
|
2020-06-26 06:52:56 +00:00
|
|
|
class MsgParameter(ExperimentParameter):
|
2020-06-25 13:56:14 +00:00
|
|
|
CLIENT_SLEEP = "msgClientSleep"
|
|
|
|
SERVER_SLEEP = "msgServerSleep"
|
|
|
|
NB_REQUESTS = "msgNbRequests"
|
|
|
|
BYTES = "msgBytes"
|
|
|
|
|
2020-06-26 06:52:56 +00:00
|
|
|
def __init__(self, experiment_parameter_filename):
|
|
|
|
super(MsgParameter, self).__init__(experiment_parameter_filename)
|
2020-06-25 13:56:14 +00:00
|
|
|
self.default_parameters.update({
|
|
|
|
MsgParameter.CLIENT_SLEEP: "5.0",
|
|
|
|
MsgParameter.SERVER_SLEEP: "5.0",
|
|
|
|
MsgParameter.NB_REQUESTS: "5",
|
|
|
|
MsgParameter.BYTES: "1200",
|
|
|
|
})
|
|
|
|
|
2020-06-26 06:52:56 +00:00
|
|
|
class Msg(Experiment):
|
2020-06-24 15:18:40 +00:00
|
|
|
NAME = "msg"
|
2020-06-25 14:57:27 +00:00
|
|
|
PARAMETER_CLASS = MsgParameter
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
SERVER_LOG = "msg_server.log"
|
|
|
|
CLIENT_LOG = "msg_client.log"
|
|
|
|
CLIENT_ERR = "msg_client.err"
|
|
|
|
PING_OUTPUT = "ping.log"
|
|
|
|
|
2020-06-26 06:52:56 +00:00
|
|
|
def __init__(self, experiment_parameter_filename, topo, topo_config):
|
|
|
|
super(Msg, 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
|
|
|
Msg.PING_OUTPUT )
|
2020-06-26 06:52:56 +00:00
|
|
|
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
|
2020-06-25 08:53:56 +00:00
|
|
|
for i in range(0, self.topo_config.getClientInterfaceCount()):
|
|
|
|
cmd = self.pingCommand(self.topo_config.getClientIP(i),
|
|
|
|
self.topo_config.getServerIP(), n = count)
|
|
|
|
self.topo.command_to(self.topo_config.client, cmd)
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
def pingCommand(self, fromIP, toIP, n=5):
|
|
|
|
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
|
|
|
|
" >> " + Msg.PING_OUTPUT
|
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
2020-06-25 12:56:47 +00:00
|
|
|
def load_parameters(self):
|
2020-06-26 06:52:56 +00:00
|
|
|
self.client_sleep = self.experiment_parameter.get(MsgParameter.CLIENT_SLEEP)
|
|
|
|
self.server_sleep = self.experiment_parameter.get(MsgParameter.SERVER_SLEEP)
|
|
|
|
self.nb_requests = self.experiment_parameter.get(MsgParameter.NB_REQUESTS)
|
|
|
|
self.bytes = self.experiment_parameter.get(MsgParameter.BYTES)
|
2020-06-24 15:18:40 +00:00
|
|
|
|
|
|
|
def prepare(self):
|
|
|
|
super(Msg, 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
|
|
|
Msg.CLIENT_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
|
|
|
Msg.SERVER_LOG)
|
|
|
|
|
2020-06-25 13:56:14 +00:00
|
|
|
def get_msg_server_cmd(self):
|
|
|
|
s = "python {}/../utils/msg_server.py --sleep {} --bytes {} &> {}&".format(
|
|
|
|
os.path.dirname(os.path.abspath(__file__)), self.server_sleep, self.bytes,
|
|
|
|
Msg.SERVER_LOG)
|
2020-06-24 15:18:40 +00:00
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
2020-06-25 13:56:14 +00:00
|
|
|
def get_msg_client_cmd(self, daemon=False):
|
|
|
|
s = "python {}/../utils/msg_client.py --sleep {} --nb {} --bytes {} > {} 2> {} {}".format(
|
|
|
|
os.path.dirname(os.path.abspath(__file__)), self.client_sleep, self.nb_requests,
|
|
|
|
self.bytes, Msg.CLIENT_LOG, Msg.CLIENT_ERR, "&" if daemon else "")
|
2020-06-24 15:18:40 +00:00
|
|
|
print(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
super(Msg, self).clean()
|
|
|
|
|
|
|
|
def run(self):
|
2020-06-25 13:56:14 +00:00
|
|
|
cmd = self.get_msg_server_cmd()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.server, "netstat -sn > netstat_server_before")
|
|
|
|
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.command_to(self.topo_config.client, "sleep 2")
|
2020-06-25 13:56:14 +00:00
|
|
|
cmd = self.get_msg_client_cmd()
|
2020-06-25 08:53:56 +00:00
|
|
|
self.topo.command_to(self.topo_config.client, "netstat -sn > netstat_client_before")
|
|
|
|
self.topo.command_to(self.topo_config.client, cmd)
|
|
|
|
self.topo.command_to(self.topo_config.server, "netstat -sn > netstat_server_after")
|
|
|
|
self.topo.command_to(self.topo_config.client, "netstat -sn > netstat_client_after")
|
|
|
|
self.topo.command_to(self.topo_config.server, "pkill -f msg_server.py")
|
|
|
|
self.topo.command_to(self.topo_config.client, "sleep 2")
|