Browse Source

[4497] Extended Pkt4o6 to support setCopyRetrievedOptions.

Marcin Siodelski 8 years ago
parent
commit
d11a96e300
4 changed files with 49 additions and 7 deletions
  1. 3 5
      src/lib/dhcp/pkt.h
  2. 9 1
      src/lib/dhcp/pkt4o6.cc
  3. 12 1
      src/lib/dhcp/pkt4o6.h
  4. 25 0
      src/lib/dhcp/tests/pkt4o6_unittest.cc

+ 3 - 5
src/lib/dhcp/pkt.h

@@ -33,6 +33,8 @@ namespace dhcp {
 /// should be disabled. The use of RAII object eliminates the need for
 /// explicitly re-disabling options copying and is safer in case of
 /// exceptions thrown by callouts and a presence of multiple exit points.
+///
+/// @tparam PktType Type of the packet, e.g. Pkt4, Pkt6, Pkt4o6.
 template<typename PktType>
 class ScopedEnableOptionsCopy {
 public:
@@ -331,10 +333,6 @@ public:
     /// @return pointer to found option (or NULL)
     OptionPtr getOption(const uint16_t type);
 
-    OptionPtr getOption(const uint16_t type) const {
-        return (getNonCopiedOption(type));
-    }
-
     /// @brief Controls whether the option retrieved by the @ref Pkt::getOption
     /// should be copied before being returned.
     ///
@@ -359,7 +357,7 @@ public:
     ///
     /// @param copy Indicates if the options should be copied when
     /// retrieved (if true), or not copied (if false).
-    void setCopyRetrievedOptions(const bool copy) {
+    virtual void setCopyRetrievedOptions(const bool copy) {
         copy_retrieved_options_ = copy;
     }
 

+ 9 - 1
src/lib/dhcp/pkt4o6.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -47,6 +47,14 @@ void Pkt4o6::pack() {
     pkt6_->pack();
 }
 
+void
+Pkt4o6::setCopyRetrievedOptions(const bool copy) {
+    Pkt4::setCopyRetrievedOptions(copy);
+    // Copy the new setting to the encapsulated instance of Pkt6.
+    pkt6_->setCopyRetrievedOptions(isCopyRetrievedOptions());
+}
+
+
 } // end of namespace isc::dhcp
 
 } // end of namespace isc

+ 12 - 1
src/lib/dhcp/pkt4o6.h

@@ -1,4 +1,4 @@
-// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -59,6 +59,17 @@ public:
         return (true);
     }
 
+    /// @brief Overrides the @ref Pkt::setCopyRetrievedOptions to also
+    /// set the flag for encapsulated @ref Pkt6 instance.
+    ///
+    /// When the flag is set for the instance of the @ref Pkt4o6 the
+    /// encapsulated Pkt6, retrieved with @ref Pkt4o6::getPkt6, will
+    /// inherit this setting.
+    ///
+    /// @param copy Indicates if the options should be copied when
+    /// retrieved (if true), or not copied (if false).
+    virtual void setCopyRetrievedOptions(const bool copy);
+
 private:
     /// Encapsulating DHCPv6 message
     Pkt6Ptr pkt6_;

+ 25 - 0
src/lib/dhcp/tests/pkt4o6_unittest.cc

@@ -93,6 +93,31 @@ TEST_F(Pkt4o6Test, pack) {
     EXPECT_EQ(0, memcmp(&cp[8], &buffer4_[0], buffer4_.size()));
 }
 
+// This test verifies that the flag indicating that the retrieved options
+// should be copied is transferred between the DHCPv4 packet and the
+// DHCPv6 packet being a member of Pkt4o6 class.
+TEST_F(Pkt4o6Test, setCopyRetrievedOptions) {
+    // Create Pkt4o6 and initially expect taht the flag is set to false.
+    Pkt4o6 pkt4o6(pkt4_, pkt6_);
+    ASSERT_FALSE(pkt4o6.isCopyRetrievedOptions());
+    Pkt6Ptr pkt6 = pkt4o6.getPkt6();
+    ASSERT_TRUE(pkt6);
+    ASSERT_FALSE(pkt6->isCopyRetrievedOptions());
+
+    // Set the flag to true for Pkt4o6.
+    pkt4o6.setCopyRetrievedOptions(true);
+    pkt6 = pkt4o6.getPkt6();
+    ASSERT_TRUE(pkt6);
+    EXPECT_TRUE(pkt6->isCopyRetrievedOptions());
+
+    // Repeat the same test but set the flag to false.
+    pkt4o6.setCopyRetrievedOptions(false);
+    EXPECT_FALSE(pkt4o6.isCopyRetrievedOptions());
+    pkt6 = pkt4o6.getPkt6();
+    ASSERT_TRUE(pkt6);
+    EXPECT_FALSE(pkt6->isCopyRetrievedOptions());
+}
+
 /// @todo: Add a test that handles actual DHCP4o6 traffic capture
 ///        once we get it. We should add the capture to pkt_captures{4,6}.cc
 }