Kea  1.5.0
isc::ha::HAService Class Reference

High availability service. More...

#include <ha_service.h>

+ Inheritance diagram for isc::ha::HAService:

Public Member Functions

 HAService (const asiolink::IOServicePtr &io_service, const dhcp::NetworkStatePtr &network_state, const HAConfigPtr &config, const HAServerType &server_type=HAServerType::DHCPv4)
 Constructor. More...
 
void adjustNetworkState ()
 Enables or disables network state depending on the served scopes. More...
 
size_t asyncSendLeaseUpdates (const dhcp::Pkt4Ptr &query, const dhcp::Lease4CollectionPtr &leases, const dhcp::Lease4CollectionPtr &deleted_leases, const hooks::ParkingLotHandlePtr &parking_lot)
 Schedules asynchronous IPv4 leases updates. More...
 
size_t asyncSendLeaseUpdates (const dhcp::Pkt6Ptr &query, const dhcp::Lease6CollectionPtr &leases, const dhcp::Lease6CollectionPtr &deleted_leases, const hooks::ParkingLotHandlePtr &parking_lot)
 Schedules asynchronous IPv6 lease updates. More...
 
void backupStateHandler ()
 Handler for the "backup" state. More...
 
virtual void defineEvents ()
 Defines events used by the HA service. More...
 
virtual void defineStates ()
 Defines states of the HA service. More...
 
HAServerType getServerType () const
 Returns HA server type used in object construction. More...
 
bool inScope (dhcp::Pkt4Ptr &query4)
 Checks if the DHCPv4 query should be processed by this server. More...
 
bool inScope (dhcp::Pkt6Ptr &query6)
 Checks if the DHCPv6 query should be processed by this server. More...
 
void normalStateHandler ()
 Handler for the "hot-standby" and "load-balancing" states. More...
 
void partnerDownStateHandler ()
 Handler for "partner-down" state. More...
 
data::ConstElementPtr processContinue ()
 Processes ha-continue command and returns a response. More...
 
data::ConstElementPtr processHeartbeat ()
 Processes ha-heartbeat command and returns a response. More...
 
data::ConstElementPtr processScopes (const std::vector< std::string > &scopes)
 Processes ha-scopes command and returns a response. More...
 
data::ConstElementPtr processSynchronize (const std::string &server_name, const unsigned int max_period)
 Processes ha-sync command and returns a response. More...
 
void readyStateHandler ()
 Handler for "ready" state. More...
 
void serveDefaultScopes ()
 Instructs the HA service to serve default scopes. More...
 
void syncingStateHandler ()
 Handler for "syncing" state. More...
 
void terminatedStateHandler ()
 Handler for "terminated" state. More...
 
bool unpause ()
 Unpauses the HA state machine with logging. More...
 
virtual void verifyEvents ()
 Verifies events used by the HA service. More...
 
void waitingStateHandler ()
 Handler for "waiting" state. More...
 
- Public Member Functions inherited from isc::util::StateModel
 StateModel ()
 Constructor. More...
 
virtual ~StateModel ()
 Destructor. More...
 
bool didModelFail () const
 Returns whether or not the model failed. More...
 
void endModel ()
 Conducts a normal transition to the end of the model. More...
 
std::string getContextStr () const
 Convenience method which returns a string rendition of the current state and next event. More...
 
unsigned int getCurrState () const
 Fetches the model's current state. More...
 
std::string getEventLabel (const int event) const
 Fetches the label associated with an event value. More...
 
unsigned int getLastEvent () const
 Fetches the model's last event. More...
 
unsigned int getNextEvent () const
 Fetches the model's next event. More...
 
std::string getPrevContextStr () const
 Convenience method which returns a string rendition of the previous state and last event. More...
 
unsigned int getPrevState () const
 Fetches the model's previous state. More...
 
std::string getStateLabel (const int state) const
 Fetches the label associated with an state value. More...
 
bool isModelDone () const
 Returns whether or not the model has finished execution. More...
 
bool isModelNew () const
 Returns whether or not the model is new. More...
 
bool isModelPaused () const
 Returns whether or not the model is paused. More...
 
bool isModelRunning () const
 Returns whether or not the model is running. More...
 
bool isModelWaiting () const
 Returns whether or not the model is waiting. More...
 
void nopStateHandler ()
 An empty state handler. More...
 
virtual void runModel (unsigned int event)
 Processes events through the state model. More...
 
void startModel (const int start_state)
 Begins execution of the model. More...
 
void unpauseModel ()
 Unpauses state model. More...
 

Static Public Attributes

static const int HA_HEARTBEAT_COMPLETE_EVT = SM_DERIVED_EVENT_MIN + 1
 Finished heartbeat commannd. More...
 
static const int HA_LEASE_UPDATES_COMPLETE_EVT = SM_DERIVED_EVENT_MIN + 2
 Finished lease updates commands. More...
 
static const int HA_SYNCING_FAILED_EVT = SM_DERIVED_EVENT_MIN + 3
 Lease database synchronization failed. More...
 
static const int HA_SYNCING_SUCCEEDED_EVT = SM_DERIVED_EVENT_MIN + 4
 Lease database synchroniation succeeded. More...
 
- Static Public Attributes inherited from isc::util::StateModel
static const int END_EVT = 2
 Event issued to end the model execution. More...
 
static const int END_ST = 1
 Final state, all the state model has reached its conclusion. More...
 
static const int FAIL_EVT = 3
 Event issued to abort the model execution. More...
 
static const int NEW_ST = 0
 State that a state model is in immediately after construction. More...
 
static const int NOP_EVT = 0
 Signifies that no event has occurred. More...
 
static const int SM_DERIVED_EVENT_MIN = 11
 Value at which custom events in a derived class should begin. More...
 
static const int SM_DERIVED_STATE_MIN = 11
 Value at which custom states in a derived class should begin. More...
 
static const int START_EVT = 1
 Event issued to start the model execution. More...
 

Protected Types

typedef std::function< void(const bool, const std::string &)> PostRequestCallback
 Callback invoked when request was sent and a response received or an error occurred. More...
 
