예제 #1
0
    def testEndPointIsBornDisconnected(self):
        mediumAB = deque()
        mediumBA = deque()

        sinkA = MockSink(mediumAB)
        sinkB = MockSink(mediumBA)
        readerA = MockSource(mediumBA)
        readerB = MockSource(mediumAB)
        
        escapingSink = [EscapingSink(sinkA), EscapingSink(sinkB)]
        escapingSource = [EscapingSource(readerA), EscapingSource(readerB)]
                
        outgoingFrameBuffer = [deque(), deque()]
        
        frameTransmitter = [FrameTransmitter(escapingSink[0]), FrameTransmitter(escapingSink[1])]
        userFrameHandler = [FrameHandler(), FrameHandler()]
        frameReceiver = [FrameReceiver(escapingSource[0]), FrameReceiver(escapingSource[1])]

        endPoint = [
            EndPoint(escapingSource[0], frameReceiver[0], userFrameHandler[0], outgoingFrameBuffer[0], frameTransmitter[0], escapingSink[0]),
            EndPoint(escapingSource[1], frameReceiver[1], userFrameHandler[1], outgoingFrameBuffer[1], frameTransmitter[1], escapingSink[1])
        ]

        frameReceiver[0].setFrameHandler(endPoint[0])
        frameReceiver[1].setFrameHandler(endPoint[1])
        
        self.assertFalse(endPoint[0].isConnected())
예제 #2
0
    def testEndPointConnectDoesWhatItSaysOnTheBox(self):
        mediumAB = deque()
        mediumBA = deque()

        sinkA = MockSink(mediumAB)
        sinkB = MockSink(mediumBA)
        readerA = MockSource(mediumBA)
        readerB = MockSource(mediumAB)
        
        escapingSink = [EscapingSink(sinkA), EscapingSink(sinkB)]
        escapingSource = [EscapingSource(readerA), EscapingSource(readerB)]
                
        outgoingFrameBuffer = [deque(), deque()]
        
        frameTransmitter = [FrameTransmitter(escapingSink[0]), FrameTransmitter(escapingSink[1])]
        userFrameHandler = [FrameHandler(), FrameHandler()]
        frameReceiver = [FrameReceiver(escapingSource[0]), FrameReceiver(escapingSource[1])]

        endPoint = [
            EndPoint(escapingSource[0], frameReceiver[0], userFrameHandler[0], outgoingFrameBuffer[0], frameTransmitter[0], escapingSink[0]),
            EndPoint(escapingSource[1], frameReceiver[1], userFrameHandler[1], outgoingFrameBuffer[1], frameTransmitter[1], escapingSink[1])
        ]
        
        frameReceiver[0].setFrameHandler(endPoint[0])
        frameReceiver[1].setFrameHandler(endPoint[1])
        
        endPoint[0].connect();
    
        for i in range(0, 100):
            endPoint[0].schedule()
            endPoint[1].schedule()
    
        self.assertTrue(endPoint[0].isConnected());
        self.assertTrue(endPoint[1].isConnected());
예제 #3
0
    def testEndPointConnectDoesNothingWhileDisconnected(self):
        mediumAB = deque()
        mediumBA = deque()

        sinkA = MockSink(mediumAB)
        sinkB = MockSink(mediumBA)
        readerA = MockSource(mediumBA)
        readerB = MockSource(mediumAB)
        
        escapingSink = [EscapingSink(sinkA), EscapingSink(sinkB)]
        escapingSource = [EscapingSource(readerA), EscapingSource(readerB)]
                
        outgoingFrameBuffer = [deque(), deque()]
        
        frameTransmitter = [FrameTransmitter(escapingSink[0]), FrameTransmitter(escapingSink[1])]
        userFrameHandler = [FrameHandler(), FrameHandler()]
        frameReceiver = [FrameReceiver(escapingSource[0]), FrameReceiver(escapingSource[1])]

        endPoint = [
            EndPoint(escapingSource[0], frameReceiver[0], userFrameHandler[0], outgoingFrameBuffer[0], frameTransmitter[0], escapingSink[0]),
            EndPoint(escapingSource[1], frameReceiver[1], userFrameHandler[1], outgoingFrameBuffer[1], frameTransmitter[1], escapingSink[1])
        ]
        
        frameReceiver[0].setFrameHandler(endPoint[0])
        frameReceiver[1].setFrameHandler(endPoint[1])

        outgoingFrameBuffer[0] += [[0x42]]
                
        for i in range(0, 100):
            endPoint[0].schedule()
            endPoint[1].schedule()
    
        self.assertTrue(0 == len(userFrameHandler[0].payloads));
        self.assertTrue(0 == len(userFrameHandler[1].payloads));
