query_with_classes->setHWAddr(generateHWAddr(6));
query_with_classes->setIface("eth0");
query_with_classes->setIndex(ETH0_INDEX);
-
query_with_classes->addClass("foo");
// Server id should come from subnet5's client-class value.
buildCfgOptionTest(IOAddress("192.0.5.254"), query_with_classes, IOAddress("192.0.5.101"), IOAddress("192.0.5.254"));
}
+ {
+ SCOPED_TRACE("Global value if client class does not define it");
+
+ Pkt4Ptr query_with_classes(new Pkt4(DHCPREQUEST, 1234));
+ query_with_classes->addOption(generateClientId());
+ query_with_classes->setHWAddr(generateHWAddr(6));
+ query_with_classes->setIface("eth0");
+ query_with_classes->setIndex(ETH0_INDEX);
+ query_with_classes->addClass("bar");
+
+ // Server id should be global value as subnet6's client-class does not define it.
+ buildCfgOptionTest(IOAddress("10.0.0.254"), query_with_classes, IOAddress("192.0.6.101"), IOAddress("192.0.6.100"));
+ }
+
+ {
+ SCOPED_TRACE("Global value if client class does not define any option");
+
+ Pkt4Ptr query_with_classes(new Pkt4(DHCPREQUEST, 1234));
+ query_with_classes->addOption(generateClientId());
+ query_with_classes->setHWAddr(generateHWAddr(6));
+ query_with_classes->setIface("eth0");
+ query_with_classes->setIndex(ETH0_INDEX);
+ query_with_classes->addClass("xyz");
+
+ // Server id should be global value as subnet7's client-class does not define any option.
+ buildCfgOptionTest(IOAddress("10.0.0.254"), query_with_classes, IOAddress("192.0.7.101"), IOAddress("192.0.7.100"));
+ }
+
{
SCOPED_TRACE("Global value");
// A DHCPv4 message holding this server identifier should be accepted.
Pkt4Ptr pkt_with_classes(new Pkt4(DHCPREQUEST, 1234));
OptionCustomPtr class_serverid(new OptionCustom(def, Option::V6));
- class_serverid->writeAddress(IOAddress("10.0.0.254"));
+ class_serverid->writeAddress(IOAddress("192.0.5.254"));
ASSERT_NO_THROW(pkt_with_classes->addOption(class_serverid));
pkt_with_classes->addClass("foo");
EXPECT_TRUE(srv.acceptServerId(pkt_with_classes));
ASSERT_NO_THROW(pkt_with_classes->delOption(DHO_DHCP_SERVER_IDENTIFIER));
// Add a server id being an IPv4 address configured on global level.
+ // The configured class does not define the server id option.
// A DHCPv4 message holding this server identifier should be accepted.
+ Pkt4Ptr pkt_with_classes_option_not_defined(new Pkt4(DHCPREQUEST, 1234));
OptionCustomPtr global_serverid(new OptionCustom(def, Option::V6));
global_serverid->writeAddress(IOAddress("10.0.0.254"));
+ ASSERT_NO_THROW(pkt_with_classes_option_not_defined->addOption(global_serverid));
+ pkt_with_classes_option_not_defined->addClass("bar");
+ EXPECT_TRUE(srv.acceptServerId(pkt_with_classes_option_not_defined));
+
+ // Remove the server identifier.
+ ASSERT_NO_THROW(pkt_with_classes_option_not_defined->delOption(DHO_DHCP_SERVER_IDENTIFIER));
+
+ // Add a server id being an IPv4 address configured on global level.
+ // The configured class does not define any option.
+ // A DHCPv4 message holding this server identifier should be accepted.
+ Pkt4Ptr pkt_with_classes_no_options(new Pkt4(DHCPREQUEST, 1234));
+ ASSERT_NO_THROW(pkt_with_classes_no_options->addOption(global_serverid));
+ pkt_with_classes_no_options->addClass("xyz");
+ EXPECT_TRUE(srv.acceptServerId(pkt_with_classes_no_options));
+
+ // Remove the server identifier.
+ ASSERT_NO_THROW(pkt_with_classes_no_options->delOption(DHO_DHCP_SERVER_IDENTIFIER));
+
+ // Add a server id being an IPv4 address configured on global level.
+ // A DHCPv4 message holding this server identifier should be accepted.
ASSERT_NO_THROW(pkt->addOption(global_serverid));
EXPECT_TRUE(srv.acceptServerId(pkt));
CfgMgr::instance().getStagingCfg()->getClientClassDictionary()->addClass("foo", ExpressionPtr(), "", true, false, options);
subnet5->requireClientClass("foo");
+ // Build and add subnet6.
+ Subnet4Ptr subnet6(new Subnet4(IOAddress("192.0.6.0"), 24, unspec, unspec, 3600, 6));
+ pool.reset(new Pool4(IOAddress("192.0.6.100"), IOAddress("192.0.6.200")));
+ subnet6->addPool(pool);
+ subnet6->setCalculateTeeTimes(false);
+
+ subnets->add(subnet6);
+
+ options.reset(new CfgOption());
+ OptionDescriptor desc_other(false);
+ desc_other.option_ = makeFqdnListOption();
+ options->add(desc_other, DHCP4_OPTION_SPACE);
+ CfgMgr::instance().getStagingCfg()->getClientClassDictionary()->addClass("bar", ExpressionPtr(), "", true, false, options);
+ subnet6->requireClientClass("bar");
+
+ // Build and add subnet7.
+ Subnet4Ptr subnet7(new Subnet4(IOAddress("192.0.7.0"), 24, unspec, unspec, 3600, 7));
+ pool.reset(new Pool4(IOAddress("192.0.7.100"), IOAddress("192.0.7.200")));
+ subnet7->addPool(pool);
+ subnet7->setCalculateTeeTimes(false);
+
+ subnets->add(subnet7);
+
+ options.reset();
+ CfgMgr::instance().getStagingCfg()->getClientClassDictionary()->addClass("xyz", ExpressionPtr(), "", true, false, options);
+ subnet7->requireClientClass("xyz");
+
// Build and add a shared-network.
CfgSharedNetworks4Ptr networks = cfg_mgr.getStagingCfg()->getCfgSharedNetworks4();
SharedNetwork4Ptr network1(new SharedNetwork4("one"));
return (server_id);
}
+OptionPtr
+Dhcpv4SrvTest::makeFqdnListOption() {
+ OptionDefinitionPtr def = LibDHCP::getOptionDef(DHCP4_OPTION_SPACE,
+ DHO_DOMAIN_SEARCH);
+
+ // Prepare buffer holding an array of FQDNs.
+ const uint8_t fqdn[] = {
+ 8, 109, 121, 100, 111, 109, 97, 105, 110, // "mydomain"
+ 7, 101, 120, 97, 109, 112, 108, 101, // "example"
+ 3, 99, 111, 109, // "com"
+ 0
+ };
+
+ // Initialize a vector with the FQDN data.
+ std::vector<uint8_t> fqdn_buf(fqdn, fqdn + sizeof(fqdn));
+
+ OptionPtr option = def->optionFactory(Option::V4, DHO_DOMAIN_SEARCH,
+ fqdn_buf.begin(), fqdn_buf.end());
+
+ return (option);
+}
+
void
Dhcpv4SrvTest::checkAddressParams(const Pkt4Ptr& rsp,
const Subnet4Ptr subnet,
/// @return Pointer to the newly constructed option.
OptionCustomPtr makeServerIdOption(const isc::asiolink::IOAddress& address);
+ /// @brief Convenience method for making a fqdn list option instance.
+ ///
+ /// @return Pointer to the newly constructed option.
+ OptionPtr makeFqdnListOption();
+
/// Check that address was returned from proper range, that its lease
/// lifetime is correct, that T1 and T2 are returned properly
/// @param rsp response to be checked
// that the equality tools reflect that the classes are not equal.
ASSERT_NO_THROW(cclass2.reset(new ClientClassDef(*cclass)));
EXPECT_TRUE(cclass->equals(*cclass2));
- OptionDefinitionPtr def = LibDHCP::getOptionDef(DHCP4_OPTION_SPACE, 43);
+ OptionDefinitionPtr def = LibDHCP::getOptionDef(DHCP4_OPTION_SPACE,
+ DHO_VENDOR_ENCAPSULATED_OPTIONS);
EXPECT_FALSE(def);
- def = LibDHCP::getLastResortOptionDef(DHCP4_OPTION_SPACE, 43);
+ def = LibDHCP::getLastResortOptionDef(DHCP4_OPTION_SPACE, DHO_VENDOR_ENCAPSULATED_OPTIONS);
EXPECT_TRUE(def);
CfgOptionDefPtr cfg(new CfgOptionDef());
ASSERT_NO_THROW(cfg->add(def));
// Add server identifier.
OptionDefinitionPtr option_def = LibDHCP::getOptionDef(DHCP4_OPTION_SPACE,
- DHO_DHCP_SERVER_IDENTIFIER);
+ DHO_DHCP_SERVER_IDENTIFIER);
OptionCustomPtr option_server_id(new OptionCustom(*option_def, Option::V4));
option_server_id->writeAddress(IOAddress("1.2.3.4"));