Kea 3.1.3
ping_context_store.h
Go to the documentation of this file.
1// Copyright (C) 2023-2025 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 PING_CONTEXT_STORE_H
8#define PING_CONTEXT_STORE_H
9
10#include <asiolink/io_address.h>
11#include <ping_context.h>
12
13#include <boost/multi_index/indexed_by.hpp>
14#include <boost/multi_index/member.hpp>
15#include <boost/multi_index/mem_fun.hpp>
16#include <boost/multi_index/ordered_index.hpp>
17#include <boost/multi_index_container.hpp>
18#include <boost/multi_index/composite_key.hpp>
19#include <boost/scoped_ptr.hpp>
20
21#include <mutex>
22#include <vector>
23
24namespace isc {
25namespace ping_check {
26
29public:
30 DuplicateContext(const char* file, size_t line, const char* what) :
31 isc::Exception(file, line, what) {}
32};
33
35struct AddressIndexTag { };
36
38struct QueryIndexTag { };
39
42
45
58typedef boost::multi_index_container<
59 // It holds pointers to Lease6 objects.
61 boost::multi_index::indexed_by<
62 // Specification of the first index starts here.
63 // This index sorts PingContexts by IPv4 addresses represented as
64 // IOAddress objects.
66 boost::multi_index::ordered_unique<
67 boost::multi_index::tag<AddressIndexTag>,
68 boost::multi_index::const_mem_fun<PingContext, const isc::asiolink::IOAddress&,
70 >,
71
72 // Specification of the second index starts here.
73 // This index sorts contexts by query.
74 boost::multi_index::ordered_unique<
75 boost::multi_index::tag<QueryIndexTag>,
76 boost::multi_index::const_mem_fun<PingContext, isc::dhcp::Pkt4Ptr,
78 >,
79
80 // Specification of the third index starts here.
81 // This index sorts contexts by send_wait_start.
82 boost::multi_index::ordered_non_unique<
83 boost::multi_index::tag<NextToSendIndexTag>,
84 boost::multi_index::composite_key<
86 // The boolean value specifying if context is waiting to send
87 boost::multi_index::const_mem_fun<PingContext, bool,
89 // Context expiration time.
90 boost::multi_index::const_mem_fun<PingContext, const TimeStamp&,
92 >
93 >,
94
95 // Specification of the fourth index starts here.
96 // This index sorts contexts by next_expiry.
97 boost::multi_index::ordered_non_unique<
98 boost::multi_index::tag<ExpirationIndexTag>,
99 boost::multi_index::composite_key<
101 // The boolean value specifying if context is waiting for a reply
102 boost::multi_index::const_mem_fun<PingContext, bool,
104 // Context expiration time.
105 boost::multi_index::const_mem_fun<PingContext, const TimeStamp&,
107 >
108 >
109 >
111
113typedef std::vector<PingContextPtr> PingContextCollection;
115typedef boost::shared_ptr<PingContextCollection> PingContextCollectionPtr;
116
126public:
127
129 PingContextStore() : pings_(), mutex_(new std::mutex) {
130 }
131
133 ~PingContextStore() = default;
134
151 isc::dhcp::Pkt4Ptr& query,
152 uint32_t min_echos,
153 uint32_t reply_timeout,
156
164 void updateContext(const PingContextPtr& context);
165
171 void deleteContext(const PingContextPtr& context);
172
180
188
195
202
209
214
216 void clear();
217
218private:
221
223 const boost::scoped_ptr<std::mutex> mutex_;
224};
225
226} // end of namespace ping_check
227} // end of namespace isc
228
229#endif
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.
DuplicateContext(const char *file, size_t line, const char *what)
void clear()
Removes all contexts from the store.
PingContextPtr getContextByQuery(isc::dhcp::Pkt4Ptr &query)
Fetches the context with a given query packet.
PingContextPtr getContextByAddress(const isc::asiolink::IOAddress &address)
Fetches the context with a given target address.
PingContextPtr addContext(isc::dhcp::Lease4Ptr &lease, isc::dhcp::Pkt4Ptr &query, uint32_t min_echos, uint32_t reply_timeout, isc::hooks::ParkingLotHandlePtr &parking_lot=PingContext::EMPTY_LOT())
Creates a new PingContext and adds it to the store.
PingContextCollectionPtr getAll()
Fetches all of the contexts (in order by target)
~PingContextStore()=default
Destructor.
PingContextCollectionPtr getExpiredSince(const TimeStamp &since=PingContext::now())
Fetches the contexts in WAITING_FOR_REPLY that expired since a given time.
void deleteContext(const PingContextPtr &context)
Removes the context from the store.
PingContextPtr getNextToSend()
Fetches the context in WAITING_TO_SEND with the oldest send wait start time.
PingContextPtr getExpiresNext()
Fetches the context in WAITING_FOR_REPLY with the oldest expiration time that has not already passed ...
void updateContext(const PingContextPtr &context)
Updates a context in the store.
Embodies the life cycle of a ping check test for a single address for a single DHCPDISCOVER.
const TimeStamp & getNextExpiry() const
Fetches the time at which the WAITING_FOR_REPLY state expires(ed)
bool isWaitingForReply() const
Returns true if state is WAITING_FOR_REPLY.
isc::dhcp::Pkt4Ptr getQuery() const
Returns the query that instigated this check.
bool isWaitingToSend() const
Returns true if state is WAITING_TO_SEND.
static TimeStamp now()
Fetches the current timestamp (UTC/milliseconds precision)
const TimeStamp & getSendWaitStart() const
Fetches the time the context went into WAITING_TO_SEND state.
static hooks::ParkingLotHandlePtr & EMPTY_LOT()
Fetches an empty parking lot handle.
const isc::asiolink::IOAddress & getTarget() const
Fetches the IP address that is under test.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition pkt4.h:556
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition lease.h:315
boost::shared_ptr< ParkingLotHandle > ParkingLotHandlePtr
Pointer to the parking lot handle.
boost::multi_index_container< PingContextPtr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< AddressIndexTag >, boost::multi_index::const_mem_fun< PingContext, const isc::asiolink::IOAddress &, &PingContext::getTarget > >, boost::multi_index::ordered_unique< boost::multi_index::tag< QueryIndexTag >, boost::multi_index::const_mem_fun< PingContext, isc::dhcp::Pkt4Ptr, &PingContext::getQuery > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< NextToSendIndexTag >, boost::multi_index::composite_key< PingContext, boost::multi_index::const_mem_fun< PingContext, bool, &PingContext::isWaitingToSend >, boost::multi_index::const_mem_fun< PingContext, const TimeStamp &, &PingContext::getSendWaitStart > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ExpirationIndexTag >, boost::multi_index::composite_key< PingContext, boost::multi_index::const_mem_fun< PingContext, bool, &PingContext::isWaitingForReply >, boost::multi_index::const_mem_fun< PingContext, const TimeStamp &, &PingContext::getNextExpiry > > > > > PingContextContainer
A multi index container holding pointers to PingContexts.
boost::shared_ptr< PingContextCollection > PingContextCollectionPtr
Type for a pointer to a collection of PingContextPtrs.
std::vector< PingContextPtr > PingContextCollection
Type for a collection of PingContextPtrs.
std::chrono::time_point< std::chrono::system_clock > TimeStamp
Specifies the type for time stamps.
boost::shared_ptr< PingContext > PingContextPtr
Defines a shared pointer to a PingContext.
Defines the logger used by the top-level component of kea-lfc.
Tag for index by target address.
Tag for index by expiration time.
Tag for index by send wait start time.
Tag for index by the query packet.