예제 #4
0
    def testEndPointIgnoresFramesWithUnexpectedSequenceNumber(self):
        mediumAB = deque()
        mediumBA = deque()

        sinkA = MockSink(mediumAB)
        sinkB = MockSink(mediumBA)
        readerA = MockSource(mediumBA)
        readerB = MockSource(mediumAB)
        
        escapingSink = [EscapingSink(sinkA), EscapingSink(sinkB)]
        escapingSource = [EscapingSource(readerA), EscapingSource(readerB)]
                
        outgoingFrameBuffer = [deque(), deque()]
        
        frameTransmitter = [FrameTransmitter(escapingSink[0]), FrameTransmitter(escapingSink[1])]
        userFrameHandler = [FrameHandler(), FrameHandler()]
        frameReceiver = [FrameReceiver(escapingSource[0]), FrameReceiver(escapingSource[1])]

        endPoint = [
            EndPoint(escapingSource[0], frameReceiver[0], userFrameHandler[0], outgoingFrameBuffer[0], frameTransmitter[0], escapingSink[0]),
            EndPoint(escapingSource[1], frameReceiver[1], userFrameHandler[1], outgoingFrameBuffer[1], frameTransmitter[1], escapingSink[1])
        ]
        
        endPoint[0].connected.timeout = 0x0000000F
        endPoint[1].connected.timeout = 0x0000000F
        
        frameReceiver[0].setFrameHandler(endPoint[0])
        frameReceiver[1].setFrameHandler(endPoint[1])
        
        endPoint[0].connect();
    
        while not endPoint[1].isConnected():
            endPoint[0].schedule();
            endPoint[1].schedule();
    
        self.assertTrue(0 == len(userFrameHandler[0].payloads));
        self.assertTrue(0 == len(userFrameHandler[1].payloads));

        mediumAB += [EscapingSource.FLAG()]
        crc = 0xFFFF
        mediumAB += [0x00 ^ 0x01]
        crc = crc_ccitt_update(crc, 0x00 ^ 0x01)
        mediumAB += [0x42]
        crc = crc_ccitt_update(crc, 0x42)
        mediumAB += [crc >> 8]
        mediumAB += [crc & 0xFF]
        mediumAB += [EscapingSource.FLAG()]

        while len(mediumAB) > 0:
            endPoint[1].schedule()
    
        self.assertTrue(len(userFrameHandler[1].payloads) == 0)
예제 #5
0
    def testEndPointMovesOneHundredFramesInEachDirectionWithNoise(self):
        seed(1)
        mediumAB = deque()
        mediumBA = deque()

        writerA = MockSink(mediumAB)
        sinkA = NoisySink(writerA)
        writerB = MockSink(mediumBA)
        sinkB = NoisySink(writerB)
        
        readerA = MockSource(mediumBA)
        readerB = MockSource(mediumAB)
        
        escapingSink = [EscapingSink(sinkA), EscapingSink(sinkB)]
        escapingSource = [EscapingSource(readerA), EscapingSource(readerB)]
                
        outgoingFrameBuffer = [deque(), deque()]
        
        frameTransmitter = [FrameTransmitter(escapingSink[0]), FrameTransmitter(escapingSink[1])]
        userFrameHandler = [FrameHandler(), FrameHandler()]
        frameReceiver = [FrameReceiver(escapingSource[0]), FrameReceiver(escapingSource[1])]

        endPoint = [
            EndPoint(escapingSource[0], frameReceiver[0], userFrameHandler[0], outgoingFrameBuffer[0], frameTransmitter[0], escapingSink[0]),
            EndPoint(escapingSource[1], frameReceiver[1], userFrameHandler[1], outgoingFrameBuffer[1], frameTransmitter[1], escapingSink[1])
        ]
        
        frameReceiver[0].setFrameHandler(endPoint[0])
        frameReceiver[1].setFrameHandler(endPoint[1])
        
        endPoint[0].connect();

        while not endPoint[1].isConnected():
            endPoint[0].schedule();
            endPoint[1].schedule();
    
        frameCount = 100
        for i in range(0, frameCount):
            outgoingFrameBuffer[0] += [[i]]
            outgoingFrameBuffer[1] += [[i]]
        
        while len(userFrameHandler[0].payloads) < frameCount or len(userFrameHandler[1].payloads) < frameCount:
            endPoint[0].schedule()
            endPoint[1].schedule()

        for i in range(0, frameCount):
            self.assertEqual([i], userFrameHandler[0].payloads[i])
            self.assertEqual([i], userFrameHandler[1].payloads[i])
