first shot at mptcptrace csv validation
This commit is contained in:
parent
a064674dc8
commit
fc3a064ad4
@ -35,6 +35,8 @@ logs_dir=options.logs_dir.rstrip("/")
|
|||||||
# take timestamp, used as subdirectory in logs_dir
|
# take timestamp, used as subdirectory in logs_dir
|
||||||
timestamp=datetime.datetime.now().isoformat()
|
timestamp=datetime.datetime.now().isoformat()
|
||||||
|
|
||||||
|
#timestamp = "2015-05-26T15:42:45.419949"
|
||||||
|
|
||||||
for test_name in [name for name in os.listdir(tests_dir) if os.path.isdir(os.path.join(tests_dir, name))]:
|
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
|
# initialise files defining the experience and test
|
||||||
test_dir = tests_dir + "/" + test_name
|
test_dir = tests_dir + "/" + test_name
|
||||||
|
47
src/mpMptcptraceData.py
Normal file
47
src/mpMptcptraceData.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
|
||||||
|
from subprocess import check_call
|
||||||
|
import csv
|
||||||
|
|
||||||
|
from io import StringIO
|
||||||
|
import re
|
||||||
|
import os
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MptcptraceData:
|
||||||
|
def __init__(self, pcap_file):
|
||||||
|
self.pcap_file=pcap_file
|
||||||
|
self.base_dir = os.path.dirname(pcap_file)
|
||||||
|
working_dir = os.getcwd()
|
||||||
|
|
||||||
|
# generate CSVs
|
||||||
|
os.chdir(self.base_dir)
|
||||||
|
print self.base_dir
|
||||||
|
print os.getcwd()
|
||||||
|
check_call(["sudo" , "/usr/local/bin/mptcptrace" , "-f", os.path.basename(pcap_file) , "-G20", "-F3", "-r7", "-s", "-S", "-a", "-w2"])
|
||||||
|
os.chdir(working_dir)
|
||||||
|
# accessing the attribute corresponding to the filename will parse the csv and return its cells
|
||||||
|
def __getattr__(self, name):
|
||||||
|
csv_file = self.base_dir+"/"+name+".csv"
|
||||||
|
print "opening csv file " + csv_file
|
||||||
|
if os.path.isfile(csv_file):
|
||||||
|
a = np.genfromtxt (csv_file, delimiter=",")
|
||||||
|
setattr(self, name, a)
|
||||||
|
return getattr(self,name)
|
||||||
|
else:
|
||||||
|
raise AttributeError("No csv file for unknown attribute "+name)
|
||||||
|
|
||||||
|
|
||||||
|
# gets cell corresponding to flow with header column
|
||||||
|
# flow 0 = first one, from 1=subflows
|
||||||
|
def get(self, name):
|
||||||
|
if hasattr(self,name):
|
||||||
|
return getattr(self,name)
|
||||||
|
else:
|
||||||
|
return self.__get_attr__(name)
|
||||||
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
from mpTcptraceData import *
|
from mpTcptraceData import *
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
# A checker runs tests, and a test is made of multiple validations
|
# A checker runs tests, and a test is made of multiple validations
|
||||||
|
|
||||||
@ -91,8 +93,23 @@ class AttributeMaximumRatioValidation(AttributeValidation):
|
|||||||
self.value = float(self.val1)/float(self.val0)
|
self.value = float(self.val1)/float(self.val0)
|
||||||
return self.compared>=self.value
|
return self.compared>=self.value
|
||||||
|
|
||||||
|
class IncreasingValueValidation(AttributeValidation):
|
||||||
|
def validate(self, values):
|
||||||
|
previous = 0
|
||||||
|
for i,v in enumerate(values):
|
||||||
|
#print i, "{:10.6f}".format(previous), "{:10.6f}".format(v)
|
||||||
|
if v<previous:
|
||||||
|
self.value=i # index of error row
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
previous=v
|
||||||
|
return self.compared>=self.value
|
||||||
|
|
||||||
|
|
||||||
class Tester:
|
class Tester:
|
||||||
|
def __init__(self, yml, trace):
|
||||||
|
self.yml = yml["validations"]
|
||||||
|
self.trace = trace
|
||||||
# performs a validation found in the yml file.
|
# performs a validation found in the yml file.
|
||||||
def validate(self):
|
def validate(self):
|
||||||
is_ok = True
|
is_ok = True
|
||||||
@ -124,9 +141,7 @@ class Tester:
|
|||||||
# the validations get this value as argument of their validate method
|
# the validations get this value as argument of their validate method
|
||||||
# The validate method iterates one the validations mentioned for the test in the yml file.
|
# The validate method iterates one the validations mentioned for the test in the yml file.
|
||||||
class TcptraceTest(Tester):
|
class TcptraceTest(Tester):
|
||||||
def __init__(self, yml, trace):
|
pass
|
||||||
self.yml = yml["validations"]
|
|
||||||
self.trace = trace
|
|
||||||
|
|
||||||
# get_tested_value returns the number of flows
|
# get_tested_value returns the number of flows
|
||||||
class NumberOfFlowsTest(TcptraceTest):
|
class NumberOfFlowsTest(TcptraceTest):
|
||||||
@ -139,6 +154,20 @@ class FlowsTest(TcptraceTest):
|
|||||||
def get_tested_value(self, yml):
|
def get_tested_value(self, yml):
|
||||||
return (yml,self.trace)
|
return (yml,self.trace)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MptcptraceTest(Tester):
|
||||||
|
pass
|
||||||
|
|
||||||
|
import code
|
||||||
|
# get_tested_value returns the number of flows
|
||||||
|
class ColumnValuesTest(TcptraceTest):
|
||||||
|
def get_tested_value(self, yml):
|
||||||
|
a = self.trace.get(yml["csv"])
|
||||||
|
code.interact(local=locals())
|
||||||
|
return a[:,yml["column"]]
|
||||||
|
|
||||||
class Checker:
|
class Checker:
|
||||||
def check(self):
|
def check(self):
|
||||||
is_ok = True
|
is_ok = True
|
||||||
@ -162,6 +191,7 @@ class TcptraceChecker(Checker):
|
|||||||
self.trace = TcptraceData(destDir+"/client.pcap")
|
self.trace = TcptraceData(destDir+"/client.pcap")
|
||||||
self.test_id = test_id
|
self.test_id = test_id
|
||||||
|
|
||||||
|
from mpMptcptraceData import *
|
||||||
|
|
||||||
# Runs tests based on mptcptrace
|
# Runs tests based on mptcptrace
|
||||||
# It (in the method inherited from its parent class) instanciates the ...Test class passing it the MptcptraceData instance
|
# It (in the method inherited from its parent class) instanciates the ...Test class passing it the MptcptraceData instance
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
mptcptrace:
|
||||||
|
- test: "column_values"
|
||||||
|
validations:
|
||||||
|
- name: "increasing_value"
|
||||||
|
csv: "c2s_seq_1"
|
||||||
|
column: 2
|
||||||
|
target: irrelevant
|
||||||
|
desc: "dummy: check sequence numbers grow"
|
||||||
tcptrace:
|
tcptrace:
|
||||||
- test: "number_of_flows"
|
- test: "number_of_flows"
|
||||||
validations:
|
validations:
|
||||||
|
Loading…
Reference in New Issue
Block a user