]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2318] Removed function that searches for options using option code.
authorMarcin Siodelski <marcin@isc.org>
Tue, 30 Oct 2012 17:42:16 +0000 (18:42 +0100)
committerMarcin Siodelski <marcin@isc.org>
Tue, 30 Oct 2012 17:42:16 +0000 (18:42 +0100)
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.

src/bin/dhcp6/config_parser.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
src/lib/dhcp/subnet.cc
src/lib/dhcp/subnet.h
src/lib/dhcp/tests/subnet_unittest.cc

index 24764974fe685529c9837af1693d64f7df0afc5a..0fca770866f238dd10c855095870c44adcf41652 100644 (file)
@@ -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
index 576e81f06cbbc883ede526acfccce57952c1c23b..dafe314424e460016598c4739573e2d1ee928eec 100644 (file)
@@ -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));
     }
 }
index 61f70a75c98ba5400c54acadcaf9f1a5c2297b63..cb82a9f12f771339e3177904feea2a79523091dd 100644 (file)
@@ -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,
index c157e7aee5eb7f0666e6f03988d3ab0118edfccb..514f422099cd23a092e356c4e4753436e8eaf37a 100644 (file)
@@ -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
     //
index c1d8d76bb4a29efce8bb20bf15cc9e369079b65a..0e2e846141b3e9f06294b8a6044608976417e784 100644 (file)
@@ -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));