From 51a472788c679a25e20fafc2303eae3cccd93f9d Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Fri, 6 Dec 2019 02:16:30 +0100 Subject: [PATCH] [#1041] Checkpoint: added reload, doc to do --- src/bin/dhcp4/ctrl_dhcp4_srv.cc | 6 +++++- src/bin/dhcp6/ctrl_dhcp6_srv.cc | 6 +++++- src/lib/dhcpsrv/cfgmgr.cc | 4 ++++ src/lib/dhcpsrv/srv_config.h | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index 4711546e56..c6774d8aa6 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -587,7 +587,11 @@ ControlledDhcpv4Srv::commandStatusGetHandler(const string&, auto uptime = now - start_; status->set("uptime", Element::create(uptime.total_seconds())); - // todo: duration since last config commit. + auto last_commit = CfgMgr::instance().getCurrentCfg()->getLastCommitTime(); + if (!last_commit.is_not_a_date_time()) { + auto reload = now - last_commit; + status->set("reload", Element::create(reload.total_seconds())); + } // todo: number of service threads. diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index d6510baa60..cc13fe2a40 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -587,7 +587,11 @@ ControlledDhcpv6Srv::commandStatusGetHandler(const string&, auto uptime = now - start_; status->set("uptime", Element::create(uptime.total_seconds())); - // todo: duration since last config commit. + auto last_commit = CfgMgr::instance().getCurrentCfg()->getLastCommitTime(); + if (!last_commit.is_not_a_date_time()) { + auto reload = now - last_commit; + status->set("reload", Element::create(reload.total_seconds())); + } // todo: number of service threads. diff --git a/src/lib/dhcpsrv/cfgmgr.cc b/src/lib/dhcpsrv/cfgmgr.cc index 69f1b314c3..a9394efc3f 100644 --- a/src/lib/dhcpsrv/cfgmgr.cc +++ b/src/lib/dhcpsrv/cfgmgr.cc @@ -108,6 +108,10 @@ CfgMgr::commit() { } } + // Set the last commit timestamp. + auto now = boost::posix_time::second_clock::universal_time(); + configuration_->setLastCommitTime(now); + // Now we need to set the statistics back. configuration_->updateStatistics(); } diff --git a/src/lib/dhcpsrv/srv_config.h b/src/lib/dhcpsrv/srv_config.h index 4d4dca7297..61e96b316c 100644 --- a/src/lib/dhcpsrv/srv_config.h +++ b/src/lib/dhcpsrv/srv_config.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -679,6 +680,18 @@ public: /// @param srv_elem server top level map to alter static void moveDdnsParams(isc::data::ElementPtr srv_elem); + /// @brief Returns the last commit timestamp. + /// @return the last commit timestamp. + boost::posix_time::ptime getLastCommitTime() const { + return (last_commit_time_); + } + + /// @brief Sets the last commit timestamp. + /// @param last_commit_time last commit timestamp. + void setLastCommitTime(const boost::posix_time::ptime& last_commit_time) { + last_commit_time_ = last_commit_time; + } + /// @brief Unparse a configuration object /// /// @return a pointer to unparsed configuration @@ -832,6 +845,9 @@ private: /// @brief Pointer to the configuration consistency settings CfgConsistencyPtr cfg_consist_; + + /// @brief Stores the last commit timestamp. + boost::posix_time::ptime last_commit_time_; }; /// @name Pointers to the @c SrvConfig object.