]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[313-return-a-list-of-all-reservations-by-subnet-id] Last changes 313-return-a-list-of-all-reservations-by-subnet-id
authorFrancis Dupont <fdupont@isc.org>
Mon, 28 Jan 2019 21:26:12 +0000 (22:26 +0100)
committerFrancis Dupont <fdupont@isc.org>
Tue, 29 Jan 2019 09:49:05 +0000 (04:49 -0500)
src/lib/dhcpsrv/cql_host_data_source.cc
src/lib/dhcpsrv/host_mgr.cc
src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h

index a94121e437084798d9165fbcfb5a8fbb569237c4..e31071b86e82a3069bdd5a7bce9b3144f8934f69 100644 (file)
@@ -1529,7 +1529,7 @@ public:
     /// @brief Implementation of @ref CqlHostDataSource::getPage4()
     ///
     /// Not implemented.
-    /// @todo: implement it.
+    /// @todo: implement it (#427).
     ///
     /// See @ref CqlHostDataSource::getPage4() for parameter details.
     ///
@@ -1545,7 +1545,7 @@ public:
     /// @brief Implementation of @ref CqlHostDataSource::getPage6()
     ///
     /// Not implemented.
-    /// @todo: implement it.
+    /// @todo: implement it (#427).
     ///
     /// See @ref CqlHostDataSource::getPage6() for parameter details.
     ///
