Ejemplo n.º 1
0
    def test_should_set_message_info_field_when_to_bytes_method_is_called(
            self):
        # GIVEN
        ipv6_packet_data = bytearray([
            0x60, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x3A, 0x40, 0xfd, 0x00, 0x12,
            0x34, 0x45, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00,
            0x18, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x87, 0x12,
            0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00,
            0x01, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41
        ])

        message_info = any_message_info()
        message_info.source_ipv6 = "ff::"
        message_info.destination_address = "ff::"

        factory = IPv6PacketFactory(
            ulpf={
                58: ICMPv6Factory(
                    body_factories={128: ICMPv6EchoBodyFactory()})
            })

        # WHEN
        factory.parse(io.BytesIO(ipv6_packet_data), message_info)

        # THEN
        self.assertEqual("fd00:1234:4555::ff:fe00:1800",
                         message_info.source_ipv6.compressed)
        self.assertEqual("ff03::1", message_info.destination_ipv6.compressed)
Ejemplo n.º 2
0
    def test_should_create_IPv6Packet_with_MPL_extension_header_and_ICMP_upper_layer_protocol_when_to_bytes_method_is_called(self):
        # GIVEN
        ipv6_packet_bytes = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x40,
                                       0xfd, 0x00, 0x12, 0x34, 0x45, 0x55, 0x00, 0x00,
                                       0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x18, 0x00,
                                       0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
                                       0x3a, 0x00, 0x6d, 0x04, 0x40, 0x02, 0x00, 0x18,
                                       0x80, 0x00, 0x87, 0x12, 0x00, 0x00, 0x00, 0x02,
                                       0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, 0x01,
                                       0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
                                       0x41, 0x41])

        ipv6_factory = IPv6PacketFactory(
            ehf={
                0: HopByHopFactory(
                    hop_by_hop_options_factory=HopByHopOptionsFactory(
                        options_factories={
                            109: MPLOptionFactory()
                        }
                    )
                )
            },
            ulpf={
                58: ICMPv6Factory(body_factories={
                    128: ICMPv6EchoBodyFactory()
                })
            })

        # WHEN
        ipv6_packet = ipv6_factory.parse(io.BytesIO(ipv6_packet_bytes), any_message_info())

        # THEN
        self.assertEqual('fd00:1234:4555::ff:fe00:1800',  ipv6_packet.ipv6_header.source_address.compressed)
        self.assertEqual('ff03::1', ipv6_packet.ipv6_header.destination_address.compressed)
        self.assertEqual(64, ipv6_packet.ipv6_header.hop_limit)
        self.assertEqual(0, ipv6_packet.ipv6_header.next_header)
        self.assertEqual(34, ipv6_packet.ipv6_header.payload_length)
        self.assertEqual(0, ipv6_packet.ipv6_header.flow_label)
        self.assertEqual(0, ipv6_packet.ipv6_header.traffic_class)
        self.assertEqual(6, ipv6_packet.ipv6_header.version)

        self.assertEqual(1, ipv6_packet.extension_headers[0].options[0].value.S)
        self.assertEqual(0, ipv6_packet.extension_headers[0].options[0].value.M)
        self.assertEqual(0, ipv6_packet.extension_headers[0].options[0].value.V)
        self.assertEqual(2, ipv6_packet.extension_headers[0].options[0].value.sequence)
        self.assertEqual(bytearray([0x00, 0x18]), ipv6_packet.extension_headers[0].options[0].value.seed_id)

        self.assertEqual(34578, ipv6_packet.upper_layer_protocol.header.checksum)
        self.assertEqual(128, ipv6_packet.upper_layer_protocol.header.type)
        self.assertEqual(0, ipv6_packet.upper_layer_protocol.header.code)
        self.assertEqual(0, ipv6_packet.upper_layer_protocol.body.identifier)
        self.assertEqual(2, ipv6_packet.upper_layer_protocol.body.sequence_number)
        self.assertEqual(b'\x80\x00\xc7\xbf\x00\x00\x00\x01AAAAAAAAAA', ipv6_packet.upper_layer_protocol.body.data)
Ejemplo n.º 3
0
    def test_should_create_IPv6Packet_without_any_extension_header_with_ICMP_when_to_bytes_method_is_called(
            self):
        # GIVEN
        ipv6_packet_bytes = bytearray([
            0x60, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x3A, 0x40, 0xfd, 0x00, 0x12,
            0x34, 0x45, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00,
            0x18, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x87, 0x12,
            0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00,
            0x01, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41
        ])

        ipv6_factory = IPv6PacketFactory(
            ulpf={
                58: ICMPv6Factory(
                    body_factories={128: ICMPv6EchoBodyFactory()})
            })

        # WHEN
        ipv6_packet = ipv6_factory.parse(io.BytesIO(ipv6_packet_bytes),
                                         any_message_info())
        ipv6_packet._validate_checksum()

        # THEN
        self.assertEqual('fd00:1234:4555::ff:fe00:1800',
                         ipv6_packet.ipv6_header.source_address.compressed)
        self.assertEqual(
            'ff03::1', ipv6_packet.ipv6_header.destination_address.compressed)
        self.assertEqual(64, ipv6_packet.ipv6_header.hop_limit)
        self.assertEqual(58, ipv6_packet.ipv6_header.next_header)
        self.assertEqual(26, ipv6_packet.ipv6_header.payload_length)
        self.assertEqual(0, ipv6_packet.ipv6_header.flow_label)
        self.assertEqual(0, ipv6_packet.ipv6_header.traffic_class)
        self.assertEqual(6, ipv6_packet.ipv6_header.version)

        self.assertEqual(34578,
                         ipv6_packet.upper_layer_protocol.header.checksum)
        self.assertEqual(128, ipv6_packet.upper_layer_protocol.header.type)
        self.assertEqual(0, ipv6_packet.upper_layer_protocol.header.code)
        self.assertEqual(0, ipv6_packet.upper_layer_protocol.body.identifier)
        self.assertEqual(2,
                         ipv6_packet.upper_layer_protocol.body.sequence_number)
        self.assertEqual(b'\x80\x00\xc7\xbf\x00\x00\x00\x01AAAAAAAAAA',
                         ipv6_packet.upper_layer_protocol.body.data)