]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[313-return-a-list-of-all-reservations-by-subnet-id] Added getAll[46] by subnet ...
authorFrancis Dupont <fdupont@isc.org>
Fri, 11 Jan 2019 15:48:30 +0000 (16:48 +0100)
committerFrancis Dupont <fdupont@isc.org>
Tue, 29 Jan 2019 09:49:05 +0000 (04:49 -0500)
14 files changed:
src/lib/dhcpsrv/base_host_data_source.h
src/lib/dhcpsrv/cfg_hosts.cc
src/lib/dhcpsrv/cfg_hosts.h
src/lib/dhcpsrv/cql_host_data_source.h
src/lib/dhcpsrv/host_mgr.cc
src/lib/dhcpsrv/host_mgr.h
src/lib/dhcpsrv/hosts_messages.mes
src/lib/dhcpsrv/mysql_host_data_source.h
src/lib/dhcpsrv/pgsql_host_data_source.h
src/lib/dhcpsrv/tests/host_cache_unittest.cc
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/testutils/memory_host_data_source.cc
src/lib/dhcpsrv/testutils/memory_host_data_source.h
src/lib/dhcpsrv/writable_host_data_source.h

index 115c82ed57fbc702b7a1b4ae39c6a3c82c59006b..815a0d9d07d91d19af76d7f10331c4301ca85b74 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-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
@@ -92,6 +92,28 @@ public:
            const uint8_t* identifier_begin,
            const size_t identifier_len) const = 0;
 
+    /// @brief Return all hosts in a DHCPv4 subnet.
+    ///
+    /// This method returns all @c Host objects which represent reservations
+    /// in a specified subnet.
+    ///
+    /// @param subnet_id Subnet identifier.
+    ///
+    /// @return Collection of const @c Host objects.
+    virtual ConstHostCollection
+    getAll4(const SubnetID& subnet_id) const = 0;
+
+    /// @brief Return all hosts in a DHCPv6 subnet.
+    ///
+    /// This method returns all @c Host objects which represent reservations
+    /// in a specified subnet.
+    ///
+    /// @param subnet_id Subnet identifier.
+    ///
+    /// @return Collection of const @c Host objects.
+    virtual ConstHostCollection
+    getAll6(const SubnetID& subnet_id) const = 0;
+
     /// @brief Returns a collection of hosts using the specified IPv4 address.
     ///
     /// This method may return multiple @c Host objects if they are connected
index b07fe152ed7d0b3caac46cccf56a6ea63de1c1d8..386bc2888e775405a4c0fbe8b906770746ef7176 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-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
@@ -46,6 +46,42 @@ CfgHosts::getAll(const Host::IdentifierType& identifier_type,
     return (collection);
 }
 
