|
@@ -1631,21 +1631,33 @@ TEST_F(Dhcpv4SrvTest, Hooks) {
|
|
|
NakedDhcpv4Srv srv(0);
|
|
|
|
|
|
// check if appropriate hooks are registered
|
|
|
- int hook_index_pkt4_received = -1;
|
|
|
- int hook_index_select_subnet = -1;
|
|
|
- int hook_index_pkt4_send = -1;
|
|
|
+ int hook_index_buffer4_receive = -1;
|
|
|
+ int hook_index_pkt4_receive = -1;
|
|
|
+ int hook_index_select_subnet = -1;
|
|
|
+ int hook_index_lease4_release = -1;
|
|
|
+ int hook_index_pkt4_send = -1;
|
|
|
+ int hook_index_buffer4_send = -1;
|
|
|
|
|
|
// check if appropriate indexes are set
|
|
|
- EXPECT_NO_THROW(hook_index_pkt4_received = ServerHooks::getServerHooks()
|
|
|
+ EXPECT_NO_THROW(hook_index_buffer4_receive = ServerHooks::getServerHooks()
|
|
|
+ .getIndex("buffer4_receive"));
|
|
|
+ EXPECT_NO_THROW(hook_index_pkt4_receive = ServerHooks::getServerHooks()
|
|
|
.getIndex("pkt4_receive"));
|
|
|
EXPECT_NO_THROW(hook_index_select_subnet = ServerHooks::getServerHooks()
|
|
|
.getIndex("subnet4_select"));
|
|
|
- EXPECT_NO_THROW(hook_index_pkt4_send = ServerHooks::getServerHooks()
|
|
|
+ EXPECT_NO_THROW(hook_index_lease4_release = ServerHooks::getServerHooks()
|
|
|
+ .getIndex("lease4_release"));
|
|
|
+ EXPECT_NO_THROW(hook_index_pkt4_send = ServerHooks::getServerHooks()
|
|
|
.getIndex("pkt4_send"));
|
|
|
+ EXPECT_NO_THROW(hook_index_buffer4_send = ServerHooks::getServerHooks()
|
|
|
+ .getIndex("buffer4_send"));
|
|
|
|
|
|
- EXPECT_TRUE(hook_index_pkt4_received > 0);
|
|
|
+ EXPECT_TRUE(hook_index_buffer4_receive > 0);
|
|
|
+ EXPECT_TRUE(hook_index_pkt4_receive > 0);
|
|
|
EXPECT_TRUE(hook_index_select_subnet > 0);
|
|
|
+ EXPECT_TRUE(hook_index_lease4_release > 0);
|
|
|
EXPECT_TRUE(hook_index_pkt4_send > 0);
|
|
|
+ EXPECT_TRUE(hook_index_buffer4_send > 0);
|
|
|
}
|
|
|
|
|
|
// a dummy MAC address
|
|
@@ -1689,9 +1701,13 @@ public:
|
|
|
/// @brief destructor (deletes Dhcpv4Srv)
|
|
|
virtual ~HooksDhcpv4SrvTest() {
|
|
|
|
|
|
+ HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts("buffer4_receive");
|
|
|
+ HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts("buffer4_send");
|
|
|
HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts("pkt4_receive");
|
|
|
HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts("pkt4_send");
|
|
|
HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts("subnet4_select");
|
|
|
+ HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts("lease4_renew");
|
|
|
+ HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts("lease4_release");
|
|
|
|
|
|
delete srv_;
|
|
|
}
|
|
@@ -1766,6 +1782,67 @@ public:
|
|
|
return (Pkt4Ptr(new Pkt4(&buf[0], buf.size())));
|
|
|
}
|
|
|
|
|
|
+ /// Test callback that stores received callout name and pkt4 value
|
|
|
+ /// @param callout_handle handle passed by the hooks framework
|
|
|
+ /// @return always 0
|
|
|
+ static int
|
|
|
+ buffer4_receive_callout(CalloutHandle& callout_handle) {
|
|
|
+ callback_name_ = string("buffer4_receive");
|
|
|
+
|
|
|
+ callout_handle.getArgument("query4", callback_pkt4_);
|
|
|
+
|
|
|
+ callback_argument_names_ = callout_handle.getArgumentNames();
|
|
|
+ return (0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Test callback that changes hwaddr value
|
|
|
+ /// @param callout_handle handle passed by the hooks framework
|
|
|
+ /// @return always 0
|
|
|
+ static int
|
|
|
+ buffer4_receive_change_hwaddr(CalloutHandle& callout_handle) {
|
|
|
+
|
|
|
+ Pkt4Ptr pkt;
|
|
|
+ callout_handle.getArgument("query4", pkt);
|
|
|
+
|
|
|
+ // If there is at least one option with data
|
|
|
+ if (pkt->data_.size() >= Pkt4::DHCPV4_PKT_HDR_LEN) {
|
|
|
+ // Offset of the first byte of the CHWADDR field. Let's the first
|
|
|
+ // byte to some new value that we could later check
|
|
|
+ pkt->data_[28] = 0xff;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Carry on as usual
|
|
|
+ return buffer4_receive_callout(callout_handle);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Test callback that deletes MAC address
|
|
|
+ /// @param callout_handle handle passed by the hooks framework
|
|
|
+ /// @return always 0
|
|
|
+ static int
|
|
|
+ buffer4_receive_delete_hwaddr(CalloutHandle& callout_handle) {
|
|
|
+
|
|
|
+ Pkt4Ptr pkt;
|
|
|
+ callout_handle.getArgument("query4", pkt);
|
|
|
+
|
|
|
+ pkt->data_[2] = 0; // offset 2 is hlen, let's set it to zero
|
|
|
+ memset(&pkt->data_[28], 0, Pkt4::MAX_CHADDR_LEN); // Clear CHADDR content
|
|
|
+
|
|
|
+ // carry on as usual
|
|
|
+ return buffer4_receive_callout(callout_handle);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Test callback that sets skip flag
|
|
|
+ /// @param callout_handle handle passed by the hooks framework
|
|
|
+ /// @return always 0
|
|
|
+ static int
|
|
|
+ buffer4_receive_skip(CalloutHandle& callout_handle) {
|
|
|
+
|
|
|
+ callout_handle.setSkip(true);
|
|
|
+
|
|
|
+ // Carry on as usual
|
|
|
+ return buffer4_receive_callout(callout_handle);
|
|
|
+ }
|
|
|
+
|
|
|
/// test callback that stores received callout name and pkt4 value
|
|
|
/// @param callout_handle handle passed by the hooks framework
|
|
|
/// @return always 0
|
|
@@ -1894,6 +1971,46 @@ public:
|
|
|
return pkt4_send_callout(callout_handle);
|
|
|
}
|
|
|
|
|
|
+ /// Test callback that stores received callout name and pkt4 value
|
|
|
+ /// @param callout_handle handle passed by the hooks framework
|
|
|
+ /// @return always 0
|
|
|
+ static int
|
|
|
+ buffer4_send_callout(CalloutHandle& callout_handle) {
|
|
|
+ callback_name_ = string("buffer4_send");
|
|
|
+
|
|
|
+ callout_handle.getArgument("response4", callback_pkt4_);
|
|
|
+
|
|
|
+ callback_argument_names_ = callout_handle.getArgumentNames();
|
|
|
+ return (0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Test callback changes the output buffer to a hardcoded value
|
|
|
+ /// @param callout_handle handle passed by the hooks framework
|
|
|
+ /// @return always 0
|
|
|
+ static int
|
|
|
+ buffer4_send_change_callout(CalloutHandle& callout_handle) {
|
|
|
+
|
|
|
+ Pkt4Ptr pkt;
|
|
|
+ callout_handle.getArgument("response4", pkt);
|
|
|
+
|
|
|
+ // modify buffer to set a diffferent payload
|
|
|
+ pkt->getBuffer().clear();
|
|
|
+ pkt->getBuffer().writeData(dummyFile, sizeof(dummyFile));
|
|
|
+
|
|
|
+ return (0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Test callback that stores received callout name and pkt4 value
|
|
|
+ /// @param callout_handle handle passed by the hooks framework
|
|
|
+ /// @return always 0
|
|
|
+ static int
|
|
|
+ skip_callout(CalloutHandle& callout_handle) {
|
|
|
+
|
|
|
+ callout_handle.setSkip(true);
|
|
|
+
|
|
|
+ return (0);
|
|
|
+ }
|
|
|
+
|
|
|
/// Test callback that stores received callout name and subnet4 values
|
|
|
/// @param callout_handle handle passed by the hooks framework
|
|
|
/// @return always 0
|
|
@@ -1932,10 +2049,44 @@ public:
|
|
|
return (0);
|
|
|
}
|
|
|
|
|
|
+ /// Test callback that stores received callout name passed parameters
|
|
|
+ /// @param callout_handle handle passed by the hooks framework
|
|
|
+ /// @return always 0
|
|
|
+ static int
|
|
|
+ lease4_release_callout(CalloutHandle& callout_handle) {
|
|
|
+ callback_name_ = string("lease4_release");
|
|
|
+
|
|
|
+ callout_handle.getArgument("query4", callback_pkt4_);
|
|
|
+ callout_handle.getArgument("lease4", callback_lease4_);
|
|
|
+
|
|
|
+ callback_argument_names_ = callout_handle.getArgumentNames();
|
|
|
+ return (0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Test callback that stores received callout name and subnet4 values
|
|
|
+ /// @param callout_handle handle passed by the hooks framework
|
|
|
+ /// @return always 0
|
|
|
+ static int
|
|
|
+ lease4_renew_callout(CalloutHandle& callout_handle) {
|
|
|
+ callback_name_ = string("lease4_renew");
|
|
|
+
|
|
|
+ callout_handle.getArgument("subnet4", callback_subnet4_);
|
|
|
+ callout_handle.getArgument("lease4", callback_lease4_);
|
|
|
+ callout_handle.getArgument("hwaddr", callback_hwaddr_);
|
|
|
+ callout_handle.getArgument("clientid", callback_clientid_);
|
|
|
+
|
|
|
+ callback_argument_names_ = callout_handle.getArgumentNames();
|
|
|
+ return (0);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/// resets buffers used to store data received by callouts
|
|
|
void resetCalloutBuffers() {
|
|
|
callback_name_ = string("");
|
|
|
callback_pkt4_.reset();
|
|
|
+ callback_lease4_.reset();
|
|
|
+ callback_hwaddr_.reset();
|
|
|
+ callback_clientid_.reset();
|
|
|
callback_subnet4_.reset();
|
|
|
callback_subnet4collection_ = NULL;
|
|
|
callback_argument_names_.clear();
|
|
@@ -1952,6 +2103,15 @@ public:
|
|
|
/// Pkt4 structure returned in the callout
|
|
|
static Pkt4Ptr callback_pkt4_;
|
|
|
|
|
|
+ /// Lease4 structure returned in the callout
|
|
|
+ static Lease4Ptr callback_lease4_;
|
|
|
+
|
|
|
+ /// Hardware address returned in the callout
|
|
|
+ static HWAddrPtr callback_hwaddr_;
|
|
|
+
|
|
|
+ /// Client-id returned in the callout
|
|
|
+ static ClientIdPtr callback_clientid_;
|
|
|
+
|
|
|
/// Pointer to a subnet received by callout
|
|
|
static Subnet4Ptr callback_subnet4_;
|
|
|
|
|
@@ -1967,23 +2127,124 @@ public:
|
|
|
string HooksDhcpv4SrvTest::callback_name_;
|
|
|
Pkt4Ptr HooksDhcpv4SrvTest::callback_pkt4_;
|
|
|
Subnet4Ptr HooksDhcpv4SrvTest::callback_subnet4_;
|
|
|
+HWAddrPtr HooksDhcpv4SrvTest::callback_hwaddr_;
|
|
|
+ClientIdPtr HooksDhcpv4SrvTest::callback_clientid_;
|
|
|
+Lease4Ptr HooksDhcpv4SrvTest::callback_lease4_;
|
|
|
const Subnet4Collection* HooksDhcpv4SrvTest::callback_subnet4collection_;
|
|
|
vector<string> HooksDhcpv4SrvTest::callback_argument_names_;
|
|
|
|
|
|
+// Checks if callouts installed on pkt4_receive are indeed called and the
|
|
|
+// all necessary parameters are passed.
|
|
|
+//
|
|
|
+// Note that the test name does not follow test naming convention,
|
|
|
+// but the proper hook name is "buffer4_receive".
|
|
|
+TEST_F(HooksDhcpv4SrvTest, Buffer4ReceiveSimple) {
|
|
|
+
|
|
|
+ // Install pkt6_receive_callout
|
|
|
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
+ "buffer4_receive", buffer4_receive_callout));
|
|
|
+
|
|
|
+ // Let's create a simple DISCOVER
|
|
|
+ Pkt4Ptr dis = generateSimpleDiscover();
|
|
|
+
|
|
|
+ // Simulate that we have received that traffic
|
|
|
+ srv_->fakeReceive(dis);
|
|
|
+
|
|
|
+ // Server will now process to run its normal loop, but instead of calling
|
|
|
+ // IfaceMgr::receive4(), it will read all packets from the list set by
|
|
|
+ // fakeReceive()
|
|
|
+ // In particular, it should call registered buffer4_receive callback.
|
|
|
+ srv_->run();
|
|
|
+
|
|
|
+ // Check that the callback called is indeed the one we installed
|
|
|
+ EXPECT_EQ("buffer4_receive", callback_name_);
|
|
|
+
|
|
|
+ // Check that pkt4 argument passing was successful and returned proper value
|
|
|
+ EXPECT_TRUE(callback_pkt4_.get() == dis.get());
|
|
|
|
|
|
-// Checks if callouts installed on pkt4_received are indeed called and the
|
|
|
+ // Check that all expected parameters are there
|
|
|
+ vector<string> expected_argument_names;
|
|
|
+ expected_argument_names.push_back(string("query4"));
|
|
|
+
|
|
|
+ EXPECT_TRUE(expected_argument_names == callback_argument_names_);
|
|
|
+}
|
|
|
+
|
|
|
+// Checks if callouts installed on buffer4_receive is able to change
|
|
|
+// the values and the parameters are indeed used by the server.
|
|
|
+TEST_F(HooksDhcpv4SrvTest, buffer4RreceiveValueChange) {
|
|
|
+
|
|
|
+ // Install callback that modifies MAC addr of incoming packet
|
|
|
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
+ "buffer4_receive", buffer4_receive_change_hwaddr));
|
|
|
+
|
|
|
+ // Let's create a simple DISCOVER
|
|
|
+ Pkt4Ptr discover = generateSimpleDiscover();
|
|
|
+
|
|
|
+ // Simulate that we have received that traffic
|
|
|
+ srv_->fakeReceive(discover);
|
|
|
+
|
|
|
+ // Server will now process to run its normal loop, but instead of calling
|
|
|
+ // IfaceMgr::receive6(), it will read all packets from the list set by
|
|
|
+ // fakeReceive()
|
|
|
+ // In particular, it should call registered buffer4_receive callback.
|
|
|
+ srv_->run();
|
|
|
+
|
|
|
+ // Check that the server did send a reposonce
|
|
|
+ ASSERT_EQ(1, srv_->fake_sent_.size());
|
|
|
+
|
|
|
+ // Make sure that we received a response
|
|
|
+ Pkt4Ptr offer = srv_->fake_sent_.front();
|
|
|
+ ASSERT_TRUE(offer);
|
|
|
+
|
|
|
+ // Get client-id...
|
|
|
+ HWAddrPtr hwaddr = offer->getHWAddr();
|
|
|
+
|
|
|
+ ASSERT_TRUE(hwaddr); // basic sanity check. HWAddr is always present
|
|
|
+
|
|
|
+ // ... and check if it is the modified value
|
|
|
+ ASSERT_FALSE(hwaddr->hwaddr_.empty()); // there must be a MAC address
|
|
|
+ EXPECT_EQ(0xff, hwaddr->hwaddr_[0]); // check that its first byte was modified
|
|
|
+}
|
|
|
+
|
|
|
+// Checks if callouts installed on buffer4_receive is able to set skip flag that
|
|
|
+// will cause the server to not parse the packet. Even though the packet is valid,
|
|
|
+// the server should eventually drop it, because there won't be mandatory options
|
|
|
+// (or rather option objects) in it.
|
|
|
+TEST_F(HooksDhcpv4SrvTest, buffer4ReceiveSkip) {
|
|
|
+
|
|
|
+ // Install pkt6_receive_callout
|
|
|
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
+ "buffer4_receive", buffer4_receive_skip));
|
|
|
+
|
|
|
+ // Let's create a simple DISCOVER
|
|
|
+ Pkt4Ptr discover = generateSimpleDiscover();
|
|
|
+
|
|
|
+ // Simulate that we have received that traffic
|
|
|
+ srv_->fakeReceive(discover);
|
|
|
+
|
|
|
+ // Server will now process to run its normal loop, but instead of calling
|
|
|
+ // IfaceMgr::receive6(), it will read all packets from the list set by
|
|
|
+ // fakeReceive()
|
|
|
+ // In particular, it should call registered pkt6_receive callback.
|
|
|
+ srv_->run();
|
|
|
+
|
|
|
+ // Check that the server dropped the packet and did not produce any response
|
|
|
+ ASSERT_EQ(0, srv_->fake_sent_.size());
|
|
|
+}
|
|
|
+
|
|
|
+// Checks if callouts installed on pkt4_receive are indeed called and the
|
|
|
// all necessary parameters are passed.
|
|
|
//
|
|
|
// Note that the test name does not follow test naming convention,
|
|
|
// but the proper hook name is "pkt4_receive".
|
|
|
-TEST_F(HooksDhcpv4SrvTest, simple_pkt4_receive) {
|
|
|
+TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveSimple) {
|
|
|
|
|
|
// Install pkt4_receive_callout
|
|
|
EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
"pkt4_receive", pkt4_receive_callout));
|
|
|
|
|
|
// Let's create a simple DISCOVER
|
|
|
- Pkt4Ptr sol = Pkt4Ptr(generateSimpleDiscover());
|
|
|
+ Pkt4Ptr sol = generateSimpleDiscover();
|
|
|
|
|
|
// Simulate that we have received that traffic
|
|
|
srv_->fakeReceive(sol);
|
|
@@ -2016,7 +2277,7 @@ TEST_F(HooksDhcpv4SrvTest, valueChange_pkt4_receive) {
|
|
|
"pkt4_receive", pkt4_receive_change_clientid));
|
|
|
|
|
|
// Let's create a simple DISCOVER
|
|
|
- Pkt4Ptr sol = Pkt4Ptr(generateSimpleDiscover());
|
|
|
+ Pkt4Ptr sol = generateSimpleDiscover();
|
|
|
|
|
|
// Simulate that we have received that traffic
|
|
|
srv_->fakeReceive(sol);
|
|
@@ -2045,14 +2306,14 @@ TEST_F(HooksDhcpv4SrvTest, valueChange_pkt4_receive) {
|
|
|
// Checks if callouts installed on pkt4_received is able to delete
|
|
|
// existing options and that change impacts server processing (mandatory
|
|
|
// client-id option is deleted, so the packet is expected to be dropped)
|
|
|
-TEST_F(HooksDhcpv4SrvTest, deleteClientId_pkt4_receive) {
|
|
|
+TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveDeleteClientId) {
|
|
|
|
|
|
// Install pkt4_receive_callout
|
|
|
EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
"pkt4_receive", pkt4_receive_delete_clientid));
|
|
|
|
|
|
// Let's create a simple DISCOVER
|
|
|
- Pkt4Ptr sol = Pkt4Ptr(generateSimpleDiscover());
|
|
|
+ Pkt4Ptr sol = generateSimpleDiscover();
|
|
|
|
|
|
// Simulate that we have received that traffic
|
|
|
srv_->fakeReceive(sol);
|
|
@@ -2069,14 +2330,14 @@ TEST_F(HooksDhcpv4SrvTest, deleteClientId_pkt4_receive) {
|
|
|
|
|
|
// Checks if callouts installed on pkt4_received is able to set skip flag that
|
|
|
// will cause the server to not process the packet (drop), even though it is valid.
|
|
|
-TEST_F(HooksDhcpv4SrvTest, skip_pkt4_receive) {
|
|
|
+TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveSkip) {
|
|
|
|
|
|
// Install pkt4_receive_callout
|
|
|
EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
"pkt4_receive", pkt4_receive_skip));
|
|
|
|
|
|
// Let's create a simple DISCOVER
|
|
|
- Pkt4Ptr sol = Pkt4Ptr(generateSimpleDiscover());
|
|
|
+ Pkt4Ptr sol = generateSimpleDiscover();
|
|
|
|
|
|
// Simulate that we have received that traffic
|
|
|
srv_->fakeReceive(sol);
|
|
@@ -2094,14 +2355,14 @@ TEST_F(HooksDhcpv4SrvTest, skip_pkt4_receive) {
|
|
|
|
|
|
// Checks if callouts installed on pkt4_send are indeed called and the
|
|
|
// all necessary parameters are passed.
|
|
|
-TEST_F(HooksDhcpv4SrvTest, simple_pkt4_send) {
|
|
|
+TEST_F(HooksDhcpv4SrvTest, pkt4SendSimple) {
|
|
|
|
|
|
// Install pkt4_receive_callout
|
|
|
EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
"pkt4_send", pkt4_send_callout));
|
|
|
|
|
|
// Let's create a simple DISCOVER
|
|
|
- Pkt4Ptr sol = Pkt4Ptr(generateSimpleDiscover());
|
|
|
+ Pkt4Ptr sol = generateSimpleDiscover();
|
|
|
|
|
|
// Simulate that we have received that traffic
|
|
|
srv_->fakeReceive(sol);
|
|
@@ -2130,14 +2391,14 @@ TEST_F(HooksDhcpv4SrvTest, simple_pkt4_send) {
|
|
|
|
|
|
// Checks if callouts installed on pkt4_send is able to change
|
|
|
// the values and the packet sent contains those changes
|
|
|
-TEST_F(HooksDhcpv4SrvTest, valueChange_pkt4_send) {
|
|
|
+TEST_F(HooksDhcpv4SrvTest, pkt4SendValueChange) {
|
|
|
|
|
|
// Install pkt4_receive_callout
|
|
|
EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
"pkt4_send", pkt4_send_change_serverid));
|
|
|
|
|
|
// Let's create a simple DISCOVER
|
|
|
- Pkt4Ptr sol = Pkt4Ptr(generateSimpleDiscover());
|
|
|
+ Pkt4Ptr sol = generateSimpleDiscover();
|
|
|
|
|
|
// Simulate that we have received that traffic
|
|
|
srv_->fakeReceive(sol);
|
|
@@ -2167,14 +2428,14 @@ TEST_F(HooksDhcpv4SrvTest, valueChange_pkt4_send) {
|
|
|
// existing options and that server applies those changes. In particular,
|
|
|
// we are trying to send a packet without server-id. The packet should
|
|
|
// be sent
|
|
|
-TEST_F(HooksDhcpv4SrvTest, deleteServerId_pkt4_send) {
|
|
|
+TEST_F(HooksDhcpv4SrvTest, pkt4SendDeleteServerId) {
|
|
|
|
|
|
// Install pkt4_receive_callout
|
|
|
EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
"pkt4_send", pkt4_send_delete_serverid));
|
|
|
|
|
|
// Let's create a simple DISCOVER
|
|
|
- Pkt4Ptr sol = Pkt4Ptr(generateSimpleDiscover());
|
|
|
+ Pkt4Ptr sol = generateSimpleDiscover();
|
|
|
|
|
|
// Simulate that we have received that traffic
|
|
|
srv_->fakeReceive(sol);
|
|
@@ -2205,7 +2466,7 @@ TEST_F(HooksDhcpv4SrvTest, skip_pkt4_send) {
|
|
|
"pkt4_send", pkt4_send_skip));
|
|
|
|
|
|
// Let's create a simple REQUEST
|
|
|
- Pkt4Ptr sol = Pkt4Ptr(generateSimpleDiscover());
|
|
|
+ Pkt4Ptr sol = generateSimpleDiscover();
|
|
|
|
|
|
// Simulate that we have received that traffic
|
|
|
srv_->fakeReceive(sol);
|
|
@@ -2213,16 +2474,111 @@ TEST_F(HooksDhcpv4SrvTest, skip_pkt4_send) {
|
|
|
// Server will now process to run its normal loop, but instead of calling
|
|
|
// IfaceMgr::receive4(), it will read all packets from the list set by
|
|
|
// fakeReceive()
|
|
|
+ // In particular, it should call registered pkt4_send callback.
|
|
|
+ srv_->run();
|
|
|
+
|
|
|
+ // Check that the server sent the message
|
|
|
+ ASSERT_EQ(1, srv_->fake_sent_.size());
|
|
|
+
|
|
|
+ // Get the first packet and check that it has zero length (i.e. the server
|
|
|
+ // did not do packing on its own)
|
|
|
+ Pkt4Ptr sent = srv_->fake_sent_.front();
|
|
|
+ EXPECT_EQ(0, sent->getBuffer().getLength());
|
|
|
+}
|
|
|
+
|
|
|
+// Checks if callouts installed on buffer4_send are indeed called and the
|
|
|
+// all necessary parameters are passed.
|
|
|
+TEST_F(HooksDhcpv4SrvTest, buffer4SendSimple) {
|
|
|
+
|
|
|
+ // Install pkt4_receive_callout
|
|
|
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
+ "buffer4_send", buffer4_send_callout));
|
|
|
+
|
|
|
+ // Let's create a simple DISCOVER
|
|
|
+ Pkt4Ptr discover = generateSimpleDiscover();
|
|
|
+
|
|
|
+ // Simulate that we have received that traffic
|
|
|
+ srv_->fakeReceive(discover);
|
|
|
+
|
|
|
+ // Server will now process to run its normal loop, but instead of calling
|
|
|
+ // IfaceMgr::receive4(), it will read all packets from the list set by
|
|
|
+ // fakeReceive()
|
|
|
// In particular, it should call registered pkt4_receive callback.
|
|
|
srv_->run();
|
|
|
|
|
|
- // check that the server dropped the packet and did not produce any response
|
|
|
+ // Check that the callback called is indeed the one we installed
|
|
|
+ EXPECT_EQ("buffer4_send", callback_name_);
|
|
|
+
|
|
|
+ // Check that there is one packet sent
|
|
|
+ ASSERT_EQ(1, srv_->fake_sent_.size());
|
|
|
+ Pkt4Ptr adv = srv_->fake_sent_.front();
|
|
|
+
|
|
|
+ // Check that pkt4 argument passing was successful and returned proper value
|
|
|
+ EXPECT_TRUE(callback_pkt4_.get() == adv.get());
|
|
|
+
|
|
|
+ // Check that all expected parameters are there
|
|
|
+ vector<string> expected_argument_names;
|
|
|
+ expected_argument_names.push_back(string("response4"));
|
|
|
+ EXPECT_TRUE(expected_argument_names == callback_argument_names_);
|
|
|
+}
|
|
|
+
|
|
|
+// Checks if callouts installed on buffer4_send are indeed called and that
|
|
|
+// the output buffer can be changed.
|
|
|
+TEST_F(HooksDhcpv4SrvTest, buffer4Send) {
|
|
|
+
|
|
|
+ // Install pkt4_receive_callout
|
|
|
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
+ "buffer4_send", buffer4_send_change_callout));
|
|
|
+
|
|
|
+ // Let's create a simple DISCOVER
|
|
|
+ Pkt4Ptr discover = generateSimpleDiscover();
|
|
|
+
|
|
|
+ // Simulate that we have received that traffic
|
|
|
+ srv_->fakeReceive(discover);
|
|
|
+
|
|
|
+ // Server will now process to run its normal loop, but instead of calling
|
|
|
+ // IfaceMgr::receive4(), it will read all packets from the list set by
|
|
|
+ // fakeReceive()
|
|
|
+ // In particular, it should call registered pkt4_receive callback.
|
|
|
+ srv_->run();
|
|
|
+
|
|
|
+ // Check that there is one packet sent
|
|
|
+ ASSERT_EQ(1, srv_->fake_sent_.size());
|
|
|
+ Pkt4Ptr adv = srv_->fake_sent_.front();
|
|
|
+
|
|
|
+ // The callout is supposed to fill the output buffer with dummyFile content
|
|
|
+ ASSERT_EQ(sizeof(dummyFile), adv->getBuffer().getLength());
|
|
|
+ EXPECT_EQ(0, memcmp(adv->getBuffer().getData(), dummyFile, sizeof(dummyFile)));
|
|
|
+}
|
|
|
+
|
|
|
+// Checks if callouts installed on buffer4_send can set skip flag and that flag
|
|
|
+// causes the packet to not be sent
|
|
|
+TEST_F(HooksDhcpv4SrvTest, buffer4SendSkip) {
|
|
|
+
|
|
|
+ // Install pkt4_receive_callout
|
|
|
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
+ "buffer4_send", skip_callout));
|
|
|
+
|
|
|
+ // Let's create a simple DISCOVER
|
|
|
+ Pkt4Ptr discover = generateSimpleDiscover();
|
|
|
+
|
|
|
+ // Simulate that we have received that traffic
|
|
|
+ srv_->fakeReceive(discover);
|
|
|
+
|
|
|
+ // Server will now process to run its normal loop, but instead of calling
|
|
|
+ // IfaceMgr::receive4(), it will read all packets from the list set by
|
|
|
+ // fakeReceive()
|
|
|
+ // In particular, it should call registered pkt4_receive callback.
|
|
|
+ srv_->run();
|
|
|
+
|
|
|
+ // Check that there is no packet sent.
|
|
|
ASSERT_EQ(0, srv_->fake_sent_.size());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// This test checks if subnet4_select callout is triggered and reports
|
|
|
// valid parameters
|
|
|
-TEST_F(HooksDhcpv4SrvTest, subnet4_select) {
|
|
|
+TEST_F(HooksDhcpv4SrvTest, subnet4SelectSimple) {
|
|
|
|
|
|
// Install pkt4_receive_callout
|
|
|
EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
@@ -2288,9 +2644,9 @@ TEST_F(HooksDhcpv4SrvTest, subnet4_select) {
|
|
|
|
|
|
// This test checks if callout installed on subnet4_select hook point can pick
|
|
|
// a different subnet.
|
|
|
-TEST_F(HooksDhcpv4SrvTest, subnet_select_change) {
|
|
|
+TEST_F(HooksDhcpv4SrvTest, subnet4SelectChange) {
|
|
|
|
|
|
- // Install pkt4_receive_callout
|
|
|
+ // Install a callout
|
|
|
EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
"subnet4_select", subnet4_select_different_subnet_callout));
|
|
|
|
|
@@ -2345,6 +2701,303 @@ TEST_F(HooksDhcpv4SrvTest, subnet_select_change) {
|
|
|
EXPECT_TRUE((*subnets)[1]->inPool(addr));
|
|
|
}
|
|
|
|
|
|
+// This test verifies that incoming (positive) REQUEST/Renewing can be handled
|
|
|
+// properly and that callout installed on lease4_renew is triggered with
|
|
|
+// expected parameters.
|
|
|
+TEST_F(HooksDhcpv4SrvTest, lease4RenewSimple) {
|
|
|
|
|
|
+ const IOAddress addr("192.0.2.106");
|
|
|
+ const uint32_t temp_t1 = 50;
|
|
|
+ const uint32_t temp_t2 = 75;
|
|
|
+ const uint32_t temp_valid = 100;
|
|
|
+ const time_t temp_timestamp = time(NULL) - 10;
|
|
|
+
|
|
|
+ // Install a callout
|
|
|
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
+ "lease4_renew", lease4_renew_callout));
|
|
|
+
|
|
|
+ // Generate client-id also sets client_id_ member
|
|
|
+ OptionPtr clientid = generateClientId();
|
|
|
+
|
|
|
+ // Check that the address we are about to use is indeed in pool
|
|
|
+ ASSERT_TRUE(subnet_->inPool(addr));
|
|
|
+
|
|
|
+ // let's create a lease and put it in the LeaseMgr
|
|
|
+ uint8_t hwaddr2[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
|
|
|
+ Lease4Ptr used(new Lease4(IOAddress("192.0.2.106"), hwaddr2, sizeof(hwaddr2),
|
|
|
+ &client_id_->getDuid()[0], client_id_->getDuid().size(),
|
|
|
+ temp_valid, temp_t1, temp_t2, temp_timestamp,
|
|
|
+ subnet_->getID()));
|
|
|
+ ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
|
|
|
+
|
|
|
+ // Check that the lease is really in the database
|
|
|
+ Lease4Ptr l = LeaseMgrFactory::instance().getLease4(addr);
|
|
|
+ ASSERT_TRUE(l);
|
|
|
+
|
|
|
+ // Let's create a RENEW
|
|
|
+ Pkt4Ptr req = Pkt4Ptr(new Pkt4(DHCPREQUEST, 1234));
|
|
|
+ req->setRemoteAddr(IOAddress(addr));
|
|
|
+ req->setYiaddr(addr);
|
|
|
+ req->setCiaddr(addr); // client's address
|
|
|
+
|
|
|
+ req->addOption(clientid);
|
|
|
+ req->addOption(srv_->getServerID());
|
|
|
+
|
|
|
+ // Pass it to the server and hope for a REPLY
|
|
|
+ Pkt4Ptr ack = srv_->processRequest(req);
|
|
|
+
|
|
|
+ // Check if we get response at all
|
|
|
+ checkResponse(ack, DHCPACK, 1234);
|
|
|
+
|
|
|
+ // Check that the lease is really in the database
|
|
|
+ l = checkLease(ack, clientid, req->getHWAddr(), addr);
|
|
|
+ ASSERT_TRUE(l);
|
|
|
+
|
|
|
+ // Check that T1, T2, preferred, valid and cltt were really updated
|
|
|
+ EXPECT_EQ(l->t1_, subnet_->getT1());
|
|
|
+ EXPECT_EQ(l->t2_, subnet_->getT2());
|
|
|
+ EXPECT_EQ(l->valid_lft_, subnet_->getValid());
|
|
|
+
|
|
|
+ // Check that the callback called is indeed the one we installed
|
|
|
+ EXPECT_EQ("lease4_renew", callback_name_);
|
|
|
+
|
|
|
+ // Check that hwaddr parameter is passed properly
|
|
|
+ ASSERT_TRUE(callback_hwaddr_);
|
|
|
+ EXPECT_TRUE(*callback_hwaddr_ == *req->getHWAddr());
|
|
|
+
|
|
|
+ // Check that the subnet is passed properly
|
|
|
+ ASSERT_TRUE(callback_subnet4_);
|
|
|
+ EXPECT_EQ(callback_subnet4_->toText(), subnet_->toText());
|
|
|
+
|
|
|
+ ASSERT_TRUE(callback_clientid_);
|
|
|
+ ASSERT_TRUE(client_id_);
|
|
|
+ EXPECT_TRUE(*client_id_ == *callback_clientid_);
|
|
|
+
|
|
|
+ // Check if all expected parameters were really received
|
|
|
+ vector<string> expected_argument_names;
|
|
|
+ expected_argument_names.push_back("subnet4");
|
|
|
+ expected_argument_names.push_back("clientid");
|
|
|
+ expected_argument_names.push_back("hwaddr");
|
|
|
+ expected_argument_names.push_back("lease4");
|
|
|
+ sort(callback_argument_names_.begin(), callback_argument_names_.end());
|
|
|
+ sort(expected_argument_names.begin(), expected_argument_names.end());
|
|
|
+ EXPECT_TRUE(callback_argument_names_ == expected_argument_names);
|
|
|
+
|
|
|
+ EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr));
|
|
|
+}
|
|
|
+
|
|
|
+// This test verifies that a callout installed on lease4_renew can trigger
|
|
|
+// the server to not renew a lease.
|
|
|
+TEST_F(HooksDhcpv4SrvTest, lease4RenewSkip) {
|
|
|
+
|
|
|
+ const IOAddress addr("192.0.2.106");
|
|
|
+ const uint32_t temp_t1 = 50;
|
|
|
+ const uint32_t temp_t2 = 75;
|
|
|
+ const uint32_t temp_valid = 100;
|
|
|
+ const time_t temp_timestamp = time(NULL) - 10;
|
|
|
+
|
|
|
+ // Install a callout
|
|
|
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
+ "lease4_renew", skip_callout));
|
|
|
+
|
|
|
+ // Generate client-id also sets client_id_ member
|
|
|
+ OptionPtr clientid = generateClientId();
|
|
|
+
|
|
|
+ // Check that the address we are about to use is indeed in pool
|
|
|
+ ASSERT_TRUE(subnet_->inPool(addr));
|
|
|
+
|
|
|
+ // let's create a lease and put it in the LeaseMgr
|
|
|
+ uint8_t hwaddr2[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
|
|
|
+ Lease4Ptr used(new Lease4(IOAddress("192.0.2.106"), hwaddr2, sizeof(hwaddr2),
|
|
|
+ &client_id_->getDuid()[0], client_id_->getDuid().size(),
|
|
|
+ temp_valid, temp_t1, temp_t2, temp_timestamp,
|
|
|
+ subnet_->getID()));
|
|
|
+ ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
|
|
|
+
|
|
|
+ // Check that the lease is really in the database
|
|
|
+ Lease4Ptr l = LeaseMgrFactory::instance().getLease4(addr);
|
|
|
+ ASSERT_TRUE(l);
|
|
|
+
|
|
|
+ // Check that T1, T2, preferred, valid and cltt really set.
|
|
|
+ // Constructed lease looks as if it was assigned 10 seconds ago
|
|
|
+ // EXPECT_EQ(l->t1_, temp_t1);
|
|
|
+ // EXPECT_EQ(l->t2_, temp_t2);
|
|
|
+ EXPECT_EQ(l->valid_lft_, temp_valid);
|
|
|
+ EXPECT_EQ(l->cltt_, temp_timestamp);
|
|
|
+
|
|
|
+ // Let's create a RENEW
|
|
|
+ Pkt4Ptr req = Pkt4Ptr(new Pkt4(DHCPREQUEST, 1234));
|
|
|
+ req->setRemoteAddr(IOAddress(addr));
|
|
|
+ req->setYiaddr(addr);
|
|
|
+ req->setCiaddr(addr); // client's address
|
|
|
+
|
|
|
+ req->addOption(clientid);
|
|
|
+ req->addOption(srv_->getServerID());
|
|
|
+
|
|
|
+ // Pass it to the server and hope for a REPLY
|
|
|
+ Pkt4Ptr ack = srv_->processRequest(req);
|
|
|
+ ASSERT_TRUE(ack);
|
|
|
+
|
|
|
+ // Check that the lease is really in the database
|
|
|
+ l = checkLease(ack, clientid, req->getHWAddr(), addr);
|
|
|
+ ASSERT_TRUE(l);
|
|
|
+
|
|
|
+ // Check that T1, T2, valid and cltt were NOT updated
|
|
|
+ EXPECT_EQ(temp_t1, l->t1_);
|
|
|
+ EXPECT_EQ(temp_t2, l->t2_);
|
|
|
+ EXPECT_EQ(temp_valid, l->valid_lft_);
|
|
|
+ EXPECT_EQ(temp_timestamp, l->cltt_);
|
|
|
+
|
|
|
+ EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr));
|
|
|
+}
|
|
|
+
|
|
|
+// This test verifies that valid RELEASE triggers lease4_release callouts
|
|
|
+TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSimple) {
|
|
|
+
|
|
|
+ const IOAddress addr("192.0.2.106");
|
|
|
+ const uint32_t temp_t1 = 50;
|
|
|
+ const uint32_t temp_t2 = 75;
|
|
|
+ const uint32_t temp_valid = 100;
|
|
|
+ const time_t temp_timestamp = time(NULL) - 10;
|
|
|
+
|
|
|
+ // Install a callout
|
|
|
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
+ "lease4_release", lease4_release_callout));
|
|
|
+
|
|
|
+ // Generate client-id also duid_
|
|
|
+ OptionPtr clientid = generateClientId();
|
|
|
+
|
|
|
+ // Check that the address we are about to use is indeed in pool
|
|
|
+ ASSERT_TRUE(subnet_->inPool(addr));
|
|
|
+
|
|
|
+ // Let's create a lease and put it in the LeaseMgr
|
|
|
+ uint8_t mac_addr[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
|
|
|
+ HWAddrPtr hw(new HWAddr(mac_addr, sizeof(mac_addr), HTYPE_ETHER));
|
|
|
+ Lease4Ptr used(new Lease4(addr, mac_addr, sizeof(mac_addr),
|
|
|
+ &client_id_->getDuid()[0], client_id_->getDuid().size(),
|
|
|
+ temp_valid, temp_t1, temp_t2, temp_timestamp,
|
|
|
+ subnet_->getID()));
|
|
|
+ ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
|
|
|
+
|
|
|
+ // Check that the lease is really in the database
|
|
|
+ Lease4Ptr l = LeaseMgrFactory::instance().getLease4(addr);
|
|
|
+ ASSERT_TRUE(l);
|
|
|
+
|
|
|
+ // Let's create a RELEASE
|
|
|
+ // Generate client-id also duid_
|
|
|
+ Pkt4Ptr rel = Pkt4Ptr(new Pkt4(DHCPRELEASE, 1234));
|
|
|
+ rel->setRemoteAddr(addr);
|
|
|
+ rel->setYiaddr(addr);
|
|
|
+ rel->addOption(clientid);
|
|
|
+ rel->addOption(srv_->getServerID());
|
|
|
+ rel->setHWAddr(hw);
|
|
|
+
|
|
|
+ // Pass it to the server and hope for a REPLY
|
|
|
+ // Note: this is no response to RELEASE in DHCPv4
|
|
|
+ EXPECT_NO_THROW(srv_->processRelease(rel));
|
|
|
+
|
|
|
+ // The lease should be gone from LeaseMgr
|
|
|
+ l = LeaseMgrFactory::instance().getLease4(addr);
|
|
|
+ EXPECT_FALSE(l);
|
|
|
+
|
|
|
+ // Try to get the lease by hardware address
|
|
|
+ // @todo: Uncomment this once trac2592 is implemented
|
|
|
+ // Lease4Collection leases = LeaseMgrFactory::instance().getLease4(hw->hwaddr_);
|
|
|
+ // EXPECT_EQ(leases.size(), 0);
|
|
|
+
|
|
|
+ // Try to get it by hw/subnet_id combination
|
|
|
+ l = LeaseMgrFactory::instance().getLease4(hw->hwaddr_, subnet_->getID());
|
|
|
+ EXPECT_FALSE(l);
|
|
|
+
|
|
|
+ // Try by client-id
|
|
|
+ // @todo: Uncomment this once trac2592 is implemented
|
|
|
+ //Lease4Collection leases = LeaseMgrFactory::instance().getLease4(*client_id_);
|
|
|
+ //EXPECT_EQ(leases.size(), 0);
|
|
|
+
|
|
|
+ // Try by client-id/subnet-id
|
|
|
+ l = LeaseMgrFactory::instance().getLease4(*client_id_, subnet_->getID());
|
|
|
+ EXPECT_FALSE(l);
|
|
|
+
|
|
|
+ // Ok, the lease is *really* not there.
|
|
|
+
|
|
|
+ // Check that the callback called is indeed the one we installed
|
|
|
+ EXPECT_EQ("lease4_release", callback_name_);
|
|
|
+
|
|
|
+ // Check that pkt4 argument passing was successful and returned proper value
|
|
|
+ EXPECT_TRUE(callback_pkt4_.get() == rel.get());
|
|
|
+
|
|
|
+ // Check if all expected parameters were really received
|
|
|
+ vector<string> expected_argument_names;
|
|
|
+ expected_argument_names.push_back("query4");
|
|
|
+ expected_argument_names.push_back("lease4");
|
|
|
+ sort(callback_argument_names_.begin(), callback_argument_names_.end());
|
|
|
+ sort(expected_argument_names.begin(), expected_argument_names.end());
|
|
|
+ EXPECT_TRUE(callback_argument_names_ == expected_argument_names);
|
|
|
+}
|
|
|
+
|
|
|
+// This test verifies that skip flag returned by a callout installed on the
|
|
|
+// lease4_release hook point will keep the lease
|
|
|
+TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSkip) {
|
|
|
+
|
|
|
+ const IOAddress addr("192.0.2.106");
|
|
|
+ const uint32_t temp_t1 = 50;
|
|
|
+ const uint32_t temp_t2 = 75;
|
|
|
+ const uint32_t temp_valid = 100;
|
|
|
+ const time_t temp_timestamp = time(NULL) - 10;
|
|
|
+
|
|
|
+ // Install a callout
|
|
|
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
+ "lease4_release", skip_callout));
|
|
|
+
|
|
|
+ // Generate client-id also duid_
|
|
|
+ OptionPtr clientid = generateClientId();
|
|
|
+
|
|
|
+ // Check that the address we are about to use is indeed in pool
|
|
|
+ ASSERT_TRUE(subnet_->inPool(addr));
|
|
|
+
|
|
|
+ // Let's create a lease and put it in the LeaseMgr
|
|
|
+ uint8_t mac_addr[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
|
|
|
+ HWAddrPtr hw(new HWAddr(mac_addr, sizeof(mac_addr), HTYPE_ETHER));
|
|
|
+ Lease4Ptr used(new Lease4(addr, mac_addr, sizeof(mac_addr),
|
|
|
+ &client_id_->getDuid()[0], client_id_->getDuid().size(),
|
|
|
+ temp_valid, temp_t1, temp_t2, temp_timestamp,
|
|
|
+ subnet_->getID()));
|
|
|
+ ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
|
|
|
+
|
|
|
+ // Check that the lease is really in the database
|
|
|
+ Lease4Ptr l = LeaseMgrFactory::instance().getLease4(addr);
|
|
|
+ ASSERT_TRUE(l);
|
|
|
+
|
|
|
+ // Let's create a RELEASE
|
|
|
+ // Generate client-id also duid_
|
|
|
+ Pkt4Ptr rel = Pkt4Ptr(new Pkt4(DHCPRELEASE, 1234));
|
|
|
+ rel->setRemoteAddr(addr);
|
|
|
+ rel->setYiaddr(addr);
|
|
|
+ rel->addOption(clientid);
|
|
|
+ rel->addOption(srv_->getServerID());
|
|
|
+ rel->setHWAddr(hw);
|
|
|
+
|
|
|
+ // Pass it to the server and hope for a REPLY
|
|
|
+ // Note: this is no response to RELEASE in DHCPv4
|
|
|
+ EXPECT_NO_THROW(srv_->processRelease(rel));
|
|
|
+
|
|
|
+ // The lease should be still there
|
|
|
+ l = LeaseMgrFactory::instance().getLease4(addr);
|
|
|
+ EXPECT_TRUE(l);
|
|
|
+
|
|
|
+ // Try by client-id/subnet-id
|
|
|
+ l = LeaseMgrFactory::instance().getLease4(*client_id_, subnet_->getID());
|
|
|
+ EXPECT_TRUE(l);
|
|
|
+
|
|
|
+ // Try to get the lease by hardware address
|
|
|
+ // @todo: Uncomment this once trac2592 is implemented
|
|
|
+ // Lease4Collection leases = LeaseMgrFactory::instance().getLease4(hw->hwaddr_);
|
|
|
+ // EXPECT_EQ(leases.size(), 1);
|
|
|
+
|
|
|
+ // Try by client-id
|
|
|
+ // @todo: Uncomment this once trac2592 is implemented
|
|
|
+ //Lease4Collection leases = LeaseMgrFactory::instance().getLease4(*client_id_);
|
|
|
+ //EXPECT_EQ(leases.size(), 1);
|
|
|
+}
|
|
|
|
|
|
} // end of anonymous namespace
|