mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-04 07:55:18 +00:00
[3982] Unit-tests fix.
This commit is contained in:
@@ -114,15 +114,15 @@ DeclineTest::acquireAndDecline(const std::string& duid1,
|
|||||||
ASSERT_NO_THROW(configure(DECLINE_CONFIGS[0], *client.getServer()));
|
ASSERT_NO_THROW(configure(DECLINE_CONFIGS[0], *client.getServer()));
|
||||||
|
|
||||||
// Let's get the subnet-id and generate statistics name out of it.
|
// Let's get the subnet-id and generate statistics name out of it.
|
||||||
const Subnet4Collection* subnets =
|
const Subnet6Collection* subnets =
|
||||||
CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll();
|
CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
|
||||||
ASSERT_EQ(1, subnets->size());
|
ASSERT_EQ(1, subnets->size());
|
||||||
std::stringstream name;
|
std::stringstream name;
|
||||||
name << "subnet[" << subnets->at(0)->getID() << "].declined-addresses";
|
name << "subnet[" << subnets->at(0)->getID() << "].declined-addresses";
|
||||||
|
|
||||||
// Set this statistic explicitly to zero.
|
// Set this statistic explicitly to zero.
|
||||||
isc::stats::StatsMgr::instance().setValue(name.str(), static_cast<int64_t>(0));
|
isc::stats::StatsMgr::instance().setValue(name.str(), static_cast<int64_t>(0));
|
||||||
|
|
||||||
// Perform 4-way exchange.
|
// Perform 4-way exchange.
|
||||||
ASSERT_NO_THROW(client.doSARR());
|
ASSERT_NO_THROW(client.doSARR());
|
||||||
|
|
||||||
@@ -143,16 +143,22 @@ DeclineTest::acquireAndDecline(const std::string& duid1,
|
|||||||
if (!decline_correct_address) {
|
if (!decline_correct_address) {
|
||||||
|
|
||||||
// Simple increase by one.
|
// Simple increase by one.
|
||||||
leases_client_na[0].addr_ = IOAddress::increase(leases_client_na[0].addr_);
|
client.config_.leases_[0].addr_ =
|
||||||
|
IOAddress::increase(client.config_.leases_[0].addr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ok, let's decline the lease.
|
// Use the second duid
|
||||||
client.setDUID(duid2);
|
client.setDUID(duid2);
|
||||||
client.useNA(iaid2);
|
|
||||||
|
// Use the second IAID
|
||||||
|
client.config_.leases_[0].iaid_ = iaid2;
|
||||||
|
|
||||||
|
// Ok, let's decline the lease.
|
||||||
ASSERT_NO_THROW(client.doDecline());
|
ASSERT_NO_THROW(client.doDecline());
|
||||||
|
|
||||||
// Let's check if there's a lease
|
// Let's check if there's a lease
|
||||||
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, acquired_address);
|
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
|
||||||
|
acquired_address);
|
||||||
ASSERT_TRUE(lease);
|
ASSERT_TRUE(lease);
|
||||||
|
|
||||||
declined_cnt = StatsMgr::instance().getObservation(name.str());
|
declined_cnt = StatsMgr::instance().getObservation(name.str());
|
||||||
@@ -178,7 +184,7 @@ DeclineTest::acquireAndDecline(const std::string& duid1,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This test checks that the client can acquire and decline the lease.
|
// This test checks that the client can acquire and decline the lease.
|
||||||
TEST_F(DeclineTest, declineBasic) {
|
TEST_F(DeclineTest, basic) {
|
||||||
acquireAndDecline("01:02:03:04:05:06", 1234,
|
acquireAndDecline("01:02:03:04:05:06", 1234,
|
||||||
"01:02:03:04:05:06", 1234,
|
"01:02:03:04:05:06", 1234,
|
||||||
true, SHOULD_PASS);
|
true, SHOULD_PASS);
|
||||||
@@ -188,7 +194,7 @@ TEST_F(DeclineTest, declineBasic) {
|
|||||||
// - Client acquires new lease using duid, iaid
|
// - Client acquires new lease using duid, iaid
|
||||||
// - Client sends the DHCPDECLINE with duid, iaid, but uses wrong address.
|
// - Client sends the DHCPDECLINE with duid, iaid, but uses wrong address.
|
||||||
// - The server rejects Decline due to address mismatch
|
// - The server rejects Decline due to address mismatch
|
||||||
TEST_F(DeclineTest, declineAddressMismatch) {
|
TEST_F(DeclineTest, addressMismatch) {
|
||||||
acquireAndDecline("01:02:03:04:05:06", 1234,
|
acquireAndDecline("01:02:03:04:05:06", 1234,
|
||||||
"01:02:03:04:05:06", 1234,
|
"01:02:03:04:05:06", 1234,
|
||||||
false, SHOULD_FAIL);
|
false, SHOULD_FAIL);
|
||||||
@@ -198,7 +204,7 @@ TEST_F(DeclineTest, declineAddressMismatch) {
|
|||||||
// - Client acquires new lease using duid, iaid1
|
// - Client acquires new lease using duid, iaid1
|
||||||
// - Client sends the DHCPDECLINE with duid, iaid2
|
// - Client sends the DHCPDECLINE with duid, iaid2
|
||||||
// - The server rejects Decline due to IAID mismatch
|
// - The server rejects Decline due to IAID mismatch
|
||||||
TEST_F(DeclineTest, declineIAIDMismatch) {
|
TEST_F(DeclineTest, iaidMismatch) {
|
||||||
acquireAndDecline("01:02:03:04:05:06", 1234,
|
acquireAndDecline("01:02:03:04:05:06", 1234,
|
||||||
"01:02:03:04:05:06", 1235,
|
"01:02:03:04:05:06", 1235,
|
||||||
true, SHOULD_FAIL);
|
true, SHOULD_FAIL);
|
||||||
@@ -208,10 +214,10 @@ TEST_F(DeclineTest, declineIAIDMismatch) {
|
|||||||
// - Client acquires new lease using duid1, iaid
|
// - Client acquires new lease using duid1, iaid
|
||||||
// - Client sends the DHCPDECLINE using duid2, iaid
|
// - Client sends the DHCPDECLINE using duid2, iaid
|
||||||
// - The server rejects the Decline due to DUID mismatch
|
// - The server rejects the Decline due to DUID mismatch
|
||||||
TEST_F(DeclineTest, declineDuidMismatch) {
|
TEST_F(DeclineTest, duidMismatch) {
|
||||||
acquireAndDecline("01:02:03:04:05:06", 1234,
|
acquireAndDecline("01:02:03:04:05:06", 1234,
|
||||||
"01:02:03:04:05:07", 1234,
|
"01:02:03:04:05:07", 1234,
|
||||||
true, SHOULD_PASS);
|
true, SHOULD_FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end of anonymous namespace
|
} // end of anonymous namespace
|
||||||
|
@@ -536,8 +536,8 @@ Dhcp6Client::doDecline() {
|
|||||||
} else {
|
} else {
|
||||||
query->addOption(forced_server_id_);
|
query->addOption(forced_server_id_);
|
||||||
}
|
}
|
||||||
copyIAs(context_.response_, query);
|
|
||||||
appendRequestedIAs(query);
|
generateIAFromLeases(query);
|
||||||
|
|
||||||
context_.query_ = query;
|
context_.query_ = query;
|
||||||
sendMsg(context_.query_);
|
sendMsg(context_.query_);
|
||||||
@@ -550,6 +550,23 @@ Dhcp6Client::doDecline() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Dhcp6Client::generateIAFromLeases(const Pkt6Ptr& query) {
|
||||||
|
/// @todo: add support for IAPREFIX here.
|
||||||
|
|
||||||
|
for (std::vector<Lease6>::const_iterator lease = config_.leases_.begin();
|
||||||
|
lease != config_.leases_.end(); ++lease) {
|
||||||
|
if (lease->type_ != Lease::TYPE_NA) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Option6IAPtr ia(new Option6IA(D6O_IA_NA, lease->iaid_));
|
||||||
|
|
||||||
|
ia->addOption(Option6IAAddrPtr(new Option6IAAddr(D6O_IAADDR,
|
||||||
|
lease->addr_, lease->preferred_lft_, lease->valid_lft_)));
|
||||||
|
query->addOption(ia);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Dhcp6Client::fastFwdTime(const uint32_t secs) {
|
Dhcp6Client::fastFwdTime(const uint32_t secs) {
|
||||||
|
@@ -565,6 +565,12 @@ public:
|
|||||||
return (duid_);
|
return (duid_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Generates IA_NA based on lease information
|
||||||
|
///
|
||||||
|
/// @param query generated IA_NA options will be added here
|
||||||
|
void
|
||||||
|
generateIAFromLeases(const Pkt6Ptr& query);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// @brief Applies the new leases for the client.
|
/// @brief Applies the new leases for the client.
|
||||||
|
Reference in New Issue
Block a user