return (options->second);
}
+Subnet::OptionDescriptor
+Subnet::getOptionSingle(const std::string& option_space,
+ const uint16_t option_code) {
+ const OptionContainer& options = getOptions(option_space);
+ if (options.empty()) {
+ return (OptionDescriptor(false));
+ }
+ const OptionContainerTypeIndex& idx = options.get<1>();
+ const OptionContainerTypeRange& range = idx.equal_range(option_code);
+ if (std::distance(range.first, range.second) == 0) {
+ return (OptionDescriptor(false));
+ }
+
+ return (*range.first);
+}
+
std::string Subnet::toText() const {
std::stringstream tmp;
tmp << prefix_.toText() << "/" << static_cast<unsigned int>(prefix_len_);
return (t2_);
}
- /// @brief Return a collection of options.
+ /// @brief Return a collection of option descriptors.
///
/// @param option_space name of the option space
///
/// returned it still exists.
const OptionContainer& getOptions(const std::string& option_space) const;
+ /// @brief Return single option descriptor.
+ ///
+ /// @param option_space name of the option space.
+ ///
+ /// @return option descriptor found for the specified option space
+ /// and option code.
+ OptionDescriptor getOptionSingle(const std::string& option_space,
+ const uint16_t option_code);
+
/// @brief returns the last address that was tried from this pool
///
/// This method returns the last address that was attempted to be allocated
EXPECT_EQ(0, options.size());
}
+TEST(Subnet6Test, getOptionSingle) {
+ Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8::"), 56, 1, 2, 3, 4));
+
+ // Add 10 options to a "dhcp6" option space in the subnet.
+ for (uint16_t code = 100; code < 110; ++code) {
+ OptionPtr option(new Option(Option::V6, code, OptionBuffer(10, 0xFF)));
+ ASSERT_NO_THROW(subnet->addOption(option, false, "dhcp6"));
+ }
+
+ // Check that we can get each added option descriptor using
+ // individually.
+ for (uint16_t code = 100; code < 110; ++code) {
+ std::ostringstream stream;
+ // First, try the invalid option space name.
+ Subnet::OptionDescriptor desc = subnet->getOptionSingle("isc", code);
+ // Returned descriptor should contain NULL option ptr.
+ EXPECT_FALSE(desc.option);
+ // Now, try the valid option space.
+ desc = subnet->getOptionSingle("dhcp6", code);
+ // Test that the option code matches the expected code.
+ ASSERT_TRUE(desc.option);
+ EXPECT_EQ(code, desc.option->getType());
+ }
+}
+
// This test verifies that inRange() and inPool() methods work properly.
TEST(Subnet6Test, inRangeinPool) {
Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8::"), 32, 1, 2, 3, 4));