From 07e39ecb604aa35131e989a5e4f34352bad0fdae Mon Sep 17 00:00:00 2001 From: Slawek Figiel Date: Thu, 6 Apr 2023 17:00:23 +0200 Subject: [PATCH] [#2815] Add unit test --- src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc b/src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc index 62e1a22e3e..0abd18d200 100644 --- a/src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc @@ -277,6 +277,34 @@ TEST_F(CfgHostsTest, getAll6BySubnet) { } } +// This test checks that hosts with the same reserved address can be retrieved +// from the host configuration. +TEST_F(CfgHostsTest, getAll6ByAddress) { + CfgHosts cfg; + // Add 25 hosts identified by DUID in the same subnet. + for (unsigned i = 0; i < 25; ++i) { + HostPtr host = HostPtr(new Host(duids_[i]->toText(), "duid", + SUBNET_ID_UNUSED, SubnetID(1), + IOAddress("0.0.0.0"))); + host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA, + increase(IOAddress("2001:db8:1::1"), + i % 5))); + cfg.add(host); + } + + // Try to retrieve all added reservations with IP equals 2001:db8:1::1. + auto hosts = cfg.getAll6(IOAddress("2001:db8:1::1")); + EXPECT_EQ(5, hosts.size()); + for (unsigned i = 0; i < 5; ++i) { + EXPECT_EQ(1 + 5 * i, hosts[i]->getIPv6SubnetID()); + IPv6ResrvRange reservations = + hosts[i]->getIPv6Reservations(IPv6Resrv::TYPE_NA); + ASSERT_EQ(1, std::distance(reservations.first, reservations.second)); + EXPECT_EQ(IOAddress("2001:db8:1::1"), + reservations.first->second.getPrefix()); + } +} + // This test checks that hosts in the same subnet can be retrieved from // the host configuration by pages. TEST_F(CfgHostsTest, getPage4) { -- 2.47.2