]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1336] count declined as allocated
authorRazvan Becheriu <razvan@isc.org>
Mon, 3 Aug 2020 12:11:34 +0000 (15:11 +0300)
committerRazvan Becheriu <razvan@isc.org>
Thu, 13 Aug 2020 19:37:50 +0000 (22:37 +0300)
src/lib/dhcpsrv/cfg_subnets4.cc
src/lib/dhcpsrv/lease_mgr.cc
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc

index eda3bd2240e2d71df0cbd2bd09b90f0b753504dc..08602ff01d1860bc6d9b9d27ba9f9ceb39de5023 100644 (file)
@@ -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();
     }
 }
 
index 9fa9d49b6bb3bd2a5dcef2dc76173dc1d81370fd..c1e2f370ad9e6da7524e7e4cc35679a9deb9eb86 100644 (file)
@@ -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;
 
index 275492e131896c64161c58f0af07b97af78b85f3..848b0826a1b815e54e3cc86d16244be45bf76696 100644 (file)
@@ -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.