Kea 3.1.1
isc::ping_check::PingContext Class Reference

Embodies the life cycle of a ping check test for a single address for a single DHCPDISCOVER. More...

#include <ping_context.h>

Public Types

enum  State {
  NEW , WAITING_TO_SEND , SENDING , WAITING_FOR_REPLY ,
  TARGET_FREE , TARGET_IN_USE
}
 Defines PingContext life cycle states. More...
 

Public Member Functions

 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.
 
virtual ~PingContext ()=default
 Destructor.
 
void beginWaitingForReply (const TimeStamp &begin_time=PingContext::now())
 Enters WAITING_TO_REPLY state.
 
void beginWaitingToSend (const TimeStamp &begin_time=PingContext::now())
 Enters WAITING_TO_SEND state.
 
const TimeStampgetCreatedTime () const
 Fetches the time at which the context was created.
 
uint32_t getEchosSent () const
 Fetches the number of ECHO REQUESTs sent.
 
const TimeStampgetLastEchoSentTime () const
 Fetches the timestamp of when the most recent ECHO REQUEST was sent.
 
isc::dhcp::Lease4Ptr getLease () const
 Returns the candidate lease whose address is the target to check.
 
uint32_t getMinEchos () const
 Fetches the minimum number of ECHO REQUESTs.
 
const TimeStampgetNextExpiry () const
 Fetches the time at which the WAITING_FOR_REPLY state expires(ed)
 
isc::hooks::ParkingLotHandlePtr getParkingLot ()
 Fetches the parking lot used for this context.
 
isc::dhcp::Pkt4Ptr getQuery () const
 Returns the query that instigated this check.
 
uint32_t getReplyTimeout () const
 Fetches the reply timeout (milliseconds)
 
const TimeStampgetSendWaitStart () const
 Fetches the time the context went into WAITING_TO_SEND state.
 
State getState () const
 Fetches the current state.
 
const isc::asiolink::IOAddressgetTarget () const
 Fetches the IP address that is under test.
 
bool isWaitingForReply () const
 Returns true if state is WAITING_FOR_REPLY.
 
bool isWaitingToSend () const
 Returns true if state is WAITING_TO_SEND.
 
void setEchosSent (uint32_t value)
 Sets the number of ECHO REQUESTs sent.
 
void setLastEchoSentTime (const TimeStamp &value)
 Sets the timestamp the most recent ECHO REQUEST was sent.
 
void setMinEchos (uint32_t value)
 Sets the minimum number of ECHO REQUESTs.
 
void setNextExpiry (const TimeStamp &value)
 Sets the timestamp which specifies the time at which the WAITING_FOR_REPLY state expires.
 
void setReplyTimeout (uint32_t value)
 Sets the reply timeout.
 
void setSendWaitStart (const TimeStamp &value)
 Sets the send wait start timestamp.
 
void setState (const State &value)
 Sets the state.
 

Static Public Member Functions

static hooks::ParkingLotHandlePtrEMPTY_LOT ()
 Fetches an empty parking lot handle.
 
static const TimeStampEMPTY_TIME ()
 Fetches an empty timestamp.
 
static const TimeStampMIN_TIME ()
 Fetches the minimum timestamp.
 
static TimeStamp now ()
 Fetches the current timestamp (UTC/milliseconds precision)
 
static std::string stateToString (const State &state)
 Converts a State to a string.
 
static State stringToState (const std::string &state_str)
 Converts a string to State.
 

Detailed Description

Embodies the life cycle of a ping check test for a single address for a single DHCPDISCOVER.

The class uses a state-model to direct the tasks needed to execute one or more ECHO REQUEST SEND/WAIT FOR REPLY cycles until the address is either deemed free to offer or in-use and should not be offered. The number of cycles conducted is dictated by the minimum number of echos (min_echos_) and whether or not either an ECHO REPLY or DESTINATION UNREACHABLE are received.

Definition at line 31 of file ping_context.h.

Member Enumeration Documentation

◆ State

Defines PingContext life cycle states.

Enumerator
NEW 
WAITING_TO_SEND 
SENDING 
WAITING_FOR_REPLY 
TARGET_FREE 
TARGET_IN_USE 

Definition at line 35 of file ping_context.h.

Constructor & Destructor Documentation

◆ PingContext()

isc::ping_check::PingContext::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.

Parameters
leasepointer to the lease whose address needs to be checked
queryDHCPDISCOVER that instigated the check
min_echosminimum number of ECHO REQUESTs sent without replies received required to declare an address free to offer. Defaults to 1, must be greater than zero.
reply_timeoutmaximum number of milliseconds to wait for an ECHO REPLY after an ECHO REQUEST has been sent. Defaults to 100, must be greater than 0.
parking_lotparking lot in which the query is parked. Defaults to an empty pointer.
Exceptions
BadValueif either lease or query are empty, or if the lease address is 0.0.0.0

