2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-01 22:45:18 +00:00

[3799] Add more tests

Update the documents a bit

Fix up handling reservations from outside the subnet

Add more tests
This commit is contained in:
Shawn Routhier
2015-06-17 20:55:15 -07:00
parent 715cf52676
commit f4963266a4
7 changed files with 138 additions and 91 deletions

View File

@@ -2608,13 +2608,14 @@ should include options from the isc option space:
<entry>subnet[id].total-NAs</entry> <entry>subnet[id].total-NAs</entry>
<entry>integer</entry> <entry>integer</entry>
<entry> <entry>
This statistic shows the total number of NA addresses available for the This statistic shows the total number of NA addresses available for
DHCPv6 management. In other words, this is the sum of all addresses in DHCPv6 management for a given subnet. In other words, this is the sum
all configured pools. This statistic changes only during configuration of all addresses in all configured pools. This statistic changes only
changes. Note it does not take into account any addresses that may be during configuration changes. Note it does not take into account any
reserved due to host reservation. The <emphasis>id</emphasis> is the addresses that may be reserved due to host reservation. The
subnet-id of a given subnet. This statistic is exposed for each subnet <emphasis>id</emphasis> is the subnet-id of a given subnet. This
separately. This statistic is reset during reconfiguration event. statistic is exposed for each subnet separately. This statistic is
reset during a reconfiguration event.
</entry> </entry>
</row> </row>
@@ -2622,14 +2623,14 @@ should include options from the isc option space:
<entry>subnet[id].assigned-NAs</entry> <entry>subnet[id].assigned-NAs</entry>
<entry>integer</entry> <entry>integer</entry>
<entry> <entry>
This statistic shows the number of assigned NA addresses in a given subnet. This statistic shows the number of NA addresses in a given subnet that
This statistic increases every time a new lease is allocated (as a result are assigned. This statistic increases every time a new lease is allocated
of receiving a REQUEST message) and is decreased every time a lease is (as a result of receiving a REQUEST message) and is decreased every time a
released (a RELEASE message is received). When lease expiration lease is released (a RELEASE message is received). When lease expiration
is implemented (planned for Kea 1.0), it will also decrease when a lease is implemented (planned for Kea 1.0), it will also decrease when a lease
is expired. The <emphasis>id</emphasis> is the subnet-id of a given is expired. The <emphasis>id</emphasis> is the subnet-id of a given
subnet. This statistic is exposed for each subnet separately. This subnet. This statistic is exposed for each subnet separately. This
statistic is reset during reconfiguration event. statistic is reset during a reconfiguration event.
</entry> </entry>
</row> </row>
@@ -2637,13 +2638,14 @@ should include options from the isc option space:
<entry>subnet[id].total-PDs</entry> <entry>subnet[id].total-PDs</entry>
<entry>integer</entry> <entry>integer</entry>
<entry> <entry>
This statistic shows the total number of PD prefixes available for the This statistic shows the total number of PD prefixes available for
DHCPv6 management. In other words, this is the sum of all prefixes in DHCPv6 management for a given subnet. In other words, this is the sum
all configured pools. This statistic changes only during configuration of all prefixes in all configured pools. This statistic changes only
changes. Note it does not take into account any prefixes that may be during configuration changes. Note it does not take into account any
reserved due to host reservation. The <emphasis>id</emphasis> is the prefixes that may be reserved due to host reservation. The
subnet-id of a given subnet. This statistic is exposed for each subnet <emphasis>id</emphasis> is the subnet-id of a given subnet. This
separately. This statistic is reset during reconfiguration event. statistic is exposed for each subnet separately. This statistic is
reset during a reconfiguration event.
</entry> </entry>
</row> </row>
@@ -2651,14 +2653,14 @@ should include options from the isc option space:
<entry>subnet[id].assigned-PDs</entry> <entry>subnet[id].assigned-PDs</entry>
<entry>integer</entry> <entry>integer</entry>
<entry> <entry>
This statistic shows the number of assigned PD prefixes in a given subnet. This statistic shows the number of PD prefixes in a given subnet that
This statistic increases every time a new lease is allocated (as a result are assigned. This statistic increases every time a new lease is allocated
of receiving a REQUEST message) and is decreased every time a lease is (as a result of receiving a REQUEST message) and is decreased every time a
released (a RELEASE message is received). When lease expiration lease is released (a RELEASE message is received). When lease expiration
is implemented (planned for Kea 1.0), it will also decrease when a lease is implemented (planned for Kea 1.0), it will also decrease when a lease
is expired. The <emphasis>id</emphasis> is the subnet-id of a given is expired. The <emphasis>id</emphasis> is the subnet-id of a given
subnet. This statistic is exposed for each subnet separately. This subnet. This statistic is exposed for each subnet separately. This
statistic is reset during reconfiguration event. statistic is reset during a reconfiguration event.
</entry> </entry>
</row> </row>

