From 2985cfb7aae275c573a906e7a5bcb8d90bb3c995 Mon Sep 17 00:00:00 2001 From: Tomek Mrugalski Date: Tue, 12 Jul 2016 20:31:08 +0200 Subject: [PATCH] [experiments/yang] set-config method implemented It's implemented, but not tested at all. --- src/bin/dhcp6/ctrl_dhcp6_srv.cc | 43 +++++++++++++++++++++++++++++++++ src/bin/dhcp6/ctrl_dhcp6_srv.h | 14 +++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 8a39820916..6b927d4ba9 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -97,6 +97,46 @@ ControlledDhcpv6Srv::commandLeasesReclaimHandler(const string&, return (answer); } +ConstElementPtr +ControlledDhcpv6Srv::commandSetConfigHandler(const string&, + ConstElementPtr args) { + const int status_code = 1; // 1 indicates an error + string message; + + ConstElementPtr result; + ConstElementPtr dhcp6; + + // args must be { "Dhcp6": { ... }, "Logging": { ... } } + // the Logging component is technically optional, but very recommended. + if (!args) { + message = "Missing mandatory 'Dhcp6' parameter."; + } else { + ConstElementPtr dhcp6 = args->get("Dhcp6"); + if (!dhcp6) { + message = "Missing mandatory 'Dhcp6' parameter."; + } else if (dhcp6->getType() != Element::map) { + message = "'Dhcp6' parameter expected to be a map."; + } + } + + if (!dhcp6) { + // Something went wrong, we can't find the Dhcp6 element. + result = isc::config::createAnswer(status_code, message); + return (result); + } + + // Let's configure logging. We should call configureLogger, even + // if there's no logging specified. It means to return to the + // default logging. + ConstElementPtr logging = args->get("Logging"); + Daemon::configureLogger(args->get("Logging"), CfgMgr::instance().getStagingCfg()); + + // Ok, logging set. Now let's configure the server. + result = ControlledDhcpv6Srv::processCommand("config-reload", dhcp6); + + return (result); +} + isc::data::ConstElementPtr ControlledDhcpv6Srv::processCommand(const std::string& command, isc::data::ConstElementPtr args) { @@ -285,6 +325,9 @@ ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t port) CommandMgr::instance().registerCommand("leases-reclaim", boost::bind(&ControlledDhcpv6Srv::commandLeasesReclaimHandler, this, _1, _2)); + CommandMgr::instance().registerCommand("set-config", + boost::bind(&ControlledDhcpv6Srv::commandSetConfigHandler, this, _1, _2)); + // Register statistic related commands CommandMgr::instance().registerCommand("statistic-get", boost::bind(&StatsMgr::statisticGetHandler, _1, _2)); diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.h b/src/bin/dhcp6/ctrl_dhcp6_srv.h index b1ca9587c1..1c6bde1664 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.h +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.h @@ -143,6 +143,20 @@ private: commandConfigReloadHandler(const std::string& command, isc::data::ConstElementPtr args); + /// @brief handler for processing 'set-config' command + /// + /// This handler processes set-config command, which processes + /// configuration specified in args parameter. + /// @param command (parameter ignored) + /// @param args configuration to be processed. Expected format: + /// map containing Dhcp6 map that contains DHCPv6 server configuration. + /// May also contain Logging map that specifies logging configuration. + /// + /// @return status of the command + isc::data::ConstElementPtr + commandSetConfigHandler(const std::string& command, + isc::data::ConstElementPtr args); + /// @brief Handler for processing 'leases-reclaim' command /// /// This handler processes leases-reclaim command, which triggers -- 2.47.2