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, ...@@ -1806,8 +1806,8 @@ Dhcpv4Srv::unpackOptions(const OptionBuffer& buf,
// Get the list of stdandard option definitions. // Get the list of stdandard option definitions.
option_defs = LibDHCP::getOptionDefs(Option::V4); option_defs = LibDHCP::getOptionDefs(Option::V4);
} else if (!option_space.empty()) { } else if (!option_space.empty()) {
OptionDefContainerPtr option_defs_ptr = OptionDefContainerPtr option_defs_ptr = CfgMgr::instance()
CfgMgr::instance().getOptionDefs(option_space); .getCurrentCfg()->getCfgOptionDef().getAll(option_space);
if (option_defs_ptr != NULL) { if (option_defs_ptr != NULL) {
option_defs = *option_defs_ptr; option_defs = *option_defs_ptr;
} }
......
...@@ -1231,7 +1231,8 @@ TEST_F(Dhcp4ParserTest, optionDefIpv4Address) { ...@@ -1231,7 +1231,8 @@ TEST_F(Dhcp4ParserTest, optionDefIpv4Address) {
ElementPtr json = Element::fromJSON(config); ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist. // 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); ASSERT_FALSE(def);
// Use the configuration string to create new option definition. // Use the configuration string to create new option definition.
...@@ -1241,7 +1242,7 @@ TEST_F(Dhcp4ParserTest, optionDefIpv4Address) { ...@@ -1241,7 +1242,7 @@ TEST_F(Dhcp4ParserTest, optionDefIpv4Address) {
checkResult(status, 0); checkResult(status, 0);
// The option definition should now be available in the CfgMgr. // 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); ASSERT_TRUE(def);
// Verify that the option definition data is valid. // Verify that the option definition data is valid.
...@@ -1272,7 +1273,8 @@ TEST_F(Dhcp4ParserTest, optionDefRecord) { ...@@ -1272,7 +1273,8 @@ TEST_F(Dhcp4ParserTest, optionDefRecord) {
ElementPtr json = Element::fromJSON(config); ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist. // 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); ASSERT_FALSE(def);
// Use the configuration string to create new option definition. // Use the configuration string to create new option definition.
...@@ -1282,7 +1284,7 @@ TEST_F(Dhcp4ParserTest, optionDefRecord) { ...@@ -1282,7 +1284,7 @@ TEST_F(Dhcp4ParserTest, optionDefRecord) {
checkResult(status, 0); checkResult(status, 0);
// The option definition should now be available in the CfgMgr. // 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); ASSERT_TRUE(def);
// Check the option data. // Check the option data.
...@@ -1330,8 +1332,10 @@ TEST_F(Dhcp4ParserTest, optionDefMultiple) { ...@@ -1330,8 +1332,10 @@ TEST_F(Dhcp4ParserTest, optionDefMultiple) {
ElementPtr json = Element::fromJSON(config); ElementPtr json = Element::fromJSON(config);
// Make sure that the option definitions do not exist yet. // Make sure that the option definitions do not exist yet.
ASSERT_FALSE(CfgMgr::instance().getOptionDef("isc", 100)); ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
ASSERT_FALSE(CfgMgr::instance().getOptionDef("isc", 101)); getCfgOptionDef().get("isc", 100));
ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 101));
// Use the configuration string to create new option definitions. // Use the configuration string to create new option definitions.
ConstElementPtr status; ConstElementPtr status;
...@@ -1340,7 +1344,8 @@ TEST_F(Dhcp4ParserTest, optionDefMultiple) { ...@@ -1340,7 +1344,8 @@ TEST_F(Dhcp4ParserTest, optionDefMultiple) {
checkResult(status, 0); checkResult(status, 0);
// Check the first definition we have created. // 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); ASSERT_TRUE(def1);
// Check the option data. // Check the option data.
...@@ -1351,7 +1356,8 @@ TEST_F(Dhcp4ParserTest, optionDefMultiple) { ...@@ -1351,7 +1356,8 @@ TEST_F(Dhcp4ParserTest, optionDefMultiple) {
EXPECT_TRUE(def1->getEncapsulatedSpace().empty()); EXPECT_TRUE(def1->getEncapsulatedSpace().empty());
// Check the second option definition we have created. // 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); ASSERT_TRUE(def2);
// Check the option data. // Check the option data.
...@@ -1392,7 +1398,8 @@ TEST_F(Dhcp4ParserTest, optionDefDuplicate) { ...@@ -1392,7 +1398,8 @@ TEST_F(Dhcp4ParserTest, optionDefDuplicate) {
ElementPtr json = Element::fromJSON(config); ElementPtr json = Element::fromJSON(config);
// Make sure that the option definition does not exist yet. // 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. // Use the configuration string to create new option definitions.
ConstElementPtr status; ConstElementPtr status;
...@@ -1422,7 +1429,8 @@ TEST_F(Dhcp4ParserTest, optionDefArray) { ...@@ -1422,7 +1429,8 @@ TEST_F(Dhcp4ParserTest, optionDefArray) {
ElementPtr json = Element::fromJSON(config); ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist. // 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); ASSERT_FALSE(def);
// Use the configuration string to create new option definition. // Use the configuration string to create new option definition.
...@@ -1432,7 +1440,8 @@ TEST_F(Dhcp4ParserTest, optionDefArray) { ...@@ -1432,7 +1440,8 @@ TEST_F(Dhcp4ParserTest, optionDefArray) {
checkResult(status, 0); checkResult(status, 0);
// The option definition should now be available in the CfgMgr. // 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); ASSERT_TRUE(def);
// Check the option data. // Check the option data.
...@@ -1463,7 +1472,8 @@ TEST_F(Dhcp4ParserTest, optionDefEncapsulate) { ...@@ -1463,7 +1472,8 @@ TEST_F(Dhcp4ParserTest, optionDefEncapsulate) {
ElementPtr json = Element::fromJSON(config); ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist. // 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); ASSERT_FALSE(def);
// Use the configuration string to create new option definition. // Use the configuration string to create new option definition.
...@@ -1473,7 +1483,8 @@ TEST_F(Dhcp4ParserTest, optionDefEncapsulate) { ...@@ -1473,7 +1483,8 @@ TEST_F(Dhcp4ParserTest, optionDefEncapsulate) {
checkResult(status, 0); checkResult(status, 0);
// The option definition should now be available in the CfgMgr. // 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); ASSERT_TRUE(def);
// Check the option data. // Check the option data.
...@@ -1670,7 +1681,8 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) { ...@@ -1670,7 +1681,8 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
"}"; "}";
ElementPtr json = Element::fromJSON(config); ElementPtr json = Element::fromJSON(config);
OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("dhcp4", 109); OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("dhcp4", 109);
ASSERT_FALSE(def); ASSERT_FALSE(def);
// Use the configuration string to create new option definition. // Use the configuration string to create new option definition.
...@@ -1680,7 +1692,8 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) { ...@@ -1680,7 +1692,8 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
checkResult(status, 0); checkResult(status, 0);
// The option definition should now be available in the CfgMgr. // 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); ASSERT_TRUE(def);
// Check the option data. // Check the option data.
...@@ -1736,7 +1749,8 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) { ...@@ -1736,7 +1749,8 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
// Expecting success. // Expecting success.
checkResult(status, 0); checkResult(status, 0);
def = CfgMgr::instance().getOptionDef("dhcp4", 65); def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("dhcp4", 65);
ASSERT_TRUE(def); ASSERT_TRUE(def);
// Check the option data. // Check the option data.
......
...@@ -1315,10 +1315,12 @@ TEST_F(Dhcpv4SrvTest, unpackOptions) { ...@@ -1315,10 +1315,12 @@ TEST_F(Dhcpv4SrvTest, unpackOptions) {
// Add option definitions to the Configuration Manager. Each goes under // Add option definitions to the Configuration Manager. Each goes under
// different option space. // different option space.
CfgMgr& cfgmgr = CfgMgr::instance(); CfgOptionDef cfg_option_def;
ASSERT_NO_THROW(cfgmgr.addOptionDef(opt_def, "space-foobar")); ASSERT_NO_THROW(cfg_option_def.add(opt_def, "space-foobar"));
ASSERT_NO_THROW(cfgmgr.addOptionDef(opt_def2, "space-foo")); ASSERT_NO_THROW(cfg_option_def.add(opt_def2, "space-foo"));
ASSERT_NO_THROW(cfgmgr.addOptionDef(opt_def3, "space-bar")); 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. // Create the buffer holding the structure of options.
const char raw_data[] = { const char raw_data[] = {
......
...@@ -2444,7 +2444,8 @@ Dhcpv6Srv::unpackOptions(const OptionBuffer& buf, ...@@ -2444,7 +2444,8 @@ Dhcpv6Srv::unpackOptions(const OptionBuffer& buf,
option_defs = LibDHCP::getOptionDefs(Option::V6); option_defs = LibDHCP::getOptionDefs(Option::V6);
} else if (!option_space.empty()) { } else if (!option_space.empty()) {
OptionDefContainerPtr option_defs_ptr = OptionDefContainerPtr option_defs_ptr =
CfgMgr::instance().getOptionDefs(option_space); CfgMgr::instance().getCurrentCfg()->getCfgOptionDef()
.getAll(option_space);
if (option_defs_ptr != NULL) { if (option_defs_ptr != NULL) {
option_defs = *option_defs_ptr; option_defs = *option_defs_ptr;
} }
......
...@@ -1466,7 +1466,8 @@ TEST_F(Dhcp6ParserTest, optionDefIpv6Address) { ...@@ -1466,7 +1466,8 @@ TEST_F(Dhcp6ParserTest, optionDefIpv6Address) {
ElementPtr json = Element::fromJSON(config); ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist. // 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); ASSERT_FALSE(def);
// Use the configuration string to create new option definition. // Use the configuration string to create new option definition.
...@@ -1475,7 +1476,7 @@ TEST_F(Dhcp6ParserTest, optionDefIpv6Address) { ...@@ -1475,7 +1476,7 @@ TEST_F(Dhcp6ParserTest, optionDefIpv6Address) {
ASSERT_TRUE(status); ASSERT_TRUE(status);
// The option definition should now be available in the CfgMgr. // 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); ASSERT_TRUE(def);
// Verify that the option definition data is valid. // Verify that the option definition data is valid.
...@@ -1505,7 +1506,8 @@ TEST_F(Dhcp6ParserTest, optionDefRecord) { ...@@ -1505,7 +1506,8 @@ TEST_F(Dhcp6ParserTest, optionDefRecord) {
ElementPtr json = Element::fromJSON(config); ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist. // 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); ASSERT_FALSE(def);
// Use the configuration string to create new option definition. // Use the configuration string to create new option definition.
...@@ -1515,7 +1517,7 @@ TEST_F(Dhcp6ParserTest, optionDefRecord) { ...@@ -1515,7 +1517,7 @@ TEST_F(Dhcp6ParserTest, optionDefRecord) {
checkResult(status, 0); checkResult(status, 0);
// The option definition should now be available in the CfgMgr. // 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); ASSERT_TRUE(def);
// Check the option data. // Check the option data.
...@@ -1562,8 +1564,10 @@ TEST_F(Dhcp6ParserTest, optionDefMultiple) { ...@@ -1562,8 +1564,10 @@ TEST_F(Dhcp6ParserTest, optionDefMultiple) {
ElementPtr json = Element::fromJSON(config); ElementPtr json = Element::fromJSON(config);
// Make sure that the option definitions do not exist yet. // Make sure that the option definitions do not exist yet.
ASSERT_FALSE(CfgMgr::instance().getOptionDef("isc", 100)); ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
ASSERT_FALSE(CfgMgr::instance().getOptionDef("isc", 101)); getCfgOptionDef().get("isc", 100));
ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("isc", 101));
// Use the configuration string to create new option definitions. // Use the configuration string to create new option definitions.
ConstElementPtr status; ConstElementPtr status;
...@@ -1572,7 +1576,8 @@ TEST_F(Dhcp6ParserTest, optionDefMultiple) { ...@@ -1572,7 +1576,8 @@ TEST_F(Dhcp6ParserTest, optionDefMultiple) {
checkResult(status, 0); checkResult(status, 0);
// Check the first definition we have created. // 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); ASSERT_TRUE(def1);
// Check the option data. // Check the option data.
...@@ -1582,7 +1587,8 @@ TEST_F(Dhcp6ParserTest, optionDefMultiple) { ...@@ -1582,7 +1587,8 @@ TEST_F(Dhcp6ParserTest, optionDefMultiple) {
EXPECT_FALSE(def1->getArrayType()); EXPECT_FALSE(def1->getArrayType());
// Check the second option definition we have created. // 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); ASSERT_TRUE(def2);
// Check the option data. // Check the option data.
...@@ -1622,7 +1628,8 @@ TEST_F(Dhcp6ParserTest, optionDefDuplicate) { ...@@ -1622,7 +1628,8 @@ TEST_F(Dhcp6ParserTest, optionDefDuplicate) {
ElementPtr json = Element::fromJSON(config); ElementPtr json = Element::fromJSON(config);
// Make sure that the option definition does not exist yet. // 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. // Use the configuration string to create new option definitions.
ConstElementPtr status; ConstElementPtr status;
...@@ -1652,7 +1659,8 @@ TEST_F(Dhcp6ParserTest, optionDefArray) { ...@@ -1652,7 +1659,8 @@ TEST_F(Dhcp6ParserTest, optionDefArray) {
ElementPtr json = Element::fromJSON(config); ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist. // 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); ASSERT_FALSE(def);
// Use the configuration string to create new option definition. // Use the configuration string to create new option definition.
...@@ -1662,7 +1670,7 @@ TEST_F(Dhcp6ParserTest, optionDefArray) { ...@@ -1662,7 +1670,7 @@ TEST_F(Dhcp6ParserTest, optionDefArray) {
checkResult(status, 0); checkResult(status, 0);
// The option definition should now be available in the CfgMgr. // 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); ASSERT_TRUE(def);
// Check the option data. // Check the option data.
...@@ -1692,7 +1700,8 @@ TEST_F(Dhcp6ParserTest, optionDefEncapsulate) { ...@@ -1692,7 +1700,8 @@ TEST_F(Dhcp6ParserTest, optionDefEncapsulate) {
ElementPtr json = Element::fromJSON(config); ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist. // 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); ASSERT_FALSE(def);
// Use the configuration string to create new option definition. // Use the configuration string to create new option definition.
...@@ -1702,7 +1711,7 @@ TEST_F(Dhcp6ParserTest, optionDefEncapsulate) { ...@@ -1702,7 +1711,7 @@ TEST_F(Dhcp6ParserTest, optionDefEncapsulate) {
checkResult(status, 0); checkResult(status, 0);
// The option definition should now be available in the CfgMgr. // 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); ASSERT_TRUE(def);
// Check the option data. // Check the option data.
...@@ -1900,7 +1909,8 @@ TEST_F(Dhcp6ParserTest, optionStandardDefOverride) { ...@@ -1900,7 +1909,8 @@ TEST_F(Dhcp6ParserTest, optionStandardDefOverride) {
"}"; "}";
ElementPtr json = Element::fromJSON(config); ElementPtr json = Element::fromJSON(config);
OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("dhcp6", 100); OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("dhcp6", 100);
ASSERT_FALSE(def); ASSERT_FALSE(def);
// Use the configuration string to create new option definition. // Use the configuration string to create new option definition.
...@@ -1910,7 +1920,8 @@ TEST_F(Dhcp6ParserTest, optionStandardDefOverride) { ...@@ -1910,7 +1920,8 @@ TEST_F(Dhcp6ParserTest, optionStandardDefOverride) {
checkResult(status, 0); checkResult(status, 0);
// The option definition should now be available in the CfgMgr. // 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); ASSERT_TRUE(def);
// Check the option data. // Check the option data.
...@@ -1966,7 +1977,8 @@ TEST_F(Dhcp6ParserTest, optionStandardDefOverride) { ...@@ -1966,7 +1977,8 @@ TEST_F(Dhcp6ParserTest, optionStandardDefOverride) {
// Expecting success. // Expecting success.
checkResult(status, 0); checkResult(status, 0);
def = CfgMgr::instance().getOptionDef("dhcp6", 59); def = CfgMgr::instance().getCurrentCfg()->
getCfgOptionDef().get("dhcp6", 59);
ASSERT_TRUE(def); ASSERT_TRUE(def);
// Check the option data. // Check the option data.
......
...@@ -1713,10 +1713,12 @@ TEST_F(Dhcpv6SrvTest, unpackOptions) { ...@@ -1713,10 +1713,12 @@ TEST_F(Dhcpv6SrvTest, unpackOptions) {
// Add option definitions to the Configuration Manager. Each goes under // Add option definitions to the Configuration Manager. Each goes under
// different option space. // different option space.
CfgMgr& cfgmgr = CfgMgr::instance(); CfgOptionDef cfg_option_def;
ASSERT_NO_THROW(cfgmgr.addOptionDef(opt_def, "space-foobar")); ASSERT_NO_THROW(cfg_option_def.add(opt_def, "space-foobar"));
ASSERT_NO_THROW(cfgmgr.addOptionDef(opt_def2, "space-foo")); ASSERT_NO_THROW(cfg_option_def.add(opt_def2, "space-foo"));
ASSERT_NO_THROW(cfgmgr.addOptionDef(opt_def3, "space-bar")); 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. // Create the buffer holding the structure of options.
const char raw_data[] = { const char raw_data[] = {
......
...@@ -92,6 +92,25 @@ OptionDefinition::OptionDefinition(const std::string& name, ...@@ -92,6 +92,25 @@ OptionDefinition::OptionDefinition(const std::string& name,
encapsulated_space_(encapsulated_space) { 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 void
OptionDefinition::addRecordField(const std::string& data_type_name) { OptionDefinition::addRecordField(const std::string& data_type_name) {
OptionDataType data_type = OptionDataTypeUtil::getDataType(data_type_name); OptionDataType data_type = OptionDataTypeUtil::getDataType(data_type_name);
......
...@@ -183,6 +183,40 @@ public: ...@@ -183,6 +183,40 @@ public:
const std::string& type, const std::string& type,
const char* encapsulated_space); 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. /// @brief Constructor.
/// ///
/// This constructor sets the name of the option space that is /// This constructor sets the name of the option space that is
...@@ -247,7 +281,9 @@ public: ...@@ -247,7 +281,9 @@ public:
/// @brief Return list of record fields. /// @brief Return list of record fields.
/// ///
/// @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. /// @brief Return option data type.
/// ///
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#define DHCP4_OPTION_SPACE "dhcp4"
#define DHCP6_OPTION_SPACE "dhcp6"
namespace isc { namespace isc {
namespace dhcp { namespace dhcp {
......
...@@ -47,6 +47,7 @@ class OptionDefinitionTest : public ::testing::Test { ...@@ -47,6 +47,7 @@ class OptionDefinitionTest : public ::testing::Test {
public: public:
// @brief Constructor. // @brief Constructor.
OptionDefinitionTest() { } OptionDefinitionTest() { }
}; };
// The purpose of this test is to verify that OptionDefinition // The purpose of this test is to verify that OptionDefinition
...