From: Francis Dupont Date: Wed, 23 Jan 2019 16:52:22 +0000 (+0100) Subject: [313-return-a-list-of-all-reservations-by-subnet-id] Added last (2.) test X-Git-Tag: 429-Updated-StampedValue-to-support-reals_base~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f59635ed74bc12a515fa0bf26961338bd7c34ba;p=thirdparty%2Fkea.git [313-return-a-list-of-all-reservations-by-subnet-id] Added last (2.) test --- diff --git a/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc index 37b7582a7f..6a1c3e1169 100644 --- a/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc @@ -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) { diff --git a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc index cceb854e4a..01343dd7a5 100644 --- a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc @@ -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) { diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc index 13b49c55e1..dabf94c15b 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc @@ -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(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 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 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. diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h index 5fe3391005..8ab7140ea8 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h @@ -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. ///