Kea  1.9.9-git
isc::perfdhcp::PerfPkt4 Class Reference

PerfPkt4 (DHCPv4 packet) More...

#include <perf_pkt4.h>

+ Inheritance diagram for isc::perfdhcp::PerfPkt4:

Public Types

typedef boost::shared_ptr< LocalizedOptionLocalizedOptionPtr
 Localized option pointer type. More...
 

Public Member Functions

 PerfPkt4 (const uint8_t *buf, size_t len, size_t transid_offset=1, uint32_t transid=0)
 Constructor, used to create messages from packet template files. More...
 
size_t getTransidOffset () const
 Returns transaction id offset in packet buffer. More...
 
bool rawPack ()
 Prepares on-wire format from raw buffer. More...
 
bool rawUnpack ()
 Handles limited binary packet parsing for packets with custom offsets of options and transaction ID. More...
 
void writeAt (size_t dest_pos, std::vector< uint8_t >::iterator first, std::vector< uint8_t >::iterator last)
 Replace contents of buffer with data. More...
 
template<typename T >
void writeValueAt (size_t dest_pos, T val)
 Replace contents of buffer with value. More...
 
- Public Member Functions inherited from isc::dhcp::Pkt4
 Pkt4 (uint8_t msg_type, uint32_t transid)
 Constructor, used in replying to a message. More...
 
 Pkt4 (const uint8_t *data, size_t len)
 Constructor, used in message reception. More...
 
virtual void addOption (const OptionPtr &opt)
 Add an option. More...
 
const isc::asiolink::IOAddressgetCiaddr () const
 Returns ciaddr field. More...
 
std::list< uint16_t > & getDeferredOptions ()
 Returns a reference to option codes which unpacking will be deferred. More...
 
const OptionBuffer getFile () const
 Returns file field. More...
 
uint16_t getFlags () const
 Returns flags field. More...
 
const isc::asiolink::IOAddressgetGiaddr () const
 Returns giaddr field. More...
 
uint8_t getHlen () const
 Returns hlen field. More...
 
uint8_t getHops () const
 Returns hops field. More...
 
uint8_t getHtype () const
 Returns htype field. More...
 
HWAddrPtr getHWAddr () const
 returns hardware address information More...
 
std::string getLabel () const
 Returns text representation of the primary packet identifiers. More...
 
HWAddrPtr getLocalHWAddr () const
 Returns local HW address. More...
 
const char * getName () const
 Returns name of the DHCP message. More...
 
uint8_t getOp () const
 Returns op field. More...
 
uint16_t getSecs () const
 Returns secs field. More...
 
const isc::asiolink::IOAddressgetSiaddr () const
 Returns siaddr field. More...
 
const OptionBuffer getSname () const
 Returns sname field. More...
 