typedef std::function< void(const bool, const std::string &, const bool)> PostSyncCallback
 Callback invoked when lease database synchronization is complete. More...
 

Protected Member Functions

void asyncDisableDHCPService (http::HttpClient &http_client, const std::string &server_name, const unsigned int max_period, PostRequestCallback post_request_action)
 Schedules asynchronous "dhcp-disable" command to the specified server. More...
 
void asyncEnableDHCPService (http::HttpClient &http_client, const std::string &server_name, PostRequestCallback post_request_action)
 Schedules asynchronous "dhcp-enable" command to the specified server. More...
 
void asyncSendHeartbeat ()
 Starts asynchronous heartbeat to a peer. More...
 
template<typename QueryPtrType >
void asyncSendLeaseUpdate (const QueryPtrType &query, const HAConfig::PeerConfigPtr &config, const data::ConstElementPtr &command, const hooks::ParkingLotHandlePtr &parking_lot)
 Asynchronously sends lease update to the peer. More...
 
void asyncSyncLeases ()
 Asynchronously reads leases from a peer and updates local lease database. More...
 
void asyncSyncLeases (http::HttpClient &http_client, const std::string &server_name, const unsigned int max_period, const dhcp::LeasePtr &last_lease, PostSyncCallback post_sync_action, const bool dhcp_disabled=false)
 Asynchronously reads leases from a peer and updates local lease database using a provided client instance. More...
 
void asyncSyncLeasesInternal (http::HttpClient &http_client, const std::string &server_name, const unsigned int max_period, const dhcp::LeasePtr &last_lease, PostSyncCallback post_sync_action, const bool dhcp_disabled)
 Implements fetching one page of leases during synchronization. More...
 
void conditionalLogPausedState () const
 Logs if the server is paused in the current state. More...
 
void localDisableDHCPService ()
 Disables local DHCP service. More...
 
void localEnableDHCPService ()
 Enables local DHCP service. More...
 
void scheduleHeartbeat ()
 Schedules asynchronous heartbeat to a peer if it is not scheduled. More...
 
bool shouldPartnerDown () const
 Indicates if the server should transition to the partner down state. More...
 
bool shouldSendLeaseUpdates (const HAConfig::PeerConfigPtr &peer_config) const
 Checks if the lease updates should be sent as result of leases allocation or release. More...
 
bool shouldTerminate () const
 Indicates if the server should transition to the terminated state as a result of high clock skew. More...
 
void startHeartbeat ()
 Unconditionally starts one heartbeat to a peer. More...
 
int synchronize (std::string &status_message, const std::string &server_name, const unsigned int max_period)
 Synchronizes lease database with a partner. More...
 
void verboseTransition (const unsigned state)
 Transitions to a desired state and logs it. More...
 
data::ConstElementPtr verifyAsyncResponse (const http::HttpResponsePtr &response)
 Checks if the response is valid or contains an error. More...
 
- Protected Member Functions inherited from isc::util::StateModel
void abortModel (const std::string &explanation)
 Aborts model execution. More...
 
void defineEvent (unsigned int value, const std::string &label)
 Adds an event value and associated label to the set of events. More...
 
void defineState (unsigned int value, const std::string &label, StateHandler handler, const StatePausing &state_pausing=STATE_PAUSE_NEVER)
 Adds an state value and associated label to the set of states. More...
 
bool doOnEntry ()
 Checks if on entry flag is true. More...
 
bool doOnExit ()
 Checks if on exit flag is true. More...
 
const EventPtrgetEvent (unsigned int value)
 Fetches the event referred to by value. More...
 
const StatePtr getState (unsigned int value)
 Fetches the state referred to by value. More...
 
void initDictionaries ()
 Initializes the event and state dictionaries. More...
 
virtual void onModelFailure (const std::string &explanation)
 Handler for fatal model execution errors. More...
 
void postNextEvent (unsigned int event)
 Sets the next event to the given event value. More...
 
void setState (unsigned int state)
 Sets the current state to the given state value. More...
 
void transition (unsigned int state, unsigned int event)
 Sets up the model to transition into given state with a given event. More...
 
virtual void verifyStates ()
 Validates the contents of the set of states. More...
 

Protected Attributes

http::HttpClient client_
 HTTP client instance used to send lease updates. More...
 
CommunicationStatePtr communication_state_
 Holds communication state with a peer. More...
 
HAConfigPtr config_
 Pointer to the HA hooks library configuration. More...
 
asiolink::IOServicePtr io_service_
 Pointer to the IO service object shared between this hooks library and the DHCP server. More...
 
dhcp::NetworkStatePtr network_state_
 Pointer to the state of the DHCP service (enabled/disabled). More...
 
std::map< boost::shared_ptr< dhcp::Pkt >, int > pending_requests_
 Map holding a number of scheduled requests for a given packet. More...
 
QueryFilter query_filter_
 Selects queries to be processed/dropped. More...
 
HAServerType server_type_
 DHCP server type. More...
 

Detailed Description

High availability service.

This class derives from the util::StateModel and implements a state machine for the high availability service in the Kea DHCP server instance.

Definition at line 38 of file ha_service.h.

Member Typedef Documentation

◆ PostRequestCallback

typedef std::function<void(const bool, const std::string&)> isc::ha::HAService::PostRequestCallback
protected

Callback invoked when request was sent and a response received or an error occurred.

The first argument indicates if the operation passed (when true). The second argument holds error message.

Definition at line 60 of file ha_service.h.

◆ PostSyncCallback

typedef std::function<void(const bool, const std::string&, const bool)> isc::ha::HAService::PostSyncCallback
protected

Callback invoked when lease database synchronization is complete.

The first argument indicates if the operation passed (when true). The second argument holds error message. The third argument indicates whether the synchronization resulted in disabling DHCP service on the partner server and has to be re-enabled.

Definition at line 69 of file ha_service.h.

Constructor & Destructor Documentation

◆ HAService()

isc::ha::HAService::HAService ( const asiolink::IOServicePtr io_service,
const dhcp::NetworkStatePtr network_state,
const HAConfigPtr config,
const HAServerType server_type = HAServerType::DHCPv4 
)

Constructor.

