return (Subnet4Ptr());
}
+Subnet4Ptr
+CfgSubnets4::getSubnet(const SubnetID id) const {
+
+ /// @todo: Once this code is migrated to multi-index container, use
+ /// an index rather than full scan.
+ for (auto subnet = subnets_.begin(); subnet != subnets_.end(); ++subnet) {
+ if ((*subnet)->getID() == id) {
+ return (*subnet);
+ }
+ }
+ return (Subnet4Ptr());
+}
+
Subnet4Ptr
CfgSubnets4::selectSubnet(const IOAddress& address,
const ClientClasses& client_classes) const {
/// or they are insufficient to select a subnet.
Subnet4Ptr selectSubnet(const SubnetSelector& selector) const;
+ /// @brief Returns subnet with specified subnet-id value
+ ///
+ /// Warning: this method uses full scan. Its use is not recommeded for
+ /// packet processing.
+ ///
+ /// @return Subnet (or NULL)
+ Subnet4Ptr getSubnet(const SubnetID id) const;
+
/// @brief Returns a pointer to a subnet if provided address is in its range.
///
/// This method returns a pointer to the subnet if the address passed in
return (Subnet6Ptr());
}
+Subnet6Ptr
+CfgSubnets6::getSubnet(const SubnetID id) const {
+
+ /// @todo: Once this code is migrated to multi-index container, use
+ /// an index rather than full scan.
+ for (auto subnet = subnets_.begin(); subnet != subnets_.end(); ++subnet) {
+ if ((*subnet)->getID() == id) {
+ return (*subnet);
+ }
+ }
+ return (Subnet6Ptr());
+}
+
+
bool
CfgSubnets6::isDuplicate(const Subnet6& subnet) const {
for (Subnet6Collection::const_iterator subnet_it = subnets_.begin();
/// @return Pointer to the selected subnet or NULL if no subnet found.
Subnet6Ptr selectSubnet(const SubnetSelector& selector) const;
+ /// @brief Returns subnet with specified subnet-id value
+ ///
+ /// Warning: this method uses full scan. Its use is not recommeded for
+ /// packet processing.
+ ///
+ /// @return Subnet (or NULL)
+ Subnet6Ptr getSubnet(const SubnetID id) const;
+
/// @brief Selects the subnet using a specified address.
///
/// This method searches for the subnet using the specified address. If
subnet->addPool(pool1);
subnet->addPool(pool2);
cfg.add(subnet);
-
+
// Unparse
std::string expected = "[\n"
"{\n"
runToElementTest<CfgSubnets4>(expected, cfg);
}
+// This test verifies that it is possible to retrieve a subnet using subnet-id.
+TEST(CfgSubnets4Test, getSubnet) {
+ CfgSubnets4 cfg;
+
+ // Create 3 subnets.
+ Subnet4Ptr subnet1(new Subnet4(IOAddress("192.0.2.0"), 26, 1, 2, 3, 100));
+ Subnet4Ptr subnet2(new Subnet4(IOAddress("192.0.2.64"), 26, 1, 2, 3, 200));
+ Subnet4Ptr subnet3(new Subnet4(IOAddress("192.0.2.128"), 26, 1, 2, 3, 300));
+
+ // Add one subnet and make sure it is returned.
+ cfg.add(subnet1);
+ cfg.add(subnet2);
+ cfg.add(subnet3);
+
+ EXPECT_EQ(subnet1, cfg.getSubnet(100));
+ EXPECT_EQ(subnet2, cfg.getSubnet(200));
+ EXPECT_EQ(subnet3, cfg.getSubnet(300));
+ EXPECT_EQ(Subnet4Ptr(), cfg.getSubnet(400)); // no such subnet
+}
+
} // end of anonymous namespace
-// Copyright (C) 2014-2015,2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
subnet->addPool(pool1);
subnet->addPool(pool2);
cfg.add(subnet);
-
+
// Unparse
std::string expected = "[\n"
"{\n"
subnet->addPool(pdpool1);
subnet->addPool(pdpool2);
cfg.add(subnet);
-
+
// Unparse
std::string expected = "[\n"
"{\n"
runToElementTest<CfgSubnets6>(expected, cfg);
}
+// This test verifies that it is possible to retrieve a subnet using subnet-id.
+TEST(CfgSubnets6Test, getSubnet) {
+ CfgSubnets6 cfg;
+
+ // Let's configure 3 subnets
+ Subnet6Ptr subnet1(new Subnet6(IOAddress("2001:db8:1::"), 48, 1, 2, 3, 4, 100));
+ Subnet6Ptr subnet2(new Subnet6(IOAddress("2001:db8:2::"), 48, 1, 2, 3, 4, 200));
+ Subnet6Ptr subnet3(new Subnet6(IOAddress("2001:db8:3::"), 48, 1, 2, 3, 4, 300));
+ cfg.add(subnet1);
+ cfg.add(subnet2);
+ cfg.add(subnet3);
+
+ EXPECT_EQ(subnet1, cfg.getSubnet(100));
+ EXPECT_EQ(subnet2, cfg.getSubnet(200));
+ EXPECT_EQ(subnet3, cfg.getSubnet(300));
+ EXPECT_EQ(Subnet6Ptr(), cfg.getSubnet(400)); // no such subnet
+}
+
} // end of anonymous namespace