]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4441] Addressed initial review comments
authorThomas Markwalder <tmark@isc.org>
Tue, 14 Apr 2026 17:45:55 +0000 (13:45 -0400)
committerThomas Markwalder <tmark@isc.org>
Fri, 17 Apr 2026 17:21:44 +0000 (17:21 +0000)
modified:   src/bin/admin/tests/mysql_tests.sh.in
modified:   src/bin/admin/tests/pgsql_tests.sh.in
modified:   src/hooks/dhcp/mysql/mysql_lease_mgr.cc
modified:   src/hooks/dhcp/mysql/tests/mysql_lease_mgr_unittest.cc
modified:   src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc
modified:   src/hooks/dhcp/pgsql/tests/pgsql_lease_mgr_unittest.cc
modified:   src/lib/dhcpsrv/parsers/shared_network_parser.cc
modified:   src/lib/dhcpsrv/sflq_allocator.cc
modified:   src/lib/dhcpsrv/subnet.cc
modified:   src/lib/dhcpsrv/tests/sflq_allocator_unittest.cc
modified:   src/lib/dhcpsrv/tests/shared_network_unittest.cc
modified:   src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc
modified:   src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.h
modified:   src/share/database/scripts/mysql/dhcpdb_create.mysql
modified:   src/share/database/scripts/mysql/upgrade_033_to_034.sh.in
modified:   src/share/database/scripts/pgsql/dhcpdb_create.pgsql
modified:   src/share/database/scripts/pgsql/upgrade_032_to_033.sh.in

17 files changed:
src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
src/hooks/dhcp/mysql/mysql_lease_mgr.cc
src/hooks/dhcp/mysql/tests/mysql_lease_mgr_unittest.cc
src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc
src/hooks/dhcp/pgsql/tests/pgsql_lease_mgr_unittest.cc
src/lib/dhcpsrv/parsers/shared_network_parser.cc
src/lib/dhcpsrv/sflq_allocator.cc
src/lib/dhcpsrv/subnet.cc
src/lib/dhcpsrv/tests/sflq_allocator_unittest.cc
src/lib/dhcpsrv/tests/shared_network_unittest.cc
src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc
src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.h
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/upgrade_033_to_034.sh.in
src/share/database/scripts/pgsql/dhcpdb_create.pgsql
src/share/database/scripts/pgsql/upgrade_032_to_033.sh.in

