<entry>subnet[id].total-NAs</entry>
<entry>integer</entry>
<entry>
- This statistic shows the total number of NA addresses available for the
- DHCPv6 management. In other words, this is the sum of all addresses in
- all configured pools. This statistic changes only during configuration
- changes. Note it does not take into account any addresses that may be
- reserved due to host reservation. The <emphasis>id</emphasis> is the
- subnet-id of a given subnet. This statistic is exposed for each subnet
- separately. This statistic is reset during reconfiguration event.
+ This statistic shows the total number of NA addresses available for
+ DHCPv6 management for a given subnet. In other words, this is the sum
+ of all addresses in all configured pools. This statistic changes only
+ during configuration changes. Note it does not take into account any
+ addresses that may be reserved due to host reservation. The
+ <emphasis>id</emphasis> is the subnet-id of a given subnet. This
+ statistic is exposed for each subnet separately. This statistic is
+ reset during a reconfiguration event.
</entry>
</row>
<entry>subnet[id].assigned-NAs</entry>
<entry>integer</entry>
<entry>
- This statistic shows the number of assigned NA addresses in a given subnet.
- This statistic increases every time a new lease is allocated (as a result
- of receiving a REQUEST message) and is decreased every time a lease is
- released (a RELEASE message is received). When lease expiration
+ This statistic shows the number of NA addresses in a given subnet that
+ are assigned. This statistic increases every time a new lease is allocated
+ (as a result of receiving a REQUEST message) and is decreased every time a
+ 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 expired. The <emphasis>id</emphasis> is the subnet-id of a given
subnet. This statistic is exposed for each subnet separately. This
- statistic is reset during reconfiguration event.
+ statistic is reset during a reconfiguration event.
</entry>
</row>
<entry>subnet[id].total-PDs</entry>
<entry>integer</entry>
<entry>
- This statistic shows the total number of PD prefixes available for the
- DHCPv6 management. In other words, this is the sum of all prefixes in
- all configured pools. This statistic changes only during configuration
- changes. Note it does not take into account any prefixes that may be
- reserved due to host reservation. The <emphasis>id</emphasis> is the
- subnet-id of a given subnet. This statistic is exposed for each subnet
- separately. This statistic is reset during reconfiguration event.
+ This statistic shows the total number of PD prefixes available for
+ DHCPv6 management for a given subnet. In other words, this is the sum
+ of all prefixes in all configured pools. This statistic changes only
+ during configuration changes. Note it does not take into account any
+ prefixes that may be reserved due to host reservation. The
+ <emphasis>id</emphasis> is the subnet-id of a given subnet. This
+ statistic is exposed for each subnet separately. This statistic is
+ reset during a reconfiguration event.
</entry>
</row>
<entry>subnet[id].assigned-PDs</entry>
<entry>integer</entry>
<entry>
- This statistic shows the number of assigned PD prefixes in a given subnet.
- This statistic increases every time a new lease is allocated (as a result
- of receiving a REQUEST message) and is decreased every time a lease is
- released (a RELEASE message is received). When lease expiration
+ This statistic shows the number of PD prefixes in a given subnet that
+ are assigned. This statistic increases every time a new lease is allocated
+ (as a result of receiving a REQUEST message) and is decreased every time a
+ 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 expired. The <emphasis>id</emphasis> is the subnet-id of a given
subnet. This statistic is exposed for each subnet separately. This
- statistic is reset during reconfiguration event.
+ statistic is reset during a reconfiguration event.
</entry>
</row>
#include <dhcp/option6_status_code.h>
#include <dhcp6/tests/dhcp6_test_utils.h>
#include <dhcp6/json_config_parser.h>
+#include <stats/stats_mgr.h>
#include <util/pointer_util.h>
#include <cc/command_interpreter.h>
#include <string.h>
using namespace isc::data;
using namespace isc::dhcp;
using namespace isc::asiolink;
+using namespace isc::stats;
namespace isc {
namespace test {
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(type, existing);
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
Pkt6Ptr rel = createMessage(DHCPV6_RELEASE, type, release_addr, prefix_len,
iaid);
l = LeaseMgrFactory::instance().getLease6(type, *duid_, iaid,
subnet_->getID());
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
// GenerateClientId() also sets duid_
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
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(type, addr);
ASSERT_FALSE(l);
l = LeaseMgrFactory::instance().getLease6(type, addr);
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
SCOPED_TRACE("CASE 2: Lease is known and belongs to this client, but to a different IAID");
l = LeaseMgrFactory::instance().getLease6(type, addr);
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
SCOPED_TRACE("CASE 3: Lease belongs to a client with different client-id");
l = LeaseMgrFactory::instance().getLease6(type, addr);
ASSERT_TRUE(l);
+ // Verify we didn't decrement the stats counter
+ EXPECT_EQ(1, stat->getInteger().first);
+
// Finally, let's cleanup the database
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr));
}
}
// 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);
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);
// 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 ---
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);
// 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.
//
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.
//
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)
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.
//
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.
//
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.
//
// - 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);
// 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
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.
// 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
}
-// 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