Commit 31a9ba39 authored by Marcin Siodelski's avatar Marcin Siodelski

[3588] Implemented CfgOptionDef class to represent user-defined option defs

parent 85ec71f6
......@@ -1806,8 +1806,8 @@ Dhcpv4Srv::unpackOptions(const OptionBuffer& buf,
// Get the list of stdandard option definitions.
option_defs = LibDHCP::getOptionDefs(Option::V4);
} else if (!option_space.empty()) {
OptionDefContainerPtr option_defs_ptr =
CfgMgr::instance().getOptionDefs(option_space);
OptionDefContainerPtr option_defs_ptr = CfgMgr::instance()
.getCurrentCfg()->getCfgOptionDef().getAll(option_space);
if (option_defs_ptr != NULL) {
option_defs = *option_defs_ptr;
}
......
......@@ -1231,7 +1231,8 @@ TEST_F(Dhcp4ParserTest, optionDefIpv4Address) {
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("isc", 100);
OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()
->getCfgOptionDef().get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
......@@ -1241,7 +1242,7 @@ TEST_F(Dhcp4ParserTest, optionDefIpv4Address) {
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
def = CfgMgr::instance().getOptionDef("isc", 100);
def = CfgMgr::instance().getCurrentCfg()->getCfgOptionDef().get("isc", 100);
ASSERT_TRUE(def);
// Verify that the option definition data is valid.
......@@ -1272,7 +1273,8 @@ TEST_F(Dhcp4ParserTest, optionDefRecord) {
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("isc", 100);
OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
......@@ -1282,7 +1284,7 @@ TEST_F(Dhcp4ParserTest, optionDefRecord) {
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
def = CfgMgr::instance().getOptionDef("isc", 100);
def = CfgMgr::instance().getCurrentCfg()->getCfgOptionDef().get("isc", 100);
ASSERT_TRUE(def);
// Check the option data.
......@@ -1330,8 +1332,10 @@ TEST_F(Dhcp4ParserTest, optionDefMultiple) {
ElementPtr json = Element::fromJSON(config);
// Make sure that the option definitions do not exist yet.
ASSERT_FALSE(CfgMgr::instance().getOptionDef("isc", 100));
ASSERT_FALSE(CfgMgr::instance().getOptionDef("isc", 101));
ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100));
ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 101));
// Use the configuration string to create new option definitions.
ConstElementPtr status;
......@@ -1340,7 +1344,8 @@ TEST_F(Dhcp4ParserTest, optionDefMultiple) {
checkResult(status, 0);
// Check the first definition we have created.
OptionDefinitionPtr def1 = CfgMgr::instance().getOptionDef("isc", 100);
OptionDefinitionPtr def1 = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100);
ASSERT_TRUE(def1);
// Check the option data.
......@@ -1351,7 +1356,8 @@ TEST_F(Dhcp4ParserTest, optionDefMultiple) {
EXPECT_TRUE(def1->getEncapsulatedSpace().empty());
// Check the second option definition we have created.
OptionDefinitionPtr def2 = CfgMgr::instance().getOptionDef("isc", 101);
OptionDefinitionPtr def2 = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 101);
ASSERT_TRUE(def2);
// Check the option data.
......@@ -1392,7 +1398,8 @@ TEST_F(Dhcp4ParserTest, optionDefDuplicate) {
ElementPtr json = Element::fromJSON(config);
// Make sure that the option definition does not exist yet.
ASSERT_FALSE(CfgMgr::instance().getOptionDef("isc", 100));
ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100));
// Use the configuration string to create new option definitions.
ConstElementPtr status;
......@@ -1422,7 +1429,8 @@ TEST_F(Dhcp4ParserTest, optionDefArray) {
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("isc", 100);
OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
......@@ -1432,7 +1440,8 @@ TEST_F(Dhcp4ParserTest, optionDefArray) {
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
def = CfgMgr::instance().getOptionDef("isc", 100);
def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100);
ASSERT_TRUE(def);
// Check the option data.
......@@ -1463,7 +1472,8 @@ TEST_F(Dhcp4ParserTest, optionDefEncapsulate) {
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("isc", 100);
OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
......@@ -1473,7 +1483,8 @@ TEST_F(Dhcp4ParserTest, optionDefEncapsulate) {
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
def = CfgMgr::instance().getOptionDef("isc", 100);
def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100);
ASSERT_TRUE(def);
// Check the option data.
......@@ -1670,7 +1681,8 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
"}";
ElementPtr json = Element::fromJSON(config);
OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("dhcp4", 109);
OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("dhcp4", 109);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
......@@ -1680,7 +1692,8 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
def = CfgMgr::instance().getOptionDef("dhcp4", 109);
def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("dhcp4", 109);
ASSERT_TRUE(def);
// Check the option data.
......@@ -1736,7 +1749,8 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
// Expecting success.
checkResult(status, 0);
def = CfgMgr::instance().getOptionDef("dhcp4", 65);
def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("dhcp4", 65);
ASSERT_TRUE(def);
// Check the option data.
......
......@@ -1315,10 +1315,12 @@ TEST_F(Dhcpv4SrvTest, unpackOptions) {
// Add option definitions to the Configuration Manager. Each goes under
// different option space.
CfgMgr& cfgmgr = CfgMgr::instance();
ASSERT_NO_THROW(cfgmgr.addOptionDef(opt_def, "space-foobar"));
ASSERT_NO_THROW(cfgmgr.addOptionDef(opt_def2, "space-foo"));
ASSERT_NO_THROW(cfgmgr.addOptionDef(opt_def3, "space-bar"));
CfgOptionDef cfg_option_def;
ASSERT_NO_THROW(cfg_option_def.add(opt_def, "space-foobar"));
ASSERT_NO_THROW(cfg_option_def.add(opt_def2, "space-foo"));
ASSERT_NO_THROW(cfg_option_def.add(opt_def3, "space-bar"));
CfgMgr::instance().getStagingCfg()->setCfgOptionDef(cfg_option_def);
CfgMgr::instance().commit();
// Create the buffer holding the structure of options.
const char raw_data[] = {
......
......@@ -2444,7 +2444,8 @@ Dhcpv6Srv::unpackOptions(const OptionBuffer& buf,
option_defs = LibDHCP::getOptionDefs(Option::V6);
} else if (!option_space.empty()) {
OptionDefContainerPtr option_defs_ptr =
CfgMgr::instance().getOptionDefs(option_space);
CfgMgr::instance().getCurrentCfg()->getCfgOptionDef()
.getAll(option_space);
if (option_defs_ptr != NULL) {
option_defs = *option_defs_ptr;
}
......
......@@ -1466,7 +1466,8 @@ TEST_F(Dhcp6ParserTest, optionDefIpv6Address) {
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("isc", 100);
OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
......@@ -1475,7 +1476,7 @@ TEST_F(Dhcp6ParserTest, optionDefIpv6Address) {
ASSERT_TRUE(status);
// The option definition should now be available in the CfgMgr.
def = CfgMgr::instance().getOptionDef("isc", 100);
def = CfgMgr::instance().getCurrentCfg()->getCfgOptionDef().get("isc", 100);
ASSERT_TRUE(def);
// Verify that the option definition data is valid.
......@@ -1505,7 +1506,8 @@ TEST_F(Dhcp6ParserTest, optionDefRecord) {
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("isc", 100);
OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
......@@ -1515,7 +1517,7 @@ TEST_F(Dhcp6ParserTest, optionDefRecord) {
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
def = CfgMgr::instance().getOptionDef("isc", 100);
def = CfgMgr::instance().getCurrentCfg()->getCfgOptionDef().get("isc", 100);
ASSERT_TRUE(def);
// Check the option data.
......@@ -1562,8 +1564,10 @@ TEST_F(Dhcp6ParserTest, optionDefMultiple) {
ElementPtr json = Element::fromJSON(config);
// Make sure that the option definitions do not exist yet.
ASSERT_FALSE(CfgMgr::instance().getOptionDef("isc", 100));
ASSERT_FALSE(CfgMgr::instance().getOptionDef("isc", 101));
ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100));
ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 101));
// Use the configuration string to create new option definitions.
ConstElementPtr status;
......@@ -1572,7 +1576,8 @@ TEST_F(Dhcp6ParserTest, optionDefMultiple) {
checkResult(status, 0);
// Check the first definition we have created.
OptionDefinitionPtr def1 = CfgMgr::instance().getOptionDef("isc", 100);
OptionDefinitionPtr def1 = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100);
ASSERT_TRUE(def1);
// Check the option data.
......@@ -1582,7 +1587,8 @@ TEST_F(Dhcp6ParserTest, optionDefMultiple) {
EXPECT_FALSE(def1->getArrayType());
// Check the second option definition we have created.
OptionDefinitionPtr def2 = CfgMgr::instance().getOptionDef("isc", 101);
OptionDefinitionPtr def2 = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 101);
ASSERT_TRUE(def2);
// Check the option data.
......@@ -1622,7 +1628,8 @@ TEST_F(Dhcp6ParserTest, optionDefDuplicate) {
ElementPtr json = Element::fromJSON(config);
// Make sure that the option definition does not exist yet.
ASSERT_FALSE(CfgMgr::instance().getOptionDef("isc", 100));
ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100));
// Use the configuration string to create new option definitions.
ConstElementPtr status;
......@@ -1652,7 +1659,8 @@ TEST_F(Dhcp6ParserTest, optionDefArray) {
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("isc", 100);
OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
......@@ -1662,7 +1670,7 @@ TEST_F(Dhcp6ParserTest, optionDefArray) {
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
def = CfgMgr::instance().getOptionDef("isc", 100);
def = CfgMgr::instance().getCurrentCfg()->getCfgOptionDef().get("isc", 100);
ASSERT_TRUE(def);
// Check the option data.
......@@ -1692,7 +1700,8 @@ TEST_F(Dhcp6ParserTest, optionDefEncapsulate) {
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("isc", 100);
OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
......@@ -1702,7 +1711,7 @@ TEST_F(Dhcp6ParserTest, optionDefEncapsulate) {
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
def = CfgMgr::instance().getOptionDef("isc", 100);
def = CfgMgr::instance().getCurrentCfg()->getCfgOptionDef().get("isc", 100);
ASSERT_TRUE(def);
// Check the option data.
......@@ -1900,7 +1909,8 @@ TEST_F(Dhcp6ParserTest, optionStandardDefOverride) {
"}";
ElementPtr json = Element::fromJSON(config);
OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("dhcp6", 100);
OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("dhcp6", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
......@@ -1910,7 +1920,8 @@ TEST_F(Dhcp6ParserTest, optionStandardDefOverride) {
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
def = CfgMgr::instance().getOptionDef("dhcp6", 100);
def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("dhcp6", 100);
ASSERT_TRUE(def);
// Check the option data.
......@@ -1966,7 +1977,8 @@ TEST_F(Dhcp6ParserTest, optionStandardDefOverride) {
// Expecting success.
checkResult(status, 0);
def = CfgMgr::instance().getOptionDef("dhcp6", 59);
def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("dhcp6", 59);
ASSERT_TRUE(def);
// Check the option data.
......
......@@ -1713,10 +1713,12 @@ TEST_F(Dhcpv6SrvTest, unpackOptions) {
// Add option definitions to the Configuration Manager. Each goes under
// different option space.
CfgMgr& cfgmgr = CfgMgr::instance();
ASSERT_NO_THROW(cfgmgr.addOptionDef(opt_def, "space-foobar"));
ASSERT_NO_THROW(cfgmgr.addOptionDef(opt_def2, "space-foo"));
ASSERT_NO_THROW(cfgmgr.addOptionDef(opt_def3, "space-bar"));
CfgOptionDef cfg_option_def;
ASSERT_NO_THROW(cfg_option_def.add(opt_def, "space-foobar"));
ASSERT_NO_THROW(cfg_option_def.add(opt_def2, "space-foo"));
ASSERT_NO_THROW(cfg_option_def.add(opt_def3, "space-bar"));
CfgMgr::instance().getStagingCfg()->setCfgOptionDef(cfg_option_def);
CfgMgr::instance().commit();
// Create the buffer holding the structure of options.
const char raw_data[] = {
......
......@@ -92,6 +92,25 @@ OptionDefinition::OptionDefinition(const std::string& name,
encapsulated_space_(encapsulated_space) {
}
OptionDefinition::OptionDefinition(const OptionDefinition& def)
: name_(def.getName()),
code_(def.getCode()),
type_(def.getType()),
array_type_(def.getArrayType()),
encapsulated_space_(def.getEncapsulatedSpace()),
record_fields_(def.getRecordFields()) {
}
bool
OptionDefinition::equals(const OptionDefinition& other) const {
return (name_ == other.name_ &&
code_ == other.code_ &&
type_ == other.type_ &&
array_type_ == other.array_type_ &&
encapsulated_space_ == other.encapsulated_space_ &&
record_fields_ == other.record_fields_);
}
void
OptionDefinition::addRecordField(const std::string& data_type_name) {
OptionDataType data_type = OptionDataTypeUtil::getDataType(data_type_name);
......
......@@ -183,6 +183,40 @@ public:
const std::string& type,
const char* encapsulated_space);
/// @brief Copy constructor.
///
/// @param def Option definition to be used to create a new instance.
explicit OptionDefinition(const OptionDefinition& def);
/// @name Comparison functions and operators.
///
//@{
/// @brief Check if option definition is equal to other.
///
/// @param other Option definition to compare to.
///
/// @return true if two option definitions are equal, false otherwise.
bool equals(const OptionDefinition& other) const;
/// @brief Equality operator.
///
/// @param other Option definition to compare to.
///
/// @return true if two option definitions are equal, false otherwise.
bool operator==(const OptionDefinition& other) const {
return (equals(other));
}
/// @brief Inequality operator.
///
/// @param other Option definition to compare to.
///
/// @return true if option definitions are not equal, false otherwise.
bool operator!=(const OptionDefinition& other) const {
return (!equals(other));
}
//@}
/// @brief Constructor.
///
/// This constructor sets the name of the option space that is
......@@ -247,7 +281,9 @@ public:
/// @brief Return list of record fields.
///
/// @return list of record fields.
const RecordFieldsCollection& getRecordFields() const { return (record_fields_); }
const RecordFieldsCollection& getRecordFields() const {
return (record_fields_);
}
/// @brief Return option data type.
///
......
......@@ -21,6 +21,9 @@
#include <stdint.h>
#include <string>
#define DHCP4_OPTION_SPACE "dhcp4"
#define DHCP6_OPTION_SPACE "dhcp6"
namespace isc {
namespace dhcp {
......
......@@ -47,6 +47,7 @@ class OptionDefinitionTest : public ::testing::Test {
public:
// @brief Constructor.
OptionDefinitionTest() { }
};
// The purpose of this test is to verify that OptionDefinition
......@@ -115,6 +116,86 @@ TEST_F(OptionDefinitionTest, constructor) {
);
}
// This test checks that the copy constructor works properly.
TEST_F(OptionDefinitionTest, copyConstructor) {
OptionDefinition opt_def("option-foo", 27, "record", true);
ASSERT_NO_THROW(opt_def.addRecordField("uint16"));
ASSERT_NO_THROW(opt_def.addRecordField("string"));
OptionDefinition opt_def_copy(opt_def);
EXPECT_EQ("option-foo", opt_def_copy.getName());
EXPECT_EQ(27, opt_def_copy.getCode());
EXPECT_TRUE(opt_def_copy.getArrayType());
EXPECT_TRUE(opt_def_copy.getEncapsulatedSpace().empty());
const OptionDefinition::RecordFieldsCollection fields =
opt_def_copy.getRecordFields();
ASSERT_EQ(2, fields.size());
EXPECT_EQ(OPT_UINT16_TYPE, fields[0]);
EXPECT_EQ(OPT_STRING_TYPE, fields[1]);
}
// This test checks that two option definitions may be compared fot equality.
TEST_F(OptionDefinitionTest, equality) {
// Equal definitions.
EXPECT_TRUE(OptionDefinition("option-foo", 5, "uint16", false)
== OptionDefinition("option-foo", 5, "uint16", false));
EXPECT_FALSE(OptionDefinition("option-foo", 5, "uint16", false)
!= OptionDefinition("option-foo", 5, "uint16", false));
// Differ by name.
EXPECT_FALSE(OptionDefinition("option-bar", 5, "uint16", false)
== OptionDefinition("option-foo", 5, "uint16", false));
EXPECT_TRUE(OptionDefinition("option-bar", 5, "uint16", false)
!= OptionDefinition("option-foo", 5, "uint16", false));
// Differ by option code.
EXPECT_FALSE(OptionDefinition("option-foo", 5, "uint16", false)
== OptionDefinition("option-foo", 6, "uint16", false));
EXPECT_TRUE(OptionDefinition("option-foo", 5, "uint16", false)
!= OptionDefinition("option-foo", 6, "uint16", false));
// Differ by type of the data.
EXPECT_FALSE(OptionDefinition("option-foo", 5, "uint16", false)
== OptionDefinition("option-foo", 5, "uint32", false));
EXPECT_TRUE(OptionDefinition("option-foo", 5, "uint16", false)
!= OptionDefinition("option-foo", 5, "uint32", false));
// Differ by array-type property.
EXPECT_FALSE(OptionDefinition("option-foo", 5, "uint16", false)
== OptionDefinition("option-foo", 5, "uint16", true));
EXPECT_TRUE(OptionDefinition("option-foo", 5, "uint16", false)
!= OptionDefinition("option-foo", 5, "uint16", true));
// Differ by record fields.
OptionDefinition def1("option-foo", 5, "record");
OptionDefinition def2("option-foo", 5, "record");
// There are no record fields specified yet, so initially they have
// to be equal.
ASSERT_TRUE(def1 == def2);
ASSERT_FALSE(def1 != def2);
// Add some record fields.
ASSERT_NO_THROW(def1.addRecordField("uint16"));
ASSERT_NO_THROW(def2.addRecordField("uint16"));
// Definitions should still remain equal.
ASSERT_TRUE(def1 == def2);
ASSERT_FALSE(def1 != def2);
// Add additional record field to one of the definitions but not the
// other. They should now be unequal.
ASSERT_NO_THROW(def1.addRecordField("string"));
ASSERT_FALSE(def1 == def2);
ASSERT_TRUE(def1 != def2);
// Add the same record field to the other definition. They should now
// be equal again.
ASSERT_NO_THROW(def2.addRecordField("string"));
EXPECT_TRUE(def1 == def2);
EXPECT_FALSE(def1 != def2);
}
// The purpose of this test is to verify that various data fields
// can be specified for an option definition when this definition
// is marked as 'record' and that fields can't be added if option
......
......@@ -46,6 +46,7 @@ libkea_dhcpsrv_la_SOURCES += addr_utilities.cc addr_utilities.h
libkea_dhcpsrv_la_SOURCES += alloc_engine.cc alloc_engine.h
libkea_dhcpsrv_la_SOURCES += callout_handle_store.h
libkea_dhcpsrv_la_SOURCES += cfg_iface.cc cfg_iface.h
libkea_dhcpsrv_la_SOURCES += cfg_option_def.cc cfg_option_def.h
libkea_dhcpsrv_la_SOURCES += cfgmgr.cc cfgmgr.h
libkea_dhcpsrv_la_SOURCES += csv_lease_file4.cc csv_lease_file4.h
libkea_dhcpsrv_la_SOURCES += csv_lease_file6.cc csv_lease_file6.h
......
// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <dhcp/libdhcp++.h>
#include <dhcp/option_definition.h>
#include <dhcp/option_space.h>
#include <dhcpsrv/cfg_option_def.h>
namespace isc {
namespace dhcp {
void
CfgOptionDef::copy(CfgOptionDef& new_config) const {
CfgOptionDef cfg;
std::list<std::string> names = option_definitions_.getOptionSpaceNames();
for (std::list<std::string>::const_iterator name = names.begin();
name != names.end(); ++name) {
OptionDefContainerPtr defs = getAll(*name);
for (OptionDefContainer::const_iterator def = defs->begin();
def != defs->end(); ++def) {
OptionDefinitionPtr new_def =
OptionDefinitionPtr(new OptionDefinition(**def));
cfg.add(new_def, *name);
}
}
new_config = cfg;
}
bool
CfgOptionDef::equals(const CfgOptionDef& other) const {
// Get our option space names.
std::list<std::string> names = option_definitions_.getOptionSpaceNames();
// Get option space names held by the other object.
std::list<std::string>
other_names = other.option_definitions_.getOptionSpaceNames();
// Compareg that sizes are the same. If they hold different number of
// option space names the objects are not equal.
if (names.size() != other_names.size()) {
return (false);
}
// Iterate over all option space names and get the definitions for each
// of them.
for (std::list<std::string>::const_iterator name = names.begin();
name != names.end(); ++name) {
// Get all definitions.
OptionDefContainerPtr defs = getAll(*name);
OptionDefContainerPtr other_defs = other.getAll(*name);
// Compare sizes. If they hold different number of definitions,
// they are unequal.
if (defs->size() != defs->size()) {
return (false);
}
// For each option definition, try to find one in the other object.
for (OptionDefContainer::const_iterator def = defs->begin();
def != defs->end(); ++def) {
OptionDefinitionPtr
other_def = other.get(*name, (*def)->getCode());
// Actually compare them.
if (!other_def || (*other_def != **def)) {
return (false);
}
}
}
// All checks passed.
return (true);
}
void
CfgOptionDef::add(const OptionDefinitionPtr& def,
const std::string& option_space) {
if (!OptionSpace::validateName(option_space)) {
isc_throw(BadValue, "invalid option space name '"
<< option_space << "'");