Browse Source

[3589] Add options confiuration object to the SrvConfig object.

Marcin Siodelski 10 years ago
parent
commit
7853fe1739

+ 11 - 1
src/lib/dhcpsrv/cfg_option.h

@@ -23,6 +23,7 @@
 #include <boost/multi_index/sequenced_index.hpp>
 #include <boost/multi_index/mem_fun.hpp>
 #include <boost/multi_index/member.hpp>
+#include <boost/shared_ptr.hpp>
 #include <stdint.h>
 #include <string>
 
@@ -348,9 +349,18 @@ private:
                                  uint32_t> VendorOptionSpaceCollection;
     /// @brief Container holding options grouped by vendor id.
     VendorOptionSpaceCollection vendor_options_;
-
 };
 
+/// @name Pointers to the @c CfgOption objects.
+//@{
+/// @brief Non-const pointer.
+typedef boost::shared_ptr<CfgOption> CfgOptionPtr;
+
+/// @brief Const pointer.
+typedef boost::shared_ptr<const CfgOption> ConstCfgOptionPtr;
+
+//@}
+
 }
 }
 

+ 8 - 5
src/lib/dhcpsrv/option_space_container.h

@@ -105,18 +105,21 @@ public:
 
             typename OptionSpaceMap::const_iterator other_it =
                 other.option_space_map_.find(it->first);
-            if (other_it == option_space_map_.end()) {
+            if (other_it == other.option_space_map_.end()) {
                 return (false);
             }
 
+            // If containers have different sizes it is an indication that
+            // they are unequal.
+            if (it->second->size() != other_it->second->size()) {
+                return (false);
+            }
+
+            // If they have the same sizes, we have to compare each element.
             for (typename ContainerType::const_iterator items_it =
                      it->second->begin();
                  items_it != it->second->end(); ++items_it) {
 
-                if (it->second->size() != other_it->second->size()) {
-                    return (false);
-                }
-
                 bool match_found = false;
                 for (typename ContainerType::const_iterator other_items_it =
                          other_it->second->begin();

+ 8 - 4
src/lib/dhcpsrv/srv_config.cc

@@ -25,11 +25,13 @@ namespace isc {
 namespace dhcp {
 
 SrvConfig::SrvConfig()
-    : sequence_(0), cfg_option_def_(new CfgOptionDef()) {
+    : sequence_(0), cfg_option_def_(new CfgOptionDef()),
+      cfg_option_(new CfgOption()) {
 }
 
-SrvConfig::SrvConfig(uint32_t sequence)
-    : sequence_(sequence), cfg_option_def_(new CfgOptionDef()) {
+SrvConfig::SrvConfig(const uint32_t sequence)
+    : sequence_(sequence), cfg_option_def_(new CfgOptionDef()),
+      cfg_option_(new CfgOption()) {
 }
 
 std::string
@@ -90,6 +92,7 @@ SrvConfig::copy(SrvConfig& new_config) const {
     new_config.setCfgIface(cfg_iface_);
     // Replace option definitions.
     cfg_option_def_->copyTo(*new_config.cfg_option_def_);
+    cfg_option_->copy(*new_config.cfg_option_);
 }
 
 void
@@ -132,7 +135,8 @@ SrvConfig::equals(const SrvConfig& other) const {
     }
     // Logging information is equal between objects, so check other values.
     return ((cfg_iface_ == other.cfg_iface_) &&
-            (*cfg_option_def_ == *other.cfg_option_def_));
+            (*cfg_option_def_ == *other.cfg_option_def_) &&
+            (*cfg_option_ == *other.cfg_option_));
 }
 
 }

+ 28 - 1
src/lib/dhcpsrv/srv_config.h

@@ -16,6 +16,7 @@
 #define DHCPSRV_CONFIG_H
 
 #include <dhcpsrv/cfg_iface.h>
+#include <dhcpsrv/cfg_option.h>
 #include <dhcpsrv/cfg_option_def.h>
 #include <dhcpsrv/logging_info.h>
 #include <boost/shared_ptr.hpp>
@@ -66,7 +67,7 @@ public:
     /// @brief Constructor.
     ///
     /// Sets arbitrary configuration sequence number.
-    SrvConfig(uint32_t sequence);
+    SrvConfig(const uint32_t sequence);
 
     /// @brief Returns summary of the configuration in the textual format.
     ///
@@ -163,6 +164,26 @@ public:
         return (cfg_option_def_);
     }
 
+    /// @brief Returns pointer to the non-const object holding options.
+    ///
+    /// This method returns a pointer to the object which holds instances
+    /// of the options to be returned to the clients belonging to any subnet.
+    ///
+    /// @return Pointer to the object holding options.
+    CfgOptionPtr getCfgOption() {
+        return (cfg_option_);
+    }
+
+    /// @brief Returns pointer to the const object holding options.
+    ///
+    /// This method returns a pointer to the object which holds instances
+    /// of the options to be returned to the clients belonging to any subnet.
+    ///
+    /// @return Pointer to the object holding options.
+    const ConstCfgOptionPtr getCfgOption() const {
+        return (cfg_option_);
+    }
+
     //@}
 
     /// @brief Copies the currnet configuration to a new configuration.
@@ -250,6 +271,12 @@ private:
     /// by option space name.
     CfgOptionDefPtr cfg_option_def_;
 
+    /// @brief Pointer to options (data) configuration.
+    ///
+    /// This object holds the instances of the options to be sent to clients
+    /// connected to any subnet.
+    CfgOptionPtr cfg_option_;
+
 };
 
 /// @name Pointers to the @c SrvConfig object.

+ 20 - 2
src/lib/dhcpsrv/tests/srv_config_unittest.cc

@@ -281,8 +281,14 @@ TEST_F(SrvConfigTest, copy) {
 
     conf1.addLoggingInfo(info);
     conf1.setCfgIface(cfg_iface);
-    conf1.getCfgOptionDef()->add(OptionDefinitionPtr(new OptionDefinition("option-foo", 5,
-                                                                          "string")), "isc");
+
+    // Add option definition.
+    OptionDefinitionPtr def(new OptionDefinition("option-foo", 5, "string"));
+    conf1.getCfgOptionDef()->add(def, "isc");
+
+    // Add an option.
+    OptionPtr option(new Option(Option::V6, 1000, OptionBuffer(10, 0xFF)));
+    conf1.getCfgOption()->add(option, true, "dhcp6");
 
     // Make sure both configurations are different.
     ASSERT_TRUE(conf1 != conf2);
@@ -354,6 +360,18 @@ TEST_F(SrvConfigTest, equality) {
                                                      "uint16_t")), "isc");
     EXPECT_TRUE(conf1 == conf2);
     EXPECT_FALSE(conf1 != conf2);
+
+    // Differ by option data.
+    OptionPtr option(new Option(Option::V6, 1000, OptionBuffer(1, 0xFF)));
+    conf1.getCfgOption()->add(option, false, "isc");
+
+    EXPECT_FALSE(conf1 == conf2);
+    EXPECT_TRUE(conf1 != conf2);
+
+    conf2.getCfgOption()->add(option, false, "isc");
+
+    EXPECT_TRUE(conf1 == conf2);
+    EXPECT_FALSE(conf1 != conf2);
 }
 
 } // end of anonymous namespace