|
@@ -1104,6 +1104,8 @@ public:
|
|
|
AllocEnginePtr engine_;
|
|
|
};
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/// @brief Specialization of the @c ExpirationAllocEngineTest class to test
|
|
|
/// reclamation of the IPv6 leases.
|
|
|
class ExpirationAllocEngine6Test : public ExpirationAllocEngineTest<Lease6Ptr> {
|
|
@@ -1115,6 +1117,14 @@ public:
|
|
|
/// stores them in the lease manager.
|
|
|
ExpirationAllocEngine6Test();
|
|
|
|
|
|
+ /// @brief Virtual destructor.
|
|
|
+ ///
|
|
|
+ /// Clears up static fields that may be modified by hooks.
|
|
|
+ virtual ~ExpirationAllocEngine6Test() {
|
|
|
+ callout_lease_.reset();
|
|
|
+ callout_name_ = string("");
|
|
|
+ }
|
|
|
+
|
|
|
/// @brief Creates collection of leases for a test.
|
|
|
///
|
|
|
/// It is called internally at the construction time.
|
|
@@ -1195,12 +1205,62 @@ public:
|
|
|
/// it the second time.
|
|
|
void testReclaimReusedLeases(const uint16_t msg_type, const bool use_reclaimed);
|
|
|
|
|
|
+ /// @brief Callout for lease6_recover
|
|
|
+ ///
|
|
|
+ /// This callout stores passed parameter into static fields.
|
|
|
+ ///
|
|
|
+ /// @param callout_handle will be provided by hooks framework
|
|
|
+ /// @return always 0
|
|
|
+ static int lease6RecoverCallout(CalloutHandle& callout_handle) {
|
|
|
+ callout_name_ = "lease6_recover";
|
|
|
+
|
|
|
+ callout_handle.getArgument("lease6", callout_lease_);
|
|
|
+
|
|
|
+ return (0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// @brief Callout for lease6_recover that sets status to SKIP
|
|
|
+ ///
|
|
|
+ /// This callout stores passed parameter into static fields.
|
|
|
+ ///
|
|
|
+ /// @param callout_handle will be provided by hooks framework
|
|
|
+ /// @return always 0
|
|
|
+ static int lease6RecoverSkipCallout(CalloutHandle& callout_handle) {
|
|
|
+ // Set the next step status to SKIP
|
|
|
+ callout_handle.setStatus(CalloutHandle::NEXT_STEP_SKIP);
|
|
|
+
|
|
|
+ return (lease6RecoverCallout(callout_handle));
|
|
|
+ }
|
|
|
+
|
|
|
+ /// @brief Test install a hook callout, recovers declined leases
|
|
|
+ ///
|
|
|
+ /// This test: declines, then expires half of the leases, then
|
|
|
+ /// installs a callout on lease6_recover hook, then reclaims
|
|
|
+ /// expired leases and checks that:
|
|
|
+ /// - the callout was indeed called
|
|
|
+ /// - the parameter (lease6) was indeed passed as expected
|
|
|
+ /// - checks that the leases are removed (skip=false) or
|
|
|
+ /// - checks that the leases are still there (skip=true)
|
|
|
+ /// @param skip should the callout set the next step status to skip?
|
|
|
+ void
|
|
|
+ testReclaimDeclinedHook(bool skip);
|
|
|
+
|
|
|
+ /// The following parameters will be written by a callout
|
|
|
+ static std::string callout_name_; ///< Stores callout name
|
|
|
+ static Lease6Ptr callout_lease_; ///< Stores callout parameter
|
|
|
};
|
|
|
|
|
|
+std::string ExpirationAllocEngine6Test::callout_name_;
|
|
|
+Lease6Ptr ExpirationAllocEngine6Test::callout_lease_;
|
|
|
+
|
|
|
ExpirationAllocEngine6Test::ExpirationAllocEngine6Test()
|
|
|
: ExpirationAllocEngineTest<Lease6Ptr>("type=memfile universe=6 persist=false") {
|
|
|
createLeases();
|
|
|
callout_argument_name = "lease6";
|
|
|
+
|
|
|
+ // Let's clear any garbage previous test may have left in static fields.
|
|
|
+ callout_name_ = string("");
|
|
|
+ callout_lease_.reset();
|
|
|
}
|
|
|
|
|
|
void
|
|
@@ -1397,6 +1457,44 @@ ExpirationAllocEngine6Test::testReclaimReusedLeases(const uint16_t msg_type,
|
|
|
|
|
|
}
|
|
|
|
|
|
+void
|
|
|
+ExpirationAllocEngine6Test::testReclaimDeclinedHook(bool skip) {
|
|
|
+ for (unsigned int i = 0; i < TEST_LEASES_NUM; ++i) {
|
|
|
+
|
|
|
+ // Mark leases with even indexes as expired.
|
|
|
+ if (evenLeaseIndex(i)) {
|
|
|
+
|
|
|
+ // Mark lease as declined with 100 seconds of probation-period
|
|
|
+ // (i.e. lease is supposed to be off limits for 100 seconds)
|
|
|
+ decline(i, 100);
|
|
|
+
|
|
|
+ // The higher the index, the more expired the lease.
|
|
|
+ expire(i, 10 + i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
+ "lease6_recover",
|
|
|
+ skip ? lease6RecoverSkipCallout : lease6RecoverCallout));
|
|
|
+
|
|
|
+ // Run leases reclamation routine on all leases.
|
|
|
+ ASSERT_NO_THROW(reclaimExpiredLeases(0, 0, true));
|
|
|
+
|
|
|
+ // Make sure that the callout really was called. It was supposed to modify
|
|
|
+ // the callout_name_ and store the lease in callout_lease_
|
|
|
+ EXPECT_EQ("lease6_recover", callout_name_);
|
|
|
+ EXPECT_TRUE(callout_lease_);
|
|
|
+
|
|
|
+ // Leases with even indexes should not exist in the DB
|
|
|
+ if (skip) {
|
|
|
+ // Skip status should have prevented removing the lease.
|
|
|
+ EXPECT_TRUE(testLeases(&leaseExists, &evenLeaseIndex));
|
|
|
+ } else {
|
|
|
+ // The hook hasn't modified next step status. The lease should be gone.
|
|
|
+ EXPECT_TRUE(testLeases(&leaseDoesntExist, &evenLeaseIndex));
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
// This test verifies that the leases can be reclaimed without being removed
|
|
|
// from the database. In such case, the leases' state is set to
|
|
|
// "expired-reclaimed".
|
|
@@ -1534,6 +1632,18 @@ TEST_F(ExpirationAllocEngine6Test, reclaimReusedLeasesSolicit) {
|
|
|
// again when the Solicit message is being processed.
|
|
|
TEST_F(ExpirationAllocEngine6Test, reclaimReusedLeasesSolicitAlreadyReclaimed) {
|
|
|
testReclaimReusedLeases(DHCPV6_SOLICIT, true);
|
|
|
+
|
|
|
+// This test verifies if the hooks installed on lease6_recover are called
|
|
|
+// when the lease expires.
|
|
|
+TEST_F(ExpirationAllocEngine6Test, reclaimDeclinedHook1) {
|
|
|
+ testReclaimDeclinedHook(false); // false = don't use skip callout
|
|
|
+}
|
|
|
+
|
|
|
+// This test verifies if the hooks installed on lease6_recover are called
|
|
|
+// when the lease expires and that the next step status set to SKIP
|
|
|
+// causes the recovery to not be conducted.
|
|
|
+TEST_F(ExpirationAllocEngine6Test, reclaimDeclinedHook2) {
|
|
|
+ testReclaimDeclinedHook(true); // true = use skip callout
|
|
|
}
|
|
|
|
|
|
// *******************************************************
|
|
@@ -1553,6 +1663,14 @@ public:
|
|
|
/// stores them in the lease manager.
|
|
|
ExpirationAllocEngine4Test();
|
|
|
|
|
|
+ /// @brief Virtual destructor.
|
|
|
+ ///
|
|
|
+ /// Clears up static fields that may be modified by hooks.
|
|
|
+ virtual ~ExpirationAllocEngine4Test() {
|
|
|
+ callout_lease_.reset();
|
|
|
+ callout_name_ = string("");
|
|
|
+ }
|
|
|
+
|
|
|
/// @brief Creates collection of leases for a test.
|
|
|
///
|
|
|
/// It is called internally at the construction time.
|
|
@@ -1646,12 +1764,62 @@ public:
|
|
|
void testReclaimReusedLeases(const uint8_t msg_type, const bool client_renews,
|
|
|
const bool use_reclaimed);
|
|
|
|
|
|
+ /// @brief Callout for lease4_recover
|
|
|
+ ///
|
|
|
+ /// This callout stores passed parameter into static fields.
|
|
|
+ ///
|
|
|
+ /// @param callout_handle will be provided by hooks framework
|
|
|
+ /// @return always 0
|
|
|
+ static int lease4RecoverCallout(CalloutHandle& callout_handle) {
|
|
|
+ callout_name_ = "lease4_recover";
|
|
|
+
|
|
|
+ callout_handle.getArgument("lease4", callout_lease_);
|
|
|
+
|
|
|
+ return (0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// @brief Callout for lease4_recover that sets status to SKIP
|
|
|
+ ///
|
|
|
+ /// This callout stores passed parameter into static fields.
|
|
|
+ ///
|
|
|
+ /// @param callout_handle will be provided by hooks framework
|
|
|
+ /// @return always 0
|
|
|
+ static int lease4RecoverSkipCallout(CalloutHandle& callout_handle) {
|
|
|
+ // Set the next step status to SKIP
|
|
|
+ callout_handle.setStatus(CalloutHandle::NEXT_STEP_SKIP);
|
|
|
+
|
|
|
+ return (lease4RecoverCallout(callout_handle));
|
|
|
+ }
|
|
|
+
|
|
|
+ /// @brief Test install a hook callout, recovers declined leases
|
|
|
+ ///
|
|
|
+ /// This test: declines, then expires half of the leases, then
|
|
|
+ /// installs a callout on lease4_recover hook, then reclaims
|
|
|
+ /// expired leases and checks that:
|
|
|
+ /// - the callout was indeed called
|
|
|
+ /// - the parameter (lease4) was indeed passed as expected
|
|
|
+ /// - checks that the leases are removed (skip=false) or
|
|
|
+ /// - checks that the leases are still there (skip=true)
|
|
|
+ /// @param skip should the callout set the next step status to skip?
|
|
|
+ void
|
|
|
+ testReclaimDeclinedHook(bool skip);
|
|
|
+
|
|
|
+ /// The following parameters will be written by a callout
|
|
|
+ static std::string callout_name_; ///< Stores callout name
|
|
|
+ static Lease4Ptr callout_lease_; ///< Stores callout parameter
|
|
|
};
|
|
|
|
|
|
+std::string ExpirationAllocEngine4Test::callout_name_;
|
|
|
+Lease4Ptr ExpirationAllocEngine4Test::callout_lease_;
|
|
|
+
|
|
|
ExpirationAllocEngine4Test::ExpirationAllocEngine4Test()
|
|
|
: ExpirationAllocEngineTest<Lease4Ptr>("type=memfile universe=4 persist=false") {
|
|
|
createLeases();
|
|
|
callout_argument_name = "lease4";
|
|
|
+
|
|
|
+ // Let's clear any garbage previous test may have left in static fields.
|
|
|
+ callout_name_ = string("");
|
|
|
+ callout_lease_.reset();
|
|
|
}
|
|
|
|
|
|
void
|
|
@@ -1945,6 +2113,43 @@ ExpirationAllocEngine4Test::testReclaimReusedLeases(const uint8_t msg_type,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void
|
|
|
+ExpirationAllocEngine4Test::testReclaimDeclinedHook(bool skip) {
|
|
|
+ for (unsigned int i = 0; i < TEST_LEASES_NUM; ++i) {
|
|
|
+
|
|
|
+ // Mark leases with even indexes as expired.
|
|
|
+ if (evenLeaseIndex(i)) {
|
|
|
+
|
|
|
+ // Mark lease as declined with 100 seconds of probation-period
|
|
|
+ // (i.e. lease is supposed to be off limits for 100 seconds)
|
|
|
+ decline(i, 100);
|
|
|
+
|
|
|
+ // The higher the index, the more expired the lease.
|
|
|
+ expire(i, 10 + i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
+ "lease4_recover",
|
|
|
+ skip ? lease4RecoverSkipCallout : lease4RecoverCallout));
|
|
|
+
|
|
|
+ // Run leases reclamation routine on all leases.
|
|
|
+ ASSERT_NO_THROW(reclaimExpiredLeases(0, 0, true));
|
|
|
+
|
|
|
+ // Make sure that the callout really was called. It was supposed to modify
|
|
|
+ // the callout_name_ and store the lease in callout_lease_
|
|
|
+ EXPECT_EQ("lease4_recover", callout_name_);
|
|
|
+ EXPECT_TRUE(callout_lease_);
|
|
|
+
|
|
|
+ // Leases with even indexes should not exist in the DB
|
|
|
+ if (skip) {
|
|
|
+ // Skip status should have prevented removing the lease.
|
|
|
+ EXPECT_TRUE(testLeases(&leaseExists, &evenLeaseIndex));
|
|
|
+ } else {
|
|
|
+ // The hook hasn't modified next step status. The lease should be gone.
|
|
|
+ EXPECT_TRUE(testLeases(&leaseDoesntExist, &evenLeaseIndex));
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
// This test verifies that the leases can be reclaimed without being removed
|
|
|
// from the database. In such case, the leases' state is set to
|
|
@@ -2102,5 +2307,17 @@ TEST_F(ExpirationAllocEngine4Test, reclaimRenewedLeasesDiscoverAlreadyReclaimed)
|
|
|
testReclaimReusedLeases(DHCPDISCOVER, false, true);
|
|
|
}
|
|
|
|
|
|
+// This test verifies if the hooks installed on lease4_recover are called
|
|
|
+// when the lease expires.
|
|
|
+TEST_F(ExpirationAllocEngine4Test, reclaimDeclinedHook1) {
|
|
|
+ testReclaimDeclinedHook(false); // false = don't use skip callout
|
|
|
+}
|
|
|
+
|
|
|
+// This test verifies if the hooks installed on lease4_recover are called
|
|
|
+// when the lease expires and that the next step status set to SKIP
|
|
|
+// causes the recovery to not be conducted.
|
|
|
+TEST_F(ExpirationAllocEngine4Test, reclaimDeclinedHook2) {
|
|
|
+ testReclaimDeclinedHook(true); // true = use skip callout
|
|
|
+}
|
|
|
|
|
|
}; // end of anonymous namespace
|