|
@@ -1,4 +1,4 @@
|
|
-// Copyright (C) 2013-2014 Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
|
|
+// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
|
|
//
|
|
//
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
@@ -16,6 +16,7 @@
|
|
#include <asiolink/io_address.h>
|
|
#include <asiolink/io_address.h>
|
|
#include <dhcp/duid.h>
|
|
#include <dhcp/duid.h>
|
|
#include <dhcpsrv/lease.h>
|
|
#include <dhcpsrv/lease.h>
|
|
|
|
+#include <util/pointer_util.h>
|
|
#include <gtest/gtest.h>
|
|
#include <gtest/gtest.h>
|
|
#include <vector>
|
|
#include <vector>
|
|
#include <sstream>
|
|
#include <sstream>
|
|
@@ -57,27 +58,24 @@ Lease4 createLease4(const std::string& hostname, const bool fqdn_fwd,
|
|
class Lease4Test : public ::testing::Test {
|
|
class Lease4Test : public ::testing::Test {
|
|
public:
|
|
public:
|
|
|
|
|
|
- /// Default constructor
|
|
|
|
|
|
+ /// @brief Default constructor
|
|
///
|
|
///
|
|
/// Currently it only initializes hardware address.
|
|
/// Currently it only initializes hardware address.
|
|
Lease4Test() {
|
|
Lease4Test() {
|
|
hwaddr_.reset(new HWAddr(HWADDR, sizeof(HWADDR), HTYPE_ETHER));
|
|
hwaddr_.reset(new HWAddr(HWADDR, sizeof(HWADDR), HTYPE_ETHER));
|
|
|
|
+ clientid_.reset(new ClientId(CLIENTID, sizeof(CLIENTID)));
|
|
}
|
|
}
|
|
|
|
|
|
/// Hardware address, used by tests.
|
|
/// Hardware address, used by tests.
|
|
HWAddrPtr hwaddr_;
|
|
HWAddrPtr hwaddr_;
|
|
|
|
+
|
|
|
|
+ /// Pointer to the client identifier used by tests.
|
|
|
|
+ ClientIdPtr clientid_;
|
|
};
|
|
};
|
|
|
|
|
|
-/// 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
|
|
|
|
|
|
+// This test checks if the Lease4 structure can be instantiated correctly.
|
|
TEST_F(Lease4Test, constructor) {
|
|
TEST_F(Lease4Test, constructor) {
|
|
-
|
|
|
|
- // Random values for the tests
|
|
|
|
- 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
|
|
|
|
|
|
+ // Get current time for the use in Lease.
|
|
const time_t current_time = time(NULL);
|
|
const time_t current_time = time(NULL);
|
|
|
|
|
|
// Other random constants.
|
|
// Other random constants.
|
|
@@ -93,15 +91,14 @@ TEST_F(Lease4Test, constructor) {
|
|
for (int i = 0; i < sizeof(ADDRESS) / sizeof(ADDRESS[0]); ++i) {
|
|
for (int i = 0; i < sizeof(ADDRESS) / sizeof(ADDRESS[0]); ++i) {
|
|
|
|
|
|
// Create the lease
|
|
// Create the lease
|
|
- Lease4 lease(ADDRESS[i], hwaddr_,
|
|
|
|
- CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, 0, 0,
|
|
|
|
|
|
+ Lease4 lease(ADDRESS[i], hwaddr_, clientid_, VALID_LIFETIME, 0, 0,
|
|
current_time, SUBNET_ID, true, true,
|
|
current_time, SUBNET_ID, true, true,
|
|
"hostname.example.com.");
|
|
"hostname.example.com.");
|
|
|
|
|
|
EXPECT_EQ(ADDRESS[i], static_cast<uint32_t>(lease.addr_));
|
|
EXPECT_EQ(ADDRESS[i], static_cast<uint32_t>(lease.addr_));
|
|
EXPECT_EQ(0, lease.ext_);
|
|
EXPECT_EQ(0, lease.ext_);
|
|
- EXPECT_TRUE(hwaddr_ == lease.hwaddr_);
|
|
|
|
- EXPECT_TRUE(clientid == *lease.client_id_);
|
|
|
|
|
|
+ EXPECT_TRUE(util::equalValues(hwaddr_, lease.hwaddr_));
|
|
|
|
+ EXPECT_TRUE(util::equalValues(clientid_, lease.client_id_));
|
|
EXPECT_EQ(0, lease.t1_);
|
|
EXPECT_EQ(0, lease.t1_);
|
|
EXPECT_EQ(0, lease.t2_);
|
|
EXPECT_EQ(0, lease.t2_);
|
|
EXPECT_EQ(VALID_LIFETIME, lease.valid_lft_);
|
|
EXPECT_EQ(VALID_LIFETIME, lease.valid_lft_);
|
|
@@ -118,11 +115,7 @@ TEST_F(Lease4Test, constructor) {
|
|
// This test verfies that copy constructor copies Lease4 fields correctly.
|
|
// This test verfies that copy constructor copies Lease4 fields correctly.
|
|
TEST_F(Lease4Test, copyConstructor) {
|
|
TEST_F(Lease4Test, copyConstructor) {
|
|
|
|
|
|
- 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
|
|
|
|
|
|
+ // Get current time for the use in Lease4.
|
|
const time_t current_time = time(NULL);
|
|
const time_t current_time = time(NULL);
|
|
|
|
|
|
// Other random constants.
|
|
// Other random constants.
|
|
@@ -130,8 +123,7 @@ TEST_F(Lease4Test, copyConstructor) {
|
|
const uint32_t VALID_LIFETIME = 500;
|
|
const uint32_t VALID_LIFETIME = 500;
|
|
|
|
|
|
// Create the lease
|
|
// Create the lease
|
|
- Lease4 lease(0xffffffff, hwaddr_,
|
|
|
|
- CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, 0, 0, current_time,
|
|
|
|
|
|
+ Lease4 lease(0xffffffff, hwaddr_, clientid_, VALID_LIFETIME, 0, 0, current_time,
|
|
SUBNET_ID);
|
|
SUBNET_ID);
|
|
|
|
|
|
// Use copy constructor to copy the lease.
|
|
// Use copy constructor to copy the lease.
|
|
@@ -160,12 +152,7 @@ TEST_F(Lease4Test, copyConstructor) {
|
|
// correctly.
|
|
// correctly.
|
|
TEST_F(Lease4Test, operatorAssign) {
|
|
TEST_F(Lease4Test, operatorAssign) {
|
|
|
|
|
|
- // Random values for the tests
|
|
|
|
- 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
|
|
|
|
|
|
+ // Get the current time for the use in Lease4.
|
|
const time_t current_time = time(NULL);
|
|
const time_t current_time = time(NULL);
|
|
|
|
|
|
// Other random constants.
|
|
// Other random constants.
|
|
@@ -173,8 +160,7 @@ TEST_F(Lease4Test, operatorAssign) {
|
|
const uint32_t VALID_LIFETIME = 500;
|
|
const uint32_t VALID_LIFETIME = 500;
|
|
|
|
|
|
// Create the lease
|
|
// Create the lease
|
|
- Lease4 lease(0xffffffff, hwaddr_,
|
|
|
|
- CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, 0, 0, current_time,
|
|
|
|
|
|
+ Lease4 lease(0xffffffff, hwaddr_, clientid_, VALID_LIFETIME, 0, 0, current_time,
|
|
SUBNET_ID);
|
|
SUBNET_ID);
|
|
|
|
|
|
// Use assignment operator to assign the lease.
|
|
// Use assignment operator to assign the lease.
|
|
@@ -199,56 +185,66 @@ TEST_F(Lease4Test, operatorAssign) {
|
|
EXPECT_TRUE(lease == copied_lease);
|
|
EXPECT_TRUE(lease == copied_lease);
|
|
}
|
|
}
|
|
|
|
|
|
-// This test verifies that the matches() returns true if two leases differ
|
|
|
|
-// by values other than address, HW address, Client ID and ext_.
|
|
|
|
-TEST_F(Lease4Test, 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_, CLIENTID,
|
|
|
|
- sizeof(CLIENTID), VALID_LIFETIME, current_time, 0, 0,
|
|
|
|
- SUBNET_ID);
|
|
|
|
- lease1.hostname_ = "lease1.example.com.";
|
|
|
|
- lease1.fqdn_fwd_ = true;
|
|
|
|
- lease1.fqdn_rev_ = true;
|
|
|
|
-
|
|
|
|
- // We need to make an explicit copy. Otherwise the second lease will just
|
|
|
|
- // store a pointer and we'll have two leases pointing to a single HWAddr.
|
|
|
|
- // That would make modifications to only one impossible.
|
|
|
|
- HWAddrPtr hwcopy(new HWAddr(*hwaddr_));
|
|
|
|
-
|
|
|
|
- Lease4 lease2(IOAddress("192.0.2.3"), hwcopy, 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_->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_;
|
|
|
|
|
|
+// This test verifies that it is correctly determined when the lease
|
|
|
|
+// belongs to the particular client identified by the client identifier
|
|
|
|
+// and hw address.
|
|
|
|
+TEST_F(Lease4Test, leaseBelongsToClient) {
|
|
|
|
+ // Client identifier that matches the one in the lease.
|
|
|
|
+ ClientIdPtr matching_client_id = ClientId::fromText("01:02:03:04");
|
|
|
|
+ // Client identifier that doesn't match the one in the lease.
|
|
|
|
+ ClientIdPtr diff_client_id = ClientId::fromText("01:02:03:05");
|
|
|
|
+ // Null (no) client identifier.
|
|
|
|
+ ClientIdPtr null_client_id;
|
|
|
|
+
|
|
|
|
+ // HW Address that matches the one in the lease.
|
|
|
|
+ HWAddrPtr matching_hw(new HWAddr(HWAddr::fromText("00:01:02:03:04:05",
|
|
|
|
+ HTYPE_ETHER)));
|
|
|
|
+ // HW Address that doesn't match the one in the lease.
|
|
|
|
+ HWAddrPtr diff_hw(new HWAddr(HWAddr::fromText("00:01:02:03:04:06",
|
|
|
|
+ HTYPE_ETHER)));
|
|
|
|
+ // Null HW Address.
|
|
|
|
+ HWAddrPtr null_hw;
|
|
|
|
+
|
|
|
|
+ // Create the lease with MAC address and Client Identifier.
|
|
|
|
+ Lease4 lease(IOAddress("192.0.2.1"), matching_hw, matching_client_id,
|
|
|
|
+ 60, time(NULL), 0, 0, 1);
|
|
|
|
+
|
|
|
|
+ // Verify cases for lease that has both hw address and client identifier.
|
|
|
|
+ EXPECT_TRUE(lease.belongsToClient(matching_hw, matching_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(matching_hw, diff_client_id));
|
|
|
|
+ EXPECT_TRUE(lease.belongsToClient(matching_hw, null_client_id));
|
|
|
|
+ EXPECT_TRUE(lease.belongsToClient(diff_hw, matching_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(diff_hw, diff_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(diff_hw, null_client_id));
|
|
|
|
+ EXPECT_TRUE(lease.belongsToClient(null_hw, matching_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(null_hw, diff_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(null_hw, null_client_id));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // Verify cases for lease that has only HW address.
|
|
|
|
+ lease.client_id_ = null_client_id;
|
|
|
|
+ EXPECT_TRUE(lease.belongsToClient(matching_hw, matching_client_id));
|
|
|
|
+ EXPECT_TRUE(lease.belongsToClient(matching_hw, diff_client_id));
|
|
|
|
+ EXPECT_TRUE(lease.belongsToClient(matching_hw, null_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(diff_hw, matching_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(diff_hw, diff_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(diff_hw, null_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(null_hw, matching_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(null_hw, diff_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(null_hw, null_client_id));
|
|
|
|
+
|
|
|
|
+ // Verify cases for lease that has only client identifier.
|
|
|
|
+ lease.client_id_ = matching_client_id;
|
|
|
|
+ lease.hwaddr_ = null_hw;
|
|
|
|
+ EXPECT_TRUE(lease.belongsToClient(matching_hw, matching_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(matching_hw, diff_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(matching_hw, null_client_id));
|
|
|
|
+ EXPECT_TRUE(lease.belongsToClient(diff_hw, matching_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(diff_hw, diff_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(diff_hw, null_client_id));
|
|
|
|
+ EXPECT_TRUE(lease.belongsToClient(null_hw, matching_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(null_hw, diff_client_id));
|
|
|
|
+ EXPECT_FALSE(lease.belongsToClient(null_hw, null_client_id));
|
|
}
|
|
}
|
|
|
|
|
|
/// @brief Lease4 Equality Test
|
|
/// @brief Lease4 Equality Test
|
|
@@ -260,28 +256,22 @@ TEST_F(Lease4Test, operatorEquals) {
|
|
|
|
|
|
// Random values for the tests
|
|
// Random values for the tests
|
|
const uint32_t ADDRESS = 0x01020304;
|
|
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 time_t current_time = time(NULL);
|
|
const uint32_t SUBNET_ID = 42;
|
|
const uint32_t SUBNET_ID = 42;
|
|
const uint32_t VALID_LIFETIME = 500;
|
|
const uint32_t VALID_LIFETIME = 500;
|
|
|
|
|
|
// Check when the leases are equal.
|
|
// Check when the leases are equal.
|
|
- Lease4 lease1(ADDRESS, hwaddr_,
|
|
|
|
- CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, current_time, 0,
|
|
|
|
|
|
+ Lease4 lease1(ADDRESS, hwaddr_, clientid_, VALID_LIFETIME, current_time, 0,
|
|
0, SUBNET_ID);
|
|
0, SUBNET_ID);
|
|
|
|
|
|
// We need to make an explicit copy. Otherwise the second lease will just
|
|
// We need to make an explicit copy. Otherwise the second lease will just
|
|
- // store a pointer and we'll have two leases pointing to a single HWAddr.
|
|
|
|
- // That would make modifications to only one impossible.
|
|
|
|
|
|
+ // store a pointer and we'll have two leases pointing to a single HWAddr
|
|
|
|
+ // or client. That would make modifications to only one impossible.
|
|
HWAddrPtr hwcopy(new HWAddr(*hwaddr_));
|
|
HWAddrPtr hwcopy(new HWAddr(*hwaddr_));
|
|
|
|
+ ClientIdPtr clientid_copy(new ClientId(*clientid_));
|
|
|
|
|
|
- Lease4 lease2(ADDRESS, hwcopy,
|
|
|
|
- CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, current_time, 0, 0,
|
|
|
|
- SUBNET_ID);
|
|
|
|
|
|
+ Lease4 lease2(ADDRESS, hwcopy, clientid_copy, VALID_LIFETIME, current_time,
|
|
|
|
+ 0, 0, SUBNET_ID);
|
|
EXPECT_TRUE(lease1 == lease2);
|
|
EXPECT_TRUE(lease1 == lease2);
|
|
EXPECT_FALSE(lease1 != lease2);
|
|
EXPECT_FALSE(lease1 != lease2);
|
|
|
|
|
|
@@ -308,6 +298,7 @@ TEST_F(Lease4Test, operatorEquals) {
|
|
EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
|
|
EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
|
|
EXPECT_FALSE(lease1 != lease2); // ... leases equal
|
|
EXPECT_FALSE(lease1 != lease2); // ... leases equal
|
|
|
|
|
|
|
|
+ std::vector<uint8_t> clientid_vec = clientid_->getClientId();
|
|
++clientid_vec[0];
|
|
++clientid_vec[0];
|
|
lease1.client_id_.reset(new ClientId(clientid_vec));
|
|
lease1.client_id_.reset(new ClientId(clientid_vec));
|
|
EXPECT_FALSE(lease1 == lease2);
|
|
EXPECT_FALSE(lease1 == lease2);
|
|
@@ -390,7 +381,7 @@ TEST_F(Lease4Test, operatorEquals) {
|
|
|
|
|
|
// Verify that the client id can be returned as a vector object and if client
|
|
// Verify that the client id can be returned as a vector object and if client
|
|
// id is NULL the empty vector is returned.
|
|
// id is NULL the empty vector is returned.
|
|
-TEST(Lease4, getClientIdVector) {
|
|
|
|
|
|
+TEST_F(Lease4Test, getClientIdVector) {
|
|
// Create a lease.
|
|
// Create a lease.
|
|
Lease4 lease;
|
|
Lease4 lease;
|
|
// By default, the lease should have client id set to NULL. If it doesn't,
|
|
// By default, the lease should have client id set to NULL. If it doesn't,
|
|
@@ -398,18 +389,17 @@ TEST(Lease4, getClientIdVector) {
|
|
ASSERT_FALSE(lease.client_id_);
|
|
ASSERT_FALSE(lease.client_id_);
|
|
// When client id is NULL the vector returned should be empty.
|
|
// When client id is NULL the vector returned should be empty.
|
|
EXPECT_TRUE(lease.getClientIdVector().empty());
|
|
EXPECT_TRUE(lease.getClientIdVector().empty());
|
|
- // Now, let's set the non NULL client id. Fill it with the 8 bytes, each
|
|
|
|
- // holding a value of 0x42.
|
|
|
|
- std::vector<uint8_t> client_id_vec(8, 0x42);
|
|
|
|
- lease.client_id_ = ClientIdPtr(new ClientId(client_id_vec));
|
|
|
|
|
|
+
|
|
|
|
+ // Initialize client identifier to non-null value.
|
|
|
|
+ lease.client_id_ = clientid_;
|
|
// Check that the returned vector, encapsulating client id is equal to
|
|
// Check that the returned vector, encapsulating client id is equal to
|
|
// the one that has been used to set the client id for the lease.
|
|
// the one that has been used to set the client id for the lease.
|
|
std::vector<uint8_t> returned_vec = lease.getClientIdVector();
|
|
std::vector<uint8_t> returned_vec = lease.getClientIdVector();
|
|
- EXPECT_TRUE(returned_vec == client_id_vec);
|
|
|
|
|
|
+ EXPECT_TRUE(returned_vec == clientid_->getClientId());
|
|
}
|
|
}
|
|
|
|
|
|
// Verify the behavior of the function which checks FQDN data for equality.
|
|
// Verify the behavior of the function which checks FQDN data for equality.
|
|
-TEST(Lease4, hasIdenticalFqdn) {
|
|
|
|
|
|
+TEST_F(Lease4Test, hasIdenticalFqdn) {
|
|
Lease4 lease = createLease4("myhost.example.com.", true, true);
|
|
Lease4 lease = createLease4("myhost.example.com.", true, true);
|
|
EXPECT_TRUE(lease.hasIdenticalFqdn(createLease4("myhost.example.com.",
|
|
EXPECT_TRUE(lease.hasIdenticalFqdn(createLease4("myhost.example.com.",
|
|
true, true)));
|
|
true, true)));
|
|
@@ -429,8 +419,8 @@ TEST(Lease4, hasIdenticalFqdn) {
|
|
TEST_F(Lease4Test, toText) {
|
|
TEST_F(Lease4Test, toText) {
|
|
|
|
|
|
const time_t current_time = 12345678;
|
|
const time_t current_time = 12345678;
|
|
- Lease4 lease(IOAddress("192.0.2.3"), hwaddr_, CLIENTID, sizeof(CLIENTID),
|
|
|
|
- 3600, 123, 456, current_time, 789);
|
|
|
|
|
|
+ Lease4 lease(IOAddress("192.0.2.3"), hwaddr_, clientid_, 3600, 123,
|
|
|
|
+ 456, current_time, 789);
|
|
|
|
|
|
std::stringstream expected;
|
|
std::stringstream expected;
|
|
expected << "Address: 192.0.2.3\n"
|
|
expected << "Address: 192.0.2.3\n"
|
|
@@ -439,12 +429,14 @@ TEST_F(Lease4Test, toText) {
|
|
<< "T2: 456\n"
|
|
<< "T2: 456\n"
|
|
<< "Cltt: 12345678\n"
|
|
<< "Cltt: 12345678\n"
|
|
<< "Hardware addr: " << hwaddr_->toText(false) << "\n"
|
|
<< "Hardware addr: " << hwaddr_->toText(false) << "\n"
|
|
|
|
+ << "Client id: " << clientid_->toText() << "\n"
|
|
<< "Subnet ID: 789\n";
|
|
<< "Subnet ID: 789\n";
|
|
|
|
|
|
EXPECT_EQ(expected.str(), lease.toText());
|
|
EXPECT_EQ(expected.str(), lease.toText());
|
|
|
|
|
|
- // Now let's try with a lease without hardware address.
|
|
|
|
|
|
+ // Now let's try with a lease without hardware address and client identifier.
|
|
lease.hwaddr_.reset();
|
|
lease.hwaddr_.reset();
|
|
|
|
+ lease.client_id_.reset();
|
|
expected.str("");
|
|
expected.str("");
|
|
expected << "Address: 192.0.2.3\n"
|
|
expected << "Address: 192.0.2.3\n"
|
|
<< "Valid life: 3600\n"
|
|
<< "Valid life: 3600\n"
|
|
@@ -452,6 +444,7 @@ TEST_F(Lease4Test, toText) {
|
|
<< "T2: 456\n"
|
|
<< "T2: 456\n"
|
|
<< "Cltt: 12345678\n"
|
|
<< "Cltt: 12345678\n"
|
|
<< "Hardware addr: (none)\n"
|
|
<< "Hardware addr: (none)\n"
|
|
|
|
+ << "Client id: (none)\n"
|
|
<< "Subnet ID: 789\n";
|
|
<< "Subnet ID: 789\n";
|
|
EXPECT_EQ(expected.str(), lease.toText());
|
|
EXPECT_EQ(expected.str(), lease.toText());
|
|
}
|
|
}
|
|
@@ -565,88 +558,6 @@ TEST(Lease6, Lease6ConstructorWithFQDN) {
|
|
subnet_id)), InvalidOperation);
|
|
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_;
|
|
|
|
-
|
|
|
|
- // Hardware address checks
|
|
|
|
- EXPECT_TRUE(lease1.matches(lease2)); // Neither lease have hardware address.
|
|
|
|
-
|
|
|
|
- // Let's add a hardware lease to the first one.
|
|
|
|
- HWAddrPtr hwaddr(new HWAddr(HWADDR, sizeof(HWADDR), HTYPE_ETHER));
|
|
|
|
- lease1.hwaddr_ = hwaddr;
|
|
|
|
-
|
|
|
|
- // Only the first one has a hardware address, so not equal.
|
|
|
|
- EXPECT_FALSE(lease1.matches(lease2));
|
|
|
|
-
|
|
|
|
- // Only the second one has it, so still not equal.
|
|
|
|
- lease1.hwaddr_.reset();
|
|
|
|
- lease2.hwaddr_ = hwaddr;
|
|
|
|
- EXPECT_FALSE(lease1.matches(lease2));
|
|
|
|
-
|
|
|
|
- // Ok, now both have it - they should be equal.
|
|
|
|
- lease1.hwaddr_ = hwaddr;
|
|
|
|
- EXPECT_TRUE(lease1.matches(lease2));
|
|
|
|
-
|
|
|
|
- // Let's create a second instance that have the same values.
|
|
|
|
- HWAddrPtr hwaddr2(new HWAddr(HWADDR, sizeof(HWADDR), HTYPE_ETHER));
|
|
|
|
- lease2.hwaddr_ = hwaddr2;
|
|
|
|
- EXPECT_TRUE(lease1.matches(lease2));
|
|
|
|
-
|
|
|
|
- // Let's modify the second address and check that they won't be equal anymore.
|
|
|
|
- hwaddr2->hwaddr_[0]++;
|
|
|
|
- EXPECT_FALSE(lease1.matches(lease2));
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
/// @brief Lease6 Equality Test
|
|
/// @brief Lease6 Equality Test
|
|
///
|
|
///
|
|
/// Checks that the operator==() correctly compares two leases for equality.
|
|
/// Checks that the operator==() correctly compares two leases for equality.
|