Definition at line 25 of file ping_context.cc.

References PingContext(), EMPTY_TIME(), getTarget(), isc::asiolink::IOAddress::IPV4_ZERO_ADDRESS(), isc_throw, NEW, and now().

Referenced by PingContext().

+ Here is the call graph for this function:

◆ ~PingContext()

virtual isc::ping_check::PingContext::~PingContext ( )
virtualdefault

Destructor.

Member Function Documentation

◆ beginWaitingForReply()

void isc::ping_check::PingContext::beginWaitingForReply ( const TimeStamp & begin_time = PingContext::now())

Enters WAITING_TO_REPLY state.

Parameters
begin_timetimestamp of when the state began. Defaults to time now. Provided for testing purposes.

Definition at line 228 of file ping_context.cc.

References WAITING_FOR_REPLY.

◆ beginWaitingToSend()

void isc::ping_check::PingContext::beginWaitingToSend ( const TimeStamp & begin_time = PingContext::now())

Enters WAITING_TO_SEND state.

Parameters
begin_timetimestamp of when the state began. Defaults to time now. Provided for testing purposes.

Definition at line 222 of file ping_context.cc.

References WAITING_TO_SEND.

◆ EMPTY_LOT()

static hooks::ParkingLotHandlePtr & isc::ping_check::PingContext::EMPTY_LOT ( )
inlinestatic

Fetches an empty parking lot handle.

Returns
an empty ParkingLotHandlePtr

Definition at line 104 of file ping_context.h.

Referenced by isc::ping_check::PingContextStore::~PingContextStore().

◆ EMPTY_TIME()

static const TimeStamp & isc::ping_check::PingContext::EMPTY_TIME ( )
inlinestatic

◆ getCreatedTime()

const TimeStamp & isc::ping_check::PingContext::getCreatedTime ( ) const

Fetches the time at which the context was created.

Returns
creation time as a TimeStamp

Definition at line 197 of file ping_context.cc.

◆ getEchosSent()

uint32_t isc::ping_check::PingContext::getEchosSent ( ) const

Fetches the number of ECHO REQUESTs sent.

Returns
number of echos sent as a unit32_t

Definition at line 147 of file ping_context.cc.

◆ getLastEchoSentTime()

const TimeStamp & isc::ping_check::PingContext::getLastEchoSentTime ( ) const

Fetches the timestamp of when the most recent ECHO REQUEST was sent.

Returns
time the last echo was sent as a TimeStamp

Definition at line 157 of file ping_context.cc.

◆ getLease()

Lease4Ptr isc::ping_check::PingContext::getLease ( ) const

Returns the candidate lease whose address is the target to check.

Returns
lease under test as a Lease4Ptr

Definition at line 217 of file ping_context.cc.

◆ getMinEchos()

uint32_t isc::ping_check::PingContext::getMinEchos ( ) const

Fetches the minimum number of ECHO REQUESTs.

Returns
minimum number of echos as a uint32_t

Definition at line 127 of file ping_context.cc.

◆ getNextExpiry()

const TimeStamp & isc::ping_check::PingContext::getNextExpiry ( ) const

Fetches the time at which the WAITING_FOR_REPLY state expires(ed)

The value returned is only meaningful when the context state is WAITING_FOR_REPLY.

Returns
expiration

Definition at line 182 of file ping_context.cc.

◆ getParkingLot()

isc::hooks::ParkingLotHandlePtr isc::ping_check::PingContext::getParkingLot ( )
inline

Fetches the parking lot used for this context.

Returns
Pointer to the parking lot handle or empty if parking is not employed.

Definition at line 233 of file ping_context.h.

◆ getQuery()

Pkt4Ptr isc::ping_check::PingContext::getQuery ( ) const

Returns the query that instigated this check.

Returns
query as a Pkt4Ptr

Definition at line 212 of file ping_context.cc.

◆ getReplyTimeout()

uint32_t isc::ping_check::PingContext::getReplyTimeout ( ) const

Fetches the reply timeout (milliseconds)

Returns
reply timeout as a unit32_t

Definition at line 137 of file ping_context.cc.

◆ getSendWaitStart()

const TimeStamp & isc::ping_check::PingContext::getSendWaitStart ( ) const

Fetches the time the context went into WAITING_TO_SEND state.

The value returned is only meaningful when the context state is WAITING_TO_SEND.

Returns
send waits start time as a TimeStamp

