]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3245] Moved Alarm into own files
authorThomas Markwalder <tmark@isc.org>
Wed, 21 Feb 2024 12:43:18 +0000 (07:43 -0500)
committerThomas Markwalder <tmark@isc.org>
Fri, 23 Feb 2024 12:08:04 +0000 (12:08 +0000)
new file:   src/hooks/dhcp/perfmon/alarm.cc
new file:   src/hooks/dhcp/perfmon/alarm.h
new file:   src/hooks/dhcp/perfmon/tests/alarm_unittests.cc

modified:   src/hooks/dhcp/perfmon/Makefile.am
modified:   src/hooks/dhcp/perfmon/monitored_duration.cc
modified:   src/hooks/dhcp/perfmon/monitored_duration.h
modified:   src/hooks/dhcp/perfmon/tests/Makefile.am
modified:   src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc

src/hooks/dhcp/perfmon/Makefile.am
src/hooks/dhcp/perfmon/alarm.cc [new file with mode: 0644]
src/hooks/dhcp/perfmon/alarm.h [new file with mode: 0644]
src/hooks/dhcp/perfmon/monitored_duration.cc
src/hooks/dhcp/perfmon/monitored_duration.h
src/hooks/dhcp/perfmon/tests/Makefile.am
src/hooks/dhcp/perfmon/tests/alarm_unittests.cc [new file with mode: 0644]
src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc

index 741cf1a3c86838231b8b937634e03fc9507ee1ea..3d96fff9ce9d7f3867b0fce80f9e33004510cd53 100644 (file)
@@ -18,6 +18,7 @@ libperfmon_la_SOURCES = perfmon_callouts.cc
 libperfmon_la_SOURCES += perfmon_log.cc perfmon_log.h
 libperfmon_la_SOURCES += perfmon_messages.cc perfmon_messages.h
 libperfmon_la_SOURCES += monitored_duration.cc monitored_duration.h
+libperfmon_la_SOURCES += alarm.cc alarm.h
 libperfmon_la_SOURCES += version.cc
 
 libperfmon_la_CXXFLAGS = $(AM_CXXFLAGS)
