]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#641,!352] Added API functions for servers.
authorMarcin Siodelski <marcin@isc.org>
Tue, 4 Jun 2019 15:43:45 +0000 (17:43 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 10 Jun 2019 12:39:17 +0000 (08:39 -0400)
src/lib/config_backend/base_config_backend_pool.h
src/lib/dhcpsrv/config_backend_dhcp4.h
src/lib/dhcpsrv/config_backend_dhcp6.h
src/lib/dhcpsrv/config_backend_pool_dhcp4.cc
src/lib/dhcpsrv/config_backend_pool_dhcp4.h
src/lib/dhcpsrv/config_backend_pool_dhcp6.cc
src/lib/dhcpsrv/config_backend_pool_dhcp6.h
src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.cc
src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.h
src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.cc
src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.h

index 9b255133c24bcfff1cb4c51e93e43ce9bf28ec67..2fc67b51646c04e59647d558aacc9061776f39a0 100644 (file)
@@ -161,6 +161,68 @@ protected:
         }
     }
 
+    /// @brief Retrieve a single configuration property from the backend.
+    ///
+    /// This is common method for retrieving a single configuration property
+    /// from the selected database without specifying the server selector. The
+    /// server specific backends call this method to retrieve a single object.
+    /// For example, the DHCPv4 configuration backend pool may use this function
+    /// to implement a @c getServer4 method:
+    ///
+    /// @code
+    /// ServerPtr getServer4(const BackendSelector& backend_selector,
+    ///                      const std::string& server_tag) const {
+    ///     ServerPtr server;
+    ///     getPropertyPtrConst<ServerPtr, const std::string&>
+    ///         (&ConfigBackendDHCPv4::getServer4, backend_selector,
+    ///          server_tag);
+    ///     return (server);
+    /// }
+    /// @endcode
+    ///
+    /// where @c ConfigBackendDHCPv4::getServer4 has the following signature:
+    ///
+    /// @code
+    /// ServerPtr getServer4(const std::string&) const;
+    /// @endcode
+    ///
+    /// This method is used in cases when server selector is not applicable.
+    ///
+    /// @tparam PropertyType Type of the object returned by the backend call.
+    /// @tparam FnPtrArgs Parameter pack holding argument types of the backend
+    /// method to be invoked.
+    /// @tparam Args Parameter pack holding types of the arguments provided
+    /// in the call to this method.
+    ///
+    /// @param MethodPointer Pointer to the backend method to be called.
+    /// @param backend_selector Backend selector.
+    /// @param [out] property Reference to the shared pointer where retrieved
+    /// property should be assigned.
+    /// @param input Values to be used as input to the backend call.
+    ///
+    /// @throw db::NoSuchDatabase if no database matching the given selector
+    /// was found.
+    /// @throw db::AmbiguousDatabase if multiple databases matching the selector
+    /// were found.
+    template<typename PropertyType, typename... FnPtrArgs, typename... Args>
+    void getBackendPropertyPtrConst(PropertyType (ConfigBackendType::*MethodPointer)
+                                    (FnPtrArgs...) const,
+                                    const db::BackendSelector& backend_selector,
+                                    PropertyType& property,
+                                    Args... input) const {
+        auto backends = selectBackends(backend_selector);
+        if (backends.empty()) {
+            isc_throw(db::NoSuchDatabase, "no such database found for selector: "
+                      << backend_selector.toText());
+
+        } else if (backends.size() > 1) {
+            isc_throw(db::AmbiguousDatabase, "more than one database found for "
+                      "selector: " << backend_selector.toText());
+        }
+
+        property = ((*(*(backends.begin())).*MethodPointer)(input...));
+    }
+
     /// @brief Retrieve multiple configuration properties from the pool.
     ///
     /// This is a common method for retrieving multiple configuration properties
@@ -309,6 +371,59 @@ protected:
         }
     }
 
