From: Marcin Siodelski Date: Wed, 22 Mar 2023 11:46:59 +0000 (+0100) Subject: [#2780] Log the number of FLQ leases X-Git-Tag: Kea-2.3.7~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59d5e47072067944c4607ce8c5de7dbc2a724f39;p=thirdparty%2Fkea.git [#2780] Log the number of FLQ leases --- diff --git a/src/lib/dhcpsrv/dhcpsrv_messages.mes b/src/lib/dhcpsrv/dhcpsrv_messages.mes index b5b7834128..643b0b74c9 100644 --- a/src/lib/dhcpsrv/dhcpsrv_messages.mes +++ b/src/lib/dhcpsrv/dhcpsrv_messages.mes @@ -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 diff --git a/src/lib/dhcpsrv/flq_allocation_state.cc b/src/lib/dhcpsrv/flq_allocation_state.cc index 1783d43780..816759afbb 100644 --- a/src/lib/dhcpsrv/flq_allocation_state.cc +++ b/src/lib/dhcpsrv/flq_allocation_state.cc @@ -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 diff --git a/src/lib/dhcpsrv/flq_allocation_state.h b/src/lib/dhcpsrv/flq_allocation_state.h index be5728ad78..839b3cb760 100644 --- a/src/lib/dhcpsrv/flq_allocation_state.h +++ b/src/lib/dhcpsrv/flq_allocation_state.h @@ -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. diff --git a/src/lib/dhcpsrv/flq_allocator.cc b/src/lib/dhcpsrv/flq_allocator.cc index 2429bfd65f..b1265559b4 100644 --- a/src/lib/dhcpsrv/flq_allocator.cc +++ b/src/lib/dhcpsrv/flq_allocator.cc @@ -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(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()); } diff --git a/src/lib/dhcpsrv/tests/flq_allocation_state_unittest.cc b/src/lib/dhcpsrv/tests/flq_allocation_state_unittest.cc index 273e071ade..8ca8c5bf51 100644 --- a/src/lib/dhcpsrv/tests/flq_allocation_state_unittest.cc +++ b/src/lib/dhcpsrv/tests/flq_allocation_state_unittest.cc @@ -34,16 +34,25 @@ TEST(PoolFreeLeaseAllocationState, addDeleteFreeLeaseV4) { auto pool = boost::make_shared(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(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(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(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"));