View File

@@ -966,6 +966,7 @@ TEST_F(Dhcpv6SrvTest, pdRenewReject) {
// - returned REPLY message has server-id // - returned REPLY message has server-id
// - returned REPLY message has IA_NA that does not include an IAADDR // - returned REPLY message has IA_NA that does not include an IAADDR
// - lease is actually removed from LeaseMgr // - lease is actually removed from LeaseMgr
// - assigned-NAs stats counter is properly decremented
TEST_F(Dhcpv6SrvTest, ReleaseBasic) { TEST_F(Dhcpv6SrvTest, ReleaseBasic) {
testReleaseBasic(Lease::TYPE_NA, IOAddress("2001:db8:1:1::cafe:babe"), testReleaseBasic(Lease::TYPE_NA, IOAddress("2001:db8:1:1::cafe:babe"),
IOAddress("2001:db8:1:1::cafe:babe")); IOAddress("2001:db8:1:1::cafe:babe"));
@@ -980,6 +981,7 @@ TEST_F(Dhcpv6SrvTest, ReleaseBasic) {
// - returned REPLY message has server-id // - returned REPLY message has server-id
// - returned REPLY message has IA_PD that does not include an IAPREFIX // - returned REPLY message has IA_PD that does not include an IAPREFIX
// - lease is actually removed from LeaseMgr // - lease is actually removed from LeaseMgr
// - assigned-PDs stats counter is properly decremented
TEST_F(Dhcpv6SrvTest, pdReleaseBasic) { TEST_F(Dhcpv6SrvTest, pdReleaseBasic) {
testReleaseBasic(Lease::TYPE_PD, IOAddress("2001:db8:1:2::"), testReleaseBasic(Lease::TYPE_PD, IOAddress("2001:db8:1:2::"),
IOAddress("2001:db8:1:2::")); IOAddress("2001:db8:1:2::"));
@@ -998,6 +1000,7 @@ TEST_F(Dhcpv6SrvTest, pdReleaseBasic) {
// - returned REPLY message has server-id // - returned REPLY message has server-id
// - returned REPLY message has IA_NA that includes STATUS-CODE // - returned REPLY message has IA_NA that includes STATUS-CODE
// - No lease in LeaseMgr // - No lease in LeaseMgr
// - assigned-NAs stats counter is properly not decremented
TEST_F(Dhcpv6SrvTest, ReleaseReject) { TEST_F(Dhcpv6SrvTest, ReleaseReject) {
testReleaseReject(Lease::TYPE_NA, IOAddress("2001:db8:1:1::dead")); testReleaseReject(Lease::TYPE_NA, IOAddress("2001:db8:1:1::dead"));
} }
@@ -1015,6 +1018,7 @@ TEST_F(Dhcpv6SrvTest, ReleaseReject) {
// - returned REPLY message has server-id // - returned REPLY message has server-id
// - returned REPLY message has IA_PD that includes STATUS-CODE // - returned REPLY message has IA_PD that includes STATUS-CODE
// - No lease in LeaseMgr // - No lease in LeaseMgr
// - assigned-PDs stats counter is properly not decremented
TEST_F(Dhcpv6SrvTest, pdReleaseReject) { TEST_F(Dhcpv6SrvTest, pdReleaseReject) {
testReleaseReject(Lease::TYPE_PD, IOAddress("2001:db8:1:2::")); testReleaseReject(Lease::TYPE_PD, IOAddress("2001:db8:1:2::"));
} }

View File

@@ -17,6 +17,7 @@
#include <dhcp/option6_status_code.h> #include <dhcp/option6_status_code.h>
#include <dhcp6/tests/dhcp6_test_utils.h> #include <dhcp6/tests/dhcp6_test_utils.h>
#include <dhcp6/json_config_parser.h> #include <dhcp6/json_config_parser.h>
#include <stats/stats_mgr.h>
#include <util/pointer_util.h> #include <util/pointer_util.h>
#include <cc/command_interpreter.h> #include <cc/command_interpreter.h>
#include <string.h> #include <string.h>
@@ -24,6 +25,7 @@
using namespace isc::data; using namespace isc::data;
using namespace isc::dhcp; using namespace isc::dhcp;
using namespace isc::asiolink; using namespace isc::asiolink;
using namespace isc::stats;
namespace isc { namespace isc {
namespace test { namespace test {
@@ -590,6 +592,12 @@ Dhcpv6SrvTest::testReleaseBasic(Lease::Type type, const IOAddress& existing,
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(type, existing); Lease6Ptr l = LeaseMgrFactory::instance().getLease6(type, existing);
ASSERT_TRUE(l); ASSERT_TRUE(l);
// And prepopulate the stats counter
std::string name = StatsMgr::generateName("subnet", subnet_->getID(),
type == Lease::TYPE_NA ? "assigned-NAs" :
"assigned-PDs");
StatsMgr::instance().setValue(name, static_cast<int64_t>(1));
// Let's create a RELEASE // Let's create a RELEASE
Pkt6Ptr rel = createMessage(DHCPV6_RELEASE, type, release_addr, prefix_len, Pkt6Ptr rel = createMessage(DHCPV6_RELEASE, type, release_addr, prefix_len,
iaid); iaid);
@@ -628,6 +636,11 @@ Dhcpv6SrvTest::testReleaseBasic(Lease::Type type, const IOAddress& existing,
l = LeaseMgrFactory::instance().getLease6(type, *duid_, iaid, l = LeaseMgrFactory::instance().getLease6(type, *duid_, iaid,
subnet_->getID()); subnet_->getID());
ASSERT_FALSE(l); ASSERT_FALSE(l);
// We should have decremented the address counter
ObservationPtr stat = StatsMgr::instance().getObservation(name);
ASSERT_TRUE(stat);
EXPECT_EQ(0, stat->getInteger().first);
} }
void void
@@ -656,6 +669,12 @@ Dhcpv6SrvTest::testReleaseReject(Lease::Type type, const IOAddress& addr) {
// GenerateClientId() also sets duid_ // GenerateClientId() also sets duid_
OptionPtr clientid = generateClientId(); OptionPtr clientid = generateClientId();
// Pretend we have allocated 1 lease
std::string name = StatsMgr::generateName("subnet", subnet_->getID(),
type == Lease::TYPE_NA ? "assigned-NAs" :
"assigned-PDs");
StatsMgr::instance().setValue(name, static_cast<int64_t>(1));
// Check that the lease is NOT in the database // Check that the lease is NOT in the database
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(type, addr); Lease6Ptr l = LeaseMgrFactory::instance().getLease6(type, addr);
ASSERT_FALSE(l); ASSERT_FALSE(l);
@@ -685,6 +704,11 @@ Dhcpv6SrvTest::testReleaseReject(Lease::Type type, const IOAddress& addr) {
l = LeaseMgrFactory::instance().getLease6(type, addr); l = LeaseMgrFactory::instance().getLease6(type, addr);
ASSERT_FALSE(l); ASSERT_FALSE(l);
// Verify we didn't decrement the stats counter
ObservationPtr stat = StatsMgr::instance().getObservation(name);
ASSERT_TRUE(stat);
EXPECT_EQ(1, stat->getInteger().first);
// CASE 2: Lease is known and belongs to this client, but to a different IAID // CASE 2: Lease is known and belongs to this client, but to a different IAID
SCOPED_TRACE("CASE 2: Lease is known and belongs to this client, but to a different IAID"); SCOPED_TRACE("CASE 2: Lease is known and belongs to this client, but to a different IAID");
@@ -713,6 +737,9 @@ Dhcpv6SrvTest::testReleaseReject(Lease::Type type, const IOAddress& addr) {
l = LeaseMgrFactory::instance().getLease6(type, addr); l = LeaseMgrFactory::instance().getLease6(type, addr);
ASSERT_TRUE(l); ASSERT_TRUE(l);
// Verify we didn't decrement the stats counter
EXPECT_EQ(1, stat->getInteger().first);
// CASE 3: Lease belongs to a client with different client-id // CASE 3: Lease belongs to a client with different client-id
SCOPED_TRACE("CASE 3: Lease belongs to a client with different client-id"); SCOPED_TRACE("CASE 3: Lease belongs to a client with different client-id");
@@ -737,6 +764,9 @@ Dhcpv6SrvTest::testReleaseReject(Lease::Type type, const IOAddress& addr) {
l = LeaseMgrFactory::instance().getLease6(type, addr); l = LeaseMgrFactory::instance().getLease6(type, addr);
ASSERT_TRUE(l); ASSERT_TRUE(l);
// Verify we didn't decrement the stats counter
EXPECT_EQ(1, stat->getInteger().first);
// Finally, let's cleanup the database // Finally, let's cleanup the database
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr)); EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr));
} }

View File

@@ -1038,12 +1038,15 @@ Lease6Ptr AllocEngine::createLease6(ClientContext6& ctx,
bool status = LeaseMgrFactory::instance().addLease(lease); bool status = LeaseMgrFactory::instance().addLease(lease);
if (status) { if (status) {
// The lease insertion succeeded, let's bump up the statistic. // The lease insertion succeeded - if the lease is in the
// current subnet lets bump up the statistic.
if (ctx.subnet_->inPool(ctx.type_, addr)) {
StatsMgr::instance().addValue( StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", ctx.subnet_->getID(), StatsMgr::generateName("subnet", ctx.subnet_->getID(),
ctx.type_ == Lease::TYPE_NA ? "assigned-NAs" : ctx.type_ == Lease::TYPE_NA ? "assigned-NAs" :
"assigned-PDs"), "assigned-PDs"),
static_cast<int64_t>(1)); static_cast<int64_t>(1));
}
return (lease); return (lease);
} else { } else {

View File

@@ -53,59 +53,51 @@ TEST_F(AllocEngine6Test, constructor) {
} }
// This test checks if the simple allocation (REQUEST) can succeed // This test checks if the simple allocation (REQUEST) can succeed
// and the stats counter is properly bumped by 1
TEST_F(AllocEngine6Test, simpleAlloc6) { 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); simpleAlloc6Test(pool_, IOAddress("::"), false);
// We should have bumped the address counter by 1 // We should have bumped the address counter by 1
string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs");
ObservationPtr stat = StatsMgr::instance().getObservation(name); ObservationPtr stat = StatsMgr::instance().getObservation(name);
ASSERT_TRUE(stat); ASSERT_TRUE(stat);
EXPECT_EQ(101, stat->getInteger().first); EXPECT_EQ(101, stat->getInteger().first);
} }
// This test checks if the simple PD allocation (REQUEST) can succeed // This test checks if the simple PD allocation (REQUEST) can succeed
// and the stats counter is properly bumped by 1
TEST_F(AllocEngine6Test, pdSimpleAlloc6) { 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); simpleAlloc6Test(pd_pool_, IOAddress("::"), false);
// We should have bumped the address counter by 1 // We should have bumped the address counter by 1
string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-PDs");
ObservationPtr stat = StatsMgr::instance().getObservation(name); ObservationPtr stat = StatsMgr::instance().getObservation(name);
ASSERT_TRUE(stat); ASSERT_TRUE(stat);
EXPECT_EQ(101, stat->getInteger().first); EXPECT_EQ(101, stat->getInteger().first);
} }
// This test checks if the fake allocation (for SOLICIT) can succeed // This test checks if the fake allocation (for SOLICIT) can succeed
// and the stats counter isn't bumped
TEST_F(AllocEngine6Test, fakeAlloc6) { 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); simpleAlloc6Test(pool_, IOAddress("::"), true);
// We should not have bumped the address counter // We should not have bumped the address counter
string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs");
ObservationPtr stat = StatsMgr::instance().getObservation(name); ObservationPtr stat = StatsMgr::instance().getObservation(name);
ASSERT_TRUE(stat); ASSERT_TRUE(stat);
EXPECT_EQ(100, stat->getInteger().first); EXPECT_EQ(100, stat->getInteger().first);
} }
// This test checks if the fake PD allocation (for SOLICIT) can succeed // This test checks if the fake PD allocation (for SOLICIT) can succeed
// and the stats counter isn't bumped
TEST_F(AllocEngine6Test, pdFakeAlloc6) { 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); simpleAlloc6Test(pd_pool_, IOAddress("::"), true);
// We should not have bumped the address counter // We should not have bumped the address counter
string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-PDs");
ObservationPtr stat = StatsMgr::instance().getObservation(name); ObservationPtr stat = StatsMgr::instance().getObservation(name);
ASSERT_TRUE(stat); ASSERT_TRUE(stat);
EXPECT_EQ(100, stat->getInteger().first); EXPECT_EQ(100, stat->getInteger().first);
@@ -566,6 +558,10 @@ TEST_F(AllocEngine6Test, requestReuseExpiredLease6) {
lease->hostname_ = "myhost.example.com."; lease->hostname_ = "myhost.example.com.";
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); 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 // A client comes along, asking specifically for this address
AllocEngine::ClientContext6 ctx(subnet_, duid_, iaid_, addr, Lease::TYPE_NA, AllocEngine::ClientContext6 ctx(subnet_, duid_, iaid_, addr, Lease::TYPE_NA,
false, false, "", false); false, false, "", false);
@@ -596,6 +592,13 @@ TEST_F(AllocEngine6Test, requestReuseExpiredLease6) {
// Now check that the lease in LeaseMgr has the same parameters // Now check that the lease in LeaseMgr has the same parameters
detailCompareLease(lease, from_mgr); 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 --- // --- v6 host reservation ---
@@ -639,9 +642,9 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolRequestNoHint) {
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false); 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"); 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); Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("::"), false);
ASSERT_TRUE(lease); ASSERT_TRUE(lease);
@@ -757,7 +760,7 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolRequestMatchingHint) {
// This test checks the behavior of the allocation engine in the following // This test checks the behavior of the allocation engine in the following
// scenario: // scenario:
// - Client has no lease in the database. // - 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 sends SOLICIT without any hints.
// - Client is allocated a reserved address. // - Client is allocated a reserved address.
// //
@@ -773,13 +776,14 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolSolicitNoHint) {
Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("::"), true, false); Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("::"), true, false);
ASSERT_TRUE(lease); ASSERT_TRUE(lease);
EXPECT_EQ("2001:db8::abcd", lease->addr_.toText()); 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 // This test checks the behavior of the allocation engine in the following
// scenario: // scenario:
// - Client has no lease in the database. // - 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 sends REQUEST without any hints.
// - Client is allocated a reserved address. // - Client is allocated a reserved address.
// //
@@ -792,9 +796,18 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolRequestNoHint) {
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false); 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); Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("::"), false, false);
ASSERT_TRUE(lease); ASSERT_TRUE(lease);
EXPECT_EQ("2001:db8::abcd", lease->addr_.toText()); 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) // 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()); 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 // This test checks the behavior of the allocation engine in the following
// scenario: // scenario:
// - Client has no lease in the database. // - 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 sends REQUEST with a hint that does not match reservation
// - Client is allocated a reserved address, not the hint. // - 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()); 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 // This test checks the behavior of the allocation engine in the following
// scenario: // scenario:
// - Client has no lease in the database. // - 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 sends SOLICIT with a hint that does matches reservation
// - Client is allocated a reserved address, not the hint. // - 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()); 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 // This test checks the behavior of the allocation engine in the following
// scenario: // scenario:
// - Client has no lease in the database. // - 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 sends REQUEST with a hint that does not match reservation
// - Client is allocated a reserved address, not the hint. // - Client is allocated a reserved address, not the hint.
// //
@@ -903,18 +916,16 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolRequestMatchingHint) {
// - client tries to get address A: // - client tries to get address A:
// Check that his existing lease for lease A is removed // Check that his existing lease for lease A is removed
// Check that he is assigned a new lease for B // Check that he is assigned a new lease for B
// - verify that the number of assigned address behaves as expected
TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedThis) { TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedThis) {
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false); 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 // Client gets an address
Lease6Ptr lease1 = simpleAlloc6Test(pool_, IOAddress("::"), false); Lease6Ptr lease1 = simpleAlloc6Test(pool_, IOAddress("::"), false);
ASSERT_TRUE(lease1); ASSERT_TRUE(lease1);
// We should have bumped the address counter // We should have bumped the address counter
string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs");
ObservationPtr stat = StatsMgr::instance().getObservation(name); ObservationPtr stat = StatsMgr::instance().getObservation(name);
ASSERT_TRUE(stat); ASSERT_TRUE(stat);
EXPECT_EQ(101, stat->getInteger().first); 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 // 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 // have decremented it on the implied release and incremented it on the reserved
EXPECT_EQ(101, stat->getInteger().first); EXPECT_EQ(101, stat->getInteger().first);
} }
// In the following situation: // In the following situation:
// - client X is assigned an address A // - client X is assigned an address A
// - HR is made for client Y (*other* client) to get 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); Lease6Ptr lease1 = simpleAlloc6Test(pool_, IOAddress("::"), false);
ASSERT_TRUE(lease1); 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 // Just check that if the client requests again, it will get the same
// address. // address.
Lease6Ptr lease2 = simpleAlloc6Test(pool_, lease1->addr_, false); Lease6Ptr lease2 = simpleAlloc6Test(pool_, lease1->addr_, false);
ASSERT_TRUE(lease2); ASSERT_TRUE(lease2);
detailCompareLease(lease1, 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 // 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 // address client X just received. Let's generate a host, but don't add it
// to the HostMgr yet. // to the HostMgr yet.
@@ -1014,6 +1032,10 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedOther) {
// Now check that the lease in LeaseMgr has the same parameters // Now check that the lease in LeaseMgr has the same parameters
detailCompareLease(lease3, from_mgr); 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 // 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 test
}; // namespace dhcp }; // namespace dhcp
}; // namespace isc }; // namespace isc

