|
@@ -1,4 +1,4 @@
|
|
|
-// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
|
|
|
+// Copyright (C) 2012-2013, 2015 Internet Systems Consortium, Inc. ("ISC")
|
|
|
//
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
@@ -19,7 +19,10 @@
|
|
|
#include <dhcp/dhcp4.h>
|
|
|
#include <dhcp4/ctrl_dhcp4_srv.h>
|
|
|
#include <dhcpsrv/cfgmgr.h>
|
|
|
+#include <dhcpsrv/lease.h>
|
|
|
+#include <dhcpsrv/lease_mgr_factory.h>
|
|
|
#include <hooks/hooks_manager.h>
|
|
|
+#include <stats/stats_mgr.h>
|
|
|
#include <testutils/unix_control_client.h>
|
|
|
|
|
|
#include "marker_file.h"
|
|
@@ -43,6 +46,7 @@ using namespace isc::data;
|
|
|
using namespace isc::dhcp;
|
|
|
using namespace isc::dhcp::test;
|
|
|
using namespace isc::hooks;
|
|
|
+using namespace isc::stats;
|
|
|
|
|
|
namespace {
|
|
|
|
|
@@ -80,6 +84,8 @@ public:
|
|
|
|
|
|
/// @brief Destructor
|
|
|
~CtrlChannelDhcpv4SrvTest() {
|
|
|
+ LeaseMgrFactory::destroy();
|
|
|
+ StatsMgr::instance().removeAll();
|
|
|
server_.reset();
|
|
|
reset();
|
|
|
};
|
|
@@ -94,6 +100,11 @@ public:
|
|
|
" \"interfaces-config\": {"
|
|
|
" \"interfaces\": [ \"*\" ]"
|
|
|
" },"
|
|
|
+ " \"expired-leases-processing\": {"
|
|
|
+ " \"reclaim-timer-wait-time\": 60,"
|
|
|
+ " \"hold-reclaimed-time\": 500,"
|
|
|
+ " \"flush-reclaimed-timer-wait-time\": 60"
|
|
|
+ " },"
|
|
|
" \"rebind-timer\": 2000, "
|
|
|
" \"renew-timer\": 1000, "
|
|
|
" \"subnet4\": [ ],"
|
|
@@ -333,6 +344,103 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlChannelShutdown) {
|
|
|
EXPECT_EQ("{ \"result\": 0, \"text\": \"Shutting down.\" }",response);
|
|
|
}
|
|
|
|
|
|
+// This test verifies that the DHCP server immediately reclaims expired
|
|
|
+// leases on leases-reclaim command
|
|
|
+TEST_F(CtrlChannelDhcpv4SrvTest, controlLeasesReclaim) {
|
|
|
+ createUnixChannelServer();
|
|
|
+
|
|
|
+ // Create expired leases. Leases are expired by 40 seconds ago
|
|
|
+ // (valid lifetime = 60, cltt = now - 100).
|
|
|
+ HWAddrPtr hwaddr0(new HWAddr(HWAddr::fromText("00:01:02:03:04:05")));
|
|
|
+ Lease4Ptr lease0(new Lease4(IOAddress("10.0.0.1"), hwaddr0,
|
|
|
+ ClientIdPtr(), 60, 10, 20,
|
|
|
+ time(NULL) - 100, SubnetID(1)));
|
|
|
+ HWAddrPtr hwaddr1(new HWAddr(HWAddr::fromText("01:02:03:04:05:06")));
|
|
|
+ Lease4Ptr lease1(new Lease4(IOAddress("10.0.0.2"), hwaddr1,
|
|
|
+ ClientIdPtr(), 60, 10, 20,
|
|
|
+ time(NULL) - 100, SubnetID(1)));
|
|
|
+
|
|
|
+ // Add leases to the database.
|
|
|
+ LeaseMgr& lease_mgr = LeaseMgrFactory().instance();
|
|
|
+ ASSERT_NO_THROW(lease_mgr.addLease(lease0));
|
|
|
+ ASSERT_NO_THROW(lease_mgr.addLease(lease1));
|
|
|
+
|
|
|
+ // Make sure they have been added.
|
|
|
+ ASSERT_TRUE(lease_mgr.getLease4(IOAddress("10.0.0.1")));
|
|
|
+ ASSERT_TRUE(lease_mgr.getLease4(IOAddress("10.0.0.2")));
|
|
|
+
|
|
|
+ // No arguments
|
|
|
+ std::string response;
|
|
|
+ sendUnixCommand("{ \"command\": \"leases-reclaim\" }", response);
|
|
|
+ EXPECT_EQ("{ \"result\": 1, \"text\": "
|
|
|
+ "\"Missing mandatory 'remove' parameter.\" }", response);
|
|
|
+
|
|
|
+ // Bad argument name
|
|
|
+ sendUnixCommand("{ \"command\": \"leases-reclaim\", "
|
|
|
+ "\"arguments\": { \"reclaim\": true } }", response);
|
|
|
+ EXPECT_EQ("{ \"result\": 1, \"text\": "
|
|
|
+ "\"Missing mandatory 'remove' parameter.\" }", response);
|
|
|
+
|
|
|
+ // Bad remove argument type
|
|
|
+ sendUnixCommand("{ \"command\": \"leases-reclaim\", "
|
|
|
+ "\"arguments\": { \"remove\": \"bogus\" } }", response);
|
|
|
+ EXPECT_EQ("{ \"result\": 1, \"text\": "
|
|
|
+ "\"'remove' parameter expected to be a boolean.\" }", response);
|
|
|
+
|
|
|
+ // Send the command
|
|
|
+ sendUnixCommand("{ \"command\": \"leases-reclaim\", "
|
|
|
+ "\"arguments\": { \"remove\": false } }", response);
|
|
|
+ EXPECT_EQ("{ \"result\": 0, \"text\": "
|
|
|
+ "\"Reclamation of expired leases is complete.\" }", response);
|
|
|
+
|
|
|
+ // Leases should be reclaimed, but not removed
|
|
|
+ ASSERT_NO_THROW(lease0 = lease_mgr.getLease4(IOAddress("10.0.0.1")));
|
|
|
+ ASSERT_NO_THROW(lease1 = lease_mgr.getLease4(IOAddress("10.0.0.2")));
|
|
|
+ ASSERT_TRUE(lease0);
|
|
|
+ ASSERT_TRUE(lease1);
|
|
|
+ EXPECT_TRUE(lease0->stateExpiredReclaimed());
|
|
|
+ EXPECT_TRUE(lease1->stateExpiredReclaimed());
|
|
|
+}
|
|
|
+
|
|
|
+// Thist test verifies that the DHCP server immediately removed expired
|
|
|
+// leases on leases-reclaim command with remove = true
|
|
|
+TEST_F(CtrlChannelDhcpv4SrvTest, controlLeasesReclaimRemove) {
|
|
|
+ createUnixChannelServer();
|
|
|
+
|
|
|
+ // Create expired leases. Leases are expired by 40 seconds ago
|
|
|
+ // (valid lifetime = 60, cltt = now - 100).
|
|
|
+ HWAddrPtr hwaddr0(new HWAddr(HWAddr::fromText("00:01:02:03:04:05")));
|
|
|
+ Lease4Ptr lease0(new Lease4(IOAddress("10.0.0.1"), hwaddr0,
|
|
|
+ ClientIdPtr(), 60, 10, 20,
|
|
|
+ time(NULL) - 100, SubnetID(1)));
|
|
|
+ HWAddrPtr hwaddr1(new HWAddr(HWAddr::fromText("01:02:03:04:05:06")));
|
|
|
+ Lease4Ptr lease1(new Lease4(IOAddress("10.0.0.2"), hwaddr1,
|
|
|
+ ClientIdPtr(), 60, 10, 20,
|
|
|
+ time(NULL) - 100, SubnetID(1)));
|
|
|
+
|
|
|
+ // Add leases to the database.
|
|
|
+ LeaseMgr& lease_mgr = LeaseMgrFactory().instance();
|
|
|
+ ASSERT_NO_THROW(lease_mgr.addLease(lease0));
|
|
|
+ ASSERT_NO_THROW(lease_mgr.addLease(lease1));
|
|
|
+
|
|
|
+ // Make sure they have been added.
|
|
|
+ ASSERT_TRUE(lease_mgr.getLease4(IOAddress("10.0.0.1")));
|
|
|
+ ASSERT_TRUE(lease_mgr.getLease4(IOAddress("10.0.0.2")));
|
|
|
+
|
|
|
+ // Send the command
|
|
|
+ std::string response;
|
|
|
+ sendUnixCommand("{ \"command\": \"leases-reclaim\", "
|
|
|
+ "\"arguments\": { \"remove\": true } }", response);
|
|
|
+ EXPECT_EQ("{ \"result\": 0, \"text\": "
|
|
|
+ "\"Reclamation of expired leases is complete.\" }", response);
|
|
|
+
|
|
|
+ // Leases should have been removed.
|
|
|
+ ASSERT_NO_THROW(lease0 = lease_mgr.getLease4(IOAddress("10.0.0.1")));
|
|
|
+ ASSERT_NO_THROW(lease1 = lease_mgr.getLease4(IOAddress("10.0.0.2")));
|
|
|
+ EXPECT_FALSE(lease0);
|
|
|
+ EXPECT_FALSE(lease1);
|
|
|
+}
|
|
|
+
|
|
|
// 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
|
|
@@ -379,5 +487,4 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlChannelStats) {
|
|
|
response);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
} // End of anonymous namespace
|