Kea  2.1.2-git
isc::dhcp::PacketQueueRing< PacketTypePtr > Class Template Reference

Provides a ring-buffer implementation of the PacketQueue interface. More...

#include <packet_queue_ring.h>

+ Inheritance diagram for isc::dhcp::PacketQueueRing< PacketTypePtr >:

Public Member Functions

 PacketQueueRing (const std::string &queue_type, size_t capacity)
 Constructor. More...
 
virtual ~PacketQueueRing ()
 virtual Destructor More...
 
virtual void clear ()
 Discards all packets currently in the buffer. More...
 
virtual PacketTypePtr dequeuePacket ()
 Dequeues the next packet from the queue. More...
 
virtual int eatPackets (const QueueEnd &)
 Discards packets from one end of the queue. More...
 
virtual bool empty () const
 Returns True if the queue is empty. More...
 
virtual void enqueuePacket (PacketTypePtr packet, const SocketInfo &source)
 Adds a packet to the queue. More...
 
virtual size_t getCapacity () const
 Returns the maximum number of packets allowed in the buffer. More...
 
virtual data::ElementPtr getInfo () const
 Fetches pertinent information. More...
 
virtual size_t getSize () const
 Returns the current number of packets in the buffer. More...
 
virtual const PacketTypePtr peek (const QueueEnd &from=QueueEnd::FRONT) const
 Gets the packet currently at one end of the queue. More...
 
virtual PacketTypePtr popPacket (const QueueEnd &from=QueueEnd::FRONT)
 Pops a packet from the queue. More...
 
virtual void pushPacket (PacketTypePtr &packet, const QueueEnd &to=QueueEnd::BACK)
 Pushes a packet onto the queue. More...
 
virtual void setCapacity (size_t capacity)
 Sets the maximum number of packets allowed in the buffer. More...
 
virtual bool shouldDropPacket (PacketTypePtr, const SocketInfo &)
 Determines if a packet should be discarded. More...
 
- Public Member Functions inherited from isc::dhcp::PacketQueue< PacketTypePtr >
 PacketQueue (const std::string &queue_type)
 Constructor. More...
 
virtual ~PacketQueue ()
 Virtual destructor. More...
 
std::string getInfoStr () const
 Fetches a JSON string representation of queue operational info. More...
 
std::string getQueueType ()
 

Static Public Attributes

static const size_t MIN_RING_CAPACITY = 5
 Minimum queue capacity permitted. More...
 

Detailed Description

template<typename PacketTypePtr>
class isc::dhcp::PacketQueueRing< PacketTypePtr >

Provides a ring-buffer implementation of the PacketQueue interface.

Template Parameters
PacketTypePtrType of packet the queue contains. This expected to be either isc::dhcp::Pkt4Ptr or isc::dhcp::Pkt6Ptr

Definition at line 26 of file packet_queue_ring.h.

Constructor & Destructor Documentation

◆ PacketQueueRing()

template<typename PacketTypePtr>
isc::dhcp::PacketQueueRing< PacketTypePtr >::PacketQueueRing ( const std::string &  queue_type,
size_t  capacity 
)
inline

Constructor.

Parameters
queue_typelogical name of the queue implementation
capacitymaximum number of packets the queue can hold

Definition at line 36 of file packet_queue_ring.h.

◆ ~PacketQueueRing()

template<typename PacketTypePtr>
virtual isc::dhcp::PacketQueueRing< PacketTypePtr >::~PacketQueueRing ( )
inlinevirtual

virtual Destructor

Definition at line 43 of file packet_queue_ring.h.

Member Function Documentation

◆ clear()

template<typename PacketTypePtr>
virtual void isc::dhcp::PacketQueueRing< PacketTypePtr >::clear ( )
inlinevirtual

Discards all packets currently in the buffer.

Implements isc::dhcp::PacketQueue< PacketTypePtr >.

Definition at line 198 of file packet_queue_ring.h.

◆ dequeuePacket()

template<typename PacketTypePtr>
virtual PacketTypePtr isc::dhcp::PacketQueueRing< PacketTypePtr >::dequeuePacket ( )
inlinevirtual

Dequeues the next packet from the queue.

Dequeues the next packet (if any) and returns it.

Returns
A pointer to dequeued packet, or an empty pointer if the queue is empty.

Implements isc::dhcp::PacketQueue< PacketTypePtr >.

Definition at line 65 of file packet_queue_ring.h.

◆ eatPackets()

template<typename PacketTypePtr>
virtual int isc::dhcp::PacketQueueRing< PacketTypePtr >::eatPackets ( const QueueEnd )
inlinevirtual

Discards packets from one end of the queue.

This function is called at the beginning of dequeuePacket and provides an opportunity to examine and discard packets from the queue prior to dequeuing the next packet to be processed. Derivations are expected to provide implementations based on their own requirements. The default implementation is to to simply return without skipping any packets.

Returns
The number of packets discarded.

Definition at line 97 of file packet_queue_ring.h.

Referenced by isc::dhcp::PacketQueueRing< Pkt6Ptr >::dequeuePacket().

◆ empty()

template<typename PacketTypePtr>
virtual bool isc::dhcp::PacketQueueRing< PacketTypePtr >::empty ( ) const
inlinevirtual

Returns True if the queue is empty.

Implements isc::dhcp::PacketQueue< PacketTypePtr >.

