const SimpleKeywords FlexOptionImpl::OPTION_PARAMETERS = {
{ "code", Element::integer },
{ "name", Element::string },
+ { "space", Element::string },
{ "csv-format", Element::boolean },
{ "add", Element::string },
{ "supersede", Element::string },
}
ConstElementPtr code_elem = option->get("code");
ConstElementPtr name_elem = option->get("name");
+ ConstElementPtr space_elem = option->get("space");
ConstElementPtr csv_format_elem = option->get("csv-format");
ConstElementPtr class_elem = option->get("client-class");
OptionDefinitionPtr def;
space = DHCP6_OPTION_SPACE;
universe = Option::V6;
}
+ if (space_elem) {
+ space = space_elem->stringValue();
+ if (!OptionSpace::validateName(space)) {
+ isc_throw(BadValue, "'" << space << "' is not a valid space name");
+ }
+ }
uint16_t code;
if (code_elem) {
int64_t value = code_elem->intValue();
isc_throw(OutOfRange, "invalid 'code' value " << value
<< " not in [0.." << max_code << "]");
}
- if (family == AF_INET) {
+ if (space == DHCP4_OPTION_SPACE) {
if (value == DHO_PAD) {
isc_throw(BadValue,
"invalid 'code' value 0: reserved for PAD");
isc_throw(BadValue,
"invalid 'code' value 255: reserved for END");
}
- } else {
+ } else if (space == DHCP6_OPTION_SPACE) {
if (value == 0) {
isc_throw(BadValue, "invalid 'code' value 0: reserved");
}
EXPECT_TRUE(impl_->getErrMsg().empty());
}
+// Verify that the space must be a string.
+TEST_F(FlexOptionTest, optionConfigBadSpace) {
+ ElementPtr options = Element::createList();
+ ElementPtr option = Element::createMap();
+ options->add(option);
+ ElementPtr add = Element::create(string("'ab'"));
+ option->set("add", add);
+ ElementPtr code = Element::create(222);
+ option->set("code", code);
+ ElementPtr space = Element::create(true);
+ option->set("space", space);
+ EXPECT_THROW(impl_->testConfigure(options), BadValue);
+ EXPECT_EQ("'space' must be a string: true", impl_->getErrMsg());
+}
+
+// Verify that the space must be valid.
+TEST_F(FlexOptionTest, optionConfigInvalidSpace) {
+ ElementPtr options = Element::createList();
+ ElementPtr option = Element::createMap();
+ options->add(option);
+ ElementPtr add = Element::create(string("'ab'"));
+ option->set("add", add);
+ ElementPtr code = Element::create(222);
+ option->set("code", code);
+ ElementPtr space = Element::create(string("-bad-"));
+ option->set("space", space);
+ EXPECT_THROW(impl_->testConfigure(options), BadValue);
+ EXPECT_EQ("'-bad-' is not a valid space name", impl_->getErrMsg());
+}
+
// Verify that the name must be a string.
TEST_F(FlexOptionTest, optionConfigBadName) {
ElementPtr options = Element::createList();
EXPECT_EQ("no known 'foobar' option in 'dhcp4' space", impl_->getErrMsg());
}
+// Verify that the space must be a known space.
+TEST_F(FlexOptionTest, optionConfigUnknownSpace) {
+ ElementPtr options = Element::createList();
+ ElementPtr option = Element::createMap();
+ options->add(option);
+ ElementPtr add = Element::create(string("'ab'"));
+ option->set("add", add);
+ ElementPtr name = Element::create(string("host-name"));
+ option->set("name", name);
+ ElementPtr space = Element::create(string("foobar"));
+ option->set("space", space);
+ EXPECT_THROW(impl_->testConfigure(options), BadValue);
+ EXPECT_EQ("no known 'host-name' option in 'foobar' space",
+ impl_->getErrMsg());
+}
+
// Verify that the definition is not required when csv-format is not specified.
TEST_F(FlexOptionTest, optionConfigUnknownCodeNoCSVFormat) {
ElementPtr options = Element::createList();
EXPECT_EQ(1, opt_lst.size());
}
+// Verify that the name can be an user defined option in a custom space.
+TEST_F(FlexOptionTest, optionConfigDefinedSpace) {
+ OptionDefSpaceContainer defs;
+ OptionDefinitionPtr def(new OptionDefinition("my-option", 222,
+ "my-space", "string"));
+ defs.addItem(def);
+ EXPECT_NO_THROW(LibDHCP::setRuntimeOptionDefs(defs));
+
+ ElementPtr options = Element::createList();
+ ElementPtr option = Element::createMap();
+ options->add(option);
+ ElementPtr add = Element::create(string("'ab'"));
+ option->set("add", add);
+ ElementPtr name = Element::create(string("my-option"));
+ option->set("name", name);
+ ElementPtr space = Element::create(string("my-space"));
+ option->set("space", space);
+ EXPECT_NO_THROW(impl_->testConfigure(options));
+ EXPECT_TRUE(impl_->getErrMsg().empty());
+
+ auto map = impl_->getOptionConfigMap();
+ EXPECT_EQ(1, map.count(222));
+ auto opt_lst = map[222];
+ EXPECT_EQ(1, opt_lst.size());
+}
+
// Last resort is only option 43...
// Verify that the name must match the code.