]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2780] Log the number of FLQ leases
authorMarcin Siodelski <msiodelski@gmail.com>
Wed, 22 Mar 2023 11:46:59 +0000 (12:46 +0100)
committerMarcin Siodelski <msiodelski@gmail.com>
Wed, 29 Mar 2023 12:44:07 +0000 (14:44 +0200)
src/lib/dhcpsrv/dhcpsrv_messages.mes
src/lib/dhcpsrv/flq_allocation_state.cc
src/lib/dhcpsrv/flq_allocation_state.h
src/lib/dhcpsrv/flq_allocator.cc
src/lib/dhcpsrv/tests/flq_allocation_state_unittest.cc

index b5b7834128ca2db45fcdf83b8578024faccd6f86..643b0b74c98103b465d91e9f01e4e8abf4d7605c 100644 (file)
@@ -86,20 +86,22 @@ This informational message is issued when the server begins building a queue
 of free address leases for the given subnet. It can take a considerable amount
 of time, depending on the size of the address pools.
 
-% DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_ADDRESS_LEASES_DONE populating free address leases for the FLQ allocator in subnet %1 completed in %2
+% DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_ADDRESS_LEASES_DONE populated %1 free address leases for the FLQ allocator in subnet %2 in %3
 This informational message is issued when the server ends building a queue
-of free address leases for a given subnet. The second argument logs the
-duration.
+of free address leases for a given subnet. The first argument logs the
+number of free leases, the second argument logs the subnet, and the third
+argument logs a duration.
 
 % DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_PREFIX_LEASES populating free prefix leases for the FLQ allocator in subnet %1; it can take a while!
 This informational message is issued when the server begins building a queue
 of free leases for the given subnet. It can take a considerable amount of
 time, depending on the size of the delegated prefix pools.
 
-% DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_PREFIX_LEASES_DONE populating free prefix leases for the FLQ allocator in subnet %1 completed in %2
+% DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_PREFIX_LEASES_DONE populated %1 free prefix leases for the FLQ allocator in subnet %2 completed in %3
 This informational message is issued when the server ends building a queue
-of free prefix leases for a given subnet. The second argument logs the
-duration.
+of free prefix leases for a given subnet. The first argument logs the
+number of free leases, the second argument logs the subnet, and the third
+argument logs a duration.
 
 % DHCPSRV_CFGMGR_IPV4_RESERVATIONS_NON_UNIQUE_IGNORED ignoring "ip-reservations-unique" setting because at least one of the host database backends does not support non-unique IP reservations in a subnet
 This warning message is issued when the server failed to use the new setting
index 1783d4378063e16773c89b56fc6182d1fc1e64e5..816759afbbf144db09286a73143d21fb231e4af3 100644 (file)
@@ -74,6 +74,14 @@ PoolFreeLeaseQueueAllocationState::offerFreeLease() {
     return (lease);
 }
 
+size_t
+PoolFreeLeaseQueueAllocationState::getFreeLeaseCount() const {
+    if (free_lease4_queue_) {
+        return (free_lease4_queue_->size());
+    }
+    return (free_lease6_queue_->size());
+}
+
 } // end of namespace isc::dhcp
 } // end of namespace isc
 
index be5728ad78e63a3987a0eb3d1515da9a30759faf..839b3cb7605cf0dee841481200e3d247e88999fa 100644 (file)
@@ -61,6 +61,11 @@ public:
     /// there are no free leases.
     asiolink::IOAddress offerFreeLease();
 
+    /// @brief Returns the current number of free leases in the queue.
+    ///
+    /// @return the number of free leases in the queue.
+    size_t getFreeLeaseCount() const;
+
 private:
 
     /// @brief A multi-index container holding free leases.
index 2429bfd65f1b641f4e2d0d797b548f86cc3acf53..b1265559b48257abb2601054ca6457fe55db4a57 100644 (file)
@@ -197,6 +197,7 @@ FreeLeaseQueueAllocator::populateFreeAddressLeases(const LeaseCollectionType& le
         }
     }
     // For each pool, check if the address is in the leases list.
+    size_t free_lease_count = 0;
     for (auto pool : pools) {
         // Create the pool permutation so the resulting lease queue is no
         // particular order.
@@ -213,11 +214,13 @@ FreeLeaseQueueAllocator::populateFreeAddressLeases(const LeaseCollectionType& le
                 pool_state->addFreeLease(address);
             }
         }
+        free_lease_count += pool_state->getFreeLeaseCount();
     }
 
     stopwatch.stop();
 
     LOG_INFO(dhcpsrv_logger, DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_ADDRESS_LEASES_DONE)
+        .arg(free_lease_count)
         .arg(subnet->toText())
         .arg(stopwatch.logFormatLastDuration());
 }
@@ -240,6 +243,7 @@ FreeLeaseQueueAllocator::populateFreePrefixDelegationLeases(const Lease6Collecti
         }
     }
     // For each pool, check if the prefix is in the leases list.