+ConstHostCollection
+CfgHosts::getAll4(const SubnetID& subnet_id) const {
+    // Do not issue logging message here because it will be logged by
+    // the getAllInternal method.
+    ConstHostCollection collection;
+    getAllInternal4<ConstHostCollection>(subnet_id, collection);
+    return (collection);
+}
+
+HostCollection
+CfgHosts::getAll4(const SubnetID& subnet_id) {
+    // Do not issue logging message here because it will be logged by
+    // the getAllInternal method.
+    HostCollection collection;
+    getAllInternal4<HostCollection>(subnet_id, collection);
+    return (collection);
+}
+
+ConstHostCollection
+CfgHosts::getAll6(const SubnetID& subnet_id) const {
+    // Do not issue logging message here because it will be logged by
+    // the getAllInternal method.
+    ConstHostCollection collection;
+    getAllInternal6<ConstHostCollection>(subnet_id, collection);
+    return (collection);
+}
+
+HostCollection
+CfgHosts::getAll6(const SubnetID& subnet_id) {
+    // Do not issue logging message here because it will be logged by
+    // the getAllInternal method.
+    HostCollection collection;
+    getAllInternal6<HostCollection>(subnet_id, collection);
+    return (collection);
+}
+
 ConstHostCollection
 CfgHosts::getAll4(const IOAddress& address) const {
     // Do not issue logging message here because it will be logged by
@@ -121,6 +157,63 @@ CfgHosts::getAllInternal(const Host::IdentifierType& identifier_type,
         .arg(storage.size());
 }
 
+template<typename Storage>
+void
+CfgHosts::getAllInternal4(const SubnetID& subnet_id,
+                          Storage& storage) const {
+
+    LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE, HOSTS_CFG_GET_ALL_SUBNET_ID4)
+        .arg(subnet_id);
+
+    // Use try DHCPv4 subnet id.
+    const HostContainerIndex2& idx = hosts_.get<2>();
+
+    // Append each Host object to the storage.
+    for (HostContainerIndex2::iterator host = idx.lower_bound(subnet_id);
+         host != idx.upper_bound(subnet_id);
+         ++host) {
+        LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE_DETAIL_DATA,
+                  HOSTS_CFG_GET_ALL_SUBNET_ID4_HOST)
+            .arg(subnet_id)
+            .arg((*host)->toText());
+        storage.push_back(*host);
+    }
+
+    // Log how many hosts have been found.
+    LOG_DEBUG(hosts_logger, HOSTS_DBG_RESULTS, HOSTS_CFG_GET_ALL_SUBNET_ID4_COUNT)
+        .arg(subnet_id)
+        .arg(storage.size());
+}
+
+template<typename Storage>
+void
+CfgHosts::getAllInternal6(const SubnetID& subnet_id,
+                          Storage& storage) const {
+
+    LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE, HOSTS_CFG_GET_ALL_SUBNET_ID6)
+        .arg(subnet_id);
+
+    // Use try DHCPv6 subnet id.
+    const HostContainerIndex3& idx = hosts_.get<3>();
+
+    // Append each Host object to the storage.
+    for (HostContainerIndex3::iterator host = idx.lower_bound(subnet_id);
+         host != idx.upper_bound(subnet_id);
+         ++host) {
+        LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE_DETAIL_DATA,
+                  HOSTS_CFG_GET_ALL_SUBNET_ID6_HOST)
+            .arg(subnet_id)
+            .arg((*host)->toText());
+        storage.push_back(*host);
+    }
+
+    // Log how many hosts have been found.
+    LOG_DEBUG(hosts_logger, HOSTS_DBG_RESULTS, HOSTS_CFG_GET_ALL_SUBNET_ID6_COUNT)
+        .arg(subnet_id)
+        .arg(storage.size());
+}
+
+
 template<typename Storage>
 void
 CfgHosts::getAllInternal4(const IOAddress& address, Storage& storage) const {
@@ -447,7 +540,7 @@ CfgHosts::add(const HostPtr& host) {
     }
 
     // At least one subnet ID must be used
-    if (host->getIPv4SubnetID() == SUBNET_ID_UNUSED && 
+    if (host->getIPv4SubnetID() == SUBNET_ID_UNUSED &&
         host->getIPv6SubnetID() == SUBNET_ID_UNUSED) {
         isc_throw(BadValue, "must not use both IPv4 and IPv6 subnet ids of"
                   " 0 when adding new host reservation");
index 52b0f4f82c59f278295ab18ec1f890ab4542ccd2..eada8a2a0c6508e8ea853198b72f291a1c6d886b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-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
@@ -75,6 +75,50 @@ public:
            const uint8_t* identifier_begin,
            const size_t identifier_len);
 
+    /// @brief Return all hosts in a DHCPv4 subnet.
+    ///
+    /// This method returns all @c Host objects which represent reservations
+    /// in a specified subnet.
+    ///
+    /// @param subnet_id Subnet identifier.
+    ///
+    /// @return Collection of const @c Host objects.
+    virtual ConstHostCollection
+    getAll4(const SubnetID& subnet_id) const;
+
+    /// @brief Return all hosts in a DHCPv4 subnet.
+    ///
+    /// This method returns all @c Host objects which represent reservations
+    /// in a specified subnet.
+    ///
+    /// @param subnet_id Subnet identifier.
+    ///
+    /// @return Collection of non-const @c Host objects.
+    virtual HostCollection
+    getAll4(const SubnetID& subnet_id);
+
+    /// @brief Return all hosts in a DHCPv6 subnet.
+    ///
+    /// This method returns all @c Host objects which represent reservations
+    /// in a specified subnet.
+    ///
+    /// @param subnet_id Subnet identifier.
+    ///
+    /// @return Collection of const @c Host objects.
+    virtual ConstHostCollection
+    getAll6(const SubnetID& subnet_id) const;
+
+    /// @brief Return all hosts in a DHCPv6 subnet.
+    ///
+    /// This method returns all @c Host objects which represent reservations
+    /// in a specified subnet.
+    ///
+    /// @param subnet_id Subnet identifier.
+    ///
+    /// @return Collection of non-const @c Host objects.
+    virtual HostCollection
+    getAll6(const SubnetID& subnet_id);
+
     /// @brief Returns a collection of hosts using the specified IPv4 address.
     ///
     /// This method may return multiple @c Host objects if they are connected
@@ -332,6 +376,34 @@ private:
                         const size_t identifier_len,
                         Storage& storage) const;
 
+    /// @brief Returns @c Host objects in a DHCPv4 subnet.
+    ///
+    /// This private method is called by the @c CfgHosts::getAllInternal
+    /// method which finds the @c Host objects in a specified subnet.
+    /// The retrieved objects are appended to the @c storage container.
+    ///
+    /// @param subnet_id Subnet identifier.
+    /// @param [out] storage Container to which the retrieved objects are
+    /// appended.
+    /// @tparam One of the @c ConstHostCollection of @c HostCollection.
+    template<typename Storage>
+    void getAllInternal4(const SubnetID& subnet_id,
+                         Storage& storage) const;
+
+    /// @brief Returns @c Host objects in a DHCPv6 subnet.
+    ///
+    /// This private method is called by the @c CfgHosts::getAllInternal
+    /// method which finds the @c Host objects in a specified subnet.
+    /// The retrieved objects are appended to the @c storage container.
+    ///
+    /// @param subnet_id Subnet identifier.
+    /// @param [out] storage Container to which the retrieved objects are
+    /// appended.
+    /// @tparam One of the @c ConstHostCollection of @c HostCollection.
+    template<typename Storage>
+    void getAllInternal6(const SubnetID& subnet_id,
+                         Storage& storage) const;
+
     /// @brief Returns @c Host objects for the specified IPv4 address.
     ///
     /// This private method is called by the @c CfgHosts::getAll4 methods
index 1b788eb7479a0f4893486681a8efd96a3ee96387..c657d9c3946cea69462300388428b1ec6ccf984d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
 // Copyright (C) 2016-2018 Deutsche Telekom AG.
 //
 // Author: Andrei Pavel <andrei.pavel@qualitance.com>
@@ -168,6 +168,28 @@ public:
            const uint8_t* identifier_begin,
            const size_t identifier_len) const override;
 