+    /// @brief Get all configuration properties from the backend.
+    ///
+    /// This is a common method for retrieving all configuration properties
+    /// from the selected database without specifying the server selector. The
+    /// server specific backends call this method to retrieve all objects of
+    /// the same type. For example, the DHCPv4 configuration backend pool may
+    /// use this function to implement a @c getAllServers4 method:
+    ///
+    /// @code
+    /// ServerCollection getAllServers4(const BackendSelector&) const {
+    ///     ServerCollection servers;
+    ///     getAllBackendPropertiesConst<ServerCollection>
+    ///         (&ConfigBackendDHCPv4::getAllServers4, backend_selector, servers);
+    ///     return (servers);
+    /// }
+    /// @endcode
+    ///
+    /// where @c ConfigBackendDHCPv4::getAllServers4 has the following signature:
+    ///
+    /// @code
+    /// ServerCollection getAllServers4() const;
+    /// @endcode
+    ///
+    /// This method is used in cases when server selector is not applicable.
+    ///
+    /// @tparam PropertyCollectionType Type of the container into which the
+    /// properties are stored.
+    ///
+    /// @param MethodPointer Pointer to the backend method to be called.
+    /// @param backend_selector Backend selector.
+    /// @param server_selector Server selector.
+    /// @param [out] properties Reference to the collection of retrieved properties.
+    ///
+    /// @throw db::NoSuchDatabase if no database matching the given selector
+    /// was found.
+    /// @throw db::AmbiguousDatabase if multiple databases matching the selector
+    /// were found.
+    template<typename PropertyCollectionType>
+    void getAllBackendPropertiesConst(PropertyCollectionType (ConfigBackendType::*MethodPointer)() const,
+                                      const db::BackendSelector& backend_selector,
+                                      PropertyCollectionType& properties) const {
+        auto backends = selectBackends(backend_selector);
+        if (backends.empty()) {
+            isc_throw(db::NoSuchDatabase, "no such database found for selector: "
+                      << backend_selector.toText());
+
+        } else if (backends.size() > 1) {
+            isc_throw(db::AmbiguousDatabase, "more than one database found for "
+                      "selector: " << backend_selector.toText());
+        }
+
+        properties = (*(*(backends.begin())).*MethodPointer)();
+    }
 
     /// @brief Add, update or delete property from the backend.
     ///
@@ -375,6 +490,67 @@ protected:
         return ((*(*(backends.begin())).*MethodPointer)(server_selector, input...));
     }
 
+    /// @brief Add, update or delete property from the backend.
+    ///
+    /// This is a common method for storing a single configuration property in
+    /// a database, updating an existing property or deleting the property
+    /// without specifying the server selector. The server specific backends
+    /// call this method. For example, the DHCPv4 configuration backend pool
+    /// may use this function to implement the @c createUpdateServer4 method:
+    ///
+    /// @code
+    /// void createUpdateServer4(const BackendSelector& backend_selector,
+    ///                          const ServerSelector& server_selector,
+    ///                          const ServerPtr& server) {
+    ///     createUpdateDeleteBackendProperty<void, const ServerPtr&>
+    ///         (&ConfigBackendDHCPv4::createUpdateServer4, backend_selector,
+    ///          server);
+    /// }
+    /// @endcode
+    ///
+    /// where @c ConfigBackendDHCPv4::createUpdateServer4 has the following
+    /// signature:
+    ///
+    /// @code
+    /// void createUpdateServer4(const ServerPtr&);
+    /// @endcode
+    ///
+    /// This method is used in cases when server selector is not applicable.
+    ///
+    /// @tparam ReturnValue Returned value, typically void or uint64_t.
+    /// @tparam FnPtrArgs Parameter pack holding argument types of the backend
+    /// method to be invoked.
+    /// @tparam Args Parameter pack holding types of the arguments provided
+    /// in the call to this method.
+    ///
+    /// @param MethodPointer Pointer to the backend method to be called.
+    /// @param backend_selector Backend selector.
+    /// @param input Objects used as arguments to the backend method to be
+    /// called.
+    ///
+    /// @throw db::NoSuchDatabase if no database matching the given selector
+    /// was found.
+    /// @throw db::AmbiguousDatabase if multiple databases matching the selector
+    /// were found.
+    /// @return Number of affected properties, if the value is non void.
+    template<typename ReturnValue, typename... FnPtrArgs, typename... Args>
+    ReturnValue createUpdateDeleteBackendProperty(ReturnValue (ConfigBackendType::*MethodPointer)
+                                                  (FnPtrArgs...),
+                                                  const db::BackendSelector& backend_selector,
+                                                  Args... input) {
+        auto backends = selectBackends(backend_selector);
+        if (backends.empty()) {
+            isc_throw(db::NoSuchDatabase, "no such database found for selector: "
+                      << backend_selector.toText());
+
+        } else if (backends.size() > 1) {
+            isc_throw(db::AmbiguousDatabase, "more than one database found for "
+                      "selector: " << backend_selector.toText());
+        }
+
+        return ((*(*(backends.begin())).*MethodPointer)(input...));
+    }
+
     /// @brief Selects existing backends matching the selector.
     ///
     /// This method selects backends matching the selector. If the selector is
