Kea 3.3.4
d2_queue_mgr.h
Go to the documentation of this file.
1// Copyright (C) 2013-2026 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 D2_QUEUE_MGR_H
8#define D2_QUEUE_MGR_H
9
11
12#include <asiolink/io_service.h>
13#include <d2srv/d2_cfg_mgr.h>
14#include <dhcp_ddns/ncr_io.h>
15#include <dhcp_ddns/ncr_msg.h>
17
18#include <boost/multi_index_container.hpp>
19#include <boost/multi_index/ordered_index.hpp>
20#include <boost/multi_index/indexed_by.hpp>
21#include <boost/multi_index/member.hpp>
22#include <boost/multi_index/mem_fun.hpp>
23#include <boost/multi_index/random_access_index.hpp>
24#include <boost/noncopyable.hpp>
25#include <boost/shared_ptr.hpp>
26
27#include <cstdint>
28
29namespace isc {
30namespace d2 {
31
43public:
53 const DdnsDomainPtr& forward_domain,
54 const DdnsDomainPtr& reverse_domain);
55
60 return (ncr_);
61 }
62
67 return (ncr_->getDhcid());
68 }
69
74 return (forward_domain_);
75 }
76
81 return (reverse_domain_);
82 }
83
85 void refresh(const MatchedNcr& source);
86
87private:
90
92 DdnsDomainPtr forward_domain_;
93
95 DdnsDomainPtr reverse_domain_;
96};
97
99typedef boost::shared_ptr<MatchedNcr> MatchedNcrPtr;
100
102struct VectorTag { };
103
105struct DhcidTag { };
106
111typedef boost::multi_index_container<
112 // It holds pointers to MatchedNcrs.
114 boost::multi_index::indexed_by<
115 // Index by insertion order
116 boost::multi_index::random_access<
117 boost::multi_index::tag<VectorTag>
118 >,
119
120 // Index by DHCID
121 boost::multi_index::ordered_non_unique<
122 boost::multi_index::tag<DhcidTag>,
123 boost::multi_index::const_mem_fun<MatchedNcr,
124 const dhcp_ddns::D2Dhcid&,
126 >
127 >
129
132public:
133 D2QueueMgrError(const char* file, size_t line, const char* what) :
134 isc::Exception(file, line, what) { }
135};
136
141public:
142 D2QueueMgrReceiveError(const char* file, size_t line, const char* what) :
143 isc::Exception(file, line, what) { }
144};
145
149public:
150 D2QueueMgrQueueFull(const char* file, size_t line, const char* what) :
151 isc::Exception(file, line, what) { }
152};
153
156public:
157 D2QueueMgrQueueEmpty(const char* file, size_t line, const char* what) :
158 isc::Exception(file, line, what) { }
159};
160
163public:
164 D2QueueMgrInvalidIndex(const char* file, size_t line, const char* what) :
165 isc::Exception(file, line, what) { }
166};
167
233 boost::noncopyable {
234public:
238 static const size_t MAX_QUEUE_DEFAULT = 1024;
239
250
256 static std::string const& stateToText(State const& state) {
257 static std::vector<std::string> const text_vector {
258 "NOT_INITTED",
259 "INITTED",
260 "RUNNING",
261 "STOPPING",
262 "STOPPED_QUEUE_FULL",
263 "STOPPED_RECV_ERROR",
264 "STOPPED",
265 };
266 static std::string const unknown("UNKNOWN");
267 return (state < text_vector.size() ? text_vector[state] : unknown);
268 }
269
284 D2QueueMgr(asiolink::IOServicePtr& io_service, D2CfgMgrPtr& cfg_mgr,
285 const size_t max_queue_size = MAX_QUEUE_DEFAULT);
286
288 virtual ~D2QueueMgr();
289
301 void initUDPListener(const isc::asiolink::IOAddress& ip_address,
302 const uint32_t port,
303 const dhcp_ddns::NameChangeFormat format,
304 const bool reuse_address = false);
305
313 void startListening();
314
343 virtual void operator()(const dhcp_ddns::NameChangeListener::Result result,
345
358 void stopListening(const State target_stop_state = STOPPED);
359
367 void removeListener();
368
370 size_t getQueueSize() const {
371 return (ncr_queue_.size());
372 };
373
375 size_t getMaxQueueSize() const {
376 return (max_queue_size_);
377 }
378
386 void setMaxQueueSize(const size_t max_queue_size);
387
390 return (mgr_state_);
391 }
392
402 const MatchedNcrPtr& peek() const;
403
414 const MatchedNcrPtr& peekAt(const size_t index) const;
415
423 void dequeueAt(const size_t index);
424
428 void dequeue();
429
434 const MatchedNcrPtr
435 findLast(const dhcp_ddns::D2Dhcid& dhcid) const;
436
450 bool suppress_duplicates = false);
451
462
465
467 void clearQueue();
468
469 private:
474 void updateStopState();
475
477 asiolink::IOServicePtr io_service_;
478
480 D2CfgMgrPtr cfg_mgr_;
481
483 size_t max_queue_size_;
484
486 NcrQueue ncr_queue_;
487
489 boost::shared_ptr<dhcp_ddns::NameChangeListener> listener_;
490
492 State mgr_state_;
493
495 State target_stop_state_;
496};
497
499typedef boost::shared_ptr<D2QueueMgr> D2QueueMgrPtr;
500
501} // namespace isc::d2
502} // namespace isc
503
504#endif
This is a base class for exceptions thrown from the DNS library module.
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
D2QueueMgrError(const char *file, size_t line, const char *what)
D2QueueMgrInvalidIndex(const char *file, size_t line, const char *what)
D2QueueMgrQueueEmpty(const char *file, size_t line, const char *what)
D2QueueMgrQueueFull(const char *file, size_t line, const char *what)
D2QueueMgrReceiveError(const char *file, size_t line, const char *what)
bool enqueue(dhcp_ddns::NameChangeRequestPtr &ncr, bool suppress_duplicates=false)
Adds a request to the end of the queue.
const MatchedNcrPtr findLast(const dhcp_ddns::D2Dhcid &dhcid) const
Fetches the last entry in the queue for a given DHCID.
State
Defines the list of possible states for D2QueueMgr.
virtual ~D2QueueMgr()
Destructor.
size_t getMaxQueueSize() const
Returns the maximum number of entries allowed in the queue.
MatchedNcrPtr matchNcr(dhcp_ddns::NameChangeRequestPtr ncr) const
Creates an NCR matched to forward and reverse domains.
State getMgrState() const
Returns the current state.
static const size_t MAX_QUEUE_DEFAULT
Maximum number of entries allowed in the request queue.
void dequeue()
Removes the entry at the front of the queue.
static std::string const & stateToText(State const &state)
Convert enum to string.
void removeListener()
Deletes the current listener.
void startListening()
Starts actively listening for requests.
void setMaxQueueSize(const size_t max_queue_size)
Sets the maximum number of entries allowed in the queue.
size_t getQueueSize() const
Returns the number of entries in the queue.
const MatchedNcrPtr & peek() const
Returns the entry at the front of the queue.
D2QueueMgr(asiolink::IOServicePtr &io_service, D2CfgMgrPtr &cfg_mgr, const size_t max_queue_size=MAX_QUEUE_DEFAULT)
Constructor.
virtual void operator()(const dhcp_ddns::NameChangeListener::Result result, dhcp_ddns::NameChangeRequestPtr &ncr)
Function operator implementing the NCR receive callback.
void clearQueue()
Removes all entries from the queue.
void initUDPListener(const isc::asiolink::IOAddress &ip_address, const uint32_t port, const dhcp_ddns::NameChangeFormat format, const bool reuse_address=false)
Initializes the listener as a UDP listener.
void dequeueAt(const size_t index)
Removes the entry at a given position in the queue.
void stopListening(const State target_stop_state=STOPPED)
Stops listening for requests.
const MatchedNcrPtr & peekAt(const size_t index) const
Returns the entry at a given position in the queue.
void refreshQueuedMatching()
Iterate over queue contents and redo the matching.
Wrapper for NameChangeRequest has been matched to forward and reverse domains.
void refresh(const MatchedNcr &source)
Update the domains from the given MatchedNcr.
DdnsDomainPtr getReverseDomain() const
Fetches the reverse domain matched to the ip Address.
dhcp_ddns::NameChangeRequestPtr getNcr() const
Fetches the NameChangeRequest.
const dhcp_ddns::D2Dhcid & getDhcid() const
Fetches the DHCID from the NCR.
DdnsDomainPtr getForwardDomain() const
Fetches the forward domain matched to the FQDN.
MatchedNcr(const dhcp_ddns::NameChangeRequestPtr &ncr, const DdnsDomainPtr &forward_domain, const DdnsDomainPtr &reverse_domain)
Constructor.
Container class for handling the DHCID value within a NameChangeRequest.
Definition ncr_msg.h:117
Abstract class for defining application layer receive callbacks.
Definition ncr_io.h:184
Result
Defines the outcome of an asynchronous NCR receive.
Definition ncr_io.h:172
Defines a State within the State Model.
Definition state_model.h:64
boost::shared_ptr< DdnsDomain > DdnsDomainPtr
Defines a pointer for DdnsDomain instances.
Definition d2_config.h:624
boost::shared_ptr< D2CfgMgr > D2CfgMgrPtr
Defines a shared pointer to D2CfgMgr.
Definition d2_cfg_mgr.h:389
boost::shared_ptr< MatchedNcr > MatchedNcrPtr
Shared pointer to a MatchedNcr.
boost::shared_ptr< D2QueueMgr > D2QueueMgrPtr
Defines a pointer for manager instances.
boost::multi_index_container< MatchedNcrPtr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< VectorTag > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< DhcidTag >, boost::multi_index::const_mem_fun< MatchedNcr, const dhcp_ddns::D2Dhcid &, &MatchedNcr::getDhcid > > > > NcrQueue
A multi index container holding MatchedNcr pointers.
NameChangeFormat
Defines the list of data wire formats supported.
Definition ncr_msg.h:63
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition ncr_msg.h:245
Defines the logger used by the top-level component of kea-lfc.
This file defines abstract classes for exchanging NameChangeRequests.
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...
Tag for index by DHCID.
Tag for insertion order index.