def test_chained_basic_options_inside_ipv6_packet(self):
        ipv6_binary_packet = [
            0x64, 0x82, 0x46, 0x05, 0x05, 0xdc, 0x00, 0x01, 0xfe, 0x80, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xf8, 0x89, 0xd1, 0x30, 0xff,
            0x25, 0x6b, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03
        ]

        hop_by_hop_binary_packet = [
            0x2b, 0x01, 0x01, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00
        ]

        routing_options_binary_packet = [
            0x3c, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00
        ]

        dest_opts_binary_packet = [
            0x3a, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00
        ]

        binary_packet = ipv6_binary_packet + hop_by_hop_binary_packet + routing_options_binary_packet + dest_opts_binary_packet

        ip6_packet = IP6.IP6()
        ip6_packet.set_traffic_class(72)
        ip6_packet.set_flow_label(148997)
        ip6_packet.set_payload_length(1500)
        ip6_packet.set_next_header(17)
        ip6_packet.set_hop_limit(1)
        ip6_packet.set_ip_src("FE80::78F8:89D1:30FF:256B")
        ip6_packet.set_ip_dst("FF02::1:3")

        hop_by_hop = IP6_Extension_Headers.Hop_By_Hop()
        hop_by_hop.add_option(IP6_Extension_Headers.Option_PADN(14))

        routing_options = IP6_Extension_Headers.Routing_Options()
        routing_options.set_next_header(58)
        routing_options.set_routing_type(0)
        routing_options.set_segments_left(10)

        dest_opts = IP6_Extension_Headers.Destination_Options()
        dest_opts.add_option(IP6_Extension_Headers.Option_PAD1())

        ip6_packet.contains(hop_by_hop)
        hop_by_hop.contains(routing_options)
        routing_options.contains(dest_opts)
        dest_opts.set_next_header(58)

        self.assertEqual(
            self.string_to_list(ip6_packet.get_packet()), binary_packet,
            "Chained options inside an IPv6 packet - Buffer mismatch")

        self.assertEqual(
            ip6_packet.get_size(), len(binary_packet),
            "Chained options inside an IPv6 packet - Size mismatch")
    def decode(self, buffer):
        destination_options = IP6_Extension_Headers.Destination_Options(buffer)
        self.set_decoded_protocol(destination_options)
        start_pos = destination_options.get_header_size()
        contained_protocol = destination_options.get_next_header()

        multi_protocol_decoder = IP6MultiProtocolDecoder(contained_protocol)
        child_packet = multi_protocol_decoder.decode(buffer[start_pos:])

        destination_options.contains(child_packet)
        return destination_options
Пример #3
0
    def test_create_simple_dest_opts(self):
        dest_opts_binary_packet = [0x3a, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00]

        dest_opts = IP6_Extension_Headers.Destination_Options()
        dest_opts.set_next_header(58)
        
        self.assertEqual(
            self.string_to_list(dest_opts.get_packet()), dest_opts_binary_packet, 
            "Simple Destination Options Header creation - Buffer mismatch")

        self.assertEqual(
            dest_opts.get_size(), len(dest_opts_binary_packet),
            "Simple Destination Options Header creation - Size mismatch")
Пример #4
0
    def test_pad_dest_opts_when_adding_option(self):
        dest_opts_binary_packet = [
            0x3a, 0x00, 0x00, 0x01,
            0x03, 0x00, 0x00, 0x00]

        dest_opts = IP6_Extension_Headers.Destination_Options()
        dest_opts.set_next_header(58)
        dest_opts.add_option(IP6_Extension_Headers.Option_PAD1())

        self.assertEqual(
            self.string_to_list(dest_opts.get_packet()), dest_opts_binary_packet, 
            "Pad Destination Options Header when adding option - Buffer mismatch")

        self.assertEqual(
            dest_opts.get_size(), len(dest_opts_binary_packet),
            "Pad Destination Options Header when adding option - Size mismatch")