Parameters
io_servicePointer to the IO service used by the DHCP server.
configParsed HA hook library configuration.
network_stateObjec holding state of the DHCP service (enabled/disabled).
server_typeServer type, i.e. DHCPv4 or DHCPv6 server.

Definition at line 44 of file ha_service.cc.

References communication_state_, isc::ha::DHCPv4, isc::ha::ha_logger, isc::ha::HA_WAITING_ST, isc::ha::HAConfig::HAModeToString(), io_service_, LOG_INFO, isc::ha::HAConfig::PeerConfig::roleToString(), and isc::util::StateModel::startModel().

+ Here is the call graph for this function:

Member Function Documentation

◆ adjustNetworkState()

void isc::ha::HAService::adjustNetworkState ( )

Enables or disables network state depending on the served scopes.

This method is called in each HA state to enable/disable DHCP service as appropriate for that state.

Definition at line 601 of file ha_service.cc.

References config_, isc::util::StateModel::getCurrState(), isc::util::StateModel::getStateLabel(), isc::ha::HA_HOT_STANDBY_ST, isc::ha::HA_LOAD_BALANCING_ST, isc::ha::ha_logger, isc::ha::HA_PARTNER_DOWN_ST, isc::ha::HA_TERMINATED_ST, LOG_INFO, and network_state_.

Referenced by backupStateHandler(), normalStateHandler(), partnerDownStateHandler(), readyStateHandler(), syncingStateHandler(), terminatedStateHandler(), and waitingStateHandler().

+ Here is the call graph for this function:

◆ asyncDisableDHCPService()

void isc::ha::HAService::asyncDisableDHCPService ( http::HttpClient http_client,
const std::string &  server_name,
const unsigned int  max_period,
PostRequestCallback  post_request_action 
)
protected

Schedules asynchronous "dhcp-disable" command to the specified server.

Parameters
http_clientreference to the client to be used to communicate with the other server.
server_namename of the server to which the command should be sent.
max_periodmaximum number of seconds for which the DHCP service should be disabled.
post_request_actionpointer to the function to be executed when the request is completed.

Definition at line 1025 of file ha_service.cc.

References isc::http::HttpClient::asyncSendRequest(), isc::ha::ha_logger, and LOG_ERROR.

+ Here is the call graph for this function:

◆ asyncEnableDHCPService()

void isc::ha::HAService::asyncEnableDHCPService ( http::HttpClient http_client,
const std::string &  server_name,
PostRequestCallback  post_request_action 
)
protected

Schedules asynchronous "dhcp-enable" command to the specified server.

Parameters
http_clientreference to the client to be used to communicate with the other server.
server_namename of the server to which the command should be sent.
post_request_actionpointer to the function to be executed when the request is completed.

Definition at line 1094 of file ha_service.cc.

References isc::http::HttpClient::asyncSendRequest(), isc::ha::ha_logger, and LOG_ERROR.

+ Here is the call graph for this function:

◆ asyncSendHeartbeat()

void isc::ha::HAService::asyncSendHeartbeat ( )
protected

Starts asynchronous heartbeat to a peer.

Definition at line 915 of file ha_service.cc.

References isc::ha::ha_logger, and LOG_WARN.

◆ asyncSendLeaseUpdate()

template<typename QueryPtrType >
void isc::ha::HAService::asyncSendLeaseUpdate ( const QueryPtrType &  query,
const HAConfig::PeerConfigPtr config,
const data::ConstElementPtr command,
const hooks::ParkingLotHandlePtr parking_lot 
)
protected

Asynchronously sends lease update to the peer.

Parameters
queryPointer to the DHCP client's query.
configPointer to the configuration of the server to which the command should be sent.
commandPointer to the command to be sent.
[out]parking_lotParking lot where the query is parked. This method uses this handle to unpark the packet when all asynchronous requests have been completed.
Template Parameters
QueryPtrTypeType of the pointer to the DHCP client's message, i.e. Pkt4Ptr or Pkt6Ptr.
Exceptions
Unexpectedwhen an unexpected error occurs.

Definition at line 753 of file ha_service.cc.

References isc::http::HttpClient::asyncSendRequest(), client_, isc::ha::ha_logger, if(), and LOG_WARN.

Referenced by asyncSendLeaseUpdates().

+ Here is the call graph for this function:

◆ asyncSendLeaseUpdates() [1/2]

size_t isc::ha::HAService::asyncSendLeaseUpdates ( const dhcp::Pkt4Ptr query,
const dhcp::Lease4CollectionPtr leases,
const dhcp::Lease4CollectionPtr deleted_leases,
const hooks::ParkingLotHandlePtr parking_lot 
)

Schedules asynchronous IPv4 leases updates.

This method schedules asynchronous lease updates as a result of the "leases4_committed" callout. The lease updates are transmitted over HTTP to the peers specified in the configuration (except self). If the server is in the partner-down state the lease updates are not sent to the partner but they are sent to all backup servers. In other states in which the server responds to DHCP queries, the lease updates are sent to all servers. The scheduled lease updates are performed after the callouts return. The server parks the processed DHCP packet and runs IO service shared between the server and the hook library.

If the lease update to the partner (primary, secondary or standby) fails, the parked packet is dropped. If the lease update to any of the backup server fails, an error message is logged but the DHCP packet is not dropped.

This method must be called only if there is at least one lease altered.

Parameters
queryPointer to the processed DHCP client message.
leasesPointer to a collection of the newly allocated or updated leases.
deleted_leasesPointer to a collection of the released leases.
[out]parking_lotPointer to the parking lot handle available for the "leases4_committed" hook point. This is where the DHCP client message is parked. This method calls unpark() on this object when the asynchronous updates are completed.
Returns
Number of peers to whom lease updates have been scheduled to be sent. This value is used to determine if the DHCP query should be parked while waiting for the lease update to complete.

Definition at line 672 of file ha_service.cc.

References asyncSendLeaseUpdate(), config_, isc::ha::CommandCreator::createLease4Delete(), isc::ha::CommandCreator::createLease4Update(), and shouldSendLeaseUpdates().

+ Here is the call graph for this function:

◆ asyncSendLeaseUpdates() [2/2]

