2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 21:45:37 +00:00

[#2898] fixed merge of stats for same pool IDs

This commit is contained in:
Razvan Becheriu
2023-06-21 14:40:20 +03:00
parent 21ff30b112
commit 3d61bdde3e
13 changed files with 310 additions and 196 deletions

View File

@@ -992,6 +992,11 @@
"require-client-classes": [],
// Pool identifier used to enable statistics for this pool.
// The pool ID does not need to be unique within the subnet
// or across subnets.
// If not unconfigured, it default to 0. The statistics
// regarding this pool will be merged with the other statistics
// of all other pools with the same pool ID in this subnet.
"pool-id": 1
}
],

View File

@@ -992,6 +992,11 @@
"require-client-classes": [],
// Pool identifier used to enable statistics for this pool.
// The pool ID does not need to be unique within the subnet
// or across subnets.
// If not unconfigured, it default to 0. The statistics
// regarding this pool will be merged with the other statistics
// of all other pools with the same pool ID in this subnet.
"pool-id": 1
}
],

View File

@@ -952,6 +952,11 @@
"require-client-classes": [],
// Pool identifier used to enable statistics for this pool.
// The pool ID does not need to be unique within the subnet
// or across subnets.
// If not unconfigured, it default to 0. The statistics
// regarding this pool will be merged with the other statistics
// of all other pools with the same pool ID in this subnet.
"pool-id": 1
}
],

View File

@@ -952,6 +952,11 @@
"require-client-classes": [],
// Pool identifier used to enable statistics for this pool.
// The pool ID does not need to be unique within the subnet
// or across subnets.
// If not unconfigured, it default to 0. The statistics
// regarding this pool will be merged with the other statistics
// of all other pools with the same pool ID in this subnet.
"pool-id": 1
}
],

View File

@@ -7255,6 +7255,16 @@ The DHCPv4 server supports the following statistics:
| | | counter is increased by 1. |
+----------------------------------------------------+----------------+------------------------------------+
.. note::
The pool ID can be configured on each pool by explicitly setting the ``pool-id``
parameter in the pool parameter map. If not configured, ``pool-id`` defaults to 0.
The statistics related to pool ID 0 refer to all the statistics of all the pools
that have unconfigured ``pool-id``.
The pool ID does not need to be unique within the subnet or across subnets.
The statistics regarding a specific pool ID within a subnet will be merged with the
other statistics of all other pools with the same pool ID in the respective subnet.
.. note::
This section describes DHCPv4-specific statistics. For a general

View File

@@ -7056,6 +7056,16 @@ The DHCPv6 server supports the following statistics:
| | | of a given subnet. |
+---------------------------------------------------+----------------+------------------------------------+
.. note::
The pool ID can be configured on each pool by explicitly setting the ``pool-id``
parameter in the pool parameter map. If not configured, ``pool-id`` defaults to 0.
The statistics related to pool ID 0 refer to all the statistics of all the pools
that have unconfigured ``pool-id``.
The pool ID does not need to be unique within the subnet or across subnets.
The statistics regarding a specific pool ID within a subnet will be merged with the
other statistics of all other pools with the same pool ID in the respective subnet.
.. note::
This section describes DHCPv6-specific statistics. For a general

View File

