Kea 2.7.5
packet_queue.h
Go to the documentation of this file.
1// Copyright (C) 2018-2024 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 <sstream>
16
17namespace isc {
18
19namespace dhcp {
20
25public:
26 InvalidQueueParameter(const char* file, size_t line, const char* what) :
27 isc::Exception(file, line, what) {}
28};
29
31enum class QueueEnd {
32 FRONT, // Typically the end packets are read from
33 BACK // Typically the end packets are written to
34};
35
46template<typename PacketTypePtr>
48public:
49
56 explicit PacketQueue(const std::string& queue_type)
57 : queue_type_(queue_type) {}
58
60 virtual ~PacketQueue(){}
61
69 virtual void enqueuePacket(PacketTypePtr packet, const SocketInfo& source) = 0;
70
78 virtual PacketTypePtr dequeuePacket() = 0;
79
81 virtual bool empty() const = 0;
82
84 virtual size_t getSize() const = 0;
85
87 virtual void clear() = 0;
88
99 virtual data::ElementPtr getInfo() const {
101 info->set("queue-type", data::Element::create(queue_type_));
102 return (info);
103 }
104
110 std::string getInfoStr() const {
112 std::ostringstream os;
113 info->toJSON(os);
114 return (os.str());
115 }
116
118 std::string getQueueType() {
119 return (queue_type_);
120 }
121
122private:
124 std::string queue_type_;
125
126};
127
131typedef boost::shared_ptr<PacketQueue<Pkt4Ptr>> PacketQueue4Ptr;
132
136typedef boost::shared_ptr<PacketQueue<Pkt6Ptr>> PacketQueue6Ptr;
137
138} // namespace dhcp
139} // namespace isc
140
141#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:249
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:304
Invalid queue parameter exception.
InvalidQueueParameter(const char *file, size_t line, const char *what)
Interface for managing a queue of inbound DHCP packets.
virtual data::ElementPtr getInfo() const
Fetches operational information about the current state of the queue.
std::string getQueueType()
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.
virtual ~PacketQueue()
Virtual destructor.
std::string getInfoStr() const
Fetches a JSON string representation of queue operational info.
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
@ info
Definition db_log.h:120
boost::shared_ptr< PacketQueue< Pkt4Ptr > > PacketQueue4Ptr
Defines pointer to the DHCPv4 queue interface used at the application level.
boost::shared_ptr< PacketQueue< Pkt6Ptr > > PacketQueue6Ptr
Defines pointer to the DHCPv6 queue interface used at the application level.
QueueEnd
Enumerates choices between the two ends of the queue.
Defines the logger used by the top-level component of kea-lfc.
Holds information about socket.
Definition socket_info.h:19