예제 #6
0
    def testEndPointMovesOneFrameInEachDirection(self):
        mediumAB = deque()
        mediumBA = deque()

        sinkA = MockSink(mediumAB)
        sinkB = MockSink(mediumBA)
        readerA = MockSource(mediumBA)
        readerB = MockSource(mediumAB)
        
        escapingSink = [EscapingSink(sinkA), EscapingSink(sinkB)]
        escapingSource = [EscapingSource(readerA), EscapingSource(readerB)]
                
        outgoingFrameBuffer = [deque(), deque()]
        
        frameTransmitter = [FrameTransmitter(escapingSink[0]), FrameTransmitter(escapingSink[1])]
        userFrameHandler = [FrameHandler(), FrameHandler()]
        frameReceiver = [FrameReceiver(escapingSource[0]), FrameReceiver(escapingSource[1])]

        endPoint = [
            EndPoint(escapingSource[0], frameReceiver[0], userFrameHandler[0], outgoingFrameBuffer[0], frameTransmitter[0], escapingSink[0]),
            EndPoint(escapingSource[1], frameReceiver[1], userFrameHandler[1], outgoingFrameBuffer[1], frameTransmitter[1], escapingSink[1])
        ]
        
        frameReceiver[0].setFrameHandler(endPoint[0])
        frameReceiver[1].setFrameHandler(endPoint[1])
        
        endPoint[0].connect();

        while not endPoint[1].isConnected():
            endPoint[0].schedule();
            endPoint[1].schedule();
    
        outgoingFrameBuffer[0] += [[0x42]]
        outgoingFrameBuffer[1] += [[0x43]]
        
        for i in range(0, 100):
            endPoint[0].schedule()
            endPoint[1].schedule()

        self.assertTrue(0 == len(outgoingFrameBuffer[0]))
        self.assertTrue(1 == len(userFrameHandler[1].payloads))
        self.assertEqual([0x42], userFrameHandler[1].payloads[0])

        self.assertTrue(0 == len(outgoingFrameBuffer[1]))
        self.assertTrue(1 == len(userFrameHandler[0].payloads))
        self.assertEqual([0x43], userFrameHandler[0].payloads[0])
예제 #7
0
    def testEndPointMovesSeventyFrames(self):
        mediumAB = deque()
        mediumBA = deque()

        sinkA = MockSink(mediumAB)
        sinkB = MockSink(mediumBA)
        readerA = MockSource(mediumBA)
        readerB = MockSource(mediumAB)
        
        escapingSink = [EscapingSink(sinkA), EscapingSink(sinkB)]
        escapingSource = [EscapingSource(readerA), EscapingSource(readerB)]
                
        outgoingFrameBuffer = [deque(), deque()]
        
        frameTransmitter = [FrameTransmitter(escapingSink[0]), FrameTransmitter(escapingSink[1])]
        userFrameHandler = [FrameHandler(), FrameHandler()]
        frameReceiver = [FrameReceiver(escapingSource[0]), FrameReceiver(escapingSource[1])]

        endPoint = [
            EndPoint(escapingSource[0], frameReceiver[0], userFrameHandler[0], outgoingFrameBuffer[0], frameTransmitter[0], escapingSink[0]),
            EndPoint(escapingSource[1], frameReceiver[1], userFrameHandler[1], outgoingFrameBuffer[1], frameTransmitter[1], escapingSink[1])
        ]
        
        frameReceiver[0].setFrameHandler(endPoint[0])
        frameReceiver[1].setFrameHandler(endPoint[1])
        
        endPoint[0].connect();

        while not endPoint[1].isConnected():
            endPoint[0].schedule();
            endPoint[1].schedule();
    
        frameCount = 70;
        for i in range(0, frameCount) :
            outgoingFrameBuffer[0] += [[0x42 + i]];
        
        for i in range(0, 1600):
            endPoint[0].schedule()
            endPoint[1].schedule()

        self.assertTrue(0 == len(outgoingFrameBuffer[0]))
        self.assertTrue(frameCount == len(userFrameHandler[1].payloads))
        for i in range(0, frameCount):
            self.assertEqual([0x42 + i], userFrameHandler[1].payloads[i])