+    /// @brief Return all hosts in a DHCPv4 subnet.
+    ///
+    /// This method returns all @ref Host objects which represent reservations
+    /// in a specified subnet.
+    ///
+    /// @param subnet_id subnet identifier to filter by
+    ///
+    /// @return Collection of const @ref Host objects.
+    virtual ConstHostCollection
+    getAll4(const SubnetID& subnet_id) const override;
+
+    /// @brief Return all hosts in a DHCPv6 subnet.
+    ///
+    /// This method returns all @ref Host objects which represent reservations
+    /// in a specified subnet.
+    ///
+    /// @param subnet_id subnet identifier to filter by
+    ///
+    /// @return Collection of const @ref Host objects.
+    virtual ConstHostCollection
+    getAll6(const SubnetID& subnet_id) const override;
+
     /// @brief Returns a collection of hosts using the specified IPv4 address.
     ///
     /// This method may return multiple @ref Host objects if they are connected
index 87770db6bc9d410e10085016909123c5579d6c57..777fceb4d2428eb31d0a83017c7f9e1505825430 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-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
@@ -110,6 +110,27 @@ HostMgr::getAll(const Host::IdentifierType& identifier_type,
     return (hosts);
 }
 
+ConstHostCollection
+HostMgr::getAll4(const SubnetID& subnet_id) const {
+    ConstHostCollection hosts = getCfgHosts()->getAll4(subnet_id);
+    for (auto source : alternate_sources_) {
+        ConstHostCollection hosts_plus = source->getAll4(subnet_id);
+        hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
+    }
+    return (hosts);
+}
+
+
+ConstHostCollection
+HostMgr::getAll6(const SubnetID& subnet_id) const {
+    ConstHostCollection hosts = getCfgHosts()->getAll6(subnet_id);
+    for (auto source : alternate_sources_) {
+        ConstHostCollection hosts_plus = source->getAll6(subnet_id);
+        hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
+    }
+    return (hosts);
+}
+
 
 ConstHostCollection
 HostMgr::getAll4(const IOAddress& address) const {
@@ -186,7 +207,7 @@ HostMgr::get4(const SubnetID& subnet_id,
     }
     return (host);
 }
