/// @brief Default constructor.
///
- /// @param length_field_size Length of the field which holds the size of
- /// the tuple.
+ /// @param length_field_type Indicates a length of the field which holds
+ /// the size of the tuple.
OpaqueDataTuple(LengthFieldType length_field_type = LENGTH_2_BYTES);
/// @brief Constructor
/// Creates a tuple from on-wire data. It calls @c OpaqueDataTuple::unpack
/// internally.
///
+ /// @param length_field_type Indicates the length of the field holding the
+ /// opaque data size.
/// @param begin Iterator pointing to the begining of the buffer holding
/// wire data.
/// @param end Iterator pointing to the end of the buffer holding wire data.
/// @tparam InputIterator Type of the iterators passed to this function.
- /// @throw It may throw an exception if the @unpack throws.
+ /// @throw It may throw an exception if the @c unpack throws.
template<typename InputIterator>
OpaqueDataTuple(LengthFieldType length_field_type, InputIterator begin,
InputIterator end)
#include <exceptions/exceptions.h>
#include <dhcp/opaque_data_tuple.h>
#include <dhcp/option_vendor_class.h>
+#include <sstream>
namespace isc {
namespace dhcp {
return (length);
}
+std::string
+OptionVendorClass::toText(int indent) {
+ std::ostringstream s;
+
+ // Apply indentation
+ s << std::string(indent, ' ');
+ // Print type, length and first occurence of enterprise id.
+ s << "type=" << getType() << ", len=" << len() - getHeaderLen() << ", "
+ " enterprise id=0x" << std::hex << getVendorId() << std::dec;
+ // Iterate over all tuples and print their size and contents.
+ for (int i = 0; i < getTuplesNum(); ++i) {
+ // The DHCPv4 V-I Vendor Class has enterprise id before every tuple.
+ if ((getUniverse() == V4) && (i > 0)) {
+ s << ", enterprise id=0x" << std::hex << getVendorId() << std::dec;
+ }
+ // Print the tuple.
+ s << ", data-len" << i << "=" << getTuple(i).getLength();
+ s << ", vendor-class-data" << i << "='" << getTuple(i) << "'";
+ }
+
+ return (s.str());
+}
+
} // namespace isc::dhcp
} // namespace isc
EXPECT_EQ(0, vendor_class->getTuplesNum());
}
+// Verifies correctness of the text representation of the DHCPv4 option.
+TEST(OptionVendorClass, toText4) {
+ OptionVendorClass vendor_class(Option::V4, 1234);
+ ASSERT_EQ(1, vendor_class.getTuplesNum());
+ // By default, there is an empty tuple in the option. Let's replace
+ // it with the tuple with some data.
+ OpaqueDataTuple tuple(OpaqueDataTuple::LENGTH_1_BYTE);
+ tuple = "Hello world";
+ vendor_class.setTuple(0, tuple);
+ // And add another tuple so as resulting option is a bit more complex.
+ tuple = "foo";
+ vendor_class.addTuple(tuple);
+ // Check that the text representation of the option is as expected.
+ EXPECT_EQ("type=124, len=24, enterprise id=0x4d2,"
+ " data-len0=11, vendor-class-data0='Hello world',"
+ " enterprise id=0x4d2, data-len1=3, vendor-class-data1='foo'",
+ vendor_class.toText());
+
+ // Check that indentation works.
+ EXPECT_EQ(" type=124, len=24, enterprise id=0x4d2,"
+ " data-len0=11, vendor-class-data0='Hello world',"
+ " enterprise id=0x4d2, data-len1=3, vendor-class-data1='foo'",
+ vendor_class.toText(3));
+}
+
+// Verifies correctness of the text representation of the DHCPv4 option.
+TEST(OptionVendorClass, toText6) {
+ OptionVendorClass vendor_class(Option::V6, 1234);
+ ASSERT_EQ(0, vendor_class.getTuplesNum());
+ // By default, there is an empty tuple in the option. Let's replace
+ // it with the tuple with some data.
+ OpaqueDataTuple tuple(OpaqueDataTuple::LENGTH_2_BYTES);
+ tuple = "Hello world";
+ vendor_class.addTuple(tuple);
+ // And add another tuple so as resulting option is a bit more complex.
+ tuple = "foo";
+ vendor_class.addTuple(tuple);
+ // Check that the text representation of the option is as expected.
+ EXPECT_EQ("type=16, len=22, enterprise id=0x4d2,"
+ " data-len0=11, vendor-class-data0='Hello world',"
+ " data-len1=3, vendor-class-data1='foo'",
+ vendor_class.toText());
+
+ // Check that indentation works.
+ EXPECT_EQ(" type=16, len=22, enterprise id=0x4d2,"
+ " data-len0=11, vendor-class-data0='Hello world',"
+ " data-len1=3, vendor-class-data1='foo'",
+ vendor_class.toText(2));
+}
+
} // end of anonymous namespace