Browse Source

[2994] selectSubnet(), hooks tests for subnet4_select fixes.

Tomek Mrugalski 11 years ago
parent
commit
02141f2524
2 changed files with 21 additions and 16 deletions
  1. 3 1
      src/bin/dhcp4/dhcp4_srv.cc
  2. 18 15
      src/bin/dhcp4/tests/dhcp4_srv_unittest.cc

+ 3 - 1
src/bin/dhcp4/dhcp4_srv.cc

@@ -885,7 +885,7 @@ Dhcpv4Srv::selectSubnet(const Pkt4Ptr& question) {
     Subnet4Ptr subnet;
     // Is this relayed message?
     IOAddress relay = question->getGiaddr();
-    if (relay.toText() == "0.0.0.0") {
+    if (relay.toText() != "0.0.0.0") {
 
         // Yes: Use relay address to select subnet
         subnet = CfgMgr::instance().getSubnet4(relay);
@@ -895,6 +895,8 @@ Dhcpv4Srv::selectSubnet(const Pkt4Ptr& question) {
         subnet = CfgMgr::instance().getSubnet4(question->getRemoteAddr());
     }
 
+    /// @todo Implement getSubnet4(interface-name)
+
     // Let's execute all callouts registered for packet_received
     if (HooksManager::getHooksManager().calloutsPresent(hook_index_subnet4_select_)) {
         CalloutHandlePtr callout_handle = getCalloutHandle(question);

+ 18 - 15
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc

@@ -1622,6 +1622,11 @@ TEST_F(Dhcpv4SrvTest, ServerID) {
     EXPECT_EQ(srvid_text, text);
 }
 
+/// @todo Implement tests for subnetSelect See tests in dhcp6_srv_unittest.cc:
+/// selectSubnetAddr, selectSubnetIface, selectSubnetRelayLinkaddr,
+/// selectSubnetRelayInterfaceId. Note that the concept of interface-id is not
+/// present in the DHCPv4, so not everything is applicable directly.
+
 // Checks if hooks are registered properly.
 TEST_F(Dhcpv4SrvTest, Hooks) {
     NakedDhcpv4Srv srv(0);
@@ -1909,14 +1914,14 @@ public:
         // Call the basic calllout to record all passed values
         subnet4_select_callout(callout_handle);
 
-        Subnet4Collection subnets;
+        const Subnet4Collection* subnets;
         Subnet4Ptr subnet;
         callout_handle.getArgument("subnet4", subnet);
         callout_handle.getArgument("subnet4collection", subnets);
 
         // Let's change to a different subnet
-        if (subnets.size() > 1) {
-            subnet = subnets[1]; // Let's pick the other subnet
+        if (subnets->size() > 1) {
+            subnet = (*subnets)[1]; // Let's pick the other subnet
             callout_handle.setArgument("subnet4", subnet);
         }
 
@@ -2222,16 +2227,15 @@ TEST_F(HooksDhcpv4SrvTest, subnet4_select) {
     // Configure 2 subnets, both directly reachable over local interface
     // (let's not complicate the matter with relays)
     string config = "{ \"interface\": [ \"all\" ],"
-        "\"preferred-lifetime\": 3000,"
         "\"rebind-timer\": 2000, "
         "\"renew-timer\": 1000, "
         "\"subnet4\": [ { "
-        "    \"pool\": [ \"2001:db8:1::/44\" ],"
-        "    \"subnet\": \"2001:db8:1::/48\", "
+        "    \"pool\": [ \"192.0.2.0/25\" ],"
+        "    \"subnet\": \"192.0.2.0/24\", "
         "    \"interface\": \"" + valid_iface_ + "\" "
         " }, {"
-        "    \"pool\": [ \"2001:db8:2::/44\" ],"
-        "    \"subnet\": \"2001:db8:2::/48\" "
+        "    \"pool\": [ \"192.0.3.0/25\" ],"
+        "    \"subnet\": \"192.0.3.0/24\" "
         " } ],"
         "\"valid-lifetime\": 4000 }";
 
@@ -2246,7 +2250,7 @@ TEST_F(HooksDhcpv4SrvTest, subnet4_select) {
 
     // Prepare discover packet. Server should select first subnet for it
     Pkt4Ptr sol = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
-    sol->setRemoteAddr(IOAddress("fe80::abcd"));
+    sol->setRemoteAddr(IOAddress("192.0.2.1"));
     sol->setIface(valid_iface_);
     OptionPtr clientid = generateClientId();
     sol->addOption(clientid);
@@ -2289,16 +2293,15 @@ TEST_F(HooksDhcpv4SrvTest, subnet_select_change) {
     // Configure 2 subnets, both directly reachable over local interface
     // (let's not complicate the matter with relays)
     string config = "{ \"interface\": [ \"all\" ],"
-        "\"preferred-lifetime\": 3000,"
         "\"rebind-timer\": 2000, "
         "\"renew-timer\": 1000, "
         "\"subnet4\": [ { "
-        "    \"pool\": [ \"2001:db8:1::/44\" ],"
-        "    \"subnet\": \"2001:db8:1::/48\", "
+        "    \"pool\": [ \"192.0.2.0/25\" ],"
+        "    \"subnet\": \"192.0.2.0/24\", "
         "    \"interface\": \"" + valid_iface_ + "\" "
         " }, {"
-        "    \"pool\": [ \"2001:db8:2::/44\" ],"
-        "    \"subnet\": \"2001:db8:2::/48\" "
+        "    \"pool\": [ \"192.0.3.0/25\" ],"
+        "    \"subnet\": \"192.0.3.0/24\" "
         " } ],"
         "\"valid-lifetime\": 4000 }";
 
@@ -2313,7 +2316,7 @@ TEST_F(HooksDhcpv4SrvTest, subnet_select_change) {
 
     // Prepare discover packet. Server should select first subnet for it
     Pkt4Ptr sol = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
-    sol->setRemoteAddr(IOAddress("fe80::abcd"));
+    sol->setRemoteAddr(IOAddress("192.0.2.1"));
     sol->setIface(valid_iface_);
     OptionPtr clientid = generateClientId();
     sol->addOption(clientid);