Esempio n. 1
0
    def test_parse_reconfig_reset_out(self):
        data = load('sctp_reconfig_reset_out.bin')
        packet = Packet.parse(data)
        self.assertEqual(packet.source_port, 5000)
        self.assertEqual(packet.destination_port, 5000)
        self.assertEqual(packet.verification_tag, 3370675819)

        self.assertEqual(len(packet.chunks), 1)
        self.assertTrue(isinstance(packet.chunks[0], ReconfigChunk))
        self.assertEqual(packet.chunks[0].type, 130)
        self.assertEqual(packet.chunks[0].flags, 0)
        self.assertEqual(
            packet.chunks[0].params,
            [(13, b'\x8b\xd8\n[\xe4\x8b\xecs\x8b\xd8\n^\x00\x01')])

        # Outgoing SSN Reset Request Parameter
        param_data = packet.chunks[0].params[0][1]
        param = StreamResetOutgoingParam.parse(param_data)
        self.assertEqual(param.request_sequence, 2346191451)
        self.assertEqual(param.response_sequence, 3834375283)
        self.assertEqual(param.last_tsn, 2346191454)
        self.assertEqual(param.streams, [1])
        self.assertEqual(bytes(param), param_data)

        self.assertEqual(bytes(packet), data)
Esempio n. 2
0
    def test_parse_cookie_echo(self):
        data = load('sctp_cookie_echo.bin')
        packet = Packet.parse(data)
        self.assertEqual(packet.source_port, 5000)
        self.assertEqual(packet.destination_port, 5000)
        self.assertEqual(packet.verification_tag, 1039286925)

        self.assertEqual(len(packet.chunks), 1)
        self.assertTrue(isinstance(packet.chunks[0], CookieEchoChunk))
        self.assertEqual(packet.chunks[0].type, 10)
        self.assertEqual(packet.chunks[0].flags, 0)
        self.assertEqual(len(packet.chunks[0].body), 8)

        self.assertEqual(bytes(packet), data)
Esempio n. 3
0
    def test_parse_init(self):
        data = load('sctp_init.bin')
        packet = Packet.parse(data)
        self.assertEqual(packet.source_port, 5000)
        self.assertEqual(packet.destination_port, 5000)
        self.assertEqual(packet.verification_tag, 0)

        self.assertEqual(len(packet.chunks), 1)
        self.assertTrue(isinstance(packet.chunks[0], InitChunk))
        self.assertEqual(packet.chunks[0].type, 1)
        self.assertEqual(packet.chunks[0].flags, 0)
        self.assertEqual(len(packet.chunks[0].body), 82)

        self.assertEqual(bytes(packet), data)
Esempio n. 4
0
    def test_parse_abort(self):
        data = load('sctp_abort.bin')
        packet = Packet.parse(data)
        self.assertEqual(packet.source_port, 5000)
        self.assertEqual(packet.destination_port, 5000)
        self.assertEqual(packet.verification_tag, 3763951554)

        self.assertEqual(len(packet.chunks), 1)
        self.assertTrue(isinstance(packet.chunks[0], AbortChunk))
        self.assertEqual(packet.chunks[0].type, 6)
        self.assertEqual(packet.chunks[0].flags, 0)
        self.assertEqual(packet.chunks[0].params, [
            (13, b'Expected B-bit for TSN=4ce1f17f, SID=0001, SSN=0000'),
        ])

        self.assertEqual(bytes(packet), data)
Esempio n. 5
0
    def test_parse_shutdown(self):
        data = load('sctp_shutdown.bin')
        packet = Packet.parse(data)
        self.assertEqual(packet.source_port, 5000)
        self.assertEqual(packet.destination_port, 5000)
        self.assertEqual(packet.verification_tag, 4019984498)

        self.assertEqual(len(packet.chunks), 1)
        self.assertTrue(isinstance(packet.chunks[0], ShutdownChunk))
        self.assertEqual(repr(packet.chunks[0]),
                         'ShutdownChunk(flags=0, cumulative_tsn=2696426712)')
        self.assertEqual(packet.chunks[0].type, 7)
        self.assertEqual(packet.chunks[0].flags, 0)
        self.assertEqual(packet.chunks[0].cumulative_tsn, 2696426712)

        self.assertEqual(bytes(packet), data)
Esempio n. 6
0
    def test_parse_error(self):
        data = load('sctp_error.bin')
        packet = Packet.parse(data)
        self.assertEqual(packet.source_port, 5000)
        self.assertEqual(packet.destination_port, 5000)
        self.assertEqual(packet.verification_tag, 3763951554)

        self.assertEqual(len(packet.chunks), 1)
        self.assertTrue(isinstance(packet.chunks[0], ErrorChunk))
        self.assertEqual(packet.chunks[0].type, 9)
        self.assertEqual(packet.chunks[0].flags, 0)
        self.assertEqual(packet.chunks[0].params, [
            (1, b'\x30\x39\x00\x00'),
        ])

        self.assertEqual(bytes(packet), data)
Esempio n. 7
0
    def test_parse_sack(self):
        data = load('sctp_sack.bin')
        packet = Packet.parse(data)
        self.assertEqual(packet.source_port, 5000)
        self.assertEqual(packet.destination_port, 5000)
        self.assertEqual(packet.verification_tag, 4146048843)

        self.assertEqual(len(packet.chunks), 1)
        self.assertTrue(isinstance(packet.chunks[0], SackChunk))
        self.assertEqual(packet.chunks[0].type, 3)
        self.assertEqual(packet.chunks[0].flags, 0)
        self.assertEqual(packet.chunks[0].cumulative_tsn, 2222939037)
        self.assertEqual(packet.chunks[0].gaps, [(2, 2), (4, 4)])
        self.assertEqual(packet.chunks[0].duplicates, [2222939041])

        self.assertEqual(bytes(packet), data)
