bool
LeaseCmdsImpl::addOrUpdate4(Lease4Ptr lease, bool force_create) {
+ if (lease->stateRegistered()) {
+ isc_throw(BadValue, "DHCPv4 leases do not support registered state");
+ }
+
Lease4Ptr existing = LeaseMgrFactory::instance().getLease4(lease->addr_);
if (force_create && !existing) {
// lease does not exist
/// remote ids.
void testLease4UpdateExtendedInfo();
+ /// @brief Check that lease4-update prohibits registered state.
+ void testLease4UpdateRegisteredInvalid();
+
/// @brief Check that lease4-del can handle a situation when the query is
/// broken (some required parameters are missing).
void testLease4DelMissingParams();
EXPECT_EQ(*l, *leases[0]);
}
+void Lease4CmdsTest::testLease4UpdateRegisteredInvalid() {
+ // Initialize lease manager (false = v4, true = add leases)
+ initLeaseMgr(false, true);
+
+ checkLease4Stats(0, 4, 0);
+ checkLease4Stats(44, 2, 0);
+ checkLease4Stats(88, 2, 0);
+
+ // Now send the command.
+ string txt =
+ "{\n"
+ " \"command\": \"lease4-update\",\n"
+ " \"arguments\": {"
+ " \"ip-address\": \"192.0.2.1\",\n"
+ " \"hw-address\": \"1a:1b:1c:1d:1e:1f\",\n"
+ " \"hostname\": \"newhostname.example.org\",\n"
+ " \"state\": 4\n"
+ " }\n"
+ "}";
+
+ string exp_rsp = "DHCPv4 leases do not support registered state";
+ testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
+
+ // Stats should not have changed.
+ checkLease4Stats(0, 4, 0);
+ checkLease4Stats(44, 2, 0);
+ checkLease4Stats(88, 2, 0);
+
+ // Check that the lease is still there.
+ Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.1"));
+ ASSERT_TRUE(l);
+
+ // State should not have changed.
+ EXPECT_EQ(l->state_, Lease::STATE_DEFAULT);
+}
+
void Lease4CmdsTest::testLease4DelMissingParams() {
// No parameters whatsoever. You want just a lease, any lease?
string cmd =
testLease4AddExtendedInfo();
}
+TEST_F(Lease4CmdsTest, lease4UpdateRegisteredInvalid) {
+ testLease4UpdateRegisteredInvalid();
+}
+
+TEST_F(Lease4CmdsTest, lease4UpdateRegisteredInvalidMultiThreading) {
+ MultiThreadingTest mt(true);
+ testLease4UpdateRegisteredInvalid();
+}
+
TEST_F(Lease4CmdsTest, lease4AddExtendedInfoMultiThreading) {
MultiThreadingTest mt(true);
testLease4AddExtendedInfo();
}
void
-LeaseMgr::bumpStatPrefixPool(const std::string& stat, SubnetID& subnet_id, PoolPtr pool, int value) {
+LeaseMgr::bumpStatPrefix(const std::string& stat, SubnetID& subnet_id, PoolPtr pool, int value) {
StatsMgr::instance().addValue(stat, static_cast<int64_t>(value));
StatsMgr::instance().addValue(StatsMgr::generateName("subnet", subnet_id, stat),
static_cast<int64_t>(value));
if (existing->type_ == Lease::TYPE_NA) {
bumpStat("assigned-nas", existing->subnet_id_, pool, 1);
} else {
- bumpStatPrefixPool("assigned-pds", existing->subnet_id_, pool, 1);
+ bumpStatPrefix("assigned-pds", existing->subnet_id_, pool, 1);
}
break;
if (existing->type_ == Lease::TYPE_NA) {
bumpStat("assigned-nas", existing->subnet_id_, pool, -1);
} else {
- bumpStatPrefixPool("assigned-pds", existing->subnet_id_, pool, -1);
+ bumpStatPrefix("assigned-pds", existing->subnet_id_, pool, -1);
}
break;
bumpStat("assigned-nas", existing->subnet_id_, existing_pool, -1);
bumpStat("assigned-nas", lease->subnet_id_, new_pool, 1);
} else {
- bumpStatPrefixPool("assigned-pds", existing->subnet_id_, existing_pool, -1);
- bumpStatPrefixPool("assigned-pds", lease->subnet_id_, new_pool, 1);
+ bumpStatPrefix("assigned-pds", existing->subnet_id_, existing_pool, -1);
+ bumpStatPrefix("assigned-pds", lease->subnet_id_, new_pool, 1);
}
break;
if (lease->type_ == Lease::TYPE_NA) {
bumpStat("assigned-nas", lease->subnet_id_, new_pool, 1);
} else {
- bumpStatPrefixPool("assigned-pds", lease->subnet_id_, new_pool, 1);
+ bumpStatPrefix("assigned-pds", lease->subnet_id_, new_pool, 1);
}
break;
if (lease->type_ == Lease::TYPE_NA) {
bumpStat("assigned-nas", existing->subnet_id_, existing_pool, -1);
} else {
- bumpStatPrefixPool("assigned-pds", existing->subnet_id_, existing_pool, -1);
+ bumpStatPrefix("assigned-pds", existing->subnet_id_, existing_pool, -1);
}
break;
/// @param pool pointer to the pool (if one) within the subnet, if empty
/// pool level is skipped.
/// @param value signed value to add to the statistic
- static void bumpStatPrefixPool(const std::string& stat, SubnetID&
- subnet_id, PoolPtr pool, int value);
+ static void bumpStatPrefix(const std::string& stat, SubnetID&
+ subnet_id, PoolPtr pool, int value);
protected:
/// Extended information / Bulk Lease Query shared interface.
{ __LINE__, Lease::STATE_DEFAULT, Lease::STATE_DEFAULT, 1, 1 },
{ __LINE__, Lease::STATE_DEFAULT, Lease::STATE_DECLINED, 1, 0 },
{ __LINE__, Lease::STATE_DEFAULT, Lease::STATE_EXPIRED_RECLAIMED, 2, 1 },
+ { __LINE__, Lease::STATE_DEFAULT, Lease::STATE_RELEASED, 2, 1 },
// New state DECLINED
{ __LINE__, Lease::STATE_DECLINED, Lease::STATE_DEFAULT, 1, 2 },
{ __LINE__, Lease::STATE_DECLINED, Lease::STATE_DECLINED, 1, 1 },
{ __LINE__, Lease::STATE_DECLINED, Lease::STATE_EXPIRED_RECLAIMED, 2, 2 },
+ { __LINE__, Lease::STATE_DECLINED, Lease::STATE_RELEASED, 2, 2 },
// New state EXPIRED_RECLAIMED
{ __LINE__, Lease::STATE_EXPIRED_RECLAIMED, Lease::STATE_DEFAULT, 0, 1 },
{ __LINE__, Lease::STATE_EXPIRED_RECLAIMED, Lease::STATE_DECLINED, 0, 0 },
{ __LINE__, Lease::STATE_EXPIRED_RECLAIMED, Lease::STATE_EXPIRED_RECLAIMED, 1, 1 },
+ { __LINE__, Lease::STATE_EXPIRED_RECLAIMED, Lease::STATE_RELEASED, 1, 1 },
// New state RELEASED
{ __LINE__, Lease::STATE_RELEASED, Lease::STATE_DEFAULT, 0, 1 },