index bfb146900f1294a616f2005c83ed85f94ff12344..94859dfad30a98f906a6e77adb36f7b4a0a97823 100644 (file)
@@ -136,55 +136,63 @@ HostMgr::getPage4(const SubnetID& subnet_id,
                   size_t& source_index,
                   uint64_t lower_host_id,
                   const HostPageSize& page_size) const {
-    for (;;) {
-        if (source_index > alternate_sources_.size()) {
-            return (ConstHostCollection());
-        }
-        ConstHostCollection hosts;
-        if (source_index == 0) {
-            hosts = getCfgHosts()->
-                getPage4(subnet_id, source_index, lower_host_id, page_size);
-        } else {
-            hosts = alternate_sources_[source_index - 1]->
-                getPage4(subnet_id, source_index, lower_host_id, page_size);
-        }
-        if (!hosts.empty()) {
-            return (hosts);
-        } else {
-            ++source_index;
-            lower_host_id = 0;
-            continue;
-        }
+    // Return empty if (and only if) sources are exhausted.
+    if (source_index > alternate_sources_.size()) {
+        return (ConstHostCollection());
+    }
+
+    ConstHostCollection hosts;
+    // Source index 0 means config file.
+    if (source_index == 0) {
+        hosts = getCfgHosts()->
+            getPage4(subnet_id, source_index, lower_host_id, page_size);
+    } else {
+        hosts = alternate_sources_[source_index - 1]->
+            getPage4(subnet_id, source_index, lower_host_id, page_size);
     }
+
+    // When got something return it.
+    if (!hosts.empty()) {
+        return (hosts);
+    }
+
+    // Nothing from this source: try the next one.
+    // Note the recursion is limited to the number of sources in all cases.
+    ++source_index;
+    return (getPage4(subnet_id, source_index, 0UL, page_size));
 }
-        
+
 ConstHostCollection
 HostMgr::getPage6(const SubnetID& subnet_id,
                   size_t& source_index,
                   uint64_t lower_host_id,
                   const HostPageSize& page_size) const {
-    for (;;) {
-        if (source_index > alternate_sources_.size()) {
-            return (ConstHostCollection());
-        }
-        ConstHostCollection hosts;
-        if (source_index == 0) {
-            hosts = getCfgHosts()->
-                getPage6(subnet_id, source_index, lower_host_id, page_size);
-        } else {
-            hosts = alternate_sources_[source_index - 1]->
-                getPage6(subnet_id, source_index, lower_host_id, page_size);
-        }
-        if (!hosts.empty()) {
-            return (hosts);
-        } else {
-            ++source_index;
-            lower_host_id = 0;
-            continue;
-        }
+    // Return empty if (and only if) sources are exhausted.
+    if (source_index > alternate_sources_.size()) {
+        return (ConstHostCollection());
+    }
+
+    ConstHostCollection hosts;
+    // Source index 0 means config file.
+    if (source_index == 0) {
+        hosts = getCfgHosts()->
+            getPage6(subnet_id, source_index, lower_host_id, page_size);
+    } else {
+        hosts = alternate_sources_[source_index - 1]->
+            getPage6(subnet_id, source_index, lower_host_id, page_size);
     }
+
+    // When got something return it.
+    if (!hosts.empty()) {
+        return (hosts);
+    }
+
+    // Nothing from this source: try the next one.
+    // Note the recursion is limited to the number of sources in all cases.
+    ++source_index;
+    return (getPage6(subnet_id, source_index, 0UL, page_size));
 }
-        
+
 ConstHostCollection
 HostMgr::getAll4(const IOAddress& address) const {
     ConstHostCollection hosts = getCfgHosts()->getAll4(address);
index 71fd3e64485ab74ee08c73c564a77a7d144aa2bd..0fe732c72c4cd0ec47ae1c126c19481bae746f5f 100644 (file)
@@ -295,25 +295,25 @@ TEST_F(CqlHostDataSourceTest, DISABLED_testReadOnlyDatabase) {
 
 // Verifies that IPv4 host reservations in the same subnet can be retrieved
 TEST_F(CqlHostDataSourceTest, getAll4BySubnet) {
-    testGetAll4(Host::IDENT_HWADDR);
+    testGetAll4();
 }
 
 // Verifies that IPv6 host reservations in the same subnet can be retrieved
 TEST_F(CqlHostDataSourceTest, getAll6BySubnet) {
-    testGetAll6(Host::IDENT_DUID);
+    testGetAll6();
 }
 
 // Verifies that IPv4 host reservations in the same subnet can be retrieved
 // by pages.
 // Does not work because TOKEN(id) order is not the same than id...
 TEST_F(CqlHostDataSourceTest, DISABLED_getPage4) {
-    testGetPage4(Host::IDENT_DUID);
+    testGetPage4();
 }
 
 // Verifies that IPv6 host reservations in the same subnet can be retrieved
 // by pages.
 TEST_F(CqlHostDataSourceTest, DISABLED_getPage6) {
-    testGetPage6(Host::IDENT_HWADDR);
+    testGetPage6();
 }
 
 // Test verifies if a host reservation can be added and later retrieved by IPv4
index 6a1c3e1169aee9db128d69c85c496ae6cbba8c5b..57c3258d15bdd39b215b200ee930925c9b7beea2 100644 (file)
@@ -313,24 +313,24 @@ TEST_F(MySqlHostDataSourceTest, maxSubnetId6) {
 
 // Verifies that IPv4 host reservations in the same subnet can be retrieved
 TEST_F(MySqlHostDataSourceTest, getAll4BySubnet) {
-    testGetAll4(Host::IDENT_HWADDR);
+    testGetAll4();
 }
 
 // Verifies that IPv6 host reservations in the same subnet can be retrieved
 TEST_F(MySqlHostDataSourceTest, getAll6BySubnet) {
-    testGetAll6(Host::IDENT_DUID);
+    testGetAll6();
 }
 
 // Verifies that IPv4 host reservations in the same subnet can be retrieved
 // by pages.
 TEST_F(MySqlHostDataSourceTest, getPage4) {
-    testGetPage4(Host::IDENT_DUID);
+    testGetPage4();
 }
 
 // Verifies that IPv6 host reservations in the same subnet can be retrieved
 // by pages.
 TEST_F(MySqlHostDataSourceTest, getPage6) {
-    testGetPage6(Host::IDENT_HWADDR);
+    testGetPage6();
 }
 
 // Verifies that IPv4 host reservations in the same subnet can be retrieved
index 01343dd7a52a19ba6bd061a886eccb7128edebb3..67f8ecc1b73b46e7803765e66ee950d904643f75 100644 (file)
@@ -298,24 +298,24 @@ TEST_F(PgSqlHostDataSourceTest, maxSubnetId6) {
 
 // Verifies that IPv4 host reservations in the same subnet can be retrieved
 TEST_F(PgSqlHostDataSourceTest, getAll4BySubnet) {
-    testGetAll4(Host::IDENT_HWADDR);
+    testGetAll4();
 }
 
 // Verifies that IPv6 host reservations in the same subnet can be retrieved
 TEST_F(PgSqlHostDataSourceTest, getAll6BySubnet) {
-    testGetAll6(Host::IDENT_DUID);
+    testGetAll6();
 }
 
 // Verifies that IPv4 host reservations in the same subnet can be retrieved
 // by pages.
 TEST_F(PgSqlHostDataSourceTest, getPage4) {
-    testGetPage4(Host::IDENT_DUID);
+    testGetPage4();
 }
 
 // Verifies that IPv6 host reservations in the same subnet can be retrieved
 // by pages.
 TEST_F(PgSqlHostDataSourceTest, getPage6) {
-    testGetPage6(Host::IDENT_HWADDR);
+    testGetPage6();
 }
 
 // Verifies that IPv4 host reservations in the same subnet can be retrieved
index dabf94c15b68e06e3fa19f5d32206376db03ae26..5d47aea68a3627c37731177aa9cd897c50cb62a2 100644 (file)
@@ -357,11 +357,12 @@ void GenericHostDataSourceTest::testMaxSubnetId6() {
 }
 
 void
-GenericHostDataSourceTest::testGetAll4(const Host::IdentifierType& id) {
+GenericHostDataSourceTest::testGetAll4() {
     // Make sure we have a pointer to the host data source.
     ASSERT_TRUE(hdsptr_);
 
     // Let's create a couple of hosts...
+    const Host::IdentifierType& id = Host::IDENT_HWADDR;
     HostPtr host1 = HostDataSourceUtils::initializeHost4("192.0.2.1", id);
     HostPtr host2 = HostDataSourceUtils::initializeHost4("192.0.2.2", id);
     HostPtr host3 = HostDataSourceUtils::initializeHost4("192.0.2.3", id);
@@ -400,11 +401,12 @@ GenericHostDataSourceTest::testGetAll4(const Host::IdentifierType& id) {
 }
 
 void
-GenericHostDataSourceTest::testGetAll6(const Host::IdentifierType& id) {
+GenericHostDataSourceTest::testGetAll6() {
     // Make sure we have a pointer to the host data source.
     ASSERT_TRUE(hdsptr_);
 
     // Let's create a couple of hosts...
+    const Host::IdentifierType& id = Host::IDENT_DUID;
     HostPtr host1 = HostDataSourceUtils::initializeHost6("2001:db8::1", id, false);
     HostPtr host2 = HostDataSourceUtils::initializeHost6("2001:db8::2", id, false);
     HostPtr host3 = HostDataSourceUtils::initializeHost6("2001:db8::3", id, false);
@@ -443,7 +445,7 @@ GenericHostDataSourceTest::testGetAll6(const Host::IdentifierType& id) {
 }
 
 void
-GenericHostDataSourceTest::testGetPage4(const Host::IdentifierType& id) {
+GenericHostDataSourceTest::testGetPage4() {
     // Make sure we have a pointer to the host data source.
     ASSERT_TRUE(hdsptr_);
 
@@ -451,6 +453,7 @@ GenericHostDataSourceTest::testGetPage4(const Host::IdentifierType& id) {
     IOAddress addr("192.0.2.0");
     SubnetID subnet4(4);
     SubnetID subnet6(6);
+    const Host::IdentifierType& id = Host::IDENT_DUID;
     for (unsigned i = 0; i < 25; ++i) {
         addr = IOAddress::increase(addr);
 
@@ -490,7 +493,7 @@ GenericHostDataSourceTest::testGetPage4(const Host::IdentifierType& id) {
 }
 
 void
-GenericHostDataSourceTest::testGetPage6(const Host::IdentifierType& id) {
+GenericHostDataSourceTest::testGetPage6() {
     // Make sure we have a pointer to the host data source.
     ASSERT_TRUE(hdsptr_);
 
@@ -498,6 +501,7 @@ GenericHostDataSourceTest::testGetPage6(const Host::IdentifierType& id) {
     IOAddress addr("2001:db8:1::");
     SubnetID subnet4(4);
     SubnetID subnet6(6);
+    const Host::IdentifierType& id = Host::IDENT_HWADDR;
     for (unsigned i = 0; i < 25; ++i) {
         addr = IOAddress::increase(addr);
 
index 8ab7140ea82b6528f556c952d15025e7baf3a841..d8e58fcbc37b0aecb2a2016afbc3d3866639f467 100644 (file)
@@ -182,29 +182,25 @@ public:
     /// same subnet can be retrieved properly.
     ///
     /// Uses gtest macros to report failures.
-    /// @param id Identifier type (hwaddr or duid).
-    void testGetAll4(const Host::IdentifierType& id);
+    void testGetAll4();
 
     /// @brief Test that Verifies that IPv6 host reservations in the
     /// same subnet can be retrieved properly.
     ///
     /// Uses gtest macros to report failures.
-    /// @param id Identifier type (hwaddr or duid).
-    void testGetAll6(const Host::IdentifierType& id);
+    void testGetAll6();
 
     /// @brief Test that Verifies that pages of host reservations in the
     /// same subnet can be retrieved properly.
     ///
     /// Uses gtest macros to report failures.
-    /// @param id Identifier type (hwaddr or duid).
-    void testGetPage4(const Host::IdentifierType& id);
+    void testGetPage4();
 
     /// @brief Test that Verifies that pages of host reservations in the
     /// same subnet can be retrieved properly.
     ///
     /// Uses gtest macros to report failures.
-    /// @param id Identifier type (hwaddr or duid).
-    void testGetPage6(const Host::IdentifierType& id);
+    void testGetPage6();
 
     /// @brief Test that Verifies that pages of complex host reservations
     /// are not truncated, i.e. the limit applies on the number of hosts