uint8_t getType () const
 Returns DHCP message type (e.g. More...
 
const isc::asiolink::IOAddressgetYiaddr () const
 Returns yiaddr field. More...
 
virtual bool isDhcp4o6 () const
 Checks if a DHCPv4 message has been transported over DHCPv6. More...
 
bool isRelayed () const
 Checks if a DHCPv4 message has been relayed. More...
 
size_t len ()
 Returns the size of the required buffer to build the packet. More...
 
virtual void pack ()
 Prepares on-wire format of DHCPv4 packet. More...
 
void setCiaddr (const isc::asiolink::IOAddress &ciaddr)
 Sets ciaddr field. More...
 
void setFile (const uint8_t *file, size_t file_len)
 Sets file field. More...
 
void setFlags (uint16_t flags)
 Sets flags field. More...
 
void setGiaddr (const isc::asiolink::IOAddress &giaddr)
 Sets giaddr field. More...
 
void setHops (uint8_t hops)
 Sets hops field. More...
 
void setHWAddr (uint8_t htype, uint8_t hlen, const std::vector< uint8_t > &mac_addr)
 Sets hardware address. More...
 
void setHWAddr (const HWAddrPtr &addr)
 Sets hardware address. More...
 
void setLocalHWAddr (const uint8_t htype, const uint8_t hlen, const std::vector< uint8_t > &mac_addr)
 Sets local HW address. More...
 
void setLocalHWAddr (const HWAddrPtr &addr)
 Sets local HW address. More...
 
void setSecs (uint16_t secs)
 Sets secs field. More...
 
void setSiaddr (const isc::asiolink::IOAddress &siaddr)
 Sets siaddr field. More...
 
void setSname (const uint8_t *sname, size_t sname_len)
 Sets sname field. More...
 
void setType (uint8_t type)
 Sets DHCP message type (e.g. More...
 
void setYiaddr (const isc::asiolink::IOAddress &yiaddr)
 Sets yiaddr field. More...
 
std::string toText () const
 Returns text representation of the packet. More...
 
virtual void unpack ()
 Parses on-wire form of DHCPv4 packet. More...
 
- Public Member Functions inherited from isc::dhcp::Pkt
virtual ~Pkt ()
 Virtual destructor. More...
 
void addClass (const isc::dhcp::ClientClass &client_class, bool required=false)
 Adds packet to a specified class. More...
 
bool delOption (uint16_t type)
 Attempts to delete first suboption of requested type. More...
 
isc::util::OutputBuffergetBuffer ()
 Returns reference to output buffer. More...
 
const ClientClassesgetClasses (bool required=false) const
 Returns the class set. More...
 
std::string getIface () const
 Returns interface name. More...
 
uint32_t getIndex () const
 Returns interface index. More...
 
const isc::asiolink::IOAddressgetLocalAddr () const
 Returns local IP address. More...
 
uint16_t getLocalPort () const
 Returns local UDP (and soon TCP) port. More...
 
HWAddrPtr getMAC (uint32_t hw_addr_src)
 Returns MAC address. More...
 
OptionPtr getOption (const uint16_t type)
 Returns the first option of specified type. More...
 
const isc::asiolink::IOAddressgetRemoteAddr () const
 Returns remote IP address. More...
 
HWAddrPtr getRemoteHWAddr () const
 Returns the remote HW address obtained from raw sockets. More...
 
uint16_t getRemotePort () const
 Returns remote port. More...
 
const boost::posix_time::ptime & getTimestamp () const
 Returns packet timestamp. More...
 
uint32_t getTransid () const
 Returns value of transaction-id field. More...
 
bool inClass (const isc::dhcp::ClientClass &client_class)
 Checks whether a client belongs to a given class. More...
 
bool indexSet () const
 Checks if interface index has been set. More...
 
bool isCopyRetrievedOptions () const
 Returns whether the copying of retrieved options is enabled. More...
 
void repack ()
 Copies content of input buffer to output buffer. More...
 
void resetIndex ()
 Resets interface index to negative value. More...
 
virtual void setCopyRetrievedOptions (const bool copy)
 Controls whether the option retrieved by the Pkt::getOption should be copied before being returned. More...
 
void setIface (const std::string &iface)
 Sets interface name. More...
 
void setIndex (uint32_t ifindex)
 Sets interface index. More...
 
void setLocalAddr (const isc::asiolink::IOAddress &local)
 Sets local IP address. More...
 
void setLocalPort (uint16_t local)
 Sets local UDP (and soon TCP) port. More...
 
void setRemoteAddr (const isc::asiolink::IOAddress &remote)
 Sets remote IP address. More...
 
void setRemoteHWAddr (const HWAddrPtr &hw_addr)
 Sets remote hardware address. More...
 
void setRemoteHWAddr (const uint8_t htype, const uint8_t hlen, const std::vector< uint8_t > &hw_addr)
 Sets remote hardware address. More...
 
void setRemotePort (uint16_t remote)
 Sets remote UDP (and soon TCP) port. More...
 
void setTimestamp (boost::posix_time::ptime &timestamp)
 Set packet timestamp. More...
 
void setTransid (uint32_t transid)
 Sets transaction-id value. More...
 
void updateTimestamp ()
 Update packet timestamp. More...
 
- Public Member Functions inherited from isc::hooks::CalloutHandleAssociate
 CalloutHandleAssociate ()
 Constructor. More...
 
CalloutHandlePtr getCalloutHandle ()
 Returns callout handle. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from isc::dhcp::Pkt4
static const char * getName (const uint8_t type)
 Returns name of the DHCP message for a given type number. More...
 
static std::string makeLabel (const HWAddrPtr &hwaddr, const ClientIdPtr &client_id, const uint32_t transid)
 Returns text representation of the given packet identifiers. More...
 
static std::string makeLabel (const HWAddrPtr &hwaddr, const ClientIdPtr &client_id)
 Returns text representation of the given packet identifiers. More...
 
- Public Attributes inherited from isc::dhcp::Pkt
ClientClasses classes_
 Classes this packet belongs to. More...
 
OptionBuffer data_
 Unparsed data (in received packets). More...
 
isc::dhcp::OptionCollection options_
 Collection of options present in this message. More...
 
ClientClasses required_classes_
 Classes which are required to be evaluated. More...
 
- Static Public Attributes inherited from isc::dhcp::Pkt4
static const size_t DHCPV4_PKT_HDR_LEN = 236
 specifies DHCPv4 packet header length (fixed part) More...
 
static const uint16_t FLAG_BROADCAST_MASK = 0x8000
 Mask for the value of flags field in the DHCPv4 message to check whether client requested broadcast response. More...
 
static const size_t MAX_CHADDR_LEN = 16
 length of the CHADDR field in DHCPv4 message More...
 
static const size_t MAX_FILE_LEN = 128
 length of the FILE field in DHCPv4 message More...
 
static const size_t MAX_SNAME_LEN = 64
 length of the SNAME field in DHCPv4 message More...
 
- Protected Member Functions inherited from isc::dhcp::Pkt4
uint8_t DHCPTypeToBootpType (uint8_t dhcpType)
 converts DHCP message type to BOOTP op type More...
 
virtual HWAddrPtr getMACFromDocsisCMTS ()
 No-op. More...
 
virtual HWAddrPtr getMACFromDocsisModem ()
 No-op. More...
 
virtual HWAddrPtr getMACFromDUID ()
 No-op. More...
 
virtual HWAddrPtr getMACFromIPv6RelayOpt ()
 No-op. More...
 
virtual HWAddrPtr getMACFromRemoteIdRelayOption ()
 No-op. More...
 
virtual HWAddrPtr getMACFromSrcLinkLocalAddr ()
 No-op. More...
 
- Protected Member Functions inherited from isc::dhcp::Pkt
 Pkt (uint32_t transid, const isc::asiolink::IOAddress &local_addr, const isc::asiolink::IOAddress &remote_addr, uint16_t local_port, uint16_t remote_port)
 Constructor. More...
 
 Pkt (const uint8_t *buf, uint32_t len, const isc::asiolink::IOAddress &local_addr, const isc::asiolink::IOAddress &remote_addr, uint16_t local_port, uint16_t remote_port)
 Constructor. More...
 
HWAddrPtr getMACFromIPv6 (const isc::asiolink::IOAddress &addr)
 Attempts to convert IPv6 address into MAC. More...
 
OptionPtr getNonCopiedOption (const uint16_t type) const
 Returns the first option of specified type without copying. More...
 
- Protected Attributes inherited from isc::dhcp::Pkt4
isc::asiolink::IOAddress ciaddr_
 ciaddr field (32 bits): Client's IP address More...
 
std::list< uint16_t > deferred_options_
 
uint8_t file_ [MAX_FILE_LEN]
 file field (128 bytes) More...
 
uint16_t flags_
 flags More...
 
isc::asiolink::IOAddress giaddr_
 giaddr field (32 bits): Gateway IP address More...
 
uint8_t hops_
 Number of relay agents traversed. More...
 
HWAddrPtr hwaddr_
 link-layer address and hardware information represents 3 fields: htype (hardware type, 1 byte), hlen (length of the hardware address, up to 16) and chaddr (hardware address field, 16 bytes) More...
 
HWAddrPtr local_hwaddr_
 local HW address (dst if receiving packet, src if sending packet) More...
 
uint8_t op_
 message operation code More...
 
uint16_t secs_
 elapsed (number of seconds since beginning of transmission) More...
 
isc::asiolink::IOAddress siaddr_
 siaddr field (32 bits): next server IP address in boot process(e.g.TFTP) More...
 
uint8_t sname_ [MAX_SNAME_LEN]
 sname field (64 bytes) More...
 
isc::asiolink::IOAddress yiaddr_
 yiaddr field (32 bits): Client's IP address ("your"), set by server More...
 
- Protected Attributes inherited from isc::dhcp::Pkt
isc::util::OutputBuffer buffer_out_
 Output buffer (used during message transmission) More...
 
bool copy_retrieved_options_
 Indicates if a copy of the retrieved option should be returned when Pkt::getOption is called. More...
 
std::string iface_
 Name of the network interface the packet was received/to be sent over. More...
 
int64_t ifindex_
 Interface index. More...
 
isc::asiolink::IOAddress local_addr_
 Local IP (v4 or v6) address. More...
 
uint16_t local_port_
 local TDP or UDP port More...
 
isc::asiolink::IOAddress remote_addr_
 Remote IP address. More...
 
HWAddrPtr remote_hwaddr_
 
uint16_t remote_port_
 remote TCP or UDP port More...
 
boost::posix_time::ptime timestamp_
 packet timestamp More...
 
uint32_t transid_
 Transaction-id (32 bits for v4, 24 bits for v6) More...
 
- Protected Attributes inherited from isc::hooks::CalloutHandleAssociate
CalloutHandlePtr callout_handle_
 Callout handle stored. More...
 

Detailed Description

PerfPkt4 (DHCPv4 packet)

This class extends the functionality of isc::dhcp::Pkt4 by adding the ability to specify an options offset in the DHCP message and to override options' contents. This is particularly useful when we create a packet object using a template file (i.e. do not build it dynamically). The client class should read data from the template file and pass it to this class in a buffer.

The contents of such a packet can be later partially replaced, notably the selected options and the transaction ID. (The transaction ID and its offset in the template file are passed via the constructor.)

In order to replace contents of the options, the client class has to create a collection of LocalizedOption, adding them using dhcp::Pkt4::addOption.

Note
If you don't use template files simply use constructors inherited from parent class and isc::dhcp::Option type instead

Definition at line 42 of file perf_pkt4.h.

Member Typedef Documentation

Localized option pointer type.

Definition at line 46 of file perf_pkt4.h.

Constructor & Destructor Documentation

isc::perfdhcp::PerfPkt4::PerfPkt4 ( const uint8_t *  buf,
size_t  len,
size_t  transid_offset = 1,
uint32_t  transid = 0 
)

Constructor, used to create messages from packet template files.

Creates a new DHCPv4 message using the provided buffer. The transaction ID and its offset are specified via this constructor. The transaction ID is stored in outgoing message when client class calls PerfPkt4::rawPack. Transaction id offset value is used for incoming and outgoing messages to identify transaction ID field's position in incoming and outgoing messages.

Parameters
bufbuffer holding contents of the message (this can be directly read from template file).
lenlength of the data in the buffer.
transid_offsettransaction id offset in a message.
transidtransaction id to be stored in outgoing message.

Definition at line 21 of file perf_pkt4.cc.

References isc::dhcp::Pkt::setTransid().

+ Here is the call graph for this function:

Member Function Documentation

size_t isc::perfdhcp::PerfPkt4::getTransidOffset ( ) const
inline

Returns transaction id offset in packet buffer.

Returns
Transaction ID offset in packet buffer

Definition at line 72 of file perf_pkt4.h.

Referenced by rawPack(), and rawUnpack().

bool isc::perfdhcp::PerfPkt4::rawPack ( )

Prepares on-wire format from raw buffer.

The method copies the buffer provided in the constructor to the output buffer and replaces the transaction ID and selected options with new data.

Note
Use this method to prepare an on-wire DHCPv4 message when you use template packets that require replacement of selected options' contents before sending.
Returns
false ID pack operation failed.

Definition at line 31 of file perf_pkt4.cc.

References isc::dhcp::Pkt::buffer_out_, isc::dhcp::Pkt::data_, isc::dhcp::Pkt::getTransid(), getTransidOffset(), isc::dhcp::Pkt::options_, isc::perfdhcp::PktTransform::pack(), and isc::dhcp::Option::V4.

+ Here is the call graph for this function:

bool isc::perfdhcp::PerfPkt4::rawUnpack ( )

Handles limited binary packet parsing for packets with custom offsets of options and transaction ID.

This method handles the parsing of packets that have custom offsets of options or transaction ID. Use isc::dhcp::Pkt4::addOption to specify which options to parse. Options should be of the isc::perfdhcp::LocalizedOption type with offset values provided. Each added option will be updated with actual data read from the binary packet buffer.

Returns
false If unpack operation failed.

Definition at line 41 of file perf_pkt4.cc.

References isc::dhcp::Pkt::data_, isc::dhcp::Pkt::getTransid(), getTransidOffset(), isc::dhcp::Pkt::options_, isc::dhcp::Pkt::setTransid(), isc::perfdhcp::PktTransform::unpack(), and isc::dhcp::Option::V4.

+ Here is the call graph for this function:

void isc::perfdhcp::PerfPkt4::writeAt ( size_t  dest_pos,
std::vector< uint8_t >::iterator  first,
std::vector< uint8_t >::iterator  last 
)

Replace contents of buffer with data.

Function replaces part of the buffer with data from vector.

Parameters
dest_posposition in buffer where data is replaced.
firstbeginning of data range in source vector.
lastend of data range in source vector.

Definition at line 55 of file perf_pkt4.cc.

References isc::dhcp::Pkt::data_, and isc::perfdhcp::PktTransform::writeAt().

+ Here is the call graph for this function:

template<typename T >
void isc::perfdhcp::PerfPkt4::writeValueAt ( size_t  dest_pos,
val 
)
inline

Replace contents of buffer with value.

Function replaces part of buffer with value.

Parameters
dest_posposition in buffer where value is to be written.
valvalue to be written.

Definition at line 119 of file perf_pkt4.h.

References isc::dhcp::Pkt::data_.


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