#include <dhcp/option6_iaaddr.h>
#include <dhcp/option_int_array.h>
#include <dhcpsrv/lease.h>
+#include <dhcp/tests/iface_mgr_test_config.h>
#include <dhcp6/tests/dhcp6_test_utils.h>
#include <boost/pointer_cast.hpp>
/// NameChangeRequest expires.
/// @param len A valid lifetime of the lease associated with the
/// NameChangeRequest.
+ /// @param fqdn The expected string value of the FQDN, if blank the
+ /// check is skipped
void verifyNameChangeRequest(const isc::dhcp_ddns::NameChangeType type,
const bool reverse, const bool forward,
const std::string& addr,
const std::string& dhcid,
const uint16_t expires,
- const uint16_t len) {
+ const uint16_t len,
+ const std::string& fqdn="") {
NameChangeRequestPtr ncr;
ASSERT_NO_THROW(ncr = d2_mgr_.peekAt(0));
ASSERT_TRUE(ncr);
EXPECT_EQ(len, ncr->getLeaseLength());
EXPECT_EQ(isc::dhcp_ddns::ST_NEW, ncr->getStatus());
+ if (! fqdn.empty()) {
+ EXPECT_EQ(fqdn, ncr->getFqdn());
+ }
+
+
// Process the message off the queue
ASSERT_NO_THROW(d2_mgr_.runReadyIO());
}
+ /// @brief Updates inherited subnet and pool members
+ ///
+ /// Hack added to set subnet_ and pool_ members that are buried into lower
+ /// level tests such as checkLease(), so one can use "configure" functionality
+ /// rather than hand-building configured objects
+ /// @param subnet_idx Element index of the desired subnet
+ /// @param pool_idx Element index of the desired pool within the desired subnet
+ /// @param type lease type of desired pool
+ ///
+ void setSubnetAndPool(int subnet_idx, int pool_idx, Lease::Type type) {
+ ConstCfgSubnets6Ptr subnets = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6();
+ ASSERT_TRUE(subnets);
+ const Subnet6Collection* subnet_col = subnets->getAll();
+ ASSERT_EQ(subnet_idx + 1, subnet_col->size());
+ subnet_ = subnet_col->at(subnet_idx);
+ ASSERT_TRUE(subnet_);
+
+ const PoolCollection& pool_col = subnet_->getPools(type);
+ ASSERT_EQ(pool_idx + 1, pool_col.size());
+ PoolPtr pool = (subnet_->getPools(type)).at(pool_idx);
+ ASSERT_TRUE(pool);
+ pool_ = boost::dynamic_pointer_cast<Pool6>(pool);
+ ASSERT_TRUE(pool);
+ }
+
// Holds a lease used by a test.
Lease6Ptr lease_;
// Verify that the host reservation is found and used. Lease host name and
// FQDN should be the reservation hostname suffixed by the qualifying suffix.
TEST_F(FqdnDhcpv6SrvTest, hostnameReservationSuffix) {
- // Create host reservation with a partial FQDN for hostname
- createHost6(true, IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1:1::babe"),
- "alice");
+ isc::dhcp::test::IfaceMgrTestConfig test_config(true);
+
+ string config_str = "{ "
+ "\"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},"
+ "\"valid-lifetime\": 4000, "
+ "\"preferred-lifetime\": 3000,"
+ "\"rebind-timer\": 2000, "
+ "\"renew-timer\": 1000, "
+ "\"subnet6\": [ "
+ " { "
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"pools\": [ { \"pool\": \"2001:db8:1:1::/64\" } ],"
+ " \"interface\" : \"eth0\" , "
+ " \"reservations\": ["
+ " {"
+ " \"duid\": \"" + duid_->toText() + "\","
+ " \"ip-addresses\": [ \"2001:db8:1:1::babe\" ],"
+ " \"hostname\": \"alice\""
+ " }"
+ " ]"
+ " } ],"
+ " \"dhcp-ddns\" : {"
+ " \"enable-updates\" : true, "
+ " \"qualifying-suffix\" : \"example.com\" }"
+ "}";
+
+ configure(config_str);
+
+ // Update subnet_ and pool_ members after config
+ setSubnetAndPool(0, 0, Lease::TYPE_NA);
+
+ ASSERT_NO_THROW(srv_->startD2());
+
+ ASSERT_TRUE(CfgMgr::instance().ddnsEnabled());
// Verify that the host reservation is found and lease name/FQDN are
// formed properly from the host name and qualifying suffix.
testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
- "alice.example.com.", 0, IOAddress("2001:db8:1:1::babe"));
- ASSERT_EQ(1, d2_mgr_.getQueueSize());
+ "alice.example.com.", 1, IOAddress("2001:db8:1:1::babe"));
+
+ // Verify that NameChangeRequest is correct.
+ verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
+ "2001:db8:1:1::babe",
+ "000201E2EB74FB53A5778E74AFD43870ECA5"
+ "4150B1F52B0CFED434802DA1259D6D3CA4",
+ 0, 4000, "alice.example.com.");
}
// Verify that the host reservation is found and used, rather than dynamic
// Address. Lease host name and FQDN should be the reservation hostname
// without a qualifying suffix.
TEST_F(FqdnDhcpv6SrvTest, hostnameReservationNoSuffix) {
+ isc::dhcp::test::IfaceMgrTestConfig test_config(true);
string config_str = "{ "
"\"interfaces-config\": {"
" \"interfaces\": [ \"*\" ]"
"},"
+ "\"valid-lifetime\": 4000, "
"\"preferred-lifetime\": 3000,"
- "\"valid-lifetime\": 4000,"
"\"rebind-timer\": 2000, "
"\"renew-timer\": 1000, "
- "\"subnet6\": [ { "
- " \"pools\": [ { \"pool\": \"2001:db8:1::/80\" } ],"
- " \"subnet\": \"2001:db8:1::/64\" } ], "
+ "\"subnet6\": [ "
+ " { "
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"pools\": [ { \"pool\": \"2001:db8:1:1::/64\" } ],"
+ " \"interface\" : \"eth0\" , "
+ " \"reservations\": ["
+ " {"
+ " \"duid\": \"" + duid_->toText() + "\","
+ " \"ip-addresses\": [ \"2001:db8:1:1::babe\" ],"
+ " \"hostname\": \"alice.example.com\""
+ " }"
+ " ]"
+ " } ],"
" \"dhcp-ddns\" : {"
" \"enable-updates\" : true, "
- " \"server-ip\" : \"::1\", "
- " \"server-port\" : 53001, "
- " \"sender-ip\" : \"::\", "
- " \"sender-port\" : 0, "
- " \"max-queue-size\" : 2048, "
- " \"ncr-protocol\" : \"UDP\", "
- " \"ncr-format\" : \"JSON\", "
- " \"always-include-fqdn\" : true, "
- " \"allow-client-update\" : true, "
- " \"override-no-update\" : true, "
- " \"override-client-update\" : true, "
- " \"replace-client-name\" : true, "
- " \"generated-prefix\" : \"test.prefix\", "
- " \"qualifying-suffix\" : \"\" },"
- "\"valid-lifetime\": 4000 }";
+ " \"qualifying-suffix\" : \"\" }"
+ "}";
configure(config_str);
+ // Update subnet_ and pool_ members after config
+ setSubnetAndPool(0, 0, Lease::TYPE_NA);
ASSERT_NO_THROW(srv_->startD2());
ASSERT_TRUE(CfgMgr::instance().ddnsEnabled());
- createHost6(true, IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1:1::babe"),
- "alice.example.com");
-
testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
- "alice.example.com.", 0, IOAddress("2001:db8:1:1::babe"));
- ASSERT_EQ(1, d2_mgr_.getQueueSize());
+ "alice.example.com.", 1,
+ IOAddress("2001:db8:1:1::babe"));
+
+ // Verify that NameChangeRequest is correct.
+ verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
+ "2001:db8:1:1::babe",
+ "000201E2EB74FB53A5778E74AFD43870ECA5"
+ "4150B1F52B0CFED434802DA1259D6D3CA4",
+ 0, 4000, "alice.example.com.");
+
}
-// Verify that the host reservation is found and used, rather than dynamic
-// Address. Lease host name and FQDN should be the reservation hostname
-// with the qualifying suffix even though updates are disabled.
TEST_F(FqdnDhcpv6SrvTest, hostnameReservationDdnsDisabled) {
+ isc::dhcp::test::IfaceMgrTestConfig test_config(true);
string config_str = "{ "
"\"interfaces-config\": {"
" \"interfaces\": [ \"*\" ]"
"},"
+ "\"valid-lifetime\": 4000, "
"\"preferred-lifetime\": 3000,"
- "\"valid-lifetime\": 4000,"
"\"rebind-timer\": 2000, "
"\"renew-timer\": 1000, "
- "\"subnet6\": [ { "
- " \"pools\": [ { \"pool\": \"2001:db8:1::/80\" } ],"
- " \"subnet\": \"2001:db8:1::/64\" } ], "
+ "\"subnet6\": [ "
+ " { "
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"pools\": [ { \"pool\": \"2001:db8:1:1::/64\" } ],"
+ " \"interface\" : \"eth0\" , "
+ " \"reservations\": ["
+ " {"
+ " \"duid\": \"" + duid_->toText() + "\","
+ " \"ip-addresses\": [ \"2001:db8:1:1::babe\" ],"
+ " \"hostname\": \"alice\""
+ " }"
+ " ]"
+ " } ],"
" \"dhcp-ddns\" : {"
" \"enable-updates\" : false, "
- " \"server-ip\" : \"::1\", "
- " \"server-port\" : 53001, "
- " \"sender-ip\" : \"::\", "
- " \"sender-port\" : 0, "
- " \"max-queue-size\" : 2048, "
- " \"ncr-protocol\" : \"UDP\", "
- " \"ncr-format\" : \"JSON\", "
- " \"always-include-fqdn\" : true, "
- " \"allow-client-update\" : true, "
- " \"override-no-update\" : true, "
- " \"override-client-update\" : true, "
- " \"replace-client-name\" : true, "
- " \"generated-prefix\" : \"test.prefix\", "
- " \"qualifying-suffix\" : \"disabled.example.com\" },"
- "\"valid-lifetime\": 4000 }";
+ " \"qualifying-suffix\" : \"disabled.example.com\" }"
+ "}";
configure(config_str);
- ASSERT_NO_THROW(srv_->startD2());
+ // Update subnet_ and pool_ members after config
+ setSubnetAndPool(0, 0, Lease::TYPE_NA);
ASSERT_FALSE(CfgMgr::instance().ddnsEnabled());
- createHost6(true, IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1:1::babe"),
- "alice");
-
testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
- "alice.disabled.example.com.", 0,
+ "alice.disabled.example.com.", 0,
IOAddress("2001:db8:1:1::babe"));
}