using namespace isc::asiolink;
using namespace isc::config;
using namespace isc::dhcp::test;
+using namespace isc::util;
namespace {
#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>
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
using namespace isc::db;
using namespace isc::dhcp;
using namespace isc::dhcp::test;
+using namespace isc::util;
namespace {
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.
// 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);"
};
/// 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!)
/// 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.
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.
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) {
<< 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
#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>
/// 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);
};
};
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
subnet_id.h \
subnet_selector.h \
timer_mgr.h \
- triplet.h \
utils.h \
writable_host_data_source.h
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);
#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>
/// @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;
}
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
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
///
#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>
/// @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"));
/// @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;
}
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.
/// @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 {
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));
}
}
}
///
/// 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.
/// 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_;
///
/// @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",
/// @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;
}
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_;
// 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>
using namespace isc::data;
using namespace isc::asiolink;
+using namespace isc::util;
using namespace std;
/// @file client_class_def_parser.cc
#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>
/// @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.
/// @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.
/// @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.
/// @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.
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
using namespace isc::asiolink;
using namespace isc::data;
using namespace isc::stats;
+using namespace isc::util;
namespace isc {
namespace dhcp {
using namespace isc::asiolink;
using namespace isc::stats;
using namespace isc::data;
+using namespace isc::util;
namespace isc {
namespace dhcp {
using namespace isc::hooks;
using namespace isc::asiolink;
using namespace isc::stats;
+using namespace isc::util;
namespace isc {
namespace dhcp {
using namespace isc;
using namespace isc::dhcp;
+using namespace isc::util;
using namespace asiolink;
namespace {
using namespace isc;
using namespace isc::dhcp;
+using namespace isc::util;
using namespace asiolink;
namespace {
using namespace isc::dhcp::test;
using namespace isc::stats;
using namespace isc::test;
+using namespace isc::util;
namespace {
using namespace isc::dhcp::test;
using namespace isc::stats;
using namespace isc::test;
+using namespace isc::util;
namespace {
using namespace isc::data;
using namespace isc::dhcp;
using namespace isc::asiolink;
+using namespace isc::util;
namespace {
#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>
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
using namespace isc::dhcp;
using namespace isc::asiolink;
using namespace isc::test;
+using namespace isc::util;
namespace {
#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 {
+++ /dev/null
-// 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
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
strutil.h \
thread_pool.h \
time_utilities.h \
+ triplet.h \
unlock_guard.h \
versioned_csv_file.h \
watch_socket.h \