index 90c0505e838c3846411d4f63ad991b7c25bec954..5a38867f2e1bc9e05acd4f0b4ff2f2e97bebb40d 100644 (file)
@@ -197,6 +197,20 @@ public:
     getRecentAuditEntries(const db::ServerSelector& server_selector,
                           const boost::posix_time::ptime& modification_time) const = 0;
 
+    /// @brief Retrieves all servers.
+    ///
+    /// @return Collection of servers from the backend.
+    virtual db::ServerCollection
+    getAllServers4() const = 0;
+
+    /// @brief Retrieves a server.
+    ///
+    /// @param server_tag Tag of the server to be retrieved.
+    /// @return Pointer to the server instance or null pointer if no server
+    /// with the particular tag was found.
+    virtual db::ServerPtr
+    getServer4(const data::ServerTag& server_tag) const = 0;
+
     /// @brief Creates or updates a subnet.
     ///
     /// @param server_selector Server selector.
@@ -272,6 +286,12 @@ public:
     createUpdateGlobalParameter4(const db::ServerSelector& server_selector,
                                  const data::StampedValuePtr& value) = 0;
 
+    /// @brief Creates or updates a server.
+    ///
+    /// @param server Instance of the server to be stored.
+    virtual void
+    createUpdateServer4(const db::ServerPtr& server) = 0;
+
     /// @brief Deletes subnet by prefix.
     ///
     /// @param server_selector Server selector.
@@ -406,6 +426,20 @@ public:
     /// @return Number of deleted global parameters.
     virtual uint64_t
     deleteAllGlobalParameters4(const db::ServerSelector& server_selector) = 0;
+
+    /// @brief Deletes a server from the backend.
+    ///
+    /// @param server_tag Tag of the server to be deleted.
+    /// @return Number of deleted servers.
+    virtual uint64_t
+    deleteServer4(const std::string& server_tag) = 0;
+
+    /// @brief Deletes all servers from the backend except the logical
+    /// server 'all'.
+    ///
+    /// @return Number of deleted servers.
+    virtual uint64_t
+    deleteAllServers4() = 0;
 };
 
 /// @brief Shared pointer to the @c ConfigBackendDHCPv4 instance.
index a887e327044d57dc798d432905e49f069f97697f..61785aa356de8d701fe5b87277d890069b6bcdb5 100644 (file)
@@ -10,6 +10,8 @@
 #include <cc/stamped_value.h>
 #include <config_backend/base_config_backend.h>
 #include <database/audit_entry.h>
+#include <database/server.h>
+#include <database/server_collection.h>
 #include <database/server_selector.h>
 #include <dhcp/option.h>
 #include <dhcp/option_definition.h>
@@ -197,6 +199,20 @@ public:
     getRecentAuditEntries(const db::ServerSelector& server_selector,
                           const boost::posix_time::ptime& modification_time) const = 0;
 
+    /// @brief Retrieves all servers.
+    ///
+    /// @return Collection of servers from the backend.
+    virtual db::ServerCollection
+    getAllServers6() const = 0;
+
+    /// @brief Retrieves a server.
+    ///
+    /// @param server_tag Tag of the server to be retrieved.
+    /// @return Pointer to the server instance or null pointer if no server
+    /// with the particular tag was found.
+    virtual db::ServerPtr
+    getServer6(const data::ServerTag& server_tag) const = 0;
+
     /// @brief Creates or updates a subnet.
     ///
     /// @param server_selector Server selector.
@@ -286,6 +302,12 @@ public:
     createUpdateGlobalParameter6(const db::ServerSelector& server_selector,
                                  const data::StampedValuePtr& value) = 0;
 
+    /// @brief Creates or updates a server.
+    ///
+    /// @param server Instance of the server to be stored.
+    virtual void
+    createUpdateServer6(const db::ServerPtr& server) = 0;
+
     /// @brief Deletes subnet by prefix.
     ///
     /// @param server_selector Server selector.