size_t isc::ha::HAService::asyncSendLeaseUpdates ( const dhcp::Pkt6Ptr query,
const dhcp::Lease6CollectionPtr leases,
const dhcp::Lease6CollectionPtr deleted_leases,
const hooks::ParkingLotHandlePtr parking_lot 
)

Schedules asynchronous IPv6 lease updates.

This method schedules asynchronous IPv6 lease updates as a result of the "leases6_committed" callout. It works analogously to the IPv4 version of this function.

Parameters
queryPointer to the processed DHCP client message.
leasesPointer to a collection of the newly allocated or updated leases.
deleted_leasesPointer to a collection of the released leases.
[out]parking_lotPointer to the parking lot handle available for the "leases6_committed" hook point. This is where the DHCP client message is parked. This method calls unpark() on this object when the asynchronous updates are completed.
Returns
Number of peers to whom lease updates have been scheduled to be sent. This value is used to determine if the DHCP query should be parked while waiting for the lease update to complete.

Definition at line 712 of file ha_service.cc.

References asyncSendLeaseUpdate(), config_, isc::ha::CommandCreator::createLease6Delete(), isc::ha::CommandCreator::createLease6Update(), and shouldSendLeaseUpdates().

+ Here is the call graph for this function:

◆ asyncSyncLeases() [1/2]

void isc::ha::HAService::asyncSyncLeases ( )
protected

Asynchronously reads leases from a peer and updates local lease database.

This method asynchronously sends lease4-get-page command to fetch leases from the HA peer database. When the response is received, the callback function iterates over the returned leases and inserts those that are not present in the local database and replaces any existing leases if the fetched lease instance is newer (based on cltt) than the instance in the local lease database.

If there is an error while inserting or updating any of the leases a warning message is logged and the process continues for the remaining leases.

This method variant uses default HTTP client for communication.

Definition at line 1170 of file ha_service.cc.

◆ asyncSyncLeases() [2/2]

void isc::ha::HAService::asyncSyncLeases ( http::HttpClient http_client,
const std::string &  server_name,
const unsigned int  max_period,
const dhcp::LeasePtr last_lease,
PostSyncCallback  post_sync_action,
const bool  dhcp_disabled = false 
)
protected

Asynchronously reads leases from a peer and updates local lease database using a provided client instance.

This method first sends dhcp-disable command to the server from which it will be fetching leases to disable its DHCP function while database synchronization is in progress. If the command is successful, it then sends lease4-get-page command to fetch a page of leases from the partner's database. Depending on the configured page size, it may be required to send multiple lease4-get-page or lease6-get-page commands to fetch all leases. If the lease database is large, the database synchronization may even take several minutes. Therefore, dhcp-disable command is sent prior to fetching each page, in order to reset the timeout for automatic re-enabling of the DHCP service on the remote server. Such timeout must only occur if there was no communication from the synchronizing server for longer period of time. If the synchronization is progressing the timeout must be deferred.

The asyncSyncLeases method calls itself (recurses) when the previous lease4-get-page or lease6-get-page command has completed successfully. If the last page of leases was fetched or if any error occurred, the synchronization is terminated and the post_sync_action callback is invoked.

The last parameter passed to the post_sync_action callback indicates whether this server has successfully disabled DHCP service on the partner server at least once. If that's the case, the DHCP service must be re-enabled by sending dhcp-enable command. This is done in the HAService::synchronize method.

If there is an error while inserting or updating any of the leases a warning message is logged and the process continues for the remaining leases.

Parameters
http_clientreference to the client to be used to communicate with the other server.
server_namename of the server to fetch leases from.
max_periodmaximum number of seconds to disable DHCP service
last_leasePointer to the last lease returned on the previous page of leases. This lease is used to set the value of the "from" parameter in the lease4-get-page and lease6-get-page commands. If this command is sent to fetch the first page, the last_lease parameter should be set to null.
post_sync_actionpointer to the function to be executed when lease database synchronization is complete. If this is null, no post synchronization action is invoked.
dhcp_disabledBoolean flag indicating if the remote DHCP server is disabled. This flag propagates down to the post_sync_action to indicate whether the DHCP service has to be enabled after the leases synchronization.

Definition at line 1186 of file ha_service.cc.

◆ asyncSyncLeasesInternal()

void isc::ha::HAService::asyncSyncLeasesInternal ( http::HttpClient http_client,
const std::string &  server_name,
const unsigned int  max_period,
const dhcp::LeasePtr last_lease,
PostSyncCallback  post_sync_action,
const bool  dhcp_disabled 
)
protected

Implements fetching one page of leases during synchronization.

This method implements the actual lease fetching from the partner and synchronization of the database. It excludes sending dhcp-disable command. This command is sent by HAService::asyncSyncLeases.

When the page of leases is successfully synchronized, this method will call HAService::asyncSyncLeases to schedule synchronization of the next page of leases.

Parameters
http_clientreference to the client to be used to communicate with the other server.
server_namename of the server to fetch leases from.
max_periodmaximum number of seconds to disable DHCP service
last_leasePointer to the last lease returned on the previous page of leases. This lease is used to set the value of the "from" parameter in the lease4-get-page and lease6-get-page commands. If this command is sent to fetch the first page, the last_lease parameter should be set to null.
post_sync_actionpointer to the function to be executed when lease database synchronization is complete. If this is null, no post synchronization action is invoked.
dhcp_disabledBoolean flag indicating if the remote DHCP server is disabled. This flag propagates down to the post_sync_action to indicate whether the DHCP service has to be enabled after the leases synchronization.

Definition at line 1217 of file ha_service.cc.

References isc::http::HttpClient::asyncSendRequest(), isc::ha::ha_logger, and LOG_ERROR.

+ Here is the call graph for this function:

◆ backupStateHandler()

void isc::ha::HAService::backupStateHandler ( )

Handler for the "backup" state.

This is the normal operation state for a backup server. Only the backup server can be transitioned to this state. The DHCP service is disabled in this state and the server merely receives lease updates from the active servers. The backup server may be manually instructed to enable DHCP service and serve selected scopes, e.g. when both primary and secondary (or standby) servers are down.

