From 246d8899931e106f7d97803d8e90a0b8d7bacdcb Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Fri, 8 Feb 2019 17:58:47 +0100 Subject: [PATCH] [458-config-backend-support-in-src-lib] Updated config backed code and test utils to handle DHCPv6 --- src/lib/dhcpsrv/Makefile.am | 3 + src/lib/dhcpsrv/config_backend_dhcp6.h | 435 +++++++++++++++ src/lib/dhcpsrv/config_backend_dhcp6_mgr.cc | 41 ++ src/lib/dhcpsrv/config_backend_dhcp6_mgr.h | 71 +++ src/lib/dhcpsrv/config_backend_pool_dhcp6.cc | 441 +++++++++++++++ src/lib/dhcpsrv/config_backend_pool_dhcp6.h | 520 +++++++++++++++++ src/lib/dhcpsrv/testutils/Makefile.am | 1 + .../dhcpsrv/testutils/test_config_backend.h | 3 +- .../testutils/test_config_backend_dhcp6.cc | 525 ++++++++++++++++++ .../testutils/test_config_backend_dhcp6.h | 466 ++++++++++++++++ 10 files changed, 2505 insertions(+), 1 deletion(-) create mode 100644 src/lib/dhcpsrv/config_backend_dhcp6.h create mode 100644 src/lib/dhcpsrv/config_backend_dhcp6_mgr.cc create mode 100644 src/lib/dhcpsrv/config_backend_dhcp6_mgr.h create mode 100644 src/lib/dhcpsrv/config_backend_pool_dhcp6.cc create mode 100644 src/lib/dhcpsrv/config_backend_pool_dhcp6.h create mode 100644 src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.cc create mode 100644 src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.h diff --git a/src/lib/dhcpsrv/Makefile.am b/src/lib/dhcpsrv/Makefile.am index eaf77320d3..383760e442 100644 --- a/src/lib/dhcpsrv/Makefile.am +++ b/src/lib/dhcpsrv/Makefile.am @@ -112,6 +112,9 @@ libkea_dhcpsrv_la_SOURCES += client_class_def.cc client_class_def.h libkea_dhcpsrv_la_SOURCES += config_backend_dhcp4.h libkea_dhcpsrv_la_SOURCES += config_backend_pool_dhcp4.cc config_backend_pool_dhcp4.h libkea_dhcpsrv_la_SOURCES += config_backend_dhcp4_mgr.cc config_backend_dhcp4_mgr.h +libkea_dhcpsrv_la_SOURCES += config_backend_dhcp6.h +libkea_dhcpsrv_la_SOURCES += config_backend_pool_dhcp6.cc config_backend_pool_dhcp6.h +libkea_dhcpsrv_la_SOURCES += config_backend_dhcp6_mgr.cc config_backend_dhcp6_mgr.h libkea_dhcpsrv_la_SOURCES += csv_lease_file4.cc csv_lease_file4.h libkea_dhcpsrv_la_SOURCES += csv_lease_file6.cc csv_lease_file6.h libkea_dhcpsrv_la_SOURCES += d2_client_cfg.cc d2_client_cfg.h diff --git a/src/lib/dhcpsrv/config_backend_dhcp6.h b/src/lib/dhcpsrv/config_backend_dhcp6.h new file mode 100644 index 0000000000..f667fd2186 --- /dev/null +++ b/src/lib/dhcpsrv/config_backend_dhcp6.h @@ -0,0 +1,435 @@ +// Copyright (C) 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 CONFIG_BACKEND_DHCP6_H +#define CONFIG_BACKEND_DHCP6_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace isc { +namespace dhcp { + +/// @brief Interface implemented by DHCPv6 configuration backends. +/// +/// All POSIX times specified in the methods belonging to this +/// class must be local times. +class ConfigBackendDHCPv6 : public cb::BaseConfigBackend { +public: + + /// @brief Virtual destructor. + virtual ~ConfigBackendDHCPv6() { } + + /// @brief Retrieves a single subnet by subnet_prefix. + /// + /// @param server_selector Server selector. + /// @param subnet_prefix Prefix of the subnet to be retrieved. + /// @return Pointer to the retrieved subnet or NULL if not found. + virtual Subnet6Ptr + getSubnet6(const db::ServerSelector& server_selector, + const std::string& subnet_prefix) const = 0; + + /// @brief Retrieves a single subnet by subnet identifier. + /// + /// @param server_selector Server selector. + /// @param subnet_id Identifier of a subnet to be retrieved. + /// @return Pointer to the retrieved subnet or NULL if not found. + virtual Subnet6Ptr + getSubnet6(const db::ServerSelector& server_selector, const SubnetID& subnet_id) const = 0; + + /// @brief Retrieves all subnets. + /// + /// @param server_selector Server selector. + /// @return Collection of subnets or empty collection if no subnet found. + virtual Subnet6Collection + getAllSubnets6(const db::ServerSelector& server_selector) const = 0; + + /// @brief Retrieves all subnets belonging to a specified shared network. + /// + /// @param server_selector Server selector. + /// @param shared_network_name Name of the shared network for which the + /// subnets should be retrieved. + /// @return Collection of subnets or empty collection if no subnet found. + virtual Subnet6Collection + getSharedNetworkSubnets6(const db::ServerSelector& server_selector, + const std::string& shared_network_name) const = 0; + + /// @brief Retrieves subnets modified after specified time. + /// + /// @param server_selector Server selector. + /// @param modification_time Lower bound subnet modification time. + /// @return Collection of subnets or empty collection if no subnet found. + virtual Subnet6Collection + getModifiedSubnets6(const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const = 0; + + /// @brief Retrieves shared network by name. + /// + /// @param server_selector Server selector. + /// @param name Name of the shared network to be retrieved. + /// @return Pointer to the shared network or NULL if not found. + virtual SharedNetwork6Ptr + getSharedNetwork6(const db::ServerSelector& server_selector, + const std::string& name) const = 0; + + /// @brief Retrieves all shared networks. + /// + /// @param server_selector Server selector. + /// @return Collection of shared network or empty collection if + /// no shared network found. + virtual SharedNetwork6Collection + getAllSharedNetworks6(const db::ServerSelector& server_selector) const = 0; + + /// @brief Retrieves shared networks modified after specified time. + /// + /// @param server_selector Server selector. + /// @param modification_time Lower bound shared network modification time. + /// @return Collection of shared network or empty collection if + /// no shared network found. + virtual SharedNetwork6Collection + getModifiedSharedNetworks6(const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const = 0; + + /// @brief Retrieves single option definition by code and space. + /// + /// @param server_selector Server selector. + /// @param code Code of the option to be retrieved. + /// @param space Option space of the option to be retrieved. + /// @return Pointer to the option definition or NULL if not found. + virtual OptionDefinitionPtr + getOptionDef6(const db::ServerSelector& server_selector, const uint16_t code, + const std::string& space) const = 0; + + /// @brief Retrieves all option definitions. + /// + /// @param server_selector Server selector. + /// @return Collection of option definitions or empty collection if + /// no option definition found. + virtual OptionDefContainer + getAllOptionDefs6(const db::ServerSelector& server_selector) const = 0; + + /// @brief Retrieves option definitions modified after specified time. + /// + /// @param server_selector Server selector. + /// @param modification_time Lower bound option definition modification + /// time. + /// @return Collection of option definitions or empty collection if + /// no option definition found. + virtual OptionDefContainer + getModifiedOptionDefs6(const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const = 0; + + /// @brief Retrieves single option by code and space. + /// + /// @param server_selector Server selector. + /// @param code Option code. + /// @param space Option space. + /// @return Pointer to the retrieved option descriptor or null if + /// no option was found. + virtual OptionDescriptorPtr + getOption6(const db::ServerSelector& server_selector, const uint16_t code, + const std::string& space) const = 0; + + /// @brief Retrieves all global options. + /// + /// @param server_selector Server selector. + /// @return Collection of global options or empty collection if no + /// option found. + virtual OptionContainer + getAllOptions6(const db::ServerSelector& server_selector) const = 0; + + /// @brief Retrieves option modified after specified time. + /// + /// @param selector Server selector. + /// @param modification_time Lower bound option modification time. + /// @return Collection of global options or empty collection if no + /// option found. + virtual OptionContainer + getModifiedOptions6(const db::ServerSelector& selector, + const boost::posix_time::ptime& modification_time) const = 0; + + /// @brief Retrieves global parameter value. + /// + /// @param selector Server selector. + /// @param name Name of the global parameter to be retrieved. + /// @return Value of the global parameter or null if parameter doesn't + /// exist. + virtual data::StampedValuePtr + getGlobalParameter6(const db::ServerSelector& selector, + const std::string& name) const = 0; + + /// @return Collection of global parameters. + virtual data::StampedValueCollection + getAllGlobalParameters6(const db::ServerSelector& selector) const = 0; + + /// @brief Retrieves global parameters modified after specified time. + /// + /// @param selector Server selector. + /// @param modification_time Modification time. + /// @return Collection of modified global parameters. + virtual data::StampedValueCollection + getModifiedGlobalParameters6(const db::ServerSelector& selector, + const boost::posix_time::ptime& modification_time) const = 0; + + /// @brief Retrieves the most recent audit entries. + /// + /// @param server_selector Server selector. + /// @param modification_time Timestamp being a lower limit for the returned + /// result set, i.e. entries later than specified time are returned. + /// @return Collection of audit entries. + virtual db::AuditEntryCollection + getRecentAuditEntries6(const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const = 0; + + /// @brief Creates or updates a subnet. + /// + /// @param server_selector Server selector. + /// @param subnet Subnet to be added or updated. + virtual void + createUpdateSubnet6(const db::ServerSelector& server_selector, + const Subnet6Ptr& subnet) = 0; + + /// @brief Creates or updates a shared network. + /// + /// @param server_selector Server selector. + /// @param shared_network Shared network to be added or updated. + virtual void + createUpdateSharedNetwork6(const db::ServerSelector& server_selector, + const SharedNetwork6Ptr& shared_network) = 0; + + /// @brief Creates or updates an option definition. + /// + /// @param server_selector Server selector. + /// @param option_def Option definition to be added or updated. + virtual void + createUpdateOptionDef6(const db::ServerSelector& server_selector, + const OptionDefinitionPtr& option_def) = 0; + + /// @brief Creates or updates global option. + /// + /// @param server_selector Server selector. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::ServerSelector& server_selector, + const OptionDescriptorPtr& option) = 0; + + /// @brief Creates or updates shared network level option. + /// + /// @param selector Server selector. + /// @param shared_network_name Name of a shared network to which option + /// belongs. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::ServerSelector& selector, + const std::string& shared_network_name, + const OptionDescriptorPtr& option) = 0; + + /// @brief Creates or updates subnet level option. + /// + /// @param server_selector Server selector. + /// @param subnet_id Identifier of a subnet to which option belongs. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::ServerSelector& server_selector, + const SubnetID& subnet_id, + const OptionDescriptorPtr& option) = 0; + + /// @brief Creates or updates pool level option. + /// + /// @param server_selector Server selector. + /// @param pool_start_address Lower bound address of the pool to which + /// the option belongs. + /// @param pool_end_address Upper bound address of the pool to which the + /// option belongs. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::ServerSelector& server_selector, + const asiolink::IOAddress& pool_start_address, + const asiolink::IOAddress& pool_end_address, + const OptionDescriptorPtr& option) = 0; + + /// @brief Creates or updates pd pool level option. + /// + /// @param server_selector Server selector. + /// @param pd_pool_prefix Address part of the prefix of the pd pool + /// to which the option belongs. + /// @param pd_pool_prefix_length Prefix length of the pd pool to which + /// the option belongs. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::ServerSelector& server_selector, + const asiolink::IOAddress& pd_pool_prefix, + const uint8_t pd_pool_prefix_length, + const OptionDescriptorPtr& option) = 0; + + /// @brief Creates or updates global parameter. + /// + /// @param server_selector Server selector. + /// @param value Value of the global parameter. + virtual void + createUpdateGlobalParameter6(const db::ServerSelector& server_selector, + const data::StampedValuePtr& value) = 0; + + /// @brief Deletes subnet by prefix. + /// + /// @param server_selector Server selector. + /// @param subnet_prefix Prefix of the subnet to be deleted. + /// @return Number of deleted subnets. + virtual uint64_t + deleteSubnet6(const db::ServerSelector& server_selector, + const std::string& subnet_prefix) = 0; + + /// @brief Deletes subnet by identifier. + /// + /// @param server_selector Server selector. + /// @param subnet_id Identifier of the subnet to be deleted. + /// @return Number of deleted subnets. + virtual uint64_t + deleteSubnet6(const db::ServerSelector& server_selector, const SubnetID& subnet_id) = 0; + + /// @brief Deletes all subnets. + /// + /// @param server_selector Server selector. + /// @return Number of deleted subnets. + virtual uint64_t + deleteAllSubnets6(const db::ServerSelector& server_selector) = 0; + + /// @brief Deletes shared network by name. + /// + /// @param server_selector Server selector. + /// @param name Name of the shared network to be deleted. + /// @return Number of deleted shared networks.. + virtual uint64_t + deleteSharedNetwork6(const db::ServerSelector& server_selector, + const std::string& name) = 0; + + /// @brief Deletes all shared networks. + /// + /// @param server_selector Server selector. + /// @return Number of deleted shared networks. + virtual uint64_t + deleteAllSharedNetworks6(const db::ServerSelector& server_selector) = 0; + + /// @brief Deletes option definition. + /// + /// @param server_selector Server selector. + /// @param code Code of the option to be deleted. + /// @param space Option space of the option to be deleted. + /// @return Number of deleted option definitions. + virtual uint64_t + deleteOptionDef6(const db::ServerSelector& server_selector, const uint16_t code, + const std::string& space) = 0; + + /// @brief Deletes all option definitions. + /// + /// @param server_selector Server selector. + /// @return Number of deleted option definitions. + virtual uint64_t + deleteAllOptionDefs6(const db::ServerSelector& server_selector) = 0; + + /// @brief Deletes global option. + /// + /// @param server_selector Server selector. + /// @param code Code of the option to be deleted. + /// @param space Option space of the option to be deleted. + /// @return Number of deleted options. + virtual uint64_t + deleteOption6(const db::ServerSelector& server_selector, const uint16_t code, + const std::string& space) = 0; + + /// @brief Deletes shared network level option. + /// + /// @param selector Server selector. + /// @param shared_network_name Name of the shared network which option + /// belongs to. + /// @param code Code of the option to be deleted. + /// @param space Option space of the option to be deleted. + virtual uint64_t + deleteOption6(const db::ServerSelector& selector, + const std::string& shared_network_name, + const uint16_t code, + const std::string& space) = 0; + + /// @brief Deletes subnet level option. + /// + /// @param server_selector Server selector. + /// @param subnet_id Identifier of the subnet to which deleted option + /// belongs. + /// @param code Code of the deleted option. + /// @param space Option space of the deleted option. + /// @return Number of deleted options. + virtual uint64_t + deleteOption6(const db::ServerSelector& server_selector, const SubnetID& subnet_id, + const uint16_t code, const std::string& space) = 0; + + /// @brief Deletes pool level option. + /// + /// @param server_selector Server selector. + /// @param pool_start_address Lower bound address of the pool to which + /// deleted option belongs. + /// @param pool_end_address Upper bound address of the pool to which the + /// deleted option belongs. + /// @param code Code of the deleted option. + /// @param space Option space of the deleted option. + /// @return Number of deleted options. + virtual uint64_t + deleteOption6(const db::ServerSelector& server_selector, + const asiolink::IOAddress& pool_start_address, + const asiolink::IOAddress& pool_end_address, + const uint16_t code, + const std::string& space) = 0; + + /// @brief Deletes pd pool level option. + /// + /// @param server_selector Server selector. + /// @param pd_pool_prefix Address part of the prefix of the pd pool + /// to which the deleted option belongs. + /// @param pd_pool_prefix_length Prefix length of the pd pool to which + /// the deleted option belongs. + /// @param code Code of the deleted option. + /// @param space Option space of the deleted option. + /// @return Number of deleted options. + virtual uint64_t + deleteOption6(const db::ServerSelector& server_selector, + const asiolink::IOAddress& pd_pool_prefix, + const uint8_t pd_pool_prefix_length, + const uint16_t code, + const std::string& space) = 0; + + /// @brief Deletes global parameter. + /// + /// @param server_selector Server selector. + /// @param name Name of the global parameter to be deleted. + /// @return Number of deleted global parameters. + virtual uint64_t + deleteGlobalParameter6(const db::ServerSelector& server_selector, + const std::string& name) = 0; + + /// @brief Deletes all global parameters. + /// + /// @param server_selector Server selector. + /// @return Number of deleted global parameters. + virtual uint64_t + deleteAllGlobalParameters6(const db::ServerSelector& server_selector) = 0; +}; + +/// @brief Shared pointer to the @c ConfigBackendDHCPv6 instance. +typedef boost::shared_ptr ConfigBackendDHCPv6Ptr; + +} // end of namespace isc::dhcp +} // end of namespace isc + +#endif // CONFIG_BACKEND_DHCP6_H diff --git a/src/lib/dhcpsrv/config_backend_dhcp6_mgr.cc b/src/lib/dhcpsrv/config_backend_dhcp6_mgr.cc new file mode 100644 index 0000000000..9d14e0ea8c --- /dev/null +++ b/src/lib/dhcpsrv/config_backend_dhcp6_mgr.cc @@ -0,0 +1,41 @@ +// Copyright (C) 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/. + +#include +#include + +#include + +namespace isc { +namespace dhcp { + +boost::scoped_ptr& +ConfigBackendDHCPv6Mgr::getConfigBackendDHCPv6MgrPtr() { + static boost::scoped_ptr cb_dhcp6_mgr; + return (cb_dhcp6_mgr); +} + +void +ConfigBackendDHCPv6Mgr::create() { + getConfigBackendDHCPv6MgrPtr().reset(new ConfigBackendDHCPv6Mgr()); +} + +void +ConfigBackendDHCPv6Mgr::destroy() { + getConfigBackendDHCPv6MgrPtr().reset(new ConfigBackendDHCPv6Mgr()); +} + +ConfigBackendDHCPv6Mgr& +ConfigBackendDHCPv6Mgr::instance() { + boost::scoped_ptr& cb_dhcp6_mgr = getConfigBackendDHCPv6MgrPtr(); + if (!cb_dhcp6_mgr) { + create(); + } + return (*cb_dhcp6_mgr); +} + +} // end of isc::dhcp namespace +} // end of isc namespace diff --git a/src/lib/dhcpsrv/config_backend_dhcp6_mgr.h b/src/lib/dhcpsrv/config_backend_dhcp6_mgr.h new file mode 100644 index 0000000000..3c1062bb28 --- /dev/null +++ b/src/lib/dhcpsrv/config_backend_dhcp6_mgr.h @@ -0,0 +1,71 @@ +// Copyright (C) 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 CONFIG_BACKEND_DHCP6_MGR_H +#define CONFIG_BACKEND_DHCP6_MGR_H + +#include +#include + +#include + +namespace isc { +namespace dhcp { + +/// @brief Configuration Backend Manager for DHPCv6 servers. +/// +/// Implements the "manager" class which holds information about the +/// supported and configured backends and provides access to those +/// backends. This is similar to @c HostMgr and @c LeaseMgr singletons +/// being used by the DHCP servers. +/// +/// It is implemented as a singleton that can be accessed from any place +/// within the server code. This includes server configuration, data +/// fetching during normal server operation and data management, including +/// processing of control commands implemented within hooks libraries. +/// +/// Unlike @c HostMgr, the it does not directly expose the API to fetch and +/// manipulate the data in the database. This is done via, the Configuration +/// Backend Pool, see @c ConfigBackendPoolDHCPv6 for details. +class ConfigBackendDHCPv6Mgr : public cb::BaseConfigBackendMgr, + public boost::noncopyable { +public: + /// @brief Creates new instance of the @c ConfigBackendDHCPv6Mgr. + /// + /// If an instance of the @c ConfigBackendDHCPv6Mgr already exists, + /// it will be replaced by the new instance. Thus, all factories + /// will be unregistered and config databases will be dropped. + static void create(); + + /// @brief Destroys the instance of the @c ConfigBackendDHCPv6Mgr. + /// + /// If an instance of the @c ConfigBackendDHCPv6Mgr exists, + /// it will be destroyed. Thus, all factories will be unregistered + /// and config databases will be dropped. + static void destroy(); + + /// @brief Returns a sole instance of the @c ConfigBackendDHCPv6Mgr. + /// + /// This method should be used to retrieve an instance of the @c ConfigBackendDHCPv6Mgr + /// to be used to gather/manage config backends. It returns an instance + /// of the @c ConfigBackendDHCPv6Mgr created by the @c create method. If + /// the instance doesn't exist yet, it is created using the @c create method + /// with the an empty set of configuration databases. + static ConfigBackendDHCPv6Mgr& instance(); + +private: + /// @brief Private default constructor. + ConfigBackendDHCPv6Mgr() {} + + /// @brief Returns a pointer to the currently used instance of the + /// @c ConfigBackendDHCPv6Mgr. + static boost::scoped_ptr& getConfigBackendDHCPv6MgrPtr(); +}; + +} // end of namespace isc::dhcp +} // end of namespace isc + +#endif // CONFIG_BACKEND_DHCP6_MGR_H diff --git a/src/lib/dhcpsrv/config_backend_pool_dhcp6.cc b/src/lib/dhcpsrv/config_backend_pool_dhcp6.cc new file mode 100644 index 0000000000..3bf3fb3716 --- /dev/null +++ b/src/lib/dhcpsrv/config_backend_pool_dhcp6.cc @@ -0,0 +1,441 @@ +// Copyright (C) 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/. + +#include +#include + +using namespace isc::asiolink; +using namespace isc::data; +using namespace isc::db; + +namespace isc { +namespace dhcp { + +Subnet6Ptr +ConfigBackendPoolDHCPv6::getSubnet6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const std::string& subnet_prefix) const { + Subnet6Ptr subnet; + getPropertyPtrConst + (&ConfigBackendDHCPv6::getSubnet6, backend_selector, server_selector, + subnet, subnet_prefix); + return (subnet); +} + +Subnet6Ptr +ConfigBackendPoolDHCPv6::getSubnet6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const SubnetID& subnet_id) const { + Subnet6Ptr subnet; + getPropertyPtrConst + (&ConfigBackendDHCPv6::getSubnet6, backend_selector, server_selector, + subnet, subnet_id); + return (subnet); +} + +Subnet6Collection +ConfigBackendPoolDHCPv6::getAllSubnets6(const BackendSelector& backend_selector, + const ServerSelector& server_selector) const { + Subnet6Collection subnets; + getAllPropertiesConst + (&ConfigBackendDHCPv6::getAllSubnets6, backend_selector, server_selector, + subnets); + return (subnets); +} + +Subnet6Collection +ConfigBackendPoolDHCPv6::getModifiedSubnets6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const { + Subnet6Collection subnets; + getMultiplePropertiesConst + (&ConfigBackendDHCPv6::getModifiedSubnets6, backend_selector, server_selector, + subnets, modification_time); + return (subnets); +} + +Subnet6Collection +ConfigBackendPoolDHCPv6::getSharedNetworkSubnets6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const std::string& shared_network_name) const { + Subnet6Collection subnets; + getMultiplePropertiesConst + (&ConfigBackendDHCPv6::getSharedNetworkSubnets6, backend_selector, server_selector, + subnets, shared_network_name); + return (subnets); +} + +SharedNetwork6Ptr +ConfigBackendPoolDHCPv6::getSharedNetwork6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const std::string& name) const { + SharedNetwork6Ptr shared_network; + getPropertyPtrConst + (&ConfigBackendDHCPv6::getSharedNetwork6, backend_selector, server_selector, + shared_network, name); + return (shared_network); +} + +SharedNetwork6Collection +ConfigBackendPoolDHCPv6::getAllSharedNetworks6(const BackendSelector& backend_selector, + const ServerSelector& server_selector) const { + SharedNetwork6Collection shared_networks; + getAllPropertiesConst + (&ConfigBackendDHCPv6::getAllSharedNetworks6, backend_selector, server_selector, + shared_networks); + return (shared_networks); +} + +SharedNetwork6Collection +ConfigBackendPoolDHCPv6:: +getModifiedSharedNetworks6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const { + SharedNetwork6Collection shared_networks; + getMultiplePropertiesConst + (&ConfigBackendDHCPv6::getModifiedSharedNetworks6, backend_selector, server_selector, + shared_networks, modification_time); + return (shared_networks); +} + +OptionDefinitionPtr +ConfigBackendPoolDHCPv6::getOptionDef6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const uint16_t code, + const std::string& space) const { + OptionDefinitionPtr option_def; + getPropertyPtrConst + (&ConfigBackendDHCPv6::getOptionDef6, backend_selector, server_selector, + option_def, code, space); + return (option_def); +} + +OptionDefContainer +ConfigBackendPoolDHCPv6::getAllOptionDefs6(const BackendSelector& backend_selector, + const ServerSelector& server_selector) const { + OptionDefContainer option_defs; + getAllPropertiesConst + (&ConfigBackendDHCPv6::getAllOptionDefs6, backend_selector, server_selector, + option_defs); + return (option_defs); +} + +OptionDefContainer +ConfigBackendPoolDHCPv6::getModifiedOptionDefs6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const { + OptionDefContainer option_defs; + getMultiplePropertiesConst + (&ConfigBackendDHCPv6::getModifiedOptionDefs6, backend_selector, server_selector, + option_defs, modification_time); + return (option_defs); +} + +OptionDescriptorPtr +ConfigBackendPoolDHCPv6::getOption6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const uint16_t code, + const std::string& space) const { + OptionDescriptorPtr option; + getPropertyPtrConst + (&ConfigBackendDHCPv6::getOption6, backend_selector, server_selector, + option, code, space); + return (option); +} + +OptionContainer +ConfigBackendPoolDHCPv6::getAllOptions6(const BackendSelector& backend_selector, + const ServerSelector& server_selector) const { + OptionContainer options; + getAllPropertiesConst + (&ConfigBackendDHCPv6::getAllOptions6, backend_selector, server_selector, + options); + return (options); +} + +OptionContainer +ConfigBackendPoolDHCPv6::getModifiedOptions6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const { + OptionContainer options; + getMultiplePropertiesConst + (&ConfigBackendDHCPv6::getModifiedOptions6, backend_selector, server_selector, + options, modification_time); + return (options); +} + +StampedValuePtr +ConfigBackendPoolDHCPv6::getGlobalParameter6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const std::string& name) const { + StampedValuePtr parameter; + getPropertyPtrConst + (&ConfigBackendDHCPv6::getGlobalParameter6, backend_selector, + server_selector, parameter, name); + return (parameter); +} + +StampedValueCollection +ConfigBackendPoolDHCPv6::getAllGlobalParameters6(const BackendSelector& backend_selector, + const ServerSelector& server_selector) const { + StampedValueCollection parameters; + getAllPropertiesConst + (&ConfigBackendDHCPv6::getAllGlobalParameters6, backend_selector, + server_selector, parameters); + return (parameters); +} + +StampedValueCollection +ConfigBackendPoolDHCPv6:: +getModifiedGlobalParameters6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const { + StampedValueCollection parameters; + getMultiplePropertiesConst + (&ConfigBackendDHCPv6::getModifiedGlobalParameters6, backend_selector, + server_selector, parameters, modification_time); + return (parameters); +} + +AuditEntryCollection +ConfigBackendPoolDHCPv6:: +getRecentAuditEntries6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const { + AuditEntryCollection audit_entries; + getMultiplePropertiesConst + (&ConfigBackendDHCPv6::getRecentAuditEntries6, backend_selector, + server_selector, audit_entries, modification_time); + return (audit_entries); +} + +void +ConfigBackendPoolDHCPv6::createUpdateSubnet6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const Subnet6Ptr& subnet) { + createUpdateDeleteProperty + (&ConfigBackendDHCPv6::createUpdateSubnet6, backend_selector, + server_selector, subnet); +} + +void +ConfigBackendPoolDHCPv6::createUpdateSharedNetwork6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const SharedNetwork6Ptr& shared_network) { + createUpdateDeleteProperty + (&ConfigBackendDHCPv6::createUpdateSharedNetwork6, backend_selector, + server_selector, shared_network); +} + +void +ConfigBackendPoolDHCPv6::createUpdateOptionDef6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const OptionDefinitionPtr& option_def) { + createUpdateDeleteProperty + (&ConfigBackendDHCPv6::createUpdateOptionDef6, backend_selector, + server_selector, option_def); +} + +void +ConfigBackendPoolDHCPv6::createUpdateOption6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const OptionDescriptorPtr& option) { + createUpdateDeleteProperty + (&ConfigBackendDHCPv6::createUpdateOption6, backend_selector, + server_selector, option); +} + +void +ConfigBackendPoolDHCPv6::createUpdateOption6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const std::string& shared_network_name, + const OptionDescriptorPtr& option) { + createUpdateDeleteProperty + (&ConfigBackendDHCPv6::createUpdateOption6, backend_selector, + server_selector, shared_network_name, option); +} + + +void +ConfigBackendPoolDHCPv6::createUpdateOption6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const SubnetID& subnet_id, + const OptionDescriptorPtr& option) { + createUpdateDeleteProperty + (&ConfigBackendDHCPv6::createUpdateOption6, backend_selector, + server_selector, subnet_id, option); +} + +void +ConfigBackendPoolDHCPv6::createUpdateOption6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const IOAddress& pool_start_address, + const IOAddress& pool_end_address, + const OptionDescriptorPtr& option) { + createUpdateDeleteProperty + (&ConfigBackendDHCPv6::createUpdateOption6, backend_selector, + server_selector, pool_start_address, pool_end_address, option); +} + +void +ConfigBackendPoolDHCPv6::createUpdateOption6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const asiolink::IOAddress& pd_pool_prefix, + const uint8_t pd_pool_prefix_length, + const OptionDescriptorPtr& option) { + createUpdateDeleteProperty + (&ConfigBackendDHCPv6::createUpdateOption6, backend_selector, + server_selector, pd_pool_prefix, pd_pool_prefix_length, option); +} + +void +ConfigBackendPoolDHCPv6::createUpdateGlobalParameter6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const StampedValuePtr& value) { + createUpdateDeleteProperty + (&ConfigBackendDHCPv6::createUpdateGlobalParameter6, backend_selector, + server_selector, value); +} + +uint64_t +ConfigBackendPoolDHCPv6::deleteSubnet6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const std::string& subnet_prefix) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv6::deleteSubnet6, backend_selector, server_selector, + subnet_prefix)); +} + +uint64_t +ConfigBackendPoolDHCPv6::deleteSubnet6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const SubnetID& subnet_id) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv6::deleteSubnet6, backend_selector, server_selector, + subnet_id)); +} + +uint64_t +ConfigBackendPoolDHCPv6::deleteAllSubnets6(const BackendSelector& backend_selector, + const ServerSelector& server_selector) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv6::deleteAllSubnets6, backend_selector, server_selector)); +} + +uint64_t +ConfigBackendPoolDHCPv6::deleteSharedNetwork6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const std::string& name) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv6::deleteSharedNetwork6, backend_selector, + server_selector, name)); +} + +uint64_t +ConfigBackendPoolDHCPv6::deleteAllSharedNetworks6(const BackendSelector& backend_selector, + const ServerSelector& server_selector) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv6::deleteAllSharedNetworks6, backend_selector, server_selector)); +} + +uint64_t +ConfigBackendPoolDHCPv6::deleteOptionDef6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const uint16_t code, + const std::string& space) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv6::deleteOptionDef6, backend_selector, + server_selector, code, space)); +} + +uint64_t +ConfigBackendPoolDHCPv6::deleteAllOptionDefs6(const BackendSelector& backend_selector, + const ServerSelector& server_selector) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv6::deleteAllOptionDefs6, backend_selector, server_selector)); +} + +uint64_t +ConfigBackendPoolDHCPv6::deleteOption6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const uint16_t code, + const std::string& space) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv6::deleteOption6, backend_selector, server_selector, + code, space)); +} + +uint64_t +ConfigBackendPoolDHCPv6::deleteOption6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const std::string& shared_network_name, + const uint16_t code, + const std::string& space) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv6::deleteOption6, backend_selector, server_selector, + shared_network_name, code, space)); +} + +uint64_t +ConfigBackendPoolDHCPv6::deleteOption6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const SubnetID& subnet_id, + const uint16_t code, + const std::string& space) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv6::deleteOption6, backend_selector, server_selector, + subnet_id, code, space)); +} + +uint64_t +ConfigBackendPoolDHCPv6::deleteOption6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const asiolink::IOAddress& pool_start_address, + const asiolink::IOAddress& pool_end_address, + const uint16_t code, + const std::string& space) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv6::deleteOption6, backend_selector, server_selector, + pool_start_address, pool_end_address, code, space)); +} + +uint64_t +ConfigBackendPoolDHCPv6::deleteOption6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const asiolink::IOAddress& pd_pool_prefix, + const uint8_t pd_pool_prefix_length, + const uint16_t code, + const std::string& space) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv6::deleteOption6, backend_selector, server_selector, + pd_pool_prefix, pd_pool_prefix_length, code, space)); +} + +uint64_t +ConfigBackendPoolDHCPv6::deleteGlobalParameter6(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const std::string& name) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv6::deleteGlobalParameter6, backend_selector, + server_selector, name)); +} + +uint64_t +ConfigBackendPoolDHCPv6::deleteAllGlobalParameters6(const BackendSelector& backend_selector, + const ServerSelector& server_selector) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv6::deleteAllGlobalParameters6, backend_selector, + server_selector)); +} + + +} // end of namespace isc::dhcp +} // end of namespace isc diff --git a/src/lib/dhcpsrv/config_backend_pool_dhcp6.h b/src/lib/dhcpsrv/config_backend_pool_dhcp6.h new file mode 100644 index 0000000000..5a2cec863a --- /dev/null +++ b/src/lib/dhcpsrv/config_backend_pool_dhcp6.h @@ -0,0 +1,520 @@ +// Copyright (C) 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 CONFIG_BACKEND_POOL_DHCP6_H +#define CONFIG_BACKEND_POOL_DHCP6_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace isc { +namespace dhcp { + +/// @brief Implementation of the Configuration Backend Pool for DHCPv6. +/// +/// All POSIX times specified in the methods belonging to this +/// class must be local times. +class ConfigBackendPoolDHCPv6 : public cb::BaseConfigBackendPool { +public: + + /// @brief Retrieves a single subnet by subnet_prefix. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param subnet_prefix Prefix of the subnet to be retrieved. + /// @return Pointer to the retrieved subnet or NULL if not found. + virtual Subnet6Ptr + getSubnet6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const std::string& subnet_prefix) const; + + /// @brief Retrieves a single subnet by subnet identifier. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param subnet_id Identifier of a subnet to be retrieved. + /// @return Pointer to the retrieved subnet or NULL if not found. + virtual Subnet6Ptr + getSubnet6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const SubnetID& subnet_id) const; + + /// @brief Retrieves all subnets. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @return Collection of subnets or empty collection if no subnet found. + virtual Subnet6Collection + getAllSubnets6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector) const; + + /// @brief Retrieves subnets modified after specified time. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param modification_time Lower bound subnet modification time. + /// @return Collection of subnets or empty collection if no subnet found. + virtual Subnet6Collection + getModifiedSubnets6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const; + + /// @brief Retrieves all subnets belonging to a specified shared network. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param shared_network_name Name of the shared network for which the + /// subnets should be retrieved. + /// @return Collection of subnets or empty collection if no subnet found. + virtual Subnet6Collection + getSharedNetworkSubnets6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const std::string& shared_network_name) const; + + /// @brief Retrieves shared network by name. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param name Name of the shared network to be retrieved. + /// @return Pointer to the shared network or NULL if not found. + virtual SharedNetwork6Ptr + getSharedNetwork6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const std::string& name) const; + + /// @brief Retrieves all shared networks. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @return Collection of shared network or empty collection if + /// no shared network found. + virtual SharedNetwork6Collection + getAllSharedNetworks6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector) const; + + /// @brief Retrieves shared networks modified after specified time. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param modification_time Lower bound shared network modification time. + /// @return Collection of shared network or empty collection if + /// no shared network found. + virtual SharedNetwork6Collection + getModifiedSharedNetworks6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const; + + /// @brief Retrieves single option definition by code and space. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param code Code of the option to be retrieved. + /// @param space Option space of the option to be retrieved. + /// @return Pointer to the option definition or NULL if not found. + virtual OptionDefinitionPtr + getOptionDef6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const uint16_t code, + const std::string& space) const; + + /// @brief Retrieves all option definitions. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @return Collection of option definitions or empty collection if + /// no option definition found. + virtual OptionDefContainer + getAllOptionDefs6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector) const; + + /// @brief Retrieves option definitions modified after specified time. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param modification_time Lower bound option definition modification + /// time. + /// @return Collection of option definitions or empty collection if + /// no option definition found. + virtual OptionDefContainer + getModifiedOptionDefs6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const; + + /// @brief Retrieves single option by code and space. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param code Option code. + /// @param space Option space. + /// @return Pointer to the retrieved option descriptor or null if + /// no option was found. + virtual OptionDescriptorPtr + getOption6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const uint16_t code, + const std::string& space) const; + + /// @brief Retrieves all global options. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @return Collection of global options or empty collection if no + /// option found. + virtual OptionContainer + getAllOptions6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector) const; + + /// @brief Retrieves option modified after specified time. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param modification_time Lower bound option modification time. + /// @return Collection of global options or empty collection if no + /// option found. + virtual OptionContainer + getModifiedOptions6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const; + + /// @brief Retrieves global parameter value. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param name Name of the global parameter to be retrieved. + /// @return Value of the global parameter. + virtual data::StampedValuePtr + getGlobalParameter6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const std::string& name) const; + + /// @brief Retrieves all global parameters. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + virtual data::StampedValueCollection + getAllGlobalParameters6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector) const; + + /// @brief Retrieves global parameters modified after specified time. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param modification_time Lower bound subnet modification time. + /// @return Collection of modified global parameters. + virtual data::StampedValueCollection + getModifiedGlobalParameters6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const; + + /// @brief Retrieves the most recent audit entries. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param modification_time Timestamp being a lower limit for the returned + /// result set, i.e. entries later than specified time are returned. + /// @return Collection of audit entries. + virtual db::AuditEntryCollection + getRecentAuditEntries6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const; + + /// @brief Creates or updates a subnet. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param subnet Subnet to be added or updated. + virtual void + createUpdateSubnet6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const Subnet6Ptr& subnet); + + /// @brief Creates or updates a shared network. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param shared_network Shared network to be added or updated. + virtual void + createUpdateSharedNetwork6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const SharedNetwork6Ptr& shared_network); + + /// @brief Creates or updates an option definition. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param option_def Option definition to be added or updated. + virtual void + createUpdateOptionDef6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const OptionDefinitionPtr& option_def); + + /// @brief Creates or updates global option. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const OptionDescriptorPtr& option); + + /// @brief Creates or updates shared network level option. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param shared_network_name Name of a shared network to which option + /// belongs. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const std::string& shared_network_name, + const OptionDescriptorPtr& option); + + /// @brief Creates or updates subnet level option. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param subnet_id Identifier of a subnet to which option belongs. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const SubnetID& subnet_id, + const OptionDescriptorPtr& option); + + /// @brief Creates or updates pool level option. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param pool_start_address Lower bound address of the pool to which + /// the option belongs. + /// @param pool_end_address Upper bound address of the pool to which the + /// option belongs. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const asiolink::IOAddress& pool_start_address, + const asiolink::IOAddress& pool_end_address, + const OptionDescriptorPtr& option); + + /// @brief Creates or updates pd pool level option. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param pd_pool_prefix Address part of the prefix of the pd pool + /// to which the option belongs. + /// @param pd_pool_prefix_length Prefix length of the pd pool to which + /// the option belongs. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const asiolink::IOAddress& pd_pool_prefix, + const uint8_t pd_pool_prefix_length, + const OptionDescriptorPtr& option); + + /// @brief Creates or updates global string parameter. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param value Value of the global parameter. + virtual void + createUpdateGlobalParameter6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const data::StampedValuePtr& value); + + /// @brief Deletes subnet by prefix. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param subnet_prefix Prefix of the subnet to be deleted. + /// @return Number of deleted subnets. + virtual uint64_t + deleteSubnet6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const std::string& subnet_prefix); + + /// @brief Deletes subnet by identifier. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param subnet_id Identifier of the subnet to be deleted. + /// @return Number of deleted subnets. + virtual uint64_t + deleteSubnet6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const SubnetID& subnet_id); + + /// @brief Deletes all subnets. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @return Number of deleted subnets. + virtual uint64_t + deleteAllSubnets6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector); + + /// @brief Deletes shared network by name. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param name Name of the shared network to be deleted. + /// @return Number of deleted shared networks. + virtual uint64_t + deleteSharedNetwork6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const std::string& name); + + /// @brief Deletes all shared networks. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @return Number of deleted shared networks. + virtual uint64_t + deleteAllSharedNetworks6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector); + + /// @brief Deletes option definition. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param code Code of the option to be deleted. + /// @param space Option space of the option to be deleted. + /// @return Number of deleted option definitions. + virtual uint64_t + deleteOptionDef6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const uint16_t code, + const std::string& space); + + /// @brief Deletes all option definitions. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @return Number of deleted option definitions. + virtual uint64_t + deleteAllOptionDefs6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector); + + /// @brief Deletes global option. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param code Code of the option to be deleted. + /// @param space Option space of the option to be deleted. + /// @return Number of deleted options. + virtual uint64_t + deleteOption6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const uint16_t code, + const std::string& space); + + /// @brief Deletes shared network level option. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param shared_network_name Name of the shared network which option + /// belongs to. + /// @param code Code of the option to be deleted. + /// @param space Option space of the option to be deleted. + virtual uint64_t + deleteOption6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const std::string& shared_network_name, + const uint16_t code, + const std::string& space); + + /// @brief Deletes subnet level option. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param subnet_id Identifier of the subnet to which deleted option + /// belongs. + /// @param code Code of the deleted option. + /// @param space Option space of the deleted option. + /// @return Number of deleted options. + virtual uint64_t + deleteOption6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const SubnetID& subnet_id, + const uint16_t code, const std::string& space); + + /// @brief Deletes pool level option. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param pool_start_address Lower bound address of the pool to which + /// deleted option belongs. + /// @param pool_end_address Upper bound address of the pool to which the + /// deleted option belongs. + /// @param code Code of the deleted option. + /// @param space Option space of the deleted option. + /// @return Number of deleted options. + virtual uint64_t + deleteOption6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const asiolink::IOAddress& pool_start_address, + const asiolink::IOAddress& pool_end_address, + const uint16_t code, + const std::string& space); + + /// @brief Deletes pool level option. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param pd_pool_prefix Address part of the prefix of the pd pool + /// to which the deleted option belongs. + /// @param pd_pool_prefix_length Prefix length of the pd pool to which + /// the deleted option belongs. + /// @param code Code of the deleted option. + /// @param space Option space of the deleted option. + /// @return Number of deleted options. + virtual uint64_t + deleteOption6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const asiolink::IOAddress& pd_pool_prefix, + const uint8_t pd_pool_prefix_length, + const uint16_t code, + const std::string& space); + + /// @brief Deletes global parameter. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param name Name of the global parameter to be deleted. + /// @return Number of deleted global parameters. + virtual uint64_t + deleteGlobalParameter6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const std::string& name); + + /// @brief Deletes all global parameters. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @return Number of deleted global parameters. + virtual uint64_t + deleteAllGlobalParameters6(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector); +}; + + +} // end of namespace isc::dhcp +} // end of namespace isc + +#endif // CONFIG_BACKEND_POOL_DHCP6_H diff --git a/src/lib/dhcpsrv/testutils/Makefile.am b/src/lib/dhcpsrv/testutils/Makefile.am index 5d339b9ae2..56ebaa2779 100644 --- a/src/lib/dhcpsrv/testutils/Makefile.am +++ b/src/lib/dhcpsrv/testutils/Makefile.am @@ -21,6 +21,7 @@ libdhcpsrvtest_la_SOURCES += generic_host_data_source_unittest.cc generic_host_d libdhcpsrvtest_la_SOURCES += lease_file_io.cc lease_file_io.h libdhcpsrvtest_la_SOURCES += test_config_backend.h libdhcpsrvtest_la_SOURCES += test_config_backend_dhcp4.cc test_config_backend_dhcp4.h +libdhcpsrvtest_la_SOURCES += test_config_backend_dhcp6.cc test_config_backend_dhcp6.h libdhcpsrvtest_la_CXXFLAGS = $(AM_CXXFLAGS) libdhcpsrvtest_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) diff --git a/src/lib/dhcpsrv/testutils/test_config_backend.h b/src/lib/dhcpsrv/testutils/test_config_backend.h index 45ae8154c1..e945d7d9b1 100644 --- a/src/lib/dhcpsrv/testutils/test_config_backend.h +++ b/src/lib/dhcpsrv/testutils/test_config_backend.h @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-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 @@ -10,6 +10,7 @@ #include #include +#include #include #include diff --git a/src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.cc b/src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.cc new file mode 100644 index 0000000000..17149ccc00 --- /dev/null +++ b/src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.cc @@ -0,0 +1,525 @@ +// Copyright (C) 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/. + +#include + +#include +#include + +using namespace isc::data; +using namespace isc::db; + +namespace isc { +namespace dhcp { +namespace test { + +bool +TestConfigBackendDHCPv6::registerBackendType(ConfigBackendDHCPv6Mgr& mgr, + const std::string& db_type) { + return(mgr.registerBackendFactory(db_type, + [](const db::DatabaseConnection::ParameterMap& params) + -> dhcp::ConfigBackendDHCPv6Ptr { + return (TestConfigBackendDHCPv6Ptr(new TestConfigBackendDHCPv6(params))); + }) + ); +} + +void +TestConfigBackendDHCPv6::unregisterBackendType(ConfigBackendDHCPv6Mgr& mgr, + const std::string& db_type) { + mgr.unregisterBackendFactory(db_type); +} + +Subnet6Ptr +TestConfigBackendDHCPv6::getSubnet6(const db::ServerSelector& /* server_selector */, + const std::string& subnet_prefix) const{ + const auto& index = subnets_.get(); + auto subnet_it = index.find(subnet_prefix); + return ((subnet_it != index.cend()) ? (*subnet_it) : Subnet6Ptr()); +} + +Subnet6Ptr +TestConfigBackendDHCPv6::getSubnet6(const db::ServerSelector& /* server_selector */, + const SubnetID& subnet_id) const { + const auto& index = subnets_.get(); + auto subnet_it = index.find(subnet_id); + return ((subnet_it != index.cend()) ? (*subnet_it) : Subnet6Ptr()); +} + +Subnet6Collection +TestConfigBackendDHCPv6::getAllSubnets6(const db::ServerSelector& /* server_selector */) const { + return (subnets_); +} + +Subnet6Collection +TestConfigBackendDHCPv6::getModifiedSubnets6(const db::ServerSelector& /* server_selector */, + const boost::posix_time::ptime& modification_time) const { + const auto& index = subnets_.get(); + Subnet6Collection subnets; + auto lb = index.lower_bound(modification_time); + for (auto subnet = lb; subnet != index.end(); ++subnet) { + subnets.push_back(*subnet); + } + return (subnets); +} + +Subnet6Collection +TestConfigBackendDHCPv6::getSharedNetworkSubnets6(const db::ServerSelector& /* server_selector */, + const std::string& shared_network_name) const { + Subnet6Collection subnets; + + // Subnet collection does not include the index by shared network name. + // We need to iterate over the subnets and pick those that are associated + // with a shared network. + for (auto subnet = subnets_.begin(); subnet != subnets_.end(); + ++subnet) { + // The subnet can be associated with a shared network instance or + // it may just point to the shared network name. The former is + // the case when the subnet belongs to the server configuration. + // The latter is the case when the subnet is fetched from the + // database. + SharedNetwork6Ptr network; + (*subnet)->getSharedNetwork(network); + if (((network && (network->getName() == shared_network_name)) || + ((*subnet)->getSharedNetworkName() == shared_network_name))) { + subnets.push_back(*subnet); + } + } + return (subnets); +} + +SharedNetwork6Ptr +TestConfigBackendDHCPv6::getSharedNetwork6(const db::ServerSelector& /* server_selector */, + const std::string& name) const { + const auto& index = shared_networks_.get(); + auto network_it = index.find(name); + return ((network_it != index.cend()) ? (*network_it) : SharedNetwork6Ptr()); +} + +SharedNetwork6Collection +TestConfigBackendDHCPv6::getAllSharedNetworks6(const db::ServerSelector& /* server_selector */) const{ + return (shared_networks_); +} + +SharedNetwork6Collection +TestConfigBackendDHCPv6::getModifiedSharedNetworks6(const db::ServerSelector& /* server_selector */, + const boost::posix_time::ptime& modification_time) const { + const auto& index = shared_networks_.get(); + SharedNetwork6Collection shared_networks; + auto lb = index.lower_bound(modification_time); + for (auto shared_network = lb; shared_network != index.end(); ++shared_network) { + shared_networks.push_back(*shared_network); + } + return (shared_networks); +} + +OptionDefinitionPtr +TestConfigBackendDHCPv6::getOptionDef6(const db::ServerSelector& /* server_selector */, + const uint16_t code, + const std::string& space) const { + const auto& index = option_defs_.get<1>(); + auto option_def_it_pair = index.equal_range(code); + + for (auto option_def_it = option_def_it_pair.first; + option_def_it != option_def_it_pair.second; + ++option_def_it) { + if ((*option_def_it)->getOptionSpaceName() == space) { + return (*option_def_it); + } + } + return (OptionDefinitionPtr()); +} + +OptionDefContainer +TestConfigBackendDHCPv6::getAllOptionDefs6(const db::ServerSelector& /* server_selector */) const { + return (option_defs_); +} + +OptionDefContainer +TestConfigBackendDHCPv6::getModifiedOptionDefs6(const db::ServerSelector& /* server_selector */, + const boost::posix_time::ptime& modification_time) const { + const auto& index = option_defs_.get<3>(); + OptionDefContainer option_defs; + auto lb = index.lower_bound(modification_time); + for (auto option_def = lb; option_def != index.end(); ++option_def) { + option_defs.push_back(*option_def); + } + return (option_defs); +} + +OptionDescriptorPtr +TestConfigBackendDHCPv6::getOption6(const db::ServerSelector& /* server_selector */, + const uint16_t code, + const std::string& space) const { + const auto& index = options_.get<1>(); + auto option_it_pair = index.equal_range(code); + + for (auto option_it = option_it_pair.first; option_it != option_it_pair.second; + ++option_it) { + if (option_it->space_name_ == space) { + return (OptionDescriptorPtr(new OptionDescriptor(*option_it))); + } + } + + return (OptionDescriptorPtr()); +} + +OptionContainer +TestConfigBackendDHCPv6::getAllOptions6(const db::ServerSelector& /* server_selector */) const { + return (options_); +} + +OptionContainer +TestConfigBackendDHCPv6::getModifiedOptions6(const db::ServerSelector& /* server_selector */, + const boost::posix_time::ptime& modification_time) const { + const auto& index = options_.get<3>(); + OptionContainer options; + auto lb = index.lower_bound(modification_time); + for (auto option = lb; option != index.end(); ++option) { + options.push_back(*option); + } + return (options); +} + +StampedValuePtr +TestConfigBackendDHCPv6::getGlobalParameter6(const db::ServerSelector& /* server_selector */, + const std::string& name) const { + const auto& index = globals_.get(); + auto global_it = index.find(name); + return ((global_it != index.cend()) ? (*global_it) : StampedValuePtr()); +} + + +StampedValueCollection +TestConfigBackendDHCPv6::getAllGlobalParameters6(const db::ServerSelector& /* server_selector */) const { + return (globals_); +} + +StampedValueCollection +TestConfigBackendDHCPv6::getModifiedGlobalParameters6(const db::ServerSelector& /* server_selector */, + const boost::posix_time::ptime& modification_time) const { + const auto& index = globals_.get(); + StampedValueCollection globals; + auto lb = index.lower_bound(modification_time); + for (auto global = lb; global != index.end(); ++global) { + globals.insert(*global); + } + return (globals); +} + +AuditEntryCollection +TestConfigBackendDHCPv6::getRecentAuditEntries6(const db::ServerSelector&, + const boost::posix_time::ptime&) const { + return (AuditEntryCollection()); +} + +void +TestConfigBackendDHCPv6::createUpdateSubnet6(const db::ServerSelector& /* server_selector */, + const Subnet6Ptr& subnet) { + auto& index = subnets_.get(); + auto subnet_it = index.find(subnet->getID()); + + if (subnet_it != index.cend()) { + index.replace(subnet_it, subnet); + + } else { + index.insert(subnet); + } +} + +void +TestConfigBackendDHCPv6::createUpdateSharedNetwork6(const db::ServerSelector& /* server_selector */, + const SharedNetwork6Ptr& shared_network) { + auto& index = shared_networks_.get(); + auto network_it = index.find(shared_network->getName()); + + if (network_it != index.cend()) { + index.replace(network_it, shared_network); + + } else { + index.insert(shared_network); + } +} + +void +TestConfigBackendDHCPv6::createUpdateOptionDef6(const db::ServerSelector& /* server_selector */, + const OptionDefinitionPtr& option_def) { + auto& index = option_defs_.get<1>(); + auto option_def_it = index.find(option_def->getCode()); + + if (option_def_it != index.cend()) { + index.replace(option_def_it, option_def); + + } else { + index.insert(option_def); + } +} + +void +TestConfigBackendDHCPv6::createUpdateOption6(const db::ServerSelector& /* server_selector */, + const OptionDescriptorPtr& option) { + auto& index = options_.get<1>(); + auto option_it = index.find(option->option_->getType()); + + if (option_it != index.end()) { + index.replace(option_it, *option); + + } else { + index.insert(*option); + } +} + +void +TestConfigBackendDHCPv6::createUpdateOption6(const db::ServerSelector& /* server_selector */, + const std::string& shared_network_name, + const OptionDescriptorPtr& option) { + auto& index = shared_networks_.get(); + auto network_it = index.find(shared_network_name); + + if (network_it != index.end()) { + auto shared_network = *network_it; + shared_network->getCfgOption()->del(option->space_name_, option->option_->getType()); + shared_network->getCfgOption()->add(*option, option->space_name_); + + } else { + isc_throw(BadValue, "attempted to create or update option in a non existing " + "shared network " << shared_network_name); + } +} + +void +TestConfigBackendDHCPv6::createUpdateOption6(const db::ServerSelector& /* server_selector */, + const SubnetID& subnet_id, + const OptionDescriptorPtr& option) { + auto& index = subnets_.get(); + auto subnet_it = index.find(subnet_id); + + if (subnet_it != index.cend()) { + auto subnet = *subnet_it; + subnet->getCfgOption()->del(option->space_name_, option->option_->getType()); + subnet->getCfgOption()->add(*option, option->space_name_); + + } else { + isc_throw(BadValue, "attempted to create or update option in a non existing " + "subnet ID " << subnet_id); + } +} + +void +TestConfigBackendDHCPv6::createUpdateOption6(const db::ServerSelector& /* server_selector */, + const asiolink::IOAddress& pool_start_address, + const asiolink::IOAddress& pool_end_address, + const OptionDescriptorPtr& option) { + for (auto subnet = subnets_.begin(); subnet != subnets_.end(); ++subnet) { + auto pool = (*subnet)->getPool(Lease::TYPE_NA, pool_start_address); + if (pool) { + pool->getCfgOption()->del(option->space_name_, option->option_->getType()); + pool->getCfgOption()->add(*option, option->space_name_); + + return; + } + } + + isc_throw(BadValue, "attempted to create or update option in a non existing " + "pool " << pool_start_address << " - " << pool_end_address); +} + +void +TestConfigBackendDHCPv6::createUpdateOption6(const db::ServerSelector& /* server_selector */, + const asiolink::IOAddress& pd_pool_prefix, + const uint8_t pd_pool_prefix_length, + const OptionDescriptorPtr& option) { + for (auto subnet = subnets_.begin(); subnet != subnets_.end(); ++subnet) { + auto pdpool = (*subnet)->getPool(Lease::TYPE_PD,pd_pool_prefix); + if (pdpool) { + pdpool->getCfgOption()->del(option->space_name_, option->option_->getType()); + pdpool->getCfgOption()->add(*option, option->space_name_); + + return; + } + } + + isc_throw(BadValue, "attempted to create or update option in a non existing " + "pd pool " << pd_pool_prefix << "/" + << static_cast(pd_pool_prefix_length)); +} + +void +TestConfigBackendDHCPv6::createUpdateGlobalParameter6(const db::ServerSelector& /* server_selector */, + const data::StampedValuePtr& value) { + auto& index = globals_.get(); + auto global_it = index.find(value->getName()); + + if (global_it != index.end()) { + index.replace(global_it, value); + + } else { + index.insert(value); + } +} + +uint64_t +TestConfigBackendDHCPv6::deleteSubnet6(const db::ServerSelector& /* server_selector */, + const std::string& subnet_prefix) { + auto& index = subnets_.get(); + return (index.erase(subnet_prefix)); +} + +uint64_t +TestConfigBackendDHCPv6::deleteSubnet6(const db::ServerSelector& /* server_selector */, + const SubnetID& subnet_id) { + auto& index = subnets_.get(); + return (index.erase(subnet_id)); +} + +uint64_t +TestConfigBackendDHCPv6::deleteAllSubnets6(const db::ServerSelector& /* server_selector */) { + auto subnets_size = subnets_.size(); + subnets_.clear(); + return (subnets_size); +} + +uint64_t +TestConfigBackendDHCPv6::deleteSharedNetwork6(const db::ServerSelector& /* server_selector */, + const std::string& name) { + auto& index = shared_networks_.get(); + return (index.erase(name)); +} + +uint64_t +TestConfigBackendDHCPv6::deleteAllSharedNetworks6(const db::ServerSelector& /* server_selector */) { + auto shared_networks_size = shared_networks_.size(); + shared_networks_.clear(); + return (shared_networks_size); +} + +uint64_t +TestConfigBackendDHCPv6::deleteOptionDef6(const db::ServerSelector& /* server_selector */, + const uint16_t code, + const std::string& space) { + uint64_t erased = 0; + for (auto option_def_it = option_defs_.begin(); option_def_it != option_defs_.end(); + ++option_def_it) { + if (((*option_def_it)->getCode() == code) && + ((*option_def_it)->getOptionSpaceName() == space)) { + option_def_it = option_defs_.erase(option_def_it); + ++erased; + } + } + return (erased); +} + +uint64_t +TestConfigBackendDHCPv6::deleteAllOptionDefs6(const db::ServerSelector& /* server_selector */) { + auto option_defs_size = option_defs_.size(); + option_defs_.clear(); + return (option_defs_size); +} + +uint64_t +TestConfigBackendDHCPv6::deleteOption6(const db::ServerSelector& /* server_selector */, + const uint16_t code, + const std::string& space) { + uint64_t erased = 0; + for (auto option_it = options_.begin(); option_it != options_.end(); + ++option_it) { + if ((option_it->option_->getType() == code) && + (option_it->space_name_ == space)) { + option_it = options_.erase(option_it); + ++erased; + } + } + return (erased); +} + +uint64_t +TestConfigBackendDHCPv6::deleteOption6(const db::ServerSelector& /* server_selector */, + const std::string& shared_network_name, + const uint16_t code, + const std::string& space) { + auto& index = shared_networks_.get(); + auto network_it = index.find(shared_network_name); + + if (network_it != index.end()) { + auto shared_network = *network_it; + return (shared_network->getCfgOption()->del(space, code)); + + } else { + isc_throw(BadValue, "attempted to delete an option in a non existing " + "shared network " << shared_network_name); + } +} + +uint64_t +TestConfigBackendDHCPv6::deleteOption6(const db::ServerSelector& /* server_selector */, + const SubnetID& subnet_id, + const uint16_t code, + const std::string& space) { + auto& index = subnets_.get(); + auto subnet_it = index.find(subnet_id); + + if (subnet_it != index.cend()) { + auto subnet = *subnet_it; + return (subnet->getCfgOption()->del(space, code)); + + } else { + isc_throw(BadValue, "attempted to delete an option in a non existing " + "subnet ID " << subnet_id); + } +} + +uint64_t +TestConfigBackendDHCPv6::deleteOption6(const db::ServerSelector& /* server_selector */, + const asiolink::IOAddress& pool_start_address, + const asiolink::IOAddress& pool_end_address, + const uint16_t code, + const std::string& space) { + for (auto subnet = subnets_.begin(); subnet != subnets_.end(); ++subnet) { + auto pool = (*subnet)->getPool(Lease::TYPE_NA, pool_start_address); + if (pool) { + return (pool->getCfgOption()->del(space, code)); + } + } + + isc_throw(BadValue, "attempted to delete an option in a non existing " + "pool " << pool_start_address << " - " << pool_end_address); +} + +uint64_t +TestConfigBackendDHCPv6::deleteOption6(const db::ServerSelector& /* server_selector */, + const asiolink::IOAddress& pd_pool_prefix, + const uint8_t pd_pool_prefix_length, + const uint16_t code, + const std::string& space) { + for (auto subnet = subnets_.begin(); subnet != subnets_.end(); ++subnet) { + auto pdpool = (*subnet)->getPool(Lease::TYPE_PD, pd_pool_prefix); + if (pdpool) { + return (pdpool->getCfgOption()->del(space, code)); + } + } + + isc_throw(BadValue, "attempted to delete an option in a non existing " + "pd pool " << pd_pool_prefix << "/" + << static_cast(pd_pool_prefix_length)); +} + +uint64_t +TestConfigBackendDHCPv6::deleteGlobalParameter6(const db::ServerSelector& /* server_selector */, + const std::string& name) { + auto& index = globals_.get(); + return (index.erase(name)); +} + +uint64_t +TestConfigBackendDHCPv6::deleteAllGlobalParameters6(const db::ServerSelector& /* server_selector */) { + auto globals_size = globals_.size(); + globals_.clear(); + return (globals_size); +} + +} // namespace test +} // namespace dhcp +} // namespace isc diff --git a/src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.h b/src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.h new file mode 100644 index 0000000000..6709ae3c36 --- /dev/null +++ b/src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.h @@ -0,0 +1,466 @@ +// Copyright (C) 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 TEST_CONFIG_BACKEND_DHCP6 +#define TEST_CONFIG_BACKEND_DHCP6 + +#include + +#include +#include +#include + +#include + +#include +#include + +namespace isc { +namespace dhcp { +namespace test { + +/// @brief Test config backend that implements all of the DHCPv6 API calls +/// +/// This backend should be used for unit testing the DHCPv6 server and the +/// commands which manpiluate the configuration information stored in the +/// database. +/// +/// This backend stores server configuration information in memory. +class TestConfigBackendDHCPv6 : public TestConfigBackend { +public: + /// @brief Constructor + /// + /// @param params Database connection parameters. + TestConfigBackendDHCPv6(const db::DatabaseConnection::ParameterMap& params) + : TestConfigBackend(params) { + } + + /// @brief virtual Destructor. + virtual ~TestConfigBackendDHCPv6(){}; + + /// @brief Registers the backend type with the given backend manager + /// + /// @param mgr configuration manager to register with + /// @brief db_type back end type - Note you will need to + /// use the same value here as you do when creating backend instances. + static bool registerBackendType(ConfigBackendDHCPv6Mgr& mgr, + const std::string& db_type); + + /// @brief Unregisters the backend from the given backend manager + /// + /// @param mgr configuration manager to unregister from + /// @brief db_type back end type - Note you will need to + /// use the same value here as you do when registering the backend type + static void unregisterBackendType(ConfigBackendDHCPv6Mgr& mgr, + const std::string& db_type); + + /// @brief Retrieves a single subnet by subnet_prefix. + /// + /// @param server_selector Server selector. + /// @param subnet_prefix Prefix of the subnet to be retrieved. + /// @return Pointer to the retrieved subnet or NULL if not found. + virtual Subnet6Ptr + getSubnet6(const db::ServerSelector& server_selector, + const std::string& subnet_prefix) const; + + /// @brief Retrieves a single subnet by subnet identifier. + /// + /// @param server_selector Server selector. + /// @param subnet_id Identifier of a subnet to be retrieved. + /// @return Pointer to the retrieved subnet or NULL if not found. + virtual Subnet6Ptr + getSubnet6(const db::ServerSelector& server_selector, const SubnetID& subnet_id) const; + + /// @brief Retrieves all subnets. + /// + /// @param server_selector Server selector. + /// @return Collection of subnets or empty collection if no subnet found. + virtual Subnet6Collection + getAllSubnets6(const db::ServerSelector& server_selector) const; + + /// @brief Retrieves subnets modified after specified time. + /// + /// @param server_selector Server selector. + /// @param modification_time Lower bound subnet modification time. + /// @return Collection of subnets or empty collection if no subnet found. + virtual Subnet6Collection + getModifiedSubnets6(const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const; + + /// @brief Retrieves all subnets belonging to a specified shared network. + /// + /// @param server_selector Server selector. + /// @param shared_network_name Name of the shared network for which the + /// subnets should be retrieved. + /// @return Collection of subnets or empty collection if no subnet found. + virtual Subnet6Collection + getSharedNetworkSubnets6(const db::ServerSelector& server_selector, + const std::string& shared_network_name) const; + + /// @brief Retrieves shared network by name. + /// + /// @param server_selector Server selector. + /// @param name Name of the shared network to be retrieved. + /// @return Pointer to the shared network or NULL if not found. + virtual SharedNetwork6Ptr + getSharedNetwork6(const db::ServerSelector& server_selector, + const std::string& name) const; + + /// @brief Retrieves all shared networks. + /// + /// @param server_selector Server selector. + /// @return Collection of shared network or empty collection if + /// no shared network found. + virtual SharedNetwork6Collection + getAllSharedNetworks6(const db::ServerSelector& server_selector) const; + + /// @brief Retrieves shared networks modified after specified time. + /// + /// @param server_selector Server selector. + /// @param modification_time Lower bound shared network modification time. + /// @return Collection of shared network or empty collection if + /// no shared network found. + virtual SharedNetwork6Collection + getModifiedSharedNetworks6(const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const; + + /// @brief Retrieves single option definition by code and space. + /// + /// @param server_selector Server selector. + /// @param code Code of the option to be retrieved. + /// @param space Option space of the option to be retrieved. + /// @return Pointer to the option definition or NULL if not found. + virtual OptionDefinitionPtr + getOptionDef6(const db::ServerSelector& server_selector, const uint16_t code, + const std::string& space) const; + + /// @brief Retrieves all option definitions. + /// + /// @param server_selector Server selector. + /// @return Collection of option definitions or empty collection if + /// no option definition found. + virtual OptionDefContainer + getAllOptionDefs6(const db::ServerSelector& server_selector) const; + + /// @brief Retrieves option definitions modified after specified time. + /// + /// @param server_selector Server selector. + /// @param modification_time Lower bound option definition modification + /// time. + /// @return Collection of option definitions or empty collection if + /// no option definition found. + virtual OptionDefContainer + getModifiedOptionDefs6(const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const; + + /// @brief Retrieves single option by code and space. + /// + /// @param server_selector Server selector. + /// @return Pointer to the retrieved option descriptor or null if + /// no option was found. + virtual OptionDescriptorPtr + getOption6(const db::ServerSelector& server_selector, const uint16_t code, + const std::string& space) const; + + /// @brief Retrieves all global options. + /// + /// @param server_selector Server selector. + /// @return Collection of global options or empty collection if no + /// option found. + virtual OptionContainer + getAllOptions6(const db::ServerSelector& server_selector) const; + + /// @brief Retrieves option modified after specified time. + /// + /// @param selector Server selector. + /// @param modification_time Lower bound option modification time. + /// @return Collection of global options or empty collection if no + /// option found. + virtual OptionContainer + getModifiedOptions6(const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const; + + /// @brief Retrieves global parameter value. + /// + /// @param server_selector Server selector. + /// @param name Name of the global parameter to be retrieved. + /// @return Value of the global parameter or null if parameter doesn't + /// exist. + virtual data::StampedValuePtr + getGlobalParameter6(const db::ServerSelector& server_selector, + const std::string& name) const; + + /// @return Collection of global parameters. + virtual data::StampedValueCollection + getAllGlobalParameters6(const db::ServerSelector& server_selector) const; + + /// @brief Retrieves global parameters modified after specified time. + /// + /// @param selector Server selector. + /// @return Collection of modified global parameters. + virtual data::StampedValueCollection + getModifiedGlobalParameters6(const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const; + + /// @brief Retrieves the most recent audit entries. + /// + /// @param server_selector Server selector. + /// @param modification_time Timestamp being a lower limit for the returned + /// result set, i.e. entries later than specified time are returned. + /// @return Collection of audit entries. + virtual db::AuditEntryCollection + getRecentAuditEntries6(const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const; + + /// @brief Creates or updates a subnet. + /// + /// @param server_selector Server selector. + /// @param subnet Subnet to be added or updated. + virtual void + createUpdateSubnet6(const db::ServerSelector& server_selector, + const Subnet6Ptr& subnet); + + /// @brief Creates or updates a shared network. + /// + /// @param server_selector Server selector. + /// @param shared_network Shared network to be added or updated. + virtual void + createUpdateSharedNetwork6(const db::ServerSelector& server_selector, + const SharedNetwork6Ptr& shared_network); + + /// @brief Creates or updates an option definition. + /// + /// @param server_selector Server selector. + /// @param option_def Option definition to be added or updated. + virtual void + createUpdateOptionDef6(const db::ServerSelector& server_selector, + const OptionDefinitionPtr& option_def); + + /// @brief Creates or updates global option. + /// + /// @param server_selector Server selector. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::ServerSelector& server_selector, + const OptionDescriptorPtr& option); + + /// @brief Creates or updates shared network level option. + /// + /// @param selector Server selector. + /// @param shared_network_name Name of a shared network to which option + /// belongs. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::ServerSelector& server_selector, + const std::string& shared_network_name, + const OptionDescriptorPtr& option); + + /// @brief Creates or updates subnet level option. + /// + /// @param server_selector Server selector. + /// @param subnet_id Identifier of a subnet to which option belongs. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::ServerSelector& server_selector, + const SubnetID& subnet_id, + const OptionDescriptorPtr& option); + + /// @brief Creates or updates pool level option. + /// + /// @param server_selector Server selector. + /// @param pool_start_address Lower bound address of the pool to which + /// the option belongs. + /// @param pool_end_address Upper bound address of the pool to which the + /// option belongs. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::ServerSelector& server_selector, + const asiolink::IOAddress& pool_start_address, + const asiolink::IOAddress& pool_end_address, + const OptionDescriptorPtr& option); + + /// @brief Creates or updates pd pool level option. + /// + /// @param server_selector Server selector. + /// @param pd_pool_prefix Address part of the prefix of the pd pool + /// to which the option belongs. + /// @param pd_pool_prefix_length Prefix length of the pd pool to which + /// the option belongs. + /// @param option Option to be added or updated. + virtual void + createUpdateOption6(const db::ServerSelector& server_selector, + const asiolink::IOAddress& pd_pool_prefix, + const uint8_t pd_pool_prefix_length, + const OptionDescriptorPtr& option); + + /// @brief Creates or updates global parameter. + /// + /// @param server_selector Server selector. + /// @param value Value of the global parameter. + virtual void + createUpdateGlobalParameter6(const db::ServerSelector& server_selector, + const data::StampedValuePtr& value); + + /// @brief Deletes subnet by prefix. + /// + /// @param server_selector Server selector. + /// @param subnet_prefix Prefix of the subnet to be deleted. + /// @return Number of deleted subnets. + virtual uint64_t + deleteSubnet6(const db::ServerSelector& server_selector, + const std::string& subnet_prefix); + + /// @brief Deletes subnet by identifier. + /// + /// @param server_selector Server selector. + /// @param subnet_id Identifier of the subnet to be deleted. + /// @return Number of deleted subnets. + virtual uint64_t + deleteSubnet6(const db::ServerSelector& server_selector, const SubnetID& subnet_id); + + /// @brief Deletes all subnets. + /// + /// @param server_selector Server selector. + /// @return Number of deleted subnets. + virtual uint64_t + deleteAllSubnets6(const db::ServerSelector& server_selector); + + /// @brief Deletes shared network by name. + /// + /// @param server_selector Server selector. + /// @param name Name of the shared network to be deleted. + /// @return Number of deleted shared networks.. + virtual uint64_t + deleteSharedNetwork6(const db::ServerSelector& server_selector, + const std::string& name); + + /// @brief Deletes all shared networks. + /// + /// @param server_selector Server selector. + /// @return Number of deleted shared networks. + virtual uint64_t + deleteAllSharedNetworks6(const db::ServerSelector& server_selector); + + /// @brief Deletes option definition. + /// + /// @param server_selector Server selector. + /// @param code Code of the option to be deleted. + /// @param space Option space of the option to be deleted. + /// @return Number of deleted option definitions. + virtual uint64_t + deleteOptionDef6(const db::ServerSelector& server_selector, const uint16_t code, + const std::string& space); + + /// @brief Deletes all option definitions. + /// + /// @param server_selector Server selector. + /// @return Number of deleted option definitions. + virtual uint64_t + deleteAllOptionDefs6(const db::ServerSelector& server_selector); + + /// @brief Deletes global option. + /// + /// @param server_selector Server selector. + /// @param code Code of the option to be deleted. + /// @param space Option space of the option to be deleted. + /// @return Number of deleted options. + virtual uint64_t + deleteOption6(const db::ServerSelector& server_selector, const uint16_t code, + const std::string& space); + + /// @brief Deletes shared network level option. + /// + /// @param selector Server selector. + /// @param shared_network_name Name of the shared network which option + /// belongs to. + /// @param code Code of the option to be deleted. + /// @param space Option space of the option to be deleted. + virtual uint64_t + deleteOption6(const db::ServerSelector& server_selector, + const std::string& shared_network_name, + const uint16_t code, + const std::string& space); + + /// @brief Deletes subnet level option. + /// + /// @param server_selector Server selector. + /// @param subnet_id Identifier of the subnet to which deleted option + /// belongs. + /// @param code Code of the deleted option. + /// @param space Option space of the deleted option. + /// @return Number of deleted options. + virtual uint64_t + deleteOption6(const db::ServerSelector& server_selector, const SubnetID& subnet_id, + const uint16_t code, const std::string& space); + + /// @brief Deletes pool level option. + /// + /// @param server_selector Server selector. + /// @param pool_start_address Lower bound address of the pool to which + /// deleted option belongs. + /// @param pool_end_address Upper bound address of the pool to which the + /// deleted option belongs. + /// @param code Code of the deleted option. + /// @param space Option space of the deleted option. + /// @return Number of deleted options. + virtual uint64_t + deleteOption6(const db::ServerSelector& server_selector, + const asiolink::IOAddress& pool_start_address, + const asiolink::IOAddress& pool_end_address, + const uint16_t code, + const std::string& space); + + /// @brief Deletes pd pool level option. + /// + /// @param server_selector Server selector. + /// @param pd_pool_prefix Address part of the prefix of the pd pool + /// to which the deleted option belongs. + /// @param pd_pool_prefix_length Prefix length of the pd pool to which + /// the deleted option belongs. + /// @param code Code of the deleted option. + /// @param space Option space of the deleted option. + /// @return Number of deleted options. + virtual uint64_t + deleteOption6(const db::ServerSelector& server_selector, + const asiolink::IOAddress& pd_pool_prefix, + const uint8_t pd_pool_prefix_length, + const uint16_t code, + const std::string& space); + + /// @brief Deletes global parameter. + /// + /// @param server_selector Server selector. + /// @param name Name of the global parameter to be deleted. + /// @return Number of deleted global parameters. + virtual uint64_t + deleteGlobalParameter6(const db::ServerSelector& server_selector, + const std::string& name); + + /// @brief Deletes all global parameters. + /// + /// @param server_selector Server selector. + /// @return Number of deleted global parameters. + virtual uint64_t + deleteAllGlobalParameters6(const db::ServerSelector& server_selector); + +/// @{ +/// @brief Containers used to house the "database" entries + Subnet6Collection subnets_; + SharedNetwork6Collection shared_networks_; + OptionDefContainer option_defs_; + OptionContainer options_; + data::StampedValueCollection globals_; +/// @} +}; + +/// @brief Shared pointer to the @c TestConfigBackend. +typedef boost::shared_ptr TestConfigBackendDHCPv6Ptr; + +} // namespace test +} // namespace dhcp +} // namespace isc + +#endif // TEST_CONFIG_BACKEND_DHCP6 -- 2.47.2