From 64029259dd2b51e2c6ed6a46cf8aad78b2f45966 Mon Sep 17 00:00:00 2001 From: Andrei Pavel Date: Wed, 13 Jul 2016 14:15:28 +0300 Subject: [PATCH] minor changes --- src/bin/dhcp4/dhcp4.dox | 8 +- src/bin/dhcp6/dhcp6.dox | 8 +- src/lib/dhcp/libdhcp++.cc | 268 ++++-------------- src/lib/dhcp/libdhcp++.h | 34 ++- src/lib/dhcp/option.cc | 4 +- src/lib/dhcp/pkt4.cc | 3 +- src/lib/dhcp/pkt6.cc | 7 +- src/lib/dhcp/tests/libdhcp++_unittest.cc | 32 +-- .../dhcp/tests/option6_pdexclude_unittest.cc | 26 +- 9 files changed, 124 insertions(+), 266 deletions(-) diff --git a/src/bin/dhcp4/dhcp4.dox b/src/bin/dhcp4/dhcp4.dox index 6afd997a4b..1663d5da8c 100644 --- a/src/bin/dhcp4/dhcp4.dox +++ b/src/bin/dhcp4/dhcp4.dox @@ -115,14 +115,14 @@ be stored in libdhcp++. Such option formats are stored in the of options which may be encapsulated by other options up to any level of encapsulation, but these functions are unaware of the option formats defined in the @ref isc::dhcp::CfgMgr because they belong to a different library. -Therefore, the generic function @ref isc::dhcp::LibDHCP::unpackOptions is only -useful to parse standard +Therefore, the generic functions @ref isc::dhcp::LibDHCP::unpackOptions4 and +@ref isc::dhcp::LibDHCP::unpackOptions6 are only useful to parse standard options whose definitions are provided in the libdhcp++. In order to overcome this problem a callback mechanism has been implemented in @c Option and @c Pkt4 classes. By installing a callback function on an instance of @c Pkt4, the server may provide a custom implementation of the options parsing algorithm. -This callback function will take precedence over the @c LibDHCP::unpackOptions -function. With this approach, the callback is +This callback function will take precedence over the @c LibDHCP::unpackOptions4 +and @c LibDHCP::unpackOptions6 functions. With this approach, the callback is implemented within the context of the server and it has access to all objects which define its configuration (including dynamically created option definitions). diff --git a/src/bin/dhcp6/dhcp6.dox b/src/bin/dhcp6/dhcp6.dox index 05c172cd47..559206348e 100644 --- a/src/bin/dhcp6/dhcp6.dox +++ b/src/bin/dhcp6/dhcp6.dox @@ -192,14 +192,14 @@ be stored in libdhcp++. Such option formats are stored in the of options which may be encapsulated by other options up to the any level of encapsulation but these functions are unaware of the option formats defined in the @ref isc::dhcp::CfgMgr because they belong to a different library. -Therefore, the generic function @ref isc::dhcp::LibDHCP::unpackOptions is only -useful to parse standard +Therefore, the generic functions @ref isc::dhcp::LibDHCP::unpackOptions4 and +@ref isc::dhcp::LibDHCP::unpackOptions6 are only useful to parse standard options whose definitions are provided in the libdhcp++. In order to overcome this problem a callback mechanism has been implemented in @c Option and @c Pkt6 classes. By installing a callback function on the instance of the @c Pkt6 the server may provide a custom implementation of the options parsing algorithm. -This callback function will take precedence over the @c LibDHCP::unpackOptions - functions. With this approach, the callback is +This callback function will take precedence over the @c LibDHCP::unpackOptions6 +and @c LibDHCP::unpackOptions4 functions. With this approach, the callback is implemented within the context of the server and it has access to all objects which define its configuration (including dynamically created option definitions). diff --git a/src/lib/dhcp/libdhcp++.cc b/src/lib/dhcp/libdhcp++.cc index e7574a61f3..27b9986e7e 100644 --- a/src/lib/dhcp/libdhcp++.cc +++ b/src/lib/dhcp/libdhcp++.cc @@ -132,7 +132,7 @@ LibDHCP::getVendorOptionDefs(const Option::Universe u, const uint32_t vendor_id) return getOptionDefs( Option::V6, ISC_V6_OPTION_SPACE ); } } - isc_throw(isc::BadValue, "invalid universe " << u ); + return OptionDefContainerPtr(); } OptionDefinitionPtr @@ -323,19 +323,23 @@ size_t LibDHCP::unpackOptions6(const OptionBuffer& buf, size_t last_offset = 0; // Get the list of standard option definitions. - const OptionDefContainerPtr& option_defs = LibDHCP::getOptionDefs(Option::V6); - // Runtime option definitions for non standard option space and if - // the definition doesn't exist within the standard option definitions. - const OptionDefContainerPtr& runtime_option_defs = LibDHCP::getRuntimeOptionDefs(option_space); - - // @todo Once we implement other option spaces we should add else clause - // here and gather option definitions for them. For now leaving option_defs - // empty will imply creation of generic Option. + OptionDefContainer option_defs; + const OptionDefContainerPtr option_defs_ptr + = LibDHCP::getOptionDefs(Option::V6, option_space); + OptionDefContainer runtime_option_defs; + const OptionDefContainerPtr runtime_option_defs_ptr + = LibDHCP::getRuntimeOptionDefs(option_space); + if (option_defs_ptr) { + option_defs = *option_defs_ptr; + } + if (runtime_option_defs_ptr) { + runtime_option_defs = *runtime_option_defs_ptr; + } // Get the search indexes #1. It allows to search for option definitions // using option code. - const OptionDefContainerTypeIndex& idx = option_defs->get<1>(); - const OptionDefContainerTypeIndex& runtime_idx = runtime_option_defs->get<1>(); + const OptionDefContainerTypeIndex& idx = option_defs.get<1>(); + const OptionDefContainerTypeIndex& runtime_idx = runtime_option_defs.get<1>(); // The buffer being read comprises a set of options, each starting with // a two-byte type code and a two-byte length field. @@ -459,15 +463,23 @@ size_t LibDHCP::unpackOptions4(const OptionBuffer& buf, size_t last_offset = 0; // Get the list of standard option definitions. - const OptionDefContainerPtr& option_defs = LibDHCP::getOptionDefs(Option::V4); - // Runtime option definitions for non standard option space and if - // the definition doesn't exist within the standard option definitions. - const OptionDefContainerPtr& runtime_option_defs = LibDHCP::getRuntimeOptionDefs(option_space); + OptionDefContainer option_defs; + const OptionDefContainerPtr option_defs_ptr + = LibDHCP::getOptionDefs(Option::V4, option_space); + OptionDefContainer runtime_option_defs; + const OptionDefContainerPtr runtime_option_defs_ptr + = LibDHCP::getRuntimeOptionDefs(option_space); + if (option_defs_ptr) { + option_defs = *option_defs_ptr; + } + if (runtime_option_defs_ptr) { + runtime_option_defs = *runtime_option_defs_ptr; + } // Get the search indexes #1. It allows to search for option definitions // using option code. - const OptionDefContainerTypeIndex& idx = option_defs->get<1>(); - const OptionDefContainerTypeIndex& runtime_idx = runtime_option_defs->get<1>(); + const OptionDefContainerTypeIndex& idx = option_defs.get<1>(); + const OptionDefContainerTypeIndex& runtime_idx = runtime_option_defs.get<1>(); // The buffer being read comprises a set of options, each starting with // a one-byte type code and a one-byte length field. @@ -564,182 +576,6 @@ size_t LibDHCP::unpackOptions4(const OptionBuffer& buf, return (last_offset); } -size_t LibDHCP::unpackOptions(const Option::Universe& universe, - const OptionBuffer& buf, - const std::string& option_space, - isc::dhcp::OptionCollection& options, - size_t* relay_msg_offset /* = NULL */, - size_t* relay_msg_len /* = NULL */) { - // Sanity check - if (universe != Option::V4 || universe != Option::V6) { - return 0U; // no options parsed - } - - if (universe == Option::V4) { - return unpackOptions4(buf, option_space, options); - } else if (universe == Option::V6){ - return unpackOptions6(buf, option_space, options, relay_msg_offset, relay_msg_len); - } else { - return 0U; - } - /* - - // Get the list of standard option definitions. - OptionDefContainer option_defs; - const OptionDefContainerPtr option_defs_ptr - = LibDHCP::getOptionDefs(universe, option_space); - OptionDefContainer runtime_option_defs; - const OptionDefContainerPtr runtime_option_defs_ptr - = LibDHCP::getRuntimeOptionDefs(option_space); - if (option_defs_ptr) { - option_defs = *option_defs_ptr; - } - if (runtime_option_defs_ptr) { - runtime_option_defs = *runtime_option_defs_ptr; - } - - // Get the search indexes #1. It allows to search for option definitions - // using option code. - const OptionDefContainerTypeIndex& idx = option_defs.get<1>(); - const OptionDefContainerTypeIndex& runtime_idx = runtime_option_defs.get<1>(); - - // The buffer being read comprises a set of options, each starting with - // a type code and a length field, both holding one byte (DHCPv4) or two - // bytes (DHCPv6). - const size_t element_size = universe == Option::V4 ? sizeof(uint8_t) : sizeof(uint16_t); - const size_t metadata_length = 2U * element_size; - const size_t length = buf.size(); - size_t offset = 0U; - uint16_t opt_type = 0U; - uint16_t opt_len = 0U; - for (offset = 0U; offset < length; offset += metadata_length + opt_len) { - size_t useful_data_offset = offset + metadata_length; - // Parse the option header - if (universe == Option::V4) { - opt_type = buf[offset]; - if (opt_type == DHO_PAD) { - // DHO_PAD is just a padding after DHO_END. Let's continue - // parsing in case we receive a message without DHO_END. - continue; - } else if (opt_type == DHO_END) { - // Just return. Don't need to add DHO_END option. - return offset; - } else if (useful_data_offset > length) { - // We peeked at the option header of the next option, but - // discovered that it would end up beyond buffer end, so - // the option is truncated. Hence we can't parse - // it. Therefore we revert back (as if we never parsed it). - // - // @note it is the responsibility of the caller to throw - // an exception on partial parsing - return offset; - } - opt_len = buf[offset + element_size]; - if (useful_data_offset + opt_len > length) { - return offset; - } - } else if (universe == Option::V6) { - if (useful_data_offset > length) { - // We peeked at the option header of the next option, but - // discovered that it would end up beyond buffer end, so - // the option is truncated. Hence we can't parse - // it. Therefore we revert back (as if we never parsed it). - // - // @note it is the responsibility of the caller to throw - // an exception on partial parsing - return offset; - } - opt_type = isc::util::readUint16(&buf[offset], element_size); - opt_len = isc::util::readUint16(&buf[offset + element_size], element_size); - if (useful_data_offset + opt_len > length) { - // We peeked at the option header of the next option, but - // discovered that it would end up beyond buffer end, so - // the option is truncated. Hence we can't parse - // it. Therefore we revert back (as if we never parsed it). - // - // @note it is the responsibility of the caller to throw - // an exception on partial parsing - return offset; - } - if (opt_type == D6O_RELAY_MSG && relay_msg_offset && relay_msg_len) { - // Remember offset of the beginning of the relay-msg option. - *relay_msg_offset = useful_data_offset; - *relay_msg_len = opt_len; - - // Do not create the relay-msg option. - continue; - } else if (opt_type == D6O_VENDOR_OPTS) { - const size_t ENTERPRISE_ID_LEN = 4U; // duid_factory.cc - if (useful_data_offset + ENTERPRISE_ID_LEN > length) { - // Truncated vendor-option. We expect at least - // 4 bytes for the enterprise-id field. Let's roll back - // option code + option length (4 bytes) and return. - return offset; - } - - // Parse this as a vendor option. - OptionBufferConstIter begin = buf.begin() + useful_data_offset; - OptionPtr vendor_opt(new OptionVendor(Option::V6, begin, begin + opt_len)); - options.insert(std::make_pair(opt_type, vendor_opt)); - continue; - } - } - - // Get all definitions with the particular option code. Note - // that option code is non-unique within this container - // however at this point we expect to get one option - // definition with the particular code. If more are returned - // we report an error. - OptionDefContainerTypeRange range; - // Number of option definitions returned. - size_t num_defs = 0U; - if (option_space == DHCP4_OPTION_SPACE || - option_space == DHCP6_OPTION_SPACE) { - range = idx.equal_range(opt_type); - num_defs = distance(range.first, range.second); - } - - // Standard option definitions do not include the definition for - // our option or we're searching for non-standard option. Try to - // find the definition among runtime option definitions. - if (num_defs == 0U) { - range = runtime_idx.equal_range(opt_type); - num_defs = distance(range.first, range.second); - } - - OptionPtr opt; - if (num_defs > 1U) { - // Multiple options of the same code are not supported right now! - isc_throw(isc::Unexpected, "Internal error: multiple option" - " definitions for option type " << opt_type << - " returned. Currently it is not supported to initialize" - " multiple option definitions for the same option code." - " This will be supported once support for option spaces" - " is implemented"); - } else if (num_defs == 0U) { - // @todo Don't crash if definition does not exist because - // only a few option definitions are initialized right - // now. In the future we will initialize definitions for - // all options and we will remove this elseif. For now, - // return generic option. - OptionBufferConstIter begin = buf.begin() + useful_data_offset; - opt = OptionPtr(new Option(universe, opt_type, begin, begin + opt_len)); - //opt->setEncapsulatedSpace(DHCP4_OPTION_SPACE); - } else { - // The option definition has been found. Use it to create - // the option instance from the provided buffer chunk. - const OptionDefinitionPtr& def = *(range.first); - assert(def); - OptionBufferConstIter begin = buf.begin() + useful_data_offset; - opt = def->optionFactory(universe, opt_type, begin, begin + opt_len); - } - - options.insert(std::make_pair(opt_type, opt)); - } - return offset; - */ -} - size_t LibDHCP::unpackVendorOptions6(const uint32_t vendor_id, const OptionBuffer& buf, isc::dhcp::OptionCollection& options) { @@ -773,14 +609,13 @@ size_t LibDHCP::unpackVendorOptions6(const uint32_t vendor_id, offset += 2; if (offset + opt_len > length) { - isc_throw(OutOfRange, "Vendor option parse failed. Tried to parse " << - offset + opt_len << " bytes from " << length << - "-byte long buffer."); + isc_throw(OutOfRange, "Vendor option parse failed. " + "Tried to parse " << offset + opt_len << " bytes from " << + length << "-byte long buffer."); } OptionPtr opt; opt.reset(); - OptionBufferConstIter begin = buf.begin() + offset; // If there is a definition for such a vendor option... if (idx) { @@ -809,7 +644,9 @@ size_t LibDHCP::unpackVendorOptions6(const uint32_t vendor_id, // the option instance from the provided buffer chunk. const OptionDefinitionPtr& def = *(range.first); assert(def); - opt = def->optionFactory(Option::V6, opt_type, begin, begin + opt_len); + OptionBufferConstIter begin = buf.begin() + offset; + opt = def->optionFactory(Option::V6, opt_type, begin, + begin + opt_len); } } @@ -819,7 +656,9 @@ size_t LibDHCP::unpackVendorOptions6(const uint32_t vendor_id, // not defined if (!opt) { - opt = OptionPtr(new Option(Option::V6, opt_type, begin, begin + opt_len)); + OptionBufferConstIter begin = buf.begin() + offset; + opt = OptionPtr(new Option(Option::V6, opt_type, begin, + begin + opt_len)); } // add option to options @@ -873,8 +712,8 @@ size_t LibDHCP::unpackVendorOptions4(const uint32_t vendor_id, const OptionBuffe // treated as unsigned char value (a number is // presented in error message). isc_throw(OutOfRange, - "Attempt to parse truncated vendor option " - << static_cast(opt_type)); + "Attempt to parse truncated vendor option " << + static_cast(opt_type)); } uint8_t opt_len = buf[offset++]; @@ -886,7 +725,6 @@ size_t LibDHCP::unpackVendorOptions4(const uint32_t vendor_id, const OptionBuffe OptionPtr opt; opt.reset(); - OptionBufferConstIter begin = buf.begin() + offset; if (idx) { // Get all definitions with the particular option @@ -904,8 +742,8 @@ size_t LibDHCP::unpackVendorOptions4(const uint32_t vendor_id, const OptionBuffe // Multiple options of the same code are not // supported right now! isc_throw(isc::Unexpected, "Internal error: multiple" - " option definitions for option type " - << opt_type << " returned. Currently it is" + " option definitions for option type " << + opt_type << " returned. Currently it is" " not supported to initialize multiple option" " definitions for the same option code." " This will be supported once support for" @@ -915,12 +753,16 @@ size_t LibDHCP::unpackVendorOptions4(const uint32_t vendor_id, const OptionBuffe // the option instance from the provided buffer chunk. const OptionDefinitionPtr& def = *(range.first); assert(def); - opt = def->optionFactory(Option::V4, opt_type, begin, begin + opt_len); + OptionBufferConstIter begin = buf.begin() + offset; + opt = def->optionFactory(Option::V4, opt_type, begin, + begin + opt_len); } } if (!opt) { - opt = OptionPtr(new Option(Option::V4, opt_type, begin, begin + opt_len)); + OptionBufferConstIter begin = buf.begin() + offset; + opt = OptionPtr(new Option(Option::V4, opt_type, begin, + begin + opt_len)); } options.insert(std::make_pair(opt_type, opt)); @@ -982,7 +824,7 @@ void LibDHCP::OptionFactoryRegister(Option::Universe u, case Option::V6: { if (v6factories_.find(opt_type) != v6factories_.end()) { isc_throw(BadValue, "There is already DHCPv6 factory registered " - << "for option type " << opt_type); + "for option type " << opt_type); } v6factories_[opt_type]=factory; return; @@ -1002,7 +844,7 @@ void LibDHCP::OptionFactoryRegister(Option::Universe u, } if (v4factories_.find(opt_type)!=v4factories_.end()) { isc_throw(BadValue, "There is already DHCPv4 factory registered " - << "for option type " << opt_type); + "for option type " << opt_type); } v4factories_[opt_type]=factory; return; @@ -1069,11 +911,11 @@ void initOptionSpace(OptionDefContainerPtr& defs, std::string encapsulates(params[i].encapsulates); if (!encapsulates.empty() && params[i].array) { isc_throw(isc::BadValue, "invalid standard option definition: " - << "option with code '" << params[i].code - << "' may not encapsulate option space '" - << encapsulates << "' because the definition" - << " indicates that this option comprises an array" - << " of values"); + "option with code '" << params[i].code << + "' may not encapsulate option space '" << + encapsulates << "' because the definition" + " indicates that this option comprises an array" + " of values"); } // Depending whether an option encapsulates an option space or not diff --git a/src/lib/dhcp/libdhcp++.h b/src/lib/dhcp/libdhcp++.h index 970a7123e9..d85b846e02 100644 --- a/src/lib/dhcp/libdhcp++.h +++ b/src/lib/dhcp/libdhcp++.h @@ -200,7 +200,7 @@ public: static void packOptions6(isc::util::OutputBuffer& buf, const isc::dhcp::OptionCollection& options); - /// @brief Parses provided buffer as DHCPV4 or DHCPv6 options and creates + /// @brief Parses provided buffer as DHCPv6 options and creates /// Option objects. /// /// Parses provided buffer and stores created Option objects in @@ -229,20 +229,30 @@ public: /// than once, and it calls option building routines which can throw. /// Partial parsing does not throw: it is the responsibility of the /// caller to handle this condition. - static size_t unpackOptions(const Option::Universe& universe, - const OptionBuffer& buf, - const std::string& option_space, - isc::dhcp::OptionCollection& options, - size_t* relay_msg_offset = NULL, - size_t* relay_msg_len = NULL); - static size_t unpackOptions4(const OptionBuffer& buf, - const std::string& option_space, - isc::dhcp::OptionCollection& options); static size_t unpackOptions6(const OptionBuffer& buf, const std::string& option_space, isc::dhcp::OptionCollection& options, - size_t* relay_msg_offset = NULL, - size_t* relay_msg_len = NULL); + size_t* relay_msg_offset = 0, + size_t* relay_msg_len = 0); + + /// @brief Parses provided buffer as DHCPv4 options and creates + /// Option objects. + /// + /// Parses provided buffer and stores created Option objects + /// in options container. + /// + /// @param buf Buffer to be parsed. + /// @param option_space A name of the option space which holds definitions + /// to be used to parse options in the packets. + /// @param options Reference to option container. Options will be + /// put here. + /// @return offset to the first byte after the last successfully + /// parsed option or the offset of the DHO_END option type. + /// + /// The unpackOptions6 note applies too. + static size_t unpackOptions4(const OptionBuffer& buf, + const std::string& option_space, + isc::dhcp::OptionCollection& options); /// Registers factory method that produces options of specific option types. /// diff --git a/src/lib/dhcp/option.cc b/src/lib/dhcp/option.cc index bc763a143b..82e3593cfb 100644 --- a/src/lib/dhcp/option.cc +++ b/src/lib/dhcp/option.cc @@ -155,10 +155,10 @@ void Option::unpackOptions(const OptionBuffer& buf) { switch (universe_) { case V4: - LibDHCP::unpackOptions(Option::V4, buf, getEncapsulatedSpace(), options_); + LibDHCP::unpackOptions4(buf, getEncapsulatedSpace(), options_); return; case V6: - LibDHCP::unpackOptions(Option::V6, buf, getEncapsulatedSpace(), options_); + LibDHCP::unpackOptions6(buf, getEncapsulatedSpace(), options_); return; default: isc_throw(isc::BadValue, "Invalid universe type " << universe_); diff --git a/src/lib/dhcp/pkt4.cc b/src/lib/dhcp/pkt4.cc index edc639bbfb..b837277e6a 100644 --- a/src/lib/dhcp/pkt4.cc +++ b/src/lib/dhcp/pkt4.cc @@ -203,8 +203,7 @@ Pkt4::unpack() { // a vector as an input. buffer_in.readVector(opts_buffer, opts_len); - size_t offset = LibDHCP::unpackOptions(Option::V4, opts_buffer, - DHCP4_OPTION_SPACE, options_); + size_t offset = LibDHCP::unpackOptions4(opts_buffer, DHCP4_OPTION_SPACE, options_); // If offset is not equal to the size and there is no DHO_END, // then something is wrong here. We either parsed past input diff --git a/src/lib/dhcp/pkt6.cc b/src/lib/dhcp/pkt6.cc index e468525b09..25afd44469 100644 --- a/src/lib/dhcp/pkt6.cc +++ b/src/lib/dhcp/pkt6.cc @@ -403,8 +403,7 @@ Pkt6::unpackMsg(OptionBuffer::const_iterator begin, // If custom option parsing function has been set, use this function // to parse options. Otherwise, use standard function from libdhcp. - size_t offset = LibDHCP::unpackOptions(Option::V6, opt_buffer, - DHCP6_OPTION_SPACE, options_); + size_t offset = LibDHCP::unpackOptions6(opt_buffer, DHCP6_OPTION_SPACE, options_); // If offset is not equal to the size, then something is wrong here. We // either parsed past input buffer (bug in our code) or we haven't parsed @@ -454,8 +453,8 @@ Pkt6::unpackRelayMsg() { // If custom option parsing function has been set, use this function // to parse options. Otherwise, use standard function from libdhcp. - LibDHCP::unpackOptions(Option::V6, opt_buffer, DHCP6_OPTION_SPACE, - relay.options_, &relay_msg_offset, &relay_msg_len); + LibDHCP::unpackOptions6(opt_buffer, DHCP6_OPTION_SPACE, relay.options_, + &relay_msg_offset, &relay_msg_len); /// @todo: check that each option appears at most once //relay.interface_id_ = options->getOption(D6O_INTERFACE_ID); diff --git a/src/lib/dhcp/tests/libdhcp++_unittest.cc b/src/lib/dhcp/tests/libdhcp++_unittest.cc index ba1ab3b98e..5f8ea9eb68 100644 --- a/src/lib/dhcp/tests/libdhcp++_unittest.cc +++ b/src/lib/dhcp/tests/libdhcp++_unittest.cc @@ -420,9 +420,8 @@ TEST_F(LibDhcpTest, unpackOptions6) { memcpy(&buf[0], v6packed, sizeof(v6packed)); EXPECT_NO_THROW ({ - OptionBufferIter begin = buf.begin(); - LibDHCP::unpackOptions(Option::V6, OptionBuffer(begin, - begin + sizeof(v6packed)), DHCP6_OPTION_SPACE, options); + LibDHCP::unpackOptions6(OptionBuffer(buf.begin(), buf.begin() + sizeof(v6packed)), + DHCP6_OPTION_SPACE, options); }); EXPECT_EQ(options.size(), 6); // there should be 5 options @@ -545,8 +544,8 @@ TEST_F(LibDhcpTest, unpackEmptyOption6) { // Parse options. OptionCollection options; - ASSERT_NO_THROW(LibDHCP::unpackOptions(Option::V6, buf, DHCP6_OPTION_SPACE, - options)); + ASSERT_NO_THROW(LibDHCP::unpackOptions6(buf, DHCP6_OPTION_SPACE, + options)); // There should be one option. ASSERT_EQ(1, options.size()); @@ -602,8 +601,7 @@ TEST_F(LibDhcpTest, unpackSubOptions6) { // Parse options. OptionCollection options; - ASSERT_NO_THROW(LibDHCP::unpackOptions(Option::V6, buf, "space-foobar", - options, 0, 0)); + ASSERT_NO_THROW(LibDHCP::unpackOptions6(buf, "space-foobar", options, 0, 0)); // There should be one top level option. ASSERT_EQ(1, options.size()); @@ -769,8 +767,7 @@ TEST_F(LibDhcpTest, unpackOptions4) { isc::dhcp::OptionCollection options; // list of options ASSERT_NO_THROW( - LibDHCP::unpackOptions(Option::V4, v4packed, DHCP4_OPTION_SPACE, - options); + LibDHCP::unpackOptions4(v4packed, DHCP4_OPTION_SPACE, options); ); isc::dhcp::OptionCollection::const_iterator x = options.find(12); @@ -861,9 +858,9 @@ TEST_F(LibDhcpTest, unpackOptions4) { ASSERT_TRUE(rai); // RAI should have 3 sub-options: Circuit ID, Agent Remote ID, Vendor // Specific Information option. Note that by parsing these suboptions we - // are checking that unpackOptions differentiates between standard option - // space called "dhcp4" or "dhcp6" and other option spaces. These sub-options - // do not belong to standard option space and should be parsed using different + // are checking that unpackOptions4 differentiates between standard option + // space called "dhcp4" and other option spaces. These sub-options do not + // belong to standard option space and should be parsed using different // option definitions. // @todo Currently, definitions for option space "dhcp-agent-options-space" // are not defined. Therefore all suboptions will be represented here by @@ -930,8 +927,8 @@ TEST_F(LibDhcpTest, unpackEmptyOption4) { // Parse options. OptionCollection options; - ASSERT_NO_THROW(LibDHCP::unpackOptions(Option::V4, buf, DHCP4_OPTION_SPACE, - options)); + ASSERT_NO_THROW(LibDHCP::unpackOptions4(buf, DHCP4_OPTION_SPACE, + options)); // There should be one option. ASSERT_EQ(1, options.size()); @@ -990,8 +987,7 @@ TEST_F(LibDhcpTest, unpackSubOptions4) { // Parse options. OptionCollection options; - ASSERT_NO_THROW(LibDHCP::unpackOptions(Option::V4, buf, "space-foobar", - options)); + ASSERT_NO_THROW(LibDHCP::unpackOptions4(buf, "space-foobar", options)); // There should be one top level option. ASSERT_EQ(1, options.size()); @@ -1703,8 +1699,8 @@ TEST_F(LibDhcpTest, vendorClass6) { isc::util::encode::decodeHex(vendor_class_hex, bin); ASSERT_NO_THROW ({ - LibDHCP::unpackOptions(Option::V4, bin, DHCP6_OPTION_SPACE, options); - }); + LibDHCP::unpackOptions6(bin, DHCP6_OPTION_SPACE, options); + }); EXPECT_EQ(options.size(), 1); // There should be 1 option. diff --git a/src/lib/dhcp/tests/option6_pdexclude_unittest.cc b/src/lib/dhcp/tests/option6_pdexclude_unittest.cc index eea68a8f25..5203cbed10 100644 --- a/src/lib/dhcp/tests/option6_pdexclude_unittest.cc +++ b/src/lib/dhcp/tests/option6_pdexclude_unittest.cc @@ -25,12 +25,22 @@ const IOAddress cafe("2001:db8:dead:cafe::"); // /48 prefix length const IOAddress beef01("2001:db8:dead:beef::01"); // /56 prefix length // Description -TEST(Option6PDExcludeTest, testName) { +TEST(Option6PDExcludeTest, constructor) { Option6PDExclude option = Option6PDExclude(beef, 56, beef01, 60); + EXPECT_EQ(option.getDelegatedAddress(), beef); + EXPECT_EQ(option.getDelegatedPrefixLength(), 56); + EXPECT_EQ(option.getExcludedAddress(), beef01); EXPECT_EQ(option.getExcludedPrefixLength(), 60); - /* + EXPECT_EQ(option.len(), Option::OPTION6_HDR_LEN + + /* excluded_prefix_length_ AKA prefix-len is 1B */ 1 + + /* [delegated_prefix_length_ - excluded_prefix_length_](bytes) */ 1); +} + +TEST(Option6PDExcludeTest, packing_and_unpacking) { + EXPECT_NO_THROW(isc_throw(Exception, "Not implemented yet.")); + /* OptionBuffer data(option.getData()); util::OutputBuffer buf(128); @@ -47,19 +57,21 @@ TEST(Option6PDExcludeTest, testName) { EXPECT_EQ(option.getExcludedAddress(), unpackedOption.getExcludedAddress()); EXPECT_EQ(option.getExcludedPrefixLength(), unpackedOption.getExcludedPrefixLength()); - */ + //*/ } TEST(Option6PDExcludeTest, pool) { - //Pool6Ptr pool6Ptr = Pool6Ptr(new Pool6(Lease::TYPE_PD, beef, cafe)); - //ASSERT_TRUE(pool6Ptr); - //ASSERT_GT(pool6Ptr->getPrefixExcludedLength(), 0); + EXPECT_NO_THROW(isc_throw(Exception, "Not implemented yet.")); + /* + Pool6Ptr pool6Ptr = Pool6Ptr(new Pool6(Lease::TYPE_PD, beef, cafe)); + ASSERT_TRUE(pool6Ptr); + ASSERT_GT(pool6Ptr->getPrefixExcludedLength(), 0); OptionPtr opt( new Option6PDExclude((*l)->addr_, (*l)->prefixlen_, pool->getPrefixExcluded(), pool->getPrefixExcludedLength())); - */ + //*/ } } // anonymous namespace -- 2.47.2