This handler disables DHCP service on the first pass. It is no-op during all subsequent passes.

Definition at line 122 of file ha_service.cc.

References adjustNetworkState(), conditionalLogPausedState(), isc::util::StateModel::doOnEntry(), isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), query_filter_, and isc::ha::QueryFilter::serveNoScopes().

Referenced by defineStates().

+ Here is the call graph for this function:

◆ conditionalLogPausedState()

void isc::ha::HAService::conditionalLogPausedState ( ) const
protected

Logs if the server is paused in the current state.

This method is internally called by the state handlers upon entry to a new state.

Definition at line 555 of file ha_service.cc.

References isc::util::StateModel::getCurrState(), isc::ha::ha_logger, isc::util::StateModel::isModelPaused(), LOG_INFO, and isc::ha::stateToString().

Referenced by backupStateHandler(), normalStateHandler(), partnerDownStateHandler(), readyStateHandler(), syncingStateHandler(), terminatedStateHandler(), and waitingStateHandler().

+ Here is the call graph for this function:

◆ defineEvents()

void isc::ha::HAService::defineEvents ( )
virtual

Defines events used by the HA service.

Reimplemented from isc::util::StateModel.

Definition at line 65 of file ha_service.cc.

References isc::util::StateModel::defineEvent(), HA_HEARTBEAT_COMPLETE_EVT, HA_LEASE_UPDATES_COMPLETE_EVT, HA_SYNCING_FAILED_EVT, and HA_SYNCING_SUCCEEDED_EVT.

+ Here is the call graph for this function:

◆ defineStates()

◆ getServerType()

HAServerType isc::ha::HAService::getServerType ( ) const
inline

Returns HA server type used in object construction.

Definition at line 86 of file ha_service.h.

References server_type_.

◆ inScope() [1/2]

bool isc::ha::HAService::inScope ( dhcp::Pkt4Ptr query4)

Checks if the DHCPv4 query should be processed by this server.

It also associates the DHCPv4 query with required classes appropriate to the server that should process the packet and increments counters of unanswered DHCP queries when in communications interrupted state.

Parameters
[out]query4pointer to the DHCPv4 query received. A client class will be appended to this query instance, appropriate for the server to process this query, e.g. "HA_server1" if the "server1" should process the query etc.
Returns
true if DHCPv4 query should be processed by this server instance, false otherwise.

Definition at line 571 of file ha_service.cc.

◆ inScope() [2/2]

bool isc::ha::HAService::inScope ( dhcp::Pkt6Ptr query6)

Checks if the DHCPv6 query should be processed by this server.

It also associates the DHCPv6 query with required classes appropriate to the server that should process the packet and increments counters of unanswered DHCP queries when in communications interrupted state.

Parameters
[out]query6pointer to the DHCPv6 query received. A client class will be appended to this query instance, appropriate for the server to process this query, e.g. "HA_server1" if the "server1" should process the query etc.
Returns
true if DHCPv6 query should be processed by this server instance, false otherwise.

Definition at line 576 of file ha_service.cc.

◆ localDisableDHCPService()

void isc::ha::HAService::localDisableDHCPService ( )
protected

Disables local DHCP service.

Definition at line 1160 of file ha_service.cc.

◆ localEnableDHCPService()

void isc::ha::HAService::localEnableDHCPService ( )
protected

Enables local DHCP service.

Definition at line 1165 of file ha_service.cc.

◆ normalStateHandler()

void isc::ha::HAService::normalStateHandler ( )

Handler for the "hot-standby" and "load-balancing" states.

This is a handler invoked for the servers running in the hot-standby or load-balancing mode, both for the primary and the standby (or secondary) server.

In the hot-standby mode, the primary server responds to all DHCP queries from the clients. The standby server receives lease updates from the primary, but it doesn't respond to any DHCP queries. Both servers exchange heartbeats to monitor each other states. If any of the servers detects a failure of its partner, it transitions to the "partner-down" state.

In the load-balancing mode, both servers respond to the DHCP queries and exchange the heartbeats and lease updates. If any of the servers detects a failure of its partner, it transitions to the "partner-down" state.

If any of the servers being in the "hot-standby" or "load-balancing" state detects that its partner is in the "partner-down" state, the server transitions to the "waiting" state. Such situation may occur if the Control Agent of this server crashes but the DHCP daemon continues to run. The partner will transition to the "partner-down" state if the failure detection algorithm (based on "secs" field or "elapsed time" option monitoring) and this server is considered to be offline based solely on the fact that it doesn't respond to heartbeats.

Definition at line 137 of file ha_service.cc.

References adjustNetworkState(), communication_state_, conditionalLogPausedState(), isc::util::StateModel::doOnEntry(), isc::ha::HA_PARTNER_DOWN_ST, isc::ha::HA_TERMINATED_ST, isc::ha::HA_UNAVAILABLE_ST, isc::ha::HA_WAITING_ST, isc::util::StateModel::isModelPaused(), isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), query_filter_, scheduleHeartbeat(), isc::ha::QueryFilter::serveDefaultScopes(), shouldPartnerDown(), shouldTerminate(), and verboseTransition().

Referenced by defineStates().

+ Here is the call graph for this function:

◆ partnerDownStateHandler()

void isc::ha::HAService::partnerDownStateHandler ( )

Handler for "partner-down" state.

This is a handler invoked for the server which detected a failure of its partner. The partner was not responding to heartbeats and did not respond to a number of DHCP queries directed to it. In some configurations, the server may transition to this state when the server is not responding to the heartbeats, without checking whether it responds to DHCP queries ("max-unacked-clients" parameter is set to 0).

In the "partner-down" state the server responds to all DHCP queries, i.e. the queries it would normally respond to and to the queries to which its partner would respond.

The backup server would never transition to this state.

The server will transition from the "partner-down" state to the "load-balancing" or "hot-standby" state if its partner is in the "ready" state. In this state, the partner indicates that it has synchronized its database and is ready to enable its DHCP service.

If this server finds that the partner is in an unexpected state, i.e. "load-balancing", "hot-standby" or "partner-down", it transitions to the "waiting" state to try to resolve the conflict with the partner.