@@ -437,6 +459,20 @@ public:
     /// @return Number of deleted global parameters.
     virtual uint64_t
     deleteAllGlobalParameters6(const db::ServerSelector& server_selector) = 0;
+
+    /// @brief Deletes a server from the backend.
+    ///
+    /// @param server_tag Tag of the server to be deleted.
+    /// @return Number of deleted servers.
+    virtual uint64_t
+    deleteServer6(const std::string& server_tag) = 0;
+
+    /// @brief Deletes all servers from the backend except the logical
+    /// server 'all'.
+    ///
+    /// @return Number of deleted servers.
+    virtual uint64_t
+    deleteAllServers6() = 0;
 };
 
 /// @brief Shared pointer to the @c ConfigBackendDHCPv6 instance.
index 018bdf53b49a6947f6b5de4a70c814cd4f7be854..ae7024f1364c46679fbdbadedb2554f33912fa11 100644 (file)
@@ -212,6 +212,24 @@ getRecentAuditEntries(const db::BackendSelector& backend_selector,
     return (audit_entries);
 }
 
+ServerCollection
+ConfigBackendPoolDHCPv4::getAllServers4(const BackendSelector& backend_selector) const {
+    ServerCollection servers;
+    getAllBackendPropertiesConst<ServerCollection>
+        (&ConfigBackendDHCPv4::getAllServers4, backend_selector, servers);
+    return (servers);
+}
+
+ServerPtr
+ConfigBackendPoolDHCPv4::getServer4(const BackendSelector& backend_selector,
+                                    const ServerTag& server_tag) const {
+    ServerPtr server;
+    getBackendPropertyPtrConst<ServerPtr, const ServerTag&>
+        (&ConfigBackendDHCPv4::getServer4, backend_selector, server,
+         server_tag);
+    return (server);
+}
+
 void
 ConfigBackendPoolDHCPv4::createUpdateSubnet4(const BackendSelector& backend_selector,
                                              const ServerSelector& server_selector,
@@ -290,6 +308,14 @@ ConfigBackendPoolDHCPv4::createUpdateGlobalParameter4(const BackendSelector& bac
          server_selector, value);
 }
 
+void
+ConfigBackendPoolDHCPv4::createUpdateServer4(const BackendSelector& backend_selector,
+                                             const ServerPtr& server) {
+    createUpdateDeleteBackendProperty<void, const ServerPtr&>
+        (&ConfigBackendDHCPv4::createUpdateServer4, backend_selector,
+         server);
+}
+
 uint64_t
 ConfigBackendPoolDHCPv4::deleteSubnet4(const BackendSelector& backend_selector,
                                        const ServerSelector& server_selector,
@@ -420,6 +446,19 @@ ConfigBackendPoolDHCPv4::deleteAllGlobalParameters4(const BackendSelector& backe
              server_selector));
 }
 
+uint64_t
+ConfigBackendPoolDHCPv4::deleteServer4(const BackendSelector& backend_selector,
+                                       const std::string& server_tag) {
+    return (createUpdateDeleteBackendProperty<uint64_t>
+            (&ConfigBackendDHCPv4::deleteServer4, backend_selector,
+             server_tag));
+}
+
+uint64_t
+ConfigBackendPoolDHCPv4::deleteAllServers4(const BackendSelector& backend_selector) {
+    return (createUpdateDeleteBackendProperty<uint64_t>
+            (&ConfigBackendDHCPv4::deleteAllServers4, backend_selector));
+}
 
 } // end of namespace isc::dhcp
 } // end of namespace isc
index 302ffe7960ed37f46590e0739587acfb6260690a..5aec95dfb5108c899755a97b9b85db6b08446181 100644 (file)
@@ -10,6 +10,8 @@
 #include <cc/stamped_value.h>
 #include <config_backend/base_config_backend_pool.h>
 #include <database/backend_selector.h>
+#include <database/server.h>
+#include <database/server_collection.h>
 #include <database/server_selector.h>
 #include <dhcp/option.h>
 #include <dhcp/option_definition.h>
@@ -231,6 +233,23 @@ public:
                           const db::ServerSelector& server_selector,
                           const boost::posix_time::ptime& modification_time) const;
 
