Kea 2.5.8
isc::ha::CommunicationState4 Class Reference

Holds communication state between DHCPv4 servers. More...

#include <communication_state.h>

+ Inheritance diagram for isc::ha::CommunicationState4:

Classes

struct  ConnectingClient4
 Structure holding information about the client which has sent the packet being analyzed. More...
 
struct  RejectedClient4
 Structure holding information about the client who has a rejected lease update. More...
 

Public Member Functions

 CommunicationState4 (const asiolink::IOServicePtr &io_service, const HAConfigPtr &config)
 Constructor.
 
virtual void analyzeMessage (const boost::shared_ptr< dhcp::Pkt > &message)
 Checks if the DHCPv4 message appears to be unanswered.
 
virtual bool failureDetected () const
 Checks if the partner failure has been detected based on the DHCP traffic analysis.
 
virtual size_t getConnectingClientsCount () const
 Returns the current number of clients which attempted to get a lease from the partner server.
 
virtual size_t getUnackedClientsCount () const
 Returns the current number of clients which haven't gotten a lease from the partner server.
 
- Public Member Functions inherited from isc::ha::CommunicationState
 CommunicationState (const asiolink::IOServicePtr &io_service, const HAConfigPtr &config)
 Constructor.
 
virtual ~CommunicationState ()
 Destructor.
 
virtual void analyzeMessage (const boost::shared_ptr< dhcp::Pkt > &message)=0
 Checks if the DHCP message appears to be unanswered.
 
void clearRejectedLeaseUpdates ()
 Clears rejected client leases (MT safe).
 
bool clockSkewShouldTerminate ()
 Indicates whether the HA service should enter "terminated" state as a result of the clock skew exceeding maximum value.
 
bool clockSkewShouldWarn ()
 Issues a warning about high clock skew between the active servers if one is warranted.
 
virtual bool failureDetected () const =0
 Checks if the partner failure has been detected based on the DHCP traffic analysis.
 
size_t getAnalyzedMessagesCount () const
 Returns the number of analyzed messages while being in the communications interrupted state.
 
virtual size_t getConnectingClientsCount () const =0
 Returns the current number of clients which attempted to get a lease from the partner server.
 
int64_t getDurationInMillisecs () const
 Returns duration between the poke time and current time.
 
boost::posix_time::time_duration getDurationSincePartnerStateTime () const
 Returns the duration since the partner was first seen in the current state.
 
std::set< std::string > getPartnerScopes () const
 Returns scopes served by the partner server.
 
int getPartnerState () const
 Returns last known state of the partner.
 
size_t getRejectedLeaseUpdatesCount ()
 Returns the number of lease updates rejected by the partner (MT safe).
 
data::ElementPtr getReport () const
 Returns the report about current communication state.
 
virtual size_t getUnackedClientsCount () const =0
 Returns the current number of clients which haven't got the lease from the partner server.
 
uint64_t getUnsentUpdateCount () const
 Returns a total number of unsent lease updates.
 
bool hasPartnerNewUnsentUpdates () const
 Checks if the partner allocated new leases for which it hasn't sent any lease updates.
 
void increaseUnsentUpdateCount ()
 Increases a total number of unsent lease updates by 1.
 
bool isCommunicationInterrupted () const
 Checks if communication with the partner is interrupted.
 
bool isHeartbeatRunning () const
 Checks if recurring heartbeat is running.
 
std::string logFormatClockSkew () const
 Returns current clock skew value in the logger friendly format.
 
void modifyPokeTime (const long secs)
 Modifies poke time by adding seconds to it.
 
void poke ()
 Pokes the communication state.
 
bool rejectedLeaseUpdatesShouldTerminate ()
 Indicates whether the HA service should enter "terminated" state due to excessive number of rejected lease updates.
 
bool reportRejectedLeaseUpdate (const dhcp::PktPtr &message, const uint32_t lifetime=86400)
 Marks that the lease update failed due to a conflict for the specified DHCP message (MT safe).
 
bool reportSuccessfulLeaseUpdate (const dhcp::PktPtr &message)
 Marks the lease update successful (MT safe).
 
void setPartnerScopes (data::ConstElementPtr new_scopes)
 Sets partner scopes.
 
