def applyCountermeasure( trace, metadata ): [targetDistributionBi, targetDistributionUp, targetDistributionDown] = metadata newTrace = Trace(trace.getId()) # primary sampling timeCursor = 0 for packet in trace.getPackets(): timeCursor = packet.getTime() targetDistribution = targetDistributionDown if packet.getDirection()==Packet.UP: targetDistribution = targetDistributionUp packets = DirectTargetSampling.morphPacket( packet, targetDistribution ) for newPacket in packets: newTrace.addPacket( newPacket ) # secondary sampling while True: l1Distance = newTrace.calcL1Distance( targetDistributionBi ) if l1Distance <= DirectTargetSampling.L1_THRESHHOLD: break timeCursor += 10 newDirection, newLen = newTrace.getMostSkewedDimension( targetDistributionBi ) packet = Packet( newDirection, timeCursor, newLen ) newTrace.addPacket( packet ) return newTrace
def applyCountermeasure(trace, metadata): [ targetDistributionBi, targetDistributionUp, targetDistributionDown, srcDistributionUp, srcDistributionDown, morphingMatrixUp, morphingMatrixDown ] = metadata newTrace = Trace(trace.getId()) # primary sampling timeCursor = 0 for packet in trace.getPackets(): timeCursor = packet.getLength() index = (packet.getLength() - Packet.HEADER_LENGTH) / 8 targetDistribution = None morphingColumn = None if packet.getDirection() == Packet.UP: if morphingMatrixUp: morphingColumn = morphingMatrixUp[:, index] else: targetDistribution = targetDistributionUp targetDistributionSecondary = targetDistributionUp else: if morphingMatrixDown: morphingColumn = morphingMatrixDown[:, index] else: targetDistribution = targetDistributionDown targetDistributionSecondary = targetDistributionDown if morphingColumn: targetDistribution = {} for i in range(len(morphingColumn)): key = str(packet.getDirection()) + '-' + str( i * 8 + Packet.HEADER_LENGTH) targetDistribution[key] = morphingColumn[i] packets = WrightStyleMorphing.morphPacket( packet, targetDistribution, targetDistributionSecondary) for newPacket in packets: newTrace.addPacket(newPacket) # secondary sampling while True: l1Distance = newTrace.calcL1Distance(targetDistributionBi) if l1Distance <= WrightStyleMorphing.L1_THRESHHOLD: break timeCursor += 10 newDirection, newLen = newTrace.getMostSkewedDimension( targetDistributionBi) packet = Packet(newDirection, timeCursor, newLen) newTrace.addPacket(packet) return newTrace
def applyCountermeasure( trace, metadata ): [targetDistributionBi, targetDistributionUp, targetDistributionDown, srcDistributionUp, srcDistributionDown, morphingMatrixUp, morphingMatrixDown] = metadata newTrace = Trace(trace.getId()) # primary sampling timeCursor = 0 for packet in trace.getPackets(): timeCursor = packet.getLength() index = (packet.getLength()-Packet.HEADER_LENGTH)/8 targetDistribution = None morphingColumn = None if packet.getDirection()==Packet.UP: if morphingMatrixUp: morphingColumn = morphingMatrixUp[:,index] else: targetDistribution = targetDistributionUp targetDistributionSecondary = targetDistributionUp else: if morphingMatrixDown: morphingColumn = morphingMatrixDown[:,index] else: targetDistribution = targetDistributionDown targetDistributionSecondary = targetDistributionDown if morphingColumn: targetDistribution = {} for i in range(len(morphingColumn)): key = str(packet.getDirection())+'-'+str( i*8 + Packet.HEADER_LENGTH ) targetDistribution[key] = morphingColumn[i] packets = WrightStyleMorphing.morphPacket( packet, targetDistribution, targetDistributionSecondary ) for newPacket in packets: newTrace.addPacket( newPacket ) # secondary sampling while True: l1Distance = newTrace.calcL1Distance( targetDistributionBi ) if l1Distance <= WrightStyleMorphing.L1_THRESHHOLD: break timeCursor += 10 newDirection, newLen = newTrace.getMostSkewedDimension( targetDistributionBi ) packet = Packet( newDirection, timeCursor, newLen ) newTrace.addPacket( packet ) return newTrace