|
@@ -53,59 +53,51 @@ 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) {
|
|
|
|
|
|
- // Pretend our pool has allocated 100 addresses
|
|
|
- string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs");
|
|
|
- StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
|
|
|
-
|
|
|
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) {
|
|
|
|
|
|
- // Pretend our pool has allocated 100 prefixes
|
|
|
- string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-PDs");
|
|
|
- StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
|
|
|
-
|
|
|
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) {
|
|
|
|
|
|
- // Pretend our pool has allocated 100 prefixes
|
|
|
- string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs");
|
|
|
- StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
|
|
|
-
|
|
|
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) {
|
|
|
- // Pretend our pool has allocated 100 prefixes
|
|
|
- string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-PDs");
|
|
|
- StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
|
|
|
-
|
|
|
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);
|
|
@@ -566,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);
|
|
@@ -596,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 ---
|
|
@@ -639,9 +642,9 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolRequestNoHint) {
|
|
|
|
|
|
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false);
|
|
|
|
|
|
- // Pretend our pool has allocated 100 addresses
|
|
|
+ // By default we pretend our subnet has 100 addresses
|
|
|
string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs");
|
|
|
- StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
|
|
|
+ StatsMgr::instance().setValue(name, static_cast<int64_t>(100));
|
|
|
|
|
|
Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("::"), false);
|
|
|
ASSERT_TRUE(lease);
|
|
@@ -757,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.
|
|
|
//
|
|
@@ -773,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.
|
|
|
//
|
|
@@ -792,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)
|
|
@@ -822,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.
|
|
|
//
|
|
@@ -847,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.
|
|
|
//
|
|
@@ -872,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.
|
|
|
//
|
|
@@ -903,18 +916,16 @@ 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);
|
|
|
|
|
|
- // Pretend our pool has allocated 100 addresses
|
|
|
- string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs");
|
|
|
- StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
|
|
|
-
|
|
|
// Client gets an address
|
|
|
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);
|
|
@@ -959,9 +970,7 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedThis) {
|
|
|
// 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
|
|
@@ -975,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.
|
|
@@ -1014,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
|
|
@@ -1430,30 +1452,6 @@ TEST_F(AllocEngine6Test, reservedAddressByMacInPoolRequestValidHint) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-// This test checks that NULL values are handled properly
|
|
|
-TEST_F(AllocEngine6Test, allocateAddress6Stats) {
|
|
|
- boost::scoped_ptr<AllocEngine> engine;
|
|
|
- ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 100)));
|
|
|
- ASSERT_TRUE(engine);
|
|
|
-
|
|
|
- // Verify our pool hasn't allocated any addresses
|
|
|
- string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs");
|
|
|
- StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
|
|
|
-
|
|
|
- Lease6Ptr lease;
|
|
|
- AllocEngine::ClientContext6 ctx1(subnet_, duid_, iaid_, IOAddress("::"),
|
|
|
- Lease::TYPE_NA, false, false, "", false);
|
|
|
- ctx1.query_.reset(new Pkt6(DHCPV6_REQUEST, 1234));
|
|
|
- EXPECT_NO_THROW(lease = expectOneLease(engine->allocateLeases6(ctx1)));
|
|
|
- ASSERT_TRUE(lease);
|
|
|
-
|
|
|
- // We should have bumped the address counter by 1
|
|
|
- ObservationPtr stat = StatsMgr::instance().getObservation(name);
|
|
|
- ASSERT_TRUE(stat);
|
|
|
- EXPECT_EQ(101, stat->getInteger().first);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
}; // namespace test
|
|
|
}; // namespace dhcp
|
|
|
}; // namespace isc
|