void setPartnerState (const std::string &state)
 Sets partner state.
 
void setPartnerTime (const std::string &time_text)
 Provide partner's notion of time so the new clock skew can be calculated.
 
void setPartnerUnavailable ()
 Sets partner state unavailable.
 
void setPartnerUnsentUpdateCount (uint64_t unsent_update_count)
 Saves new total number of unsent lease updates from the partner.
 
void startHeartbeat (const long interval, const std::function< void()> &heartbeat_impl)
 Starts recurring heartbeat (public interface).
 
void stopHeartbeat ()
 Stops recurring heartbeat.
 

Protected Types

template<typename ClientData >
using ClientIdent4 = boost::multi_index::hashed_unique< boost::multi_index::composite_key< ClientData, boost::multi_index::member< ClientData, std::vector< uint8_t >, &ClientData::hwaddr_ >, boost::multi_index::member< ClientData, std::vector< uint8_t >, &ClientData::clientid_ > > >
 Hashed index used in the multi index containers to find clients by HW address and client identifier.
 
typedef boost::multi_index_container< ConnectingClient4, boost::multi_index::indexed_by< ClientIdent4< ConnectingClient4 >, boost::multi_index::ordered_non_unique< boost::multi_index::member< ConnectingClient4, bool, &ConnectingClient4::unacked_ > > > > ConnectingClients4
 Multi index container holding information about the clients attempting to get leases from the partner server.
 
typedef boost::multi_index_container< RejectedClient4, boost::multi_index::indexed_by< ClientIdent4< RejectedClient4 >, boost::multi_index::ordered_non_unique< boost::multi_index::member< RejectedClient4, int64_t, &RejectedClient4::expire_ > > > > RejectedClients4
 Multi index container holding information about the clients who have rejected leases.
 

Protected Member Functions

virtual void analyzeMessageInternal (const boost::shared_ptr< dhcp::Pkt > &message)
 Checks if the DHCPv4 message appears to be unanswered.
 
virtual void clearConnectingClients ()
 Removes information about the clients the partner server should respond to while communication with the partner was interrupted.
 
virtual void clearRejectedLeaseUpdatesInternal ()
 Clears rejected client leases.
 
virtual bool failureDetectedInternal () const
 Checks if the partner failure has been detected based on the DHCP traffic analysis.
 
virtual size_t getRejectedLeaseUpdatesCountInternal ()
 Returns the number of lease updates rejected by the partner.
 
virtual bool reportRejectedLeaseUpdateInternal (const dhcp::PktPtr &message, const uint32_t lifetime)
 Marks that the lease update failed due to a conflict for the specified DHCP message.
 
virtual bool reportSuccessfulLeaseUpdateInternal (const dhcp::PktPtr &message)
 Marks the lease update successful.
 
- Protected Member Functions inherited from isc::ha::CommunicationState
virtual void clearConnectingClients ()=0
 Removes information about the clients the partner server should respond to while communication with the partner was interrupted.
 
virtual void clearRejectedLeaseUpdatesInternal ()=0
 Clears rejected client leases.
 
virtual size_t getRejectedLeaseUpdatesCountInternal ()=0
 Returns the number of lease updates rejected by the partner.
 
virtual bool reportRejectedLeaseUpdateInternal (const dhcp::PktPtr &message, const uint32_t lifetime)=0
 Marks that the lease update failed due to a conflict for the specified DHCP message.
 
virtual bool reportSuccessfulLeaseUpdateInternal (const dhcp::PktPtr &message)=0
 Marks the lease update successful.
 
boost::posix_time::time_duration updatePokeTime ()
 Update the poke time and compute the duration.
 

Protected Attributes

ConnectingClients4 connecting_clients_
 Holds information about the clients attempting to contact the partner server while the servers are in communications interrupted state.
 
RejectedClients4 rejected_clients_
 Holds information about the clients for whom lease updates have been rejected by the partner.
 
- Protected Attributes inherited from isc::ha::CommunicationState
size_t analyzed_messages_count_
 Total number of analyzed messages to be responded by partner.
 
boost::posix_time::time_duration clock_skew_
 Clock skew between the active servers.
 
