Commit fe3766ae authored by Thomas Markwalder's avatar Thomas Markwalder

[5247] Corrected issues with assigned-<lease/nas/pd> stats

doc/guide/dhcp4-srv.xml
doc/guide/dhcp6-srv.xml
    Added entries for reclaimed-leases

src/lib/dhcpsrv/alloc_engine.cc

    AllocEngine::reuseExpiredLease(Lease6Ptr&...) - increment
    assigned-<nas/pds> for real allocations

    AllocEngine::extendLease6() - increment assigned-<nas/pds>
    for real allocations if the lease expired

    AllocEngine::renewLease4(const Lease4Ptr&...)
    - set lease state to STATE_DEFAULT for real allocations
    - increment assigned-leases if lease is expired or reclaimed
      for real allocations

    AllocEngine::reuseExpiredLease4(Lease4Ptr&...)
    - increment assigned-leases for real allocations

src/lib/dhcpsrv/cfg_subnets4.cc
    CfgSubnets4::removeStatistics() - added "reclaimed-leases"

src/lib/dhcpsrv/cfg_subnets6.cc
    CfgSubnets4::removeStatistics() - added "reclaimed-leases"

src/lib/dhcpsrv/lease_mgr.cc
    LeaseMgr::recountLeaseStats4()
    LeaseMgr::recountLeaseStats6()
    - added handling of "reclaimed-leases"
    - fixed name of "reclaimed-declined-addresses"

src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc
    TEST_F(AllocEngine4Test, simpleRenew4)  - new test to verify stats
    on a normal renew, non-expired
    Added EXPECT_TRUE around calls to testStatistics for invocation line numbers
    Added stat checks to several tests

src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc
    Added EXPECT_TRUE around calls to testStatistics for invocation line numbers
    Added stat checks to several tests

src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc
    Added checks of assigned stats

src/lib/dhcpsrv/tests/alloc_engine_utils.cc
    AllocEngine6Test::initSubnet() - removed artificial stat values

    NakedAllocEngine::addHost() - new method to add a host to the
    current configuration, rather than use staging/commit as the latter
