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")
Ejemplo n.º 2
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")
Ejemplo n.º 3
0
    def test_pad_hop_by_hop_when_adding_option(self):
        hop_by_hop_binary_packet = [
            0x3a, 0x00, 0x00, 0x01,
            0x03, 0x00, 0x00, 0x00]

        hop_by_hop = IP6_Extension_Headers.Hop_By_Hop()
        hop_by_hop.set_next_header(58)
        hop_by_hop.add_option(IP6_Extension_Headers.Option_PAD1())

        self.assertEqual(
            self.string_to_list(hop_by_hop.get_packet()), hop_by_hop_binary_packet, 
            "Pad Hop By Hop Header when adding option - Buffer mismatch")

        self.assertEqual(
            hop_by_hop.get_size(), len(hop_by_hop_binary_packet),
            "Pad Hop By Hop Header when adding option - Size mismatch")
    def test_add_option_to_hop_by_hop(self):
        hop_by_hop_binary_packet = [
            0x3a, 0x01, 0x01, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00
        ]

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

        self.assertEqual(self.string_to_list(hop_by_hop.get_packet()),
                         hop_by_hop_binary_packet,
                         "Add Option to Hop By Hop Header - Buffer mismatch")

        self.assertEqual(hop_by_hop.get_size(), len(hop_by_hop_binary_packet),
                         "Add Option to Hop By Hop Header - Size mismatch")
    def test_simple_hop_by_hop_contained_in_ipv6(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 = [
            0x3a, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00
        ]

        binary_packet = ipv6_binary_packet + hop_by_hop_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.set_next_header(58)

        ip6_packet.contains(hop_by_hop)

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

        self.assertEqual(
            ip6_packet.get_size(), len(binary_packet),
            "IP6 Hop By Hop Header contained in IPv6 Header - Size mismatch")
Ejemplo n.º 6
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")
    def decode(self, buffer):
        routing_options = IP6_Extension_Headers.Routing_Options(buffer)
        self.set_decoded_protocol(routing_options)
        start_pos = routing_options.get_header_size()
        contained_protocol = routing_options.get_next_header()

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

        routing_options.contains(child_packet)
        return routing_options
    def decode(self, buffer):
        hop_by_hop = IP6_Extension_Headers.Hop_By_Hop(buffer)
        self.set_decoded_protocol(hop_by_hop)
        start_pos = hop_by_hop.get_header_size()
        contained_protocol = hop_by_hop.get_next_header()

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

        hop_by_hop.contains(child_packet)
        return hop_by_hop
Ejemplo n.º 9
0
    def test_create_simple_hop_by_hop(self):
        hop_by_hop_binary_packet = [0x3a, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00]

        hop_by_hop = IP6_Extension_Headers.Hop_By_Hop()
        hop_by_hop.set_next_header(58)

        self.assertEqual(
            self.string_to_list(hop_by_hop.get_packet()), hop_by_hop_binary_packet, 
            "Simple Hop By Hop Header creation - Buffer mismatch")
        
        self.assertEqual(
            hop_by_hop.get_size(), len(hop_by_hop_binary_packet),
            "Simple Hop By Hop Header creation - Size mismatch")
Ejemplo n.º 10
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")
Ejemplo n.º 11
0
    def test_create_simple_routing_options(self):
        routing_options_binary_packet = [0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]

        routing_options = IP6_Extension_Headers.Routing_Options()
        routing_options.set_next_header(58)
        
        self.assertEqual(
            self.string_to_list(routing_options.get_packet()), routing_options_binary_packet, 
            "Simple Routing Options Header creation - Buffer mismatch")
        
        self.assertEqual(
            routing_options.get_size(), len(routing_options_binary_packet),
            "Simple Routing Options Header creation - Size mismatch")
Ejemplo n.º 12
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")
    def test_simple_routing_options_contained_in_ipv6(self):
        ipv6_binary_packet = [ 
               0x64, 0x82, 0x46, 0x05, 
               0x05, 0xdc, 0x2b, 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]
        
        routing_options_binary_packet = [
               0x3a, 0x00, 0x00, 0x0a,
               0x00, 0x00, 0x00, 0x00]

        binary_packet = ipv6_binary_packet + routing_options_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_source_address("FE80::78F8:89D1:30FF:256B")
        ip6_packet.set_destination_address("FF02::1:3")
        
        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)

        ip6_packet.contains(routing_options)

        self.assertEquals(
            self.string_to_list(ip6_packet.get_packet()), binary_packet, 
            "IP6 Hop By Hop Header contained in IPv6 Header - Buffer mismatch")

        self.assertEquals(
            ip6_packet.get_size(), len(binary_packet),
            "IP6 Hop By Hop Header contained in IPv6 Header - Size mismatch")