+    /// @brief Retrieves all servers from the particular backend.
+    ///
+    /// @param backend_selector Backend selector.
+    /// @return Collection of servers from the backend.
+    virtual db::ServerCollection
+    getAllServers4(const db::BackendSelector& backend_selector) const;
+
+    /// @brief Retrieves a server from the particular backend.
+    ///
+    /// @param backend_selector Backend selector.
+    /// @param server_tag Tag of the server to be retrieved.
+    /// @return Pointer to the server instance or null pointer if no server
+    /// with the particular tag was found.
+    virtual db::ServerPtr
+    getServer4(const db::BackendSelector& backend_selector,
+               const data::ServerTag& server_tag) const;
+
     /// @brief Creates or updates a subnet.
     ///
     /// @param backend_selector Backend selector.
@@ -322,6 +341,14 @@ public:
                                  const db::ServerSelector& server_selector,
                                  const data::StampedValuePtr& value);
 
+    /// @brief Creates or updates a server.
+    ///
+    /// @param backend_selector Backend selector.
+    /// @param server Instance of the server to be stored.
+    virtual void
+    createUpdateServer4(const db::BackendSelector& backend_selector,
+                        const db::ServerPtr& server);
+
     /// @brief Deletes subnet by prefix.
     ///
     /// @param backend_selector Backend selector.
@@ -488,6 +515,23 @@ public:
     virtual uint64_t
     deleteAllGlobalParameters4(const db::BackendSelector& backend_selector,
                                const db::ServerSelector& server_selector);
+
+    /// @brief Deletes a server from the backend.
+    ///
+    /// @param backend_selector Backend selector.
+    /// @param server_tag Tag of the server to be deleted.
+    /// @return Number of deleted servers.
+    virtual uint64_t
+    deleteServer4(const db::BackendSelector& backend_selector,
+                  const std::string& server_tag);
+
+    /// @brief Deletes all servers from the backend except the logical
+    /// server 'all'.
+    ///
+    /// @param backend_selector Backend selector.
+    /// @return Number of deleted servers.
+    virtual uint64_t
+    deleteAllServers4(const db::BackendSelector& backend_selector);
 };
 
 
index 66d8f01c627c6f465faa3e57b01b634b6567f41c..eec5501248a47d9582224dd93af3ff3280daa73b 100644 (file)
@@ -212,6 +212,24 @@ getRecentAuditEntries(const db::BackendSelector& backend_selector,
     return (audit_entries);
 }
 
+ServerCollection
+ConfigBackendPoolDHCPv6::getAllServers6(const BackendSelector& backend_selector) const {
+    ServerCollection servers;
+    getAllBackendPropertiesConst<ServerCollection>
+        (&ConfigBackendDHCPv6::getAllServers6, backend_selector, servers);
+    return (servers);
+}
+
+ServerPtr
+ConfigBackendPoolDHCPv6::getServer6(const BackendSelector& backend_selector,
+                                    const ServerTag& server_tag) const {
+    ServerPtr server;
+    getBackendPropertyPtrConst<ServerPtr, const ServerTag&>
+        (&ConfigBackendDHCPv6::getServer6, backend_selector, server,
+         server_tag);
+    return (server);
+}
+
 void
 ConfigBackendPoolDHCPv6::createUpdateSubnet6(const BackendSelector& backend_selector,
                                              const ServerSelector& server_selector,
@@ -302,6 +320,14 @@ ConfigBackendPoolDHCPv6::createUpdateGlobalParameter6(const BackendSelector& bac
          server_selector, value);
 }
 
+void
+ConfigBackendPoolDHCPv6::createUpdateServer6(const BackendSelector& backend_selector,
+                                             const ServerPtr& server) {
+    createUpdateDeleteBackendProperty<void, const ServerPtr&>
+        (&ConfigBackendDHCPv6::createUpdateServer6, backend_selector,
+         server);
+}
+
 uint64_t
 ConfigBackendPoolDHCPv6::deleteSubnet6(const BackendSelector& backend_selector,
                                        const ServerSelector& server_selector,
@@ -445,6 +471,19 @@ ConfigBackendPoolDHCPv6::deleteAllGlobalParameters6(const BackendSelector& backe
              server_selector));
 }
 