@@ -2245,17 +2245,19 @@ LeaseCmdsImpl::lease4WipeHandler(CalloutHandle& handle) {
auto const& sub = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(id);
if (sub) {
for (const auto& pool : sub->getPools(Lease::TYPE_V4)) {
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"assigned-addresses")),
static_cast<int64_t>(0));
const std::string& name_aa(StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"assigned-addresses")));
if (!StatsMgr::instance().getObservation(name_aa)) {
StatsMgr::instance().setValue(name_aa, static_cast<int64_t>(0));
}
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"declined-addresses")),
static_cast<int64_t>(0));
const std::string& name_da(StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"declined-addresses")));
if (!StatsMgr::instance().getObservation(name_da)) {
StatsMgr::instance().setValue(name_da, static_cast<int64_t>(0));
}
}
}
@@ -2279,17 +2281,19 @@ LeaseCmdsImpl::lease4WipeHandler(CalloutHandle& handle) {
static_cast<int64_t>(0));
for (const auto& pool : sub->getPools(Lease::TYPE_V4)) {
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"assigned-addresses")),
static_cast<int64_t>(0));
const std::string& name_aa(StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"assigned-addresses")));
if (!StatsMgr::instance().getObservation(name_aa)) {
StatsMgr::instance().setValue(name_aa, static_cast<int64_t>(0));
}
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"declined-addresses")),
static_cast<int64_t>(0));
const std::string& name_da(StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"declined-addresses")));
if (!StatsMgr::instance().getObservation(name_da)) {
StatsMgr::instance().setValue(name_da, static_cast<int64_t>(0));
}
}
}
@@ -2365,25 +2369,28 @@ LeaseCmdsImpl::lease6WipeHandler(CalloutHandle& handle) {
auto const& sub = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(id);
if (sub) {
for (const auto& pool : sub->getPools(Lease::TYPE_NA)) {
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"assigned-nas")),
static_cast<int64_t>(0));
const std::string& name_anas(StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"assigned-nas")));
if (!StatsMgr::instance().getObservation(name_anas)) {
StatsMgr::instance().setValue(name_anas, static_cast<int64_t>(0));
}
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"declined-addresses")),
static_cast<int64_t>(0));
const std::string& name_da(StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"declined-addresses")));
if (!StatsMgr::instance().getObservation(name_da)) {
StatsMgr::instance().setValue(name_da, static_cast<int64_t>(0));
}
}
for (const auto& pool : sub->getPools(Lease::TYPE_PD)) {
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pd-pool", pool->getID(),
"assigned-pds")),
static_cast<int64_t>(0));
const std::string& name_apds(StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pd-pool", pool->getID(),
"assigned-pds")));
if (!StatsMgr::instance().getObservation(name_apds)) {
StatsMgr::instance().setValue(name_apds, static_cast<int64_t>(0));
}
}
}
@@ -2411,25 +2418,28 @@ LeaseCmdsImpl::lease6WipeHandler(CalloutHandle& handle) {
static_cast<int64_t>(0));
for (const auto& pool : sub->getPools(Lease::TYPE_NA)) {
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"assigned-nas")),
static_cast<int64_t>(0));
const std::string& name_anas(StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"assigned-nas")));
if (!StatsMgr::instance().getObservation(name_anas)) {
StatsMgr::instance().setValue(name_anas, static_cast<int64_t>(0));
}
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"declined-addresses")),
static_cast<int64_t>(0));
const std::string& name_da(StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pool", pool->getID(),
"declined-addresses")));
if (!StatsMgr::instance().getObservation(name_da)) {
StatsMgr::instance().setValue(name_da, static_cast<int64_t>(0));
}
}
for (const auto& pool : sub->getPools(Lease::TYPE_PD)) {
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pd-pool", pool->getID(),
"assigned-pds")),
static_cast<int64_t>(0));
const std::string& name_apds(StatsMgr::generateName("subnet", sub->getID(),
StatsMgr::generateName("pd-pool", pool->getID(),
"assigned-pds")));
if (!StatsMgr::instance().getObservation(name_apds)) {
StatsMgr::instance().setValue(name_apds, static_cast<int64_t>(0));
}
}
}

View File

