92 lines
3.7 KiB
Python
92 lines
3.7 KiB
Python
from core.experiment import Experiment, ExperimentParameter
|
|
import os
|
|
|
|
|
|
class MsgParameter(ExperimentParameter):
|
|
CLIENT_SLEEP = "msgClientSleep"
|
|
SERVER_SLEEP = "msgServerSleep"
|
|
NB_REQUESTS = "msgNbRequests"
|
|
BYTES = "msgBytes"
|
|
|
|
def __init__(self, experiment_parameter_filename):
|
|
super(MsgParameter, self).__init__(experiment_parameter_filename)
|
|
self.default_parameters.update({
|
|
MsgParameter.CLIENT_SLEEP: "5.0",
|
|
MsgParameter.SERVER_SLEEP: "5.0",
|
|
MsgParameter.NB_REQUESTS: "5",
|
|
MsgParameter.BYTES: "1200",
|
|
})
|
|
|
|
class Msg(Experiment):
|
|
NAME = "msg"
|
|
PARAMETER_CLASS = MsgParameter
|
|
|
|
SERVER_LOG = "msg_server.log"
|
|
CLIENT_LOG = "msg_client.log"
|
|
CLIENT_ERR = "msg_client.err"
|
|
PING_OUTPUT = "ping.log"
|
|
|
|
def __init__(self, experiment_parameter_filename, topo, topo_config):
|
|
super(Msg, self).__init__(experiment_parameter_filename, topo, topo_config)
|
|
self.load_parameters()
|
|
self.ping()
|
|
|
|
def ping(self):
|
|
self.topo.command_to(self.topo_config.client, "rm " + \
|
|
Msg.PING_OUTPUT )
|
|
count = self.experiment_parameter.get(ExperimentParameter.PING_COUNT)
|
|
for i in range(0, self.topo_config.client_interface_count()):
|
|
cmd = self.ping_command(self.topo_config.getClientIP(i),
|
|
self.topo_config.getServerIP(), n = count)
|
|
self.topo.command_to(self.topo_config.client, cmd)
|
|
|
|
def ping_command(self, fromIP, toIP, n=5):
|
|
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
|
|
" >> " + Msg.PING_OUTPUT
|
|
print(s)
|
|
return s
|
|
|
|
def load_parameters(self):
|
|
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)
|
|
|
|
def prepare(self):
|
|
super(Msg, self).prepare()
|
|
self.topo.command_to(self.topo_config.client, "rm " + \
|
|
Msg.CLIENT_LOG)
|
|
self.topo.command_to(self.topo_config.server, "rm " + \
|
|
Msg.SERVER_LOG)
|
|
|
|
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)
|
|
print(s)
|
|
return s
|
|
|
|
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 "")
|
|
print(s)
|
|
return s
|
|
|
|
def clean(self):
|
|
super(Msg, self).clean()
|
|
|
|
def run(self):
|
|
cmd = self.get_msg_server_cmd()
|
|
self.topo.command_to(self.topo_config.server, "netstat -sn > netstat_server_before")
|
|
self.topo.command_to(self.topo_config.server, cmd)
|
|
|
|
self.topo.command_to(self.topo_config.client, "sleep 2")
|
|
cmd = self.get_msg_client_cmd()
|
|
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")
|