Definition at line 165 of file packet_queue_ring.h.

◆ enqueuePacket()

template<typename PacketTypePtr>
virtual void isc::dhcp::PacketQueueRing< PacketTypePtr >::enqueuePacket ( PacketTypePtr  packet,
const SocketInfo source 
)
inlinevirtual

Adds a packet to the queue.

Calls shouldDropPacket to determine if the packet should be queued or dropped. If it should be queued it is added to the end of the queue specified by the "to" parameter.

Parameters
packetpacket to enqueue
sourcesocket the packet came from

Implements isc::dhcp::PacketQueue< PacketTypePtr >.

Definition at line 53 of file packet_queue_ring.h.

◆ getCapacity()

template<typename PacketTypePtr>
virtual size_t isc::dhcp::PacketQueueRing< PacketTypePtr >::getCapacity ( ) const
inlinevirtual

Returns the maximum number of packets allowed in the buffer.

Definition at line 171 of file packet_queue_ring.h.

Referenced by isc::dhcp::PacketQueueRing< Pkt6Ptr >::getInfo().

◆ getInfo()

template<typename PacketTypePtr>
virtual data::ElementPtr isc::dhcp::PacketQueueRing< PacketTypePtr >::getInfo ( ) const
inlinevirtual

Fetches pertinent information.

Reimplemented from isc::dhcp::PacketQueue< PacketTypePtr >.

Definition at line 203 of file packet_queue_ring.h.

◆ getSize()

template<typename PacketTypePtr>
virtual size_t isc::dhcp::PacketQueueRing< PacketTypePtr >::getSize ( ) const
inlinevirtual

Returns the current number of packets in the buffer.

Implements isc::dhcp::PacketQueue< PacketTypePtr >.

Definition at line 193 of file packet_queue_ring.h.

Referenced by isc::dhcp::PacketQueueRing< Pkt6Ptr >::getInfo().

◆ peek()

template<typename PacketTypePtr>
virtual const PacketTypePtr isc::dhcp::PacketQueueRing< PacketTypePtr >::peek ( const QueueEnd from = QueueEnd::FRONT) const
inlinevirtual

Gets the packet currently at one end of the queue.

Returns a pointer the packet at the specified end of the queue without dequeuing it.

Parameters
fromspecifies which end of the queue to examine.
Returns
A pointer to packet, or an empty pointer if the queue is empty.

Definition at line 155 of file packet_queue_ring.h.

◆ popPacket()

template<typename PacketTypePtr>
virtual PacketTypePtr isc::dhcp::PacketQueueRing< PacketTypePtr >::popPacket ( const QueueEnd from = QueueEnd::FRONT)
inlinevirtual

Pops a packet from the queue.

Removes a packet from the end of the queue specified and returns it.

Parameters
fromspecifies the end of the queue from which the packet should be taken. It locks the queue's Mutex upon entry.
Returns
A pointer to dequeued packet, or an empty pointer if the queue is empty.

Definition at line 126 of file packet_queue_ring.h.

Referenced by isc::dhcp::PacketQueueRing< Pkt6Ptr >::dequeuePacket().

◆ pushPacket()

template<typename PacketTypePtr>
virtual void isc::dhcp::PacketQueueRing< PacketTypePtr >::pushPacket ( PacketTypePtr &  packet,
const QueueEnd to = QueueEnd::BACK 
)
inlinevirtual

Pushes a packet onto the queue.

Adds a packet onto the end of queue specified.

Parameters
packetpacket to add to the queue
tospecifies the end of the queue to which the packet should be added.

Definition at line 108 of file packet_queue_ring.h.

Referenced by isc::dhcp::PacketQueueRing< Pkt6Ptr >::enqueuePacket().

◆ setCapacity()

template<typename PacketTypePtr>
virtual void isc::dhcp::PacketQueueRing< PacketTypePtr >::setCapacity ( size_t  capacity)
inlinevirtual

Sets the maximum number of packets allowed in the buffer.

Todo:
  • do we want to change size on the fly? This might need to be private, called only by constructor
Exceptions
BadValueif capacity is too low.
Todo:
should probably throw if it's zero

Definition at line 181 of file packet_queue_ring.h.

◆ shouldDropPacket()

template<typename PacketTypePtr>
virtual bool isc::dhcp::PacketQueueRing< PacketTypePtr >::shouldDropPacket ( PacketTypePtr  ,
const SocketInfo  
)
inlinevirtual

Determines if a packet should be discarded.

This function is called in enqueuePackets for each packet in its packet list. It provides an opportunity to examine the packet and its source and decide whether it should be dropped or added to the queue. Derivations are expected to provide implementations based on their own requirements. Bear in mind that the packet has NOT been unpacked at this point. The default implementation simply returns false (i.e. keep the packet).

Returns
true if the packet should be dropped, false if it should be kept.

Definition at line 82 of file packet_queue_ring.h.

Referenced by isc::dhcp::PacketQueueRing< Pkt6Ptr >::enqueuePacket().

Member Data Documentation

◆ MIN_RING_CAPACITY

template<typename PacketTypePtr>
const size_t isc::dhcp::PacketQueueRing< PacketTypePtr >::MIN_RING_CAPACITY = 5
static

Minimum queue capacity permitted.

Below five is pretty much nonsensical.

Definition at line 30 of file packet_queue_ring.h.


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