from mpTcptraceData import * import numpy as np # to get a REPL: #import code #code.interact(local=locals()) # A checker runs tests, and a test is made of multiple validations # For a validation, the value to compare to is the target value from the yaml # The validation takes place in the validate method, which takes # as argument a value from which to extract the value to compare or the value itself class Validation: def __init__(self, yml): if "target" in yml: self.compared=yml["target"] else: self.compared=None def name(self): return self.__class__.__name__ def validate(self,value): raise Exception("Method not implemented") def setup(self): raise Exception("Method not implemented") # 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 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 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) 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) 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): def validate(self, values): previous = 0 for i,v in enumerate(values): #print i, "{:10.6f}".format(previous), "{:10.6f}".format(v) if v