Kea 2.7.5
isc::ha::HAService Class Reference

High availability service. More...

#include <ha_service.h>

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

Public Member Functions

 HAService (const unsigned int id, const asiolink::IOServicePtr &io_service, const dhcp::NetworkStatePtr &network_state, const HAConfigPtr &config, const HAServerType &server_type=HAServerType::DHCPv4)
 Constructor.
 
virtual ~HAService ()
 Destructor.
 
void adjustNetworkState ()
 Enables or disables network state depending on the served scopes.
 
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.
 
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.
 
size_t asyncSendSingleLeaseUpdate (const dhcp::Pkt4Ptr &query, const dhcp::Lease4Ptr &lease, const hooks::ParkingLotHandlePtr &parking_lot)
 Schedules an asynchronous IPv4 lease update.
 
void checkPermissionsClientAndListener ()
 Check client and(or) listener current thread permissions to perform thread pool state transition.
 
HAServerType getServerType () const
 Returns HA server type used in object construction.
 
bool inScope (dhcp::Pkt4Ptr &query4)
 Checks if the DHCPv4 query should be processed by this server.
 
bool inScope (dhcp::Pkt6Ptr &query6)
 Checks if the DHCPv6 query should be processed by this server.
 
void pauseClientAndListener ()
 Pauses client and(or) listener thread pool operations.
 
data::ConstElementPtr processContinue ()
 Processes ha-continue command and returns a response.
 
data::ConstElementPtr processHAReset ()
 Processes ha-reset command and returns a response.
 
data::ConstElementPtr processHeartbeat ()
 Processes ha-heartbeat command and returns a response.
 
data::ConstElementPtr processMaintenanceCancel ()
 Processes ha-maintenance-cancel command and returns a response.
 
data::ConstElementPtr processMaintenanceNotify (const bool cancel)
 Processes ha-maintenance-notify command and returns a response.
 
data::ConstElementPtr processMaintenanceStart ()
 Processes ha-maintenance-start command and returns a response.
 
data::ConstElementPtr processScopes (const std::vector< std::string > &scopes)
 Processes ha-scopes command and returns a response.
 
data::ConstElementPtr processStatusGet () const
 Processes status-get command and returns a response.
 
data::ConstElementPtr processSyncCompleteNotify (const unsigned int origin_id)
 Process ha-sync-complete-notify command and returns a response.
 
data::ConstElementPtr processSynchronize (const std::string &server_name, const unsigned int max_period)
 Processes ha-sync command and returns a response.
 
void resumeClientAndListener ()
 Resumes client and(or) listener thread pool operations.
 
void serveDefaultScopes ()
 Instructs the HA service to serve default scopes.
 
void serveFailoverScopes ()
 Instructs the HA service to serve failover scopes.
 
void startClientAndListener ()
 Start the client and(or) listener instances.
 
void stopClientAndListener ()
 Stop the client and(or) listener instances.
 
bool unpause ()
 Unpauses the HA state machine with logging.
 
- Public Member Functions inherited from isc::util::StateModel
 StateModel ()
 Constructor.
 
virtual ~StateModel ()
 Destructor.
 
bool didModelFail () const
 Returns whether or not the model failed.
 
void endModel ()
 Conducts a normal transition to the end of the model.
 
std::string getContextStr () const
 Convenience method which returns a string rendition of the current state and next event.
 
unsigned int getCurrState () const
 Fetches the model's current state.
 
std::string getEventLabel (const int event) const
 Fetches the label associated with an event value.
 
unsigned int getLastEvent () const
 Fetches the model's last event.
 
unsigned int getNextEvent () const
 Fetches the model's next event.
 
std::string getPrevContextStr () const
 Convenience method which returns a string rendition of the previous state and last event.
 
unsigned int getPrevState () const
 Fetches the model's previous state.
 
std::string getStateLabel (const int state) const
 Fetches the label associated with an state value.
 
bool isModelDone () const
 Returns whether or not the model has finished execution.
 
bool isModelNew () const
 Returns whether or not the model is new.
 
bool isModelPaused () const
 Returns whether or not the model is paused.
 
bool isModelRunning () const
 Returns whether or not the model is running.
 
bool isModelWaiting () const
 Returns whether or not the model is waiting.
 
void nopStateHandler ()
 An empty state handler.
 
virtual void runModel (unsigned int event)
 Processes events through the state model.
 
void startModel (const int start_state)
 Begins execution of the model.
 
void unpauseModel ()
 Unpauses state model.
 

Static Public Attributes

static const int HA_CONTROL_RESULT_MAINTENANCE_NOT_ALLOWED = 1001
 Control result returned in response to ha-maintenance-notify.
 
static const int HA_HEARTBEAT_COMPLETE_EVT = SM_DERIVED_EVENT_MIN + 1
 Finished heartbeat command.
 
static const int HA_LEASE_UPDATES_COMPLETE_EVT = SM_DERIVED_EVENT_MIN + 2
 Finished lease updates commands.
 
static const int HA_MAINTENANCE_CANCEL_EVT = SM_DERIVED_EVENT_MIN + 7
 ha-maintenance-cancel command received.
 
static const int HA_MAINTENANCE_NOTIFY_EVT = SM_DERIVED_EVENT_MIN + 5
 ha-maintenance-notify command received.
 
static const int HA_MAINTENANCE_START_EVT = SM_DERIVED_EVENT_MIN + 6
 ha-maintenance-start command received.
 
static const int HA_SYNCED_PARTNER_UNAVAILABLE_EVT = SM_DERIVED_EVENT_MIN + 8
 The heartbeat command failed after receiving ha-sync-complete-notify command from the partner.
 
static const int HA_SYNCING_FAILED_EVT = SM_DERIVED_EVENT_MIN + 3
 Lease database synchronization failed.
 
static const int HA_SYNCING_SUCCEEDED_EVT = SM_DERIVED_EVENT_MIN + 4
 Lease database synchronization succeeded.
 
static const int HA_WAITING_TO_TERMINATED_ST_DELAY_MINUTES = 10
 A delay in minutes to transition from the waiting to terminated state when the partner remains in terminated state.
 
