Browse Source

[2318] Removed function that searches for options using option code.

The index object used to get the range of searched options was local
to the function and when returned from it search results were destroyed
along with index (Mac, Solaris only). The alternative solution to
copy results to another container was not picked due to performance
considerations.
Marcin Siodelski 12 years ago
parent
commit
17749f1ef3

+ 5 - 4
src/bin/dhcp6/config_parser.cc

@@ -829,10 +829,12 @@ public:
             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());
@@ -847,8 +849,7 @@ public:
         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

+ 1 - 1
src/bin/dhcp6/tests/config_parser_unittest.cc

@@ -408,7 +408,7 @@ TEST_F(Dhcp6ParserTest, optionDataDefaults) {
 
     // Check that options with other option codes are not returned.
     for (uint16_t code = 102; code < 110; ++code) {
-        ASSERT_NO_THROW(range = subnet->getOptions(code));
+        range = idx.equal_range(code);
         EXPECT_EQ(0, std::distance(range.first, range.second));
     }
 }

+ 0 - 12
src/lib/dhcp/subnet.cc

@@ -52,18 +52,6 @@ Subnet::delOptions() {
     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,

+ 0 - 7
src/lib/dhcp/subnet.h

@@ -233,13 +233,6 @@ public:
         return (options_);
     }
 
-    /// @brief Return a collection of options of a specified type.
-    ///
-    /// @param type option type.
-    /// @return pair of iterators, first indicating begining of
-    /// options range, second indicating end of the range.
-    OptionContainerTypeRange getOptions(uint16_t type);
-
 protected:
     /// @brief protected constructor
     //

+ 0 - 37
src/lib/dhcp/tests/subnet_unittest.cc

@@ -285,43 +285,6 @@ TEST(Subnet6Test, addNonUniqueOptions) {
     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));