@@ -57,6 +57,7 @@ public:
/// @param subnet_id expected subnet-id
/// @param hwaddr expected value of hardware address
/// @param client_id_required true if client-id is expected
/// @param pool_id expected pool-id (if value is 0 the parameter pool-id should not be present)
void checkLease4(isc::data::ConstElementPtr l, std::string ip,
uint32_t subnet_id, std::string hwaddr,
bool client_id_required, uint32_t pool_id = 0) {

View File

@@ -58,6 +58,7 @@ public:
/// @param subnet_id expected subnet-id
/// @param duid expected value of DUID
/// @param hwaddr_required true if hwaddr is expected
/// @param pool_id expected pool-id (if value is 0 the parameter pool-id should not be present)
void checkLease6(isc::data::ConstElementPtr l, std::string ip,
uint8_t prefixlen, uint32_t subnet_id, std::string duid,
bool hwaddr_required, uint32_t pool_id = 0) {

View File

@@ -580,33 +580,39 @@ CfgSubnets4::updateStatistics() {
stats_mgr.setValue(StatsMgr::
generateName("subnet", subnet_id, "total-addresses"),
int64_t(subnet4->getPoolCapacity(Lease::TYPE_V4)));
std::string name =
StatsMgr::generateName("subnet", subnet_id, "cumulative-assigned-addresses");
const std::string& name(StatsMgr::generateName("subnet", subnet_id,
"cumulative-assigned-addresses"));
if (!stats_mgr.getObservation(name)) {
stats_mgr.setValue(name, static_cast<int64_t>(0));
}
name = StatsMgr::generateName("subnet", subnet_id, "v4-lease-reuses");
if (!stats_mgr.getObservation(name)) {
stats_mgr.setValue(name, int64_t(0));
const std::string& name_reuses(StatsMgr::generateName("subnet", subnet_id,
"v4-lease-reuses"));
if (!stats_mgr.getObservation(name_reuses)) {
stats_mgr.setValue(name_reuses, int64_t(0));
}
name = StatsMgr::generateName("subnet", subnet_id, "v4-reservation-conflicts");
if (!stats_mgr.getObservation(name)) {
stats_mgr.setValue(name, static_cast<int64_t>(0));
const std::string& name_conflicts(StatsMgr::generateName("subnet", subnet_id,
"v4-reservation-conflicts"));
if (!stats_mgr.getObservation(name_conflicts)) {
stats_mgr.setValue(name_conflicts, static_cast<int64_t>(0));
}
for (const auto& pool : subnet4->getPools(Lease::TYPE_V4)) {
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"total-addresses")),
static_cast<int64_t>(pool->getCapacity()));
const std::string& name_total(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"total-addresses")));
if (!stats_mgr.getObservation(name_total)) {
stats_mgr.setValue(name_total, static_cast<int64_t>(pool->getCapacity()));
} else {
stats_mgr.addValue(name_total, static_cast<int64_t>(pool->getCapacity()));
}
name = StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"cumulative-assigned-addresses"));
if (!stats_mgr.getObservation(name)) {
stats_mgr.setValue(name, static_cast<int64_t>(0));
const std::string& name_ca(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"cumulative-assigned-addresses")));
if (!stats_mgr.getObservation(name_ca)) {
stats_mgr.setValue(name_ca, static_cast<int64_t>(0));
}
}
}

View File

@@ -502,55 +502,63 @@ CfgSubnets6::updateStatistics() {
"total-pds"),
subnet6->getPoolCapacity(Lease::TYPE_PD));
const std::string& name_nas = StatsMgr::generateName("subnet", subnet_id, "cumulative-assigned-nas");
const std::string& name_nas(StatsMgr::generateName("subnet", subnet_id,
"cumulative-assigned-nas"));
if (!stats_mgr.getObservation(name_nas)) {
stats_mgr.setValue(name_nas, static_cast<int64_t>(0));
}
const std::string& name_pds = StatsMgr::generateName("subnet", subnet_id, "cumulative-assigned-pds");
const std::string& name_pds(StatsMgr::generateName("subnet", subnet_id,
"cumulative-assigned-pds"));
if (!stats_mgr.getObservation(name_pds)) {
stats_mgr.setValue(name_pds, static_cast<int64_t>(0));
}
string const& name_ia_na_reuses(
StatsMgr::generateName("subnet", subnet_id, "v6-ia-na-lease-reuses"));
string const& name_ia_na_reuses(StatsMgr::generateName("subnet", subnet_id,
"v6-ia-na-lease-reuses"));
if (!stats_mgr.getObservation(name_ia_na_reuses)) {
stats_mgr.setValue(name_ia_na_reuses, int64_t(0));
}
string const& name_ia_pd_reuses(
StatsMgr::generateName("subnet", subnet_id, "v6-ia-pd-lease-reuses"));
string const& name_ia_pd_reuses(StatsMgr::generateName("subnet", subnet_id,
"v6-ia-pd-lease-reuses"));
if (!stats_mgr.getObservation(name_ia_pd_reuses)) {
stats_mgr.setValue(name_ia_pd_reuses, int64_t(0));
}
for (const auto& pool : subnet6->getPools(Lease::TYPE_NA)) {
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"total-nas")),
pool->getCapacity());
const std::string& name_total_nas(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"total-nas")));
if (!stats_mgr.getObservation(name_total_nas)) {
stats_mgr.setValue(name_total_nas, pool->getCapacity());
} else {
stats_mgr.addValue(name_total_nas, pool->getCapacity());
}
const std::string& name_nas =
StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"cumulative-assigned-nas"));
if (!stats_mgr.getObservation(name_nas)) {
stats_mgr.setValue(name_nas, static_cast<int64_t>(0));
const std::string& name_ca_nas(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"cumulative-assigned-nas")));
if (!stats_mgr.getObservation(name_ca_nas)) {
stats_mgr.setValue(name_ca_nas, static_cast<int64_t>(0));
}
}
for (const auto& pool : subnet6->getPools(Lease::TYPE_PD)) {
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pd-pool", pool->getID(),
"total-pds")),
pool->getCapacity());
const std::string& name_total_pds(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pd-pool", pool->getID(),
"total-pds")));
if (!stats_mgr.getObservation(name_total_pds)) {
stats_mgr.setValue(name_total_pds, pool->getCapacity());
} else {
stats_mgr.addValue(name_total_pds, pool->getCapacity());
}
const std::string& name_pds =
StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pd-pool", pool->getID(),
"cumulative-assigned-pds"));
if (!stats_mgr.getObservation(name_pds)) {
stats_mgr.setValue(name_pds, static_cast<int64_t>(0));
const std::string& name_ca_pds(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pd-pool", pool->getID(),
"cumulative-assigned-pds")));
if (!stats_mgr.getObservation(name_ca_pds)) {
stats_mgr.setValue(name_ca_pds, static_cast<int64_t>(0));
}
}
}

View File

