From: Thomas Markwalder Date: Tue, 23 Aug 2016 20:34:28 +0000 (-0400) Subject: [4294] Refactored AddressStatsRow and AddressStatsQuery classes X-Git-Tag: trac4631_base~6^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a1249f166f2584a82972c87459ad0b03d940d1f;p=thirdparty%2Fkea.git [4294] Refactored AddressStatsRow and AddressStatsQuery classes src/lib/dhcpsrv/cfg_subnets4.cc CfgSubnets4::updateStatistics() - replaced recountAddressStats4() with recountLeaseStats4() src/lib/dhcpsrv/cfg_subnets6.cc CfgSubnets6::updateStatistics() - replaced recountAddressStats6() with recountLeaseStats6() src/lib/dhcpsrv/lease_mgr.cc renamed LeaseMgr::recountAddressStats4() to recountLeaseStats4() renamed LeaseMgr::recountAddressStats6() to recountLeaseStats6() renamed LeaseMgr::startAddressStats4() to startLeaseStats4() renamed LeaseMgr::startAddressStats6() to startLeaseStats6() src/lib/dhcpsrv/lease_mgr.h replaced AddressStatsRow4 and AddressStatsRow6 with single class, LeaseStatsRow replaced AddressStatsQuery4 and AddressStatsQuery6 with single class, AddressStatsQuery src/lib/dhcpsrv/memfile_lease_mgr.h src/lib/dhcpsrv/memfile_lease_mgr.cc Replaced this class heirarchy: AddressStatsQuery4 <-- MemfileAddressStatsQuery4 AddressStatsQuery6 <-- MemfileAddressStatsQuery6 With this one: LeaseStatsQuery | +--- MemfileLeaseStatsQuery | +--- MemfileLeaseStatsQuery4 | +--- MemfileLeaseStatsQuery6 Replaced startAddressStatsQuery4() with startLeaseStatsQuery4() Replaced startAddressStatsQuery6() with startLeaseStatsQuery6() src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc Renamed: checkAddressStats() to checkLeaseStats() testAddressLeaseStats4() to testRecountLeaseStats4() testAddressLeaseStats6() to testRecountLeaseStats6() src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc Renamed tests to recountLeaseStats4 and recountLeaseStats6 --- diff --git a/src/lib/dhcpsrv/cfg_subnets4.cc b/src/lib/dhcpsrv/cfg_subnets4.cc index f33b40e958..5dcb413d4e 100644 --- a/src/lib/dhcpsrv/cfg_subnets4.cc +++ b/src/lib/dhcpsrv/cfg_subnets4.cc @@ -269,7 +269,8 @@ CfgSubnets4::updateStatistics() { // Only recount the stats if we have subnets. if (subnets_.begin() != subnets_.end()) { - LeaseMgrFactory::instance().recountAddressStats4(); + //LeaseMgrFactory::instance().recountAddressStats4(); + LeaseMgrFactory::instance().recountLeaseStats4(); } } diff --git a/src/lib/dhcpsrv/cfg_subnets6.cc b/src/lib/dhcpsrv/cfg_subnets6.cc index e8e36b4f5d..3136763f3c 100644 --- a/src/lib/dhcpsrv/cfg_subnets6.cc +++ b/src/lib/dhcpsrv/cfg_subnets6.cc @@ -223,7 +223,7 @@ CfgSubnets6::updateStatistics() { // Only recount the stats if we have subnets. if (subnets_.begin() != subnets_.end()) { - LeaseMgrFactory::instance().recountAddressStats6(); + LeaseMgrFactory::instance().recountLeaseStats6(); } } diff --git a/src/lib/dhcpsrv/lease_mgr.cc b/src/lib/dhcpsrv/lease_mgr.cc index 02aedf5f4a..cd84a69839 100644 --- a/src/lib/dhcpsrv/lease_mgr.cc +++ b/src/lib/dhcpsrv/lease_mgr.cc @@ -48,12 +48,12 @@ LeaseMgr::getLease6(Lease::Type type, const DUID& duid, } void -LeaseMgr::recountAddressStats4() { +LeaseMgr::recountLeaseStats4() { using namespace stats; StatsMgr& stats_mgr = StatsMgr::instance(); - AddressStatsQuery4Ptr query = startAddressStatsQuery4(); + LeaseStatsQueryPtr query = startLeaseStatsQuery4(); if (!query) { /// NULL means not backend does not support recounting. return; @@ -86,7 +86,7 @@ LeaseMgr::recountAddressStats4() { // Get counts per state per subnet. Iterate over the result set // updating the subnet and global values. - AddressStatsRow4 row; + LeaseStatsRow row; while (query->getNextRow(row)) { if (row.lease_state_ == Lease::STATE_DEFAULT) { // Set subnet level value. @@ -105,23 +105,23 @@ LeaseMgr::recountAddressStats4() { } } -AddressStatsQuery4Ptr -LeaseMgr::startAddressStatsQuery4() { - return(AddressStatsQuery4Ptr()); +LeaseStatsQueryPtr +LeaseMgr::startLeaseStatsQuery4() { + return(LeaseStatsQueryPtr()); } bool -AddressStatsQuery4::getNextRow(AddressStatsRow4& /*row*/) { +LeaseStatsQuery::getNextRow(LeaseStatsRow& /*row*/) { return (false); } void -LeaseMgr::recountAddressStats6() { +LeaseMgr::recountLeaseStats6() { using namespace stats; StatsMgr& stats_mgr = StatsMgr::instance(); - AddressStatsQuery6Ptr query = startAddressStatsQuery6(); + LeaseStatsQueryPtr query = startLeaseStatsQuery6(); if (!query) { /// NULL means not backend does not support recounting. return; @@ -163,7 +163,7 @@ LeaseMgr::recountAddressStats6() { // Get counts per state per subnet. Iterate over the result set // updating the subnet and global values. - AddressStatsRow6 row; + LeaseStatsRow row; while (query->getNextRow(row)) { switch(row.lease_type_) { case Lease::TYPE_NA: @@ -202,14 +202,9 @@ LeaseMgr::recountAddressStats6() { } } -AddressStatsQuery6Ptr -LeaseMgr::startAddressStatsQuery6() { - return(AddressStatsQuery6Ptr()); -} - -bool -AddressStatsQuery6::getNextRow(AddressStatsRow6& /*row*/) { - return (false); +LeaseStatsQueryPtr +LeaseMgr::startLeaseStatsQuery6() { + return(LeaseStatsQueryPtr()); } std::string diff --git a/src/lib/dhcpsrv/lease_mgr.h b/src/lib/dhcpsrv/lease_mgr.h index 456a237f66..c8b4ef4e0d 100644 --- a/src/lib/dhcpsrv/lease_mgr.h +++ b/src/lib/dhcpsrv/lease_mgr.h @@ -147,78 +147,29 @@ public: ExchangeColumnInfoContainer parameters_; ///< Column names and types }; -/// @brief Contains a single row of IPv4 lease statistical data +/// @brief Contains a single row of lease statistical data /// -/// The contents of the row consist of a subnet ID, a lease state, -/// and the number of leases in that state for that subnet ID. -struct AddressStatsRow4 { +/// The contents of the row consist of a subnet ID, a lease +/// type, a lease state, and the number of leases in that state +/// for that type for that subnet ID. +struct LeaseStatsRow { /// @brief Default constructor - AddressStatsRow4() : - subnet_id_(0), lease_state_(Lease::STATE_DEFAULT), state_count_(0) { + LeaseStatsRow() : + subnet_id_(0), lease_type_(Lease::TYPE_NA), + lease_state_(Lease::STATE_DEFAULT), state_count_(0) { } /// @brief Constructor /// + /// Constructor which defaults the type to TYPE_NA. + /// /// @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 - AddressStatsRow4(const SubnetID& subnet_id, - const uint32_t lease_state, - const int64_t state_count) - : subnet_id_(subnet_id), lease_state_(lease_state), - state_count_(state_count) { - } - - /// @brief The subnet ID to which this data applies - SubnetID subnet_id_; - /// @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_; -}; - -/// @brief Base class for fulfilling IPv4 statistical lease data query -/// -/// LeaseMgr derivations implement this class such that it provides -/// upto date IPv4 statistical lease data organized as rows of -/// AddressStatsRow4 instances. The rows must be accessible in -/// ascending order by subnet id. -class AddressStatsQuery4 { -public: - /// @brief Default constructor - AddressStatsQuery4() {}; - - /// @brief virtual destructor - virtual ~AddressStatsQuery4() {}; - - /// @brief Executes the query - /// - /// This method should conduct whatever steps are required to - /// calculate the IPv4 lease statistical data by examining the - /// IPv4 lease data and making that results available row by row. - virtual void start() {}; - - /// @brief Fetches the next row of data - /// - /// @param[out] row Storage into which the row is fetched - /// - /// @return True if a row was fetched, false if there are no - /// more rows. - virtual bool getNextRow(AddressStatsRow4& row); -}; - -/// @brief Defines a pointer to an AddressStatsQuery4. -typedef boost::shared_ptr AddressStatsQuery4Ptr; - -/// @brief Contains a single row of IPv6 lease statistical data -/// -/// The contents of the row consist of a subnet ID, a lease state, -/// and the number of leases in that state for that subnet ID. -struct AddressStatsRow6 { - /// @brief Default constructor - AddressStatsRow6() : - subnet_id_(0), lease_type_(Lease::TYPE_NA), - lease_state_(Lease::STATE_DEFAULT), state_count_(0) { + LeaseStatsRow(const SubnetID& subnet_id, const uint32_t lease_state, + const int64_t state_count) + : subnet_id_(subnet_id), lease_type_(Lease::TYPE_NA), + lease_state_(lease_state), state_count_(state_count) { } /// @brief Constructor @@ -227,9 +178,8 @@ struct AddressStatsRow6 { /// @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 - AddressStatsRow6(const SubnetID& subnet_id, const Lease::Type& lease_type, - const uint32_t lease_state, - const int64_t state_count) + 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), lease_state_(lease_state), state_count_(state_count) { } @@ -244,25 +194,24 @@ struct AddressStatsRow6 { int64_t state_count_; }; -/// @brief Base class for fulfilling IPv6 statistical lease data query +/// @brief Base class for fulfilling a statistical lease data query /// /// LeaseMgr derivations implement this class such that it provides -/// upto date IPv6 statistical lease data organized as rows of -/// AddressStatsRow6 instances. The rows must be accessible in -/// ascending order by subnet id. -class AddressStatsQuery6 { +/// upto date statistical lease data organized as rows of LeaseStatsRow +/// instances. The rows must be accessible in ascending order by subnet id. +class LeaseStatsQuery { public: /// @brief Default constructor - AddressStatsQuery6() {}; + LeaseStatsQuery() {}; /// @brief virtual destructor - virtual ~AddressStatsQuery6() {}; + virtual ~LeaseStatsQuery() {}; /// @brief Executes the query /// /// This method should conduct whatever steps are required to - /// calculate the IPv6 lease statistical data by examining the - /// IPv6 lease data and making that results available row by row. + /// calculate the lease statistical data by examining the + /// lease data and making that results available row by row. virtual void start() {}; /// @brief Fetches the next row of data @@ -271,11 +220,11 @@ public: /// /// @return True if a row was fetched, false if there are no /// more rows. - virtual bool getNextRow(AddressStatsRow6& row); + virtual bool getNextRow(LeaseStatsRow& row); }; -/// @brief Defines a pointer to an AddressStatsQuery6. -typedef boost::shared_ptr AddressStatsQuery6Ptr; +/// @brief Defines a pointer to an LeaseStatsQuery. +typedef boost::shared_ptr LeaseStatsQueryPtr; /// @brief Abstract Lease Manager /// @@ -539,24 +488,25 @@ public: /// - declined-addresses /// - declined-reclaimed-addresses (reset to zero) /// - /// It invokes the virtual method, startAddressStatsQuery4(), which - /// returns an instance of an AddressStats4Qry. The query - /// query contains a "result set" where each row is an AddressStatRow4 - /// that contains a subnet id, a lease state, the number of leases in that - /// state and is ordered by subnet id. The method iterates over the + /// It invokes the virtual method, startLeaseStatsQuery4(), which + /// returns an instance of an LeaseStatsQuery. The query + /// query contains a "result set" where each row is an LeaseStatRow + /// that contains a subnet id, a lease type (currently always TYPE_NA), + /// a lease state, and the number of leases of that type, in that state + /// and is ordered by subnet id. The method iterates over the /// result set rows, setting the appropriate statistic per subnet and /// adding to the approporate global statistic. - void recountAddressStats4(); + void recountLeaseStats4(); /// @brief Virtual method which creates and runs the IPv4 lease stats query /// /// LeaseMgr derivations implement this method such that it creates and - /// returns an instance of an AddressStatsQuery whose result set has been + /// returns an instance of an LeaseStatsQuery whose result set has been /// populated with upto date IPv4 lease statistical data. Each row of the - /// result set is an AddressStatRow4 which ordered ascending by subnet ID. + /// result set is an LeaseStatRow which ordered ascending by subnet ID. /// - /// @return A populated AddressStatsQuery4 - virtual AddressStatsQuery4Ptr startAddressStatsQuery4(); + /// @return A populated LeaseStatsQuery + virtual LeaseStatsQueryPtr startLeaseStatsQuery4(); /// @brief Recalculates per-subnet and global stats for IPv6 leases /// @@ -570,24 +520,24 @@ public: /// - declined-addresses /// - declined-reclaimed-addresses (reset to zero) /// - /// It invokes the virtual method, startAddressStatsQuery6(), which - /// returns an instance of an AddressStats6Qry. The query - /// query contains a "result set" where each row is an AddressStatRow6 - /// that contains a subnet id, a lease state, the number of leases in that - /// state and is ordered by subnet id. The method iterates over the - /// result set rows, setting the appropriate statistic per subnet and - /// adding to the approporate global statistic. - void recountAddressStats6(); + /// It invokes the virtual method, startLeaseStatsQuery6(), which + /// returns an instance of an LeaseStatsQuery. The query contains + /// a "result set" where each row is an LeaseStatRow that contains + /// a subnet id, a lease type, a lease state, and the number of leases + /// of that type, in that state and is ordered by subnet id. The method + /// iterates over the result set rows, setting the appropriate statistic + /// per subnet and adding to the approporate global statistic. + void recountLeaseStats6(); /// @brief Virtual method which creates and runs the IPv6 lease stats query /// /// LeaseMgr derivations implement this method such that it creates and - /// returns an instance of an AddressStatsQuery whose result set has been + /// returns an instance of an LeaseStatsQuery whose result set has been /// populated with upto date IPv6 lease statistical data. Each row of the - /// result set is an AddressStatRow6 which ordered ascending by subnet ID. + /// result set is an LeaseStatRow which ordered ascending by subnet ID. /// - /// @return A populated AddressStatsQuery6 - virtual AddressStatsQuery6Ptr startAddressStatsQuery6(); + /// @return A populated LeaseStatsQuery + virtual LeaseStatsQueryPtr startLeaseStatsQuery6(); /// @brief Return backend type /// diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index 8f5313a997..bfc57dccbf 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -257,6 +257,55 @@ LFCSetup::getExitStatus() const { } +/// @brief Base Memfile derivation of the statistical lease data query +/// +/// This class provides the functionality such as results storgae and row +/// fetching common to fulfilling the statistical lease data query. +/// +class MemfileLeaseStatsQuery : public LeaseStatsQuery { +public: + /// @brief Constructor + /// + MemfileLeaseStatsQuery() + : rows_(0), next_pos_(rows_.end()) { + }; + + /// @brief Destructor + virtual ~MemfileLeaseStatsQuery() {}; + + /// @brief Fetches the next row in the result set + /// + /// Once the internal result set has been populated by invoking the + /// the start() method, this method is used to iterate over the + /// result set rows. Once the last row has been fetched, subsequent + /// calls will return false. + /// @param row Storage for the fetched row + /// + /// @return True if the fetch succeeded, false if there are no more + /// rows to fetch. + virtual bool getNextRow(LeaseStatsRow& row) { + if (next_pos_ == rows_.end()) { + return (false); + } + + row = *next_pos_; + ++next_pos_; + return (true); + } + + /// @brief Returns the number of rows in the result set + int getRowCount() const { + return (rows_.size()); + } + +protected: + /// @brief A vector containing the "result set" + std::vector rows_; + + /// @brief An iterator for accessing the next row within the result set + std::vector::iterator next_pos_; +}; + /// @brief Memfile derivation of the IPv4 statistical lease data query /// /// This class is used to recalculate IPv4 lease statistics for Memfile @@ -266,17 +315,17 @@ LFCSetup::getExitStatus() const { /// The populated result set will contain one entry per monitored state /// per subnet. /// -class MemfileAddressStatsQuery4 : public AddressStatsQuery4 { +class MemfileLeaseStatsQuery4 : public MemfileLeaseStatsQuery { public: /// @brief Constructor /// /// @param storage4 A pointer to the v4 lease storage to be counted - MemfileAddressStatsQuery4(Lease4Storage& storage4) - : storage4_(storage4), rows_(0), next_pos_(rows_.end()) { + MemfileLeaseStatsQuery4(Lease4Storage& storage4) + : MemfileLeaseStatsQuery(), storage4_(storage4) { }; /// @brief Destructor - virtual ~MemfileAddressStatsQuery4() {}; + virtual ~MemfileLeaseStatsQuery4() {}; /// @brief Creates the IPv4 lease statistical data result set /// @@ -309,13 +358,11 @@ public: // and wipe the accumulators if ((*lease)->subnet_id_ > cur_id) { if (cur_id > 0) { - rows_.push_back(AddressStatsRow4(cur_id, - Lease::STATE_DEFAULT, - assigned)); + rows_.push_back(LeaseStatsRow(cur_id, Lease::STATE_DEFAULT, + assigned)); assigned = 0; - rows_.push_back(AddressStatsRow4(cur_id, - Lease::STATE_DECLINED, - declined)); + rows_.push_back(LeaseStatsRow(cur_id, Lease::STATE_DECLINED, + declined)); declined = 0; } @@ -333,50 +380,19 @@ public: // Make the rows for last subnet, unless there were no rows if (idx.begin() != idx.end()) { - rows_.push_back(AddressStatsRow4(cur_id, Lease::STATE_DEFAULT, - assigned)); - rows_.push_back(AddressStatsRow4(cur_id, Lease::STATE_DECLINED, - declined)); + rows_.push_back(LeaseStatsRow(cur_id, Lease::STATE_DEFAULT, + assigned)); + rows_.push_back(LeaseStatsRow(cur_id, Lease::STATE_DECLINED, + declined)); } // Set the next row position to the beginning of the rows. next_pos_ = rows_.begin(); } - /// @brief Fetches the next row in the result set - /// - /// Once the internal result set has been populated by invoking the - /// the start() method, this method is used to iterate over the - /// result set rows. Once the last row has been fetched, subsequent - /// calls will return false. - /// @param row Storage for the fetched row - /// - /// @return True if the fetch succeeded, false if there are no more - /// rows to fetch. - virtual bool getNextRow(AddressStatsRow4& row) { - if (next_pos_ == rows_.end()) { - return (false); - } - - row = *next_pos_; - ++next_pos_; - return (true); - } - - /// @brief Returns the number of rows in the result set - int getRowCount() const { - return (rows_.size()); - } - private: /// @brief The Memfile storage containing the IPv4 leases to analyze Lease4Storage& storage4_; - - /// @brief A vector containing the "result set" - std::vector rows_; - - /// @brief An iterator for accessing the next row within the result set - std::vector::iterator next_pos_; }; @@ -389,17 +405,17 @@ private: /// The populated result set will contain one entry per monitored state /// per subnet. /// -class MemfileAddressStatsQuery6 : public AddressStatsQuery6 { +class MemfileLeaseStatsQuery6 : public MemfileLeaseStatsQuery { public: /// @brief Constructor /// /// @param storage6 A pointer to the v6 lease storage to be counted - MemfileAddressStatsQuery6(Lease6Storage& storage6) - : storage6_(storage6), rows_(0), next_pos_(rows_.end()) { + MemfileLeaseStatsQuery6(Lease6Storage& storage6) + : MemfileLeaseStatsQuery(), storage6_(storage6) { }; /// @brief Destructor - virtual ~MemfileAddressStatsQuery6() {}; + virtual ~MemfileLeaseStatsQuery6() {}; /// @brief Creates the IPv6 lease statistical data result set /// @@ -434,17 +450,17 @@ public: // and wipe the accumulators if ((*lease)->subnet_id_ > cur_id) { if (cur_id > 0) { - rows_.push_back(AddressStatsRow6(cur_id, Lease::TYPE_NA, - Lease::STATE_DEFAULT, - assigned)); + rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA, + Lease::STATE_DEFAULT, + assigned)); assigned = 0; - rows_.push_back(AddressStatsRow6(cur_id, Lease::TYPE_NA, - Lease::STATE_DECLINED, - declined)); + rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA, + Lease::STATE_DECLINED, + declined)); declined = 0; - rows_.push_back(AddressStatsRow6(cur_id, Lease::TYPE_PD, - Lease::STATE_DEFAULT, - assigned_pds)); + rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_PD, + Lease::STATE_DEFAULT, + assigned_pds)); assigned_pds = 0; } @@ -474,55 +490,24 @@ public: // Make the rows for last subnet, unless there were no rows if (idx.begin() != idx.end()) { - rows_.push_back(AddressStatsRow6(cur_id, Lease::TYPE_NA, - Lease::STATE_DEFAULT, - assigned)); - rows_.push_back(AddressStatsRow6(cur_id, Lease::TYPE_NA, - Lease::STATE_DECLINED, - declined)); - rows_.push_back(AddressStatsRow6(cur_id, Lease::TYPE_PD, - Lease::STATE_DEFAULT, - assigned_pds)); + rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA, + Lease::STATE_DEFAULT, + assigned)); + rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA, + Lease::STATE_DECLINED, + declined)); + rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_PD, + Lease::STATE_DEFAULT, + assigned_pds)); } // Set the next row position to the beginning of the rows. next_pos_ = rows_.begin(); } - /// @brief Fetches the next row in the result set - /// - /// Once the internal result set has been populated by invoking the - /// the start() method, this method is used to iterate over the - /// result set rows. Once the last row has been fetched, subsequent - /// calls will return false. - /// @param row Storage for the fetched row - /// - /// @return True if the fetch succeeded, false if there are no more - /// rows to fetch. - virtual bool getNextRow(AddressStatsRow6& row) { - if (next_pos_ == rows_.end()) { - return (false); - } - - row = *next_pos_; - ++next_pos_; - return (true); - } - - /// @brief Returns the number of rows in the result set - int getRowCount() { - return (rows_.size()); - } - private: /// @brief The Memfile storage containing the IPv6 leases to analyze Lease6Storage& storage6_; - - /// @brief A vector containing the "result set" - std::vector rows_; - - /// @brief An iterator for accessing the next row within the result set - std::vector::iterator next_pos_; }; // Explicit definition of class static constants. Values are given in the @@ -1318,16 +1303,16 @@ void Memfile_LeaseMgr::lfcExecute(boost::shared_ptr& lease_file) } } -AddressStatsQuery4Ptr -Memfile_LeaseMgr::startAddressStatsQuery4() { - AddressStatsQuery4Ptr query(new MemfileAddressStatsQuery4(storage4_)); +LeaseStatsQueryPtr +Memfile_LeaseMgr::startLeaseStatsQuery4() { + LeaseStatsQueryPtr query(new MemfileLeaseStatsQuery4(storage4_)); query->start(); return(query); } -AddressStatsQuery6Ptr -Memfile_LeaseMgr::startAddressStatsQuery6() { - AddressStatsQuery6Ptr query(new MemfileAddressStatsQuery6(storage6_)); +LeaseStatsQueryPtr +Memfile_LeaseMgr::startLeaseStatsQuery6() { + LeaseStatsQueryPtr query(new MemfileLeaseStatsQuery6(storage6_)); query->start(); return(query); } diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.h b/src/lib/dhcpsrv/memfile_lease_mgr.h index d4e7c1a94a..d996b45dcb 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.h +++ b/src/lib/dhcpsrv/memfile_lease_mgr.h @@ -595,23 +595,23 @@ public: int getLFCExitStatus() const; //@} - /// @brief Creates and runs the IPv4 lease stats query + /// @brief Creates and runs the IPv4 lease stats query /// - /// It creates an instance of a MemfileAddressStatsQuery4 and then - /// invokes it's start method in which the query constructs its + /// It creates an instance of a MemfileLeaseStatsQuery4 and then + /// invokes it's start method in which the query constructs its /// statistical data result set. The query object is then returned. - /// - /// @return The populated query as a pointer to an AddressStatsQuery4 - virtual AddressStatsQuery4Ptr startAddressStatsQuery4(); + /// + /// @return The populated query as a pointer to an LeaseStatsQuery + virtual LeaseStatsQueryPtr startLeaseStatsQuery4(); - /// @brief Creates and runs the IPv6 lease stats query + /// @brief Creates and runs the IPv6 lease stats query /// - /// It creates an instance of a MemfileAddressStatsQuery6 and then - /// invokes it's start method in which the query constructs its + /// It creates an instance of a MemfileLeaseStatsQuery6 and then + /// invokes it's start method in which the query constructs its /// statistical data result set. The query object is then returned. - /// - /// @return The populated query as a pointer to an AddressStatsQuery6 - virtual AddressStatsQuery6Ptr startAddressStatsQuery6(); + /// + /// @return The populated query as a pointer to an LeaseStatsQuery. + virtual LeaseStatsQueryPtr startLeaseStatsQuery6(); /// @name Protected methods used for %Lease File Cleanup. /// The following methods are protected so as they can be accessed and diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc index 399533da0e..57511fef8e 100644 --- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc @@ -2401,7 +2401,7 @@ GenericLeaseMgrTest::checkStat(const std::string& name, } void -GenericLeaseMgrTest::checkAddressStats(const StatValMapList& expectedStats) { +GenericLeaseMgrTest::checkLeaseStats(const StatValMapList& expectedStats) { // Global accumulators int64_t declined_addresses = 0; int64_t declined_reclaimed_addresses = 0; @@ -2469,9 +2469,8 @@ GenericLeaseMgrTest::makeLease6(const Lease::Type& type, ASSERT_TRUE(lmptr_->addLease(lease)); } - void -GenericLeaseMgrTest::testRecountAddressStats4() { +GenericLeaseMgrTest::testRecountLeaseStats4() { using namespace stats; StatsMgr::instance().removeAll(); @@ -2509,13 +2508,13 @@ GenericLeaseMgrTest::testRecountAddressStats4() { } // Make sure stats are as expected. - ASSERT_NO_FATAL_FAILURE(checkAddressStats(expectedStats)); + ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); // Recount stats. We should have the same results. - ASSERT_NO_THROW(lmptr_->recountAddressStats4()); + ASSERT_NO_THROW(lmptr_->recountLeaseStats4()); // Make sure stats are as expected. - ASSERT_NO_FATAL_FAILURE(checkAddressStats(expectedStats)); + ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); // Now let's insert some leases into subnet 1. int subnet_id = 1; @@ -2546,10 +2545,10 @@ GenericLeaseMgrTest::testRecountAddressStats4() { expectedStats[subnet_id - 1]["declined-addresses"] = 1; // Now Recount the stats. - ASSERT_NO_THROW(lmptr_->recountAddressStats4()); + ASSERT_NO_THROW(lmptr_->recountLeaseStats4()); // Make sure stats are as expected. - ASSERT_NO_FATAL_FAILURE(checkAddressStats(expectedStats)); + ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); // Delete some leases from subnet, and update the expected stats. EXPECT_TRUE(lmptr_->deleteLease(IOAddress("192.0.1.1"))); @@ -2559,14 +2558,15 @@ GenericLeaseMgrTest::testRecountAddressStats4() { expectedStats[0]["declined-addresses"] = 0; // Recount the stats. - ASSERT_NO_THROW(lmptr_->recountAddressStats4()); + ASSERT_NO_THROW(lmptr_->recountLeaseStats4()); // Make sure stats are as expected. - ASSERT_NO_FATAL_FAILURE(checkAddressStats(expectedStats)); + ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); } + void -GenericLeaseMgrTest::testRecountAddressStats6() { +GenericLeaseMgrTest::testRecountLeaseStats6() { using namespace stats; StatsMgr::instance().removeAll(); @@ -2615,14 +2615,14 @@ GenericLeaseMgrTest::testRecountAddressStats6() { } // Make sure stats are as expected. - ASSERT_NO_FATAL_FAILURE(checkAddressStats(expectedStats)); + ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); // Recount stats. We should have the same results. - ASSERT_NO_THROW(lmptr_->recountAddressStats4()); + ASSERT_NO_THROW(lmptr_->recountLeaseStats4()); // Make sure stats are as expected. - ASSERT_NO_FATAL_FAILURE(checkAddressStats(expectedStats)); + ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); // Now let's insert some leases into subnet 1. subnet_id = 1; @@ -2669,10 +2669,10 @@ GenericLeaseMgrTest::testRecountAddressStats6() { expectedStats[subnet_id - 1]["declined-addresses"] = 1; // Now Recount the stats. - ASSERT_NO_THROW(lmptr_->recountAddressStats6()); + ASSERT_NO_THROW(lmptr_->recountLeaseStats6()); // Make sure stats are as expected. - ASSERT_NO_FATAL_FAILURE(checkAddressStats(expectedStats)); + ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); // Delete some leases and update the expected stats. EXPECT_TRUE(lmptr_->deleteLease(IOAddress("3001:1::2"))); @@ -2682,10 +2682,10 @@ GenericLeaseMgrTest::testRecountAddressStats6() { expectedStats[1]["declined-addresses"] = 0; // Recount the stats. - ASSERT_NO_THROW(lmptr_->recountAddressStats6()); + ASSERT_NO_THROW(lmptr_->recountLeaseStats6()); // Make sure stats are as expected. - ASSERT_NO_FATAL_FAILURE(checkAddressStats(expectedStats)); + ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); } diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h index b3b1f66550..ec6a4b4837 100644 --- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h +++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h @@ -118,7 +118,7 @@ public: /// do not match. /// /// @param expected_stats Map of expected static names and values. - void checkAddressStats(const StatValMapList& expected_stats); + void checkLeaseStats(const StatValMapList& expected_stats); /// @brief Constructs a minimal IPv4 lease and adds it to the lease storage /// @@ -365,14 +365,14 @@ public: /// This test creates two subnets and several leases associated with /// them, then verifies that lease statistics are recalculated correctly /// after altering the lease states in various ways. - void testRecountAddressStats4(); + void testRecountLeaseStats4(); /// @brief Check that the IPv6 lease statistics can be recounted /// /// This test creates two subnets and several leases associated with /// them, then verifies that lease statistics are recalculated correctly /// after altering the lease states in various ways. - void testRecountAddressStats6(); + void testRecountLeaseStats6(); /// @brief String forms of IPv4 addresses std::vector straddress4_; diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index 1379cf1c14..f52f2c1bd3 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -1884,15 +1884,15 @@ TEST_F(MemfileLeaseMgrTest, lease6ContainerIndexUpdate) { } // Verifies that IPv4 lease statistics can be recalculated. -TEST_F(MemfileLeaseMgrTest, recountAddressStats4) { +TEST_F(MemfileLeaseMgrTest, recountLeaseStats4) { startBackend(V4); - testRecountAddressStats4(); + testRecountLeaseStats4(); } // Verifies that IPv6 lease statistics can be recalculated. -TEST_F(MemfileLeaseMgrTest, recountAddressStats6) { +TEST_F(MemfileLeaseMgrTest, recountLeaseStats6) { startBackend(V6); - testRecountAddressStats6(); + testRecountLeaseStats6(); } }; // end of anonymous namespace