Commit 81784141 authored by Marcin Siodelski's avatar Marcin Siodelski

[1955] Added remaining unit tests for PerfPkt4 and cleaned up the code.

parent 5c430ad5
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE. // PERFORMANCE OF THIS SOFTWARE.
#include <iostream>
#include <exceptions/exceptions.h>
#include <dhcp/libdhcp++.h> #include <dhcp/libdhcp++.h>
#include <dhcp/dhcp6.h> #include <dhcp/dhcp6.h>
...@@ -27,22 +25,30 @@ using namespace dhcp; ...@@ -27,22 +25,30 @@ using namespace dhcp;
namespace isc { namespace isc {
namespace perfdhcp { namespace perfdhcp {
PerfPkt4::PerfPkt4(const uint8_t* buf, uint32_t len, size_t transid_offset, uint32_t transid) : PerfPkt4::PerfPkt4(const uint8_t* buf, size_t len) :
Pkt4(buf, len),
transid_offset_(1) {
}
PerfPkt4::PerfPkt4(const uint8_t* buf,
size_t len,
size_t transid_offset,
uint32_t transid) :
Pkt4(buf, len), Pkt4(buf, len),
transid_offset_(transid_offset) { transid_offset_(transid_offset) {
transid_ = transid; transid_ = transid;
} }
PerfPkt4::PerfPkt4(const uint8_t* buf, uint32_t len, size_t transid_offset) : PerfPkt4::PerfPkt4(const uint8_t* buf, size_t len, size_t transid_offset) :
Pkt4(buf, len), Pkt4(buf, len),
transid_offset_(transid_offset) { transid_offset_(transid_offset) {
} }
bool bool
PerfPkt4::rawPack() { PerfPkt4::rawPack() {
return (PktTransform::pack(dhcp::Option::V4, return (PktTransform::pack(dhcp::Option::V4,
data_, data_,
options_, options_,
transid_offset_, transid_offset_,
transid_, transid_,
bufferOut_)); bufferOut_));
...@@ -50,9 +56,9 @@ PerfPkt4::rawPack() { ...@@ -50,9 +56,9 @@ PerfPkt4::rawPack() {
bool bool
PerfPkt4::rawUnpack() { PerfPkt4::rawUnpack() {
return (PktTransform::unpack(dhcp::Option::V4, return (PktTransform::unpack(dhcp::Option::V4,
data_, data_,
options_, options_,
transid_offset_, transid_offset_,
transid_)); transid_));
} }
......
...@@ -56,6 +56,16 @@ public: ...@@ -56,6 +56,16 @@ public:
/// Localized option pointer type. /// Localized option pointer type.
typedef boost::shared_ptr<LocalizedOption> LocalizedOptionPtr; typedef boost::shared_ptr<LocalizedOption> LocalizedOptionPtr;
/// \brief Constructor, used for outgoing and incoming messages
///
/// This constructor initializes transaction id and
/// transaction id offset of the packet with default
/// values.
///
/// \param buf buffer holding contents of the message.
/// \param len length of the data in the buffer.
PerfPkt4(const uint8_t* buf, size_t len);
/// \brief Constructor, used for outgoing DHCP messages. /// \brief Constructor, used for outgoing DHCP messages.
/// ///
/// Creates new DHCPv4 message using provided buffer. /// Creates new DHCPv4 message using provided buffer.
...@@ -73,7 +83,7 @@ public: ...@@ -73,7 +83,7 @@ public:
/// \param transid_offset transaction id offset in outgoing message. /// \param transid_offset transaction id offset in outgoing message.
/// \param transid transaction id to be stored in outgoing message. /// \param transid transaction id to be stored in outgoing message.
PerfPkt4(const uint8_t* buf, PerfPkt4(const uint8_t* buf,
uint32_t len, size_t len,
size_t transid_offset, size_t transid_offset,
uint32_t transid); uint32_t transid);
...@@ -100,7 +110,7 @@ public: ...@@ -100,7 +110,7 @@ public:
/// \param len size of buffer of packet content. /// \param len size of buffer of packet content.
/// \param transid_offset transaction id offset in a message. /// \param transid_offset transaction id offset in a message.
PerfPkt4(const uint8_t* buf, PerfPkt4(const uint8_t* buf,
uint32_t len, size_t len,
size_t transid_offset); size_t transid_offset);
/// \brief Returns transaction id offset in packet buffer /// \brief Returns transaction id offset in packet buffer
......
...@@ -57,7 +57,7 @@ PktTransform::pack(const Option::Universe universe, ...@@ -57,7 +57,7 @@ PktTransform::pack(const Option::Universe universe,
out_buffer.skip(transid_offset); out_buffer.skip(transid_offset);
try { try {
if (universe == Option::V6) { if (universe == Option::V4) {
out_buffer.writeUint8(transid >> 24 & 0xFF); out_buffer.writeUint8(transid >> 24 & 0xFF);
} }
out_buffer.writeUint8(transid >> 16 & 0xFF); out_buffer.writeUint8(transid >> 16 & 0xFF);
...@@ -111,7 +111,7 @@ PktTransform::unpack(const Option::Universe universe, ...@@ -111,7 +111,7 @@ PktTransform::unpack(const Option::Universe universe,
} }
try { try {
PktTransform::unpackOptions(universe, in_buffer, options); PktTransform::unpackOptions(in_buffer, options);
} catch (const isc::BadValue& e) { } catch (const isc::BadValue& e) {
cout << "Packet parsing failed: " << e.what() << endl; cout << "Packet parsing failed: " << e.what() << endl;
return (false); return (false);
...@@ -156,8 +156,7 @@ PktTransform::packOptions(const OptionBuffer& in_buffer, ...@@ -156,8 +156,7 @@ PktTransform::packOptions(const OptionBuffer& in_buffer,
} }
void void
PktTransform::unpackOptions(const Option::Universe universe, PktTransform::unpackOptions(const OptionBuffer& in_buffer,
const OptionBuffer& in_buffer,
const Option::OptionCollection& options) { const Option::OptionCollection& options) {
for (Option::OptionCollection::const_iterator it = options.begin(); for (Option::OptionCollection::const_iterator it = options.begin();
it != options.end(); ++it) { it != options.end(); ++it) {
...@@ -168,7 +167,7 @@ PktTransform::unpackOptions(const Option::Universe universe, ...@@ -168,7 +167,7 @@ PktTransform::unpackOptions(const Option::Universe universe,
if (opt_pos == 0) { if (opt_pos == 0) {
isc_throw(isc::BadValue, "failed to unpack packet from raw buffer " isc_throw(isc::BadValue, "failed to unpack packet from raw buffer "
"(Option position not specified)"); "(Option position not specified)");
} else if (opt_pos + 4 > in_buffer.size()) { } else if (opt_pos + option->getHeaderLen() > in_buffer.size()) {
isc_throw(isc::BadValue, isc_throw(isc::BadValue,
"failed to unpack options from from raw buffer " "failed to unpack options from from raw buffer "
"(Option position out of bounds)"); "(Option position out of bounds)");
...@@ -177,7 +176,7 @@ PktTransform::unpackOptions(const Option::Universe universe, ...@@ -177,7 +176,7 @@ PktTransform::unpackOptions(const Option::Universe universe,
size_t offset = opt_pos; size_t offset = opt_pos;
size_t offset_step = 1; size_t offset_step = 1;
uint16_t opt_type = 0; uint16_t opt_type = 0;
if (universe == Option::V6) { if (option->getUniverse() == Option::V6) {
offset_step = 2; offset_step = 2;
// For DHCPv6 option type is in first two octets. // For DHCPv6 option type is in first two octets.
opt_type = in_buffer[offset] * 256 + in_buffer[offset + 1]; opt_type = in_buffer[offset] * 256 + in_buffer[offset + 1];
...@@ -195,14 +194,14 @@ PktTransform::unpackOptions(const Option::Universe universe, ...@@ -195,14 +194,14 @@ PktTransform::unpackOptions(const Option::Universe universe,
// Get option length which is supposed to be after option type. // Get option length which is supposed to be after option type.
offset += offset_step; offset += offset_step;
uint16_t opt_len = in_buffer[offset] * 256 + in_buffer[offset + 1]; uint16_t opt_len = in_buffer[offset] * 256 + in_buffer[offset + 1];
if (universe == Option::V6) { if (option->getUniverse() == Option::V6) {
opt_len = in_buffer[offset] * 256 + in_buffer[offset + 1]; opt_len = in_buffer[offset] * 256 + in_buffer[offset + 1];
} else { } else {
opt_len = in_buffer[offset]; opt_len = in_buffer[offset];
} }
// Check if packet is not truncated. // Check if packet is not truncated.
if (offset + opt_len > in_buffer.size()) { if (offset + option->getHeaderLen() + opt_len > in_buffer.size()) {
isc_throw(isc::BadValue, isc_throw(isc::BadValue,
"failed to unpack option from raw buffer " "failed to unpack option from raw buffer "
"(option truncated)"); "(option truncated)");
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#ifndef __PKT_TRANSFORM_H #ifndef __PKT_TRANSFORM_H
#define __PKT_TRANSFORM_H #define __PKT_TRANSFORM_H
#include <boost/shared_ptr.hpp>
#include <dhcp/option.h> #include <dhcp/option.h>
#include "localized_option.h" #include "localized_option.h"
...@@ -27,20 +26,20 @@ namespace perfdhcp { ...@@ -27,20 +26,20 @@ namespace perfdhcp {
/// ///
/// This class provides static functions to read raw /// This class provides static functions to read raw
/// data from packet buffer and write raw data to packet /// data from packet buffer and write raw data to packet
/// buffer. When reading data with unpack() method, the /// buffer. When reading data with unpack() method, the
/// corresponding options objects are updated. /// corresponding options objects are updated.
/// When writting to the packet buffer with pack() nethod, /// When writting to the packet buffer with pack() nethod,
/// options objects carry input data to be written. /// options objects carry input data to be written.
/// This class is used both by \ref PerfPkt4 and /// This class is used both by \ref PerfPkt4 and
/// \ref PerfPkt6 classes in case DHCP packets are created /// \ref PerfPkt6 classes in case DHCP packets are created
/// from template files. In this case, some of the template /// from template files. In this case, some of the template
/// packet's options are replaced before sending it to /// packet's options are replaced before sending it to
/// server. Offset of specific options are provided from /// server. Offset of specific options are provided from
/// command line by perfdhcp tool user and passed in /// command line by perfdhcp tool user and passed in
/// options collection. /// options collection.
/// This class also provide mechanism to read some data /// This class also provide mechanism to read some data
/// from incoming packet buffer and update options /// from incoming packet buffer and update options
/// in options collection with these data. /// in options collection with these data.
/// It is assumed either in case of writting or reading /// It is assumed either in case of writting or reading
/// that all options have to be added to options collection /// that all options have to be added to options collection
/// and their offset have to be specified in buffer /// and their offset have to be specified in buffer
...@@ -54,11 +53,11 @@ public: ...@@ -54,11 +53,11 @@ public:
/// to output buffer. Input buffer must contain whole /// to output buffer. Input buffer must contain whole
/// initial packet data. Parts of this data will be /// initial packet data. Parts of this data will be
/// overriden by options data specified in options /// overriden by options data specified in options
/// collection. Such options must have their offsets in /// collection. Such options must have their offsets in
/// a packet specified (\see LocalizedOption to find out how /// a packet specified (\see LocalizedOption to find out how
/// to specify options offset). /// to specify options offset).
/// ///
/// \note Specified options must fit into size of the /// \note Specified options must fit into size of the
/// initial packet data. Call to this function will fail /// initial packet data. Call to this function will fail
/// if option's offset + its size is out of bounds. /// if option's offset + its size is out of bounds.
/// ///
...@@ -71,7 +70,7 @@ public: ...@@ -71,7 +70,7 @@ public:
/// offset /// offset
/// \param transid transaction id value /// \param transid transaction id value
/// \param out_buffer output buffer holding "packed" data /// \param out_buffer output buffer holding "packed" data
/// ///
/// \retrun false, if pack operation failed. /// \retrun false, if pack operation failed.
static bool pack(const dhcp::Option::Universe universe, static bool pack(const dhcp::Option::Universe universe,
const dhcp::OptionBuffer& in_buffer, const dhcp::OptionBuffer& in_buffer,
...@@ -88,8 +87,8 @@ public: ...@@ -88,8 +87,8 @@ public:
/// \ref isc::dhcp::Pkt6::addOption to specify which options to parse. /// \ref isc::dhcp::Pkt6::addOption to specify which options to parse.
/// Each option should be of the \ref isc::perfdhcp::LocalizedOption /// Each option should be of the \ref isc::perfdhcp::LocalizedOption
/// type with offset value indicated. /// type with offset value indicated.
/// Transaction id offset is specified as separate argument and /// Transaction id offset is specified as separate argument and
/// is used to read transaction id value from buffer. /// is used to read transaction id value from buffer.
/// ///
/// \param universe universe used, V4 or V6 /// \param universe universe used, V4 or V6
/// \param in_buffer input buffer to be parsed /// \param in_buffer input buffer to be parsed
...@@ -97,7 +96,7 @@ public: ...@@ -97,7 +96,7 @@ public:
/// \param transid_offset offset of transaction id in input buffer /// \param transid_offset offset of transaction id in input buffer
/// \param transid transaction id value read from input buffer /// \param transid transaction id value read from input buffer
/// \return false, if unpack operation failed. /// \return false, if unpack operation failed.
static bool unpack(const dhcp::Option::Universe universe, static bool unpack(const dhcp::Option::Universe universe,
const dhcp::OptionBuffer& in_buffer, const dhcp::OptionBuffer& in_buffer,
const dhcp::Option::OptionCollection& options, const dhcp::Option::OptionCollection& options,
const size_t transid_offset, const size_t transid_offset,
...@@ -106,9 +105,9 @@ public: ...@@ -106,9 +105,9 @@ public:
private: private:
/// \brief Replaces options contents of options in a buffer /// \brief Replaces options contents of options in a buffer
/// ///
/// The method uses localized options collection added to /// The method uses localized options collection added to
/// replace parts of initial packet data (e.g. read from /// replace parts of initial packet data (e.g. read from
/// template file). /// template file).
/// This private method is called from \ref PktTransform::pack /// This private method is called from \ref PktTransform::pack
/// ///
/// \param in_buffer input buffer holding initial packet data. /// \param in_buffer input buffer holding initial packet data.
...@@ -123,24 +122,23 @@ private: ...@@ -123,24 +122,23 @@ private:
/// ///
/// The method reads options data from the input buffer /// The method reads options data from the input buffer
/// and stores read data in options objects. Options /// and stores read data in options objects. Options
/// must have their offsets in a buffer specified /// must have their offsets in a buffer specified
/// (\see LocalizedOption to find out how to specify /// (\see LocalizedOption to find out how to specify
/// option offset). /// option offset).
/// This private method is called by \ref PktTransform::unpack. /// This private method is called by \ref PktTransform::unpack.
/// ///
/// \note This method iterates through all options in /// \note This method iterates through all options in
/// options collection, checks offset of the option /// options collection, checks offset of the option
/// in input buffer and reads data from the buffer to /// in input buffer and reads data from the buffer to
/// update option's buffer. If provided options collection /// update option's buffer. If provided options collection
/// is empty, call to this function will have no effect. /// is empty, call to this function will have no effect.
/// ///
/// \param universe universe used, V4 or V6 /// \param universe universe used, V4 or V6
/// \param in_buffer input buffer to be parsed. /// \param in_buffer input buffer to be parsed.
/// \param options oprions collection with their offsets /// \param options oprions collection with their offsets
/// in input buffer specified. /// in input buffer specified.
/// \throw isc::Unexpected if options unpack failed. /// \throw isc::Unexpected if options unpack failed.
static void unpackOptions(const dhcp::Option::Universe universe, static void unpackOptions(const dhcp::OptionBuffer& in_buffer,
const dhcp::OptionBuffer& in_buffer,
const dhcp::Option::OptionCollection& options); const dhcp::Option::OptionCollection& options);
}; };
......
...@@ -35,23 +35,6 @@ typedef PerfPkt4::LocalizedOptionPtr LocalizedOptionPtr; ...@@ -35,23 +35,6 @@ typedef PerfPkt4::LocalizedOptionPtr LocalizedOptionPtr;
namespace { namespace {
// a sample data
const uint8_t dummyOp = BOOTREQUEST;
const uint8_t dummyHtype = 6;
const uint8_t dummyHlen = 6;
const uint8_t dummyHops = 13;
const uint32_t dummyTransid = 0x12345678;
const uint16_t dummySecs = 42;
const uint16_t dummyFlags = BOOTP_BROADCAST;
const IOAddress dummyCiaddr("192.0.2.1");
const IOAddress dummyYiaddr("1.2.3.4");
const IOAddress dummySiaddr("192.0.2.255");
const IOAddress dummyGiaddr("255.255.255.255");
// a dummy MAC address
const uint8_t dummyMacAddr[] = {0, 1, 2, 3, 4, 5};
// a dummy MAC address, padded with 0s // a dummy MAC address, padded with 0s
const uint8_t dummyChaddr[16] = {0, 1, 2, 3, 4, 5, 0, 0, const uint8_t dummyChaddr[16] = {0, 1, 2, 3, 4, 5, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 }; 0, 0, 0, 0, 0, 0, 0, 0 };
...@@ -70,16 +53,14 @@ public: ...@@ -70,16 +53,14 @@ public:
PerfPkt4Test() { PerfPkt4Test() {
} }
/// \brief Returns captured SOLICIT packet. /// \brief Returns buffer with sample DHCPDISCOVER message.
/// ///
/// Captured SOLICIT packet with transid=0x3d79fb and options: client-id, /// This method creates buffer containing on-wire data of
/// in_na, dns-server, elapsed-time, option-request /// DHCPDICOSVER message. This buffer is used by tests below
/// This code was autogenerated /// to create DHCPv4 test packets.
/// (see src/bin/dhcp6/tests/iface_mgr_unittest.c),
/// but we spent some time to make is less ugly than it used to be.
/// ///
/// \return pointer to Pkt6 that represents received SOLICIT /// \return vector containing on-wire data
std::vector<uint8_t> capture() { std::vector<uint8_t>& capture() {
// That is only part of the header. It contains all "short" fields, // That is only part of the header. It contains all "short" fields,
// larger fields are constructed separately. // larger fields are constructed separately.
...@@ -97,28 +78,36 @@ public: ...@@ -97,28 +78,36 @@ public:
12, 3, 0, 1, 2, // Host name option. 12, 3, 0, 1, 2, // Host name option.
13, 3, 10, 11, 12, // Boot file size option 13, 3, 10, 11, 12, // Boot file size option
14, 3, 20, 21, 22, // Merit dump file 14, 3, 20, 21, 22, // Merit dump file
53, 1, 1, // DHCP message type. 53, 1, 1, // DHCP message type.
128, 3, 30, 31, 32, 128, 3, 30, 31, 32,
254, 3, 40, 41, 42, 254, 3, 40, 41, 42,
}; };
// Initialize the vector with the header fields defined above. // Initialize the vector with the header fields defined above.
vector<uint8_t> buf(hdr, hdr + sizeof(hdr)); static std::vector<uint8_t> buf(hdr, hdr + sizeof(hdr));
// Append the large header fields. // If this is a first call to this function. Initialize
std::copy(dummyChaddr, dummyChaddr + Pkt4::MAX_CHADDR_LEN, back_inserter(buf)); // remaining data.
std::copy(dummySname, dummySname + Pkt4::MAX_SNAME_LEN, back_inserter(buf)); if (buf.size() == sizeof(hdr))
std::copy(dummyFile, dummyFile + Pkt4::MAX_FILE_LEN, back_inserter(buf)); {
// Append magic cookie. // Append the large header fields.
buf.push_back(0x63); std::copy(dummyChaddr, dummyChaddr + Pkt4::MAX_CHADDR_LEN,
buf.push_back(0x82); back_inserter(buf));
buf.push_back(0x53); std::copy(dummySname, dummySname + Pkt4::MAX_SNAME_LEN,
buf.push_back(0x63); back_inserter(buf));
std::copy(dummyFile, dummyFile + Pkt4::MAX_FILE_LEN,
// Append options. back_inserter(buf));
std::copy(v4Opts, v4Opts + sizeof(v4Opts), back_inserter(buf));
// Append magic cookie.
buf.push_back(0x63);
buf.push_back(0x82);
buf.push_back(0x53);
buf.push_back(0x63);
// Append options.
std::copy(v4Opts, v4Opts + sizeof(v4Opts), back_inserter(buf));
}
return buf; return buf;
} }
}; };
...@@ -137,28 +126,34 @@ TEST_F(PerfPkt4Test, Constructor) { ...@@ -137,28 +126,34 @@ TEST_F(PerfPkt4Test, Constructor) {
// Test constructor to be used for outgoing messages. // Test constructor to be used for outgoing messages.
// Use non-zero offset and specify transaction id. // Use non-zero offset and specify transaction id.
boost::scoped_ptr<PerfPkt4> pkt2(new PerfPkt4(data, sizeof(data), 10, 0x010203)); boost::scoped_ptr<PerfPkt4> pkt2(new PerfPkt4(data, sizeof(data),
10, 0x010203));
EXPECT_EQ(0x010203, pkt2->getTransid()); EXPECT_EQ(0x010203, pkt2->getTransid());
EXPECT_EQ(10, pkt2->getTransIdOffset()); EXPECT_EQ(10, pkt2->getTransIdOffset());
// Test default constructor. Transaction id offset is expected to be 1.
boost::scoped_ptr<PerfPkt4> pkt3(new PerfPkt4(data, sizeof(data)));
EXPECT_EQ(1, pkt3->getTransIdOffset());
} }
TEST_F(PerfPkt4Test, RawPack) { TEST_F(PerfPkt4Test, RawPack) {
// Create new packet. // Create new packet.
std::vector<uint8_t> buf = capture(); std::vector<uint8_t> buf = capture();
boost::scoped_ptr<PerfPkt4> pkt(new PerfPkt4(&buf[0], buf.size(), 0x1, 1)); boost::scoped_ptr<PerfPkt4> pkt(new PerfPkt4(&buf[0], buf.size()));
// Initialize options data. // Initialize options data.
uint8_t buf_hostname[] = { 12, 3, 4, 5, 6 }; uint8_t buf_hostname[] = { 12, 3, 4, 5, 6 };
uint8_t buf_boot_filesize[] = { 13, 3, 1, 2, 3 }; uint8_t buf_boot_filesize[] = { 13, 3, 1, 2, 3 };
OptionBuffer vec_hostname(buf_hostname + 2, buf_hostname + 5); OptionBuffer vec_hostname(buf_hostname + 2, buf_hostname + 5);
OptionBuffer vec_boot_filesize(buf_boot_filesize + 2, buf_boot_filesize + 5); OptionBuffer vec_boot_filesize(buf_boot_filesize + 2,
buf_boot_filesize + 5);
// Create options objects. // Create options objects.
LocalizedOptionPtr pkt_hostname(new LocalizedOption(Option::V4, LocalizedOptionPtr pkt_hostname(new LocalizedOption(Option::V4,
DHO_HOST_NAME, DHO_HOST_NAME,
vec_hostname, vec_hostname,
240)); 240));
LocalizedOptionPtr pkt_boot_filesize(new LocalizedOption(Option::V4, LocalizedOptionPtr pkt_boot_filesize(new LocalizedOption(Option::V4,
DHO_BOOT_SIZE, DHO_BOOT_SIZE,
vec_boot_filesize, vec_boot_filesize,
245)); 245));
...@@ -167,7 +162,7 @@ TEST_F(PerfPkt4Test, RawPack) { ...@@ -167,7 +162,7 @@ TEST_F(PerfPkt4Test, RawPack) {
ASSERT_NO_THROW(pkt->addOption(pkt_boot_filesize)); ASSERT_NO_THROW(pkt->addOption(pkt_boot_filesize));
ASSERT_NO_THROW(pkt->addOption(pkt_hostname)); ASSERT_NO_THROW(pkt->addOption(pkt_hostname));
// We have valid options addedwith valid offsets so // We have valid options addedwith valid offsets so
// pack operation should succeed. // pack operation should succeed.
ASSERT_TRUE(pkt->rawPack()); ASSERT_TRUE(pkt->rawPack());
...@@ -175,7 +170,8 @@ TEST_F(PerfPkt4Test, RawPack) { ...@@ -175,7 +170,8 @@ TEST_F(PerfPkt4Test, RawPack) {
// DHO_BOOT_SIZE options. // DHO_BOOT_SIZE options.
util::OutputBuffer pkt_output = pkt->getBuffer(); util::OutputBuffer pkt_output = pkt->getBuffer();
ASSERT_EQ(buf.size(), pkt_output.getLength()); ASSERT_EQ(buf.size(), pkt_output.getLength());
const uint8_t* out_buf_data = static_cast<const uint8_t*>(pkt_output.getData()); const uint8_t* out_buf_data =
static_cast<const uint8_t*>(pkt_output.getData());
// Check if options we read from buffer is valid. // Check if options we read from buffer is valid.
EXPECT_EQ(0, memcmp(buf_hostname, out_buf_data + 240, 5)); EXPECT_EQ(0, memcmp(buf_hostname, out_buf_data + 240, 5));
...@@ -185,43 +181,47 @@ TEST_F(PerfPkt4Test, RawPack) { ...@@ -185,43 +181,47 @@ TEST_F(PerfPkt4Test, RawPack) {
TEST_F(PerfPkt4Test, RawUnpack) { TEST_F(PerfPkt4Test, RawUnpack) {
// Create new packet. // Create new packet.
std::vector<uint8_t> buf = capture(); std::vector<uint8_t> buf = capture();
boost::scoped_ptr<PerfPkt4> pkt(new PerfPkt4(&buf[0], buf.size(), 0x1, 1)); boost::scoped_ptr<PerfPkt4> pkt(new PerfPkt4(&buf[0], buf.size()));
// Create options (existing in the packet) and specify their offsets. // Create options (existing in the packet) and specify their offsets.
LocalizedOptionPtr opt_merit(new LocalizedOption(Option::V4, LocalizedOptionPtr opt_merit(new LocalizedOption(Option::V4,
DHO_MERIT_DUMP, DHO_MERIT_DUMP,
OptionBuffer(), OptionBuffer(),
250)); 250));
LocalizedOptionPtr opt_msg_type(new LocalizedOption(Option::V4, LocalizedOptionPtr opt_msg_type(new LocalizedOption(Option::V4,
DHO_DHCP_MESSAGE_TYPE, DHO_DHCP_MESSAGE_TYPE,
OptionBuffer(), OptionBuffer(),
255)); 255));
// Addition should be successful // Addition should be successful
ASSERT_NO_THROW(pkt->addOption(opt_merit)); ASSERT_NO_THROW(pkt->addOption(opt_merit));
ASSERT_NO_THROW(pkt->addOption(opt_msg_type)); ASSERT_NO_THROW(pkt->addOption(opt_msg_type));
// Option fit to packet boundaries and offsets are valid, // Option fit to packet boundaries and offsets are valid,