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

Static Public Attributes

static const size_t MIN_RING_CAPACITY = 5
 Minimum queue capacity permitted.
 

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.

References isc::dhcp::PacketQueueRing< PacketTypePtr >::eatPackets(), isc::dhcp::FRONT, and isc::dhcp::PacketQueueRing< PacketTypePtr >::popPacket().

+ Here is the call graph for this function:

◆ 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< PacketTypePtr >::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.

References isc::dhcp::PacketQueueRing< PacketTypePtr >::pushPacket(), and isc::dhcp::PacketQueueRing< PacketTypePtr >::shouldDropPacket().

+ Here is the call graph for this function:

◆ 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< PacketTypePtr >::getInfo().

◆ getInfo()

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

◆ 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< PacketTypePtr >::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.

References isc::dhcp::FRONT.

◆ 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.

References isc::dhcp::FRONT.

Referenced by isc::dhcp::PacketQueueRing< PacketTypePtr >::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.

References isc::dhcp::BACK.

Referenced by isc::dhcp::PacketQueueRing< PacketTypePtr >::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.

References isc_throw, and isc::dhcp::PacketQueueRing< PacketTypePtr >::MIN_RING_CAPACITY.

◆ 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< PacketTypePtr >::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.

Referenced by isc::dhcp::PacketQueueRing< PacketTypePtr >::setCapacity().


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