diff options
author | Francis Dupont <fdupont@isc.org> | 2022-10-14 17:01:57 +0200 |
---|---|---|
committer | Francis Dupont <fdupont@isc.org> | 2022-10-18 19:28:45 +0200 |
commit | d857f781253a8b741f8ae02ed0513651ce82c3ac (patch) | |
tree | d752077ce32c60b4957b284dd0bb539a4c2335e1 /src | |
parent | [#2585] Checkpoint: tests to add (diff) | |
download | kea-d857f781253a8b741f8ae02ed0513651ce82c3ac.tar.xz kea-d857f781253a8b741f8ae02ed0513651ce82c3ac.zip |
[#2585] Checkpoint: finish unit tests
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/dhcpsrv/lease_mgr.cc | 14 | ||||
-rw-r--r-- | src/lib/dhcpsrv/lease_mgr.h | 81 | ||||
-rw-r--r-- | src/lib/dhcpsrv/memfile_lease_mgr.cc | 130 | ||||
-rw-r--r-- | src/lib/dhcpsrv/memfile_lease_mgr.h | 118 | ||||
-rw-r--r-- | src/lib/dhcpsrv/mysql_lease_mgr.cc | 11 | ||||
-rw-r--r-- | src/lib/dhcpsrv/mysql_lease_mgr.h | 88 | ||||
-rw-r--r-- | src/lib/dhcpsrv/pgsql_lease_mgr.cc | 11 | ||||
-rw-r--r-- | src/lib/dhcpsrv/pgsql_lease_mgr.h | 96 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/Makefile.am | 1 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/memfile_lease_extended_info_unittest.cc | 98 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc | 1 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc | 10 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc | 10 |
13 files changed, 485 insertions, 184 deletions
diff --git a/src/lib/dhcpsrv/lease_mgr.cc b/src/lib/dhcpsrv/lease_mgr.cc index ed3d87607b..6373b56a63 100644 --- a/src/lib/dhcpsrv/lease_mgr.cc +++ b/src/lib/dhcpsrv/lease_mgr.cc @@ -361,6 +361,20 @@ LeaseMgr::getDBVersion() { isc_throw(NotImplemented, "LeaseMgr::getDBVersion() called"); } +void +LeaseMgr::setExtendedInfoEnabled(const DatabaseConnection::ParameterMap& parameters) { + std::string extended_info_tables; + try { + extended_info_tables = parameters.at("extended-info-tables"); + } catch (const exception&) { + extended_info_tables = "false"; + } + // If extended_info_tables is 'true' we will enable them. + if (extended_info_tables == "true") { + setExtendedInfoEnabled(true); + } +} + bool LeaseMgr::upgradeLease4ExtendedInfo(const Lease4Ptr& lease) { static OptionDefinitionPtr rai_def; diff --git a/src/lib/dhcpsrv/lease_mgr.h b/src/lib/dhcpsrv/lease_mgr.h index 4b314ae2ea..2f95a79b13 100644 --- a/src/lib/dhcpsrv/lease_mgr.h +++ b/src/lib/dhcpsrv/lease_mgr.h @@ -10,6 +10,7 @@ #include <asiolink/io_address.h> #include <asiolink/io_service.h> #include <cc/data.h> +#include <database/database_connection.h> #include <database/db_exceptions.h> #include <dhcp/duid.h> #include <dhcp/option.h> @@ -813,9 +814,9 @@ public: /// @brief Clears the class-lease count map. virtual void clearClassLeaseCounts() = 0; - /// The following queries are used to fulfill Bulk LeaseQuery queries. They rely - /// on relay data contained in lease's user-context when the extended-store-info flag - /// is enabled. + /// The following queries are used to fulfill Bulk Lease Query + /// queries. They rely on relay data contained in lease's + /// user-context when the extended-store-info flag is enabled. /// @brief Upgrade a V4 lease user context to the new extended info entry. /// @@ -913,7 +914,7 @@ public: /// @brief Returns existing IPv6 leases with on a given link. /// - /// @param link_addr limit results to leases on this link when not :: + /// @param link_addr limit results to leases on this link. /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -924,6 +925,48 @@ public: const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) = 0; + /// @brief Write V4 leases to a file. + /// + /// @param filename File name to write leases. + virtual void writeLeases4(const std::string& filename) = 0; + + /// @brief Write V6 leases to a file. + /// + /// @param filename File name to write leases. + virtual void writeLeases6(const std::string& filename) = 0; + + /// @brief Returns the setting indicating if lease extended info tables + /// are enabled. + /// + /// @return true if lease extended info tables are enabled or false + /// if they are disabled. + bool getExtendedInfoEnabled() const { + return (extended_info_enabled_); + } + +protected: + + /// Extended information / Bulk Lease Query shared interface. + + /// @brief Modifies the setting whether the lease extended info tables + /// are enabled. + /// + /// @note This method is virtual so backend doing specific action + /// on value changes can intercept it by redefining it. + /// + /// @param enabled new setting. + virtual void setExtendedInfoEnabled(const bool enabled) { + extended_info_enabled_ = enabled; + } + + /// @brief Decode parameters to set whether the lease extended info tables + /// are enabled. + /// + /// @note: common code in constructors. + /// + /// @param parameters The parameter map. + virtual void setExtendedInfoEnabled(const db::DatabaseConnection::ParameterMap& parameters); + /// @brief Delete lease6 extended info from tables. /// /// @param addr The address of the lease. @@ -954,36 +997,6 @@ public: virtual void addLinkAddr6(const isc::asiolink::IOAddress& lease_addr, const isc::asiolink::IOAddress& link_addr) = 0; - /// @brief Modifies the setting whether the lease extended info tables - /// are enabled. - /// - /// @note This method is virtual so backend doing specific action - /// on value changes can intercept it by redefining it. - /// - /// @param enabled new setting. - virtual void setExtendedInfoEnabled(const bool enabled) { - extended_info_enabled_ = enabled; - } - - /// @brief Returns the setting indicating if lease extended info tables - /// are enabled. - /// - /// @return true if lease extended info tables are enabled or false - /// if they are disabled. - bool getExtendedInfoEnabled() const { - return (extended_info_enabled_); - } - - /// @brief Write V4 leases to a file. - /// - /// @param filename File name to write leases. - virtual void writeLeases4(const std::string& filename) = 0; - - /// @brief Write V6 leases to a file. - /// - /// @param filename File name to write leases. - virtual void writeLeases6(const std::string& filename) = 0; - private: /// The IOService object, used for all ASIO operations. static isc::asiolink::IOServicePtr io_service_; diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index 7215c237ee..d20ca9503e 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -639,17 +639,7 @@ Memfile_LeaseMgr::Memfile_LeaseMgr(const DatabaseConnection::ParameterMap& param bool conversion_needed = false; // Check if the extended info tables are enabled. - bool extended_info_enabled = false; - std::string extended_info_tables; - try { - extended_info_tables = conn_.getParameter("extended-info-tables"); - } catch (const Exception&) { - extended_info_tables = "false"; - } - // If extended_info_tables is 'true' we will enable them. - if (extended_info_tables == "true") { - setExtendedInfoEnabled(true); - } + setExtendedInfoEnabled(parameters); // Check the universe and use v4 file or v6 file. std::string universe = conn_.getParameter("universe"); @@ -2407,20 +2397,64 @@ Memfile_LeaseMgr::getLeaseLimit(ConstElementPtr parent, Lease::Type ltype, size_ } Lease4Collection -Memfile_LeaseMgr::getLeases4ByRelayId(const OptionBuffer& /* relay_id */, - const IOAddress& /* lower_bound_address */, - const LeasePageSize& /* page_size */, - const time_t& /* qry_start_time = 0 */, - const time_t& /* qry_end_time = 0 */) { +Memfile_LeaseMgr::getLeases4ByRelayId(const OptionBuffer& relay_id, + const IOAddress& lower_bound_address, + const LeasePageSize& page_size, + const time_t& qry_start_time /* = 0 */, + const time_t& qry_end_time /* = 0 */) { + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard<std::mutex> lock(*mutex_); + return (getLeases4ByRelayIdInternal(relay_id, + lower_bound_address, + page_size, + qry_start_time, + qry_end_time)); + } else { + return (getLeases4ByRelayIdInternal(relay_id, + lower_bound_address, + page_size, + qry_start_time, + qry_end_time)); + } +} + +Lease4Collection +Memfile_LeaseMgr::getLeases4ByRelayIdInternal(const OptionBuffer&, + const IOAddress&, + const LeasePageSize&, + const time_t&, + const time_t&) { isc_throw(NotImplemented, "Memfile_LeaseMgr::getLeases4ByRelayId not implemented"); } Lease4Collection -Memfile_LeaseMgr::getLeases4ByRemoteId(const OptionBuffer& /* remote_id */, - const IOAddress& /* lower_bound_address */, - const LeasePageSize& /* page_size */, - const time_t& /* qry_start_time = 0 */, - const time_t& /* qry_end_time = 0 */) { +Memfile_LeaseMgr::getLeases4ByRemoteId(const OptionBuffer& remote_id, + const IOAddress& lower_bound_address, + const LeasePageSize& page_size, + const time_t& qry_start_time /* = 0 */, + const time_t& qry_end_time /* = 0 */) { + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard<std::mutex> lock(*mutex_); + return (getLeases4ByRemoteIdInternal(remote_id, + lower_bound_address, + page_size, + qry_start_time, + qry_end_time)); + } else { + return (getLeases4ByRemoteIdInternal(remote_id, + lower_bound_address, + page_size, + qry_start_time, + qry_end_time)); + } +} + +Lease4Collection +Memfile_LeaseMgr::getLeases4ByRemoteIdInternal(const OptionBuffer&, + const IOAddress&, + const LeasePageSize&, + const time_t&, + const time_t&) { isc_throw(NotImplemented, "Memfile_LeaseMgr::getLeases4ByRemoteId not implemented"); } @@ -2429,6 +2463,25 @@ Memfile_LeaseMgr::getLeases6ByRelayId(const DUID& relay_id, const IOAddress& link_addr, const IOAddress& lower_bound_address, const LeasePageSize& page_size) { + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard<std::mutex> lock(*mutex_); + return (getLeases6ByRelayIdInternal(relay_id, + link_addr, + lower_bound_address, + page_size)); + } else { + return (getLeases6ByRelayIdInternal(relay_id, + link_addr, + lower_bound_address, + page_size)); + } +} + +Lease6Collection +Memfile_LeaseMgr::getLeases6ByRelayIdInternal(const DUID& relay_id, + const IOAddress& link_addr, + const IOAddress& lower_bound_address, + const LeasePageSize& page_size) { const std::vector<uint8_t>& relay_id_data = relay_id.getDuid(); Lease6Collection collection; if (link_addr.isV6Zero()) { @@ -2486,6 +2539,25 @@ Memfile_LeaseMgr::getLeases6ByRemoteId(const OptionBuffer& remote_id, const IOAddress& link_addr, const IOAddress& lower_bound_address, const LeasePageSize& page_size) { + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard<std::mutex> lock(*mutex_); + return (getLeases6ByRemoteIdInternal(remote_id, + link_addr, + lower_bound_address, + page_size)); + } else { + return (getLeases6ByRemoteIdInternal(remote_id, + link_addr, + lower_bound_address, + page_size)); + } +} + +Lease6Collection +Memfile_LeaseMgr::getLeases6ByRemoteIdInternal(const OptionBuffer& remote_id, + const IOAddress& link_addr, + const IOAddress& lower_bound_address, + const LeasePageSize& page_size) { Lease6Collection collection; std::set<IOAddress> sorted; if (link_addr.isV6Zero()) { @@ -2544,6 +2616,22 @@ Lease6Collection Memfile_LeaseMgr::getLeases6ByLink(const IOAddress& link_addr, const IOAddress& lower_bound_address, const LeasePageSize& page_size) { + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard<std::mutex> lock(*mutex_); + return (getLeases6ByLinkInternal(link_addr, + lower_bound_address, + page_size)); + } else { + return (getLeases6ByLinkInternal(link_addr, + lower_bound_address, + page_size)); + } +} + +Lease6Collection +Memfile_LeaseMgr::getLeases6ByLinkInternal(const IOAddress& link_addr, + const IOAddress& lower_bound_address, + const LeasePageSize& page_size) { Lease6Collection collection; const LinkAddressIndex& idx = link_addr6_.get<LinkAddressIndexTag>(); LinkAddressIndex::const_iterator lb = diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.h b/src/lib/dhcpsrv/memfile_lease_mgr.h index 16d098c974..f29fa0704e 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.h +++ b/src/lib/dhcpsrv/memfile_lease_mgr.h @@ -981,7 +981,6 @@ public: private: - /// @brief Initialize the location of the lease file. /// /// This method uses the parameters passed as a map to the constructor to @@ -1282,9 +1281,9 @@ public: /// Must be called from a thread-safe context. virtual void clearClassLeaseCounts() override; - /// The following queries are used to fulfill Bulk LeaseQuery queries. They rely - /// on relay data contained in lease's user-context when the extended-store-info flag - /// is enabled. + /// The following queries are used to fulfill Bulk Lease Query + /// queries. They rely on relay data contained in lease's + /// user-context when the extended-store-info flag is enabled. /// @brief Returns existing IPv4 leases with a given relay-id. /// @@ -1356,7 +1355,7 @@ public: /// @brief Returns existing IPv6 leases with on a given link. /// - /// @param link_addr limit results to leases on this link when not :: + /// @param link_addr limit results to leases on this link. /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1367,6 +1366,105 @@ public: const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; +private: + + /// @brief Returns existing IPv4 leases with a given relay-id. + /// + /// @param relay_id RAI Relay-ID sub-option value for relay_id of interest + /// @param lower_bound_address IPv4 address used as lower bound for the + /// returned range. + /// @param page_size maximum size of the page returned. + /// @param qry_start_time when not zero, only leases whose CLTT is greater than + /// or equal to this value will be included + /// @param qry_end_time when not zero, only leases whose CLTT is less than + /// or equal to this value will be included + /// + /// @return collection of IPv4 leases + Lease4Collection + getLeases4ByRelayIdInternal(const OptionBuffer& relay_id, + const asiolink::IOAddress& lower_bound_address, + const LeasePageSize& page_size, + const time_t& qry_start_time, + const time_t& qry_end_time); + + /// @brief Returns existing IPv4 leases with a given remote-id. + /// + /// @param remote_id RAI Remote-ID sub-option value for remote-id of interest + /// @param lower_bound_address IPv4 address used as lower bound for the + /// returned range. + /// @param page_size maximum size of the page returned. + /// @param qry_start_time when not zero, only leases whose CLTT is greater than + /// or equal to this value will be included. Defaults to zero. + /// @param qry_end_time when not zero, only leases whose CLTT is less than + /// or equal to this value will be included. Defaults to zero. + /// + /// @return collection of IPv4 leases + Lease4Collection + getLeases4ByRemoteIdInternal(const OptionBuffer& remote_id, + const asiolink::IOAddress& lower_bound_address, + const LeasePageSize& page_size, + const time_t& qry_start_time, + const time_t& qry_end_time); + + /// @brief Returns existing IPv6 leases with a given relay-id. + /// + /// @param relay_id DUID for relay_id of interest + /// @param link_addr limit results to leases on this link when not :: + /// @param lower_bound_address IPv4 address used as lower bound for the + /// returned range. + /// @param page_size maximum size of the page returned. + /// + /// @return collection of IPv6 leases + Lease6Collection + getLeases6ByRelayIdInternal(const DUID& relay_id, + const asiolink::IOAddress& link_addr, + const asiolink::IOAddress& lower_bound_address, + const LeasePageSize& page_size); + + /// @brief Returns existing IPv6 leases with a given remote-id. + /// + /// @param remote_id remote-id option data of interest + /// @param link_addr limit results to leases on this link when not :: + /// @param lower_bound_address IPv4 address used as lower bound for the + /// returned range. + /// @param page_size maximum size of the page returned. + /// + /// @return collection of IPv6 leases + Lease6Collection + getLeases6ByRemoteIdInternal(const OptionBuffer& remote_id, + const asiolink::IOAddress& link_addr, + const asiolink::IOAddress& lower_bound_address, + const LeasePageSize& page_size); + + /// @brief Returns existing IPv6 leases with on a given link. + /// + /// @param link_addr limit results to leases on this link. + /// @param lower_bound_address IPv4 address used as lower bound for the + /// returned range. + /// @param page_size maximum size of the page returned. + /// + /// @return collection of IPv6 leases + Lease6Collection + getLeases6ByLinkInternal(const asiolink::IOAddress& link_addr, + const asiolink::IOAddress& lower_bound_address, + const LeasePageSize& page_size); + +public: + + /// @brief Write V4 leases to a file. + /// + /// @param filename File name to write leases. + virtual void writeLeases4(const std::string& filename) override; + + /// @brief Write V6 leases to a file. + /// + /// @param filename File name to write leases. + virtual void writeLeases6(const std::string& filename) override; + +protected: + + /// Extended information / Bulk Lease Query shared interface. + /// @brief Delete lease6 extended info from tables. /// /// @param addr The address of the lease. @@ -1397,16 +1495,6 @@ public: virtual void addLinkAddr6(const isc::asiolink::IOAddress& lease_addr, const isc::asiolink::IOAddress& link_addr) override; - /// @brief Write V4 leases to a file. - /// - /// @param filename File name to write leases. - virtual void writeLeases4(const std::string& filename) override; - - /// @brief Write V6 leases to a file. - /// - /// @param filename File name to write leases. - virtual void writeLeases6(const std::string& filename) override; - private: /// @brief Write V4 leases to a file. /// diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc index 7377017c61..e36bb4e873 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.cc +++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc @@ -1800,16 +1800,7 @@ MySqlLeaseMgr::MySqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters) : parameters_(parameters), timer_name_("") { // Check if the extended info tables are enabled. - std::string extended_info_tables; - try { - extended_info_tables = parameters_.at("extended-info-tables"); - } catch (const exception&) { - extended_info_tables = "false"; - } - // If extended_info_tables is 'true' we will enable them. - if (extended_info_tables == "true") { - setExtendedInfoEnabled(true); - } + LeaseMgr::setExtendedInfoEnabled(parameters); // Create unique timer name per instance. timer_name_ = "MySqlLeaseMgr["; diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.h b/src/lib/dhcpsrv/mysql_lease_mgr.h index ff62eadab5..26c8228a1f 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.h +++ b/src/lib/dhcpsrv/mysql_lease_mgr.h @@ -1018,9 +1018,9 @@ private: int status, StatementIndex index, const char* what) const; - /// The following queries are used to fulfill Bulk LeaseQuery queries. They rely - /// on relay data contained in lease's user-context when the extended-store-info flag - /// is enabled. + /// The following queries are used to fulfill Bulk Lease Query + /// queries. They rely on relay data contained in lease's + /// user-context when the extended-store-info flag is enabled. /// @brief Returns existing IPv4 leases with a given relay-id. /// @@ -1092,7 +1092,7 @@ private: /// @brief Returns existing IPv6 leases with on a given link. /// - /// @param link_addr limit results to leases on this link when not :: + /// @param link_addr limit results to leases on this link. /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1103,6 +1103,48 @@ private: const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; + /// @brief Context RAII Allocator. + class MySqlLeaseContextAlloc { + public: + + /// @brief Constructor + /// + /// This constructor takes a context of the pool if one is available + /// or creates a new one. + /// + /// @param mgr A parent instance + MySqlLeaseContextAlloc(const MySqlLeaseMgr& mgr); + + /// @brief Destructor + /// + /// This destructor puts back the context in the pool. + ~MySqlLeaseContextAlloc(); + + /// @brief The context + MySqlLeaseContextPtr ctx_; + + private: + + /// @brief The manager + const MySqlLeaseMgr& mgr_; + }; + +protected: + + /// Extended information / Bulk Lease Query shared interface. + + /// @brief Modifies the setting whether the lease extended info tables + /// are enabled. + /// + /// Transient redefine to refuse the enable setting. + /// @param enabled new setting. + virtual void setExtendedInfoEnabled(const bool enabled) override { + if (enabled) { + isc_throw(isc::NotImplemented, + "extended info tables are not yet supported by mysql"); + } + } + /// @brief Delete lease6 extended info from tables. /// /// @param addr The address of the lease. @@ -1133,44 +1175,6 @@ private: virtual void addLinkAddr6(const isc::asiolink::IOAddress& lease_addr, const isc::asiolink::IOAddress& link_addr) override; - /// @brief Modifies the setting whether the lease extended info tables - /// are enabled. - /// - /// Transient redefine to refuse the enable setting. - /// @param enabled new setting. - virtual void setExtendedInfoEnabled(const bool enabled) override { - if (enabled) { - isc_throw(isc::NotImplemented, - "extended info tables are not yet supported by mysql"); - } - } - - /// @brief Context RAII Allocator. - class MySqlLeaseContextAlloc { - public: - - /// @brief Constructor - /// - /// This constructor takes a context of the pool if one is available - /// or creates a new one. - /// - /// @param mgr A parent instance - MySqlLeaseContextAlloc(const MySqlLeaseMgr& mgr); - - /// @brief Destructor - /// - /// This destructor puts back the context in the pool. - ~MySqlLeaseContextAlloc(); - - /// @brief The context - MySqlLeaseContextPtr ctx_; - - private: - - /// @brief The manager - const MySqlLeaseMgr& mgr_; - }; - private: // Members diff --git a/src/lib/dhcpsrv/pgsql_lease_mgr.cc b/src/lib/dhcpsrv/pgsql_lease_mgr.cc index b324b86ae6..cf8277413d 100644 --- a/src/lib/dhcpsrv/pgsql_lease_mgr.cc +++ b/src/lib/dhcpsrv/pgsql_lease_mgr.cc @@ -1256,16 +1256,7 @@ PgSqlLeaseMgr::PgSqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters) : parameters_(parameters), timer_name_("") { // Check if the extended info tables are enabled. - std::string extended_info_tables; - try { - extended_info_tables = parameters_.at("extended-info-tables"); - } catch (const exception&) { - extended_info_tables = "false"; - } - // If extended_info_tables is 'true' we will enable them. - if (extended_info_tables == "true") { - setExtendedInfoEnabled(true); - } + LeaseMgr::setExtendedInfoEnabled(parameters); // Create unique timer name per instance. timer_name_ = "PgSqlLeaseMgr["; diff --git a/src/lib/dhcpsrv/pgsql_lease_mgr.h b/src/lib/dhcpsrv/pgsql_lease_mgr.h index afb0082f34..ad59ffa790 100644 --- a/src/lib/dhcpsrv/pgsql_lease_mgr.h +++ b/src/lib/dhcpsrv/pgsql_lease_mgr.h @@ -971,9 +971,9 @@ private: /// @brief Clears the class-lease count map. virtual void clearClassLeaseCounts() override; - /// The following queries are used to fulfill Bulk LeaseQuery queries. They rely - /// on relay data contained in lease's user-context when the extended-store-info flag - /// is enabled. + /// The following queries are used to fulfill Bulk Lease Query + /// queries. They rely on relay data contained in lease's + /// user-context when the extended-store-info flag is enabled. /// @brief Returns existing IPv4 leases with a given relay-id. /// @@ -1045,7 +1045,7 @@ private: /// @brief Returns existing IPv6 leases with on a given link. /// - /// @param link_addr limit results to leases on this link when not :: + /// @param link_addr limit results to leases on this link. /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1056,54 +1056,12 @@ private: const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; - /// @brief Delete lease6 extended info from tables. - /// - /// @param addr The address of the lease. - virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress& addr) override; - - /// @brief Add lease6 extended info into by-relay-id table. - /// - /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the relay header. - /// @param relay_id The relay id from the relay header options. - virtual void addRelayId6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr, - const std::vector<uint8_t>& relay_id) override; - - /// @brief Add lease6 extended info into by-remote-id table. - /// - /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the remote header. - /// @param remote_id The remote id from the relay header options. - virtual void addRemoteId6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr, - const std::vector<uint8_t>& remote_id) override; - - /// @brief Add lease6 extended info into by-link-addr table. - /// - /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the remote header. - virtual void addLinkAddr6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr) override; - /// @brief Write V4 leases to a file. virtual void writeLeases4(const std::string& /*filename*/) override; /// @brief Write V6 leases to a file. virtual void writeLeases6(const std::string& /*filename*/) override; - /// @brief Modifies the setting whether the lease extended info tables - /// are enabled. - /// - /// Transient redefine to refuse the enable setting. - /// @param enabled new setting. - virtual void setExtendedInfoEnabled(const bool enabled) override { - if (enabled) { - isc_throw(isc::NotImplemented, - "extended info tables are not yet supported by postgresql"); - } - } - /// @brief Context RAII Allocator. class PgSqlLeaseContextAlloc { public: @@ -1130,6 +1088,52 @@ private: const PgSqlLeaseMgr& mgr_; }; +protected: + + /// Extended information / Bulk Lease Query shared interface. + + /// @brief Modifies the setting whether the lease extended info tables + /// are enabled. + /// + /// Transient redefine to refuse the enable setting. + /// @param enabled new setting. + virtual void setExtendedInfoEnabled(const bool enabled) override { + if (enabled) { + isc_throw(isc::NotImplemented, + "extended info tables are not yet supported by postgresql"); + } + } + + /// @brief Delete lease6 extended info from tables. + /// + /// @param addr The address of the lease. + virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress& addr) override; + + /// @brief Add lease6 extended info into by-relay-id table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the relay header. + /// @param relay_id The relay id from the relay header options. + virtual void addRelayId6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr, + const std::vector<uint8_t>& relay_id) override; + + /// @brief Add lease6 extended info into by-remote-id table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the remote header. + /// @param remote_id The remote id from the relay header options. + virtual void addRemoteId6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr, + const std::vector<uint8_t>& remote_id) override; + + /// @brief Add lease6 extended info into by-link-addr table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the remote header. + virtual void addLinkAddr6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr) override; + private: // Members diff --git a/src/lib/dhcpsrv/tests/Makefile.am b/src/lib/dhcpsrv/tests/Makefile.am index 495fef6f73..c9523eb9b8 100644 --- a/src/lib/dhcpsrv/tests/Makefile.am +++ b/src/lib/dhcpsrv/tests/Makefile.am @@ -104,6 +104,7 @@ libdhcpsrv_unittests_SOURCES += lease_unittest.cc libdhcpsrv_unittests_SOURCES += lease_mgr_factory_unittest.cc libdhcpsrv_unittests_SOURCES += lease_mgr_unittest.cc libdhcpsrv_unittests_SOURCES += generic_lease_mgr_unittest.cc generic_lease_mgr_unittest.h +libdhcpsrv_unittests_SOURCES += memfile_lease_extended_info_unittest.cc libdhcpsrv_unittests_SOURCES += memfile_lease_limits_unittest.cc libdhcpsrv_unittests_SOURCES += memfile_lease_mgr_unittest.cc libdhcpsrv_unittests_SOURCES += multi_threading_config_parser_unittest.cc diff --git a/src/lib/dhcpsrv/tests/memfile_lease_extended_info_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_extended_info_unittest.cc new file mode 100644 index 0000000000..093d0ae30f --- /dev/null +++ b/src/lib/dhcpsrv/tests/memfile_lease_extended_info_unittest.cc @@ -0,0 +1,98 @@ +// Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <config.h> + +#include <asiolink/io_address.h> +#include <cc/data.h> +#include <dhcpsrv/lease_mgr.h> +#include <dhcpsrv/memfile_lease_mgr.h> +#include <testutils/gtest_utils.h> +#include <util/multi_threading_mgr.h> + +#include <gtest/gtest.h> + +using namespace isc; +using namespace isc::asiolink; +using namespace isc::data; +using namespace isc::db; +using namespace isc::dhcp; +using namespace isc::util; +using namespace std; + +namespace { + +/// @brief A derivation of the lease manager exposing protected methods. +class NakedMemfileLeaseMgr : public Memfile_LeaseMgr { +public: + /// @brief Constructor. + /// + /// Creates anto create an instance of the lease manager. + /// + /// @param parameters Parameter map. + NakedMemfileLeaseMgr(const DatabaseConnection::ParameterMap& parameters) + : Memfile_LeaseMgr(parameters) { + } + + /// @brief Destructor. + virtual ~NakedMemfileLeaseMgr() { + } + + /// @brief Exposes protected methods. + using Memfile_LeaseMgr::deleteExtendedInfo6; + using Memfile_LeaseMgr::addRelayId6; + using Memfile_LeaseMgr::addRemoteId6; + using Memfile_LeaseMgr::addLinkAddr6; +}; + +/// @brief Type of unique pointers to naked lease manager. +typedef unique_ptr<NakedMemfileLeaseMgr> NakedMemfileLeaseMgrPtr; + +/// @brief Test fixture class for extended info tests. +class MemfileLeaseExtendedInfoTest : public ::testing::Test { +public: + /// @brief Constructor. + MemfileLeaseExtendedInfoTest() { + pmap_.clear(); + lease_mgr_.reset(); + MultiThreadingMgr::instance().setMode(false); + } + + /// @brief Destructor. + ~MemfileLeaseExtendedInfoTest() { + pmap_.clear(); + lease_mgr_.reset(); + MultiThreadingMgr::instance().setMode(false); + } + + /// @brief Parameter map. + DatabaseConnection::ParameterMap pmap_; + + /// @brief Lease manager. + NakedMemfileLeaseMgrPtr lease_mgr_; +}; + +/// @brief Verifies that the lease manager can start in V4. +TEST_F(MemfileLeaseExtendedInfoTest, v4) { + pmap_["universe"] = "4"; + pmap_["persist"] = "false"; + pmap_["extended-info-tables"] = "true"; + + EXPECT_NO_THROW(lease_mgr_.reset(new NakedMemfileLeaseMgr(pmap_))); + EXPECT_TRUE(lease_mgr_->getExtendedInfoEnabled()); +} + +/// @brief Verifies that the lease manager can start in V6. +TEST_F(MemfileLeaseExtendedInfoTest, v6) { + pmap_["universe"] = "6"; + pmap_["persist"] = "false"; + pmap_["extended-info-tables"] = "true"; + + EXPECT_NO_THROW(lease_mgr_.reset(new NakedMemfileLeaseMgr(pmap_))); + EXPECT_TRUE(lease_mgr_->getExtendedInfoEnabled()); +} + +} // namespace diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index 102896b1da..bcc5ba17a5 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -98,6 +98,7 @@ public: } using Memfile_LeaseMgr::lfcCallback; + using Memfile_LeaseMgr::setExtendedInfoEnabled; }; /// @brief Test fixture class for @c Memfile_LeaseMgr diff --git a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc index 66473b2331..50a0fc3820 100644 --- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc @@ -126,8 +126,6 @@ TEST(MySqlOpenTest, OpenDatabase) { try { LeaseMgrFactory::create(validMySQLConnectionString()); EXPECT_NO_THROW((void)LeaseMgrFactory::instance()); - EXPECT_THROW(LeaseMgrFactory::instance().setExtendedInfoEnabled(true), - NotImplemented); LeaseMgrFactory::destroy(); } catch (const isc::Exception& ex) { FAIL() << "*** ERROR: unable to open database, reason:\n" @@ -200,9 +198,15 @@ TEST(MySqlOpenTest, OpenDatabase) { // Check for missing parameters EXPECT_THROW(LeaseMgrFactory::create(connectionString( - MYSQL_VALID_TYPE, NULL, VALID_HOST, INVALID_USER, VALID_PASSWORD)), + MYSQL_VALID_TYPE, NULL, VALID_HOST, VALID_USER, VALID_PASSWORD)), NoDatabaseName); + // Check for extended info tables. + const char* EX_INFO = "extended-info-tables=true"; + EXPECT_THROW(LeaseMgrFactory::create(connectionString( + MYSQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, EX_INFO)), + NotImplemented); + // Tidy up after the test destroyMySQLSchema(true); LeaseMgrFactory::destroy(); diff --git a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc index 8233cd0b5d..90b06ca706 100644 --- a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc @@ -126,8 +126,6 @@ TEST(PgSqlOpenTest, OpenDatabase) { try { LeaseMgrFactory::create(validPgSQLConnectionString()); EXPECT_NO_THROW((void)LeaseMgrFactory::instance()); - EXPECT_THROW(LeaseMgrFactory::instance().setExtendedInfoEnabled(true), - NotImplemented); LeaseMgrFactory::destroy(); } catch (const isc::Exception& ex) { FAIL() << "*** ERROR: unable to open database, reason:\n" @@ -197,7 +195,7 @@ TEST(PgSqlOpenTest, OpenDatabase) { // Check for missing parameters EXPECT_THROW(LeaseMgrFactory::create(connectionString( - PGSQL_VALID_TYPE, NULL, VALID_HOST, INVALID_USER, VALID_PASSWORD)), + PGSQL_VALID_TYPE, NULL, VALID_HOST, VALID_USER, VALID_PASSWORD)), NoDatabaseName); // Check for SSL/TLS support. @@ -211,6 +209,12 @@ TEST(PgSqlOpenTest, OpenDatabase) { 0, 0, 0, 0, VALID_CA)), DbOpenError); #endif + // Check for extended info tables. + const char* EX_INFO = "extended-info-tables=true"; + EXPECT_THROW(LeaseMgrFactory::create(connectionString( + PGSQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, EX_INFO)), + NotImplemented); + // Tidy up after the test destroyPgSQLSchema(); LeaseMgrFactory::destroy(); |