View File

@@ -22,6 +22,7 @@
#include <dhcpsrv/host_mgr.h> #include <dhcpsrv/host_mgr.h>
#include <dhcpsrv/lease_mgr.h> #include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/memfile_lease_mgr.h> #include <dhcpsrv/memfile_lease_mgr.h>
#include <stats/stats_mgr.h>
#include <dhcpsrv/tests/test_utils.h> #include <dhcpsrv/tests/test_utils.h>
#include <dhcpsrv/tests/alloc_engine_utils.h> #include <dhcpsrv/tests/alloc_engine_utils.h>
@@ -40,6 +41,7 @@
using namespace std; using namespace std;
using namespace isc::hooks; using namespace isc::hooks;
using namespace isc::asiolink; using namespace isc::asiolink;
using namespace isc::stats;
namespace isc { namespace isc {
namespace dhcp { namespace dhcp {
@@ -82,6 +84,14 @@ AllocEngine6Test::initSubnet(const asiolink::IOAddress& subnet,
cfg_mgr.getStagingCfg()->getCfgSubnets6()->add(subnet_); cfg_mgr.getStagingCfg()->getCfgSubnets6()->add(subnet_);
cfg_mgr.commit(); cfg_mgr.commit();
// By default we pretend our subnet has 100 addresses and prefixes allocated.
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs"),
static_cast<int64_t>(100));
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", subnet_->getID(), "assigned-PDs"),
static_cast<int64_t>(100));
} }
void void

View File

@@ -583,7 +583,7 @@ TEST_F(CfgMgrTest, commitStats4) {
StatsMgr& stats_mgr = StatsMgr::instance(); StatsMgr& stats_mgr = StatsMgr::instance();
// Let's prepare the "old" configuration: a subnet with id 123 // Let's prepare the "old" configuration: a subnet with id 123
// and pretend there ware addresses assigned, so statistics are non-zero. // and pretend there were addresses assigned, so statistics are non-zero.
Subnet4Ptr subnet1(new Subnet4(IOAddress("192.1.2.0"), 24, 1, 2, 3, 123)); Subnet4Ptr subnet1(new Subnet4(IOAddress("192.1.2.0"), 24, 1, 2, 3, 123));
CfgSubnets4Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets4(); CfgSubnets4Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets4();
subnets->add(subnet1); subnets->add(subnet1);
@@ -622,7 +622,7 @@ TEST_F(CfgMgrTest, clearStats4) {
StatsMgr& stats_mgr = StatsMgr::instance(); StatsMgr& stats_mgr = StatsMgr::instance();
// Let's prepare the "old" configuration: a subnet with id 123 // Let's prepare the "old" configuration: a subnet with id 123
// and pretend there ware addresses assigned, so statistics are non-zero. // and pretend there were addresses assigned, so statistics are non-zero.
Subnet4Ptr subnet1(new Subnet4(IOAddress("192.1.2.0"), 24, 1, 2, 3, 123)); Subnet4Ptr subnet1(new Subnet4(IOAddress("192.1.2.0"), 24, 1, 2, 3, 123));
CfgSubnets4Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets4(); CfgSubnets4Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets4();
subnets->add(subnet1); subnets->add(subnet1);
@@ -649,7 +649,7 @@ TEST_F(CfgMgrTest, commitStats6) {
StatsMgr& stats_mgr = StatsMgr::instance(); StatsMgr& stats_mgr = StatsMgr::instance();
// Let's prepare the "old" configuration: a subnet with id 123 // Let's prepare the "old" configuration: a subnet with id 123
// and pretend there ware addresses assigned, so statistics are non-zero. // and pretend there were addresses assigned, so statistics are non-zero.
Subnet6Ptr subnet1(new Subnet6(IOAddress("2001:db8:1::"), 48, 1, 2, 3, 4, 123)); Subnet6Ptr subnet1(new Subnet6(IOAddress("2001:db8:1::"), 48, 1, 2, 3, 4, 123));
CfgSubnets6Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets6(); CfgSubnets6Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets6();
subnets->add(subnet1); subnets->add(subnet1);
@@ -700,7 +700,7 @@ TEST_F(CfgMgrTest, clearStats6) {
StatsMgr& stats_mgr = StatsMgr::instance(); StatsMgr& stats_mgr = StatsMgr::instance();
// Let's prepare the "old" configuration: a subnet with id 123 // Let's prepare the "old" configuration: a subnet with id 123
// and pretend there ware addresses assigned, so statistics are non-zero. // and pretend there were addresses assigned, so statistics are non-zero.
Subnet6Ptr subnet1(new Subnet6(IOAddress("2001:db8:1::"), 48, 1, 2, 3, 4, 123)); Subnet6Ptr subnet1(new Subnet6(IOAddress("2001:db8:1::"), 48, 1, 2, 3, 4, 123));
CfgSubnets6Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets6(); CfgSubnets6Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets6();
subnets->add(subnet1); subnets->add(subnet1);