From: Thomas Markwalder Date: Tue, 16 Dec 2025 15:47:45 +0000 (-0500) Subject: [#4176] Initial review comments X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3df126f5f6f87cd2b541bc7326331f9bebaf0fe;p=thirdparty%2Fkea.git [#4176] Initial review comments modified: src/hooks/dhcp/lease_cmds/lease_cmds.cc modified: src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc modified: src/lib/dhcpsrv/lease_mgr.cc modified: src/lib/dhcpsrv/lease_mgr.h --- diff --git a/src/hooks/dhcp/lease_cmds/lease_cmds.cc b/src/hooks/dhcp/lease_cmds/lease_cmds.cc index ab9efddc9f..12bae7b089 100644 --- a/src/hooks/dhcp/lease_cmds/lease_cmds.cc +++ b/src/hooks/dhcp/lease_cmds/lease_cmds.cc @@ -576,7 +576,6 @@ LeaseCmdsImpl::addOrUpdate6(Lease6Ptr lease, bool force_create) { "retry might succeed"); } - std::cout << "TKM, OK we're here" << std::endl; LeaseMgr::updateStatsOnUpdate(existing, lease); return (false); } diff --git a/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc b/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc index 61fdbe097d..5919790f92 100644 --- a/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc +++ b/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc @@ -2368,10 +2368,10 @@ void Lease6CmdsTest::testLease6GetByStateFind2() { // Let's check if the response makes any sense. ConstElementPtr lease = leases->get(0); ASSERT_TRUE(lease); - checkLease6(lease, "2001:db8:1::1", 0, 66, "42:42:42:42:42:42:42:42"); + checkLease6(__LINE__, lease, "2001:db8:1::1", 0, 66, "42:42:42:42:42:42:42:42"); lease = leases->get(2); ASSERT_TRUE(lease); - checkLease6(lease, "2001:db8:2::1", 0, 99, "42:42:42:42:42:42:42:42"); + checkLease6(__LINE__, lease, "2001:db8:2::1", 0, 99, "42:42:42:42:42:42:42:42"); } void Lease6CmdsTest::testLease6GetByStateFindN() { diff --git a/src/lib/dhcpsrv/lease_mgr.cc b/src/lib/dhcpsrv/lease_mgr.cc index a66e56a4d8..26de00a7d0 100644 --- a/src/lib/dhcpsrv/lease_mgr.cc +++ b/src/lib/dhcpsrv/lease_mgr.cc @@ -1412,15 +1412,8 @@ LeaseMgr::updateStatsOnAdd(const Lease6Ptr& lease) { } } -/// @brief Helper function that adds a value to an address stat's global, -/// subnet, and pool level values. -/// -/// @param stat base name of the statistic e.g. "assigned-addresses", "assigned-nas" -/// @param subnet_id id of desired subnet -/// @param pool pointer to the pool (if one) within the subnet, if empty -/// pool level is skipped. -/// @param value signed value to add to the statistic -void bumpStat(const std::string& stat, SubnetID& subnet_id, PoolPtr pool, int value) { +void +LeaseMgr::bumpStat(const std::string& stat, SubnetID& subnet_id, PoolPtr pool, int value) { StatsMgr::instance().addValue(stat, static_cast(value)); StatsMgr::instance().addValue(StatsMgr::generateName("subnet", subnet_id, stat), static_cast(value)); @@ -1431,21 +1424,14 @@ void bumpStat(const std::string& stat, SubnetID& subnet_id, PoolPtr pool, int va } } -/// @brief Helper function that adds a value to a PD stat's global, -/// subnet, and pool level values. -/// -/// @param stat base name of the statistic e.g. "assigned-pds" -/// @param subnet_id id of desired subnet -/// @param pool pointer to the pool (if one) within the subnet, if empty -/// pool level is skipped. -/// @param value signed value to add to the statistic -void bumpStatPDPool(const std::string& stat, SubnetID& subnet_id, PoolPtr pool, int value) { +void +LeaseMgr::bumpStatPrefixPool(const std::string& stat, SubnetID& subnet_id, PoolPtr pool, int value) { StatsMgr::instance().addValue(stat, static_cast(value)); StatsMgr::instance().addValue(StatsMgr::generateName("subnet", subnet_id, stat), static_cast(value)); if (pool) { StatsMgr::instance().addValue(StatsMgr::generateName("subnet", subnet_id, - StatsMgr::generateName("pd-pool", pool->getID(), stat)), + StatsMgr::generateName("pd-pool", pool->getID(), stat)), static_cast(value)); } } @@ -1682,7 +1668,7 @@ LeaseMgr::updateStatsOnUpdate(const Lease6Ptr& existing, if (existing->type_ == Lease::TYPE_NA) { bumpStat("assigned-nas", existing->subnet_id_, pool, 1); } else { - bumpStatPDPool("assigned-pds", existing->subnet_id_, pool, 1); + bumpStatPrefixPool("assigned-pds", existing->subnet_id_, pool, 1); } break; @@ -1711,7 +1697,7 @@ LeaseMgr::updateStatsOnUpdate(const Lease6Ptr& existing, if (existing->type_ == Lease::TYPE_NA) { bumpStat("assigned-nas", existing->subnet_id_, pool, -1); } else { - bumpStatPDPool("assigned-pds", existing->subnet_id_, pool, -1); + bumpStatPrefixPool("assigned-pds", existing->subnet_id_, pool, -1); } break; @@ -1774,8 +1760,8 @@ LeaseMgr::updateStatsOnUpdate(const Lease6Ptr& existing, bumpStat("assigned-nas", existing->subnet_id_, existing_pool, -1); bumpStat("assigned-nas", lease->subnet_id_, new_pool, 1); } else { - bumpStatPDPool("assigned-pds", existing->subnet_id_, existing_pool, -1); - bumpStatPDPool("assigned-pds", lease->subnet_id_, new_pool, 1); + bumpStatPrefixPool("assigned-pds", existing->subnet_id_, existing_pool, -1); + bumpStatPrefixPool("assigned-pds", lease->subnet_id_, new_pool, 1); } break; @@ -1790,7 +1776,7 @@ LeaseMgr::updateStatsOnUpdate(const Lease6Ptr& existing, if (lease->type_ == Lease::TYPE_NA) { bumpStat("assigned-nas", lease->subnet_id_, new_pool, 1); } else { - bumpStatPDPool("assigned-pds", lease->subnet_id_, new_pool, 1); + bumpStatPrefixPool("assigned-pds", lease->subnet_id_, new_pool, 1); } break; @@ -1829,7 +1815,7 @@ LeaseMgr::updateStatsOnUpdate(const Lease6Ptr& existing, if (lease->type_ == Lease::TYPE_NA) { bumpStat("assigned-nas", existing->subnet_id_, existing_pool, -1); } else { - bumpStatPDPool("assigned-pds", existing->subnet_id_, existing_pool, -1); + bumpStatPrefixPool("assigned-pds", existing->subnet_id_, existing_pool, -1); } break; diff --git a/src/lib/dhcpsrv/lease_mgr.h b/src/lib/dhcpsrv/lease_mgr.h index 720b614452..d7a55e220e 100644 --- a/src/lib/dhcpsrv/lease_mgr.h +++ b/src/lib/dhcpsrv/lease_mgr.h @@ -1132,6 +1132,27 @@ public: /// @param lease Deleted lease. static void updateStatsOnDelete(const Lease6Ptr& lease); + /// @brief Helper function that adds a value to an address stat's global, + /// subnet, and pool level values. + /// + /// @param stat base name of the statistic e.g. "assigned-addresses", "assigned-nas" + /// @param subnet_id id of desired subnet + /// @param pool pointer to the pool (if one) within the subnet, if empty + /// pool level is skipped. + /// @param value signed value to add to the statistic + static void bumpStat(const std::string& stat, SubnetID& subnet_id, + PoolPtr pool, int value); + + /// @brief Helper function that adds a value to a prefix stat's global, + /// subnet, and pool level values. + /// + /// @param stat base name of the statistic e.g. "assigned-pds" + /// @param subnet_id id of desired subnet + /// @param pool pointer to the pool (if one) within the subnet, if empty + /// pool level is skipped. + /// @param value signed value to add to the statistic + static void bumpStatPrefixPool(const std::string& stat, SubnetID& + subnet_id, PoolPtr pool, int value); protected: /// Extended information / Bulk Lease Query shared interface.