コード例 #1
0
    def test_receive_data(self):
        client_transport, _ = dummy_dtls_transport_pair()
        client = RTCSctpTransport(client_transport)
        client._last_received_tsn = 0

        # receive chunk
        chunk = DataChunk(flags=(SCTP_DATA_FIRST_FRAG | SCTP_DATA_LAST_FRAG))
        chunk.user_data = b'foo'
        chunk.tsn = 1
        run(client._receive_chunk(chunk))

        self.assertEqual(client._sack_needed, True)
        self.assertEqual(client._sack_duplicates, [])
        self.assertEqual(client._last_received_tsn, 1)
        client._sack_needed = False

        # receive chunk again
        run(client._receive_chunk(chunk))
        self.assertEqual(client._sack_needed, True)
        self.assertEqual(client._sack_duplicates, [1])
        self.assertEqual(client._last_received_tsn, 1)
コード例 #2
0
    def test_receive_data_out_of_order(self):
        client_transport, _ = dummy_dtls_transport_pair()
        client = RTCSctpTransport(client_transport)
        client._last_received_tsn = 0

        # build chunks
        chunks = []

        chunk = DataChunk(flags=SCTP_DATA_FIRST_FRAG)
        chunk.user_data = b'foo'
        chunk.tsn = 1
        chunks.append(chunk)

        chunk = DataChunk()
        chunk.user_data = b'bar'
        chunk.tsn = 2
        chunks.append(chunk)

        chunk = DataChunk(flags=SCTP_DATA_LAST_FRAG)
        chunk.user_data = b'baz'
        chunk.tsn = 3
        chunks.append(chunk)

        # receive first chunk
        run(client._receive_chunk(chunks[0]))
        self.assertEqual(client._sack_needed, True)
        self.assertEqual(client._sack_duplicates, [])
        self.assertEqual(client._sack_misordered, set())
        self.assertEqual(client._last_received_tsn, 1)
        client._sack_needed = False

        # receive last chunk
        run(client._receive_chunk(chunks[2]))
        self.assertEqual(client._sack_needed, True)
        self.assertEqual(client._sack_duplicates, [])
        self.assertEqual(client._sack_misordered, set([3]))
        self.assertEqual(client._last_received_tsn, 1)
        client._sack_needed = False

        # receive middle chunk
        run(client._receive_chunk(chunks[1]))
        self.assertEqual(client._sack_needed, True)
        self.assertEqual(client._sack_duplicates, [])
        self.assertEqual(client._sack_misordered, set([]))
        self.assertEqual(client._last_received_tsn, 3)
        client._sack_needed = False

        # receive last chunk again
        run(client._receive_chunk(chunks[2]))
        self.assertEqual(client._sack_needed, True)
        self.assertEqual(client._sack_duplicates, [3])
        self.assertEqual(client._sack_misordered, set([]))
        self.assertEqual(client._last_received_tsn, 3)
        client._sack_needed = False
コード例 #3
0
    def setUp(self):
        self.fragmented = []
        self.whole = []

        # fragmented
        chunk = DataChunk(flags=SCTP_DATA_FIRST_FRAG)
        chunk.tsn = 1
        chunk.protocol = 123
        chunk.stream_id = 456
        chunk.user_data = b'foo'
        self.fragmented.append(chunk)

        chunk = DataChunk()
        chunk.protocol = 123
        chunk.stream_id = 456
        chunk.tsn = 2
        chunk.user_data = b'bar'
        self.fragmented.append(chunk)

        chunk = DataChunk(flags=SCTP_DATA_LAST_FRAG)
        chunk.protocol = 123
        chunk.stream_id = 456
        chunk.tsn = 3
        chunk.user_data = b'baz'
        self.fragmented.append(chunk)

        # whole
        chunk = DataChunk(flags=SCTP_DATA_FIRST_FRAG | SCTP_DATA_LAST_FRAG)
        chunk.tsn = 1
        chunk.protocol = 123
        chunk.stream_id = 456
        chunk.stream_seq = 0
        chunk.user_data = b'foo'
        self.whole.append(chunk)

        chunk = DataChunk(flags=SCTP_DATA_FIRST_FRAG | SCTP_DATA_LAST_FRAG)
        chunk.tsn = 2
        chunk.protocol = 123
        chunk.stream_id = 456
        chunk.stream_seq = 1
        chunk.user_data = b'bar'
        self.whole.append(chunk)

        chunk = DataChunk(flags=SCTP_DATA_FIRST_FRAG)
        chunk.tsn = 3
        chunk.protocol = 123
        chunk.stream_id = 456
        chunk.stream_seq = 2
        chunk.user_data = b'baz'
        self.whole.append(chunk)