Commit 3d7a6b9c authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[2414] Tests for selectSubnet() implemented.

parent fd7e25ad
......@@ -40,6 +40,7 @@ using namespace isc::asiolink;
using namespace isc::dhcp;
using namespace isc::util;
using namespace std;
using namespace boost;
const std::string HARDCODED_DNS_SERVER = "2001:db8:1::1";
......@@ -319,7 +320,7 @@ OptionPtr Dhcpv6Srv::createStatusCode(uint16_t code, const std::string& text) {
return (status);
}
Subnet6Ptr Dhcpv6Srv::getSubnet(const Pkt6Ptr& question) {
Subnet6Ptr Dhcpv6Srv::selectSubnet(const Pkt6Ptr& question) {
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(question->getRemoteAddr());
return (subnet);
......@@ -327,7 +328,7 @@ Subnet6Ptr Dhcpv6Srv::getSubnet(const Pkt6Ptr& question) {
void Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer) {
Subnet6Ptr subnet = getSubnet(question);
Subnet6Ptr subnet = selectSubnet(question);
if (subnet) {
cout << "#### Selected subnet " << subnet->toText() << endl;
} else {
......@@ -347,10 +348,12 @@ void Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer) {
cout << "#### Failed to find client-id :(" << endl;
}
for (Option::OptionCollection::iterator opt = question->options_.begin(); opt != question->options_.end(); ++opt) {
for (Option::OptionCollection::iterator opt = question->options_.begin();
opt != question->options_.end(); ++opt) {
switch (opt->second->getType()) {
case D6O_IA_NA: {
OptionPtr answer_opt = handleIA_NA(subnet, duid, question, boost::dynamic_pointer_cast<Option6IA>(opt->second));
OptionPtr answer_opt = handleIA_NA(subnet, duid, question,
boost::dynamic_pointer_cast<Option6IA>(opt->second));
if (answer_opt) {
answer->addOption(answer_opt);
}
......@@ -371,7 +374,7 @@ OptionPtr Dhcpv6Srv::handleIA_NA(const Subnet6Ptr& subnet, const DuidPtr& duid,
return (ia_rsp);
}
boost::shared_ptr<Option6IAAddr> hintOpt = boost::dynamic_pointer_cast<Option6IAAddr>(ia->getOption(D6O_IAADDR));
shared_ptr<Option6IAAddr> hintOpt = dynamic_pointer_cast<Option6IAAddr>(ia->getOption(D6O_IAADDR));
IOAddress hint("::");
cout << "#### Processing request IA_NA: iaid=" << ia->getIAID();
......
......@@ -161,7 +161,7 @@ protected:
/// @brief selects a subnet for a given client's packet
///
/// @return selected subnet (or NULL if no suitable subnet was found)
isc::dhcp::Subnet6Ptr getSubnet(const Pkt6Ptr& question);
isc::dhcp::Subnet6Ptr selectSubnet(const Pkt6Ptr& question);
/// @brief processes IA_NA option (and assigns addresses if necessary)
///
......
......@@ -50,6 +50,7 @@ public:
using Dhcpv6Srv::processSolicit;
using Dhcpv6Srv::processRequest;
using Dhcpv6Srv::createStatusCode;
using Dhcpv6Srv::selectSubnet;
};
class Dhcpv6SrvTest : public ::testing::Test {
......@@ -264,6 +265,9 @@ TEST_F(Dhcpv6SrvTest, DUID) {
}
}
// There are no dedicated tests for Dhcpv6Srv::handleIA_NA and Dhcpv6Srv::assignLeases
// as they are indirectly tested in Solicit and Request tests.
// This test verifies that incoming SOLICIT can be handled properly, that a
// reponse is generated, that the response has an address and that address
// really belongs to the configured pool.
......@@ -478,7 +482,6 @@ TEST_F(Dhcpv6SrvTest, RequestBasic) {
LeaseMgr::instance().deleteLease6(addr->getAddress());
}
TEST_F(Dhcpv6SrvTest, serverReceivedPacketName) {
// Check all possible packet types
for (int itype = 0; itype < 256; ++itype) {
......@@ -524,6 +527,7 @@ TEST_F(Dhcpv6SrvTest, serverReceivedPacketName) {
}
}
// This test verifies if the status code option is generated properly.
TEST_F(Dhcpv6SrvTest, StatusCode) {
boost::scoped_ptr<NakedDhcpv6Srv> srv;
ASSERT_NO_THROW( srv.reset(new NakedDhcpv6Srv(0)) );
......@@ -537,4 +541,27 @@ TEST_F(Dhcpv6SrvTest, StatusCode) {
EXPECT_TRUE(status->getData() == exp);
}
// This test verifies if the selectSubnet() method works as expected.
TEST_F(Dhcpv6SrvTest, SelectSubnet) {
boost::scoped_ptr<NakedDhcpv6Srv> srv;
ASSERT_NO_THROW( srv.reset(new NakedDhcpv6Srv(0)) );
Pkt6Ptr pkt = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 1234));
// check that the packets originating from local addresses can be
pkt->setRemoteAddr(IOAddress("fe80::abcd"));
EXPECT_EQ(subnet_, srv->selectSubnet(pkt));
// packets originating from subnet A will select subnet A
pkt->setRemoteAddr(IOAddress("2001:db8:1::6789"));
EXPECT_EQ(subnet_, srv->selectSubnet(pkt));
// packets from a subnet that is not supported will not get
// a subnet
pkt->setRemoteAddr(IOAddress("3000::faf"));
EXPECT_FALSE(srv->selectSubnet(pkt));
/// @todo: expand this test once support for relays is implemented
}
} // end of anonymous namespace
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