Kea: isc::perfdhcp::PktTransform Class Reference

| Kea 2.2.0

Static Public Member Functions | List of all members
isc::perfdhcp::PktTransform Class Reference

Read and write raw data to DHCP packets. More...

`#include <pkt_transform.h>`

## Static Public Member Functions
static bool | pack (const dhcp::Option::Universe universe, const dhcp::OptionBuffer &in_buffer, const dhcp::OptionCollection &options, const size_t transid_offset, const uint32_t transid, util::OutputBuffer &out_buffer)
| Prepares on-wire format from raw buffer. More...
static bool | unpack (const dhcp::Option::Universe universe, const dhcp::OptionBuffer &in_buffer, const dhcp::OptionCollection &options, const size_t transid_offset, uint32_t &transid)
| Handles selective binary packet parsing. More...
static void | writeAt (dhcp::OptionBuffer &in_buffer, size_t dest_pos, std::vector< uint8_t >::iterator first, std::vector< uint8_t >::iterator last)
| Replace contents of buffer with vector. More...
template<typename T >
static void | writeValueAt (dhcp::OptionBuffer &in_buffer, size_t dest_pos, T val)
| Replace contents of one vector with uint16 value. More...

## Detailed Description

Read and write raw data to DHCP packets.

This class provides static functions to read/write raw data from/to the packet buffer. When reading data with the unpack() method, the corresponding options objects are updated. When writing to the packet buffer with pack(), options objects carry input data to be written.

This class is used both by PerfPkt4 and PerfPkt6 classes in case DHCP packets are created from template files. In this case, some of the template packet's options are replaced before sending it to the server. Offset of specific options are provided from the command line by the perfdhcp tool user, and passed in an options collection.

Definition at line 31 of file pkt_transform.h.

## Member Function Documentation

## ◆ pack()

bool isc::perfdhcp::PktTransform::pack | ( | const dhcp::Option::Universe | universe,
|  | const dhcp::OptionBuffer & | in_buffer,
|  | const dhcp::OptionCollection & | options,
|  | const size_t | transid_offset,
|  | const uint32_t | transid,
|  | util::OutputBuffer & | out_buffer
| ) |  |
| static

Prepares on-wire format from raw buffer.

The method copies the input buffer and options contents to the output buffer. The input buffer must contain whole initial packet data. Parts of this data will be overridden by options data specified in an options collection. Such options must have their offsets within a packet specified (see LocalizedOption to find out how to specify options offset).

Note
  The specified options must fit into the size of the initial packet data. A call to this method will fail if the option's offset + its size is beyond the packet's size.

Parameters

  universe | Universe used, V4 or V6
  in_buffer | Input buffer holding initial packet data, this can be directly read from template file
  options | Options collection with offsets
  transid_offset | offset of transaction id in a packet, transaction ID will be written to output buffer at this offset
  transid | Transaction ID value
  out_buffer | Output buffer holding "packed" data

Returns
  false, if pack operation failed.

Definition at line 29 of file pkt_transform.cc.

References isc::util::OutputBuffer::clear(), isc::Exception::what(), isc::util::OutputBuffer::writeData(), and isc::util::OutputBuffer::writeUint8At().

Referenced by isc::perfdhcp::PerfPkt4::rawPack(), and isc::perfdhcp::PerfPkt6::rawPack().

Here is the call graph for this function:

## ◆ unpack()

bool isc::perfdhcp::PktTransform::unpack | ( | const dhcp::Option::Universe | universe,
|  | const dhcp::OptionBuffer & | in_buffer,
|  | const dhcp::OptionCollection & | options,
|  | const size_t | transid_offset,
|  | uint32_t & | transid
| ) |  |
| static

Handles selective binary packet parsing.

This method handles the parsing of packets that have non-default options or transaction ID offsets. The client class has to use isc::dhcp::Pkt6::addOption to specify which options to parse. Each option should be of the isc::perfdhcp::LocalizedOption type with the offset value specified.

Parameters

  universe | universe used, V4 or V6
  in_buffer | input buffer to be parsed
  options | options collection with options offsets
  transid_offset | offset of transaction id in input buffer
  transid | transaction id value read from input buffer

Returns
  false, if unpack operation failed.

Definition at line 72 of file pkt_transform.cc.

References isc::perfdhcp::ExchangeStats::malformed_pkts_, and isc::Exception::what().

Referenced by isc::perfdhcp::PerfPkt4::rawUnpack(), and isc::perfdhcp::PerfPkt6::rawUnpack().

Here is the call graph for this function:

## ◆ writeAt()

void isc::perfdhcp::PktTransform::writeAt | ( | dhcp::OptionBuffer & | in_buffer,
|  | size_t | dest_pos,
|  | std::vector< uint8_t >::iterator | first,
|  | std::vector< uint8_t >::iterator | last
| ) |  |
| static

Replace contents of buffer with vector.

Function replaces data of the buffer with data from vector.

Parameters

  in_buffer | destination buffer.
  dest_pos | position in destination buffer.
  first | beginning of data range in source vector.
  last | end of data range in source vector.

Definition at line 216 of file pkt_transform.cc.

Referenced by isc::perfdhcp::PerfPkt4::writeAt(), and isc::perfdhcp::PerfPkt6::writeAt().

## ◆ writeValueAt()

template<typename T >

static void isc::perfdhcp::PktTransform::writeValueAt | ( | dhcp::OptionBuffer & | in_buffer,
|  | size_t | dest_pos,
|  | T | val
| ) |  |
| inlinestatic

Replace contents of one vector with uint16 value.

Function replaces data inside one vector with uint16_t value.

Parameters

  in_buffer | destination buffer.
  dest_pos | position in destination buffer.
  val | value to be written.

Definition at line 107 of file pkt_transform.h.

The documentation for this class was generated from the following files:

- pkt_transform.h
- pkt_transform.cc