Definition at line 167 of file ping_context.cc.

◆ getState()

PingContext::State isc::ping_check::PingContext::getState ( ) const

Fetches the current state.

Returns
current state as PingContext::State

Definition at line 202 of file ping_context.cc.

◆ getTarget()

const IOAddress & isc::ping_check::PingContext::getTarget ( ) const

Fetches the IP address that is under test.

Returns
IP address as an IOAddress

Definition at line 122 of file ping_context.cc.

Referenced by PingContext().

◆ isWaitingForReply()

bool isc::ping_check::PingContext::isWaitingForReply ( ) const

Returns true if state is WAITING_FOR_REPLY.

Returns
True if the context is in WAITING_TO_REPLY state

Definition at line 187 of file ping_context.cc.

References WAITING_FOR_REPLY.

◆ isWaitingToSend()

bool isc::ping_check::PingContext::isWaitingToSend ( ) const

Returns true if state is WAITING_TO_SEND.

Returns
True if the context is in WAITING_TO_SEND state

Definition at line 172 of file ping_context.cc.

References WAITING_TO_SEND.

◆ MIN_TIME()

static const TimeStamp & isc::ping_check::PingContext::MIN_TIME ( )
inlinestatic

Fetches the minimum timestamp.

Returns
the minimum timestamp

Definition at line 96 of file ping_context.h.

Referenced by isc::ping_check::PingContextStore::getExpiredSince(), and isc::ping_check::PingContextStore::getNextToSend().

◆ now()

TimeStamp isc::ping_check::PingContext::now ( )
static

Fetches the current timestamp (UTC/milliseconds precision)

Returns
current time as a TimeStamp

Definition at line 91 of file ping_context.cc.

Referenced by PingContext(), isc::ping_check::PingContextStore::~PingContextStore(), isc::ping_check::PingContextStore::getExpiresNext(), and isc::ping_check::PingCheckMgr::setNextExpirationInternal().

◆ setEchosSent()

void isc::ping_check::PingContext::setEchosSent ( uint32_t value)

Sets the number of ECHO REQUESTs sent.

Parameters
valuenew value

Definition at line 152 of file ping_context.cc.

◆ setLastEchoSentTime()

void isc::ping_check::PingContext::setLastEchoSentTime ( const TimeStamp & value)

Sets the timestamp the most recent ECHO REQUEST was sent.

Parameters
valuenew value

Definition at line 162 of file ping_context.cc.

◆ setMinEchos()

void isc::ping_check::PingContext::setMinEchos ( uint32_t value)

Sets the minimum number of ECHO REQUESTs.

Parameters
valuenew value, must be greater than 0
Exceptions
BadValueif the given value is 0

Definition at line 132 of file ping_context.cc.

◆ setNextExpiry()

void isc::ping_check::PingContext::setNextExpiry ( const TimeStamp & value)

Sets the timestamp which specifies the time at which the WAITING_FOR_REPLY state expires.

Parameters
valuenew value

Definition at line 192 of file ping_context.cc.

◆ setReplyTimeout()

void isc::ping_check::PingContext::setReplyTimeout ( uint32_t value)

Sets the reply timeout.

Parameters
valuenew value in milliseconds, must be greater than 0
Exceptions
BadValueif the given value is 0.

Definition at line 142 of file ping_context.cc.

◆ setSendWaitStart()

void isc::ping_check::PingContext::setSendWaitStart ( const TimeStamp & value)

Sets the send wait start timestamp.

Parameters
valuenew value

Definition at line 177 of file ping_context.cc.

◆ setState()

void isc::ping_check::PingContext::setState ( const State & value)

Sets the state.

Parameters
valuenew state value

Definition at line 207 of file ping_context.cc.

◆ stateToString()

std::string isc::ping_check::PingContext::stateToString ( const State & state)
static

Converts a State to a string.

Parameters
stateState to convert
Returns
string label corresponding to the given state

Definition at line 96 of file ping_context.cc.

References NEW, SENDING, TARGET_FREE, TARGET_IN_USE, WAITING_FOR_REPLY, and WAITING_TO_SEND.

◆ stringToState()

PingContext::State isc::ping_check::PingContext::stringToState ( const std::string & state_str)
static

Converts a string to State.

Parameters
state_strUpper case string label to convert
Returns
State value corresponding to the given string
Exceptions
BadValueif the string is not a valid state label

Definition at line 62 of file ping_context.cc.

References isc_throw, NEW, SENDING, TARGET_FREE, TARGET_IN_USE, WAITING_FOR_REPLY, and WAITING_TO_SEND.


The documentation for this class was generated from the following files: