From: Razvan Becheriu Date: Mon, 3 Aug 2020 12:11:34 +0000 (+0300) Subject: [#1336] count declined as allocated X-Git-Tag: Kea-1.8.0~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8fb99b074496327bc8751fcc8a1b93db068a3a8;p=thirdparty%2Fkea.git [#1336] count declined as allocated --- diff --git a/src/lib/dhcpsrv/cfg_subnets4.cc b/src/lib/dhcpsrv/cfg_subnets4.cc index eda3bd2240..08602ff01d 100644 --- a/src/lib/dhcpsrv/cfg_subnets4.cc +++ b/src/lib/dhcpsrv/cfg_subnets4.cc @@ -521,7 +521,7 @@ CfgSubnets4::updateStatistics() { // Only recount the stats if we have subnets. if (subnets_.begin() != subnets_.end()) { - LeaseMgrFactory::instance().recountLeaseStats4(); + LeaseMgrFactory::instance().recountLeaseStats4(); } } diff --git a/src/lib/dhcpsrv/lease_mgr.cc b/src/lib/dhcpsrv/lease_mgr.cc index 9fa9d49b6b..c1e2f370ad 100644 --- a/src/lib/dhcpsrv/lease_mgr.cc +++ b/src/lib/dhcpsrv/lease_mgr.cc @@ -114,8 +114,8 @@ LeaseMgr::recountLeaseStats4() { LeaseStatsRow row; while (query->getNextRow(row)) { if (row.lease_state_ == Lease::STATE_DEFAULT) { - // Set subnet level value. - stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_, + // Add to subnet level value. + stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_, "assigned-addresses"), row.state_count_); } else if (row.lease_state_ == Lease::STATE_DECLINED) { @@ -126,6 +126,11 @@ LeaseMgr::recountLeaseStats4() { // Add to the global value. stats_mgr.addValue("declined-addresses", row.state_count_); + + // Add to subnet level value. + stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_, + "assigned-addresses"), + row.state_count_); } } } @@ -208,6 +213,7 @@ LeaseMgr::recountLeaseStats6() { if (!stats_mgr.getObservation("cumulative-assigned-nas")) { stats_mgr.setValue("cumulative-assigned-nas", zero); } + if (!stats_mgr.getObservation("cumulative-assigned-pds")) { stats_mgr.setValue("cumulative-assigned-pds", zero); } @@ -249,8 +255,8 @@ LeaseMgr::recountLeaseStats6() { switch(row.lease_type_) { case Lease::TYPE_NA: if (row.lease_state_ == Lease::STATE_DEFAULT) { - // Set subnet level value. - stats_mgr.setValue(StatsMgr:: + // Add subnet level value. + stats_mgr.addValue(StatsMgr:: generateName("subnet", row.subnet_id_, "assigned-nas"), row.state_count_); @@ -263,6 +269,12 @@ LeaseMgr::recountLeaseStats6() { // Add to the global value. stats_mgr.addValue("declined-addresses", row.state_count_); + + // Add subnet level value. + stats_mgr.addValue(StatsMgr:: + generateName("subnet", row.subnet_id_, + "assigned-nas"), + row.state_count_); } break; diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc index 275492e131..848b0826a1 100644 --- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc @@ -3047,7 +3047,7 @@ GenericLeaseMgrTest::testRecountLeaseStats4() { makeLease4("192.0.1.4", subnet_id); // Update the expected stats list for subnet 1. - expectedStats[subnet_id - 1]["assigned-addresses"] = 2; + expectedStats[subnet_id - 1]["assigned-addresses"] = 3; // 2 + 1 declined expectedStats[subnet_id - 1]["declined-addresses"] = 1; // Now let's add leases to subnet 2. @@ -3057,6 +3057,7 @@ GenericLeaseMgrTest::testRecountLeaseStats4() { makeLease4("192.0.2.2", subnet_id, Lease::STATE_DECLINED); // Update the expected stats. + expectedStats[subnet_id - 1]["assigned-addresses"] = 1; // 0 + 1 declined expectedStats[subnet_id - 1]["declined-addresses"] = 1; // Now Recount the stats. @@ -3067,9 +3068,10 @@ GenericLeaseMgrTest::testRecountLeaseStats4() { // Delete some leases from subnet, and update the expected stats. EXPECT_TRUE(lmptr_->deleteLease(lease1)); - expectedStats[0]["assigned-addresses"] = 1; + expectedStats[0]["assigned-addresses"] = 2; EXPECT_TRUE(lmptr_->deleteLease(lease2)); + expectedStats[0]["assigned-addresses"] = 1; expectedStats[0]["declined-addresses"] = 0; // Recount the stats. @@ -3148,7 +3150,7 @@ GenericLeaseMgrTest::testRecountLeaseStats6() { makeLease6(Lease::TYPE_NA, "3001:1::1", 0, subnet_id); Lease6Ptr lease2 = makeLease6(Lease::TYPE_NA, "3001:1::2", 0, subnet_id); makeLease6(Lease::TYPE_NA, "3001:1::3", 0, subnet_id); - expectedStats[subnet_id - 1]["assigned-nas"] = 3; + expectedStats[subnet_id - 1]["assigned-nas"] = 5; // 3 + 2 declined // Insert two declined NAs. makeLease6(Lease::TYPE_NA, "3001:1::4", 0, subnet_id, @@ -3178,7 +3180,7 @@ GenericLeaseMgrTest::testRecountLeaseStats6() { // Insert two assigned NAs. makeLease6(Lease::TYPE_NA, "2001:db81::1", 0, subnet_id); makeLease6(Lease::TYPE_NA, "2001:db81::2", 0, subnet_id); - expectedStats[subnet_id - 1]["assigned-nas"] = 2; + expectedStats[subnet_id - 1]["assigned-nas"] = 3; // 2 + 1 declined // Insert one declined NA. Lease6Ptr lease3 = makeLease6(Lease::TYPE_NA, "2001:db81::3", 0, subnet_id, @@ -3193,9 +3195,10 @@ GenericLeaseMgrTest::testRecountLeaseStats6() { // Delete some leases and update the expected stats. EXPECT_TRUE(lmptr_->deleteLease(lease2)); - expectedStats[0]["assigned-nas"] = 2; + expectedStats[0]["assigned-nas"] = 4; EXPECT_TRUE(lmptr_->deleteLease(lease3)); + expectedStats[1]["assigned-nas"] = 2; expectedStats[1]["declined-addresses"] = 0; // Recount the stats.