BIND 10 trac2414, updated. 3d7a6b9c7e01032d583a61f5aa10065cb31fd5e1 [2414] Tests for selectSubnet() implemented.

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Nov 1 10:54:28 UTC 2012


The branch, trac2414 has been updated
       via  3d7a6b9c7e01032d583a61f5aa10065cb31fd5e1 (commit)
      from  fd7e25adfafa0696f3c13ae5f504ceb7a110c23e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 3d7a6b9c7e01032d583a61f5aa10065cb31fd5e1
Author: Tomek Mrugalski <tomasz at isc.org>
Date:   Thu Nov 1 11:54:17 2012 +0100

    [2414] Tests for selectSubnet() implemented.

-----------------------------------------------------------------------

Summary of changes:
 src/bin/dhcp6/dhcp6_srv.cc                |   13 ++++++++-----
 src/bin/dhcp6/dhcp6_srv.h                 |    2 +-
 src/bin/dhcp6/tests/dhcp6_srv_unittest.cc |   29 ++++++++++++++++++++++++++++-
 3 files changed, 37 insertions(+), 7 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc
index c801afc..a61d259 100644
--- a/src/bin/dhcp6/dhcp6_srv.cc
+++ b/src/bin/dhcp6/dhcp6_srv.cc
@@ -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();
diff --git a/src/bin/dhcp6/dhcp6_srv.h b/src/bin/dhcp6/dhcp6_srv.h
index b6daf49..1b17eda 100644
--- a/src/bin/dhcp6/dhcp6_srv.h
+++ b/src/bin/dhcp6/dhcp6_srv.h
@@ -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)
     ///
diff --git a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
index 3030c41..67ec5b7 100644
--- a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
+++ b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
@@ -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



More information about the bind10-changes mailing list