]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[313-return-a-list-of-all-reservations-by-subnet-id] Added last (2.) test
authorFrancis Dupont <fdupont@isc.org>
Wed, 23 Jan 2019 16:52:22 +0000 (17:52 +0100)
committerFrancis Dupont <fdupont@isc.org>
Tue, 29 Jan 2019 09:49:05 +0000 (04:49 -0500)
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 37b7582a7f300844ae067573196465a4165cc8cc..6a1c3e1169aee9db128d69c85c496ae6cbba8c5b 100644 (file)
@@ -345,6 +345,18 @@ TEST_F(MySqlHostDataSourceTest, getPageLimit6) {
     testGetPageLimit6(Host::IDENT_HWADDR);
 }
 
+// Verifies that IPv4 host reservations in the same subnet can be retrieved
+// by pages even with multiple subnets.
+TEST_F(MySqlHostDataSourceTest, getPage4Subnets) {
+    testGetPage4Subnets();
+}
+
+// Verifies that IPv6 host reservations in the same subnet can be retrieved
+// by pages even with multiple subnets.
+TEST_F(MySqlHostDataSourceTest, getPage6Subnets) {
+    testGetPage6Subnets();
+}
+
 // Test verifies if a host reservation can be added and later retrieved by IPv4
 // address. Host uses client-id (DUID) as identifier.
 TEST_F(MySqlHostDataSourceTest, basic4ClientId) {
index cceb854e4aeb412091a80138d6bde33ba75549ac..01343dd7a52a19ba6bd061a886eccb7128edebb3 100644 (file)
@@ -330,6 +330,18 @@ TEST_F(PgSqlHostDataSourceTest, getPageLimit6) {
     testGetPageLimit6(Host::IDENT_HWADDR);
 }
 
+// Verifies that IPv4 host reservations in the same subnet can be retrieved
+// by pages even with multiple subnets.
+TEST_F(PgSqlHostDataSourceTest, getPage4Subnets) {
+    testGetPage4Subnets();
+}
+
+// Verifies that IPv6 host reservations in the same subnet can be retrieved
+// by pages even with multiple subnets.
+TEST_F(PgSqlHostDataSourceTest, getPage6Subnets) {
+    testGetPage6Subnets();
+}
+
 // Test verifies if a host reservation can be added and later retrieved by IPv4
 // address. Host uses client-id (DUID) as identifier.
 TEST_F(PgSqlHostDataSourceTest, basic4ClientId) {
index 13b49c55e1fa69e0692f08b4c14ba89b0733203f..dabf94c15b68e06e3fa19f5d32206376db03ae26 100644 (file)
@@ -635,7 +635,10 @@ GenericHostDataSourceTest::testGetPageLimit6(const Host::IdentifierType& id) {
                                              D6O_INFORMATION_REFRESH_TIME,
                                              false, false, 3600 + i),
                   DHCP6_OPTION_SPACE);
-        opts->add(createEmptyOption(Option::V6, 1, true), "isc2");
+        opts->add(createAddressOption<Option6AddrLst>(D6O_SIP_SERVERS_ADDR,
+                                                      false, false,
+                                                      addr.toText()),
+                  DHCP6_OPTION_SPACE);
 
         ASSERT_NO_THROW(hdsptr_->add(host));
         hosts.push_back(host);
@@ -669,6 +672,184 @@ GenericHostDataSourceTest::testGetPageLimit6(const Host::IdentifierType& id) {
     ASSERT_EQ(0, page.size());
 }
 
+void
+GenericHostDataSourceTest::testGetPage4Subnets() {
+    // From the ticket: add one host to subnet1, add one host to subnet2.
+    // repeat 5 times. Get hosts from subnet1 with page size 3.
+    // Make sure the right hosts are returned and in expected page
+    //sizes (3, then 2).
+
+    // Make sure we have a pointer to the host data source.
+    ASSERT_TRUE(hdsptr_);
+
+    // Let's create some hosts...
+    const Host::IdentifierType& id = Host::IDENT_HWADDR;
+    IOAddress addr("192.0.2.0");
+    SubnetID subnet4(4);
+    SubnetID subnet6(6);
+    vector<HostPtr> hosts;
+    for (unsigned i = 0; i < 10; ++i) {
+        addr = IOAddress::increase(addr);
+
+        HostPtr host = HostDataSourceUtils::initializeHost4(addr.toText(), id);
+        host->setIPv4SubnetID(subnet4 + (i & 1));
+        host->setIPv6SubnetID(subnet6 + (i & 1));
+
+        ASSERT_NO_THROW(hdsptr_->add(host));
+        hosts.push_back(host);
+    }
+
+    // First subnet.
+
+    // Get first page.
+    size_t idx(1);
+    uint64_t host_id(0);
+    HostPageSize page_size(3);
+    ConstHostCollection page;
+    ASSERT_NO_THROW(page = hdsptr_->getPage4(subnet4, idx, host_id, page_size));
+    ASSERT_EQ(3, page.size());
+    host_id = page[2]->getHostId();
+    ASSERT_NE(0, host_id);
+
+    // Verify retrieved hosts.
+    for (size_t i = 0; i < 3; ++i) {
+        HostDataSourceUtils::compareHosts(hosts[i * 2], page[i]);
+    }
+
+    // Get second and last pages.
+    ASSERT_NO_THROW(page = hdsptr_->getPage4(subnet4, idx, host_id, page_size));
+    ASSERT_EQ(2, page.size());
+    host_id = page[1]->getHostId();
+
+    // Verify retrieved hosts.
+    for (size_t i = 0; i < 2; ++i) {
+        HostDataSourceUtils::compareHosts(hosts[(i + 3) * 2], page[i]);
+    }
+
+    // Verify we have everything.
+    ASSERT_NO_THROW(page = hdsptr_->getPage4(subnet4, idx, host_id, page_size));
+    ASSERT_EQ(0, page.size());
+
+    // Second subnet.
+    ++subnet4;
+
+    // Get first page.
+    idx = 0;
+    host_id = 0;
+    ASSERT_NO_THROW(page = hdsptr_->getPage4(subnet4, idx, host_id, page_size));
+    ASSERT_EQ(3, page.size());
+    host_id = page[2]->getHostId();
+    ASSERT_NE(0, host_id);
+
+    // Verify retrieved hosts.
+    for (size_t i = 0; i < 3; ++i) {
+        HostDataSourceUtils::compareHosts(hosts[1 + (i * 2)], page[i]);
+    }
+
+    // Get second and last pages.
+    ASSERT_NO_THROW(page = hdsptr_->getPage4(subnet4, idx, host_id, page_size));
+    ASSERT_EQ(2, page.size());
+    host_id = page[1]->getHostId();
+
+    // Verify retrieved hosts.
+    for (size_t i = 0; i < 2; ++i) {
+        HostDataSourceUtils::compareHosts(hosts[1 + ((i + 3) * 2)], page[i]);
+    }
+
+    // Verify we have everything.
+    ASSERT_NO_THROW(page = hdsptr_->getPage4(subnet4, idx, host_id, page_size));
+    ASSERT_EQ(0, page.size());
+}
+
+void
+GenericHostDataSourceTest::testGetPage6Subnets() {
+    // From the ticket: add one host to subnet1, add one host to subnet2.
+    // repeat 5 times. Get hosts from subnet1 with page size 3.
+    // Make sure the right hosts are returned and in expected page
+    //sizes (3, then 2).
+
+    // Make sure we have a pointer to the host data source.
+    ASSERT_TRUE(hdsptr_);
+
+    // Let's create some hosts...
+    const Host::IdentifierType& id = Host::IDENT_DUID;
+    IOAddress addr("2001:db8:1::");
+    SubnetID subnet4(4);
+    SubnetID subnet6(6);
+    vector<HostPtr> hosts;
+    for (unsigned i = 0; i < 10; ++i) {
+        addr = IOAddress::increase(addr);
+
+        HostPtr host = HostDataSourceUtils::initializeHost6(addr.toText(), id, false);
+        host->setIPv4SubnetID(subnet4 + (i & 1));
+        host->setIPv6SubnetID(subnet6 + (i & 1));
+
+        ASSERT_NO_THROW(hdsptr_->add(host));
+        hosts.push_back(host);
+    }
+
+    // First subnet.
+
+    // Get first page.
+    size_t idx(1);
+    uint64_t host_id(0);
+    HostPageSize page_size(3);
+    ConstHostCollection page;
+    ASSERT_NO_THROW(page = hdsptr_->getPage6(subnet6, idx, host_id, page_size));
+    ASSERT_EQ(3, page.size());
+    host_id = page[2]->getHostId();
+    ASSERT_NE(0, host_id);
+
+    // Verify retrieved hosts.
+    for (size_t i = 0; i < 3; ++i) {
+        HostDataSourceUtils::compareHosts(hosts[i * 2], page[i]);
+    }
+
+    // Get second and last pages.
+    ASSERT_NO_THROW(page = hdsptr_->getPage6(subnet6, idx, host_id, page_size));
+    ASSERT_EQ(2, page.size());
+    host_id = page[1]->getHostId();
+
+    // Verify retrieved hosts.
+    for (size_t i = 0; i < 2; ++i) {
+        HostDataSourceUtils::compareHosts(hosts[(i + 3) * 2], page[i]);
+    }
+
+    // Verify we have everything.
+    ASSERT_NO_THROW(page = hdsptr_->getPage6(subnet6, idx, host_id, page_size));
+    ASSERT_EQ(0, page.size());
+
+    // Second subnet.
+    ++subnet6;
+
+    // Get first page.
+    idx = 0;
+    host_id = 0;
+    ASSERT_NO_THROW(page = hdsptr_->getPage6(subnet6, idx, host_id, page_size));
+    ASSERT_EQ(3, page.size());
+    host_id = page[2]->getHostId();
+    ASSERT_NE(0, host_id);
+
+    // Verify retrieved hosts.
+    for (size_t i = 0; i < 3; ++i) {
+        HostDataSourceUtils::compareHosts(hosts[1 + (i * 2)], page[i]);
+    }
+
+    // Get second and last pages.
+    ASSERT_NO_THROW(page = hdsptr_->getPage6(subnet6, idx, host_id, page_size));
+    ASSERT_EQ(2, page.size());
+    host_id = page[1]->getHostId();
+
+    // Verify retrieved hosts.
+    for (size_t i = 0; i < 2; ++i) {
+        HostDataSourceUtils::compareHosts(hosts[1 + ((i + 3) * 2)], page[i]);
+    }
+
+    // Verify we have everything.
+    ASSERT_NO_THROW(page = hdsptr_->getPage6(subnet6, idx, host_id, page_size));
+    ASSERT_EQ(0, page.size());
+}
+
 void
 GenericHostDataSourceTest::testGetByIPv4(const Host::IdentifierType& id) {
     // Make sure we have a pointer to the host data source.
index 5fe33910051ad57057d14b418fe2607e19faf177..8ab7140ea82b6528f556c952d15025e7baf3a841 100644 (file)
@@ -222,6 +222,18 @@ public:
     /// @param id Identifier type (hwaddr or duid).
     void testGetPageLimit6(const Host::IdentifierType& id);
 
+    /// @brief Test that Verifies that pages of host reservations in the
+    /// same subnet can be retrieved properly even with multiple subnets.
+    ///
+    /// Uses gtest macros to report failures.
+    void testGetPage4Subnets();
+
+    /// @brief Test that Verifies that pages of host reservations in the
+    /// same subnet can be retrieved properly even with multiple subnets.
+    ///
+    /// Uses gtest macros to report failures.
+    void testGetPage6Subnets();
+
     /// @brief Test inserts several hosts with unique IPv4 address and
     ///        checks that they can be retrieved properly.
     ///