HAConfigPtr config_
 High availability configuration.
 
std::function< void()> heartbeat_impl_
 Pointer to the function providing heartbeat implementation.
 
long interval_
 Interval specified for the heartbeat.
 
asiolink::IOServicePtr io_service_
 Pointer to the common IO service instance.
 
boost::posix_time::ptime last_clock_skew_warn_
 Holds a time when last warning about too high clock skew was issued.
 
const boost::scoped_ptr< std::mutex > mutex_
 The mutex used to protect internal state.
 
boost::posix_time::ptime my_time_at_skew_
 My time when skew was calculated.
 
std::set< std::string > partner_scopes_
 Last known set of scopes served by the partner server.
 
int partner_state_
 Last known state of the partner server.
 
boost::posix_time::ptime partner_state_time_
 Holds a time when partner was first seen in the current state.
 
boost::posix_time::ptime partner_time_at_skew_
 Partner reported time when skew was calculated.
 
std::pair< uint64_t, uint64_t > partner_unsent_update_count_
 Previous and current total number of unsent lease updates from the partner.
 
boost::posix_time::ptime poke_time_
 Last poke time.
 
asiolink::IntervalTimerPtr timer_
 Interval timer triggering heartbeat commands.
 
uint64_t unsent_update_count_
 Total number of unsent lease updates.
 

Additional Inherited Members

- Static Protected Member Functions inherited from isc::ha::CommunicationState
static std::vector< uint8_t > getClientId (const dhcp::PktPtr &message, const uint16_t option_type)
 Convenience function attempting to retrieve client identifier from the DHCP message.
 
template<typename RejectedClientsType >
static size_t getRejectedLeaseUpdatesCountFromContainer (RejectedClientsType &rejected_clients)
 Extracts the number of lease updates rejected by the partner from the specified container.
 

Detailed Description

Holds communication state between DHCPv4 servers.

This class implements DHCPv4 failure detection by monitoring the value of the "secs" field in received DHCPv4 messages as described in CommunicationState::analyzeMessage.

Definition at line 778 of file communication_state.h.

Member Typedef Documentation

◆ ClientIdent4

template<typename ClientData >
using isc::ha::CommunicationState4::ClientIdent4 = boost::multi_index::hashed_unique< boost::multi_index::composite_key< ClientData, boost::multi_index::member<ClientData, std::vector<uint8_t>, &ClientData::hwaddr_>, boost::multi_index::member<ClientData, std::vector<uint8_t>, &ClientData::clientid_> > >
protected

Hashed index used in the multi index containers to find clients by HW address and client identifier.

Template Parameters
ClientDataType of a structure holding client information.

Definition at line 910 of file communication_state.h.

◆ ConnectingClients4

typedef boost::multi_index_container< ConnectingClient4, boost::multi_index::indexed_by< ClientIdent4<ConnectingClient4>, boost::multi_index::ordered_non_unique< boost::multi_index::member<ConnectingClient4, bool, &ConnectingClient4::unacked_> > > > isc::ha::CommunicationState4::ConnectingClients4
protected

Multi index container holding information about the clients attempting to get leases from the partner server.

Definition at line 942 of file communication_state.h.

◆ RejectedClients4

typedef boost::multi_index_container< RejectedClient4, boost::multi_index::indexed_by< ClientIdent4<RejectedClient4>, boost::multi_index::ordered_non_unique< boost::multi_index::member<RejectedClient4, int64_t, &RejectedClient4::expire_> > > > isc::ha::CommunicationState4::RejectedClients4
protected

Multi index container holding information about the clients who have rejected leases.

Definition at line 968 of file communication_state.h.

Constructor & Destructor Documentation

◆ CommunicationState4()

isc::ha::CommunicationState4::CommunicationState4 ( const asiolink::IOServicePtr io_service,
const HAConfigPtr config 
)

Constructor.

Parameters
io_servicepointer to the common IO service instance.
configpointer to the HA configuration.

Definition at line 654 of file communication_state.cc.

Member Function Documentation

◆ analyzeMessage()

void isc::ha::CommunicationState4::analyzeMessage ( const boost::shared_ptr< dhcp::Pkt > &  message)
virtual

