/// 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:
/// @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.
///
///
/// @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;
}
-// 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
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
-// 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
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_;
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
}