#include <dhcp/libdhcp++.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/dhcpsrv_log.h>
-#include <stats/stats_mgr.h>
#include <sstream>
#include <string>
using namespace isc::asiolink;
using namespace isc::util;
-using namespace isc::stats;
namespace isc {
namespace dhcp {
return (cfg_mgr);
}
-void
-CfgMgr::addOptionSpace4(const OptionSpacePtr& space) {
- if (!space) {
- isc_throw(InvalidOptionSpace,
- "provided option space object is NULL.");
- }
- OptionSpaceCollection::iterator it = spaces4_.find(space->getName());
- if (it != spaces4_.end()) {
- isc_throw(InvalidOptionSpace, "option space " << space->getName()
- << " already added.");
- }
- spaces4_.insert(make_pair(space->getName(), space));
-}
-
-void
-CfgMgr::addOptionSpace6(const OptionSpacePtr& space) {
- if (!space) {
- isc_throw(InvalidOptionSpace,
- "provided option space object is NULL.");
- }
- OptionSpaceCollection::iterator it = spaces6_.find(space->getName());
- if (it != spaces6_.end()) {
- isc_throw(InvalidOptionSpace, "option space " << space->getName()
- << " already added.");
- }
- spaces6_.insert(make_pair(space->getName(), space));
-}
-
-
std::string CfgMgr::getDataDir() const {
return (datadir_);
}
/// and a valid lifetime of 1000s. The second subnet has preferred lifetime
/// of 500s, but valid lifetime of 2000s.
///
-/// Parameter inheritance is likely to be implemented in configuration handling
-/// routines, so there is no storage capability in a global scope for
-/// subnet-specific parameters.
-///
+/// Parameter inheritance is implemented in dedicated classes. See
+/// @ref isc::dhcp::SimpleParser4::deriveParameters and
+/// @ref isc::dhcp::SimpleParser6::deriveParameters.
class CfgMgr : public boost::noncopyable {
public:
/// accessing it.
static CfgMgr& instance();
- /// @brief Adds new DHCPv4 option space to the collection.
- ///
- /// @param space option space to be added.
- ///
- /// @throw isc::dhcp::InvalidOptionSpace invalid option space
- /// has been specified.
- void addOptionSpace4(const OptionSpacePtr& space);
-
- /// @brief Adds new DHCPv6 option space to the collection.
- ///
- /// @param space option space to be added.
- ///
- /// @throw isc::dhcp::InvalidOptionSpace invalid option space
- /// has been specified.
- void addOptionSpace6(const OptionSpacePtr& space);
-
- /// @brief Return option spaces for DHCPv4.
- ///
- /// @return A collection of option spaces.
- const OptionSpaceCollection& getOptionSpaces4() const {
- return (spaces4_);
- }
-
- /// @brief Return option spaces for DHCPv6.
- ///
- /// @return A collection of option spaces.
- const OptionSpaceCollection& getOptionSpaces6() const {
- return (spaces6_);
- }
-
/// @brief returns path do the data directory
///
/// This method returns a path to writable directory that DHCP servers
/// default current configuration.
void ensureCurrentAllocated();
- /// @brief Container for defined DHCPv6 option spaces.
- OptionSpaceCollection spaces6_;
-
- /// @brief Container for defined DHCPv4 option spaces.
- OptionSpaceCollection spaces4_;
-
/// @brief directory where data files (e.g. server-id) are stored
std::string datadir_;
EXPECT_TRUE(configuration->getLoggingInfo().empty());
}
-// This test verifies that new DHCPv4 option spaces can be added to
-// the configuration manager and that duplicated option space is
-// rejected.
-TEST_F(CfgMgrTest, optionSpace4) {
- CfgMgr& cfg_mgr = CfgMgr::instance();
-
- // Create some option spaces.
- OptionSpacePtr space1(new OptionSpace("isc", false));
- OptionSpacePtr space2(new OptionSpace("xyz", true));
-
- // Add option spaces with different names and expect they
- // are accepted.
- ASSERT_NO_THROW(cfg_mgr.addOptionSpace4(space1));
- ASSERT_NO_THROW(cfg_mgr.addOptionSpace4(space2));
-
- // Validate that the option spaces have been added correctly.
- const OptionSpaceCollection& spaces = cfg_mgr.getOptionSpaces4();
-
- ASSERT_EQ(2, spaces.size());
- EXPECT_FALSE(spaces.find("isc") == spaces.end());
- EXPECT_FALSE(spaces.find("xyz") == spaces.end());
-
- // Create another option space with the name that duplicates
- // the existing option space.
- OptionSpacePtr space3(new OptionSpace("isc", true));
- // Expect that the duplicate option space is rejected.
- ASSERT_THROW(
- cfg_mgr.addOptionSpace4(space3), isc::dhcp::InvalidOptionSpace
- );
-
- /// @todo decode if a duplicate vendor space is allowed.
-}
-
-// This test verifies that new DHCPv6 option spaces can be added to
-// the configuration manager and that duplicated option space is
-// rejected.
-TEST_F(CfgMgrTest, optionSpace6) {
- CfgMgr& cfg_mgr = CfgMgr::instance();
-
- // Create some option spaces.
- OptionSpacePtr space1(new OptionSpace("isc", false));
- OptionSpacePtr space2(new OptionSpace("xyz", true));
-
- // Add option spaces with different names and expect they
- // are accepted.
- ASSERT_NO_THROW(cfg_mgr.addOptionSpace6(space1));
- ASSERT_NO_THROW(cfg_mgr.addOptionSpace6(space2));
-
- // Validate that the option spaces have been added correctly.
- const OptionSpaceCollection& spaces = cfg_mgr.getOptionSpaces6();
-
- ASSERT_EQ(2, spaces.size());
- EXPECT_FALSE(spaces.find("isc") == spaces.end());
- EXPECT_FALSE(spaces.find("xyz") == spaces.end());
-
- // Create another option space with the name that duplicates
- // the existing option space.
- OptionSpacePtr space3(new OptionSpace("isc", true));
- // Expect that the duplicate option space is rejected.
- ASSERT_THROW(
- cfg_mgr.addOptionSpace6(space3), isc::dhcp::InvalidOptionSpace
- );
-
- /// @todo decide if a duplicate vendor space is allowed.
-}
-
// This test checks the D2ClientMgr wrapper methods.
TEST_F(CfgMgrTest, d2ClientConfig) {
// After CfgMgr construction, D2ClientMgr member should be initialized