parent 1aceaf32
......@@ -3614,7 +3614,25 @@ src/lib/dhcpsrv/cfg_host_operations.cc -->
separately. This statistic is reset during reconfiguration event.
</entry>
</row>
<row>
<entry>reclaimed-leases</entry>
<entry>integer</entry>
<entry>This statistic shows the number of expired leases that have
have been reclaimed since server startup. It increases every time an
expired lease undergoes expiration reclamation. This statistic is reset
during reconfiguration event.
</entry>
</row>
<row>
<entry>subnet[id].reclaimed-leases</entry>
<entry>integer</entry>
<entry>This statistic shows the number of expired leases that have
and been reclaimed since server startup. It increases every time an expired
lease undergoes expiration reclamation. The <emphasis>id</emphasis> is
the subnet-id of the subnet. This statistic is exposed for each subnet
separately. This statistic is reset during reconfiguration event.
</entry>
</row>
<row>
<entry>declined-addresses</entry>
<entry>integer</entry>
......
......@@ -3856,6 +3856,29 @@ If not specified, the default value is:
</entry>
</row>
<row>
<entry>reclaimed-leases</entry>
<entry>integer</entry>
<entry>This statistic shows the number of expired leases that have
and been reclaimed since server startup. It increases every time an
expired lease undergoes expiration reclamation. This statistic is reset
during reconfiguration event. Note it counts both NA and PD reclamations.
This statistic is reset during reconfiguration event.
</entry>
</row>
<row>
<entry>subnet[id].reclaimed-leases</entry>
<entry>integer</entry>
<entry>This statistic shows the number of expired leases that have
and been reclaimed since server startup. It increases every time an expired
lease undergoes expiration reclamation. The <emphasis>id</emphasis> is
the subnet-id of the subnet. This statistic is exposed for each subnet
separately. Note it counts both NA and PD reclamations.
This statistic is reset during reconfiguration event.
</entry>
</row>
<row>
<entry>declined-addresses</entry>
<entry>integer</entry>
......
......@@ -1093,6 +1093,16 @@ AllocEngine::reuseExpiredLease(Lease6Ptr& expired, ClientContext6& ctx,
if (!ctx.fake_allocation_) {
// for REQUEST we do update the lease
LeaseMgrFactory::instance().updateLease6(expired);
// If the lease is in the current subnet we need to account
// for the re-assignment of The lease.
if (ctx.subnet_->inPool(ctx.currentIA().type_, expired->addr_)) {
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", ctx.subnet_->getID(),
ctx.currentIA().type_ == Lease::TYPE_NA ?
"assigned-nas" : "assigned-pds"),
static_cast<int64_t>(1));
}
}
// We do nothing for SOLICIT. We'll just update database when
......@@ -1387,6 +1397,15 @@ AllocEngine::extendLease6(ClientContext6& ctx, Lease6Ptr lease) {
if (old_data->expired()) {
reclaimExpiredLease(old_data, ctx.callout_handle_);
// If the lease is in the current subnet we need to account
// for the re-assignment of The lease.
if (ctx.subnet_->inPool(ctx.currentIA().type_, old_data->addr_)) {
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", ctx.subnet_->getID(),
ctx.currentIA().type_ == Lease::TYPE_NA ?
"assigned-nas" : "assigned-pds"),
static_cast<int64_t>(1));
}
} else {
if (!lease->hasIdenticalFqdn(*old_data)) {
// We're not reclaiming the lease but since the FQDN has changed
......@@ -2656,13 +2675,14 @@ AllocEngine::renewLease4(const Lease4Ptr& lease,
// involves execution of hooks and DNS update.
if (ctx.old_lease_->expired()) {
reclaimExpiredLease(ctx.old_lease_, ctx.callout_handle_);
lease->state_ = Lease::STATE_DEFAULT;
} else if (!lease->hasIdenticalFqdn(*ctx.old_lease_)) {
// The lease is not expired but the FQDN information has
// changed. So, we have to remove the previous DNS entry.
queueNCR(CHG_REMOVE, ctx.old_lease_);
}
lease->state_ = Lease::STATE_DEFAULT;
}
bool skip = false;
......@@ -2710,6 +2730,13 @@ AllocEngine::renewLease4(const Lease4Ptr& lease,
if (!ctx.fake_allocation_ && !skip) {
// for REQUEST we do update the lease
LeaseMgrFactory::instance().updateLease4(lease);
// We need to account for the re-assignment of The lease.
if (ctx.old_lease_->expired() || ctx.old_lease_->state_ == Lease::STATE_EXPIRED_RECLAIMED) {
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", ctx.subnet_->getID(), "assigned-addresses"),
static_cast<int64_t>(1));
}
}
if (skip) {
// Rollback changes (really useful only for memfile)
......@@ -2796,6 +2823,11 @@ AllocEngine::reuseExpiredLease4(Lease4Ptr& expired,
if (!ctx.fake_allocation_) {
// for REQUEST we do update the lease
LeaseMgrFactory::instance().updateLease4(expired);
// We need to account for the re-assignment of The lease.
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", ctx.subnet_->getID(), "assigned-addresses"),
static_cast<int64_t>(1));
}
// We do nothing for SOLICIT. We'll just update database when
......
......@@ -250,6 +250,9 @@ CfgSubnets4::removeStatistics() {
stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
"declined-reclaimed-addresses"));
stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
"reclaimed-leases"));
}
}
......
......@@ -201,6 +201,9 @@ CfgSubnets6::removeStatistics() {
stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
"declined-reclaimed-addresses"));
stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
"reclaimed-leases"));
}
}
......
......@@ -62,7 +62,8 @@ LeaseMgr::recountLeaseStats4() {
// Zero out the global stats.
int64_t zero = 0;
stats_mgr.setValue("declined-addresses", zero);
stats_mgr.setValue("declined-reclaimed-addresses", zero);
stats_mgr.setValue("reclaimed-declined-addresses", zero);
stats_mgr.setValue("reclaimed-leases", zero);
// Clear subnet level stats. This ensures we don't end up with corner
// cases that leave stale values in place.
......@@ -79,8 +80,13 @@ LeaseMgr::recountLeaseStats4() {
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
"declined-addresses"),
zero);
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
"reclaimed-declined-addresses"),
zero);
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
"declined-reclaimed-addresses"),
"reclaimed-leases"),
zero);
}
......@@ -133,7 +139,8 @@ LeaseMgr::recountLeaseStats6() {
// clearing it when we clear the rest.
int64_t zero = 0;
stats_mgr.setValue("declined-addresses", zero);
stats_mgr.setValue("declined-reclaimed-addresses", zero);
stats_mgr.setValue("reclaimed-declined-addresses", zero);
stats_mgr.setValue("reclaimed-leases", zero);
// Clear subnet level stats. This ensures we don't end up with corner
// cases that leave stale values in place.
......@@ -153,12 +160,16 @@ LeaseMgr::recountLeaseStats6() {
stats_mgr.setValue(StatsMgr::
generateName("subnet", subnet_id,
"declined-reclaimed-addresses"),
"reclaimed-declined-addresses"),
zero);
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
"assigned-pds"),
zero);
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
"reclaimed-leases"),
zero);
}
// Get counts per state per subnet. Iterate over the result set
......
......@@ -44,7 +44,6 @@ TEST_F(AllocEngine4Test, constructor) {
EXPECT_THROW(x->getAllocator(Lease::TYPE_PD), BadValue);
}
// This test checks if the simple IPv4 allocation can succeed
TEST_F(AllocEngine4Test, simpleAlloc4) {
boost::scoped_ptr<AllocEngine> engine;
......@@ -52,6 +51,9 @@ TEST_F(AllocEngine4Test, simpleAlloc4) {
100, false)));
ASSERT_TRUE(engine);
// Assigned addresses should be zero.
EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
false, true, "somehost.example.com.", false);
ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
......@@ -72,6 +74,9 @@ TEST_F(AllocEngine4Test, simpleAlloc4) {
// Now check that the lease in LeaseMgr has the same parameters
detailCompareLease(lease, from_mgr);
// Assigned addresses should have incremented.
EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()));
}
// This test checks if the fake allocation (for DHCPDISCOVER) can succeed
......@@ -81,6 +86,9 @@ TEST_F(AllocEngine4Test, fakeAlloc4) {
100, false)));
ASSERT_TRUE(engine);
// Assigned addresses should be zero.
EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
IOAddress("0.0.0.0"), false, true,
"host.example.com.", true);
......@@ -100,6 +108,9 @@ TEST_F(AllocEngine4Test, fakeAlloc4) {
// Check that the lease is NOT in LeaseMgr
Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
ASSERT_FALSE(from_mgr);
// Assigned addresses should still be zero.
EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
}
......@@ -267,7 +278,45 @@ TEST_F(AllocEngine4Test, allocateLease4Nulls) {
detailCompareLease(lease, from_mgr);
}
// This test checks if a returning client can renew an
// an existing lease and assigned-leases increments accordingly
TEST_F(AllocEngine4Test, simpleRenew4) {
boost::scoped_ptr<AllocEngine> engine;
ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE,
100, false)));
ASSERT_TRUE(engine);
EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
false, true, "somehost.example.com.", false);
ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
Lease4Ptr lease = engine->allocateLease4(ctx);
// Check that we got a lease and it's sane
ASSERT_TRUE(lease);
checkLease4(lease);
// The new lease has been allocated, so the old lease should not exist.
EXPECT_FALSE(ctx.old_lease_);
// We should have incremented assigned-addresses
EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()));
// Do it again, this should amount to the renew of an existing lease
Lease4Ptr lease2 = engine->allocateLease4(ctx);
// Check that we got a lease and it's sane
ASSERT_TRUE(lease2);
checkLease4(lease2);
// Lease already existsed, so old_lease should be set.
EXPECT_TRUE(ctx.old_lease_);
// Should NOT have bumped assigned-addresses
EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()));
}
// This test verifies that the allocator picks addresses that belong to the
// pool
......@@ -504,14 +553,18 @@ TEST_F(AllocEngine4Test, requestReuseExpiredLease4) {
IOAddress addr("192.0.2.105");
EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
EXPECT_TRUE(testStatistics("reclaimed-leases", 0));
EXPECT_TRUE(testStatistics("reclaimed-leases", 0, subnet_->getID()));
// Just a different hw/client-id for the second client
uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
time_t now = time(NULL) - 500; // Allocated 500 seconds ago
Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2),
sizeof(hwaddr2), 495, 100, 200, now,
subnet_->getID()));
495, 100, 200, now, subnet_->getID()));
// Make a copy of the lease, so as we can compare that with the old lease
// instance returned by the allocation engine.
Lease4 original_lease(*lease);
......@@ -543,6 +596,13 @@ TEST_F(AllocEngine4Test, requestReuseExpiredLease4) {
// lease should be equal to the original lease.
ASSERT_TRUE(ctx.old_lease_);
EXPECT_TRUE(*ctx.old_lease_ == original_lease);
// Check that the stats declined stats were modified correctly. Note, because
// added the lease directly, assigned-leases never bumped to one, so when we
// reclaime it gets decremented to -1, then on assignment back to 0.
EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
EXPECT_TRUE(testStatistics("reclaimed-leases", 1));
EXPECT_TRUE(testStatistics("reclaimed-leases", 1, subnet_->getID()));
}
// This test checks if an expired declined lease can be reused when responding
......@@ -599,35 +659,23 @@ TEST_F(AllocEngine4Test, discoverReuseDeclinedLease4Stats) {
pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
subnet_->addPool(pool_);
cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
cfg_mgr.commit(); // so we will recalc stats
// Now create a declined lease, decline it and rewind its cltt, so it
// is expired.
Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10);
// Let's fix some global stats...
StatsMgr& stats_mgr = StatsMgr::instance();
stats_mgr.setValue("declined-addresses", static_cast<int64_t>(1000));
stats_mgr.setValue("reclaimed-declined-addresses", static_cast<int64_t>(1000));
// ...and subnet specific stats as well.
string stat1 = StatsMgr::generateName("subnet", subnet_->getID(),
"declined-addresses");
string stat2 = StatsMgr::generateName("subnet", subnet_->getID(),
"reclaimed-declined-addresses");
stats_mgr.setValue(stat1, static_cast<int64_t>(1000));
stats_mgr.setValue(stat2, static_cast<int64_t>(1000));
// Ask for any address. There's only one address in the pool, so it doesn't
// matter much.
Lease4Ptr assigned;
testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned);
// Check that the stats were not modified
testStatistics("declined-addresses", 1000);
testStatistics("reclaimed-declined-addresses", 1000);
testStatistics(stat1, 1000);
testStatistics(stat2, 1000);
// Check that the stats declined stats were not modified
EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
EXPECT_TRUE(testStatistics("declined-addresses", 0));
EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 0));
EXPECT_TRUE(testStatistics("declined-addresses", 0, subnet_->getID()));
EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 0, subnet_->getID()));
}
// This test checks if an expired declined lease can be reused when responding
......@@ -682,36 +730,26 @@ TEST_F(AllocEngine4Test, requestReuseDeclinedLease4Stats) {
pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
subnet_->addPool(pool_);
cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
cfg_mgr.commit();
// Now create a declined lease, decline it and rewind its cltt, so it
// is expired.
Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10);
// Let's fix some global stats...
StatsMgr& stats_mgr = StatsMgr::instance();
stats_mgr.setValue("declined-addresses", static_cast<int64_t>(1000));
stats_mgr.setValue("reclaimed-declined-addresses", static_cast<int64_t>(1000));
// ...and subnet specific stats as well.
string stat1 = StatsMgr::generateName("subnet", subnet_->getID(),
"declined-addresses");
string stat2 = StatsMgr::generateName("subnet", subnet_->getID(),
"reclaimed-declined-addresses");
stats_mgr.setValue(stat1, static_cast<int64_t>(1000));
stats_mgr.setValue(stat2, static_cast<int64_t>(1000));
// Asking specifically for this address
Lease4Ptr assigned;
testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned);
// Check that we got it.
ASSERT_TRUE(assigned);
// Check that the stats were modified
testStatistics("declined-addresses", 999);
testStatistics("reclaimed-declined-addresses", 1001);
testStatistics(stat1, 999);
testStatistics(stat2, 1001);
// Check that the stats are correct. Note that assigned-addresses does
// not get decremented when a lease is declined, ergo not incremented
// when it is reused.
EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
EXPECT_TRUE(testStatistics("declined-addresses", -1));
EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 1));
EXPECT_TRUE(testStatistics("declined-addresses", -1, subnet_->getID()));
EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 1, subnet_->getID()));
}
// This test checks that the Allocation Engine correctly identifies the
......
......@@ -77,7 +77,7 @@ TEST_F(AllocEngine6Test, simpleAlloc6) {
string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-nas");
ObservationPtr stat = StatsMgr::instance().getObservation(name);
ASSERT_TRUE(stat);
EXPECT_EQ(101, stat->getInteger().first);
EXPECT_EQ(1, stat->getInteger().first);
}
// This test checks if the simple PD allocation (REQUEST) can succeed
......@@ -90,7 +90,7 @@ TEST_F(AllocEngine6Test, pdSimpleAlloc6) {
string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-pds");
ObservationPtr stat = StatsMgr::instance().getObservation(name);
ASSERT_TRUE(stat);
EXPECT_EQ(101, stat->getInteger().first);
EXPECT_EQ(1, stat->getInteger().first);
}
// This test checks if the fake allocation (for SOLICIT) can succeed
......@@ -103,7 +103,7 @@ TEST_F(AllocEngine6Test, fakeAlloc6) {
string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-nas");
ObservationPtr stat = StatsMgr::instance().getObservation(name);
ASSERT_TRUE(stat);
EXPECT_EQ(100, stat->getInteger().first);
EXPECT_EQ(0, stat->getInteger().first);
}
// This test checks if the fake PD allocation (for SOLICIT) can succeed
......@@ -115,7 +115,7 @@ TEST_F(AllocEngine6Test, pdFakeAlloc6) {
string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-pds");
ObservationPtr stat = StatsMgr::instance().getObservation(name);
ASSERT_TRUE(stat);
EXPECT_EQ(100, stat->getInteger().first);
EXPECT_EQ(0, stat->getInteger().first);
};
// This test checks if the allocation with a hint that is valid (in range,
......@@ -545,6 +545,11 @@ TEST_F(AllocEngine6Test, solicitReuseExpiredLease6) {
// Check that we got that single lease
ASSERT_TRUE(lease);
EXPECT_EQ(addr, lease->addr_);
// Verify the none of relelvant stats were altered.
EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
EXPECT_TRUE(testStatistics("reclaimed-leases", 0));
EXPECT_TRUE(testStatistics("reclaimed-leases", 0, subnet_->getID()));
}
// This test checks if an expired lease can be reused in REQUEST (actual allocation)
......@@ -567,10 +572,12 @@ TEST_F(AllocEngine6Test, requestReuseExpiredLease6) {
// Let's create an expired lease
DuidPtr other_duid = DuidPtr(new DUID(vector<uint8_t>(12, 0xff)));
const uint32_t other_iaid = 3568;
const SubnetID other_subnetid = 999;
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid,
501, 502, 503, 504, other_subnetid, HWAddrPtr(),
0));
lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago
lease->valid_lft_ = 495; // Lease was valid for 495 seconds
lease->fqdn_fwd_ = true;
......@@ -578,10 +585,6 @@ 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_, false, false, "", false,
Pkt6Ptr(new Pkt6(DHCPV6_REQUEST, 1234)));
......@@ -615,12 +618,12 @@ 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);
// Verify the stats got adjusted correctly
EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
EXPECT_TRUE(testStatistics("assigned-nas", -1, other_subnetid));
EXPECT_TRUE(testStatistics("reclaimed-leases", 1));
EXPECT_TRUE(testStatistics("reclaimed-leases", 0, subnet_->getID()));
EXPECT_TRUE(testStatistics("reclaimed-leases", 1, other_subnetid));
}
// Checks if the lease lifetime is extended when the client sends the
......@@ -776,18 +779,15 @@ 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));
// Assigned count should be zero.
EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
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);
// Assigned count should have been incremented by one.
EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
}
// Checks that a client gets the address reserved (in-pool case)
......@@ -807,12 +807,18 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolSolicitValidHint) {
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false);
// Assigned count should be zero.
EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
// Let's pretend the client sends hint 2001:db8:1::10.
Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("2001:db8:1::10"), true);
ASSERT_TRUE(lease);
// The hint should be ignored and the reserved address should be assigned
EXPECT_EQ("2001:db8:1::1c", lease->addr_.toText());
// Assigned count should not have been incremented.
EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
}
// Checks that a client gets the address reserved (in-pool case)
......@@ -832,12 +838,18 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolRequestValidHint) {
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false);
// Assigned count should be zero.
EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
// Let's pretend the client sends hint 2001:db8:1::10.
Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("2001:db8:1::10"), false);
ASSERT_TRUE(lease);
// The hint should be ignored and the reserved address should be assigned
EXPECT_EQ("2001:db8:1::1c", lease->addr_.toText());
// Assigned count should have been incremented.
EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
}
// Checks that a client gets the address reserved (in-pool case)
......@@ -857,12 +869,18 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolSolicitMatchingHint) {
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false);
// Assigned count should be zero.
EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
// Let's pretend the client sends hint 2001:db8:1::10.
Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("2001:db8:1::1c"), true);
ASSERT_TRUE(lease);
// The hint should be ignored and the reserved address should be assigned
EXPECT_EQ("2001:db8:1::1c", lease->addr_.toText());
// Assigned count should not have been incremented.
EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
}
// Checks that a client gets the address reserved (in-pool case)
......@@ -882,12 +900,18 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolRequestMatchingHint) {
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false);
// Assigned count should be zero.
EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
// Let's pretend the client sends hint 2001:db8:1::10.
Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("2001:db8:1::1c"), false);
ASSERT_TRUE(lease);
// The hint should be ignored and the reserved address should be assigned
EXPECT_EQ("2001:db8:1::1c", lease->addr_.toText());
// Assigned count should have been incremented.
EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));