simplify usage of HTTP server

This commit is contained in:
Quentin De Coninck 2020-07-01 16:02:54 +02:00
parent af78af3d5f
commit 3bd620a53b
4 changed files with 11 additions and 39 deletions

View File

@ -36,7 +36,7 @@ class Epload(Experiment):
self.topo.command_to(self.topo_config.server, "rm " + \ self.topo.command_to(self.topo_config.server, "rm " + \
Epload.SERVER_LOG ) Epload.SERVER_LOG )
def getHTTPServerCmd(self): def get_http_server_cmd(self):
s = "/etc/init.d/apache2 restart &>" + Epload.SERVER_LOG + " &" s = "/etc/init.d/apache2 restart &>" + Epload.SERVER_LOG + " &"
print(s) print(s)
return s return s
@ -71,7 +71,7 @@ class Epload(Experiment):
super(Epload, self).clean() super(Epload, self).clean()
def run(self): 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.server, cmd)
self.topo.command_to(self.topo_config.client, "sleep 2") self.topo.command_to(self.topo_config.client, "sleep 2")

View File

@ -25,13 +25,12 @@ class HTTP(RandomFileExperiment):
self.topo.command_to(self.topo_config.server, "rm " + \ self.topo.command_to(self.topo_config.server, "rm " + \
HTTP.SERVER_LOG ) HTTP.SERVER_LOG )
def getHTTPServerCmd(self): def get_http_server_cmd(self):
s = "python {}/../utils/http_server.py &> {}&".format( s = "python3 -m http.server 80 &> {}&".format(HTTP.SERVER_LOG)
os.path.dirname(os.path.abspath(__file__)), HTTP.SERVER_LOG)
logging.info(s) logging.info(s)
return s return s
def getHTTPClientCmd(self): def get_http_client_cmd(self):
s = "(time {} http://{}/{} --no-check-certificate) &> {}".format(HTTP.WGET_BIN, s = "(time {} http://{}/{} --no-check-certificate) &> {}".format(HTTP.WGET_BIN,
self.topo_config.get_server_ip(), self.file, HTTP.CLIENT_LOG) self.topo_config.get_server_ip(), self.file, HTTP.CLIENT_LOG)
logging.info(s) logging.info(s)
@ -41,12 +40,12 @@ class HTTP(RandomFileExperiment):
super(HTTP, self).clean() super(HTTP, self).clean()
def run(self): 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, "netstat -sn > netstat_server_before")
self.topo.command_to(self.topo_config.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, "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, "netstat -sn > netstat_client_before")
self.topo.command_to(self.topo_config.client, cmd) 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.server, "netstat -sn > netstat_server_after")

View File

@ -48,12 +48,12 @@ class SiriHTTP(Siri, RandomFileExperiment):
self.topo.command_to(self.topo_config.server, "rm " + \ self.topo.command_to(self.topo_config.server, "rm " + \
SiriHTTP.HTTP_SERVER_LOG) SiriHTTP.HTTP_SERVER_LOG)
def getHTTPServerCmd(self): def get_http_server_cmd(self):
s = "/etc/init.d/apache2 restart &>" + SiriHTTP.SERVER_LOG + "&" s = "/etc/init.d/apache2 restart &>" + SiriHTTP.SERVER_LOG + "&"
print(s) print(s)
return s return s
def getHTTPClientCmd(self): def get_http_client_cmd(self):
s = SiriHTTP.WGET_BIN + " http://" + self.topo_config.get_server_ip() + \ s = SiriHTTP.WGET_BIN + " http://" + self.topo_config.get_server_ip() + \
"/" + self.file + " --no-check-certificate" "/" + self.file + " --no-check-certificate"
print(s) print(s)
@ -66,12 +66,12 @@ class SiriHTTP(Siri, RandomFileExperiment):
cmd = self.get_siri_server_cmd() 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, "netstat -sn > netstat_server_before")
self.topo.command_to(self.topo_config.server, cmd) 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.server, cmd)
self.topo.command_to(self.topo_config.client, "sleep 2") self.topo.command_to(self.topo_config.client, "sleep 2")
self.topo.command_to(self.topo_config.client, "netstat -sn > netstat_client_before") 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 &") self.topo.command_to(self.topo_config.client, "for i in {1..200}; do " + cmd + "; done &")
cmd = self.get_siri_client_cmd() cmd = self.get_siri_client_cmd()
self.topo.command_to(self.topo_config.client, cmd) self.topo.command_to(self.topo_config.client, cmd)

View File

@ -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()