restructured and improved code

This commit is contained in:
Raphael Bauduin 2015-05-20 11:31:03 -07:00
parent 33b75b5922
commit a91bbc4791
2 changed files with 92 additions and 117 deletions

View File

@ -1,5 +1,7 @@
#!/usr/bin/python
# apt-get install python-configglue
import sys, getopt
from mpXpRunner import MpXpRunner
from mpTopo import MpTopo
@ -9,141 +11,114 @@ import os
from subprocess import call
import datetime
from mpTcptraceData import *
# currently all checkers and validations and defined in this file
from mpValidations import *
from yaml import load, dump
topoParamFile = None
xpParamFile = None
topoBuilder = "mininet"
# A checker runs tests, and a test is made of multiple validations
from optparse import OptionParser
# Define supported options
parser = OptionParser()
parser.add_option("-t", "--tests", dest="tests_dir",
help="Directory holding tests", metavar="TESTSDIR" , default="./tests")
parser.add_option("-l", "--logs", dest="logs_dir",
help="Directory where to log", metavar="LOGSDIR" , default="./logs")
# checks a value passed is greater or equel (generic)
class MinValueValidation:
def __init__(self, yml):
self.compared=yml["target"]
def validate(self, value):
return self.compared<=value
(options, args) = parser.parse_args()
# individual flow validation (specific)
class MinDelayValidation:
def __init__(self, v):
self.compared=v["target"]
def validate(self, flow):
return self.compared<=flow[5]
# class testing tcptrace results
# the inheriting class should implement get_tested_value(self, yml)
class TcptraceTest:
def __init__(self, yml, trace):
self.yml = yml["validations"]
self.trace = trace
# performs a validation found in the yml file.
def validate(self):
for val in self.yml:
tested_value = self.get_tested_value(val)
klass_name=val["name"].title().replace("_","")+"Validation"
tester_klass=globals()[klass_name]
tester = tester_klass(val)
if tester.validate(tested_value):
print "SUCCESS"
else:
print "FAIL"
class NumberOfFlowsTest(TcptraceTest):
def get_tested_value(self, yml):
return self.trace.number_of_flows
class FlowsTest(TcptraceTest):
def get_tested_value(self, yml):
return self.trace.flows[yml["index"]]
class TcptraceChecker:
def __init__(self, yml, trace):
self.yml = yml["tcptrace"]
self.trace = trace
def check(self):
for test in self.yml:
name=test["test"].title().replace("_","")+"Test"
klass = globals()[name]
r = klass(test, self.trace)
r.validate()
def write_entry(f, key, val):
f.write("{}:{}\n".format(key,val))
def generateTopo():
path="/tmp/topo"
f=open(path,"w")
# delay, queueSize (in packets), bw
write_entry(f, "path_0", "10,15,5")
write_entry(f, "path_1", "10,15,5")
write_entry(f, "topoType", "MultiIf")
f.close()
return path
def generateXp():
path="/tmp/xp"
f=open(path,"w")
write_entry(f, "xpType", "nc")
write_entry(f, "kpm", "fullmesh")
write_entry(f, "kpms", "netlink")
write_entry(f, "kpmc", "netlink")
write_entry(f, "upmc", "fullmesh")
# write_entry(f, "upmc_args", "-t 600000 -i 500 -c 7800")
write_entry(f, "ddCount", "10000")
write_entry(f, "clientPcap", "yes")
write_entry(f, "ncClientPort_0", "0:33400")
write_entry(f, "rmem","300000 300000 300000")
f.close()
return path
# initialise flags values
tests_dir=options.tests_dir.rstrip("/")
logs_dir=options.logs_dir.rstrip("/")
# take timestamp, used as subdirectory in logs_dir
timestamp=datetime.datetime.now().isoformat()
#topoFile=generateTopo()
#print(topoFile)
#xpFile=generateXp()
#print(xpFile)
topoFile="./conf/topo/simple_para"
xpFile="./conf/xp/4_nc"
for test_name in [name for name in os.listdir(tests_dir) if os.path.isdir(os.path.join(tests_dir, name))]:
# initialise files defining the experience and test
test_dir = tests_dir + "/" + test_name
xpFile = test_dir+"/xp"
topoFile = test_dir+"/topo"
validation_file=test_dir+"/validation.yml"
destDir=logs_dir+"/"+timestamp+"/"+test_name
if not os.path.exists(destDir):
os.makedirs(destDir)
#MpXpRunner(MpTopo.mininetBuilder, topoFile, xpFile)
print "Running " + test_dir
# run the experience
MpXpRunner(MpTopo.mininetBuilder, topoFile, xpFile)
destDir="/tmp/dest"
if not os.path.exists(destDir):
os.makedirs(destDir)
#copy xp, topo and validation to log
copy(topoFile,destDir)
copy(xpFile,destDir)
copy(validation_file,destDir)
#copy log files
for l in ["client.pcap" ,"command.log" ,"upmc.log" ,"upms.log" ,"client.pcap" ,"netcat_server_0.log" ,"netcat_client_0.log"]:
copy(l,destDir)
#copy log files
copy("client.pcap",destDir)
#copy xp and topo
copy(topoFile,destDir)
copy(xpFile,destDir)
# Run validations
with open(validation_file, 'r') as f:
validations = load(f)
for k in validations.keys():
# Identify checker class
name = k.title().replace("_","")+"Checker"
klass= globals()[name]
# instantiate checker with validations and test_name
checker = klass(validations, test_name)
if checker.check():
print checker.logs
else:
print checker.logs
#os.chdir(destDir)
#print(os.getcwd())
#call(["/usr/local/bin/mptcptrace", "-f", "/tmp/dest/client.pcap", "-G20", "-F3", "-r7", "-s", "-S", "-a"])
t = TcptraceData("/tmp/dest/client.pcap")
print "Number of flows:", t.number_of_flows
print "Time for fist flow:", t.first_packet(1)
validation_file="validation.yml"
with open(validation_file, 'r') as f:
validations = load(f)
print validations
tcptrace_checker = TcptraceChecker(validations, t )
print "WILL VALIDATE"
tcptrace_checker.check()
#tcptrace_checker = TcptraceChecker(validations, t )
#print "WILL VALIDATE"
#tcptrace_checker.check()
#for v in validations["tcptrace"]:
# print dump(v)
# /usr/local/bin/mptcptrace -f /tmp/dest/client.pcap -G20 -F3 -r7 -s -S -a
# Here are functions that can be used to generate topo and xp files:
#def write_entry(f, key, val):
# f.write("{}:{}\n".format(key,val))
#
#def generateTopo():
# path="/tmp/topo"
# f=open(path,"w")
# # delay, queueSize (in packets), bw
# write_entry(f, "path_0", "10,15,5")
# write_entry(f, "path_1", "10,15,5")
# write_entry(f, "topoType", "MultiIf")
# f.close()
# return path
#
#def generateXp():
# path="/tmp/xp"
# f=open(path,"w")
# write_entry(f, "xpType", "nc")
# write_entry(f, "kpm", "fullmesh")
# write_entry(f, "kpms", "netlink")
# write_entry(f, "kpmc", "netlink")
# write_entry(f, "upmc", "fullmesh")
## write_entry(f, "upmc_args", "-t 600000 -i 500 -c 7800")
# write_entry(f, "ddCount", "10000")
# write_entry(f, "clientPcap", "yes")
# write_entry(f, "ncClientPort_0", "0:33400")
# write_entry(f, "rmem","300000 300000 300000")
# f.close()
# return path
#topoFile=generateTopo()
#print(topoFile)
#xpFile=generateXp()
#print(xpFile)

View File

@ -7,4 +7,4 @@ tcptrace:
validations:
- name: "min_delay"
index: 1
target: 7000
target: 29000