diff --git a/src/mpIterator.py b/src/mpIterator.py index 30c4731..d428728 100755 --- a/src/mpIterator.py +++ b/src/mpIterator.py @@ -35,6 +35,8 @@ logs_dir=options.logs_dir.rstrip("/") # take timestamp, used as subdirectory in logs_dir 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))]: # initialise files defining the experience and test test_dir = tests_dir + "/" + test_name diff --git a/src/mpMptcptraceData.py b/src/mpMptcptraceData.py new file mode 100644 index 0000000..5b63763 --- /dev/null +++ b/src/mpMptcptraceData.py @@ -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) + + diff --git a/src/mpValidations.py b/src/mpValidations.py index 8afc69c..b776d41 100644 --- a/src/mpValidations.py +++ b/src/mpValidations.py @@ -2,6 +2,8 @@ from mpTcptraceData import * +import numpy as np + # 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) 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=self.value + class Tester: + def __init__(self, yml, trace): + self.yml = yml["validations"] + self.trace = trace # performs a validation found in the yml file. def validate(self): is_ok = True @@ -123,10 +140,8 @@ class Tester: # the get_tested_value should return the value that all validations of this test will use # 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. -class TcptraceTest(Tester): - def __init__(self, yml, trace): - self.yml = yml["validations"] - self.trace = trace +class TcptraceTest(Tester): + pass # get_tested_value returns the number of flows class NumberOfFlowsTest(TcptraceTest): @@ -139,6 +154,20 @@ class FlowsTest(TcptraceTest): def get_tested_value(self, yml): 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: def check(self): is_ok = True @@ -162,6 +191,7 @@ class TcptraceChecker(Checker): self.trace = TcptraceData(destDir+"/client.pcap") self.test_id = test_id +from mpMptcptraceData import * # Runs tests based on mptcptrace # It (in the method inherited from its parent class) instanciates the ...Test class passing it the MptcptraceData instance diff --git a/src/tests/base/validation.yml b/src/tests/base/validation.yml index 2336c5a..3cc145e 100644 --- a/src/tests/base/validation.yml +++ b/src/tests/base/validation.yml @@ -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: - test: "number_of_flows" validations: