20using namespace std::chrono;
27 uint32_t reply_timeout ,
29 : min_echos_(min_echos),
30 reply_timeout_(reply_timeout),
39 parking_lot_(parking_lot) {
52 if (min_echos_ == 0) {
56 if (reply_timeout_ == 0) {
63 if (state_str ==
"NEW") {
67 if (state_str ==
"WAITING_TO_SEND") {
71 if (state_str ==
"SENDING") {
75 if (state_str ==
"WAITING_FOR_REPLY") {
79 if (state_str ==
"TARGET_FREE") {
83 if (state_str ==
"TARGET_IN_USE") {
92 return (time_point_cast<milliseconds>(std::chrono::system_clock::now()));
97 std::string label =
"";
103 label =
"WAITING_TO_SEND";
109 label =
"WAITING_FOR_REPLY";
112 label =
"TARGET_FREE";
115 label =
"TARGET_IN_USE";
123 return (lease_->addr_);
138 return (reply_timeout_);
143 reply_timeout_ = value;
148 return (echos_sent_);
158 return (last_echo_sent_time_);
163 last_echo_sent_time_ = value;
168 return (send_wait_start_);
178 send_wait_start_ = value;
183 return (next_expiry_);
193 next_expiry_ = value;
198 return (created_time_);
224 send_wait_start_ = begin_time;
230 last_echo_sent_time_ = begin_time;
231 next_expiry_ = begin_time + milliseconds(reply_timeout_);
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
The IOAddress class represents an IP addresses (version agnostic)
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
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.
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)
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.
State
Defines PingContext life cycle states.
const TimeStamp & getSendWaitStart() const
Fetches the time the context went into WAITING_TO_SEND state.
static std::string stateToString(const State &state)
Converts a State to a string.
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.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
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.
Defines the logger used by the top-level component of kea-lfc.