Commit a715f62a authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[3153] pdReleaseBasic implemented

parent 361505f1
......@@ -1166,83 +1166,32 @@ TEST_F(Dhcpv6SrvTest, pdRenewReject) {
testRenewReject(Lease::TYPE_PD, IOAddress("2001:db8:1:2::"));
}
// This test verifies that incoming (positive) RELEASE can be handled properly,
// that a REPLY is generated, that the response has status code and that the
// lease is indeed removed from the database.
// This test verifies that incoming (positive) RELEASE with address can be
// handled properly, that a REPLY is generated, that the response has status
// code and that the lease is indeed removed from the database.
//
// expected:
// - returned REPLY message has copy of client-id
// - returned REPLY message has server-id
// - returned REPLY message has IA that does not include an IAADDR
// - returned REPLY message has IA_NA that does not include an IAADDR
// - lease is actually removed from LeaseMgr
TEST_F(Dhcpv6SrvTest, ReleaseBasic) {
NakedDhcpv6Srv srv(0);
const IOAddress addr("2001:db8:1:1::cafe:babe");
const uint32_t iaid = 234;
// Generate client-id also duid_
OptionPtr clientid = generateClientId();
// Check that the address we are about to use is indeed in pool
ASSERT_TRUE(subnet_->inPool(Lease::TYPE_NA, addr));
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid,
501, 502, 503, 504, subnet_->getID(), 0));
lease->cltt_ = 1234;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
addr);
ASSERT_TRUE(l);
// Let's create a RELEASE
Pkt6Ptr req = Pkt6Ptr(new Pkt6(DHCPV6_RELEASE, 1234));
req->setRemoteAddr(IOAddress("fe80::abcd"));
boost::shared_ptr<Option6IA> ia = generateIA(D6O_IA_NA, iaid, 1500, 3000);
OptionPtr released_addr_opt(new Option6IAAddr(D6O_IAADDR, addr, 300, 500));
ia->addOption(released_addr_opt);
req->addOption(ia);
req->addOption(clientid);
// Server-id is mandatory in RELEASE
req->addOption(srv.getServerID());
// Pass it to the server and hope for a REPLY
Pkt6Ptr reply = srv.processRelease(req);
// Check if we get response at all
checkResponse(reply, DHCPV6_REPLY, 1234);
OptionPtr tmp = reply->getOption(D6O_IA_NA);
ASSERT_TRUE(tmp);
// Check that IA_NA was returned and that there's an address included
ia = boost::dynamic_pointer_cast<Option6IA>(tmp);
checkIA_NAStatusCode(ia, STATUS_Success);
checkMsgStatusCode(reply, STATUS_Success);
// There should be no address returned in RELEASE (see RFC3315, 18.2.6)
EXPECT_FALSE(tmp->getOption(D6O_IAADDR));
// Check DUIDs
checkServerId(reply, srv.getServerID());
checkClientId(reply, clientid);
// Check that the lease is really gone in the database
// get lease by address
l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
ASSERT_FALSE(l);
testReleaseBasic(Lease::TYPE_NA, IOAddress("2001:db8:1:1::cafe:babe"),
IOAddress("2001:db8:1:1::cafe:babe"));
}
// get lease by subnetid/duid/iaid combination
l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, *duid_, iaid,
subnet_->getID());
ASSERT_FALSE(l);
// This test verifies that incoming (positive) RELEASE with prefix can be
// handled properly, that a REPLY is generated, that the response has
// status code and that the lease is indeed removed from the database.
//
// expected:
// - returned REPLY message has copy of client-id
// - returned REPLY message has server-id
// - returned REPLY message has IA_PD that does not include an IAPREFIX
// - lease is actually removed from LeaseMgr
TEST_F(Dhcpv6SrvTest, pdReleaseBasic) {
testReleaseBasic(Lease::TYPE_NA, IOAddress("2001:db8:1:2::"),
IOAddress("2001:db8:1:2::"));
}
// This test verifies that incoming (invalid) RELEASE can be handled properly.
......
......@@ -351,6 +351,80 @@ Dhcpv6SrvTest::testRenewReject(Lease::Type type, const IOAddress& addr) {
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr));
}
void
Dhcpv6SrvTest::testReleaseBasic(Lease::Type type, const IOAddress& existing,
const IOAddress& release_addr) {
NakedDhcpv6Srv srv(0);
const uint32_t iaid = 234;
uint32_t code; // option code of the container (IA_NA or IA_PD)
uint8_t prefix_len;
if (type == Lease::TYPE_NA) {
code = D6O_IA_NA;
prefix_len = 128;
} else if (type == Lease::TYPE_PD) {
code = D6O_IA_PD;
prefix_len = pd_pool_->getLength();
} else {
isc_throw(BadValue, "Invalid lease type");
}
// Generate client-id also duid_
OptionPtr clientid = generateClientId();
// Check that the address we are about to use is indeed in pool
ASSERT_TRUE(subnet_->inPool(type, existing));
// Let's prepopulate the database
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, existing, duid_, iaid,
501, 502, 503, 504, subnet_->getID(),
prefix_len));
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(type, existing);
ASSERT_TRUE(l);
// Let's create a RELEASE
Pkt6Ptr rel = createMessage(DHCPV6_RELEASE, type, release_addr, prefix_len,
iaid);
rel->addOption(clientid);
rel->addOption(srv.getServerID());
// Pass it to the server and hope for a REPLY
Pkt6Ptr reply = srv.processRelease(rel);
// Check if we get response at all
checkResponse(reply, DHCPV6_REPLY, 1234);
OptionPtr tmp = reply->getOption(code);
ASSERT_TRUE(tmp);
// Check that IA_NA was returned and that there's an address included
boost::shared_ptr<Option6IA> ia = boost::dynamic_pointer_cast<Option6IA>(tmp);
checkIA_NAStatusCode(ia, STATUS_Success);
checkMsgStatusCode(reply, STATUS_Success);
// There should be no address returned in RELEASE (see RFC3315, 18.2.6)
// There should be no prefix
EXPECT_FALSE(tmp->getOption(D6O_IAADDR));
EXPECT_FALSE(tmp->getOption(D6O_IAPREFIX));
// Check DUIDs
checkServerId(reply, srv.getServerID());
checkClientId(reply, clientid);
// Check that the lease is really gone in the database
// get lease by address
l = LeaseMgrFactory::instance().getLease6(type, release_addr);
ASSERT_FALSE(l);
// get lease by subnetid/duid/iaid combination
l = LeaseMgrFactory::instance().getLease6(type, *duid_, iaid,
subnet_->getID());
ASSERT_FALSE(l);
}
// Generate IA_NA option with specified parameters
boost::shared_ptr<Option6IA>
......
......@@ -429,6 +429,20 @@ public:
void
testRenewReject(Lease::Type type, const IOAddress& addr);
/// @brief Performs basic (positive) RELEASE test
///
/// See releaseBasic and pdReleaseBasic tests for detailed explanation.
/// In essence the test attempts to perform a successful RELEASE scenario.
///
/// This method does not throw, but uses gtest macros to signify failures.
///
/// @param type type (TYPE_NA or TYPE_PD)
/// @param existing address to be preinserted into the database
/// @param release_addr address being sent in RELEASE
void
testReleaseBasic(Lease::Type type, const IOAddress& existing,
const IOAddress& release_addr);
~Dhcpv6SrvTest() {
CfgMgr::instance().deleteSubnets6();
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment