mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 13:37:55 +00:00
[#3149] Simplified getLinks
This commit is contained in:
@@ -498,18 +498,12 @@ CfgSubnets4::selectSubnet(const IOAddress& address,
|
||||
}
|
||||
|
||||
SubnetIDSet
|
||||
CfgSubnets4::getLinks(const IOAddress& link_addr, uint8_t& link_len) const {
|
||||
CfgSubnets4::getLinks(const IOAddress& link_addr) const {
|
||||
SubnetIDSet links;
|
||||
bool link_len_set = false;
|
||||
for (auto const& subnet : subnets_) {
|
||||
if (!subnet->inRange(link_addr)) {
|
||||
continue;
|
||||
}
|
||||
uint8_t plen = subnet->get().second;
|
||||
if (!link_len_set || (plen < link_len)) {
|
||||
link_len_set = true;
|
||||
link_len = plen;
|
||||
}
|
||||
links.insert(subnet->getID());
|
||||
}
|
||||
return (links);
|
||||
|
@@ -301,14 +301,13 @@ public:
|
||||
/// @brief Convert a link address into a link set.
|
||||
///
|
||||
/// Given a link address this returns the ordered list aka set of id
|
||||
/// of subnets the address belongs to. It also sets the minimum link
|
||||
/// length when there is at least one subnet.
|
||||
/// of subnets the address belongs to.
|
||||
///
|
||||
/// @todo: extend to consider whether a shared network is a link.
|
||||
///
|
||||
/// @param link_addr The link address.
|
||||
/// @param[out] link_len The minimum link length.
|
||||
/// @return The set of subnet ids the link address belongs to.
|
||||
SubnetIDSet getLinks(const asiolink::IOAddress& link_addr,
|
||||
uint8_t& link_len) const;
|
||||
SubnetIDSet getLinks(const asiolink::IOAddress& link_addr) const;
|
||||
|
||||
/// @brief Updates statistics.
|
||||
///
|
||||
|
@@ -387,18 +387,12 @@ CfgSubnets6::getSubnet(const SubnetID id) const {
|
||||
}
|
||||
|
||||
SubnetIDSet
|
||||
CfgSubnets6::getLinks(const IOAddress& link_addr, uint8_t& link_len) const {
|
||||
CfgSubnets6::getLinks(const IOAddress& link_addr) const {
|
||||
SubnetIDSet links;
|
||||
bool link_len_set = false;
|
||||
for (auto const& subnet : subnets_) {
|
||||
if (!subnet->inRange(link_addr)) {
|
||||
continue;
|
||||
}
|
||||
uint8_t plen = subnet->get().second;
|
||||
if (!link_len_set || (plen < link_len)) {
|
||||
link_len_set = true;
|
||||
link_len = plen;
|
||||
}
|
||||
links.insert(subnet->getID());
|
||||
}
|
||||
return (links);
|
||||
|
@@ -251,14 +251,13 @@ public:
|
||||
/// @brief Convert a link address into a link set.
|
||||
///
|
||||
/// Given a link address this returns the ordered list aka set of id
|
||||
/// of subnets the address belongs to. It also sets the minimum link
|
||||
/// length when there is at least one subnet.
|
||||
/// of subnets the address belongs to.
|
||||
///
|
||||
/// @todo: extend to consider whether a shared network is a link.
|
||||
///
|
||||
/// @param link_addr The link address.
|
||||
/// @param[out] link_len The minimum link length.
|
||||
/// @return The set of subnet ids the link address belongs to.
|
||||
SubnetIDSet getLinks(const asiolink::IOAddress& link_addr,
|
||||
uint8_t& link_len) const;
|
||||
SubnetIDSet getLinks(const asiolink::IOAddress& link_addr) const;
|
||||
|
||||
/// @brief Updates statistics.
|
||||
///
|
||||
|
@@ -2334,32 +2334,24 @@ TEST(CfgSubnets4Test, getLinks) {
|
||||
|
||||
// No 192.0.4.0 subnet.
|
||||
SubnetIDSet links;
|
||||
uint8_t link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.4.0"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.4.0")));
|
||||
EXPECT_TRUE(links.empty());
|
||||
EXPECT_EQ(111, link_len);
|
||||
|
||||
// A 192.0.2.0/26 subnet.
|
||||
links.clear();
|
||||
link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.0"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.0")));
|
||||
SubnetIDSet expected = { 2 };
|
||||
EXPECT_EQ(expected, links);
|
||||
EXPECT_EQ(26, link_len);
|
||||
|
||||
// Check that any address in the subnet works.
|
||||
links.clear();
|
||||
link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.23"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.23")));
|
||||
EXPECT_EQ(expected, links);
|
||||
EXPECT_EQ(26, link_len);
|
||||
|
||||
// Check that an address outside the subnet does not work.
|
||||
links.clear();
|
||||
link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.123"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.123")));
|
||||
EXPECT_TRUE(links.empty());
|
||||
EXPECT_EQ(111, link_len);
|
||||
|
||||
// Add a second 192.0.2.0/26 subnet.
|
||||
Subnet4Ptr subnet10(new Subnet4(IOAddress("192.0.2.10"),
|
||||
@@ -2368,40 +2360,32 @@ TEST(CfgSubnets4Test, getLinks) {
|
||||
|
||||
// Now we should get 2 subnets.
|
||||
links.clear();
|
||||
link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.0"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.0")));
|
||||
expected = { 2, 10 };
|
||||
EXPECT_EQ(expected, links);
|
||||
EXPECT_EQ(26, link_len);
|
||||
|
||||
// Add a larger subnet.
|
||||
Subnet4Ptr subnet20(new Subnet4(IOAddress("192.0.2.20"),
|
||||
24, 1, 2, 3, SubnetID(20)));
|
||||
ASSERT_NO_THROW(cfg.add(subnet20));
|
||||
|
||||
// Now we should get 3 subnets and a smaller prefix length.
|
||||
// Now we should get 3 subnets.
|
||||
links.clear();
|
||||
link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.0"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.0")));
|
||||
expected = { 2, 10, 20 };
|
||||
EXPECT_EQ(expected, links);
|
||||
EXPECT_EQ(24, link_len);
|
||||
|
||||
// But only the larger subnet if the address is only in it.
|
||||
links.clear();
|
||||
link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.123"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.123")));
|
||||
expected = { 20 };
|
||||
EXPECT_EQ(expected, links);
|
||||
EXPECT_EQ(24, link_len);
|
||||
|
||||
// Even it is not used for Bulk Leasequery, it works for 0.0.0.0 too.
|
||||
links.clear();
|
||||
link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("0.0.0.0"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("0.0.0.0")));
|
||||
expected = { 111 };
|
||||
EXPECT_EQ(expected, links);
|
||||
EXPECT_EQ(24, link_len);
|
||||
}
|
||||
|
||||
// This test verifies that for each subnet in the configuration it calls
|
||||
|
@@ -2361,33 +2361,24 @@ TEST(CfgSubnets6Test, getLinks) {
|
||||
|
||||
// No 2001:db8:4:: subnet.
|
||||
SubnetIDSet links;
|
||||
uint8_t link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:4::"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:4::")));
|
||||
EXPECT_TRUE(links.empty());
|
||||
EXPECT_EQ(111, link_len);
|
||||
|
||||
// A 2001:db8:2::/64 subnet.
|
||||
links.clear();
|
||||
link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::")));
|
||||
SubnetIDSet expected = { 2 };
|
||||
EXPECT_EQ(expected, links);
|
||||
EXPECT_EQ(64, link_len);
|
||||
|
||||
// Check that any address in the subnet works.
|
||||
links.clear();
|
||||
link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::1234:5678:9abc:def0"),
|
||||
link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::1234:5678:9abc:def0")));
|
||||
EXPECT_EQ(expected, links);
|
||||
EXPECT_EQ(64, link_len);
|
||||
|
||||
// Check that an address outside the subnet does not work.
|
||||
links.clear();
|
||||
link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2:1::"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2:1::")));
|
||||
EXPECT_TRUE(links.empty());
|
||||
EXPECT_EQ(111, link_len);
|
||||
|
||||
// Add a second 2001:db8:2::/64 subnet.
|
||||
Subnet6Ptr subnet10(new Subnet6(IOAddress("2001:db8:2::10"), 64, 1, 2, 3,
|
||||
@@ -2396,40 +2387,32 @@ TEST(CfgSubnets6Test, getLinks) {
|
||||
|
||||
// Now we should get 2 subnets.
|
||||
links.clear();
|
||||
link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::")));
|
||||
expected = { 2, 10 };
|
||||
EXPECT_EQ(expected, links);
|
||||
EXPECT_EQ(64, link_len);
|
||||
|
||||
// Add a larger subnet.
|
||||
Subnet6Ptr subnet20(new Subnet6(IOAddress("2001:db8:2::20"), 56, 1, 2, 3,
|
||||
4, SubnetID(20)));
|
||||
ASSERT_NO_THROW(cfg.add(subnet20));
|
||||
|
||||
// Now we should get 3 subnets and a smaller prefix length.
|
||||
// Now we should get 3 subnets.
|
||||
links.clear();
|
||||
link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::")));
|
||||
expected = { 2, 10, 20 };
|
||||
EXPECT_EQ(expected, links);
|
||||
EXPECT_EQ(56, link_len);
|
||||
|
||||
// But only the larger subnet if the address is only in it.
|
||||
links.clear();
|
||||
link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2:1::"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2:1::")));
|
||||
expected = { 20 };
|
||||
EXPECT_EQ(expected, links);
|
||||
EXPECT_EQ(56, link_len);
|
||||
|
||||
// Even it is not used for Bulk Leasequery, it works for :: too.
|
||||
links.clear();
|
||||
link_len = 111;
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("::"), link_len));
|
||||
EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("::")));
|
||||
expected = { 111 };
|
||||
EXPECT_EQ(expected, links);
|
||||
EXPECT_EQ(48, link_len);
|
||||
}
|
||||
|
||||
// This test verifies that for each subnet in the configuration it calls
|
||||
|
Reference in New Issue
Block a user