45 auto configs =
config_->getAll();
46 for (
auto id = 0;
id < configs.size(); ++id) {
48 auto service = boost::make_shared<HAService>(
id,
io_service_, network_state,
49 configs[
id], server_type);
50 for (
auto const& peer_config : configs[id]->getAllServersConfig()) {
51 services_->map(peer_config.first, service);
57 for (
auto const& service :
services_->getAll()) {
58 service->startClientAndListener();
64 for (
auto const& service :
services_->getAll()) {
67 service->stopClientAndListener();
83 callout_handle.getArgument(
"query4", query4);
101 }
catch (
const std::exception& ex) {
104 .arg(query4->getRemoteAddr().toText())
105 .arg(query4->getLocalAddr().toText())
106 .arg(query4->getIface())
119 if (!
services_->get()->inScope(query4)) {
121 .arg(query4->getLabel());
143 callout_handle.getArgument(
"query4", query4);
146 callout_handle.getArgument(
"subnet4", subnet4);
156 .arg(query4->getLabel());
166 std::string server_name;
169 if (server_name.empty()) {
171 .arg(query4->getLabel())
172 .arg(subnet4->toText());
180 .arg(query4->getLabel())
181 .arg(subnet4->toText());
188 auto service =
services_->get(server_name);
191 .arg(query4->getLabel())
201 if (!service->inScope(query4)) {
203 .arg(query4->getLabel())
212 callout_handle.setContext(
"ha-server-name", server_name);
225 callout_handle.getArgument(
"query4", query4);
227 callout_handle.getArgument(
"leases4", leases4);
228 callout_handle.getArgument(
"deleted_leases4", deleted_leases4);
231 if (leases4->empty() && deleted_leases4->empty()) {
233 .arg(query4->getLabel());
247 std::string server_name;
248 callout_handle.getContext(
"ha-server-name", server_name);
249 config =
config_->get(server_name);
253 if (!config || !service) {
257 }
catch (
const std::exception& ex) {
259 .arg(query4->getLabel())
269 if (!config->amSendingLeaseUpdates()) {
281 parking_lot->reference(query4);
288 if (service->asyncSendLeaseUpdates(query4, leases4, deleted_leases4, parking_lot) == 0) {
290 parking_lot->dereference(query4);
295 parking_lot->dereference(query4);
309 size_t peers_to_update = 0;
314 if (!
config_->get()->amSendingLeaseUpdates()) {
317 callout_handle.setArgument(
"peers_to_update", peers_to_update);
326 callout_handle.getArgument(
"query4", query4);
329 callout_handle.getArgument(
"lease4", lease4);
334 peers_to_update =
services_->get()->asyncSendSingleLeaseUpdate(query4, lease4, 0);
335 callout_handle.setArgument(
"peers_to_update", peers_to_update);
347 callout_handle.getArgument(
"query6", query6);
365 }
catch (
const std::exception& ex) {
368 .arg(query6->getRemoteAddr().toText())
369 .arg(query6->getLocalAddr().toText())
370 .arg(query6->getIface())
383 if (!
services_->get()->inScope(query6)) {
385 .arg(query6->getLabel());
407 callout_handle.getArgument(
"query6", query6);
410 callout_handle.getArgument(
"subnet6", subnet6);
420 .arg(query6->getLabel());
430 std::string server_name;
433 if (server_name.empty()) {
435 .arg(query6->getLabel())
436 .arg(subnet6->toText());
444 .arg(query6->getLabel())
445 .arg(subnet6->toText());
452 auto service =
services_->get(server_name);
455 .arg(query6->getLabel())
465 if (!service->inScope(query6)) {
467 .arg(query6->getLabel())
476 callout_handle.setContext(
"ha-server-name", server_name);
489 callout_handle.getArgument(
"query6", query6);
491 callout_handle.getArgument(
"leases6", leases6);
492 callout_handle.getArgument(
"deleted_leases6", deleted_leases6);
495 if (leases6->empty() && deleted_leases6->empty()) {
497 .arg(query6->getLabel());
505 std::string server_name;
506 callout_handle.getContext(
"ha-server-name", server_name);
507 config =
config_->get(server_name);
510 if (!config || !service) {
511 isc_throw(
Unexpected,
"relationship not found for the ha-server-name='" << server_name <<
"'");
514 }
catch (
const std::exception& ex) {
516 .arg(query6->getLabel())
526 if (!config->amSendingLeaseUpdates()) {
538 parking_lot->reference(query6);
545 if (service->asyncSendLeaseUpdates(query6, leases6, deleted_leases6, parking_lot) == 0) {
547 parking_lot->dereference(query6);
552 parking_lot->dereference(query6);
564 std::string command_name;
565 callout_handle.getArgument(
"name", command_name);
566 if (command_name ==
"status-get") {
569 callout_handle.getArgument(
"response", response);
570 if (!response || (response->getType() !=
Element::map)) {
575 if (!resp_args || (resp_args->getType() !=
Element::map)) {
580 boost::const_pointer_cast<Element>(resp_args);
584 for (
auto const& service :
services_->getAll()) {
587 ha_relationship->set(
"ha-servers", ha_servers);
589 ha_relationships->add(ha_relationship);
590 mutable_resp_args->set(
"high-availability", ha_relationships);
599 callout_handle.getArgument(
"command", command);
609 }
catch (
const std::exception& ex) {
613 callout_handle.setArgument(
"response", response);
619 callout_handle.setArgument(
"response", response);
626 callout_handle.getArgument(
"command", command);
633 unsigned int max_period_value = 0;
649 server_name = args->get(
"server-name");
664 (max_period->intValue() <= 0)) {
665 isc_throw(
BadValue,
"'max-period' must be a positive integer in the 'ha-sync' command");
668 max_period_value =
static_cast<unsigned int>(max_period->intValue());
673 }
catch (
const std::exception& ex) {
677 callout_handle.setArgument(
"response", response);
682 ConstElementPtr response = service->processSynchronize(server_name->stringValue(),
684 callout_handle.setArgument(
"response", response);
691 callout_handle.getArgument(
"command", command);
698 std::vector<std::string> scopes_vector;
723 for (
size_t i = 0; i < scopes->size(); ++i) {
728 scopes_vector.push_back(scope->stringValue());
733 }
catch (
const std::exception& ex) {
737 callout_handle.setArgument(
"response", response);
743 callout_handle.setArgument(
"response", response);
750 callout_handle.getArgument(
"command", command);
760 }
catch (
const std::exception& ex) {
764 callout_handle.setArgument(
"response", response);
768 callout_handle.setArgument(
"response", response);
775 callout_handle.getArgument(
"command", command);
785 isc_throw(
BadValue,
"'cancel' is mandatory for the 'ha-maintenance-notify' command");
789 isc_throw(
BadValue,
"'cancel' must be a boolean in the 'ha-maintenance-notify' command");
794 ConstElementPtr response = service->processMaintenanceNotify(cancel_op->boolValue());
795 callout_handle.setArgument(
"response", response);
797 }
catch (
const std::exception& ex) {
801 callout_handle.setArgument(
"response", response);
808 for (
auto const& service :
services_->getAll()) {
809 response = service->processMaintenanceStart();
816 callout_handle.setArgument(
"response", response);
822 for (
auto const& service :
services_->getAll()) {
823 response = service->processMaintenanceCancel();
825 callout_handle.setArgument(
"response", response);
832 callout_handle.getArgument(
"command", command);
842 }
catch (
const std::exception& ex) {
846 callout_handle.setArgument(
"response", response);
851 callout_handle.setArgument(
"response", response);
858 callout_handle.getArgument(
"command", command);
868 auto origin_id = args->get(
"origin-id");
869 auto origin = args->get(
"origin");
874 isc_throw(
BadValue,
"'origin-id' must be an integer in the 'ha-sync-complete-notify' command");
876 origin_id_value = origin_id->intValue();
880 isc_throw(
BadValue,
"'origin' must be an integer in the 'ha-sync-complete-notify' command");
882 origin_id_value = origin->intValue();
888 }
catch (
const std::exception& ex) {
892 callout_handle.setArgument(
"response", response);
896 ConstElementPtr response = service->processSyncCompleteNotify(origin_id_value);
897 callout_handle.setArgument(
"response", response);
906 isc_throw(
BadValue,
"arguments in the '" << command_name <<
"' command are not a map");
909 auto server_name = args->get(
"server-name");
913 isc_throw(
BadValue,
"'server-name' must be a string in the '" << command_name <<
"' command");
915 service =
services_->get(server_name->stringValue());
918 <<
" 'server-name'");
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown when an unexpected error condition occurs.
The IOService class is a wrapper for the ASIO io_service class.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
static const unsigned int HA_REMOTE_COMMAND
The network state is being altered by a "dhcp-disable" or "dhcp-enable" command sent by a HA partner.
Exception thrown during option unpacking This exception is thrown when an error has occurred,...
static HAConfigMapperPtr parse(const data::ConstElementPtr &config)
Parses HA configuration.
static std::string getSubnetServerName(const dhcp::ConstSubnetPtr &subnet)
Convenience function extracting a value of the ha-server-name parameter from a subnet context.
static std::string HAModeToString(const HAMode &ha_mode)
Returns HA mode name.
void scopesHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-scopes command.
void continueHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-continue command.
HAConfigMapperPtr config_
Holds parsed configuration.
void syncCompleteNotifyHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-sync-complete-notify command.
HAServicePtr getHAServiceByServerName(const std::string &command_name, data::ConstElementPtr args) const
Attempts to get an HAService by server name.
HAServiceMapperPtr services_
Pointer to the high availability services (state machines).
void startServices(const dhcp::NetworkStatePtr &network_state, const HAServerType &server_type)
Creates high availability services using current configuration.
void subnet4Select(hooks::CalloutHandle &callout_handle)
Implementation of the "subnet4_select" callout.
void configure(const data::ConstElementPtr &input_config)
Parses configuration.
void maintenanceCancelHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-maintenance-cancel command.
void haResetHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-reset command.
void maintenanceNotifyHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-maintenance-notify command.
void synchronizeHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-sync command.
void maintenanceStartHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-maintenance-start command.
isc::asiolink::IOServicePtr io_service_
The hook I/O service.
void leases4Committed(hooks::CalloutHandle &callout_handle)
Implementation of the "leases4_committed" callout.
void buffer4Receive(hooks::CalloutHandle &callout_handle)
Implementation of the "buffer4_receive" callout.
void buffer6Receive(hooks::CalloutHandle &callout_handle)
Implementation of the "buffer6_receive" callout.
void commandProcessed(hooks::CalloutHandle &callout_handle)
Implementation of the "command_processed" callout.
void leases6Committed(hooks::CalloutHandle &callout_handle)
Implementation of the "leases6_committed" callout.
void subnet6Select(hooks::CalloutHandle &callout_handle)
Implementation of the "subnet6_select" callout.
void lease4ServerDecline(hooks::CalloutHandle &callout_handle)
Implementation of the "lease4_server_decline" callout.
void heartbeatHandler(hooks::CalloutHandle &callout_handle)
Implements handle for the heartbeat command.
Per-packet callout handle.
@ NEXT_STEP_PARK
park the packet
@ NEXT_STEP_CONTINUE
continue normally
@ NEXT_STEP_DROP
drop the packet
@ NEXT_STEP_SKIP
skip the next processing step
static StatsMgr & instance()
Statistics Manager accessor method.
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
std::string parseCommandWithArgs(ConstElementPtr &arg, ConstElementPtr command)
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
std::string parseCommand(ConstElementPtr &arg, ConstElementPtr command)
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< Lease4Collection > Lease4CollectionPtr
A shared pointer to the collection of IPv4 leases.
boost::shared_ptr< const Subnet6 > ConstSubnet6Ptr
A const pointer to a Subnet6 object.
boost::shared_ptr< const Subnet4 > ConstSubnet4Ptr
A const pointer to a Subnet4 object.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< NetworkState > NetworkStatePtr
Pointer to the NetworkState object.
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
const isc::log::MessageID HA_BUFFER4_RECEIVE_UNPACK_FAILED
const isc::log::MessageID HA_SUBNET4_SELECT_NO_SUBNET_SELECTED
const isc::log::MessageID HA_LEASES6_COMMITTED_NOTHING_TO_UPDATE
const isc::log::MessageID HA_LEASES6_COMMITTED_NO_RELATIONSHIP
const isc::log::MessageID HA_BUFFER4_RECEIVE_PACKET_OPTIONS_SKIPPED
const isc::log::MessageID HA_BUFFER6_RECEIVE_UNPACK_FAILED
HARelationshipMapper< HAService > HAServiceMapper
Type of an object mapping HAService to relationships.
const isc::log::MessageID HA_SUBNET6_SELECT_NO_SUBNET_SELECTED
const isc::log::MessageID HA_SUBNET6_SELECT_INVALID_HA_SERVER_NAME
const isc::log::MessageID HA_LEASES4_COMMITTED_NO_RELATIONSHIP
isc::log::Logger ha_logger("ha-hooks")
const isc::log::MessageID HA_SUBNET6_SELECT_NOT_FOR_US
const isc::log::MessageID HA_BUFFER6_RECEIVE_PACKET_OPTIONS_SKIPPED
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
const isc::log::MessageID HA_SUBNET4_SELECT_INVALID_HA_SERVER_NAME
HAServerType
Lists possible server types for which HA service is created.
const isc::log::MessageID HA_SUBNET4_SELECT_NO_RELATIONSHIP_FOR_SUBNET
const isc::log::MessageID HA_SUBNET4_SELECT_NOT_FOR_US
const isc::log::MessageID HA_SUBNET6_SELECT_NO_RELATIONSHIP_FOR_SUBNET
const isc::log::MessageID HA_LEASES4_COMMITTED_NOTHING_TO_UPDATE
const isc::log::MessageID HA_SUBNET4_SELECT_NO_RELATIONSHIP_SELECTOR_FOR_SUBNET
const isc::log::MessageID HA_SUBNET6_SELECT_NO_RELATIONSHIP_SELECTOR_FOR_SUBNET
const isc::log::MessageID HA_BUFFER4_RECEIVE_NOT_FOR_US
const isc::log::MessageID HA_BUFFER6_RECEIVE_NOT_FOR_US
boost::shared_ptr< HAService > HAServicePtr
Pointer to the HAService class.
boost::shared_ptr< ParkingLotHandle > ParkingLotHandlePtr
Pointer to the parking lot handle.
const int DBGLVL_TRACE_BASIC
Trace basic operations.
Defines the logger used by the top-level component of kea-lfc.