def reset_lsa_instances():
     first = lsa.Lsa()
     first.create_header(0, 0, conf.LSA_TYPE_ROUTER, '0.0.0.0',
                         conf.ROUTER_ID, conf.INITIAL_SEQUENCE_NUMBER,
                         conf.VERSION_IPV4)
     second = lsa.Lsa()
     second.create_header(0, 0, conf.LSA_TYPE_ROUTER, '0.0.0.0',
                          conf.ROUTER_ID, conf.INITIAL_SEQUENCE_NUMBER,
                          conf.VERSION_IPV4)
     return first, second
    def lsdb_startup(router_id, version, area_id, is_abr, physical_ids,
                     interface_costs):
        database = lsdb.Lsdb(version, area_id)
        router_lsa = lsa.Lsa()
        if version == conf.VERSION_IPV4:
            link_state_id = router_id
            options = conf.OPTIONS_V2
        else:
            link_state_id = conf.DEFAULT_LINK_STATE_ID
            options = conf.OPTIONS_V3
        router_lsa.create_header(conf.INITIAL_LS_AGE, options,
                                 conf.LSA_TYPE_ROUTER, link_state_id,
                                 router_id, conf.INITIAL_SEQUENCE_NUMBER,
                                 version)
        router_lsa.create_router_lsa_body(False, False, is_abr, options,
                                          version)
        if version == conf.VERSION_IPV4:
            for i in range(len(physical_ids)):
                identifier = physical_ids[i]
                prefix = utils.Utils.interface_name_to_ipv4_prefix_and_length(
                    identifier)[0]
                netmask = utils.Utils.interface_name_to_ipv4_network_mask(
                    identifier)
                cost = interface_costs[i]
                router_lsa.add_link_info_v2(prefix, netmask,
                                            conf.LINK_TO_STUB_NETWORK,
                                            conf.DEFAULT_TOS, cost)
        database.add_lsa(router_lsa, None)

        if version == conf.VERSION_IPV6:
            intra_area_prefix_lsa = lsa.Lsa()
            referenced_ls_type = router_lsa.header.ls_type
            referenced_link_state_id = router_lsa.header.link_state_id
            referenced_advertising_router = router_lsa.header.advertising_router
            intra_area_prefix_lsa.create_header(
                conf.INITIAL_LS_AGE, conf.OPTIONS_V3,
                conf.LSA_TYPE_INTRA_AREA_PREFIX, link_state_id, router_id,
                conf.INITIAL_SEQUENCE_NUMBER, version)
            intra_area_prefix_lsa.create_intra_area_prefix_lsa_body(
                referenced_ls_type, referenced_link_state_id,
                referenced_advertising_router)
            for i in range(len(physical_ids)):
                identifier = physical_ids[i]
                prefix_data = utils.Utils.interface_name_to_ipv6_prefix_and_length(
                    identifier)
                prefix_length = prefix_data[1]
                prefix_options = conf.PREFIX_OPTIONS
                metric = interface_costs[i]
                prefix = prefix_data[0]
                intra_area_prefix_lsa.add_prefix_info(
                    prefix_length, prefix_options, metric, prefix,
                    conf.LSA_TYPE_INTRA_AREA_PREFIX)
            database.add_lsa(intra_area_prefix_lsa, None)
        return database
    def setUp(self):
        self.abr_lsa_v2 = lsa.Lsa()
        self.abr_lsa_v3 = lsa.Lsa()
        self.prefix_lsa_v2 = lsa.Lsa()
        self.prefix_lsa_v3 = lsa.Lsa()
        self.abr_lsa_v2.create_extension_header(conf.INITIAL_LS_AGE,
                                                conf.OPTIONS_V2,
                                                conf.OPAQUE_TYPE_ABR_LSA, 0,
                                                ADVERTISING_ROUTER,
                                                conf.INITIAL_SEQUENCE_NUMBER,
                                                conf.VERSION_IPV4)
        self.abr_lsa_v3.create_extension_header(
            conf.INITIAL_LS_AGE, conf.OPTIONS_V3, 0,
            conf.LSA_TYPE_EXTENSION_ABR_LSA, ADVERTISING_ROUTER,
            conf.INITIAL_SEQUENCE_NUMBER, conf.VERSION_IPV6)
        self.prefix_lsa_v2.create_extension_header(
            conf.INITIAL_LS_AGE, conf.OPTIONS_V2, conf.OPAQUE_TYPE_PREFIX_LSA,
            0, ADVERTISING_ROUTER, conf.INITIAL_SEQUENCE_NUMBER,
            conf.VERSION_IPV4)
        self.prefix_lsa_v3.create_extension_header(
            conf.INITIAL_LS_AGE, conf.OPTIONS_V3, 0,
            conf.LSA_TYPE_EXTENSION_PREFIX_LSA, ADVERTISING_ROUTER,
            conf.INITIAL_SEQUENCE_NUMBER, conf.VERSION_IPV6)
        self.abr_lsa_v2.create_extension_abr_lsa_body()
        self.abr_lsa_v3.create_extension_abr_lsa_body()
        self.prefix_lsa_v2.create_extension_prefix_lsa_body(conf.VERSION_IPV4)
        self.prefix_lsa_v3.create_extension_prefix_lsa_body(conf.VERSION_IPV6)
        self.abr_lsa_v2_id = [
            conf.LSA_TYPE_OPAQUE_AS,
            utils.Utils.decimal_to_ipv4(conf.OPAQUE_TYPE_ABR_LSA << 3 *
                                        conf.BYTE_SIZE), ADVERTISING_ROUTER
        ]
        self.abr_lsa_v3_id = [
            BITS_U_S1_S2 + conf.LSA_TYPE_EXTENSION_ABR_LSA,
            conf.DEFAULT_LINK_STATE_ID, ADVERTISING_ROUTER
        ]
        self.prefix_lsa_v2_id = [
            conf.LSA_TYPE_OPAQUE_AS,
            utils.Utils.decimal_to_ipv4(conf.OPAQUE_TYPE_PREFIX_LSA << 3 *
                                        conf.BYTE_SIZE), ADVERTISING_ROUTER
        ]
        self.prefix_lsa_v3_id = [
            BITS_U_S1_S2 + conf.LSA_TYPE_EXTENSION_PREFIX_LSA,
            conf.DEFAULT_LINK_STATE_ID, ADVERTISING_ROUTER
        ]

        self.extension_lsdb_v2 = extension_lsdb.ExtensionLsdb(
            conf.VERSION_IPV4)
        self.extension_lsdb_v3 = extension_lsdb.ExtensionLsdb(
            conf.VERSION_IPV6)
 def test_is_lsa_checksum_valid(self):
     new_lsa = lsa.Lsa()
     self.assertFalse(new_lsa.is_lsa_checksum_valid())
     new_lsa.create_header(1, 2, 1, '0.0.0.0', '1.1.1.1', 0,
                           conf.VERSION_IPV4)
     self.assertFalse(new_lsa.is_lsa_checksum_valid())
     new_lsa.create_router_lsa_body(False, False, False, 2,
                                    conf.VERSION_IPV4)
     self.assertTrue(new_lsa.is_lsa_checksum_valid())
     new_lsa.header.ls_age = 2
     self.assertTrue(new_lsa.is_lsa_checksum_valid())
     new_lsa.header.options = 3
     self.assertFalse(new_lsa.is_lsa_checksum_valid())
     new_lsa.set_lsa_checksum()
     self.assertTrue(new_lsa.is_lsa_checksum_valid())
     new_lsa.header.ls_checksum = 1
     self.assertFalse(new_lsa.is_lsa_checksum_valid())
     new_lsa.set_lsa_checksum()
     self.assertTrue(new_lsa.is_lsa_checksum_valid())
    def setUp(self):
        interface_identifier = conf.INTERFACE_NAMES[0]
        ipv4_address = utils.Utils.interface_name_to_ipv4_address(conf.INTERFACE_NAMES[0])
        ipv6_address = utils.Utils.interface_name_to_ipv6_link_local_address(conf.INTERFACE_NAMES[0])
        network_mask = utils.Utils.interface_name_to_ipv4_network_mask(conf.INTERFACE_NAMES[0])
        link_prefixes = utils.Utils.interface_name_to_ipv6_prefix_and_length(conf.INTERFACE_NAMES[0])
        area_id = conf.INTERFACE_AREAS[0]
        interface_pipeline_v2 = queue.Queue()
        interface_pipeline_v3 = queue.Queue()
        interface_shutdown_v2 = threading.Event()
        interface_shutdown_v3 = threading.Event()
        self.interface_ospfv2 = interface.Interface(
            conf.ROUTER_ID, interface_identifier, ipv4_address, '', network_mask, [], area_id, interface_pipeline_v2,
            interface_shutdown_v2, conf.VERSION_IPV4, None, False, False, conf.INTERFACE_COSTS[0])
        self.interface_ospfv3 = interface.Interface(
            conf.ROUTER_ID, interface_identifier, '', ipv6_address, '', link_prefixes, area_id, interface_pipeline_v3,
            interface_shutdown_v3, conf.VERSION_IPV6, None, False, False, conf.INTERFACE_COSTS[0])

        self.lsa_ospfv2_1 = lsa.Lsa()
        self.lsa_ospfv2_2 = lsa.Lsa()
        self.lsa_ospfv3_1 = lsa.Lsa()
        self.lsa_ospfv3_2 = lsa.Lsa()
        self.lsa_ospfv3_3 = lsa.Lsa()
        self.lsa_ospfv3_4 = lsa.Lsa()
        self.lsa_ospfv2_1.create_header(0, 34, 1, '1.1.1.1', '1.1.1.1', 2147483654, conf.VERSION_IPV4)
        self.lsa_ospfv2_1.create_router_lsa_body(False, False, False, 0, conf.VERSION_IPV4)
        self.lsa_ospfv2_2.create_header(0, 34, 2, '222.222.3.2', '2.2.2.2', 2147483649, conf.VERSION_IPV4)
        self.lsa_ospfv2_2.create_network_lsa_body('255.255.255.0', 0, ['2.2.2.2', '1.1.1.1'], conf.VERSION_IPV4)
        self.lsa_ospfv3_1.create_header(0, 0, 1, '0.0.0.0', '2.2.2.2', 2147483655, conf.VERSION_IPV6)
        self.lsa_ospfv3_1.create_router_lsa_body(False, False, False, 51, conf.VERSION_IPV6)
        self.lsa_ospfv3_2.create_header(0, 0, 2, '0.0.0.5', '2.2.2.2', 2147483650, conf.VERSION_IPV6)
        self.lsa_ospfv3_2.create_network_lsa_body('', 51, ['2.2.2.2', '1.1.1.1'], conf.VERSION_IPV6)
        self.lsa_ospfv3_3.create_header(0, 0, 9, '0.0.0.0', '2.2.2.2', 2147483653, conf.VERSION_IPV6)
        self.lsa_ospfv3_3.create_intra_area_prefix_lsa_body(1, '0.0.0.0', '2.2.2.2')
        self.lsa_ospfv3_4.create_header(0, 0, 8, '0.0.0.4', '1.1.1.1', 2147483650, conf.VERSION_IPV6)
        self.lsa_ospfv3_4.create_link_lsa_body(1, 51, 'fe80::c001:18ff:fe34:0')

        self.lsdb_ospfv2 = lsdb.Lsdb(conf.VERSION_IPV4, conf.BACKBONE_AREA)
        self.lsdb_ospfv3 = lsdb.Lsdb(conf.VERSION_IPV6, conf.BACKBONE_AREA)
    def test_clean_unconnected_routers(self):
        #  Setup
        router_id_1 = '1.1.1.1'
        router_id_2 = '2.2.2.2'
        router_id_3 = '3.3.3.3'
        router_id_4 = '4.4.4.4'
        router_ip_1_1 = '222.222.1.1'
        router_ip_1_2 = '222.222.2.1'
        router_ip_2 = '222.222.1.2'
        router_ip_3 = '222.222.1.3'
        router_ip_4 = '222.222.2.4'
        network_prefix_1 = '222.222.1.0'
        network_prefix_2 = '222.222.2.0'
        options = conf.OPTIONS_V2
        cost = 10
        network_mask = '255.255.255.0'
        area_1 = '1.1.1.1'
        area_2 = '2.2.2.2'

        #  Case 1

        router_lsa_1 = lsa.Lsa()
        router_lsa_2 = lsa.Lsa()
        router_lsa_3 = lsa.Lsa()
        network_lsa_1 = lsa.Lsa()

        router_lsa_1.create_header(conf.INITIAL_LS_AGE, options, conf.LSA_TYPE_ROUTER, router_id_1, router_id_1,
                                   conf.INITIAL_SEQUENCE_NUMBER, conf.VERSION_IPV4)
        router_lsa_2.create_header(conf.INITIAL_LS_AGE, options, conf.LSA_TYPE_ROUTER, router_id_2, router_id_2,
                                   conf.INITIAL_SEQUENCE_NUMBER, conf.VERSION_IPV4)
        router_lsa_3.create_header(conf.INITIAL_LS_AGE, options, conf.LSA_TYPE_ROUTER, router_id_3, router_id_3,
                                   conf.INITIAL_SEQUENCE_NUMBER, conf.VERSION_IPV4)
        network_lsa_1.create_header(conf.INITIAL_LS_AGE, options, conf.LSA_TYPE_NETWORK, conf.DEFAULT_LINK_STATE_ID,
                                    router_ip_1_1, conf.INITIAL_SEQUENCE_NUMBER, conf.VERSION_IPV4)
        router_lsa_1.create_router_lsa_body(False, False, True, options, conf.VERSION_IPV4)
        router_lsa_2.create_router_lsa_body(False, False, True, options, conf.VERSION_IPV4)
        router_lsa_3.create_router_lsa_body(False, False, True, options, conf.VERSION_IPV4)
        network_lsa_1.create_network_lsa_body(
            network_mask, options, [router_id_1, router_id_2, router_id_3], conf.VERSION_IPV4)
        router_lsa_1.add_link_info_v2(
            router_ip_1_1, router_ip_1_1, conf.LINK_TO_TRANSIT_NETWORK, conf.DEFAULT_TOS, cost)
        router_lsa_2.add_link_info_v2(router_ip_1_1, router_ip_2, conf.LINK_TO_TRANSIT_NETWORK, conf.DEFAULT_TOS, cost)
        router_lsa_3.add_link_info_v2(router_ip_1_1, router_ip_3, conf.LINK_TO_TRANSIT_NETWORK, conf.DEFAULT_TOS, cost)

        database = lsdb.Lsdb(conf.VERSION_IPV4, conf.BACKBONE_AREA)
        for query_lsa in [router_lsa_1, router_lsa_2, router_lsa_3, network_lsa_1]:
            database.add_lsa(query_lsa, None)
        lsdb_dict = {conf.BACKBONE_AREA: database}

        self.assertTrue(router.Router.is_router_connected(router_id_1, lsdb_dict, conf.VERSION_IPV4))
        self.assertTrue(router.Router.is_router_connected(router_id_2, lsdb_dict, conf.VERSION_IPV4))
        self.assertTrue(router.Router.is_router_connected(router_id_3, lsdb_dict, conf.VERSION_IPV4))
        self.assertFalse(router.Router.is_router_connected('10.10.10.10', lsdb_dict, conf.VERSION_IPV4))
        lsdb_dict = router.Router.clean_unconnected_routers(copy.deepcopy(lsdb_dict), None, conf.VERSION_IPV4)
        self.assertEqual(4, len(lsdb_dict[conf.BACKBONE_AREA].get_lsdb([], None)))

        router_lsa_3.body.links = []
        router_lsa_3.add_link_info_v2(network_prefix_1, network_mask, conf.LINK_TO_STUB_NETWORK, conf.DEFAULT_TOS, cost)
        network_lsa_1.body.attached_routers = [router_id_1, router_id_2]
        database = lsdb.Lsdb(conf.VERSION_IPV4, conf.BACKBONE_AREA)
        for query_lsa in [router_lsa_1, router_lsa_2, router_lsa_3, network_lsa_1]:
            database.add_lsa(query_lsa, None)
        lsdb_dict = {conf.BACKBONE_AREA: database}

        self.assertTrue(router.Router.is_router_connected(router_id_1, lsdb_dict, conf.VERSION_IPV4))
        self.assertTrue(router.Router.is_router_connected(router_id_2, lsdb_dict, conf.VERSION_IPV4))
        self.assertFalse(router.Router.is_router_connected(router_id_3, lsdb_dict, conf.VERSION_IPV4))
        lsdb_dict = router.Router.clean_unconnected_routers(copy.deepcopy(lsdb_dict), None, conf.VERSION_IPV4)
        self.assertNotEqual(len(database.get_lsdb([], None)), len(lsdb_dict[conf.BACKBONE_AREA].get_lsdb([], None)))
        self.assertEqual(3, len(lsdb_dict[conf.BACKBONE_AREA].get_lsdb([], None)))
        self.assertEqual(2, len(lsdb_dict[conf.BACKBONE_AREA].router_lsa_list))
        self.assertEqual(1, len(lsdb_dict[conf.BACKBONE_AREA].network_lsa_list))

        #  Case 2

        router_lsa_1_1 = lsa.Lsa()
        router_lsa_1_2 = lsa.Lsa()
        router_lsa_2 = lsa.Lsa()
        router_lsa_3 = lsa.Lsa()
        router_lsa_4 = lsa.Lsa()
        network_lsa_1 = lsa.Lsa()
        network_lsa_2 = lsa.Lsa()

        router_lsa_1_1.create_header(conf.INITIAL_LS_AGE, options, conf.LSA_TYPE_ROUTER, router_id_1, router_id_1,
                                     conf.INITIAL_SEQUENCE_NUMBER, conf.VERSION_IPV4)
        router_lsa_1_2.create_header(conf.INITIAL_LS_AGE, options, conf.LSA_TYPE_ROUTER, router_id_1, router_id_1,
                                     conf.INITIAL_SEQUENCE_NUMBER, conf.VERSION_IPV4)
        router_lsa_2.create_header(conf.INITIAL_LS_AGE, options, conf.LSA_TYPE_ROUTER, router_id_2, router_id_2,
                                   conf.INITIAL_SEQUENCE_NUMBER, conf.VERSION_IPV4)
        router_lsa_3.create_header(conf.INITIAL_LS_AGE, options, conf.LSA_TYPE_ROUTER, router_id_3, router_id_3,
                                   conf.INITIAL_SEQUENCE_NUMBER, conf.VERSION_IPV4)
        router_lsa_4.create_header(conf.INITIAL_LS_AGE, options, conf.LSA_TYPE_ROUTER, router_id_4, router_id_4,
                                   conf.INITIAL_SEQUENCE_NUMBER, conf.VERSION_IPV4)
        network_lsa_1.create_header(conf.INITIAL_LS_AGE, options, conf.LSA_TYPE_NETWORK, router_ip_3, router_id_3,
                                    conf.INITIAL_SEQUENCE_NUMBER, conf.VERSION_IPV4)
        network_lsa_2.create_header(conf.INITIAL_LS_AGE, options, conf.LSA_TYPE_NETWORK, router_ip_4, router_id_4,
                                    conf.INITIAL_SEQUENCE_NUMBER, conf.VERSION_IPV4)
        router_lsa_1_1.create_router_lsa_body(False, False, True, options, conf.VERSION_IPV4)
        router_lsa_1_2.create_router_lsa_body(False, False, True, options, conf.VERSION_IPV4)
        router_lsa_2.create_router_lsa_body(False, False, True, options, conf.VERSION_IPV4)
        router_lsa_3.create_router_lsa_body(False, False, True, options, conf.VERSION_IPV4)
        router_lsa_4.create_router_lsa_body(False, False, True, options, conf.VERSION_IPV4)
        network_lsa_1.create_network_lsa_body(
            network_mask, options, [router_id_1, router_id_2, router_id_3], conf.VERSION_IPV4)
        network_lsa_2.create_network_lsa_body(network_mask, options, [router_id_1, router_id_4], conf.VERSION_IPV4)
        router_lsa_1_1.add_link_info_v2(
            router_ip_3, router_ip_1_1, conf.LINK_TO_TRANSIT_NETWORK, conf.DEFAULT_TOS, cost)
        router_lsa_1_2.add_link_info_v2(
            router_ip_4, router_ip_1_2, conf.LINK_TO_TRANSIT_NETWORK, conf.DEFAULT_TOS, cost)
        router_lsa_2.add_link_info_v2(router_ip_3, router_ip_2, conf.LINK_TO_TRANSIT_NETWORK, conf.DEFAULT_TOS, cost)
        router_lsa_3.add_link_info_v2(router_ip_3, router_ip_3, conf.LINK_TO_TRANSIT_NETWORK, conf.DEFAULT_TOS, cost)
        router_lsa_4.add_link_info_v2(router_ip_4, router_ip_4, conf.LINK_TO_TRANSIT_NETWORK, conf.DEFAULT_TOS, cost)

        database_1 = lsdb.Lsdb(conf.VERSION_IPV4, area_1)
        database_2 = lsdb.Lsdb(conf.VERSION_IPV4, area_2)
        for query_lsa in [router_lsa_1_1, router_lsa_2, router_lsa_3, network_lsa_1]:
            database_1.add_lsa(query_lsa, None)
        for query_lsa in [router_lsa_1_2, router_lsa_4, network_lsa_2]:
            database_2.add_lsa(query_lsa, None)
        lsdb_dict = {area_1: database_1, area_2: database_2}

        self.assertTrue(router.Router.is_router_connected(router_id_1, lsdb_dict, conf.VERSION_IPV4))
        self.assertTrue(router.Router.is_router_connected(router_id_2, lsdb_dict, conf.VERSION_IPV4))
        self.assertTrue(router.Router.is_router_connected(router_id_3, lsdb_dict, conf.VERSION_IPV4))
        self.assertTrue(router.Router.is_router_connected(router_id_4, lsdb_dict, conf.VERSION_IPV4))
        self.assertFalse(router.Router.is_router_connected('10.10.10.10', lsdb_dict, conf.VERSION_IPV4))
        lsdb_dict = router.Router.clean_unconnected_routers(copy.deepcopy(lsdb_dict), None, conf.VERSION_IPV4)
        self.assertEqual(4, len(lsdb_dict[area_1].get_lsdb([], None)))
        self.assertEqual(3, len(lsdb_dict[area_2].get_lsdb([], None)))
    def test_add_lsa(self):

        #  OSPFv2

        self.lsdb_ospfv2.add_lsa(self.lsa_ospfv2_1, None)
        self.assertEqual(1, len(self.lsdb_ospfv2.get_lsdb([self.interface_ospfv2], None)))
        self.assertEqual(1, self.lsdb_ospfv2.get_lsdb([self.interface_ospfv2], None)[0].header.ls_type)
        self.assertEqual(
            2147483654, self.lsdb_ospfv2.get_lsdb([self.interface_ospfv2], None)[0].header.ls_sequence_number)
        self.assertTrue(self.lsdb_ospfv2.is_modified.is_set())
        self.lsdb_ospfv2.is_modified.clear()
        lsa_ospfv2_3 = lsa.Lsa()
        lsa_ospfv2_3.create_header(1, 34, 1, '1.1.1.1', '1.1.1.1', 10000, conf.VERSION_IPV4)
        lsa_ospfv2_3.create_router_lsa_body(False, False, False, 0, conf.VERSION_IPV4)
        self.lsdb_ospfv2.add_lsa(lsa_ospfv2_3, None)
        self.assertEqual(1, len(self.lsdb_ospfv2.get_lsdb([self.interface_ospfv2], None)))
        self.assertEqual(1, self.lsdb_ospfv2.get_lsdb([self.interface_ospfv2], None)[0].header.ls_type)
        self.assertEqual(10000, self.lsdb_ospfv2.get_lsdb([self.interface_ospfv2], None)[0].header.ls_sequence_number)
        self.assertTrue(self.lsdb_ospfv2.is_modified.is_set())
        self.lsdb_ospfv2.is_modified.clear()
        lsa_ospfv2_4 = lsa.Lsa()
        lsa_ospfv2_4.create_header(1, 34, 1, '4.4.4.4', '1.1.1.1', 10000, conf.VERSION_IPV4)
        lsa_ospfv2_4.create_router_lsa_body(False, False, False, 0, conf.VERSION_IPV4)
        self.lsdb_ospfv2.add_lsa(lsa_ospfv2_4, None)
        self.assertEqual(2, len(self.lsdb_ospfv2.get_lsdb([self.interface_ospfv2], None)))
        self.assertEqual('1.1.1.1', self.lsdb_ospfv2.get_lsdb([self.interface_ospfv2], None)[0].header.link_state_id)
        self.assertEqual('4.4.4.4', self.lsdb_ospfv2.get_lsdb([self.interface_ospfv2], None)[1].header.link_state_id)
        self.assertTrue(self.lsdb_ospfv2.is_modified.is_set())
        self.lsdb_ospfv2.is_modified.clear()
        self.lsdb_ospfv2.add_lsa(self.lsa_ospfv2_2, None)
        self.assertEqual(3, len(self.lsdb_ospfv2.get_lsdb([self.interface_ospfv2], None)))
        self.assertEqual(2, self.lsdb_ospfv2.get_lsdb([self.interface_ospfv2], None)[2].header.ls_type)
        self.assertTrue(self.lsdb_ospfv2.is_modified.is_set())
        self.lsdb_ospfv2.is_modified.clear()

        #  OSPFv3 - Area scope LSAs

        self.lsdb_ospfv3.add_lsa(self.lsa_ospfv3_1, None)
        self.assertEqual(1, len(self.lsdb_ospfv3.get_lsdb([self.interface_ospfv3], None)))
        self.assertEqual(0x2001, self.lsdb_ospfv3.get_lsdb([self.interface_ospfv3], None)[0].header.ls_type)
        self.assertEqual(
            2147483655, self.lsdb_ospfv3.get_lsdb([self.interface_ospfv3], None)[0].header.ls_sequence_number)
        self.assertTrue(self.lsdb_ospfv3.is_modified.is_set())
        self.lsdb_ospfv3.is_modified.clear()
        lsa_ospfv3_5 = lsa.Lsa()
        lsa_ospfv3_5.create_header(1, 0, 1, '0.0.0.0', '2.2.2.2', 10000, conf.VERSION_IPV6)
        lsa_ospfv3_5.create_router_lsa_body(False, False, False, 51, conf.VERSION_IPV6)
        self.lsdb_ospfv3.add_lsa(lsa_ospfv3_5, None)
        self.assertEqual(1, len(self.lsdb_ospfv3.get_lsdb([self.interface_ospfv3], None)))
        self.assertEqual(0x2001, self.lsdb_ospfv3.get_lsdb([self.interface_ospfv3], None)[0].header.ls_type)
        self.assertEqual(10000, self.lsdb_ospfv3.get_lsdb([self.interface_ospfv3], None)[0].header.ls_sequence_number)
        self.assertTrue(self.lsdb_ospfv3.is_modified.is_set())
        self.lsdb_ospfv3.is_modified.clear()
        lsa_ospfv3_6 = lsa.Lsa()
        lsa_ospfv3_6.create_header(1, 0, 9, '5.5.5.5', '2.2.2.2', 2147483653, conf.VERSION_IPV6)
        lsa_ospfv3_6.create_intra_area_prefix_lsa_body(1, '0.0.0.0', '2.2.2.2')
        self.lsdb_ospfv3.add_lsa(lsa_ospfv3_6, None)
        self.assertEqual(2, len(self.lsdb_ospfv3.get_lsdb([self.interface_ospfv3], None)))
        self.assertEqual('0.0.0.0', self.lsdb_ospfv3.get_lsdb([self.interface_ospfv3], None)[0].header.link_state_id)
        self.assertEqual('5.5.5.5', self.lsdb_ospfv3.get_lsdb([self.interface_ospfv3], None)[1].header.link_state_id)
        self.assertTrue(self.lsdb_ospfv3.is_modified.is_set())
        self.lsdb_ospfv3.is_modified.clear()
        self.lsdb_ospfv3.add_lsa(self.lsa_ospfv3_2, None)
        self.assertEqual(3, len(self.lsdb_ospfv3.get_lsdb([self.interface_ospfv3], None)))
        self.assertEqual(0x2001, self.lsdb_ospfv3.get_lsdb([self.interface_ospfv3], None)[0].header.ls_type)
        self.assertEqual(0x2002, self.lsdb_ospfv3.get_lsdb([self.interface_ospfv3], None)[1].header.ls_type)
        self.assertEqual(0x2009, self.lsdb_ospfv3.get_lsdb([self.interface_ospfv3], None)[2].header.ls_type)
        self.assertTrue(self.lsdb_ospfv3.is_modified.is_set())
        self.lsdb_ospfv3.is_modified.clear()

        #  OSPFv3 - Link-local scope LSAs

        self.interface_ospfv3.link_local_lsa_list = []
        self.lsdb_ospfv3.add_lsa(self.lsa_ospfv3_4, self.interface_ospfv3)
        self.assertEqual(4, len(self.lsdb_ospfv3.get_lsdb([self.interface_ospfv3], None)))
        self.assertEqual(1, len(self.interface_ospfv3.link_local_lsa_list))
        ls_type = self.lsa_ospfv3_4.header.ls_type
        link_state_id = self.lsa_ospfv3_4.header.link_state_id
        advertising_router = self.lsa_ospfv3_4.header.advertising_router
        self.assertEqual(8, self.interface_ospfv3.get_link_local_lsa(ls_type, link_state_id, advertising_router).
                         header.ls_type)
        self.assertTrue(self.lsdb_ospfv3.is_modified.is_set())
        self.lsdb_ospfv3.is_modified.clear()
    def test_add_lsa(self):

        #  OSPFv2

        new_lsa_v2_1 = lsa.Lsa()
        new_lsa_v2_1.create_extension_header(conf.INITIAL_LS_AGE,
                                             conf.OPTIONS_V2,
                                             conf.OPAQUE_TYPE_ABR_LSA, 0,
                                             ADVERTISING_ROUTER,
                                             conf.INITIAL_SEQUENCE_NUMBER + 1,
                                             conf.VERSION_IPV4)
        new_lsa_v2_1.create_extension_abr_lsa_body()
        new_lsa_v2_2 = lsa.Lsa()
        new_lsa_v2_2.create_extension_header(conf.INITIAL_LS_AGE,
                                             conf.OPTIONS_V2,
                                             conf.OPAQUE_TYPE_PREFIX_LSA, 0,
                                             ADVERTISING_ROUTER,
                                             conf.INITIAL_SEQUENCE_NUMBER + 1,
                                             conf.VERSION_IPV4)
        new_lsa_v2_2.create_extension_prefix_lsa_body(conf.VERSION_IPV4)

        self.extension_lsdb_v2.add_extension_lsa(self.abr_lsa_v2)
        self.assertEqual(1,
                         len(self.extension_lsdb_v2.get_extension_lsdb(None)))
        self.assertEqual(
            conf.LSA_TYPE_OPAQUE_AS,
            self.extension_lsdb_v2.get_extension_lsdb(None)[0].header.ls_type)
        self.assertEqual(
            conf.OPAQUE_TYPE_ABR_LSA,
            self.extension_lsdb_v2.get_extension_lsdb(None)
            [0].get_opaque_type())
        self.assertEqual(
            conf.INITIAL_SEQUENCE_NUMBER,
            self.extension_lsdb_v2.get_extension_lsdb(None)
            [0].header.ls_sequence_number)
        self.assertTrue(self.extension_lsdb_v2.is_modified.is_set())
        self.extension_lsdb_v2.is_modified.clear()

        self.extension_lsdb_v2.add_extension_lsa(new_lsa_v2_1)
        self.assertEqual(1,
                         len(self.extension_lsdb_v2.get_extension_lsdb(None)))
        self.assertEqual(
            conf.LSA_TYPE_OPAQUE_AS,
            self.extension_lsdb_v2.get_extension_lsdb(None)[0].header.ls_type)
        self.assertEqual(
            conf.OPAQUE_TYPE_ABR_LSA,
            self.extension_lsdb_v2.get_extension_lsdb(None)
            [0].get_opaque_type())
        self.assertEqual(
            conf.INITIAL_SEQUENCE_NUMBER + 1,
            self.extension_lsdb_v2.get_extension_lsdb(None)
            [0].header.ls_sequence_number)
        self.assertTrue(self.extension_lsdb_v2.is_modified.is_set())
        self.extension_lsdb_v2.is_modified.clear()

        self.extension_lsdb_v2.add_extension_lsa(new_lsa_v2_2)
        self.assertEqual(2,
                         len(self.extension_lsdb_v2.get_extension_lsdb(None)))
        self.assertEqual(
            conf.LSA_TYPE_OPAQUE_AS,
            self.extension_lsdb_v2.get_extension_lsdb(None)[1].header.ls_type)
        self.assertEqual(
            conf.OPAQUE_TYPE_PREFIX_LSA,
            self.extension_lsdb_v2.get_extension_lsdb(None)
            [1].get_opaque_type())
        self.assertEqual(
            conf.INITIAL_SEQUENCE_NUMBER + 1,
            self.extension_lsdb_v2.get_extension_lsdb(None)
            [1].header.ls_sequence_number)
        self.assertTrue(self.extension_lsdb_v2.is_modified.is_set())
        self.extension_lsdb_v2.is_modified.clear()

        self.extension_lsdb_v2.add_extension_lsa(self.prefix_lsa_v2)
        self.assertEqual(2,
                         len(self.extension_lsdb_v2.get_extension_lsdb(None)))
        self.assertEqual(
            conf.LSA_TYPE_OPAQUE_AS,
            self.extension_lsdb_v2.get_extension_lsdb(None)[1].header.ls_type)
        self.assertEqual(
            conf.OPAQUE_TYPE_PREFIX_LSA,
            self.extension_lsdb_v2.get_extension_lsdb(None)
            [1].get_opaque_type())
        self.assertEqual(
            conf.INITIAL_SEQUENCE_NUMBER,
            self.extension_lsdb_v2.get_extension_lsdb(None)
            [1].header.ls_sequence_number)
        self.assertTrue(self.extension_lsdb_v2.is_modified.is_set())
        self.extension_lsdb_v2.is_modified.clear()

        #  OSPFv3

        new_lsa_v3_1 = lsa.Lsa()
        new_lsa_v3_1.create_extension_header(conf.INITIAL_LS_AGE,
                                             conf.OPTIONS_V3, 0,
                                             conf.LSA_TYPE_EXTENSION_ABR_LSA,
                                             ADVERTISING_ROUTER,
                                             conf.INITIAL_SEQUENCE_NUMBER + 1,
                                             conf.VERSION_IPV6)
        new_lsa_v3_1.create_extension_abr_lsa_body()
        new_lsa_v3_2 = lsa.Lsa()
        new_lsa_v3_2.create_extension_header(
            conf.INITIAL_LS_AGE, conf.OPTIONS_V3, 0,
            conf.LSA_TYPE_EXTENSION_PREFIX_LSA, ADVERTISING_ROUTER,
            conf.INITIAL_SEQUENCE_NUMBER + 1, conf.VERSION_IPV6)
        new_lsa_v3_2.create_extension_prefix_lsa_body(conf.VERSION_IPV6)

        self.extension_lsdb_v3.add_extension_lsa(self.abr_lsa_v3)
        self.assertEqual(1,
                         len(self.extension_lsdb_v3.get_extension_lsdb(None)))
        self.assertEqual(
            BITS_U_S1_S2 + conf.LSA_TYPE_EXTENSION_ABR_LSA,
            self.extension_lsdb_v3.get_extension_lsdb(None)[0].header.ls_type)
        self.assertEqual(
            conf.INITIAL_SEQUENCE_NUMBER,
            self.extension_lsdb_v3.get_extension_lsdb(None)
            [0].header.ls_sequence_number)
        self.assertTrue(self.extension_lsdb_v3.is_modified.is_set())
        self.extension_lsdb_v3.is_modified.clear()

        self.extension_lsdb_v3.add_extension_lsa(new_lsa_v3_1)
        self.assertEqual(1,
                         len(self.extension_lsdb_v3.get_extension_lsdb(None)))
        self.assertEqual(
            BITS_U_S1_S2 + conf.LSA_TYPE_EXTENSION_ABR_LSA,
            self.extension_lsdb_v3.get_extension_lsdb(None)[0].header.ls_type)
        self.assertEqual(
            conf.INITIAL_SEQUENCE_NUMBER + 1,
            self.extension_lsdb_v3.get_extension_lsdb(None)
            [0].header.ls_sequence_number)
        self.assertTrue(self.extension_lsdb_v3.is_modified.is_set())
        self.extension_lsdb_v3.is_modified.clear()

        self.extension_lsdb_v3.add_extension_lsa(new_lsa_v3_2)
        self.assertEqual(2,
                         len(self.extension_lsdb_v3.get_extension_lsdb(None)))
        self.assertEqual(
            BITS_U_S1_S2 + conf.LSA_TYPE_EXTENSION_PREFIX_LSA,
            self.extension_lsdb_v3.get_extension_lsdb(None)[1].header.ls_type)
        self.assertEqual(
            conf.INITIAL_SEQUENCE_NUMBER + 1,
            self.extension_lsdb_v3.get_extension_lsdb(None)
            [1].header.ls_sequence_number)
        self.assertTrue(self.extension_lsdb_v3.is_modified.is_set())
        self.extension_lsdb_v3.is_modified.clear()

        self.extension_lsdb_v3.add_extension_lsa(self.prefix_lsa_v3)
        self.assertEqual(2,
                         len(self.extension_lsdb_v3.get_extension_lsdb(None)))
        self.assertEqual(
            BITS_U_S1_S2 + conf.LSA_TYPE_EXTENSION_PREFIX_LSA,
            self.extension_lsdb_v3.get_extension_lsdb(None)[1].header.ls_type)
        self.assertEqual(
            conf.INITIAL_SEQUENCE_NUMBER,
            self.extension_lsdb_v3.get_extension_lsdb(None)
            [1].header.ls_sequence_number)
        self.assertTrue(self.extension_lsdb_v3.is_modified.is_set())
        self.extension_lsdb_v3.is_modified.clear()
    def test_pack_lsa(self):
        #  Router-LSA - OSPFv2
        router_lsa = lsa.Lsa()
        router_lsa.create_header(1, 34, 1, '1.1.1.1', '1.1.1.1', 2147483654,
                                 conf.VERSION_IPV4)
        router_lsa.create_router_lsa_body(False, False, False, 0,
                                          conf.VERSION_IPV4)
        router_lsa.add_link_info_v2('3.3.3.3', '222.222.6.1', 1, 0, 64)
        router_lsa.add_link_info_v2('222.222.6.0', '255.255.255.0', 3, 0, 64)
        router_lsa.add_link_info_v2('222.222.3.2', '222.222.3.1', 2, 0, 10)
        router_lsa.add_link_info_v2('222.222.2.0', '255.255.255.0', 3, 0, 10)
        router_lsa.add_link_info_v2('222.222.1.0', '255.255.255.0', 3, 0, 1)
        self.assertEqual(TestLsa.router_lsa_v2_bytes, router_lsa.pack_lsa())

        #  Router-LSA - OSPFv3
        router_lsa = lsa.Lsa()
        router_lsa.create_header(1, 0, 1, '0.0.0.0', '2.2.2.2', 2147483655,
                                 conf.VERSION_IPV6)
        router_lsa.create_router_lsa_body(False, False, False, 51,
                                          conf.VERSION_IPV6)
        router_lsa.add_link_info_v3(2, 1, 6, 4, '3.3.3.3')
        router_lsa.add_link_info_v3(2, 10, 5, 5, '2.2.2.2')
        self.assertEqual(TestLsa.router_lsa_v3_bytes, router_lsa.pack_lsa())

        #  Network-LSA - OSPFv2
        network_lsa = lsa.Lsa()
        network_lsa.create_header(1, 34, 2, '222.222.3.2', '2.2.2.2',
                                  2147483649, conf.VERSION_IPV4)
        network_lsa.create_network_lsa_body('255.255.255.0', 0,
                                            ['2.2.2.2', '1.1.1.1'],
                                            conf.VERSION_IPV4)
        self.assertEqual(TestLsa.network_lsa_v2_bytes, network_lsa.pack_lsa())

        #  Network-LSA - OSPFv3
        network_lsa = lsa.Lsa()
        network_lsa.create_header(1, 0, 2, '0.0.0.5', '2.2.2.2', 2147483650,
                                  conf.VERSION_IPV6)
        network_lsa.create_network_lsa_body('', 51, ['2.2.2.2', '1.1.1.1'],
                                            conf.VERSION_IPV6)
        self.assertEqual(TestLsa.network_lsa_v3_bytes, network_lsa.pack_lsa())

        #  Intra-Area-Prefix-LSA
        intra_area_prefix_lsa = lsa.Lsa()
        intra_area_prefix_lsa.create_header(1, 0, 9, '0.0.0.0', '2.2.2.2',
                                            2147483653, conf.VERSION_IPV6)
        intra_area_prefix_lsa.create_intra_area_prefix_lsa_body(
            1, '0.0.0.0', '2.2.2.2')
        intra_area_prefix_lsa.add_prefix_info(64, 0, 10, '2001:db8:cafe:4::',
                                              conf.LSA_TYPE_INTRA_AREA_PREFIX)
        self.assertEqual(TestLsa.intra_area_prefix_lsa_bytes,
                         intra_area_prefix_lsa.pack_lsa())

        #  Link-LSA
        link_lsa = lsa.Lsa()
        link_lsa.create_header(38, 0, 8, '0.0.0.4', '1.1.1.1', 2147483650,
                               conf.VERSION_IPV6)
        link_lsa.create_link_lsa_body(1, 51, 'fe80::c001:18ff:fe34:0')
        link_lsa.add_prefix_info(64, 0, 0, '2001:db8:cafe:3::',
                                 conf.LSA_TYPE_LINK)
        self.assertEqual(TestLsa.link_lsa_bytes, link_lsa.pack_lsa())

        #  Summary-LSA
        summary_lsa_3 = lsa.Lsa()
        summary_lsa_4 = lsa.Lsa()
        summary_lsa_3.create_header(20, 0, 3, '222.222.1.0', '4.4.4.4',
                                    2147483649, conf.VERSION_IPV4)
        summary_lsa_4.create_header(20, 0, 4, '222.222.1.0', '4.4.4.4',
                                    2147483649, conf.VERSION_IPV4)
        summary_lsa_3.create_summary_lsa_body('255.255.255.0', 10)
        summary_lsa_4.create_summary_lsa_body('255.255.255.0', 10)
        self.assertEqual(TestLsa.summary_lsa_3_bytes, summary_lsa_3.pack_lsa())
        self.assertEqual(TestLsa.summary_lsa_4_bytes, summary_lsa_4.pack_lsa())

        #  Inter-Area-Prefix LSA
        inter_area_prefix_lsa = lsa.Lsa()
        inter_area_prefix_lsa.create_header(20, 0, 3, '0.0.0.1', '4.4.4.4',
                                            2147483649, conf.VERSION_IPV6)
        inter_area_prefix_lsa.create_inter_area_prefix_lsa_body(
            10, 64, 0, '2001:db8:cafe:1::')
        self.assertEqual(TestLsa.inter_area_prefix_lsa_bytes,
                         inter_area_prefix_lsa.pack_lsa())

        #  Extension ABR-LSA - OSPFv2
        extension_abr_lsa = lsa.Lsa()
        extension_abr_lsa.create_extension_header(1, 0,
                                                  conf.OPAQUE_TYPE_ABR_LSA, 0,
                                                  '4.4.4.4', 2147483649,
                                                  conf.VERSION_IPV4)
        extension_abr_lsa.create_extension_abr_lsa_body()
        extension_abr_lsa.add_abr_info(10, '1.1.1.1')
        extension_abr_lsa.add_abr_info(20, '2.2.2.2')
        self.assertEqual(TestLsa.extension_abr_lsa_v2_bytes,
                         extension_abr_lsa.pack_lsa())

        #  Extension ABR-LSA - OSPFv3
        extension_abr_lsa = lsa.Lsa()
        extension_abr_lsa.create_extension_header(
            10, 0, 0, conf.LSA_TYPE_EXTENSION_ABR_LSA, '4.4.4.4', 2147483650,
            conf.VERSION_IPV6)
        extension_abr_lsa.create_extension_abr_lsa_body()
        extension_abr_lsa.add_abr_info(30, '3.3.3.3')
        extension_abr_lsa.add_abr_info(40, '4.4.4.4')
        self.assertEqual(TestLsa.extension_abr_lsa_v3_bytes,
                         extension_abr_lsa.pack_lsa())

        #  Extension Prefix-LSA - OSPFv2
        extension_prefix_lsa = lsa.Lsa()
        extension_prefix_lsa.create_extension_header(
            10, 0, conf.OPAQUE_TYPE_PREFIX_LSA, 0, '1.1.1.1', 2147483649,
            conf.VERSION_IPV4)
        extension_prefix_lsa.create_extension_prefix_lsa_body(
            conf.VERSION_IPV4)
        extension_prefix_lsa.add_subnet_info(10, '255.255.255.0',
                                             '222.222.1.0')
        extension_prefix_lsa.add_subnet_info(20, '255.255.0.0', '222.1.0.0')
        extension_prefix_lsa.add_subnet_info(30, '255.0.0.0', '1.0.0.0')
        extension_prefix_lsa.add_subnet_info(40, '0.0.0.0', '0.0.0.0')
        self.assertEqual(TestLsa.extension_prefix_lsa_v2_bytes,
                         extension_prefix_lsa.pack_lsa())

        #  Extension Prefix-LSA - OSPFv3
        extension_prefix_lsa = lsa.Lsa()
        extension_prefix_lsa.create_extension_header(
            10, 0, 0, conf.LSA_TYPE_EXTENSION_PREFIX_LSA, '4.4.4.4',
            2147483650, conf.VERSION_IPV6)
        extension_prefix_lsa.create_extension_prefix_lsa_body(
            conf.VERSION_IPV6)
        extension_prefix_lsa.add_prefix_info_extension(10, 0, 0, '::')
        extension_prefix_lsa.add_prefix_info_extension(20, 32, 0, '2001:db8::')
        extension_prefix_lsa.add_prefix_info_extension(30, 64, 0,
                                                       '2001:db8:cafe:1::')
        extension_prefix_lsa.add_prefix_info_extension(40, 96, 0,
                                                       '2001:db8:cafe:1::')
        extension_prefix_lsa.add_prefix_info_extension(50, 128, 0,
                                                       '2001:db8:cafe:1::')
        self.assertEqual(TestLsa.extension_prefix_lsa_v3_bytes,
                         extension_prefix_lsa.pack_lsa())
    def test_is_extension_lsa_identifier_equal(self):
        #  OSPFv2

        initial_opaque_type = conf.OPAQUE_TYPE_ABR_LSA
        initial_ls_type = conf.LSA_TYPE_EXTENSION_ABR_LSA
        initial_advertising_router = '1.1.1.1'

        first = lsa.Lsa()
        first.create_extension_header(conf.INITIAL_LS_AGE, conf.OPTIONS_V2,
                                      conf.OPAQUE_TYPE_ABR_LSA,
                                      initial_opaque_type,
                                      initial_advertising_router,
                                      conf.INITIAL_SEQUENCE_NUMBER,
                                      conf.VERSION_IPV4)
        second = lsa.Lsa()
        second.create_extension_header(
            conf.INITIAL_LS_AGE + 1, conf.OPTIONS_V2 + 1,
            conf.OPAQUE_TYPE_ABR_LSA, initial_opaque_type,
            initial_advertising_router, conf.INITIAL_SEQUENCE_NUMBER + 1,
            conf.VERSION_IPV4)
        self.assertTrue(
            first.is_lsa_identifier_equal(second.header.ls_type,
                                          second.header.link_state_id,
                                          second.header.advertising_router))
        self.assertTrue(
            second.is_lsa_identifier_equal(first.header.ls_type,
                                           first.header.link_state_id,
                                           first.header.advertising_router))

        first.create_extension_header(conf.INITIAL_LS_AGE, conf.OPTIONS_V2,
                                      conf.OPAQUE_TYPE_PREFIX_LSA,
                                      conf.LSA_TYPE_OPAQUE_AS,
                                      initial_advertising_router,
                                      conf.INITIAL_SEQUENCE_NUMBER,
                                      conf.VERSION_IPV4)
        self.assertFalse(
            first.is_lsa_identifier_equal(second.header.ls_type,
                                          second.header.link_state_id,
                                          second.header.advertising_router))
        self.assertFalse(
            second.is_lsa_identifier_equal(first.header.ls_type,
                                           first.header.link_state_id,
                                           first.header.advertising_router))

        first.create_extension_header(conf.INITIAL_LS_AGE, conf.OPTIONS_V2,
                                      initial_opaque_type,
                                      conf.LSA_TYPE_OPAQUE_AS, '2.2.2.2',
                                      conf.INITIAL_SEQUENCE_NUMBER,
                                      conf.VERSION_IPV4)
        self.assertFalse(
            first.is_lsa_identifier_equal(second.header.ls_type,
                                          second.header.link_state_id,
                                          second.header.advertising_router))
        self.assertFalse(
            second.is_lsa_identifier_equal(first.header.ls_type,
                                           first.header.link_state_id,
                                           first.header.advertising_router))

        #  OSPFv3

        first.create_extension_header(conf.INITIAL_LS_AGE, conf.OPTIONS_V3, 0,
                                      initial_ls_type,
                                      initial_advertising_router,
                                      conf.INITIAL_SEQUENCE_NUMBER,
                                      conf.VERSION_IPV6)
        second.create_extension_header(conf.INITIAL_LS_AGE + 1,
                                       conf.OPTIONS_V3 + 1, 0, initial_ls_type,
                                       initial_advertising_router,
                                       conf.INITIAL_SEQUENCE_NUMBER + 1,
                                       conf.VERSION_IPV6)
        self.assertTrue(
            first.is_lsa_identifier_equal(second.header.ls_type,
                                          second.header.link_state_id,
                                          second.header.advertising_router))
        self.assertTrue(
            second.is_lsa_identifier_equal(first.header.ls_type,
                                           first.header.link_state_id,
                                           first.header.advertising_router))

        first.create_extension_header(conf.INITIAL_LS_AGE, conf.OPTIONS_V3, 0,
                                      conf.LSA_TYPE_EXTENSION_PREFIX_LSA,
                                      initial_advertising_router,
                                      conf.INITIAL_SEQUENCE_NUMBER,
                                      conf.VERSION_IPV6)
        self.assertFalse(
            first.is_lsa_identifier_equal(second.header.ls_type,
                                          second.header.link_state_id,
                                          second.header.advertising_router))
        self.assertFalse(
            second.is_lsa_identifier_equal(first.header.ls_type,
                                           first.header.link_state_id,
                                           first.header.advertising_router))

        first.create_extension_header(conf.INITIAL_LS_AGE, conf.OPTIONS_V3, 0,
                                      initial_ls_type, '2.2.2.2',
                                      conf.INITIAL_SEQUENCE_NUMBER,
                                      conf.VERSION_IPV6)
        self.assertFalse(
            first.is_lsa_identifier_equal(second.header.ls_type,
                                          second.header.link_state_id,
                                          second.header.advertising_router))
        self.assertFalse(
            second.is_lsa_identifier_equal(first.header.ls_type,
                                           first.header.link_state_id,
                                           first.header.advertising_router))
    def test_pack_packet(self):
        #  OSPFv2

        body_bytes = b'\x01!"\x01\x02\x02\x02\x02\x02\x02\x02\x02\x80\x00\x00\x03\xf7&\x00<\x0e\x10"\x02\xde\xde\x03' \
                     b'\x02\x02\x02\x02\x02\x80\x00\x00\x02\xde\x83\x00 \x00\x02"\x01\x03\x03\x03\x03\x03\x03\x03\x03' \
                     b'\x80\x00\x00\x06\x07P\x00<\x00\x01"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x80\x00\x00\x05\xea' \
                     b'\xd2\x00T\x00\x01"\x02\xde\xde\x03\x01\x01\x01\x01\x01\x80\x00\x00\x01\x19O\x00 \x00\x02"\x02' \
                     b'\xde\xde\x05\x02\x03\x03\x03\x03\x80\x00\x00\x03\xfcV\x00 '
        lsa_header_1 = lsa.Lsa()
        lsa_header_2 = lsa.Lsa()
        lsa_header_3 = lsa.Lsa()
        lsa_header_4 = lsa.Lsa()
        lsa_header_5 = lsa.Lsa()
        lsa_header_6 = lsa.Lsa()
        lsa_header_1.create_header(289, 34, 1, '2.2.2.2', '2.2.2.2',
                                   0x80000003, conf.VERSION_IPV4)
        lsa_header_1.header.ls_checksum = 63270
        lsa_header_1.header.length = 60
        lsa_header_2.create_header(3600, 34, 2, '222.222.3.2', '2.2.2.2',
                                   0x80000002, conf.VERSION_IPV4)
        lsa_header_2.header.ls_checksum = 56963
        lsa_header_2.header.length = 32
        lsa_header_3.create_header(2, 34, 1, '3.3.3.3', '3.3.3.3', 0x80000006,
                                   conf.VERSION_IPV4)
        lsa_header_3.header.ls_checksum = 1872
        lsa_header_3.header.length = 60
        lsa_header_4.create_header(1, 34, 1, '1.1.1.1', '1.1.1.1', 0x80000005,
                                   conf.VERSION_IPV4)
        lsa_header_4.header.ls_checksum = 60114
        lsa_header_4.header.length = 84
        lsa_header_5.create_header(1, 34, 2, '222.222.3.1', '1.1.1.1',
                                   0x80000001, conf.VERSION_IPV4)
        lsa_header_5.header.ls_checksum = 6479
        lsa_header_5.header.length = 32
        lsa_header_6.create_header(2, 34, 2, '222.222.5.2', '3.3.3.3',
                                   0x80000003, conf.VERSION_IPV4)
        lsa_header_6.header.ls_checksum = 64598
        lsa_header_6.header.length = 32
        packet_body = ls_acknowledgment.LSAcknowledgement(conf.VERSION_IPV4)
        packet_body.add_lsa_header(lsa_header_1)
        packet_body.add_lsa_header(lsa_header_2)
        packet_body.add_lsa_header(lsa_header_3)
        packet_body.add_lsa_header(lsa_header_4)
        packet_body.add_lsa_header(lsa_header_5)
        packet_body.add_lsa_header(lsa_header_6)
        self.assertEqual(body_bytes, packet_body.pack_packet_body())

        #  OSPFv3

        body_bytes = b'\x00\n \x01\x00\x00\x00\x00\x01\x01\x01\x01\x80\x00\x00\x06:\x0f\x00H\x01# \x01\x00\x00\x00' \
                     b'\x00\x02\x02\x02\x02\x80\x00\x00\x042}\x008\x00\t \x01\x00\x00\x00\x00\x03\x03\x03\x03\x80\x00' \
                     b'\x00\x06e\t\x008\x00\n \x02\x00\x00\x00\x04\x01\x01\x01\x01\x80\x00\x00\x011\xc3\x00 \x01+ ' \
                     b'\x02\x00\x00\x00\x05\x02\x02\x02\x02\x80\x00\x00\x01\xf8\xf6\x00 \x01+ \x02\x00\x00\x00\x04' \
                     b'\x03\x03\x03\x03\x80\x00\x00\x019\xab\x00 \x01N\x00\x08\x00\x00\x00\x04\x01\x01\x01\x01\x80' \
                     b'\x00\x00\x02\x80\xfe\x008\x01* \t\x00\x00\x00\x00\x01\x01\x01\x01\x80\x00\x00\x03\x9c\x1f\x00D' \
                     b'\x00\n \t\x00\x00\x10\x00\x01\x01\x01\x01\x80\x00\x00\x01J\xab\x00,\x01+ \t\x00\x00\x00\x00' \
                     b'\x02\x02\x02\x02\x80\x00\x00\x03\xabJ\x00,\x01+ \t\x00\x00\x14\x00\x02\x02\x02\x02\x80\x00\x00' \
                     b'\x01<\xac\x00,\x01+ \t\x00\x00\x00\x00\x03\x03\x03\x03\x80\x00\x00\x03\xc3\xf1\x00,\x01+ \t' \
                     b'\x00\x00\x10\x00\x03\x03\x03\x03\x80\x00\x00\x01\xa6=\x00,\x00\x01 \x01\x00\x00\x00\x00\x01' \
                     b'\x01\x01\x01\x80\x00\x00\x078\x10\x00H\x00\x02 \x01\x00\x00\x00\x00\x02\x02\x02\x02\x80\x00' \
                     b'\x00\x05\x1e\xbe\x00(\x00\x02 \t\x00\x00\x00\x00\x02\x02\x02\x02\x80\x00\x00\x04\x9aV\x008'
        lsa_header_1 = lsa.Lsa()
        lsa_header_2 = lsa.Lsa()
        lsa_header_3 = lsa.Lsa()
        lsa_header_4 = lsa.Lsa()
        lsa_header_5 = lsa.Lsa()
        lsa_header_6 = lsa.Lsa()
        lsa_header_7 = lsa.Lsa()
        lsa_header_8 = lsa.Lsa()
        lsa_header_9 = lsa.Lsa()
        lsa_header_10 = lsa.Lsa()
        lsa_header_11 = lsa.Lsa()
        lsa_header_12 = lsa.Lsa()
        lsa_header_13 = lsa.Lsa()
        lsa_header_14 = lsa.Lsa()
        lsa_header_15 = lsa.Lsa()
        lsa_header_16 = lsa.Lsa()
        lsa_header_1.create_header(10, 0, 1, '0.0.0.0', '1.1.1.1', 0x80000006,
                                   conf.VERSION_IPV6)
        lsa_header_1.header.ls_checksum = 14863
        lsa_header_1.header.length = 72
        lsa_header_2.create_header(291, 0, 1, '0.0.0.0', '2.2.2.2', 0x80000004,
                                   conf.VERSION_IPV6)
        lsa_header_2.header.ls_checksum = 12925
        lsa_header_2.header.length = 56
        lsa_header_3.create_header(9, 0, 1, '0.0.0.0', '3.3.3.3', 0x80000006,
                                   conf.VERSION_IPV6)
        lsa_header_3.header.ls_checksum = 25865
        lsa_header_3.header.length = 56
        lsa_header_4.create_header(10, 0, 2, '0.0.0.4', '1.1.1.1', 0x80000001,
                                   conf.VERSION_IPV6)
        lsa_header_4.header.ls_checksum = 12739
        lsa_header_4.header.length = 32
        lsa_header_5.create_header(299, 0, 2, '0.0.0.5', '2.2.2.2', 0x80000001,
                                   conf.VERSION_IPV6)
        lsa_header_5.header.ls_checksum = 63734
        lsa_header_5.header.length = 32
        lsa_header_6.create_header(299, 0, 2, '0.0.0.4', '3.3.3.3', 0x80000001,
                                   conf.VERSION_IPV6)
        lsa_header_6.header.ls_checksum = 14763
        lsa_header_6.header.length = 32
        lsa_header_7.create_header(334, 0, 8, '0.0.0.4', '1.1.1.1', 0x80000002,
                                   conf.VERSION_IPV6)
        lsa_header_7.header.ls_checksum = 33022
        lsa_header_7.header.length = 56
        lsa_header_8.create_header(298, 0, 9, '0.0.0.0', '1.1.1.1', 0x80000003,
                                   conf.VERSION_IPV6)
        lsa_header_8.header.ls_checksum = 39967
        lsa_header_8.header.length = 68
        lsa_header_9.create_header(10, 0, 9, '0.0.16.0', '1.1.1.1', 0x80000001,
                                   conf.VERSION_IPV6)
        lsa_header_9.header.ls_checksum = 19115
        lsa_header_9.header.length = 44
        lsa_header_10.create_header(299, 0, 9, '0.0.0.0', '2.2.2.2',
                                    0x80000003, conf.VERSION_IPV6)
        lsa_header_10.header.ls_checksum = 43850
        lsa_header_10.header.length = 44
        lsa_header_11.create_header(299, 0, 9, '0.0.20.0', '2.2.2.2',
                                    0x80000001, conf.VERSION_IPV6)
        lsa_header_11.header.ls_checksum = 15532
        lsa_header_11.header.length = 44
        lsa_header_12.create_header(299, 0, 9, '0.0.0.0', '3.3.3.3',
                                    0x80000003, conf.VERSION_IPV6)
        lsa_header_12.header.ls_checksum = 50161
        lsa_header_12.header.length = 44
        lsa_header_13.create_header(299, 0, 9, '0.0.16.0', '3.3.3.3',
                                    0x80000001, conf.VERSION_IPV6)
        lsa_header_13.header.ls_checksum = 42557
        lsa_header_13.header.length = 44
        lsa_header_14.create_header(1, 0, 1, '0.0.0.0', '1.1.1.1', 0x80000007,
                                    conf.VERSION_IPV6)
        lsa_header_14.header.ls_checksum = 14352
        lsa_header_14.header.length = 72
        lsa_header_15.create_header(2, 0, 1, '0.0.0.0', '2.2.2.2', 0x80000005,
                                    conf.VERSION_IPV6)
        lsa_header_15.header.ls_checksum = 7870
        lsa_header_15.header.length = 40
        lsa_header_16.create_header(2, 0, 9, '0.0.0.0', '2.2.2.2', 0x80000004,
                                    conf.VERSION_IPV6)
        lsa_header_16.header.ls_checksum = 39510
        lsa_header_16.header.length = 56
        packet_body = ls_acknowledgment.LSAcknowledgement(conf.VERSION_IPV6)
        packet_body.add_lsa_header(lsa_header_1)
        packet_body.add_lsa_header(lsa_header_2)
        packet_body.add_lsa_header(lsa_header_3)
        packet_body.add_lsa_header(lsa_header_4)
        packet_body.add_lsa_header(lsa_header_5)
        packet_body.add_lsa_header(lsa_header_6)
        packet_body.add_lsa_header(lsa_header_7)
        packet_body.add_lsa_header(lsa_header_8)
        packet_body.add_lsa_header(lsa_header_9)
        packet_body.add_lsa_header(lsa_header_10)
        packet_body.add_lsa_header(lsa_header_11)
        packet_body.add_lsa_header(lsa_header_12)
        packet_body.add_lsa_header(lsa_header_13)
        packet_body.add_lsa_header(lsa_header_14)
        packet_body.add_lsa_header(lsa_header_15)
        packet_body.add_lsa_header(lsa_header_16)
        self.assertEqual(body_bytes, packet_body.pack_packet_body())
    def test_pack_packet(self):
        #  OSPFv2

        body_bytes = b'\x00\x00\x00\x04\x00\x05"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x80\x00\x00\x04\x8c\xf3\x00T\x00' \
                     b'\x00\x00\x05\x03\x03\x03\x03\xde\xde\x06\x01\x01\x00\x00@\xde\xde\x06\x00\xff\xff\xff\x00\x03' \
                     b'\x00\x00@\xde\xde\x03\x00\xff\xff\xff\x00\x03\x00\x00\n\xde\xde\x02\x00\xff\xff\xff\x00\x03' \
                     b'\x00\x00\n\xde\xde\x01\x00\xff\xff\xff\x00\x03\x00\x00\x01\x01!"\x01\x02\x02\x02\x02\x02\x02' \
                     b'\x02\x02\x80\x00\x00\x03\xf7&\x00<\x00\x00\x00\x03\xde\xde\x05\x02\xde\xde\x05\x01\x02\x00\x00' \
                     b'\x01\xde\xde\x04\x00\xff\xff\xff\x00\x03\x00\x00\n\xde\xde\x03\x02\xde\xde\x03\x02\x02\x00\x00' \
                     b'\n\x00\x06"\x01\x03\x03\x03\x03\x03\x03\x03\x03\x80\x00\x00\x05\x16\x08\x00<\x00\x00\x00\x03' \
                     b'\x01\x01\x01\x01\xde\xde\x06\x02\x01\x00\x00@\xde\xde\x06\x00\xff\xff\xff\x00\x03\x00\x00@\xde' \
                     b'\xde\x05\x00\xff\xff\xff\x00\x03\x00\x00\n\x01!"\x02\xde\xde\x03\x02\x02\x02\x02\x02\x80\x00' \
                     b'\x00\x01\xe0\x82\x00 \xff\xff\xff\x00\x02\x02\x02\x02\x01\x01\x01\x01'

        lsa_1 = lsa.Lsa()
        lsa_2 = lsa.Lsa()
        lsa_3 = lsa.Lsa()
        lsa_4 = lsa.Lsa()
        lsa_1.create_header(5, 34, 1, '1.1.1.1', '1.1.1.1', 0x80000004,
                            conf.VERSION_IPV4)
        lsa_2.create_header(289, 34, 1, '2.2.2.2', '2.2.2.2', 0x80000003,
                            conf.VERSION_IPV4)
        lsa_3.create_header(6, 34, 1, '3.3.3.3', '3.3.3.3', 0x80000005,
                            conf.VERSION_IPV4)
        lsa_4.create_header(289, 34, 2, '222.222.3.2', '2.2.2.2', 0x80000001,
                            conf.VERSION_IPV4)
        lsa_1.create_router_lsa_body(False, False, False, 0, conf.VERSION_IPV4)
        lsa_1.add_link_info_v2('3.3.3.3', '222.222.6.1', 1, 0, 64)
        lsa_1.add_link_info_v2('222.222.6.0', '255.255.255.0', 3, 0, 64)
        lsa_1.add_link_info_v2('222.222.3.0', '255.255.255.0', 3, 0, 10)
        lsa_1.add_link_info_v2('222.222.2.0', '255.255.255.0', 3, 0, 10)
        lsa_1.add_link_info_v2('222.222.1.0', '255.255.255.0', 3, 0, 1)
        lsa_2.create_router_lsa_body(False, False, False, 0, conf.VERSION_IPV4)
        lsa_2.add_link_info_v2('222.222.5.2', '222.222.5.1', 2, 0, 1)
        lsa_2.add_link_info_v2('222.222.4.0', '255.255.255.0', 3, 0, 10)
        lsa_2.add_link_info_v2('222.222.3.2', '222.222.3.2', 2, 0, 10)
        lsa_3.create_router_lsa_body(False, False, False, 0, conf.VERSION_IPV4)
        lsa_3.add_link_info_v2('1.1.1.1', '222.222.6.2', 1, 0, 64)
        lsa_3.add_link_info_v2('222.222.6.0', '255.255.255.0', 3, 0, 64)
        lsa_3.add_link_info_v2('222.222.5.0', '255.255.255.0', 3, 0, 10)
        lsa_4.create_network_lsa_body('255.255.255.0', 0,
                                      ['2.2.2.2', '1.1.1.1'],
                                      conf.VERSION_IPV4)

        packet_body = ls_update.LSUpdate(conf.VERSION_IPV4)
        packet_body.add_lsa(lsa_1)
        packet_body.add_lsa(lsa_2)
        packet_body.add_lsa(lsa_3)
        packet_body.add_lsa(lsa_4)
        self.assertEqual(body_bytes, packet_body.pack_packet_body())

        #  OSPFv3

        body_bytes = b'\x00\x00\x00\r\x00\n \x01\x00\x00\x00\x00\x01\x01\x01\x01\x80\x00\x00\x06:\x0f\x00H\x00\x00' \
                     b'\x003\x01\x00\x00@\x00\x00\x00\x07\x00\x00\x00\x06\x03\x03\x03\x03\x02\x00\x00\n\x00\x00\x00' \
                     b'\x04\x00\x00\x00\x05\x02\x02\x02\x02\x02\x00\x00\n\x00\x00\x00\x04\x00\x00\x00\x04\x01\x01\x01' \
                     b'\x01\x01# \x01\x00\x00\x00\x00\x02\x02\x02\x02\x80\x00\x00\x042}\x008\x00\x00\x003\x02\x00\x00' \
                     b'\x01\x00\x00\x00\x06\x00\x00\x00\x04\x03\x03\x03\x03\x02\x00\x00\n\x00\x00\x00\x05\x00\x00\x00' \
                     b'\x05\x02\x02\x02\x02\x00\t \x01\x00\x00\x00\x00\x03\x03\x03\x03\x80\x00\x00\x06e\t\x008\x00' \
                     b'\x00\x003\x01\x00\x00@\x00\x00\x00\x06\x00\x00\x00\x07\x01\x01\x01\x01\x02\x00\x00\n\x00\x00' \
                     b'\x00\x04\x00\x00\x00\x04\x03\x03\x03\x03\x00\n \x02\x00\x00\x00\x04\x01\x01\x01\x01\x80\x00' \
                     b'\x00\x011\xc3\x00 \x00\x00\x003\x01\x01\x01\x01\x02\x02\x02\x02\x01+ \x02\x00\x00\x00\x05\x02' \
                     b'\x02\x02\x02\x80\x00\x00\x01\xf8\xf6\x00 \x00\x00\x003\x02\x02\x02\x02\x01\x01\x01\x01\x01+ ' \
                     b'\x02\x00\x00\x00\x04\x03\x03\x03\x03\x80\x00\x00\x019\xab\x00 \x00\x00\x003\x03\x03\x03\x03' \
                     b'\x02\x02\x02\x02\x01N\x00\x08\x00\x00\x00\x04\x01\x01\x01\x01\x80\x00\x00\x02\x80\xfe\x008\x01' \
                     b'\x00\x003\xfe\x80\x00\x00\x00\x00\x00\x00\xc0\x01\x18\xff\xfe4\x00\x00\x00\x00\x00\x01@\x00' \
                     b'\x00\x00 \x01\r\xb8\xca\xfe\x00\x03\x01* \t\x00\x00\x00\x00\x01\x01\x01\x01\x80\x00\x00\x03' \
                     b'\x9c\x1f\x00D\x00\x03 \x01\x00\x00\x00\x00\x01\x01\x01\x01@\x00\x00@ \x01\r\xb8\xca\xfe\x00' \
                     b'\x06@\x00\x00\x01 \x01\r\xb8\xca\xfe\x00\x01@\x00\x00\n \x01\r\xb8\xca\xfe\x00\x02\x00\n \t' \
                     b'\x00\x00\x10\x00\x01\x01\x01\x01\x80\x00\x00\x01J\xab\x00,\x00\x01 \x02\x00\x00\x00\x04\x01' \
                     b'\x01\x01\x01@\x00\x00\x00 \x01\r\xb8\xca\xfe\x00\x03\x01+ \t\x00\x00\x00\x00\x02\x02\x02\x02' \
                     b'\x80\x00\x00\x03\xabJ\x00,\x00\x01 \x01\x00\x00\x00\x00\x02\x02\x02\x02@\x00\x00\n \x01\r\xb8' \
                     b'\xca\xfe\x00\x04\x01+ \t\x00\x00\x14\x00\x02\x02\x02\x02\x80\x00\x00\x01<\xac\x00,\x00\x01 ' \
                     b'\x02\x00\x00\x00\x05\x02\x02\x02\x02@\x00\x00\x00 \x01\r\xb8\xca\xfe\x00\x03\x01+ \t\x00\x00' \
                     b'\x00\x00\x03\x03\x03\x03\x80\x00\x00\x03\xc3\xf1\x00,\x00\x01 \x01\x00\x00\x00\x00\x03\x03\x03' \
                     b'\x03@\x00\x00@ \x01\r\xb8\xca\xfe\x00\x06\x01+ \t\x00\x00\x10\x00\x03\x03\x03\x03\x80\x00\x00' \
                     b'\x01\xa6=\x00,\x00\x01 \x02\x00\x00\x00\x04\x03\x03\x03\x03@\x00\x00\x00 \x01\r\xb8\xca\xfe' \
                     b'\x00\x05'

        lsa_1 = lsa.Lsa()
        lsa_2 = lsa.Lsa()
        lsa_3 = lsa.Lsa()
        lsa_4 = lsa.Lsa()
        lsa_5 = lsa.Lsa()
        lsa_6 = lsa.Lsa()
        lsa_7 = lsa.Lsa()
        lsa_8 = lsa.Lsa()
        lsa_9 = lsa.Lsa()
        lsa_10 = lsa.Lsa()
        lsa_11 = lsa.Lsa()
        lsa_12 = lsa.Lsa()
        lsa_13 = lsa.Lsa()
        lsa_1.create_header(10, 0, 1, '0.0.0.0', '1.1.1.1', 0x80000006,
                            conf.VERSION_IPV6)
        lsa_2.create_header(291, 0, 1, '0.0.0.0', '2.2.2.2', 0x80000004,
                            conf.VERSION_IPV6)
        lsa_3.create_header(9, 0, 1, '0.0.0.0', '3.3.3.3', 0x80000006,
                            conf.VERSION_IPV6)
        lsa_4.create_header(10, 0, 2, '0.0.0.4', '1.1.1.1', 0x80000001,
                            conf.VERSION_IPV6)
        lsa_5.create_header(299, 0, 2, '0.0.0.5', '2.2.2.2', 0x80000001,
                            conf.VERSION_IPV6)
        lsa_6.create_header(299, 0, 2, '0.0.0.4', '3.3.3.3', 0x80000001,
                            conf.VERSION_IPV6)
        lsa_7.create_header(334, 0, 8, '0.0.0.4', '1.1.1.1', 0x80000002,
                            conf.VERSION_IPV6)
        lsa_8.create_header(298, 0, 9, '0.0.0.0', '1.1.1.1', 0x80000003,
                            conf.VERSION_IPV6)
        lsa_9.create_header(10, 0, 9, '0.0.16.0', '1.1.1.1', 0x80000001,
                            conf.VERSION_IPV6)
        lsa_10.create_header(299, 0, 9, '0.0.0.0', '2.2.2.2', 0x80000003,
                             conf.VERSION_IPV6)
        lsa_11.create_header(299, 0, 9, '0.0.20.0', '2.2.2.2', 0x80000001,
                             conf.VERSION_IPV6)
        lsa_12.create_header(299, 0, 9, '0.0.0.0', '3.3.3.3', 0x80000003,
                             conf.VERSION_IPV6)
        lsa_13.create_header(299, 0, 9, '0.0.16.0', '3.3.3.3', 0x80000001,
                             conf.VERSION_IPV6)
        lsa_1.create_router_lsa_body(False, False, False, 51,
                                     conf.VERSION_IPV6)
        lsa_1.add_link_info_v3(1, 64, 7, 6, '3.3.3.3')
        lsa_1.add_link_info_v3(2, 10, 4, 5, '2.2.2.2')
        lsa_1.add_link_info_v3(2, 10, 4, 4, '1.1.1.1')
        lsa_2.create_router_lsa_body(False, False, False, 51,
                                     conf.VERSION_IPV6)
        lsa_2.add_link_info_v3(2, 1, 6, 4, '3.3.3.3')
        lsa_2.add_link_info_v3(2, 10, 5, 5, '2.2.2.2')
        lsa_3.create_router_lsa_body(False, False, False, 51,
                                     conf.VERSION_IPV6)
        lsa_3.add_link_info_v3(1, 64, 6, 7, '1.1.1.1')
        lsa_3.add_link_info_v3(2, 10, 4, 4, '3.3.3.3')
        lsa_4.create_network_lsa_body('', 51, ['1.1.1.1', '2.2.2.2'],
                                      conf.VERSION_IPV6)
        lsa_5.create_network_lsa_body('', 51, ['2.2.2.2', '1.1.1.1'],
                                      conf.VERSION_IPV6)
        lsa_6.create_network_lsa_body('', 51, ['3.3.3.3', '2.2.2.2'],
                                      conf.VERSION_IPV6)
        lsa_7.create_link_lsa_body(1, 51, 'fe80::c001:18ff:fe34:0')
        lsa_7.add_prefix_info(64, 0, 0, '2001:db8:cafe:3::',
                              conf.LSA_TYPE_LINK)
        lsa_8.create_intra_area_prefix_lsa_body(1, '0.0.0.0', '1.1.1.1')
        lsa_8.add_prefix_info(64, 0, 64, '2001:db8:cafe:6::',
                              conf.LSA_TYPE_INTRA_AREA_PREFIX)
        lsa_8.add_prefix_info(64, 0, 1, '2001:db8:cafe:1::',
                              conf.LSA_TYPE_INTRA_AREA_PREFIX)
        lsa_8.add_prefix_info(64, 0, 10, '2001:db8:cafe:2::',
                              conf.LSA_TYPE_INTRA_AREA_PREFIX)
        lsa_9.create_intra_area_prefix_lsa_body(2, '0.0.0.4', '1.1.1.1')
        lsa_9.add_prefix_info(64, 0, 0, '2001:db8:cafe:3::',
                              conf.LSA_TYPE_INTRA_AREA_PREFIX)
        lsa_10.create_intra_area_prefix_lsa_body(1, '0.0.0.0', '2.2.2.2')
        lsa_10.add_prefix_info(64, 0, 10, '2001:db8:cafe:4::',
                               conf.LSA_TYPE_INTRA_AREA_PREFIX)
        lsa_11.create_intra_area_prefix_lsa_body(2, '0.0.0.5', '2.2.2.2')
        lsa_11.add_prefix_info(64, 0, 0, '2001:db8:cafe:3::',
                               conf.LSA_TYPE_INTRA_AREA_PREFIX)
        lsa_12.create_intra_area_prefix_lsa_body(1, '0.0.0.0', '3.3.3.3')
        lsa_12.add_prefix_info(64, 0, 64, '2001:db8:cafe:6::',
                               conf.LSA_TYPE_INTRA_AREA_PREFIX)
        lsa_13.create_intra_area_prefix_lsa_body(2, '0.0.0.4', '3.3.3.3')
        lsa_13.add_prefix_info(64, 0, 0, '2001:db8:cafe:5::',
                               conf.LSA_TYPE_INTRA_AREA_PREFIX)

        packet_body = ls_update.LSUpdate(conf.VERSION_IPV6)
        packet_body.add_lsa(lsa_1)
        packet_body.add_lsa(lsa_2)
        packet_body.add_lsa(lsa_3)
        packet_body.add_lsa(lsa_4)
        packet_body.add_lsa(lsa_5)
        packet_body.add_lsa(lsa_6)
        packet_body.add_lsa(lsa_7)
        packet_body.add_lsa(lsa_8)
        packet_body.add_lsa(lsa_9)
        packet_body.add_lsa(lsa_10)
        packet_body.add_lsa(lsa_11)
        packet_body.add_lsa(lsa_12)
        packet_body.add_lsa(lsa_13)
        self.assertEqual(body_bytes, packet_body.pack_packet_body())