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;
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));
// 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
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);
// 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()));
}
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
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);
// 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
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
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
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
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
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
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,
// 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)
// 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;
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)));
// 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
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)
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)
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)
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)
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()));
}
// Checks that a client gets the address reserved (out-of-pool case)
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false);
+ // Assigned count should be zero.
+ EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
+
Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("::"), true, false);
ASSERT_TRUE(lease);
EXPECT_EQ("2001:db8::abcd", 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 (out-of-pool case)
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, 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);
+ EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
}
// Checks that a client gets the address reserved (in-pool case)
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, false);
ASSERT_TRUE(lease);
// The hint should be ignored and the reserved address should be assigned
EXPECT_EQ("2001:db8::abcd", lease->addr_.toText());
+
+ // We should not have bumped the address counter
+ EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
}
// Checks that a client gets the address reserved (out-of-pool case)
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, false);
ASSERT_TRUE(lease);
// The hint should be ignored and the reserved address should be assigned
EXPECT_EQ("2001:db8::abcd", lease->addr_.toText());
+
+ // We should not have bumped the address counter
+ EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
}
// Checks that a client gets the address reserved (out-of-pool case)
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, false);
ASSERT_TRUE(lease);
// The hint should be ignored and the reserved address should be assigned
EXPECT_EQ("2001:db8::abcd", lease->addr_.toText());
+
+ // We should not have bumped the address counter
+ EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
}
// Checks that a client gets the address reserved (out-of-pool case)
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, false);
ASSERT_TRUE(lease);
// The hint should be ignored and the reserved address should be assigned
EXPECT_EQ("2001:db8::abcd", lease->addr_.toText());
+
+ // We should not have bumped the address counter
+ EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
}
// In the following situation:
TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedThis) {
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false);
+ // Assigned count should be zero.
+ EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
+
// 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);
+ EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
// Just check that if the client requests again, it will get the same
// address.
detailCompareLease(lease1, lease2);
// We should not have bumped the address counter again
- EXPECT_EQ(101, stat->getInteger().first);
+ EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
// 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.
// 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
+ // Lastly check to see that the address counter is still 1, we should have
// have decremented it on the implied release and incremented it on the reserved
- EXPECT_EQ(101, stat->getInteger().first);
+ EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
}
// In the following situation:
// - client X is assigned an address A
TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedOther) {
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false);
+ // Assigned count should be zero.
+ EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
+
// 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);
+ EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
// Just check that if the client requests again, it will get the same
// address.
detailCompareLease(lease1, lease2);
// We should not have bumped the address counter again
- EXPECT_EQ(101, stat->getInteger().first);
+ EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
// 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
host->setIdentifier(&other_duid[0], other_duid.size(), Host::IDENT_DUID);
// Ok, now add it to the HostMgr
- CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
- CfgMgr::instance().commit();
+ addHost(host);
// Just check that this time the client will get a different lease.
Lease6Ptr lease3 = simpleAlloc6Test(pool_, lease1->addr_, false);
// 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
+ // Lastly check to see that the address counter is still 1 we should have
// have decremented it on the implied release and incremented it on the reserved
- EXPECT_EQ(101, stat->getInteger().first);
+ EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
}
// Checks that a reserved address for client A is not assigned when
TEST_F(AllocEngine6Test, addressRenewal) {
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100);
+ // Assigned count should zero.
+ EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
+
Lease6Collection leases;
leases = allocateTest(engine, pool_, IOAddress("::"), false, true);
ASSERT_EQ(1, leases.size());
+ // Assigned count should be one.
+ EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
+
// This is what the client will send in his renew message.
AllocEngine::HintContainer hints;
hints.push_back(make_pair(leases[0]->addr_, 128));
EXPECT_EQ(leases[0]->type_, renewed[0]->type_);
EXPECT_EQ(leases[0]->preferred_lft_, renewed[0]->preferred_lft_);
EXPECT_EQ(leases[0]->valid_lft_, renewed[0]->valid_lft_);
+
+ // Assigned count should still be one.
+ EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
}
// Checks whether an address can be renewed (in-pool reservation)
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100);
+ // Assigned count should zero.
+ EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
+
Lease6Collection leases;
leases = allocateTest(engine, pool_, IOAddress("::"), false, true);
ASSERT_EQ(1, leases.size());
ASSERT_EQ("2001:db8:1::1c", leases[0]->addr_.toText());
+ // Assigned count should be one.
+ EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
+
// This is what the client will send in his renew message.
AllocEngine::HintContainer hints;
hints.push_back(make_pair(leases[0]->addr_, 128));
Lease6Collection renewed = renewTest(engine, pool_, hints, true);
ASSERT_EQ(1, renewed.size());
ASSERT_EQ("2001:db8:1::1c", leases[0]->addr_.toText());
+
+ // Assigned count should still be one.
+ EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
}
// Checks whether a single host can have more than one reservation.
// is expired.
Lease6Ptr declined = generateDeclinedLease(addr_txt, 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.
Lease6Ptr assigned;
testReuseLease6(engine, declined, "::", 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);
+ EXPECT_TRUE(testStatistics("assigned-nas", 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 statistics are not updated when expired declined lease
// is expired.
Lease6Ptr declined = generateDeclinedLease(addr_txt, 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.
Lease6Ptr assigned;
testReuseLease6(engine, declined, "::", false, SHOULD_PASS, assigned);
- // Check that the stats were not modified
- testStatistics("declined-addresses", 999);
- testStatistics("reclaimed-declined-addresses", 1001);
+ // Check that the stats were modified as expected.
+ EXPECT_TRUE(testStatistics("assigned-nas", 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()));
- testStatistics(stat1, 999);
- testStatistics(stat2, 1001);
}
}; // namespace test