From: Franciszek Gorski Date: Wed, 4 Sep 2019 12:49:33 +0000 (+0200) Subject: [755-Kea-DHCP-servers-observations-should-be-reset-to-some-initial] changes to way... X-Git-Tag: Kea-1.7.0~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61cda1b5e1bc976df9b005c69173ce1a77d09764;p=thirdparty%2Fkea.git [755-Kea-DHCP-servers-observations-should-be-reset-to-some-initial] changes to way of initial values --- diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index b84e5c3be3..dc8a37f568 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -107,7 +107,25 @@ struct Dhcp4Hooks { hook_index_host4_identifier_ = HooksManager::registerHook("host4_identifier"); } }; - + /// Set of all statistics observed in DHCPv4 server + std::set dhcp4_statistics = { + "pkt4-received", + "pkt4-discover-received", + "pkt4-offer-received", + "pkt4-request-received", + "pkt4-ack-received", + "pkt4-nak-received", + "pkt4-release-received", + "pkt4-decline-received", + "pkt4-inform-received", + "pkt4-unknown-received", + "pkt4-sent", + "pkt4-offer-sent", + "pkt4-ack-sent", + "pkt4-nak-sent", + "pkt4-parse-failed", + "pkt4-receive-drop" + }; } // end of anonymous namespace // Declare a Hooks object. As this is outside any function or method, it @@ -481,51 +499,22 @@ Dhcpv4Srv::Dhcpv4Srv(uint16_t server_port, uint16_t client_port, return; } - // Initializing all observations with zero value - isc::stats::StatsMgr::instance().setValue("pkt4-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt4-discover-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt4-offer-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt4-request-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt4-ack-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt4-nak-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt4-release-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt4-decline-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt4-inform-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt4-unknown-received", - static_cast(0)); - - isc::stats::StatsMgr::instance().setValue("pkt4-sent", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt4-offer-sent", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt4-ack-sent", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt4-nak-sent", - static_cast(0)); - - isc::stats::StatsMgr::instance().setValue("pkt4-parse-failed", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt4-receive-drop", - static_cast(0)); - - isc::stats::StatsMgr::instance().setValue("reclaimed-leases", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("declined-addresses", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("reclaimed-declined-addresses", - static_cast(0)); + // Initializing all observations with default value + setPacketStatisticsDefaults(); shutdown_ = false; } +void Dhcpv4Srv::setPacketStatisticsDefaults() { + std::set::iterator it; + isc::stats::StatsMgr& stats_mgr = isc::stats::StatsMgr::instance(); + + // Iterate over set of observed statistics + for (it = dhcp4_statistics.begin(); it != dhcp4_statistics.end(); ++it) { + // Initialize them with default value 0 + stats_mgr.setValue((*it), static_cast(0)); + } +} + Dhcpv4Srv::~Dhcpv4Srv() { // Discard any cached packets or parked packets discardPackets(); diff --git a/src/bin/dhcp4/dhcp4_srv.h b/src/bin/dhcp4/dhcp4_srv.h index 72680fff36..a28fc6e1e6 100644 --- a/src/bin/dhcp4/dhcp4_srv.h +++ b/src/bin/dhcp4/dhcp4_srv.h @@ -234,6 +234,9 @@ public: /// @brief Destructor. Used during DHCPv4 service shutdown. virtual ~Dhcpv4Srv(); + /// @brief This function set to defaults all statistics starting with pkt4-. + void setPacketStatisticsDefaults(); + /// @brief Checks if the server is running in a test mode. /// /// @return true if the server is running in the test mode,