+uint64_t
+ConfigBackendPoolDHCPv6::deleteServer6(const BackendSelector& backend_selector,
+                                       const std::string& server_tag) {
+    return (createUpdateDeleteBackendProperty<uint64_t>
+            (&ConfigBackendDHCPv6::deleteServer6, backend_selector,
+             server_tag));
+}
+
+uint64_t
+ConfigBackendPoolDHCPv6::deleteAllServers6(const BackendSelector& backend_selector) {
+    return (createUpdateDeleteBackendProperty<uint64_t>
+            (&ConfigBackendDHCPv6::deleteAllServers6, backend_selector));
+}
 
 } // end of namespace isc::dhcp
 } // end of namespace isc
index f26fa606e59b47817088c349b73d0221534c7921..820997fc7d718dfdf54d1ede7eea2875348429da 100644 (file)
@@ -231,6 +231,23 @@ public:
                           const db::ServerSelector& server_selector,
                           const boost::posix_time::ptime& modification_time) const;
 
+    /// @brief Retrieves all servers from the particular backend.
+    ///
+    /// @param backend_selector Backend selector.
+    /// @return Collection of servers from the backend.
+    virtual db::ServerCollection
+    getAllServers6(const db::BackendSelector& backend_selector) const;
+
+    /// @brief Retrieves a server from the particular backend.
+    ///
+    /// @param backend_selector Backend selector.
+    /// @param server_tag Tag of the server to be retrieved.
+    /// @return Pointer to the server instance or null pointer if no server
+    /// with the particular tag was found.
+    virtual db::ServerPtr
+    getServer6(const db::BackendSelector& backend_selector,
+               const data::ServerTag& server_tag) const;
+
     /// @brief Creates or updates a subnet.
     ///
     /// @param backend_selector Backend selector.
@@ -338,6 +355,14 @@ public:
                                  const db::ServerSelector& server_selector,
                                  const data::StampedValuePtr& value);
 
+    /// @brief Creates or updates a server.
+    ///
+    /// @param backend_selector Backend selector.
+    /// @param server Instance of the server to be stored.
+    virtual void
+    createUpdateServer6(const db::BackendSelector& backend_selector,
+                        const db::ServerPtr& server);
+
     /// @brief Deletes subnet by prefix.
     ///
     /// @param backend_selector Backend selector.
@@ -523,6 +548,23 @@ public:
     virtual uint64_t
     deleteAllGlobalParameters6(const db::BackendSelector& backend_selector,
                                const db::ServerSelector& server_selector);
+
+    /// @brief Deletes a server from the backend.
+    ///
+    /// @param backend_selector Backend selector.
+    /// @param server_tag Tag of the server to be deleted.
+    /// @return Number of deleted servers.
+    virtual uint64_t
+    deleteServer6(const db::BackendSelector& backend_selector,
+                  const std::string& server_tag);
+
+    /// @brief Deletes all servers from the backend except the logical
+    /// server 'all'.
+    ///
+    /// @param backend_selector Backend selector.
+    /// @return Number of deleted servers.
+    virtual uint64_t
+    deleteAllServers6(const db::BackendSelector& backend_selector);
 };
 
 
index 70b2ba830f570d79c80414e6bbf0608ab57de059..863677cc380231e66782fa629301604e6a865877 100644 (file)
@@ -217,6 +217,18 @@ TestConfigBackendDHCPv4::getRecentAuditEntries(const db::ServerSelector&,
     return (AuditEntryCollection());
 }
 
+ServerCollection
+TestConfigBackendDHCPv4::getAllServers4() const {
+    return (servers_);
+}
+
+ServerPtr
+TestConfigBackendDHCPv4::getServer4(const ServerTag& server_tag) const {
+    const auto& index = servers_.get<ServerTagIndexTag>();
+    auto server_it = index.find(server_tag.get());
+    return ((server_it != index.cend()) ? (*server_it) : ServerPtr());
+}
+
 void
 TestConfigBackendDHCPv4::createUpdateSubnet4(const db::ServerSelector& server_selector,
                                              const Subnet4Ptr& subnet) {
@@ -352,6 +364,19 @@ TestConfigBackendDHCPv4::createUpdateGlobalParameter4(const db::ServerSelector&
     }
 }
 
