From 3bd620a53bc9f455a2f5ec5be66d8e12966c68d5 Mon Sep 17 00:00:00 2001 From: Quentin De Coninck Date: Wed, 1 Jul 2020 16:02:54 +0200 Subject: [PATCH] simplify usage of HTTP server --- experiments/epload.py | 4 ++-- experiments/http.py | 11 +++++------ experiments/siri_http.py | 8 ++++---- utils/http_server.py | 27 --------------------------- 4 files changed, 11 insertions(+), 39 deletions(-) delete mode 100644 utils/http_server.py diff --git a/experiments/epload.py b/experiments/epload.py index 1ff6e9e..5504a66 100644 --- a/experiments/epload.py +++ b/experiments/epload.py @@ -36,7 +36,7 @@ class Epload(Experiment): self.topo.command_to(self.topo_config.server, "rm " + \ Epload.SERVER_LOG ) - def getHTTPServerCmd(self): + def get_http_server_cmd(self): s = "/etc/init.d/apache2 restart &>" + Epload.SERVER_LOG + " &" print(s) return s @@ -71,7 +71,7 @@ class Epload(Experiment): super(Epload, self).clean() def run(self): - cmd = self.getHTTPServerCmd() + cmd = self.get_http_server_cmd() self.topo.command_to(self.topo_config.server, cmd) self.topo.command_to(self.topo_config.client, "sleep 2") diff --git a/experiments/http.py b/experiments/http.py index 769a3f9..e5400ad 100644 --- a/experiments/http.py +++ b/experiments/http.py @@ -25,13 +25,12 @@ class HTTP(RandomFileExperiment): self.topo.command_to(self.topo_config.server, "rm " + \ HTTP.SERVER_LOG ) - def getHTTPServerCmd(self): - s = "python {}/../utils/http_server.py &> {}&".format( - os.path.dirname(os.path.abspath(__file__)), HTTP.SERVER_LOG) + def get_http_server_cmd(self): + s = "python3 -m http.server 80 &> {}&".format(HTTP.SERVER_LOG) logging.info(s) return s - def getHTTPClientCmd(self): + def get_http_client_cmd(self): s = "(time {} http://{}/{} --no-check-certificate) &> {}".format(HTTP.WGET_BIN, self.topo_config.get_server_ip(), self.file, HTTP.CLIENT_LOG) logging.info(s) @@ -41,12 +40,12 @@ class HTTP(RandomFileExperiment): super(HTTP, self).clean() def run(self): - cmd = self.getHTTPServerCmd() + cmd = self.get_http_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.getHTTPClientCmd() + cmd = self.get_http_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") diff --git a/experiments/siri_http.py b/experiments/siri_http.py index 8cad8b8..07337a6 100644 --- a/experiments/siri_http.py +++ b/experiments/siri_http.py @@ -48,12 +48,12 @@ class SiriHTTP(Siri, RandomFileExperiment): self.topo.command_to(self.topo_config.server, "rm " + \ SiriHTTP.HTTP_SERVER_LOG) - def getHTTPServerCmd(self): + def get_http_server_cmd(self): s = "/etc/init.d/apache2 restart &>" + SiriHTTP.SERVER_LOG + "&" print(s) return s - def getHTTPClientCmd(self): + def get_http_client_cmd(self): s = SiriHTTP.WGET_BIN + " http://" + self.topo_config.get_server_ip() + \ "/" + self.file + " --no-check-certificate" print(s) @@ -66,12 +66,12 @@ class SiriHTTP(Siri, RandomFileExperiment): cmd = self.get_siri_server_cmd() self.topo.command_to(self.topo_config.server, "netstat -sn > netstat_server_before") self.topo.command_to(self.topo_config.server, cmd) - cmd = self.getHTTPServerCmd() + cmd = self.get_http_server_cmd() self.topo.command_to(self.topo_config.server, cmd) self.topo.command_to(self.topo_config.client, "sleep 2") self.topo.command_to(self.topo_config.client, "netstat -sn > netstat_client_before") - cmd = self.getHTTPClientCmd() + cmd = self.get_http_client_cmd() self.topo.command_to(self.topo_config.client, "for i in {1..200}; do " + cmd + "; done &") cmd = self.get_siri_client_cmd() self.topo.command_to(self.topo_config.client, cmd) diff --git a/utils/http_server.py b/utils/http_server.py deleted file mode 100644 index e37855e..0000000 --- a/utils/http_server.py +++ /dev/null @@ -1,27 +0,0 @@ -''' -From : -http://code.activestate.com/recipes/442473-simple-http-server-supporting-ssl-secure-communica/ - -SimpleHTTPServer.py - simple HTTP server supporting SSL. - -- the default port is 80. - -usage: python SimpleHTTPServer.py -''' - -import sys -if sys.version_info[0] == 3: - # Python 3 - import http.server - server_address = ('', 80) - httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler) - print("Serving HTTP on 0.0.0.0 port 80...") - httpd.serve_forever() -else: - # Python2 - import BaseHTTPServer, SimpleHTTPServer - import os - - httpd = BaseHTTPServer.HTTPServer(('', 443), SimpleHTTPServer.SimpleHTTPRequestHandler) - print("Serving HTTP on 0.0.0.0 port 80...") - httpd.serve_forever() \ No newline at end of file