Example #1
0
    def test_should_convert_HopByHopOption_to_bytes_when_to_bytes_method_is_called(self):
        # GIVEN
        length = any_length()
        header = any_hop_by_hop_bytes_option_header(length)
        value = any_hop_by_hop_bytes_value(length)

        hop_by_hop_option = HopByHopOption(header, value)

        # WHEN
        data = hop_by_hop_option.to_bytes()

        # THEN
        expected_data = header.to_bytes() + value.to_bytes()
        self.assertEqual(expected_data, data)
Example #2
0
    def test_should_convert_HopByHopOption_to_bytes_when_to_bytes_method_is_called(self):
        # GIVEN
        length = any_length()
        header = any_hop_by_hop_bytes_option_header(length)
        value = any_hop_by_hop_bytes_value(length)

        hop_by_hop_option = HopByHopOption(header, value)

        # WHEN
        data = hop_by_hop_option.to_bytes()

        # THEN
        expected_data = header.to_bytes() + value.to_bytes()
        self.assertEqual(expected_data, data)
Example #3
0
    def test_should_build_IPv6Packet_with_ICMP_payload_from_well_know_values_when_to_bytes_method_is_called(self):
        # GIVEN

        ipv6_packet = IPv6Packet(IPv6Header(source_address="fd00:1234:4555::ff:fe00:1800",
                                            destination_address="ff03::1"),
                                 ICMPv6(ICMPv6Header(128, 0),
                                        ICMPv6EchoBody(0, 2, bytearray([0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, 0x01,
                                                                        0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
                                                                        0x41, 0x41]))),
                                 [HopByHop(options=[
                                     HopByHopOption(HopByHopOptionHeader(_type=0x6d),
                                                    MPLOption(S=1, M=0, V=0, sequence=2, seed_id=bytearray([0x00, 0x18])))
                                 ])])

        # WHEN
        ipv6_packet_bytes = ipv6_packet.to_bytes()

        # THEN
        expected_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])

        self.assertEqual(expected_ipv6_packet_bytes, ipv6_packet_bytes)
Example #4
0
    def test_should_return_length_of_HopByHopOption_when_len_is_called_with_hop_by_hop_option_object(self):
        # GIVEN
        length = any_length()
        header = any_hop_by_hop_bytes_option_header(length)
        value = any_hop_by_hop_bytes_value(length)

        hop_by_hop_option = HopByHopOption(header, value)

        # WHEN
        hop_by_hop_option_length = len(hop_by_hop_option)

        # THEN
        header_length = 2
        expected_hop_by_hop_option_length = header_length + length
        self.assertEqual(expected_hop_by_hop_option_length, hop_by_hop_option_length)
Example #5
0
def any_hop_by_hop_mpl_option():
    mpl_option = any_mpl_option()
    return HopByHopOption(any_hop_by_hop_bytes_option_header(len(mpl_option)),
                          mpl_option)
Example #6
0
def any_hop_by_hop_bytes_option():
    length = any_length()
    return HopByHopOption(any_hop_by_hop_bytes_option_header(length),
                          any_hop_by_hop_bytes_value(length))