EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.100");
}
+ // This test checks that the client requesting an address which is
+ // reserved for another client will get no lease or a different
+ // address will be assigned if the client is sending a DHCPDISCOVER.
+ TEST_F(AllocEngine4Test, reservedAddressHintUsedByOtherClient) {
+ // Create a reservation for the client.
+ HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(),
+ Host::IDENT_HWADDR, subnet_->getID(),
+ SubnetID(0), IOAddress("192.0.2.100")));
+ CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
+ CfgMgr::instance().commit();
+
+ AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false);
+
+ // Different client is requesting this address.
+ Lease4Ptr allocated_lease = engine.allocateLease4(subnet_, ClientIdPtr(),
+ hwaddr_,
+ IOAddress("192.0.2.100"),
+ false, false, "", false,
+ CalloutHandlePtr(),
+ old_lease_);
+ // The client should get no lease (DHCPNAK).
+ ASSERT_FALSE(allocated_lease);
+
+ // The same client should get a different lease than requested if
+ // if is sending a DHCPDISCOVER (fake allocation is true).
+ allocated_lease = engine.allocateLease4(subnet_, ClientIdPtr(),
+ hwaddr_,
+ IOAddress("192.0.2.100"),
+ false, false, "", true,
+ CalloutHandlePtr(),
+ old_lease_);
+ ASSERT_TRUE(allocated_lease);
+ // Make sure the lease obtained is for a different address.
+ EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.100");
+ }
+
+// This test checks that the allocation engine refuses to allocate an
+// address when the pool is exhausted, and the only one available
+// address is reserved for a different client.
+TEST_F(AllocEngine4Test, reservedAddressShortPool) {
+ AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false);
+
+ // Create short pool with only one address.
+ initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100"));
+ // Reserve the address for a different client.
+ HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(),
+ Host::IDENT_HWADDR, subnet_->getID(),
+ SubnetID(0), IOAddress("192.0.2.100")));
+ CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
+ CfgMgr::instance().commit();
+
+ // Allocation engine should determine that the available address is
+ // reserved for someone else and not allocate it.
+ Lease4Ptr allocated_lease = engine.allocateLease4(subnet_, ClientIdPtr(),
+ hwaddr_,
+ IOAddress("0.0.0.0"),
+ false, false, "", false,
+ CalloutHandlePtr(),
+ old_lease_);
+ EXPECT_FALSE(allocated_lease);
+
+ // Now, let's remove the reservation.
+ initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100"));
+ CfgMgr::instance().commit();
+
+ // Address should be successfully allocated.
+ allocated_lease = engine.allocateLease4(subnet_, ClientIdPtr(), hwaddr_,
+ IOAddress("0.0.0.0"), false, false,
+ "", false, CalloutHandlePtr(),
+ old_lease_);
+ ASSERT_TRUE(allocated_lease);
+ EXPECT_EQ("192.0.2.100", allocated_lease->addr_.toText());
+}
+
/// @brief helper class used in Hooks testing in AllocEngine6
///
/// It features a couple of callout functions and buffers to store