47 auto configs =
config_->getAll();
48 for (
unsigned id = 0;
id < configs.size(); ++id) {
50 auto service = boost::make_shared<HAService>(
id,
io_service_, network_state,
51 configs[
id], server_type);
52 for (
auto const& peer_config : configs[
id]->getAllServersConfig()) {
53 services_->map(peer_config.first, service);
59 for (
auto const& service :
services_->getAll()) {
60 service->startClientAndListener();
74 for (
auto const& service :
services_->getAll()) {
77 service->stopClientAndListener();
109 }
catch (
const std::exception& ex) {
112 .arg(query4->getRemoteAddr().toText())
113 .arg(query4->getLocalAddr().toText())
114 .arg(query4->getIface())
125 if (!
services_->get()->inScope(query4)) {
127 .arg(query4->getLabel());
164 .arg(query4->getLabel());
176 std::string server_name;
179 if (server_name.empty()) {
181 .arg(query4->getLabel())
182 .arg(subnet4->toText());
192 .arg(query4->getLabel())
193 .arg(subnet4->toText());
201 auto service =
services_->get(server_name);
204 .arg(query4->getLabel())
215 if (!service->inScope(query4)) {
217 .arg(query4->getLabel())
228 callout_handle.
setContext(
"ha-server-name", server_name);
244 callout_handle.
getArgument(
"deleted_leases4", deleted_leases4);
247 if (leases4->empty() && deleted_leases4->empty()) {
249 .arg(query4->getLabel());
263 std::string server_name;
264 callout_handle.
getContext(
"ha-server-name", server_name);
269 if (!
config || !service) {
273 }
catch (
const std::exception& ex) {
275 .arg(query4->getLabel())
287 if (!
config->amSendingLeaseUpdates()) {
299 parking_lot->reference(query4);
306 if (service->asyncSendLeaseUpdates(query4, leases4, deleted_leases4, parking_lot) == 0) {
308 parking_lot->dereference(query4);
313 parking_lot->dereference(query4);
327 size_t peers_to_update = 0;
332 if (!
config_->get()->amSendingLeaseUpdates()) {
335 callout_handle.
setArgument(
"peers_to_update", peers_to_update);
352 peers_to_update =
services_->get()->asyncSendSingleLeaseUpdate(query4, lease4, 0);
353 callout_handle.
setArgument(
"peers_to_update", peers_to_update);
374 std::string server_name;
377 if (server_name.empty()) {
386 .arg(lease4->addr_.toText())
387 .arg(subnet4->toText());
407 .arg(lease4->addr_.toText());
440 }
catch (
const std::exception& ex) {
443 .arg(query6->getRemoteAddr().toText())
444 .arg(query6->getLocalAddr().toText())
445 .arg(query6->getIface())
458 if (!
services_->get()->inScope(query6)) {
460 .arg(query6->getLabel());
497 .arg(query6->getLabel());
509 std::string server_name;
512 if (server_name.empty()) {
514 .arg(query6->getLabel())
515 .arg(subnet6->toText());
525 .arg(query6->getLabel())
526 .arg(subnet6->toText());
534 auto service =
services_->get(server_name);
537 .arg(query6->getLabel())
548 if (!service->inScope(query6)) {
550 .arg(query6->getLabel())
561 callout_handle.
setContext(
"ha-server-name", server_name);
577 callout_handle.
getArgument(
"deleted_leases6", deleted_leases6);
580 if (leases6->empty() && deleted_leases6->empty()) {
582 .arg(query6->getLabel());
590 std::string server_name;
591 callout_handle.
getContext(
"ha-server-name", server_name);
595 if (!
config || !service) {
596 isc_throw(
Unexpected,
"relationship not found for the ha-server-name='" << server_name <<
"'");
599 }
catch (
const std::exception& ex) {
601 .arg(query6->getLabel())
613 if (!
config->amSendingLeaseUpdates()) {
625 parking_lot->reference(query6);
632 if (service->asyncSendLeaseUpdates(query6, leases6, deleted_leases6, parking_lot) == 0) {
634 parking_lot->dereference(query6);
639 parking_lot->dereference(query6);
667 std::string server_name;
670 if (server_name.empty()) {
679 .arg(lease6->addr_.toText())
680 .arg(subnet6->toText());
700 .arg(lease6->addr_.toText());
708 std::string command_name;
710 if (command_name ==
"status-get") {
714 if (!response || (response->getType() !=
Element::map)) {
719 if (!resp_args || (resp_args->getType() !=
Element::map)) {
724 boost::const_pointer_cast<Element>(resp_args);
728 for (
auto const& service :
services_->getAll()) {
731 ha_relationship->set(
"ha-servers", ha_servers);
733 ha_relationships->add(ha_relationship);
734 mutable_resp_args->set(
"high-availability", ha_relationships);
753 }
catch (
const std::exception& ex) {
777 unsigned int max_period_value = 0;
793 server_name = args->get(
"server-name");
808 (max_period->intValue() <= 0)) {
809 isc_throw(
BadValue,
"'max-period' must be a positive integer in the 'ha-sync' command");
812 max_period_value =
static_cast<unsigned int>(max_period->intValue());
817 }
catch (
const std::exception& ex) {
826 ConstElementPtr response = service->processSynchronize(server_name->stringValue(),
842 std::vector<std::string> scopes_vector;
867 for (
size_t i = 0; i < scopes->size(); ++i) {
872 scopes_vector.push_back(scope->stringValue());
877 }
catch (
const std::exception& ex) {
904 }
catch (
const std::exception& ex) {
929 isc_throw(
BadValue,
"'cancel' is mandatory for the 'ha-maintenance-notify' command");
933 isc_throw(
BadValue,
"'cancel' must be a boolean in the 'ha-maintenance-notify' command");
938 isc_throw(
BadValue,
"'state' must be a string in the 'ha-maintenance-notify' command");
943 ConstElementPtr response = service->processMaintenanceNotify(cancel_op->boolValue(),
944 state ? state->stringValue() :
"unavailable");
947 }
catch (
const std::exception& ex) {
958 for (
auto const& service :
services_->getAll()) {
959 response = service->processMaintenanceStart();
972 for (
auto const& service :
services_->getAll()) {
973 response = service->processMaintenanceCancel();
992 }
catch (
const std::exception& ex) {
1018 auto origin_id = args->get(
"origin-id");
1019 auto origin = args->get(
"origin");
1024 isc_throw(
BadValue,
"'origin-id' must be an integer in the 'ha-sync-complete-notify' command");
1026 origin_id_value = origin_id->intValue();
1028 }
else if (origin) {
1030 isc_throw(
BadValue,
"'origin' must be an integer in the 'ha-sync-complete-notify' command");
1032 origin_id_value = origin->intValue();
1038 }
catch (
const std::exception& ex) {
1046 ConstElementPtr response = service->processSyncCompleteNotify(origin_id_value);
1056 isc_throw(
BadValue,
"arguments in the '" << command_name <<
"' command are not a map");
1059 auto server_name = args->get(
"server-name");
1063 isc_throw(
BadValue,
"'server-name' must be a string in the '" << command_name <<
"' command");
1065 service =
services_->get(server_name->stringValue());
1068 <<
" 'server-name'");
1082 return (service->shouldReclaim(lease4));
1087 return (service->shouldReclaim(lease6));
@ 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 ElementPtr create(const Position &pos=ZERO_POSITION())
Create a NullElement.
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.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when an unexpected error condition occurs.
The IOService class is a wrapper for the ASIO io_context class.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
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 stop()
Stop the client and listener.
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.
void lease4Expire(hooks::CalloutHandle &callout_handle)
Implementation of the "lease4_expire" callout.
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.
virtual ~HAImpl()
Destructor.
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.
void lease6Expire(hooks::CalloutHandle &callout_handle)
Implementation of the "lease6_expire" callout.
isc::asiolink::IOServicePtr io_service_
The hook I/O service.
void leases4Committed(hooks::CalloutHandle &callout_handle)
Implementation of the "leases4_committed" callout.
virtual bool shouldReclaim(const HAServicePtr &service, const dhcp::Lease4Ptr &lease4) const
Checks if the lease should be reclaimed by this server.
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.
void getContext(const std::string &name, T &value) const
Get context.
ParkingLotHandlePtr getParkingLotHandlePtr() const
Returns pointer to the parking lot handle for this hook point.
void setContext(const std::string &name, T value)
Set context.
CalloutNextStep getStatus() const
Returns the next processing step.
void setStatus(const CalloutNextStep next)
Sets the next processing step.
void getArgument(const std::string &name, T &value) const
Get argument.
void setArgument(const std::string &name, T value)
Set argument.
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.
void addValue(const std::string &name, const int64_t value)
Records incremental integer observation.
#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.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
Parses a standard config/command level answer and returns arguments or text status code.
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
std::string parseCommand(ConstElementPtr &arg, ConstElementPtr command)
Parses the given command into a string containing the actual command and an ElementPtr containing the...
std::string parseCommandWithArgs(ConstElementPtr &arg, ConstElementPtr command)
Parses the given command into a string containing the command name and an ElementPtr containing the m...
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
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< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
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_LEASE4_EXPIRE_INVALID_HA_SERVER_NAME
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_LEASE6_EXPIRE_RECLAMATION_SKIP
const isc::log::MessageID HA_SUBNET6_SELECT_NO_RELATIONSHIP_FOR_SUBNET
const isc::log::MessageID HA_LEASE4_EXPIRE_RECLAMATION_SKIP
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.
const isc::log::MessageID HA_LEASE6_EXPIRE_INVALID_HA_SERVER_NAME
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.