Kea 3.1.1
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
47struct StateIndexTag { };
48
61typedef boost::multi_index_container<
62 // It holds pointers to Lease6 objects.
64 boost::multi_index::indexed_by<
65 // Specification of the first index starts here.
66 // This index sorts PingContexts by IPv4 addresses represented as
67 // IOAddress objects.
69 boost::multi_index::ordered_unique<
70 boost::multi_index::tag<AddressIndexTag>,
71 boost::multi_index::const_mem_fun<PingContext, const isc::asiolink::IOAddress&,
73 >,
74
75 // Specification of the second index starts here.
76 // This index sorts contexts by query.
77 boost::multi_index::ordered_unique<
78 boost::multi_index::tag<QueryIndexTag>,
79 boost::multi_index::const_mem_fun<PingContext, isc::dhcp::Pkt4Ptr,
81 >,
82
83 // Specification of the third index starts here.
84 // This index sorts contexts by send_wait_start.
85 boost::multi_index::ordered_non_unique<
86 boost::multi_index::tag<NextToSendIndexTag>,
87 boost::multi_index::composite_key<
89 // The boolean value specifying if context is waiting to send
90 boost::multi_index::const_mem_fun<PingContext, bool,
92 // Context expiration time.
93 boost::multi_index::const_mem_fun<PingContext, const TimeStamp&,
95 >
96 >,
97
98 // Specification of the fourth index starts here.
99 // This index sorts contexts by next_expiry.
100 boost::multi_index::ordered_non_unique<
101 boost::multi_index::tag<ExpirationIndexTag>,
102 boost::multi_index::composite_key<
104 // The boolean value specifying if context is waiting for a reply
105 boost::multi_index::const_mem_fun<PingContext, bool,
107 // Context expiration time.
108 boost::multi_index::const_mem_fun<PingContext, const TimeStamp&,
110 >
111 >,
112
113 // Specification of the fifth index starts here.
114 // This index sorts contexts by State.
115 boost::multi_index::ordered_non_unique<
116 boost::multi_index::tag<StateIndexTag>,
117 boost::multi_index::const_mem_fun<PingContext, PingContext::State,
119 >
120 >
122
124typedef std::vector<PingContextPtr> PingContextCollection;
126typedef boost::shared_ptr<PingContextCollection> PingContextCollectionPtr;
127
137public:
138
140 PingContextStore() : pings_(), mutex_(new std::mutex) {
141 }
142
144 ~PingContextStore() = default;
145
162 isc::dhcp::Pkt4Ptr& query,
163 uint32_t min_echos,
164 uint32_t reply_timeout,
167
175 void updateContext(const PingContextPtr& context);
176
182 void deleteContext(const PingContextPtr& context);
183
191
199
206
213
220
225
227 void clear();
228
229private:
232
234 const boost::scoped_ptr<std::mutex> mutex_;
235};
236
237} // end of namespace ping_check
238} // end of namespace isc
239
240#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)
State getState() const
Fetches the current state.
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)
State
Defines PingContext life cycle states.
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::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::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 > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< StateIndexTag >, boost::multi_index::const_mem_fun< PingContext, PingContext::State, &PingContext::getState > > > > PingContextContainer
A multi index container holding pointers to PingContexts.
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.