ConstElementPtr args) {
std::ostringstream message;
int64_t max_period = 0;
- int64_t handle_id = 0;
+ std::string handle_id;
NetworkState::ControllerType type = NetworkState::COMMAND;
- // Parse arguments to see if the 'max-period' parameter has been specified.
+ // Parse arguments to see if the 'max-period' of 'handle-id' parameters have
+ // been specified.
if (args) {
// Arguments must be a map.
if (args->getType() != Element::map) {
ConstElementPtr handle_id_element = args->get("handle-id");
// handle-id is optional.
if (handle_id_element) {
- // It must be an integer, if specified.
- if (handle_id_element->getType() != Element::integer) {
- message << "'handle-id' argument must be a number";
+ // It must be a string, if specified.
+ if (handle_id_element->getType() != Element::string) {
+ message << "'handle-id' argument must be a string";
} else {
- // It must be positive integer.
- handle_id = handle_id_element->intValue();
- if (handle_id <= 0) {
- message << "'handle-id' must be positive integer";
- }
+ handle_id = handle_id_element->stringValue();
type = NetworkState::HA;
}
}
ControlledDhcpv4Srv::commandDhcpEnableHandler(const std::string&,
ConstElementPtr args) {
std::ostringstream message;
- int64_t handle_id = 0;
+ std::string handle_id;
NetworkState::ControllerType type = NetworkState::COMMAND;
- // Parse arguments to see if the 'max-period' parameter has been specified.
+ // Parse arguments to see if the 'handle-id' parameter has been specified.
if (args) {
// Arguments must be a map.
if (args->getType() != Element::map) {
ConstElementPtr handle_id_element = args->get("handle-id");
// handle-id is optional.
if (handle_id_element) {
- // It must be an integer, if specified.
- if (handle_id_element->getType() != Element::integer) {
- message << "'handle-id' argument must be a number";
+ // It must be a string, if specified.
+ if (handle_id_element->getType() != Element::string) {
+ message << "'handle-id' argument must be a string";
} else {
- // It must be positive integer.
- handle_id = handle_id_element->intValue();
- if (handle_id <= 0) {
- message << "'handle-id' must be positive integer";
- }
+ handle_id = handle_id_element->stringValue();
type = NetworkState::HA;
}
}
ConstElementPtr args) {
std::ostringstream message;
int64_t max_period = 0;
- int64_t handle_id = 0;
+ std::string handle_id;
NetworkState::ControllerType type = NetworkState::COMMAND;
- // Parse arguments to see if the 'max-period' parameter has been specified.
+ // Parse arguments to see if the 'max-period' of 'handle-id' parameters have
+ // been specified.
if (args) {
// Arguments must be a map.
if (args->getType() != Element::map) {
ConstElementPtr handle_id_element = args->get("handle-id");
// handle-id is optional.
if (handle_id_element) {
- // It must be an integer, if specified.
- if (handle_id_element->getType() != Element::integer) {
- message << "'handle-id' argument must be a number";
+ // It must be a string, if specified.
+ if (handle_id_element->getType() != Element::string) {
+ message << "'handle-id' argument must be a string";
} else {
- // It must be positive integer.
- handle_id = handle_id_element->intValue();
- if (handle_id <= 0) {
- message << "'handle-id' must be positive integer";
- }
+ handle_id = handle_id_element->stringValue();
type = NetworkState::HA;
}
}
ControlledDhcpv6Srv::commandDhcpEnableHandler(const std::string&,
ConstElementPtr args) {
std::ostringstream message;
- int64_t handle_id = 0;
+ std::string handle_id;
NetworkState::ControllerType type = NetworkState::COMMAND;
- // Parse arguments to see if the 'max-period' parameter has been specified.
+ // Parse arguments to see if the 'handle-id' parameter has been specified.
if (args) {
// Arguments must be a map.
if (args->getType() != Element::map) {
ConstElementPtr handle_id_element = args->get("handle-id");
// handle-id is optional.
if (handle_id_element) {
- // It must be an integer, if specified.
- if (handle_id_element->getType() != Element::integer) {
- message << "'handle-id' argument must be a number";
+ // It must be a string, if specified.
+ if (handle_id_element->getType() != Element::string) {
+ message << "'handle-id' argument must be a string";
} else {
- // It must be positive integer.
- handle_id = handle_id_element->intValue();
- if (handle_id <= 0) {
- message << "'handle-id' must be positive integer";
- }
+ handle_id = handle_id_element->stringValue();
type = NetworkState::HA;
}
}
namespace ha {
ConstElementPtr
-CommandCreator::createDHCPDisable(const unsigned int max_period,
+CommandCreator::createDHCPDisable(const std::string& service_name,
+ const unsigned int max_period,
const HAServerType& server_type) {
ElementPtr args;
+ args = Element::createMap();
+ args->set("handle-id", Element::create(service_name));
// max-period is optional. A value of 0 means that it is not specified.
if (max_period > 0) {
- args = Element::createMap();
args->set("max-period", Element::create(static_cast<long int>(max_period)));
}
ConstElementPtr command = config::createCommand("dhcp-disable", args);
}
ConstElementPtr
-CommandCreator::createDHCPEnable(const HAServerType& server_type) {
- ConstElementPtr command = config::createCommand("dhcp-enable");
+CommandCreator::createDHCPEnable(const std::string& service_name,
+ const HAServerType& server_type) {
+ ElementPtr args;
+ args = Element::createMap();
+ args->set("handle-id", Element::create(service_name));
+ ConstElementPtr command = config::createCommand("dhcp-enable", args);
insertService(command, server_type);
return (command);
}
///
/// @return Pointer to the JSON representation of the command.
static data::ConstElementPtr
- createDHCPDisable(const unsigned int max_period,
+ createDHCPDisable(const std::string& service_name,
+ const unsigned int max_period,
const HAServerType& server_type);
/// @brief Creates dhcp-enable command for DHCP server.
/// @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
- createDHCPEnable(const HAServerType& server_type);
+ createDHCPEnable(const std::string& service_name,
+ const HAServerType& server_type);
/// @brief Creates ha-reset command.
///
HAImpl::commandProcessed(hooks::CalloutHandle& callout_handle) {
std::string command_name;
callout_handle.getArgument("name", command_name);
- if (command_name == "dhcp-enable") {
- service_->adjustNetworkState();
- } else if (command_name == "status-get") {
+ if (command_name == "status-get") {
// Get the response.
ConstElementPtr response;
callout_handle.getArgument("response", response);
HostHttpHeader(remote_config->getUrl().getHostname()));
remote_config->addBasicAuthHttpHeader(request);
- request->setBodyAsJson(CommandCreator::createDHCPDisable(max_period,
+ request->setBodyAsJson(CommandCreator::createDHCPDisable(server_name,
+ max_period,
server_type_));
request->finalize();
(HttpRequest::Method::HTTP_POST, "/", HttpVersion::HTTP_11(),
HostHttpHeader(remote_config->getUrl().getHostname()));
remote_config->addBasicAuthHttpHeader(request);
- request->setBodyAsJson(CommandCreator::createDHCPEnable(server_type_));
+ request->setBodyAsJson(CommandCreator::createDHCPEnable(server_name,
+ server_type_));
request->finalize();
// Response object should also be created because the HTTP client needs
// This test verifies that the dhcp-disable command is correct.
TEST(CommandCreatorTest, createDHCPDisable4) {
// Create command with max-period value set to 20.
- ConstElementPtr command = CommandCreator::createDHCPDisable(20, HAServerType::DHCPv4);
+ ConstElementPtr command = CommandCreator::createDHCPDisable("this-server",
+ 20, HAServerType::DHCPv4);
ConstElementPtr arguments;
ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "dhcp-disable", "dhcp4",
arguments));
+ ASSERT_EQ(2, arguments->size());
ConstElementPtr max_period = arguments->get("max-period");
ASSERT_TRUE(max_period);
ASSERT_EQ(Element::integer, max_period->getType());
EXPECT_EQ(20, max_period->intValue());
+ ConstElementPtr handle_id = arguments->get("handle-id");
+ ASSERT_TRUE(handle_id);
+ ASSERT_EQ("this-server", handle_id->stringValue());
// Repeat the test but this time the max-period is not specified.
- command = CommandCreator::createDHCPDisable(0, HAServerType::DHCPv4);
- ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "dhcp-disable", "dhcp4"));
+ command = CommandCreator::createDHCPDisable("this-server", 0,
+ HAServerType::DHCPv4);
+ ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "dhcp-disable", "dhcp4",
+ arguments));
+ ASSERT_EQ(1, arguments->size());
+ handle_id = arguments->get("handle-id");
+ ASSERT_TRUE(handle_id);
+ ASSERT_EQ("this-server", handle_id->stringValue());
}
// This test verifies that the dhcp-enable command is correct.
TEST(CommandCreatorTest, createDHCPEnable4) {
- ConstElementPtr command = CommandCreator::createDHCPEnable(HAServerType::DHCPv4);
- ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "dhcp-enable", "dhcp4"));
+ ConstElementPtr arguments;
+ ConstElementPtr command = CommandCreator::createDHCPEnable("this-server",
+ HAServerType::DHCPv4);
+ ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "dhcp-enable", "dhcp4",
+ arguments));
+ ASSERT_EQ(1, arguments->size());
+ ConstElementPtr handle_id = arguments->get("handle-id");
+ ASSERT_TRUE(handle_id);
+ ASSERT_EQ("this-server", handle_id->stringValue());
}
// This test verifies that the ha-reset command sent to DHCPv4 server is correct.
// correct.
TEST(CommandCreatorTest, createDHCPDisable6) {
// Create command with max-period value set to 20.
- ConstElementPtr command = CommandCreator::createDHCPDisable(20, HAServerType::DHCPv6);
+ ConstElementPtr command = CommandCreator::createDHCPDisable("this-server",
+ 20, HAServerType::DHCPv6);
ConstElementPtr arguments;
ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "dhcp-disable", "dhcp6",
arguments));
+ ASSERT_EQ(2, arguments->size());
ConstElementPtr max_period = arguments->get("max-period");
ASSERT_TRUE(max_period);
ASSERT_EQ(Element::integer, max_period->getType());
EXPECT_EQ(20, max_period->intValue());
+ ConstElementPtr handle_id = arguments->get("handle-id");
+ ASSERT_TRUE(handle_id);
+ ASSERT_EQ("this-server", handle_id->stringValue());
// Repeat the test but this time the max-period is not specified.
- command = CommandCreator::createDHCPDisable(0, HAServerType::DHCPv6);
- ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "dhcp-disable", "dhcp6"));
+ command = CommandCreator::createDHCPDisable("this-server", 0,
+ HAServerType::DHCPv6);
+ ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "dhcp-disable", "dhcp6",
+ arguments));
+ ASSERT_EQ(1, arguments->size());
+ handle_id = arguments->get("handle-id");
+ ASSERT_TRUE(handle_id);
+ ASSERT_EQ("this-server", handle_id->stringValue());
}
// This test verifies that the dhcp-enable command (DHCPv6 case) is
// correct.
TEST(CommandCreatorTest, createDHCPEnable6) {
- ConstElementPtr command = CommandCreator::createDHCPEnable(HAServerType::DHCPv6);
- ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "dhcp-enable", "dhcp6"));
+ ConstElementPtr arguments;
+ ConstElementPtr command = CommandCreator::createDHCPEnable("this-server",
+ HAServerType::DHCPv6);
+ ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "dhcp-enable", "dhcp6",
+ arguments));
+ ASSERT_EQ(1, arguments->size());
+ ConstElementPtr handle_id = arguments->get("handle-id");
+ ASSERT_TRUE(handle_id);
+ ASSERT_EQ("this-server", handle_id->stringValue());
}
// This test verifies that the ha-reset command sent to DHCPv6 server is correct.