step one in validation
This commit is contained in:
parent
d930a1694c
commit
f4c77e9ddd
152
src/mpIterator.py
Executable file
152
src/mpIterator.py
Executable file
@ -0,0 +1,152 @@
|
|||||||
|
#!/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"
|
||||||
|
|
||||||
|
class MinValueValidation:
|
||||||
|
def __init__(self, compared):
|
||||||
|
self.compared=compared
|
||||||
|
def validate(self, value):
|
||||||
|
return self.compared<=value
|
||||||
|
|
||||||
|
class NumberOfFlowsTest:
|
||||||
|
def __init__(self, yml, trace):
|
||||||
|
self.yml = yml["validations"]
|
||||||
|
self.trace = trace
|
||||||
|
def validate(self):
|
||||||
|
print self.yml
|
||||||
|
tested_value = self.trace.number_of_flows
|
||||||
|
for k,v in self.yml.iteritems():
|
||||||
|
name = k.title().replace("_","")+"Validation"
|
||||||
|
tester_klass=globals()[name]
|
||||||
|
tester = tester_klass(v)
|
||||||
|
if tester.validate(tested_value):
|
||||||
|
print "SUCCESS"
|
||||||
|
else:
|
||||||
|
print "FAIL"
|
||||||
|
print k,v
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TcptraceValidator:
|
||||||
|
def __init__(self, yml, trace):
|
||||||
|
self.yml = yml["tcptrace"]
|
||||||
|
self.trace = trace
|
||||||
|
def validate(self):
|
||||||
|
for test in self.yml:
|
||||||
|
name=test["test"].title().replace("_","")+"Test"
|
||||||
|
klass = globals()[name]
|
||||||
|
r = klass(test, self.trace)
|
||||||
|
r.validate()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def printHelp():
|
||||||
|
print("Help Menu")
|
||||||
|
|
||||||
|
def parseArgs(argv):
|
||||||
|
global topoParamFile
|
||||||
|
global xpParamFile
|
||||||
|
try:
|
||||||
|
opts, args = getopt.getopt(argv, "ht:x:", ["topoParam=","xp="])
|
||||||
|
except getopt.GetoptError:
|
||||||
|
printHelp()
|
||||||
|
sys.exit(1)
|
||||||
|
for opt, arg in opts:
|
||||||
|
if opt == "-h":
|
||||||
|
printHelp()
|
||||||
|
sys.exit(1)
|
||||||
|
elif opt in ("-x","--xp"):
|
||||||
|
xpParamFile = arg
|
||||||
|
elif opt in ("-t","--topoParam"):
|
||||||
|
print("hey")
|
||||||
|
topoParamFile = arg
|
||||||
|
if topoParamFile is None:
|
||||||
|
print("Missing the topo...")
|
||||||
|
printHelp()
|
||||||
|
sys.exit(1)
|
||||||
|
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
|
||||||
|
|
||||||
|
tcptrace_validator = TcptraceValidator(validations, t )
|
||||||
|
print "WILL VALIDATE"
|
||||||
|
tcptrace_validator.validate()
|
||||||
|
|
||||||
|
#for v in validations["tcptrace"]:
|
||||||
|
# print dump(v)
|
||||||
|
|
||||||
|
# /usr/local/bin/mptcptrace -f /tmp/dest/client.pcap -G20 -F3 -r7 -s -S -a
|
46
src/mpTcptraceData.py
Executable file
46
src/mpTcptraceData.py
Executable file
@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
|
||||||
|
from subprocess import check_output
|
||||||
|
import csv
|
||||||
|
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TcptraceData:
|
||||||
|
def __init__(self, pcap_file):
|
||||||
|
self.pcap_file=pcap_file
|
||||||
|
csv_content = check_output(["tcptrace", "-l", "--csv", pcap_file])
|
||||||
|
tcptrace_reader = csv.reader(filter(lambda l: len(l)>0 and l[0]!="#",csv_content.splitlines()))
|
||||||
|
cells=list(tcptrace_reader)
|
||||||
|
self.headers=cells[0]
|
||||||
|
self.flows=cells[1:]
|
||||||
|
self.number_of_flows=len(self.flows)
|
||||||
|
# gets cell corresponding to flow with header column
|
||||||
|
# flow 0 = first one, from 1=subflows
|
||||||
|
def get(self, flow, column):
|
||||||
|
if flow>self.number_of_flows-1:
|
||||||
|
raise Exception("Bad flow index")
|
||||||
|
return self.flows[flow][self.headers.index(column)]
|
||||||
|
# returns first packet time of flow
|
||||||
|
def first_packet(self, flow):
|
||||||
|
return float(self.flows[flow][self.header_index("first_packet")])-float(self.flows[0][self.header_index("first_packet")])
|
||||||
|
# util: get column index based on header name
|
||||||
|
def header_index(self, column):
|
||||||
|
return self.headers.index(column)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#t = TcptraceData("client.pcap")
|
||||||
|
#print t.number_of_flows
|
||||||
|
#print t.first_packet(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
8
src/validation.yml
Normal file
8
src/validation.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
tcptrace:
|
||||||
|
- test: "number_of_flows"
|
||||||
|
validations:
|
||||||
|
min_value: 2
|
||||||
|
# - test: "flows"
|
||||||
|
# validations:
|
||||||
|
# - index: 1
|
||||||
|
# min_delay: 7000
|
Loading…
Reference in New Issue
Block a user