index d06dc2620a211ceb7c079ac419006aa85c21cc51..b5aa63c86219bc47d9c072ce5e23b99506385626 100755 (executable)
@@ -4497,7 +4497,7 @@ mysql_sflqInsertLease4() {
 }
 
 mysql_sflqUpdateLease4() {
-    test_start "mysql.mysql_sflQUpdateLease4"
+    test_start "mysql.mysql_sflqUpdateLease4"
 
     # Let's wipe the whole database
     mysql_wipe
index d1b7f2a53f8449ee8f8d0f29d56e62de1cdfd5ba..fac6d31b7be423827dd9e2f57f4e70b5c89643db 100755 (executable)
@@ -3759,7 +3759,7 @@ pgsql_sflqUpdateLease4() {
                                1::bigint, 'f'::boolean, 'f'::boolean, NULL,\
                                0::bigint, NULL, NULL, NULL, 0::bigint,\
                                $bigint_address, '$expired'::timestamp)";
-    run_statement "sflqUpdateLease4 4" "$sql"
+    run_statement "sflqUpdateLease4 3" "$sql"
 
     # Verify lease is updated in lease4 and added to free_lease4
     sql="select count(address) from lease4 where address = $bigint_address and state = 0;"
index bd7cb7bb0ffb3080d04b395506eaf77966a1451f..604f3fec908878c6c0cb1e047ddc884f9663144a 100644 (file)
@@ -4930,7 +4930,7 @@ MySqlLeaseMgr::sflqCreateFlqPool4(IOAddress start_address, IOAddress end_address
     /// @todo 16M? this is arbitrary number for now.
     if (capacity > 16777216 ) {
         isc_throw(BadValue, "MySqlLeasMgr::sflqCreateFlqPool4 "
-                            "- pool capcity " << capacity << " is too large"
+                            "- pool capacity " << capacity << " is too large"
                             " for shared-flq allocator");
     }
 
@@ -5054,7 +5054,7 @@ MySqlLeaseMgr::sflqCreateFlqPool6(IOAddress start_address, IOAddress end_address
     // @todo 16M? this is arbitrary number for now.
     if (capacity > 16777216 ) {
         isc_throw(BadValue, "MySqlLeasMgr::sflqCreateFlqPool6 "
-                            "- pool capcity " << capacity << " is too large"
+                            "- pool capacity " << capacity << " is too large"
                             " for shared-flq allocator");
     }
 
index 7edfa5e83e0e76d2168cab0d40068094eaf1acfd..c41ccc8ce1003757a888dc2f568d716ed47ff28c 100644 (file)
@@ -81,9 +81,9 @@ public:
     /// @brief Destroys the LM and the schema.
     void destroyTest() {
         LeaseMgrFactory::destroy();
-        if (getenv("KEA_UNIT_TEST_KEEP_DB_DATA")) {
+        if (getenv("KEA_UNIT_TEST_KEEP_SCHEMA")) {
             // Leaves schema intact for post-test debugging.
-            std::cout << "KEA_UNIT_TEST_KEEP_DB_DATA set" << std::endl;
+            std::cout << "KEA_UNIT_TEST_KEEP_SCHEMA set" << std::endl;
         } else {
             // If data wipe enabled, delete transient data otherwise destroy the schema
             destroyMySQLSchema();
@@ -1454,8 +1454,12 @@ TEST_F(MySqlLeaseMgrTest, testSflqCreateAndPick6) {
     testSflqCreateAndPick6();
 }
 
-TEST_F(MySqlLeaseMgrTest, testSflqLeaseOps6) {
-    testSflqLeaseOps6();
+TEST_F(MySqlLeaseMgrTest, testSflqLeaseOps6NA) {
+    testSflqLeaseOps6(Lease::TYPE_NA);
+}
+
+TEST_F(MySqlLeaseMgrTest, testSflqLeaseOps6PD) {
+    testSflqLeaseOps6(Lease::TYPE_PD);
 }
 
 /// @brief Test fixture class for testing @ref CfgDbAccessTest using MySQL
index 76a6bc5901ae63794a283d2b384e85a446e0eb9d..f002322e7f502f48ae4ee7aa9e39c873d894bd5e 100644 (file)
@@ -3951,7 +3951,7 @@ PgSqlLeaseMgr::sflqCreateFlqPool4(IOAddress start_address, IOAddress end_address
     /// @todo 16M? this is arbitrary number for now.
     if (capacity > 16777216 ) {
         isc_throw(BadValue, "MySqlLeasMgr::sflqCreateFlqPool4 "
-                            "- pool capcity " << capacity << " is too large"
+                            "- pool capacity " << capacity << " is too large"
                             " for shared-flq allocator");
     }
 
@@ -4056,7 +4056,7 @@ PgSqlLeaseMgr::sflqCreateFlqPool6(IOAddress start_address, IOAddress end_address
     /// @todo 16M? this is arbitrary number for now.
     if (capacity > 16777216 ) {
         isc_throw(BadValue, "MySqlLeasMgr::sflqCreateFlqPool6 "
-                            "- pool capcity " << capacity << " is too large"
+                            "- pool capacity " << capacity << " is too large"
                             " for shared-flq allocator");
     }
 
index 3c117fce5c7ee13264fbaaee908422b929cad807..23c9bac49f240a62df3ecb160a033f138d1c31a4 100644 (file)
@@ -83,9 +83,9 @@ public:
         LeaseMgrFactory::destroy();
 
         // If data wipe enabled, delete transient data otherwise destroy the schema
-        if (getenv("KEA_UNIT_TEST_KEEP_DB_DATA")) {
+        if (getenv("KEA_UNIT_TEST_KEEP_SCHEMA")) {
             // Leaves schema intact for post-test debugging.
-            std::cout << "KEA_UNIT_TEST_KEEP_DB_DATA set" << std::endl;
+            std::cout << "KEA_UNIT_TEST_KEEP_SCHEMA set" << std::endl;
         } else {
             // If data wipe enabled, delete transient data otherwise destroy the schema
             destroyPgSQLSchema();
@@ -1418,8 +1418,12 @@ TEST_F(PgSqlLeaseMgrTest, testSflqCreateAndPick6) {
     testSflqCreateAndPick6();
 }
 
-TEST_F(PgSqlLeaseMgrTest, testSflqLeaseOps6) {
-    testSflqLeaseOps6();
+TEST_F(PgSqlLeaseMgrTest, testSflqLeaseOps6NA) {
+    testSflqLeaseOps6(Lease::TYPE_NA);
+}
+
+TEST_F(PgSqlLeaseMgrTest, testSflqLeaseOps6PD) {
+    testSflqLeaseOps6(Lease::TYPE_PD);
 }
 
 /// @brief Test fixture class for testing @ref CfgDbAccessTest using PostgreSQL
index ccf57f4b30fb60abbc42996b398d451b1fc2ed5f..5b8089db5722e0e1af88b240a33782244ba80f3f 100644 (file)
@@ -367,12 +367,6 @@ SharedNetwork6Parser::parse(const data::ConstElementPtr& shared_network_data,
             isc_throw(BadValue, "Free Lease Queue allocator is not supported for IPv6 address pools");
         }
 
-        /// @todo Do we want this or not?  One potential use case would be someone
-        /// using a mapped v4 addresses?  "::xxxx:xxxx" -> "::192.0.2.1"
-        if (network->getAllocatorType() == "shared-flq") {
-            isc_throw(BadValue, "Shared FLQ allocator is not supported for IPv6 address pools");
-        }
-
         // Parse prefix delegation allocator params.
         auto network6 = boost::dynamic_pointer_cast<Network6>(shared_network);
         parsePdAllocatorParams(shared_network_data, network6);
index 5b31c3deb6fe66124cc66ecaf4d1601ee9830bce..579e746e1c3d8b9226154d4c0a729b39b4b4e16c 100644 (file)
@@ -216,8 +216,14 @@ SharedFlqAllocator::getSubnetState() const {
                                    boost::make_shared<SubnetSflqAllocationState>());
     }
 
-    return (boost::dynamic_pointer_cast<SubnetSflqAllocationState>
-                                       (subnet->getAllocationState(pool_type_)));
+    SubnetSflqAllocationStatePtr state;
+    state = boost::dynamic_pointer_cast<SubnetSflqAllocationState>
+                                       (subnet->getAllocationState(pool_type_));
+    if (!state) {
+        isc_throw(Unexpected, "SharedFlqAllocator::getSubnetState - wrong allcoation state type");
+    }
+
+    return (state);
 }
 
 } // end of namespace isc::dhcp
index 88fefc9f50bd49ea2cb4e0a8e7dc15501ca58148..a05c8c16a79cfd2fee2c9a7a4b2ca48353d7ed8c 100644 (file)
@@ -850,7 +850,12 @@ Subnet6::createAllocators() {
 
     } else if (allocator_type == "flq") {
         isc_throw(BadValue, "Free Lease Queue allocator is not supported for IPv6 address pools");
-
+    } else if (allocator_type == "shared-flq") {
+        setAllocator(Lease::TYPE_NA,
+                     boost::make_shared<SharedFlqAllocator>
+                     (Lease::TYPE_NA, shared_from_this()));
+        setAllocationState(Lease::TYPE_NA,
+                           boost::make_shared<SubnetSflqAllocationState>());
     } else {
         setAllocator(Lease::TYPE_NA,
                      boost::make_shared<IterativeAllocator>
index 44c49152d637e5872b263e48c93f82a7d1b4d91e..0fc0d9f6b93a5b7aa40c94dd2ed9f1ee35769ef7 100644 (file)
@@ -40,6 +40,7 @@ public:
         SharedFlqAllocator::setInUse(false);
     }
 
+    /// @brief Post-test cleanup.
     virtual void TearDown() {
         SharedFlqAllocator::setInUse(false);
     }
@@ -62,6 +63,9 @@ public:
         pool->allowClientClass("ALL");
         pool->allowClientClass("three");
         subnet_->addPool(pool);
+
+        subnet_->setAllocatorType("shared-flq");
+        subnet_->createAllocators();
     }
 
     /// @brief Subnet used in tests.
@@ -77,10 +81,10 @@ TEST_F(SharedFlqAllocatorTest4, getType) {
 // Tests initAfterConfigure() function. It should create
 // an SFLQ pool for each pool in the subnet.
 TEST_F(SharedFlqAllocatorTest4, initAfterConfigure) {
-    SharedFlqAllocator alloc(Lease::TYPE_V4, subnet_);
-
     EXPECT_FALSE(SharedFlqAllocator::inUse());
-    EXPECT_NO_THROW(alloc.initAfterConfigure());
+    auto alloc = subnet_->getAllocator(Lease::TYPE_V4);
+    ASSERT_TRUE(alloc);
+    ASSERT_NO_THROW_LOG(alloc->initAfterConfigure());
     EXPECT_TRUE(SharedFlqAllocator::inUse());
 
     SflqTestLeaseMgr& slm = dynamic_cast<SflqTestLeaseMgr&>(LeaseMgrFactory::instance());
@@ -91,12 +95,13 @@ TEST_F(SharedFlqAllocatorTest4, initAfterConfigure) {
     }
 }
 
-// Exercises ShareFlqAllocator::pickAddressInternal() for a V4 subnet.
+// Exercises SharedFlqAllocator::pickAddressInternal() for a V4 subnet.
 TEST_F(SharedFlqAllocatorTest4, pickAddress) {
     IOAddress zero_address = IOAddress::IPV4_ZERO_ADDRESS();
-    SharedFlqAllocator alloc(Lease::TYPE_V4, subnet_);
 
-    EXPECT_NO_THROW(alloc.initAfterConfigure());
+    auto alloc = subnet_->getAllocator(Lease::TYPE_V4);
+    ASSERT_TRUE(alloc);
+    ASSERT_NO_THROW_LOG(alloc->initAfterConfigure());
 
     SflqTestLeaseMgr& slm = dynamic_cast<SflqTestLeaseMgr&>(LeaseMgrFactory::instance());
     for (auto pool : subnet_->getPools(Lease::TYPE_V4)) {
@@ -114,9 +119,9 @@ TEST_F(SharedFlqAllocatorTest4, pickAddress) {
     for (int i = 0; i < 6; ++i) {
         IOAddress picked_address = zero_address;
         ASSERT_NO_THROW_LOG(picked_address =
-                            alloc.pickAddress(client_classes,
-                                              IdentifierBaseTypePtr(),
-                                              zero_address));
+                            alloc->pickAddress(client_classes,
+                                               IdentifierBaseTypePtr(),
+                                               zero_address));
         ASSERT_NE(picked_address, zero_address);
         picked.emplace(picked_address);
     }
@@ -130,7 +135,7 @@ TEST_F(SharedFlqAllocatorTest4, pickAddress) {
     ASSERT_TRUE(picked.count(IOAddress("192.0.3.1")));
 
     // Verify an additional pick returns zero address.
-    ASSERT_EQ(alloc.pickAddress(client_classes, IdentifierBaseTypePtr(), zero_address),
+    ASSERT_EQ(alloc->pickAddress(client_classes, IdentifierBaseTypePtr(), zero_address),
               zero_address);
 
     // Verify that only pool 2 addresses are picked for class "two"
@@ -141,9 +146,9 @@ TEST_F(SharedFlqAllocatorTest4, pickAddress) {
     for (int i = 0; i < 2; ++i) {
         IOAddress picked_address = zero_address;
         ASSERT_NO_THROW_LOG(picked_address =
-                            alloc.pickAddress(client_classes,
-                                              IdentifierBaseTypePtr(),
-                                              zero_address))
+                            alloc->pickAddress(client_classes,
+                                               IdentifierBaseTypePtr(),
+                                               zero_address))
         ASSERT_NE(picked_address, zero_address);
         picked.emplace(picked_address);
     }
@@ -153,7 +158,7 @@ TEST_F(SharedFlqAllocatorTest4, pickAddress) {
     ASSERT_TRUE(picked.count(IOAddress("192.0.2.1")));
 
     // Verify an additional pick returns zero address.
-    ASSERT_EQ(alloc.pickAddress(client_classes, IdentifierBaseTypePtr(), zero_address),
+    ASSERT_EQ(alloc->pickAddress(client_classes, IdentifierBaseTypePtr(), zero_address),
               zero_address);
 
     // Verify that only pool 1 and 3 addresses are picked for classes "one" or "three"
@@ -165,9 +170,9 @@ TEST_F(SharedFlqAllocatorTest4, pickAddress) {
     for (int i = 0; i < 4; ++i) {
         IOAddress picked_address = zero_address;
         ASSERT_NO_THROW_LOG(picked_address =
-                            alloc.pickAddress(client_classes,
-                                              IdentifierBaseTypePtr(),
-                                              zero_address));
+                            alloc->pickAddress(client_classes,
+                                               IdentifierBaseTypePtr(),
+                                               zero_address));
         ASSERT_NE(picked_address, zero_address);
         picked.emplace(picked_address);
     }
@@ -179,7 +184,7 @@ TEST_F(SharedFlqAllocatorTest4, pickAddress) {
     ASSERT_TRUE(picked.count(IOAddress("192.0.3.1")));
 
     // Verify an additional pick returns zero address.
-    ASSERT_EQ(alloc.pickAddress(client_classes, IdentifierBaseTypePtr(), zero_address),
+    ASSERT_EQ(alloc->pickAddress(client_classes, IdentifierBaseTypePtr(), zero_address),
               zero_address);
 }
 
@@ -197,11 +202,18 @@ public:
         ASSERT_TRUE(LeaseMgrFactory::haveInstance());
         ASSERT_EQ(LeaseMgrFactory::instance().getType(), "sflqtest");
         initSubnet6();
+        SharedFlqAllocator::setInUse(false);
+    }
+
+    /// @brief Post-test cleanup.
+    virtual void TearDown() {
+        SharedFlqAllocator::setInUse(false);
     }
 
     /// @brief Initializes the test subnet for V4 tests.
     void initSubnet6() {
         static SubnetID id(1);
+
         subnet_ = Subnet6::create(IOAddress("3001::"), 64, 0, 0, 0, 0 , id);
         PoolPtr pool(new Pool6(Lease::TYPE_NA, IOAddress("3001::10"), IOAddress("3001::11")));
         pool->allowClientClass("ALL");
@@ -248,10 +260,14 @@ public:
         pool.reset(new Pool6(Lease::TYPE_PD, IOAddress("4001:30::"), 124, 128));
         pool->allowClientClass("LENGTH_HINT");
         subnet_->addPool(pool);
+
+        subnet_->setAllocatorType("shared-flq");
+        subnet_->setPdAllocatorType("shared-flq");
+        subnet_->createAllocators();
     }
 
     /// @brief Subnet used in tests.
-    SubnetPtr subnet_;
+    Subnet6Ptr subnet_;
 };
 
 // Test that the allocator returns the correct type.
@@ -269,30 +285,30 @@ TEST_F(SharedFlqAllocatorTest6, getType) {
 
 // Tests initAfterConfigure() for V6/TYPE_NA pools.
 TEST_F(SharedFlqAllocatorTest6, initAfterConfigureNA) {
-    SharedFlqAllocator alloc(Lease::TYPE_NA, subnet_);
-
     EXPECT_FALSE(SharedFlqAllocator::inUse());
-    EXPECT_NO_THROW(alloc.initAfterConfigure());
+    auto alloc = subnet_->getAllocator(Lease::TYPE_NA);
+    ASSERT_TRUE(alloc);
+    ASSERT_NO_THROW_LOG(alloc->initAfterConfigure());
     EXPECT_TRUE(SharedFlqAllocator::inUse());
 
     // Verify the NA pools.
-    SflqTestLeaseMgr& slm = dynamic_cast<SflqTestLeaseMgr&>(LeaseMgrFactory::instance());
+   SflqTestLeaseMgr& slm = dynamic_cast<SflqTestLeaseMgr&>(LeaseMgrFactory::instance());
 
     for (auto pool : subnet_->getPools(Lease::TYPE_NA)) {
-        auto sflq_pool = slm.findPool(pool->getFirstAddress(), pool->getLastAddress());
+       auto sflq_pool = slm.findPool(pool->getFirstAddress(), pool->getLastAddress());
         ASSERT_TRUE(sflq_pool) << "no sflq pool for: " << pool->toText();
         ASSERT_EQ(sflq_pool->lease_type_, Lease::TYPE_NA);
     }
 }
 
-// Exercises ShareFlqAllocator::pickAddressInternal() for V6/TYPE_NA
+// Exercises SharedFlqAllocator::pickAddressInternal() for V6/TYPE_NA
 // using various class matches.
 TEST_F(SharedFlqAllocatorTest6, pickAddress) {
     IOAddress zero_address = IOAddress::IPV6_ZERO_ADDRESS();
 
-    SharedFlqAllocator alloc(Lease::TYPE_NA, subnet_);
-
-    ASSERT_NO_THROW_LOG(alloc.initAfterConfigure());
+    auto alloc = subnet_->getAllocator(Lease::TYPE_NA);
+    ASSERT_TRUE(alloc);
+    ASSERT_NO_THROW_LOG(alloc->initAfterConfigure());
 
     SflqTestLeaseMgr& slm = dynamic_cast<SflqTestLeaseMgr&>(LeaseMgrFactory::instance());
     for (auto pool : subnet_->getPools(Lease::TYPE_NA)) {
@@ -310,9 +326,9 @@ TEST_F(SharedFlqAllocatorTest6, pickAddress) {
     for (int i = 0; i < 6; ++i) {
         IOAddress picked_address = zero_address;
         ASSERT_NO_THROW_LOG(picked_address =
-                            alloc.pickAddress(client_classes,
-                                              IdentifierBaseTypePtr(),
-                                              zero_address));
+                            alloc->pickAddress(client_classes,
+                                               IdentifierBaseTypePtr(),
+                                               zero_address));
         ASSERT_NE(picked_address, zero_address);
         picked.emplace(picked_address);
     }
@@ -326,7 +342,7 @@ TEST_F(SharedFlqAllocatorTest6, pickAddress) {
     ASSERT_TRUE(picked.count(IOAddress("3001::31")));
 
     // Verify an additional pick returns zero address.
-    ASSERT_EQ(alloc.pickAddress(client_classes, IdentifierBaseTypePtr(), zero_address),
+    ASSERT_EQ(alloc->pickAddress(client_classes, IdentifierBaseTypePtr(), zero_address),
               zero_address);
 
     // Verify that only pool 2 addresses are picked for class "two"
@@ -337,7 +353,7 @@ TEST_F(SharedFlqAllocatorTest6, pickAddress) {
     for (int i = 0; i < 2; ++i) {
         IOAddress picked_address = zero_address;
         ASSERT_NO_THROW_LOG(picked_address =
-                            alloc.pickAddress(client_classes,
+                            alloc->pickAddress(client_classes,
                                               IdentifierBaseTypePtr(),
                                               zero_address))
         ASSERT_NE(picked_address, zero_address);
@@ -349,7 +365,7 @@ TEST_F(SharedFlqAllocatorTest6, pickAddress) {
     ASSERT_TRUE(picked.count(IOAddress("3001::21")));
 
     // Verify an additional pick returns zero address.
-    ASSERT_EQ(alloc.pickAddress(client_classes, IdentifierBaseTypePtr(), zero_address),
+    ASSERT_EQ(alloc->pickAddress(client_classes, IdentifierBaseTypePtr(), zero_address),
               zero_address);
 
     // Verify that only pool 1 and 3 addresses are picked for classes "one" or "three"
@@ -361,9 +377,9 @@ TEST_F(SharedFlqAllocatorTest6, pickAddress) {
     for (int i = 0; i < 4; ++i) {
         IOAddress picked_address = zero_address;
         ASSERT_NO_THROW_LOG(picked_address =
-                            alloc.pickAddress(client_classes,
-                                              IdentifierBaseTypePtr(),
-                                              zero_address));
+                            alloc->pickAddress(client_classes,
+                                               IdentifierBaseTypePtr(),
+                                               zero_address));
         ASSERT_NE(picked_address, zero_address);
         picked.emplace(picked_address);
     }
@@ -375,15 +391,21 @@ TEST_F(SharedFlqAllocatorTest6, pickAddress) {
     ASSERT_TRUE(picked.count(IOAddress("3001::31")));
 
     // Verify an additional pick returns zero address.
-    ASSERT_EQ(alloc.pickAddress(client_classes, IdentifierBaseTypePtr(), zero_address),
+    ASSERT_EQ(alloc->pickAddress(client_classes, IdentifierBaseTypePtr(), zero_address),
               zero_address);
 }
 
 // Tests initAfterConfigure() for V6/TYPE_PD pools.
 TEST_F(SharedFlqAllocatorTest6, initAfterConfigurePD) {
-    SharedFlqAllocator alloc(Lease::TYPE_PD, subnet_);
+    subnet_->setPdAllocatorType("shared-flq");
+    ASSERT_NO_THROW(subnet_->createAllocators());
 
-    ASSERT_NO_THROW_LOG(alloc.initAfterConfigure());
+    EXPECT_FALSE(SharedFlqAllocator::inUse());
+
+    auto alloc = subnet_->getAllocator(Lease::TYPE_PD);
+    ASSERT_TRUE(alloc);
+    ASSERT_NO_THROW_LOG(alloc->initAfterConfigure());
+    EXPECT_TRUE(SharedFlqAllocator::inUse());
 
     // Verify the PD pools.
     SflqTestLeaseMgr& slm = dynamic_cast<SflqTestLeaseMgr&>(LeaseMgrFactory::instance());
@@ -395,14 +417,16 @@ TEST_F(SharedFlqAllocatorTest6, initAfterConfigurePD) {
     }
 }
 
-// Exercises ShareFlqAllocator::pickPrefixInternal() V6/TYPE_PD using
+// Exercises SharedFlqAllocator::pickPrefixInternal() V6/TYPE_PD using
 // various class matches.
 TEST_F(SharedFlqAllocatorTest6, pickPrefix) {
     IOAddress zero_address = IOAddress::IPV6_ZERO_ADDRESS();
 
-    SharedFlqAllocator alloc(Lease::TYPE_PD, subnet_);
-
-    EXPECT_NO_THROW(alloc.initAfterConfigure());
+    subnet_->setPdAllocatorType("shared-flq");
+    ASSERT_NO_THROW(subnet_->createAllocators());
+    auto alloc = subnet_->getAllocator(Lease::TYPE_PD);
+    ASSERT_TRUE(alloc);
+    ASSERT_NO_THROW_LOG(alloc->initAfterConfigure());
 
     SflqTestLeaseMgr& slm = dynamic_cast<SflqTestLeaseMgr&>(LeaseMgrFactory::instance());
 
@@ -423,12 +447,12 @@ TEST_F(SharedFlqAllocatorTest6, pickPrefix) {
     for (int i = 0; i < 6; ++i) {
         IOAddress picked_address = zero_address;
         ASSERT_NO_THROW_LOG(picked_address =
-                            alloc.pickPrefix(client_classes,
-                                             dummy,
-                                             IdentifierBaseTypePtr(),
-                                             Allocator::PREFIX_LEN_EQUAL,
-                                             zero_address,
-                                             0));
+                            alloc->pickPrefix(client_classes,
+                                              dummy,
+                                              IdentifierBaseTypePtr(),
+                                              Allocator::PREFIX_LEN_EQUAL,
+                                              zero_address,
+                                              0));
         ASSERT_NE(picked_address, zero_address);
         picked.emplace(picked_address);
     }
@@ -442,8 +466,8 @@ TEST_F(SharedFlqAllocatorTest6, pickPrefix) {
     ASSERT_TRUE(picked.count(IOAddress("2001::31")));
 
     // Verify an additional pick returns zero address.
-    ASSERT_EQ(alloc.pickPrefix(client_classes, dummy, IdentifierBaseTypePtr(),
-                               Allocator::PREFIX_LEN_EQUAL, zero_address, 0),
+    ASSERT_EQ(alloc->pickPrefix(client_classes, dummy, IdentifierBaseTypePtr(),
+                                Allocator::PREFIX_LEN_EQUAL, zero_address, 0),
                zero_address);
 
     // Verify that only pool 2 addresses are picked for class "two"
@@ -454,12 +478,12 @@ TEST_F(SharedFlqAllocatorTest6, pickPrefix) {
     for (int i = 0; i < 2; ++i) {
         IOAddress picked_address = zero_address;
         ASSERT_NO_THROW_LOG(picked_address =
-                            alloc.pickPrefix(client_classes,
-                                             dummy,
-                                             IdentifierBaseTypePtr(),
-                                             Allocator::PREFIX_LEN_EQUAL,
-                                             zero_address,
-                                             0));
+                            alloc->pickPrefix(client_classes,
+                                              dummy,
+                                              IdentifierBaseTypePtr(),
+                                              Allocator::PREFIX_LEN_EQUAL,
+                                              zero_address,
+                                              0));
         ASSERT_NE(picked_address, zero_address);
         picked.emplace(picked_address);
     }
@@ -469,8 +493,8 @@ TEST_F(SharedFlqAllocatorTest6, pickPrefix) {
     ASSERT_TRUE(picked.count(IOAddress("2001::21")));
 
     // Verify an additional pick returns zero address.
-    ASSERT_EQ(alloc.pickPrefix(client_classes, dummy, IdentifierBaseTypePtr(),
-                               Allocator::PREFIX_LEN_EQUAL, zero_address, 0),
+    ASSERT_EQ(alloc->pickPrefix(client_classes, dummy, IdentifierBaseTypePtr(),
+                                Allocator::PREFIX_LEN_EQUAL, zero_address, 0),
                zero_address);
 
     // Verify that only pool 1 and 3 addresses are picked for classes "one" or "three"
@@ -481,7 +505,7 @@ TEST_F(SharedFlqAllocatorTest6, pickPrefix) {
     client_classes.insert("three");
     for (int i = 0; i < 4; ++i) {
         IOAddress picked_address = zero_address;
-        ASSERT_NO_THROW_LOG(picked_address = alloc.pickPrefix(client_classes,
+        ASSERT_NO_THROW_LOG(picked_address = alloc->pickPrefix(client_classes,
                                                               dummy,
                                                               IdentifierBaseTypePtr(),
                                                               Allocator::PREFIX_LEN_EQUAL,
@@ -498,19 +522,21 @@ TEST_F(SharedFlqAllocatorTest6, pickPrefix) {
     ASSERT_TRUE(picked.count(IOAddress("2001::31")));
 
     // Verify an additional pick returns zero address.
-    ASSERT_EQ(alloc.pickPrefix(client_classes, dummy, IdentifierBaseTypePtr(),
+    ASSERT_EQ(alloc->pickPrefix(client_classes, dummy, IdentifierBaseTypePtr(),
                                Allocator::PREFIX_LEN_EQUAL, zero_address, 0),
                zero_address);
 }
 
-// Exercises ShareFlqAllocator::pickPrefixInternal() V6/TYPE_PD
+// Exercises SharedFlqAllocator::pickPrefixInternal() V6/TYPE_PD
 // when specifying a prefix length mode and hint.
 TEST_F(SharedFlqAllocatorTest6, pickPrefixLenHint) {
     IOAddress zero_address = IOAddress::IPV6_ZERO_ADDRESS();
 
-    SharedFlqAllocator alloc(Lease::TYPE_PD, subnet_);
-
-    EXPECT_NO_THROW(alloc.initAfterConfigure());
+    subnet_->setPdAllocatorType("shared-flq");
+    ASSERT_NO_THROW(subnet_->createAllocators());
+    auto alloc = subnet_->getAllocator(Lease::TYPE_PD);
+    ASSERT_TRUE(alloc);
+    ASSERT_NO_THROW_LOG(alloc->initAfterConfigure());
 
     SflqTestLeaseMgr& slm = dynamic_cast<SflqTestLeaseMgr&>(LeaseMgrFactory::instance());
 
@@ -525,28 +551,28 @@ TEST_F(SharedFlqAllocatorTest6, pickPrefixLenHint) {
     client_classes.insert("LENGTH_HINT");
 
     IOAddress picked_address = zero_address;
-    ASSERT_NO_THROW_LOG(picked_address = alloc.pickPrefix(client_classes,
-                                                          dummy,
-                                                          IdentifierBaseTypePtr(),
-                                                          Allocator::PREFIX_LEN_EQUAL,
-                                                          zero_address,
-                                                          126));
+    ASSERT_NO_THROW_LOG(picked_address = alloc->pickPrefix(client_classes,
+                                                           dummy,
+                                                           IdentifierBaseTypePtr(),
+                                                           Allocator::PREFIX_LEN_EQUAL,
+                                                           zero_address,
+                                                           126));
     EXPECT_EQ(picked_address, IOAddress("4001:20::"));
 
-    ASSERT_NO_THROW_LOG(picked_address = alloc.pickPrefix(client_classes,
-                                                          dummy,
-                                                          IdentifierBaseTypePtr(),
-                                                          Allocator::PREFIX_LEN_LOWER,
-                                                          zero_address,
-                                                          126));
+    ASSERT_NO_THROW_LOG(picked_address = alloc->pickPrefix(client_classes,
+                                                           dummy,
+                                                           IdentifierBaseTypePtr(),
+                                                           Allocator::PREFIX_LEN_LOWER,
+                                                           zero_address,
+                                                           126));
     EXPECT_EQ(picked_address, IOAddress("4001:10::"));
 
-    ASSERT_NO_THROW_LOG(picked_address = alloc.pickPrefix(client_classes,
-                                                          dummy,
-                                                          IdentifierBaseTypePtr(),
-                                                          Allocator::PREFIX_LEN_HIGHER,
-                                                          zero_address,
-                                                          126));
+    ASSERT_NO_THROW_LOG(picked_address = alloc->pickPrefix(client_classes,
+                                                           dummy,
+                                                           IdentifierBaseTypePtr(),
+                                                           Allocator::PREFIX_LEN_HIGHER,
+                                                           zero_address,
+                                                           126));
     EXPECT_EQ(picked_address, IOAddress("4001:30::"));
 }
 
index ed672be5fefa2c9a008c04a5cac118a87380063a..fc761830217f502b4c621e14a49c008e55905e84 100644 (file)
@@ -1706,7 +1706,7 @@ TEST(SharedNetwork4Test, sflqGetPreferredSubnet) {
 
     // Allocate an address from remaining subnets and make sure that the
     // allocation from the subnet4 is slightly more recent. Both are
-    // more recent than subnet3b.
+    // more recent than subnet3.
     auto now = boost::posix_time::microsec_clock::universal_time();
     state4->setLastAllocatedTime(now + boost::posix_time::seconds(2));
     state4->setLastAllocatedTime(now + boost::posix_time::seconds(1));
@@ -1719,10 +1719,6 @@ TEST(SharedNetwork4Test, sflqGetPreferredSubnet) {
 // This test verifies that the v4 preferred subnet is returned based
 // on the timestamp when the subnet was last used and allowed
 // client classes when SFLQ allocation is used.
-// @todo Note that this test uses SFLQ for TYPE_NA pools. While this
-// is currently not allowed through configuration, the underlying
-// logic supports it. This test includes SFLQ for TYPE_NA in
-// the event that it utlimately is supported.
 TEST(SharedNetwork6Test, sflqGetPreferredSubnet) {
     SharedNetwork6Ptr network(new SharedNetwork6("frog"));
 
index 9156d5df7bc36bcab678550c61d748c3df117d48..691e11325dfbc96413e0ac30d50456f7ac4774b7 100644 (file)
@@ -5900,7 +5900,7 @@ GenericLeaseMgrTest::testSflqLeaseOps4() {
             ASSERT_FALSE(returned);
         }
 
-        // Ask for a free lease and verifly accordingly.
+        // Ask for a free lease and verify accordingly.
         IOAddress picked = IOAddress::IPV4_ZERO_ADDRESS();
         ASSERT_NO_THROW_LOG(picked = lmptr_->sflqPickFreeLease4(start_address, end_address));
         if (scenario.can_pick_) {
@@ -5958,9 +5958,8 @@ GenericLeaseMgrTest::testSflqCreateAndPick6(bool exp_not_implemented /* = false
     }
 }
 
-// will need a PD and an NA version
 void
-GenericLeaseMgrTest::testSflqLeaseOps6() {
+GenericLeaseMgrTest::testSflqLeaseOps6(Lease::Type lease_type) {
     // Create a subnet with a one address pool for simplicity.
     IOAddress start_address("2001:db8::");
     IOAddress end_address("2001:db8::");
@@ -5968,10 +5967,18 @@ GenericLeaseMgrTest::testSflqLeaseOps6() {
     Subnet6Ptr subnet;
     Pool6Ptr pool;
     subnet.reset(new Subnet6(start_address, 64, 1, 2, 3, 4, 1));
-    pool.reset(new Pool6(Lease::TYPE_NA, start_address, end_address));
-    subnet->addPool(pool);
-    AllocatorPtr sflq_allocator(new SharedFlqAllocator(Lease::TYPE_NA, subnet));
-    subnet->setAllocator(Lease::TYPE_NA, sflq_allocator);
+
+    if (lease_type == Lease::TYPE_NA) {
+        pool.reset(new Pool6(Lease::TYPE_NA, start_address, end_address));
+        subnet->addPool(pool);
+        subnet->setAllocatorType("shared-flq");
+    } else {
+        pool.reset(new Pool6(Lease::TYPE_PD, start_address, 128, 128));
+        subnet->addPool(pool);
+        subnet->setPdAllocatorType("shared-flq");
+    }
+
+    ASSERT_NO_THROW_LOG(subnet->createAllocators());
     cfg->add(subnet);
 
     // Should create the SFLQ pool for the subnet.
@@ -6032,6 +6039,7 @@ GenericLeaseMgrTest::testSflqLeaseOps6() {
 
     // Iterate over the scenarios.
     Lease6Ptr preop_lease = initializeLease6(start_address.toText());
+    preop_lease->type_ = lease_type;
     for ( auto const& scenario : scenarios ){
         std::ostringstream os;
         os << "scenario at line: " << scenario.lineno_;
@@ -6060,7 +6068,7 @@ GenericLeaseMgrTest::testSflqLeaseOps6() {
         };
 
         // Attempt to the fetch the lease and test accordingly.
-        Lease6Ptr returned = lmptr_->getLease6(Lease::TYPE_NA, preop_lease->addr_);
+        Lease6Ptr returned = lmptr_->getLease6(lease_type, preop_lease->addr_);
         if (scenario.should_exist_) {
             ASSERT_TRUE(returned);
             detailCompareLease(preop_lease, returned);
@@ -6068,7 +6076,7 @@ GenericLeaseMgrTest::testSflqLeaseOps6() {
             ASSERT_FALSE(returned);
         }
 
-        // Ask for a free lease and verifly accordingly.
+        // Ask for a free lease and verify accordingly.
         IOAddress picked = IOAddress::IPV6_ZERO_ADDRESS();
         ASSERT_NO_THROW_LOG(picked = lmptr_->sflqPickFreeLease6(start_address, end_address));
         if (scenario.can_pick_) {
index 9abe4c282ee6267541d18acdfd9598bf3ace47c3..26fea68293712e199b5b59d6f548c3a0b18d28c2 100644 (file)
@@ -709,7 +709,9 @@ public:
     void testSflqCreateAndPick6(bool exp_not_implemented = false);
 
     /// @brief Checks v6 SFLQ add, update, and delete
-    void testSflqLeaseOps6();
+    ///
+    /// @param lease_type lease type to test (TYPE_NA or TYPE_PD)
+    void testSflqLeaseOps6(Lease::Type lease_type);
 
     /// @brief String forms of IPv4 addresses
     std::vector<std::string> straddress4_;
index 2a5365bfb76b32fa500e6079e018179b76959944..bc33dd379cb9c0e3d507b1d7bc16a3809b50f088 100644 (file)
@@ -7055,7 +7055,7 @@ END $$
 DELIMITER ;
 
 -- Procedure to create an affected rows count of 1.
--- Used after udpate and delete lease operations.
+-- Used after update and delete lease operations.
 DROP TEMPORARY TABLE IF EXISTS sflq_dummy_row_count;
 DROP PROCEDURE IF EXISTS sflqFakeRowCount;
 DELIMITER $$
index 326febe92e5d1c04d9f41234f3428f5095e578a9..800d8f9e2c5e1e0b825c7aa34eb1ebe043ca88da 100755 (executable)
@@ -636,7 +636,7 @@ END $$
 DELIMITER ;
 
 -- Procedure to create an affected rows count of 1.
--- Used after udpate and delete lease operations.
+-- Used after update and delete lease operations.
 DROP TEMPORARY TABLE IF EXISTS sflq_dummy_row_count;
 DROP PROCEDURE IF EXISTS sflqFakeRowCount;
 DELIMITER $$
index 333509914a11c7048b5225a9604bf4e0b3b492d1..125dc32589d6b0093f7a1934672252e90bf1a138 100644 (file)
@@ -7359,7 +7359,7 @@ END;
 $$ LANGUAGE plpgsql;
 
 -- Procedure to create an affected rows count of 1.
--- Used after udpate and delete lease operations.
+-- Used after update and delete lease operations.
 CREATE OR REPLACE FUNCTION sflqFakeRowCount()
 RETURNS VOID
 LANGUAGE plpgsql AS $$
index 4f3391bbf4dcebfe269d7f27a2c66c22862cf31a..fafc7db2104cf78bc9e451dc19d95f58841a7981 100755 (executable)
@@ -646,7 +646,7 @@ END;
 \$\$ LANGUAGE plpgsql;
 
 -- Procedure to create an affected rows count of 1.
--- Used after udpate and delete lease operations.
+-- Used after update and delete lease operations.
 CREATE OR REPLACE FUNCTION sflqFakeRowCount()
 RETURNS VOID
 LANGUAGE plpgsql AS \$\$