Browse Source

[3982] Unit-tests fix.

Tomek Mrugalski 9 years ago
parent
commit
02c71efcaf

+ 19 - 13
src/bin/dhcp6/tests/decline_unittest.cc

@@ -114,15 +114,15 @@ DeclineTest::acquireAndDecline(const std::string& duid1,
     ASSERT_NO_THROW(configure(DECLINE_CONFIGS[0], *client.getServer()));
 
     // Let's get the subnet-id and generate statistics name out of it.
-    const Subnet4Collection* subnets =
-        CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll();
+    const Subnet6Collection* subnets =
+        CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
     ASSERT_EQ(1, subnets->size());
     std::stringstream name;
     name << "subnet[" << subnets->at(0)->getID() << "].declined-addresses";
 
     // Set this statistic explicitly to zero.
     isc::stats::StatsMgr::instance().setValue(name.str(), static_cast<int64_t>(0));
-    
+
     // Perform 4-way exchange.
     ASSERT_NO_THROW(client.doSARR());
 
@@ -143,16 +143,22 @@ DeclineTest::acquireAndDecline(const std::string& duid1,
     if (!decline_correct_address) {
 
         // 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.useNA(iaid2);
+
+    // Use the second IAID
+    client.config_.leases_[0].iaid_ = iaid2;
+
+    // Ok, let's decline the lease.
     ASSERT_NO_THROW(client.doDecline());
 
     // 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);
     
     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.
-TEST_F(DeclineTest, declineBasic) {
+TEST_F(DeclineTest, basic) {
     acquireAndDecline("01:02:03:04:05:06", 1234,
                       "01:02:03:04:05:06", 1234,
                       true, SHOULD_PASS);
@@ -188,7 +194,7 @@ TEST_F(DeclineTest, declineBasic) {
 // - Client acquires new lease using duid, iaid
 // - Client sends the DHCPDECLINE with duid, iaid, but uses wrong address.
 // - The server rejects Decline due to address mismatch
-TEST_F(DeclineTest, declineAddressMismatch) {
+TEST_F(DeclineTest, addressMismatch) {
     acquireAndDecline("01:02:03:04:05:06", 1234,
                       "01:02:03:04:05:06", 1234,
                       false, SHOULD_FAIL);
@@ -198,7 +204,7 @@ TEST_F(DeclineTest, declineAddressMismatch) {
 // - Client acquires new lease using duid, iaid1
 // - Client sends the DHCPDECLINE with duid, iaid2
 // - The server rejects Decline due to IAID mismatch
-TEST_F(DeclineTest, declineIAIDMismatch) {
+TEST_F(DeclineTest, iaidMismatch) {
     acquireAndDecline("01:02:03:04:05:06", 1234,
                       "01:02:03:04:05:06", 1235,
                       true, SHOULD_FAIL);
@@ -208,10 +214,10 @@ TEST_F(DeclineTest, declineIAIDMismatch) {
 // - Client acquires new lease using duid1, iaid
 // - Client sends the DHCPDECLINE using duid2, iaid
 // - 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,
                       "01:02:03:04:05:07", 1234,
-                      true, SHOULD_PASS);
+                      true, SHOULD_FAIL);
 }
 
 } // end of anonymous namespace

+ 19 - 2
src/bin/dhcp6/tests/dhcp6_client.cc

@@ -536,8 +536,8 @@ Dhcp6Client::doDecline() {
     } else {
         query->addOption(forced_server_id_);
     }
-    copyIAs(context_.response_, query);
-    appendRequestedIAs(query);
+
+    generateIAFromLeases(query);
 
     context_.query_ = 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
 Dhcp6Client::fastFwdTime(const uint32_t secs) {

+ 6 - 0
src/bin/dhcp6/tests/dhcp6_client.h

@@ -565,6 +565,12 @@ public:
         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:
 
     /// @brief Applies the new leases for the client.