Definition at line 187 of file ha_service.cc.

References adjustNetworkState(), communication_state_, conditionalLogPausedState(), config_, isc::util::StateModel::doOnEntry(), isc::ha::HA_HOT_STANDBY_ST, isc::ha::HA_LOAD_BALANCING_ST, isc::ha::HA_PARTNER_DOWN_ST, isc::ha::HA_READY_ST, isc::ha::HA_TERMINATED_ST, isc::ha::HA_WAITING_ST, isc::util::StateModel::isModelPaused(), isc::ha::HAConfig::LOAD_BALANCING, isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), query_filter_, scheduleHeartbeat(), isc::ha::QueryFilter::serveDefaultScopes(), isc::ha::QueryFilter::serveFailoverScopes(), shouldTerminate(), and verboseTransition().

Referenced by defineStates().

+ Here is the call graph for this function:

◆ processContinue()

data::ConstElementPtr isc::ha::HAService::processContinue ( )

Processes ha-continue command and returns a response.

Returns
Pointer to the response to the ha-continue command.

Definition at line 1496 of file ha_service.cc.

References isc::config::CONTROL_RESULT_SUCCESS, and isc::config::createAnswer().

+ Here is the call graph for this function:

◆ processHeartbeat()

ConstElementPtr isc::ha::HAService::processHeartbeat ( )

Processes ha-heartbeat command and returns a response.

This method processes a ha-heartbeat command sent by a peer. This command is sent periodically to the server to detect its state. The servers use the heartbeat mechanism to detect peers' failures and to synchronize their operations when they start up after the failure or a restart.

The ha-heartbeat command takes no arguments. The response contains a server state and timestamp in the following format:

{
"arguments": {
"date-time": "Thu, 01 Feb 2018 21:18:26 GMT",
"state": "waiting"
},
"result": 0,
"text": "HA peer status returned."
}
Returns
Pointer to the response to the heartbeat.

Definition at line 902 of file ha_service.cc.

References isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), and isc::http::HttpDateTime::rfc1123Format().

+ Here is the call graph for this function:

◆ processScopes()

ConstElementPtr isc::ha::HAService::processScopes ( const std::vector< std::string > &  scopes)

Processes ha-scopes command and returns a response.

Parameters
scopesvector of scope names to be enabled.
Returns
Pointer to the response to the ha-scopes command.

Definition at line 1483 of file ha_service.cc.

References isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, and isc::config::createAnswer().

+ Here is the call graph for this function:

◆ processSynchronize()

ConstElementPtr isc::ha::HAService::processSynchronize ( const std::string &  server_name,
const unsigned int  max_period 
)

Processes ha-sync command and returns a response.

This method processes ha-sync command. It instructs the server to disable the DHCP service on the HA peer, fetch all leases from the peer and update the local lease database. Leases synchronization is usually performed automatically by the server which starts up for the first time or after a failure. However, the ha-sync command can also be triggered manually by the server administrator to force synchronization of the lease database in cases when manual recovery is required. One of the possible cases is when the lease database has to be recovered from the backup server, e.g. when both primary and secondary (or standby) servers have crashed.

Parameters
server_namename of the server to fetch leases from.
max_periodmaximum number of seconds to disable DHCP service of the peer. This value is used in dhcp-disable command issued to the peer before the lease4-get-page command.
Returns
Pointer to the response to the ha-sync command.

Definition at line 1395 of file ha_service.cc.

References isc::config::createAnswer().

+ Here is the call graph for this function:

◆ readyStateHandler()

void isc::ha::HAService::readyStateHandler ( )

Handler for "ready" state.

This a handler invoked for the server which finished synchronizing its lease database with the partner and is indicating readiness to start normal operation, i.e. load balancing or hot standby. The partner being in the "partner-down" state will transition to the "load-balancing" or "hot-standby" state. The "ready" server will also transition to one of these states following the transition of the partner.

If both servers appear to be in the "ready" state, the primary server transitions to the "load-balancing" or "hot-standby" state first.

The server in the "ready" state is not responding to the DHCP queries.

Definition at line 243 of file ha_service.cc.

References adjustNetworkState(), communication_state_, conditionalLogPausedState(), config_, isc::util::StateModel::doOnEntry(), isc::ha::HA_HOT_STANDBY_ST, isc::ha::HA_LOAD_BALANCING_ST, isc::ha::HA_PARTNER_DOWN_ST, isc::ha::HA_READY_ST, isc::ha::HA_TERMINATED_ST, isc::ha::HA_UNAVAILABLE_ST, isc::util::StateModel::isModelPaused(), isc::ha::HAConfig::LOAD_BALANCING, isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), isc::ha::HAConfig::PeerConfig::PRIMARY, query_filter_, scheduleHeartbeat(), isc::ha::QueryFilter::serveNoScopes(), shouldPartnerDown(), shouldTerminate(), and verboseTransition().

Referenced by defineStates().

+ Here is the call graph for this function:

◆ scheduleHeartbeat()

void isc::ha::HAService::scheduleHeartbeat ( )
protected

Schedules asynchronous heartbeat to a peer if it is not scheduled.

The heartbeat will be sent according to the value of the heartbeat-delay setting in the HA configuration. This is one shot heartbeat. The callback will reschedule it.

Definition at line 1009 of file ha_service.cc.

Referenced by normalStateHandler(), partnerDownStateHandler(), readyStateHandler(), syncingStateHandler(), and waitingStateHandler().

◆ serveDefaultScopes()

void isc::ha::HAService::serveDefaultScopes ( )

Instructs the HA service to serve default scopes.

This method is mostly useful for unit testing. The scopes need to be enabled to test inScope methods invoked via HAImpl class.

Definition at line 566 of file ha_service.cc.

References query_filter_, and isc::ha::QueryFilter::serveDefaultScopes().

+ Here is the call graph for this function:

◆ shouldPartnerDown()

bool isc::ha::HAService::shouldPartnerDown ( ) const
protected

Indicates if the server should transition to the partner down state.

It indicates that the server should transition to the partner down state when the communications is interrupted (over the control channel) and the partner is not answering DHCP queries in the load balancing case and in the hot standby case, when this server is a secondary.

