restructured and improved code
This commit is contained in:
parent
33b75b5922
commit
a91bbc4791
@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
# apt-get install python-configglue
|
||||||
|
|
||||||
import sys, getopt
|
import sys, getopt
|
||||||
from mpXpRunner import MpXpRunner
|
from mpXpRunner import MpXpRunner
|
||||||
from mpTopo import MpTopo
|
from mpTopo import MpTopo
|
||||||
@ -9,141 +11,114 @@ import os
|
|||||||
from subprocess import call
|
from subprocess import call
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
from mpTcptraceData import *
|
# currently all checkers and validations and defined in this file
|
||||||
|
from mpValidations import *
|
||||||
|
|
||||||
from yaml import load, dump
|
from yaml import load, dump
|
||||||
|
|
||||||
topoParamFile = None
|
from optparse import OptionParser
|
||||||
xpParamFile = None
|
|
||||||
topoBuilder = "mininet"
|
|
||||||
|
|
||||||
# A checker runs tests, and a test is made of multiple validations
|
|
||||||
|
|
||||||
|
|
||||||
|
# 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)
|
(options, args) = parser.parse_args()
|
||||||
class MinValueValidation:
|
|
||||||
def __init__(self, yml):
|
|
||||||
self.compared=yml["target"]
|
|
||||||
def validate(self, value):
|
|
||||||
return self.compared<=value
|
|
||||||
|
|
||||||
# individual flow validation (specific)
|
# initialise flags values
|
||||||
class MinDelayValidation:
|
tests_dir=options.tests_dir.rstrip("/")
|
||||||
def __init__(self, v):
|
logs_dir=options.logs_dir.rstrip("/")
|
||||||
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
|
|
||||||
|
|
||||||
|
# take timestamp, used as subdirectory in logs_dir
|
||||||
timestamp=datetime.datetime.now().isoformat()
|
timestamp=datetime.datetime.now().isoformat()
|
||||||
#topoFile=generateTopo()
|
|
||||||
#print(topoFile)
|
|
||||||
#xpFile=generateXp()
|
|
||||||
#print(xpFile)
|
|
||||||
|
|
||||||
topoFile="./conf/topo/simple_para"
|
for test_name in [name for name in os.listdir(tests_dir) if os.path.isdir(os.path.join(tests_dir, name))]:
|
||||||
xpFile="./conf/xp/4_nc"
|
# initialise files defining the experience and test
|
||||||
|
test_dir = tests_dir + "/" + test_name
|
||||||
#MpXpRunner(MpTopo.mininetBuilder, topoFile, xpFile)
|
xpFile = test_dir+"/xp"
|
||||||
|
topoFile = test_dir+"/topo"
|
||||||
destDir="/tmp/dest"
|
validation_file=test_dir+"/validation.yml"
|
||||||
if not os.path.exists(destDir):
|
destDir=logs_dir+"/"+timestamp+"/"+test_name
|
||||||
|
if not os.path.exists(destDir):
|
||||||
os.makedirs(destDir)
|
os.makedirs(destDir)
|
||||||
|
|
||||||
#copy log files
|
print "Running " + test_dir
|
||||||
copy("client.pcap",destDir)
|
# run the experience
|
||||||
#copy xp and topo
|
MpXpRunner(MpTopo.mininetBuilder, topoFile, xpFile)
|
||||||
copy(topoFile,destDir)
|
|
||||||
copy(xpFile,destDir)
|
|
||||||
|
|
||||||
#os.chdir(destDir)
|
#copy xp, topo and validation to log
|
||||||
#print(os.getcwd())
|
copy(topoFile,destDir)
|
||||||
#call(["/usr/local/bin/mptcptrace", "-f", "/tmp/dest/client.pcap", "-G20", "-F3", "-r7", "-s", "-S", "-a"])
|
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)
|
||||||
|
|
||||||
t = TcptraceData("/tmp/dest/client.pcap")
|
# Run validations
|
||||||
print "Number of flows:", t.number_of_flows
|
with open(validation_file, 'r') as f:
|
||||||
print "Time for fist flow:", t.first_packet(1)
|
|
||||||
|
|
||||||
validation_file="validation.yml"
|
|
||||||
with open(validation_file, 'r') as f:
|
|
||||||
validations = load(f)
|
validations = load(f)
|
||||||
print validations
|
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
|
||||||
|
|
||||||
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"]:
|
#for v in validations["tcptrace"]:
|
||||||
# print dump(v)
|
# print dump(v)
|
||||||
|
|
||||||
# /usr/local/bin/mptcptrace -f /tmp/dest/client.pcap -G20 -F3 -r7 -s -S -a
|
# /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)
|
||||||
|
|
||||||
|
@ -7,4 +7,4 @@ tcptrace:
|
|||||||
validations:
|
validations:
|
||||||
- name: "min_delay"
|
- name: "min_delay"
|
||||||
index: 1
|
index: 1
|
||||||
target: 7000
|
target: 29000
|
Loading…
Reference in New Issue
Block a user