" \"fqdn\" : \"example.com.\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"0102030405060708\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-exists-with-dhcid\""
"}";
// Verify that construction with wrong change type fails.
EXPECT_THROW(CheckExistsAddTransaction(io_service, ncr,
- forward_domain, reverse_domain, cfg_mgr),
- CheckExistsAddTransactionError);
+ forward_domain, reverse_domain, cfg_mgr),
+ CheckExistsAddTransactionError);
// Verify that a valid construction attempt works.
ncr->setChangeType(isc::dhcp_ddns::CHG_ADD);
EXPECT_NO_THROW(CheckExistsAddTransaction(io_service, ncr,
- forward_domain, reverse_domain,
- cfg_mgr));
+ forward_domain, reverse_domain,
+ cfg_mgr));
+}
+
+/// @brief Tests CheckExistsAddTransaction construction.
+/// This test verifies that valid construction functions properly if extra
+/// parameters are present.
+TEST(CheckExistsAddTransaction, constructionWithExtra) {
+ asiolink::IOServicePtr io_service(new isc::asiolink::IOService());
+ D2CfgMgrPtr cfg_mgr(new D2CfgMgr());
+
+ const char* msg_str =
+ "{"
+ " \"change-type\" : 1 , "
+ " \"forward-change\" : true , "
+ " \"reverse-change\" : true , "
+ " \"fqdn\" : \"example.com.\" , "
+ " \"ip-address\" : \"192.168.2.1\" , "
+ " \"dhcid\" : \"0102030405060708\" , "
+ " \"extra\" : \"19700101000000\" , "
+ " \"lease-length\" : 1300, "
+ " \"conflict-resolution-mode\" : \"check-exists-with-dhcid\""
+ "}";
+
+ dhcp_ddns::NameChangeRequestPtr ncr;
+ DnsServerInfoStoragePtr servers;
+ DdnsDomainPtr forward_domain;
+ DdnsDomainPtr reverse_domain;
+ DdnsDomainPtr empty_domain;
+
+ ASSERT_NO_THROW(ncr = dhcp_ddns::NameChangeRequest::fromJSON(msg_str));
+ ASSERT_NO_THROW(forward_domain.reset(new DdnsDomain("*", servers)));
+ ASSERT_NO_THROW(reverse_domain.reset(new DdnsDomain("*", servers)));
+
+ // Verify that a valid construction attempt works.
+ ncr->setChangeType(isc::dhcp_ddns::CHG_ADD);
+ EXPECT_NO_THROW(CheckExistsAddTransaction(io_service, ncr,
+ forward_domain, reverse_domain,
+ cfg_mgr));
}
/// @brief Tests event and state dictionary construction and verification.
" \"fqdn\" : \"example.com.\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"0102030405060708\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-exists-with-dhcid\""
"}";
// Verify that construction with wrong change type fails.
EXPECT_THROW(CheckExistsRemoveTransaction(io_service, ncr,
- forward_domain, reverse_domain, cfg_mgr),
- CheckExistsRemoveTransactionError);
+ forward_domain, reverse_domain, cfg_mgr),
+ CheckExistsRemoveTransactionError);
// Verify that a valid construction attempt works.
ncr->setChangeType(isc::dhcp_ddns::CHG_REMOVE);
EXPECT_NO_THROW(CheckExistsRemoveTransaction(io_service, ncr,
- forward_domain, reverse_domain,
- cfg_mgr));
+ forward_domain, reverse_domain,
+ cfg_mgr));
+}
+
+/// @brief Tests CheckExistsRemoveTransaction construction.
+/// This test verifies that valid construction functions properly if extra
+/// parameters are present.
+TEST(CheckExistsRemoveTransaction, constructionWithExtra) {
+ asiolink::IOServicePtr io_service(new isc::asiolink::IOService());
+ D2CfgMgrPtr cfg_mgr(new D2CfgMgr());
+
+ const char* msg_str =
+ "{"
+ " \"change-type\" : 0 , "
+ " \"forward-change\" : true , "
+ " \"reverse-change\" : true , "
+ " \"fqdn\" : \"example.com.\" , "
+ " \"ip-address\" : \"192.168.2.1\" , "
+ " \"dhcid\" : \"0102030405060708\" , "
+ " \"extra\" : \"19700101000000\" , "
+ " \"lease-length\" : 1300, "
+ " \"conflict-resolution-mode\" : \"check-exists-with-dhcid\""
+ "}";
+
+ dhcp_ddns::NameChangeRequestPtr ncr;
+ DnsServerInfoStoragePtr servers;
+ DdnsDomainPtr forward_domain;
+ DdnsDomainPtr reverse_domain;
+ DdnsDomainPtr empty_domain;
+
+ ASSERT_NO_THROW(ncr = dhcp_ddns::NameChangeRequest::fromJSON(msg_str));
+ ASSERT_NO_THROW(forward_domain.reset(new DdnsDomain("*", servers)));
+ ASSERT_NO_THROW(reverse_domain.reset(new DdnsDomain("*", servers)));
+
+ // Verify that a valid construction attempt works.
+ ncr->setChangeType(isc::dhcp_ddns::CHG_REMOVE);
+ EXPECT_NO_THROW(CheckExistsRemoveTransaction(io_service, ncr,
+ forward_domain, reverse_domain,
+ cfg_mgr));
}
/// @brief Tests event and state dictionary construction and verification.
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-with-dhcid\""
"}";
" \"fqdn\" : \"fish.example.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-with-dhcid\""
"}";
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"fe80::2acf:e9ff:fe12:e56f\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-with-dhcid\""
"}"
" \"fqdn\" : \"my.example.com.\" , "
" \"ip-address\" : \"192.168.1.2\" , "
" \"dhcid\" : \"0102030405060708\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-with-dhcid\""
"}";
" \"fqdn\" : \"example.com.\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"0102030405060708\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-with-dhcid\""
"}";
cfg_mgr));
}
+/// @brief Tests NameAddTransaction construction.
+/// This test verifies that valid construction functions properly if extra
+/// parameters are present.
+TEST(NameAddTransaction, constructionWithExtra) {
+ asiolink::IOServicePtr io_service(new isc::asiolink::IOService());
+ D2CfgMgrPtr cfg_mgr(new D2CfgMgr());
+
+ const char* msg_str =
+ "{"
+ " \"change-type\" : 1 , "
+ " \"forward-change\" : true , "
+ " \"reverse-change\" : true , "
+ " \"fqdn\" : \"example.com.\" , "
+ " \"ip-address\" : \"192.168.2.1\" , "
+ " \"dhcid\" : \"0102030405060708\" , "
+ " \"extra\" : \"19700101000000\" , "
+ " \"lease-length\" : 1300, "
+ " \"conflict-resolution-mode\" : \"check-with-dhcid\""
+ "}";
+
+ dhcp_ddns::NameChangeRequestPtr ncr;
+ DnsServerInfoStoragePtr servers;
+ DdnsDomainPtr forward_domain;
+ DdnsDomainPtr reverse_domain;
+ DdnsDomainPtr empty_domain;
+
+ ASSERT_NO_THROW(ncr = dhcp_ddns::NameChangeRequest::fromJSON(msg_str));
+ ASSERT_NO_THROW(forward_domain.reset(new DdnsDomain("*", servers)));
+ ASSERT_NO_THROW(reverse_domain.reset(new DdnsDomain("*", servers)));
+
+ // Verify that a valid construction attempt works.
+ ncr->setChangeType(isc::dhcp_ddns::CHG_ADD);
+ EXPECT_NO_THROW(NameAddTransaction(io_service, ncr,
+ forward_domain, reverse_domain,
+ cfg_mgr));
+}
+
/// @brief Tests event and state dictionary construction and verification.
TEST_F(NameAddTransactionTest, dictionaryCheck) {
NameAddStubPtr name_add;
" \"fqdn\" : \"example.com.\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"0102030405060708\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-with-dhcid\""
"}";
cfg_mgr));
}
+/// @brief Tests NameRemoveTransaction construction.
+/// This test verifies that valid construction functions properly if extra
+/// parameters are present.
+TEST(NameRemoveTransaction, constructionWithExtra) {
+ asiolink::IOServicePtr io_service(new isc::asiolink::IOService());
+ D2CfgMgrPtr cfg_mgr(new D2CfgMgr());
+
+ const char* msg_str =
+ "{"
+ " \"change-type\" : 0 , "
+ " \"forward-change\" : true , "
+ " \"reverse-change\" : true , "
+ " \"fqdn\" : \"example.com.\" , "
+ " \"ip-address\" : \"192.168.2.1\" , "
+ " \"dhcid\" : \"0102030405060708\" , "
+ " \"extra\" : \"19700101000000\" , "
+ " \"lease-length\" : 1300, "
+ " \"conflict-resolution-mode\" : \"check-with-dhcid\""
+ "}";
+
+ dhcp_ddns::NameChangeRequestPtr ncr;
+ DnsServerInfoStoragePtr servers;
+ DdnsDomainPtr forward_domain;
+ DdnsDomainPtr reverse_domain;
+ DdnsDomainPtr empty_domain;
+
+ ASSERT_NO_THROW(ncr = dhcp_ddns::NameChangeRequest::fromJSON(msg_str));
+ ASSERT_NO_THROW(forward_domain.reset(new DdnsDomain("*", servers)));
+ ASSERT_NO_THROW(reverse_domain.reset(new DdnsDomain("*", servers)));
+
+ // Verify that a valid construction attempt works.
+ ncr->setChangeType(isc::dhcp_ddns::CHG_REMOVE);
+ EXPECT_NO_THROW(NameRemoveTransaction(io_service, ncr,
+ forward_domain, reverse_domain,
+ cfg_mgr));
+}
+
/// @brief Tests event and state dictionary construction and verification.
TEST_F(NameRemoveTransactionTest, dictionaryCheck) {
NameRemoveStubPtr name_remove;
" \"fqdn\" : \"example.com.\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"0102030405060708\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"no-check-with-dhcid\""
"}";
" \"fqdn\" : \"example.com.\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"0102030405060708\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"no-check-without-dhcid\""
"}";
" \"fqdn\" : \"example.com.\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"0102030405060708\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"no-check-with-dhcid\""
"}";
" \"fqdn\" : \"example.com.\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"0102030405060708\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"use-conflict-resolution\" : true "
"}";
<< std::hex << std::setfill('0') << std::setw(16)
<< dhcid_id_num << "\" , "
- " \"lease-expires-on\" : \"20140121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-with-dhcid\""
"}";
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
resp->getYiaddr().toText(),
"client1.example.com.", "",
- time(NULL), lease->valid_lft_, true,
+ lease->valid_lft_,
CHECK_WITH_DHCID,
ddns_ttl_percent,
ddns_ttl,
/// @param fqdn - expected FQDN in the NCR
/// @param dhcid - expected DHCID in the NCR (comparison is performed only
/// if the value supplied is not empty):w
- /// @param cltt - cltt value from the lease the NCR for which the NCR
- /// was generated expected value for
/// @param lifetime - lease's valid lifetime from which NCR ttl was
/// generated
- /// @param not_strict_expire_check - when true the comparison of the NCR
- /// lease expiration time is conducted as greater than or equal to rather
- /// equal to CLTT plus lease ttl .
/// @param exp_conflict_resolution_mode expected value of conflict resolution mode
/// @param ddns_ttl_percent expected configured value for ddns-ttl-percent
/// @param ddns_ttl expected configured value for ddns-ttl
const std::string& addr,
const std::string& fqdn,
const std::string& dhcid,
- const time_t cltt,
const uint16_t valid_lft,
- const bool not_strict_expire_check = false,
- const ConflictResolutionMode
- exp_conflict_resolution_mode = CHECK_WITH_DHCID,
+ const ConflictResolutionMode exp_conflict_resolution_mode = CHECK_WITH_DHCID,
Optional<double> ddns_ttl_percent = Optional<double>(),
Optional<uint32_t> ddns_ttl = Optional<uint32_t>(),
Optional<uint32_t> ddns_ttl_min = Optional<uint32_t>(),
EXPECT_EQ(dhcid, ncr->getDhcid().toStr());
}
- // In some cases, the test doesn't have access to the last transmission
- // time for the particular client. In such cases, the test can use the
- // current time as cltt but the it may not check the lease expiration
- // time for equality but rather check that the lease expiration time
- // is not greater than the current time + lease lifetime.
-
uint32_t ttl = calculateDdnsTtl(valid_lft, ddns_ttl_percent,
ddns_ttl, ddns_ttl_min, ddns_ttl_max);
- if (not_strict_expire_check) {
- EXPECT_GE(cltt + ttl, ncr->getLeaseExpiresOn());
- } else {
- EXPECT_EQ(cltt + ttl, ncr->getLeaseExpiresOn());
- }
-
EXPECT_EQ(ttl, ncr->getLeaseLength());
EXPECT_EQ(isc::dhcp_ddns::ST_NEW, ncr->getStatus());
EXPECT_EQ(exp_conflict_resolution_mode, ncr->getConflictResolutionMode());
reply->getYiaddr().toText(),
"myhost.example.com.",
"", // empty DHCID means don't check it
- time(NULL) + subnet_->getValid(),
- subnet_->getValid(), true);
+ subnet_->getValid());
}
}
}
"192.0.2.3", "myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436965"
"B68B6D438D98E680BF10B09F3BCF",
- lease->cltt_, 100);
+ 100);
}
// Verify that conflict resolution is disabled in the NCR when it is
"192.0.2.3", "myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436965"
"B68B6D438D98E680BF10B09F3BCF",
- lease->cltt_, 100, false, NO_CHECK_WITH_DHCID);
+ 100, NO_CHECK_WITH_DHCID);
}
// Verifies that createNameChange request only generates requests
// Verify NCR content
verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true,
scenario.old_lease_->addr_.toText(),
- scenario.old_lease_->hostname_, "", time(NULL),
- scenario.old_lease_->valid_lft_, true);
+ scenario.old_lease_->hostname_, "",
+ scenario.old_lease_->valid_lft_);
}
// If we expect an add, check it.
// Verify NCR content
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
scenario.new_lease_->addr_.toText(),
- scenario.new_lease_->hostname_, "", time(NULL),
- scenario.new_lease_->valid_lft_, true);
+ scenario.new_lease_->hostname_, "",
+ scenario.new_lease_->valid_lft_);
}
}
}
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
reply->getYiaddr().toText(), hostname,
"", // empty DHCID forces that it is not checked
- time(NULL) + subnet_->getValid(),
- subnet_->getValid(), true);
+ subnet_->getValid());
req = generatePktWithFqdn(DHCPREQUEST, Option4ClientFqdn::FLAG_S |
Option4ClientFqdn::FLAG_E,
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
reply->getYiaddr().toText(), hostname,
"", // empty DHCID forces that it is not checked
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
}
// Test that client may send two requests, each carrying FQDN option with
reply->getYiaddr().toText(), "myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436"
"965B68B6D438D98E680BF10B09F3BCF",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
// Create another Request message but with a different FQDN. Server
// should generate two NameChangeRequests: one to remove existing entry,
"myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436"
"965B68B6D438D98E680BF10B09F3BCF",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
reply->getYiaddr().toText(),
"otherhost.example.com.",
"000101A5AEEA7498BD5AD9D3BF600E49FF39A7E3"
"AFDCE8C3D0E53F35CC584DD63C89CA",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
}
// Test that client may send two requests, each carrying Hostname option with
reply->getYiaddr().toText(), "myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436"
"965B68B6D438D98E680BF10B09F3BCF",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
// Create another Request message but with a different Hostname. Server
// should generate two NameChangeRequests: one to remove existing entry,
"myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436"
"965B68B6D438D98E680BF10B09F3BCF",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
reply->getYiaddr().toText(),
"otherhost.example.com.",
"000101A5AEEA7498BD5AD9D3BF600E49FF39A7E3"
"AFDCE8C3D0E53F35CC584DD63C89CA",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
}
// Test that client may send two requests, each carrying the same FQDN option.
reply->getYiaddr().toText(), "myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436"
"965B68B6D438D98E680BF10B09F3BCF",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
// Create another Request message with the same FQDN. Case changes in the
// hostname should be ignored. Server should generate no NameChangeRequests.
reply->getYiaddr().toText(), "myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436"
"965B68B6D438D98E680BF10B09F3BCF",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
// Create another Request message with the same Hostname. Case changes in the
// hostname should be ignored. Server should generate no NameChangeRequests.
reply->getYiaddr().toText(), "myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436"
"965B68B6D438D98E680BF10B09F3BCF",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
// Create and process the Release message.
Pkt4Ptr rel = Pkt4Ptr(new Pkt4(DHCPRELEASE, 1234));
reply->getYiaddr().toText(), "myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436"
"965B68B6D438D98E680BF10B09F3BCF",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
}
// Test that when a release message is sent for a previously acquired lease,
reply->getYiaddr().toText(), "myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436"
"965B68B6D438D98E680BF10B09F3BCF",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
// Create and process the Release message.
Pkt4Ptr rel = Pkt4Ptr(new Pkt4(DHCPRELEASE, 1234));
"unique-host.example.com.",
"000001B6547DCC62E44C4D1A42D0A05B149EA1168"
"01A9481A98E3A876A9E0D261F8326",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
}
// And that this FQDN has been stored in the lease database.
"unique-host.example.com.",
"000001B6547DCC62E44C4D1A42D0A05B149EA1168"
"01A9481A98E3A876A9E0D261F8326",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
}
{
"foobar.fake-suffix.isc.org.",
"0000017C29B3C236344924E448E247F3FD56C7E9"
"167B3397B1305FB664C160B967CE1F",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
}
}
"unique-host.example.com.",
"000001B6547DCC62E44C4D1A42D0A05B149EA1168"
"01A9481A98E3A876A9E0D261F8326",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
}
// Reconfigure DHCP server to use a different hostname for the client.
"unique-host.example.com.",
"000001B6547DCC62E44C4D1A42D0A05B149EA1168"
"01A9481A98E3A876A9E0D261F8326",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
}
{
"foobar.fake-suffix.isc.org.",
"0000017C29B3C236344924E448E247F3FD56C7E9"
"167B3397B1305FB664C160B967CE1F",
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
}
}
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
resp->getYiaddr().toText(),
"two.example.com.", "",
- time(NULL), 7200, true);
+ 7200);
}
// Verifies that when reusing an expired lease, whether or not it is given to its
true, true,
resp->getYiaddr().toText(), scenario.hostname1_,
scenario.dhcid1_,
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
}
// Expire the lease
true, true,
resp->getYiaddr().toText(), scenario.hostname1_,
scenario.dhcid1_,
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
}
if (scenario.expect_add_) {
true, true,
resp->getYiaddr().toText(), scenario.hostname2_,
scenario.dhcid2_,
- time(NULL), subnet_->getValid(), true);
+ subnet_->getValid());
}
bool deleted = false;
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
resp->getYiaddr().toText(),
"client1.one.example.com.", "",
- time(NULL), 7200, true);
+ 7200);
// Now let's try with a second client. The first subnet is full so we should
// end up on the second subnet.
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
resp->getYiaddr().toText(),
"client2.two.example.com.", "",
- time(NULL), 7200, true);
+ 7200);
// Make sure the lease is in the database and hostname is correct.
lease = LeaseMgrFactory::instance().getLease4(IOAddress("10.0.0.10"));
"client-name.example.com.",
"0000011E5D6FA61FCBAC969FF4EF0EBCA3FDE554E"
"B020A13F44859F30A108793564A97",
- time(NULL), subnet->getValid(), true);
+ subnet->getValid());
// And that this FQDN has been stored in the lease database.
lease = LeaseMgrFactory::instance().getLease4(client.config_.lease_.addr_);
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
resp->getYiaddr().toText(),
"client1.example.com.", "",
- time(NULL), lease->valid_lft_, true,
+ lease->valid_lft_,
CHECK_WITH_DHCID, Optional<double>(.25));
}
"192.0.2.3", "myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436965"
"B68B6D438D98E680BF10B09F3BCF",
- lease->cltt_, 100, false, CHECK_WITH_DHCID);
+ 100, CHECK_WITH_DHCID);
}
// Verify that conflict resolution mode is set to "no-check-with-dhcid" in the NCR
"192.0.2.3", "myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436965"
"B68B6D438D98E680BF10B09F3BCF",
- lease->cltt_, 100, false, NO_CHECK_WITH_DHCID);
+ 100, NO_CHECK_WITH_DHCID);
}
// Verify that conflict resolution mode is set to "no-check-without-dhcid" in the NCR
"192.0.2.3", "myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436965"
"B68B6D438D98E680BF10B09F3BCF",
- lease->cltt_, 100, false, NO_CHECK_WITHOUT_DHCID);
+ 100, NO_CHECK_WITHOUT_DHCID);
}
// Verify that conflict resolution mode is set to "check-exists-with-dhcid" in the NCR
"192.0.2.3", "myhost.example.com.",
"00010132E91AA355CFBB753C0F0497A5A940436965"
"B68B6D438D98E680BF10B09F3BCF",
- lease->cltt_, 100, false, CHECK_EXISTS_WITH_DHCID);
+ 100, CHECK_EXISTS_WITH_DHCID);
}
// Verify the ddns-ttl-percent is used when specified.
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
resp->getYiaddr().toText(),
(scenario.expected_hostname_ + "."), "",
- time(NULL), lease->valid_lft_, true,
+ lease->valid_lft_,
CHECK_WITH_DHCID);
}
}
// Get the IP address from the lease.
NameChangeRequestPtr ncr;
auto cr_mode = StringToConflictResolutionMode(ctx.getDdnsParams()->getConflictResolutionMode());
- ncr.reset(new NameChangeRequest(isc::dhcp_ddns::CHG_ADD,
- do_fwd, do_rev,
- opt_fqdn->getDomainName(),
- iaaddr->getAddress().toText(),
- dhcid, 0,
+ ncr.reset(new NameChangeRequest(isc::dhcp_ddns::CHG_ADD, do_fwd, do_rev, opt_fqdn->getDomainName(),
+ iaaddr->getAddress().toText(), dhcid,
calculateDdnsTtl(iaaddr->getValid(),
ctx.getDdnsParams()->getTtlPercent(),
ctx.getDdnsParams()->getTtl(),
<< std::hex << std::setfill('0') << std::setw(16)
<< dhcid_id_num << "\" , "
- " \"lease-expires-on\" : \"20140121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-with-dhcid\" "
"}";
const bool reverse, const bool forward,
const std::string& addr,
const std::string& dhcid,
- const uint64_t expires,
const uint16_t valid_lft,
const std::string& fqdn = "",
const ConflictResolutionMode exp_cr_mode = CHECK_WITH_DHCID,
- util::Optional<double> exp_ddns_ttl_percent
- = util::Optional<double>(),
+ util::Optional<double> exp_ddns_ttl_percent = util::Optional<double>(),
Optional<uint32_t> exp_ddns_ttl = Optional<uint32_t>(),
Optional<uint32_t> exp_ddns_ttl_min = Optional<uint32_t>(),
Optional<uint32_t> exp_ddns_ttl_max = Optional<uint32_t>()) {
uint32_t ttl = calculateDdnsTtl(valid_lft, exp_ddns_ttl_percent, exp_ddns_ttl,
exp_ddns_ttl_min, exp_ddns_ttl_max);
- if (expires != 0) {
- EXPECT_EQ(expires + ttl, ncr->getLeaseExpiresOn());
- }
EXPECT_EQ(ttl, ncr->getLeaseLength());
"2001:db8:1::1",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, valid_lft, "", NO_CHECK_WITH_DHCID,
+ valid_lft, "", NO_CHECK_WITH_DHCID,
ddns_ttl_percent,
ddns_ttl,
ddns_ttl_min,
"2001:db8:1::1",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, 500);
+ 500);
}
// Verify that conflict resolution is turned off when the
"2001:db8:1::1",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, 500, "", NO_CHECK_WITH_DHCID);
+ 500, "", NO_CHECK_WITH_DHCID);
}
// Checks that NameChangeRequests to add entries are not
"2001:db8:1::1",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- lease_->cltt_, lease_->valid_lft_);
+ lease_->valid_lft_);
}
// Checks that calling queueNCR would not result in error if DDNS updates are
"2001:db8:1::1",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- lease_->cltt_, lease_->valid_lft_);
+ lease_->valid_lft_);
}
// Test that NameChangeRequest to remove DNS records is not generated when
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, 4000);
+ 4000);
// Client may send another request message with a new domain-name. In this
// case the same lease will be returned. The existing DNS entry needs to
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- lease_->cltt_, lease_->valid_lft_);
+ lease_->valid_lft_);
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
"2001:db8:1:1::dead:beef",
"000201D422AA463306223D269B6CB7AFE7AAD265FC"
"EA97F93623019B2E0D14E5323D5A",
- 0, lease_->valid_lft_);
+ lease_->valid_lft_);
}
// Test that client may send two requests, each carrying FQDN option with
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, 4000);
+ 4000);
// Client may send another request message with a same domain-name. In this
// case the same lease will be returned. The existing DNS entry should be
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, 4000);
+ 4000);
// When the returning client sends Solicit the code should never generate
// NameChangeRequest and preserve existing DNS entries for the client.
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, 4000);
+ 4000);
// Client may send Renew message with a new domain-name. In this
// case the same lease will be returned. The existing DNS entry needs to
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- lease_->cltt_, lease_->valid_lft_);
+ lease_->valid_lft_);
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
"2001:db8:1:1::dead:beef",
"000201D422AA463306223D269B6CB7AFE7AAD265FC"
"EA97F93623019B2E0D14E5323D5A",
- 0, lease_->valid_lft_);
+ lease_->valid_lft_);
}
// Test that client may send Request followed by the Renew, both holding
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, 4000);
+ 4000);
ASSERT_EQ(0, d2_mgr_.getQueueSize());
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, 4000);
+ 4000);
// Renew again with the same flags, this should not generate any NCRs.
testProcessMessage(DHCPV6_RENEW, "myhost.example.com",
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- lease_->cltt_, lease_->valid_lft_);
+ lease_->valid_lft_);
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, lease_->valid_lft_);
+ lease_->valid_lft_);
// Lastly, we renew with the N flag = 1 (which means no updates) so we
// should have a dual direction remove NCR but NO add NCR.
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- lease_->cltt_, lease_->valid_lft_);
+ lease_->valid_lft_);
}
TEST_F(FqdnDhcpv6SrvTest, processRequestRelease) {
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, lease_->valid_lft_);
+ lease_->valid_lft_);
// Client may send Release message. In this case the lease should be
// removed and all existing DNS entries for this lease should also
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- lease_->cltt_, lease_->valid_lft_);
+ lease_->valid_lft_);
}
TEST_F(FqdnDhcpv6SrvTest, processRequestReleaseNoDelete) {
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, lease_->valid_lft_);
+ lease_->valid_lft_);
// Client may send Release message. In this case the lease should be
// expired and no NameChangeRequest to remove DNS entries is generated.
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, 4000);
+ 4000);
}
// Checks that FQDN is generated from an ip address, when client sends an empty
"2001:db8:1:1::dead:beef",
"000201C905E54BE12DE6AF92ADE72752B9F362"
"13B5A8BC9D217548CD739B4CF31AFB1B",
- 0, 4000);
+ 4000);
}
// Checks that when the server reuses expired lease, the NameChangeRequest
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, lease_->valid_lft_);
+ lease_->valid_lft_);
// One of the following: IAID, DUID or subnet identifier has to be changed
// because otherwise the allocation engine will treat the lease as
// being renewed by the same client. If we at least change subnet identifier
"2001:db8:1:1::dead:beef",
"000201D422AA463306223D269B6CB7AFE7AAD2"
"65FCEA97F93623019B2E0D14E5323D5A",
- lease->cltt_, lease->valid_lft_);
+ lease->valid_lft_);
// The second name change request should add a DNS mapping for
// a new lease.
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
- "FAAAA3EBD29826B5C907B2C9268A6F52", 0, 4);
+ "FAAAA3EBD29826B5C907B2C9268A6F52", 4);
}
TEST_F(FqdnDhcpv6SrvTest, processClientDelegation) {
"2001:db8:1:1::dead:beef",
"000201415AA33D1187D148275136FA30300478"
"FAAAA3EBD29826B5C907B2C9268A6F52",
- 0, 4000);
+ 4000);
}
// Verify that the host reservation is found and used. Lease host name and
"2001:db8:1:1::babe",
"000201E2EB74FB53A5778E74AFD43870ECA5"
"4150B1F52B0CFED434802DA1259D6D3CA4",
- 0, 4000, "alice.example.com.");
+ 4000, "alice.example.com.");
}
// Verify that the host reservation is found and used, rather than dynamic
"2001:db8:1:1::babe",
"000201E2EB74FB53A5778E74AFD43870ECA5"
"4150B1F52B0CFED434802DA1259D6D3CA4",
- 0, 4000, "alice.example.com.");
+ 4000, "alice.example.com.");
}
TEST_F(FqdnDhcpv6SrvTest, hostnameReservationDdnsDisabled) {
// ddns-send-updates for subnet 2 are enabled, verify the NCR is correct.
ASSERT_EQ(1, CfgMgr::instance().getD2ClientMgr().getQueueSize());
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, "2001:db8:2::1",
- "", 0, 4000);
+ "", 4000);
}
// Verifies that the DDNS parameters used for a lease in subnet in
// ddns-send-updates for subnet 1 are enabled, verify the NCR is correct.
ASSERT_EQ(1, CfgMgr::instance().getD2ClientMgr().getQueueSize());
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, "2001:db8:1::1",
- "", 0, 4000, "client1.one.example.com.");
+ "", 4000, "client1.one.example.com.");
// Make sure the lease hostname and fqdn flags are correct.
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
// ddns-send-updates for subnet 2 are enabled, verify the NCR is correct.
ASSERT_EQ(1, CfgMgr::instance().getD2ClientMgr().getQueueSize());
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, "2001:db8:2::1",
- "", 0, 4000, "client2.two.example.com.");
+ "", 4000, "client2.two.example.com.");
// Make sure the lease hostname and fqdn flags are correct.
lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, IOAddress("2001:db8:2::1"));
// ddns-send-updates for subnet 1 are enabled, verify the NCR is correct.
ASSERT_EQ(1, CfgMgr::instance().getD2ClientMgr().getQueueSize());
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, "2001:db8:1::1",
- "", 0, 4000, "client1.one.example.com.");
+ "", 4000, "client1.one.example.com.");
// Make sure the lease hostname and fdqn flags are correct.
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
ASSERT_EQ(1, d2_mgr_.getQueueSize());
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
old_lease->addr_.toText(), "",
- 0, old_lease->valid_lft_,
+ old_lease->valid_lft_,
old_lease->hostname_);
}
// Verify NCR content
verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true,
old_lease->addr_.toText(), "",
- 0, old_lease->valid_lft_,
+ old_lease->valid_lft_,
old_lease->hostname_);
}
// Verify NCR content
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
new_lease->addr_.toText(), "",
- 0, new_lease->valid_lft_,
+ new_lease->valid_lft_,
new_lease->hostname_);
}
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
scenario.expected_address_.toText(),
scenario.expected_dhcid_,
- 0, 4000,
+ 4000,
scenario.expected_fqdn_);
}
}
/// @brief Pointer to the tested server object
boost::shared_ptr<NakedControlledDhcpv6Srv> server_;
- /// @brief Flag which indicates if the server has stopped the IOService and
- /// the client needs to handle it's own IO events.
+ /// @brief Flag which indicates if the server has stopped the IO service and
+ /// the client needs to handle its own IO events.
bool handle_stop_;
/// @brief Default constructor
" \"fqdn\" : \"example.com.\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"0102030405060708\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"use-conflict-resolution\" : true "
"}";
" \"fqdn\" : \"my.forward.example.com.\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"0102030405060708\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-with-dhcid\""
"}";
" \"fqdn\" : \"my6.forward.example.com.\" , "
" \"ip-address\" : \"2001:1::100\" , "
" \"dhcid\" : \"0102030405060708\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-with-dhcid\""
"}";
/// " \"fqdn\" : \"my.example.com.\" , "
/// " \"ip-address\" : \"192.168.2.1\" , "
/// " \"dhcid\" : \"0102030405060708\" , "
-/// " \"lease-expires-on\" : \"20130121132405\" , "
/// " \"lease-length\" : 1300 "
/// "}";
///
given FQDN
- dhcid - DHCID (a form of identification) of the client to whom the IP
address is leased
- - lease-expires-on - timestamp containing the date/time the lease expires
- lease-length - duration in seconds for which the lease is valid.
These requests are implemented in this library by the class,
#include <sstream>
#include <limits>
-
namespace isc {
namespace dhcp_ddns {
-
NameChangeFormat stringToNcrFormat(const std::string& fmt_str) {
if (boost::iequals(fmt_str, "JSON")) {
return FMT_JSON;
isc_throw(BadValue, "Invalid NameChangeRequest format: " << fmt_str);
}
-
std::string ncrFormatToString(NameChangeFormat format) {
if (format == FMT_JSON) {
return ("JSON");
}
std::ostringstream stream;
- stream << "UNKNOWN(" << format << ")";
+ stream << "UNKNOWN(" << format << ")";
return (stream.str());
}
}
std::ostringstream stream;
- stream << "unknown(" << mode << ")";
+ stream << "unknown(" << mode << ")";
return (stream.str());
}
fromDUID(duid, wire_fqdn);
}
-
void
D2Dhcid::fromStr(const std::string& data) {
bytes_.clear();
createDigest(DHCID_ID_HWADDR, hwaddr_data, wire_fqdn);
}
-
void
D2Dhcid::fromDUID(const isc::dhcp::DUID& duid,
const std::vector<uint8_t>& wire_fqdn) {
return (os);
}
-
-
/**************************** NameChangeRequest ******************************/
-
NameChangeRequest::NameChangeRequest()
- : change_type_(CHG_ADD), forward_change_(false),
- reverse_change_(false), fqdn_(""), ip_io_address_("0.0.0.0"),
- dhcid_(), lease_expires_on_(), lease_length_(0),
- conflict_resolution_mode_(CHECK_WITH_DHCID),
- status_(ST_NEW) {
+ : change_type_(CHG_ADD), forward_change_(false), reverse_change_(false),
+ fqdn_(""), ip_io_address_("0.0.0.0"), dhcid_(), lease_length_(0),
+ conflict_resolution_mode_(CHECK_WITH_DHCID), status_(ST_NEW) {
}
NameChangeRequest::NameChangeRequest(const NameChangeType change_type,
const bool forward_change, const bool reverse_change,
const std::string& fqdn, const std::string& ip_address,
- const D2Dhcid& dhcid,
- const uint64_t lease_expires_on,
- const uint32_t lease_length,
+ const D2Dhcid& dhcid, const uint32_t lease_length,
const ConflictResolutionMode conflict_resolution_mode)
: change_type_(change_type), forward_change_(forward_change),
reverse_change_(reverse_change), fqdn_(fqdn), ip_io_address_("0.0.0.0"),
- dhcid_(dhcid), lease_expires_on_(lease_expires_on),
- lease_length_(lease_length),
+ dhcid_(dhcid), lease_length_(lease_length),
conflict_resolution_mode_(conflict_resolution_mode),
status_(ST_NEW) {
element = ncr->getElement("dhcid", element_map);
ncr->setDhcid(element);
- element = ncr->getElement("lease-expires-on", element_map);
- ncr->setLeaseExpiresOn(element);
-
element = ncr->getElement("lease-length", element_map);
ncr->setLeaseLength(element);
}
std::string
-NameChangeRequest::toJSON() const {
+NameChangeRequest::toJSON() const {
// Create a JSON string of this request's contents. Note that this method
// does NOT use the isc::data library as generating the output is straight
// forward.
<< "\"fqdn\":\"" << getFqdn() << "\","
<< "\"ip-address\":\"" << getIpAddress() << "\","
<< "\"dhcid\":\"" << getDhcid().toStr() << "\","
- << "\"lease-expires-on\":\"" << getLeaseExpiresOnStr() << "\","
<< "\"lease-length\":" << getLeaseLength() << ","
<< "\"conflict-resolution-mode\":"
<< "\"" <<ConflictResolutionModeToString(getConflictResolutionMode()) << "\""
return (stream.str());
}
-
void
NameChangeRequest::validateContent() {
//@todo This is an initial implementation which provides a minimal amount
}
// Validate the DHCID.
- if (dhcid_.getBytes().size() == 0) {
+ if (dhcid_.getBytes().size() == 0) {
isc_throw(NcrMessageError, "DHCID cannot be blank");
}
change_type_ = value;
}
-
void
NameChangeRequest::setChangeType(isc::data::ConstElementPtr element) {
long raw_value = -1;
setReverseChange(value);
}
-
void
NameChangeRequest::setFqdn(isc::data::ConstElementPtr element) {
setFqdn(element->stringValue());
setIpAddress(element->stringValue());
}
-
void
NameChangeRequest::setDhcid(const std::string& value) {
dhcid_.fromStr(value);
setDhcid(element->stringValue());
}
-std::string
-NameChangeRequest::getLeaseExpiresOnStr() const {
- return (isc::util::timeToText64(lease_expires_on_));
-}
-
-void
-NameChangeRequest::setLeaseExpiresOn(const std::string& value) {
- try {
- lease_expires_on_ = isc::util::timeFromText64(value);
- } catch (...) {
- // We were given an invalid string, so throw.
- isc_throw(NcrMessageError,
- "Invalid date-time string: [" << value << "]");
- }
-
-}
-
-void NameChangeRequest::setLeaseExpiresOn(isc::data::ConstElementPtr element) {
- // Pull out the string value and pass it into the string setter.
- setLeaseExpiresOn(element->stringValue());
-}
-
void
NameChangeRequest::setLeaseLength(const uint32_t value) {
lease_length_ = value;
}
if (value < 0) {
isc_throw(NcrMessageError, "lease_length value " << value <<
- "is negative. It must greater than or equal to zero ");
+ "is negative. It must greater than or equal to zero ");
}
// Good to go, make the assignment.
<< "FQDN: [" << fqdn_ << "]" << std::endl
<< "IP Address: [" << ip_io_address_ << "]" << std::endl
<< "DHCID: [" << dhcid_.toStr() << "]" << std::endl
- << "Lease Expires On: " << getLeaseExpiresOnStr() << std::endl
<< "Lease Length: " << lease_length_ << std::endl
<< "Conflict Resolution Mode: "
<< ConflictResolutionModeToString(getConflictResolutionMode())
(fqdn_ == other.fqdn_) &&
(ip_io_address_ == other.ip_io_address_) &&
(dhcid_ == other.dhcid_) &&
- (lease_expires_on_ == other.lease_expires_on_) &&
(lease_length_ == other.lease_length_) &&
(conflict_resolution_mode_ == other.conflict_resolution_mode_));
}
return (!(*this == other));
}
-
} // end of isc::dhcp namespace
} // end of isc namespace
const bool forward_change, const bool reverse_change,
const std::string& fqdn, const std::string& ip_address,
const D2Dhcid& dhcid,
- const uint64_t lease_expires_on,
const uint32_t lease_length,
const ConflictResolutionMode
conflict_resolution_mode = CHECK_WITH_DHCID);
/// (NOTE currently only JSON is supported.)
///
/// @param format indicates the data format to use
- /// @param buffer is the input buffer containing the marshalled request
+ /// @param buffer is the input buffer containing the marshaled request
///
/// @return a pointer to the new NameChangeRequest
///
/// "fqdn" : "<fqdn>",
/// "ip-address" : "<address>",
/// "dhcid" : "<hex_string>",
- /// "lease-expires-on" : "<yyyymmddHHMMSS>",
/// "lease-length" : <secs>,
/// "use-conflict-resolution": <boolean>
/// }
/// been leased. The value is a string containing an even number of
/// hexadecimal digits without delimiters such as "2C010203040A7F8E3D"
/// (case insensitive).
- /// - lease-expires-on - the date and time on which the lease expires.
- /// The value is a string of the form "yyyymmddHHMMSS" where:
- /// - yyyy - four digit year
- /// - mm - month of year (1-12),
- /// - dd - day of the month (1-31),
- /// - HH - hour of the day (0-23)
- /// - MM - minutes of the hour (0-59)
- /// - SS - seconds of the minute (0-59)
/// - lease-length - the length of the lease in seconds. This is an
/// integer and may range between 1 and 4294967295 (2^32 - 1) inclusive.
/// - use-conflict-resolution - when true, follow RFC 4703 which uses
/// "fqdn" : "myhost.example.com.",
/// "ip-address" : "192.168.2.1" ,
/// "dhcid" : "010203040A7F8E3D" ,
- /// "lease-expires-on" : "20130121132405",
/// "lease-length" : 1300,
/// "use-conflict-resolution": true
/// }
/// "fqdn" : "someother.example.com.",
/// "ip-address" : "2001::db8:1::2",
/// "dhcid" : "010203040A7F8E3D" , "
- /// "lease-expires-on" : "20130121132405",
/// "lease-length" : 27400,
/// "use-conflict-resolution": true
/// }
return (dhcid_.toStr());
}
- /// @brief Fetches the request lease expiration
- ///
- /// @return the lease expiration as the number of seconds since
- /// the (00:00:00 January 1, 1970)
- uint64_t getLeaseExpiresOn() const {
- return (lease_expires_on_);
- }
-
- /// @brief Fetches the request lease expiration as string.
- ///
- /// The format of the string returned is:
- ///
- /// YYYYMMDDHHmmSS
- ///
- /// Example: 18:54:54 June 26, 2013 would be: 20130626185455
- /// NOTE This is always UTC time.
- ///
- /// @return a ISO date-time string of the lease expiration.
- std::string getLeaseExpiresOnStr() const;
-
- /// @brief Sets the lease expiration based on the given string.
- ///
- /// @param value is an date-time string from which to set the
- /// lease expiration. The format of the input is:
- ///
- /// YYYYMMDDHHmmSS
- ///
- /// Example: 18:54:54 June 26, 2013 would be: 20130626185455
- /// NOTE This is always UTC time.
- ///
- /// @throw NcrMessageError if the ISO string is invalid.
- void setLeaseExpiresOn(const std::string& value);
-
- /// @brief Sets the lease expiration based on the given Element.
- ///
- /// @param element is string Element containing a date-time string.
- ///
- /// @throw NcrMessageError if the element is not a string
- /// Element, or if the element value is an invalid date-time string.
- void setLeaseExpiresOn(isc::data::ConstElementPtr element);
-
/// @brief Fetches the request lease length.
///
/// @return an integer containing the lease length
/// dns::DHCID which provides additional validation.
D2Dhcid dhcid_;
- /// @brief The date-time the lease expires.
- uint64_t lease_expires_on_;
-
/// @brief The amount of time in seconds for which the lease is valid (TTL).
uint32_t lease_length_;
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"no-check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"fe80::2acf:e9ff:fe12:e56f\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}"
ncr_buffer.getLength()), listener_endpoint);
}
-
-
/// @brief Handler invoked when test timeout is hit
///
/// This callback stops all running (hanging) tasks on IO service.
EXPECT_EQ(1, sender.getQueueSize());
}
-
// Tests error handling of a failure to clear the watch socket during
// completion handling.
TEST_F(NameChangeUDPSenderBasicTest, watchSocketBadRead) {
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"fe80::2acf:e9ff:fe12:e56f\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300 "
"}",
// Has use-conflict-resolution instead of mode
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"use-conflict-resolution\": true"
"}"
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
" \"fqdn\" : \"\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
" \"fqdn\" : \".bad_name\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"xxxxxx\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300 "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"THIS IS BOGUS!!!\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
- " \"lease-length\" : 1300, "
- " \"conflict-resolution-mode\": \"check-with-dhcid\""
- "}",
- // Invalid lease expiration string
- "{"
- " \"change-type\" : 0 , "
- " \"forward-change\" : true , "
- " \"reverse-change\" : false , "
- " \"fqdn\" : \"walah.walah.com\" , "
- " \"ip-address\" : \"192.168.2.1\" , "
- " \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"Wed Jun 26 13:46:46 EDT 2013\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : \"BOGUS\", "
" \"conflict-resolution-mode\": \"check-with-dhcid\""
"}",
- // Invalid conflict-resolution-mode
+ // Invalid conflict-resolution-mode.
"{"
" \"change-type\" : 0 , "
" \"forward-change\" : true , "
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\": \"bogus\""
"}"
- // Invalid use-conflict-resolution
+ // Invalid use-conflict-resolution.
"{"
" \"change-type\" : 0 , "
" \"forward-change\" : true , "
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"use-conflict-resolution\": \"bogus\""
"}"
EXPECT_TRUE(ncr);
// Verify that full constructor works.
- uint64_t expiry = isc::util::detail::getTimeWrapper();
D2Dhcid dhcid("010203040A7F8E3D");
EXPECT_NO_THROW(ncr.reset(new NameChangeRequest(
CHG_ADD, true, true, "walah.walah.com",
- "192.168.1.101", dhcid, expiry, 1300)));
+ "192.168.1.101", dhcid, 1300)));
EXPECT_TRUE(ncr);
ncr.reset();
// Verify blank FQDN is detected.
EXPECT_THROW(NameChangeRequest(CHG_ADD, true, true, "",
- "192.168.1.101", dhcid, expiry, 1300), NcrMessageError);
+ "192.168.1.101", dhcid, 1300), NcrMessageError);
// Verify that an invalid IP address is detected.
EXPECT_THROW(NameChangeRequest(CHG_ADD, true, true, "valid.fqdn",
- "xxx.168.1.101", dhcid, expiry, 1300), NcrMessageError);
+ "xxx.168.1.101", dhcid, 1300), NcrMessageError);
// Verify that a blank DHCID is detected.
D2Dhcid blank_dhcid;
EXPECT_THROW(NameChangeRequest(CHG_ADD, true, true, "walah.walah.com",
- "192.168.1.101", blank_dhcid, expiry, 1300), NcrMessageError);
+ "192.168.1.101", blank_dhcid, 1300), NcrMessageError);
// Verify that one or both of direction flags must be true.
EXPECT_THROW(NameChangeRequest(CHG_ADD, false, false, "valid.fqdn",
- "192.168.1.101", dhcid, expiry, 1300), NcrMessageError);
+ "192.168.1.101", dhcid, 1300), NcrMessageError);
}
clientid.clear();
EXPECT_THROW(dhcid.fromClientId(clientid, wire_fqdn_),
isc::dhcp_ddns::DhcidRdataComputeError);
-
-
}
// This test verifies that DHCID is properly computed from a buffer holding
"\"fqdn\":\"walah.walah.com.\","
"\"ip-address\":\"192.168.2.1\","
"\"dhcid\":\"010203040A7F8E3D\","
- "\"lease-expires-on\":\"20130121132405\","
"\"lease-length\":1300,"
"\"conflict-resolution-mode\":\"check-with-dhcid\""
"}";
/// 2. Invalid forward change
/// 3. Invalid reverse change
/// 4. Forward and reverse change both false
-/// 5. Invalid forward change
-/// 6. Blank FQDN
+/// 5. Blank FQDN
+/// 6. Malformed FQDN
/// 7. Bad IP address
/// 8. Blank DHCID
/// 9. Odd number of digits in DHCID
/// 10. Text in DHCID
-/// 11. Invalid lease expiration string
-/// 12. Non-integer for lease length.
+/// 11. Non-integer for lease length.
+/// 12. Invalid conflict-resolution-mode.
+/// 13. Invalid use-conflict-resolution.
/// If more permutations arise they can easily be added to the list.
TEST(NameChangeRequestTest, invalidMsgChecks) {
// Iterate over the list of JSON strings, attempting to create a
"\"fqdn\":\"walah.walah.com.\","
"\"ip-address\":\"192.168.2.1\","
"\"dhcid\":\"010203040A7F8E3D\","
- "\"lease-expires-on\":\"20130121132405\","
"\"lease-length\":1300,"
"\"conflict-resolution-mode\":\"check-with-dhcid\""
"}";
ASSERT_EQ(final_str, msg_str);
}
+/// @brief Tests converting to and from JSON via isc::util buffer classes.
+/// This test verifies that a InputBuffer containing a valid JSON request rendition
+/// but with extra parameter can be used to create a NameChangeRequest.
+TEST(NameChangeRequestTest, toFromBufferTestWithExtra) {
+ // Define a string containing a valid JSON NameChangeRequest rendition.
+ std::string msg_str = "{"
+ "\"change-type\":1,"
+ "\"forward-change\":true,"
+ "\"reverse-change\":false,"
+ "\"fqdn\":\"walah.walah.com.\","
+ "\"ip-address\":\"192.168.2.1\","
+ "\"dhcid\":\"010203040A7F8E3D\","
+ "\"extra\":\"19700101000000\","
+ "\"lease-length\":1300,"
+ "\"conflict-resolution-mode\":\"check-with-dhcid\""
+ "}";
+
+ // Create a request from JSON directly.
+ NameChangeRequestPtr ncr;
+ ASSERT_NO_THROW(ncr = NameChangeRequest::fromJSON(msg_str));
+
+ // Verify that we output the request as JSON text to a buffer
+ // without error.
+ isc::util::OutputBuffer output_buffer(1024);
+ ASSERT_NO_THROW(ncr->toFormat(FMT_JSON, output_buffer));
+
+ // Make an InputBuffer from the OutputBuffer.
+ isc::util::InputBuffer input_buffer(output_buffer.getData(),
+ output_buffer.getLength());
+
+ // Verify that we can create a new request from the InputBuffer.
+ NameChangeRequestPtr ncr2;
+ ASSERT_NO_THROW(ncr2 =
+ NameChangeRequest::fromFormat(FMT_JSON, input_buffer));
+
+ // Convert the new request to JSON directly.
+ std::string final_str = ncr2->toJSON();
+
+ std::string exp_msg_str = "{"
+ "\"change-type\":1,"
+ "\"forward-change\":true,"
+ "\"reverse-change\":false,"
+ "\"fqdn\":\"walah.walah.com.\","
+ "\"ip-address\":\"192.168.2.1\","
+ "\"dhcid\":\"010203040A7F8E3D\","
+ "\"lease-length\":1300,"
+ "\"conflict-resolution-mode\":\"check-with-dhcid\""
+ "}";
+
+ // Verify that the final string matches the original.
+ ASSERT_EQ(final_str, exp_msg_str);
+}
+
/// @brief Tests ip address modification and validation
TEST(NameChangeRequestTest, ipAddresses) {
NameChangeRequest ncr;
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300 ";
std::string its_true(base_json + ",\"use-conflict-resolution\": true}");
" \"fqdn\" : \"walah.walah.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300 ";
std::string its_check_with_dhcid(base_json + ",\"conflict-resolution-mode\": \"check-with-dhcid\"}");
NameChangeRequestPtr ncr
(new NameChangeRequest(chg_type, lease->fqdn_fwd_, lease->fqdn_rev_,
lease->hostname_, lease->addr_.toText(),
- dhcid, lease->cltt_ + ttl,
- ttl, conflict_resolution_mode));
+ dhcid, ttl, conflict_resolution_mode));
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL_DATA, DHCPSRV_QUEUE_NCR)
.arg(label)
" \"fqdn\" : \"myhost.example.com.\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20140121132405\" , "
" \"lease-length\" : 1300, "
" \"conflict-resolution-mode\" : \"check-with-dhcid\""
"}";
/// these values programmatically and place them here. Should the
/// underlying implementation of createDigest() change these test values
/// will likely need to be updated as well.
- /// @param expires A timestamp when the lease associated with the
- /// 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
const bool reverse, const bool forward,
const std::string& addr,
const std::string& dhcid,
- const uint64_t expires,
const uint16_t len,
const std::string& fqdn="",
const ConflictResolutionMode
EXPECT_EQ(reverse, ncr->isReverseChange());
EXPECT_EQ(addr, ncr->getIpAddress());
EXPECT_EQ(dhcid, ncr->getDhcid().toStr());
- EXPECT_EQ(expires, ncr->getLeaseExpiresOn());
EXPECT_EQ(len, ncr->getLeaseLength());
EXPECT_EQ(isc::dhcp_ddns::ST_NEW, ncr->getStatus());
EXPECT_EQ(conflict_resolution_mode, ncr->getConflictResolutionMode());
// Check the details of the NCR.
verifyNameChangeRequest(chg_type, rev, fwd, lease_->addr_.toText(), exp_dhcid,
- lease_->cltt_ + ttl, ttl, fqdn, exp_cr_mode);
+ ttl, fqdn, exp_cr_mode);
}
/// @brief Test that calling queueNCR for NULL lease doesn't cause
verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true,
"192.0.2.1",
"000101C7AA5420483BDA99C437636EA7DA2FE18"
- "31C9679FEB031C360CA571298F3D1FA",
- lease_->cltt_ + ttl, ttl);
+ "31C9679FEB031C360CA571298F3D1FA", ttl);
{
SCOPED_TRACE("case CHG_REMOVE");
testNCR(CHG_REMOVE, true, true, "myhost.example.com.",