+    size_t free_lease_count = 0;
     for (auto pool : pools) {
         auto pool6 = boost::dynamic_pointer_cast<Pool6>(pool);
         if (!pool6) {
@@ -260,11 +264,13 @@ FreeLeaseQueueAllocator::populateFreePrefixDelegationLeases(const Lease6Collecti
                 pool_state->addFreeLease(prefix);
             }
         }
+        free_lease_count += pool_state->getFreeLeaseCount();
     }
 
     stopwatch.stop();
 
     LOG_INFO(dhcpsrv_logger, DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_PREFIX_LEASES_DONE)
+        .arg(free_lease_count)
         .arg(subnet->toText())
         .arg(stopwatch.logFormatLastDuration());
 }
index 273e071ade018f1d5581f2a069954ef2de4a3704..8ca8c5bf5185521b534ffc2f2e5002cd0c624977 100644 (file)
@@ -34,16 +34,25 @@ TEST(PoolFreeLeaseAllocationState, addDeleteFreeLeaseV4) {
     auto pool = boost::make_shared<Pool4>(IOAddress("192.0.2.1"), IOAddress("192.0.2.10"));
     auto state = PoolFreeLeaseQueueAllocationState::create(pool);
     ASSERT_TRUE(state);
+    EXPECT_EQ(0, state->getFreeLeaseCount());
 
     state->addFreeLease(IOAddress("192.0.2.1"));
     EXPECT_FALSE(state->exhausted());
     EXPECT_EQ("192.0.2.1", state->offerFreeLease().toText());
+    EXPECT_EQ(1, state->getFreeLeaseCount());
 
-    state->deleteFreeLease(IOAddress("192.0.2.2"));
+    state->addFreeLease(IOAddress("192.0.2.3"));
     EXPECT_FALSE(state->exhausted());
     EXPECT_EQ("192.0.2.1", state->offerFreeLease().toText());
+    EXPECT_EQ(2, state->getFreeLeaseCount());
+
+    state->deleteFreeLease(IOAddress("192.0.2.2"));
+    EXPECT_FALSE(state->exhausted());
+    EXPECT_EQ("192.0.2.3", state->offerFreeLease().toText());
+    EXPECT_EQ(2, state->getFreeLeaseCount());
 
     state->deleteFreeLease(IOAddress("192.0.2.1"));
+    state->deleteFreeLease(IOAddress("192.0.2.3"));
     EXPECT_TRUE(state->exhausted());
     EXPECT_TRUE(state->offerFreeLease().isV4Zero());
 }
@@ -53,21 +62,25 @@ TEST(PoolFreeLeaseAllocationState, addFreeLeaseV4SeveralTimes) {
     auto pool = boost::make_shared<Pool4>(IOAddress("192.0.2.1"), IOAddress("192.0.2.10"));
     auto state = PoolFreeLeaseQueueAllocationState::create(pool);
     ASSERT_TRUE(state);
+    EXPECT_EQ(0, state->getFreeLeaseCount());
 
     // Add the free lease for the first time.
     state->addFreeLease(IOAddress("192.0.2.1"));
     EXPECT_FALSE(state->exhausted());
     EXPECT_EQ("192.0.2.1", state->offerFreeLease().toText());
+    EXPECT_EQ(1, state->getFreeLeaseCount());
 
     // Add the same lease the second time. The second lease instance should
     // not be inserted.
     state->addFreeLease(IOAddress("192.0.2.1"));
     EXPECT_FALSE(state->exhausted());
     EXPECT_EQ("192.0.2.1", state->offerFreeLease().toText());
+    EXPECT_EQ(1, state->getFreeLeaseCount());
 
     // Delete the sole lease and ensure there are no more leases.
     state->deleteFreeLease(IOAddress("192.0.2.1"));
     EXPECT_TRUE(state->exhausted());
+    EXPECT_EQ(0, state->getFreeLeaseCount());
 }
 
 
@@ -87,16 +100,25 @@ TEST(PoolFreeLeaseAllocationState, addDeleteFreeLeaseNA) {
                                           IOAddress("2001:db8:1::10"));
     auto state = PoolFreeLeaseQueueAllocationState::create(pool);
     ASSERT_TRUE(state);
+    EXPECT_EQ(0, state->getFreeLeaseCount());
 
     state->addFreeLease(IOAddress("2001:db8:1::1"));
     EXPECT_FALSE(state->exhausted());
     EXPECT_EQ("2001:db8:1::1", state->offerFreeLease().toText());
+    EXPECT_EQ(1, state->getFreeLeaseCount());
 
-    state->deleteFreeLease(IOAddress("2001:db8:1::2"));
+    state->addFreeLease(IOAddress("2001:db8:1::3"));
     EXPECT_FALSE(state->exhausted());
     EXPECT_EQ("2001:db8:1::1", state->offerFreeLease().toText());
