diff --git a/src/http.py b/src/http.py new file mode 100644 index 0000000..baca0ec --- /dev/null +++ b/src/http.py @@ -0,0 +1,29 @@ +''' +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 socket, os +from SocketServer import BaseServer +from BaseHTTPServer import HTTPServer +from SimpleHTTPServer import 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], "...") + httpd.serve_forever() + + +if __name__ == '__main__': + test() diff --git a/src/mpExperience.py b/src/mpExperience.py index a014924..fabbdf5 100644 --- a/src/mpExperience.py +++ b/src/mpExperience.py @@ -6,6 +6,7 @@ class MpExperience: NC = "nc" NONE = "none" HTTPS = "https" + HTTP = "http" EPLOAD = "epload" def __init__(self, xpParam, mpTopo, mpConfig): diff --git a/src/mpExperienceHTTP.py b/src/mpExperienceHTTP.py new file mode 100644 index 0000000..2f00012 --- /dev/null +++ b/src/mpExperienceHTTP.py @@ -0,0 +1,78 @@ +from mpExperience import MpExperience +from mpParamXp import MpParamXp +from mpPvAt import MpPvAt +import os + +class MpExperienceHTTP(MpExperience): + SERVER_LOG = "http_server.log" + CLIENT_LOG = "http_client.log" + WGET_BIN = "wget" + PING_OUTPUT = "ping.log" + + def __init__(self, xpParamFile, mpTopo, mpConfig): + MpExperience.__init__(self, xpParamFile, mpTopo, mpConfig) + self.loadParam() + self.ping() + MpExperience.classicRun(self) + + def ping(self): + self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ + MpExperienceHTTP.PING_OUTPUT ) + count = self.xpParam.getParam(MpParamXp.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 + \ + " >> " + MpExperienceHTTP.PING_OUTPUT + print(s) + return s + + def loadParam(self): + """ + todo : param LD_PRELOAD ?? + """ + self.file = self.xpParam.getParam(MpParamXp.HTTPFILE) + self.random_size = self.xpParam.getParam(MpParamXp.HTTPRANDOMSIZE) + + def prepare(self): + MpExperience.prepare(self) + self.mpTopo.commandTo(self.mpConfig.client, "rm " + \ + MpExperienceHTTP.CLIENT_LOG ) + self.mpTopo.commandTo(self.mpConfig.server, "rm " + \ + MpExperienceHTTP.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 = "python " + os.path.dirname(os.path.abspath(__file__)) + \ + "/http.py &>" + MpExperienceHTTP.SERVER_LOG + "&" + print(s) + return s + + def getHTTPClientCmd(self): + s = MpExperienceHTTP.WGET_BIN + " http://" + self.mpConfig.getServerIP() + \ + "/" + self.file + " --no-check-certificate &>" + MpExperienceHTTP.CLIENT_LOG + print(s) + return s + + def clean(self): + MpExperience.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, cmd) + + self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") + cmd = self.getHTTPClientCmd() + self.mpTopo.commandTo(self.mpConfig.client, cmd) + self.mpTopo.commandTo(self.mpConfig.client, "sleep 2") diff --git a/src/mpParamXp.py b/src/mpParamXp.py index e618354..27e311b 100644 --- a/src/mpParamXp.py +++ b/src/mpParamXp.py @@ -30,6 +30,8 @@ class MpParamXp(MpParam): HTTPSFILE = "file" # file to wget, if random : we create a file with random data called random. HTTPSRANDOMSIZE = "file_size" # if file is set to random, define the size of the random file EPLOADTESTDIR = "epload_test_dir" + HTTPFILE = "http_file" + HTTPRANDOMSIZE = "http_file_size" # global sysctl @@ -75,6 +77,8 @@ class MpParamXp(MpParam): defaultValue[HTTPSFILE] = "random" defaultValue[HTTPSRANDOMSIZE] = "1024" defaultValue[EPLOADTESTDIR] = "/bla/bla/bla" + defaultValue[HTTPFILE] = "random" + defaultValue[HTTPRANDOMSIZE] = "1024" def __init__(self, paramFile): MpParam.__init__(self, paramFile) diff --git a/src/mpXpRunner.py b/src/mpXpRunner.py index 7ca38bf..97ed7ca 100644 --- a/src/mpXpRunner.py +++ b/src/mpXpRunner.py @@ -9,6 +9,7 @@ from mpExperiencePing import MpExperiencePing from mpExperienceNCPV import MpExperienceNCPV from mpExperienceNC import MpExperienceNC from mpExperienceHTTPS import MpExperienceHTTPS +from mpExperienceHTTP import MpExperienceHTTP from mpExperienceEpload import MpExperienceEpload from mpExperienceNone import MpExperienceNone from mpExperience import MpExperience @@ -80,6 +81,9 @@ class MpXpRunner: elif xp == MpExperience.HTTPS: MpExperienceHTTPS(self.xpParam, self.mpTopo, self.mpTopoConfig) + elif xp == MpExperience.HTTP: + MpExperienceHTTP(self.xpParam, self.mpTopo, + self.mpTopoConfig) elif xp == MpExperience.EPLOAD: MpExperienceEpload(self.xpParam, self.mpTopo, self.mpTopoConfig)