- Static Public Attributes inherited from isc::util::StateModel
static const int END_EVT = 2
 Event issued to end the model execution.
 
static const int END_ST = 1
 Final state, all the state model has reached its conclusion.
 
static const int FAIL_EVT = 3
 Event issued to abort the model execution.
 
static const int NEW_ST = 0
 State that a state model is in immediately after construction.
 
static const int NOP_EVT = 0
 Signifies that no event has occurred.
 
static const int SM_DERIVED_EVENT_MIN = 11
 Value at which custom events in a derived class should begin.
 
static const int SM_DERIVED_STATE_MIN = 11
 Value at which custom states in a derived class should begin.
 
static const int START_EVT = 1
 Event issued to start the model execution.
 

Protected Types

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

Protected Member Functions

void asyncDisableDHCPService (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, const unsigned int max_period, PostRequestCallback post_request_action)
 Schedules asynchronous "dhcp-disable" command to the specified server.
 
void asyncEnableDHCPService (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, PostRequestCallback post_request_action)
 Schedules asynchronous "dhcp-enable" command to the specified server.
 
void asyncSendHAReset (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, PostRequestCallback post_request_action)
 Sends ha-reset command to partner asynchronously.
 
void asyncSendHeartbeat ()
 Starts asynchronous heartbeat to a peer.
 
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.
 
void asyncSendLeaseUpdatesFromBacklog (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, PostRequestCallback post_request_action)
 Sends lease updates from backlog to partner asynchronously.
 
void asyncSyncCompleteNotify (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, PostRequestCallback post_request_action)
 Schedules asynchronous "ha-sync-complete-notify" command to the specified server.
 
void asyncSyncLeases ()
 Asynchronously reads leases from a peer and updates local lease database.
 
