#include <gtest/gtest.h>
#include <database/backend_selector.h>
+#include <dhcp/option_int.h>
#include <dhcp/option_string.h>
#include <dhcp/tests/iface_mgr_test_config.h>
#include <dhcp6/dhcp6_srv.h>
// This test verifies that externally configured options
// merged correctly into staging configuration.
-TEST_F(Dhcp6CBTest, DISABLED_mergeOptions) {
+TEST_F(Dhcp6CBTest, mergeOptions) {
string base_config =
"{ \n"
" \"option-data\": [ { \n"
- " \"name\": \"dhcp-message\", \n"
- " \"data\": \"0A0B0C0D\", \n"
- " \"csv-format\": false \n"
+ " \"name\": \"solmax-rt\", \n"
+ " \"data\": \"500\" \n"
" },{ \n"
- " \"name\": \"host-name\", \n"
- " \"data\": \"old.example.com\", \n"
- " \"csv-format\": true \n"
+ " \"name\": \"bootfile-url\", \n"
+ " \"data\": \"orig-boot-file\" \n"
" } \n"
" ], \n"
" \"config-control\": { \n"
" } \n"
"} \n";
- extractConfig(base_config);
OptionDescriptorPtr opt;
-
- // Add host-name to the first backend.
- opt.reset(new OptionDescriptor(
- createOption<OptionString>(Option::V6, DHO_HOST_NAME,
- true, false, "new.example.com")));
- opt->space_name_ = DHCP6_OPTION_SPACE;
- db1_->createUpdateOption6(ServerSelector::ALL(), opt);
-
- // Add boot-file-name to the first backend.
+ // Add solmax-rt to the first backend.
opt.reset(new OptionDescriptor(
- createOption<OptionString>(Option::V6, DHO_BOOT_FILE_NAME,
- true, false, "my-boot-file")));
+ createOption<OptionString>(Option::V6, D6O_BOOTFILE_URL,
+ true, false, "updated-boot-file")));
opt->space_name_ = DHCP6_OPTION_SPACE;
db1_->createUpdateOption6(ServerSelector::ALL(), opt);
- // Add boot-file-name to the second backend.
+ // Add solmax-rt to the second backend.
opt.reset(new OptionDescriptor(
- createOption<OptionString>(Option::V6, DHO_BOOT_FILE_NAME,
- true, false, "your-boot-file")));
+ createOption<OptionUint32>(Option::V6, D6O_SOL_MAX_RT,
+ false, true, 700)));
opt->space_name_ = DHCP6_OPTION_SPACE;
db2_->createUpdateOption6(ServerSelector::ALL(), opt);
// Should parse and merge without error.
ASSERT_NO_FATAL_FAILURE(configure(base_config, CONTROL_RESULT_SUCCESS, ""));
- // Verify the composite staging is correct.
+ // Now let's verify that composite staging options are correct.
SrvConfigPtr staging_cfg = CfgMgr::instance().getStagingCfg();
-
- // Option definition from JSON should be there.
CfgOptionPtr options = staging_cfg->getCfgOption();
- // dhcp-message should come from the original config.
- OptionDescriptor found_opt = options->get("dhcp6", DHO_DHCP_MESSAGE);
- ASSERT_TRUE(found_opt.option_);
- EXPECT_EQ("0x0A0B0C0D", found_opt.option_->toHexString());
-
- // host-name should come from the first back end,
+ // bootfile-url should come from the first config back end.
// (overwriting the original).
- found_opt = options->get("dhcp6", DHO_HOST_NAME);
+ OptionDescriptor found_opt = options->get("dhcp6", D6O_BOOTFILE_URL);
ASSERT_TRUE(found_opt.option_);
- EXPECT_EQ("new.example.com", found_opt.option_->toString());
+ OptionStringPtr opstr = boost::dynamic_pointer_cast<OptionString>(found_opt.option_);
+ ASSERT_TRUE(opstr);
+ EXPECT_EQ("updated-boot-file", opstr->getValue());
- // booth-file-name should come from the first back end.
- found_opt = options->get("dhcp6", DHO_BOOT_FILE_NAME);
+ // sol-maxt-rt should come from the original config
+ found_opt = options->get("dhcp6", D6O_SOL_MAX_RT);
ASSERT_TRUE(found_opt.option_);
- EXPECT_EQ("my-boot-file", found_opt.option_->toString());
+ OptionUint32Ptr opint = boost::dynamic_pointer_cast<OptionUint32>(found_opt.option_);
+ ASSERT_TRUE(opint);
+ EXPECT_EQ(500, opint->getValue());
}
// This test verifies that externally configured shared-networks are
#include <config.h>
#include <dhcp/dhcp6.h>
#include <dhcp/option.h>
+#include <dhcp/option_custom.h>
#include <dhcp/option_int.h>
#include <dhcp/option_int_array.h>
#include <dhcp/option_space.h>
defs->add((OptionDefinitionPtr(new OptionDefinition("one", 1, "uint8"))), "isc");
defs->add((OptionDefinitionPtr(new OptionDefinition("two", 2, "uint8", true))), "isc");
- // We'll try a standard option first.
+ // We'll try a standard V4 option first.
std::string space = "dhcp4";
- std::string value("example.org");
- OptionPtr option(new Option(Option::V4, DHO_HOST_NAME));
+ std::string value = "v4.example.com";
+ OptionPtr option(new Option(Option::V6, DHO_HOST_NAME));
option->setData(value.begin(), value.end());
OptionDescriptorPtr desc(new OptionDescriptor(option, false));
ASSERT_TRUE(updated);
OptionStringPtr opstr = boost::dynamic_pointer_cast<OptionString>(desc->option_);
ASSERT_TRUE(opstr);
- EXPECT_EQ("example.org", opstr->getValue());
+ EXPECT_EQ("v4.example.com", opstr->getValue());
+
+ // Next we'll try a standard V6 option.
+ space = "dhcp6";
+ std::vector<uint8_t> fqdn =
+ { 2, 'v', '6', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'c', 'o', 'm', 0 };
+ option.reset(new Option(Option::V6, D6O_AFTR_NAME));
+ option->setData(fqdn.begin(), fqdn.end());
+ desc.reset(new OptionDescriptor(option, false));
+
+ ASSERT_NO_THROW(updated = CfgOption::createDescriptorOption(defs, space, *desc));
+ ASSERT_TRUE(updated);
+ OptionCustomPtr opcustom = boost::dynamic_pointer_cast<OptionCustom>(desc->option_);
+ ASSERT_TRUE(opcustom);
+ EXPECT_EQ("v6.example.com.", opcustom->readFqdn());
// Next we'll try a vendor option with a formatted value
space = "vendor-4491";