os << "[subnets " << first_subnet_id_
<< " through " << last_subnet_id_ << "]";
break;
+ default:
+ os << "unsupported";
}
return (os.str());
.startSubnetRangeLeaseStatsQuery4(params.first_subnet_id_,
params.last_subnet_id_);
break;
+ default:
+ return (0);
}
// Create the result-set map.
.startSubnetRangeLeaseStatsQuery6(params.first_subnet_id_,
params.last_subnet_id_);
break;
+ default:
+ return (0);
}
// Create the result-set map.
// Add(update) the extended information on the lease.
updateLease6ExtendedInfo(expired, ctx);
+ const auto& pool = ctx.subnet_->getPool(ctx.currentIA().type_, expired->addr_, false);
+ if (pool) {
+ expired->pool_id_ = pool->getID();
+ }
+
// for REQUEST we do update the lease
LeaseMgrFactory::instance().updateLease6(expired);
"cumulative-assigned-nas" : "cumulative-assigned-pds"),
static_cast<int64_t>(1));
- const auto& pool = ctx.subnet_->getPool(ctx.currentIA().type_,expired->addr_, false);
if (pool) {
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", ctx.subnet_->getID(),
// Add(update) the extended information on the lease.
updateLease6ExtendedInfo(lease, ctx);
+ const auto& pool = ctx.subnet_->getPool(ctx.currentIA().type_, lease->addr_, false);
+ if (pool) {
+ lease->pool_id_ = pool->getID();
+ }
+
// That is a real (REQUEST) allocation
bool status = LeaseMgrFactory::instance().addLease(lease);
"cumulative-assigned-nas" : "cumulative-assigned-pds"),
static_cast<int64_t>(1));
- const auto& pool = ctx.subnet_->getPool(ctx.currentIA().type_, lease->addr_, false);
if (pool) {
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", ctx.subnet_->getID(),
// Now that the lease has been reclaimed, we can go ahead and update it
// in the lease database.
if (lease->reuseable_valid_lft_ == 0) {
+ const auto& pool = ctx.subnet_->getPool(ctx.currentIA().type_, lease->addr_, false);
+ if (pool) {
+ lease->pool_id_ = pool->getID();
+ }
LeaseMgrFactory::instance().updateLease6(lease);
}
}
// Get the context appropriate lifetime.
- uint32_t valid_lft = (ctx.offer_lft_ ? ctx.offer_lft_ : getValidLft(ctx));
+ uint32_t valid_lft = (ctx.offer_lft_ ? ctx.offer_lft_ : getValidLft(ctx));
time_t now = time(NULL);
}
if (!ctx.fake_allocation_ || ctx.offer_lft_) {
+ const auto& pool = ctx.subnet_->getPool(Lease::TYPE_V4, lease->addr_, false);
+ if (pool) {
+ lease->pool_id_ = pool->getID();
+ }
// That is a real (REQUEST) allocation
bool status = LeaseMgrFactory::instance().addLease(lease);
if (status) {
"cumulative-assigned-addresses"),
static_cast<int64_t>(1));
- const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(ctx.subnet_->getID());
- if (subnet) {
- const auto& pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
- if (pool) {
- StatsMgr::instance().addValue(
- StatsMgr::generateName("subnet", subnet->getID(),
- StatsMgr::generateName(".pool", pool->getID(),
- "assigned-addresses")),
- static_cast<int64_t>(1));
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(1));
- StatsMgr::instance().addValue(
- StatsMgr::generateName("subnet", subnet->getID(),
- StatsMgr::generateName(".pool", pool->getID(),
- "cumulative-assigned-addresses")),
- static_cast<int64_t>(1));
- }
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "cumulative-assigned-addresses")),
+ static_cast<int64_t>(1));
}
StatsMgr::instance().addValue("cumulative-assigned-addresses",
setLeaseReusable(lease, ctx);
}
- if (!ctx.fake_allocation_ || ctx.offer_lft_) {
+ if (!ctx.fake_allocation_ || ctx.offer_lft_) {
// If the lease is expired we have to reclaim it before
// re-assigning it to the client. The lease reclamation
// involves execution of hooks and DNS update.
}
if ((!ctx.fake_allocation_ || ctx.offer_lft_) && !skip && (lease->reuseable_valid_lft_ == 0)) {
+ const auto& pool = ctx.subnet_->getPool(Lease::TYPE_V4, lease->addr_, false);
+ if (pool) {
+ lease->pool_id_ = pool->getID();
+ }
+
// for REQUEST we do update the lease
LeaseMgrFactory::instance().updateLease4(lease);
"cumulative-assigned-addresses"),
static_cast<int64_t>(1));
- const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(ctx.subnet_->getID());
- if (subnet) {
- const auto& pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
- if (pool) {
- StatsMgr::instance().addValue(
- StatsMgr::generateName("subnet", subnet->getID(),
- StatsMgr::generateName(".pool", pool->getID(),
- "assigned-addresses")),
- static_cast<int64_t>(1));
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(1));
- StatsMgr::instance().addValue(
- StatsMgr::generateName("subnet", subnet->getID(),
- StatsMgr::generateName(".pool", pool->getID(),
- "cumulative-assigned-addresses")),
- static_cast<int64_t>(1));
- }
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "cumulative-assigned-addresses")),
+ static_cast<int64_t>(1));
}
StatsMgr::instance().addValue("cumulative-assigned-addresses",
}
if (!ctx.fake_allocation_ || ctx.offer_lft_) {
+ const auto& pool = ctx.subnet_->getPool(Lease::TYPE_V4, expired->addr_, false);
+ if (pool) {
+ expired->pool_id_ = pool->getID();
+ }
// for REQUEST we do update the lease
LeaseMgrFactory::instance().updateLease4(expired);
"cumulative-assigned-addresses"),
static_cast<int64_t>(1));
- const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(ctx.subnet_->getID());
- if (subnet) {
- const auto& pool = subnet->getPool(Lease::TYPE_V4, expired->addr_, false);
- if (pool) {
- StatsMgr::instance().addValue(
- StatsMgr::generateName("subnet", subnet->getID(),
- StatsMgr::generateName(".pool", pool->getID(),
- "assigned-addresses")),
- static_cast<int64_t>(1));
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(1));
- StatsMgr::instance().addValue(
- StatsMgr::generateName("subnet", subnet->getID(),
- StatsMgr::generateName(".pool", pool->getID(),
- "cumulative-assigned-addresses")),
- static_cast<int64_t>(1));
- }
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "cumulative-assigned-addresses")),
+ static_cast<int64_t>(1));
}
StatsMgr::instance().addValue("cumulative-assigned-addresses",
to.current_valid_lft_ = from.valid_lft_;
}
-Lease4::Lease4(const Lease4& other)
- : Lease(other.addr_, other.valid_lft_,
- other.subnet_id_, other.cltt_, other.fqdn_fwd_,
- other.fqdn_rev_, other.hostname_, other.hwaddr_) {
-
- // Copy over fields derived from Lease.
- state_ = other.state_;
-
- // Copy the hardware address if it is defined.
- if (other.hwaddr_) {
- hwaddr_.reset(new HWAddr(*other.hwaddr_));
- } else {
- hwaddr_.reset();
- }
-
- if (other.client_id_) {
- client_id_.reset(new ClientId(other.client_id_->getClientId()));
- } else {
- client_id_.reset();
- }
-
- if (other.getContext()) {
- setContext(other.getContext());
- relay_id_ = other.relay_id_;
- remote_id_ = other.remote_id_;
- }
-}
-
Lease4::Lease4(const isc::asiolink::IOAddress& address,
const HWAddrPtr& hw_address,
const ClientIdPtr& client_id,
const bool fqdn_fwd,
const bool fqdn_rev,
const std::string& hostname)
-
: Lease(address, valid_lifetime, subnet_id, cltt, fqdn_fwd,
fqdn_rev, hostname, hw_address),
client_id_(client_id), remote_id_(), relay_id_() {
}
+Lease4::Lease4() : Lease(0, 0, 0, 0, false, false, "", HWAddrPtr()) {
+}
+
std::string
Lease4::statesToText(const uint32_t state) {
return (Lease::basicStatesToText(state));
valid_lft_ = probation_period;
}
-Lease4&
-Lease4::operator=(const Lease4& other) {
- if (this != &other) {
- addr_ = other.addr_;
- valid_lft_ = other.valid_lft_;
- current_valid_lft_ = other.current_valid_lft_;
- reuseable_valid_lft_ = other.reuseable_valid_lft_;
- cltt_ = other.cltt_;
- current_cltt_ = other.current_cltt_;
- subnet_id_ = other.subnet_id_;
- pool_id_ = other.pool_id_;
- hostname_ = other.hostname_;
- fqdn_fwd_ = other.fqdn_fwd_;
- fqdn_rev_ = other.fqdn_rev_;
- state_ = other.state_;
-
- // Copy the hardware address if it is defined.
- if (other.hwaddr_) {
- hwaddr_.reset(new HWAddr(*other.hwaddr_));
- } else {
- hwaddr_.reset();
- }
-
- if (other.client_id_) {
- client_id_.reset(new ClientId(other.client_id_->getClientId()));
- } else {
- client_id_.reset();
- }
-
- if (other.getContext()) {
- setContext(other.getContext());
- relay_id_ = other.relay_id_;
- remote_id_ = other.remote_id_;
- }
- }
- return (*this);
-}
-
isc::data::ElementPtr
Lease4::toElement() const {
// Prepare the map
/// @brief Default constructor
///
/// Initialize fields that don't have a default constructor.
- Lease4() : Lease(0, 0, 0, 0, false, false, "", HWAddrPtr())
- {
- }
-
- /// @brief Copy constructor
- ///
- /// @param other the @c Lease4 object to be copied.
- Lease4(const Lease4& other);
+ Lease4();
/// @brief Returns Lease type
///
bool belongsToClient(const HWAddrPtr& hw_address,
const ClientIdPtr& client_id) const;
- /// @brief Assignment operator.
- ///
- /// @param other the @c Lease4 object to be assigned.
- Lease4& operator=(const Lease4& other);
-
/// @brief Compare two leases for equality
///
/// @param other lease6 object with which to compare
using LeaseTPtr = boost::shared_ptr<LeaseT<D>>;
/// @}
-}; // end of isc::dhcp namespace
-}; // end of isc namespace
+} // end of isc::dhcp namespace
+} // end of isc namespace
#endif // LEASE_H
row.state_count_);
}
}
- // Can not update counters at pool level. This would require retrieving all
- // leases and matching them one by one to one possible pool.
+
+ query = startPoolLeaseStatsQuery4();
+ if (!query) {
+ /// NULL means not backend does not support recounting.
+ return;
+ }
+
+ // Get counts per state per subnet and pool. Iterate over the result set
+ // updating the subnet and pool and global values.
+ while (query->getNextRow(row)) {
+ if (row.lease_state_ == Lease::STATE_DEFAULT) {
+ // Add to subnet and pool level value.
+ stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
+ StatsMgr::generateName(".pool", row.pool_id_,
+ "assigned-addresses")),
+ row.state_count_);
+ } else if (row.lease_state_ == Lease::STATE_DECLINED) {
+ // Set subnet and pool level value.
+ stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
+ StatsMgr::generateName(".pool", row.pool_id_,
+ "declined-addresses")),
+ row.state_count_);
+
+ // Add to subnet and pool level value.
+ // Declined leases also count as assigned.
+ stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
+ StatsMgr::generateName(".pool", row.pool_id_,
+ "assigned-addresses")),
+ row.state_count_);
+ }
+ }
}
-LeaseStatsQuery::LeaseStatsQuery()
- : first_subnet_id_(0), last_subnet_id_(0), select_mode_(ALL_SUBNETS) {
+LeaseStatsQuery::LeaseStatsQuery(const SelectMode& select_mode)
+ : first_subnet_id_(0), last_subnet_id_(0), select_mode_(select_mode) {
+ if (select_mode != ALL_SUBNETS && select_mode != ALL_SUBNET_POOLS) {
+ isc_throw(BadValue, "LeaseStatsQuery: mode must be either ALL_SUBNETS or ALL_SUBNET_POOLS");
+ }
}
LeaseStatsQuery::LeaseStatsQuery(const SubnetID& subnet_id)
return(LeaseStatsQueryPtr());
}
+LeaseStatsQueryPtr
+LeaseMgr::startPoolLeaseStatsQuery4() {
+ return(LeaseStatsQueryPtr());
+}
+
LeaseStatsQueryPtr
LeaseMgr::startSubnetLeaseStatsQuery4(const SubnetID& /* subnet_id */) {
return(LeaseStatsQueryPtr());
break;
default:
- // We dont' support TYPE_TAs yet
+ // We don't support TYPE_TAs yet
+ break;
+ }
+ }
+
+ query = startPoolLeaseStatsQuery6();
+ if (!query) {
+ /// NULL means not backend does not support recounting.
+ return;
+ }
+
+ // Get counts per state per subnet and pool. Iterate over the result set
+ // updating the subnet and pool and global values.
+ while (query->getNextRow(row)) {
+ switch(row.lease_type_) {
+ case Lease::TYPE_NA:
+ if (row.lease_state_ == Lease::STATE_DEFAULT) {
+ // Add to subnet and pool level value.
+ stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
+ StatsMgr::generateName(".pool", row.pool_id_,
+ "assigned-nas")),
+ row.state_count_);
+ } else if (row.lease_state_ == Lease::STATE_DECLINED) {
+ // Set subnet and pool level value.
+ stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
+ StatsMgr::generateName(".pool", row.pool_id_,
+ "declined-addresses")),
+ row.state_count_);
+
+ // Add to subnet and pool level value.
+ // Declined leases also count as assigned.
+ stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
+ StatsMgr::generateName(".pool", row.pool_id_,
+ "assigned-nas")),
+ row.state_count_);
+ }
+ break;
+
+ case Lease::TYPE_PD:
+ if (row.lease_state_ == Lease::STATE_DEFAULT) {
+ // Set subnet and pool level value.
+ stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
+ StatsMgr::generateName(".pd-pool", row.pool_id_,
+ "assigned-pds")),
+ row.state_count_);
+ }
+ break;
+
+ default:
+ // We don't support TYPE_TAs yet
break;
}
}
- // Can not update counters at pool level. This would require retrieving all
- // leases and matching them one by one to one possible pool.
}
LeaseStatsQueryPtr
return(LeaseStatsQueryPtr());
}
+LeaseStatsQueryPtr
+LeaseMgr::startPoolLeaseStatsQuery6() {
+ return(LeaseStatsQueryPtr());
+}
+
LeaseStatsQueryPtr
LeaseMgr::startSubnetLeaseStatsQuery6(const SubnetID& /* subnet_id */) {
return(LeaseStatsQueryPtr());
struct LeaseStatsRow {
/// @brief Default constructor
LeaseStatsRow() :
- subnet_id_(0), lease_type_(Lease::TYPE_NA),
+ subnet_id_(0), pool_id_(0), lease_type_(Lease::TYPE_NA),
lease_state_(Lease::STATE_DEFAULT), state_count_(0) {
}
/// @param subnet_id The subnet id to which this data applies
/// @param lease_state The lease state counted
/// @param state_count The count of leases in the lease state
+ /// @param pool_id The pool id to which this data applies or 0 if it is not
+ /// used
LeaseStatsRow(const SubnetID& subnet_id, const uint32_t lease_state,
- const int64_t state_count)
- : subnet_id_(subnet_id), lease_type_(Lease::TYPE_NA),
+ const int64_t state_count, uint32_t pool_id = 0)
+ : subnet_id_(subnet_id), pool_id_(pool_id), lease_type_(Lease::TYPE_NA),
lease_state_(lease_state), state_count_(state_count) {
}
/// @param lease_type The lease type for this state count
/// @param lease_state The lease state counted
/// @param state_count The count of leases in the lease state
+ /// @param pool_id The pool id to which this data applies or 0 if it is not
+ /// used
LeaseStatsRow(const SubnetID& subnet_id, const Lease::Type& lease_type,
- const uint32_t lease_state, const int64_t state_count)
- : subnet_id_(subnet_id), lease_type_(lease_type),
+ const uint32_t lease_state, const int64_t state_count,
+ uint32_t pool_id = 0)
+ : subnet_id_(subnet_id), pool_id_(pool_id), lease_type_(lease_type),
lease_state_(lease_state), state_count_(state_count) {
}
}
if (subnet_id_ == rhs.subnet_id_ &&
+ pool_id_ < rhs.pool_id_) {
+ return (true);
+ }
+
+ if (subnet_id_ == rhs.subnet_id_ &&
+ pool_id_ == rhs.pool_id_ &&
lease_type_ < rhs.lease_type_) {
- return (true);
+ return (true);
}
if (subnet_id_ == rhs.subnet_id_ &&
+ pool_id_ == rhs.pool_id_ &&
lease_type_ == rhs.lease_type_ &&
lease_state_ < rhs.lease_state_) {
- return (true);
+ return (true);
}
return (false);
/// @brief The subnet ID to which this data applies
SubnetID subnet_id_;
+
+ /// @brief The pool ID to which this data applies
+ uint32_t pool_id_;
+
/// @brief The lease_type to which the count applies
Lease::Type lease_type_;
+
/// @brief The lease_state to which the count applies
uint32_t lease_state_;
+
/// @brief state_count The count of leases in the lease state
int64_t state_count_;
};
typedef enum {
ALL_SUBNETS,
SINGLE_SUBNET,
- SUBNET_RANGE
+ SUBNET_RANGE,
+ ALL_SUBNET_POOLS
} SelectMode;
- /// @brief Default constructor
+ /// @brief Constructor to query statistics for all subnets
+ ///
/// The query created will return statistics for all subnets
- LeaseStatsQuery();
+ ///
+ /// @param select_mode The selection criteria which is either ALL_SUBNETS or
+ /// ALL_SUBNET_POOLS
+ LeaseStatsQuery(const SelectMode& select_mode = ALL_SUBNETS);
/// @brief Constructor to query for a single subnet's stats
///
/// @return A populated LeaseStatsQuery
virtual LeaseStatsQueryPtr startLeaseStatsQuery4();
+ /// @brief Creates and runs the IPv4 lease stats query for all subnets and
+ /// pools
+ ///
+ /// LeaseMgr derivations implement this method such that it creates and
+ /// returns an instance of an LeaseStatsQuery whose result set has been
+ /// populated with up to date IPv4 lease statistical data for all subnets
+ /// and pools.
+ /// Each row of the result set is an LeaseStatRow which ordered ascending
+ /// by subnet ID and pool ID.
+ ///
+ /// @return A populated LeaseStatsQuery
+ virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery4();
+
/// @brief Creates and runs the IPv4 lease stats query for a single subnet
///
/// LeaseMgr derivations implement this method such that it creates and
/// @return A populated LeaseStatsQuery
virtual LeaseStatsQueryPtr startLeaseStatsQuery6();
+ /// @brief Creates and runs the IPv6 lease stats query for all subnets and
+ /// pools
+ ///
+ /// LeaseMgr derivations implement this method such that it creates and
+ /// returns an instance of an LeaseStatsQuery whose result set has been
+ /// populated with up to date IPv6 lease statistical data for all subnets
+ /// and pools.
+ /// Each row of the result set is an LeaseStatRow which ordered ascending
+ /// by subnet ID and pool ID.
+ ///
+ /// @return A populated LeaseStatsQuery
+ virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery6();
+
/// @brief Creates and runs the IPv6 lease stats query for a single subnet
///
/// LeaseMgr derivations implement this method such that it creates and
public:
/// @brief Constructor for all subnets query
///
- MemfileLeaseStatsQuery()
- : rows_(0), next_pos_(rows_.end()) {
+ /// @param select_mode The selection criteria which is either ALL_SUBNETS or
+ /// ALL_SUBNET_POOLS
+ MemfileLeaseStatsQuery(const SelectMode& select_mode = ALL_SUBNETS)
+ : LeaseStatsQuery(select_mode), rows_(0), next_pos_(rows_.end()) {
};
/// @brief Constructor for single subnet query
/// @brief Constructor for an all subnets query
///
/// @param storage4 A pointer to the v4 lease storage to be counted
- MemfileLeaseStatsQuery4(Lease4Storage& storage4)
- : MemfileLeaseStatsQuery(), storage4_(storage4) {
+ /// @param select_mode The selection criteria which is either ALL_SUBNETS or
+ /// ALL_SUBNET_POOLS
+ MemfileLeaseStatsQuery4(Lease4Storage& storage4,
+ const SelectMode& select_mode = ALL_SUBNETS)
+ : MemfileLeaseStatsQuery(select_mode), storage4_(storage4) {
};
/// @brief Constructor for a single subnet query
/// @brief Creates the IPv4 lease statistical data result set
///
/// The result set is populated by iterating over the IPv4 leases in
- /// storage, in ascending order by address, accumulating the lease state
+ /// storage, in ascending order by subnet id or by subnet id and pool id,
+ /// accumulating the lease state counts per subnet or per subnet and pool.
+ /// At the completion of all entries for a given subnet or pool, the counts
+ /// are used to create LeaseStatsRow instances which are appended to an
+ /// internal vector. The process results in a vector containing one entry
+ /// per state per subnet or per subnet and pool.
+ ///
+ /// Currently the states counted are:
+ ///
+ /// - Lease::STATE_DEFAULT (i.e. assigned)
+ /// - Lease::STATE_DECLINED
+ void start() {
+ switch (getSelectMode()) {
+ case ALL_SUBNETS:
+ case SINGLE_SUBNET:
+ case SUBNET_RANGE:
+ startSubnets();
+ break;
+
+ case ALL_SUBNET_POOLS:
+ startSubnetPools();
+ break;
+ }
+ }
+
+ /// @brief Creates the IPv4 lease statistical data result set
+ ///
+ /// The result set is populated by iterating over the IPv4 leases in
+ /// storage, in ascending order by subnet id, accumulating the lease state
/// counts per subnet.
/// At the completion of all entries for a given subnet, the counts are
/// used to create LeaseStatsRow instances which are appended to an
///
/// - Lease::STATE_DEFAULT (i.e. assigned)
/// - Lease::STATE_DECLINED
- void start() {
+ void startSubnets() {
const Lease4StorageSubnetIdIndex& idx
= storage4_.get<SubnetIdIndexTag>();
// Set lower and upper bounds based on select mode
Lease4StorageSubnetIdIndex::const_iterator lower;
Lease4StorageSubnetIdIndex::const_iterator upper;
+
switch (getSelectMode()) {
case ALL_SUBNETS:
lower = idx.begin();
lower = idx.lower_bound(getFirstSubnetID());
upper = idx.upper_bound(getLastSubnetID());
break;
+
+ default:
+ return;
}
// Return an empty set if there are no rows.
next_pos_ = rows_.begin();
}
+ /// @brief Creates the IPv4 lease statistical data result set
+ ///
+ /// The result set is populated by iterating over the IPv4 leases in
+ /// storage, in ascending order by subnet id and pool id, accumulating the
+ /// lease state counts per subnet and pool.
+ /// At the completion of all entries for a given subnet or pool, the counts
+ /// are used to create LeaseStatsRow instances which are appended to an
+ /// internal vector. The process results in a vector containing one entry
+ /// per state per subnet and pool.
+ ///
+ /// Currently the states counted are:
+ ///
+ /// - Lease::STATE_DEFAULT (i.e. assigned)
+ /// - Lease::STATE_DECLINED
+ void startSubnetPools() {
+ const Lease4StorageSubnetIdPoolIdIndex& idx
+ = storage4_.get<SubnetIdPoolIdIndexTag>();
+
+ // Set lower and upper bounds based on select mode
+ Lease4StorageSubnetIdPoolIdIndex::const_iterator lower;
+ Lease4StorageSubnetIdPoolIdIndex::const_iterator upper;
+
+ switch (getSelectMode()) {
+ case ALL_SUBNET_POOLS:
+ lower = idx.begin();
+ upper = idx.end();
+ break;
+
+ default:
+ return;
+ }
+
+ // Return an empty set if there are no rows.
+ if (lower == upper) {
+ return;
+ }
+
+ // Iterate over the leases in order by subnet and pool, accumulating per
+ // subnet and pool counts for each state of interest. As we finish each
+ // subnet or pool, add the appropriate rows to our result set.
+ SubnetID cur_id = 0;
+ uint32_t cur_pool_id = 0;
+ int64_t assigned = 0;
+ int64_t declined = 0;
+ for (Lease4StorageSubnetIdPoolIdIndex::const_iterator lease = lower;
+ lease != upper; ++lease) {
+ // If we've hit the next pool, add rows for the current subnet and
+ // pool and wipe the accumulators
+ if ((*lease)->pool_id_ != cur_pool_id) {
+ if (assigned > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id,
+ Lease::STATE_DEFAULT,
+ assigned, cur_pool_id));
+ assigned = 0;
+ }
+
+ if (declined > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id,
+ Lease::STATE_DECLINED,
+ declined, cur_pool_id));
+ declined = 0;
+ }
+
+ // Update current pool id
+ cur_pool_id = (*lease)->pool_id_;
+ }
+
+ // If we've hit the next subnet, add rows for the current subnet
+ // and wipe the accumulators
+ if ((*lease)->subnet_id_ != cur_id) {
+ if (cur_id > 0) {
+ if (assigned > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id,
+ Lease::STATE_DEFAULT,
+ assigned, cur_pool_id));
+ assigned = 0;
+ }
+
+ if (declined > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id,
+ Lease::STATE_DECLINED,
+ declined, cur_pool_id));
+ declined = 0;
+ }
+ }
+
+ // Update current subnet id
+ cur_id = (*lease)->subnet_id_;
+
+ // Reset pool id
+ cur_pool_id = 0;
+ }
+
+ // Bump the appropriate accumulator
+ if ((*lease)->state_ == Lease::STATE_DEFAULT) {
+ ++assigned;
+ } else if ((*lease)->state_ == Lease::STATE_DECLINED) {
+ ++declined;
+ }
+ }
+
+ // Make the rows for last subnet
+ if (assigned > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::STATE_DEFAULT,
+ assigned, cur_pool_id));
+ }
+
+ if (declined > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::STATE_DECLINED,
+ declined, cur_pool_id));
+ }
+
+ // Reset the next row position back to the beginning of the rows.
+ next_pos_ = rows_.begin();
+ }
+
private:
/// @brief The Memfile storage containing the IPv4 leases to analyze
Lease4Storage& storage4_;
/// @brief Constructor
///
/// @param storage6 A pointer to the v6 lease storage to be counted
- MemfileLeaseStatsQuery6(Lease6Storage& storage6)
- : MemfileLeaseStatsQuery(), storage6_(storage6) {
+ /// @param select_mode The selection criteria which is either ALL_SUBNETS or
+ /// ALL_SUBNET_POOLS
+ MemfileLeaseStatsQuery6(Lease6Storage& storage6,
+ const SelectMode& select_mode = ALL_SUBNETS)
+ : MemfileLeaseStatsQuery(select_mode), storage6_(storage6) {
};
/// @brief Constructor for a single subnet query
/// @brief Destructor
virtual ~MemfileLeaseStatsQuery6() {};
+ /// @brief Creates the IPv6 lease statistical data result set
+ ///
+ /// The result set is populated by iterating over the IPv6 leases in
+ /// storage, in ascending order by subnet id or by subnet id and pool id,
+ /// accumulating the lease state counts per subnet or per subnet and pool.
+ /// At the completion of all entries for a given subnet or pool, the counts
+ /// are used to create LeaseStatsRow instances which are appended to an
+ /// internal vector. The process results in a vector containing one entry
+ /// per state per subnet or per subnet and pool.
+ ///
+ /// Currently the states counted are:
+ ///
+ /// - Lease::STATE_DEFAULT (i.e. assigned)
+ /// - Lease::STATE_DECLINED
+ void start() {
+ switch (getSelectMode()) {
+ case ALL_SUBNETS:
+ case SINGLE_SUBNET:
+ case SUBNET_RANGE:
+ startSubnets();
+ break;
+
+ case ALL_SUBNET_POOLS:
+ startSubnetPools();
+ break;
+ }
+ }
+
/// @brief Creates the IPv6 lease statistical data result set
///
/// The result set is populated by iterating over the IPv6 leases in
/// storage, in ascending order by subnet id, accumulating the lease state
- /// counts per subnet. At the completion of all entries for a given subnet,
- /// the counts are used to create LeaseStatsRow instances which are appended
- /// to an internal vector. The process results in a vector containing one
- /// entry per state per lease type per subnet.
+ /// counts per subnet.
+ /// At the completion of all entries for a given subnet, the counts are
+ /// used to create LeaseStatsRow instances which are appended to an
+ /// internal vector. The process results in a vector containing one entry
+ /// per state per subnet.
///
/// Currently the states counted are:
///
/// - Lease::STATE_DEFAULT (i.e. assigned)
/// - Lease::STATE_DECLINED
- virtual void start() {
+ virtual void startSubnets() {
// Get the subnet_id index
const Lease6StorageSubnetIdIndex& idx
= storage6_.get<SubnetIdIndexTag>();
lower = idx.lower_bound(getFirstSubnetID());
upper = idx.upper_bound(getLastSubnetID());
break;
+
+ default:
+ return;
}
// Return an empty set if there are no rows.
next_pos_ = rows_.begin();
}
+ /// @brief Creates the IPv6 lease statistical data result set
+ ///
+ /// The result set is populated by iterating over the IPv6 leases in
+ /// storage, in ascending order by subnet id and pool id, accumulating the
+ /// lease state counts per subnet and pool.
+ /// At the completion of all entries for a given subnet or pool, the counts
+ /// are used to create LeaseStatsRow instances which are appended to an
+ /// internal vector. The process results in a vector containing one entry
+ /// per state per subnet and pool.
+ ///
+ /// Currently the states counted are:
+ ///
+ /// - Lease::STATE_DEFAULT (i.e. assigned)
+ /// - Lease::STATE_DECLINED
+ virtual void startSubnetPools() {
+ // Get the subnet_id index
+ const Lease6StorageSubnetIdPoolIdIndex& idx
+ = storage6_.get<SubnetIdPoolIdIndexTag>();
+
+ // Set lower and upper bounds based on select mode
+ Lease6StorageSubnetIdPoolIdIndex::const_iterator lower;
+ Lease6StorageSubnetIdPoolIdIndex::const_iterator upper;
+ switch (getSelectMode()) {
+ case ALL_SUBNET_POOLS:
+ lower = idx.begin();
+ upper = idx.end();
+ break;
+
+ default:
+ return;
+ }
+
+ // Return an empty set if there are no rows.
+ if (lower == upper) {
+ return;
+ }
+
+ // Iterate over the leases in order by subnet, accumulating per
+ // subnet counts for each state of interest. As we finish each
+ // subnet, add the appropriate rows to our result set.
+ SubnetID cur_id = 0;
+ uint32_t cur_pool_id = 0;
+ int64_t assigned = 0;
+ int64_t declined = 0;
+ int64_t assigned_pds = 0;
+ for (Lease6StorageSubnetIdPoolIdIndex::const_iterator lease = lower;
+ lease != upper; ++lease) {
+ // If we've hit the next pool, add rows for the current subnet and
+ // pool and wipe the accumulators
+ if ((*lease)->pool_id_ != cur_pool_id) {
+ if (assigned > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA,
+ Lease::STATE_DEFAULT,
+ assigned, cur_pool_id));
+ assigned = 0;
+ }
+
+ if (declined > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA,
+ Lease::STATE_DECLINED,
+ declined, cur_pool_id));
+ declined = 0;
+ }
+
+ if (assigned_pds > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_PD,
+ Lease::STATE_DEFAULT,
+ assigned_pds, cur_pool_id));
+ assigned_pds = 0;
+ }
+
+ // Update current pool id
+ cur_pool_id = (*lease)->pool_id_;
+ }
+
+ // If we've hit the next subnet, add rows for the current subnet
+ // and wipe the accumulators
+ if ((*lease)->subnet_id_ != cur_id) {
+ if (cur_id > 0) {
+ if (assigned > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA,
+ Lease::STATE_DEFAULT,
+ assigned, cur_pool_id));
+ assigned = 0;
+ }
+
+ if (declined > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA,
+ Lease::STATE_DECLINED,
+ declined, cur_pool_id));
+ declined = 0;
+ }
+
+ if (assigned_pds > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_PD,
+ Lease::STATE_DEFAULT,
+ assigned_pds, cur_pool_id));
+ assigned_pds = 0;
+ }
+ }
+
+ // Update current subnet id
+ cur_id = (*lease)->subnet_id_;
+
+ // Reset pool id
+ cur_pool_id = 0;
+ }
+
+ // Bump the appropriate accumulator
+ if ((*lease)->state_ == Lease::STATE_DEFAULT) {
+ switch((*lease)->type_) {
+ case Lease::TYPE_NA:
+ ++assigned;
+ break;
+ case Lease::TYPE_PD:
+ ++assigned_pds;
+ break;
+ default:
+ break;
+ }
+ } else if ((*lease)->state_ == Lease::STATE_DECLINED) {
+ // In theory only NAs can be declined
+ if (((*lease)->type_) == Lease::TYPE_NA) {
+ ++declined;
+ }
+ }
+ }
+
+ // Make the rows for last subnet, unless there were no rows
+ if (assigned > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA,
+ Lease::STATE_DEFAULT, assigned,
+ cur_pool_id));
+ }
+
+ if (declined > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA,
+ Lease::STATE_DECLINED, declined,
+ cur_pool_id));
+ }
+
+ if (assigned_pds > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_PD,
+ Lease::STATE_DEFAULT, assigned_pds,
+ cur_pool_id));
+ }
+
+ // Set the next row position to the beginning of the rows.
+ next_pos_ = rows_.begin();
+ }
+
private:
/// @brief The Memfile storage containing the IPv6 leases to analyze
Lease6Storage& storage6_;
return(query);
}
+LeaseStatsQueryPtr
+Memfile_LeaseMgr::startPoolLeaseStatsQuery4() {
+ LeaseStatsQueryPtr query(new MemfileLeaseStatsQuery4(storage4_, LeaseStatsQuery::ALL_SUBNET_POOLS));
+ if (MultiThreadingMgr::instance().getMode()) {
+ std::lock_guard<std::mutex> lock(*mutex_);
+ query->start();
+ } else {
+ query->start();
+ }
+
+ return(query);
+}
+
LeaseStatsQueryPtr
Memfile_LeaseMgr::startSubnetLeaseStatsQuery4(const SubnetID& subnet_id) {
LeaseStatsQueryPtr query(new MemfileLeaseStatsQuery4(storage4_, subnet_id));
return(query);
}
+LeaseStatsQueryPtr
+Memfile_LeaseMgr::startPoolLeaseStatsQuery6() {
+ LeaseStatsQueryPtr query(new MemfileLeaseStatsQuery6(storage6_, LeaseStatsQuery::ALL_SUBNET_POOLS));
+ if (MultiThreadingMgr::instance().getMode()) {
+ std::lock_guard<std::mutex> lock(*mutex_);
+ query->start();
+ } else {
+ query->start();
+ }
+
+ return(query);
+}
+
LeaseStatsQueryPtr
Memfile_LeaseMgr::startSubnetLeaseStatsQuery6(const SubnetID& subnet_id) {
LeaseStatsQueryPtr query(new MemfileLeaseStatsQuery6(storage6_, subnet_id));
/// @return The populated query as a pointer to an LeaseStatsQuery
virtual LeaseStatsQueryPtr startLeaseStatsQuery4() override;
+ /// @brief Creates and runs the IPv4 lease stats query for all subnets and
+ /// pools
+ ///
+ /// LeaseMgr derivations implement this method such that it creates and
+ /// returns an instance of an LeaseStatsQuery whose result set has been
+ /// populated with up to date IPv4 lease statistical data for all subnets
+ /// and pools.
+ /// Each row of the result set is an LeaseStatRow which ordered ascending
+ /// by subnet ID and pool ID.
+ ///
+ /// @return A populated LeaseStatsQuery
+ virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery4() override;
+
/// @brief Creates and runs the IPv4 lease stats query for a single subnet
///
/// It creates an instance of a MemfileLeaseStatsQuery4 for a single subnet
/// @return The populated query as a pointer to an LeaseStatsQuery.
virtual LeaseStatsQueryPtr startLeaseStatsQuery6() override;
+ /// @brief Creates and runs the IPv6 lease stats query for all subnets and
+ /// pools
+ ///
+ /// LeaseMgr derivations implement this method such that it creates and
+ /// returns an instance of an LeaseStatsQuery whose result set has been
+ /// populated with up to date IPv6 lease statistical data for all subnets
+ /// and pools.
+ /// Each row of the result set is an LeaseStatRow which ordered ascending
+ /// by subnet ID and pool ID.
+ ///
+ /// @return A populated LeaseStatsQuery
+ virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery6() override;
+
/// @brief Creates and runs the IPv6 lease stats query for a single subnet
///
/// It creates an instance of a MemfileLeaseStatsQuery6 for a single subnet
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE address > ? AND user_context IS NOT NULL "
"ORDER BY address "
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE address > ? AND user_context IS NOT NULL "
"ORDER BY address "
"FROM lease4_stat "
"WHERE subnet_id >= ? and subnet_id <= ? "
"ORDER BY subnet_id, state"},
+ {MySqlLeaseMgr::ALL_POOL_LEASE4_STATS,
+ "SELECT subnet_id, pool_id, state, leases as state_count "
+ "FROM lease4_pool_stat ORDER BY subnet_id, pool_id, state"},
{MySqlLeaseMgr::ALL_LEASE6_STATS,
"SELECT subnet_id, lease_type, state, leases as state_count "
"FROM lease6_stat ORDER BY subnet_id, lease_type, state"},
"FROM lease6_stat "
"WHERE subnet_id >= ? and subnet_id <= ? "
"ORDER BY subnet_id, lease_type, state"},
- {MySqlLeaseMgr::CHECK_LEASE4_LIMITS, "SELECT checkLease4Limits(?)"},
- {MySqlLeaseMgr::CHECK_LEASE6_LIMITS, "SELECT checkLease6Limits(?)"},
- {MySqlLeaseMgr::IS_JSON_SUPPORTED, "SELECT isJsonSupported()"},
+ {MySqlLeaseMgr::ALL_POOL_LEASE6_STATS,
+ "SELECT subnet_id, pool_id, lease_type, state, leases as state_count "
+ "FROM lease6_pool_stat ORDER BY subnet_id, pool_id, lease_type, state"},
+ {MySqlLeaseMgr::CHECK_LEASE4_LIMITS,
+ "SELECT checkLease4Limits(?)"},
+ {MySqlLeaseMgr::CHECK_LEASE6_LIMITS,
+ "SELECT checkLease6Limits(?)"},
+ {MySqlLeaseMgr::IS_JSON_SUPPORTED,
+ "SELECT isJsonSupported()"},
{MySqlLeaseMgr::GET_LEASE4_COUNT_BY_CLASS,
"SELECT leases "
"FROM lease4_stat_by_client_class "
/// @param conn An open connection to the database housing the lease data
/// @param statement_index Index of the query's prepared statement
/// @param fetch_type Indicates if query supplies lease type
+ /// @param fetch_pool Indicates if query requires pool data
/// @throw if statement index is invalid.
MySqlLeaseStatsQuery(MySqlConnection& conn, const size_t statement_index,
- const bool fetch_type)
+ const bool fetch_type, const bool fetch_pool = false)
: conn_(conn), statement_index_(statement_index), statement_(NULL),
- fetch_type_(fetch_type),
+ fetch_type_(fetch_type), fetch_pool_(fetch_pool),
// Set the number of columns in the bind array based on fetch_type
// This is the number of columns expected in the result set
- bind_(fetch_type_ ? 4 : 3),
- subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
+ bind_(fetch_type_ ? (fetch_pool_ ? 5 : 4) : (fetch_pool_ ? 4 : 3)),
+ subnet_id_(0), pool_id_(0), lease_type_(Lease::TYPE_NA),
+ state_(Lease::STATE_DEFAULT), state_count_(0) {
validateStatement();
}
MySqlLeaseStatsQuery(MySqlConnection& conn, const size_t statement_index,
const bool fetch_type, const SubnetID& subnet_id)
: LeaseStatsQuery(subnet_id), conn_(conn), statement_index_(statement_index),
- statement_(NULL), fetch_type_(fetch_type),
+ statement_(NULL), fetch_type_(fetch_type), fetch_pool_(false),
// Set the number of columns in the bind array based on fetch_type
// This is the number of columns expected in the result set
- bind_(fetch_type_ ? 4 : 3),
- subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
+ bind_(fetch_type_ ? 4 : 3), subnet_id_(0), pool_id_(0),
+ lease_type_(Lease::TYPE_NA), state_(Lease::STATE_DEFAULT),
+ state_count_(0) {
validateStatement();
}
const bool fetch_type, const SubnetID& first_subnet_id,
const SubnetID& last_subnet_id)
: LeaseStatsQuery(first_subnet_id, last_subnet_id), conn_(conn),
- statement_index_(statement_index), statement_(NULL), fetch_type_(fetch_type),
+ statement_index_(statement_index), statement_(NULL),
+ fetch_type_(fetch_type), fetch_pool_(false),
// Set the number of columns in the bind array based on fetch_type
// This is the number of columns expected in the result set
- bind_(fetch_type_ ? 4 : 3),
- subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
+ bind_(fetch_type_ ? 4 : 3), subnet_id_(0), pool_id_(0),
+ lease_type_(Lease::TYPE_NA), state_(Lease::STATE_DEFAULT),
+ state_count_(0) {
validateStatement();
}
/// entire result set.
void start() {
// Set up where clause inputs if needed.
- if (getSelectMode() != ALL_SUBNETS) {
+ if (getSelectMode() != ALL_SUBNETS && getSelectMode() != ALL_SUBNET_POOLS) {
MYSQL_BIND inbind[2];
memset(inbind, 0, sizeof(inbind));
bind_[col].is_unsigned = MLM_TRUE;
++col;
+ // Fetch the pool id if we were told to do so.
+ if (fetch_pool_) {
+ // pool id: uint32_t
+ bind_[col].buffer_type = MYSQL_TYPE_LONG;
+ bind_[col].buffer = reinterpret_cast<char*>(&pool_id_);
+ bind_[col].is_unsigned = MLM_TRUE;
+ ++col;
+ }
+
// Fetch the lease type if we were told to do so.
if (fetch_type_) {
// lease type: uint32_t
int status = mysql_stmt_fetch(statement_);
if (status == MLM_MYSQL_FETCH_SUCCESS) {
row.subnet_id_ = static_cast<SubnetID>(subnet_id_);
+ row.pool_id_ = pool_id_;
row.lease_type_ = static_cast<Lease::Type>(lease_type_);
row.lease_state_ = state_;
if (state_count_ >= 0) {
/// @brief Indicates if query supplies lease type
bool fetch_type_;
+ /// @brief Indicates if query requires pool data
+ bool fetch_pool_;
+
/// @brief Bind array used to store the query result set;
std::vector<MYSQL_BIND> bind_;
/// @brief Receives subnet ID when fetching a row
uint32_t subnet_id_;
+ /// @brief Receives pool ID when fetching a row
+ uint32_t pool_id_;
+
/// @brief Receives the lease type when fetching a row
uint32_t lease_type_;
return(query);
}
+LeaseStatsQueryPtr
+MySqlLeaseMgr::startPoolLeaseStatsQuery4() {
+ // Get a context
+ MySqlLeaseContextAlloc get_context(*this);
+ MySqlLeaseContextPtr ctx = get_context.ctx_;
+
+ LeaseStatsQueryPtr query(new MySqlLeaseStatsQuery(ctx->conn_,
+ ALL_POOL_LEASE4_STATS,
+ false, true));
+ query->start();
+ return(query);
+}
+
LeaseStatsQueryPtr
MySqlLeaseMgr::startSubnetLeaseStatsQuery4(const SubnetID& subnet_id) {
// Get a context
return(query);
}
+LeaseStatsQueryPtr
+MySqlLeaseMgr::startPoolLeaseStatsQuery6() {
+ // Get a context
+ MySqlLeaseContextAlloc get_context(*this);
+ MySqlLeaseContextPtr ctx = get_context.ctx_;
+
+ LeaseStatsQueryPtr query(new MySqlLeaseStatsQuery(ctx->conn_,
+ ALL_POOL_LEASE6_STATS,
+ true, true));
+ query->start();
+ return(query);
+}
+
LeaseStatsQueryPtr
MySqlLeaseMgr::startSubnetLeaseStatsQuery6(const SubnetID& subnet_id) {
// Get a context
/// @return The populated query as a pointer to an LeaseStatsQuery
virtual LeaseStatsQueryPtr startLeaseStatsQuery4() override;
+ /// @brief Creates and runs the IPv4 lease stats query for all subnets and
+ /// pools
+ ///
+ /// LeaseMgr derivations implement this method such that it creates and
+ /// returns an instance of an LeaseStatsQuery whose result set has been
+ /// populated with up to date IPv4 lease statistical data for all subnets
+ /// and pools.
+ /// Each row of the result set is an LeaseStatRow which ordered ascending
+ /// by subnet ID and pool ID.
+ ///
+ /// @return A populated LeaseStatsQuery
+ virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery4() override;
+
/// @brief Creates and runs the IPv4 lease stats query for a single subnet
///
/// It creates an instance of a MySqlLeaseStatsQuery4 for a single subnet
/// @return The populated query as a pointer to an LeaseStatsQuery
virtual LeaseStatsQueryPtr startLeaseStatsQuery6() override;
+ /// @brief Creates and runs the IPv6 lease stats query for all subnets and
+ /// pools
+ ///
+ /// LeaseMgr derivations implement this method such that it creates and
+ /// returns an instance of an LeaseStatsQuery whose result set has been
+ /// populated with up to date IPv6 lease statistical data for all subnets
+ /// and pools.
+ /// Each row of the result set is an LeaseStatRow which ordered ascending
+ /// by subnet ID and pool ID.
+ ///
+ /// @return A populated LeaseStatsQuery
+ virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery6() override;
+
/// @brief Creates and runs the IPv6 lease stats query for a single subnet
///
/// It creates an instance of a MySqlLeaseStatsQuery6 for a single subnet
ALL_LEASE4_STATS, // Fetches IPv4 lease statistics
SUBNET_LEASE4_STATS, // Fetched IPv4 lease stats for a single subnet.
SUBNET_RANGE_LEASE4_STATS, // Fetched IPv4 lease stats for a subnet range.
+ ALL_POOL_LEASE4_STATS, // Fetches IPv4 lease pool statistics
ALL_LEASE6_STATS, // Fetches IPv6 lease statistics
SUBNET_LEASE6_STATS, // Fetched IPv6 lease stats for a single subnet.
SUBNET_RANGE_LEASE6_STATS, // Fetched IPv6 lease stats for a subnet range.
+ ALL_POOL_LEASE6_STATS, // Fetches IPv6 lease pool statistics
CHECK_LEASE4_LIMITS, // Check if allocated IPv4 leases are inside the set limits.
CHECK_LEASE6_LIMITS, // Check if allocated IPv6 leases are inside the set limits.
IS_JSON_SUPPORTED, // Checks if JSON support is enabled in the database.
// DELETE_LEASE4
{ 2, { OID_INT8, OID_TIMESTAMP },
"delete_lease4",
- "DELETE FROM lease4 WHERE address = $1 AND expire = $2"},
+ "DELETE FROM lease4 WHERE address = $1 AND expire = $2" },
// DELETE_LEASE4_STATE_EXPIRED
{ 2, { OID_INT8, OID_TIMESTAMP },
"delete_lease4_state_expired",
"DELETE FROM lease4 "
- "WHERE state = $1 AND expire < $2"},
+ "WHERE state = $1 AND expire < $2" },
// DELETE_LEASE6
{ 2, { OID_VARCHAR, OID_TIMESTAMP },
"delete_lease6",
- "DELETE FROM lease6 WHERE address = $1 AND expire = $2"},
+ "DELETE FROM lease6 WHERE address = $1 AND expire = $2" },
// DELETE_LEASE6_STATE_EXPIRED
{ 2, { OID_INT8, OID_TIMESTAMP },
"delete_lease6_state_expired",
"DELETE FROM lease6 "
- "WHERE state = $1 AND expire < $2"},
+ "WHERE state = $1 AND expire < $2" },
// GET_LEASE4
{ 0, { OID_NONE },
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
"state, user_context, relay_id, remote_id, pool_id "
- "FROM lease4"},
+ "FROM lease4" },
// GET_LEASE4_ADDR
{ 1, { OID_INT8 },
"fqdn_fwd, fqdn_rev, hostname, "
"state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
- "WHERE address = $1"},
+ "WHERE address = $1" },
// GET_LEASE4_CLIENTID
{ 1, { OID_BYTEA },
"fqdn_fwd, fqdn_rev, hostname, "
"state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
- "WHERE client_id = $1"},
+ "WHERE client_id = $1" },
// GET_LEASE4_CLIENTID_SUBID
{ 2, { OID_BYTEA, OID_INT8 },
"fqdn_fwd, fqdn_rev, hostname, "
"state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
- "WHERE client_id = $1 AND subnet_id = $2"},
+ "WHERE client_id = $1 AND subnet_id = $2" },
// GET_LEASE4_HWADDR
{ 1, { OID_BYTEA },
"fqdn_fwd, fqdn_rev, hostname, "
"state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
- "WHERE hwaddr = $1"},
+ "WHERE hwaddr = $1" },
// GET_LEASE4_HWADDR_SUBID
{ 2, { OID_BYTEA, OID_INT8 },
"fqdn_fwd, fqdn_rev, hostname, "
"state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
- "WHERE hwaddr = $1 AND subnet_id = $2"},
+ "WHERE hwaddr = $1 AND subnet_id = $2" },
// GET_LEASE4_PAGE
{ 2, { OID_INT8, OID_INT8 },
"FROM lease4 "
"WHERE address > $1 "
"ORDER BY address "
- "LIMIT $2"},
+ "LIMIT $2" },
// GET_LEASE4_UCTX_PAGE
{ 2, { OID_INT8, OID_INT8 },
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE address > $1 AND user_context IS NOT NULL "
"ORDER BY address "
"fqdn_fwd, fqdn_rev, hostname, "
"state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
- "WHERE subnet_id = $1"},
+ "WHERE subnet_id = $1" },
// GET_LEASE4_HOSTNAME
{ 1, { OID_VARCHAR },
"fqdn_fwd, fqdn_rev, hostname, "
"state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
- "WHERE lower(hostname) = $1"},
+ "WHERE lower(hostname) = $1" },
// GET_LEASE4_EXPIRE
{ 3, { OID_INT8, OID_TIMESTAMP, OID_INT8 },
"FROM lease4 "
"WHERE state != $1 AND valid_lifetime != 4294967295 AND expire < $2 "
"ORDER BY expire "
- "LIMIT $3"},
+ "LIMIT $3" },
// GET_LEASE4_RELAYID
{ 3, { OID_BYTEA, OID_INT8, OID_INT8 },
"FROM lease4 "
"WHERE relay_id = $1 and address > $2 "
"ORDER BY address "
- "LIMIT $3"},
+ "LIMIT $3" },
// GET_LEASE4_RELAYID_QST
{ 4, { OID_BYTEA, OID_INT8, OID_INT8, OID_INT8 },
"and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
"THEN 0 ELSE valid_lifetime END) >= $3 "
"ORDER BY address "
- "LIMIT $4"},
+ "LIMIT $4" },
// GET_LEASE4_RELAYID_QSET
{ 5, { OID_BYTEA, OID_INT8, OID_INT8, OID_INT8, OID_INT8 },
"and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
"THEN 0 ELSE valid_lifetime END) <= $4 "
"ORDER BY address "
- "LIMIT $5"},
+ "LIMIT $5" },
// GET_LEASE4_RELAYID_QET
{ 4, { OID_BYTEA, OID_INT8, OID_INT8, OID_INT8 },
"and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
"THEN 0 ELSE valid_lifetime END) <= $3 "
"ORDER BY address "
- "LIMIT $4"},
+ "LIMIT $4" },
// GET_LEASE4_REMOTEID
{ 3, { OID_BYTEA, OID_INT8, OID_INT8 },
"FROM lease4 "
"WHERE remote_id = $1 and address > $2 "
"ORDER BY address "
- "LIMIT $3"},
+ "LIMIT $3" },
// GET_LEASE4_REMOTEID_QST
{ 4, { OID_BYTEA, OID_INT8, OID_INT8, OID_INT8 },
"and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
"THEN 0 ELSE valid_lifetime END) >= $3 "
"ORDER BY address "
- "LIMIT $4"},
+ "LIMIT $4" },
// GET_LEASE4_REMOTEID_QSET
{ 5, { OID_BYTEA, OID_INT8, OID_INT8, OID_INT8, OID_INT8 },
"and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
"THEN 0 ELSE valid_lifetime END) <= $4 "
"ORDER BY address "
- "LIMIT $5"},
+ "LIMIT $5" },
// GET_LEASE4_REMOTEID_QET
{ 4, { OID_BYTEA, OID_INT8, OID_INT8, OID_INT8 },
"and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
"THEN 0 ELSE valid_lifetime END) <= $3 "
"ORDER BY address "
- "LIMIT $4"},
+ "LIMIT $4" },
// GET_LEASE6
{ 0, { OID_NONE },
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
"state, user_context, pool_id "
- "FROM lease6"},
+ "FROM lease6" },
// GET_LEASE6_ADDR
{ 2, { OID_VARCHAR, OID_INT2 },
"hwaddr, hwtype, hwaddr_source, "
"state, user_context, pool_id "
"FROM lease6 "
- "WHERE address = $1 AND lease_type = $2"},
+ "WHERE address = $1 AND lease_type = $2" },
// GET_LEASE6_DUID_IAID
{ 3, { OID_BYTEA, OID_INT8, OID_INT2 },
"hwaddr, hwtype, hwaddr_source, "
"state, user_context, pool_id "
"FROM lease6 "
- "WHERE duid = $1 AND iaid = $2 AND lease_type = $3"},
+ "WHERE duid = $1 AND iaid = $2 AND lease_type = $3" },
// GET_LEASE6_DUID_IAID_SUBID
{ 4, { OID_INT2, OID_BYTEA, OID_INT8, OID_INT8 },
"state, user_context, pool_id "
"FROM lease6 "
"WHERE lease_type = $1 "
- "AND duid = $2 AND iaid = $3 AND subnet_id = $4"},
+ "AND duid = $2 AND iaid = $3 AND subnet_id = $4" },
// GET_LEASE6_PAGE
{ 2, { OID_VARCHAR, OID_INT8 },
"FROM lease6 "
"WHERE address > $1 "
"ORDER BY address "
- "LIMIT $2"},
+ "LIMIT $2" },
// GET_LEASE6_UCTX_PAGE
{ 2, { OID_VARCHAR, OID_INT8 },
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE address > $1 AND user_context IS NOT NULL "
"ORDER BY address "
"hwaddr, hwtype, hwaddr_source, "
"state, user_context, pool_id "
"FROM lease6 "
- "WHERE subnet_id = $1"},
+ "WHERE subnet_id = $1" },
// GET_LEASE6_DUID
{ 1, { OID_BYTEA },
"hwaddr, hwtype, hwaddr_source, "
"state, user_context, pool_id "
"FROM lease6 "
- "WHERE duid = $1"},
+ "WHERE duid = $1" },
// GET_LEASE6_HOSTNAME
{ 1, { OID_VARCHAR },
"hwaddr, hwtype, hwaddr_source, "
"state, user_context, pool_id "
"FROM lease6 "
- "WHERE lower(hostname) = $1"},
+ "WHERE lower(hostname) = $1" },
// GET_LEASE6_EXPIRE
{ 3, { OID_INT8, OID_TIMESTAMP, OID_INT8 },
"FROM lease6 "
"WHERE state != $1 AND valid_lifetime != 4294967295 AND expire < $2 "
"ORDER BY expire "
- "LIMIT $3"},
+ "LIMIT $3" },
// GET_LEASE6_LINK
{ 3, { OID_BYTEA, OID_BYTEA, OID_INT8 },
"INSERT INTO lease4(address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, "
"state, user_context, relay_id, remote_id, pool_id) "
- "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)"},
+ "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)" },
// INSERT_LEASE6
{ 19, { OID_VARCHAR, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8,
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
"state, user_context, binaddr, pool_id) "
- "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)"},
+ "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)" },
// UPDATE_LEASE4
{ 16, { OID_INT8, OID_BYTEA, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8,
"client_id = $3, valid_lifetime = $4, expire = $5, "
"subnet_id = $6, fqdn_fwd = $7, fqdn_rev = $8, hostname = $9, "
"state = $10, user_context = $11, relay_id = $12, remote_id = $13, pool_id = $14 "
- "WHERE address = $15 AND expire = $16"},
+ "WHERE address = $15 AND expire = $16" },
// UPDATE_LEASE6
{ 21, { OID_VARCHAR, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8, OID_INT8,
"prefix_len = $9, fqdn_fwd = $10, fqdn_rev = $11, hostname = $12, "
"hwaddr = $13, hwtype = $14, hwaddr_source = $15, "
"state = $16, user_context = $17, binaddr = $18, pool_id = $19 "
- "WHERE address = $20 AND expire = $21"},
+ "WHERE address = $20 AND expire = $21" },
// ALL_LEASE4_STATS
{ 0, { OID_NONE },
"all_lease4_stats",
"SELECT subnet_id, state, leases as state_count"
- " FROM lease4_stat ORDER BY subnet_id, state"},
+ " FROM lease4_stat ORDER BY subnet_id, state" },
// SUBNET_LEASE4_STATS
{ 1, { OID_INT8 },
"SELECT subnet_id, state, leases as state_count"
" FROM lease4_stat "
" WHERE subnet_id = $1 "
- " ORDER BY state"},
+ " ORDER BY state" },
// SUBNET_RANGE_LEASE4_STATS
{ 2, { OID_INT8, OID_INT8 },
"SELECT subnet_id, state, leases as state_count"
" FROM lease4_stat "
" WHERE subnet_id >= $1 and subnet_id <= $2 "
- " ORDER BY subnet_id, state"},
+ " ORDER BY subnet_id, state" },
+
+ // ALL_POOL_LEASE4_STATS
+ { 0, { OID_NONE },
+ "all_pool_lease4_stats",
+ "SELECT subnet_id, pool_id, state, leases as state_count"
+ " FROM lease4_pool_stat ORDER BY subnet_id, pool_id, state" },
// ALL_LEASE6_STATS,
{ 0, { OID_NONE },
- "all_lease6_stats",
- "SELECT subnet_id, lease_type, state, leases as state_count"
- " FROM lease6_stat ORDER BY subnet_id, lease_type, state" },
+ "all_lease6_stats",
+ "SELECT subnet_id, lease_type, state, leases as state_count"
+ " FROM lease6_stat ORDER BY subnet_id, lease_type, state" },
// SUBNET_LEASE6_STATS
{ 1, { OID_INT8 },
" WHERE subnet_id >= $1 and subnet_id <= $2 "
" ORDER BY subnet_id, lease_type, state" },
+ // ALL_POOL_LEASE6_STATS,
+ { 0, { OID_NONE },
+ "all_pool_lease6_stats",
+ "SELECT subnet_id, pool_id, lease_type, state, leases as state_count"
+ " FROM lease6_pool_stat ORDER BY subnet_id, pool_id, lease_type, state" },
+
// CHECK_LEASE4_LIMITS
{ 1, { OID_TEXT },
"check_lease4_limits",
"get_lease4_count_by_class",
"SELECT leases "
"FROM lease4_stat_by_client_class "
- "WHERE client_class = $1"},
+ "WHERE client_class = $1" },
// GET_LEASE6_COUNT_BY_CLASS
{ 2, { OID_VARCHAR, OID_INT2 },
"get_lease6_count_by_class",
"SELECT leases "
"FROM lease6_stat_by_client_class "
- "WHERE client_class = $1 AND lease_type = $2"},
+ "WHERE client_class = $1 AND lease_type = $2" },
// End of list sentinel
{ 0, { 0 }, NULL, NULL}
/// @param statement The lease data SQL prepared statement to execute
/// @param fetch_type Indicates whether or not lease_type should be
/// fetched from the result set
+ /// @param fetch_pool Indicates if query requires pool data
PgSqlLeaseStatsQuery(PgSqlConnection& conn, PgSqlTaggedStatement& statement,
- const bool fetch_type)
+ const bool fetch_type, const bool fetch_pool = false)
: conn_(conn), statement_(statement), result_set_(), next_row_(0),
- fetch_type_(fetch_type) {
+ fetch_type_(fetch_type), fetch_pool_(fetch_pool) {
}
/// @brief Constructor to query for a single subnet's stats
PgSqlLeaseStatsQuery(PgSqlConnection& conn, PgSqlTaggedStatement& statement,
const bool fetch_type, const SubnetID& subnet_id)
: LeaseStatsQuery(subnet_id), conn_(conn), statement_(statement), result_set_(),
- next_row_(0), fetch_type_(fetch_type) {
+ next_row_(0), fetch_type_(fetch_type), fetch_pool_(false) {
}
/// @brief Constructor to query for the stats for a range of subnets
const bool fetch_type, const SubnetID& first_subnet_id,
const SubnetID& last_subnet_id)
: LeaseStatsQuery(first_subnet_id, last_subnet_id), conn_(conn), statement_(statement),
- result_set_(), next_row_(0), fetch_type_(fetch_type) {
+ result_set_(), next_row_(0), fetch_type_(fetch_type), fetch_pool_(false) {
}
/// @brief Destructor
/// a first and last subnet id for a subnet range.
void start() {
- if (getSelectMode() == ALL_SUBNETS) {
+ if (getSelectMode() == ALL_SUBNETS || getSelectMode() == ALL_SUBNET_POOLS) {
// Run the query with no where clause parameters.
result_set_.reset(new PgSqlResult(PQexecPrepared(conn_, statement_.name,
0, 0, 0, 0, 0)));
row.subnet_id_ = static_cast<SubnetID>(subnet_id);
++col;
+ // Fetch the pool id if we were told to do so.
+ if (fetch_pool_) {
+ PgSqlExchange::getColumnValue(*result_set_, next_row_ , col,
+ row.pool_id_);
+ ++col;
+ }
+
// Fetch the lease type if we were told to do so.
if (fetch_type_) {
uint32_t lease_type;
/// @brief Indicates if query supplies lease type
bool fetch_type_;
+ /// @brief Indicates if query requires pool data
+ bool fetch_pool_;
+
/// @brief Received negative state count showing a problem
static bool negative_count_;
};
return(query);
}
+LeaseStatsQueryPtr
+PgSqlLeaseMgr::startPoolLeaseStatsQuery4() {
+ // Get a context
+ PgSqlLeaseContextAlloc get_context(*this);
+ PgSqlLeaseContextPtr ctx = get_context.ctx_;
+
+ LeaseStatsQueryPtr query(new PgSqlLeaseStatsQuery(ctx->conn_,
+ tagged_statements[ALL_POOL_LEASE4_STATS],
+ false, true));
+ query->start();
+ return(query);
+}
+
LeaseStatsQueryPtr
PgSqlLeaseMgr::startSubnetLeaseStatsQuery4(const SubnetID& subnet_id) {
// Get a context
return(query);
}
+LeaseStatsQueryPtr
+PgSqlLeaseMgr::startPoolLeaseStatsQuery6() {
+ // Get a context
+ PgSqlLeaseContextAlloc get_context(*this);
+ PgSqlLeaseContextPtr ctx = get_context.ctx_;
+
+ LeaseStatsQueryPtr query(new PgSqlLeaseStatsQuery(ctx->conn_,
+ tagged_statements[ALL_POOL_LEASE6_STATS],
+ true, true));
+ query->start();
+ return(query);
+}
+
LeaseStatsQueryPtr
PgSqlLeaseMgr::startSubnetLeaseStatsQuery6(const SubnetID& subnet_id) {
// Get a context
/// @return The populated query as a pointer to an LeaseStatsQuery
virtual LeaseStatsQueryPtr startLeaseStatsQuery4() override;
+ /// @brief Creates and runs the IPv4 lease stats query for all subnets and
+ /// pools
+ ///
+ /// LeaseMgr derivations implement this method such that it creates and
+ /// returns an instance of an LeaseStatsQuery whose result set has been
+ /// populated with up to date IPv4 lease statistical data for all subnets
+ /// and pools.
+ /// Each row of the result set is an LeaseStatRow which ordered ascending
+ /// by subnet ID and pool ID.
+ ///
+ /// @return A populated LeaseStatsQuery
+ virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery4() override;
+
/// @brief Creates and runs the IPv4 lease stats query for a single subnet
///
/// It creates an instance of a PgSqlLeaseStatsQuery4 for a single subnet
/// @return The populated query as a pointer to an LeaseStatsQuery
virtual LeaseStatsQueryPtr startLeaseStatsQuery6() override;
+ /// @brief Creates and runs the IPv6 lease stats query for all subnets and
+ /// pools
+ ///
+ /// LeaseMgr derivations implement this method such that it creates and
+ /// returns an instance of an LeaseStatsQuery whose result set has been
+ /// populated with up to date IPv6 lease statistical data for all subnets
+ /// and pools.
+ /// Each row of the result set is an LeaseStatRow which ordered ascending
+ /// by subnet ID and pool ID.
+ ///
+ /// @return A populated LeaseStatsQuery
+ virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery6() override;
+
/// @brief Creates and runs the IPv6 lease stats query for a single subnet
///
/// It creates an instance of a PgSqlLeaseStatsQuery6 for a single subnet
ALL_LEASE4_STATS, // Fetches IPv4 lease statistics
SUBNET_LEASE4_STATS, // Fetched IPv4 lease stats for a single subnet.
SUBNET_RANGE_LEASE4_STATS, // Fetched IPv4 lease stats for a subnet range.
+ ALL_POOL_LEASE4_STATS, // Fetches IPv4 lease pool statistics
ALL_LEASE6_STATS, // Fetches IPv6 lease statistics
SUBNET_LEASE6_STATS, // Fetched IPv6 lease stats for a single subnet.
SUBNET_RANGE_LEASE6_STATS, // Fetched IPv6 lease stats for a subnet range.
+ ALL_POOL_LEASE6_STATS, // Fetches IPv6 lease pool statistics
CHECK_LEASE4_LIMITS, // Check if allocated IPv4 leases are inside the set limits.
CHECK_LEASE6_LIMITS, // Check if allocated IPv6 leases are inside the set limits.
IS_JSON_SUPPORTED, // Checks if JSON support is enabled in the database.
}
}
-// This test verifies that copy constructor copies Lease4 fields correctly.
-TEST_F(Lease4Test, copyConstructor) {
-
- // Get current time for the use in Lease4.
- const time_t current_time = time(0);
-
- // Create the lease
- Lease4 lease(0xffffffff, hwaddr_, clientid_, VALID_LIFETIME, current_time,
- SUBNET_ID);
-
- // Declined is a non-default state. We'll see if the state will be copied
- // or the default state will be set for the copied lease.
- lease.state_ = Lease::STATE_DECLINED;
-
- // Set an user context.
- lease.setContext(Element::fromJSON("{ \"foobar\": 1234 }"));
-
- // Set relay and remote id.
- const std::vector<uint8_t> relay_id = { 0xaa, 0xbb, 0xcc };
- lease.relay_id_ = relay_id;
- const std::vector<uint8_t> remote_id = { 1, 2, 3 };
- lease.remote_id_ = remote_id;
-
- // Use copy constructor to copy the lease.
- Lease4 copied_lease(lease);
-
- // Both leases should be now equal. When doing this check we assume that
- // the equality operator works correctly.
- EXPECT_TRUE(lease == copied_lease);
- // Client IDs are equal, but they should be in two distinct pointers.
- EXPECT_FALSE(lease.client_id_ == copied_lease.client_id_);
-
- // User context are equal and point to the same object.
- ASSERT_TRUE(copied_lease.getContext());
- EXPECT_TRUE(lease.getContext() == copied_lease.getContext());
- EXPECT_TRUE(*lease.getContext() == *copied_lease.getContext());
-
- // Relay and remote ids are equal.
- EXPECT_TRUE(lease.relay_id_ == copied_lease.relay_id_);
- EXPECT_TRUE(lease.remote_id_ == copied_lease.remote_id_);
-
- // Hardware addresses are equal, but they should point to two objects,
- // each holding the same data. The content should be equal...
- EXPECT_TRUE(*lease.hwaddr_ == *copied_lease.hwaddr_);
-
- // ... but it should point to different objects.
- EXPECT_FALSE(lease.hwaddr_ == copied_lease.hwaddr_);
-
- // Now let's check that the hwaddr pointer is copied even if it's null:
- lease.hwaddr_.reset();
- Lease4 copied_lease2(lease);
- EXPECT_TRUE(lease == copied_lease2);
-}
-
-// This test verifies that the assignment operator copies all Lease4 fields
-// correctly.
-TEST_F(Lease4Test, operatorAssign) {
-
- // Get the current time for the use in Lease4.
- const time_t current_time = time(0);
-
- // Create the lease
- Lease4 lease(0xffffffff, hwaddr_, clientid_, VALID_LIFETIME, current_time,
- SUBNET_ID);
-
- // Declined is a non-default state. We'll see if the state will be copied
- // or the default state will be set for the copied lease.
- lease.state_ = Lease::STATE_DECLINED;
-
- // Set an user context.
- lease.setContext(Element::fromJSON("{ \"foobar\": 1234 }"));
-
- // Set relay and remote id.
- const std::vector<uint8_t> relay_id = { 0xaa, 0xbb, 0xcc };
- lease.relay_id_ = relay_id;
- const std::vector<uint8_t> remote_id = { 1, 2, 3 };
- lease.remote_id_ = remote_id;
-
- // Create a default lease.
- Lease4 assigned_lease;
- // Use assignment operator to assign new lease.
- assigned_lease = lease;
-
- // Both leases should be now equal. When doing this check we assume that
- // the equality operator works correctly.
- EXPECT_TRUE(lease == assigned_lease);
- // Client IDs are equal, but they should be in two distinct pointers.
- EXPECT_FALSE(lease.client_id_ == assigned_lease.client_id_);
-
- // User context are equal and point to the same object.
- ASSERT_TRUE(assigned_lease.getContext());
- EXPECT_TRUE(lease.getContext() == assigned_lease.getContext());
- EXPECT_TRUE(*lease.getContext() == *assigned_lease.getContext());
-
- // User context are equal and point to the same object.
- ASSERT_TRUE(assigned_lease.getContext());
- EXPECT_TRUE(lease.getContext() == assigned_lease.getContext());
- EXPECT_TRUE(*lease.getContext() == *assigned_lease.getContext());
-
- // Hardware addresses are equal, but they should point to two objects,
- // each holding the same data. The content should be equal...
- EXPECT_TRUE(*lease.hwaddr_ == *assigned_lease.hwaddr_);
-
- // ... but it should point to different objects.
- EXPECT_FALSE(lease.hwaddr_ == assigned_lease.hwaddr_);
-
- // Now let's check that the hwaddr pointer is copied even if it's null:
- lease.hwaddr_.reset();
- assigned_lease = lease;
- EXPECT_TRUE(lease == assigned_lease);
-}
-
// This test verifies that it is correctly determined when the lease
// belongs to the particular client identified by the client identifier
// and hw address.
}
}
-
} // end of namespace isc::dhcp
} // end of namespace isc
} // end of namespace isc::dhcp
} // end of namespace isc
-
#endif // TRACKING_LEASE_MGR_H