BIND 10 trac3295_2, updated. 629c9c5a4fd4c96be25003e44a6bc7e2341c51c8 [3295] Implemented lease function which checks FQDN for equality.
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Jan 27 16:12:26 UTC 2014
The branch, trac3295_2 has been updated
via 629c9c5a4fd4c96be25003e44a6bc7e2341c51c8 (commit)
via e91931226acc70061e191d8e55e3f3c3ef77c02e (commit)
via fcd99b14aaf1b7e5938f1ff66d434eabfcd2b698 (commit)
via d71c2e5e68d17d99349936232277155b7db9f7eb (commit)
via c50566742ff9f7e75d79ae1ad707550be054c3c6 (commit)
from 05755b228e2dee87eca0deb10a913bce60edf135 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 629c9c5a4fd4c96be25003e44a6bc7e2341c51c8
Author: Marcin Siodelski <marcin at isc.org>
Date: Mon Jan 27 17:11:59 2014 +0100
[3295] Implemented lease function which checks FQDN for equality.
Also, moved lease unit tests to a dedicated test file.
commit e91931226acc70061e191d8e55e3f3c3ef77c02e
Author: Marcin Siodelski <marcin at isc.org>
Date: Mon Jan 27 16:07:51 2014 +0100
[3295] Generated hostname for a client who sent an empty FQDN.
Also, allow the server to generate FQDN if configured to do so, even if
client specified non-empty FQDN.
commit fcd99b14aaf1b7e5938f1ff66d434eabfcd2b698
Author: Marcin Siodelski <marcin at isc.org>
Date: Mon Jan 27 11:08:00 2014 +0100
[3295] Generate client FQDN using leased IP address.
commit d71c2e5e68d17d99349936232277155b7db9f7eb
Author: Marcin Siodelski <marcin at isc.org>
Date: Mon Jan 27 10:45:58 2014 +0100
[3295] Adjusted unit test to expect only one NCR to be generated for 3 IAs.
commit c50566742ff9f7e75d79ae1ad707550be054c3c6
Author: Marcin Siodelski <marcin at isc.org>
Date: Mon Jan 27 10:40:24 2014 +0100
[3295] Do not generate NameChangeRequests for Solicit.
-----------------------------------------------------------------------
Summary of changes:
src/bin/dhcp4/dhcp4_srv.cc | 9 +-
src/bin/dhcp6/dhcp6_messages.mes | 5 +
src/bin/dhcp6/dhcp6_srv.cc | 85 +++-
src/bin/dhcp6/dhcp6_srv.h | 42 ++
src/bin/dhcp6/tests/fqdn_unittest.cc | 137 ++++--
src/lib/dhcpsrv/alloc_engine.cc | 6 +-
src/lib/dhcpsrv/lease.cc | 9 +-
src/lib/dhcpsrv/lease.h | 10 +-
src/lib/dhcpsrv/tests/lease_mgr_unittest.cc | 623 +-----------------------
src/lib/dhcpsrv/tests/lease_unittest.cc | 694 ++++++++++++++++++++++++++-
10 files changed, 937 insertions(+), 683 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc
index 22ab653..e45e799 100644
--- a/src/bin/dhcp4/dhcp4_srv.cc
+++ b/src/bin/dhcp4/dhcp4_srv.cc
@@ -911,17 +911,14 @@ Dhcpv4Srv::createNameChangeRequests(const Lease4Ptr& lease,
// removal request for non-existent hostname.
// - A server has performed reverse, forward or both updates.
// - FQDN data between the new and old lease do not match.
- if ((lease->hostname_ != old_lease->hostname_) ||
- (lease->fqdn_fwd_ != old_lease->fqdn_fwd_) ||
- (lease->fqdn_rev_ != old_lease->fqdn_rev_)) {
+ if (!lease->hasIdenticalFqdn(*old_lease)) {
queueNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE,
old_lease);
// If FQDN data from both leases match, there is no need to update.
- } else if ((lease->hostname_ == old_lease->hostname_) &&
- (lease->fqdn_fwd_ == old_lease->fqdn_fwd_) &&
- (lease->fqdn_rev_ == old_lease->fqdn_rev_)) {
+ } else if (lease->hasIdenticalFqdn(*old_lease)) {
return;
+
}
}
diff --git a/src/bin/dhcp6/dhcp6_messages.mes b/src/bin/dhcp6/dhcp6_messages.mes
index 7e8b64e..afa04dc 100644
--- a/src/bin/dhcp6/dhcp6_messages.mes
+++ b/src/bin/dhcp6/dhcp6_messages.mes
@@ -233,6 +233,11 @@ but the lease does not contain any client identification. This is most
likely due to a software error: please raise a bug report. As a temporary
workaround, manually remove the lease entry from the database.
+% DHCP6_NAME_GEN_UPDATE_FAIL failed to update the lease using address %1, after generating FQDN for a client, reason: %2
+This message indicates the failure when trying to update the lease and/or
+options in the server's response with the hostname generated by the server
+from the acquired address.
+
% DHCP6_NOT_RUNNING IPv6 DHCP server is not running
A warning message is issued when an attempt is made to shut down the
IPv6 DHCP server but it is not running.
diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc
index 4663f30..0282e01 100644
--- a/src/bin/dhcp6/dhcp6_srv.cc
+++ b/src/bin/dhcp6/dhcp6_srv.cc
@@ -1017,13 +1017,14 @@ Dhcpv6Srv::processClientFqdn(const Pkt6Ptr& question, const Pkt6Ptr& answer) {
// generate one.
if (fqdn->getDomainNameType() == Option6ClientFqdn::PARTIAL) {
std::ostringstream name;
- if (fqdn->getDomainName().empty()) {
- name << FQDN_GENERATED_PARTIAL_NAME;
+ if (fqdn->getDomainName().empty() || FQDN_REPLACE_CLIENT_NAME) {
+ fqdn->setDomainName("", Option6ClientFqdn::PARTIAL);
+
} else {
name << fqdn->getDomainName();
+ name << "." << FQDN_PARTIAL_SUFFIX;
+ fqdn_resp->setDomainName(name.str(), Option6ClientFqdn::FULL);
}
- name << "." << FQDN_PARTIAL_SUFFIX;
- fqdn_resp->setDomainName(name.str(), Option6ClientFqdn::FULL);
// Server may be configured to replace a name supplied by a client,
// even if client supplied fully qualified domain-name.
@@ -1322,10 +1323,8 @@ Dhcpv6Srv::assignIA_NA(const Subnet6Ptr& subnet, const DuidPtr& duid,
// have to check that the FQDN settings we provided are the same
// that were set. If they aren't, we will have to remove existing
// DNS records and update the lease with the new settings.
- if (old_lease &&
- ((lease->hostname_ != old_lease->hostname_) ||
- (lease->fqdn_fwd_ != old_lease->fqdn_fwd_) ||
- (lease->fqdn_rev_ != old_lease->fqdn_rev_))) {
+ if (!fake_allocation && old_lease &&
+ !lease->hasIdenticalFqdn(*old_lease)) {
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL,
DHCP6_DDNS_LEASE_ASSIGN_FQDN_CHANGE)
.arg(old_lease->toText())
@@ -2151,6 +2150,8 @@ Dhcpv6Srv::processSolicit(const Pkt6Ptr& solicit) {
// perform DNS Updates for Solicit. Client must send Request to update
// DNS.
+ generateFqdn(advertise);
+
return (advertise);
}
@@ -2168,6 +2169,7 @@ Dhcpv6Srv::processRequest(const Pkt6Ptr& request) {
processClientFqdn(request, reply);
assignLeases(request, reply);
+ generateFqdn(reply);
createNameChangeRequests(reply);
return (reply);
@@ -2186,6 +2188,7 @@ Dhcpv6Srv::processRenew(const Pkt6Ptr& renew) {
processClientFqdn(renew, reply);
renewLeases(renew, reply);
+ generateFqdn(reply);
createNameChangeRequests(reply);
return (reply);
@@ -2390,5 +2393,71 @@ Dhcpv6Srv::ifaceMgrSocket6ErrorHandler(const std::string& errmsg) {
LOG_WARN(dhcp6_logger, DHCP6_OPEN_SOCKET_FAIL).arg(errmsg);
}
+void
+Dhcpv6Srv::generateFqdn(const Pkt6Ptr& answer) {
+ if (!answer) {
+ isc_throw(isc::Unexpected, "an instance of the object encapsulating"
+ " a message must not be NULL when generating FQDN");
+ }
+
+ // It is likely that client haven't included the FQDN option. In such case,
+ // FQDN option will be NULL. Also, there is nothing to do if the option
+ // is present and conveys the non-empty FQDN.
+ Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
+ Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
+ if (!fqdn || !fqdn->getDomainName().empty()) {
+ return;
+ }
+
+ // Get the first IA_NA acquired for the client.
+ OptionPtr ia = answer->getOption(D6O_IA_NA);
+ if (!ia) {
+ return;
+ }
+
+ // If it has any IAAddr, use the first one to generate unique FQDN.
+ Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<
+ Option6IAAddr>(ia->getOption(D6O_IAADDR));
+ if (!iaaddr) {
+ return;
+ }
+ // Get the IPv6 address acquired by the client.
+ IOAddress addr = iaaddr->getAddress();
+ std::string hostname = addr.toText();
+ // Colons may not be ok for FQDNs so let's replace them with hyphens.
+ std::replace(hostname.begin(), hostname.end(), ':', '-');
+ std::ostringstream stream;
+ // The final FQDN consists of the partial domain name and the suffix.
+ // For example, if the acquired address is 2001:db8:1::2, the generated
+ // FQDN may be:
+ // host-2001-db8:1--2.example.com.
+ // where prefix 'host' should be configurable. The domain name suffix
+ // should also be configurable.
+ stream << "host-" << hostname << "." << FQDN_PARTIAL_SUFFIX << ".";
+ try {
+ // The lease has been acquired but the FQDN for this lease hasn't
+ // been updated in the lease database. We now have new FQDN
+ // generated, so the lease database has to be updated here.
+ // However, never update lease database for Advertise, just send
+ // our notion of client's FQDN in the Client FQDN option.
+ if (answer->getType() != DHCPV6_ADVERTISE) {
+ Lease6Ptr lease =
+ LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
+ if (lease) {
+ lease->hostname_ = stream.str();
+ }
+ LeaseMgrFactory::instance().updateLease6(lease);
+ }
+
+ // Set the generated FQDN in the Client FQDN option.
+ fqdn->setDomainName(stream.str(), Option6ClientFqdn::FULL);
+
+ } catch (const Exception& ex) {
+ LOG_ERROR(dhcp6_logger, DHCP6_NAME_GEN_UPDATE_FAIL)
+ .arg(hostname)
+ .arg(ex.what());
+ }
+}
+
};
};
diff --git a/src/bin/dhcp6/dhcp6_srv.h b/src/bin/dhcp6/dhcp6_srv.h
index ce9fcd3..6fda705 100644
--- a/src/bin/dhcp6/dhcp6_srv.h
+++ b/src/bin/dhcp6/dhcp6_srv.h
@@ -527,6 +527,48 @@ private:
/// @param errmsg An error message containing a cause of the failure.
static void ifaceMgrSocket6ErrorHandler(const std::string& errmsg);
+ /// @brief Generate FQDN to be sent to a client if none exists.
+ ///
+ /// This function is meant to be called by the functions which process
+ /// client's messages. The function should be called after a function
+ /// which creates FQDN option for the client. This option must exist
+ /// in the answer message specified as an argument. It must also be
+ /// called after functions which assign leases for a client. The
+ /// IA options being a result of lease acquisition must be appended
+ /// to the message specified as a parameter.
+ ///
+ /// If the Client FQDN option being present in the message carries empty
+ /// hostname, this function will attempt to generate hostname from the
+ /// IPv6 address being acquired by the client. The IPv6 address is retrieved
+ /// from the IA_NA option carried in the specified message. If multiple
+ /// addresses are present in the particular IA_NA option or multiple IA_NA
+ /// options exist, the first address found is selected.
+ ///
+ /// The IPv6 address is converted to the hostname using the following
+ /// pattern:
+ /// @code
+ /// prefix-converted-ip-address.domain-name-suffix.
+ /// @endcode
+ /// where:
+ /// - prefix is a configurable prefix string appended to all auto-generated
+ /// hostnames.
+ /// - converted-ip-address is created by replacing all colons from the IPv6
+ /// address with hyphens.
+ /// - domain-name-suffix is a suffix for a domain name that, together with
+ /// the other parts, constitute the fully qualified domain name.
+ ///
+ /// When hostname is successfully generated, it is either used to update
+ /// FQDN-related fields in a lease database or to update the Client FQDN
+ /// option being sent back to the client. The lease database update is
+ /// NOT performed if Advertise message is being processed.
+ ///
+ /// @param answer Message being sent to a client, which may hold IA_NA
+ /// and Client FQDN options to be used to generate name for a client.
+ ///
+ /// @throw isc::Unexpected if specified message is NULL. This is treated
+ /// as a programmatic error.
+ void generateFqdn(const Pkt6Ptr& answer);
+
/// @brief Allocation Engine.
/// Pointer to the allocation engine that we are currently using
/// It must be a pointer, because we will support changing engines
diff --git a/src/bin/dhcp6/tests/fqdn_unittest.cc b/src/bin/dhcp6/tests/fqdn_unittest.cc
index bba8fc0..8b975c9 100644
--- a/src/bin/dhcp6/tests/fqdn_unittest.cc
+++ b/src/bin/dhcp6/tests/fqdn_unittest.cc
@@ -266,7 +266,19 @@ public:
EXPECT_EQ(flag_o, answ_fqdn->getFlag(Option6ClientFqdn::FLAG_O));
EXPECT_EQ(exp_domain_name, answ_fqdn->getDomainName());
- EXPECT_EQ(Option6ClientFqdn::FULL, answ_fqdn->getDomainNameType());
+ // If server is configured to generate full FQDN for a client, and/or
+ // client sent empty FQDN the expected result of the processing by
+ // processClientFqdn is an empty, partial FQDN. This is an indication
+ // for the code which performs lease allocation that the FQDN has to
+ // be generated from the lease address.
+ if (exp_domain_name.empty()) {
+ EXPECT_EQ(Option6ClientFqdn::PARTIAL,
+ answ_fqdn->getDomainNameType());
+
+ } else {
+ EXPECT_EQ(Option6ClientFqdn::FULL, answ_fqdn->getDomainNameType());
+
+ }
}
/// @brief Tests that the client's message holding an FQDN is processed
@@ -282,15 +294,18 @@ public:
/// that the server doesn't respond with the FQDN.
void testProcessMessage(const uint8_t msg_type,
const std::string& hostname,
+ const std::string& exp_hostname,
NakedDhcpv6Srv& srv,
const bool include_oro = true) {
// Create a message of a specified type, add server id and
// FQDN option.
OptionPtr srvid = srv.getServerID();
+ // Set the appropriate FQDN type. It must be partial if hostname is
+ // empty.
+ Option6ClientFqdn::DomainNameType fqdn_type = hostname.empty() ?
+ Option6ClientFqdn::PARTIAL : Option6ClientFqdn::FULL;
Pkt6Ptr req = generateMessage(msg_type, Option6ClientFqdn::FLAG_S,
- hostname,
- Option6ClientFqdn::FULL,
- include_oro, srvid);
+ hostname, fqdn_type, include_oro, srvid);
// For different client's message types we have to invoke different
// functions to generate response.
@@ -336,11 +351,15 @@ public:
Lease6Ptr lease =
checkLease(duid_, reply->getOption(D6O_IA_NA), addr);
ASSERT_TRUE(lease);
+ EXPECT_EQ(exp_hostname, lease->hostname_);
}
// The Client FQDN option should be always present in the server's
// response, regardless if requested using ORO or not.
- ASSERT_TRUE(reply->getOption(D6O_CLIENT_FQDN));
+ Option6ClientFqdnPtr fqdn;
+ ASSERT_TRUE(fqdn = boost::dynamic_pointer_cast<
+ Option6ClientFqdn>(reply->getOption(D6O_CLIENT_FQDN)));
+ EXPECT_EQ(exp_hostname, fqdn->getDomainName());
}
/// @brief Verify that NameChangeRequest holds valid values.
@@ -409,8 +428,7 @@ TEST_F(FqdnDhcpv6SrvTest, serverAAAAUpdatePartialName) {
// that server performs AAAA update.
TEST_F(FqdnDhcpv6SrvTest, serverAAAAUpdateNoName) {
testFqdn(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_S, "",
- Option6ClientFqdn::PARTIAL, Option6ClientFqdn::FLAG_S,
- "myhost.example.com.");
+ Option6ClientFqdn::PARTIAL, Option6ClientFqdn::FLAG_S, "");
}
// Test server's response when client requests no DNS update.
@@ -492,9 +510,8 @@ TEST_F(FqdnDhcpv6SrvTest, createNameChangeRequestsNoAddr) {
ASSERT_TRUE(srv.name_change_reqs_.empty());
}
-// Test that a number of NameChangeRequests is created as a result of
-// processing the answer message which holds 3 IAs and when FQDN is
-// specified.
+// Test that exactly one NameChangeRequest is created as a result of processing
+// the answer message which holds 3 IAs and when FQDN is specified.
TEST_F(FqdnDhcpv6SrvTest, createNameChangeRequests) {
NakedDhcpv6Srv srv(0);
@@ -514,32 +531,17 @@ TEST_F(FqdnDhcpv6SrvTest, createNameChangeRequests) {
Option6ClientFqdn::FULL);
answer->addOption(fqdn);
- // Create NameChangeRequests. Since we have added 3 IAs, it should
- // result in generation of 3 distinct NameChangeRequests.
+ // Create NameChangeRequest for the first allocated address.
ASSERT_NO_THROW(srv.createNameChangeRequests(answer));
- ASSERT_EQ(3, srv.name_change_reqs_.size());
-
- // Verify that NameChangeRequests are correct. Each call to the
- // verifyNameChangeRequest will pop verified request from the queue.
+ ASSERT_EQ(1, srv.name_change_reqs_.size());
+ // Verify that NameChangeRequest is correct.
verifyNameChangeRequest(srv, isc::dhcp_ddns::CHG_ADD, true, true,
"2001:db8:1::1",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
0, 500);
- verifyNameChangeRequest(srv, isc::dhcp_ddns::CHG_ADD, true, true,
- "2001:db8:1::2",
- "000201415AA33D1187D148275136FA30300478"
- "FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, 500);
-
- verifyNameChangeRequest(srv, isc::dhcp_ddns::CHG_ADD, true, true,
- "2001:db8:1::3",
- "000201415AA33D1187D148275136FA30300478"
- "FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, 500);
-
}
// Test creation of the NameChangeRequest to remove both forward and reverse
@@ -639,7 +641,8 @@ TEST_F(FqdnDhcpv6SrvTest, processSolicit) {
// Create a Solicit message with FQDN option and generate server's
// response using processSolicit function.
- testProcessMessage(DHCPV6_SOLICIT, "myhost.example.com", srv);
+ testProcessMessage(DHCPV6_SOLICIT, "myhost.example.com",
+ "myhost.example.com.", srv);
EXPECT_TRUE(srv.name_change_reqs_.empty());
}
@@ -654,7 +657,8 @@ TEST_F(FqdnDhcpv6SrvTest, processTwoRequests) {
// response using processRequest function. This will result in the
// creation of a new lease and the appropriate NameChangeRequest
// to add both reverse and forward mapping to DNS.
- testProcessMessage(DHCPV6_REQUEST, "myhost.example.com", srv);
+ testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
+ "myhost.example.com.", srv);
ASSERT_EQ(1, srv.name_change_reqs_.size());
verifyNameChangeRequest(srv, isc::dhcp_ddns::CHG_ADD, true, true,
"2001:db8:1:1::dead:beef",
@@ -669,7 +673,8 @@ TEST_F(FqdnDhcpv6SrvTest, processTwoRequests) {
// entries should be removed and the entries for the new domain-name
// should be added. Therefore, we expect two NameChangeRequests. One to
// remove the existing entries, one to add new entries.
- testProcessMessage(DHCPV6_REQUEST, "otherhost.example.com", srv);
+ testProcessMessage(DHCPV6_REQUEST, "otherhost.example.com",
+ "otherhost.example.com.", srv);
ASSERT_EQ(2, srv.name_change_reqs_.size());
verifyNameChangeRequest(srv, isc::dhcp_ddns::CHG_REMOVE, true, true,
"2001:db8:1:1::dead:beef",
@@ -684,6 +689,38 @@ TEST_F(FqdnDhcpv6SrvTest, processTwoRequests) {
}
+// Test that NameChangeRequest is not generated when Solicit message is sent.
+// The Solicit is here sent after a lease has been allocated for a client.
+// The Solicit conveys a different hostname which would trigger updates to
+// DNS if the Request was sent instead of Soicit. The code should differentiate
+// behavior depending whether Solicit or Request is sent.
+TEST_F(FqdnDhcpv6SrvTest, processRequestSolicit) {
+ NakedDhcpv6Srv srv(0);
+
+ // Create a Request message with FQDN option and generate server's
+ // response using processRequest function. This will result in the
+ // creation of a new lease and the appropriate NameChangeRequest
+ // to add both reverse and forward mapping to DNS.
+ testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
+ "myhost.example.com.", srv);
+ ASSERT_EQ(1, srv.name_change_reqs_.size());
+ verifyNameChangeRequest(srv, isc::dhcp_ddns::CHG_ADD, true, true,
+ "2001:db8:1:1::dead:beef",
+ "000201415AA33D1187D148275136FA30300478"
+ "FAAAA3EBD29826B5C907B2C9268A6F52",
+ 0, 4000);
+
+ // When the returning client sends Solicit the code should never generate
+ // NameChangeRequest and preserve existing DNS entries for the client.
+ // The NameChangeRequest should only be generated when a client sends
+ // Request or Renew.
+ testProcessMessage(DHCPV6_SOLICIT, "otherhost.example.com",
+ "otherhost.example.com.", srv);
+ ASSERT_TRUE(srv.name_change_reqs_.empty());
+
+}
+
+
// Test that client may send Request followed by the Renew, both holding
// FQDN options, but each option holding different domain-name. The Renew
// should result in generation of the two NameChangeRequests, one to remove
@@ -696,7 +733,8 @@ TEST_F(FqdnDhcpv6SrvTest, processRequestRenew) {
// response using processRequest function. This will result in the
// creation of a new lease and the appropriate NameChangeRequest
// to add both reverse and forward mapping to DNS.
- testProcessMessage(DHCPV6_REQUEST, "myhost.example.com", srv);
+ testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
+ "myhost.example.com.", srv);
ASSERT_EQ(1, srv.name_change_reqs_.size());
verifyNameChangeRequest(srv, isc::dhcp_ddns::CHG_ADD, true, true,
"2001:db8:1:1::dead:beef",
@@ -711,7 +749,8 @@ TEST_F(FqdnDhcpv6SrvTest, processRequestRenew) {
// entries should be removed and the entries for the new domain-name
// should be added. Therefore, we expect two NameChangeRequests. One to
// remove the existing entries, one to add new entries.
- testProcessMessage(DHCPV6_RENEW, "otherhost.example.com", srv);
+ testProcessMessage(DHCPV6_RENEW, "otherhost.example.com",
+ "otherhost.example.com.", srv);
ASSERT_EQ(2, srv.name_change_reqs_.size());
verifyNameChangeRequest(srv, isc::dhcp_ddns::CHG_REMOVE, true, true,
"2001:db8:1:1::dead:beef",
@@ -733,7 +772,8 @@ TEST_F(FqdnDhcpv6SrvTest, processRequestRelease) {
// response using processRequest function. This will result in the
// creation of a new lease and the appropriate NameChangeRequest
// to add both reverse and forward mapping to DNS.
- testProcessMessage(DHCPV6_REQUEST, "myhost.example.com", srv);
+ testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
+ "myhost.example.com.", srv);
ASSERT_EQ(1, srv.name_change_reqs_.size());
verifyNameChangeRequest(srv, isc::dhcp_ddns::CHG_ADD, true, true,
"2001:db8:1:1::dead:beef",
@@ -745,7 +785,8 @@ TEST_F(FqdnDhcpv6SrvTest, processRequestRelease) {
// removed and all existing DNS entries for this lease should be
// also removed. Therefore, we expect that single NameChangeRequest to
// remove DNS entries is generated.
- testProcessMessage(DHCPV6_RELEASE, "otherhost.example.com", srv);
+ testProcessMessage(DHCPV6_RELEASE, "otherhost.example.com",
+ "otherhost.example.com.", srv);
ASSERT_EQ(1, srv.name_change_reqs_.size());
verifyNameChangeRequest(srv, isc::dhcp_ddns::CHG_REMOVE, true, true,
"2001:db8:1:1::dead:beef",
@@ -763,7 +804,8 @@ TEST_F(FqdnDhcpv6SrvTest, processRequestWithoutFqdn) {
// The last parameter disables use of the ORO to request FQDN option
// In this case, we expect that the FQDN option will not be included
// in the server's response. The testProcessMessage will check that.
- testProcessMessage(DHCPV6_REQUEST, "myhost.example.com", srv, false);
+ testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
+ "myhost.example.com.", srv, false);
ASSERT_EQ(1, srv.name_change_reqs_.size());
verifyNameChangeRequest(srv, isc::dhcp_ddns::CHG_ADD, true, true,
"2001:db8:1:1::dead:beef",
@@ -772,6 +814,23 @@ TEST_F(FqdnDhcpv6SrvTest, processRequestWithoutFqdn) {
0, 4000);
}
+// Checks that FQDN is generated from an ip address, when client sends an empty
+// FQDN.
+TEST_F(FqdnDhcpv6SrvTest, processRequestEmptyFqdn) {
+ NakedDhcpv6Srv srv(0);
+
+ testProcessMessage(DHCPV6_REQUEST, "",
+ "host-2001-db8-1-1--dead-beef.example.com.",
+ srv, false);
+ ASSERT_EQ(1, srv.name_change_reqs_.size());
+ verifyNameChangeRequest(srv, isc::dhcp_ddns::CHG_ADD, true, true,
+ "2001:db8:1:1::dead:beef",
+ "0002018D6874B105A5C92DBBD6E4F6C80A93161"
+ "BC03996F0CD0EB75800DEF997C29961",
+ 0, 4000);
+
+}
+
// Checks that when the server reuses expired lease, the NameChangeRequest
// is generated to remove the DNS mapping for the expired lease and second
// NameChangeRequest to add a DNS mapping for a new lease.
@@ -790,7 +849,8 @@ TEST_F(FqdnDhcpv6SrvTest, processRequestReuseExpiredLease) {
// Allocate a lease.
NakedDhcpv6Srv srv(0);
- testProcessMessage(DHCPV6_REQUEST, "myhost.example.com", srv);
+ testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
+ "myhost.example.com.", srv);
// Test that the appropriate NameChangeRequest has been generated.
ASSERT_EQ(1, srv.name_change_reqs_.size());
verifyNameChangeRequest(srv, isc::dhcp_ddns::CHG_ADD, true, true,
@@ -822,7 +882,8 @@ TEST_F(FqdnDhcpv6SrvTest, processRequestReuseExpiredLease) {
// exactly one address and this address is used by the lease in the
// lease database, it is guaranteed that the allocation engine will
// reuse this lease.
- testProcessMessage(DHCPV6_REQUEST, "myhost.example.com.", srv);
+ testProcessMessage(DHCPV6_REQUEST, "myhost.example.com.",
+ "myhost.example.com.", srv);
ASSERT_EQ(2, srv.name_change_reqs_.size());
// The first name change request generated, should remove a DNS
// mapping for an expired lease.
diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc
index a154cc6..11b0700 100644
--- a/src/lib/dhcpsrv/alloc_engine.cc
+++ b/src/lib/dhcpsrv/alloc_engine.cc
@@ -432,6 +432,10 @@ AllocEngine::allocateLeases6(const Subnet6Ptr& subnet, const DuidPtr& duid,
rev_dns_update, hostname,
callout_handle, fake_allocation);
if (lease) {
+ // We are allocating a new lease (not renewing). So, the
+ // old lease should be NULL.
+ old_leases.push_back(Lease6Ptr());
+
Lease6Collection collection;
collection.push_back(lease);
return (collection);
@@ -444,7 +448,7 @@ AllocEngine::allocateLeases6(const Subnet6Ptr& subnet, const DuidPtr& duid,
if (existing->expired()) {
// Copy an existing, expired lease so as it can be returned
// to the caller.
- Lease6Ptr old_lease(new Lease6(*lease));
+ Lease6Ptr old_lease(new Lease6(*existing));
old_leases.push_back(old_lease);
existing = reuseExpiredLease(existing, subnet, duid, iaid,
diff --git a/src/lib/dhcpsrv/lease.cc b/src/lib/dhcpsrv/lease.cc
index a15d300..7bc71f9 100644
--- a/src/lib/dhcpsrv/lease.cc
+++ b/src/lib/dhcpsrv/lease.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
@@ -56,6 +56,13 @@ bool Lease::expired() const {
return (expire_time < time(NULL));
}
+bool
+Lease::hasIdenticalFqdn(const Lease& other) const {
+ return (hostname_ == other.hostname_ &&
+ fqdn_fwd_ == other.fqdn_fwd_ &&
+ fqdn_rev_ == other.fqdn_rev_);
+}
+
Lease4::Lease4(const Lease4& other)
: Lease(other.addr_, other.t1_, other.t2_, other.valid_lft_,
other.subnet_id_, other.cltt_, other.fqdn_fwd_,
diff --git a/src/lib/dhcpsrv/lease.h b/src/lib/dhcpsrv/lease.h
index 8626620..c767142 100644
--- a/src/lib/dhcpsrv/lease.h
+++ b/src/lib/dhcpsrv/lease.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
@@ -141,6 +141,14 @@ struct Lease {
/// @return true if the lease is expired
bool expired() const;
+ /// @brief Returns true if the other lease has equal FQDN data.
+ ///
+ /// @param other Lease which FQDN data is to be compared with our lease.
+ ///
+ /// @return Boolean value which indicates whether FQDN data of the other
+ /// lease is equal to the FQDN data of our lease (true) or not (false).
+ bool hasIdenticalFqdn(const Lease& other) const;
+
};
/// @brief Structure that holds a lease for IPv4 address
diff --git a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
index ab5a8b2..f8a4aed 100644
--- a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
@@ -251,17 +251,6 @@ public:
namespace {
-/// Hardware address used by different tests.
-const uint8_t HWADDR[] = {0x08, 0x00, 0x2b, 0x02, 0x3f, 0x4e};
-/// Client id used by different tests.
-const uint8_t CLIENTID[] = {0x17, 0x34, 0xe2, 0xff, 0x09, 0x92, 0x54};
-/// Valid lifetime value used by different tests.
-const uint32_t VALID_LIFETIME = 500;
-/// Subnet ID used by different tests.
-const uint32_t SUBNET_ID = 42;
-/// IAID value used by different tests.
-const uint32_t IAID = 7;
-
/// @brief getParameter test
///
/// This test checks if the LeaseMgr can be instantiated and that it
@@ -320,616 +309,6 @@ TEST_F(LeaseMgrTest, getLease6) {
// are purely virtual, so we would only call ConcreteLeaseMgr methods.
// Those methods are just stubs that do not return anything.
-/// @brief Lease4 Constructor Test
-///
-/// Lease4 is also defined in lease_mgr.h, so is tested in this file as well.
-// This test checks if the Lease4 structure can be instantiated correctly
-TEST(Lease4, constructor) {
-
- // Random values for the tests
- const uint8_t HWADDR[] = {0x08, 0x00, 0x2b, 0x02, 0x3f, 0x4e};
- std::vector<uint8_t> hwaddr(HWADDR, HWADDR + sizeof(HWADDR));
-
- const uint8_t CLIENTID[] = {0x17, 0x34, 0xe2, 0xff, 0x09, 0x92, 0x54};
- std::vector<uint8_t> clientid_vec(CLIENTID, CLIENTID + sizeof(CLIENTID));
- ClientId clientid(clientid_vec);
-
- // ...and a time
- const time_t current_time = time(NULL);
-
- // Other random constants.
- const uint32_t SUBNET_ID = 42;
- const uint32_t VALID_LIFETIME = 500;
-
- // We want to check that various addresses work, so let's iterate over
- // these.
- const uint32_t ADDRESS[] = {
- 0x00000000, 0x01020304, 0x7fffffff, 0x80000000, 0x80000001, 0xffffffff
- };
-
- for (int i = 0; i < sizeof(ADDRESS) / sizeof(ADDRESS[0]); ++i) {
-
- // Create the lease
- Lease4 lease(ADDRESS[i], HWADDR, sizeof(HWADDR),
- CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, 0, 0,
- current_time, SUBNET_ID, true, true,
- "hostname.example.com.");
-
- EXPECT_EQ(ADDRESS[i], static_cast<uint32_t>(lease.addr_));
- EXPECT_EQ(0, lease.ext_);
- EXPECT_TRUE(hwaddr == lease.hwaddr_);
- EXPECT_TRUE(clientid == *lease.client_id_);
- EXPECT_EQ(0, lease.t1_);
- EXPECT_EQ(0, lease.t2_);
- EXPECT_EQ(VALID_LIFETIME, lease.valid_lft_);
- EXPECT_EQ(current_time, lease.cltt_);
- EXPECT_EQ(SUBNET_ID, lease.subnet_id_);
- EXPECT_FALSE(lease.fixed_);
- EXPECT_EQ("hostname.example.com.", lease.hostname_);
- EXPECT_TRUE(lease.fqdn_fwd_);
- EXPECT_TRUE(lease.fqdn_rev_);
- EXPECT_TRUE(lease.comments_.empty());
- }
-}
-
-// This test verfies that copy constructor copies Lease4 fields correctly.
-TEST(Lease4, copyConstructor) {
-
- // Random values for the tests
- const uint8_t HWADDR[] = {0x08, 0x00, 0x2b, 0x02, 0x3f, 0x4e};
- std::vector<uint8_t> hwaddr(HWADDR, HWADDR + sizeof(HWADDR));
-
- const uint8_t CLIENTID[] = {0x17, 0x34, 0xe2, 0xff, 0x09, 0x92, 0x54};
- std::vector<uint8_t> clientid_vec(CLIENTID, CLIENTID + sizeof(CLIENTID));
- ClientId clientid(clientid_vec);
-
- // ...and a time
- const time_t current_time = time(NULL);
-
- // Other random constants.
- const uint32_t SUBNET_ID = 42;
- const uint32_t VALID_LIFETIME = 500;
-
- // Create the lease
- Lease4 lease(0xffffffff, HWADDR, sizeof(HWADDR),
- CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, 0, 0, current_time,
- SUBNET_ID);
-
- // Use copy constructor to copy the lease.
- Lease4 copied_lease(lease);
-
- // Both leases should be now equal. When doing this check we assume that
- // the equality operator works correctly.
- EXPECT_TRUE(lease == copied_lease);
- // Client IDs are equal, but they should be in two distinct pointers.
- EXPECT_FALSE(lease.client_id_ == copied_lease.client_id_);
-}
-
-// This test verfies that the assignment operator copies all Lease4 fields
-// correctly.
-TEST(Lease4, operatorAssign) {
-
- // Random values for the tests
- const uint8_t HWADDR[] = {0x08, 0x00, 0x2b, 0x02, 0x3f, 0x4e};
- std::vector<uint8_t> hwaddr(HWADDR, HWADDR + sizeof(HWADDR));
-
- const uint8_t CLIENTID[] = {0x17, 0x34, 0xe2, 0xff, 0x09, 0x92, 0x54};
- std::vector<uint8_t> clientid_vec(CLIENTID, CLIENTID + sizeof(CLIENTID));
- ClientId clientid(clientid_vec);
-
- // ...and a time
- const time_t current_time = time(NULL);
-
- // Other random constants.
- const uint32_t SUBNET_ID = 42;
- const uint32_t VALID_LIFETIME = 500;
-
- // Create the lease
- Lease4 lease(0xffffffff, HWADDR, sizeof(HWADDR),
- CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, 0, 0, current_time,
- SUBNET_ID);
-
- // Use assignment operator to assign the lease.
- Lease4 copied_lease = lease;
-
- // Both leases should be now equal. When doing this check we assume that
- // the equality operator works correctly.
- EXPECT_TRUE(lease == copied_lease);
- // Client IDs are equal, but they should be in two distinct pointers.
- EXPECT_FALSE(lease.client_id_ == copied_lease.client_id_);
-}
-
-// This test verifies that the matches() returns true if two leases differ
-// by values other than address, HW address, Client ID and ext_.
-TEST(Lease4, matches) {
- // Create two leases which share the same address, HW address, client id
- // and ext_ value.
- const time_t current_time = time(NULL);
- Lease4 lease1(IOAddress("192.0.2.3"), HWADDR, sizeof(HWADDR), CLIENTID,
- sizeof(CLIENTID), VALID_LIFETIME, current_time, 0, 0,
- SUBNET_ID);
- lease1.hostname_ = "lease1.example.com.";
- lease1.fqdn_fwd_ = true;
- lease1.fqdn_rev_ = true;
- Lease4 lease2(IOAddress("192.0.2.3"), HWADDR, sizeof(HWADDR), CLIENTID,
- sizeof(CLIENTID), VALID_LIFETIME + 10, current_time - 10,
- 100, 200, SUBNET_ID);
- lease2.hostname_ = "lease2.example.com.";
- lease2.fqdn_fwd_ = false;
- lease2.fqdn_rev_ = true;
-
- // Leases should match.
- EXPECT_TRUE(lease1.matches(lease2));
- EXPECT_TRUE(lease2.matches(lease1));
-
- // Change address, leases should not match anymore.
- lease1.addr_ = IOAddress("192.0.2.4");
- EXPECT_FALSE(lease1.matches(lease2));
- lease1.addr_ = lease2.addr_;
-
- // Change HW address, leases should not match.
- lease1.hwaddr_[1] += 1;
- EXPECT_FALSE(lease1.matches(lease2));
- lease1.hwaddr_ = lease2.hwaddr_;
-
- // Chanage client id, leases should not match.
- std::vector<uint8_t> client_id = lease1.client_id_->getClientId();
- client_id[1] += 1;
- lease1.client_id_.reset(new ClientId(client_id));
- EXPECT_FALSE(lease1.matches(lease2));
- lease1.client_id_ = lease2.client_id_;
-
- // Change ext_, leases should not match.
- lease1.ext_ += 1;
- EXPECT_FALSE(lease1.matches(lease2));
- lease1.ext_ = lease2.ext_;
-}
-
-/// @brief Lease4 Equality Test
-///
-/// Checks that the operator==() correctly compares two leases for equality.
-/// As operator!=() is also defined for this class, every check on operator==()
-/// is followed by the reverse check on operator!=().
-TEST(Lease4, operatorEquals) {
-
- // Random values for the tests
- const uint32_t ADDRESS = 0x01020304;
- const uint8_t HWADDR[] = {0x08, 0x00, 0x2b, 0x02, 0x3f, 0x4e};
- std::vector<uint8_t> hwaddr(HWADDR, HWADDR + sizeof(HWADDR));
- const uint8_t CLIENTID[] = {0x17, 0x34, 0xe2, 0xff, 0x09, 0x92, 0x54};
- std::vector<uint8_t> clientid_vec(CLIENTID, CLIENTID + sizeof(CLIENTID));
- ClientId clientid(clientid_vec);
- const time_t current_time = time(NULL);
- const uint32_t SUBNET_ID = 42;
- const uint32_t VALID_LIFETIME = 500;
-
- // Check when the leases are equal.
- Lease4 lease1(ADDRESS, HWADDR, sizeof(HWADDR),
- CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, current_time, 0,
- 0, SUBNET_ID);
- Lease4 lease2(ADDRESS, HWADDR, sizeof(HWADDR),
- CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, current_time, 0, 0,
- SUBNET_ID);
- EXPECT_TRUE(lease1 == lease2);
- EXPECT_FALSE(lease1 != lease2);
-
- // Now vary individual fields in a lease and check that the leases compare
- // not equal in every case.
- lease1.addr_ = IOAddress(ADDRESS + 1);
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.addr_ = lease2.addr_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.ext_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.ext_ = lease2.ext_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.hwaddr_[0];
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.hwaddr_ = lease2.hwaddr_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++clientid_vec[0];
- lease1.client_id_.reset(new ClientId(clientid_vec));
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- --clientid_vec[0];
- lease1.client_id_.reset(new ClientId(clientid_vec));
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.t1_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.t1_ = lease2.t1_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.t2_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.t2_ = lease2.t2_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.valid_lft_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.valid_lft_ = lease2.valid_lft_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.cltt_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.cltt_ = lease2.cltt_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.subnet_id_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.subnet_id_ = lease2.subnet_id_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- lease1.fixed_ = !lease1.fixed_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.fixed_ = lease2.fixed_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- lease1.hostname_ += string("Something random");
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.hostname_ = lease2.hostname_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- lease1.fqdn_fwd_ = !lease1.fqdn_fwd_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.fqdn_fwd_ = lease2.fqdn_fwd_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- lease1.fqdn_rev_ = !lease1.fqdn_rev_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.fqdn_rev_ = lease2.fqdn_rev_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- lease1.comments_ += string("Something random");
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.comments_ = lease2.comments_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-}
-
-
-
-// Lease6 is also defined in lease_mgr.h, so is tested in this file as well.
-// This test checks if the Lease6 structure can be instantiated correctly
-TEST(Lease6, Lease6ConstructorDefault) {
-
- // check a variety of addresses with different bits set.
- const char* ADDRESS[] = {
- "::", "::1", "2001:db8:1::456",
- "7fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
- "8000::", "8000::1",
- "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
- };
-
- // Other values
- uint8_t llt[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
- DuidPtr duid(new DUID(llt, sizeof(llt)));
- uint32_t iaid = 7; // Just a number
- SubnetID subnet_id = 8; // Just another number
-
- for (int i = 0; i < sizeof(ADDRESS) / sizeof(ADDRESS[0]); ++i) {
- IOAddress addr(ADDRESS[i]);
- Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr,
- duid, iaid, 100, 200, 50, 80,
- subnet_id));
-
- EXPECT_TRUE(lease->addr_ == addr);
- EXPECT_TRUE(*lease->duid_ == *duid);
- EXPECT_TRUE(lease->iaid_ == iaid);
- EXPECT_TRUE(lease->subnet_id_ == subnet_id);
- EXPECT_TRUE(lease->type_ == Lease::TYPE_NA);
- EXPECT_TRUE(lease->preferred_lft_ == 100);
- EXPECT_TRUE(lease->valid_lft_ == 200);
- EXPECT_TRUE(lease->t1_ == 50);
- EXPECT_TRUE(lease->t2_ == 80);
- EXPECT_FALSE(lease->fqdn_fwd_);
- EXPECT_FALSE(lease->fqdn_rev_);
- EXPECT_TRUE(lease->hostname_.empty());
-
- }
-
- // Lease6 must be instantiated with a DUID, not with NULL pointer
- IOAddress addr(ADDRESS[0]);
- Lease6Ptr lease2;
- EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr,
- DuidPtr(), iaid, 100, 200, 50, 80,
- subnet_id)), InvalidOperation);
-}
-
-// This test verifies that the Lease6 constructor which accepts FQDN data,
-// sets the data correctly for the lease.
-TEST(Lease6, Lease6ConstructorWithFQDN) {
-
- // check a variety of addresses with different bits set.
- const char* ADDRESS[] = {
- "::", "::1", "2001:db8:1::456",
- "7fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
- "8000::", "8000::1",
- "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
- };
-
- // Other values
- uint8_t llt[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
- DuidPtr duid(new DUID(llt, sizeof(llt)));
- uint32_t iaid = 7; // Just a number
- SubnetID subnet_id = 8; // Just another number
-
- for (int i = 0; i < sizeof(ADDRESS) / sizeof(ADDRESS[0]); ++i) {
- IOAddress addr(ADDRESS[i]);
- Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr,
- duid, iaid, 100, 200, 50, 80, subnet_id,
- true, true, "host.example.com."));
-
- EXPECT_TRUE(lease->addr_ == addr);
- EXPECT_TRUE(*lease->duid_ == *duid);
- EXPECT_TRUE(lease->iaid_ == iaid);
- EXPECT_TRUE(lease->subnet_id_ == subnet_id);
- EXPECT_TRUE(lease->type_ == Lease::TYPE_NA);
- EXPECT_TRUE(lease->preferred_lft_ == 100);
- EXPECT_TRUE(lease->valid_lft_ == 200);
- EXPECT_TRUE(lease->t1_ == 50);
- EXPECT_TRUE(lease->t2_ == 80);
- EXPECT_TRUE(lease->fqdn_fwd_);
- EXPECT_TRUE(lease->fqdn_rev_);
- EXPECT_EQ("host.example.com.", lease->hostname_);
- }
- // Lease6 must be instantiated with a DUID, not with NULL pointer
- IOAddress addr(ADDRESS[0]);
- Lease6Ptr lease2;
- EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr,
- DuidPtr(), iaid, 100, 200, 50, 80,
- subnet_id)), InvalidOperation);
-}
-
-// This test verifies that the matches() function returns true if two leases
-// differ by values other than address, type, prefix length, IAID and DUID.
-TEST(Lease6, matches) {
-
- // Create two matching leases.
- uint8_t llt[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
- DuidPtr duid(new DUID(llt, sizeof(llt)));
-
- Lease6 lease1(Lease6::TYPE_NA, IOAddress("2001:db8:1::1"), duid,
- IAID, 100, 200, 50, 80,
- SUBNET_ID);
- lease1.hostname_ = "lease1.example.com.";
- lease1.fqdn_fwd_ = true;
- lease1.fqdn_rev_ = true;
- Lease6 lease2(Lease6::TYPE_NA, IOAddress("2001:db8:1::1"), duid,
- IAID, 200, 300, 90, 70,
- SUBNET_ID);
- lease2.hostname_ = "lease1.example.com.";
- lease2.fqdn_fwd_ = false;
- lease2.fqdn_rev_ = true;
-
- EXPECT_TRUE(lease1.matches(lease2));
-
- // Modify each value used to match both leases, and make sure that
- // leases don't match.
-
- // Modify address.
- lease1.addr_ = IOAddress("2001:db8:1::2");
- EXPECT_FALSE(lease1.matches(lease2));
- lease1.addr_ = lease2.addr_;
-
- // Modify lease type.
- lease1.type_ = Lease6::TYPE_TA;
- EXPECT_FALSE(lease1.matches(lease2));
- lease1.type_ = lease2.type_;
-
- // Modify prefix length.
- lease1.prefixlen_ += 1;
- EXPECT_FALSE(lease1.matches(lease2));
- lease1.prefixlen_ = lease2.prefixlen_;
-
- // Modify IAID.
- lease1.iaid_ += 1;
- EXPECT_FALSE(lease1.matches(lease2));
- lease1.iaid_ = lease2.iaid_;
-
- // Modify DUID.
- llt[1] += 1;
- duid.reset(new DUID(llt, sizeof(llt)));
- lease1.duid_ = duid;
- EXPECT_FALSE(lease1.matches(lease2));
- lease1.duid_ = lease2.duid_;
-}
-
-/// @brief Lease6 Equality Test
-///
-/// Checks that the operator==() correctly compares two leases for equality.
-/// As operator!=() is also defined for this class, every check on operator==()
-/// is followed by the reverse check on operator!=().
-TEST(Lease6, OperatorEquals) {
-
- // check a variety of addresses with different bits set.
- const IOAddress addr("2001:db8:1::456");
- uint8_t duid_array[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
- DuidPtr duid(new DUID(duid_array, sizeof(duid_array)));
- uint32_t iaid = 7; // just a number
- SubnetID subnet_id = 8; // just another number
-
- // Check for equality.
- Lease6 lease1(Lease::TYPE_NA, addr, duid, iaid, 100, 200, 50, 80,
- subnet_id);
- Lease6 lease2(Lease::TYPE_NA, addr, duid, iaid, 100, 200, 50, 80,
- subnet_id);
-
- // cltt_ constructs with time(NULL), make sure they are always equal
- lease1.cltt_ = lease2.cltt_;
-
- EXPECT_TRUE(lease1 == lease2);
- EXPECT_FALSE(lease1 != lease2);
-
- // Go through and alter all the fields one by one
-
- lease1.addr_ = IOAddress("::1");
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.addr_ = lease2.addr_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- lease1.type_ = Lease::TYPE_PD;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.type_ = lease2.type_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.prefixlen_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.prefixlen_ = lease2.prefixlen_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.iaid_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.iaid_ = lease2.iaid_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++duid_array[0];
- lease1.duid_.reset(new DUID(duid_array, sizeof(duid_array)));
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- --duid_array[0];
- lease1.duid_.reset(new DUID(duid_array, sizeof(duid_array)));
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.preferred_lft_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.preferred_lft_ = lease2.preferred_lft_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.valid_lft_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.valid_lft_ = lease2.valid_lft_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.t1_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.t1_ = lease2.t1_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.t2_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.t2_ = lease2.t2_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.cltt_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.cltt_ = lease2.cltt_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- ++lease1.subnet_id_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.subnet_id_ = lease2.subnet_id_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- lease1.fixed_ = !lease1.fixed_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.fixed_ = lease2.fixed_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- lease1.hostname_ += string("Something random");
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.hostname_ = lease2.hostname_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- lease1.fqdn_fwd_ = !lease1.fqdn_fwd_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.fqdn_fwd_ = lease2.fqdn_fwd_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- lease1.fqdn_rev_ = !lease1.fqdn_rev_;
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.fqdn_rev_ = lease2.fqdn_rev_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-
- lease1.comments_ += string("Something random");
- EXPECT_FALSE(lease1 == lease2);
- EXPECT_TRUE(lease1 != lease2);
- lease1.comments_ = lease2.comments_;
- EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
- EXPECT_FALSE(lease1 != lease2); // ... leases equal
-}
-
-// Checks if lease expiration is calculated properly
-TEST(Lease6, Lease6Expired) {
- const IOAddress addr("2001:db8:1::456");
- const uint8_t duid_array[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
- const DuidPtr duid(new DUID(duid_array, sizeof(duid_array)));
- const uint32_t iaid = 7; // Just a number
- const SubnetID subnet_id = 8; // Just another number
- Lease6 lease(Lease::TYPE_NA, addr, duid, iaid, 100, 200, 50, 80,
- subnet_id);
-
- // Case 1: a second before expiration
- lease.cltt_ = time(NULL) - 100;
- lease.valid_lft_ = 101;
- EXPECT_FALSE(lease.expired());
-
- // Case 2: the lease will expire after this second is concluded
- lease.cltt_ = time(NULL) - 101;
- EXPECT_FALSE(lease.expired());
-
- // Case 3: the lease is expired
- lease.cltt_ = time(NULL) - 102;
- EXPECT_TRUE(lease.expired());
-}
}; // end of anonymous namespace
diff --git a/src/lib/dhcpsrv/tests/lease_unittest.cc b/src/lib/dhcpsrv/tests/lease_unittest.cc
index 6f57f30..0b57dac 100644
--- a/src/lib/dhcpsrv/tests/lease_unittest.cc
+++ b/src/lib/dhcpsrv/tests/lease_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
@@ -13,23 +13,342 @@
// PERFORMANCE OF THIS SOFTWARE.
#include <config.h>
+#include <asiolink/io_address.h>
#include <dhcp/duid.h>
#include <dhcpsrv/lease.h>
#include <gtest/gtest.h>
#include <vector>
using namespace isc;
+using namespace isc::asiolink;
using namespace isc::dhcp;
namespace {
-// @todo Currently this file contains tests for new functions which return DUID
-// or client identifier. Other tests for Lease objects must be implemented.
-// See http://bind10.isc.org/ticket/3240.
+/// Hardware address used by different tests.
+const uint8_t HWADDR[] = {0x08, 0x00, 0x2b, 0x02, 0x3f, 0x4e};
+/// Client id used by different tests.
+const uint8_t CLIENTID[] = {0x17, 0x34, 0xe2, 0xff, 0x09, 0x92, 0x54};
+/// Valid lifetime value used by different tests.
+const uint32_t VALID_LIFETIME = 500;
+/// Subnet ID used by different tests.
+const uint32_t SUBNET_ID = 42;
+/// IAID value used by different tests.
+const uint32_t IAID = 7;
+
+/// @brief Creates an instance of the lease with certain FQDN data.
+///
+/// @param hostname Hostname.
+/// @param fqdn_fwd Forward FQDN update setting for a created lease.
+/// @param fqdn_rev Reverse FQDN update setting for a created lease.
+///
+/// @return Instance of the created lease.
+Lease4 createLease4(const std::string& hostname, const bool fqdn_fwd,
+ const bool fqdn_rev) {
+ Lease4 lease;
+ lease.hostname_ = hostname;
+ lease.fqdn_fwd_ = fqdn_fwd;
+ lease.fqdn_rev_ = fqdn_rev;
+ return (lease);
+}
+
+/// Lease4 is also defined in lease_mgr.h, so is tested in this file as well.
+// This test checks if the Lease4 structure can be instantiated correctly
+TEST(Lease4, constructor) {
+
+ // Random values for the tests
+ const uint8_t HWADDR[] = {0x08, 0x00, 0x2b, 0x02, 0x3f, 0x4e};
+ std::vector<uint8_t> hwaddr(HWADDR, HWADDR + sizeof(HWADDR));
+
+ const uint8_t CLIENTID[] = {0x17, 0x34, 0xe2, 0xff, 0x09, 0x92, 0x54};
+ std::vector<uint8_t> clientid_vec(CLIENTID, CLIENTID + sizeof(CLIENTID));
+ ClientId clientid(clientid_vec);
+
+ // ...and a time
+ const time_t current_time = time(NULL);
+
+ // Other random constants.
+ const uint32_t SUBNET_ID = 42;
+ const uint32_t VALID_LIFETIME = 500;
+
+ // We want to check that various addresses work, so let's iterate over
+ // these.
+ const uint32_t ADDRESS[] = {
+ 0x00000000, 0x01020304, 0x7fffffff, 0x80000000, 0x80000001, 0xffffffff
+ };
+
+ for (int i = 0; i < sizeof(ADDRESS) / sizeof(ADDRESS[0]); ++i) {
+
+ // Create the lease
+ Lease4 lease(ADDRESS[i], HWADDR, sizeof(HWADDR),
+ CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, 0, 0,
+ current_time, SUBNET_ID, true, true,
+ "hostname.example.com.");
+
+ EXPECT_EQ(ADDRESS[i], static_cast<uint32_t>(lease.addr_));
+ EXPECT_EQ(0, lease.ext_);
+ EXPECT_TRUE(hwaddr == lease.hwaddr_);
+ EXPECT_TRUE(clientid == *lease.client_id_);
+ EXPECT_EQ(0, lease.t1_);
+ EXPECT_EQ(0, lease.t2_);
+ EXPECT_EQ(VALID_LIFETIME, lease.valid_lft_);
+ EXPECT_EQ(current_time, lease.cltt_);
+ EXPECT_EQ(SUBNET_ID, lease.subnet_id_);
+ EXPECT_FALSE(lease.fixed_);
+ EXPECT_EQ("hostname.example.com.", lease.hostname_);
+ EXPECT_TRUE(lease.fqdn_fwd_);
+ EXPECT_TRUE(lease.fqdn_rev_);
+ EXPECT_TRUE(lease.comments_.empty());
+ }
+}
+
+// This test verfies that copy constructor copies Lease4 fields correctly.
+TEST(Lease4, copyConstructor) {
+
+ // Random values for the tests
+ const uint8_t HWADDR[] = {0x08, 0x00, 0x2b, 0x02, 0x3f, 0x4e};
+ std::vector<uint8_t> hwaddr(HWADDR, HWADDR + sizeof(HWADDR));
+
+ const uint8_t CLIENTID[] = {0x17, 0x34, 0xe2, 0xff, 0x09, 0x92, 0x54};
+ std::vector<uint8_t> clientid_vec(CLIENTID, CLIENTID + sizeof(CLIENTID));
+ ClientId clientid(clientid_vec);
+
+ // ...and a time
+ const time_t current_time = time(NULL);
+
+ // Other random constants.
+ const uint32_t SUBNET_ID = 42;
+ const uint32_t VALID_LIFETIME = 500;
+
+ // Create the lease
+ Lease4 lease(0xffffffff, HWADDR, sizeof(HWADDR),
+ CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, 0, 0, current_time,
+ SUBNET_ID);
+
+ // Use copy constructor to copy the lease.
+ Lease4 copied_lease(lease);
+
+ // Both leases should be now equal. When doing this check we assume that
+ // the equality operator works correctly.
+ EXPECT_TRUE(lease == copied_lease);
+ // Client IDs are equal, but they should be in two distinct pointers.
+ EXPECT_FALSE(lease.client_id_ == copied_lease.client_id_);
+}
+
+// This test verfies that the assignment operator copies all Lease4 fields
+// correctly.
+TEST(Lease4, operatorAssign) {
+
+ // Random values for the tests
+ const uint8_t HWADDR[] = {0x08, 0x00, 0x2b, 0x02, 0x3f, 0x4e};
+ std::vector<uint8_t> hwaddr(HWADDR, HWADDR + sizeof(HWADDR));
+
+ const uint8_t CLIENTID[] = {0x17, 0x34, 0xe2, 0xff, 0x09, 0x92, 0x54};
+ std::vector<uint8_t> clientid_vec(CLIENTID, CLIENTID + sizeof(CLIENTID));
+ ClientId clientid(clientid_vec);
+
+ // ...and a time
+ const time_t current_time = time(NULL);
+
+ // Other random constants.
+ const uint32_t SUBNET_ID = 42;
+ const uint32_t VALID_LIFETIME = 500;
+
+ // Create the lease
+ Lease4 lease(0xffffffff, HWADDR, sizeof(HWADDR),
+ CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, 0, 0, current_time,
+ SUBNET_ID);
+
+ // Use assignment operator to assign the lease.
+ Lease4 copied_lease = lease;
+
+ // Both leases should be now equal. When doing this check we assume that
+ // the equality operator works correctly.
+ EXPECT_TRUE(lease == copied_lease);
+ // Client IDs are equal, but they should be in two distinct pointers.
+ EXPECT_FALSE(lease.client_id_ == copied_lease.client_id_);
+}
+
+// This test verifies that the matches() returns true if two leases differ
+// by values other than address, HW address, Client ID and ext_.
+TEST(Lease4, matches) {
+ // Create two leases which share the same address, HW address, client id
+ // and ext_ value.
+ const time_t current_time = time(NULL);
+ Lease4 lease1(IOAddress("192.0.2.3"), HWADDR, sizeof(HWADDR), CLIENTID,
+ sizeof(CLIENTID), VALID_LIFETIME, current_time, 0, 0,
+ SUBNET_ID);
+ lease1.hostname_ = "lease1.example.com.";
+ lease1.fqdn_fwd_ = true;
+ lease1.fqdn_rev_ = true;
+ Lease4 lease2(IOAddress("192.0.2.3"), HWADDR, sizeof(HWADDR), CLIENTID,
+ sizeof(CLIENTID), VALID_LIFETIME + 10, current_time - 10,
+ 100, 200, SUBNET_ID);
+ lease2.hostname_ = "lease2.example.com.";
+ lease2.fqdn_fwd_ = false;
+ lease2.fqdn_rev_ = true;
+
+ // Leases should match.
+ EXPECT_TRUE(lease1.matches(lease2));
+ EXPECT_TRUE(lease2.matches(lease1));
+
+ // Change address, leases should not match anymore.
+ lease1.addr_ = IOAddress("192.0.2.4");
+ EXPECT_FALSE(lease1.matches(lease2));
+ lease1.addr_ = lease2.addr_;
+
+ // Change HW address, leases should not match.
+ lease1.hwaddr_[1] += 1;
+ EXPECT_FALSE(lease1.matches(lease2));
+ lease1.hwaddr_ = lease2.hwaddr_;
+
+ // Chanage client id, leases should not match.
+ std::vector<uint8_t> client_id = lease1.client_id_->getClientId();
+ client_id[1] += 1;
+ lease1.client_id_.reset(new ClientId(client_id));
+ EXPECT_FALSE(lease1.matches(lease2));
+ lease1.client_id_ = lease2.client_id_;
+
+ // Change ext_, leases should not match.
+ lease1.ext_ += 1;
+ EXPECT_FALSE(lease1.matches(lease2));
+ lease1.ext_ = lease2.ext_;
+}
+
+/// @brief Lease4 Equality Test
+///
+/// Checks that the operator==() correctly compares two leases for equality.
+/// As operator!=() is also defined for this class, every check on operator==()
+/// is followed by the reverse check on operator!=().
+TEST(Lease4, operatorEquals) {
+
+ // Random values for the tests
+ const uint32_t ADDRESS = 0x01020304;
+ const uint8_t HWADDR[] = {0x08, 0x00, 0x2b, 0x02, 0x3f, 0x4e};
+ std::vector<uint8_t> hwaddr(HWADDR, HWADDR + sizeof(HWADDR));
+ const uint8_t CLIENTID[] = {0x17, 0x34, 0xe2, 0xff, 0x09, 0x92, 0x54};
+ std::vector<uint8_t> clientid_vec(CLIENTID, CLIENTID + sizeof(CLIENTID));
+ ClientId clientid(clientid_vec);
+ const time_t current_time = time(NULL);
+ const uint32_t SUBNET_ID = 42;
+ const uint32_t VALID_LIFETIME = 500;
+
+ // Check when the leases are equal.
+ Lease4 lease1(ADDRESS, HWADDR, sizeof(HWADDR),
+ CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, current_time, 0,
+ 0, SUBNET_ID);
+ Lease4 lease2(ADDRESS, HWADDR, sizeof(HWADDR),
+ CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, current_time, 0, 0,
+ SUBNET_ID);
+ EXPECT_TRUE(lease1 == lease2);
+ EXPECT_FALSE(lease1 != lease2);
+
+ // Now vary individual fields in a lease and check that the leases compare
+ // not equal in every case.
+ lease1.addr_ = IOAddress(ADDRESS + 1);
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.addr_ = lease2.addr_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.ext_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.ext_ = lease2.ext_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.hwaddr_[0];
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.hwaddr_ = lease2.hwaddr_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++clientid_vec[0];
+ lease1.client_id_.reset(new ClientId(clientid_vec));
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ --clientid_vec[0];
+ lease1.client_id_.reset(new ClientId(clientid_vec));
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.t1_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.t1_ = lease2.t1_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.t2_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.t2_ = lease2.t2_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.valid_lft_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.valid_lft_ = lease2.valid_lft_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.cltt_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.cltt_ = lease2.cltt_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.subnet_id_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.subnet_id_ = lease2.subnet_id_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ lease1.fixed_ = !lease1.fixed_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.fixed_ = lease2.fixed_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ lease1.hostname_ += std::string("Something random");
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.hostname_ = lease2.hostname_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ lease1.fqdn_fwd_ = !lease1.fqdn_fwd_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.fqdn_fwd_ = lease2.fqdn_fwd_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ lease1.fqdn_rev_ = !lease1.fqdn_rev_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.fqdn_rev_ = lease2.fqdn_rev_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ lease1.comments_ += std::string("Something random");
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.comments_ = lease2.comments_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+}
// Verify that the client id can be returned as a vector object and if client
// id is NULL the empty vector is returned.
-TEST(Lease4Test, getClientIdVector) {
+TEST(Lease4, getClientIdVector) {
// Create a lease.
Lease4 lease;
// By default, the lease should have client id set to NULL. If it doesn't,
@@ -47,9 +366,356 @@ TEST(Lease4Test, getClientIdVector) {
EXPECT_TRUE(returned_vec == client_id_vec);
}
+// Verify the behavior of the function which checks FQDN data for equality.
+TEST(Lease4, hasIdenticalFqdn) {
+ Lease4 lease = createLease4("myhost.example.com.", true, true);
+ EXPECT_TRUE(lease.hasIdenticalFqdn(createLease4("myhost.example.com.",
+ true, true)));
+ EXPECT_FALSE(lease.hasIdenticalFqdn(createLease4("other.example.com.",
+ true, true)));
+ EXPECT_FALSE(lease.hasIdenticalFqdn(createLease4("myhost.example.com.",
+ false, true)));
+ EXPECT_FALSE(lease.hasIdenticalFqdn(createLease4("myhost.example.com.",
+ true, false)));
+ EXPECT_FALSE(lease.hasIdenticalFqdn(createLease4("myhost.example.com.",
+ false, false)));
+ EXPECT_FALSE(lease.hasIdenticalFqdn(createLease4("other.example.com.",
+ false, false)));
+}
+
+/// @brief Creates an instance of the lease with certain FQDN data.
+///
+/// @param hostname Hostname.
+/// @param fqdn_fwd Forward FQDN update setting for a created lease.
+/// @param fqdn_rev Reverse FQDN update setting for a created lease.
+///
+/// @return Instance of the created lease.
+Lease6 createLease6(const std::string& hostname, const bool fqdn_fwd,
+ const bool fqdn_rev) {
+ Lease6 lease;
+ lease.hostname_ = hostname;
+ lease.fqdn_fwd_ = fqdn_fwd;
+ lease.fqdn_rev_ = fqdn_rev;
+ return (lease);
+}
+
+// Lease6 is also defined in lease_mgr.h, so is tested in this file as well.
+// This test checks if the Lease6 structure can be instantiated correctly
+TEST(Lease6, Lease6ConstructorDefault) {
+
+ // check a variety of addresses with different bits set.
+ const char* ADDRESS[] = {
+ "::", "::1", "2001:db8:1::456",
+ "7fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
+ "8000::", "8000::1",
+ "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
+ };
+
+ // Other values
+ uint8_t llt[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
+ DuidPtr duid(new DUID(llt, sizeof(llt)));
+ uint32_t iaid = 7; // Just a number
+ SubnetID subnet_id = 8; // Just another number
+
+ for (int i = 0; i < sizeof(ADDRESS) / sizeof(ADDRESS[0]); ++i) {
+ IOAddress addr(ADDRESS[i]);
+ Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr,
+ duid, iaid, 100, 200, 50, 80,
+ subnet_id));
+
+ EXPECT_TRUE(lease->addr_ == addr);
+ EXPECT_TRUE(*lease->duid_ == *duid);
+ EXPECT_TRUE(lease->iaid_ == iaid);
+ EXPECT_TRUE(lease->subnet_id_ == subnet_id);
+ EXPECT_TRUE(lease->type_ == Lease::TYPE_NA);
+ EXPECT_TRUE(lease->preferred_lft_ == 100);
+ EXPECT_TRUE(lease->valid_lft_ == 200);
+ EXPECT_TRUE(lease->t1_ == 50);
+ EXPECT_TRUE(lease->t2_ == 80);
+ EXPECT_FALSE(lease->fqdn_fwd_);
+ EXPECT_FALSE(lease->fqdn_rev_);
+ EXPECT_TRUE(lease->hostname_.empty());
+
+ }
+
+ // Lease6 must be instantiated with a DUID, not with NULL pointer
+ IOAddress addr(ADDRESS[0]);
+ Lease6Ptr lease2;
+ EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr,
+ DuidPtr(), iaid, 100, 200, 50, 80,
+ subnet_id)), InvalidOperation);
+}
+
+// This test verifies that the Lease6 constructor which accepts FQDN data,
+// sets the data correctly for the lease.
+TEST(Lease6, Lease6ConstructorWithFQDN) {
+
+ // check a variety of addresses with different bits set.
+ const char* ADDRESS[] = {
+ "::", "::1", "2001:db8:1::456",
+ "7fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
+ "8000::", "8000::1",
+ "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
+ };
+
+ // Other values
+ uint8_t llt[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
+ DuidPtr duid(new DUID(llt, sizeof(llt)));
+ uint32_t iaid = 7; // Just a number
+ SubnetID subnet_id = 8; // Just another number
+
+ for (int i = 0; i < sizeof(ADDRESS) / sizeof(ADDRESS[0]); ++i) {
+ IOAddress addr(ADDRESS[i]);
+ Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr,
+ duid, iaid, 100, 200, 50, 80, subnet_id,
+ true, true, "host.example.com."));
+
+ EXPECT_TRUE(lease->addr_ == addr);
+ EXPECT_TRUE(*lease->duid_ == *duid);
+ EXPECT_TRUE(lease->iaid_ == iaid);
+ EXPECT_TRUE(lease->subnet_id_ == subnet_id);
+ EXPECT_TRUE(lease->type_ == Lease::TYPE_NA);
+ EXPECT_TRUE(lease->preferred_lft_ == 100);
+ EXPECT_TRUE(lease->valid_lft_ == 200);
+ EXPECT_TRUE(lease->t1_ == 50);
+ EXPECT_TRUE(lease->t2_ == 80);
+ EXPECT_TRUE(lease->fqdn_fwd_);
+ EXPECT_TRUE(lease->fqdn_rev_);
+ EXPECT_EQ("host.example.com.", lease->hostname_);
+ }
+
+ // Lease6 must be instantiated with a DUID, not with NULL pointer
+ IOAddress addr(ADDRESS[0]);
+ Lease6Ptr lease2;
+ EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr,
+ DuidPtr(), iaid, 100, 200, 50, 80,
+ subnet_id)), InvalidOperation);
+}
+
+// This test verifies that the matches() function returns true if two leases
+// differ by values other than address, type, prefix length, IAID and DUID.
+TEST(Lease6, matches) {
+
+ // Create two matching leases.
+ uint8_t llt[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
+ DuidPtr duid(new DUID(llt, sizeof(llt)));
+
+ Lease6 lease1(Lease6::TYPE_NA, IOAddress("2001:db8:1::1"), duid,
+ IAID, 100, 200, 50, 80,
+ SUBNET_ID);
+ lease1.hostname_ = "lease1.example.com.";
+ lease1.fqdn_fwd_ = true;
+ lease1.fqdn_rev_ = true;
+ Lease6 lease2(Lease6::TYPE_NA, IOAddress("2001:db8:1::1"), duid,
+ IAID, 200, 300, 90, 70,
+ SUBNET_ID);
+ lease2.hostname_ = "lease1.example.com.";
+ lease2.fqdn_fwd_ = false;
+ lease2.fqdn_rev_ = true;
+
+ EXPECT_TRUE(lease1.matches(lease2));
+
+ // Modify each value used to match both leases, and make sure that
+ // leases don't match.
+
+ // Modify address.
+ lease1.addr_ = IOAddress("2001:db8:1::2");
+ EXPECT_FALSE(lease1.matches(lease2));
+ lease1.addr_ = lease2.addr_;
+
+ // Modify lease type.
+ lease1.type_ = Lease6::TYPE_TA;
+ EXPECT_FALSE(lease1.matches(lease2));
+ lease1.type_ = lease2.type_;
+
+ // Modify prefix length.
+ lease1.prefixlen_ += 1;
+ EXPECT_FALSE(lease1.matches(lease2));
+ lease1.prefixlen_ = lease2.prefixlen_;
+
+ // Modify IAID.
+ lease1.iaid_ += 1;
+ EXPECT_FALSE(lease1.matches(lease2));
+ lease1.iaid_ = lease2.iaid_;
+
+ // Modify DUID.
+ llt[1] += 1;
+ duid.reset(new DUID(llt, sizeof(llt)));
+ lease1.duid_ = duid;
+ EXPECT_FALSE(lease1.matches(lease2));
+ lease1.duid_ = lease2.duid_;
+}
+
+/// @brief Lease6 Equality Test
+///
+/// Checks that the operator==() correctly compares two leases for equality.
+/// As operator!=() is also defined for this class, every check on operator==()
+/// is followed by the reverse check on operator!=().
+TEST(Lease6, OperatorEquals) {
+
+ // check a variety of addresses with different bits set.
+ const IOAddress addr("2001:db8:1::456");
+ uint8_t duid_array[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
+ DuidPtr duid(new DUID(duid_array, sizeof(duid_array)));
+ uint32_t iaid = 7; // just a number
+ SubnetID subnet_id = 8; // just another number
+
+ // Check for equality.
+ Lease6 lease1(Lease::TYPE_NA, addr, duid, iaid, 100, 200, 50, 80,
+ subnet_id);
+ Lease6 lease2(Lease::TYPE_NA, addr, duid, iaid, 100, 200, 50, 80,
+ subnet_id);
+
+ // cltt_ constructs with time(NULL), make sure they are always equal
+ lease1.cltt_ = lease2.cltt_;
+
+ EXPECT_TRUE(lease1 == lease2);
+ EXPECT_FALSE(lease1 != lease2);
+
+ // Go through and alter all the fields one by one
+
+ lease1.addr_ = IOAddress("::1");
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.addr_ = lease2.addr_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ lease1.type_ = Lease::TYPE_PD;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.type_ = lease2.type_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.prefixlen_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.prefixlen_ = lease2.prefixlen_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.iaid_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.iaid_ = lease2.iaid_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++duid_array[0];
+ lease1.duid_.reset(new DUID(duid_array, sizeof(duid_array)));
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ --duid_array[0];
+ lease1.duid_.reset(new DUID(duid_array, sizeof(duid_array)));
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.preferred_lft_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.preferred_lft_ = lease2.preferred_lft_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.valid_lft_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.valid_lft_ = lease2.valid_lft_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.t1_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.t1_ = lease2.t1_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.t2_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.t2_ = lease2.t2_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.cltt_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.cltt_ = lease2.cltt_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ ++lease1.subnet_id_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.subnet_id_ = lease2.subnet_id_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ lease1.fixed_ = !lease1.fixed_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.fixed_ = lease2.fixed_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ lease1.hostname_ += std::string("Something random");
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.hostname_ = lease2.hostname_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ lease1.fqdn_fwd_ = !lease1.fqdn_fwd_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.fqdn_fwd_ = lease2.fqdn_fwd_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ lease1.fqdn_rev_ = !lease1.fqdn_rev_;
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.fqdn_rev_ = lease2.fqdn_rev_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+
+ lease1.comments_ += std::string("Something random");
+ EXPECT_FALSE(lease1 == lease2);
+ EXPECT_TRUE(lease1 != lease2);
+ lease1.comments_ = lease2.comments_;
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
+}
+
+// Checks if lease expiration is calculated properly
+TEST(Lease6, Lease6Expired) {
+ const IOAddress addr("2001:db8:1::456");
+ const uint8_t duid_array[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
+ const DuidPtr duid(new DUID(duid_array, sizeof(duid_array)));
+ const uint32_t iaid = 7; // Just a number
+ const SubnetID subnet_id = 8; // Just another number
+ Lease6 lease(Lease::TYPE_NA, addr, duid, iaid, 100, 200, 50, 80,
+ subnet_id);
+
+ // Case 1: a second before expiration
+ lease.cltt_ = time(NULL) - 100;
+ lease.valid_lft_ = 101;
+ EXPECT_FALSE(lease.expired());
+
+ // Case 2: the lease will expire after this second is concluded
+ lease.cltt_ = time(NULL) - 101;
+ EXPECT_FALSE(lease.expired());
+
+ // Case 3: the lease is expired
+ lease.cltt_ = time(NULL) - 102;
+ EXPECT_TRUE(lease.expired());
+}
+
// Verify that the DUID can be returned as a vector object and if DUID is NULL
// the empty vector is returned.
-TEST(Lease6Test, getDuidVector) {
+TEST(Lease6, getDuidVector) {
// Create a lease.
Lease6 lease;
// By default, the lease should have client id set to NULL. If it doesn't,
@@ -67,5 +733,21 @@ TEST(Lease6Test, getDuidVector) {
EXPECT_TRUE(returned_vec == duid_vec);
}
+// Verify the behavior of the function which checks FQDN data for equality.
+TEST(Lease6, hasIdenticalFqdn) {
+ Lease6 lease = createLease6("myhost.example.com.", true, true);
+ EXPECT_TRUE(lease.hasIdenticalFqdn(createLease4("myhost.example.com.",
+ true, true)));
+ EXPECT_FALSE(lease.hasIdenticalFqdn(createLease4("other.example.com.",
+ true, true)));
+ EXPECT_FALSE(lease.hasIdenticalFqdn(createLease4("myhost.example.com.",
+ false, true)));
+ EXPECT_FALSE(lease.hasIdenticalFqdn(createLease4("myhost.example.com.",
+ true, false)));
+ EXPECT_FALSE(lease.hasIdenticalFqdn(createLease4("myhost.example.com.",
+ false, false)));
+ EXPECT_FALSE(lease.hasIdenticalFqdn(createLease4("other.example.com.",
+ false, false)));
+}
}; // end of anonymous namespace
More information about the bind10-changes
mailing list