Checks if the DHCPv4 message appears to be unanswered.

This method uses "secs" field value for detecting client communication failures as described in the CommunicationState::analyzeMessage. Some misbehaving Windows clients were reported to swap "secs" field bytes. In this case the first byte is set to non-zero byte and the second byte is set to 0. This method handles such cases and corrects bytes order before comparing against the threshold.

Parameters
messageDHCPv4 message to be analyzed. This must be the message which belongs to the partner, i.e. the caller must filter out messages belonging to the partner prior to calling this method.

Implements isc::ha::CommunicationState.

Definition at line 661 of file communication_state.cc.

References analyzeMessageInternal(), isc::util::MultiThreadingMgr::instance(), and isc::ha::CommunicationState::mutex_.

+ Here is the call graph for this function:

◆ analyzeMessageInternal()

void isc::ha::CommunicationState4::analyzeMessageInternal ( const boost::shared_ptr< dhcp::Pkt > &  message)
protectedvirtual

Checks if the DHCPv4 message appears to be unanswered.

Should be called in a thread safe context.

This method uses "secs" field value for detecting client communication failures as described in the CommunicationState::analyzeMessage. Some misbehaving Windows clients were reported to swap "secs" field bytes. In this case the first byte is set to non-zero byte and the second byte is set to 0. This method handles such cases and corrects bytes order before comparing against the threshold.

Parameters
messageDHCPv4 message to be analyzed. This must be the message which belongs to the partner, i.e. the caller must filter out messages belonging to the partner prior to calling this method.

Definition at line 671 of file communication_state.cc.

References isc::ha::CommunicationState::analyzed_messages_count_, isc::ha::CommunicationState::config_, connecting_clients_, isc::dhcp::DHO_DHCP_CLIENT_IDENTIFIER, isc::ha::CommunicationState::getClientId(), isc::ha::HA_COMMUNICATION_INTERRUPTED_CLIENT4, isc::ha::HA_COMMUNICATION_INTERRUPTED_CLIENT4_UNACKED, isc::ha::ha_logger, isc::ha::CommunicationState4::ConnectingClient4::hwaddr_, isc_throw, and LOG_INFO.

Referenced by analyzeMessage().

+ Here is the call graph for this function:

◆ clearConnectingClients()

void isc::ha::CommunicationState4::clearConnectingClients ( )
protectedvirtual

Removes information about the clients the partner server should respond to while communication with the partner was interrupted.

See CommunicationState::analyzeMessage for details.

Implements isc::ha::CommunicationState.

Definition at line 786 of file communication_state.cc.

References connecting_clients_.

◆ clearRejectedLeaseUpdatesInternal()

void isc::ha::CommunicationState4::clearRejectedLeaseUpdatesInternal ( )
protectedvirtual

Clears rejected client leases.

Implements isc::ha::CommunicationState.

Definition at line 832 of file communication_state.cc.

References rejected_clients_.

◆ failureDetected()

bool isc::ha::CommunicationState4::failureDetected ( ) const
virtual

Checks if the partner failure has been detected based on the DHCP traffic analysis.

Returns
true if the partner failure has been detected, false otherwise.

Implements isc::ha::CommunicationState.

Definition at line 749 of file communication_state.cc.

References failureDetectedInternal(), isc::util::MultiThreadingMgr::instance(), and isc::ha::CommunicationState::mutex_.

+ Here is the call graph for this function:

◆ failureDetectedInternal()

bool isc::ha::CommunicationState4::failureDetectedInternal ( ) const
protectedvirtual

Checks if the partner failure has been detected based on the DHCP traffic analysis.

Should be called in a thread safe context.

Returns
true if the partner failure has been detected, false otherwise.

Definition at line 759 of file communication_state.cc.

References isc::ha::CommunicationState::config_, and connecting_clients_.

Referenced by failureDetected().

◆ getConnectingClientsCount()

size_t isc::ha::CommunicationState4::getConnectingClientsCount ( ) const
virtual

Returns the current number of clients which attempted to get a lease from the partner server.

The returned number is reset to 0 when the server successfully establishes communication with the partner. The number is incremented only in the communications interrupted case.

Returns
The number of clients including unacked clients.