In the hot standby case, when the server is primary, the communications interrupted is enough to transition to the partner down state.

Returns
true if the server should transition to the partner down state, false otherwise.

Definition at line 630 of file ha_service.cc.

References communication_state_, config_, isc::ha::HAConfig::LOAD_BALANCING, network_state_, and isc::ha::HAConfig::PeerConfig::STANDBY.

Referenced by normalStateHandler(), readyStateHandler(), syncingStateHandler(), and waitingStateHandler().

◆ shouldSendLeaseUpdates()

bool isc::ha::HAService::shouldSendLeaseUpdates ( const HAConfig::PeerConfigPtr peer_config) const
protected

Checks if the lease updates should be sent as result of leases allocation or release.

This method checks if the lease updates should be sent by the server while this server is in the given state. Note that the backup server will never send lease updates.

Parameters
peer_configpointer to the configuration of the peer to which the updates are to be sent.
Returns
true if the server should send lease updates, false otherwise.

Definition at line 871 of file ha_service.cc.

References isc::ha::HA_HOT_STANDBY_ST, and isc::ha::HA_LOAD_BALANCING_ST.

Referenced by asyncSendLeaseUpdates(), and verboseTransition().

◆ shouldTerminate()

bool isc::ha::HAService::shouldTerminate ( ) const
protected

Indicates if the server should transition to the terminated state as a result of high clock skew.

It indicates that the server should transition to the terminated state because of the clock skew being too high. If the clock skew is is higher than 30 seconds but lower than 60 seconds this method only logs a warning. In case, the clock skew exceeds 60 seconds, this method logs a warning and returns true.

Returns
true if the server should transition to the terminated state, false otherwise.

Definition at line 657 of file ha_service.cc.

References communication_state_, isc::ha::ha_logger, LOG_ERROR, and LOG_WARN.

Referenced by normalStateHandler(), partnerDownStateHandler(), readyStateHandler(), syncingStateHandler(), and waitingStateHandler().

◆ startHeartbeat()

void isc::ha::HAService::startHeartbeat ( )
protected

Unconditionally starts one heartbeat to a peer.

Definition at line 1016 of file ha_service.cc.

◆ synchronize()

int isc::ha::HAService::synchronize ( std::string &  status_message,
const std::string &  server_name,
const unsigned int  max_period 
)
protected

Synchronizes lease database with a partner.

It instructs the server to disable the DHCP service on the HA peer, fetch all leases from the peer and update the local lease database.

Parameters
[out]status_messagestatus message in textual form.
server_namename of the server to fetch leases from.
max_periodmaximum number of seconds to disable DHCP service of the peer. This value is used in dhcp-disable command issued to the peer before the lease4-get-page command.
Returns
Synchronization result according to the status codes returned in responses to control commands.

Definition at line 1403 of file ha_service.cc.

References isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, isc::ha::ha_logger, LOG_ERROR, LOG_INFO, isc::util::Stopwatch::logFormatLastDuration(), isc::asiolink::IOService::run(), isc::asiolink::IOService::stop(), and isc::util::Stopwatch::stop().

Referenced by syncingStateHandler().

+ Here is the call graph for this function:

◆ syncingStateHandler()

void isc::ha::HAService::syncingStateHandler ( )

Handler for "syncing" state.

This is a handler invoked for the server in the "syncing" state. The server being in this state is trying to retrieve leases from the partner's database and update its local database. Every primary, secondary and standby server must transition via this state to retrieve up to date lease information from the active partner. If the partner is offline the server will eventually transition to the "partner-down" state without synchronizing the lease database.

The lease database synchronization is performed synchronously, i.e. the handler doesn't return until the synchronization completes or a communication failure occurs.

The server in the "syncing" state is not responding to the DHCP queries.

Definition at line 308 of file ha_service.cc.

References adjustNetworkState(), communication_state_, conditionalLogPausedState(), config_, isc::config::CONTROL_RESULT_SUCCESS, isc::util::StateModel::doOnEntry(), isc::ha::HA_PARTNER_DOWN_ST, isc::ha::HA_READY_ST, isc::ha::HA_TERMINATED_ST, isc::ha::HA_UNAVAILABLE_ST, isc::util::StateModel::isModelPaused(), isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), query_filter_, scheduleHeartbeat(), isc::ha::QueryFilter::serveNoScopes(), shouldPartnerDown(), shouldTerminate(), synchronize(), and verboseTransition().

Referenced by defineStates().

+ Here is the call graph for this function:

◆ terminatedStateHandler()

void isc::ha::HAService::terminatedStateHandler ( )

Handler for "terminated" state.

This is a handler invoked for the server in the "terminated" state. This indicates that the HA service is disabled, typically as a result of an unrecoverable error such as detecting that clocks skew between the active HA servers being too large. This situation requires manual intervation of an administrator. When the problem is corrected, the HA service needs to be restarted.

Note
Currently, restarting the HA service requires restarting the DHCP server. In the future, we will provide a command to restart the HA service.

The server being in the "terminated" state will respond to DHCP clients as if it was in a hot-standby or load-balancing state. However, it will neither send nor receive lease updates. It also won't send heartbeats to the partner.

Definition at line 389 of file ha_service.cc.

References adjustNetworkState(), communication_state_, conditionalLogPausedState(), isc::util::StateModel::doOnEntry(), isc::ha::ha_logger, LOG_ERROR, isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), query_filter_, and isc::ha::QueryFilter::serveDefaultScopes().

Referenced by defineStates().

+ Here is the call graph for this function:

◆ unpause()

bool isc::ha::HAService::unpause ( )

Unpauses the HA state machine with logging.

It un-pauses the state machine if it is paused and logs an informational message. It doesn't log the message if the state machine is not paused.

Returns
true if the state machine was unpaused, false if the state machine was not paused when this method was invoked.

Definition at line 545 of file ha_service.cc.

References isc::ha::ha_logger, isc::util::StateModel::isModelPaused(), LOG_INFO, and isc::util::StateModel::unpauseModel().

+ Here is the call graph for this function:

◆ verboseTransition()

void isc::ha::HAService::verboseTransition ( const unsigned  state)
protected

