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);
56 io_service->post([&]() {
57 for (
auto const& service :
services_->getAll()) {
58 service->startClientAndListener();
64 for (
auto const& service :
services_->getAll()) {
67 service->stopClientAndListener();
98 }
catch (
const std::exception& ex) {
101 .arg(query4->getRemoteAddr().toText())
102 .arg(query4->getLocalAddr().toText())
103 .arg(query4->getIface())
108 static_cast<int64_t
>(1));
110 static_cast<int64_t
>(1));
118 if (!
services_->get()->inScope(query4)) {
120 .arg(query4->getLabel());
155 .arg(query4->getLabel());
164 std::string server_name;
167 if (server_name.empty()) {
169 .arg(query4->getLabel())
170 .arg(subnet4->toText());
177 .arg(query4->getLabel())
178 .arg(subnet4->toText());
184 auto service =
services_->get(server_name);
187 .arg(query4->getLabel())
196 if (!service->inScope(query4)) {
198 .arg(query4->getLabel())
207 callout_handle.
setContext(
"ha-server-name", server_name);
223 callout_handle.
getArgument(
"deleted_leases4", deleted_leases4);
226 if (leases4->empty() && deleted_leases4->empty()) {
228 .arg(query4->getLabel());
242 std::string server_name;
243 callout_handle.
getContext(
"ha-server-name", server_name);
244 config =
config_->get(server_name);
248 if (!config || !service) {
252 }
catch (
const std::exception& ex) {
254 .arg(query4->getLabel())
264 if (!config->amSendingLeaseUpdates()) {
276 parking_lot->reference(query4);
283 if (service->asyncSendLeaseUpdates(query4, leases4, deleted_leases4, parking_lot) == 0) {
285 parking_lot->dereference(query4);
290 parking_lot->dereference(query4);
304 size_t peers_to_update = 0;
309 if (!
config_->get()->amSendingLeaseUpdates()) {
312 callout_handle.
setArgument(
"peers_to_update", peers_to_update);
329 peers_to_update =
services_->get()->asyncSendSingleLeaseUpdate(query4, lease4, 0);
330 callout_handle.
setArgument(
"peers_to_update", peers_to_update);
360 }
catch (
const std::exception& ex) {
363 .arg(query6->getRemoteAddr().toText())
364 .arg(query6->getLocalAddr().toText())
365 .arg(query6->getIface())
370 static_cast<int64_t
>(1));
372 static_cast<int64_t
>(1));
380 if (!
services_->get()->inScope(query6)) {
382 .arg(query6->getLabel());
417 .arg(query6->getLabel());
426 std::string server_name;
429 if (server_name.empty()) {
431 .arg(query6->getLabel())
432 .arg(subnet6->toText());
439 .arg(query6->getLabel())
440 .arg(subnet6->toText());
446 auto service =
services_->get(server_name);
449 .arg(query6->getLabel())
458 if (!service->inScope(query6)) {
460 .arg(query6->getLabel())
469 callout_handle.
setContext(
"ha-server-name", server_name);
485 callout_handle.
getArgument(
"deleted_leases6", deleted_leases6);
488 if (leases6->empty() && deleted_leases6->empty()) {
490 .arg(query6->getLabel());
498 std::string server_name;
499 callout_handle.
getContext(
"ha-server-name", server_name);
500 config =
config_->get(server_name);
503 if (!config || !service) {
504 isc_throw(
Unexpected,
"relationship not found for the ha-server-name='" << server_name <<
"'");
507 }
catch (
const std::exception& ex) {
509 .arg(query6->getLabel())
519 if (!config->amSendingLeaseUpdates()) {
531 parking_lot->reference(query6);
538 if (service->asyncSendLeaseUpdates(query6, leases6, deleted_leases6, parking_lot) == 0) {
540 parking_lot->dereference(query6);
545 parking_lot->dereference(query6);
557 std::string command_name;
559 if (command_name ==
"status-get") {
563 if (!response || (response->getType() !=
Element::map)) {
568 if (!resp_args || (resp_args->getType() !=
Element::map)) {
573 boost::const_pointer_cast<Element>(resp_args);
577 for (
auto const& service :
services_->getAll()) {
580 ha_relationship->set(
"ha-servers", ha_servers);
582 ha_relationships->add(ha_relationship);
583 mutable_resp_args->set(
"high-availability", ha_relationships);
602 }
catch (
const std::exception& ex) {
626 unsigned int max_period_value = 0;
642 server_name = args->get(
"server-name");
657 (max_period->intValue() <= 0)) {
658 isc_throw(
BadValue,
"'max-period' must be a positive integer in the 'ha-sync' command");
661 max_period_value =
static_cast<unsigned int>(max_period->intValue());
666 }
catch (
const std::exception& ex) {
675 ConstElementPtr response = service->processSynchronize(server_name->stringValue(),
691 std::vector<std::string> scopes_vector;
716 for (
size_t i = 0; i < scopes->size(); ++i) {
721 scopes_vector.push_back(scope->stringValue());
726 }
catch (
const std::exception& ex) {
753 }
catch (
const std::exception& ex) {
778 isc_throw(
BadValue,
"'cancel' is mandatory for the 'ha-maintenance-notify' command");
782 isc_throw(
BadValue,
"'cancel' must be a boolean in the 'ha-maintenance-notify' command");
787 ConstElementPtr response = service->processMaintenanceNotify(cancel_op->boolValue());
790 }
catch (
const std::exception& ex) {
801 for (
auto const& service :
services_->getAll()) {
802 response = service->processMaintenanceStart();
815 for (
auto const& service :
services_->getAll()) {
816 response = service->processMaintenanceCancel();
835 }
catch (
const std::exception& ex) {
861 auto origin = args->get(
"origin");
864 isc_throw(
BadValue,
"'origin' must be an integer in the 'ha-sync-complete-notify' command");
866 origin_value = origin->intValue();
872 }
catch (
const std::exception& ex) {
880 ConstElementPtr response = service->processSyncCompleteNotify(origin_value);
890 isc_throw(
BadValue,
"arguments in the '" << command_name <<
"' command are not a map");
893 auto server_name = args->get(
"server-name");
897 isc_throw(
BadValue,
"'server-name' must be a string in the '" << command_name <<
"' command");
899 service =
services_->get(server_name->stringValue());
902 <<
" 'server-name'");
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.
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::SubnetPtr &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 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.
void leases4Committed(hooks::CalloutHandle &callout_handle)
Implementation of the "leases4_committed" callout.
void startServices(const asiolink::IOServicePtr &io_service, const dhcp::NetworkStatePtr &network_state, const HAServerType &server_type)
Creates high availability services using current configuration.
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.
Holds associations between objects and HA relationships.
Per-packet callout handle.
void getContext(const std::string &name, T &value) const
Get context.
@ 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
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.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
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< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object.
boost::shared_ptr< Lease4Collection > Lease4CollectionPtr
A shared pointer to the collection of IPv4 leases.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 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
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.