Kea 2.7.6
isc::perfdhcp::PacketStorage< T > Class Template Reference

Represents a list of packets with a sequential and random access to list elements. More...

#include <packet_storage.h>

+ Inheritance diagram for isc::perfdhcp::PacketStorage< T >:

Public Types

typedef boost::shared_ptr< T > PacketPtr
 A type which represents the pointer to a packet.
 

Public Member Functions

 PacketStorage ()
 Constructor.
 
void append (const PacketPtr &packet)
 Appends the new packet object to the collection.
 
void clear (const uint64_t num=0)
 Removes packets from the storage.
 
bool empty () const
 Checks if the storage has no packets.
 
PacketPtr getNext ()
 Returns next packet from the storage.
 
PacketPtr getRandom ()
 Returns random packet from the storage.
 
uint64_t size () const
 Returns number of packets in the storage.
 

Detailed Description

template<typename T>
class isc::perfdhcp::PacketStorage< T >

Represents a list of packets with a sequential and random access to list elements.

The main purpose of this class is to support sending Renew and Release messages from perfdhcp. The Renew and Release messages are sent for existing leases only. Therefore, the typical use case for this class is that it holds a list of Reply messages sent by the server in response to Request messages. The Request messages hold addresses and/or IPv6 prefixes acquired so they can be used to identify existing leases. When perfdhcp needs to send Renew or Release message, it will access one of the elements on this list and will create the Renew or Release message based on its content. Once the element (packet) is returned it is also deleted from the list, so as it is not used again. This class provide either sequential access to the packets or random access. The random access algorithm is much slower but at least it allows to simulate more real scenario when the renewing or releasing client is random.

Template Parameters
Pkt4or Pkt6 class, which represents DHCPv4 or DHCPv6 message respectively.
Note
Although the class is intended to hold Pkt4 and Pkt6 objects, the current implementation is generic enough to holds any object wrapped in the boost::shared_ptr.

Definition at line 42 of file packet_storage.h.

Member Typedef Documentation

◆ PacketPtr

template<typename T >
boost::shared_ptr<T> isc::perfdhcp::PacketStorage< T >::PacketPtr

A type which represents the pointer to a packet.

Definition at line 45 of file packet_storage.h.

Constructor & Destructor Documentation

◆ PacketStorage()

template<typename T >
isc::perfdhcp::PacketStorage< T >::PacketStorage ( )
inline

Constructor.

Definition at line 56 of file packet_storage.h.

Member Function Documentation

◆ append()

template<typename T >
void isc::perfdhcp::PacketStorage< T >::append ( const PacketPtr & packet)
inline

Appends the new packet object to the collection.

Parameters
packetA pointer to an object representing a packet.

Definition at line 61 of file packet_storage.h.

◆ clear()

template<typename T >
void isc::perfdhcp::PacketStorage< T >::clear ( const uint64_t num = 0)
inline

Removes packets from the storage.

It is possible to specify a number of packets to be removed from a storage. Packets are removed from the beginning of the storage. If specified number is greater than the size of the storage, all packets are removed.

Parameters
numA number of packets to be removed. If omitted, all packets will be removed.

Definition at line 77 of file packet_storage.h.

References isc::perfdhcp::PacketStorage< T >::size().

+ Here is the call graph for this function:

◆ empty()

template<typename T >
bool isc::perfdhcp::PacketStorage< T >::empty ( ) const
inline

Checks if the storage has no packets.

Returns
true if storage is empty, false otherwise.

Definition at line 91 of file packet_storage.h.

Referenced by isc::perfdhcp::PacketStorage< T >::getRandom().

◆ getNext()

template<typename T >
PacketPtr isc::perfdhcp::PacketStorage< T >::getNext ( )
inline

Returns next packet from the storage.

This function returns packets sequentially (in the same order in which they have been appended). The returned packet is instantly removed from the storage.

Returns
next packet from the storage.

Definition at line 102 of file packet_storage.h.

◆ getRandom()

template<typename T >
PacketPtr isc::perfdhcp::PacketStorage< T >::getRandom ( )
inline

Returns random packet from the storage.

This function picks random packet from the storage and returns it. It is way slower than the getNext function because it has to iterate over all existing entries from the beginning of the storage to the random packet's position. Therefore, care should be taken when using this function to access elements when storage is large.

Returns
random packet from the storage.

Definition at line 122 of file packet_storage.h.

References isc::perfdhcp::PacketStorage< T >::empty(), and isc::perfdhcp::PacketStorage< T >::size().

+ Here is the call graph for this function:

◆ size()

template<typename T >
uint64_t isc::perfdhcp::PacketStorage< T >::size ( ) const
inline

Returns number of packets in the storage.

Returns
number of packets in the storage.

Definition at line 138 of file packet_storage.h.

Referenced by isc::perfdhcp::PacketStorage< T >::clear(), and isc::perfdhcp::PacketStorage< T >::getRandom().


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