Пример #5
0
    def test_add_option_to_dest_opts(self):
        dest_opts_binary_packet = [
            0x3a, 0x01, 0x01, 0x0C,
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00]

        dest_opts = IP6_Extension_Headers.Destination_Options()
        dest_opts.set_next_header(58)
        dest_opts.add_option(IP6_Extension_Headers.Option_PADN(14))

        self.assertEqual(
            self.string_to_list(dest_opts.get_packet()), dest_opts_binary_packet, 
            "Add Option to Destination Options Header - Buffer mismatch")

        self.assertEqual(
            dest_opts.get_size(), len(dest_opts_binary_packet),
            "Add Option to Destination Options Header - Size mismatch")
Пример #6
0
    def test_simple_dest_opts_contained_in_ipv6(self):
        ipv6_binary_packet = [ 
               0x64, 0x82, 0x46, 0x05, 
               0x05, 0xdc, 0x3c, 0x01, 
               0xfe, 0x80, 0x00, 0x00, 
               0x00, 0x00, 0x00, 0x00, 
               0x78, 0xf8, 0x89, 0xd1,
               0x30, 0xff, 0x25, 0x6b, 
               0xff, 0x02, 0x00, 0x00, 
               0x00, 0x00, 0x00, 0x00, 
               0x00, 0x00, 0x00, 0x00, 
               0x00, 0x01, 0x00, 0x03]
        
        dest_opts_binary_packet = [
               0x3a, 0x00, 0x01, 0x04,
               0x00, 0x00, 0x00, 0x00]

        binary_packet = ipv6_binary_packet + dest_opts_binary_packet
        
        ip6_packet = IP6.IP6()
        ip6_packet.set_traffic_class(72)
        ip6_packet.set_flow_label(148997)
        ip6_packet.set_payload_length(1500)
        ip6_packet.set_next_header(17)
        ip6_packet.set_hop_limit(1)
        ip6_packet.set_ip_src("FE80::78F8:89D1:30FF:256B")
        ip6_packet.set_ip_dst("FF02::1:3")
        
        dest_opts = IP6_Extension_Headers.Destination_Options()
        dest_opts.set_next_header(58)

        ip6_packet.contains(dest_opts)

        self.assertEqual(
            self.string_to_list(ip6_packet.get_packet()), binary_packet, 
            "IP6 Destination Options Header contained in IPv6 Header - Buffer mismatch")

        self.assertEqual(
            ip6_packet.get_size(), len(binary_packet),
            "IP6 Destination Options Header contained in IPv6 Header - Size mismatch")
Пример #7
0
    def test_chained_basic_options(self):
        dest_opts_binary_packet = [
            0x2b, 0x00, 0x00, 0x01,
            0x03, 0x00, 0x00, 0x00]

        routing_options_binary_packet = [
           0x00, 0x00, 0x00, 0x0a,
           0x00, 0x00, 0x00, 0x00]

        hop_by_hop_binary_packet = [
            0x3a, 0x01, 0x01, 0x0C,
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00]

        binary_packet = dest_opts_binary_packet + routing_options_binary_packet + hop_by_hop_binary_packet

        dest_opts = IP6_Extension_Headers.Destination_Options()
        dest_opts.add_option(IP6_Extension_Headers.Option_PAD1())

        routing_options = IP6_Extension_Headers.Routing_Options()
        routing_options.set_next_header(58)
        routing_options.set_routing_type(0)
        routing_options.set_segments_left(10)

        hop_by_hop = IP6_Extension_Headers.Hop_By_Hop()
        hop_by_hop.add_option(IP6_Extension_Headers.Option_PADN(14))
        
        dest_opts.contains(routing_options)
        routing_options.contains(hop_by_hop)
        hop_by_hop.set_next_header(58)

        self.assertEqual(
            self.string_to_list(dest_opts.get_packet()), binary_packet, 
            "Chained options - Buffer mismatch")

        self.assertEqual(
            dest_opts.get_size(), len(binary_packet),
            "Chained options - Size mismatch")