subnet->addPool6(*it);
}
+ const Subnet::OptionContainer& options = subnet->getOptions();
+ const Subnet::OptionContainerTypeIndex& idx = options.get<1>();
+
// Add subnet specific options.
BOOST_FOREACH(OptionPtr option, options_) {
- Subnet::OptionContainerTypeRange range =
- subnet->getOptions(option->getType());
+ Subnet::OptionContainerTypeRange range = idx.equal_range(option->getType());
if (std::distance(range.first, range.second) > 0) {
LOG_WARN(dhcp6_logger, DHCP6_CONFIG_OPTION_DUPLICATE)
.arg(option->getType()).arg(addr.toText());
BOOST_FOREACH(OptionPtr option, option_defaults) {
// Get all options specified locally in the subnet and having
// code equal to global option's code.
- Subnet::OptionContainerTypeRange range =
- subnet->getOptions(option->getType());
+ Subnet::OptionContainerTypeRange range = idx.equal_range(option->getType());
// @todo: In the future we will be searching for options using either
// option code or namespace. Currently we have only the option
// code available so if there is at least one option found with the
options_.clear();
}
-Subnet::OptionContainerTypeRange
-Subnet::getOptions(uint16_t type) {
- OptionContainer options = getOptions();
- // Get the search index #1. This index allows to search
- // for options using option type.
- OptionContainerTypeIndex& idx = options.get<1>();
- OptionContainerTypeRange range = idx.equal_range(type);
- // We don't perform any check if this range is empty. It is
- // up to the calling function to check it with std::distance().
- return (range);
-}
-
Subnet4::Subnet4(const isc::asiolink::IOAddress& prefix, uint8_t length,
const Triplet<uint32_t>& t1,
const Triplet<uint32_t>& t2,
EXPECT_EQ(0, options.size());
}
-TEST(Subnet6Test, getOptionsByType) {
- Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:1::"), 56, 1, 2, 3, 4));
- Subnet::OptionContainerTypeRange range;
-
- // First check that subnet does not contain any options with
- // option codes 100 and 101.
- ASSERT_NO_THROW(range = subnet->getOptions(100));
- EXPECT_EQ(0, std::distance(range.first, range.second));
- ASSERT_NO_THROW(range = subnet->getOptions(101));
- EXPECT_EQ(0, std::distance(range.first, range.second));
-
- // Add 3 options with option code 100.
- for (int i = 0; i < 3; ++i) {
- OptionPtr option(new Option(Option::V6, 100, OptionBuffer(10, 0xFF)));
- ASSERT_NO_THROW(subnet->addOption(option));
- }
- // Add 7 options with option code 101.
- for (int i = 0; i < 7; ++i) {
- OptionPtr option(new Option(Option::V6, 101, OptionBuffer(10, 0xFF)));
- ASSERT_NO_THROW(subnet->addOption(option));
- }
- // Get options by their type and check that 3 options with the
- // code 100 and 7 options with the code 101 are returned.
- ASSERT_NO_THROW(range = subnet->getOptions(100));
- EXPECT_EQ(3, std::distance(range.first, range.second));
- ASSERT_NO_THROW(range = subnet->getOptions(101));
- EXPECT_EQ(7, std::distance(range.first, range.second));
- // Delete all options.
- EXPECT_NO_THROW(subnet->delOptions());
- // Verify that after deletion getOptions will not return
- // any options.
- ASSERT_NO_THROW(range = subnet->getOptions(100));
- EXPECT_EQ(0, std::distance(range.first, range.second));
- ASSERT_NO_THROW(range = subnet->getOptions(101));
- EXPECT_EQ(0, std::distance(range.first, range.second));
-}
-
TEST(Subnet6Test, addInvalidOption) {
// Create as subnet to add options to it.
Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:1::"), 56, 1, 2, 3, 4));