Esempio n. 8
0
    def test_parse_heartbeat(self):
        data = load('sctp_heartbeat.bin')
        packet = Packet.parse(data)
        self.assertEqual(packet.source_port, 5000)
        self.assertEqual(packet.destination_port, 5000)
        self.assertEqual(packet.verification_tag, 3100082021)

        self.assertEqual(len(packet.chunks), 1)
        self.assertTrue(isinstance(packet.chunks[0], HeartbeatChunk))
        self.assertEqual(packet.chunks[0].type, 4)
        self.assertEqual(packet.chunks[0].flags, 0)
        self.assertEqual(packet.chunks[0].params, [(
            1,
            b'\xb5o\xaaZvZ\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00{\x10\x00\x00'
            b'\x004\xeb\x07F\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')])

        self.assertEqual(bytes(packet), data)
Esempio n. 9
0
    def test_receive_heartbeat(self):
        client_transport, server_transport = dummy_dtls_transport_pair()
        client = RTCSctpTransport(client_transport)
        client._last_received_tsn = 0
        client._remote_port = 5000

        # receive heartbeat
        chunk = HeartbeatChunk()
        chunk.params.append((1, b'\x01\x02\x03\x04'))
        chunk.tsn = 1
        run(client._receive_chunk(chunk))

        # check response
        data = run(server_transport.recv())
        packet = Packet.parse(data)
        self.assertEqual(len(packet.chunks), 1)
        self.assertTrue(isinstance(packet.chunks[0], HeartbeatAckChunk))
        self.assertEqual(packet.chunks[0].params, [(1, b'\x01\x02\x03\x04')])
Esempio n. 10
0
    def test_parse_data(self):
        data = load('sctp_data.bin')
        packet = Packet.parse(data)
        self.assertEqual(packet.source_port, 5000)
        self.assertEqual(packet.destination_port, 5000)
        self.assertEqual(packet.verification_tag, 264304801)

        self.assertEqual(len(packet.chunks), 1)
        self.assertTrue(isinstance(packet.chunks[0], DataChunk))
        self.assertEqual(packet.chunks[0].type, 0)
        self.assertEqual(packet.chunks[0].flags, 3)
        self.assertEqual(packet.chunks[0].tsn, 2584679421)
        self.assertEqual(packet.chunks[0].stream_id, 1)
        self.assertEqual(packet.chunks[0].stream_seq, 1)
        self.assertEqual(packet.chunks[0].protocol, 51)
        self.assertEqual(packet.chunks[0].user_data, b'ping')
        self.assertEqual(
            repr(packet.chunks[0]),
            'DataChunk(flags=3, tsn=2584679421, stream_id=1, stream_seq=1)')

        self.assertEqual(bytes(packet), data)
Esempio n. 11
0
    def test_parse_reconfig_response(self):
        data = load('sctp_reconfig_response.bin')
        packet = Packet.parse(data)
        self.assertEqual(packet.source_port, 5000)
        self.assertEqual(packet.destination_port, 5000)
        self.assertEqual(packet.verification_tag, 2982117117)

        self.assertEqual(len(packet.chunks), 1)
        self.assertTrue(isinstance(packet.chunks[0], ReconfigChunk))
        self.assertEqual(packet.chunks[0].type, 130)
        self.assertEqual(packet.chunks[0].flags, 0)
        self.assertEqual(packet.chunks[0].params,
                         [(16, b'\x91S\x1fT\x00\x00\x00\x01')])

        # Re-configuration Response Parameter
        param_data = packet.chunks[0].params[0][1]
        param = StreamResetResponseParam.parse(param_data)
        self.assertEqual(param.response_sequence, 2438143828)
        self.assertEqual(param.result, 1)
        self.assertEqual(bytes(param), param_data)

        self.assertEqual(bytes(packet), data)
Esempio n. 12
0
    def test_parse_reconfig_add_out(self):
        data = load('sctp_reconfig_add_out.bin')
        packet = Packet.parse(data)
        self.assertEqual(packet.source_port, 5000)
        self.assertEqual(packet.destination_port, 5000)
        self.assertEqual(packet.verification_tag, 3909981950)

        self.assertEqual(len(packet.chunks), 1)
        self.assertTrue(isinstance(packet.chunks[0], ReconfigChunk))
        self.assertEqual(packet.chunks[0].type, 130)
        self.assertEqual(packet.chunks[0].flags, 0)
        self.assertEqual(packet.chunks[0].params,
                         [(17, b'\xca\x02\xf60\x00\x10\x00\x00')])

        # Add Outgoing Streams Request Parameter
        param_data = packet.chunks[0].params[0][1]
        param = StreamAddOutgoingParam.parse(param_data)
        self.assertEqual(param.request_sequence, 3389191728)
        self.assertEqual(param.new_streams, 16)
        self.assertEqual(bytes(param), param_data)

        self.assertEqual(bytes(packet), data)
Esempio n. 13
0
 def test_parse_init_truncated_packet_header(self):
     data = load('sctp_init.bin')[0:10]
     with self.assertRaises(ValueError) as cm:
         Packet.parse(data)
     self.assertEqual(str(cm.exception),
                      'SCTP packet length is less than 12 bytes')
Esempio n. 14
0
 def test_parse_init_invalid_checksum(self):
     data = load('sctp_init.bin')
     data = data[0:8] + b'\x01\x02\x03\x04' + data[12:]
     with self.assertRaises(ValueError) as cm:
         Packet.parse(data)
     self.assertEqual(str(cm.exception), 'SCTP packet has invalid checksum')