-    
+
 ConstHostPtr
 HostMgr::get4(const SubnetID& subnet_id,
               const asiolink::IOAddress& address) const {
index fa6248f0250930922e1502ab77cedd78dd828060..a5e90a02c4878fbc50526c6b181f225e6ec08cb1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-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
@@ -124,6 +124,42 @@ public:
            const uint8_t* identifier_begin,
            const size_t identifier_len) const;
 
+    /// @brief Return all hosts in a DHCPv4 subnet.
+    ///
+    /// This method returns all @c Host objects representing reservations
+    /// in a specified subnet as documented in the
+    /// @c BaseHostDataSource::getAll4
+    ///
+    /// It retrieves reservations from both primary and alternate host data
+    /// source as a single collection of @c Host objects, i.e. if matching
+    /// reservations are in both sources, all of them are returned. The
+    /// reservations from the primary data source are placed before the
+    /// reservations from the alternate source.
+    ///
+    /// @param subnet_id Subnet identifier.
+    ///
+    /// @return Collection of const @c Host objects.
+    virtual ConstHostCollection
+    getAll4(const SubnetID& subnet_id) const;
+
+    /// @brief Return all hosts in a DHCPv6 subnet.
+    ///
+    /// This method returns all @c Host objects representing reservations
+    /// in a specified subnet as documented in the
+    /// @c BaseHostDataSource::getAll6
+    ///
+    /// It retrieves reservations from both primary and alternate host data
+    /// source as a single collection of @c Host objects, i.e. if matching
+    /// reservations are in both sources, all of them are returned. The
+    /// reservations from the primary data source are placed before the
+    /// reservations from the alternate source.
+    ///
+    /// @param subnet_id Subnet identifier.
+    ///
+    /// @return Collection of const @c Host objects.
+    virtual ConstHostCollection
+    getAll6(const SubnetID& subnet_id) const;
+
     /// @brief Returns a collection of hosts using the specified IPv4 address.
     ///
     /// This method may return multiple @c Host objects if they are connected to
@@ -195,7 +231,7 @@ public:
     /// @brief Returns any host connected to the IPv6 subnet.
     ///
     /// This method returns a host connected to the IPv6 subnet as described
-    /// in the @c BaseHostDataSource::get6 even when the             
+    /// in the @c BaseHostDataSource::get6 even when the
     /// reservation is marked as from negative caching. This allows to
     /// monitor negative caching.
     ///
index bdae8d9b1ee7de5756b237d7d291202d2e7b9ccf..41b933bbcd2ad4c53e6529e85ea595bf6e3f8137 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2015-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
@@ -88,6 +88,14 @@ This debug message is issued when found host identified by the specific
 identifier. The arguments specify the identifier and the detailed
 description of the host found.
 
