28 #include <boost/noncopyable.hpp> 29 #include <boost/shared_ptr.hpp> 91 typedef std::function<void(const bool, const std::string&, const bool)>
PostSyncCallback;
444 template<
typename QueryPtrType>
445 bool inScopeInternal(QueryPtrType& query);
592 template<
typename QueryPtrType>
710 const std::string& server_name,
711 const unsigned int max_period,
712 PostRequestCallback post_request_action);
724 const std::string& server_name,
725 PostRequestCallback post_request_action);
801 const std::string& server_name,
802 const unsigned int max_period,
804 PostSyncCallback post_sync_action,
805 const bool dhcp_disabled =
false);
834 const std::string& server_name,
835 const unsigned int max_period,
837 PostSyncCallback post_sync_action,
838 const bool dhcp_disabled);
862 const unsigned int max_period);
886 int synchronize(std::string& status_message,
const std::string& server_name,
887 const unsigned int max_period);
909 PostRequestCallback post_request_action);
934 PostRequestCallback post_request_action);
1040 const std::string& server_name,
1041 PostRequestCallback post_request_action);
1198 template<
typename QueryPtrType>
1207 template<
typename QueryPtrType>
1225 template<
typename QueryPtrType>
1247 template<
typename QueryPtrType>
1248 bool leaseUpdateCompleteInternal(QueryPtrType& query,
1258 template<
typename QueryPtrType>
1259 void updatePendingRequestInternal(QueryPtrType& query);
1271 template<
typename QueryPtrType>
1272 int getPendingRequestInternal(
const QueryPtrType& query);
1285 std::map<boost::shared_ptr<dhcp::Pkt>,
int> pending_requests_;
config::CmdHttpListenerPtr listener_
HTTP listener instance used to receive and respond to HA commands and lease updates.
static const int HA_CONTROL_RESULT_MAINTENANCE_NOT_ALLOWED
Control result returned in response to ha-maintenance-notify.
virtual void defineStates()
Defines states of the HA service.
Implements a finite state machine.
void serveDefaultScopes()
Instructs the HA service to serve default scopes.
data::ConstElementPtr processHAReset()
Processes ha-reset command and returns a response.
void pauseClientAndListener()
Pauses client and(or) listener thread pool operations.
bool leaseUpdateComplete(QueryPtrType &query, const hooks::ParkingLotHandlePtr &parking_lot)
Handle last pending request for this query.
static const int HA_MAINTENANCE_CANCEL_EVT
ha-maintenance-cancel command received.
void readyStateHandler()
Handler for "ready" state.
size_t pendingRequestSize()
Get the number of entries in the pending request map.
data::ConstElementPtr processScopes(const std::vector< std::string > &scopes)
Processes ha-scopes command and returns a response.
void scheduleHeartbeat()
Schedules asynchronous heartbeat to a peer if it is not scheduled.
void asyncEnableDHCPService(http::HttpClient &http_client, const std::string &server_name, PostRequestCallback post_request_action)
Schedules asynchronous "dhcp-enable" command to the specified server.
bool unpause()
Unpauses the HA state machine with logging.
void passiveBackupStateHandler()
Handler for "passive-backup" state.
void asyncSyncLeases()
Asynchronously reads leases from a peer and updates local lease database.
void asyncSyncCompleteNotify(http::HttpClient &http_client, const std::string &server_name, PostRequestCallback post_request_action)
Schedules asynchronous "ha-sync-complete-notify" command to the specified server. ...
data::ConstElementPtr processHeartbeat()
Processes ha-heartbeat command and returns a response.
QueryFilter query_filter_
Selects queries to be processed/dropped.
boost::shared_ptr< CmdHttpListener > CmdHttpListenerPtr
Defines a shared pointer to CmdHttpListener.
LeaseUpdateBacklog lease_update_backlog_
Backlog of DHCP lease updates.
CommunicationStatePtr communication_state_
Holds communication state with a peer.
virtual void verifyEvents()
Verifies events used by the HA service.
static const int HA_SYNCING_SUCCEEDED_EVT
Lease database synchronization succeeded.
bool clientConnectHandler(const boost::system::error_code &ec, int tcp_native_fd)
HttpClient connect callback handler.
HAServerType server_type_
DHCP server type.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
static const int HA_MAINTENANCE_NOTIFY_EVT
ha-maintenance-notify command received.
data::ConstElementPtr processMaintenanceCancel()
Processes ha-maintenance-cancel command and returns a response.
void waitingStateHandler()
Handler for "waiting" state.
void updatePendingRequest(QueryPtrType &query)
Update pending request counter for this query.
void partnerInMaintenanceStateHandler()
Handler for "partner-in-maintenance" state.
HAServerType
Lists possible server types for which HA service is created.
virtual ~HAService()
Destructor.
bool shouldTerminate() const
Indicates if the server should transition to the terminated state.
void logFailedLeaseUpdates(const dhcp::PktPtr &query, const data::ConstElementPtr &args) const
Log failed lease updates.
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
dhcp::NetworkStatePtr network_state_
Pointer to the state of the DHCP service (enabled/disabled).
static const int HA_MAINTENANCE_START_EVT
ha-maintenance-start command received.
asiolink::IOServicePtr io_service_
Pointer to the IO service object shared between this hooks library and the DHCP server.
data::ConstElementPtr processContinue()
Processes ha-continue command and returns a response.
HAServerType getServerType() const
Returns HA server type used in object construction.
DHCP query filtering class.
void resumeClientAndListener()
Resumes client and(or) listener thread pool operations.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
void checkPermissionsClientAndListener()
Check client and(or) listener current thread permissions to perform thread pool state transition...
data::ConstElementPtr processSyncCompleteNotify()
Process ha-sync-complete-notify command and returns a response.
static const int HA_HEARTBEAT_COMPLETE_EVT
Finished heartbeat command.
static const int HA_LEASE_UPDATES_COMPLETE_EVT
Finished lease updates commands.
HAService(const asiolink::IOServicePtr &io_service, const dhcp::NetworkStatePtr &network_state, const HAConfigPtr &config, const HAServerType &server_type=HAServerType::DHCPv4)
Constructor.
void partnerDownStateHandler()
Handler for "partner-down" state.
void syncingStateHandler()
Handler for "syncing" state.
static const int HA_SYNCED_PARTNER_UNAVAILABLE_EVT
The heartbeat command failed after receiving ha-sync-complete-notify command from the partner...
boost::shared_ptr< HttpResponse > HttpResponsePtr
Pointer to the HttpResponse object.
void asyncSendHeartbeat()
Starts asynchronous heartbeat to a peer.
boost::shared_ptr< HAService > HAServicePtr
Pointer to the HAService class.
boost::shared_ptr< Lease4Collection > Lease4CollectionPtr
A shared pointer to the collection of IPv4 leases.
void inMaintenanceStateHandler()
Handler for the "in-maintenance" state.
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.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< const Element > ConstElementPtr
data::ConstElementPtr processMaintenanceNotify(const bool cancel)
Processes ha-maintenance-notify command and returns a response.
bool inScope(dhcp::Pkt4Ptr &query4)
Checks if the DHCPv4 query should be processed by this server.
void terminatedStateHandler()
Handler for "terminated" state.
static const int SM_DERIVED_EVENT_MIN
Value at which custom events in a derived class should begin.
void stopClientAndListener()
Stop the client and(or) listener instances.
void localDisableDHCPService()
Disables local DHCP service.
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
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.
void adjustNetworkState()
Enables or disables network state depending on the served scopes.
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.
std::function< void(const bool, const std::string &, const bool)> PostSyncCallback
Callback invoked when lease database synchronization is complete.
void communicationRecoveryHandler()
Handler for the "communication-recovery" state.
Defines the logger used by the top-level component of kea-lfc.
bool shouldPartnerDown() const
Indicates if the server should transition to the partner down state.
data::ConstElementPtr processMaintenanceStart()
Processes ha-maintenance-start command and returns a response.
HAConfigPtr config_
Pointer to the HA hooks library configuration.
bool isMaintenanceCanceled() const
Convenience method checking if the current state is a result of canceling the maintenance.
void startHeartbeat()
Unconditionally starts one heartbeat to a peer.
data::ConstElementPtr processStatusGet() const
Processes status-get command and returns a response.
bool sync_complete_notified_
An indicator that a partner sent ha-sync-complete-notify command.
void startClientAndListener()
Start the client and(or) listener instances.
http::HttpClientPtr client_
HTTP client instance used to send HA commands and lease updates.
void normalStateHandler()
Handler for the "hot-standby" and "load-balancing" states.
High availability service.
bool sendLeaseUpdatesFromBacklog()
Attempts to send all lease updates from the backlog synchronously.
void localEnableDHCPService()
Enables local DHCP service.
virtual void defineEvents()
Defines events used by the HA service.
int getPartnerState() const
Returns last known state of the partner.
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
boost::shared_ptr< NetworkState > NetworkStatePtr
Pointer to the NetworkState object.
bool isPartnerStateInvalid() const
Indicates if the partner's state is invalid.
bool shouldSendLeaseUpdates(const HAConfig::PeerConfigPtr &peer_config) const
Checks if the lease updates should be sent as result of leases allocation or release.
void backupStateHandler()
Handler for the "backup" state.
int getPendingRequest(const QueryPtrType &query)
Get the number of scheduled requests for a given query.
static const int HA_SYNCING_FAILED_EVT
Lease database synchronization failed.
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.
boost::shared_ptr< ParkingLotHandle > ParkingLotHandlePtr
Pointer to the parking lot handle.
void asyncSendHAReset(http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, PostRequestCallback post_request_action)
Sends ha-reset command to partner asynchronously.
void socketReadyHandler(int tcp_native_fd)
IfaceMgr external socket ready callback handler.
This file defines the class StateModel.
int getNormalState() const
Returns normal operation state for the current configuration.
void conditionalLogPausedState() const
Logs if the server is paused in the current state.
data::ConstElementPtr processSynchronize(const std::string &server_name, const unsigned int max_period)
Processes ha-sync command and returns a response.
Queue holding a backlog of unsent lease updates.
data::ConstElementPtr verifyAsyncResponse(const http::HttpResponsePtr &response, int &rcode)
Checks if the response is valid or contains an error.
boost::shared_ptr< CommunicationState > CommunicationStatePtr
Type of the pointer to the CommunicationState object.
void clientCloseHandler(int tcp_native_fd)
HttpClient close callback handler.
void verboseTransition(const unsigned state)
Transitions to a desired state and logs it.
bool shouldQueueLeaseUpdates(const HAConfig::PeerConfigPtr &peer_config) const
Checks if the lease updates should be queued.
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
bool sendHAReset()
Sends ha-reset command to partner synchronously.
int synchronize(std::string &status_message, const std::string &server_name, const unsigned int max_period)
Synchronizes lease database with a partner.
bool clientHandshakeHandler(const boost::system::error_code &)
HttpClient handshake callback handler.
boost::shared_ptr< HttpClient > HttpClientPtr
Defines a pointer to an HttpClient instance.
boost::shared_ptr< PeerConfig > PeerConfigPtr
Pointer to the server's configuration.
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.
void asyncSendLeaseUpdatesFromBacklog(http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, PostRequestCallback post_request_action)
Sends lease updates from backlog to partner asynchronously.