+void
+TestConfigBackendDHCPv4::createUpdateServer4(const db::ServerPtr& server) {
+    auto& index = servers_.get<ServerTagIndexTag>();
+    auto server_it = index.find(server->getServerTag());
+
+    if (server_it != index.end()) {
+        index.replace(server_it, server);
+
+    } else {
+        index.insert(server);
+    }
+}
+
 uint64_t
 TestConfigBackendDHCPv4::deleteSubnet4(const db::ServerSelector& /* server_selector */,
                                        const std::string& subnet_prefix) {
@@ -524,6 +549,19 @@ TestConfigBackendDHCPv4::deleteAllGlobalParameters4(const db::ServerSelector& /*
     return (globals_size);
 }
 
+uint64_t
+TestConfigBackendDHCPv4::deleteServer4(const std::string& server_tag) {
+    auto& index = servers_.get<ServerTagIndexTag>();
+    return (index.erase(server_tag));
+}
+
+uint64_t
+TestConfigBackendDHCPv4::deleteAllServers4() {
+    auto servers_size = servers_.size();
+    servers_.clear();
+    return (servers_size);
+}
+
 } // namespace test
 } // namespace dhcp
 } // namespace isc
index 2754c1bc83ec15e79a15d3465675df5929042161..3973452a73775fa8913a9ef586986933e3cbe751 100644 (file)
@@ -10,6 +10,8 @@
 #include <config.h>
 
 #include <database/database_connection.h>
+#include <database/server.h>
+#include <database/server_collection.h>
 #include <dhcpsrv/config_backend_dhcp4_mgr.h>
 #include <dhcpsrv/testutils/test_config_backend.h>
 
@@ -218,6 +220,20 @@ public:
     getRecentAuditEntries(const db::ServerSelector& server_selector,
                           const boost::posix_time::ptime& modification_time) const;
 
+    /// @brief Retrieves all servers.
+    ///
+    /// @return Collection of servers from the backend.
+    virtual db::ServerCollection
+    getAllServers4() const;
+
+    /// @brief Retrieves a server.
+    ///
+    /// @param server_tag Tag of the server to be retrieved.
+    /// @return Pointer to the server instance or null pointer if no server
+    /// with the particular tag was found.
+    virtual db::ServerPtr
+    getServer4(const data::ServerTag& server_tag) const;
+
     /// @brief Creates or updates a subnet.
     ///
     /// @param server_selector Server selector.
@@ -293,6 +309,12 @@ public:
     createUpdateGlobalParameter4(const db::ServerSelector& server_selector,
                                  const data::StampedValuePtr& value);
 
+    /// @brief Creates or updates a server.
+    ///
+    /// @param server Instance of the server to be stored.
+    virtual void
+    createUpdateServer4(const db::ServerPtr& server);
+
     /// @brief Deletes subnet by prefix.
     ///
     /// @param server_selector Server selector.
@@ -428,6 +450,20 @@ public:
     virtual uint64_t
     deleteAllGlobalParameters4(const db::ServerSelector& server_selector);
 
+    /// @brief Deletes a server from the backend.
+    ///
+    /// @param server_tag Tag of the server to be deleted.
+    /// @return Number of deleted servers.
+    virtual uint64_t
+    deleteServer4(const std::string& server_tag);
+
+    /// @brief Deletes all servers from the backend except the logical
+    /// server 'all'.
+    ///
+    /// @return Number of deleted servers.
+    virtual uint64_t
+    deleteAllServers4();
+
 /// @{
 /// @brief Containers used to house the "database" entries
     Subnet4Collection subnets_;
@@ -435,6 +471,7 @@ public:
     OptionDefContainer option_defs_;
     OptionContainer options_;
     data::StampedValueCollection globals_;
+    db::ServerCollection servers_;
 /// @}
 };
 
index 74303f673d16eaa57edff6371401ee3c59fe6893..6f68212a87506ebd29f8104a30394a600c66161d 100644 (file)
@@ -216,6 +216,18 @@ TestConfigBackendDHCPv6::getRecentAuditEntries(const db::ServerSelector&,
     return (AuditEntryCollection());
 }
 
+ServerCollection
+TestConfigBackendDHCPv6::getAllServers6() const {
+    return (servers_);
+}
+
+ServerPtr
+TestConfigBackendDHCPv6::getServer6(const ServerTag& server_tag) const {
+    const auto& index = servers_.get<ServerTagIndexTag>();
+    auto server_it = index.find(server_tag.get());
+    return ((server_it != index.cend()) ? (*server_it) : ServerPtr());
+}
+
 void
 TestConfigBackendDHCPv6::createUpdateSubnet6(const db::ServerSelector& server_selector,
                                              const Subnet6Ptr& subnet) {
@@ -371,6 +383,19 @@ TestConfigBackendDHCPv6::createUpdateGlobalParameter6(const db::ServerSelector&
     }
 }
 
+void
+TestConfigBackendDHCPv6::createUpdateServer6(const db::ServerPtr& server) {
+    auto& index = servers_.get<ServerTagIndexTag>();
+    auto server_it = index.find(server->getServerTag());
+
+    if (server_it != index.end()) {
+        index.replace(server_it, server);
+
+    } else {
+        index.insert(server);
+    }
+}
+
 uint64_t
 TestConfigBackendDHCPv6::deleteSubnet6(const db::ServerSelector& /* server_selector */,
                                        const std::string& subnet_prefix) {
@@ -561,6 +586,20 @@ TestConfigBackendDHCPv6::deleteAllGlobalParameters6(const db::ServerSelector& /*
     return (globals_size);
 }
 
+uint64_t
+TestConfigBackendDHCPv6::deleteServer6(const std::string& server_tag) {
+    auto& index = servers_.get<ServerTagIndexTag>();
+    return (index.erase(server_tag));
+}
+
+uint64_t
+TestConfigBackendDHCPv6::deleteAllServers6() {
+    auto servers_size = servers_.size();
+    servers_.clear();
+    return (servers_size);
+}
+
+
 } // namespace test
 } // namespace dhcp
 } // namespace isc
index e18bba3b6ad09d379125f08ce0d3fdb60f7ef159..b0f319f5c7ce2ee0aba98e6e88b1ae5a31dc4404 100644 (file)
@@ -10,6 +10,8 @@
 #include <config.h>
 
 #include <database/database_connection.h>
+#include <database/server.h>
+#include <database/server_collection.h>
 #include <dhcpsrv/config_backend_dhcp6_mgr.h>
 #include <dhcpsrv/testutils/test_config_backend.h>
 
@@ -218,6 +220,20 @@ public:
     getRecentAuditEntries(const db::ServerSelector& server_selector,
                           const boost::posix_time::ptime& modification_time) const;
 
+    /// @brief Retrieves all servers.
+    ///
+    /// @return Collection of servers from the backend.
+    virtual db::ServerCollection
+    getAllServers6() const;
+
+    /// @brief Retrieves a server.
+    ///
+    /// @param server_tag Tag of the server to be retrieved.
+    /// @return Pointer to the server instance or null pointer if no server
+    /// with the particular tag was found.
+    virtual db::ServerPtr
+    getServer6(const data::ServerTag& server_tag) const;
+
     /// @brief Creates or updates a subnet.
     ///
     /// @param server_selector Server selector.
@@ -307,6 +323,12 @@ public:
     createUpdateGlobalParameter6(const db::ServerSelector& server_selector,
                                  const data::StampedValuePtr& value);
 
+    /// @brief Creates or updates a server.
+    ///
+    /// @param server Instance of the server to be stored.
+    virtual void
+    createUpdateServer6(const db::ServerPtr& server);
+
     /// @brief Deletes subnet by prefix.
     ///
     /// @param server_selector Server selector.
@@ -459,6 +481,20 @@ public:
     virtual uint64_t
     deleteAllGlobalParameters6(const db::ServerSelector& server_selector);
 
+    /// @brief Deletes a server from the backend.
+    ///
+    /// @param server_tag Tag of the server to be deleted.
+    /// @return Number of deleted servers.
+    virtual uint64_t
+    deleteServer6(const std::string& server_tag);
+
+    /// @brief Deletes all servers from the backend except the logical
+    /// server 'all'.
+    ///
+    /// @return Number of deleted servers.
+    virtual uint64_t
+    deleteAllServers6();
+
 /// @{
 /// @brief Containers used to house the "database" entries
     Subnet6Collection subnets_;
@@ -466,6 +502,7 @@ public:
     OptionDefContainer option_defs_;
     OptionContainer options_;
     data::StampedValueCollection globals_;
+    db::ServerCollection servers_;
 /// @}
 };