Kea 1.5.0
packet_queue.h
Go to the documentation of this file.
1// Copyright (C) 2018 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#include <util/threads/sync.h>
15
16#include <boost/function.hpp>
17#include <boost/circular_buffer.hpp>
18#include <sstream>
19
20namespace isc {
21
22namespace dhcp {
23
28public:
29 InvalidQueueParameter(const char* file, size_t line, const char* what) :
30 isc::Exception(file, line, what) {}
31};
32
34enum class QueueEnd {
35 FRONT, // Typically the end packets are read from
36 BACK // Typically the end packets are written to
37};
38
49template<typename PacketTypePtr>
51public:
52
59 explicit PacketQueue(const std::string& queue_type)
60 : queue_type_(queue_type) {}
61
63 virtual ~PacketQueue(){};
64
72 virtual void enqueuePacket(PacketTypePtr packet, const SocketInfo& source) = 0;
73
81 virtual PacketTypePtr dequeuePacket() = 0;
82
84 virtual bool empty() const = 0;
85
87 virtual size_t getSize() const = 0;
88
90 virtual void clear() = 0;
91
102 virtual data::ElementPtr getInfo() const {
104 info->set("queue-type", data::Element::create(queue_type_));
105 return(info);
106 }
107
113 std::string getInfoStr() const {
114 data::ElementPtr info = getInfo();
115 std::ostringstream os;
116 info->toJSON(os);
117 return (os.str());
118 }
119
121 std::string getQueueType() {
122 return (queue_type_);
123 };
124
125private:
127 std::string queue_type_;
128
129};
130
134typedef boost::shared_ptr<PacketQueue<Pkt4Ptr>> PacketQueue4Ptr;
135
139typedef boost::shared_ptr<PacketQueue<Pkt6Ptr>> PacketQueue6Ptr;
140
141}; // namespace isc::dhcp
142}; // namespace isc
143
144#endif // PACKET_QUEUE_H
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition: data.cc:223
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:268
Invalid queue parameter exception.
Definition: packet_queue.h:27
InvalidQueueParameter(const char *file, size_t line, const char *what)
Definition: packet_queue.h:29
Interface for managing a queue of inbound DHCP packets.
Definition: packet_queue.h:50
virtual data::ElementPtr getInfo() const
Fetches operational information about the current state of the queue.
Definition: packet_queue.h:102
std::string getQueueType()
Definition: packet_queue.h:121
virtual size_t getSize() const =0
Returns the current number of packets 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 clear()=0
Discards all packets currently in the buffer.
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:59
virtual ~PacketQueue()
Virtual destructor.
Definition: packet_queue.h:63
std::string getInfoStr() const
Fetches a JSON string representation of queue operational info.
Definition: packet_queue.h:113
boost::shared_ptr< Element > ElementPtr
Definition: data.h:22
boost::shared_ptr< PacketQueue< Pkt4Ptr > > PacketQueue4Ptr
Defines pointer to the DHCPv4 queue interface used at the application level.
Definition: packet_queue.h:134
boost::shared_ptr< PacketQueue< Pkt6Ptr > > PacketQueue6Ptr
Defines pointer to the DHCPv6 queue interface used at the application level.
Definition: packet_queue.h:139
QueueEnd
Enumerates choices between the two ends of the queue.
Definition: packet_queue.h:34
Defines the logger used by the top-level component of kea-dhcp-ddns.
Holds information about socket.
Definition: socket_info.h:19