diff options
author | Thomas Markwalder <tmark@isc.org> | 2021-11-10 17:14:00 +0100 |
---|---|---|
committer | Tomek Mrugalski <tomek@isc.org> | 2021-11-17 15:35:19 +0100 |
commit | fe31eee4ed21d5aa3fcb085ca89dc104c87bcb00 (patch) | |
tree | d0c51c701997f09e0ea6a2442efa9d29cc6a7c99 /src | |
parent | [#1848] The tests now manage their own schema (diff) | |
download | kea-fe31eee4ed21d5aa3fcb085ca89dc104c87bcb00.tar.xz kea-fe31eee4ed21d5aa3fcb085ca89dc104c87bcb00.zip |
[#1848] Moves Triplet to isc::util
renamed: src/lib/dhcpsrv/triplet.h -> src/lib/util/triplet.h
modified:
src/hooks/dhcp/pgsql_cb/pgsql_cb_impl.h
src/hooks/dhcp/pgsql_cb/tests/pgsql_cb_impl_unittest.cc
src/lib/cc/simple_parser.cc
src/lib/cc/simple_parser.h
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/client_class_def.cc
src/lib/dhcpsrv/client_class_def.h
src/lib/dhcpsrv/network.h
src/lib/dhcpsrv/parsers/base_network_parser.cc
src/lib/dhcpsrv/parsers/client_class_def_parser.cc
src/lib/dhcpsrv/subnet.h
src/lib/dhcpsrv/tests/Makefile.am
src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc
src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc
src/lib/dhcpsrv/tests/alloc_engine_utils.cc
src/lib/dhcpsrv/tests/cfg_shared_networks4_unittest.cc
src/lib/dhcpsrv/tests/cfg_shared_networks6_unittest.cc
src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc
src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc
src/lib/dhcpsrv/tests/client_class_def_parser_unittest.cc
src/lib/dhcpsrv/tests/shared_network_unittest.cc
src/lib/dhcpsrv/tests/srv_config_unittest.cc
src/lib/dhcpsrv/tests/subnet_unittest.cc
src/lib/dhcpsrv/tests/triplet_unittest.cc
src/lib/util/Makefile.am
Diffstat (limited to 'src')
28 files changed, 85 insertions, 196 deletions
diff --git a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc index f85f7fcaa3..69f638339a 100644 --- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc @@ -49,6 +49,7 @@ using namespace isc::data; using namespace isc::asiolink; using namespace isc::config; using namespace isc::dhcp::test; +using namespace isc::util; namespace { diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc index 44005351e0..7a8b1c73a6 100644 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@ -23,7 +23,7 @@ #include <dhcpsrv/pool.h> #include <dhcpsrv/subnet.h> #include <dhcpsrv/timer_mgr.h> -#include <dhcpsrv/triplet.h> +#include <util/triplet.h> #include <dhcpsrv/parsers/client_class_def_parser.h> #include <dhcpsrv/parsers/dhcp_parsers.h> #include <dhcpsrv/parsers/duid_config_parser.h> diff --git a/src/hooks/dhcp/pgsql_cb/pgsql_cb_impl.h b/src/hooks/dhcp/pgsql_cb/pgsql_cb_impl.h index f0a046d283..ef4bd42074 100644 --- a/src/hooks/dhcp/pgsql_cb/pgsql_cb_impl.h +++ b/src/hooks/dhcp/pgsql_cb/pgsql_cb_impl.h @@ -112,12 +112,12 @@ public: virtual ~PgSqlConfigBackendImpl(); /// @todo: implement condCreateInteger(const util::Optional<T>& value) - static db::PsqlBindArrayPtr createBinding(const Triplet<uint32_t>& triplet); - static db::PsqlBindArrayPtr createMaxBinding(const Triplet<uint32_t>& triplet); - static db::PsqlBindArrayPtr createMinBinding(const Triplet<uint32_t>& triplet); + static db::PsqlBindArrayPtr createBinding(const isc::util::Triplet<uint32_t>& triplet); + static db::PsqlBindArrayPtr createMaxBinding(const isc::util::Triplet<uint32_t>& triplet); + static db::PsqlBindArrayPtr createMinBinding(const isc::util::Triplet<uint32_t>& triplet); #if 0 - static Triplet<uint32_t> createTriplet(const db::PsqlBindArrayPtr& binding); - static Triplet<uint32_t> createTriplet(const db::PsqlBindArrayPtr& def_binding, + static isc::util::Triplet<uint32_t> createTriplet(const db::PsqlBindArrayPtr& binding); + static isc::util::Triplet<uint32_t> createTriplet(const db::PsqlBindArrayPtr& def_binding, const db::PsqlBindArrayPtr& min_binding, const db::PsqlBindArrayPtr& max_binding); #endif diff --git a/src/hooks/dhcp/pgsql_cb/tests/pgsql_cb_impl_unittest.cc b/src/hooks/dhcp/pgsql_cb/tests/pgsql_cb_impl_unittest.cc index b4dff0abeb..fda1e93df7 100644 --- a/src/hooks/dhcp/pgsql_cb/tests/pgsql_cb_impl_unittest.cc +++ b/src/hooks/dhcp/pgsql_cb/tests/pgsql_cb_impl_unittest.cc @@ -16,6 +16,7 @@ using namespace isc::db; using namespace isc::dhcp; using namespace isc::dhcp::test; +using namespace isc::util; namespace { @@ -29,13 +30,16 @@ public: params["password"] = "keatest"; params["user"] = "keatest"; - createDummySchema(); + //createDummySchema(); + createFullSchema(); cbptr_.reset(new PgSqlConfigBackendImpl(params, 0)); } ~PgsqlConfigBackendTest() { - destroyDummySchema(); + destroyFullSchema(); + + //destroyDummySchema(); } /// @brief Creates the absolute minimum schema. @@ -57,6 +61,7 @@ public: // Dummy schema queries const char* sql[] = { + "DROP TABLE IF EXISTS schema_version;", "CREATE TABLE schema_version (version INT PRIMARY KEY NOT NULL, minor INT);", "INSERT INTO schema_version VALUES (7,0);" }; @@ -92,7 +97,7 @@ public: /// Don't forget to tear it down with @ref destroyFullSchema(); void createFullSchema() { // Create the actual full Kea schema. - isc::db::test::createPgSQLSchema(true, true); + isc::db::test::createPgSQLSchema(); } /// @brief destroys the full schema (slow!) @@ -100,7 +105,7 @@ public: /// Don't forget to call this method once you're done, if you used @ref createFullSchema(). void destroyFullSchema() { // Clean up after ourselves. - isc::db::test::destroyPgSQLSchema(true, true); + isc::db::test::destroyPgSQLSchema(); } /// @brief checks if specified triplet generating function stores the values properly. diff --git a/src/lib/cc/simple_parser.cc b/src/lib/cc/simple_parser.cc index 1d77a7b7cf..dbde486748 100644 --- a/src/lib/cc/simple_parser.cc +++ b/src/lib/cc/simple_parser.cc @@ -281,7 +281,7 @@ SimpleParser::deriveParams(ConstElementPtr parent, return (cnt); } -const Triplet<uint32_t> +const util::Triplet<uint32_t> SimpleParser::parseIntTriplet(const ConstElementPtr& scope, const std::string& name) { // Initialize as some compilers complain otherwise. @@ -304,7 +304,7 @@ SimpleParser::parseIntTriplet(const ConstElementPtr& scope, has_max = true; } if (!has_value && !has_min && !has_max) { - return (Triplet<uint32_t>()); + return (util::Triplet<uint32_t>()); } if (has_value) { if (!has_min && !has_max) { @@ -359,7 +359,7 @@ SimpleParser::parseIntTriplet(const ConstElementPtr& scope, << min_value << ") and max-" << name << " (" << max_value << ")"); } - return (Triplet<uint32_t>(min_value, value, max_value)); + return (util::Triplet<uint32_t>(min_value, value, max_value)); } }; // end of isc::dhcp namespace diff --git a/src/lib/cc/simple_parser.h b/src/lib/cc/simple_parser.h index 34a207b516..b91ba54b3b 100644 --- a/src/lib/cc/simple_parser.h +++ b/src/lib/cc/simple_parser.h @@ -10,7 +10,7 @@ #include <asiolink/io_address.h> #include <cc/data.h> #include <cc/dhcp_config_error.h> -#include <dhcpsrv/triplet.h> +#include <util/triplet.h> #include <map> #include <vector> #include <string> @@ -329,8 +329,8 @@ public: /// to be parsed. /// @param name Base name of the parameter. /// @return A triplet with the parsed value. - const dhcp::Triplet<uint32_t> parseIntTriplet(const data::ConstElementPtr& scope, - const std::string& name); + const isc::util::Triplet<uint32_t> parseIntTriplet(const data::ConstElementPtr& scope, + const std::string& name); }; }; diff --git a/src/lib/dhcpsrv/Makefile.am b/src/lib/dhcpsrv/Makefile.am index 7ecf8b9dfa..5822a2e407 100644 --- a/src/lib/dhcpsrv/Makefile.am +++ b/src/lib/dhcpsrv/Makefile.am @@ -153,7 +153,6 @@ libkea_dhcpsrv_la_SOURCES += subnet.cc subnet.h libkea_dhcpsrv_la_SOURCES += subnet_id.h libkea_dhcpsrv_la_SOURCES += subnet_selector.h libkea_dhcpsrv_la_SOURCES += timer_mgr.cc timer_mgr.h -libkea_dhcpsrv_la_SOURCES += triplet.h libkea_dhcpsrv_la_SOURCES += utils.h libkea_dhcpsrv_la_SOURCES += writable_host_data_source.h @@ -374,7 +373,6 @@ libkea_dhcpsrv_include_HEADERS = \ subnet_id.h \ subnet_selector.h \ timer_mgr.h \ - triplet.h \ utils.h \ writable_host_data_source.h diff --git a/src/lib/dhcpsrv/client_class_def.cc b/src/lib/dhcpsrv/client_class_def.cc index cbc2fede57..7930231a7f 100644 --- a/src/lib/dhcpsrv/client_class_def.cc +++ b/src/lib/dhcpsrv/client_class_def.cc @@ -264,8 +264,8 @@ ClientClassDictionary::addClass(const std::string& name, asiolink::IOAddress next_server, const std::string& sname, const std::string& filename, - const Triplet<uint32_t>& valid, - const Triplet<uint32_t>& preferred) { + const util::Triplet<uint32_t>& valid, + const util::Triplet<uint32_t>& preferred) { ClientClassDefPtr cclass(new ClientClassDef(name, match_expr, cfg_option)); cclass->setTest(test); cclass->setRequired(required); diff --git a/src/lib/dhcpsrv/client_class_def.h b/src/lib/dhcpsrv/client_class_def.h index 012f3e9c39..b2c288144d 100644 --- a/src/lib/dhcpsrv/client_class_def.h +++ b/src/lib/dhcpsrv/client_class_def.h @@ -12,7 +12,7 @@ #include <cc/user_context.h> #include <dhcpsrv/cfg_option.h> #include <dhcpsrv/cfg_option_def.h> -#include <dhcpsrv/triplet.h> +#include <util/triplet.h> #include <eval/token.h> #include <exceptions/exceptions.h> @@ -197,28 +197,28 @@ public: /// @brief Return valid-lifetime value /// /// @return a triplet containing the valid lifetime. - Triplet<uint32_t> getValid() const { + util::Triplet<uint32_t> getValid() const { return (valid_); } /// @brief Sets new valid lifetime /// /// @param valid New valid lifetime in seconds. - void setValid(const Triplet<uint32_t>& valid) { + void setValid(const util::Triplet<uint32_t>& valid) { valid_ = valid; } /// @brief Return preferred-lifetime value /// /// @return a triplet containing the preferred lifetime. - Triplet<uint32_t> getPreferred() const { + util::Triplet<uint32_t> getPreferred() const { return (preferred_); } /// @brief Sets new preferred lifetime /// /// @param preferred New valid lifetime in seconds. - void setPreferred(const Triplet<uint32_t>& preferred) { + void setPreferred(const util::Triplet<uint32_t>& preferred) { preferred_ = preferred; } @@ -279,10 +279,10 @@ private: std::string filename_; /// @brief a Triplet (min/default/max) holding allowed valid lifetime values - Triplet<uint32_t> valid_; + util::Triplet<uint32_t> valid_; /// @brief a Triplet (min/default/max) holding allowed preferred lifetime values - Triplet<uint32_t> preferred_; + util::Triplet<uint32_t> preferred_; }; /// @brief a pointer to an ClientClassDef @@ -339,8 +339,8 @@ public: asiolink::IOAddress next_server = asiolink::IOAddress("0.0.0.0"), const std::string& sname = std::string(), const std::string& filename = std::string(), - const Triplet<uint32_t>&valid = Triplet<uint32_t>(), - const Triplet<uint32_t>&preferred = Triplet<uint32_t>()); + const util::Triplet<uint32_t>&valid = util::Triplet<uint32_t>(), + const util::Triplet<uint32_t>&preferred = util::Triplet<uint32_t>()); /// @brief Adds a new class to the list /// diff --git a/src/lib/dhcpsrv/network.h b/src/lib/dhcpsrv/network.h index 1ca386f7f5..5521afacab 100644 --- a/src/lib/dhcpsrv/network.h +++ b/src/lib/dhcpsrv/network.h @@ -17,7 +17,7 @@ #include <dhcpsrv/cfg_option.h> #include <dhcpsrv/cfg_4o6.h> #include <dhcpsrv/d2_client_cfg.h> -#include <dhcpsrv/triplet.h> +#include <util/triplet.h> #include <util/optional.h> #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> @@ -337,7 +337,7 @@ public: /// @brief Return valid-lifetime for addresses in that prefix /// /// @param inheritance inheritance mode to be used. - Triplet<uint32_t> getValid(const Inheritance& inheritance = Inheritance::ALL) const { + isc::util::Triplet<uint32_t> getValid(const Inheritance& inheritance = Inheritance::ALL) const { return (getProperty<Network>(&Network::getValid, valid_, inheritance, "valid-lifetime", "min-valid-lifetime", "max-valid-lifetime")); @@ -346,35 +346,35 @@ public: /// @brief Sets new valid lifetime for a network. /// /// @param valid New valid lifetime in seconds. - void setValid(const Triplet<uint32_t>& valid) { + void setValid(const isc::util::Triplet<uint32_t>& valid) { valid_ = valid; } /// @brief Returns T1 (renew timer), expressed in seconds /// /// @param inheritance inheritance mode to be used. - Triplet<uint32_t> getT1(const Inheritance& inheritance = Inheritance::ALL) const { + isc::util::Triplet<uint32_t> getT1(const Inheritance& inheritance = Inheritance::ALL) const { return (getProperty<Network>(&Network::getT1, t1_, inheritance, "renew-timer")); } /// @brief Sets new renew timer for a network. /// /// @param t1 New renew timer value in seconds. - void setT1(const Triplet<uint32_t>& t1) { + void setT1(const isc::util::Triplet<uint32_t>& t1) { t1_ = t1; } /// @brief Returns T2 (rebind timer), expressed in seconds /// /// @param inheritance inheritance mode to be used. - Triplet<uint32_t> getT2(const Inheritance& inheritance = Inheritance::ALL) const { + isc::util::Triplet<uint32_t> getT2(const Inheritance& inheritance = Inheritance::ALL) const { return (getProperty<Network>(&Network::getT2, t2_, inheritance, "rebind-timer")); } /// @brief Sets new rebind timer for a network. /// /// @param t2 New rebind timer value in seconds. - void setT2(const Triplet<uint32_t>& t2) { + void setT2(const isc::util::Triplet<uint32_t>& t2) { t2_ = t2; } @@ -798,7 +798,7 @@ protected: return (property); } - /// @brief The @c getGlobalProperty specialization for Triplet<T>. + /// @brief The @c getGlobalProperty specialization for isc::util::Triplet<T>. /// /// @note: use overloading vs specialization because full specialization /// is not allowed in this scope. @@ -817,7 +817,7 @@ protected: /// @return Optional value fetched from the global level or the value /// of @c property. template<typename NumType> - Triplet<NumType> getGlobalProperty(Triplet<NumType> property, + isc::util::Triplet<NumType> getGlobalProperty(isc::util::Triplet<NumType> property, const std::string& global_name, const std::string& min_name = "", const std::string& max_name = "") const { @@ -841,7 +841,7 @@ protected: if (max_param) { max_value = static_cast<NumType>(max_param->intValue()); } - return (Triplet<NumType>(min_value, def_value, max_value)); + return (isc::util::Triplet<NumType>(min_value, def_value, max_value)); } } } @@ -879,7 +879,7 @@ protected: /// /// This template method provides a generic mechanism to retrieve a /// network parameter using inheritance. It is called from public - /// accessor methods which return an @c OptionalValue or @c Triplet. + /// accessor methods which return an @c OptionalValue or @c isc::util::Triplet. /// /// @tparam BaseType Type of this instance, e.g. @c Network, @c Network4 /// etc, which exposes a method to be called. @@ -1043,14 +1043,14 @@ protected: /// incoming packet and their evaluation will be required. ClientClasses required_classes_; - /// @brief a Triplet (min/default/max) holding allowed renew timer values - Triplet<uint32_t> t1_; + /// @brief a isc::util::Triplet (min/default/max) holding allowed renew timer values + isc::util::Triplet<uint32_t> t1_; - /// @brief a Triplet (min/default/max) holding allowed rebind timer values - Triplet<uint32_t> t2_; + /// @brief a isc::util::Triplet (min/default/max) holding allowed rebind timer values + isc::util::Triplet<uint32_t> t2_; - /// @brief a Triplet (min/default/max) holding allowed valid lifetime values - Triplet<uint32_t> valid_; + /// @brief a isc::util::Triplet (min/default/max) holding allowed valid lifetime values + isc::util::Triplet<uint32_t> valid_; /// @brief Enables global reservations. util::Optional<bool> reservations_global_; @@ -1276,7 +1276,7 @@ public: /// /// @param inheritance inheritance mode to be used. /// @return a triplet with preferred lifetime - Triplet<uint32_t> + isc::util::Triplet<uint32_t> getPreferred(const Inheritance& inheritance = Inheritance::ALL) const { return (getProperty<Network6>(&Network6::getPreferred, preferred_, inheritance, "preferred-lifetime", @@ -1287,7 +1287,7 @@ public: /// @brief Sets new preferred lifetime for a network. /// /// @param preferred New preferred lifetime in seconds. - void setPreferred(const Triplet<uint32_t>& preferred) { + void setPreferred(const isc::util::Triplet<uint32_t>& preferred) { preferred_ = preferred; } @@ -1335,7 +1335,7 @@ public: private: /// @brief a triplet with preferred lifetime (in seconds) - Triplet<uint32_t> preferred_; + isc::util::Triplet<uint32_t> preferred_; /// @brief specifies optional interface-id OptionPtr interface_id_; diff --git a/src/lib/dhcpsrv/parsers/base_network_parser.cc b/src/lib/dhcpsrv/parsers/base_network_parser.cc index 88f5886169..21c6d7a305 100644 --- a/src/lib/dhcpsrv/parsers/base_network_parser.cc +++ b/src/lib/dhcpsrv/parsers/base_network_parser.cc @@ -5,7 +5,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. #include <config.h> -#include <dhcpsrv/triplet.h> +#include <util/triplet.h> #include <dhcpsrv/parsers/base_network_parser.h> #include <util/optional.h> #include <util/strutil.h> diff --git a/src/lib/dhcpsrv/parsers/client_class_def_parser.cc b/src/lib/dhcpsrv/parsers/client_class_def_parser.cc index 4899f0a79f..07107a2baf 100644 --- a/src/lib/dhcpsrv/parsers/client_class_def_parser.cc +++ b/src/lib/dhcpsrv/parsers/client_class_def_parser.cc @@ -22,6 +22,7 @@ using namespace isc::data; using namespace isc::asiolink; +using namespace isc::util; using namespace std; /// @file client_class_def_parser.cc diff --git a/src/lib/dhcpsrv/subnet.h b/src/lib/dhcpsrv/subnet.h index 07458b25cf..990d95fb6f 100644 --- a/src/lib/dhcpsrv/subnet.h +++ b/src/lib/dhcpsrv/subnet.h @@ -15,7 +15,7 @@ #include <dhcpsrv/network.h> #include <dhcpsrv/pool.h> #include <dhcpsrv/subnet_id.h> -#include <dhcpsrv/triplet.h> +#include <util/triplet.h> #include <boost/multi_index/mem_fun.hpp> #include <boost/multi_index/indexed_by.hpp> #include <boost/multi_index/ordered_index.hpp> @@ -541,9 +541,9 @@ public: /// @param id arbitrary subnet id, default value of 0 triggers /// autogeneration of subnet id Subnet4(const isc::asiolink::IOAddress& prefix, uint8_t length, - const Triplet<uint32_t>& t1, - const Triplet<uint32_t>& t2, - const Triplet<uint32_t>& valid_lifetime, + const util::Triplet<uint32_t>& t1, + const util::Triplet<uint32_t>& t2, + const util::Triplet<uint32_t>& valid_lifetime, const SubnetID id = 0); /// @brief Factory function creating an instance of the @c Subnet4. @@ -564,9 +564,9 @@ public: /// @return Pointer to the @c Subnet4 instance. static Subnet4Ptr create(const isc::asiolink::IOAddress& prefix, uint8_t length, - const Triplet<uint32_t>& t1, - const Triplet<uint32_t>& t2, - const Triplet<uint32_t>& valid_lifetime, + const util::Triplet<uint32_t>& t1, + const util::Triplet<uint32_t>& t2, + const util::Triplet<uint32_t>& valid_lifetime, const SubnetID id = 0); /// @brief Returns next subnet within shared network. @@ -690,10 +690,10 @@ public: /// @param id arbitrary subnet id, default value of 0 triggers /// autogeneration of subnet id Subnet6(const isc::asiolink::IOAddress& prefix, uint8_t length, - const Triplet<uint32_t>& t1, - const Triplet<uint32_t>& t2, - const Triplet<uint32_t>& preferred_lifetime, - const Triplet<uint32_t>& valid_lifetime, + const util::Triplet<uint32_t>& t1, + const util::Triplet<uint32_t>& t2, + const util::Triplet<uint32_t>& preferred_lifetime, + const util::Triplet<uint32_t>& valid_lifetime, const SubnetID id = 0); /// @brief Factory function creating an instance of the @c Subnet4. @@ -715,10 +715,10 @@ public: /// @return Pointer to the @c Subnet6 instance. static Subnet6Ptr create(const isc::asiolink::IOAddress& prefix, uint8_t length, - const Triplet<uint32_t>& t1, - const Triplet<uint32_t>& t2, - const Triplet<uint32_t>& preferred_lifetime, - const Triplet<uint32_t>& valid_lifetime, + const util::Triplet<uint32_t>& t1, + const util::Triplet<uint32_t>& t2, + const util::Triplet<uint32_t>& preferred_lifetime, + const util::Triplet<uint32_t>& valid_lifetime, const SubnetID id = 0); /// @brief Returns next subnet within shared network. diff --git a/src/lib/dhcpsrv/tests/Makefile.am b/src/lib/dhcpsrv/tests/Makefile.am index 8aba044350..5a0dc629c9 100644 --- a/src/lib/dhcpsrv/tests/Makefile.am +++ b/src/lib/dhcpsrv/tests/Makefile.am @@ -130,7 +130,6 @@ libdhcpsrv_unittests_SOURCES += shared_networks_list_parser_unittest.cc libdhcpsrv_unittests_SOURCES += srv_config_unittest.cc libdhcpsrv_unittests_SOURCES += subnet_unittest.cc libdhcpsrv_unittests_SOURCES += test_get_callout_handle.cc test_get_callout_handle.h -libdhcpsrv_unittests_SOURCES += triplet_unittest.cc libdhcpsrv_unittests_SOURCES += timer_mgr_unittest.cc libdhcpsrv_unittests_SOURCES += network_state_unittest.cc libdhcpsrv_unittests_SOURCES += network_unittest.cc diff --git a/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc index 598c303b3b..a0941f9ca5 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc @@ -22,6 +22,7 @@ using namespace isc::hooks; using namespace isc::asiolink; using namespace isc::data; using namespace isc::stats; +using namespace isc::util; namespace isc { namespace dhcp { diff --git a/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc index 825b74386b..f833c3a02b 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc @@ -18,6 +18,7 @@ using namespace isc::hooks; using namespace isc::asiolink; using namespace isc::stats; using namespace isc::data; +using namespace isc::util; namespace isc { namespace dhcp { diff --git a/src/lib/dhcpsrv/tests/alloc_engine_utils.cc b/src/lib/dhcpsrv/tests/alloc_engine_utils.cc index daa85e574b..bcda6ba57b 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine_utils.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine_utils.cc @@ -34,6 +34,7 @@ using namespace std; using namespace isc::hooks; using namespace isc::asiolink; using namespace isc::stats; +using namespace isc::util; namespace isc { namespace dhcp { diff --git a/src/lib/dhcpsrv/tests/cfg_shared_networks4_unittest.cc b/src/lib/dhcpsrv/tests/cfg_shared_networks4_unittest.cc index fcc7ad8f2c..fbb554565e 100644 --- a/src/lib/dhcpsrv/tests/cfg_shared_networks4_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_shared_networks4_unittest.cc @@ -14,6 +14,7 @@ using namespace isc; using namespace isc::dhcp; +using namespace isc::util; using namespace asiolink; namespace { diff --git a/src/lib/dhcpsrv/tests/cfg_shared_networks6_unittest.cc b/src/lib/dhcpsrv/tests/cfg_shared_networks6_unittest.cc index c44156ad3a..b884a890a1 100644 --- a/src/lib/dhcpsrv/tests/cfg_shared_networks6_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_shared_networks6_unittest.cc @@ -14,6 +14,7 @@ using namespace isc; using namespace isc::dhcp; +using namespace isc::util; using namespace asiolink; namespace { diff --git a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc index 365a469fc6..64627e1d43 100644 --- a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc @@ -37,6 +37,7 @@ using namespace isc::dhcp; using namespace isc::dhcp::test; using namespace isc::stats; using namespace isc::test; +using namespace isc::util; namespace { diff --git a/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc index 4a461bf54c..efb9111b69 100644 --- a/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc @@ -34,6 +34,7 @@ using namespace isc::dhcp; using namespace isc::dhcp::test; using namespace isc::stats; using namespace isc::test; +using namespace isc::util; namespace { diff --git a/src/lib/dhcpsrv/tests/client_class_def_parser_unittest.cc b/src/lib/dhcpsrv/tests/client_class_def_parser_unittest.cc index 11601a8240..a12a1ea99a 100644 --- a/src/lib/dhcpsrv/tests/client_class_def_parser_unittest.cc +++ b/src/lib/dhcpsrv/tests/client_class_def_parser_unittest.cc @@ -27,6 +27,7 @@ using namespace isc::data; using namespace isc::dhcp; using namespace isc::asiolink; +using namespace isc::util; namespace { diff --git a/src/lib/dhcpsrv/tests/shared_network_unittest.cc b/src/lib/dhcpsrv/tests/shared_network_unittest.cc index a2318d82c7..85763c5184 100644 --- a/src/lib/dhcpsrv/tests/shared_network_unittest.cc +++ b/src/lib/dhcpsrv/tests/shared_network_unittest.cc @@ -12,7 +12,7 @@ #include <dhcpsrv/shared_network.h> #include <dhcpsrv/subnet.h> #include <dhcpsrv/subnet_id.h> -#include <dhcpsrv/triplet.h> +#include <util/triplet.h> #include <exceptions/exceptions.h> #include <testutils/test_to_element.h> #include <testutils/multi_threading_utils.h> diff --git a/src/lib/dhcpsrv/tests/srv_config_unittest.cc b/src/lib/dhcpsrv/tests/srv_config_unittest.cc index 7c2663f79f..b9390c1785 100644 --- a/src/lib/dhcpsrv/tests/srv_config_unittest.cc +++ b/src/lib/dhcpsrv/tests/srv_config_unittest.cc @@ -21,6 +21,7 @@ using namespace isc::asiolink; using namespace isc::dhcp; using namespace isc::data; using namespace isc::process; +using namespace isc::util; // Those are the tests for SrvConfig storage. Right now they are minimal, // but the number is expected to grow significantly once we migrate more diff --git a/src/lib/dhcpsrv/tests/subnet_unittest.cc b/src/lib/dhcpsrv/tests/subnet_unittest.cc index af2e1a80a3..f19b06efac 100644 --- a/src/lib/dhcpsrv/tests/subnet_unittest.cc +++ b/src/lib/dhcpsrv/tests/subnet_unittest.cc @@ -32,6 +32,7 @@ using namespace isc; using namespace isc::dhcp; using namespace isc::asiolink; using namespace isc::test; +using namespace isc::util; namespace { diff --git a/src/lib/dhcpsrv/tests/triplet_unittest.cc b/src/lib/dhcpsrv/tests/triplet_unittest.cc index 1618b30f5e..23e3b8a225 100644 --- a/src/lib/dhcpsrv/tests/triplet_unittest.cc +++ b/src/lib/dhcpsrv/tests/triplet_unittest.cc @@ -6,14 +6,14 @@ #include <config.h> -#include <dhcpsrv/triplet.h> +#include <util/triplet.h> #include <exceptions/exceptions.h> #include <gtest/gtest.h> #include <stdint.h> -using namespace isc::dhcp; +using namespace isc::util; using namespace isc; namespace { diff --git a/src/lib/dhcpsrv/triplet.h b/src/lib/dhcpsrv/triplet.h deleted file mode 100644 index 02222f8060..0000000000 --- a/src/lib/dhcpsrv/triplet.h +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (C) 2012-2019 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/. - -#ifndef TRIPLET_H -#define TRIPLET_H - -#include <exceptions/exceptions.h> -#include <util/optional.h> - -namespace isc { -namespace dhcp { - -/// @brief This template specifies a parameter value -/// -/// This template class is used to store configuration parameters, like lifetime -/// or T1. It defines 3 parameters: min, default, and max value. If the -/// particular configuration parameter is not mandatory, it is possible to -/// mark the parameter described by a @c Triplet "unspecified". For example, the -/// T1 and T2 values in DHCPv4 server are optional and may be not specified -/// in the configuration. The @c Triplets describing these parameters will be -/// marked "unspecified". If the server finds that the particular parameter -/// is unspecified it will not include it (e.g. option 58 or 59) in the message -/// to a client. -/// -/// There are 3 constructors: -/// - without parameters - marks the parameter "unspecified" -/// - simple (just one value that sets all parameters) -/// - extended (that sets default value and two thresholds) -/// -/// It will be used with integer types. It provides necessary operators, so -/// it can be assigned to a plain integer or integer assigned to a Triplet. -/// See TripletTest.operator test for details on an easy Triplet usage. -template <class T> -class Triplet : public util::Optional<T> { -public: - - using util::Optional<T>::get; - - /// @brief Base type to Triplet conversion. - /// - /// Typically: uint32_t to Triplet assignment. It is very convenient - /// to be able to simply write Triplet<uint32_t> x = 7; - /// - /// @param other A number to be assigned as min, max and default value. - Triplet<T>& operator=(T other) { - min_ = other; - util::Optional<T>::default_ = other; - max_ = other; - // The value is now specified because we just assigned one. - util::Optional<T>::unspecified_ = false; - return (*this); - } - - /// @brief Constructor without parameters. - /// - /// Marks value in @c Triplet unspecified. - Triplet() - : util::Optional<T>(), min_(0), max_(0) { - } - - /// @brief Sets a fixed value. - /// - /// This constructor assigns a fixed (i.e. no range, just a single value) - /// value. - /// - /// @param value A number to be assigned as min, max and default value. - Triplet(T value) - : util::Optional<T>(value), min_(value), max_(value) { - } - - /// @brief Sets the default value and thresholds - /// - /// @throw BadValue if min <= def <= max rule is violated - Triplet(T min, T def, T max) - : util::Optional<T>(def), min_(min), max_(max) { - if ( (min_ > def) || (def > max_) ) { - isc_throw(BadValue, "Invalid triplet values."); - } - } - - /// @brief Returns a minimum allowed value - T getMin() const { return (min_);} - - /// @brief Returns value with a hint - /// - /// DHCP protocol treats any values sent by a client as hints. - /// This is a method that implements that. We can assign any value - /// from configured range that client asks. - /// - /// @param hint A value being returned when if it is within the range - /// between min and max value of @c Triplet. If the hint value is lower - /// than min value, the min value is returned. if the hint is greater - /// than max value, the max value is returned. - /// - /// @return A value adjusted to the hint. - T get(T hint) const { - if (hint <= min_) { - return (min_); - } - - if (hint >= max_) { - return (max_); - } - - return (hint); - } - - /// @brief Returns a maximum allowed value - T getMax() const { return (max_); } - -private: - - /// @brief the minimum value - T min_; - - /// @brief the maximum value - T max_; -}; - - -} // namespace isc::dhcp -} // namespace isc - -#endif // TRIPLET_H diff --git a/src/lib/util/Makefile.am b/src/lib/util/Makefile.am index e596b0249c..a86cf0e82e 100644 --- a/src/lib/util/Makefile.am +++ b/src/lib/util/Makefile.am @@ -30,6 +30,7 @@ libkea_util_la_SOURCES += stopwatch_impl.cc stopwatch_impl.h libkea_util_la_SOURCES += strutil.h strutil.cc libkea_util_la_SOURCES += thread_pool.h libkea_util_la_SOURCES += time_utilities.h time_utilities.cc +libkea_util_la_SOURCES += triplet.h libkea_util_la_SOURCES += unlock_guard.h libkea_util_la_SOURCES += versioned_csv_file.h versioned_csv_file.cc libkea_util_la_SOURCES += watch_socket.cc watch_socket.h @@ -76,6 +77,7 @@ libkea_util_include_HEADERS = \ strutil.h \ thread_pool.h \ time_utilities.h \ + triplet.h \ unlock_guard.h \ versioned_csv_file.h \ watch_socket.h \ |