+% HOSTS_CFG_GET_ALL_SUBNET_ID4 get all hosts with reservations for subnet id4 %1
+This debug message is issued when starting to retrieve all hosts connected to
+the specific DHCPv4 subnet. The argument specifies subnet id.
+
+% HOSTS_CFG_GET_ALL_SUBNET_ID6 get all hosts with reservations for subnet id6 %1
+This debug message is issued when starting to retrieve all hosts connected to
+the specific DHCPv6 subnet. The argument specifies subnet id.
+
 % HOSTS_CFG_GET_ALL_SUBNET_ID_ADDRESS6 get all hosts with reservations for subnet id %1 and IPv6 address %2
 This debug message is issued when starting to retrieve all hosts connected to
 the specific subnet and having the specific IPv6 address reserved.
@@ -96,13 +104,32 @@ The arguments specify subnet id and IPv6 address respectively.
 % HOSTS_CFG_GET_ALL_SUBNET_ID_ADDRESS6_COUNT using subnet id %1 and address %2, found %3 host(s)
 This debug message include the details of the host found using the
 subnet id and address. The arguments specify subnet id, address and
-found host details respectively.
+the number of hosts found respectively.
 
 % HOSTS_CFG_GET_ALL_SUBNET_ID_ADDRESS6_HOST using subnet id %1 and address %2, found host: %3
 This debug message includes the details of the host found using the
 subnet id and address. The arguments specify subnet id, address and
+the number of hosts found respectively.
 found host details respectively.
 
+% HOSTS_CFG_GET_ALL_SUBNET_ID4_COUNT using subnet id4 %1, found %2 host(s)
+This debug message include the details of the host found using the DHCPv4
+subnet id. The arguments specify subnet id and the number of hosts found
+respectively.
+
+% HOSTS_CFG_GET_ALL_SUBNET_ID6_COUNT using subnet id6 %1, found %2 host(s)
+This debug message include the details of the host found using the DHCPv6
+subnet id. The arguments specify subnet id and the number of hosts found
+respectively.
+
+% HOSTS_CFG_GET_ALL_SUBNET_ID4_HOST using subnet id4 %1, found host: %2
+This debug message includes the details of the host found using the DHCPv4
+subnet id. The arguments specify subnet id and found host details respectively.
+
+% HOSTS_CFG_GET_ALL_SUBNET_ID6_HOST using subnet id6 %1, found host: %2
+This debug message includes the details of the host found using the DHCPv6
+subnet id. The arguments specify subnet id and found host details respectively.
+
 % HOSTS_CFG_GET_ONE_PREFIX get one host with reservation for prefix %1/%2
 This debug message is issued when starting to retrieve a host having a
 reservation for a specified prefix. The arguments specify a prefix and
index 9bae27107fd36f05c18a82cc8d2e2486436f134f..73b3058c4eab31a686bbda607612427e85e7099c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-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
@@ -131,6 +131,28 @@ public:
     getAll(const Host::IdentifierType& identifier_type,
            const uint8_t* identifier_begin, const size_t identifier_len) const;
 
+    /// @brief Return all hosts in a DHCPv4 subnet.
+    ///
+    /// This method returns all @ref Host objects which represent reservations
+    /// in a specified subnet.
+    ///
+    /// @param subnet_id subnet identifier to filter by
+    ///
+    /// @return Collection of const @ref Host objects.
+    virtual ConstHostCollection
+    getAll4(const SubnetID& subnet_id) const override;
+
+    /// @brief Return all hosts in a DHCPv6 subnet.
+    ///
+    /// This method returns all @ref Host objects which represent reservations
+    /// in a specified subnet.
+    ///
+    /// @param subnet_id subnet identifier to filter by
+    ///
+    /// @return Collection of const @ref Host objects.
+    virtual ConstHostCollection
+    getAll6(const SubnetID& subnet_id) const override;
+
     /// @brief Returns a collection of hosts using the specified IPv4 address.
     ///
     /// This method may return multiple @c Host objects if they are connected
