mpExperienceHTTP

This commit is contained in:
Quentin De Coninck 2015-12-01 17:48:32 +01:00
parent b1f390b4e4
commit af949fe45b
5 changed files with 116 additions and 0 deletions

29
src/http.py Normal file
View File

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

View File

@ -6,6 +6,7 @@ class MpExperience:
NC = "nc" NC = "nc"
NONE = "none" NONE = "none"
HTTPS = "https" HTTPS = "https"
HTTP = "http"
EPLOAD = "epload" EPLOAD = "epload"
def __init__(self, xpParam, mpTopo, mpConfig): def __init__(self, xpParam, mpTopo, mpConfig):

78
src/mpExperienceHTTP.py Normal file
View File

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

View File

@ -30,6 +30,8 @@ class MpParamXp(MpParam):
HTTPSFILE = "file" # file to wget, if random : we create a file with random data called random. 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 HTTPSRANDOMSIZE = "file_size" # if file is set to random, define the size of the random file
EPLOADTESTDIR = "epload_test_dir" EPLOADTESTDIR = "epload_test_dir"
HTTPFILE = "http_file"
HTTPRANDOMSIZE = "http_file_size"
# global sysctl # global sysctl
@ -75,6 +77,8 @@ class MpParamXp(MpParam):
defaultValue[HTTPSFILE] = "random" defaultValue[HTTPSFILE] = "random"
defaultValue[HTTPSRANDOMSIZE] = "1024" defaultValue[HTTPSRANDOMSIZE] = "1024"
defaultValue[EPLOADTESTDIR] = "/bla/bla/bla" defaultValue[EPLOADTESTDIR] = "/bla/bla/bla"
defaultValue[HTTPFILE] = "random"
defaultValue[HTTPRANDOMSIZE] = "1024"
def __init__(self, paramFile): def __init__(self, paramFile):
MpParam.__init__(self, paramFile) MpParam.__init__(self, paramFile)

View File

@ -9,6 +9,7 @@ from mpExperiencePing import MpExperiencePing
from mpExperienceNCPV import MpExperienceNCPV from mpExperienceNCPV import MpExperienceNCPV
from mpExperienceNC import MpExperienceNC from mpExperienceNC import MpExperienceNC
from mpExperienceHTTPS import MpExperienceHTTPS from mpExperienceHTTPS import MpExperienceHTTPS
from mpExperienceHTTP import MpExperienceHTTP
from mpExperienceEpload import MpExperienceEpload from mpExperienceEpload import MpExperienceEpload
from mpExperienceNone import MpExperienceNone from mpExperienceNone import MpExperienceNone
from mpExperience import MpExperience from mpExperience import MpExperience
@ -80,6 +81,9 @@ class MpXpRunner:
elif xp == MpExperience.HTTPS: elif xp == MpExperience.HTTPS:
MpExperienceHTTPS(self.xpParam, self.mpTopo, MpExperienceHTTPS(self.xpParam, self.mpTopo,
self.mpTopoConfig) self.mpTopoConfig)
elif xp == MpExperience.HTTP:
MpExperienceHTTP(self.xpParam, self.mpTopo,
self.mpTopoConfig)
elif xp == MpExperience.EPLOAD: elif xp == MpExperience.EPLOAD:
MpExperienceEpload(self.xpParam, self.mpTopo, MpExperienceEpload(self.xpParam, self.mpTopo,
self.mpTopoConfig) self.mpTopoConfig)