diff --git a/src/hooks/dhcp/perfmon/alarm.cc b/src/hooks/dhcp/perfmon/alarm.cc
new file mode 100644 (file)
index 0000000..d32ce8b
--- /dev/null
@@ -0,0 +1,139 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <dhcp/pkt4.h>
+#include <dhcp/pkt6.h>
+#include <dhcp/dhcp6.h>
+#include <exceptions/exceptions.h>
+#include <alarm.h>
+
+using namespace isc::dhcp;
+using namespace boost::posix_time;
+
+namespace isc {
+namespace perfmon {
+
+Alarm::Alarm(uint16_t family,
+             uint8_t query_type,
+             uint8_t response_type,
+             const std::string& start_event_label,
+             const std::string& end_event_label,
+             dhcp::SubnetID subnet_id,
+             const Duration& low_water,
+             const Duration& high_water,
+             bool enabled /* = true */)
+    : DurationKey(family, query_type, response_type, start_event_label, end_event_label, subnet_id),
+      low_water_(low_water),
+      high_water_(high_water),
+      state_(enabled ? CLEAR : DISABLED),
+      stos_time_(PktEvent::now()),
+      last_high_water_report_(PktEvent::EMPTY_TIME()) {
+    if (low_water >= high_water_) {
+        isc_throw(BadValue, "low water: " << low_water_
+                   << ", must be less than high water: " << high_water_);
+    }
+}
+
+Alarm::Alarm(const DurationKey& key,
+             const Duration& low_water,
+             const Duration& high_water,
+             bool enabled /* = true */)
+    : DurationKey(key),
+      low_water_(low_water),
+      high_water_(high_water),
+      state_(enabled ? CLEAR : DISABLED),
+      stos_time_(PktEvent::now()),
+      last_high_water_report_(PktEvent::EMPTY_TIME()) {
+    if (low_water >= high_water_) {
+        isc_throw(BadValue, "low water: " << low_water_
+                   << ", must be less than high water: " << high_water_);
+    }
+}
+
+void
+Alarm::setLowWater(const Duration& low_water) {
+    if (low_water >= high_water_) {
+        isc_throw(BadValue, "low water: " << low_water
+                  << ", must be less than high water: " << high_water_);
+    }
+
+    low_water_ = low_water;
+}
+
+void
+Alarm::setHighWater(const Duration& high_water) {
+    if (high_water <= low_water_) {
+        isc_throw(BadValue, "high water: " << high_water
+                  << ", must be greater than low water: " << low_water_);
+    }
+
+    high_water_ = high_water;
+}
+
+void
+Alarm::setState(State state) {
+    state_ = state;
+    stos_time_ = PktEvent::now();
+    last_high_water_report_ = PktEvent::EMPTY_TIME();
+}
+
+void
+Alarm::clear() {
+    setState(CLEAR);
+}
+
+void
+Alarm::disable() {
+    setState(DISABLED);
+}
+
+bool
+Alarm::checkSample(const Duration& sample, const Duration& report_interval) {
+    if (state_ == DISABLED) {
+        isc_throw(InvalidOperation, "Alarm::checkSample() "
+                  "- should not be called when alarm is DISABLED");
+    }
+
+    // Low water subceeded?
+    if (sample < low_water_) {
+        // If the alarm is currently triggered, transition to CLEAR
+        // state and return true to signal reportable condition.
+        if (state_ == TRIGGERED) {
+            setState(CLEAR);
+            return (true);
+        }
+
+        // Nothing to report.
+        return (false);
+    }
+
+    // High water exceeded?
+    if (sample > high_water_) {
+        // If the alarm isn't yet triggered, transition to the TRIGGERED state.
+        if (state_ != TRIGGERED) {
+            setState(TRIGGERED);
+        }
+    }
+
+    // If we're triggered and have not yet reported it or it is time to report again,
+    // update the report time and return true.
+    if (state_ == TRIGGERED) {
+        auto now = PktEvent::now();
+        if ((last_high_water_report_ == PktEvent::EMPTY_TIME()) ||
+            ((now - last_high_water_report_) > report_interval)) {
+            last_high_water_report_ = now;
+            return (true);
+        }
+    }
+
+    // Nothing to report.
+    return (false);
+}
+
+} // end of namespace perfmon
+} // end of namespace isc
diff --git a/src/hooks/dhcp/perfmon/alarm.h b/src/hooks/dhcp/perfmon/alarm.h
new file mode 100644 (file)
index 0000000..f0080ae
--- /dev/null
@@ -0,0 +1,173 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef _ALARM_H
+#define _ALARM_H
+
+#include <dhcp/pkt.h>
+#include <dhcpsrv/subnet_id.h>
+#include <monitored_duration.h>
+
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+namespace isc {
+namespace perfmon {
+
+/// @brief Defines an alarm for a duration.
+class Alarm : public DurationKey {
+public:
+    /// @brief Defines Alarm states
+    enum State {
+        CLEAR,      // Enabled and not currently triggered
+        TRIGGERED,  // High water has been exceeded
+        DISABLED    // Disabled
+    };
+
+    /// @brief Constructor
+    ///
+    /// @param family protocol family AF_INET or AF_INET6
+    /// @param query_type message type of the query packet
+    /// @param response_type_ message type of the response packet
+    /// @param start_event_label label of the start event
+    /// @param end_event_label label of the end event
+    /// @param SubnetID subnet_id id of the selected subnet
+    /// @param low_water threshold below which the average duration must fall to clear the alarm
+    /// @brief high_water threshold above which the average duration must rise to trigger the alarm.
+    /// @brief enabled true sets state to CLEAR, otherwise DISABLED, defaults to true.
+    Alarm(uint16_t family, uint8_t query_type_, uint8_t response_type_,
+          const std::string& start_event_label, const std::string& end_event_label,
+          dhcp::SubnetID subnet_id_,
+          const Duration& low_water, const Duration& high_water, bool enabled = true);
+
+    /// @brief Constructor
+    ///
+    /// param key composite key that identifies the alarm
+    /// @param low_water threshold below which the average duration must fall to clear the alarm
+    /// @brief high_water threshold above which the average duration must rise to trigger the alarm.
+    /// @brief enabled true sets state to CLEAR, otherwise DISABLED, defaults to true.
+    Alarm(const DurationKey& key, const Duration& low_water, const Duration& high_water, bool enabled = true);
+
+    /// @brief Destructor
+    virtual ~Alarm() = default;
+
+    /// @brief Get the low water threshold.
+    ///
+    /// @return Duration containing the low water threshold.
+    Duration getLowWater() const {
+        return (low_water_);
+    }
+
+    /// @brief Set the low water threshold.
+    ///
+    /// @param low_water new value for the low water threshold.
+    /// @throw BadValue if new value is greater than the current value
+    /// of high water.
+    void setLowWater(const Duration& low_water);
+
+    /// @brief Get the high water threshold.
+    ///
+    /// @return Duration containing the high water threshold.
+    Duration getHighWater() const {
+        return (high_water_);
+    }
+
+    /// @brief Set the high water threshold.
+    ///
+    /// @param high_water new value for the high water threshold.
+    /// @throw BadValue if new value is less than the current value
+    /// of low water.
+    void setHighWater(const Duration& high_water);
+
+    /// @brief Get the alarm's state.
+    State getState() {
+        return (state_);
+    }
+
+    /// @brief Sets the alarm state.
+    ///
+    /// Sets the alarm's state to the given value,
+    /// sets the start of state time to the current time,
+    /// and resets the last high water report.
+    ///
+    /// @param state new state to which to transition.
+    void setState(State state);
+
+    /// @brief Get the time the current state began.
+    ///
+    /// @return Timestamp the alarm entered it's current state.
+    Timestamp getStosTime() {
+        return (stos_time_);
+    }
+
+    /// @brief Get the timestamp of the last high water report.
+    ///
+    /// @return Timestamp containing the last high water report time.
+    Timestamp getLastHighWaterReport() {
+        return (last_high_water_report_);
+    }
+
+    /// @brief Set the timestamp of the last high water report.
+    ///
+    /// This function is provided for test purposes only.
+    ///
+    /// @param timestamp new value of the last high water report, defaults to
+    /// the current time.
+    void setLastHighWaterReport(const Timestamp& timestamp = dhcp::PktEvent::now()) {
+        last_high_water_report_ = timestamp;
+    }
+
+    /// @brief Sets the alarm back to the CLEAR state.
+    void clear();
+
+    /// @brief Disables the alarm by setting the state to DISABLED.
+    void disable();
+
+    /// @brief Checks a duration against the high and low water thresholds
+    /// and calls the appropriate event handler.
+    ///
+    /// -# If the sample is less than the low water threshold:
+    /// If the state is TRIGGERED, transition to CLEAR and return true otherwise
+    /// return false.
+    /// -# If the sample is greater than high water threshold:
+    /// If the state is not TRIGGERED, transition to TRIGGERED
+    /// -# If the state is TRIGGERED and the last report time either not set or
+    /// is more than report interval old, update the last report time to current
+    /// time and return true.
+    /// -# Otherwise return false.
+    ///
+    /// @param sample duration to test against the thresholds.
+    /// @param report_interval amount of time that must elapse between high
+    /// water reports.
+    ///
+    /// @return True if alarm state should be reported.
+    ///
+    /// @throw InvalidOperation if called when the state is DISABLED.
+    bool checkSample(const Duration& sample, const Duration& report_interval);
+
+private:
+    /// @brief Threshold below which the average duration must fall to clear the alarm.
+    Duration low_water_;
+
+    /// @brief Threshold above which the average duration must rise to trigger the alarm.
+    Duration high_water_;
+
+    /// @brief Current alarm state.
+    State state_;
+
+    /// @brief Timestamp of the beginning of the current state.
+    Timestamp stos_time_;
+
+    /// @brief Last time the high water breach was reported.
+    Timestamp last_high_water_report_;
+};
+
+/// @brief Defines a pointer to an Alarm instance.
+typedef boost::shared_ptr<Alarm> AlarmPtr;
+
+} // end of namespace isc::perfmon
+} // end of namespace isc
+
+#endif
index db210859d187cef0dbc107846ef3bb379c384ddc..abc434387236da9b947f0f6118308607f2529cb2 100644 (file)
@@ -164,125 +164,6 @@ DurationKey::getLabel() const {
     return (oss.str());
 };
 
