]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1065] update stats according to current lease state
authorRazvan Becheriu <razvan@isc.org>
Fri, 24 Jul 2020 12:21:04 +0000 (15:21 +0300)
committerRazvan Becheriu <razvan@isc.org>
Wed, 12 Aug 2020 06:56:43 +0000 (09:56 +0300)
src/hooks/dhcp/lease_cmds/lease_cmds.cc
src/hooks/dhcp/lease_cmds/tests/lease_cmds_unittest.cc
src/lib/dhcpsrv/alloc_engine.cc
src/lib/dhcpsrv/lease.cc

index e97f4c4e810326e0197e71b11f1ea5a33df7c3b7..8832422ef6a1e74a2915d8c6110d4d94ae68c931 100644 (file)
@@ -1207,7 +1207,7 @@ void updateOrAdd(Lease6Ptr lease) {
             LeaseMgrFactory::instance().getLease6(lease->type_, lease->addr_);
         // Try to update.
         LeaseMgrFactory::instance().updateLease6(lease);
-        bool update = lease6->checkUpdateStats();
+        bool update = lease6->stateExpiredReclaimed();
         if (lease6->subnet_id_ != lease->subnet_id_) {
             StatsMgr::instance().addValue(
                 StatsMgr::generateName("subnet", lease6->subnet_id_,
@@ -1532,7 +1532,7 @@ bool addOrUpdate4(Lease4Ptr lease, bool force_create) {
         return (true);
     }
     LeaseMgrFactory::instance().updateLease4(lease);
-    bool update = lease4->checkUpdateStats();
+    bool update = lease4->stateExpiredReclaimed();
     if (lease4->subnet_id_ != lease->subnet_id_) {
         StatsMgr::instance().addValue(
             StatsMgr::generateName("subnet", lease4->subnet_id_,
@@ -1622,7 +1622,7 @@ bool addOrUpdate6(Lease6Ptr lease, bool force_create) {
         return (true);
     }
     LeaseMgrFactory::instance().updateLease6(lease);
-    bool update = lease6->checkUpdateStats();
+    bool update = lease6->stateExpiredReclaimed();
     if (lease6->subnet_id_ != lease->subnet_id_) {
         StatsMgr::instance().addValue(
             StatsMgr::generateName("subnet", lease6->subnet_id_,
index 999ef07a1c835725f420a1632e4c35e48c9ceb06..d7ca915848fbf7c9fed82306214fd3b44bca85f9 100644 (file)
@@ -301,8 +301,8 @@ public:
     ///
     /// @param v6 true = v6, false = v4
     /// @param insert_lease governs whether a lease should be pre-inserted
-    /// @param expired governs whether a lease should be expired
-    void initLeaseMgr(bool v6, bool insert_lease, bool expired = false) {
+    /// @param reclaimed governs whether a lease should be in reclaimed state
+    void initLeaseMgr(bool v6, bool insert_lease, bool reclaimed = false) {
 
         LeaseMgrFactory::destroy();
         std::ostringstream s;
@@ -331,10 +331,10 @@ public:
 
         if (insert_lease) {
             if (v6) {
-                lmptr_->addLease(createLease6("2001:db8:1::1", 66, 0x42, expired));
-                lmptr_->addLease(createLease6("2001:db8:1::2", 66, 0x56, expired));
-                lmptr_->addLease(createLease6("2001:db8:2::1", 99, 0x42, expired));
-                lmptr_->addLease(createLease6("2001:db8:2::2", 99, 0x56, expired));
+                lmptr_->addLease(createLease6("2001:db8:1::1", 66, 0x42, reclaimed));
+                lmptr_->addLease(createLease6("2001:db8:1::2", 66, 0x56, reclaimed));
+                lmptr_->addLease(createLease6("2001:db8:2::1", 99, 0x42, reclaimed));
+                lmptr_->addLease(createLease6("2001:db8:2::2", 99, 0x56, reclaimed));
                 StatsMgr::instance().setValue(
                     StatsMgr::generateName("subnet", 66, "assigned-nas" ),
                     int64_t(2));
@@ -342,10 +342,10 @@ public:
                     StatsMgr::generateName("subnet", 99, "assigned-nas" ),
                     int64_t(2));
             } else {
-                lmptr_->addLease(createLease4("192.0.2.1", 44, 0x08, 0x42, expired));
-                lmptr_->addLease(createLease4("192.0.2.2", 44, 0x09, 0x56, expired));
-                lmptr_->addLease(createLease4("192.0.3.1", 88, 0x08, 0x42, expired));
-                lmptr_->addLease(createLease4("192.0.3.2", 88, 0x09, 0x56, expired));
+                lmptr_->addLease(createLease4("192.0.2.1", 44, 0x08, 0x42, reclaimed));
+                lmptr_->addLease(createLease4("192.0.2.2", 44, 0x09, 0x56, reclaimed));
+                lmptr_->addLease(createLease4("192.0.3.1", 88, 0x08, 0x42, reclaimed));
+                lmptr_->addLease(createLease4("192.0.3.2", 88, 0x09, 0x56, reclaimed));
                 StatsMgr::instance().setValue(
                     StatsMgr::generateName("subnet", 44, "assigned-addresses"),
                     int64_t(2));
@@ -367,13 +367,13 @@ public:
     /// it 6 times.
     /// @param client_id_pattern value to be used for generating client identifier by
     /// repeating it 8 times.
-    /// @param expired controls weather the lease should be expired.
+    /// @param reclaimed controls weather the lease should be in reclaimed state.
     /// @return Returns the lease created
     Lease4Ptr createLease4(const std::string& ip_address,
                            const SubnetID& subnet_id,
                            const uint8_t hw_address_pattern,
                            const uint8_t client_id_pattern,
-                           bool expired = false) {
+                           bool reclaimed = false) {
         Lease4Ptr lease(new Lease4());
 
         lease->addr_ = IOAddress(ip_address);
@@ -383,12 +383,10 @@ public:
         lease->client_id_ = ClientIdPtr(new ClientId(vector<uint8_t>(8, client_id_pattern)));
         // Purposely using high cltt and valid lifetime to test that
         // expiration time is cast properly.
-        if (expired) {
-            lease->cltt_ = 0;
-            lease->valid_lft_ = 60;
-        } else {
-            lease->cltt_ = DEC_2030_TIME; // December 11th 2030
-            lease->valid_lft_ = HIGH_VALID_LIFETIME; // Very high valid lifetime
+        lease->valid_lft_ = HIGH_VALID_LIFETIME; // Very high valid lifetime
+        lease->cltt_ = DEC_2030_TIME; // December 11th 2030
+        if (reclaimed) {
+            lease->state_ = Lease::STATE_EXPIRED_RECLAIMED;
         }
         lease->subnet_id_ = subnet_id;
         lease->fqdn_fwd_ = false;
@@ -408,12 +406,12 @@ public:
     /// @param subnet_id subnet identifier
     /// @param duid_address_pattern value to be used for generating DUID by
     /// repeating it 8 times
-    /// @param expired controls weather the lease should be expired.
+    /// @param reclaimed controls weather the lease should be in reclaimed state.
     /// @return Returns the lease created
     Lease6Ptr createLease6(const std::string& ip_address,
                            const SubnetID& subnet_id,
                            const uint8_t duid_pattern,
-                           bool expired = false) {
+                           bool reclaimed = false) {
         Lease6Ptr lease(new Lease6());
 
         lease->addr_ = IOAddress(ip_address);
@@ -424,12 +422,10 @@ public:
         lease->preferred_lft_ = 1800;
         // Purposely using high cltt and valid lifetime to test that
         // expiration time is cast properly.
-        if (expired) {
-            lease->cltt_ = 0;
-            lease->valid_lft_ = 60;
-        } else {
-            lease->cltt_ = DEC_2030_TIME; // December 11th 2030
-            lease->valid_lft_ = HIGH_VALID_LIFETIME; // Very high valid lifetime
+        lease->valid_lft_ = HIGH_VALID_LIFETIME; // Very high valid lifetime
+        lease->cltt_ = DEC_2030_TIME; // December 11th 2030
+        if (reclaimed) {
+            lease->state_ = Lease::STATE_EXPIRED_RECLAIMED;
         }
         lease->subnet_id_ = subnet_id;
         lease->fqdn_fwd_ = false;
index 08217247f7d342a16b5882a528f9ebf500c5243f..9962d101252b047c1fe76fa3a272529f90b567ae 100644 (file)
@@ -3837,8 +3837,7 @@ AllocEngine::renewLease4(const Lease4Ptr& lease,
         LeaseMgrFactory::instance().updateLease4(lease);
 
         // We need to account for the re-assignment of The lease.
-        if (ctx.old_lease_->checkUpdateStats()) {
-
+        if (ctx.old_lease_->expired() || ctx.old_lease_->state_ == Lease::STATE_EXPIRED_RECLAIMED) {
             StatsMgr::instance().addValue(
                 StatsMgr::generateName("subnet", ctx.subnet_->getID(),
                                        "assigned-addresses"),
index 542a74b9a553707cf6146a5fd994611e3e21e601..c9c8ba969940af3195d503e75cc235c8fef1253b 100644 (file)
@@ -130,11 +130,6 @@ Lease::hasIdenticalFqdn(const Lease& other) const {
             fqdn_rev_ == other.fqdn_rev_);
 }
 
-bool
-Lease::checkUpdateStats() const {
-    return (expired() || stateExpiredReclaimed());
-}
-
 void
 Lease::fromElementCommon(const LeasePtr& lease, const data::ConstElementPtr& element) {
     if (!element) {