From: Marcin Siodelski Date: Mon, 22 Sep 2014 11:14:25 +0000 (+0200) Subject: [3589] Add options confiuration object to the SrvConfig object. X-Git-Tag: trac3162a_base~4^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7853fe1739b601ef36ef253cbe903fd1a1b8fbdb;p=thirdparty%2Fkea.git [3589] Add options confiuration object to the SrvConfig object. --- diff --git a/src/lib/dhcpsrv/cfg_option.h b/src/lib/dhcpsrv/cfg_option.h index e6fb0c54f6..948afc5a78 100644 --- a/src/lib/dhcpsrv/cfg_option.h +++ b/src/lib/dhcpsrv/cfg_option.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -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 CfgOptionPtr; + +/// @brief Const pointer. +typedef boost::shared_ptr ConstCfgOptionPtr; + +//@} + } } diff --git a/src/lib/dhcpsrv/option_space_container.h b/src/lib/dhcpsrv/option_space_container.h index 7bca7d4801..26199b7e34 100644 --- a/src/lib/dhcpsrv/option_space_container.h +++ b/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(); diff --git a/src/lib/dhcpsrv/srv_config.cc b/src/lib/dhcpsrv/srv_config.cc index 6e722823a5..f82075ae85 100644 --- a/src/lib/dhcpsrv/srv_config.cc +++ b/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_)); } } diff --git a/src/lib/dhcpsrv/srv_config.h b/src/lib/dhcpsrv/srv_config.h index a566d2dd26..0cd7b37e2f 100644 --- a/src/lib/dhcpsrv/srv_config.h +++ b/src/lib/dhcpsrv/srv_config.h @@ -16,6 +16,7 @@ #define DHCPSRV_CONFIG_H #include +#include #include #include #include @@ -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. diff --git a/src/lib/dhcpsrv/tests/srv_config_unittest.cc b/src/lib/dhcpsrv/tests/srv_config_unittest.cc index 835246047a..aeb791898c 100644 --- a/src/lib/dhcpsrv/tests/srv_config_unittest.cc +++ b/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