/// @param client_id_required true if client-id is expected
void checkLease4(isc::data::ConstElementPtr l, std::string ip,
uint32_t subnet_id, std::string hwaddr,
- bool client_id_required) {
+ bool client_id_required, uint32_t pool_id = 0) {
ASSERT_TRUE(l);
// If the element is a list we need to retrieve the lease that
EXPECT_TRUE(l->get("client-id"));
}
- // Check that other parameters are there.
+ if (pool_id) {
+ ASSERT_TRUE(l->get("pool-id"));
+ EXPECT_EQ(pool_id, l->get("pool-id")->intValue());
+ } else {
+ EXPECT_FALSE(l->get("pool-id"));
+ }
+
+ // Check that all expected fields are there.
ASSERT_TRUE(l->contains("valid-lft"));
ASSERT_TRUE(l->contains("cltt"));
ASSERT_TRUE(l->contains("subnet-id"));
ASSERT_TRUE(l->contains("hostname"));
ASSERT_TRUE(l->contains("state"));
- // Check that there are no v6 specific fields
+ // Check that there are no v6 specific fields.
ASSERT_FALSE(l->contains("prefix"));
ASSERT_FALSE(l->contains("duid"));
ASSERT_FALSE(l->contains("preferred-lft"));
/// @brief Verifies that the limit must be a number.
void testLease4GetPagedLimitNotNumber();
+ /// @brief Verifies that the limit of 0 is rejected.
+ void testLease4GetPagedLimitIsZero();
+
/// @brief Check that lease4-get-by-hw-address can handle a situation when
/// the query is broken (required parameter is missing).
void testLease4GetByHwAddressParams();
/// leases).
void testLease4GetByClientIdFind2();
- /// @brief Verifies that the limit of 0 is rejected.
- void testLease4GetPagedLimitIsZero();
-
/// @brief Check that lease4-get-by-hostname can handle a situation when
/// the query is broken (required parameter is missing).
void testLease4GetByHostnameParams();
// Initialize lease manager (false = v4, false = don't add leases)
initLeaseMgr(false, false);
- // Everything missing. What sort of crap is that?
+ // Everything missing. What sort of nonsense is that?
string txt =
"{\n"
" \"command\": \"lease4-add\",\n"
exp_rsp = "missing parameter 'hw-address' (<string>:3:19)";
testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
- // Better, but still no luck. (hwaddr missing).
+ // Just subnet-id and ip is not enough. (hwaddr missing).
txt =
"{\n"
" \"command\": \"lease4-add\",\n"
exp_rsp = "Non-IPv4 address specified: 2001:db8:1::1";
testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
- // currently defined states are 0,1 and 2. 123 is junk.
+ // Invalid state: the only supported values are 0,1,2.
txt =
"{\n"
" \"command\": \"lease4-add\",\n"
exp_rsp = "Duplicated comment entry '\"direct\"' in user context "
"'{ \"comment\": \"in user context\" }'";
testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
+
+ // Negative expiration time.
+ txt =
+ "{\n"
+ " \"command\": \"lease4-add\",\n"
+ " \"arguments\": {"
+ " \"subnet-id\": 44,\n"
+ " \"ip-address\": \"192.0.2.1\",\n"
+ " \"hw-address\": \"1a:1b:1c:1d:1e:1f\",\n"
+ " \"user-context\": { \"comment\": \"in user context\" },\n"
+ " \"expire\": -6218189367\n"
+ " }\n"
+ "}";
+ exp_rsp = "expiration time must be positive for address 192.0.2.1";
+ testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
+
+ // Negative cltt
+ txt =
+ "{\n"
+ " \"command\": \"lease4-add\",\n"
+ " \"arguments\": {"
+ " \"subnet-id\": 44,\n"
+ " \"ip-address\": \"192.0.2.1\",\n"
+ " \"hw-address\": \"1a:1b:1c:1d:1e:1f\",\n"
+ " \"user-context\": { \"comment\": \"in user context\" },\n"
+ " \"expire\": 123456,\n"
+ " \"valid-lft\": 123457"
+ " }\n"
+ "}";
+ exp_rsp = "expiration time must be greater than valid lifetime for address "
+ "192.0.2.1";
+ testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
}
void Lease4CmdsTest::testLease4Add() {
Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.202"));
ASSERT_TRUE(l);
- // Make sure the lease have proper value set.
+ // Make sure the lease has proper value set.
ASSERT_TRUE(l->hwaddr_);
EXPECT_EQ("1a:1b:1c:1d:1e:1f", l->hwaddr_->toText(false));
EXPECT_EQ(3, l->valid_lft_); // taken from subnet configuration
checkLease4Stats(88, 0, 0);
- // Now check that the lease is really there.
+ // Now check that the lease is really there and has correct subnet-id.
Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.202"));
ASSERT_TRUE(l);
EXPECT_EQ(44, l->subnet_id_);
checkLease4Stats(88, 0, 0);
- // Now check that the lease is really there.
+ // Now check that the lease is really there and has correct subnet-id.
Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.202"));
ASSERT_TRUE(l);
EXPECT_EQ(44, l->subnet_id_);
" \"fqdn-fwd\": true,\n"
" \"fqdn-rev\": true,\n"
" \"hostname\": \"urania.example.org\",\n"
+ " \"pool-id\": 5,\n"
" \"user-context\": { \"foobar\": true }\n"
" }\n"
"}";
EXPECT_EQ(true, l->fqdn_fwd_);
EXPECT_EQ(true, l->fqdn_rev_);
EXPECT_EQ("urania.example.org", l->hostname_);
+ EXPECT_EQ(5, l->pool_id_);
ASSERT_TRUE(l->getContext());
EXPECT_EQ("{ \"foobar\": true }", l->getContext()->str());
}
Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.202"));
ASSERT_TRUE(l);
- // Make sure the lease have proper value set.
+ // Make sure the lease has proper value set.
ASSERT_TRUE(l->hwaddr_);
EXPECT_EQ("1a:1b:1c:1d:1e:1f", l->hwaddr_->toText(false));
ASSERT_TRUE(l->getContext());
Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.202"));
ASSERT_TRUE(l);
- // Make sure the lease have proper value set.
+ // Make sure the lease has proper value set.
ASSERT_TRUE(l->hwaddr_);
EXPECT_EQ("1a:1b:1c:1d:1e:1f", l->hwaddr_->toText(false));
+
+ // Check the user context / extended info too.
ConstElementPtr ctx = l->getContext();
ASSERT_TRUE(ctx);
string expected = "{ \"ISC\": { \"relay-agent-info\": ";
" }\n"
"}";
string exp_rsp = "Lease not found.";
- ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
+
+ // Note the status expected is empty. The query completed correctly,
+ // just didn't found the lease.
+ testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
}
void Lease4CmdsTest::testLease4GetByAddr() {
// Initialize lease manager (false = v4, true = add leases)
initLeaseMgr(false, true);
- // Query for valid, existing lease.
+ // Now send the command.
string cmd =
"{\n"
" \"command\": \"lease4-get\",\n"
" }\n"
"}";
string exp_rsp = "IPv4 lease found.";
+
+ // The status expected is success. The lease should be returned.
ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
// Now check that the lease parameters were indeed returned.
ASSERT_TRUE(rsp);
+
ConstElementPtr lease = rsp->get("arguments");
ASSERT_TRUE(lease);
- // Let's check if the response makes any sense.
+ // Now check that the lease was indeed returned.
checkLease4(lease, "192.0.2.1", 44, "08:08:08:08:08:08", true);
}
" }\n"
"}";
string exp_rsp = "Lease not found.";
- ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
+ testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
}
void Lease4CmdsTest::testLease4GetByHWAddr() {
// Initialize lease manager (false = v4, true = add leases)
initLeaseMgr(false, true);
- // Invalid
+ // Now send the command.
string cmd =
"{\n"
" \"command\": \"lease4-get\",\n"
" }\n"
"}";
string exp_rsp = "IPv4 lease found.";
+
+ // The status expected is success. The lease should be returned.
ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
// Now check that the lease parameters were indeed returned.
ASSERT_TRUE(rsp);
+
ConstElementPtr lease = rsp->get("arguments");
ASSERT_TRUE(lease);
- // Let's check if the response makes any sense.
+ // Now check that the lease was indeed returned.
checkLease4(lease, "192.0.2.1", 44, "08:08:08:08:08:08", false);
}
" }\n"
"}";
string exp_rsp = "Lease not found.";
- ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
+ testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
}
void Lease4CmdsTest::testLease4GetByClientId() {
" }\n"
"}";
string exp_rsp = "IPv4 lease found.";
+
+ // The status expected is success. The lease should be returned.
ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
// Now check that the lease parameters were indeed returned.
ASSERT_TRUE(rsp);
+
ConstElementPtr lease = rsp->get("arguments");
ASSERT_TRUE(lease);
- // Let's check if the response makes any sense.
+ // Now check that the lease was indeed returned.
checkLease4(lease, "192.0.2.1", 44, "08:08:08:08:08:08", false);
}
// Let's check if the response contains desired leases.
checkLease4(leases, "192.0.2.1", 44, "08:08:08:08:08:08", true);
- checkLease4(leases, "192.0.2.2", 44, "09:09:09:09:09:09", true);
+ checkLease4(leases, "192.0.2.2", 44, "09:09:09:09:09:09", true, 5);
checkLease4(leases, "192.0.3.1", 88, "08:08:08:08:08:08", true);
checkLease4(leases, "192.0.3.2", 88, "09:09:09:09:09:09", true);
}
// Let's check if the response contains desired leases.
checkLease4(leases, "192.0.2.1", 44, "08:08:08:08:08:08", true);
- checkLease4(leases, "192.0.2.2", 44, "09:09:09:09:09:09", true);
+ checkLease4(leases, "192.0.2.2", 44, "09:09:09:09:09:09", true, 5);
}
void Lease4CmdsTest::testLease4GetAllBySubnetIdNoLeases() {
// Let's check if the response contains desired leases.
checkLease4(leases, "192.0.2.1", 44, "08:08:08:08:08:08", true);
- checkLease4(leases, "192.0.2.2", 44, "09:09:09:09:09:09", true);
+ checkLease4(leases, "192.0.2.2", 44, "09:09:09:09:09:09", true, 5);
checkLease4(leases, "192.0.3.1", 88, "08:08:08:08:08:08", true);
checkLease4(leases, "192.0.3.2", 88, "09:09:09:09:09:09", true);
}
// ask the Lease Manager.
Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(IOAddress(last_address));
ASSERT_TRUE(from_mgr);
+ uint32_t pool_id = 0;
+ if (last_address == "192.0.2.2") {
+ pool_id = 5;
+ }
checkLease4(leases, last_address, from_mgr->subnet_id_,
- from_mgr->hwaddr_->toText(false), true);
+ from_mgr->hwaddr_->toText(false), true, pool_id);
}
} else {
// Initialize lease manager (false = v4, true = add leases)
initLeaseMgr(false, true);
- // Everything missing. What sort of crap is that?
+ // Everything missing. What sort of nonsense is that?
string txt =
"{\n"
" \"command\": \"lease4-update\",\n"
testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
// Just ip is not enough (subnet-id and hwaddr missing, although
- // Kea can now figure out subnet-id on its own).
+ // Kea should be able to figure out the subnet-id on its own).
txt =
"{\n"
" \"command\": \"lease4-update\",\n"
// Initialize lease manager (false = v4, false = don't add leases)
initLeaseMgr(false, false);
+ checkLease4Stats(44, 0, 0);
+
+ checkLease4Stats(88, 0, 0);
+
// Now send the command.
string txt =
"{\n"
"either because the lease has been deleted or it has changed in the "
"database, in both cases a retry might succeed";
testCommand(txt, CONTROL_RESULT_CONFLICT, exp_rsp);
+
+ checkLease4Stats(44, 0, 0);
+
+ checkLease4Stats(88, 0, 0);
}
void Lease4CmdsTest::testLease4Update() {
" \"subnet-id\": 44,\n"
" \"ip-address\": \"192.0.2.1\",\n"
" \"hw-address\": \"1a:1b:1c:1d:1e:1f\",\n"
+ " \"pool-id\": 3,\n"
" \"hostname\": \"newhostname.example.org\""
" }\n"
"}";
checkLease4Stats(88, 2, 0);
- // Now check that the lease is still there.
+ // Now check that the lease is really there.
Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.1"));
ASSERT_TRUE(l);
- // Make sure it's been updated.
+ // Make sure the lease has been updated.
ASSERT_TRUE(l->hwaddr_);
EXPECT_EQ("1a:1b:1c:1d:1e:1f", l->hwaddr_->toText(false));
+ EXPECT_EQ(3, l->pool_id_);
EXPECT_EQ("newhostname.example.org", l->hostname_);
EXPECT_FALSE(l->getContext());
}
" \"subnet-id\": 44,\n"
" \"ip-address\": \"192.0.2.1\",\n"
" \"hw-address\": \"1a:1b:1c:1d:1e:1f\",\n"
+ " \"pool-id\": 3,\n"
" \"hostname\": \"newhostname.example.org\""
" }\n"
"}";
Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.1"));
ASSERT_TRUE(l);
- // Make sure it's been updated.
+ // Make sure the lease has been updated.
ASSERT_TRUE(l->hwaddr_);
EXPECT_EQ("1a:1b:1c:1d:1e:1f", l->hwaddr_->toText(false));
+ EXPECT_EQ(3, l->pool_id_);
EXPECT_EQ("newhostname.example.org", l->hostname_);
EXPECT_FALSE(l->getContext());
}
Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.1"));
ASSERT_TRUE(l);
- // Make sure it's been updated.
+ // Make sure the subnet-id is correct.
+ EXPECT_EQ(44, l->subnet_id_);
+
+ // Make sure the lease has been updated.
ASSERT_TRUE(l->hwaddr_);
EXPECT_EQ("1a:1b:1c:1d:1e:1f", l->hwaddr_->toText(false));
EXPECT_EQ("newhostname.example.org", l->hostname_);
checkLease4Stats(88, 2, 2);
- // Now check that the lease is still there.
+ // Now check that the lease is really there.
Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.1"));
ASSERT_TRUE(l);
- // Make sure it's been updated.
+ // Make sure the subnet-id is correct.
+ EXPECT_EQ(44, l->subnet_id_);
+
+ // Make sure the lease has been updated.
ASSERT_TRUE(l->hwaddr_);
EXPECT_EQ("1a:1b:1c:1d:1e:1f", l->hwaddr_->toText(false));
EXPECT_EQ("newhostname.example.org", l->hostname_);
checkLease4Stats(88, 0, 0);
- // Now check that the lease is still there.
+ // Now check that the lease is really there.
Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.1"));
ASSERT_TRUE(l);
- // Make sure it contains expected values..
+ // Make sure the lease is correct.
ASSERT_TRUE(l->hwaddr_);
EXPECT_EQ("1a:1b:1c:1d:1e:1f", l->hwaddr_->toText(false));
EXPECT_EQ("newhostname.example.org", l->hostname_);
checkLease4Stats(88, 0, 0);
- // Now check that the lease is still there.
+ // Now check that the lease is really there.
Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.1"));
ASSERT_TRUE(l);
// Make sure the subnet-id is figured out correctly.
EXPECT_EQ(44, l->subnet_id_);
- // Make sure it contains expected values..
+ // Make sure the lease is correct.
ASSERT_TRUE(l->hwaddr_);
EXPECT_EQ("1a:1b:1c:1d:1e:1f", l->hwaddr_->toText(false));
EXPECT_EQ("newhostname.example.org", l->hostname_);
checkLease4Stats(88, 2, 0);
- // Now check that the lease is still there.
+ // Now check that the lease is really there.
Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.1"));
ASSERT_TRUE(l);
- // Make sure it's been updated.
+ // Make sure the lease has been updated.
ASSERT_TRUE(l->hwaddr_);
EXPECT_EQ("42:42:42:42:42:42:42:42", l->hwaddr_->toText(false));
checkLease4Stats(88, 2, 0);
- // Now check that the lease is still there.
+ // Now check that the lease is really there.
Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.1"));
ASSERT_TRUE(l);
- // Make sure it's been updated.
+ // Make sure the lease has been updated.
ASSERT_TRUE(l->hwaddr_);
EXPECT_EQ("42:42:42:42:42:42:42:42", l->hwaddr_->toText(false));
- // Check user context.
+ // Check the user context / extended info too.
ConstElementPtr ctx = l->getContext();
ASSERT_TRUE(ctx);
string expected = "{ \"ISC\": { \"relay-agent-info\": ";
checkLease4Stats(88, 2, 0);
- // Invalid
+ // Now send the command.
string cmd =
"{\n"
" \"command\": \"lease4-del\",\n"
" }\n"
"}";
string exp_rsp = "IPv4 lease not found.";
+
+ // Note the status expected is empty. The query completed correctly,
+ // just didn't found the lease.
ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
checkLease4Stats(44, 2, 0);
checkLease4Stats(88, 2, 0);
- // Query for valid, existing lease.
+ // Now send the command.
string cmd =
"{\n"
" \"command\": \"lease4-del\",\n"
" }\n"
"}";
string exp_rsp = "IPv4 lease deleted.";
+
+ // The status expected is success. The lease should be deleted.
testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
checkLease4Stats(44, 1, 0);
checkLease4Stats(88, 2, 2);
- // Query for valid, existing lease.
+ // Now send the command.
string cmd =
"{\n"
" \"command\": \"lease4-del\",\n"
" }\n"
"}";
string exp_rsp = "IPv4 lease deleted.";
+
+ // The status expected is success. The lease should be deleted.
testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
checkLease4Stats(44, 1, 1);
checkLease4Stats(88, 2, 0);
- // Invalid
+ // Now send the command.
string cmd =
"{\n"
" \"command\": \"lease4-del\",\n"
" }\n"
"}";
string exp_rsp = "IPv4 lease deleted.";
+
+ // The status expected is success. The lease should be deleted.
ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
checkLease4Stats(44, 1, 0);
checkLease4Stats(88, 2, 0);
- // Invalid
+ // Now send the command.
string cmd =
"{\n"
" \"command\": \"lease4-del\",\n"
" }\n"
"}";
string exp_rsp = "IPv4 lease deleted.";
+
+ // The status expected is success. The lease should be deleted.
ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
checkLease4Stats(44, 1, 0);
checkLease4Stats(88, 2, 0);
- // Query for valid, existing lease.
+ // Now send the command.
string cmd =
"{\n"
" \"command\": \"lease4-wipe\",\n"
" }\n"
"}";
string exp_rsp = "Deleted 2 IPv4 lease(s) from subnet(s) 44";
+
+ // The status expected is success. The lease should be deleted.
testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
checkLease4Stats(44, 0, 0);
checkLease4Stats(88, 2, 0);
- // Query for valid, existing lease.
+ // Now send the command.
string cmd =
"{\n"
" \"command\": \"lease4-wipe\",\n"
" }\n"
"}";
string exp_rsp = "Deleted 4 IPv4 lease(s) from subnet(s) 44 88";
+
+ // The status expected is success. The lease should be deleted.
testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
checkLease4Stats(44, 0, 0);
checkLease4Stats(88, 2, 0);
- // Query for valid, existing lease.
+ // Now send the command.
string cmd =
"{\n"
" \"command\": \"lease4-wipe\"\n"
"}";
string exp_rsp = "Deleted 4 IPv4 lease(s) from subnet(s) 44 88";
+
+ // The status expected is success. The lease should be deleted.
testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
checkLease4Stats(44, 0, 0);
// Initialize lease manager (false = v4, true = add leases)
initLeaseMgr(false, true);
+ // Disable DDNS updating.
disableD2();
// Query for valid, existing lease.
" }\n"
"}\n";
string exp_rsp = "No lease found for: 192.0.2.5";
- ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
+ testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
}
void Lease4CmdsTest::testLease4ResendNoHostname() {
testLease4UpdateNoSubnetIdDeclinedLeases();
}
+TEST_F(Lease4CmdsTest, lease4UpdateComment) {
+ testLease4UpdateComment();
+}
+
+TEST_F(Lease4CmdsTest, lease4UpdateCommentMultiThreading) {
+ MultiThreadingTest mt(true);
+ testLease4UpdateComment();
+}
+
+TEST_F(Lease4CmdsTest, lease4UpdateExtendedInfo) {
+ testLease4UpdateExtendedInfo();
+}
+
+TEST_F(Lease4CmdsTest, lease4UpdateExtendedInfoMultiThreading) {
+ MultiThreadingTest mt(true);
+ testLease4UpdateExtendedInfo();
+}
+
TEST_F(Lease4CmdsTest, lease4UpdateForceCreate) {
testLease4UpdateForceCreate();
}
testLease4UpdateDoNotForceCreate();
}
-TEST_F(Lease4CmdsTest, lease4UpdateComment) {
- testLease4UpdateComment();
-}
-
-TEST_F(Lease4CmdsTest, lease4UpdateCommentMultiThreading) {
- MultiThreadingTest mt(true);
- testLease4UpdateComment();
-}
-
-TEST_F(Lease4CmdsTest, lease4UpdateExtendedInfo) {
- testLease4UpdateExtendedInfo();
-}
-
-TEST_F(Lease4CmdsTest, lease4UpdateExtendedInfoMultiThreading) {
- MultiThreadingTest mt(true);
- testLease4UpdateExtendedInfo();
-}
-
TEST_F(Lease4CmdsTest, lease4DelMissingParams) {
testLease4DelMissingParams();
}
testLease4WipeNoLeasesAll();
}
-
TEST_F(Lease4CmdsTest, lease4BrokenUpdate) {
testLease4BrokenUpdate();
}
/// @param duid expected value of DUID
/// @param hwaddr_required true if hwaddr is expected
void checkLease6(isc::data::ConstElementPtr l, std::string ip,
- uint8_t prefixlen,
- uint32_t subnet_id, std::string duid,
- bool hwaddr_required) {
+ uint8_t prefixlen, uint32_t subnet_id, std::string duid,
+ bool hwaddr_required, uint32_t pool_id = 0) {
ASSERT_TRUE(l);
// If the element is a list we need to retrieve the lease that
ASSERT_TRUE(l);
}
- ASSERT_TRUE(l->contains("ip-address"));
+ ASSERT_TRUE(l->get("ip-address"));
EXPECT_EQ(ip, l->get("ip-address")->stringValue());
if (prefixlen != 0) {
ASSERT_TRUE(l->get("prefix-len"));
EXPECT_EQ(prefixlen, l->get("prefix-len")->intValue());
}
- ASSERT_TRUE(l->contains("subnet-id"));
+ ASSERT_TRUE(l->get("subnet-id"));
EXPECT_EQ(subnet_id, l->get("subnet-id")->intValue());
- ASSERT_TRUE(l->contains("duid"));
+ ASSERT_TRUE(l->get("duid"));
EXPECT_EQ(duid, l->get("duid")->stringValue());
// hwaddr may or may not appear
EXPECT_TRUE(l->get("hwaddr"));
}
- // Check that there are expected fields
+ if (pool_id) {
+ ASSERT_TRUE(l->get("pool-id"));
+ EXPECT_EQ(pool_id, l->get("pool-id")->intValue());
+ } else {
+ EXPECT_FALSE(l->get("pool-id"));
+ }
+
+ // Check that all expected fields are there.
ASSERT_TRUE(l->contains("preferred-lft"));
ASSERT_TRUE(l->contains("valid-lft"));
ASSERT_TRUE(l->contains("cltt"));
/// @brief Check that a well formed lease6 with a comment can be added.
void testLease6AddComment();
+ /// @brief Check that a well formed lease6 with relay and remote ids
+ /// can be added.
+ void testLease6AddExtendedInfo();
+
/// @brief Check that lease6-get can handle a situation when the query is
/// broken (some required parameters are missing).
void testLease6GetMissingParams();
/// @brief Check that lease6-get can return a lease by prefix.
void testLease6GetByAddrPrefix();
- /// @bfief Check that lease6-get rejects queries by client-id.
+ /// @brief Check that lease6-get rejects queries by client-id.
void testLease6GetByClientIdInvalidType();
/// @brief Check that lease6-get can handle a situation when the query is
/// correctly formed, but the lease is not there.
void testLease6GetByDuidNotFound();
- /// @bfief Check that lease6-get can find a lease by duid.
+ /// @brief Check that lease6-get can find a lease by duid.
void testLease6GetByDuid();
/// @brief Check that lease6-get-all returns all leases.
/// lease to be updated.
void testLease6UpdateNoLease();
- /// @brief Check that a lease6 can be updated. We're changing hw-address,
- /// hostname and extended info.
- void testLease6UpdateExtendedInfo();
-
/// @brief Check that a lease6 can be updated. We're changing hw-address and
/// a hostname.
void testLease6Update();
/// user context.
void testLease6UpdateComment();
+ /// @brief Check that a lease6 can be updated. We're changing hw-address,
+ /// hostname and extended info.
+ void testLease6UpdateExtendedInfo();
+
/// @brief Check that lease6-del can handle a situation when the query is
/// broken (some required parameters are missing).
void testLease6DelMissingParams();
string exp_rsp = "missing parameter 'ip-address' (<string>:3:19)";
testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
- // Just ip is not enough (subnet-id and duid missing, but subnet-id
- // can now be figured out by kea)
+ // Just ip is not enough (subnet-id and duid missing, although
+ // subnet-id can now be figured out by Kea code)
txt =
"{\n"
" \"command\": \"lease6-add\",\n"
// Now check that the lease is really there.
Lease6Ptr l = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::3"));
ASSERT_TRUE(l);
+
+ // Make sure the lease has proper value set.
+ ASSERT_TRUE(l->duid_);
+ EXPECT_EQ("1a:1b:1c:1d:1e:1f", l->duid_->toText());
+ EXPECT_EQ(4, l->valid_lft_); // taken from subnet configuration
+ EXPECT_FALSE(l->fqdn_fwd_);
+ EXPECT_FALSE(l->fqdn_rev_);
EXPECT_EQ("", l->hostname_);
EXPECT_FALSE(l->getContext());
// Now check that the lease is really there.
Lease6Ptr l = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::3"));
ASSERT_TRUE(l);
+
+ // Make sure the lease has proper value set.
+ ASSERT_TRUE(l->duid_);
+ EXPECT_EQ("1a:1b:1c:1d:1e:1f", l->duid_->toText());
+ EXPECT_EQ(4, l->valid_lft_); // taken from subnet configuration
+ EXPECT_FALSE(l->fqdn_fwd_);
+ EXPECT_FALSE(l->fqdn_rev_);
EXPECT_EQ("", l->hostname_);
EXPECT_FALSE(l->getContext());
checkLease6Stats(99, 0, 0, 0);
- // Now send the command (without subnet-id)
+ // Now send the command without subnet-id. Kea should select
+ // the subnet id on its own.
string txt =
"{\n"
" \"command\": \"lease6-add\",\n"
checkLease6Stats(99, 0, 0, 0);
- // Now send the command (without subnet-id)
+ // Now send the command without subnet-id. Kea should select
+ // the subnet id on its own.
string txt =
"{\n"
" \"command\": \"lease6-add\",\n"
checkLease6Stats(99, 0, 0, 0);
- // Now send the command (without subnet-id)
+ // Now send the command without subnet-id. Kea should select
+ // the subnet id on its own.
string txt =
"{\n"
" \"command\": \"lease6-add\",\n"
" \"fqdn-fwd\": true,\n"
" \"fqdn-rev\": true,\n"
" \"hostname\": \"urania.example.org\",\n"
+ " \"pool-id\": 5,\n"
" \"user-context\": { \"foobar\": true }\n"
" }\n"
"}";
EXPECT_EQ(true, l->fqdn_fwd_);
EXPECT_EQ(true, l->fqdn_rev_);
EXPECT_EQ("urania.example.org", l->hostname_);
+ EXPECT_EQ(5, l->pool_id_);
ASSERT_TRUE(l->getContext());
EXPECT_EQ("{ \"foobar\": true }", l->getContext()->str());
}
Lease6Ptr l = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::3"));
ASSERT_TRUE(l);
- // Make sure the lease have proper value set.
+ // Make sure the lease has proper value set.
+ ASSERT_TRUE(l->duid_);
+ EXPECT_EQ("1a:1b:1c:1d:1e:1f", l->duid_->toText());
ASSERT_TRUE(l->getContext());
EXPECT_EQ("{ \"comment\": \"a comment\" }", l->getContext()->str());
}
-void Lease6CmdsTest::testLease6GetByAddrNotFound() {
- // Initialize lease manager (true = v6, true = add leases)
- initLeaseMgr(true, true);
-
- // Now send the command.
- string cmd =
- "{\n"
- " \"command\": \"lease6-get\",\n"
- " \"arguments\": {"
- " \"subnet-id\": 1,\n"
- " \"ip-address\": \"2001:db8:1::10\"\n"
- " }\n"
- "}";
- string exp_rsp = "Lease not found.";
-
- // Note the status expected is empty. The query completed correctly,
- // just didn't found the lease.
- testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
-}
+void Lease6CmdsTest::testLease6AddExtendedInfo() {
+ // Initialize lease manager (true = v6, false = don't add leases)
+ initLeaseMgr(true, false);
-void Lease6CmdsTest::testLease6GetByClientIdInvalidType() {
- // Initialize lease manager (true = v6, true = add leases)
- initLeaseMgr(true, true);
+ checkLease6Stats(66, 0, 0, 0);
- // client-id query is allowed in v4 only.
- string cmd =
- "{\n"
- " \"command\": \"lease6-get\",\n"
- " \"arguments\": {"
- " \"identifier-type\": \"client-id\","
- " \"identifier\": \"01:02:03:04\","
- " \"subnet-id\": 44"
- " }\n"
- "}";
- string exp_rsp = "Query by client-id is not allowed in v6.";
- ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
-}
+ checkLease6Stats(99, 0, 0, 0);
-void Lease6CmdsTest::testLease6GetByDuidNotFound() {
- // Initialize lease manager (true = v6, true = add leases)
- initLeaseMgr(true, true);
+ Lease6Collection leases;
+ vector<uint8_t> remote_id = { 1, 2, 3, 4, 5, 6 };
+ leases = lmptr_->getLeases6ByRemoteId(remote_id,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ 0,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ LeasePageSize(10));
+ EXPECT_TRUE(leases.empty());
+ vector<uint8_t> relay_bin(8, 0x64);
+ DuidPtr relay_id(new DUID(relay_bin));
+ leases = lmptr_->getLeases6ByRelayId(*relay_id,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ 0,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ LeasePageSize(10));
+ EXPECT_TRUE(leases.empty());
// Now send the command.
- string cmd =
+ string txt =
"{\n"
- " \"command\": \"lease6-get\",\n"
+ " \"command\": \"lease6-add\",\n"
" \"arguments\": {"
- " \"subnet-id\": 1,\n"
- " \"identifier-type\": \"duid\","
- " \"identifier\": \"00:01:02:03:04:05:06:07\"\n"
+ " \"subnet-id\": 66,\n"
+ " \"ip-address\": \"2001:db8:1::1\",\n"
+ " \"iaid\": 7654321,\n"
+ " \"duid\": \"88:88:88:88:88:88:88:88\",\n"
+ " \"hostname\": \"newhostname.example.org\",\n"
+ " \"user-context\": { \"ISC\": { \"relay-info\": [ {\n"
+ " \"remote-id\": \"010203040506\",\n"
+ " \"relay-id\": \"6464646464646464\" } ] } }\n"
" }\n"
"}";
- string exp_rsp = "Lease not found.";
+ string exp_rsp = "Lease for address 2001:db8:1::1, subnet-id 66 added.";
+ testCommand(txt, CONTROL_RESULT_SUCCESS, exp_rsp);
- // Note the status expected is empty. The query completed correctly,
- // just didn't found the lease.
- testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
-}
+ checkLease6Stats(66, 1, 0, 0);
-void Lease6CmdsTest::testLease6GetByAddr() {
- // Initialize lease manager (true = v6, true = add leases)
- initLeaseMgr(true, true);
+ checkLease6Stats(99, 0, 0, 0);
- // Now send the command.
- string cmd =
- "{\n"
- " \"command\": \"lease6-get\",\n"
- " \"arguments\": {\n"
- " \"ip-address\": \"2001:db8:1::1\"\n"
- " }\n"
- "}";
- string exp_rsp = "IPv6 lease found.";
+ // Now check that the lease is really there.
+ Lease6Ptr l = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"));
+ ASSERT_TRUE(l);
- // The status expected is success. The lease should be returned.
- ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
- ASSERT_TRUE(rsp);
+ // Make sure the lease has proper value set.
+ ASSERT_TRUE(l->duid_);
+ EXPECT_EQ("88:88:88:88:88:88:88:88", l->duid_->toText());
+ EXPECT_EQ("newhostname.example.org", l->hostname_);
+ EXPECT_EQ(7654321, l->iaid_);
- ConstElementPtr lease = rsp->get("arguments");
- ASSERT_TRUE(lease);
+ // Check the user context / extended info too.
+ ConstElementPtr ctx = l->getContext();
+ ASSERT_TRUE(ctx);
+ string expected = "{ \"ISC\": { \"relay-info\": ";
+ expected += "[ { \"relay-id\": \"6464646464646464\", ";
+ expected += "\"remote-id\": \"010203040506\" } ] } }";
+ EXPECT_EQ(expected, ctx->str());
- // Now check that the lease was indeed returned.
- checkLease6(lease, "2001:db8:1::1", 0, 66, "42:42:42:42:42:42:42:42", false);
+ // Check that BLQ tables were updated.
+ leases = lmptr_->getLeases6ByRemoteId(remote_id,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ 0,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ LeasePageSize(10));
+ // The lease must be retrieved from the remote id table.
+ ASSERT_EQ(1, leases.size());
+ Lease6Ptr lx = leases[0];
+ ASSERT_TRUE(lx);
+ EXPECT_EQ(IOAddress("2001:db8:1::1"), lx->addr_);
+ EXPECT_EQ(*l, *lx);
+
+ // The lease must be retrieved from the relay id table.
+ leases = lmptr_->getLeases6ByRelayId(*relay_id,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ 0,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ LeasePageSize(10));
+ ASSERT_EQ(1, leases.size());
+ lx = leases[0];
+ ASSERT_TRUE(lx);
+ EXPECT_EQ(IOAddress("2001:db8:1::1"), lx->addr_);
+ EXPECT_EQ(*l, *lx);
}
void Lease6CmdsTest::testLease6GetMissingParams() {
testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
}
+void Lease6CmdsTest::testLease6GetByAddrNotFound() {
+ // Initialize lease manager (true = v6, true = add leases)
+ initLeaseMgr(true, true);
+
+ // Invalid
+ string cmd =
+ "{\n"
+ " \"command\": \"lease6-get\",\n"
+ " \"arguments\": {"
+ " \"subnet-id\": 1,\n"
+ " \"ip-address\": \"2001:db8:1::10\"\n"
+ " }\n"
+ "}";
+ string exp_rsp = "Lease not found.";
+
+ // Note the status expected is empty. The query completed correctly,
+ // just didn't found the lease.
+ testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
+}
+
+void Lease6CmdsTest::testLease6GetByClientIdInvalidType() {
+ // Initialize lease manager (true = v6, true = add leases)
+ initLeaseMgr(true, true);
+
+ // client-id query is allowed in v4 only.
+ string cmd =
+ "{\n"
+ " \"command\": \"lease6-get\",\n"
+ " \"arguments\": {"
+ " \"identifier-type\": \"client-id\","
+ " \"identifier\": \"01:02:03:04\","
+ " \"subnet-id\": 44"
+ " }\n"
+ "}";
+ string exp_rsp = "Query by client-id is not allowed in v6.";
+ testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
+}
+
+void Lease6CmdsTest::testLease6GetByDuidNotFound() {
+ // Initialize lease manager (true = v6, true = add leases)
+ initLeaseMgr(true, true);
+
+ // Now send the command.
+ string cmd =
+ "{\n"
+ " \"command\": \"lease6-get\",\n"
+ " \"arguments\": {"
+ " \"subnet-id\": 1,\n"
+ " \"identifier-type\": \"duid\","
+ " \"identifier\": \"00:01:02:03:04:05:06:07\"\n"
+ " }\n"
+ "}";
+ string exp_rsp = "Lease not found.";
+
+ // Note the status expected is empty. The query completed correctly,
+ // just didn't found the lease.
+ testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
+}
+
+void Lease6CmdsTest::testLease6GetByAddr() {
+ // Initialize lease manager (true = v6, true = add leases)
+ initLeaseMgr(true, true);
+
+ // Now send the command.
+ string cmd =
+ "{\n"
+ " \"command\": \"lease6-get\",\n"
+ " \"arguments\": {\n"
+ " \"ip-address\": \"2001:db8:1::1\"\n"
+ " }\n"
+ "}";
+ string exp_rsp = "IPv6 lease found.";
+
+ // The status expected is success. The lease should be returned.
+ ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
+
+ // Now check that the lease parameters were indeed returned.
+ ASSERT_TRUE(rsp);
+
+ ConstElementPtr lease = rsp->get("arguments");
+ ASSERT_TRUE(lease);
+
+ // Now check that the lease was indeed returned.
+ checkLease6(lease, "2001:db8:1::1", 0, 66, "42:42:42:42:42:42:42:42", false);
+}
void Lease6CmdsTest::testLease6GetByAddrPrefix() {
// Initialize lease manager (true = v6, false = don't add leases)
initLeaseMgr(true, false);
// The status expected is success. The lease should be returned.
ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
+
+ // Now check that the lease parameters were indeed returned.
ASSERT_TRUE(rsp);
ConstElementPtr lease = rsp->get("arguments");
// The status expected is success. The lease should be returned.
ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
+
+ // Now check that the lease parameters were indeed returned.
ASSERT_TRUE(rsp);
ConstElementPtr lease = rsp->get("arguments");
// Let's check if the response contains desired leases.
checkLease6(leases, "2001:db8:1::1", 0, 66, "42:42:42:42:42:42:42:42", false);
- checkLease6(leases, "2001:db8:1::2", 0, 66, "56:56:56:56:56:56:56:56", false);
+ checkLease6(leases, "2001:db8:1::2", 0, 66, "56:56:56:56:56:56:56:56", false, 5);
checkLease6(leases, "2001:db8:2::1", 0, 99, "42:42:42:42:42:42:42:42", false);
checkLease6(leases, "2001:db8:2::2", 0, 99, "56:56:56:56:56:56:56:56", false);
}
// Let's check if the response contains desired leases.
checkLease6(leases, "2001:db8:1::1", 0, 66, "42:42:42:42:42:42:42:42", false);
- checkLease6(leases, "2001:db8:1::2", 0, 66, "56:56:56:56:56:56:56:56", false);
+ checkLease6(leases, "2001:db8:1::2", 0, 66, "56:56:56:56:56:56:56:56", false, 5);
}
void Lease6CmdsTest::testLease6GetAllBySubnetIdNoLeases() {
// Let's check if the response contains desired leases.
checkLease6(leases, "2001:db8:1::1", 0, 66, "42:42:42:42:42:42:42:42", false);
- checkLease6(leases, "2001:db8:1::2", 0, 66, "56:56:56:56:56:56:56:56", false);
+ checkLease6(leases, "2001:db8:1::2", 0, 66, "56:56:56:56:56:56:56:56", false, 5);
checkLease6(leases, "2001:db8:2::1", 0, 99, "42:42:42:42:42:42:42:42", false);
checkLease6(leases, "2001:db8:2::2", 0, 99, "56:56:56:56:56:56:56:56", false);
}
Lease6Ptr from_mgr = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
IOAddress(last_address));
ASSERT_TRUE(from_mgr);
+ uint32_t pool_id = 0;
+ if (last_address == "2001:db8:1::2") {
+ pool_id = 5;
+ }
checkLease6(leases, last_address, 0, from_mgr->subnet_id_,
- from_mgr->duid_->toText(), false);
+ from_mgr->duid_->toText(), false, pool_id);
}
} else {
// Initialize lease manager (true = v6, true = add leases)
initLeaseMgr(true, true);
- // Everything missing. What sort of crap is that?
+ // Everything missing. What sort of nonsense is that?
string txt =
"{\n"
" \"command\": \"lease6-update\",\n"
testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
// Just ip is not enough (subnet-id and duid missing, although
- // kea should be able to figure out the subnet-id on its own.
+ // Kea should be able to figure out the subnet-id on its own.
txt =
"{\n"
" \"command\": \"lease6-update\",\n"
exp_rsp = "The address 3000::1 does not belong to subnet 2001:db8:1::/48, subnet-id=66";
testCommand(txt, CONTROL_RESULT_CONFLICT, exp_rsp);
- // Nope, can't do v4 address in v6 lease.
+ // v4? You're a time traveler from early 80s or what?
txt =
"{\n"
" \"command\": \"lease6-update\",\n"
testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
}
-void Lease6CmdsTest::testLease6Update() {
- // Initialize lease manager (true = v6, true = add leases)
- initLeaseMgr(true, true);
+void Lease6CmdsTest::testLease6UpdateNoLease() {
+ // Initialize lease manager (true = v6, false = don't add leases)
+ initLeaseMgr(true, false);
- checkLease6Stats(66, 2, 0, 0);
+ checkLease6Stats(66, 0, 0, 0);
- checkLease6Stats(99, 2, 0, 0);
+ checkLease6Stats(99, 0, 0, 0);
// Now send the command.
string txt =
" \"hostname\": \"newhostname.example.org\""
" }\n"
"}";
- string exp_rsp = "IPv6 lease updated.";
- testCommand(txt, CONTROL_RESULT_SUCCESS, exp_rsp);
-
- checkLease6Stats(66, 2, 0, 0);
-
- checkLease6Stats(99, 2, 0, 0);
+ string exp_rsp = "failed to update the lease with address 2001:db8:1::1 "
+ "either because the lease has been deleted or it has changed in the "
+ "database, in both cases a retry might succeed";
+ testCommand(txt, CONTROL_RESULT_CONFLICT, exp_rsp);
- // Now check that the lease is really there.
- Lease6Ptr l = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"));
- ASSERT_TRUE(l);
+ checkLease6Stats(66, 0, 0, 0);
- // Make sure the lease has been updated.
- ASSERT_TRUE(l->duid_);
- EXPECT_EQ("88:88:88:88:88:88:88:88", l->duid_->toText());
- EXPECT_EQ("newhostname.example.org", l->hostname_);
- EXPECT_EQ(7654321, l->iaid_);
- EXPECT_FALSE(l->getContext());
+ checkLease6Stats(99, 0, 0, 0);
}
-void Lease6CmdsTest::testLease6UpdateExtendedInfo() {
+void Lease6CmdsTest::testLease6Update() {
// Initialize lease manager (true = v6, true = add leases)
initLeaseMgr(true, true);
checkLease6Stats(99, 2, 0, 0);
- Lease6Collection leases;
- vector<uint8_t> remote_id = { 1, 2, 3, 4, 5, 6 };
- leases = lmptr_->getLeases6ByRemoteId(remote_id,
- IOAddress::IPV6_ZERO_ADDRESS(),
- 0,
- IOAddress::IPV6_ZERO_ADDRESS(),
- LeasePageSize(10));
- EXPECT_TRUE(leases.empty());
- vector<uint8_t> relay_bin(8, 0x64);
- DuidPtr relay_id(new DUID(relay_bin));
- leases = lmptr_->getLeases6ByRelayId(*relay_id,
- IOAddress::IPV6_ZERO_ADDRESS(),
- 0,
- IOAddress::IPV6_ZERO_ADDRESS(),
- LeasePageSize(10));
- EXPECT_TRUE(leases.empty());
-
// Now send the command.
string txt =
"{\n"
" \"ip-address\": \"2001:db8:1::1\",\n"
" \"iaid\": 7654321,\n"
" \"duid\": \"88:88:88:88:88:88:88:88\",\n"
- " \"hostname\": \"newhostname.example.org\",\n"
- " \"user-context\": { \"ISC\": { \"relay-info\": [ {\n"
- " \"remote-id\": \"010203040506\",\n"
- " \"relay-id\": \"6464646464646464\" } ] } }\n"
+ " \"pool-id\": 3,\n"
+ " \"hostname\": \"newhostname.example.org\""
" }\n"
"}";
string exp_rsp = "IPv6 lease updated.";
// Make sure the lease has been updated.
ASSERT_TRUE(l->duid_);
EXPECT_EQ("88:88:88:88:88:88:88:88", l->duid_->toText());
+ EXPECT_EQ(3, l->pool_id_);
EXPECT_EQ("newhostname.example.org", l->hostname_);
EXPECT_EQ(7654321, l->iaid_);
-
- // Check the user context / extended info too.
- ConstElementPtr ctx = l->getContext();
- ASSERT_TRUE(ctx);
- string expected = "{ \"ISC\": { \"relay-info\": ";
- expected += "[ { \"relay-id\": \"6464646464646464\", ";
- expected += "\"remote-id\": \"010203040506\" } ] } }";
- EXPECT_EQ(expected, ctx->str());
-
- // Check that BLQ tables were updated.
- leases = lmptr_->getLeases6ByRemoteId(remote_id,
- IOAddress::IPV6_ZERO_ADDRESS(),
- 0,
- IOAddress::IPV6_ZERO_ADDRESS(),
- LeasePageSize(10));
- // The lease must be retrieved from the remote id table.
- ASSERT_EQ(1, leases.size());
- Lease6Ptr lx = leases[0];
- ASSERT_TRUE(lx);
- EXPECT_EQ(IOAddress("2001:db8:1::1"), lx->addr_);
- EXPECT_EQ(*l, *lx);
-
- // The lease must be retrieved from the relay id table.
- leases = lmptr_->getLeases6ByRelayId(*relay_id,
- IOAddress::IPV6_ZERO_ADDRESS(),
- 0,
- IOAddress::IPV6_ZERO_ADDRESS(),
- LeasePageSize(10));
- ASSERT_EQ(1, leases.size());
- lx = leases[0];
- ASSERT_TRUE(lx);
- EXPECT_EQ(IOAddress("2001:db8:1::1"), lx->addr_);
- EXPECT_EQ(*l, *lx);
+ EXPECT_FALSE(l->getContext());
}
void Lease6CmdsTest::testLease6UpdateDeclinedLeases() {
" \"ip-address\": \"2001:db8:1::1\",\n"
" \"iaid\": 7654321,\n"
" \"duid\": \"88:88:88:88:88:88:88:88\",\n"
+ " \"pool-id\": 3,\n"
" \"hostname\": \"newhostname.example.org\""
" }\n"
"}";
checkLease6Stats(99, 2, 2, 0);
- // Now check that the lease is really there.
+ // Now check that the lease is still there.
Lease6Ptr l = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"));
ASSERT_TRUE(l);
// Make sure the lease has been updated.
ASSERT_TRUE(l->duid_);
EXPECT_EQ("88:88:88:88:88:88:88:88", l->duid_->toText());
+ EXPECT_EQ(3, l->pool_id_);
EXPECT_EQ("newhostname.example.org", l->hostname_);
EXPECT_EQ(7654321, l->iaid_);
EXPECT_FALSE(l->getContext());
checkLease6Stats(99, 2, 0, 0);
- // Now check that the lease is really there.
- Lease6Ptr l = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"));
- ASSERT_TRUE(l);
-
- // Make sure the subnet-id is correct.
- EXPECT_EQ(66, l->subnet_id_);
-
- // Make sure the lease has been updated.
- ASSERT_TRUE(l->duid_);
- EXPECT_EQ("88:88:88:88:88:88:88:88", l->duid_->toText());
- EXPECT_EQ("newhostname.example.org", l->hostname_);
- EXPECT_EQ(7654321, l->iaid_);
- EXPECT_FALSE(l->getContext());
-}
-
-void Lease6CmdsTest::testLease6UpdateNoSubnetIdDeclinedLeases() {
- // Initialize lease manager (true = v6, true = add leases)
- initLeaseMgr(true, true, true);
-
- checkLease6Stats(66, 2, 2, 0);
-
- checkLease6Stats(99, 2, 2, 0);
-
- // Now send the command.
- string txt =
- "{\n"
- " \"command\": \"lease6-update\",\n"
- " \"arguments\": {"
- " \"ip-address\": \"2001:db8:1::1\",\n"
- " \"iaid\": 7654321,\n"
- " \"duid\": \"88:88:88:88:88:88:88:88\",\n"
- " \"hostname\": \"newhostname.example.org\""
- " }\n"
- "}";
- string exp_rsp = "IPv6 lease updated.";
- testCommand(txt, CONTROL_RESULT_SUCCESS, exp_rsp);
-
- checkLease6Stats(66, 2, 1, 0);
-
- checkLease6Stats(99, 2, 2, 0);
-
- // Now check that the lease is really there.
- Lease6Ptr l = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"));
- ASSERT_TRUE(l);
-
- // Make sure the subnet-id is correct.
- EXPECT_EQ(66, l->subnet_id_);
-
- // Make sure the lease has been updated.
- ASSERT_TRUE(l->duid_);
- EXPECT_EQ("88:88:88:88:88:88:88:88", l->duid_->toText());
- EXPECT_EQ("newhostname.example.org", l->hostname_);
- EXPECT_EQ(7654321, l->iaid_);
- EXPECT_FALSE(l->getContext());
-}
-
-void Lease6CmdsTest::testLease6UpdateComment() {
- // Initialize lease manager (true = v6, true = add leases)
- initLeaseMgr(true, true);
-
- checkLease6Stats(66, 2, 0, 0);
-
- checkLease6Stats(99, 2, 0, 0);
-
- // Now send the command.
- string txt =
- "{\n"
- " \"command\": \"lease6-update\",\n"
- " \"arguments\": {"
- " \"subnet-id\": 66,\n"
- " \"ip-address\": \"2001:db8:1::1\",\n"
- " \"iaid\": 42,\n"
- " \"duid\": \"42:42:42:42:42:42:42:42\",\n"
- " \"comment\": \"a comment\",\n"
- " \"user-context\": { \"foobar\": true }\n"
- " }\n"
- "}";
- string exp_rsp = "IPv6 lease updated.";
- testCommand(txt, CONTROL_RESULT_SUCCESS, exp_rsp);
-
- checkLease6Stats(66, 2, 0, 0);
-
- checkLease6Stats(99, 2, 0, 0);
-
- // Now check that the lease is really there.
- Lease6Ptr l = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"));
- ASSERT_TRUE(l);
-
- // Make sure the lease has been updated.
- ASSERT_TRUE(l->duid_);
-
- // Check user context.
- ConstElementPtr ctx = l->getContext();
- ASSERT_TRUE(ctx);
- EXPECT_EQ(2, ctx->size());
- ASSERT_TRUE(ctx->contains("comment"));
- EXPECT_EQ("\"a comment\"", ctx->get("comment")->str());
- ASSERT_TRUE(ctx->contains("foobar"));
- EXPECT_EQ("true", ctx->get("foobar")->str());
+ // Now check that the lease is still there.
+ Lease6Ptr l = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"));
+ ASSERT_TRUE(l);
+
+ // Make sure the subnet-id is correct.
+ EXPECT_EQ(66, l->subnet_id_);
+
+ // Make sure the lease has been updated.
+ ASSERT_TRUE(l->duid_);
+ EXPECT_EQ("88:88:88:88:88:88:88:88", l->duid_->toText());
+ EXPECT_EQ("newhostname.example.org", l->hostname_);
+ EXPECT_EQ(7654321, l->iaid_);
+ EXPECT_FALSE(l->getContext());
}
-void Lease6CmdsTest::testLease6UpdateNoLease() {
- // Initialize lease manager (true = v6, false = don't add leases)
- initLeaseMgr(true, false);
+void Lease6CmdsTest::testLease6UpdateNoSubnetIdDeclinedLeases() {
+ // Initialize lease manager (true = v6, true = add leases)
+ initLeaseMgr(true, true, true);
- checkLease6Stats(66, 0, 0, 0);
+ checkLease6Stats(66, 2, 2, 0);
- checkLease6Stats(99, 0, 0, 0);
+ checkLease6Stats(99, 2, 2, 0);
// Now send the command.
string txt =
"{\n"
" \"command\": \"lease6-update\",\n"
" \"arguments\": {"
- " \"subnet-id\": 66,\n"
" \"ip-address\": \"2001:db8:1::1\",\n"
" \"iaid\": 7654321,\n"
" \"duid\": \"88:88:88:88:88:88:88:88\",\n"
" \"hostname\": \"newhostname.example.org\""
" }\n"
"}";
- string exp_rsp = "failed to update the lease with address 2001:db8:1::1 "
- "either because the lease has been deleted or it has changed in the "
- "database, in both cases a retry might succeed";
- testCommand(txt, CONTROL_RESULT_CONFLICT, exp_rsp);
+ string exp_rsp = "IPv6 lease updated.";
+ testCommand(txt, CONTROL_RESULT_SUCCESS, exp_rsp);
- checkLease6Stats(66, 0, 0, 0);
+ checkLease6Stats(66, 2, 1, 0);
- checkLease6Stats(99, 0, 0, 0);
+ checkLease6Stats(99, 2, 2, 0);
+
+ // Now check that the lease is really there.
+ Lease6Ptr l = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"));
+ ASSERT_TRUE(l);
+
+ // Make sure the subnet-id is correct.
+ EXPECT_EQ(66, l->subnet_id_);
+
+ // Make sure the lease has been updated.
+ ASSERT_TRUE(l->duid_);
+ EXPECT_EQ("88:88:88:88:88:88:88:88", l->duid_->toText());
+ EXPECT_EQ("newhostname.example.org", l->hostname_);
+ EXPECT_EQ(7654321, l->iaid_);
+ EXPECT_FALSE(l->getContext());
}
void Lease6CmdsTest::testLease6UpdateForceCreate() {
checkLease6Stats(99, 0, 0, 0);
}
+void Lease6CmdsTest::testLease6UpdateComment() {
+ // Initialize lease manager (true = v6, true = add leases)
+ initLeaseMgr(true, true);
+
+ checkLease6Stats(66, 2, 0, 0);
+
+ checkLease6Stats(99, 2, 0, 0);
+
+ // Now send the command.
+ string txt =
+ "{\n"
+ " \"command\": \"lease6-update\",\n"
+ " \"arguments\": {"
+ " \"subnet-id\": 66,\n"
+ " \"ip-address\": \"2001:db8:1::1\",\n"
+ " \"iaid\": 42,\n"
+ " \"duid\": \"42:42:42:42:42:42:42:42\",\n"
+ " \"comment\": \"a comment\",\n"
+ " \"user-context\": { \"foobar\": true }\n"
+ " }\n"
+ "}";
+ string exp_rsp = "IPv6 lease updated.";
+ testCommand(txt, CONTROL_RESULT_SUCCESS, exp_rsp);
+
+ checkLease6Stats(66, 2, 0, 0);
+
+ checkLease6Stats(99, 2, 0, 0);
+
+ // Now check that the lease is really there.
+ Lease6Ptr l = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"));
+ ASSERT_TRUE(l);
+
+ // Make sure the lease has been updated.
+ ASSERT_TRUE(l->duid_);
+ EXPECT_EQ("42:42:42:42:42:42:42:42", l->duid_->toText());
+
+ // Check user context.
+ ConstElementPtr ctx = l->getContext();
+ ASSERT_TRUE(ctx);
+ EXPECT_EQ(2, ctx->size());
+ ASSERT_TRUE(ctx->contains("comment"));
+ EXPECT_EQ("\"a comment\"", ctx->get("comment")->str());
+ ASSERT_TRUE(ctx->contains("foobar"));
+ EXPECT_EQ("true", ctx->get("foobar")->str());
+}
+
+void Lease6CmdsTest::testLease6UpdateExtendedInfo() {
+ // Initialize lease manager (true = v6, true = add leases)
+ initLeaseMgr(true, true);
+
+ checkLease6Stats(66, 2, 0, 0);
+
+ checkLease6Stats(99, 2, 0, 0);
+
+ Lease6Collection leases;
+ vector<uint8_t> remote_id = { 1, 2, 3, 4, 5, 6 };
+ leases = lmptr_->getLeases6ByRemoteId(remote_id,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ 0,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ LeasePageSize(10));
+ EXPECT_TRUE(leases.empty());
+ vector<uint8_t> relay_bin(8, 0x64);
+ DuidPtr relay_id(new DUID(relay_bin));
+ leases = lmptr_->getLeases6ByRelayId(*relay_id,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ 0,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ LeasePageSize(10));
+ EXPECT_TRUE(leases.empty());
+
+ // Now send the command.
+ string txt =
+ "{\n"
+ " \"command\": \"lease6-update\",\n"
+ " \"arguments\": {"
+ " \"subnet-id\": 66,\n"
+ " \"ip-address\": \"2001:db8:1::1\",\n"
+ " \"iaid\": 7654321,\n"
+ " \"duid\": \"88:88:88:88:88:88:88:88\",\n"
+ " \"hostname\": \"newhostname.example.org\",\n"
+ " \"user-context\": { \"ISC\": { \"relay-info\": [ {\n"
+ " \"remote-id\": \"010203040506\",\n"
+ " \"relay-id\": \"6464646464646464\" } ] } }\n"
+ " }\n"
+ "}";
+ string exp_rsp = "IPv6 lease updated.";
+ testCommand(txt, CONTROL_RESULT_SUCCESS, exp_rsp);
+
+ checkLease6Stats(66, 2, 0, 0);
+
+ checkLease6Stats(99, 2, 0, 0);
+
+ // Now check that the lease is really there.
+ Lease6Ptr l = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"));
+ ASSERT_TRUE(l);
+
+ // Make sure the lease has been updated.
+ ASSERT_TRUE(l->duid_);
+ EXPECT_EQ("88:88:88:88:88:88:88:88", l->duid_->toText());
+ EXPECT_EQ("newhostname.example.org", l->hostname_);
+ EXPECT_EQ(7654321, l->iaid_);
+
+ // Check the user context / extended info too.
+ ConstElementPtr ctx = l->getContext();
+ ASSERT_TRUE(ctx);
+ string expected = "{ \"ISC\": { \"relay-info\": ";
+ expected += "[ { \"relay-id\": \"6464646464646464\", ";
+ expected += "\"remote-id\": \"010203040506\" } ] } }";
+ EXPECT_EQ(expected, ctx->str());
+
+ // Check that BLQ tables were updated.
+ leases = lmptr_->getLeases6ByRemoteId(remote_id,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ 0,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ LeasePageSize(10));
+ // The lease must be retrieved from the remote id table.
+ ASSERT_EQ(1, leases.size());
+ Lease6Ptr lx = leases[0];
+ ASSERT_TRUE(lx);
+ EXPECT_EQ(IOAddress("2001:db8:1::1"), lx->addr_);
+ EXPECT_EQ(*l, *lx);
+
+ // The lease must be retrieved from the relay id table.
+ leases = lmptr_->getLeases6ByRelayId(*relay_id,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ 0,
+ IOAddress::IPV6_ZERO_ADDRESS(),
+ LeasePageSize(10));
+ ASSERT_EQ(1, leases.size());
+ lx = leases[0];
+ ASSERT_TRUE(lx);
+ EXPECT_EQ(IOAddress("2001:db8:1::1"), lx->addr_);
+ EXPECT_EQ(*l, *lx);
+}
+
void Lease6CmdsTest::testLease6DelMissingParams() {
// No parameters whatsoever. You want just a lease, any lease?
string cmd =
// Initialize lease manager (true = v6, true = add leases)
initLeaseMgr(true, true);
+ checkLease6Stats(66, 2, 0, 0);
+
+ checkLease6Stats(99, 2, 0, 0);
+
// Invalid family
string cmd =
"{\n"
string exp_rsp = "Invalid IPv6 address specified: 192.0.2.1";
testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
+ checkLease6Stats(66, 2, 0, 0);
+
+ checkLease6Stats(99, 2, 0, 0);
+
// This is way off
cmd =
"{\n"
" }\n"
"}\n";
string exp_rsp = "No lease found for: 2001::dead:beef";
- ConstElementPtr rsp = testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
+ testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
}
void Lease6CmdsTest::testLease6ResendNoHostname() {
ASSERT_FALSE(lease);
}
+// Verify that v4 lease add handles conflict as expected.
void Lease6CmdsTest::testLease6ConflictingAdd() {
MultiThreadingTest mt(true);
// Initialize lease manager (true = v6, true = add leases)
initLeaseMgr(true, true);
- // Verify lease stats show leases.
+ // Verify stats show no leases.
checkLease6Stats(66, 2, 0, 0);
// Make sure the lease exists.
}
void Lease6CmdsTest::testLease6Write() {
+ // lease4-write negative tests. Positive tests are in the
+ // memfile_lease_mgr_unittest.cc file.
+
// Initialize lease manager (true = v6, false = don't add leases)
initLeaseMgr(true, false);
testLease6AddComment();
}
+TEST_F(Lease6CmdsTest, lease6AddExtendedInfo) {
+ testLease6AddExtendedInfo();
+}
+
+TEST_F(Lease6CmdsTest, lease6AddExtendedInfoMultiThreading) {
+ MultiThreadingTest mt(true);
+ testLease6AddExtendedInfo();
+}
+
+TEST_F(Lease6CmdsTest, lease6GetMissingParams) {
+ testLease6GetMissingParams();
+}
+
+TEST_F(Lease6CmdsTest, lease6GetMissingParamsMultiThreading) {
+ MultiThreadingTest mt(true);
+ testLease6GetMissingParams();
+}
+
+TEST_F(Lease6CmdsTest, lease6GetByAddrBadParam) {
+ testLease6GetByAddrBadParam();
+}
+
+TEST_F(Lease6CmdsTest, lease6GetByAddrBadParamMultiThreading) {
+ MultiThreadingTest mt(true);
+ testLease6GetByAddrBadParam();
+}
+
TEST_F(Lease6CmdsTest, lease6GetByAddrNotFound) {
testLease6GetByAddrNotFound();
}
testLease6GetByAddr();
}
-TEST_F(Lease6CmdsTest, lease6GetMissingParams) {
- testLease6GetMissingParams();
-}
-
-TEST_F(Lease6CmdsTest, lease6GetMissingParamsMultiThreading) {
- MultiThreadingTest mt(true);
- testLease6GetMissingParams();
-}
-
-TEST_F(Lease6CmdsTest, lease6GetByAddrBadParam) {
- testLease6GetByAddrBadParam();
-}
-
-TEST_F(Lease6CmdsTest, lease6GetByAddrBadParamMultiThreading) {
- MultiThreadingTest mt(true);
- testLease6GetByAddrBadParam();
-}
-
TEST_F(Lease6CmdsTest, lease6GetByAddrPrefix) {
testLease6GetByAddrPrefix();
}
testLease6UpdateBadParams();
}
-TEST_F(Lease6CmdsTest, lease6Update) {
- testLease6Update();
+TEST_F(Lease6CmdsTest, lease6UpdateNoLease) {
+ testLease6UpdateNoLease();
}
-TEST_F(Lease6CmdsTest, lease6UpdateExtendedInfo) {
- testLease6UpdateExtendedInfo();
+TEST_F(Lease6CmdsTest, lease6UpdateNoLeaseMultiThreading) {
+ MultiThreadingTest mt(true);
+ testLease6UpdateNoLease();
+}
+
+TEST_F(Lease6CmdsTest, lease6Update) {
+ testLease6Update();
}
TEST_F(Lease6CmdsTest, lease6UpdateMultiThreading) {
testLease6UpdateComment();
}
-TEST_F(Lease6CmdsTest, lease6UpdateNoLease) {
- testLease6UpdateNoLease();
+TEST_F(Lease6CmdsTest, lease6UpdateExtendedInfo) {
+ testLease6UpdateExtendedInfo();
}
-TEST_F(Lease6CmdsTest, lease6UpdateNoLeaseMultiThreading) {
+TEST_F(Lease6CmdsTest, lease6UpdateExtendedInfoMultiThreading) {
MultiThreadingTest mt(true);
- testLease6UpdateNoLease();
+ testLease6UpdateExtendedInfo();
}
TEST_F(Lease6CmdsTest, lease6UpdateForceCreate) {