+    EXPECT_EQ(2, state->getFreeLeaseCount());
+
+    state->deleteFreeLease(IOAddress("2001:db8:1::2"));
+    EXPECT_FALSE(state->exhausted());
+    EXPECT_EQ("2001:db8:1::3", state->offerFreeLease().toText());
+    EXPECT_EQ(2, state->getFreeLeaseCount());
 
     state->deleteFreeLease(IOAddress("2001:db8:1::1"));
+    state->deleteFreeLease(IOAddress("2001:db8:1::3"));
     EXPECT_TRUE(state->exhausted());
     EXPECT_TRUE(state->offerFreeLease().isV6Zero());
 }
@@ -107,17 +129,20 @@ TEST(PoolFreeLeaseAllocationState, addFreeLeasNASeveralTimes) {
                                           IOAddress("2001:db8:1::10"));
     auto state = PoolFreeLeaseQueueAllocationState::create(pool);
     ASSERT_TRUE(state);
+    EXPECT_EQ(0, state->getFreeLeaseCount());
 
     // Add the free lease for the first time.
     state->addFreeLease(IOAddress("2001:db8:1::5"));
     EXPECT_FALSE(state->exhausted());
     EXPECT_EQ("2001:db8:1::5", state->offerFreeLease().toText());
+    EXPECT_EQ(1, state->getFreeLeaseCount());
 
     // Add the same lease the second time. The second lease instance should
     // not be inserted.
     state->addFreeLease(IOAddress("2001:db8:1::5"));
     EXPECT_FALSE(state->exhausted());
     EXPECT_EQ("2001:db8:1::5", state->offerFreeLease().toText());
+    EXPECT_EQ(1, state->getFreeLeaseCount());
 
     // Delete the sole lease and ensure there are no more leases.
     state->deleteFreeLease(IOAddress("2001:db8:1::5"));
@@ -126,21 +151,30 @@ TEST(PoolFreeLeaseAllocationState, addFreeLeasNASeveralTimes) {
 
 // Test creating a new free lease queue allocation state for a
 // delegated prefix pool.
-TEST(PoolFreeLeaseAllocationState, createPD) {
+TEST(PoolFreeLeaseAllocationState, addDeleteFreeLeasePD) {
     auto pool = boost::make_shared<Pool6>(Lease::TYPE_PD, IOAddress("3000::"), 112, 120);
     auto state = PoolFreeLeaseQueueAllocationState::create(pool);
     ASSERT_TRUE(state);
     EXPECT_TRUE(state->exhausted());
+    EXPECT_EQ(0, state->getFreeLeaseCount());
 
     state->addFreeLease(IOAddress("3000::5600"));
     EXPECT_FALSE(state->exhausted());
     EXPECT_EQ("3000::5600", state->offerFreeLease().toText());
+    EXPECT_EQ(1, state->getFreeLeaseCount());
 
-    state->deleteFreeLease(IOAddress("3000::6400"));
+    state->addFreeLease(IOAddress("3000::7800"));
     EXPECT_FALSE(state->exhausted());
     EXPECT_EQ("3000::5600", state->offerFreeLease().toText());
+    EXPECT_EQ(2, state->getFreeLeaseCount());
+
+    state->deleteFreeLease(IOAddress("3000::6400"));
+    EXPECT_FALSE(state->exhausted());
+    EXPECT_EQ("3000::7800", state->offerFreeLease().toText());
+    EXPECT_EQ(2, state->getFreeLeaseCount());
 
     state->deleteFreeLease(IOAddress("3000::5600"));
+    state->deleteFreeLease(IOAddress("3000::7800"));
     EXPECT_TRUE(state->exhausted());
     EXPECT_TRUE(state->offerFreeLease().isV6Zero());
 }
@@ -150,17 +184,20 @@ TEST(PoolFreeLeaseAllocationState, addFreeLeasPDSeveralTimes) {
     auto pool = boost::make_shared<Pool6>(Lease::TYPE_PD, IOAddress("3000::"), 112, 120);
     auto state = PoolFreeLeaseQueueAllocationState::create(pool);
     ASSERT_TRUE(state);
+    EXPECT_EQ(0, state->getFreeLeaseCount());
 
     // Add the free lease for the first time.
     state->addFreeLease(IOAddress("3000::5600"));
     EXPECT_FALSE(state->exhausted());
     EXPECT_EQ("3000::5600", state->offerFreeLease().toText());
+    EXPECT_EQ(1, state->getFreeLeaseCount());
 
     // Add the same lease the second time. The second lease instance should
     // not be inserted.
     state->addFreeLease(IOAddress("3000::5600"));
     EXPECT_FALSE(state->exhausted());
     EXPECT_EQ("3000::5600", state->offerFreeLease().toText());
+    EXPECT_EQ(1, state->getFreeLeaseCount());
 
     // Delete the sole lease and ensure there are no more leases.
     state->deleteFreeLease(IOAddress("3000::5600"));