@@ -119,55 +119,45 @@ LeaseMgr::recountLeaseStats4() {
"declined-addresses"),
zero);
if (!stats_mgr.getObservation(
StatsMgr::generateName("subnet", subnet_id,
"reclaimed-declined-addresses"))) {
stats_mgr.setValue(
StatsMgr::generateName("subnet", subnet_id,
"reclaimed-declined-addresses"),
zero);
const std::string name_rec_dec(StatsMgr::generateName("subnet", subnet_id,
"reclaimed-declined-addresses"));
if (!stats_mgr.getObservation(name_rec_dec)) {
stats_mgr.setValue(name_rec_dec, zero);
}
if (!stats_mgr.getObservation(
StatsMgr::generateName("subnet", subnet_id,
"reclaimed-leases"))) {
stats_mgr.setValue(
StatsMgr::generateName("subnet", subnet_id,
"reclaimed-leases"),
zero);
const std::string name_rec(StatsMgr::generateName("subnet", subnet_id,
"reclaimed-leases"));
if (!stats_mgr.getObservation(name_rec)) {
stats_mgr.setValue(name_rec, zero);
}
for (const auto & pool : (*subnet)->getPools(Lease::TYPE_V4)) {
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"assigned-addresses")),
zero);
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"declined-addresses")),
zero);
if (!stats_mgr.getObservation(
StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"reclaimed-declined-addresses")))) {
stats_mgr.setValue(
StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"reclaimed-declined-addresses")),
zero);
for (const auto& pool : (*subnet)->getPools(Lease::TYPE_V4)) {
const std::string name_aa(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"assigned-addresses")));
if (!stats_mgr.getObservation(name_aa)) {
stats_mgr.setValue(name_aa, zero);
}
if (!stats_mgr.getObservation(
StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"reclaimed-leases")))) {
stats_mgr.setValue(
StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"reclaimed-leases")),
zero);
const std::string& name_da(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"declined-addresses")));
if (!stats_mgr.getObservation(name_da)) {
stats_mgr.setValue(name_da, zero);
}
const std::string& name_rec_dec(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"reclaimed-declined-addresses")));
if (!stats_mgr.getObservation(name_rec_dec)) {
stats_mgr.setValue(name_rec_dec, zero);
}
const std::string& name_rec(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"reclaimed-leases")));
if (!stats_mgr.getObservation(name_rec)) {
stats_mgr.setValue(name_rec, zero);
}
}
}
@@ -366,54 +356,48 @@ LeaseMgr::recountLeaseStats6() {
}
for (const auto& pool : (*subnet)->getPools(Lease::TYPE_NA)) {
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"assigned-nas")),
zero);
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"declined-addresses")),
zero);
if (!stats_mgr.getObservation(
StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"reclaimed-declined-addresses")))) {
stats_mgr.setValue(
StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"reclaimed-declined-addresses")),
zero);
const std::string& name_anas(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"assigned-nas")));
if (!stats_mgr.getObservation(name_anas)) {
stats_mgr.setValue(name_anas, zero);
}
if (!stats_mgr.getObservation(
StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"reclaimed-leases")))) {
stats_mgr.setValue(
StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"reclaimed-leases")),
zero);
const std::string& name_da(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"declined-addresses")));
if (!stats_mgr.getObservation(name_da)) {
stats_mgr.setValue(name_da, zero);
}
const std::string name_rec_dec(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"reclaimed-declined-addresses")));
if (!stats_mgr.getObservation(name_rec_dec)) {
stats_mgr.setValue(name_rec_dec, zero);
}
const std::string& name_rec(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pool", pool->getID(),
"reclaimed-leases")));
if (!stats_mgr.getObservation(name_rec)) {
stats_mgr.setValue(name_rec, zero);
}
}
for (const auto& pool : (*subnet)->getPools(Lease::TYPE_PD)) {
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pd-pool", pool->getID(),
"assigned-pds")),
zero);
const std::string& name_apds(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pd-pool", pool->getID(),
"assigned-pds")));
if (!stats_mgr.getObservation(name_apds)) {
stats_mgr.setValue(name_apds, zero);
}
if (!stats_mgr.getObservation(
StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pd-pool", pool->getID(),
"reclaimed-leases")))) {
stats_mgr.setValue(
StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pd-pool", pool->getID(),
"reclaimed-leases")),
zero);
const std::string& name_rec(StatsMgr::generateName("subnet", subnet_id,
StatsMgr::generateName("pd-pool", pool->getID(),
"reclaimed-leases")));
if (!stats_mgr.getObservation(name_rec)) {
stats_mgr.setValue(name_rec, zero);
}
}
}

View File

