Esempio n. 1
0
    def test_should_convert_MPLOption_to_bytes_when_to_bytes_method_is_called(self):
        # GIVEN
        S = any_mpl_S()
        M = any_mpl_M()
        V = any_mpl_V()
        sequence = any_mpl_sequence()
        seed_id = any_mpl_seed_id(S)

        mpl_option = MPLOption(S, M, V, sequence, seed_id)

        # WHEN
        data = mpl_option.to_bytes()

        # THEN
        expected_data = bytearray([(S << 6) | (M << 5) | (V << 4), sequence]) + seed_id
        self.assertEqual(expected_data, data)
Esempio n. 2
0
    def test_should_convert_MPLOption_to_bytes_when_to_bytes_method_is_called(self):
        # GIVEN
        S = any_mpl_S()
        M = any_mpl_M()
        V = any_mpl_V()
        sequence = any_mpl_sequence()
        seed_id = any_mpl_seed_id(S)

        mpl_option = MPLOption(S, M, V, sequence, seed_id)

        # WHEN
        data = mpl_option.to_bytes()

        # THEN
        expected_data = bytearray([(S << 6) | (M << 5) | (V << 4), sequence]) + seed_id
        self.assertEqual(expected_data, data)
Esempio n. 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)
Esempio n. 4
0
def any_mpl_option():
    S = any_mpl_S()
    M = any_mpl_M()
    V = any_mpl_V()
    sequence = any_mpl_sequence()
    seed_id = any_mpl_seed_id(S)

    return MPLOption(S, M, V, sequence, seed_id)
Esempio n. 5
0
    def test_should_return_proper_length_when_len_is_called_with_mpl_option_object(self):
        # GIVEN
        S = any_mpl_S()
        M = any_mpl_M()
        V = any_mpl_V()
        sequence = any_mpl_sequence()
        seed_id = any_mpl_seed_id(S)

        mpl_option = MPLOption(S, M, V, sequence, seed_id)

        # WHEN
        mpl_option_length = len(mpl_option)

        # THEN
        SMV_and_sequence_length = 2
        self.assertEqual(SMV_and_sequence_length + len(seed_id), mpl_option_length)
Esempio n. 6
0
    def test_should_create_MPLOption_when_to_bytes_method_is_called_with_data(self):
        # GIVEN
        S = any_mpl_S()
        M = any_mpl_M()
        V = any_mpl_V()
        sequence = any_mpl_sequence()
        seed_id = any_mpl_seed_id(S)

        data = bytearray([(S << 6) | (M << 5) | (V << 4), sequence]) + seed_id

        # WHEN
        mpl_option = MPLOption.from_bytes(io.BytesIO(data))

        # THEN
        self.assertEqual(S, mpl_option.S)
        self.assertEqual(M, mpl_option.M)
        self.assertEqual(V, mpl_option.V)
        self.assertEqual(sequence, mpl_option.sequence)
        self.assertEqual(seed_id, mpl_option.seed_id)
Esempio n. 7
0
    def test_should_create_MPLOption_when_to_bytes_method_is_called_with_data(self):
        # GIVEN
        S = any_mpl_S()
        M = any_mpl_M()
        V = any_mpl_V()
        sequence = any_mpl_sequence()
        seed_id = any_mpl_seed_id(S)

        data = bytearray([(S << 6) | (M << 5) | (V << 4), sequence]) + seed_id

        # WHEN
        mpl_option = MPLOption.from_bytes(io.BytesIO(data))

        # THEN
        self.assertEqual(S, mpl_option.S)
        self.assertEqual(M, mpl_option.M)
        self.assertEqual(V, mpl_option.V)
        self.assertEqual(sequence, mpl_option.sequence)
        self.assertEqual(seed_id, mpl_option.seed_id)