|
@@ -17,10 +17,12 @@
|
|
|
#include <dhcp/pkt6.h>
|
|
|
#include <dhcpsrv/tests/alloc_engine_utils.h>
|
|
|
#include <dhcpsrv/tests/test_utils.h>
|
|
|
+#include <stats/stats_mgr.h>
|
|
|
|
|
|
using namespace std;
|
|
|
using namespace isc::hooks;
|
|
|
using namespace isc::asiolink;
|
|
|
+using namespace isc::stats;
|
|
|
|
|
|
namespace isc {
|
|
|
namespace dhcp {
|
|
@@ -51,24 +53,54 @@ TEST_F(AllocEngine6Test, constructor) {
|
|
|
}
|
|
|
|
|
|
// This test checks if the simple allocation (REQUEST) can succeed
|
|
|
+// and the stats counter is properly bumped by 1
|
|
|
TEST_F(AllocEngine6Test, simpleAlloc6) {
|
|
|
+
|
|
|
simpleAlloc6Test(pool_, IOAddress("::"), false);
|
|
|
+
|
|
|
+ // We should have bumped the address counter by 1
|
|
|
+ string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-nas");
|
|
|
+ ObservationPtr stat = StatsMgr::instance().getObservation(name);
|
|
|
+ ASSERT_TRUE(stat);
|
|
|
+ EXPECT_EQ(101, stat->getInteger().first);
|
|
|
}
|
|
|
|
|
|
// This test checks if the simple PD allocation (REQUEST) can succeed
|
|
|
+// and the stats counter is properly bumped by 1
|
|
|
TEST_F(AllocEngine6Test, pdSimpleAlloc6) {
|
|
|
+
|
|
|
simpleAlloc6Test(pd_pool_, IOAddress("::"), false);
|
|
|
+
|
|
|
+ // We should have bumped the address counter by 1
|
|
|
+ string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-pds");
|
|
|
+ ObservationPtr stat = StatsMgr::instance().getObservation(name);
|
|
|
+ ASSERT_TRUE(stat);
|
|
|
+ EXPECT_EQ(101, stat->getInteger().first);
|
|
|
}
|
|
|
|
|
|
// This test checks if the fake allocation (for SOLICIT) can succeed
|
|
|
+// and the stats counter isn't bumped
|
|
|
TEST_F(AllocEngine6Test, fakeAlloc6) {
|
|
|
|
|
|
simpleAlloc6Test(pool_, IOAddress("::"), true);
|
|
|
+
|
|
|
+ // We should not have bumped the address counter
|
|
|
+ string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-nas");
|
|
|
+ ObservationPtr stat = StatsMgr::instance().getObservation(name);
|
|
|
+ ASSERT_TRUE(stat);
|
|
|
+ EXPECT_EQ(100, stat->getInteger().first);
|
|
|
}
|
|
|
|
|
|
// This test checks if the fake PD allocation (for SOLICIT) can succeed
|
|
|
+// and the stats counter isn't bumped
|
|
|
TEST_F(AllocEngine6Test, pdFakeAlloc6) {
|
|
|
simpleAlloc6Test(pd_pool_, IOAddress("::"), true);
|
|
|
+
|
|
|
+ // We should not have bumped the address counter
|
|
|
+ string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-pds");
|
|
|
+ ObservationPtr stat = StatsMgr::instance().getObservation(name);
|
|
|
+ ASSERT_TRUE(stat);
|
|
|
+ EXPECT_EQ(100, stat->getInteger().first);
|
|
|
};
|
|
|
|
|
|
// This test checks if the allocation with a hint that is valid (in range,
|
|
@@ -526,6 +558,10 @@ TEST_F(AllocEngine6Test, requestReuseExpiredLease6) {
|
|
|
lease->hostname_ = "myhost.example.com.";
|
|
|
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
|
|
|
|
|
|
+ // By default we pretend our subnet has 100 addresses
|
|
|
+ string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-nas");
|
|
|
+ StatsMgr::instance().setValue(name, static_cast<int64_t>(100));
|
|
|
+
|
|
|
// A client comes along, asking specifically for this address
|
|
|
AllocEngine::ClientContext6 ctx(subnet_, duid_, iaid_, addr, Lease::TYPE_NA,
|
|
|
false, false, "", false);
|
|
@@ -556,6 +592,13 @@ TEST_F(AllocEngine6Test, requestReuseExpiredLease6) {
|
|
|
|
|
|
// Now check that the lease in LeaseMgr has the same parameters
|
|
|
detailCompareLease(lease, from_mgr);
|
|
|
+
|
|
|
+ // We should not have bumped the address counter
|
|
|
+ // NOTE: when we start expiring addresses and removing them from
|
|
|
+ // the stats this will no longer be true.
|
|
|
+ ObservationPtr stat = StatsMgr::instance().getObservation(name);
|
|
|
+ ASSERT_TRUE(stat);
|
|
|
+ EXPECT_EQ(100, stat->getInteger().first);
|
|
|
}
|
|
|
|
|
|
// --- v6 host reservation ---
|
|
@@ -568,7 +611,7 @@ TEST_F(AllocEngine6Test, requestReuseExpiredLease6) {
|
|
|
// - Client sends SOLICIT without any hints.
|
|
|
// - Client is allocated a reserved address.
|
|
|
//
|
|
|
-// Note that DHCPv6 client can, but don't have to send any hints in its
|
|
|
+// Note that a DHCPv6 client can, but doesn't have to send any hints in its
|
|
|
// Solicit message.
|
|
|
TEST_F(AllocEngine6Test, reservedAddressInPoolSolicitNoHint) {
|
|
|
// Create reservation for the client. This is in-pool reservation,
|
|
@@ -599,9 +642,18 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolRequestNoHint) {
|
|
|
|
|
|
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false);
|
|
|
|
|
|
+ // By default we pretend our subnet has 100 addresses
|
|
|
+ string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-nas");
|
|
|
+ StatsMgr::instance().setValue(name, static_cast<int64_t>(100));
|
|
|
+
|
|
|
Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("::"), false);
|
|
|
ASSERT_TRUE(lease);
|
|
|
EXPECT_EQ("2001:db8:1::1c", lease->addr_.toText());
|
|
|
+
|
|
|
+ // We should have bumped the address counter
|
|
|
+ ObservationPtr stat = StatsMgr::instance().getObservation(name);
|
|
|
+ ASSERT_TRUE(stat);
|
|
|
+ EXPECT_EQ(101, stat->getInteger().first);
|
|
|
}
|
|
|
|
|
|
// Checks that a client gets the address reserved (in-pool case)
|
|
@@ -708,7 +760,7 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolRequestMatchingHint) {
|
|
|
// This test checks the behavior of the allocation engine in the following
|
|
|
// scenario:
|
|
|
// - Client has no lease in the database.
|
|
|
-// - Client has an in-pool reservation.
|
|
|
+// - Client has an out-of-pool reservation.
|
|
|
// - Client sends SOLICIT without any hints.
|
|
|
// - Client is allocated a reserved address.
|
|
|
//
|
|
@@ -724,13 +776,14 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolSolicitNoHint) {
|
|
|
Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("::"), true, false);
|
|
|
ASSERT_TRUE(lease);
|
|
|
EXPECT_EQ("2001:db8::abcd", lease->addr_.toText());
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-// Checks that a client gets the address reserved (in-pool case)
|
|
|
+// Checks that a client gets the address reserved (out-of-pool case)
|
|
|
// This test checks the behavior of the allocation engine in the following
|
|
|
// scenario:
|
|
|
// - Client has no lease in the database.
|
|
|
-// - Client has an in-pool reservation.
|
|
|
+// - Client has an out-of-pool reservation.
|
|
|
// - Client sends REQUEST without any hints.
|
|
|
// - Client is allocated a reserved address.
|
|
|
//
|
|
@@ -743,9 +796,18 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolRequestNoHint) {
|
|
|
|
|
|
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false);
|
|
|
|
|
|
+ // By default we pretend our subnet has 100 addresses
|
|
|
+ string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-nas");
|
|
|
+ StatsMgr::instance().setValue(name, static_cast<int64_t>(100));
|
|
|
+
|
|
|
Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("::"), false, false);
|
|
|
ASSERT_TRUE(lease);
|
|
|
EXPECT_EQ("2001:db8::abcd", lease->addr_.toText());
|
|
|
+
|
|
|
+ // We should not have bumped the address counter
|
|
|
+ ObservationPtr stat = StatsMgr::instance().getObservation(name);
|
|
|
+ ASSERT_TRUE(stat);
|
|
|
+ EXPECT_EQ(100, stat->getInteger().first);
|
|
|
}
|
|
|
|
|
|
// Checks that a client gets the address reserved (in-pool case)
|
|
@@ -773,11 +835,11 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolSolicitValidHint) {
|
|
|
EXPECT_EQ("2001:db8::abcd", lease->addr_.toText());
|
|
|
}
|
|
|
|
|
|
-// Checks that a client gets the address reserved (in-pool case)
|
|
|
+// Checks that a client gets the address reserved (out-of-pool case)
|
|
|
// This test checks the behavior of the allocation engine in the following
|
|
|
// scenario:
|
|
|
// - Client has no lease in the database.
|
|
|
-// - Client has an in-pool reservation.
|
|
|
+// - Client has an out-of-pool reservation.
|
|
|
// - Client sends REQUEST with a hint that does not match reservation
|
|
|
// - Client is allocated a reserved address, not the hint.
|
|
|
//
|
|
@@ -798,11 +860,11 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolRequestValidHint) {
|
|
|
EXPECT_EQ("2001:db8::abcd", lease->addr_.toText());
|
|
|
}
|
|
|
|
|
|
-// Checks that a client gets the address reserved (in-pool case)
|
|
|
+// Checks that a client gets the address reserved (out-of-pool case)
|
|
|
// This test checks the behavior of the allocation engine in the following
|
|
|
// scenario:
|
|
|
// - Client has no lease in the database.
|
|
|
-// - Client has an in-pool reservation.
|
|
|
+// - Client has an out-of-pool reservation.
|
|
|
// - Client sends SOLICIT with a hint that does matches reservation
|
|
|
// - Client is allocated a reserved address, not the hint.
|
|
|
//
|
|
@@ -823,11 +885,11 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolSolicitMatchingHint) {
|
|
|
EXPECT_EQ("2001:db8::abcd", lease->addr_.toText());
|
|
|
}
|
|
|
|
|
|
-// Checks that a client gets the address reserved (in-pool case)
|
|
|
+// Checks that a client gets the address reserved (out-of-pool case)
|
|
|
// This test checks the behavior of the allocation engine in the following
|
|
|
// scenario:
|
|
|
// - Client has no lease in the database.
|
|
|
-// - Client has an in-pool reservation.
|
|
|
+// - Client has an out-of-pool reservation.
|
|
|
// - Client sends REQUEST with a hint that does not match reservation
|
|
|
// - Client is allocated a reserved address, not the hint.
|
|
|
//
|
|
@@ -854,6 +916,7 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolRequestMatchingHint) {
|
|
|
// - client tries to get address A:
|
|
|
// Check that his existing lease for lease A is removed
|
|
|
// Check that he is assigned a new lease for B
|
|
|
+// - verify that the number of assigned address behaves as expected
|
|
|
TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedThis) {
|
|
|
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false);
|
|
|
|
|
@@ -861,12 +924,21 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedThis) {
|
|
|
Lease6Ptr lease1 = simpleAlloc6Test(pool_, IOAddress("::"), false);
|
|
|
ASSERT_TRUE(lease1);
|
|
|
|
|
|
+ // We should have bumped the address counter
|
|
|
+ string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-nas");
|
|
|
+ ObservationPtr stat = StatsMgr::instance().getObservation(name);
|
|
|
+ ASSERT_TRUE(stat);
|
|
|
+ EXPECT_EQ(101, stat->getInteger().first);
|
|
|
+
|
|
|
// Just check that if the client requests again, it will get the same
|
|
|
// address.
|
|
|
Lease6Ptr lease2 = simpleAlloc6Test(pool_, lease1->addr_, false);
|
|
|
ASSERT_TRUE(lease2);
|
|
|
detailCompareLease(lease1, lease2);
|
|
|
|
|
|
+ // We should not have bumped the address counter again
|
|
|
+ EXPECT_EQ(101, stat->getInteger().first);
|
|
|
+
|
|
|
// Now admin creates a reservation for this client. This is in-pool
|
|
|
// reservation, as the pool is 2001:db8:1::10 - 2001:db8:1::20.
|
|
|
createHost6(true, IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::1c"), 128);
|
|
@@ -894,8 +966,11 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedThis) {
|
|
|
|
|
|
// Now check that the lease in LeaseMgr has the same parameters
|
|
|
detailCompareLease(lease3, from_mgr);
|
|
|
-}
|
|
|
|
|
|
+ // Lastly check to see that the address counter is still 101 we should have
|
|
|
+ // have decremented it on the implied release and incremented it on the reserved
|
|
|
+ EXPECT_EQ(101, stat->getInteger().first);
|
|
|
+}
|
|
|
// In the following situation:
|
|
|
// - client X is assigned an address A
|
|
|
// - HR is made for client Y (*other* client) to get A
|
|
@@ -909,12 +984,21 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedOther) {
|
|
|
Lease6Ptr lease1 = simpleAlloc6Test(pool_, IOAddress("::"), false);
|
|
|
ASSERT_TRUE(lease1);
|
|
|
|
|
|
+ // We should have bumped the address counter
|
|
|
+ string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-nas");
|
|
|
+ ObservationPtr stat = StatsMgr::instance().getObservation(name);
|
|
|
+ ASSERT_TRUE(stat);
|
|
|
+ EXPECT_EQ(101, stat->getInteger().first);
|
|
|
+
|
|
|
// Just check that if the client requests again, it will get the same
|
|
|
// address.
|
|
|
Lease6Ptr lease2 = simpleAlloc6Test(pool_, lease1->addr_, false);
|
|
|
ASSERT_TRUE(lease2);
|
|
|
detailCompareLease(lease1, lease2);
|
|
|
|
|
|
+ // We should not have bumped the address counter again
|
|
|
+ EXPECT_EQ(101, stat->getInteger().first);
|
|
|
+
|
|
|
// Now admin creates a reservation for this client. Let's use the
|
|
|
// address client X just received. Let's generate a host, but don't add it
|
|
|
// to the HostMgr yet.
|
|
@@ -948,6 +1032,10 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedOther) {
|
|
|
|
|
|
// Now check that the lease in LeaseMgr has the same parameters
|
|
|
detailCompareLease(lease3, from_mgr);
|
|
|
+
|
|
|
+ // Lastly check to see that the address counter is still 101 we should have
|
|
|
+ // have decremented it on the implied release and incremented it on the reserved
|
|
|
+ EXPECT_EQ(101, stat->getInteger().first);
|
|
|
}
|
|
|
|
|
|
// Checks that a reserved address for client A is not assigned when
|
|
@@ -1363,6 +1451,7 @@ TEST_F(AllocEngine6Test, reservedAddressByMacInPoolRequestValidHint) {
|
|
|
EXPECT_EQ("2001:db8:1::1c", lease->addr_.toText());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}; // namespace test
|
|
|
}; // namespace dhcp
|
|
|
}; // namespace isc
|