Kea  1.9.9-git
packet_queue.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef PACKET_QUEUE_H
8 #define PACKET_QUEUE_H
9 
10 #include <cc/data.h>
11 #include <dhcp/socket_info.h>
12 #include <dhcp/pkt4.h>
13 #include <dhcp/pkt6.h>
14 
15 #include <boost/circular_buffer.hpp>
16 #include <sstream>
17 
18 namespace isc {
19 
20 namespace dhcp {
21 
26 public:
27  InvalidQueueParameter(const char* file, size_t line, const char* what) :
28  isc::Exception(file, line, what) {}
29 };
30 
32 enum class QueueEnd {
33  FRONT, // Typically the end packets are read from
34  BACK // Typically the end packets are written to
35 };
36 
47 template<typename PacketTypePtr>
48 class PacketQueue {
49 public:
50 
57  explicit PacketQueue(const std::string& queue_type)
58  : queue_type_(queue_type) {}
59 
61  virtual ~PacketQueue(){};
62 
70  virtual void enqueuePacket(PacketTypePtr packet, const SocketInfo& source) = 0;
71 
79  virtual PacketTypePtr dequeuePacket() = 0;
80 
82  virtual bool empty() const = 0;
83 
85  virtual size_t getSize() const = 0;
86 
88  virtual void clear() = 0;
89 
100  virtual data::ElementPtr getInfo() const {
102  info->set("queue-type", data::Element::create(queue_type_));
103  return(info);
104  }
105 
111  std::string getInfoStr() const {
113  std::ostringstream os;
114  info->toJSON(os);
115  return (os.str());
116  }
117 
119  std::string getQueueType() {
120  return (queue_type_);
121  };
122 
123 private:
125  std::string queue_type_;
126 
127 };
128 
132 typedef boost::shared_ptr<PacketQueue<Pkt4Ptr>> PacketQueue4Ptr;
133 
137 typedef boost::shared_ptr<PacketQueue<Pkt6Ptr>> PacketQueue6Ptr;
138 
139 }; // namespace isc::dhcp
140 }; // namespace isc
141 
142 #endif // PACKET_QUEUE_H
virtual bool empty() const =0
return True if the queue is empty.
std::string getQueueType()
Definition: packet_queue.h:119
Interface for managing a queue of inbound DHCP packets.
Definition: packet_queue.h:48
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
std::string getInfoStr() const
Fetches a JSON string representation of queue operational info.
Definition: packet_queue.h:111
QueueEnd
Enumerates choices between the two ends of the queue.
Definition: packet_queue.h:32
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:267
boost::shared_ptr< PacketQueue< Pkt4Ptr > > PacketQueue4Ptr
Defines pointer to the DHCPv4 queue interface used at the application level.
Definition: packet_queue.h:132
virtual size_t getSize() const =0
Returns the current number of packets in the buffer.
InvalidQueueParameter(const char *file, size_t line, const char *what)
Definition: packet_queue.h:27
boost::shared_ptr< PacketQueue< Pkt6Ptr > > PacketQueue6Ptr
Defines pointer to the DHCPv6 queue interface used at the application level.
Definition: packet_queue.h:137
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition: data.cc:222
virtual ~PacketQueue()
Virtual destructor.
Definition: packet_queue.h:61
virtual void enqueuePacket(PacketTypePtr packet, const SocketInfo &source)=0
Adds a packet to the queue.
PacketQueue(const std::string &queue_type)
Constructor.
Definition: packet_queue.h:57
virtual void clear()=0
Discards all packets currently in the buffer.
Invalid queue parameter exception.
Definition: packet_queue.h:25
virtual data::ElementPtr getInfo() const
Fetches operational information about the current state of the queue.
Definition: packet_queue.h:100
virtual PacketTypePtr dequeuePacket()=0
Dequeues the next packet from the queue.
Holds information about socket.
Definition: socket_info.h:19