-// Alarm methods
-
-Alarm::Alarm(uint16_t family,
-             uint8_t query_type,
-             uint8_t response_type,
-             const std::string& start_event_label,
-             const std::string& end_event_label,
-             dhcp::SubnetID subnet_id,
-             const Duration& low_water,
-             const Duration& high_water,
-             bool enabled /* = true */)
-    : DurationKey(family, query_type, response_type, start_event_label, end_event_label, subnet_id),
-      low_water_(low_water),
-      high_water_(high_water),
-      state_(enabled ? CLEAR : DISABLED),
-      stos_time_(PktEvent::now()),
-      last_high_water_report_(PktEvent::EMPTY_TIME()) {
-    if (low_water >= high_water_) {
-        isc_throw(BadValue, "low water: " << low_water_
-                   << ", must be less than high water: " << high_water_);
-    }
-}
-
-Alarm::Alarm(const DurationKey& key,
-             const Duration& low_water,
-             const Duration& high_water,
-             bool enabled /* = true */)
-    : DurationKey(key),
-      low_water_(low_water),
-      high_water_(high_water),
-      state_(enabled ? CLEAR : DISABLED),
-      stos_time_(PktEvent::now()),
-      last_high_water_report_(PktEvent::EMPTY_TIME()) {
-    if (low_water >= high_water_) {
-        isc_throw(BadValue, "low water: " << low_water_
-                   << ", must be less than high water: " << high_water_);
-    }
-}
-
-void
-Alarm::setLowWater(const Duration& low_water) {
-    if (low_water >= high_water_) {
-        isc_throw(BadValue, "low water: " << low_water
-                  << ", must be less than high water: " << high_water_);
-    }
-
-    low_water_ = low_water;
-}
-
-void
-Alarm::setHighWater(const Duration& high_water) {
-    if (high_water <= low_water_) {
-        isc_throw(BadValue, "high water: " << high_water
-                  << ", must be greater than low water: " << low_water_);
-    }
-
-    high_water_ = high_water;
-}
-
-void
-Alarm::setState(State state) {
-    state_ = state;
-    stos_time_ = PktEvent::now();
-    last_high_water_report_ = PktEvent::EMPTY_TIME();
-}
-
-void
-Alarm::clear() {
-    setState(CLEAR);
-}
-
-void
-Alarm::disable() {
-    setState(DISABLED);
-}
-
-bool
-Alarm::checkSample(const Duration& sample, const Duration& report_interval) {
-    if (state_ == DISABLED) {
-        isc_throw(InvalidOperation, "Alarm::checkSample() "
-                  "- should not be called when alarm is DISABLED");
-    }
-
-    // Low water subceeded?
-    if (sample < low_water_) {
-        // If the alarm is currently triggered, transition to CLEAR
-        // state and return true to signal reportable condition.
-        if (state_ == TRIGGERED) {
-            setState(CLEAR);
-            return (true);
-        }
-
-        // Nothing to report.
-        return (false);
-    }
-
-    // High water exceeded?
-    if (sample > high_water_) {
-        // If the alarm isn't yet triggered, transition to the TRIGGERED state.
-        if (state_ != TRIGGERED) {
-            setState(TRIGGERED);
-        }
-    }
-
-    // If we're triggered and have not yet reported it or it is time to report again,
-    // update the report time and return true.
-    if (state_ == TRIGGERED) {
-        auto now = PktEvent::now();
-        if ((last_high_water_report_ == PktEvent::EMPTY_TIME()) ||
-            ((now - last_high_water_report_) > report_interval)) {
-            last_high_water_report_ = now;
-            return (true);
-        }
-    }
-
-    // Nothing to report.
-    return (false);
-}
-
 // MonitoredDuration methods
 
 MonitoredDuration::MonitoredDuration(uint16_t family,
index 9c630d17563fc89a4d04436f67345cca2ca723c9..9709c864b58c1f3442546a1db27879e29099c5f1 100644 (file)
@@ -233,157 +233,6 @@ protected:
 /// @brief Defines a pointer to a DurationKey instance.
 typedef boost::shared_ptr<DurationKey> DurationKeyPtr;
 
-/// @brief Defines an alarm for a duration.
-class Alarm : public DurationKey {
-public:
-    /// @brief Defines Alarm states
-    enum State {
-        CLEAR,      // Enabled and not currently triggered
-        TRIGGERED,  // High water has been exceeded
-        DISABLED    // Disabled
-    };
-
-    /// @brief Constructor
-    ///
-    /// @param family protocol family AF_INET or AF_INET6
-    /// @param query_type message type of the query packet
-    /// @param response_type_ message type of the response packet
-    /// @param start_event_label label of the start event
-    /// @param end_event_label label of the end event
-    /// @param SubnetID subnet_id id of the selected subnet
-    /// @param low_water threshold below which the average duration must fall to clear the alarm
-    /// @brief high_water threshold above which the average duration must rise to trigger the alarm.
-    /// @brief enabled true sets state to CLEAR, otherwise DISABLED, defaults to true.
-    Alarm(uint16_t family, uint8_t query_type_, uint8_t response_type_,
-          const std::string& start_event_label, const std::string& end_event_label,
-          dhcp::SubnetID subnet_id_,
-          const Duration& low_water, const Duration& high_water, bool enabled = true);
-
-    /// @brief Constructor
-    ///
-    /// param key composite key that identifies the alarm
-    /// @param low_water threshold below which the average duration must fall to clear the alarm
-    /// @brief high_water threshold above which the average duration must rise to trigger the alarm.
-    /// @brief enabled true sets state to CLEAR, otherwise DISABLED, defaults to true.
-    Alarm(const DurationKey& key, const Duration& low_water, const Duration& high_water, bool enabled = true);
-
-    /// @brief Destructor
-    virtual ~Alarm() = default;
-
-    /// @brief Get the low water threshold.
-    ///
-    /// @return Duration containing the low water threshold.
-    Duration getLowWater() const {
-        return (low_water_);
-    }
-
-    /// @brief Set the low water threshold.
-    ///
-    /// @param low_water new value for the low water threshold.
-    /// @throw BadValue if new value is greater than the current value
-    /// of high water.
-    void setLowWater(const Duration& low_water);
-
-    /// @brief Get the high water threshold.
-    ///
-    /// @return Duration containing the high water threshold.
-    Duration getHighWater() const {
-        return (high_water_);
-    }
-
-    /// @brief Set the high water threshold.
-    ///
-    /// @param high_water new value for the high water threshold.
-    /// @throw BadValue if new value is less than the current value
-    /// of low water.
-    void setHighWater(const Duration& high_water);
-
-    /// @brief Get the alarm's state.
-    State getState() {
-        return (state_);
-    }
-
-    /// @brief Sets the alarm state.
-    ///
-    /// Sets the alarm's state to the given value,
-    /// sets the start of state time to the current time,
-    /// and resets the last high water report.
-    ///
-    /// @param state new state to which to transition.
-    void setState(State state);
-
-    /// @brief Get the time the current state began.
-    ///
-    /// @return Timestamp the alarm entered it's current state.
-    Timestamp getStosTime() {
-        return (stos_time_);
-    }
-
-    /// @brief Get the timestamp of the last high water report.
-    ///
-    /// @return Timestamp containing the last high water report time.
-    Timestamp getLastHighWaterReport() {
-        return (last_high_water_report_);
-    }
-
-    /// @brief Set the timestamp of the last high water report.
-    ///
-    /// This function is provided for test purposes only.
-    ///
-    /// @param timestamp new value of the last high water report, defaults to
-    /// the current time.
-    void setLastHighWaterReport(const Timestamp& timestamp = dhcp::PktEvent::now()) {
-        last_high_water_report_ = timestamp;
-    }
-
-    /// @brief Sets the alarm back to the CLEAR state.
-    void clear();
-
-    /// @brief Disables the alarm by setting the state to DISABLED.
-    void disable();
-
-    /// @brief Checks a duration against the high and low water thresholds
-    /// and calls the appropriate event handler.
-    ///
-    /// -# If the sample is less than the low water threshold:
-    /// If the state is TRIGGERED, transition to CLEAR and return true otherwise
-    /// return false.
-    /// -# If the sample is greater than high water threshold:
-    /// If the state is not TRIGGERED, transition to TRIGGERED
-    /// -# If the state is TRIGGERED and the last report time either not set or
-    /// is more than report interval old, update the last report time to current
-    /// time and return true.
-    /// -# Otherwise return false.
-    ///
-    /// @param sample duration to test against the thresholds.
-    /// @param report_interval amount of time that must elapse between high
-    /// water reports.
-    ///
-    /// @return True if alarm state should be reported.
-    ///
-    /// @throw InvalidOperation if called when the state is DISABLED.
-    bool checkSample(const Duration& sample, const Duration& report_interval);
-
-private:
-    /// @brief Threshold below which the average duration must fall to clear the alarm.
-    Duration low_water_;
-
-    /// @brief Threshold above which the average duration must rise to trigger the alarm.
-    Duration high_water_;
-
-    /// @brief Current alarm state.
-    State state_;
-
-    /// @brief Timestamp of the beginning of the current state.
-    Timestamp stos_time_;
-
-    /// @brief Last time the high water breach was reported.
-    Timestamp last_high_water_report_;
-};
-
-/// @brief Defines a pointer to an Alarm instance.
-typedef boost::shared_ptr<Alarm> AlarmPtr;
-
 class MonitoredDuration : public DurationKey {
 public:
     /// @brief Constructor
index b6cb195a09790a415fb3e2194bf44c5000945329..b091c961c49a713d72eac23d78f1304a2fc98d65 100644 (file)
@@ -28,6 +28,7 @@ TESTS += perfmon_unittests
 
 perfmon_unittests_SOURCES = run_unittests.cc
 perfmon_unittests_SOURCES += monitored_duration_unittests.cc
+perfmon_unittests_SOURCES += alarm_unittests.cc
 
 perfmon_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES)
 
diff --git a/src/hooks/dhcp/perfmon/tests/alarm_unittests.cc b/src/hooks/dhcp/perfmon/tests/alarm_unittests.cc
new file mode 100644 (file)
index 0000000..3e121cf
--- /dev/null
@@ -0,0 +1,328 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+#include <alarm.h>
+#include <dhcp/dhcp6.h>
+#include <testutils/gtest_utils.h>
+
+#include <gtest/gtest.h>
+#include <sstream>
+#include <unordered_set>
+
+using namespace isc;
+using namespace isc::dhcp;
+using namespace isc::perfmon;
+using namespace boost::posix_time;
+
+namespace {
+
+/// @brief Verifies Alarm construction.
+TEST(Alarm, validConstructors) {
+    AlarmPtr alarm;
+
+    auto start_time = PktEvent::now();
+
+    // Create valid v4 alarm, verify contents and label.
+    Duration low_water(milliseconds(50));
+    Duration high_water(milliseconds(250));
+    ASSERT_NO_THROW_LOG(alarm.reset(new Alarm(AF_INET, DHCPDISCOVER, DHCPOFFER,
+                              "process_started", "process_completed",
+                              SUBNET_ID_GLOBAL,
+                              low_water, high_water)));
+    ASSERT_TRUE(alarm);
+    EXPECT_EQ(alarm->getFamily(), AF_INET);
+    EXPECT_EQ(alarm->getQueryType(), DHCPDISCOVER);
+    EXPECT_EQ(alarm->getResponseType(), DHCPOFFER);
+    EXPECT_EQ(alarm->getStartEventLabel(), "process_started");
+    EXPECT_EQ(alarm->getEndEventLabel(), "process_completed");
+    EXPECT_EQ(alarm->getSubnetId(), SUBNET_ID_GLOBAL);
+    EXPECT_EQ("DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0", alarm->getLabel());
+    EXPECT_EQ(alarm->getSubnetId(), SUBNET_ID_GLOBAL);
+    EXPECT_EQ(alarm->getLowWater(), low_water);
+    EXPECT_EQ(alarm->getHighWater(), high_water);
+    EXPECT_EQ(alarm->getState(), Alarm::CLEAR);
+    EXPECT_GE(alarm->getStosTime(), start_time);
+
+    start_time = PktEvent::now();
+
+    // Create valid v6 key and use that to create an alarm. Verify contents and label.
+    DurationKeyPtr key;
+    ASSERT_NO_THROW_LOG(key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE,
+                                  "mt_queued", "process_started", 77)));
+
+    ASSERT_NO_THROW_LOG(alarm.reset(new Alarm(*key, low_water, high_water, false)));
+    ASSERT_TRUE(alarm);
+    EXPECT_EQ(alarm->getFamily(), AF_INET6);
+    EXPECT_EQ(alarm->getQueryType(), DHCPV6_SOLICIT);
+    EXPECT_EQ(alarm->getResponseType(), DHCPV6_ADVERTISE);
+    EXPECT_EQ(alarm->getStartEventLabel(), "mt_queued");
+    EXPECT_EQ(alarm->getEndEventLabel(), "process_started");
+    EXPECT_EQ(alarm->getSubnetId(), 77);
+    EXPECT_EQ("SOLICIT-ADVERTISE.mt_queued-process_started.77", alarm->getLabel());
+    EXPECT_EQ(alarm->getLowWater(), low_water);
+    EXPECT_EQ(alarm->getHighWater(), high_water);
+    EXPECT_EQ(alarm->getState(), Alarm::DISABLED);
+    EXPECT_GE(alarm->getStosTime(), start_time);
+}
+
+/// @brief Verifies Alarm invalid construction.
+TEST(Alarm, invalidConstructors) {
+    AlarmPtr alarm;
+
+    // Make sure we catch an invalid message pairing.
+    Duration low_water(milliseconds(50));
+    Duration high_water(milliseconds(250));
+    ASSERT_THROW_MSG(alarm.reset(new Alarm(AF_INET, DHCPDISCOVER, DHCPDISCOVER,
+                                 "process_started", "process_completed",
+                                 SUBNET_ID_GLOBAL, low_water, high_water)),
+                      BadValue,
+                      "Response type: DHCPDISCOVER not valid for query type: DHCPDISCOVER");
+
+    // Low water too high, should throw.
+    ASSERT_THROW_MSG(alarm.reset(new Alarm(AF_INET, DHCPDISCOVER, DHCPOFFER,
+                                "process_started", "process_completed",
+                                 SUBNET_ID_GLOBAL, high_water, low_water)),
+                      BadValue,
+                      "low water: 00:00:00.250000, must be less than high water:"
+                      " 00:00:00.050000");
+
+    // Create valid v6 key.
+    DurationKeyPtr key;
+    ASSERT_NO_THROW_LOG(key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE,
+                                  "mt_queued", "process_started", 77)));
+
+    // Low water too high, should throw.
+    ASSERT_THROW_MSG(alarm.reset(new Alarm(*key, high_water, low_water)),
+                     BadValue,
+                     "low water: 00:00:00.250000, must be less than high water:"
+                     " 00:00:00.050000");
+}
+
+TEST(Alarm, lowWaterHighWaterSetters) {
+    // Create valid v4 alarm.
+    Duration low_water(milliseconds(50));
+    Duration high_water(milliseconds(250));
+    AlarmPtr alarm;
+    ASSERT_NO_THROW_LOG(alarm.reset(new Alarm(AF_INET, DHCPDISCOVER, DHCPOFFER,
+                              "process_started", "process_completed",
+                              SUBNET_ID_GLOBAL,
+                              low_water, high_water)));
+
+    // Should be able to set thresholds to new, valid values.
+    low_water += milliseconds(50);
+    high_water -= milliseconds(100);
+    ASSERT_NO_THROW(alarm->setLowWater(low_water));
+    EXPECT_EQ(alarm->getLowWater(), low_water);
+    ASSERT_NO_THROW(alarm->setHighWater(high_water));
+    EXPECT_EQ(alarm->getHighWater(), high_water);
+
+    // Setting low too high should fail and leave Alarm intact.
+    ASSERT_THROW_MSG(alarm->setLowWater(high_water), BadValue,
+                     "low water: 00:00:00.150000, must be less than high water: 00:00:00.150000");
+    EXPECT_EQ(alarm->getLowWater(), low_water);
+
+    // Setting high too low should fail and leave Alarm intact.
+    ASSERT_THROW_MSG(alarm->setHighWater(low_water), BadValue,
+                     "high water: 00:00:00.100000, must be greater than low water: 00:00:00.100000");
+    EXPECT_EQ(alarm->getHighWater(), high_water);
+}
+
+TEST(Alarm, clearAndDisable) {
+    auto start_time = PktEvent::now();
+    AlarmPtr alarm;
+    ASSERT_NO_THROW_LOG(alarm.reset(new Alarm(AF_INET, DHCPDISCOVER, DHCPOFFER,
+                              "process_started", "process_completed",
+                              SUBNET_ID_GLOBAL, milliseconds(100), milliseconds(200))));
+
+    // Initial state should be CLEAR, stos_time_ should be close to now, no report time.
+    EXPECT_EQ(alarm->getState(), Alarm::CLEAR);
+    EXPECT_GE(alarm->getStosTime(), start_time);
+    EXPECT_EQ(alarm->getLastHighWaterReport(), PktEvent::EMPTY_TIME());
+
+    // Save stos then nap.
+    auto prev_time = alarm->getStosTime();
+    usleep(100);
+
+    // Change the state to DISABLED.  Should have a later stos_time_.
+    ASSERT_NO_THROW(alarm->disable());
+    EXPECT_EQ(alarm->getState(), Alarm::DISABLED);
+    EXPECT_GE(alarm->getStosTime(), prev_time);
+    EXPECT_EQ(alarm->getLastHighWaterReport(), PktEvent::EMPTY_TIME());
+
+    // While we're disabled verify operations that are not allowed.
+    ASSERT_THROW_MSG(alarm->checkSample(milliseconds(75), seconds(60)), InvalidOperation,
+                     "Alarm::checkSample() - should not be called when alarm is DISABLED");
+
+    // Save stos then nap.
+    prev_time = alarm->getStosTime();
+    usleep(100);
+
+    // Restore the alarm to CLEAR.
+    ASSERT_NO_THROW(alarm->clear());
+    EXPECT_EQ(alarm->getState(), Alarm::CLEAR);
+    EXPECT_GE(alarm->getStosTime(), prev_time);
+    EXPECT_EQ(alarm->getLastHighWaterReport(), PktEvent::EMPTY_TIME());
+}
+
+/// @brief Verifies the result of Alarm::checkSample() over the range of scenarios.
+/// The alarm is created in either the CLEAR or TRIGGERED state and then checkSample()
+/// is invoked.  The scenarios tested are described by the table below:
+///
+/// ```
+///                     INPUT                           |          OUTPUT
+///    Test sample relationship       Input  Report Int.|
+//     to the thresholds              State   Elapsed   | Report  State  Stos   Last Report
+///    -------------------------------------------------|----------------------------------
+///    sample < low_water                C      false   | false     C      -       -
+///    sample < low_water                C      true    | false     C      -       -
+///    sample < low_water                T      false   | true      C    updated  reset
+///    sample < low_water                T      true    | true      C    updated  reset
+///                                                     |
+///    sample == low_water               C      false   | false     C      -       -
+///    sample == low_water               C      true    | false     C      -       -
+///    sample == low_water               T      false   | false     T      -       -
+///    sample == low_water               T      true    | true      T             updated
+///                                                     |
+///    low_water < sample < high_water   C      false   | false     C      -       -
+///    low_water < sample < high_water   C      true    | false     C      -       -
+///    low_water < sample < high_water   T      false   | false     T      -       -
+///    low_water < sample < high_water   T      true    | true      T      -      updated
+///                                                     |
+///    sample == high water              C      false   | false     C      -       -
+///    sample == high water              C      true    | false     C      -       -
+///    sample == high water              T      false   | false     T      -       -
+///    sample == high water              T      true    | true      T      -      updated
+///                                                     |
+///    sample > high water               C      false   | true      T    updated  set
+///    sample > high water               C      true    | true      T    updated  set
+///    sample > high water               T      false   | false     T      -       -
+///    sample > high water               T      true    | true      T      -      updated
+/// ```
+TEST(Alarm, checkSample) {
+    // Create mnemonic constants.
+    Duration low_water(milliseconds(100));
+    Duration high_water(milliseconds(200));
+    Duration lt_low_water(milliseconds(50));
+    Duration eq_low_water = low_water;
+    Duration mid_range(milliseconds(150));
+    Duration eq_high_water = high_water;
+    Duration gt_high_water(milliseconds(250));
+    Duration report_interval(milliseconds(25));
+
+    bool report_elapsed = true;
+    bool should_report = true;
+
+    // Enumerates possible outcomes for last_high_water_report.
+    enum TimeChange {
+        none,       // no change
+        set,        // from empty time to time
+        updated,    // updated to a more recent time
+        reset       // reset to empty time
+    };
+
+    // Embodies a test scenario based on the table in the commentary. It does not
+    // include a column for stos_time_ changes as they are easily inferred.
+    struct Scenario {
+        Duration sample_;                   // duration to test the alarm with
+        Alarm::State input_state_;          // Starting state of the Alarm (CLEAR or TRIGGERED)
+        bool report_interval_elapsed_;      // True if report interval has elapsed
+        bool should_report_;                // True if checkSample() should return true
+        Alarm::State output_state_;         // Alarm state after calling checkSample()
+        TimeChange last_report_chg_;        // Expected change to last_high_water_report_
+    };
+
+    // Scenarios as described in the commentary.
+    std::list<Scenario> scenarios = {
+        { lt_low_water,   Alarm::CLEAR,     !report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
+        { lt_low_water,   Alarm::CLEAR,      report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
+        { lt_low_water,   Alarm::TRIGGERED, !report_elapsed,  should_report, Alarm::CLEAR,     TimeChange::reset },
+        { lt_low_water,   Alarm::TRIGGERED,  report_elapsed,  should_report, Alarm::CLEAR,     TimeChange::reset },
+
+        { eq_low_water,   Alarm::CLEAR,     !report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
+        { eq_low_water,   Alarm::CLEAR,      report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
+        { eq_low_water,   Alarm::TRIGGERED, !report_elapsed, !should_report, Alarm::TRIGGERED, TimeChange::none },
+        { eq_low_water,   Alarm::TRIGGERED,  report_elapsed,  should_report, Alarm::TRIGGERED, TimeChange::updated },
+
+        { mid_range,      Alarm::CLEAR,     !report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
+        { mid_range,      Alarm::CLEAR,      report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
+        { mid_range,      Alarm::TRIGGERED, !report_elapsed, !should_report, Alarm::TRIGGERED, TimeChange::none },
+        { mid_range,      Alarm::TRIGGERED,  report_elapsed,  should_report, Alarm::TRIGGERED, TimeChange::updated },
+
+        { eq_high_water,  Alarm::CLEAR,     !report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
+        { eq_high_water,  Alarm::CLEAR,      report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
+        { eq_high_water,  Alarm::TRIGGERED, !report_elapsed, !should_report, Alarm::TRIGGERED, TimeChange::none },
+        { eq_high_water,  Alarm::TRIGGERED,  report_elapsed,  should_report, Alarm::TRIGGERED, TimeChange::updated },
+
+        { gt_high_water,  Alarm::CLEAR,     !report_elapsed,  should_report, Alarm::TRIGGERED, TimeChange::set },
+        { gt_high_water,  Alarm::CLEAR,      report_elapsed,  should_report, Alarm::TRIGGERED, TimeChange::set },
+        { gt_high_water,  Alarm::TRIGGERED, !report_elapsed, !should_report, Alarm::TRIGGERED, TimeChange::none },
+        { gt_high_water,  Alarm::TRIGGERED,  report_elapsed,  should_report, Alarm::TRIGGERED, TimeChange::updated },
+    };
+
+    AlarmPtr alarm;
+    DurationKey key(AF_INET, DHCPDISCOVER, DHCPOFFER,
+                    "process_started", "process_completed", SUBNET_ID_GLOBAL);
+    size_t pass = 0;
+    for (auto const& scenario : scenarios) {
+        std::ostringstream oss;
+        oss << "scenario: " << pass++;
+        SCOPED_TRACE(oss.str());
+
+        auto start_time = PktEvent::now();
+
+        // Create an Alarm with the scenario starting characteristics.
+        ASSERT_NO_THROW_LOG(alarm.reset(new Alarm(key, low_water, high_water)));
+        if (scenario.input_state_ == Alarm::TRIGGERED) {
+            alarm->setState(Alarm::TRIGGERED);
+            alarm->setLastHighWaterReport(!scenario.report_interval_elapsed_ ?
+                                          PktEvent::now() : start_time - (report_interval * 2));
+        }
+
+        // Save the current timestamps.
+        auto prev_stos_time = alarm->getStosTime();
+        auto prev_report_time = alarm->getLastHighWaterReport();
+
+        // Take a little nap.
+        usleep(50);
+
+        // Invoke checkSample() with the scenario sample duration.  It should not throw.
+        bool should_report;
+        ASSERT_NO_THROW_LOG(should_report = alarm->checkSample(scenario.sample_, report_interval));
+
+        //  Verify that we returned the expected value for a reportable event (or not).
+        EXPECT_EQ(should_report, scenario.should_report_);
+
+        // Verify we ended up in the expected state.
+        ASSERT_EQ(alarm->getState(), scenario.output_state_);
+
+        // If the state changed, stos_time_ should have been updated.
+        if (scenario.input_state_ != scenario.output_state_) {
+            EXPECT_GT(alarm->getStosTime(), prev_stos_time);
+        } else {
+            EXPECT_EQ(alarm->getStosTime(), prev_stos_time);
+        }
+
+        // Verify the last_high_water_report_ outcome.
+        switch(scenario.last_report_chg_) {
+        case TimeChange::none:
+            EXPECT_EQ(alarm->getLastHighWaterReport(), prev_report_time);
+            break;
+        case TimeChange::set:
+            EXPECT_EQ(prev_report_time, PktEvent::EMPTY_TIME());
+            EXPECT_GE(alarm->getLastHighWaterReport(), alarm->getStosTime());
+            break;
+        case TimeChange::updated:
+            EXPECT_GT(alarm->getLastHighWaterReport(), prev_report_time);
+            break;
+        case TimeChange::reset:
+            EXPECT_EQ(alarm->getLastHighWaterReport(), PktEvent::EMPTY_TIME());
+            break;
+        }
+    }
+}
+
+} // end of anonymous namespace
index c417f3af32c8174e4b898c9a096e0cc3766e6cd7..5b788e5ffc28fa1e9a5340af5a244b0f1929299b 100644 (file)
@@ -232,311 +232,6 @@ TEST(DurationKey, validateMessagePairs6) {
     }
 }
 
-/// @brief Verifies Alarm construction.
-TEST(Alarm, validConstructors) {
-    AlarmPtr alarm;
-
-    auto start_time = PktEvent::now();
-
-    // Create valid v4 alarm, verify contents and label.
-    Duration low_water(milliseconds(50));
-    Duration high_water(milliseconds(250));
-    ASSERT_NO_THROW_LOG(alarm.reset(new Alarm(AF_INET, DHCPDISCOVER, DHCPOFFER,
-                              "process_started", "process_completed",
-                              SUBNET_ID_GLOBAL,
-                              low_water, high_water)));
-    ASSERT_TRUE(alarm);
-    EXPECT_EQ(alarm->getFamily(), AF_INET);
-    EXPECT_EQ(alarm->getQueryType(), DHCPDISCOVER);
-    EXPECT_EQ(alarm->getResponseType(), DHCPOFFER);
-    EXPECT_EQ(alarm->getStartEventLabel(), "process_started");
-    EXPECT_EQ(alarm->getEndEventLabel(), "process_completed");
-    EXPECT_EQ(alarm->getSubnetId(), SUBNET_ID_GLOBAL);
-    EXPECT_EQ("DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0", alarm->getLabel());
-    EXPECT_EQ(alarm->getSubnetId(), SUBNET_ID_GLOBAL);
-    EXPECT_EQ(alarm->getLowWater(), low_water);
-    EXPECT_EQ(alarm->getHighWater(), high_water);
-    EXPECT_EQ(alarm->getState(), Alarm::CLEAR);
-    EXPECT_GE(alarm->getStosTime(), start_time);
-
-    start_time = PktEvent::now();
-
-    // Create valid v6 key and use that to create an alarm. Verify contents and label.
-    DurationKeyPtr key;
-    ASSERT_NO_THROW_LOG(key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE,
-                                  "mt_queued", "process_started", 77)));
-
-    ASSERT_NO_THROW_LOG(alarm.reset(new Alarm(*key, low_water, high_water, false)));
-    ASSERT_TRUE(alarm);
-    EXPECT_EQ(alarm->getFamily(), AF_INET6);
-    EXPECT_EQ(alarm->getQueryType(), DHCPV6_SOLICIT);
-    EXPECT_EQ(alarm->getResponseType(), DHCPV6_ADVERTISE);
-    EXPECT_EQ(alarm->getStartEventLabel(), "mt_queued");
-    EXPECT_EQ(alarm->getEndEventLabel(), "process_started");
-    EXPECT_EQ(alarm->getSubnetId(), 77);
-    EXPECT_EQ("SOLICIT-ADVERTISE.mt_queued-process_started.77", alarm->getLabel());
-    EXPECT_EQ(alarm->getLowWater(), low_water);
-    EXPECT_EQ(alarm->getHighWater(), high_water);
-    EXPECT_EQ(alarm->getState(), Alarm::DISABLED);
-    EXPECT_GE(alarm->getStosTime(), start_time);
-}
-
-/// @brief Verifies Alarm invalid construction.
-TEST(Alarm, invalidConstructors) {
-    AlarmPtr alarm;
-
-    // Make sure we catch an invalid message pairing.
-    Duration low_water(milliseconds(50));
-    Duration high_water(milliseconds(250));
-    ASSERT_THROW_MSG(alarm.reset(new Alarm(AF_INET, DHCPDISCOVER, DHCPDISCOVER,
-                                 "process_started", "process_completed",
-                                 SUBNET_ID_GLOBAL, low_water, high_water)),
-                      BadValue,
-                      "Response type: DHCPDISCOVER not valid for query type: DHCPDISCOVER");
-
-    // Low water too high, should throw.
-    ASSERT_THROW_MSG(alarm.reset(new Alarm(AF_INET, DHCPDISCOVER, DHCPOFFER,
-                                "process_started", "process_completed",
-                                 SUBNET_ID_GLOBAL, high_water, low_water)),
-                      BadValue,
-                      "low water: 00:00:00.250000, must be less than high water:"
-                      " 00:00:00.050000");
-
-    // Create valid v6 key.
-    DurationKeyPtr key;
-    ASSERT_NO_THROW_LOG(key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE,
-                                  "mt_queued", "process_started", 77)));
-
-    // Low water too high, should throw.
-    ASSERT_THROW_MSG(alarm.reset(new Alarm(*key, high_water, low_water)),
-                     BadValue,
-                     "low water: 00:00:00.250000, must be less than high water:"
-                     " 00:00:00.050000");
-}
-
-TEST(Alarm, lowWaterHighWaterSetters) {
-    // Create valid v4 alarm.
-    Duration low_water(milliseconds(50));
-    Duration high_water(milliseconds(250));
-    AlarmPtr alarm;
-    ASSERT_NO_THROW_LOG(alarm.reset(new Alarm(AF_INET, DHCPDISCOVER, DHCPOFFER,
-                              "process_started", "process_completed",
-                              SUBNET_ID_GLOBAL,
-                              low_water, high_water)));
-
-    // Should be able to set thresholds to new, valid values.
-    low_water += milliseconds(50);
-    high_water -= milliseconds(100);
-    ASSERT_NO_THROW(alarm->setLowWater(low_water));
-    EXPECT_EQ(alarm->getLowWater(), low_water);
-    ASSERT_NO_THROW(alarm->setHighWater(high_water));
-    EXPECT_EQ(alarm->getHighWater(), high_water);
-
-    // Setting low too high should fail and leave Alarm intact.
-    ASSERT_THROW_MSG(alarm->setLowWater(high_water), BadValue,
-                     "low water: 00:00:00.150000, must be less than high water: 00:00:00.150000");
-    EXPECT_EQ(alarm->getLowWater(), low_water);
-
-    // Setting high too low should fail and leave Alarm intact.
-    ASSERT_THROW_MSG(alarm->setHighWater(low_water), BadValue,
-                     "high water: 00:00:00.100000, must be greater than low water: 00:00:00.100000");
-    EXPECT_EQ(alarm->getHighWater(), high_water);
-}
-
-TEST(Alarm, clearAndDisable) {
-    auto start_time = PktEvent::now();
-    AlarmPtr alarm;
-    ASSERT_NO_THROW_LOG(alarm.reset(new Alarm(AF_INET, DHCPDISCOVER, DHCPOFFER,
-                              "process_started", "process_completed",
-                              SUBNET_ID_GLOBAL, milliseconds(100), milliseconds(200))));
-
-    // Initial state should be CLEAR, stos_time_ should be close to now, no report time.
-    EXPECT_EQ(alarm->getState(), Alarm::CLEAR);
-    EXPECT_GE(alarm->getStosTime(), start_time);
-    EXPECT_EQ(alarm->getLastHighWaterReport(), PktEvent::EMPTY_TIME());
-
-    // Save stos then nap.
-    auto prev_time = alarm->getStosTime();
-    usleep(100);
-
-    // Change the state to DISABLED.  Should have a later stos_time_.
-    ASSERT_NO_THROW(alarm->disable());
-    EXPECT_EQ(alarm->getState(), Alarm::DISABLED);
-    EXPECT_GE(alarm->getStosTime(), prev_time);
-    EXPECT_EQ(alarm->getLastHighWaterReport(), PktEvent::EMPTY_TIME());
-
-    // While we're disabled verify operations that are not allowed.
-    ASSERT_THROW_MSG(alarm->checkSample(milliseconds(75), seconds(60)), InvalidOperation,
-                     "Alarm::checkSample() - should not be called when alarm is DISABLED");
-
-    // Save stos then nap.
-    prev_time = alarm->getStosTime();
-    usleep(100);
-
-    // Restore the alarm to CLEAR.
-    ASSERT_NO_THROW(alarm->clear());
-    EXPECT_EQ(alarm->getState(), Alarm::CLEAR);
-    EXPECT_GE(alarm->getStosTime(), prev_time);
-    EXPECT_EQ(alarm->getLastHighWaterReport(), PktEvent::EMPTY_TIME());
-}
-
-/// @brief Verifies the result of Alarm::checkSample() over the range of scenarios.
-/// The alarm is created in either the CLEAR or TRIGGERED state and then checkSample()
-/// is invoked.  The scenarios tested are described by the table below:
-///
-/// ```
-///                     INPUT                           |          OUTPUT
-///    Test sample relationship       Input  Report Int.|
-//     to the thresholds              State   Elapsed   | Report  State  Stos   Last Report
-///    -------------------------------------------------|----------------------------------
-///    sample < low_water                C      false   | false     C      -       -
-///    sample < low_water                C      true    | false     C      -       -
-///    sample < low_water                T      false   | true      C    updated  reset
-///    sample < low_water                T      true    | true      C    updated  reset
-///                                                     |
-///    sample == low_water               C      false   | false     C      -       -
-///    sample == low_water               C      true    | false     C      -       -
-///    sample == low_water               T      false   | false     T      -       -
-///    sample == low_water               T      true    | true      T             updated
-///                                                     |
-///    low_water < sample < high_water   C      false   | false     C      -       -
-///    low_water < sample < high_water   C      true    | false     C      -       -
-///    low_water < sample < high_water   T      false   | false     T      -       -
-///    low_water < sample < high_water   T      true    | true      T      -      updated
-///                                                     |
-///    sample == high water              C      false   | false     C      -       -
-///    sample == high water              C      true    | false     C      -       -
-///    sample == high water              T      false   | false     T      -       -
-///    sample == high water              T      true    | true      T      -      updated
-///                                                     |
-///    sample > high water               C      false   | true      T    updated  set
-///    sample > high water               C      true    | true      T    updated  set
-///    sample > high water               T      false   | false     T      -       -
-///    sample > high water               T      true    | true      T      -      updated
-/// ```
-TEST(Alarm, checkSample) {
-    // Create mnemonic constants.
-    Duration low_water(milliseconds(100));
-    Duration high_water(milliseconds(200));
-    Duration lt_low_water(milliseconds(50));
-    Duration eq_low_water = low_water;
-    Duration mid_range(milliseconds(150));
-    Duration eq_high_water = high_water;
-    Duration gt_high_water(milliseconds(250));
-    Duration report_interval(milliseconds(25));
-
-    bool report_elapsed = true;
-    bool should_report = true;
-
-    // Enumerates possible outcomes for last_high_water_report.
-    enum TimeChange {
-        none,       // no change
-        set,        // from empty time to time
-        updated,    // updated to a more recent time
-        reset       // reset to empty time
-    };
-
-    // Embodies a test scenario based on the table in the commentary. It does not
-    // include a column for stos_time_ changes as they are easily inferred.
-    struct Scenario {
-        Duration sample_;                   // duration to test the alarm with
-        Alarm::State input_state_;          // Starting state of the Alarm (CLEAR or TRIGGERED)
-        bool report_interval_elapsed_;      // True if report interval has elapsed
-        bool should_report_;                // True if checkSample() should return true
-        Alarm::State output_state_;         // Alarm state after calling checkSample()
-        TimeChange last_report_chg_;        // Expected change to last_high_water_report_
-    };
-
-    // Scenarios as described in the commentary.
-    std::list<Scenario> scenarios = {
-        { lt_low_water,   Alarm::CLEAR,     !report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
-        { lt_low_water,   Alarm::CLEAR,      report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
-        { lt_low_water,   Alarm::TRIGGERED, !report_elapsed,  should_report, Alarm::CLEAR,     TimeChange::reset },
-        { lt_low_water,   Alarm::TRIGGERED,  report_elapsed,  should_report, Alarm::CLEAR,     TimeChange::reset },
-
-        { eq_low_water,   Alarm::CLEAR,     !report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
-        { eq_low_water,   Alarm::CLEAR,      report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
-        { eq_low_water,   Alarm::TRIGGERED, !report_elapsed, !should_report, Alarm::TRIGGERED, TimeChange::none },
-        { eq_low_water,   Alarm::TRIGGERED,  report_elapsed,  should_report, Alarm::TRIGGERED, TimeChange::updated },
-
-        { mid_range,      Alarm::CLEAR,     !report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
-        { mid_range,      Alarm::CLEAR,      report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
-        { mid_range,      Alarm::TRIGGERED, !report_elapsed, !should_report, Alarm::TRIGGERED, TimeChange::none },
-        { mid_range,      Alarm::TRIGGERED,  report_elapsed,  should_report, Alarm::TRIGGERED, TimeChange::updated },
-
-        { eq_high_water,  Alarm::CLEAR,     !report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
-        { eq_high_water,  Alarm::CLEAR,      report_elapsed, !should_report, Alarm::CLEAR,     TimeChange::none },
-        { eq_high_water,  Alarm::TRIGGERED, !report_elapsed, !should_report, Alarm::TRIGGERED, TimeChange::none },
-        { eq_high_water,  Alarm::TRIGGERED,  report_elapsed,  should_report, Alarm::TRIGGERED, TimeChange::updated },
-
-        { gt_high_water,  Alarm::CLEAR,     !report_elapsed,  should_report, Alarm::TRIGGERED, TimeChange::set },
-        { gt_high_water,  Alarm::CLEAR,      report_elapsed,  should_report, Alarm::TRIGGERED, TimeChange::set },
-        { gt_high_water,  Alarm::TRIGGERED, !report_elapsed, !should_report, Alarm::TRIGGERED, TimeChange::none },
-        { gt_high_water,  Alarm::TRIGGERED,  report_elapsed,  should_report, Alarm::TRIGGERED, TimeChange::updated },
-    };
-
-    AlarmPtr alarm;
-    DurationKey key(AF_INET, DHCPDISCOVER, DHCPOFFER,
-                    "process_started", "process_completed", SUBNET_ID_GLOBAL);
-    size_t pass = 0;
-    for (auto const& scenario : scenarios) {
-        std::ostringstream oss;
-        oss << "scenario: " << pass++;
-        SCOPED_TRACE(oss.str());
-
-        auto start_time = PktEvent::now();
-
-        // Create an Alarm with the scenario starting characteristics.
-        ASSERT_NO_THROW_LOG(alarm.reset(new Alarm(key, low_water, high_water)));
-        if (scenario.input_state_ == Alarm::TRIGGERED) {
-            alarm->setState(Alarm::TRIGGERED);
-            alarm->setLastHighWaterReport(!scenario.report_interval_elapsed_ ?
-                                          PktEvent::now() : start_time - (report_interval * 2));
-        }
-
-        // Save the current timestamps.
-        auto prev_stos_time = alarm->getStosTime();
-        auto prev_report_time = alarm->getLastHighWaterReport();
-
-        // Take a little nap.
-        usleep(50);
-
-        // Invoke checkSample() with the scenario sample duration.  It should not throw.
-        bool should_report;
-        ASSERT_NO_THROW_LOG(should_report = alarm->checkSample(scenario.sample_, report_interval));
-
-        //  Verify that we returned the expected value for a reportable event (or not).
-        EXPECT_EQ(should_report, scenario.should_report_);
-
-        // Verify we ended up in the expected state.
-        ASSERT_EQ(alarm->getState(), scenario.output_state_);
-
-        // If the state changed, stos_time_ should have been updated.
-        if (scenario.input_state_ != scenario.output_state_) {
-            EXPECT_GT(alarm->getStosTime(), prev_stos_time);
-        } else {
-            EXPECT_EQ(alarm->getStosTime(), prev_stos_time);
-        }
-
-        // Verify the last_high_water_report_ outcome.
-        switch(scenario.last_report_chg_) {
-        case TimeChange::none:
-            EXPECT_EQ(alarm->getLastHighWaterReport(), prev_report_time);
-            break;
-        case TimeChange::set:
-            EXPECT_EQ(prev_report_time, PktEvent::EMPTY_TIME());
-            EXPECT_GE(alarm->getLastHighWaterReport(), alarm->getStosTime());
-            break;
-        case TimeChange::updated:
-            EXPECT_GT(alarm->getLastHighWaterReport(), prev_report_time);
-            break;
-        case TimeChange::reset:
-            EXPECT_EQ(alarm->getLastHighWaterReport(), PktEvent::EMPTY_TIME());
-            break;
-        }
-    }
-}
-
 /// @brief Verifies MonitoredDuration valid construction.
 TEST(MonitoredDuration, validConstructors) {
     MonitoredDurationPtr mond;