Implements isc::ha::CommunicationState.

Definition at line 766 of file communication_state.cc.

References connecting_clients_, isc::util::MultiThreadingMgr::instance(), and isc::ha::CommunicationState::mutex_.

+ Here is the call graph for this function:

◆ getRejectedLeaseUpdatesCountInternal()

size_t isc::ha::CommunicationState4::getRejectedLeaseUpdatesCountInternal ( )
protectedvirtual

Returns the number of lease updates rejected by the partner.

Each rejected lease update is counted only once if it failed multiple times. Before returning the counter, it discards expired rejected lease updates.

Returns
Current rejected lease update number count.

Implements isc::ha::CommunicationState.

Definition at line 791 of file communication_state.cc.

References isc::ha::CommunicationState::getRejectedLeaseUpdatesCountFromContainer(), and rejected_clients_.

Referenced by reportSuccessfulLeaseUpdateInternal().

+ Here is the call graph for this function:

◆ getUnackedClientsCount()

size_t isc::ha::CommunicationState4::getUnackedClientsCount ( ) const
virtual

Returns the current number of clients which haven't gotten a lease from the partner server.

The returned number is reset to 0 when the server successfully establishes communication with the partner. The number is incremented only in the communications interrupted case.

Returns
Number of unacked clients.

Implements isc::ha::CommunicationState.

Definition at line 776 of file communication_state.cc.

References connecting_clients_, isc::util::MultiThreadingMgr::instance(), and isc::ha::CommunicationState::mutex_.

+ Here is the call graph for this function:

◆ reportRejectedLeaseUpdateInternal()

bool isc::ha::CommunicationState4::reportRejectedLeaseUpdateInternal ( const dhcp::PktPtr message,
const uint32_t  lifetime 
)
protectedvirtual

Marks that the lease update failed due to a conflict for the specified DHCP message.

If the conflict has been already reported for the given client, the rejected lease count remains unchanged.

Parameters
messageDHCP message for which a lease update failed due to a conflict.
lifetimea time in seconds after which the rejected lease update entry should be discarded.
Returns
true if the update was rejected for the first time, false otherwise.

Implements isc::ha::CommunicationState.

Definition at line 796 of file communication_state.cc.

References isc::dhcp::DHO_DHCP_CLIENT_IDENTIFIER, isc::ha::CommunicationState::getClientId(), isc::ha::CommunicationState4::RejectedClient4::hwaddr_, isc_throw, and rejected_clients_.

+ Here is the call graph for this function:

◆ reportSuccessfulLeaseUpdateInternal()

bool isc::ha::CommunicationState4::reportSuccessfulLeaseUpdateInternal ( const dhcp::PktPtr message)
protectedvirtual

Marks the lease update successful.

If the lease update was previously marked "in conflict", it is now cleared, effectively lowering the number of conflicted leases.

Parameters
messageDHCP message for which the lease update was successful.
Returns
true when the lease was marked "in conflict" and it is now cleared.

Implements isc::ha::CommunicationState.

Definition at line 813 of file communication_state.cc.

References isc::dhcp::DHO_DHCP_CLIENT_IDENTIFIER, isc::ha::CommunicationState::getClientId(), getRejectedLeaseUpdatesCountInternal(), isc_throw, and rejected_clients_.

+ Here is the call graph for this function:

Member Data Documentation

◆ connecting_clients_

ConnectingClients4 isc::ha::CommunicationState4::connecting_clients_
protected

Holds information about the clients attempting to contact the partner server while the servers are in communications interrupted state.

Definition at line 947 of file communication_state.h.

Referenced by analyzeMessageInternal(), clearConnectingClients(), failureDetectedInternal(), getConnectingClientsCount(), and getUnackedClientsCount().

◆ rejected_clients_

RejectedClients4 isc::ha::CommunicationState4::rejected_clients_
protected

Holds information about the clients for whom lease updates have been rejected by the partner.

Definition at line 972 of file communication_state.h.

Referenced by clearRejectedLeaseUpdatesInternal(), getRejectedLeaseUpdatesCountInternal(), reportRejectedLeaseUpdateInternal(), and reportSuccessfulLeaseUpdateInternal().


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