|
@@ -184,57 +184,6 @@ TEST_F(Lease4Test, operatorAssign) {
|
|
|
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_, 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.
|
|
@@ -637,88 +586,6 @@ TEST(Lease6, Lease6ConstructorWithFQDN) {
|
|
|
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
|
|
|
///
|
|
|
/// Checks that the operator==() correctly compares two leases for equality.
|