|
@@ -22,6 +22,7 @@
|
|
|
#include <dhcpsrv/lease_mgr_factory.h>
|
|
|
#include <dhcp6/ctrl_dhcp6_srv.h>
|
|
|
#include <hooks/hooks_manager.h>
|
|
|
+#include <stats/stats_mgr.h>
|
|
|
#include <testutils/unix_control_client.h>
|
|
|
|
|
|
#include "marker_file.h"
|
|
@@ -41,6 +42,7 @@ using namespace isc::data;
|
|
|
using namespace isc::dhcp;
|
|
|
using namespace isc::dhcp::test;
|
|
|
using namespace isc::hooks;
|
|
|
+using namespace isc::stats;
|
|
|
|
|
|
namespace {
|
|
|
|
|
@@ -63,6 +65,8 @@ public:
|
|
|
}
|
|
|
|
|
|
virtual ~CtrlDhcpv6SrvTest() {
|
|
|
+ LeaseMgrFactory::destroy();
|
|
|
+ StatsMgr::instance().removeAll();
|
|
|
reset();
|
|
|
};
|
|
|
|
|
@@ -415,6 +419,37 @@ TEST_F(CtrlChannelDhcpv6SrvTest, controlChannelShutdown) {
|
|
|
EXPECT_EQ("{ \"result\": 0, \"text\": \"Shutting down.\" }",response);
|
|
|
}
|
|
|
|
|
|
+// Thist test verifies that the DHCP server immediately reclaims expired
|
|
|
+// leases on leases-reclaim command
|
|
|
+TEST_F(CtrlChannelDhcpv6SrvTest, controlLeasesReclaim) {
|
|
|
+ createUnixChannelServer();
|
|
|
+
|
|
|
+ // Create an expired lease. The lease is expired by 40 seconds ago
|
|
|
+ // (valid lifetime = 60, cltt = now - 100).
|
|
|
+ DuidPtr duid_expired(new DUID(DUID::fromText("00:01:02:03:04:05:06").getDuid()));
|
|
|
+ Lease6Ptr lease_expired(new Lease6(Lease::TYPE_NA, IOAddress("3000::1"),
|
|
|
+ duid_expired, 1, 50, 60, 10, 20, SubnetID(1)));
|
|
|
+ lease_expired->cltt_ = time(NULL) - 100;
|
|
|
+
|
|
|
+ // Add lease to the database.
|
|
|
+ LeaseMgr& lease_mgr = LeaseMgrFactory().instance();
|
|
|
+ ASSERT_NO_THROW(lease_mgr.addLease(lease_expired));
|
|
|
+
|
|
|
+ // Make sure it has been added.
|
|
|
+ ASSERT_TRUE(lease_mgr.getLease6(Lease::TYPE_NA, IOAddress("3000::1")));
|
|
|
+
|
|
|
+ // Send the command.
|
|
|
+ std::string response;
|
|
|
+ sendUnixCommand("{ \"command\": \"leases-reclaim\" }", response);
|
|
|
+ EXPECT_EQ("{ \"result\": 0, \"text\": \"Leases successfully reclaimed.\" }", response);
|
|
|
+
|
|
|
+ // Verify that the lease in the database has been processed as expected.
|
|
|
+ ASSERT_NO_THROW(
|
|
|
+ lease_expired = lease_mgr.getLease6(Lease::TYPE_NA, IOAddress("3000::1"))
|
|
|
+ );
|
|
|
+ EXPECT_FALSE(lease_expired);
|
|
|
+}
|
|
|
+
|
|
|
// Tests that the server properly responds to statistics commands. Note this
|
|
|
// is really only intended to verify that the appropriate Statistics handler
|
|
|
// is called based on the command. It is not intended to be an exhaustive
|
|
@@ -461,36 +496,4 @@ TEST_F(CtrlChannelDhcpv6SrvTest, controlChannelStats) {
|
|
|
response);
|
|
|
}
|
|
|
|
|
|
-// Thist test verifies that the DHCP server immediately reclaims expired
|
|
|
-// leases on leases-reclaim command
|
|
|
-// @todo currently must be last as it changes statistics.
|
|
|
-TEST_F(CtrlChannelDhcpv6SrvTest, controlLeasesReclaim) {
|
|
|
- createUnixChannelServer();
|
|
|
-
|
|
|
- // Create an expired lease. The lease is expired by 40 seconds ago
|
|
|
- // (valid lifetime = 60, cltt = now - 100).
|
|
|
- DuidPtr duid_expired(new DUID(DUID::fromText("00:01:02:03:04:05:06").getDuid()));
|
|
|
- Lease6Ptr lease_expired(new Lease6(Lease::TYPE_NA, IOAddress("3000::1"),
|
|
|
- duid_expired, 1, 50, 60, 10, 20, SubnetID(1)));
|
|
|
- lease_expired->cltt_ = time(NULL) - 100;
|
|
|
-
|
|
|
- // Add lease to the database.
|
|
|
- LeaseMgr& lease_mgr = LeaseMgrFactory().instance();
|
|
|
- ASSERT_NO_THROW(lease_mgr.addLease(lease_expired));
|
|
|
-
|
|
|
- // Make sure it has been added.
|
|
|
- ASSERT_TRUE(lease_mgr.getLease6(Lease::TYPE_NA, IOAddress("3000::1")));
|
|
|
-
|
|
|
- // Send the command.
|
|
|
- std::string response;
|
|
|
- sendUnixCommand("{ \"command\": \"leases-reclaim\" }", response);
|
|
|
- EXPECT_EQ("{ \"result\": 0, \"text\": \"Leases successfully reclaimed.\" }", response);
|
|
|
-
|
|
|
- // Verify that the lease in the database has been processed as expected.
|
|
|
- ASSERT_NO_THROW(
|
|
|
- lease_expired = lease_mgr.getLease6(Lease::TYPE_NA, IOAddress("3000::1"))
|
|
|
- );
|
|
|
- EXPECT_FALSE(lease_expired);
|
|
|
-}
|
|
|
-
|
|
|
} // End of anonymous namespace
|