◆ verifyAsyncResponse()

ConstElementPtr isc::ha::HAService::verifyAsyncResponse ( const http::HttpResponsePtr response)
protected

Checks if the response is valid or contains an error.

The response must be non-null, must contain a JSON body and must contain a success status code.

Parameters
responsepointer to the received response.
Returns
Pointer to the response arguments.
Exceptions
CtrlChannelErrorif response is invalid or contains an error.

Definition at line 1504 of file ha_service.cc.

References isc::config::CONTROL_RESULT_EMPTY, isc::config::CONTROL_RESULT_SUCCESS, isc_throw, and isc::config::parseAnswer().

+ Here is the call graph for this function:

◆ verifyEvents()

void isc::ha::HAService::verifyEvents ( )
virtual

Verifies events used by the HA service.

Reimplemented from isc::util::StateModel.

Definition at line 75 of file ha_service.cc.

References isc::util::StateModel::getEvent(), HA_HEARTBEAT_COMPLETE_EVT, HA_LEASE_UPDATES_COMPLETE_EVT, HA_SYNCING_FAILED_EVT, and HA_SYNCING_SUCCEEDED_EVT.

+ Here is the call graph for this function:

◆ waitingStateHandler()

void isc::ha::HAService::waitingStateHandler ( )

Handler for "waiting" state.

This is a handler invoked for the server in the "waiting" state. This is the first state of every server after its startup. The server initiates a heartbeat to learn the state of its partner. If the partner is operating (e.g. is in the "partner-down" state), the server will transition to the "syncing" state to fetch lease information from the partner. If leases synchronization is administratively disabled with 'sync-leases' parameter, the server will transition directly to the "ready" state. If both servers are in the "waiting" state the primary transitions to the "syncing" or "ready" state first. If the partner is in the "syncing" state, this server will remain in the "waiting" state until the partner completes synchronization.

If the server starts, but the partner appears to be offline, the server transitions to the "partner-down" state.

A backup server transitions from the "waiting" to the "backup" state directly.

The server in the "waiting" state is not responding to the DHCP queries.

Definition at line 410 of file ha_service.cc.

References adjustNetworkState(), isc::ha::HAConfig::PeerConfig::BACKUP, communication_state_, conditionalLogPausedState(), config_, isc::util::StateModel::doOnEntry(), isc::ha::HA_BACKUP_ST, isc::ha::HA_HOT_STANDBY_ST, isc::ha::HA_LOAD_BALANCING_ST, isc::ha::HA_PARTNER_DOWN_ST, isc::ha::HA_READY_ST, isc::ha::HA_SYNCING_ST, isc::ha::HA_TERMINATED_ST, isc::ha::HA_UNAVAILABLE_ST, isc::ha::HA_WAITING_ST, isc::util::StateModel::isModelPaused(), isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), isc::ha::HAConfig::PeerConfig::PRIMARY, query_filter_, scheduleHeartbeat(), isc::ha::QueryFilter::serveNoScopes(), shouldPartnerDown(), shouldTerminate(), and verboseTransition().

Referenced by defineStates().

+ Here is the call graph for this function:

Member Data Documentation

◆ client_

http::HttpClient isc::ha::HAService::client_
protected

HTTP client instance used to send lease updates.

Definition at line 732 of file ha_service.h.

Referenced by asyncSendLeaseUpdate().

◆ communication_state_

CommunicationStatePtr isc::ha::HAService::communication_state_
protected

◆ config_

HAConfigPtr isc::ha::HAService::config_
protected

◆ HA_HEARTBEAT_COMPLETE_EVT

const int isc::ha::HAService::HA_HEARTBEAT_COMPLETE_EVT = SM_DERIVED_EVENT_MIN + 1
static

Finished heartbeat commannd.

Definition at line 42 of file ha_service.h.

Referenced by defineEvents(), and verifyEvents().

◆ HA_LEASE_UPDATES_COMPLETE_EVT

const int isc::ha::HAService::HA_LEASE_UPDATES_COMPLETE_EVT = SM_DERIVED_EVENT_MIN + 2
static

Finished lease updates commands.

Definition at line 45 of file ha_service.h.

Referenced by defineEvents(), and verifyEvents().

◆ HA_SYNCING_FAILED_EVT

const int isc::ha::HAService::HA_SYNCING_FAILED_EVT = SM_DERIVED_EVENT_MIN + 3
static

Lease database synchronization failed.

Definition at line 48 of file ha_service.h.

Referenced by defineEvents(), and verifyEvents().

◆ HA_SYNCING_SUCCEEDED_EVT

const int isc::ha::HAService::HA_SYNCING_SUCCEEDED_EVT = SM_DERIVED_EVENT_MIN + 4
static

Lease database synchroniation succeeded.

Definition at line 51 of file ha_service.h.

Referenced by defineEvents(), and verifyEvents().

◆ io_service_

asiolink::IOServicePtr isc::ha::HAService::io_service_
protected

Pointer to the IO service object shared between this hooks library and the DHCP server.

Definition at line 720 of file ha_service.h.

Referenced by HAService().

◆ network_state_

dhcp::NetworkStatePtr isc::ha::HAService::network_state_
protected

Pointer to the state of the DHCP service (enabled/disabled).

Definition at line 723 of file ha_service.h.

Referenced by adjustNetworkState(), and shouldPartnerDown().

◆ pending_requests_

std::map<boost::shared_ptr<dhcp::Pkt>, int> isc::ha::HAService::pending_requests_
protected

Map holding a number of scheduled requests for a given packet.

A single callout may send multiple requests at the same time, e.g. "leases4_committed" may provide multiple deleted leases and multiple newly allocated leases. The parked packet may be unparked when all requests have been delivered. Therefore, it is required to count the number of responses received so far and unpark the packet when all responses have been received. That's what this map is used for.

Definition at line 748 of file ha_service.h.

◆ query_filter_

QueryFilter isc::ha::HAService::query_filter_
protected

◆ server_type_

HAServerType isc::ha::HAService::server_type_
protected

DHCP server type.

Definition at line 729 of file ha_service.h.

Referenced by getServerType().


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