Kea 3.3.3
ping_context.h
Go to the documentation of this file.
1// Copyright (C) 2023-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 PING_CONTEXT_H
8#define PING_CONTEXT_H
9
10#include <dhcp/pkt4.h>
11#include <dhcpsrv/lease.h>
12#include <hooks/parking_lots.h>
13
14#include <chrono>
15#include <cstdint>
16
17namespace isc {
18namespace ping_check {
19
21using TimeStamp = std::chrono::time_point<std::chrono::system_clock>;
22
33public:
34
36 enum State : uint16_t {
37 NEW, // Newly created
38 WAITING_TO_SEND, // Waiting to send next ECHO REQUEST
39 SENDING, // Next ECHO REQUEST is being sent
40 WAITING_FOR_REPLY, // ECHO REQUEST sent, Waiting for reply or timeout
41 TARGET_FREE, // Target has been deemed free to offer.
42 TARGET_IN_USE // Target has been deemed in-use, do not offer
43 };
44
51 static State stringToState(const std::string& state_str);
52
57 static std::string stateToString(const State& state);
58
75 uint32_t min_echos = 1, uint32_t reply_timeout = 100,
77
79 virtual ~PingContext() = default;
80
84 static TimeStamp now();
85
89 static const TimeStamp& EMPTY_TIME() {
90 static TimeStamp empty_time;
91 return (empty_time);
92 }
93
97 static const TimeStamp& MIN_TIME() {
98 static TimeStamp min_time = std::chrono::system_clock::time_point::min();
99 return (min_time);
100 }
101
106 static hooks::ParkingLotHandlePtr empty_lot(0);
107 return (empty_lot);
108 }
109
113 const isc::asiolink::IOAddress& getTarget() const;
114
118 uint32_t getMinEchos() const;
119
125 void setMinEchos(uint32_t value);
126
130 uint32_t getReplyTimeout() const;
131
137 void setReplyTimeout(uint32_t value);
138
142 uint32_t getEchosSent() const;
143
147 void setEchosSent(uint32_t value);
148
153 const TimeStamp& getLastEchoSentTime() const;
154
158 void setLastEchoSentTime(const TimeStamp& value);
159
165 const TimeStamp& getSendWaitStart() const;
166
170 void setSendWaitStart(const TimeStamp& value);
171
175 bool isWaitingToSend() const;
176
182 const TimeStamp& getNextExpiry() const;
183
186 void setNextExpiry(const TimeStamp& value);
187
191 bool isWaitingForReply() const;
192
196 const TimeStamp& getCreatedTime() const;
197
201 State getState() const;
202
206 void setState(const State& value);
207
212
217
222 void beginWaitingToSend(const TimeStamp& begin_time = PingContext::now());
223
228 void beginWaitingForReply(const TimeStamp& begin_time = PingContext::now());
229
235 return (parking_lot_);
236 };
237
238private:
241 uint32_t min_echos_ = 0;
242
244 uint32_t reply_timeout_ = 0;
245
247 uint32_t echos_sent_ = 0;
248
250 TimeStamp last_echo_sent_time_;
251
253 TimeStamp send_wait_start_;
254
256 TimeStamp next_expiry_;
257
259 TimeStamp created_time_;
260
263
265 isc::dhcp::Pkt4Ptr query_;
266
268 State state_;
269
273};
274
276typedef boost::shared_ptr<PingContext> PingContextPtr;
277
278} // end of namespace ping_check
279} // end of namespace isc
280
281#endif
const TimeStamp & getNextExpiry() const
Fetches the time at which the WAITING_FOR_REPLY state expires(ed).
const TimeStamp & getLastEchoSentTime() const
Fetches the timestamp of when the most recent ECHO REQUEST was sent.
State getState() const
Fetches the current state.
void setEchosSent(uint32_t value)
Sets the number of ECHO REQUESTs sent.
void setMinEchos(uint32_t value)
Sets the minimum number of ECHO REQUESTs.
isc::dhcp::Lease4Ptr getLease() const
Returns the candidate lease whose address is the target to check.
void setState(const State &value)
Sets the state.
bool isWaitingForReply() const
Returns true if state is WAITING_FOR_REPLY.
static const TimeStamp & MIN_TIME()
Fetches the minimum timestamp.
uint32_t getReplyTimeout() const
Fetches the reply timeout (milliseconds).
uint32_t getMinEchos() const
Fetches the minimum number of ECHO REQUESTs.
void setSendWaitStart(const TimeStamp &value)
Sets the send wait start timestamp.
isc::dhcp::Pkt4Ptr getQuery() const
Returns the query that instigated this check.
const TimeStamp & getCreatedTime() const
Fetches the time at which the context was created.
void beginWaitingToSend(const TimeStamp &begin_time=PingContext::now())
Enters WAITING_TO_SEND state.
bool isWaitingToSend() const
Returns true if state is WAITING_TO_SEND.
static const TimeStamp & EMPTY_TIME()
Fetches an empty timestamp.
PingContext(isc::dhcp::Lease4Ptr &lease, isc::dhcp::Pkt4Ptr &query, uint32_t min_echos=1, uint32_t reply_timeout=100, isc::hooks::ParkingLotHandlePtr &parking_lot=EMPTY_LOT())
Constructor.
static TimeStamp now()
Fetches the current timestamp (UTC/milliseconds precision).
isc::hooks::ParkingLotHandlePtr getParkingLot()
Fetches the parking lot used for this context.
void setNextExpiry(const TimeStamp &value)
Sets the timestamp which specifies the time at which the WAITING_FOR_REPLY state expires.
uint32_t getEchosSent() const
Fetches the number of ECHO REQUESTs sent.
const TimeStamp & getSendWaitStart() const
Fetches the time the context went into WAITING_TO_SEND state.
virtual ~PingContext()=default
Destructor.
State
Defines PingContext life cycle states.
static std::string stateToString(const State &state)
Converts a State to a string.
static hooks::ParkingLotHandlePtr & EMPTY_LOT()
Fetches an empty parking lot handle.
void setLastEchoSentTime(const TimeStamp &value)
Sets the timestamp the most recent ECHO REQUEST was sent.
void beginWaitingForReply(const TimeStamp &begin_time=PingContext::now())
Enters WAITING_TO_REPLY state.
const isc::asiolink::IOAddress & getTarget() const
Fetches the IP address that is under test.
void setReplyTimeout(uint32_t value)
Sets the reply timeout.
static State stringToState(const std::string &state_str)
Converts a string to State.
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:343
boost::shared_ptr< ParkingLotHandle > ParkingLotHandlePtr
Pointer to the parking lot handle.
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.