mininet-sample/src/mpIterator.py

150 lines
3.5 KiB
Python
Raw Normal View History

2015-05-19 13:26:10 +00:00
#!/usr/bin/python
import sys, getopt
from mpXpRunner import MpXpRunner
from mpTopo import MpTopo
from shutil import copy
import os
from subprocess import call
import datetime
from mpTcptraceData import *
from yaml import load, dump
topoParamFile = None
xpParamFile = None
topoBuilder = "mininet"
2015-05-19 14:21:06 +00:00
# A checker runs tests, and a test is made of multiple validations
# checks a value passed is greater or equel (generic)
2015-05-19 13:26:10 +00:00
class MinValueValidation:
2015-05-19 13:50:02 +00:00
def __init__(self, yml):
self.compared=yml["target"]
2015-05-19 13:26:10 +00:00
def validate(self, value):
return self.compared<=value
2015-05-19 14:21:06 +00:00
# individual flow validation (specific)
2015-05-19 13:50:02 +00:00
class MinDelayValidation:
def __init__(self, v):
self.compared=v["target"]
def validate(self, flow):
return self.compared<=flow[5]
2015-05-19 14:01:14 +00:00
2015-05-19 14:21:06 +00:00
# class testing tcptrace results
# the inheriting class should implement get_tested_value(self, yml)
2015-05-19 13:50:02 +00:00
class TcptraceTest:
2015-05-19 13:26:10 +00:00
def __init__(self, yml, trace):
self.yml = yml["validations"]
self.trace = trace
2015-05-19 14:21:06 +00:00
# performs a validation found in the yml file.
2015-05-19 13:26:10 +00:00
def validate(self):
2015-05-19 13:50:02 +00:00
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)
2015-05-19 13:26:10 +00:00
if tester.validate(tested_value):
print "SUCCESS"
else:
print "FAIL"
2015-05-19 13:50:02 +00:00
class NumberOfFlowsTest(TcptraceTest):
2015-05-19 14:21:06 +00:00
def get_tested_value(self, yml):
2015-05-19 13:50:02 +00:00
return self.trace.number_of_flows
class FlowsTest(TcptraceTest):
2015-05-19 14:21:06 +00:00
def get_tested_value(self, yml):
return self.trace.flows[yml["index"]]
2015-05-19 13:26:10 +00:00
2015-05-19 14:21:06 +00:00
class TcptraceChecker:
2015-05-19 13:26:10 +00:00
def __init__(self, yml, trace):
self.yml = yml["tcptrace"]
self.trace = trace
2015-05-19 14:21:06 +00:00
def check(self):
2015-05-19 13:26:10 +00:00
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
timestamp=datetime.datetime.now().isoformat()
#topoFile=generateTopo()
#print(topoFile)
#xpFile=generateXp()
#print(xpFile)
topoFile="./conf/topo/simple_para"
xpFile="./conf/xp/4_nc"
#MpXpRunner(MpTopo.mininetBuilder, topoFile, xpFile)
destDir="/tmp/dest"
if not os.path.exists(destDir):
os.makedirs(destDir)
#copy log files
copy("client.pcap",destDir)
#copy xp and topo
copy(topoFile,destDir)
copy(xpFile,destDir)
#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
2015-05-19 14:21:06 +00:00
tcptrace_checker = TcptraceChecker(validations, t )
2015-05-19 13:26:10 +00:00
print "WILL VALIDATE"
2015-05-19 14:21:06 +00:00
tcptrace_checker.check()
2015-05-19 13:26:10 +00:00
#for v in validations["tcptrace"]:
# print dump(v)
# /usr/local/bin/mptcptrace -f /tmp/dest/client.pcap -G20 -F3 -r7 -s -S -a