void asyncSyncLeases (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, 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.
 
void asyncSyncLeasesInternal (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, 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.
 
void clientCloseHandler (int tcp_native_fd)
 HttpClient close callback handler.
 
bool clientConnectHandler (const boost::system::error_code &ec, int tcp_native_fd)
 HttpClient connect callback handler.
 
bool clientHandshakeHandler (const boost::system::error_code &)
 HttpClient handshake callback handler.
 
void conditionalLogPausedState () const
 Logs if the server is paused in the current state.
 
int getNormalState () const
 Returns normal operation state for the current configuration.
 
template<typename QueryPtrType >
int getPendingRequest (const QueryPtrType &query)
 Get the number of scheduled requests for a given query.
 
bool isMaintenanceCanceled () const
 Convenience method checking if the current state is a result of canceling the maintenance.
 
bool isPartnerStateInvalid () const
 Indicates if the partner's state is invalid.
 
template<typename QueryPtrType >
bool leaseUpdateComplete (QueryPtrType &query, const hooks::ParkingLotHandlePtr &parking_lot)
 Handle last pending request for this query.
 
void localDisableDHCPService ()
 Disables local DHCP service.
 
void localEnableDHCPService ()
 Enables local DHCP service.
 
void logFailedLeaseUpdates (const dhcp::PktPtr &query, const data::ConstElementPtr &args) const
 Log failed lease updates.
 
size_t pendingRequestSize ()
 Get the number of entries in the pending request map.
 
void scheduleHeartbeat ()
 Schedules asynchronous heartbeat to a peer if it is not scheduled.
 
bool sendHAReset ()
 Sends ha-reset command to partner synchronously.
 
bool sendLeaseUpdatesFromBacklog ()
 Attempts to send all lease updates from the backlog synchronously.
 
bool shouldPartnerDown () const
 Indicates if the server should transition to the partner down state.
 
bool shouldQueueLeaseUpdates (const HAConfig::PeerConfigPtr &peer_config) const
 Checks if the lease updates should be queued.
 
bool shouldSendLeaseUpdates (const HAConfig::PeerConfigPtr &peer_config) const
 Checks if the lease updates should be sent as result of leases allocation or release.
 
bool shouldTerminate () const
 Indicates if the server should transition to the terminated state.
 
void socketReadyHandler (int tcp_native_fd)
 IfaceMgr external socket ready callback handler.
 
void startHeartbeat ()
 Unconditionally starts one heartbeat to a peer.
 
int synchronize (std::string &status_message, const HAConfig::PeerConfigPtr &remote_config, const unsigned int max_period)
 Synchronizes lease database with a partner.
 
template<typename QueryPtrType >
void updatePendingRequest (QueryPtrType &query)
 Update pending request counter for this query.
 
void verboseTransition (const unsigned state)
 Transitions to a desired state and logs it.
 
data::ConstElementPtr verifyAsyncResponse (const http::HttpResponsePtr &response, int &rcode)
 Checks if the response is valid or contains an error.
 
- Protected Member Functions inherited from isc::util::StateModel
void abortModel (const std::string &explanation)
 Aborts model execution.
 
void defineEvent (unsigned int value, const std::string &label)
 Adds an event value and associated label to the set of events.
 
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.
 
bool doOnEntry ()
 Checks if on entry flag is true.
 
bool doOnExit ()
 Checks if on exit flag is true.
 
const EventPtrgetEvent (unsigned int value)
 Fetches the event referred to by value.
 
const StatePtr getState (unsigned int value)
 Fetches the state referred to by value.
 
const StatePtr getStateInternal (unsigned int value)
 Fetches the state referred to by value.
 
void initDictionaries ()
 Initializes the event and state dictionaries.
 
virtual void onModelFailure (const std::string &explanation)
 Handler for fatal model execution errors.
 
void postNextEvent (unsigned int event)
 Sets the next event to the given event value.
 
void setState (unsigned int state)
 Sets the current state to the given state value.
 
void transition (unsigned int state, unsigned int event)
 Sets up the model to transition into given state with a given event.
 
virtual void verifyStates ()
 Validates the contents of the set of states.
 

Protected Attributes

http::HttpClientPtr client_
 HTTP client instance used to send HA commands and lease updates.
 
CommunicationStatePtr communication_state_
 Holds communication state with a peer.
 
HAConfigPtr config_
 Pointer to the HA hooks library configuration.
 
unsigned int id_
 Unique service id.
 
asiolink::IOServicePtr io_service_
 Pointer to the IO service object shared between this hooks library and the DHCP server.
 
LeaseSyncFilter lease_sync_filter_
 Lease synchronization filter used in hub-and-spoke model.
 
LeaseUpdateBacklog lease_update_backlog_
 Backlog of DHCP lease updates.
 
config::CmdHttpListenerPtr listener_
 HTTP listener instance used to receive and respond to HA commands and lease updates.
 
dhcp::NetworkStatePtr network_state_
 Pointer to the state of the DHCP service (enabled/disabled).
 
QueryFilter query_filter_
 Selects queries to be processed/dropped.
 
HAServerType server_type_
 DHCP server type.
 
bool sync_complete_notified_
 An indicator that a partner sent ha-sync-complete-notify command.
 

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 52 of file ha_service.h.

Member Typedef Documentation

◆ PostRequestCallback

typedef std::function<void(const bool, const std::string&, const int) 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. The third argument holds control status returned.

Definition at line 95 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 104 of file ha_service.h.

Constructor & Destructor Documentation

◆ HAService()

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

Constructor.

It clears the DHCP state using origin HA internal command and starts the state model in waiting state. Creates and starts the client and the listener (if one).

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

Definition at line 76 of file ha_service.cc.

References client_, isc::config::CmdResponseCreator::command_accept_list_, communication_state_, config_, isc::ha::DHCPv4, isc::ha::CommandCreator::ha_commands4_, isc::ha::CommandCreator::ha_commands6_, isc::ha::ha_logger, isc::ha::HA_SERVICE_STARTED, isc::ha::HA_WAITING_ST, isc::ha::HAConfig::HAModeToString(), io_service_, isc::asiolink::IOAddress::IPV4_ZERO_ADDRESS(), isc_throw, listener_, LOG_INFO, network_state_, isc::ha::HAConfig::PeerConfig::roleToString(), and isc::util::StateModel::startModel().

+ Here is the call graph for this function:

◆ ~HAService()

isc::ha::HAService::~HAService ( )
virtual

Destructor.

Stops the client and listener (if one). It clears the DHCP state using origin HA internal command.

Definition at line 147 of file ha_service.cc.

References network_state_, and stopClientAndListener().

+ 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 1089 of file ha_service.cc.

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

+ Here is the call graph for this function:

◆ asyncDisableDHCPService()

void isc::ha::HAService::asyncDisableDHCPService ( http::HttpClient & http_client,
const HAConfig::PeerConfigPtr & remote_config,
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.
remote_configconfig of the partner 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 1936 of file ha_service.cc.

References isc::ha::HA_DHCP_DISABLE_FAILED, isc::ha::ha_logger, isc::http::HttpVersion::HTTP_11(), and LOG_ERROR.

+ Here is the call graph for this function:

◆ asyncEnableDHCPService()

void isc::ha::HAService::asyncEnableDHCPService ( http::HttpClient & http_client,
const HAConfig::PeerConfigPtr & remote_config,
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.
remote_configconfig of the partner to which the command should be sent.
post_request_actionpointer to the function to be executed when the request is completed.

Definition at line 2017 of file ha_service.cc.

References isc::ha::HA_DHCP_ENABLE_FAILED, isc::ha::ha_logger, isc::http::HttpVersion::HTTP_11(), and LOG_ERROR.

+ Here is the call graph for this function:

◆ asyncSendHAReset()

void isc::ha::HAService::asyncSendHAReset ( http::HttpClient & http_client,
const HAConfig::PeerConfigPtr & remote_config,
PostRequestCallback post_request_action )
protected

Sends ha-reset command to partner asynchronously.

Parameters
http_clientreference to the HTTP client to be used for communication.
remote_configpointer to the remote server's configuration.
post_request_actioncallback to be invoked when the operation completes. It can be used for handling errors.

Definition at line 2649 of file ha_service.cc.

References isc::ha::ha_logger, isc::ha::HA_RESET_FAILED, isc::http::HttpVersion::HTTP_11(), and LOG_WARN.

+ Here is the call graph for this function:

◆ asyncSendHeartbeat()

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

Starts asynchronous heartbeat to a peer.

Definition at line 1763 of file ha_service.cc.

References isc::ha::HA_HEARTBEAT_FAILED, isc::ha::ha_logger, isc::http::HttpVersion::HTTP_11(), and LOG_WARN.

+ Here is the call graph for this function:

◆ 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 1418 of file ha_service.cc.

References isc::ha::HAConfig::PeerConfig::BACKUP, client_, communication_state_, config_, isc::ha::HA_LEASE_UPDATE_COMMUNICATIONS_FAILED, isc::ha::HA_LEASE_UPDATE_CONFLICT, isc::ha::HA_LEASE_UPDATE_FAILED, HA_LEASE_UPDATES_COMPLETE_EVT, isc::ha::ha_logger, isc::http::HttpVersion::HTTP_11(), leaseUpdateComplete(), LOG_WARN, logFailedLeaseUpdates(), isc::util::StateModel::runModel(), and verifyAsyncResponse().

Referenced by asyncSendLeaseUpdates(), and 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.
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 and from which we expect a response prior to unparking the packet and sending a response to the DHCP client.

Definition at line 1202 of file ha_service.cc.

References isc::ha::LeaseUpdateBacklog::ADD, asyncSendLeaseUpdate(), isc::ha::HAConfig::PeerConfig::BACKUP, communication_state_, config_, isc::ha::CommandCreator::createLease4Delete(), isc::ha::CommandCreator::createLease4Update(), isc::ha::LeaseUpdateBacklog::DELETE, lease_update_backlog_, isc::ha::LeaseUpdateBacklog::push(), shouldQueueLeaseUpdates(), and shouldSendLeaseUpdates().

Referenced by asyncSendSingleLeaseUpdate().

+ 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 and from which we expect a response prior to unparking the packet and sending a response to the DHCP client.

Definition at line 1295 of file ha_service.cc.

References isc::ha::LeaseUpdateBacklog::ADD, asyncSendLeaseUpdate(), isc::ha::HAConfig::PeerConfig::BACKUP, communication_state_, config_, isc::ha::CommandCreator::createLease6BulkApply(), isc::ha::LeaseUpdateBacklog::DELETE, lease_update_backlog_, isc::ha::LeaseUpdateBacklog::push(), shouldQueueLeaseUpdates(), and shouldSendLeaseUpdates().

+ Here is the call graph for this function:

◆ asyncSendLeaseUpdatesFromBacklog()

void isc::ha::HAService::asyncSendLeaseUpdatesFromBacklog ( http::HttpClient & http_client,
const HAConfig::PeerConfigPtr & remote_config,
PostRequestCallback post_request_action )
protected

Sends lease updates from backlog to partner asynchronously.

This method checks if there are any outstanding DHCPv4 or DHCPv6 leases in the backlog and schedules asynchronous sends of these leases. In DHCPv6 case it sends a single lease6-bulk-apply command with all outstanding leases. In DHCPv4 case, it sends lease4-update or lease4-delete commands recursively (when one lease update completes successfully it schedules sending next lease update).

If there are no lease updates in the backlog it calls post_request_action callback.

This method is called from sendLeaseUpdatesFromBacklog.

Parameters
http_clientreference to the HTTP client to be used for communication.
remote_configpointer to the remote server's configuration.
post_request_actioncallback to be invoked when the operation completes. It can be used for handling errors.

Definition at line 2523 of file ha_service.cc.

References isc::config::CONTROL_RESULT_SUCCESS, isc::ha::HA_LEASES_BACKLOG_FAILED, isc::ha::ha_logger, isc::http::HttpVersion::HTTP_11(), and LOG_WARN.

+ Here is the call graph for this function:

◆ asyncSendSingleLeaseUpdate()

size_t isc::ha::HAService::asyncSendSingleLeaseUpdate ( const dhcp::Pkt4Ptr & query,
const dhcp::Lease4Ptr & lease,
const hooks::ParkingLotHandlePtr & parking_lot )

Schedules an asynchronous IPv4 lease update.

This method is a convenience wrapper around asyncSendLeaseUpdates() for propagating updates for a single lease. It is currently only used by the "lease4_server_decline" callout.

Parameters
queryPointer to the processed DHCP client message.
leasePointer to the updated lease
parking_lotPointer to the parking lot handle available for the hook point if one. This is where the DHCP client message is parked if it is parked. This method calls unpark() on this object when the asynchronous updates are completed.
Returns
Number of peers to whom the lease update has been scheduled to be sent and from which we expect a response prior to unparking the packet and sending a response to the DHCP client.

Definition at line 1284 of file ha_service.cc.

References asyncSendLeaseUpdates().

+ Here is the call graph for this function:

◆ asyncSyncCompleteNotify()

void isc::ha::HAService::asyncSyncCompleteNotify ( http::HttpClient & http_client,
const HAConfig::PeerConfigPtr & remote_config,
PostRequestCallback post_request_action )
protected

Schedules asynchronous "ha-sync-complete-notify" command to the specified server.

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

Definition at line 3022 of file ha_service.cc.

References isc::config::CONTROL_RESULT_COMMAND_UNSUPPORTED, isc::ha::ha_logger, isc::ha::HA_SYNC_COMPLETE_NOTIFY_FAILED, isc::http::HttpVersion::HTTP_11(), and LOG_ERROR.

+ 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 2105 of file ha_service.cc.

◆ asyncSyncLeases() [2/2]

void isc::ha::HAService::asyncSyncLeases ( http::HttpClient & http_client,
const HAConfig::PeerConfigPtr & remote_config,
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.
remote_configconfig of the partner 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 2122 of file ha_service.cc.

◆ asyncSyncLeasesInternal()

void isc::ha::HAService::asyncSyncLeasesInternal ( http::HttpClient & http_client,
const HAConfig::PeerConfigPtr & remote_config,
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.
remote_configconfig of the partner 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 2153 of file ha_service.cc.

References isc::ha::HA_LEASES_SYNC_FAILED, isc::ha::ha_logger, isc::http::HttpVersion::HTTP_11(), and LOG_ERROR.

+ Here is the call graph for this function:

◆ checkPermissionsClientAndListener()

void isc::ha::HAService::checkPermissionsClientAndListener ( )

Check client and(or) listener current thread permissions to perform thread pool state transition.

Exceptions
MultiThreadingInvalidOperationif the state transition is done on any of the worker threads.

Definition at line 3327 of file ha_service.cc.

References isc::ha::ha_logger, isc::ha::HA_PAUSE_CLIENT_LISTENER_FAILED, isc::ha::HA_PAUSE_CLIENT_LISTENER_ILLEGAL, and LOG_ERROR.

◆ clientCloseHandler()

void isc::ha::HAService::clientCloseHandler ( int tcp_native_fd)
protected

HttpClient close callback handler.

Passed into HttpClient calls to allow unregistration of client's TCP socket with an external monitor (such as IfaceMgr's main-thread select()).

Parameters
tcp_native_fdsocket descriptor to register

Definition at line 3289 of file ha_service.cc.

References isc::dhcp::IfaceMgr::instance().

+ Here is the call graph for this function:

◆ clientConnectHandler()

bool isc::ha::HAService::clientConnectHandler ( const boost::system::error_code & ec,
int tcp_native_fd )
protected

HttpClient connect callback handler.

Passed into HttpClient calls to allow registration of client's TCP socket with an external monitor (such as IfaceMgr's main-thread select()).

Parameters
ecError status of the ASIO connect
tcp_native_fdsocket descriptor to register
Returns
always true. Registration cannot fail, and if ec indicates a real error we want Connection logic to process it.

Definition at line 3249 of file ha_service.cc.

References isc::dhcp::IfaceMgr::instance().

+ Here is the call graph for this function:

◆ clientHandshakeHandler()

bool isc::ha::HAService::clientHandshakeHandler ( const boost::system::error_code & )
inlineprotected

HttpClient handshake callback handler.

Currently is never called and does nothing.

Returns
always true.

Definition at line 1196 of file ha_service.h.

◆ 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 1037 of file ha_service.cc.

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

+ Here is the call graph for this function:

◆ getNormalState()

int isc::ha::HAService::getNormalState ( ) const
protected

Returns normal operation state for the current configuration.

Returns
"load-balancing" for active servers in load balancing mode, "hot-standby" for active servers in hot-standby mode, "backup" for backup servers and "passive-backup" for primary server in the "passive-backup" mode.

Definition at line 1010 of file ha_service.cc.

References isc::ha::HAConfig::PeerConfig::BACKUP, config_, isc::ha::HA_BACKUP_ST, isc::ha::HA_HOT_STANDBY_ST, isc::ha::HA_LOAD_BALANCING_ST, isc::ha::HA_PASSIVE_BACKUP_ST, isc::ha::HAConfig::HOT_STANDBY, and isc::ha::HAConfig::LOAD_BALANCING.

◆ getPendingRequest()

template<typename QueryPtrType >
template int isc::ha::HAService::getPendingRequest ( const QueryPtrType & query)
protected

Get the number of scheduled requests for a given query.

Note
Currently for testing purposes only.

If there is an entry in the pending request map for the given query the entry is returned else zero is returned.

Parameters
queryPointer to the DHCP client's query.
Returns
Number of scheduled requests for the query or zero.

Definition at line 3307 of file ha_service.cc.

References isc::util::MultiThreadingMgr::instance().

+ Here is the call graph for this function:

◆ getServerType()

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

Returns HA server type used in object construction.

Definition at line 133 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 1059 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 1064 of file ha_service.cc.

◆ isMaintenanceCanceled()

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

Convenience method checking if the current state is a result of canceling the maintenance.

Returns
true if the maintenance was canceled, false otherwise.

Definition at line 1164 of file ha_service.cc.

References isc::util::StateModel::getLastEvent(), and HA_MAINTENANCE_CANCEL_EVT.

+ Here is the call graph for this function:

◆ isPartnerStateInvalid()

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

Indicates if the partner's state is invalid.

Partner's state is invalid from the local server's perspective when the remote server can't transition to this state if the configuration is consistent with the local server's configuration.

The following cases are currently checked:

  • partner in communication-recovery state but this server not in the load balancing mode,
  • partner in the hot-standby state but this server not in the hot standby mode,
  • partner in the load-balancing state but this server not in the load balancing mode.
Returns
true if the partner's state is invalid, false otherwise.

Definition at line 1169 of file ha_service.cc.

References communication_state_, config_, isc::ha::HA_COMMUNICATION_RECOVERY_ST, isc::ha::HA_HOT_STANDBY_ST, isc::ha::HA_INVALID_PARTNER_STATE_COMMUNICATION_RECOVERY, isc::ha::HA_INVALID_PARTNER_STATE_HOT_STANDBY, isc::ha::HA_INVALID_PARTNER_STATE_LOAD_BALANCING, isc::ha::HA_LOAD_BALANCING_ST, isc::ha::ha_logger, isc::ha::HAConfig::HOT_STANDBY, isc::ha::HAConfig::LOAD_BALANCING, and LOG_WARN.

◆ leaseUpdateComplete()

template<typename QueryPtrType >
bool isc::ha::HAService::leaseUpdateComplete ( QueryPtrType & query,
const hooks::ParkingLotHandlePtr & parking_lot )
protected

Handle last pending request for this query.

Search if there are pending requests for this query:

  • if there are decrement the count
  • if there were at least two return false
  • if there was none or one unpark the query
  • if there was one remove the query from the map
  • return true
Template Parameters
QueryPtrTypeType of the pointer to the DHCP client's message, i.e. Pkt4Ptr or Pkt6Ptr.
Parameters
queryPointer to the DHCP client's query.
[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.
Returns
When all lease updates are complete returns true, false otherwise.

Definition at line 1362 of file ha_service.cc.

References isc::util::MultiThreadingMgr::instance().

Referenced by asyncSendLeaseUpdate().

+ Here is the call graph for this function:

◆ localDisableDHCPService()

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

Disables local DHCP service.

Definition at line 2095 of file ha_service.cc.

◆ localEnableDHCPService()

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

Enables local DHCP service.

Definition at line 2100 of file ha_service.cc.

◆ logFailedLeaseUpdates()

void isc::ha::HAService::logFailedLeaseUpdates ( const dhcp::PktPtr & query,
const data::ConstElementPtr & args ) const
protected

Log failed lease updates.

Logs failed lease updates included in the "failed-deleted-leases" and/or "failed-leases" carried in the response to the lease6-bulk-apply command.

Parameters
queryPointer to the DHCP client's query.
argsArguments of the response. It may be null, in which case the function simply returns.

Definition at line 1621 of file ha_service.cc.

References isc::ha::HA_LEASE_UPDATE_CREATE_UPDATE_FAILED_ON_PEER, isc::ha::HA_LEASE_UPDATE_DELETE_FAILED_ON_PEER, isc::ha::ha_logger, isc::data::Element::list, LOG_INFO, isc::data::Element::map, and isc::data::Element::string.

Referenced by asyncSendLeaseUpdate().

◆ pauseClientAndListener()

void isc::ha::HAService::pauseClientAndListener ( )

Pauses client and(or) listener thread pool operations.

Suspends the client and listener thread pool event processing. Has no effect in single-threaded mode or if thread pools are not currently running. Serves as the MultiThreading critical section entry callback.

Definition at line 3373 of file ha_service.cc.

References isc::ha::ha_logger, isc::ha::HA_PAUSE_CLIENT_LISTENER_FAILED, and LOG_ERROR.

◆ pendingRequestSize()

size_t isc::ha::HAService::pendingRequestSize ( )
protected

Get the number of entries in the pending request map.

Note
Currently for testing purposes only.
Returns
Number of entries in the pending request map.

Definition at line 3296 of file ha_service.cc.

References isc::util::MultiThreadingMgr::instance().

+ Here is the call graph for this function:

◆ processContinue()

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 2738 of file ha_service.cc.

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

+ Here is the call graph for this function:

◆ processHAReset()

ConstElementPtr isc::ha::HAService::processHAReset ( )

Processes ha-reset command and returns a response.

This method processes ha-reset command which instructs the server to transition to the waiting state. A partner may send this command when the communication is re-established between the servers in the communication-recovery state and full lease database synchronization is required. This command may also be sent by an operator if the server's state is invalid and the reset operation may help correct the situation.

The ha-reset takes no arguments.

Returns
Pointer to a response to the ha-reset command.

Definition at line 1753 of file ha_service.cc.

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

+ 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, served scopes and timestamp in the following format:

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

Definition at line 1730 of file ha_service.cc.

References isc::config::CONTROL_RESULT_SUCCESS, isc::data::Element::create(), isc::config::createAnswer(), isc::data::Element::createList(), isc::data::Element::createMap(), and isc::http::HttpDateTime::rfc1123Format().

+ Here is the call graph for this function:

◆ processMaintenanceCancel()

ConstElementPtr isc::ha::HAService::processMaintenanceCancel ( )

Processes ha-maintenance-cancel command and returns a response.

The server receiving this command will try to revert the partner's state from the in-maintenance to the previous state, and also it will try to revert its own state from the partner-in-maintenance to the previous state. It effectively means canceling the request for maintenance signaled with the ha-maintenance-start command.

In some cases canceling the maintenance is no longer possible, e.g. if the server has already got into the partner-down state. Generally, canceling the maintenance is only possible if this server is in the partner-in-maintenance state and the partner is in the in-maintenance state.

Returns
Pointer to the response to the ha-maintenance-cancel.

Definition at line 2919 of file ha_service.cc.

References isc::config::CONTROL_RESULT_ERROR, isc::config::createAnswer(), isc::ha::ha_logger, isc::ha::HA_MAINTENANCE_NOTIFY_CANCEL_FAILED, isc::ha::HA_PARTNER_IN_MAINTENANCE_ST, isc::http::HttpVersion::HTTP_11(), and LOG_ERROR.

+ Here is the call graph for this function:

◆ processMaintenanceNotify()

ConstElementPtr isc::ha::HAService::processMaintenanceNotify ( const bool cancel)

Processes ha-maintenance-notify command and returns a response.

This command attempts to transition the server to the in-maintenance state if the cancel flag is set to false. Such transition is not allowed if the server is currently in one of the following states:

  • backup: because maintenance is not supported for backup servers,
  • partner-in-maintenance: because only one server is in maintenance while the partner must be in partner-in-maintenance state,
  • terminated: because the only way to resume HA service is by shutting down the server, fixing the clock skew and restarting.

If the cancel flag is set to true, the server will be transitioned from the in-maintenance state to the previous state it was in before entering the in-maintenance state.

Parameters
cancelboolean value indicating if the maintenance is being canceled with this operation. If it is set to false the maintenance is being started.
Returns
Pointer to the response to the ha-maintenance-notify.

Definition at line 2746 of file ha_service.cc.

References isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), isc::ha::HA_BACKUP_ST, isc::ha::HA_IN_MAINTENANCE_ST, isc::ha::HA_PARTNER_IN_MAINTENANCE_ST, isc::ha::HA_TERMINATED_ST, and isc::ha::stateToString().

+ Here is the call graph for this function:

◆ processMaintenanceStart()

ConstElementPtr isc::ha::HAService::processMaintenanceStart ( )

Processes ha-maintenance-start command and returns a response.

The server receiving this command will try to send the ha-maintenance-notify command to the partner to instruct the partner to transition to the in-maintenance state. In this state the partner will not respond to any DHCP queries. Next, this server will transition to the partner-in-maintenance state and therefore will start responding to all DHCP queries. If the partner responds to the ha-maintenance-notify with an error, this server won't transition to the partner-in-maintenance state and signal an error to the caller. If the partner is unavailable, this server will directly transition to the partner-down state.

This method creates its own instances of the HttpClient and IOService and invokes IOService::run().

Returns
Pointer to the response to the ha-maintenance-start.

Definition at line 2782 of file ha_service.cc.

References isc::config::CONTROL_RESULT_ERROR, isc::config::createAnswer(), isc::ha::HA_BACKUP_ST, isc::ha::HA_IN_MAINTENANCE_ST, isc::ha::ha_logger, isc::ha::HA_MAINTENANCE_NOTIFY_FAILED, isc::ha::HA_PARTNER_IN_MAINTENANCE_ST, isc::ha::HA_TERMINATED_ST, isc::http::HttpVersion::HTTP_11(), LOG_ERROR, and isc::ha::stateToString().

+ 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 2725 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:

◆ processStatusGet()

ConstElementPtr isc::ha::HAService::processStatusGet ( ) const

Processes status-get command and returns a response.

HAImpl::commandProcessed calls this to add information about the HA servers status into the status-get response.

Definition at line 1673 of file ha_service.cc.

References isc::data::Element::create(), isc::data::Element::createList(), isc::data::Element::createMap(), isc::util::ptimeToText(), and isc::ha::stateToString().

+ Here is the call graph for this function:

◆ processSyncCompleteNotify()

ConstElementPtr isc::ha::HAService::processSyncCompleteNotify ( const unsigned int origin_id)

Process ha-sync-complete-notify command and returns a response.

A server finishing a lease database synchronization may notify its partner about it with this command. This function implements reception and processing of the command.

It enables DHCP service unless the server is in the partner-down state. In this state, the server will first have to check connectivity with the partner and transition to a state in which it will send lease updates.

Parameters
origin_ida numeric value of the origin created from the HAService identifier to enable the DHCP service.
Returns
Pointer to the response to the ha-sync-complete-notify command.

Definition at line 3105 of file ha_service.cc.

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

+ 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 2369 of file ha_service.cc.

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

+ Here is the call graph for this function:

◆ resumeClientAndListener()

void isc::ha::HAService::resumeClientAndListener ( )

Resumes client and(or) listener thread pool operations.

Resumes the client and listener thread pool event processing. Has no effect in single-threaded mode or if thread pools are not currently paused. Serves as the MultiThreading critical section exit callback.

Definition at line 3391 of file ha_service.cc.

References isc::ha::ha_logger, isc::ha::HA_RESUME_CLIENT_LISTENER_FAILED, and LOG_ERROR.

◆ 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 1920 of file ha_service.cc.

◆ sendHAReset()

bool isc::ha::HAService::sendHAReset ( )
protected

Sends ha-reset command to partner synchronously.

This method attempts to send ha-reset command to the active partner synchronously. It may be invoked when the communication with the partner is re-established after temporary failure. It causes the partner to transition the partner to the waiting state. This effectively means that the partner will synchronize its lease database with this server.

This method creates its own instances of the HttpClient and IOService and invokes IOService::run().

Returns
true if the command was sent successfully, false otherwise.

Definition at line 2702 of file ha_service.cc.

◆ sendLeaseUpdatesFromBacklog()

bool isc::ha::HAService::sendLeaseUpdatesFromBacklog ( )
protected

Attempts to send all lease updates from the backlog synchronously.

This method is called upon exiting communication-recovery state and before entering the load-balancing state. It ensures that all outstanding lease updates are sent to the partner before the server can continue normal operation in the load-balancing state. In order to prevent collisions between new allocations and outstanding updates this method is synchronous.

This method creates its own instances of the HttpClient and IOService and invokes IOService::run().

Returns
boolean value indicating that the lease updates were delivered successfully (when true) or unsuccessfully (when false).

Definition at line 2601 of file ha_service.cc.

References isc::ha::HA_LEASES_BACKLOG_NOTHING_TO_SEND, isc::ha::HA_LEASES_BACKLOG_START, isc::ha::HA_LEASES_BACKLOG_SUCCESS, isc::ha::ha_logger, LOG_INFO, and isc::util::Stopwatch::stop().

+ Here is the call graph for this function:

◆ 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 1049 of file ha_service.cc.

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

+ Here is the call graph for this function:

◆ serveFailoverScopes()

void isc::ha::HAService::serveFailoverScopes ( )

Instructs the HA service to serve failover 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 1054 of file ha_service.cc.

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

+ 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 1121 of file ha_service.cc.

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

◆ shouldQueueLeaseUpdates()

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

Checks if the lease updates should be queued.

If lease updates should be sent to the partner but the server is in the communication-recovery state (temporarily unavailable) the lease updates should be queued and later sent when the communication is re-established. This function checks if the server is in the state in which lease updates should be queued.

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

Definition at line 1608 of file ha_service.cc.

References isc::ha::HA_COMMUNICATION_RECOVERY_ST.

Referenced by asyncSendLeaseUpdates(), and asyncSendLeaseUpdates().

◆ 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 1576 of file ha_service.cc.

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

Referenced by asyncSendLeaseUpdates(), asyncSendLeaseUpdates(), and verboseTransition().

◆ shouldTerminate()

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

Indicates if the server should transition to the terminated state.

There are two reasons for the server to transition to the terminated state. First, when the clock skew being too high. Second, when the server monitors rejected lease updates and the maximum configured rejected updates have been exceeded.

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.

If the clock skew is acceptable the function can cause the transition to the terminated state when the number of recorded rejected lease updates exceeded the configured threshold.

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

Definition at line 1148 of file ha_service.cc.

References communication_state_.

◆ socketReadyHandler()

void isc::ha::HAService::socketReadyHandler ( int tcp_native_fd)
protected

IfaceMgr external socket ready callback handler.

IfaceMgr invokes this call back when a registered socket has been flagged as ready to read. It is installed by the invocation to register the socket with IfaceMgr made in clientConnectHandler.

The handler calls http::HttpClient::closeIfOutOfBand() to catch and close any sockets that have gone ready outside of transactions.

We do this in case the other peer closed the socket (e.g. idle timeout), as this will cause the socket to appear ready to read to the IfaceMgr::select(). If this happens while no transactions are in progress, we won't have anything to deal with the socket event. This causes IfaceMgr::select() to endlessly interrupt on the socket.

Parameters
tcp_native_fdsocket descriptor of the ready socket

Definition at line 3280 of file ha_service.cc.

◆ startClientAndListener()

void isc::ha::HAService::startClientAndListener ( )

Start the client and(or) listener instances.

When HA+MT is enabled it starts the client's thread pool and the dedicated listener thread pool, if the listener exists. It registers pauseClientAndListener() and resumeClientAndListener() as the MultiThreading critical section entry and exit callbacks, respectively.

Definition at line 3356 of file ha_service.cc.

References isc::util::MultiThreadingMgr::instance().

+ Here is the call graph for this function:

◆ startHeartbeat()

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

Unconditionally starts one heartbeat to a peer.

Definition at line 1927 of file ha_service.cc.

◆ stopClientAndListener()

void isc::ha::HAService::stopClientAndListener ( )

Stop the client and(or) listener instances.

It unregisters the MultiThreading critical section callbacks, closes all connections and stops the thread pools for the client and listener, if they exist.

Definition at line 3410 of file ha_service.cc.

References isc::util::MultiThreadingMgr::instance().

Referenced by ~HAService().

+ Here is the call graph for this function:

◆ synchronize()

int isc::ha::HAService::synchronize ( std::string & status_message,
const HAConfig::PeerConfigPtr & remote_config,
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. It sends ha-sync-complete-notify command to the partner when the synchronization completes successfully. If the partner does not support this command, it sends dhcp-enable command to enable the DHCP service on the partner.

This method creates its own instances of the HttpClient and IOService and invokes IOService::run().

Parameters
[out]status_messagestatus message in textual form.
remote_configconfig 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 2388 of file ha_service.cc.

References isc::config::CONTROL_RESULT_COMMAND_UNSUPPORTED, isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, isc::ha::ha_logger, isc::ha::HA_SYNC_FAILED, isc::ha::HA_SYNC_START, isc::ha::HA_SYNC_SUCCESSFUL, LOG_ERROR, LOG_INFO, and isc::util::Stopwatch::stop().

+ 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 1026 of file ha_service.cc.

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

+ Here is the call graph for this function:

◆ updatePendingRequest()

template<typename QueryPtrType >
void isc::ha::HAService::updatePendingRequest ( QueryPtrType & query)
protected

Update pending request counter for this query.

Template Parameters
QueryPtrTypeType of the pointer to the DHCP client's message, i.e. Pkt4Ptr or Pkt6Ptr.
Parameters
queryPointer to the DHCP client's query.

Definition at line 1397 of file ha_service.cc.

References isc::util::MultiThreadingMgr::instance().

+ 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,
int & rcode )
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.
[out]rcoderesult found in the response.
Returns
Pointer to the response arguments.
Exceptions
CtrlChannelErrorif response is invalid or contains an error.
CommandUnsupportedErrorif sent command is unsupported.
ConflictErrorif the response comprises the conflict status code or it contains an empty status code in response to the lease6-bulk-apply and there are leases with the conflict status codes listed in the response.

Definition at line 3126 of file ha_service.cc.

References isc::config::CONTROL_RESULT, isc::config::CONTROL_RESULT_COMMAND_UNSUPPORTED, isc::config::CONTROL_RESULT_CONFLICT, isc::config::CONTROL_RESULT_EMPTY, isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, isc::config::CONTROL_TEXT, isc::data::Element::create(), isc::data::Element::createList(), isc::data::Element::createMap(), isc::data::Element::integer, isc_throw, isc::data::Element::list, isc::data::Element::map, isc::config::parseAnswer(), and isc::data::Element::string.

Referenced by asyncSendLeaseUpdate().

+ Here is the call graph for this function:

Member Data Documentation

◆ client_

http::HttpClientPtr isc::ha::HAService::client_
protected

HTTP client instance used to send HA commands and lease updates.

Definition at line 1244 of file ha_service.h.

Referenced by HAService(), and asyncSendLeaseUpdate().

◆ communication_state_

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

◆ config_

◆ HA_CONTROL_RESULT_MAINTENANCE_NOT_ALLOWED

const int isc::ha::HAService::HA_CONTROL_RESULT_MAINTENANCE_NOT_ALLOWED = 1001
static

Control result returned in response to ha-maintenance-notify.

Definition at line 81 of file ha_service.h.

◆ HA_HEARTBEAT_COMPLETE_EVT

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

Finished heartbeat command.

Definition at line 56 of file ha_service.h.

◆ 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 59 of file ha_service.h.

Referenced by asyncSendLeaseUpdate().

◆ HA_MAINTENANCE_CANCEL_EVT

const int isc::ha::HAService::HA_MAINTENANCE_CANCEL_EVT = SM_DERIVED_EVENT_MIN + 7
static

ha-maintenance-cancel command received.

Definition at line 74 of file ha_service.h.

Referenced by isMaintenanceCanceled().

◆ HA_MAINTENANCE_NOTIFY_EVT

const int isc::ha::HAService::HA_MAINTENANCE_NOTIFY_EVT = SM_DERIVED_EVENT_MIN + 5
static

ha-maintenance-notify command received.

Definition at line 68 of file ha_service.h.

◆ HA_MAINTENANCE_START_EVT

const int isc::ha::HAService::HA_MAINTENANCE_START_EVT = SM_DERIVED_EVENT_MIN + 6
static

ha-maintenance-start command received.

Definition at line 71 of file ha_service.h.

◆ HA_SYNCED_PARTNER_UNAVAILABLE_EVT

const int isc::ha::HAService::HA_SYNCED_PARTNER_UNAVAILABLE_EVT = SM_DERIVED_EVENT_MIN + 8
static

The heartbeat command failed after receiving ha-sync-complete-notify command from the partner.

Definition at line 78 of file ha_service.h.

◆ 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 62 of file ha_service.h.

◆ HA_SYNCING_SUCCEEDED_EVT

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

Lease database synchronization succeeded.

Definition at line 65 of file ha_service.h.

◆ HA_WAITING_TO_TERMINATED_ST_DELAY_MINUTES

const int isc::ha::HAService::HA_WAITING_TO_TERMINATED_ST_DELAY_MINUTES = 10
static

A delay in minutes to transition from the waiting to terminated state when the partner remains in terminated state.

Definition at line 85 of file ha_service.h.

◆ id_

unsigned int isc::ha::HAService::id_
protected

Unique service id.

Definition at line 1228 of file ha_service.h.

◆ 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 1232 of file ha_service.h.

Referenced by HAService().

◆ lease_sync_filter_

LeaseSyncFilter isc::ha::HAService::lease_sync_filter_
protected

Lease synchronization filter used in hub-and-spoke model.

Definition at line 1257 of file ha_service.h.

◆ lease_update_backlog_

LeaseUpdateBacklog isc::ha::HAService::lease_update_backlog_
protected

Backlog of DHCP lease updates.

Unsent lease updates are stored in this queue when the server is in the communication-recovery state and is temporarily unable to send lease updates to the partner.

Definition at line 1371 of file ha_service.h.

Referenced by asyncSendLeaseUpdates(), and asyncSendLeaseUpdates().

◆ listener_

config::CmdHttpListenerPtr isc::ha::HAService::listener_
protected

HTTP listener instance used to receive and respond to HA commands and lease updates.

Definition at line 1248 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 1235 of file ha_service.h.

Referenced by HAService(), ~HAService(), adjustNetworkState(), and shouldPartnerDown().

◆ query_filter_

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

Selects queries to be processed/dropped.

Definition at line 1254 of file ha_service.h.

Referenced by serveDefaultScopes(), and serveFailoverScopes().

◆ server_type_

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

DHCP server type.

Definition at line 1241 of file ha_service.h.

Referenced by getServerType().

◆ sync_complete_notified_

bool isc::ha::HAService::sync_complete_notified_
protected

An indicator that a partner sent ha-sync-complete-notify command.

This indicator is set when the partner finished synchronization. It blocks enabling DHCP service in the partner-down state. The server will first send heartbeat to the partner to ensure that the communication is re-established. If the communication remains broken, the server clears this flag and enables DHCP service to continue the service.

Definition at line 1380 of file ha_service.h.


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