From ac1e857f799467267541f10cebe9dbe36a332111 Mon Sep 17 00:00:00 2001 From: Raphael Bauduin Date: Tue, 26 May 2015 12:00:03 -0700 Subject: [PATCH] generic tcptrace flows value comparison testing (difference currently) --- src/mpTcptraceData.py | 13 ++++++++++++- src/mpValidations.py | 30 +++++++++++++++++++++--------- src/tests/base/validation.yml | 9 ++++++++- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/mpTcptraceData.py b/src/mpTcptraceData.py index 56a8e18..c2bdaf6 100755 --- a/src/mpTcptraceData.py +++ b/src/mpTcptraceData.py @@ -5,6 +5,8 @@ from subprocess import check_output import csv from io import StringIO +import re + @@ -22,7 +24,16 @@ class TcptraceData: 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)] + value = self.flows[flow][self.headers.index(column)] + if re.search("[a-zA-Z]", value): + return value + elif re.search("\.", value): + return float(value) + elif re.search("^[0-9]+$", value): + return int(value) + else: + return value + # 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")]) diff --git a/src/mpValidations.py b/src/mpValidations.py index aa53fd7..13cfda6 100644 --- a/src/mpValidations.py +++ b/src/mpValidations.py @@ -20,22 +20,27 @@ class Validation: # checks a value passed is greater or equal (generic) class MinValueValidation(Validation): def validate(self, value): + self.value = value return self.compared<=value # checks a value passed is greater or equal (generic) class MaxValueValidation(Validation): def validate(self, value): + self.value = value return self.compared>=value # checks a value passed is greater or equal (generic) class ExactValueValidation(Validation): def validate(self, value): + self.value = value return self.compared==value # individual flow validation (specific) # gets flow_spec = (index, flows) where index is the index of the flow to validate, and flows is the array of flows class MinDelayValidation(Validation): def validate(self, flow_spec): - (index,trace) = flow_spec + (yml,trace) = flow_spec + index=yml["index"] val = trace.first_packet(index)-trace.first_packet(0) + self.value = val return self.compared<=val # individual flow validation (specific) @@ -45,10 +50,19 @@ class MinDelayValidation(Validation): # - flows is the array of flows class MinDelayBetweenValidation(Validation): def validate(self, flow_spec): - ([index0, index1] ,trace) = flow_spec + (yml ,trace) = flow_spec + [index0, index1] = yml["index"] val = trace.first_packet(index1)-trace.first_packet(index0) + self.value = val return self.compared<=val +class AttributeMinimumDifferenceValidation(Validation): + def validate(self, flow_spec): + (yml ,trace) = flow_spec + [index0, index1] = yml["index"] + val = trace.get(index1, yml["attribute"]) - trace.get(index0, yml["attribute"]) + self.value = val + return self.compared<=val # Base class testing tcptrace results @@ -64,21 +78,19 @@ class TcptraceTest: def validate(self): is_ok = True self.logs = "" - print self.yml for val in self.yml: - print val["name"] tested_value = self.get_tested_value(val) klass_name=val["name"].title().replace("_","")+"Validation" tester_klass=globals()[klass_name] tester = tester_klass(val) try: if tester.validate(tested_value): - self.logs=self.logs+ ("" if self.logs=="" else "\n ")+ " -" +tester.name()+" OK\n" + self.logs=self.logs+ " " + " OK :" + val["desc"] +" - " + tester.name()+ " value : " + str(tester.value) +" vs " + str(val["target"]) + "\n" else: - self.logs=self.logs+ ("" if self.logs=="" else "\n ")+ " -" +tester.name()+" FAILS "+ val["desc"] +"\n" + self.logs=self.logs+ " " + " FAIL:" + val["desc"] +" - " + tester.name()+ " value : " + str(tester.value) +" vs " + str(val["target"]) + "\n" is_ok = False except Exception as e: - self.logs=self.logs+ ("" if self.logs=="" else "\n ")+ " -" +tester.name()+" FAILS (EXCEPTION:"+ str(e) + ") "+ val["desc"] +"\n" + self.logs=self.logs+ ("" if self.logs=="" else "\n ")+ " EXCP:" + val["desc"] +" - " + tester.name()+ " " + str(e) + "\n" return is_ok def name(self): return self.__class__.__name__ @@ -94,7 +106,7 @@ class NumberOfFlowsTest(TcptraceTest): # index can be a compound value, as in the case of min_delay_between where it is an array of indexes class FlowsTest(TcptraceTest): def get_tested_value(self, yml): - return (yml["index"],self.trace) + return (yml,self.trace) # Runs tests based on tcptrace @@ -111,7 +123,7 @@ class TcptraceChecker: klass = globals()[name] r = klass(test, self.trace) if r.validate(): - self.logs = self.logs + " *" + r.name() + " SUCCESS\n" + self.logs = self.logs + " *" + self.test_id + " " + r.name() + " SUCCESS\n" self.logs = self.logs + r.logs else: self.logs = self.logs + " *" + self.test_id + " " + r.name() + " FAIL\n" diff --git a/src/tests/base/validation.yml b/src/tests/base/validation.yml index 6949102..05690c6 100644 --- a/src/tests/base/validation.yml +++ b/src/tests/base/validation.yml @@ -8,7 +8,7 @@ tcptrace: target: 4 desc: "Open maximum 4 flows" - name: "exact_value" - target: 5 + target: 4 desc: "Open exactly 4 flows" # This tests the flows opened by the connection. See class FlowsTest - test: "flows" @@ -26,3 +26,10 @@ tcptrace: - 2 target: 1 desc: "Minimum 1 second delay between opening of second and third flow" + - name: "attribute_minimum_difference" + attribute: "first_packet" + index: + - 0 + - 1 + target: 2 + desc: "first packet delay 2nd flow"