Commit c924b233 authored by Marcin Siodelski's avatar Marcin Siodelski

[2317] Test configuration of option definition comprising a record.

parent f000b6b5
...@@ -1145,32 +1145,16 @@ public: ...@@ -1145,32 +1145,16 @@ public:
CfgMgr& cfg_mgr = CfgMgr::instance(); CfgMgr& cfg_mgr = CfgMgr::instance();
cfg_mgr.deleteOptionDefs();
// We need to move option definitions from the temporary // We need to move option definitions from the temporary
// storage to the global storage. However for new definition // storage to the global storage.
// we need to check whether such a definition already exists
// or we are adding it for the fitsy time.
BOOST_FOREACH(std::string space_name, BOOST_FOREACH(std::string space_name,
option_defs_local_.getOptionSpaceNames()) { option_defs_local_.getOptionSpaceNames()) {
// For the particular option space we have to get all
// items in the temporary storage and store it in the
// global storage.
BOOST_FOREACH(OptionDefinitionPtr def, BOOST_FOREACH(OptionDefinitionPtr def,
*option_defs_local_.getItems(space_name)) { *option_defs_local_.getItems(space_name)) {
assert(def); assert(def);
// For the particular option space get all definitions
// existing in the global storage.
OptionDefContainerPtr global_defs = cfg_mgr.getOptionDefs(space_name);
assert(global_defs);
// Find the option definition for the particular
// option code.
OptionDefContainerTypeIndex& idx = global_defs->get<1>();
const OptionDefContainerTypeRange& range =
idx.equal_range(def->getCode());
// If there is one in the global storage, erase it.
if (std::distance(range.first, range.second) > 0) {
idx.erase(range.first, range.second);
}
// Add the newly created option definition.
cfg_mgr.addOptionDef(def, space_name); cfg_mgr.addOptionDef(def, space_name);
} }
} }
......
...@@ -234,6 +234,7 @@ public: ...@@ -234,6 +234,7 @@ public:
"\"renew-timer\": 1000, " "\"renew-timer\": 1000, "
"\"valid-lifetime\": 4000, " "\"valid-lifetime\": 4000, "
"\"subnet4\": [ ], " "\"subnet4\": [ ], "
"\"option-def\": [ ], "
"\"option-data\": [ ] }"; "\"option-data\": [ ] }";
try { try {
...@@ -437,8 +438,8 @@ TEST_F(Dhcp4ParserTest, poolPrefixLen) { ...@@ -437,8 +438,8 @@ TEST_F(Dhcp4ParserTest, poolPrefixLen) {
} }
// The goal of this test is to check whether an option definition // The goal of this test is to check whether an option definition
// can be added to the dhcp4 option space. // that defines an option carrying an IPv4 address can be created.
TEST_F(Dhcp4ParserTest, optionDefAdd) { TEST_F(Dhcp4ParserTest, optionDefIpv4Address) {
// Configuration string. // Configuration string.
std::string config = std::string config =
...@@ -473,6 +474,54 @@ TEST_F(Dhcp4ParserTest, optionDefAdd) { ...@@ -473,6 +474,54 @@ TEST_F(Dhcp4ParserTest, optionDefAdd) {
EXPECT_EQ(OPT_IPV4_ADDRESS_TYPE, def->getType()); EXPECT_EQ(OPT_IPV4_ADDRESS_TYPE, def->getType());
} }
// The goal of this test is to check whether an option definiiton
// that defines an option carrying a record of data fields can
// be created.
TEST_F(Dhcp4ParserTest, optionDefRecord) {
// Configuration string.
std::string config =
"{ \"option-def\": [ {"
" \"name\": \"foo\","
" \"code\": 100,"
" \"type\": \"record\","
" \"array\": False,"
" \"record-types\": \"uint16, ipv4-address, ipv6-address, string\","
" \"space\": \"isc\""
" } ]"
"}";
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
ConstElementPtr status;
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
ASSERT_TRUE(status);
// The option definition should now be available in the CfgMgr.
def = CfgMgr::instance().getOptionDef("isc", 100);
ASSERT_TRUE(def);
// Check the option data.
EXPECT_EQ("foo", def->getName());
EXPECT_EQ(100, def->getCode());
EXPECT_EQ(OPT_RECORD_TYPE, def->getType());
EXPECT_FALSE(def->getArrayType());
// The option comprises the record of data fields. Verify that all
// fields are present and they are of the expected types.
const OptionDefinition::RecordFieldsCollection& record_fields =
def->getRecordFields();
ASSERT_EQ(4, record_fields.size());
EXPECT_EQ(OPT_UINT16_TYPE, record_fields[0]);
EXPECT_EQ(OPT_IPV4_ADDRESS_TYPE, record_fields[1]);
EXPECT_EQ(OPT_IPV6_ADDRESS_TYPE, record_fields[2]);
EXPECT_EQ(OPT_STRING_TYPE, record_fields[3]);
}
// Goal of this test is to verify that global option // Goal of this test is to verify that global option
// data is configured for the subnet if the subnet // data is configured for the subnet if the subnet
// configuration does not include options configuration. // configuration does not include options configuration.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment