Browse Source

[2365] Added packOptions and unpackOptions.

Marcin Siodelski 12 years ago
parent
commit
69950d299b
2 changed files with 49 additions and 2 deletions
  1. 30 2
      src/lib/dhcp/option.cc
  2. 19 0
      src/lib/dhcp/option.h

+ 30 - 2
src/lib/dhcp/option.cc

@@ -114,7 +114,7 @@ Option::pack4(isc::util::OutputBuffer& buf) {
             buf.writeData(&data_[0], data_.size());
         }
 
-        LibDHCP::packOptions(buf, options_);
+        packOptions(buf);
 
     } else {
         isc_throw(BadValue, "Invalid universe type " << universe_);
@@ -131,18 +131,46 @@ void Option::pack6(isc::util::OutputBuffer& buf) {
             buf.writeData(&data_[0], data_.size());
         }
 
-        LibDHCP::packOptions6(buf, options_);
+        packOptions(buf);
     } else {
         isc_throw(BadValue, "Invalid universe type " << universe_);
     }
     return;
 }
 
+void
+Option::packOptions(isc::util::OutputBuffer& buf) {
+    switch (universe_) {
+    case V4:
+        LibDHCP::packOptions(buf, options_);
+        return;
+    case V6:
+        LibDHCP::packOptions6(buf, options_);
+        return;
+    default:
+        isc_throw(isc::BadValue, "Invalid universe type " << universe_);
+    }
+}
+
 void Option::unpack(OptionBufferConstIter begin,
                     OptionBufferConstIter end) {
     data_ = OptionBuffer(begin, end);
 }
 
+void
+Option::unpackOptions(const OptionBuffer& buf) {
+    switch (universe_) {
+    case V4:
+        LibDHCP::unpackOptions4(buf, options_);
+        return;
+    case V6:
+        LibDHCP::unpackOptions6(buf, options_);
+        return;
+    default:
+        isc_throw(isc::BadValue, "Invalid universe type " << universe_);
+    }
+}
+
 uint16_t Option::len() {
     // Returns length of the complete option (data length + DHCPv4/DHCPv6
     // option header)

+ 19 - 0
src/lib/dhcp/option.h

@@ -312,6 +312,25 @@ protected:
     /// @throw BadValue Universe is not V6.
     virtual void pack6(isc::util::OutputBuffer& buf);
 
+    /// @brief Store sub options in a buffer.
+    ///
+    /// This method stores all sub-options defined for a particular
+    /// option in a on-wire format in output buffer provided.
+    /// This function is called by pack function in this class or
+    /// derived classes that override pack.
+    ///
+    /// @param [out] buf output buffer.
+    void packOptions(isc::util::OutputBuffer& buf);
+
+    /// @brief Builds a collection of sub options from the buffer.
+    ///
+    /// This method parses the provided buffer and builds a collection
+    /// of objects representing sub options. This function may throw
+    /// different exceptions when option assembly fails.
+    ///
+    /// @param buf buffer to be parsed.
+    void unpackOptions(const OptionBuffer& buf);
+
     /// @brief A private method used for option correctness.
     ///
     /// It is used in constructors. In there are any problems detected