index 66b024a5f796c2e5653652bed92d63937ff893a8..f829d973bb3b9e888df7c2682556ba749e5cafd6 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-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
@@ -158,6 +158,28 @@ public:
     getAll(const Host::IdentifierType& identifier_type,
            const uint8_t* identifier_begin, const size_t identifier_len) const;
 
+    /// @brief Return all hosts in a DHCPv4 subnet.
+    ///
+    /// This method returns all @ref Host objects which represent reservations
+    /// in a specified subnet.
+    ///
+    /// @param subnet_id subnet identifier to filter by
+    ///
+    /// @return Collection of const @ref Host objects.
+    virtual ConstHostCollection
+    getAll4(const SubnetID& subnet_id) const override;
+
+    /// @brief Return all hosts in a DHCPv6 subnet.
+    ///
+    /// This method returns all @ref Host objects which represent reservations
+    /// in a specified subnet.
+    ///
+    /// @param subnet_id subnet identifier to filter by
+    ///
+    /// @return Collection of const @ref Host objects.
+    virtual ConstHostCollection
+    getAll6(const SubnetID& subnet_id) const override;
+
     /// @brief Returns a collection of hosts using the specified IPv4 address.
     ///
     /// This method may return multiple @c Host objects if they are connected
index 2a3d4269a94051f587b864f53846844c07fa99f7..91eca0996010148b5a7edfb89706cbae4e9121bb 100644 (file)
@@ -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
@@ -182,7 +182,7 @@ TEST_F(HostCacheTest, identifier4) {
 
     // Remove it from test host data source.
     EXPECT_TRUE(memptr_->del(host->getIPv4SubnetID(), address));
-    
+
     // It is cached so we can still get it.
     got = HostMgr::instance().get4(host->getIPv4SubnetID(),
                                    host->getIdentifierType(),
@@ -190,7 +190,7 @@ TEST_F(HostCacheTest, identifier4) {
                                    host->getIdentifier().size());
     ASSERT_TRUE(got);
     HostDataSourceUtils::compareHosts(got, host);
-                                                
+
     // Even by address.
     got = HostMgr::instance().get4(host->getIPv4SubnetID(), address);
     ASSERT_TRUE(got);
@@ -215,7 +215,7 @@ TEST_F(HostCacheTest, identifier6) {
                                                         Host::IDENT_DUID,
                                                         false);
     ASSERT_TRUE(host);  // Make sure the host is generated properly.
-    
+
     // Get the address.
     IPv6ResrvRange resrvs = host->getIPv6Reservations();
     ASSERT_EQ(1, std::distance(resrvs.first, resrvs.second));
@@ -239,7 +239,7 @@ TEST_F(HostCacheTest, identifier6) {
 
     // Remove it from test host data source.
     EXPECT_TRUE(memptr_->del(host->getIPv6SubnetID(), address));
-    
+
     // It is cached so we can still get it.
     got = HostMgr::instance().get6(host->getIPv6SubnetID(),
                                    host->getIdentifierType(),
@@ -247,7 +247,7 @@ TEST_F(HostCacheTest, identifier6) {
                                    host->getIdentifier().size());
     ASSERT_TRUE(got);
     HostDataSourceUtils::compareHosts(got, host);
-                                                
+
     // Even by address.
     got = HostMgr::instance().get6(host->getIPv6SubnetID(), address);
     ASSERT_TRUE(got);
@@ -288,12 +288,12 @@ TEST_F(HostCacheTest, address4) {
 
     // Remove it from test host data source.
     EXPECT_TRUE(memptr_->del(host->getIPv4SubnetID(), address));
-    
+
     // It is cached so we can still get it.
     got = HostMgr::instance().get4(host->getIPv4SubnetID(), address);
     ASSERT_TRUE(got);
     HostDataSourceUtils::compareHosts(got, host);
-                                                
+
     // Even by identifier.
     got = HostMgr::instance().get4(host->getIPv4SubnetID(),
                                    host->getIdentifierType(),
@@ -321,7 +321,7 @@ TEST_F(HostCacheTest, address6) {
                                                         Host::IDENT_DUID,
                                                         false);
     ASSERT_TRUE(host);  // Make sure the host is generated properly.
-    
+
     // Get the address.
     IPv6ResrvRange resrvs = host->getIPv6Reservations();
     ASSERT_EQ(1, std::distance(resrvs.first, resrvs.second));
@@ -343,12 +343,12 @@ TEST_F(HostCacheTest, address6) {
 
     // Remove it from test host data source.
     EXPECT_TRUE(memptr_->del(host->getIPv6SubnetID(), address));
-    
+
     // It is cached so we can still get it.
     got = HostMgr::instance().get6(host->getIPv6SubnetID(), address);
     ASSERT_TRUE(got);
     HostDataSourceUtils::compareHosts(got, host);
-                                                
+
     // Even by identifier.
     got = HostMgr::instance().get6(host->getIPv6SubnetID(),
                                    host->getIdentifierType(),
@@ -565,7 +565,7 @@ TEST_F(HostCacheTest, negativeAddress6) {
                                                         Host::IDENT_DUID,
                                                         false);
     ASSERT_TRUE(host);  // Make sure the host is generated properly.
-    
+
     // Get the address.
     IPv6ResrvRange resrvs = host->getIPv6Reservations();
     ASSERT_EQ(1, std::distance(resrvs.first, resrvs.second));
@@ -598,11 +598,19 @@ public:
     /// Destructor
     virtual ~TestOneBackend() { }
 
-    ConstHostCollection getAll(const Host::IdentifierType&, const uint8_t*, 
+    ConstHostCollection getAll(const Host::IdentifierType&, const uint8_t*,
                                const size_t) const {
         return (getCollection());
     }
 
+    ConstHostCollection getAll4(const SubnetID&) const {
+        return (getCollection());
+    }
+
+    ConstHostCollection getAll6(const SubnetID&) const {
+        return (getCollection());
+    }
+
     ConstHostCollection getAll4(const IOAddress&) const {
         return (getCollection());
     }
index f9f6e6a67cdba48e999cda1acfc9053361374366..8a53dd5930c3dc797ffa6f21cca181ad08e3eb8c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-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
@@ -98,7 +98,7 @@ GenericHostDataSourceTest::addTestOptions(const HostPtr& host,
     if ((added_options == DHCP4_ONLY) || (added_options == DHCP4_AND_DHCP6)) {
         // Add DHCPv4 options.
         CfgOptionPtr opts = host->getCfgOption4();
-        OptionDescriptor desc = 
+        OptionDescriptor desc =
             createOption<OptionString>(Option::V4, DHO_BOOT_FILE_NAME,
                                        true, formatted, "my-boot-file");
         desc.setContext(user_context);
@@ -129,7 +129,7 @@ GenericHostDataSourceTest::addTestOptions(const HostPtr& host,
     if ((added_options == DHCP6_ONLY) || (added_options == DHCP4_AND_DHCP6)) {
         // Add DHCPv6 options.
         CfgOptionPtr opts = host->getCfgOption6();
-        OptionDescriptor desc = 
+        OptionDescriptor desc =
             createOption<OptionString>(Option::V6, D6O_BOOTFILE_URL,
                                        true, formatted, "my-boot-file");
         desc.setContext(user_context);
@@ -1022,6 +1022,11 @@ void GenericHostDataSourceTest::testOptionsReservations4(const bool formatted,
     // Subnet id will be used in queries to the database.
     SubnetID subnet_id = host->getIPv4SubnetID();
 
+    // getAll4(subnet_id)
+    ConstHostCollection hosts_by_subnet = hdsptr_->getAll4(subnet_id);
+    // Not yet implemented.
+    EXPECT_EQ(0, hosts_by_subnet.size());
+
     // getAll4(address)
     ConstHostCollection hosts_by_addr =
         hdsptr_->getAll4(host->getIPv4Reservation());
@@ -1069,6 +1074,13 @@ GenericHostDataSourceTest::testOptionsReservations46(const bool formatted) {
     ASSERT_NO_THROW(addTestOptions(host, formatted, DHCP4_AND_DHCP6));
     // Insert host, options and IPv6 reservations into respective tables.
     ASSERT_NO_THROW(hdsptr_->add(host));
+    // Subnet id will be used in queries to the database.
+    SubnetID subnet_id = host->getIPv6SubnetID();
+
+    // getAll6(subnet_id)
+    ConstHostCollection hosts_by_subnet = hdsptr_->getAll6(subnet_id);
+    // Not yet implemented.
+    EXPECT_EQ(0, hosts_by_subnet.size());
 
     // getAll(identifier_type, identifier, identifier_size)
     ConstHostCollection hosts_by_id =
@@ -1289,7 +1301,7 @@ GenericHostDataSourceTest::stressTest(unsigned int nOfHosts /* = 0xfffdU */) {
         const std::string prefix = std::string("2001:db8::") + n_host;
         hosts.push_back(HostDataSourceUtils::initializeHost6(prefix,
                         Host::IDENT_HWADDR, false, "key##1"));
-        
+
         IPv6ResrvRange range = hosts.back()->getIPv6Reservations();
         ASSERT_EQ(1, std::distance(range.first, range.second));
         EXPECT_TRUE(HostDataSourceUtils::reservationExists
index d5589476f5c47c369cf07399ddef4bdd18ad114a..3c28949d5f6c3a6d782560fc7d745de1d5cf2cb5 100644 (file)
@@ -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
@@ -22,6 +22,16 @@ MemHostDataSource::getAll(const Host::IdentifierType& /*identifier_type*/,
     return (ConstHostCollection());
 }
 
+ConstHostCollection
+MemHostDataSource::getAll4(const SubnetID& /*subnet_id*/) const {
+    return (ConstHostCollection());
+}
+
+ConstHostCollection
+MemHostDataSource::getAll6(const SubnetID& /*subnet_id*/) const {
+    return (ConstHostCollection());
+}
+
 ConstHostCollection
 MemHostDataSource::getAll4(const asiolink::IOAddress& /*address*/) const {
     return (ConstHostCollection());
index ce43090e0bc0481a0e8eb52e6104e6eaa22793fb..380a6dba2373c970b03681ff610b7cd66d4af70d 100644 (file)
@@ -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
@@ -46,6 +46,22 @@ public:
            const uint8_t* identifier_begin,
            const size_t identifier_len) const;
 
+    /// @brief Return all hosts in a DHCPv4 subnet.
+    ///
+    /// Currently not implemented.
+    ///
+    /// @param subnet_id Subnet identifier.
+    virtual ConstHostCollection
+    getAll4(const SubnetID& subnet_id) const;
+
+    /// @brief Return all hosts in a DHCPv6 subnet.
+    ///
+    /// Currently not implemented.
+    ///
+    /// @param subnet_id Subnet identifier.
+    virtual ConstHostCollection
+    getAll6(const SubnetID& subnet_id) const;
+
     /// @brief Returns a collection of hosts using the specified IPv4 address.
     ///
     /// Currently not implemented.
index 931ed129957e093c06374f18589e85ce78b9bbd4..d3965c9e2fd5bef4742da4cbce576f28671057f2 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-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
@@ -41,6 +41,22 @@ public:
            const uint8_t* identifier_begin,
            const size_t identifier_len) = 0;
 
+    /// @brief Returns a collection of hosts in the specified DHCPv4 subnet.
+    ///
+    /// @param subnet_id Subnet identifier.
+    ///
+    /// @return Collection of non-const @c Host objects.
+    virtual HostCollection
+    getAll4(const SubnetID& subnet_id) = 0;
+
+    /// @brief Returns a collection of hosts in the specified DHCPv6 subnet.
+    ///
+    /// @param subnet_id Subnet identifier.
+    ///
+    /// @return Collection of non-const @c Host objects.
+    virtual HostCollection
+    getAll6(const SubnetID& subnet_id) = 0;
+
     /// @brief Returns a collection of hosts using the specified IPv4 address.
     ///
     /// This method may return multiple @c Host objects if they are connected