@@ -297,6 +297,7 @@ public:
" lease database backend: " << ex.what() << std::endl;
throw;
}
CfgMgr::instance().setFamily(family);
}
/// used in client classification (or just empty container for other tests)
@@ -595,9 +596,11 @@ TEST_F(CfgMgrTest, commitStats4) {
// There's a subnet 192.1.2.0/24 with ID=42
Subnet4Ptr subnet2(new Subnet4(IOAddress("192.1.2.0"), 24, 1, 2, 3, 42));
// Let's make a pool with 128 addresses available.
PoolPtr pool(new Pool4(IOAddress("192.1.2.0"), 25)); // 128 addrs
subnet2->addPool(pool);
// Let's make pools with 128 addresses available in total.
PoolPtr pool1(new Pool4(IOAddress("192.1.2.0"), 26)); // 64 addrs
PoolPtr pool2(new Pool4(IOAddress("192.1.2.64"), 26)); // 64 addrs
subnet2->addPool(pool1);
subnet2->addPool(pool2);
subnets = cfg_mgr.getStagingCfg()->getCfgSubnets4();
subnets->add(subnet2);
@@ -616,6 +619,8 @@ TEST_F(CfgMgrTest, commitStats4) {
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].total-addresses"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].assigned-addresses"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].pool[0].total-addresses"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].pool[0].assigned-addresses"));
ObservationPtr total_addrs;
EXPECT_NO_THROW(total_addrs = stats_mgr.getObservation("subnet[42].total-addresses"));
@@ -625,6 +630,15 @@ TEST_F(CfgMgrTest, commitStats4) {
EXPECT_EQ(15, total_addrs->getMaxSampleCount().second);
EXPECT_FALSE(total_addrs->getMaxSampleAge().first);
EXPECT_EQ("00:00:02", durationToText(total_addrs->getMaxSampleAge().second, 0));
EXPECT_NO_THROW(total_addrs = stats_mgr.getObservation("subnet[42].pool[0].total-addresses"));
ASSERT_TRUE(total_addrs);
EXPECT_EQ(128, total_addrs->getInteger().first);
EXPECT_NO_THROW(total_addrs = stats_mgr.getObservation("subnet[42].assigned-addresses"));
ASSERT_TRUE(total_addrs);
EXPECT_EQ(0, total_addrs->getInteger().first);
EXPECT_NO_THROW(total_addrs = stats_mgr.getObservation("subnet[42].pool[0].assigned-addresses"));
ASSERT_TRUE(total_addrs);
EXPECT_EQ(0, total_addrs->getInteger().first);
}
// This test verifies that once the configuration is merged into the current
@@ -696,15 +710,22 @@ TEST_F(CfgMgrTest, clearStats4) {
// Let's prepare the "old" configuration: a subnet with id 123
// 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));
// Let's make pools with 128 addresses available in total.
PoolPtr pool1(new Pool4(IOAddress("192.1.2.0"), 26)); // 64 addrs
PoolPtr pool2(new Pool4(IOAddress("192.1.2.64"), 26)); // 64 addrs
subnet1->addPool(pool1);
subnet1->addPool(pool2);
CfgSubnets4Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets4();
subnets->add(subnet1);
cfg_mgr.commit();
stats_mgr.addValue("subnet[123].total-addresses", int64_t(256));
stats_mgr.setValue("subnet[123].assigned-addresses", static_cast<int64_t>(150));
stats_mgr.setValue("subnet[123].pool[0].assigned-addresses", static_cast<int64_t>(150));
// The stats should be there.
EXPECT_TRUE(stats_mgr.getObservation("subnet[123].total-addresses"));
EXPECT_TRUE(stats_mgr.getObservation("subnet[123].assigned-addresses"));
EXPECT_TRUE(stats_mgr.getObservation("subnet[123].pool[0].assigned-addresses"));
// Let's remove all configurations
cfg_mgr.clear();
@@ -712,6 +733,8 @@ TEST_F(CfgMgrTest, clearStats4) {
// The stats should not be there anymore.
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].total-addresses"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].assigned-addresses"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].pool[0].total-addresses"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].pool[0].assigned-addresses"));
}
// This test verifies that once the configuration is committed, statistics
@@ -738,11 +761,15 @@ TEST_F(CfgMgrTest, commitStats6) {
// There's a subnet 2001:db8:2::/48 with ID=42
Subnet6Ptr subnet2(new Subnet6(IOAddress("2001:db8:2::"), 48, 1, 2, 3, 4, 42));
// Let's make pools with 128 addresses and 65536 prefixes available.
PoolPtr pool1(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:2::"), 121)); // 128 addrs
PoolPtr pool2(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8:3::"), 96, 112)); // 65536 prefixes
// Let's make pools with 128 addresses in total and 65536 prefixes available in total.
PoolPtr pool1(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:2::"), 122)); // 64 addrs
PoolPtr pool2(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:2::1:0"), 122)); // 64 addrs
PoolPtr pool3(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8:3::"), 97, 112)); // 32768 prefixes
PoolPtr pool4(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8:3::8000:0"), 97, 112)); // 32768 prefixes
subnet2->addPool(pool1);
subnet2->addPool(pool2);
subnet2->addPool(pool3);
subnet2->addPool(pool4);
subnets = cfg_mgr.getStagingCfg()->getCfgSubnets6();
subnets->add(subnet2);
@@ -761,9 +788,13 @@ TEST_F(CfgMgrTest, commitStats6) {
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].total-nas"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].assigned-nas"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].pool[0].total-nas"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].pool[0].assigned-nas"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].total-pds"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].assigned-pds"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].pd-pool[0].total-pds"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].pd-pool[0].assigned-pds"));
ObservationPtr total_addrs;
EXPECT_NO_THROW(total_addrs = stats_mgr.getObservation("subnet[42].total-nas"));
@@ -773,6 +804,15 @@ TEST_F(CfgMgrTest, commitStats6) {
EXPECT_EQ(14, total_addrs->getMaxSampleCount().second);
EXPECT_FALSE(total_addrs->getMaxSampleAge().first);
EXPECT_EQ("00:00:10", durationToText(total_addrs->getMaxSampleAge().second, 0));
EXPECT_NO_THROW(total_addrs = stats_mgr.getObservation("subnet[42].pool[0].total-nas"));
ASSERT_TRUE(total_addrs);
EXPECT_EQ(128, total_addrs->getBigInteger().first);
EXPECT_NO_THROW(total_addrs = stats_mgr.getObservation("subnet[42].assigned-nas"));
ASSERT_TRUE(total_addrs);
EXPECT_EQ(0, total_addrs->getInteger().first);
EXPECT_NO_THROW(total_addrs = stats_mgr.getObservation("subnet[42].pool[0].assigned-nas"));
ASSERT_TRUE(total_addrs);
EXPECT_EQ(0, total_addrs->getInteger().first);
ObservationPtr total_prfx;
EXPECT_NO_THROW(total_prfx = stats_mgr.getObservation("subnet[42].total-pds"));
@@ -782,12 +822,20 @@ TEST_F(CfgMgrTest, commitStats6) {
EXPECT_EQ(14, total_prfx->getMaxSampleCount().second);
EXPECT_FALSE(total_prfx->getMaxSampleAge().first);
EXPECT_EQ("00:00:10", durationToText(total_prfx->getMaxSampleAge().second, 0));
EXPECT_NO_THROW(total_prfx = stats_mgr.getObservation("subnet[42].pd-pool[0].total-pds"));
ASSERT_TRUE(total_prfx);
EXPECT_EQ(65536, total_prfx->getBigInteger().first);
EXPECT_NO_THROW(total_prfx = stats_mgr.getObservation("subnet[42].assigned-pds"));
ASSERT_TRUE(total_prfx);
EXPECT_EQ(0, total_prfx->getInteger().first);
EXPECT_NO_THROW(total_prfx = stats_mgr.getObservation("subnet[42].pd-pool[0].assigned-pds"));
ASSERT_TRUE(total_prfx);
EXPECT_EQ(0, total_prfx->getInteger().first);
}
// This test verifies that once the configuration is merged into the current
// configuration, statistics are updated appropriately.
/// @todo Enable this test once merging v6 configuration is enabled.
TEST_F(CfgMgrTest, DISABLED_mergeIntoCurrentStats6) {
TEST_F(CfgMgrTest, mergeIntoCurrentStats6) {
CfgMgr& cfg_mgr = CfgMgr::instance();
StatsMgr& stats_mgr = StatsMgr::instance();
startBackend(AF_INET6);
@@ -798,10 +846,10 @@ TEST_F(CfgMgrTest, DISABLED_mergeIntoCurrentStats6) {
CfgSubnets6Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets6();
subnets->add(subnet1);
cfg_mgr.commit();
stats_mgr.addValue("subnet[123].total-nas", static_cast<int64_t>(256));
stats_mgr.addValue("subnet[123].total-nas", static_cast<int128_t>(256));
stats_mgr.setValue("subnet[123].assigned-nas", static_cast<int64_t>(150));
stats_mgr.addValue("subnet[123].total-pds", static_cast<int64_t>(256));
stats_mgr.addValue("subnet[123].total-pds", static_cast<int128_t>(256));
stats_mgr.setValue("subnet[123].assigned-pds", static_cast<int64_t>(150));
// There should be no stats for subnet 42 at this point.
@@ -834,6 +882,8 @@ TEST_F(CfgMgrTest, DISABLED_mergeIntoCurrentStats6) {
// Let's merge it.
cfg_mgr.mergeIntoCurrentCfg(external_cfg->getSequence());
// The stats should have been updated and so we should be able to get
// observations for subnet 42.
EXPECT_EQ(17, stats_mgr.getMaxSampleCountDefault());
EXPECT_EQ("00:00:04", durationToText(stats_mgr.getMaxSampleAgeDefault(), 0));
@@ -842,6 +892,7 @@ TEST_F(CfgMgrTest, DISABLED_mergeIntoCurrentStats6) {
EXPECT_TRUE(stats_mgr.getObservation("subnet[42].total-pds"));
EXPECT_TRUE(stats_mgr.getObservation("subnet[42].assigned-pds"));
// And also for 123
EXPECT_TRUE(stats_mgr.getObservation("subnet[123].total-nas"));
EXPECT_TRUE(stats_mgr.getObservation("subnet[123].assigned-nas"));
EXPECT_TRUE(stats_mgr.getObservation("subnet[123].total-pds"));
@@ -865,22 +916,31 @@ TEST_F(CfgMgrTest, clearStats6) {
// Let's prepare the "old" configuration: a subnet with id 123
// 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:2::"), 48, 1, 2, 3, 4, 123));
// Let's make pools with 128 addresses in total and 65536 prefixes available in total.
PoolPtr pool1(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:2::"), 122)); // 64 addrs
PoolPtr pool2(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:2:0:0:0:1:0"), 122)); // 64 addrs
PoolPtr pool3(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8:3::"), 97, 112)); // 32768 prefixes
PoolPtr pool4(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8:3::8000:0"), 97, 112)); // 32768 prefixes
subnet1->addPool(pool1);
subnet1->addPool(pool2);
subnet1->addPool(pool3);
subnet1->addPool(pool4);
CfgSubnets6Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets6();
subnets->add(subnet1);
cfg_mgr.commit();
stats_mgr.addValue("subnet[123].total-nas", static_cast<int64_t>(256));
stats_mgr.setValue("subnet[123].assigned-nas", static_cast<int64_t>(150));
stats_mgr.addValue("subnet[123].total-pds", static_cast<int64_t>(256));
stats_mgr.setValue("subnet[123].pool[0].assigned-nas", static_cast<int64_t>(150));
stats_mgr.setValue("subnet[123].assigned-pds", static_cast<int64_t>(150));
stats_mgr.setValue("subnet[123].pd-pool[0].assigned-pds", static_cast<int64_t>(150));
// The stats should be there.
EXPECT_TRUE(stats_mgr.getObservation("subnet[123].total-nas"));
EXPECT_TRUE(stats_mgr.getObservation("subnet[123].assigned-nas"));
EXPECT_TRUE(stats_mgr.getObservation("subnet[123].total-pds"));
EXPECT_TRUE(stats_mgr.getObservation("subnet[123].pool[0].assigned-nas"));
EXPECT_TRUE(stats_mgr.getObservation("subnet[123].assigned-pds"));
EXPECT_TRUE(stats_mgr.getObservation("subnet[123].pd-pool[0].assigned-pds"));
// Let's remove all configurations
cfg_mgr.clear();
@@ -888,9 +948,13 @@ TEST_F(CfgMgrTest, clearStats6) {
// The stats should not be there anymore.
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].total-nas"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].assigned-nas"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].pool[0].total-nas"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].pool[0].assigned-nas"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].total-pds"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].assigned-pds"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].pd-pool[0].total-pds"));
EXPECT_FALSE(stats_mgr.getObservation("subnet[123].pd-pool[0].assigned-pds"));
}
// This test verifies that the external configuration can be merged into