Browse Source

[3203] v6 vendor-class option updated, unit-test added

Tomek Mrugalski 11 years ago
parent
commit
3dade343a9
2 changed files with 43 additions and 1 deletions
  1. 2 1
      src/lib/dhcp/std_option_defs.h
  2. 41 0
      src/lib/dhcp/tests/libdhcp++_unittest.cc

+ 2 - 1
src/lib/dhcp/std_option_defs.h

@@ -230,7 +230,8 @@ RECORD_DECL(REMOTE_ID_RECORDS, OPT_UINT32_TYPE, OPT_BINARY_TYPE);
 // status-code
 RECORD_DECL(STATUS_CODE_RECORDS, OPT_UINT16_TYPE, OPT_STRING_TYPE);
 // vendor-class
-RECORD_DECL(VENDOR_CLASS_RECORDS, OPT_UINT32_TYPE, OPT_BINARY_TYPE);
+RECORD_DECL(VENDOR_CLASS_RECORDS, OPT_UINT32_TYPE, OPT_UINT16_TYPE,
+            OPT_STRING_TYPE);
 
 /// Standard DHCPv6 option definitions.
 ///

+ 41 - 0
src/lib/dhcp/tests/libdhcp++_unittest.cc

@@ -30,6 +30,9 @@
 #include <dhcp/option_string.h>
 #include <dhcp/option_vendor.h>
 #include <util/buffer.h>
+#include <util/encode/hex.h>
+
+#include <boost/pointer_cast.hpp>
 
 #include <gtest/gtest.h>
 
@@ -1122,4 +1125,42 @@ TEST_F(LibDhcpTest, stdOptionDefs6) {
                                     typeid(Option6AddrLst));
 }
 
+// tests whether v6 vendor-class option can be parsed properly.
+TEST_F(LibDhcpTest, vendorClass6) {
+
+    isc::dhcp::OptionCollection options; // Will store parsed option here
+
+    // Exported from wireshark: vendor-class option with enterprise-id = 4491
+    // and a single data entry containing "eRouter1.0"
+    string vendor_class_hex = "001000100000118b000a65526f75746572312e30";
+    OptionBuffer bin;
+
+    // Decode the hex string and store it in bin (which happens
+    // to be OptionBuffer format)
+    isc::util::encode::decodeHex(vendor_class_hex, bin);
+
+    EXPECT_NO_THROW ({
+            LibDHCP::unpackOptions6(bin, "dhcp6", options);
+        });
+
+    EXPECT_EQ(options.size(), 1); // There should be 1 option.
+
+    // Option vendor-class should be there
+    ASSERT_FALSE(options.find(D6O_VENDOR_CLASS) == options.end());
+
+    // It should be of type OptionCustom
+    boost::shared_ptr<OptionCustom> vclass =
+        boost::dynamic_pointer_cast<OptionCustom> (options.begin()->second);
+    ASSERT_TRUE(vclass);
+
+    // Let's investigate if the option content is correct
+
+    // 3 fields expected: vendor-id, data-len and data
+    ASSERT_EQ(3, vclass->getDataFieldsNum());
+
+    EXPECT_EQ(4491, vclass->readInteger<uint32_t>(0)); // vendor-id=4491
+    EXPECT_EQ(10, vclass->readInteger<uint16_t>(1)); // data len = 10
+    EXPECT_EQ("eRouter1.0", vclass->readString(2)); // data="eRouter1.0"
 }
+
+} // end of anonymous space