diff --git a/src/mpMptcptraceData.py b/src/mpMptcptraceData.py index 5b63763..e69eaeb 100644 --- a/src/mpMptcptraceData.py +++ b/src/mpMptcptraceData.py @@ -38,7 +38,7 @@ class MptcptraceData: # gets cell corresponding to flow with header column # flow 0 = first one, from 1=subflows - def get(self, name): + def get_csv(self, name): if hasattr(self,name): return getattr(self,name) else: diff --git a/src/mpTcptraceData.py b/src/mpTcptraceData.py index c2bdaf6..99fb2da 100755 --- a/src/mpTcptraceData.py +++ b/src/mpTcptraceData.py @@ -6,6 +6,7 @@ import csv from io import StringIO import re +import numpy as np @@ -15,43 +16,12 @@ class TcptraceData: 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) + cells=np.array(list(tcptrace_reader)) + #drop header row + cells= cells[1:] + self.cells = cells 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") - 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")]) - # 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) - - - - - + def get_csv(self, name): + return self.cells diff --git a/src/mpValidations.py b/src/mpValidations.py index d41f012..6b7722b 100644 --- a/src/mpValidations.py +++ b/src/mpValidations.py @@ -47,72 +47,42 @@ class ExactValueValidation(Validation): self.value = value return self.compared==value -# individual flow validations (used with FlowsTest) -################################################### -class MinDelayValidation(Validation): - # receives flow_spec = (index, flows) where index is the index of the flow to validate, and flows is the array of flows - def validate(self, 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 - -class MinDelayBetweenValidation(Validation): - # gets flow_spec = ( [ index0, index1] , flows) where: - # - index0 is the index of the flow taken as reference for timing - # - index1 is the flow for which we want to validate the timing - # - flows is the array of flows - def validate(self, 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 AttributeValidation(Validation): - def setup(self, flow_spec): - (yml ,trace) = flow_spec - [index0, index1] = yml["index"] - self.val0 = trace.get(index0, yml["attribute"]) - self.val1 = trace.get(index1, yml["attribute"]) - -class AttributeMinimumDifferenceValidation(AttributeValidation): - def validate(self, flow_spec): - self.setup(flow_spec) - self.value = self.val1 - self.val0 +# the method get_tested_value of the tester returns the value passed to validate. +# the CsvTester returns an array of values +class MinDifferenceValidation(Validation): + def validate(self, value): + v = value.flatten() + if len(v)>2: + raise Exception("MinDifferenceValidation requires 2 values maximum, not "+ str(len(v))) + self.value = float(v[1])-float(v[0]) return self.compared<=self.value - -class AttributeMaximumDifferenceValidation(AttributeValidation): - def validate(self, flow_spec): - self.setup(flow_spec) - self.value = self.val1 - self.val0 - return self.compared>=self.value - - -class AttributeMinimumRatioValidation(AttributeValidation): - def validate(self, flow_spec): - self.setup(flow_spec) - self.value = float(self.val1)/+float(self.val1) +class MinRowsValidation(Validation): + def validate(self, value): + self.value = len(value) return self.compared<=self.value - -class AttributeMaximumRatioValidation(AttributeValidation): - def validate(self, flow_spec): - self.setup(flow_spec) - self.value = float(self.val1)/float(self.val0) +class MaxRowsValidation(Validation): + def validate(self, value): + self.value = len(value) + return self.compared>=self.value +class ExactRowsValidation(Validation): + def validate(self, value): + self.value = len(value) + return self.compared==self.value +class MaxRatioValidation(Validation): + def validate(self, value): + v = value.flatten() + if len(v)>2: + raise Exception("MinDifferenceValidation requires 2 values maximum, not "+ str(len(v))) + self.value = float(v[1])/(float(v[0])+float(v[1])) return self.compared>=self.value - -# mptcptrace csv validations -############################ - # validates all values passed have increasing values # it is the Tester's get_tested_value method that does the work # to extract the values list from the trace. -class IncreasingValueValidation(AttributeValidation): +class IncreasingValuesValidation(Validation): def validate(self, values): previous = 0 - for i,v in enumerate(values): + for i,v in enumerate(values.flatten()): #print i, "{:10.6f}".format(previous), "{:10.6f}".format(v) if vb packet ration flow 2 compard to flow1" + desc: "max ration of packet a->b on flow 1 compared to flow 0."