diff --git a/config/https/topo b/config/https/topo new file mode 100644 index 0000000..1e5f37d --- /dev/null +++ b/config/https/topo @@ -0,0 +1,5 @@ +leftSubnet:10.0. +rightSubnet:10.1. +path_0:100,20,4 +path_1:1,20,4 +topoType:MultiIf diff --git a/config/https/xp b/config/https/xp new file mode 100644 index 0000000..c09aff7 --- /dev/null +++ b/config/https/xp @@ -0,0 +1,5 @@ +xpType:https +clientPcap:yes +kpms:fullmesh +kpmc:fullmesh +rmem:300000 300000 300000 diff --git a/core/experience.py b/core/experience.py index 1ea220e..83125c8 100644 --- a/core/experience.py +++ b/core/experience.py @@ -2,20 +2,25 @@ from .parameter import ExperienceParameter from topos.multi_interface import MultiInterfaceTopo class Experience(object): - PING = "ping" + """ + Base class to instantiate an experience to perform. + + This class is not instantiable as it. You must define a child class with the + `NAME` attribute. + """ + NCPV = "ncpv" NC = "nc" - NONE = "none" + HTTPS = "https" HTTP = "http" EPLOAD = "epload" NETPERF = "netperf" - AB = "ab" + SIRI = "siri" SENDFILE = "sendfile" VLC = "vlc" IPERF = "iperf" - DITG = "ditg" MSG = "msg" SIRIHTTP = "sirihttp" SIRIMSG = "sirimsg" diff --git a/core/topo.py b/core/topo.py index 71f084e..39a7146 100644 --- a/core/topo.py +++ b/core/topo.py @@ -202,11 +202,11 @@ class TopoParameter(Parameter): class Topo(object): """ - Base class to instantiate a topology. + Base class to instantiate a topology. - This class is not instantiable as it. You must define a child class with the - `NAME` attribute. - """ + This class is not instantiable as it. You must define a child class with the + `NAME` attribute. + """ mininetBuilder = "mininet" topoAttr = "topoType" switchNamePrefix = "s" @@ -264,11 +264,11 @@ class Topo(object): class TopoConfig(object): """ - Base class to instantiate a topology. + Base class to instantiate a topology. - This class is not instantiable as it. You must define a child class with the - `NAME` attribute. - """ + This class is not instantiable as it. You must define a child class with the + `NAME` attribute. + """ PING_OUTPUT = "ping.log" diff --git a/experiences/__init__.py b/experiences/__init__.py new file mode 100644 index 0000000..607b7a8 --- /dev/null +++ b/experiences/__init__.py @@ -0,0 +1,11 @@ +import importlib +import pkgutil +import os + +from core.experience import Experience + +pkg_dir = os.path.dirname(__file__) +for (module_loader, name, ispkg) in pkgutil.iter_modules([pkg_dir]): + importlib.import_module('.' + name, __package__) + +EXPERIENCES = {cls.NAME: cls for cls in Experience.__subclasses__()} \ No newline at end of file diff --git a/experiences/ab.py b/experiences/ab.py new file mode 100644 index 0000000..00df41c --- /dev/null +++ b/experiences/ab.py @@ -0,0 +1,78 @@ +from core.experience import Experience, ExperienceParameter +import os + +class AB(Experience): + NAME = "ab" + + SERVER_LOG = "ab_server.log" + CLIENT_LOG = "ab_client.log" + AB_BIN = "ab" + PING_OUTPUT = "ping.log" + + def __init__(self, xpParamFile, mpTopo, mpConfig): + super(AB, self).__init__(xpParamFile, mpTopo, mpConfig) + self.loadParam() + self.ping() + super(AB, self).classicRun() + + def ping(self): + self.mpTopo.commandTo(self.mpConfig.client, + "rm " + AB.PING_OUTPUT) + count = self.xpParam.getParam(ExperienceParameter.PINGCOUNT) + for i in range(0, self.mpConfig.getClientInterfaceCount()): + cmd = self.pingCommand(self.mpConfig.getClientIP(i), + self.mpConfig.getServerIP(), n = count) + self.mpTopo.commandTo(self.mpConfig.client, cmd) + + def pingCommand(self, fromIP, toIP, n=5): + s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ + " >> " + AB.PING_OUTPUT + print(s) + return s + + def loadParam(self): + self.file = self.xpParam.getParam(ExperienceParameter.HTTPFILE) + self.random_size = self.xpParam.getParam(ExperienceParameter.HTTPRANDOMSIZE) + self.concurrent_requests = self.xpParam.getParam(ExperienceParameter.ABCONCURRENTREQUESTS) + self.timelimit = self.xpParam.getParam(ExperienceParameter.ABTIMELIMIT) + + def prepare(self): + Experience.prepare(self) + self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ + AB.CLIENT_LOG ) + self.mpTopo.commandTo(self.mpConfig.server, "rm " + \ + AB.SERVER_LOG ) + if self.file == "random": + self.mpTopo.commandTo(self.mpConfig.client, + "dd if=/dev/urandom of=random bs=1K count=" + \ + self.random_size) + + def getAbServerCmd(self): + s = "python " + os.path.dirname(os.path.abspath(__file__)) + \ + "/utils/http_server.py &>" + AB.SERVER_LOG + "&" + print(s) + return s + + def getAbClientCmd(self): + s = AB.AB_BIN + " -c " + self.concurrent_requests + " -t " + \ + self.timelimit + " http://" + self.mpConfig.getServerIP() + "/" + self.file + \ + " &>" + AB.CLIENT_LOG + print(s) + return s + + def clean(self): + Experience.clean(self) + if self.file == "random": + self.mpTopo.commandTo(self.mpConfig.client, "rm random*") + #todo use cst + #self.mpTopo.commandTo(self.mpConfig.server, "killall netcat") + + + def run(self): + cmd = self.getAbServerCmd() + self.mpTopo.commandTo(self.mpConfig.server, cmd) + + self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") + cmd = self.getAbClientCmd() + self.mpTopo.commandTo(self.mpConfig.client, cmd) + self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") diff --git a/experiences/ditg.py b/experiences/ditg.py new file mode 100644 index 0000000..b118192 --- /dev/null +++ b/experiences/ditg.py @@ -0,0 +1,86 @@ +from core.experience import Experience, ExperienceParameter +import os + +class DITG(Experience): + NAME = "ditg" + + DITG_LOG = "ditg.log" + DITG_SERVER_LOG = "ditg_server.log" + ITGDEC_BIN = "/home/mininet/D-ITG-2.8.1-r1023/bin/ITGDec" + ITGRECV_BIN = "/home/mininet/D-ITG-2.8.1-r1023/bin/ITGRecv" + ITGSEND_BIN = "/home/mininet/D-ITG-2.8.1-r1023/bin/ITGSend" + DITG_TEMP_LOG = "snd_log_file" + DITG_SERVER_TEMP_LOG = "recv_log_file" + PING_OUTPUT = "ping.log" + + + def __init__(self, xpParamFile, mpTopo, mpConfig): + super(DITG, self).__init__(xpParamFile, mpTopo, mpConfig) + self.loadParam() + self.ping() + super(DITG, self).classicRun() + + def ping(self): + self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ + Experience.PING_OUTPUT) + count = self.xpParam.getParam(ExperienceParameter.PINGCOUNT) + for i in range(0, self.mpConfig.getClientInterfaceCount()): + cmd = self.pingCommand(self.mpConfig.getClientIP(i), + self.mpConfig.getServerIP(), n = count) + self.mpTopo.commandTo(self.mpConfig.client, cmd) + + def pingCommand(self, fromIP, toIP, n=5): + s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ + " >> " + DITG.PING_OUTPUT + print(s) + return s + + def loadParam(self): + self.kbytes = self.xpParam.getParam(ExperienceParameter.DITGKBYTES) + self.constant_packet_size = self.xpParam.getParam(ExperienceParameter.DITGCONSTANTPACKETSIZE) + self.mean_poisson_packets_sec = self.xpParam.getParam(ExperienceParameter.DITGMEANPOISSONPACKETSSEC) + self.constant_packets_sec = self.xpParam.getParam(ExperienceParameter.DITGCONSTANTPACKETSSEC) + self.bursts_on_packets_sec = self.xpParam.getParam(ExperienceParameter.DITGBURSTSONPACKETSSEC) + self.bursts_off_packets_sec = self.xpParam.getParam(ExperienceParameter.DITGBURSTSOFFPACKETSSEC) + + def prepare(self): + super(DITG, self).prepare() + self.mpTopo.commandTo(self.mpConfig.client, "rm " + DITG.DITG_LOG) + self.mpTopo.commandTo(self.mpConfig.server, "rm " + DITG.DITG_SERVER_LOG) + self.mpTopo.commandTo(self.mpConfig.client, "rm " + DITG.DITG_TEMP_LOG) + + def getClientCmd(self): + s = DITG.ITGSEND_BIN + " -a " + self.mpConfig.getServerIP() + \ + " -T TCP -k " + self.kbytes + " -l " + DITG.DITG_TEMP_LOG + + if self.constant_packet_size != "0": + s += " -c " + self.constant_packet_size + elif self.mean_poisson_packets_sec != "0": + s += " -O " + self.mean_poisson_packets_sec + elif self.constant_packets_sec != "0": + s += " -C " + self.constant_packets_sec + elif self.bursts_on_packets_sec != "0" and self.bursts_off_packets_sec != "0": + s += " -B C " + self.bursts_on_packets_sec + " C " + self.bursts_off_packets_sec + + s += " && " + DITG.ITGDEC_BIN + " " + DITG.DITG_TEMP_LOG + " &> " + DITG.DITG_LOG + print(s) + return s + + def getServerCmd(self): + s = DITG.ITGRECV_BIN + " -l " + DITG.DITG_SERVER_TEMP_LOG + " &" + print(s) + return s + + def clean(self): + super(DITG, self).clean() + + def run(self): + cmd = self.getServerCmd() + self.mpTopo.commandTo(self.mpConfig.server, cmd) + + self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") + cmd = self.getClientCmd() + self.mpTopo.commandTo(self.mpConfig.client, cmd) + self.mpTopo.commandTo(self.mpConfig.server, "pkill -9 -f ITGRecv") + self.mpTopo.commandTo(self.mpConfig.server, DITG.ITGDEC_BIN + " " + DITG.DITG_SERVER_TEMP_LOG + " &> " + DITG.DITG_SERVER_LOG) + self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") diff --git a/experiences/http.py b/experiences/http.py new file mode 100644 index 0000000..9d8e543 --- /dev/null +++ b/experiences/http.py @@ -0,0 +1,75 @@ +from core.experience import Experience, ExperienceParameter +import os + +class HTTP(Experience): + NAME = "http" + + SERVER_LOG = "http_server.log" + CLIENT_LOG = "http_client.log" + WGET_BIN = "wget" + PING_OUTPUT = "ping.log" + + def __init__(self, xpParamFile, mpTopo, mpConfig): + super(HTTP, self).__init__(xpParamFile, mpTopo, mpConfig) + self.loadParam() + self.ping() + super(HTTP, self).classicRun() + + def ping(self): + self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ + HTTP.PING_OUTPUT ) + count = self.xpParam.getParam(ExperienceParameter.PINGCOUNT) + for i in range(0, self.mpConfig.getClientInterfaceCount()): + cmd = self.pingCommand(self.mpConfig.getClientIP(i), + self.mpConfig.getServerIP(), n = count) + self.mpTopo.commandTo(self.mpConfig.client, cmd) + + def pingCommand(self, fromIP, toIP, n=5): + s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ + " >> " + HTTP.PING_OUTPUT + print(s) + return s + + def loadParam(self): + self.file = self.xpParam.getParam(ExperienceParameter.HTTPFILE) + self.random_size = self.xpParam.getParam(ExperienceParameter.HTTPRANDOMSIZE) + + def prepare(self): + super(HTTP, self).prepare() + self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ + HTTP.CLIENT_LOG ) + self.mpTopo.commandTo(self.mpConfig.server, "rm " + \ + HTTP.SERVER_LOG ) + if self.file == "random": + self.mpTopo.commandTo(self.mpConfig.client, + "dd if=/dev/urandom of=random bs=1K count=" + \ + self.random_size) + + def getHTTPServerCmd(self): + s = "/etc/init.d/apache2 restart &>" + HTTP.SERVER_LOG + "&" + print(s) + return s + + def getHTTPClientCmd(self): + s = "(time " + HTTP.WGET_BIN + " http://" + self.mpConfig.getServerIP() + \ + "/" + self.file + " --no-check-certificate) &>" + HTTP.CLIENT_LOG + print(s) + return s + + def clean(self): + super(HTTP, self).clean() + if self.file == "random": + self.mpTopo.commandTo(self.mpConfig.client, "rm random*") + + def run(self): + cmd = self.getHTTPServerCmd() + self.mpTopo.commandTo(self.mpConfig.server, "netstat -sn > netstat_server_before") + self.mpTopo.commandTo(self.mpConfig.server, cmd) + + self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") + cmd = self.getHTTPClientCmd() + self.mpTopo.commandTo(self.mpConfig.client, "netstat -sn > netstat_client_before") + self.mpTopo.commandTo(self.mpConfig.client, cmd) + self.mpTopo.commandTo(self.mpConfig.server, "netstat -sn > netstat_server_after") + self.mpTopo.commandTo(self.mpConfig.client, "netstat -sn > netstat_client_after") + self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") diff --git a/experiences/https.py b/experiences/https.py new file mode 100644 index 0000000..01397ec --- /dev/null +++ b/experiences/https.py @@ -0,0 +1,78 @@ +from core.experience import Experience, ExperienceParameter +import os + +class HTTPS(Experience): + NAME = "https" + + SERVER_LOG = "https_server.log" + CLIENT_LOG = "https_client.log" + WGET_BIN = "wget" + PING_OUTPUT = "ping.log" + + def __init__(self, xpParamFile, mpTopo, mpConfig): + super(HTTPS, self).__init__(xpParamFile, mpTopo, mpConfig) + self.loadParam() + self.ping() + super(HTTPS, self).classicRun() + + def ping(self): + self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ + HTTPS.PING_OUTPUT ) + count = self.xpParam.getParam(ExperienceParameter.PINGCOUNT) + for i in range(0, self.mpConfig.getClientInterfaceCount()): + cmd = self.pingCommand(self.mpConfig.getClientIP(i), + self.mpConfig.getServerIP(), n = count) + self.mpTopo.commandTo(self.mpConfig.client, cmd) + + def pingCommand(self, fromIP, toIP, n=5): + s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ + " >> " + HTTPS.PING_OUTPUT + print(s) + return s + + def loadParam(self): + self.file = self.xpParam.getParam(ExperienceParameter.HTTPSFILE) + self.random_size = self.xpParam.getParam(ExperienceParameter.HTTPSRANDOMSIZE) + + def prepare(self): + super(HTTPS, self).prepare() + self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ + HTTPS.CLIENT_LOG ) + self.mpTopo.commandTo(self.mpConfig.server, "rm " + \ + HTTPS.SERVER_LOG ) + if self.file == "random": + self.mpTopo.commandTo(self.mpConfig.client, + "dd if=/dev/urandom of=random bs=1K count=" + \ + self.random_size) + + def getHTTPSServerCmd(self): + s = "python {}/../utils/https_server.py {}/../utils/server.pem &> {}&".format(os.path.dirname(os.path.abspath(__file__)), + os.path.dirname(os.path.abspath(__file__)), HTTPS.SERVER_LOG) + print(s) + return s + + def getHTTPSClientCmd(self): + s = "(time " + HTTPS.WGET_BIN + " https://" + self.mpConfig.getServerIP() + \ + "/" + self.file + " --no-check-certificate) &>" + HTTPS.CLIENT_LOG + print(s) + return s + + def clean(self): + super(HTTPS, self).clean() + if self.file == "random": + self.mpTopo.commandTo(self.mpConfig.client, "rm random*") + + def run(self): + cmd = self.getHTTPSServerCmd() + self.mpTopo.commandTo(self.mpConfig.server, "netstat -sn > netstat_server_before") + self.mpTopo.commandTo(self.mpConfig.server, cmd) + + print("Waiting for the server to run") + self.mpTopo.commandTo(self.mpConfig.client, "sleep 15") + cmd = self.getHTTPSClientCmd() + self.mpTopo.commandTo(self.mpConfig.client, "netstat -sn > netstat_client_before") + self.mpTopo.commandTo(self.mpConfig.client, cmd) + self.mpTopo.commandTo(self.mpConfig.server, "netstat -sn > netstat_server_after") + self.mpTopo.commandTo(self.mpConfig.client, "netstat -sn > netstat_client_after") + self.mpTopo.commandTo(self.mpConfig.server, "pkill -f https_server.py") + self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") diff --git a/experiences/none.py b/experiences/none.py new file mode 100644 index 0000000..519c86e --- /dev/null +++ b/experiences/none.py @@ -0,0 +1,17 @@ +from core.experience import Experience, ExperienceParameter + +class NoneExperience(Experience): + NAME = "none" + + def __init__(self, xpParamFile, mpTopo, mpConfig): + super(NoneExperience, self).__init__(xpParamFile, mpTopo, mpConfig) + super(NoneExperience, self).classicRun() + + def prepare(self): + Experience.prepare(self) + + def clean(self): + Experience.clean(self) + + def run(self): + self.mpTopo.getCLI() diff --git a/mpExperiencePing.py b/experiences/ping.py similarity index 70% rename from mpExperiencePing.py rename to experiences/ping.py index 82055fd..e0bb407 100644 --- a/mpExperiencePing.py +++ b/experiences/ping.py @@ -1,21 +1,23 @@ from core.experience import Experience, ExperienceParameter -class ExperiencePing(Experience): +class Ping(Experience): + NAME = "ping" PING_OUTPUT = "ping.log" def __init__(self, xpParamFile, mpTopo, mpConfig): - Experience.__init__(self, xpParamFile, mpTopo, mpConfig) - Experience.classicRun(self) - def prepapre(self): - Experience.prepare(self) + super(Ping, self).__init__(xpParamFile, mpTopo, mpConfig) + super(Ping, self).classicRun() + + def prepare(self): + super(Ping, self).prepare() def clean(self): - Experience.clean(self) + super(Ping, self).clean() def run(self): self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ - ExperiencePing.PING_OUTPUT ) + Ping.PING_OUTPUT ) count = self.xpParam.getParam(ExperienceParameter.PINGCOUNT) for i in range(0, self.mpConfig.getClientInterfaceCount()): cmd = self.pingCommand(self.mpConfig.getClientIP(i), @@ -24,6 +26,6 @@ class ExperiencePing(Experience): def pingCommand(self, fromIP, toIP, n=5): s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ - " >> " + ExperiencePing.PING_OUTPUT + " >> " + Ping.PING_OUTPUT print(s) return s diff --git a/mpExperienceAb.py b/mpExperienceAb.py deleted file mode 100644 index 11c050f..0000000 --- a/mpExperienceAb.py +++ /dev/null @@ -1,79 +0,0 @@ -from core.experience import Experience, ExperienceParameter -import os - -class ExperienceAb(Experience): - SERVER_LOG = "ab_server.log" - CLIENT_LOG = "ab_client.log" - AB_BIN = "ab" - PING_OUTPUT = "ping.log" - - def __init__(self, xpParamFile, mpTopo, mpConfig): - Experience.__init__(self, xpParamFile, mpTopo, mpConfig) - self.loadParam() - self.ping() - Experience.classicRun(self) - - def ping(self): - self.mpTopo.commandTo(self.mpConfig.client, - "rm " + ExperienceAb.PING_OUTPUT) - count = self.xpParam.getParam(ExperienceParameter.PINGCOUNT) - for i in range(0, self.mpConfig.getClientInterfaceCount()): - cmd = self.pingCommand(self.mpConfig.getClientIP(i), - self.mpConfig.getServerIP(), n = count) - self.mpTopo.commandTo(self.mpConfig.client, cmd) - - def pingCommand(self, fromIP, toIP, n=5): - s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ - " >> " + ExperienceAb.PING_OUTPUT - print(s) - return s - - def loadParam(self): - """ - todo : param LD_PRELOAD ?? - """ - self.file = self.xpParam.getParam(ExperienceParameter.HTTPFILE) - self.random_size = self.xpParam.getParam(ExperienceParameter.HTTPRANDOMSIZE) - self.concurrent_requests = self.xpParam.getParam(ExperienceParameter.ABCONCURRENTREQUESTS) - self.timelimit = self.xpParam.getParam(ExperienceParameter.ABTIMELIMIT) - - def prepare(self): - Experience.prepare(self) - self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ - ExperienceAb.CLIENT_LOG ) - self.mpTopo.commandTo(self.mpConfig.server, "rm " + \ - ExperienceAb.SERVER_LOG ) - if self.file == "random": - self.mpTopo.commandTo(self.mpConfig.client, - "dd if=/dev/urandom of=random bs=1K count=" + \ - self.random_size) - - def getAbServerCmd(self): - s = "python " + os.path.dirname(os.path.abspath(__file__)) + \ - "/utils/http.py &>" + ExperienceAb.SERVER_LOG + "&" - print(s) - return s - - def getAbClientCmd(self): - s = ExperienceAb.AB_BIN + " -c " + self.concurrent_requests + " -t " + \ - self.timelimit + " http://" + self.mpConfig.getServerIP() + "/" + self.file + \ - " &>" + ExperienceAb.CLIENT_LOG - print(s) - return s - - def clean(self): - Experience.clean(self) - if self.file == "random": - self.mpTopo.commandTo(self.mpConfig.client, "rm random*") - #todo use cst - #self.mpTopo.commandTo(self.mpConfig.server, "killall netcat") - - - def run(self): - cmd = self.getAbServerCmd() - self.mpTopo.commandTo(self.mpConfig.server, cmd) - - self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") - cmd = self.getAbClientCmd() - self.mpTopo.commandTo(self.mpConfig.client, cmd) - self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") diff --git a/mpExperienceDITG.py b/mpExperienceDITG.py deleted file mode 100644 index 49ea728..0000000 --- a/mpExperienceDITG.py +++ /dev/null @@ -1,90 +0,0 @@ -from core.experience import Experience, ExperienceParameter -import os - -class ExperienceDITG(Experience): - DITG_LOG = "ditg.log" - DITG_SERVER_LOG = "ditg_server.log" - ITGDEC_BIN = "/home/mininet/D-ITG-2.8.1-r1023/bin/ITGDec" - ITGRECV_BIN = "/home/mininet/D-ITG-2.8.1-r1023/bin/ITGRecv" - ITGSEND_BIN = "/home/mininet/D-ITG-2.8.1-r1023/bin/ITGSend" - DITG_TEMP_LOG = "snd_log_file" - DITG_SERVER_TEMP_LOG = "recv_log_file" - PING_OUTPUT = "ping.log" - - - def __init__(self, xpParamFile, mpTopo, mpConfig): - Experience.__init__(self, xpParamFile, mpTopo, mpConfig) - self.loadParam() - self.ping() - Experience.classicRun(self) - - def ping(self): - self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ - ExperienceDITG.PING_OUTPUT) - count = self.xpParam.getParam(ExperienceParameter.PINGCOUNT) - for i in range(0, self.mpConfig.getClientInterfaceCount()): - cmd = self.pingCommand(self.mpConfig.getClientIP(i), - self.mpConfig.getServerIP(), n = count) - self.mpTopo.commandTo(self.mpConfig.client, cmd) - - def pingCommand(self, fromIP, toIP, n=5): - s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ - " >> " + ExperienceDITG.PING_OUTPUT - print(s) - return s - - def loadParam(self): - """ - todo : param LD_PRELOAD ?? - """ - self.kbytes = self.xpParam.getParam(ExperienceParameter.DITGKBYTES) - self.constant_packet_size = self.xpParam.getParam(ExperienceParameter.DITGCONSTANTPACKETSIZE) - self.mean_poisson_packets_sec = self.xpParam.getParam(ExperienceParameter.DITGMEANPOISSONPACKETSSEC) - self.constant_packets_sec = self.xpParam.getParam(ExperienceParameter.DITGCONSTANTPACKETSSEC) - self.bursts_on_packets_sec = self.xpParam.getParam(ExperienceParameter.DITGBURSTSONPACKETSSEC) - self.bursts_off_packets_sec = self.xpParam.getParam(ExperienceParameter.DITGBURSTSOFFPACKETSSEC) - - def prepare(self): - Experience.prepare(self) - self.mpTopo.commandTo(self.mpConfig.client, "rm " + ExperienceDITG.DITG_LOG) - self.mpTopo.commandTo(self.mpConfig.server, "rm " + ExperienceDITG.DITG_SERVER_LOG) - self.mpTopo.commandTo(self.mpConfig.client, "rm " + ExperienceDITG.DITG_TEMP_LOG) - - def getClientCmd(self): - s = ExperienceDITG.ITGSEND_BIN + " -a " + self.mpConfig.getServerIP() + \ - " -T TCP -k " + self.kbytes + " -l " + ExperienceDITG.DITG_TEMP_LOG - - if self.constant_packet_size != "0": - s += " -c " + self.constant_packet_size - elif self.mean_poisson_packets_sec != "0": - s += " -O " + self.mean_poisson_packets_sec - elif self.constant_packets_sec != "0": - s += " -C " + self.constant_packets_sec - elif self.bursts_on_packets_sec != "0" and self.bursts_off_packets_sec != "0": - s += " -B C " + self.bursts_on_packets_sec + " C " + self.bursts_off_packets_sec - - s += " && " + ExperienceDITG.ITGDEC_BIN + " " + ExperienceDITG.DITG_TEMP_LOG + " &> " + ExperienceDITG.DITG_LOG - print(s) - return s - - def getServerCmd(self): - s = ExperienceDITG.ITGRECV_BIN + " -l " + ExperienceDITG.DITG_SERVER_TEMP_LOG + " &" - print(s) - return s - - def clean(self): - Experience.clean(self) - #todo use cst - #self.mpTopo.commandTo(self.mpConfig.server, "killall netcat") - - - def run(self): - cmd = self.getServerCmd() - self.mpTopo.commandTo(self.mpConfig.server, cmd) - - self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") - cmd = self.getClientCmd() - self.mpTopo.commandTo(self.mpConfig.client, cmd) - self.mpTopo.commandTo(self.mpConfig.server, "pkill -9 -f ITGRecv") - self.mpTopo.commandTo(self.mpConfig.server, ExperienceDITG.ITGDEC_BIN + " " + ExperienceDITG.DITG_SERVER_TEMP_LOG + " &> " + ExperienceDITG.DITG_SERVER_LOG) - self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") diff --git a/mpExperienceHTTP.py b/mpExperienceHTTP.py deleted file mode 100644 index 73d3af0..0000000 --- a/mpExperienceHTTP.py +++ /dev/null @@ -1,79 +0,0 @@ -from core.experience import Experience, ExperienceParameter -import os - -class ExperienceHTTP(Experience): - SERVER_LOG = "http_server.log" - CLIENT_LOG = "http_client.log" - WGET_BIN = "wget" - PING_OUTPUT = "ping.log" - - def __init__(self, xpParamFile, mpTopo, mpConfig): - Experience.__init__(self, xpParamFile, mpTopo, mpConfig) - self.loadParam() - self.ping() - Experience.classicRun(self) - - def ping(self): - self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ - ExperienceHTTP.PING_OUTPUT ) - count = self.xpParam.getParam(ExperienceParameter.PINGCOUNT) - for i in range(0, self.mpConfig.getClientInterfaceCount()): - cmd = self.pingCommand(self.mpConfig.getClientIP(i), - self.mpConfig.getServerIP(), n = count) - self.mpTopo.commandTo(self.mpConfig.client, cmd) - - def pingCommand(self, fromIP, toIP, n=5): - s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ - " >> " + ExperienceHTTP.PING_OUTPUT - print(s) - return s - - def loadParam(self): - """ - todo : param LD_PRELOAD ?? - """ - self.file = self.xpParam.getParam(ExperienceParameter.HTTPFILE) - self.random_size = self.xpParam.getParam(ExperienceParameter.HTTPRANDOMSIZE) - - def prepare(self): - Experience.prepare(self) - self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ - ExperienceHTTP.CLIENT_LOG ) - self.mpTopo.commandTo(self.mpConfig.server, "rm " + \ - ExperienceHTTP.SERVER_LOG ) - if self.file == "random": - self.mpTopo.commandTo(self.mpConfig.client, - "dd if=/dev/urandom of=random bs=1K count=" + \ - self.random_size) - - def getHTTPServerCmd(self): - s = "/etc/init.d/apache2 restart &>" + ExperienceHTTP.SERVER_LOG + "&" - print(s) - return s - - def getHTTPClientCmd(self): - s = "(time " + ExperienceHTTP.WGET_BIN + " http://" + self.mpConfig.getServerIP() + \ - "/" + self.file + " --no-check-certificate) &>" + ExperienceHTTP.CLIENT_LOG - print(s) - return s - - def clean(self): - Experience.clean(self) - if self.file == "random": - self.mpTopo.commandTo(self.mpConfig.client, "rm random*") - #todo use cst - #self.mpTopo.commandTo(self.mpConfig.server, "killall netcat") - - - def run(self): - cmd = self.getHTTPServerCmd() - self.mpTopo.commandTo(self.mpConfig.server, "netstat -sn > netstat_server_before") - self.mpTopo.commandTo(self.mpConfig.server, cmd) - - self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") - cmd = self.getHTTPClientCmd() - self.mpTopo.commandTo(self.mpConfig.client, "netstat -sn > netstat_client_before") - self.mpTopo.commandTo(self.mpConfig.client, cmd) - self.mpTopo.commandTo(self.mpConfig.server, "netstat -sn > netstat_server_after") - self.mpTopo.commandTo(self.mpConfig.client, "netstat -sn > netstat_client_after") - self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") diff --git a/mpExperienceHTTPS.py b/mpExperienceHTTPS.py deleted file mode 100644 index 9ec3645..0000000 --- a/mpExperienceHTTPS.py +++ /dev/null @@ -1,81 +0,0 @@ -from core.experience import Experience, ExperienceParameter -import os - -class ExperienceHTTPS(Experience): - SERVER_LOG = "https_server.log" - CLIENT_LOG = "https_client.log" - WGET_BIN = "wget" - PING_OUTPUT = "ping.log" - - def __init__(self, xpParamFile, mpTopo, mpConfig): - Experience.__init__(self, xpParamFile, mpTopo, mpConfig) - self.loadParam() - self.ping() - Experience.classicRun(self) - - def ping(self): - self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ - ExperienceHTTPS.PING_OUTPUT ) - count = self.xpParam.getParam(ExperienceParameter.PINGCOUNT) - for i in range(0, self.mpConfig.getClientInterfaceCount()): - cmd = self.pingCommand(self.mpConfig.getClientIP(i), - self.mpConfig.getServerIP(), n = count) - self.mpTopo.commandTo(self.mpConfig.client, cmd) - - def pingCommand(self, fromIP, toIP, n=5): - s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \ - " >> " + ExperienceHTTPS.PING_OUTPUT - print(s) - return s - - def loadParam(self): - """ - todo : param LD_PRELOAD ?? - """ - self.file = self.xpParam.getParam(ExperienceParameter.HTTPSFILE) - self.random_size = self.xpParam.getParam(ExperienceParameter.HTTPSRANDOMSIZE) - - def prepare(self): - Experience.prepare(self) - self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ - ExperienceHTTPS.CLIENT_LOG ) - self.mpTopo.commandTo(self.mpConfig.server, "rm " + \ - ExperienceHTTPS.SERVER_LOG ) - if self.file == "random": - self.mpTopo.commandTo(self.mpConfig.client, - "dd if=/dev/urandom of=random bs=1K count=" + \ - self.random_size) - - def getHTTPSServerCmd(self): - s = "python " + os.path.dirname(os.path.abspath(__file__)) + \ - "/utils/https.py &>" + ExperienceHTTPS.SERVER_LOG + "&" - print(s) - return s - - def getHTTPSClientCmd(self): - s = "(time " +ExperienceHTTPS.WGET_BIN + " https://" + self.mpConfig.getServerIP() + \ - "/" + self.file + " --no-check-certificate) &>" + ExperienceHTTPS.CLIENT_LOG - print(s) - return s - - def clean(self): - Experience.clean(self) - if self.file == "random": - self.mpTopo.commandTo(self.mpConfig.client, "rm random*") - #todo use cst - #self.mpTopo.commandTo(self.mpConfig.server, "killall netcat") - - - def run(self): - cmd = self.getHTTPSServerCmd() - self.mpTopo.commandTo(self.mpConfig.server, "netstat -sn > netstat_server_before") - self.mpTopo.commandTo(self.mpConfig.server, cmd) - - self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") - cmd = self.getHTTPSClientCmd() - self.mpTopo.commandTo(self.mpConfig.client, "netstat -sn > netstat_client_before") - self.mpTopo.commandTo(self.mpConfig.client, cmd) - self.mpTopo.commandTo(self.mpConfig.server, "netstat -sn > netstat_server_after") - self.mpTopo.commandTo(self.mpConfig.client, "netstat -sn > netstat_client_after") - self.mpTopo.commandTo(self.mpConfig.server, "pkill -f https.py") - self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") diff --git a/mpExperienceNone.py b/mpExperienceNone.py deleted file mode 100644 index 17ad731..0000000 --- a/mpExperienceNone.py +++ /dev/null @@ -1,15 +0,0 @@ -from core.experience import Experience, ExperienceParameter - -class ExperienceNone(Experience): - def __init__(self, xpParamFile, mpTopo, mpConfig): - Experience.__init__(self, xpParamFile, mpTopo, mpConfig) - Experience.classicRun(self) - - def prepare(self): - Experience.prepare(self) - - def clean(self): - Experience.clean(self) - - def run(self): - self.mpTopo.getCLI() diff --git a/mpExperienceQUIC.py b/mpExperienceQUIC.py index 01f9828..6206bc9 100644 --- a/mpExperienceQUIC.py +++ b/mpExperienceQUIC.py @@ -70,7 +70,7 @@ class ExperienceQUIC(Experience): def getCongServerCmd(self, congID): s = "python " + os.path.dirname(os.path.abspath(__file__)) + \ - "/utils/https.py &> https_server" + str(congID) + ".log &" + "/utils/https_server.py &> https_server" + str(congID) + ".log &" print(s) return s @@ -123,7 +123,7 @@ class ExperienceQUIC(Experience): self.mpTopo.commandTo(self.mpConfig.server, "pkill -f " + ExperienceQUIC.SERVER_GO_FILE) if isinstance(self.mpConfig, MultiInterfaceCongConfig): for cs in self.mpConfig.cong_servers: - self.mpTopo.commandTo(cs, "pkill -f https.py") + self.mpTopo.commandTo(cs, "pkill -f https_server.py") self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") # Need to delete the go-build directory in tmp; could lead to no more space left error diff --git a/mpXpRunner.py b/mpXpRunner.py index c5984ac..05ed847 100644 --- a/mpXpRunner.py +++ b/mpXpRunner.py @@ -3,27 +3,23 @@ from core.topo import Topo, TopoParameter from mininet_builder import MininetBuilder -import topos +from topos import TOPO_CONFIGS, TOPOS +from experiences import EXPERIENCES -from mpExperiencePing import ExperiencePing from mpExperienceNCPV import ExperienceNCPV from mpExperienceNC import ExperienceNC -from mpExperienceHTTPS import ExperienceHTTPS -from mpExperienceHTTP import ExperienceHTTP from mpExperienceSendFile import ExperienceSendFile from mpExperienceEpload import ExperienceEpload from mpExperienceNetperf import ExperienceNetperf -from mpExperienceAb import ExperienceAb from mpExperienceSiri import ExperienceSiri from mpExperienceVLC import ExperienceVLC from mpExperienceIperf import ExperienceIperf -from mpExperienceDITG import ExperienceDITG from mpExperienceMsg import ExperienceMsg from mpExperienceSiriHTTP import ExperienceSiriHTTP from mpExperienceSiriMsg import ExperienceSiriMsg from mpExperienceQUIC import ExperienceQUIC from mpExperienceQUICSiri import ExperienceQUICSiri -from mpExperienceNone import ExperienceNone + class MpXpRunner: def __init__(self, builderType, topoParamFile, xpParamFile): @@ -47,16 +43,16 @@ class MpXpRunner: builderType) def defTopo(self): t = self.topoParam.getParam(Topo.topoAttr) - if t in topos.topos: - self.Topo = topos.topos[t](self.topoBuilder, self.topoParam) + if t in TOPOS: + self.Topo = TOPOS[t](self.topoBuilder, self.topoParam) else: raise Exception("Unknown topo: {}".format(t)) print(self.Topo) def defConfig(self): t = self.topoParam.getParam(Topo.topoAttr) - if t in topos.configs: - self.TopoConfig = topos.configs[t](self.Topo, self.topoParam) + if t in TOPO_CONFIGS: + self.TopoConfig = TOPO_CONFIGS[t](self.Topo, self.topoParam) else: raise Exception("Unknown topo config: {}".format(t)) @@ -66,33 +62,20 @@ class MpXpRunner: def runXp(self): xp = self.xpParam.getParam(ExperienceParameter.XPTYPE) - if xp ==Experience.PING: - ExperiencePing(self.xpParam, self.Topo, - self.TopoConfig) + if xp in EXPERIENCES: + EXPERIENCES[xp](self.xpParam, self.Topo, self.TopoConfig) elif xp ==Experience.NCPV: ExperienceNCPV(self.xpParam, self.Topo, self.TopoConfig) elif xp ==Experience.NC: ExperienceNC(self.xpParam, self.Topo, self.TopoConfig) - elif xp ==Experience.NONE: - ExperienceNone(self.xpParam, self.Topo, - self.TopoConfig) - elif xp ==Experience.HTTPS: - ExperienceHTTPS(self.xpParam, self.Topo, - self.TopoConfig) - elif xp ==Experience.HTTP: - ExperienceHTTP(self.xpParam, self.Topo, - self.TopoConfig) elif xp ==Experience.EPLOAD: ExperienceEpload(self.xpParam, self.Topo, self.TopoConfig) elif xp ==Experience.NETPERF: ExperienceNetperf(self.xpParam, self.Topo, self.TopoConfig) - elif xp ==Experience.AB: - ExperienceAb(self.xpParam, self.Topo, - self.TopoConfig) elif xp ==Experience.SIRI: ExperienceSiri(self.xpParam, self.Topo, self.TopoConfig) @@ -105,8 +88,6 @@ class MpXpRunner: elif xp ==Experience.IPERF: ExperienceIperf(self.xpParam, self.Topo, self.TopoConfig) - elif xp ==Experience.DITG: - ExperienceDITG(self.xpParam, self.Topo, self.TopoConfig) elif xp ==Experience.MSG: ExperienceMsg(self.xpParam, self.Topo, self.TopoConfig) elif xp ==Experience.SIRIHTTP: @@ -118,7 +99,7 @@ class MpXpRunner: elif xp ==Experience.QUICSIRI: ExperienceQUICSiri(self.xpParam, self.Topo, self.TopoConfig) else: - print("Unfound xp type..." + xp) + raise Exception("Unknown experience {}".format(xp)) def stopTopo(self): self.Topo.stopNetwork() diff --git a/topos/__init__.py b/topos/__init__.py index 353d9f1..c2729a4 100644 --- a/topos/__init__.py +++ b/topos/__init__.py @@ -8,5 +8,5 @@ pkg_dir = os.path.dirname(__file__) for (module_loader, name, ispkg) in pkgutil.iter_modules([pkg_dir]): importlib.import_module('.' + name, __package__) -configs = {cls.NAME: cls for cls in TopoConfig.__subclasses__()} -topos = {cls.NAME: cls for cls in Topo.__subclasses__()} \ No newline at end of file +TOPO_CONFIGS = {cls.NAME: cls for cls in TopoConfig.__subclasses__()} +TOPOS = {cls.NAME: cls for cls in Topo.__subclasses__()} \ No newline at end of file diff --git a/utils/http.py b/utils/http_server.py similarity index 61% rename from utils/http.py rename to utils/http_server.py index baca0ec..aae6a44 100644 --- a/utils/http.py +++ b/utils/http_server.py @@ -10,18 +10,24 @@ usage: python SimpleHTTPServer.py ''' import socket, os -from SocketServer import BaseServer -from BaseHTTPServer import HTTPServer -from SimpleHTTPServer import SimpleHTTPRequestHandler -from OpenSSL import SSL +try: + # Python 2 + from SocketServer import BaseServer + from BaseHTTPServer import HTTPServer + from SimpleHTTPServer import SimpleHTTPRequestHandler +except ImportError: + # Python 3 + from socketserver import BaseServer + from http.server import HTTPServer, SimpleHTTPRequestHandler +from OpenSSL import SSL def test(HandlerClass=SimpleHTTPRequestHandler, ServerClass=HTTPServer): server_address = ('', 80) # (address, port) httpd = ServerClass(server_address, HandlerClass) sa = httpd.socket.getsockname() - print("Serving HTTPS on", sa[0], "port", sa[1], "...") + print("Serving HTTP on", sa[0], "port", sa[1], "...") httpd.serve_forever() diff --git a/utils/https.py b/utils/https.py deleted file mode 100644 index ef4e7ba..0000000 --- a/utils/https.py +++ /dev/null @@ -1,54 +0,0 @@ -''' -From : -http://code.activestate.com/recipes/442473-simple-http-server-supporting-ssl-secure-communica/ - -SimpleSecureHTTPServer.py - simple HTTP server supporting SSL. - -- replace fpem with the location of your .pem server file. -- the default port is 443. - -usage: python SimpleSecureHTTPServer.py -''' - -import socket, os -from SocketServer import BaseServer -from BaseHTTPServer import HTTPServer -from SimpleHTTPServer import SimpleHTTPRequestHandler -from OpenSSL import SSL - - -class SecureHTTPServer(HTTPServer): - def __init__(self, server_address, HandlerClass): - BaseServer.__init__(self, server_address, HandlerClass) - ctx = SSL.Context(SSL.SSLv23_METHOD) - #server.pem's location (containing the server private key and - #the server certificate). - fpem = os.path.dirname(os.path.abspath(__file__)) + "/server.pem" - ctx.use_privatekey_file (fpem) - ctx.use_certificate_file(fpem) - self.socket = SSL.Connection(ctx, socket.socket(self.address_family, - self.socket_type)) - self.server_bind() - self.server_activate() - - def shutdown_request(self,request): - request.shutdown() - -class SecureHTTPRequestHandler(SimpleHTTPRequestHandler): - def setup(self): - self.connection = self.request - self.rfile = socket._fileobject(self.request, "rb", self.rbufsize) - self.wfile = socket._fileobject(self.request, "wb", self.wbufsize) - - -def test(HandlerClass = SecureHTTPRequestHandler, - ServerClass = SecureHTTPServer): - server_address = ('', 443) # (address, port) - httpd = ServerClass(server_address, HandlerClass) - sa = httpd.socket.getsockname() - print("Serving HTTPS on", sa[0], "port", sa[1], "...") - httpd.serve_forever() - - -if __name__ == '__main__': - test() diff --git a/utils/https_server.py b/utils/https_server.py new file mode 100644 index 0000000..697a678 --- /dev/null +++ b/utils/https_server.py @@ -0,0 +1,38 @@ +''' +From : +http://code.activestate.com/recipes/442473-simple-http-server-supporting-ssl-secure-communica/ + +SimpleSecureHTTPServer.py - simple HTTP server supporting SSL. + +- replace fpem with the location of your .pem server file. +- the default port is 443. + +usage: python SimpleSecureHTTPServer.py +''' + +import sys +if sys.version_info[0] == 3: + # Python 3 + import http.server, ssl + server_address = ('', 443) + httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler) + httpd.socket = ssl.wrap_socket(httpd.socket, + server_side=True, + certfile=sys.argv[1], + ssl_version=ssl.PROTOCOL_TLS) + print("Serving HTTPS on 0.0.0.0 port 443...") + httpd.serve_forever() +else: + # Python2 + import BaseHTTPServer, SimpleHTTPServer + import ssl + import os + + httpd = BaseHTTPServer.HTTPServer(('', 443), SimpleHTTPServer.SimpleHTTPRequestHandler) + httpd.socket = ssl.wrap_socket(httpd.socket, certfile=sys.argv[1], server_side=True) + + if len(sys.argv) > 1: + os.chdir(sys.argv[1]) + + print("Serving HTTPS on 0.0.0.0 port 443...") + httpd.serve_forever() \ No newline at end of file