}
ConstElementPtr
-CommandCreator::createSyncCompleteNotify(const std::string& server_name,
+CommandCreator::createSyncCompleteNotify(const unsigned int origin,
+ const std::string& server_name,
const HAServerType& server_type) {
auto args = Element::createMap();
args->set("server-name", Element::create(server_name));
+ args->set("origin", Element::create(origin));
auto command = config::createCommand("ha-sync-complete-notify", args);
insertService(command, server_type);
return (command);
/// @brief Creates ha-sync-complete-notify command.
///
+ /// @param origin a numeric value of the origin created from the
+ /// @c HAService identifier to enable the DHCP service.
/// @param server_name name of the server sending the command allowing
/// for associating the command with the relationship.
/// @param server_type type of the DHCP server, i.e. v4 or v6.
/// @return Pointer to the JSON representation of the command.
static data::ConstElementPtr
- createSyncCompleteNotify(const std::string& server_name,
+ createSyncCompleteNotify(const unsigned int origin,
+ const std::string& server_name,
const HAServerType& server_type);
/// @brief List of commands used by the High Availability in v4.
static_cast<void>(parseCommand(args, command));
HAServicePtr service;
+ auto origin_value = NetworkState::HA_REMOTE_COMMAND+1;
try {
+ if (args) {
+ auto origin = args->get("origin");
+ if (origin) {
+ if (origin->getType() != Element::integer) {
+ isc_throw(BadValue, "'origin' must be an integer in the 'ha-sync-complete-notify' command");
+ }
+ origin_value = origin->intValue();
+ }
+ }
+
service = getHAServiceByServerName("ha-sync-complete-notify", args);
} catch (const std::exception& ex) {
return;
}
- ConstElementPtr response = services_->get()->processSyncCompleteNotify();
+ ConstElementPtr response = service->processSyncCompleteNotify(origin_value);
callout_handle.setArgument("response", response);
}
HostHttpHeader(remote_config->getUrl().getStrippedHostname()));
remote_config->addBasicAuthHttpHeader(request);
- request->setBodyAsJson(CommandCreator::createSyncCompleteNotify(config_->getThisServerConfig()->getName(),
+ request->setBodyAsJson(CommandCreator::createSyncCompleteNotify(NetworkState::HA_REMOTE_COMMAND+id_,
+ config_->getThisServerConfig()->getName(),
server_type_));
request->finalize();
}
ConstElementPtr
-HAService::processSyncCompleteNotify() {
+HAService::processSyncCompleteNotify(const unsigned int origin) {
if (getCurrState() == HA_PARTNER_DOWN_ST) {
sync_complete_notified_ = true;
} else {
- localEnableDHCPService();
+ network_state_->enableService(origin);
}
return (createAnswer(CONTROL_RESULT_SUCCESS,
"Server successfully notified about the synchronization completion."));
/// 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.
///
+ /// @param origin a numeric value of the origin created from the
+ /// @c HAService identifier to enable the DHCP service.
/// @return Pointer to the response to the ha-sync-complete-notify command.
- data::ConstElementPtr processSyncCompleteNotify();
+ data::ConstElementPtr processSyncCompleteNotify(const unsigned int origin);
/// @brief Start the client and(or) listener instances.
///
// This test verifies that the ha-sync-complete-notify command sent to a
// DHCPv4 server is correct.
TEST(CommandCreatorTest, createSyncCompleteNotify4) {
- ConstElementPtr command = CommandCreator::createSyncCompleteNotify("server1", HAServerType::DHCPv4);
+ ConstElementPtr command = CommandCreator::createSyncCompleteNotify(1, "server1", HAServerType::DHCPv4);
ConstElementPtr arguments;
ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "ha-sync-complete-notify", "dhcp4", arguments));
auto server_name = arguments->get("server-name");
ASSERT_TRUE(server_name);
ASSERT_EQ(Element::string, server_name->getType());
EXPECT_EQ("server1", server_name->stringValue());
+ auto origin = arguments->get("origin");
+ ASSERT_TRUE(origin);
+ EXPECT_EQ(Element::integer, origin->getType());
+ EXPECT_EQ(1, origin->intValue());
}
// This test verifies that the ha-sync-complete-notify command sent to a
-// DHCPv4 server is correct.
+// DHCPv6 server is correct.
TEST(CommandCreatorTest, createSyncCompleteNotify6) {
- ConstElementPtr command = CommandCreator::createSyncCompleteNotify("server1", HAServerType::DHCPv6);
+ ConstElementPtr command = CommandCreator::createSyncCompleteNotify(1, "server1", HAServerType::DHCPv6);
ConstElementPtr arguments;
ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "ha-sync-complete-notify", "dhcp6", arguments));
auto server_name = arguments->get("server-name");
ASSERT_TRUE(server_name);
ASSERT_EQ(Element::string, server_name->getType());
EXPECT_EQ("server1", server_name->stringValue());
+ auto origin = arguments->get("origin");
+ ASSERT_TRUE(origin);
+ EXPECT_EQ(Element::integer, origin->getType());
+ EXPECT_EQ(1, origin->intValue());
}
}
// Simulate disabling the DHCP service for synchronization.
if (service.network_state_->isServiceEnabled()) {
- EXPECT_NO_THROW(service.network_state_->disableService(NetworkState::HA_LOCAL_COMMAND+1));
+ EXPECT_NO_THROW(service.network_state_->disableService(NetworkState::HA_REMOTE_COMMAND+1));
}
ConstElementPtr rsp;
- EXPECT_NO_THROW(rsp = service.processSyncCompleteNotify());
+ EXPECT_NO_THROW(rsp = service.processSyncCompleteNotify(NetworkState::HA_REMOTE_COMMAND+1));
ASSERT_TRUE(rsp);
checkAnswer(rsp, CONTROL_RESULT_SUCCESS,
EXPECT_NO_THROW(service.transition(HA_LOAD_BALANCING_ST, HAService::NOP_EVT));
// Disable the service again.
- EXPECT_NO_THROW(service.network_state_->disableService(NetworkState::HA_LOCAL_COMMAND+1));
+ EXPECT_NO_THROW(service.network_state_->disableService(NetworkState::HA_REMOTE_COMMAND+1));
- EXPECT_NO_THROW(rsp = service.processSyncCompleteNotify());
+ EXPECT_NO_THROW(rsp = service.processSyncCompleteNotify(NetworkState::HA_REMOTE_COMMAND+1));
ASSERT_TRUE(rsp);
checkAnswer(rsp, CONTROL_RESULT_SUCCESS,