diff options
author | Razvan Becheriu <razvan@isc.org> | 2024-03-26 18:27:27 +0100 |
---|---|---|
committer | Thomas Markwalder <tmark@isc.org> | 2024-03-26 20:33:28 +0100 |
commit | e917b75f500d4b8d8e2833b000d4c8620e996a7d (patch) | |
tree | 84d3ca8068ad565d7f6cba68b4f6a31392f0657d | |
parent | [#3278] Fix JSON in ARM again (diff) | |
download | kea-e917b75f500d4b8d8e2833b000d4c8620e996a7d.tar.xz kea-e917b75f500d4b8d8e2833b000d4c8620e996a7d.zip |
[#3278] addressed review
-rw-r--r-- | doc/sphinx/arm/hooks-perfmon.rst | 24 | ||||
-rw-r--r-- | src/hooks/dhcp/perfmon/alarm.h | 8 | ||||
-rw-r--r-- | src/hooks/dhcp/perfmon/libloadtests/load_unload_unittests.cc | 24 | ||||
-rw-r--r-- | src/hooks/dhcp/perfmon/monitored_duration.cc | 2 | ||||
-rw-r--r-- | src/hooks/dhcp/perfmon/monitored_duration.h | 2 | ||||
-rw-r--r-- | src/hooks/dhcp/perfmon/perfmon_config.cc | 102 | ||||
-rw-r--r-- | src/hooks/dhcp/perfmon/perfmon_config.h | 117 | ||||
-rw-r--r-- | src/hooks/dhcp/perfmon/perfmon_mgr.cc | 2 | ||||
-rw-r--r-- | src/hooks/dhcp/perfmon/perfmon_mgr.h | 38 | ||||
-rw-r--r-- | src/hooks/dhcp/perfmon/tests/alarm_parser_unittests.cc | 130 | ||||
-rw-r--r-- | src/hooks/dhcp/perfmon/tests/duration_key_parser_unittests.cc | 24 | ||||
-rw-r--r-- | src/hooks/dhcp/perfmon/tests/monitored_duration_store_unittests.cc | 2 | ||||
-rw-r--r-- | src/hooks/dhcp/perfmon/tests/perfmon_config_unittests.cc | 384 | ||||
-rw-r--r-- | src/hooks/dhcp/perfmon/tests/perfmon_mgr_unittests.cc | 34 |
14 files changed, 448 insertions, 445 deletions
diff --git a/doc/sphinx/arm/hooks-perfmon.rst b/doc/sphinx/arm/hooks-perfmon.rst index d668e8c186..b5207cc4bc 100644 --- a/doc/sphinx/arm/hooks-perfmon.rst +++ b/doc/sphinx/arm/hooks-perfmon.rst @@ -127,22 +127,22 @@ An example of the anticipated configuration is shown below: { "library": "lib/kea/hooks/libdhcp_perfmon.so", "parameters": { - "enable-monitoring" : true, - "interval-width-secs" : 5, - "stats-mgr-reporting" : true, - "alarm-report-secs" : 600, + "enable-monitoring": true, + "interval-width-secs": 5, + "stats-mgr-reporting": true, + "alarm-report-secs": 600, "alarms": [ { "duration-key": { - "query-type" : "DHCPDISCOVER", - "response-type" : "DHCPOFFER", - "start-event" : "process-started", - "stop-event" : "process-completed", - "subnet-id" : 0 + "query-type": "DHCPDISCOVER", + "response-type": "DHCPOFFER", + "start-event": "process-started", + "stop-event": "process-completed", + "subnet-id": 0 }, - "enable-alarm" : true, - "high-water-ms" : 500, - "low-water-ms" : 25 + "enable-alarm": true, + "high-water-ms": 500, + "low-water-ms": 25 }] } }] diff --git a/src/hooks/dhcp/perfmon/alarm.h b/src/hooks/dhcp/perfmon/alarm.h index 00005572ea..883431d91a 100644 --- a/src/hooks/dhcp/perfmon/alarm.h +++ b/src/hooks/dhcp/perfmon/alarm.h @@ -35,8 +35,8 @@ public: /// @param stop_event_label label of the end event /// @param subnet_id SubnetID of the selected subnet /// @param low_water threshold below which the average duration must fall to clear the alarm - /// @param high_water threshold above which the average duration must rise to trigger the alarm. - /// @param enabled true sets state to CLEAR, otherwise DISABLED, defaults to true. + /// @param high_water threshold above which the average duration must rise to trigger the alarm + /// @param 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& stop_event_label, dhcp::SubnetID subnet_id, @@ -46,8 +46,8 @@ public: /// /// @param key composite key that identifies the alarm /// @param low_water threshold below which the average duration must fall to clear the alarm - /// @param high_water threshold above which the average duration must rise to trigger the alarm. - /// @param enabled true sets state to CLEAR, otherwise DISABLED, defaults to true. + /// @param high_water threshold above which the average duration must rise to trigger the alarm + /// @param 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 diff --git a/src/hooks/dhcp/perfmon/libloadtests/load_unload_unittests.cc b/src/hooks/dhcp/perfmon/libloadtests/load_unload_unittests.cc index 92792d26a6..e2996d245e 100644 --- a/src/hooks/dhcp/perfmon/libloadtests/load_unload_unittests.cc +++ b/src/hooks/dhcp/perfmon/libloadtests/load_unload_unittests.cc @@ -47,21 +47,21 @@ public: virtual isc::data::ElementPtr validConfigParams() { std::string valid_config = R"({ - "enable-monitoring" : true, - "interval-width-secs" : 5, - "stats-mgr-reporting" : true, - "alarm-report-secs" : 600, + "enable-monitoring": true, + "interval-width-secs": 5, + "stats-mgr-reporting": true, + "alarm-report-secs": 600, "alarms": [{ "duration-key": { - "query-type" : "*", - "response-type" : "*", - "start-event" : "socket-received", - "stop-event" : "buffer-read", - "subnet-id" : 70 + "query-type": "*", + "response-type": "*", + "start-event": "socket-received", + "stop-event": "buffer-read", + "subnet-id": 70 }, - "enable-alarm" : true, - "high-water-ms" : 500, - "low-water-ms" : 25 + "enable-alarm": true, + "high-water-ms": 500, + "low-water-ms": 25 }] })"; diff --git a/src/hooks/dhcp/perfmon/monitored_duration.cc b/src/hooks/dhcp/perfmon/monitored_duration.cc index d010db106d..906f6d7d39 100644 --- a/src/hooks/dhcp/perfmon/monitored_duration.cc +++ b/src/hooks/dhcp/perfmon/monitored_duration.cc @@ -169,7 +169,7 @@ std::string DurationKey::getLabel() const { std::ostringstream oss; oss << getMessageTypeLabel(family_, query_type_) - << "-" + << "-" << getMessageTypeLabel(family_, response_type_) << "." << start_event_label_ << "-" << stop_event_label_ << "." << subnet_id_; diff --git a/src/hooks/dhcp/perfmon/monitored_duration.h b/src/hooks/dhcp/perfmon/monitored_duration.h index 1ab40bef63..83a0db6d95 100644 --- a/src/hooks/dhcp/perfmon/monitored_duration.h +++ b/src/hooks/dhcp/perfmon/monitored_duration.h @@ -189,7 +189,7 @@ public: } /// @brief Get a label for a family-specific message type (e.g. - /// "DHCPDISCOVER", "SOLICIT") + /// "DHCPDISCOVER", "SOLICIT") /// /// @param family Protocol family of the key (AF_INET or AF_INET6) /// @param msg_type numeric message type to translate diff --git a/src/hooks/dhcp/perfmon/perfmon_config.cc b/src/hooks/dhcp/perfmon/perfmon_config.cc index 4fd4187160..99ab61c1d4 100644 --- a/src/hooks/dhcp/perfmon/perfmon_config.cc +++ b/src/hooks/dhcp/perfmon/perfmon_config.cc @@ -22,11 +22,11 @@ namespace perfmon { const data::SimpleKeywords DurationKeyParser::CONFIG_KEYWORDS = { - { "query-type", Element::string }, - { "response-type", Element::string }, - { "start-event", Element::string }, - { "stop-event", Element::string }, - { "subnet-id", Element::integer } + {"query-type", Element::string}, + {"response-type", Element::string}, + {"start-event", Element::string}, + {"stop-event", Element::string}, + {"subnet-id", Element::integer} }; uint16_t @@ -63,56 +63,58 @@ DurationKeyParser::getMessageNameType4(const std::string& name) { uint16_t DurationKeyParser::getMessageNameType6(const std::string& name) { static std::map<std::string, uint16_t> name_type_map = { - {"", DHCPV6_NOTYPE}, - {"*", DHCPV6_NOTYPE}, - {"SOLICIT", DHCPV6_SOLICIT}, - {"ADVERTISE", DHCPV6_ADVERTISE}, - {"REQUEST", DHCPV6_REQUEST}, - {"CONFIRM", DHCPV6_CONFIRM}, - {"RENEW", DHCPV6_RENEW}, - {"REBIND", DHCPV6_REBIND}, - {"REPLY", DHCPV6_REPLY}, - {"RELEASE", DHCPV6_RELEASE}, - {"DECLINE", DHCPV6_DECLINE}, - {"RECONFIGURE", DHCPV6_RECONFIGURE}, - {"INFORMATION_REQUEST", DHCPV6_INFORMATION_REQUEST}, - {"RELAY_FORW", DHCPV6_RELAY_FORW}, - {"RELAY_REPL", DHCPV6_RELAY_REPL}, - {"LEASEQUERY", DHCPV6_LEASEQUERY}, - {"LEASEQUERY_REPLY", DHCPV6_LEASEQUERY_REPLY}, - {"LEASEQUERY_DONE", DHCPV6_LEASEQUERY_DONE}, - {"LEASEQUERY_DATA", DHCPV6_LEASEQUERY_DATA}, - {"RECONFIGURE_REQUEST", DHCPV6_RECONFIGURE_REQUEST}, - {"RECONFIGURE_REPLY", DHCPV6_RECONFIGURE_REPLY}, - {"DHCPV4_QUERY", DHCPV6_DHCPV4_QUERY}, - {"DHCPV4_RESPONSE", DHCPV6_DHCPV4_RESPONSE}, - {"ACTIVELEASEQUERY", DHCPV6_ACTIVELEASEQUERY}, - {"STARTTLS", DHCPV6_STARTTLS}, - {"BNDUPD", DHCPV6_BNDUPD}, - {"BNDREPLY", DHCPV6_BNDREPLY}, - {"POOLREQ", DHCPV6_POOLREQ}, - {"POOLRESP", DHCPV6_POOLRESP}, - {"UPDREQ", DHCPV6_UPDREQ}, - {"UPDREQALL", DHCPV6_UPDREQALL}, - {"UPDDONE", DHCPV6_UPDDONE}, - {"CONNECT", DHCPV6_CONNECT}, - {"CONNECTREPLY", DHCPV6_CONNECTREPLY}, - {"DISCONNECT", DHCPV6_DISCONNECT}, - {"STATE", DHCPV6_STATE}, - {"CONTACT", DHCPV6_CONTACT} + {"", DHCPV6_NOTYPE}, + {"*", DHCPV6_NOTYPE}, + {"SOLICIT", DHCPV6_SOLICIT}, + {"ADVERTISE", DHCPV6_ADVERTISE}, + {"REQUEST", DHCPV6_REQUEST}, + {"CONFIRM", DHCPV6_CONFIRM}, + {"RENEW", DHCPV6_RENEW}, + {"REBIND", DHCPV6_REBIND}, + {"REPLY", DHCPV6_REPLY}, + {"RELEASE", DHCPV6_RELEASE}, + {"DECLINE", DHCPV6_DECLINE}, + {"RECONFIGURE", DHCPV6_RECONFIGURE}, + {"INFORMATION_REQUEST", DHCPV6_INFORMATION_REQUEST}, + {"RELAY_FORW", DHCPV6_RELAY_FORW}, + {"RELAY_REPL", DHCPV6_RELAY_REPL}, + {"LEASEQUERY", DHCPV6_LEASEQUERY}, + {"LEASEQUERY_REPLY", DHCPV6_LEASEQUERY_REPLY}, + {"LEASEQUERY_DONE", DHCPV6_LEASEQUERY_DONE}, + {"LEASEQUERY_DATA", DHCPV6_LEASEQUERY_DATA}, + {"RECONFIGURE_REQUEST", DHCPV6_RECONFIGURE_REQUEST}, + {"RECONFIGURE_REPLY", DHCPV6_RECONFIGURE_REPLY}, + {"DHCPV4_QUERY", DHCPV6_DHCPV4_QUERY}, + {"DHCPV4_RESPONSE", DHCPV6_DHCPV4_RESPONSE}, + {"ACTIVELEASEQUERY", DHCPV6_ACTIVELEASEQUERY}, + {"STARTTLS", DHCPV6_STARTTLS}, + {"BNDUPD", DHCPV6_BNDUPD}, + {"BNDREPLY", DHCPV6_BNDREPLY}, + {"POOLREQ", DHCPV6_POOLREQ}, + {"POOLRESP", DHCPV6_POOLRESP}, + {"UPDREQ", DHCPV6_UPDREQ}, + {"UPDREQALL", DHCPV6_UPDREQALL}, + {"UPDDONE", DHCPV6_UPDDONE}, + {"CONNECT", DHCPV6_CONNECT}, + {"CONNECTREPLY", DHCPV6_CONNECTREPLY}, + {"DISCONNECT", DHCPV6_DISCONNECT}, + {"STATE", DHCPV6_STATE}, + {"CONTACT", DHCPV6_CONTACT} }; try { const auto& found = name_type_map.at(name); - return(found); + return (found); } catch (const std::out_of_range& ex) { isc_throw(BadValue, "'" << name << "' is not a valid DHCPV6 message type"); } } uint16_t -DurationKeyParser::getMessageType(data::ConstElementPtr config, uint16_t family, - const std::string param_name, bool required /*= true */) { +DurationKeyParser::getMessageType(data::ConstElementPtr config, + uint16_t family, + const std::string& param_name, + bool required /*= true */) { // Parse members. uint16_t msg_type = 0; ConstElementPtr elem = config->get(param_name); @@ -255,11 +257,11 @@ AlarmParser::parse(data::ConstElementPtr config, uint16_t family) { const data::SimpleKeywords PerfMonConfig::CONFIG_KEYWORDS = { - { "enable-monitoring", Element::boolean }, - { "interval-width-secs", Element::integer }, - { "stats-mgr-reporting", Element::boolean }, - { "alarm-report-secs", Element::integer}, - { "alarms", Element::list} + {"enable-monitoring", Element::boolean}, + {"interval-width-secs", Element::integer}, + {"stats-mgr-reporting", Element::boolean}, + {"alarm-report-secs", Element::integer}, + {"alarms", Element::list} }; PerfMonConfig::PerfMonConfig(uint16_t family) diff --git a/src/hooks/dhcp/perfmon/perfmon_config.h b/src/hooks/dhcp/perfmon/perfmon_config.h index c004d3d92c..cc03616a8b 100644 --- a/src/hooks/dhcp/perfmon/perfmon_config.h +++ b/src/hooks/dhcp/perfmon/perfmon_config.h @@ -22,22 +22,22 @@ namespace perfmon { /// { /// "library": "lib/kea/hooks/libdhcp_perf_mon.so", /// "parameters": { -/// "enable-monitoring" : true, -/// "interval-width-secs" : 5, -/// "stats-mgr-reporting" : true, -/// "alarm-report-secs" : 600, +/// "enable-monitoring": true, +/// "interval-width-secs": 5, +/// "stats-mgr-reporting": true, +/// "alarm-report-secs": 600, /// "alarms": [ /// { /// "duration-key": { -/// "query-type" : "DHCPDISCOVER", -/// "response-type" : "DHCPOFFER", -/// "start-event" : "process-started", -/// "stop-event" : "process-completed", -/// "subnet-id" : 0 +/// "query-type": "DHCPDISCOVER", +/// "response-type": "DHCPOFFER", +/// "start-event": "process-started", +/// "stop-event": "process-completed", +/// "subnet-id": 0 /// }, -/// "enable-alarm" : true, -/// "high-water-ms" : 500, -/// "low-water-ms" : 25 +/// "enable-alarm": true, +/// "high-water-ms": 500, +/// "low-water-ms": 25 /// }, /// .. /// }] @@ -45,7 +45,7 @@ namespace perfmon { /// } /// @endcode -/// @brief Parses configuration parameters for a single DurationKey +/// @brief Parses configuration parameters for a single DurationKey. /// /// DurationKey is used to identify both MonitoredDurations and /// Alarms, thus they could be use to define either in configuration @@ -57,38 +57,39 @@ public: /// @brief List of valid parameters and expected types. static const data::SimpleKeywords CONFIG_KEYWORDS; - /// @brief Constructor + /// @brief Constructor. explicit DurationKeyParser() = default; - /// @brief Destructor - ~DurationKeyParser() = default; + /// @brief Destructor. + ~DurationKeyParser() = default; - /// @brief Convert a configuration parameter to family-specific message type + /// @brief Convert a configuration parameter to family-specific message type. /// /// @param config element map containing the duration key parameters. - /// @param family protocol family AF_INET or AF_INET6 - /// @param param_name configuration parameter name + /// @param family protocol family AF_INET or AF_INET6. + /// @param param_name configuration parameter name. /// @param required if true then function will throw if the parameter does /// not exist in the configuration. Defaults to true. /// /// @return numeric message type, returns DHCP_NOTYPE if name is empty. /// @throw DhcpConfigError if parameter type or value is not valid, or when - /// requrred is true and the parameter is not in the map. + /// required is true and the parameter is not in the map. static uint16_t getMessageType(data::ConstElementPtr config, - uint16_t family, const std::string param_name, + uint16_t family, + const std::string& param_name, bool required = true); - /// @brief Convert string message name to DHCP message type + /// @brief Convert string message name to DHCP message type. /// - /// @param name upper-case message name (e.g "DHCPDISCOVER", "DHCPOFFER") + /// @param name upper-case message name (e.g "DHCPDISCOVER", "DHCPOFFER"). /// /// @return numeric message type, returns DHCP_NOTYPE if name is empty. /// @throw BadValue if the message name is unknown. static uint16_t getMessageNameType4(const std::string& name); - /// @brief Convert string message name to DHCP6 message type + /// @brief Convert string message name to DHCP6 message type. /// - /// @param name upper-case message name (e.g "DHCPV6_SOLICIT", "DHCV6_REPLY") + /// @param name upper-case message name (e.g "DHCPV6_SOLICIT", "DHCV6_REPLY"). /// /// @return numeric message type, returns DHCPV6_NOTYPE if name is empty. /// @throw BadValue if the message name is unknown. @@ -97,7 +98,7 @@ public: /// @brief Convert a map of Elements into a DurationKey. /// /// @param config element map containing the duration key parameters. - /// @param family protocol family AF_INET or AF_INET6 + /// @param family protocol family AF_INET or AF_INET6. static DurationKeyPtr parse(data::ConstElementPtr config, uint16_t family); /// @brief Convert a DurationKey into a map of Elements. @@ -108,22 +109,22 @@ public: static data::ElementPtr toElement(DurationKeyPtr key); }; -/// @brief Parses configuration parameters for a single Alarm +/// @brief Parses configuration parameters for a single Alarm. class AlarmParser { public: /// @brief List of valid parameters and expected types. static const data::SimpleKeywords CONFIG_KEYWORDS; - /// @brief Constructor + /// @brief Constructor. explicit AlarmParser(); - /// @brief Destructor + /// @brief Destructor. ~AlarmParser() = default; /// @brief /// /// @param config element map containing the alarm parameters. - /// @param family protocol family AF_INET or AF_INET6 + /// @param family protocol family AF_INET or AF_INET6. static AlarmPtr parse(data::ConstElementPtr config, uint16_t family); }; @@ -137,15 +138,15 @@ public: /// @brief List of valid parameter defaults. static const data::SimpleDefaults SIMPLE_DEFAULTS; - /// @brief Constructor + /// @brief Constructor. explicit PerfMonConfig(uint16_t family); - /// @brief Destructor + /// @brief Destructor. virtual ~PerfMonConfig() = default; - /// @brief Extracts member values from an Element::map + /// @brief Extracts member values from an Element::map. /// - /// @param config map of configuration parameters + /// @param config map of configuration parameters. /// /// @throw DhcpConfigError if invalid values are detected. void parse(data::ConstElementPtr config); @@ -153,80 +154,80 @@ public: /// @brief Re-creates the AlarmStore and populates it by parsing a /// list of alarm elements. /// - /// @param config list of alarm configuration elements + /// @param config list of alarm configuration elements. /// /// @throw DhcpConfigError if a parsing error occurs or /// there are duplicate alarm keys. void parseAlarms(data::ConstElementPtr config); - /// @brief Fetches the value of enable-monitoring + /// @brief Fetches the value of enable-monitoring. /// - /// @return boolean value of enable-monitoring + /// @return boolean value of enable-monitoring. bool getEnableMonitoring() const { return (enable_monitoring_); - }; + } - /// @brief Sets the value of enable-monitoring + /// @brief Sets the value of enable-monitoring. /// - /// @param value new value for enable-monitoring + /// @param value new value for enable-monitoring. void setEnableMonitoring(bool value) { enable_monitoring_ = value; } - /// @brief Fetches the value of interval-width-secs + /// @brief Fetches the value of interval-width-secs. /// - /// @return integer value of interval-width-secs + /// @return integer value of interval-width-secs. uint32_t getIntervalWidthSecs() const { return (interval_width_secs_); } - /// @brief Sets the value of interval-width-secs + /// @brief Sets the value of interval-width-secs. /// - /// @param value new value for interval-width-secs + /// @param value new value for interval-width-secs. void setIntervalWidthSecs(uint32_t value) { interval_width_secs_ = value; } - /// @brief Fetches the value of stats-mgr-reporting + /// @brief Fetches the value of stats-mgr-reporting. /// - /// @return boolean value of stats-mgr-reporting + /// @return boolean value of stats-mgr-reporting. bool getStatsMgrReporting() const { return (stats_mgr_reporting_); }; - /// @brief Sets the value of stats-mgr-reporting + /// @brief Sets the value of stats-mgr-reporting. /// - /// @param value new value for stats-mgr-reporting + /// @param value new value for stats-mgr-reporting. void setStatsMgrReporting(bool value) { stats_mgr_reporting_ = value; } - /// @brief Fetches the value of alarm-report-secs + /// @brief Fetches the value of alarm-report-secs. /// - /// @return integer value of alarm-report-secs + /// @return integer value of alarm-report-secs. uint32_t getAlarmReportSecs() const { return (alarm_report_secs_); } - /// @brief Sets the value of alarm-report-secs + /// @brief Sets the value of alarm-report-secs. /// - /// @param value new value for alarm-report-secs + /// @param value new value for alarm-report-secs. void setAlarmReportSecs(uint32_t value) { alarm_report_secs_ = value; } - /// @brief Get protocol family + /// @brief Get protocol family. /// - /// @return uint16_t containing the family (AF_INET or AF_INET6) + /// @return uint16_t containing the family (AF_INET or AF_INET6). uint16_t getFamily() { return (family_); } - /// @brief Get the alarm store + /// @brief Get the alarm store. /// - /// @return pointer to the alarm store + /// @return pointer to the alarm store. AlarmStorePtr getAlarmStore() { - return alarm_store_; + return (alarm_store_); } protected: @@ -247,7 +248,7 @@ protected: /// Defaults to true. bool stats_mgr_reporting_; - /// @brief Nubmer of seconds between reports of a raised alarm. + /// @brief Number of seconds between reports of a raised alarm. /// Defaults to 300. A value of zero disables alarms. uint32_t alarm_report_secs_; diff --git a/src/hooks/dhcp/perfmon/perfmon_mgr.cc b/src/hooks/dhcp/perfmon/perfmon_mgr.cc index 09f1ffbf0f..d24a548368 100644 --- a/src/hooks/dhcp/perfmon/perfmon_mgr.cc +++ b/src/hooks/dhcp/perfmon/perfmon_mgr.cc @@ -25,7 +25,7 @@ PerfMonMgr::PerfMonMgr(uint16_t family_) duration_store_.reset(new MonitoredDurationStore(family_, interval_duration_)); } -void PerfMonMgr::configure(const ConstElementPtr & params) { +void PerfMonMgr::configure(const ConstElementPtr& params) { if (!params) { // User wants passive logging only. setEnableMonitoring(false); diff --git a/src/hooks/dhcp/perfmon/perfmon_mgr.h b/src/hooks/dhcp/perfmon/perfmon_mgr.h index 3164fb8f1d..db73f2a2d1 100644 --- a/src/hooks/dhcp/perfmon/perfmon_mgr.h +++ b/src/hooks/dhcp/perfmon/perfmon_mgr.h @@ -25,12 +25,12 @@ namespace perfmon { /// PerfMonConfig. class PerfMonMgr : public PerfMonConfig { public: - /// @brief Constructor + /// @brief Constructor. /// /// @param family Protocol family AF_INET or AF_INET6. explicit PerfMonMgr(uint16_t family); - /// @brief Destructor + /// @brief Destructor. virtual ~PerfMonMgr() = default; /// @brief Parses the hook library 'parameters' element. @@ -38,18 +38,18 @@ public: /// @param params map of configuration parameters to parse. void configure(const isc::data::ConstElementPtr& params); - /// @brief Processes the event stack of a query packet + /// @brief Processes the event stack of a query packet. /// /// @todo DETAILS TO FOLLOW /// - /// @param query query packet whose stack is to be processed - /// @param response response packet generated for the query - /// @param subnet_id id of the selected subnet + /// @param query query packet whose stack is to be processed. + /// @param response response packet generated for the query. + /// @param subnet_id id of the selected subnet. void processPktEventStack(isc::dhcp::PktPtr query, isc::dhcp::PktPtr response, const isc::dhcp::SubnetID& subnet_id); - /// @brief Adds a duration sample to a MonitoredDuration + /// @brief Adds a duration sample to a MonitoredDuration. /// /// The MonitoredDuration identified by the given key is fetched from /// the store and updated with the sample. If the update returns the @@ -58,28 +58,28 @@ public: /// If the check returns the alarm, then the alarm has undergone a /// reportable event and is passed to reporting. /// - /// @param key identifies the duration to update + /// @param key identifies the duration to update. /// @param sample amount of time that elapsed between the two events - /// identified in the key + /// identified in the key. void addDurationSample(DurationKeyPtr key, const Duration& sample); - /// @brief Emits an entry to StatsMgr for a given duration + /// @brief Emits an entry to StatsMgr for a given duration. /// /// Calculates the average duration for the reportable interval and /// reports the value to StatsMgr if stat-mgr-reporting is true. /// - /// @param duration duration to report + /// @param duration duration to report. /// /// @return Always returns the average duration for reportable interval. Duration reportToStatsMgr(MonitoredDurationPtr duration); - /// @brief Emits a report for a given alarm + /// @brief Emits a report for a given alarm. /// /// Emits a WARN log if the alarm state is TRIGGERED or an /// INFO log if it is CLEARED. This may expand in the future to - /// accomodate additional reporting mechanisms. + /// accommodate additional reporting mechanisms. /// - /// @param alarm Alarm to report + /// @param alarm Alarm to report. /// @param average Duration average which caused the state transition. void reportAlarm(AlarmPtr alarm, const Duration& average); @@ -102,7 +102,7 @@ public: /// /// @return interval-width-secs as a Duration. Duration getIntervalDuration() { - return (interval_duration_); + return (interval_duration_); } /// @brief Get the alarm report interval. @@ -112,9 +112,9 @@ public: return (alarm_report_interval_); } - /// @brief Get the duration store + /// @brief Get the duration store. /// - /// @return pointer to the duration store + /// @return pointer to the duration store. MonitoredDurationStorePtr getDurationStore() { return (duration_store_); } @@ -136,9 +136,9 @@ private: /// timer but nothing more until traffic resumes. /// /// @brief Tracks whether or not the server is processing DHCP packets. - ///dhcp::NetworkStatePtr network_state_; + // dhcp::NetworkStatePtr network_state_; - /// @brief IOService instance used to the timer. + /// @brief IOService instance used by the timer. asiolink::IOServicePtr io_service_; /// @brief Timer which tracks the next duration due to report. diff --git a/src/hooks/dhcp/perfmon/tests/alarm_parser_unittests.cc b/src/hooks/dhcp/perfmon/tests/alarm_parser_unittests.cc index a775672d6a..dfc0959973 100644 --- a/src/hooks/dhcp/perfmon/tests/alarm_parser_unittests.cc +++ b/src/hooks/dhcp/perfmon/tests/alarm_parser_unittests.cc @@ -24,19 +24,19 @@ using namespace boost::posix_time; namespace { // These tests excerise AlarmParser which, with the help of DurationKeyParser -// (tested rigourously elsewhere), parses a map of paramters as shown below: +// (tested rigorously elsewhere), parses a map of parameters as shown below: // // { // "duration-key": { -// "query-type" : "DHCPDISCOVER", -// "response-type" : "DHCPOFFER", -// "start-event" : "process-started", -// "stop-event" : "process-completed", -// "subnet-id" : 70 +// "query-type": "DHCPDISCOVER", +// "response-type": "DHCPOFFER", +// "start-event": "process-started", +// "stop-event": "process-completed", +// "subnet-id": 70 // }, -// "enable-alarm" : true, -// "high-water-ms" : 500, -// "low-water-ms" : 25, +// "enable-alarm": true, +// "high-water-ms": 500, +// "low-water-ms": 25, // } /// @brief Describes a valid test scenario. @@ -55,8 +55,8 @@ struct InvalidScenario { std::string exp_message_; // Expected error text }; -/// @brief Base class test fixture for testing AlarmParser. -class AlarmParserTest: public ::testing::Test { +/// @brief Base class test fixture for testing AlarmParser. +class AlarmParserTest : public ::testing::Test { public: /// @brief Constructor. explicit AlarmParserTest(uint16_t family) : family_(family) { @@ -80,9 +80,9 @@ public: // All parameters __LINE__, R"( - "enable-alarm" : true, - "high-water-ms" : 500, - "low-water-ms" : 25 + "enable-alarm": true, + "high-water-ms": 500, + "low-water-ms": 25 )", Alarm::CLEAR, 500, 25 }, @@ -90,18 +90,18 @@ public: // No enable-alarm, should default to CLEAR state. __LINE__, R"( - "high-water-ms" : 500, - "low-water-ms" : 25 + "high-water-ms": 500, + "low-water-ms": 25 )", Alarm::CLEAR, 500, 25 }, { - // State should be DISALBED when enable-alarm is false + // State should be DISABLED when enable-alarm is false __LINE__, R"( - "enable-alarm" : false, - "high-water-ms" : 500, - "low-water-ms" : 25 + "enable-alarm": false, + "high-water-ms": 500, + "low-water-ms": 25 )", Alarm::DISABLED, 500, 25 } @@ -145,9 +145,9 @@ public: // Spurious parameter __LINE__, R"( - "enable-alarm" : true, - "high-water-ms" : 500, - "low-water-ms" : 25, + "enable-alarm": true, + "high-water-ms": 500, + "low-water-ms": 25, "bogus": true )", "spurious 'bogus' parameter" @@ -156,9 +156,9 @@ public: // Invalid type enable-alarm __LINE__, R"( - "enable-alarm" : "bogus", - "high-water-ms" : 500, - "low-water-ms" : 25, + "enable-alarm": "bogus", + "high-water-ms": 500, + "low-water-ms": 25, "bogus": true )", "'enable-alarm' parameter is not a boolean" @@ -167,8 +167,8 @@ public: // Missing high-water-ms __LINE__, R"( - "enable-alarm" : true, - "low-water-ms" : 25 + "enable-alarm": true, + "low-water-ms": 25 )", "'high-water-ms' parameter is required" }, @@ -176,9 +176,9 @@ public: // Invalid type for high-water-ms __LINE__, R"( - "enable-alarm" : true, - "high-water-ms" : "bogus", - "low-water-ms" : 25 + "enable-alarm": true, + "high-water-ms": "bogus", + "low-water-ms": 25 )", "'high-water-ms' parameter is not an integer" }, @@ -186,8 +186,8 @@ public: // Missing low-water-ms __LINE__, R"( - "enable-alarm" : true, - "high-water-ms" : 500 + "enable-alarm": true, + "high-water-ms": 500 )", "'low-water-ms' parameter is required" }, @@ -195,9 +195,9 @@ public: // Invalid type for low-water-ms __LINE__, R"( - "enable-alarm" : true, - "high-water-ms" : 500, - "low-water-ms" : "bogus" + "enable-alarm": true, + "high-water-ms": 500, + "low-water-ms": "bogus" )", "'low-water-ms' parameter is not an integer" }, @@ -205,9 +205,9 @@ public: // Invalid threshold combination __LINE__, R"( - "enable-alarm" : true, - "high-water-ms" : 25, - "low-water-ms" : 500 + "enable-alarm": true, + "high-water-ms": 25, + "low-water-ms": 500 )", "'low-water-ms': 500, must be less than 'high-water-ms': 25" }, @@ -218,7 +218,7 @@ public: /// @brief Runs a list of invalid configurations through AlarmParser::parse(). /// - /// @param list of valid scenarios to run + /// @param list of valid scenarios to run. /// @param add_key When true, scenario json will be prepended with valid, family-specific /// duration-key element prior to parsing. void testInvalidScenarios(std::list<InvalidScenario>& scenarios, @@ -249,13 +249,13 @@ public: DurationKeyPtr expected_key_; }; -/// @brief Test fixture for testing AlarmParser for DHCP(v4). +/// @brief Test fixture for testing AlarmParser for DHCPV4. class AlarmParserTest4: public AlarmParserTest { public: /// @brief Constructor. explicit AlarmParserTest4() : AlarmParserTest(AF_INET) { expected_key_.reset(new DurationKey(family_, DHCPDISCOVER, DHCPOFFER, - "start_here", "stop_there", 33)); + "start_here", "stop_there", 33)); } /// @brief Destructor. @@ -319,7 +319,7 @@ public: } }; -TEST_F(AlarmParserTest4, validScenarios4) { +TEST_F(AlarmParserTest4, validScenarios) { testValidScenarios(); } @@ -335,9 +335,9 @@ TEST_F(AlarmParserTest4, invalidDurationKey) { // Missing duration-key element __LINE__, R"({ - "enable-alarm" : true, - "high-water-ms" : 500, - "low-water-ms" : 25 + "enable-alarm": true, + "high-water-ms": 500, + "low-water-ms": 25 })", "'duration-key' parameter is required" }, @@ -346,9 +346,9 @@ TEST_F(AlarmParserTest4, invalidDurationKey) { __LINE__, R"({ "duration-key": "not-a-map", - "enable-alarm" : true, - "high-water-ms" : 500, - "low-water-ms" : 25 + "enable-alarm": true, + "high-water-ms": 500, + "low-water-ms": 25 })", "'duration-key' parameter is not a map" }, @@ -359,12 +359,12 @@ TEST_F(AlarmParserTest4, invalidDurationKey) { "duration-key": { "query-type": "REQUEST", "response-type": "REPLY", - "start-event" : "start-here", - "stop-event" : "stop-here" + "start-event": "start-here", + "stop-event": "stop-here" }, - "enable-alarm" : true, - "high-water-ms" : 500, - "low-water-ms" : 25 + "enable-alarm": true, + "high-water-ms": 500, + "low-water-ms": 25 })", "'query-type' parameter is invalid, 'REQUEST' is not a valid DHCP message type" }, @@ -389,9 +389,9 @@ TEST_F(AlarmParserTest6, invalidDurationKey) { // Missing duration-key element __LINE__, R"({ - "enable-alarm" : true, - "high-water-ms" : 500, - "low-water-ms" : 25 + "enable-alarm": true, + "high-water-ms": 500, + "low-water-ms": 25 })", "'duration-key' parameter is required" }, @@ -400,9 +400,9 @@ TEST_F(AlarmParserTest6, invalidDurationKey) { __LINE__, R"({ "duration-key": "not-a-map", - "enable-alarm" : true, - "high-water-ms" : 500, - "low-water-ms" : 25 + "enable-alarm": true, + "high-water-ms": 500, + "low-water-ms": 25 })", "'duration-key' parameter is not a map" }, @@ -413,12 +413,12 @@ TEST_F(AlarmParserTest6, invalidDurationKey) { "duration-key": { "query-type": "DHCPDISCOVER", "response-type": "DHCPOFFER", - "start-event" : "start-here", - "stop-event" : "stop-here" + "start-event": "start-here", + "stop-event": "stop-here" }, - "enable-alarm" : true, - "high-water-ms" : 500, - "low-water-ms" : 25 + "enable-alarm": true, + "high-water-ms": 500, + "low-water-ms": 25 })", "'query-type' parameter is invalid, 'DHCPDISCOVER' is not a valid DHCPV6 message type" }, diff --git a/src/hooks/dhcp/perfmon/tests/duration_key_parser_unittests.cc b/src/hooks/dhcp/perfmon/tests/duration_key_parser_unittests.cc index 9abe417dab..e7b6445612 100644 --- a/src/hooks/dhcp/perfmon/tests/duration_key_parser_unittests.cc +++ b/src/hooks/dhcp/perfmon/tests/duration_key_parser_unittests.cc @@ -23,13 +23,13 @@ using namespace isc::perfmon; namespace { // These tests excerise DurationKeyParser which parses a map of -// paramters as shown below: +// parameters as shown below: // "duration-key": { -// "query-type" : "DHCPDISCOVER", -// "response-type" : "DHCPOFFER", -// "start-event" : "process-started", -// "stop-event" : "process-completed", -// "subnet-id" : 70 +// "query-type": "DHCPDISCOVER", +// "response-type": "DHCPOFFER", +// "start-event": "process-started", +// "stop-event": "process-completed", +// "subnet-id": 70 // } /// @brief Describes a valid test scenario. @@ -51,7 +51,7 @@ struct InvalidScenario { }; /// @brief Test fixture for testing DurationKeyParser. -class DurationKeyParserTest: public ::testing::Test { +class DurationKeyParserTest : public ::testing::Test { public: /// @brief Constructor. DurationKeyParserTest() = default; @@ -61,8 +61,8 @@ public: /// @brief Runs a list of valid configurations through parsing. /// - /// @param list of valid scenarios to run - /// @param family protocol family to use when parsing + /// @param list of valid scenarios to run. + /// @param family protocol family to use when parsing. void testValidScenarios(std::list<ValidScenario>& scenarios, uint16_t family) { // Iterate over the scenarios. for (auto const& scenario : scenarios) { @@ -90,8 +90,8 @@ public: /// @brief Runs a list of invalid configurations through parsing. /// - /// @param list of valid scenarios to run - /// @param family protocol family to use when parsing + /// @param list of valid scenarios to run. + /// @param family protocol family to use when parsing. void testInvalidScenarios(std::list<InvalidScenario>& scenarios, uint16_t family) { // Iterate over the scenarios. for (auto const& scenario : scenarios) { @@ -357,7 +357,7 @@ TEST_F(DurationKeyParserTest, invalidScenarios4) { testInvalidScenarios(scenarios, AF_INET); } -TEST_F(DurationKeyParserTest, parseValidScenarios6) { +TEST_F(DurationKeyParserTest, validScenarios6) { // List of test scenarios to run. std::list<ValidScenario> scenarios = { { diff --git a/src/hooks/dhcp/perfmon/tests/monitored_duration_store_unittests.cc b/src/hooks/dhcp/perfmon/tests/monitored_duration_store_unittests.cc index ae79933f8b..f466e6fdb2 100644 --- a/src/hooks/dhcp/perfmon/tests/monitored_duration_store_unittests.cc +++ b/src/hooks/dhcp/perfmon/tests/monitored_duration_store_unittests.cc @@ -110,7 +110,7 @@ public: int idx = monds.size() - 1; for (auto const& d : *durations) { - EXPECT_EQ(*d, *monds[idx]) << "failed on pass :" << idx; + EXPECT_EQ(*d, *monds[idx]) << "failed on pass: " << idx; --idx; } diff --git a/src/hooks/dhcp/perfmon/tests/perfmon_config_unittests.cc b/src/hooks/dhcp/perfmon/tests/perfmon_config_unittests.cc index cbad54d687..ea16a25156 100644 --- a/src/hooks/dhcp/perfmon/tests/perfmon_config_unittests.cc +++ b/src/hooks/dhcp/perfmon/tests/perfmon_config_unittests.cc @@ -83,7 +83,7 @@ public: bool exp_enable_monitoring_; // Expected value for enable-monitoring uint32_t exp_interval_width_secs_; // Expected value for interval-width-secs bool exp_stats_mgr_reporting_; // Expected value for stats-mgr-reporting - uint32_t exp_alarm_report_secs_; // Expected value for alarm-report-secs + uint32_t exp_alarm_report_secs_; // Expected value for alarm-report-secs }; // List of test scenarios to run. @@ -97,25 +97,25 @@ public: { // Only enable-monitoring", __LINE__, - R"({ "enable-monitoring" : true })", + R"({ "enable-monitoring": true })", true, 60, true, 300 }, { // Only interval-width-secs", __LINE__, - R"({ "interval-width-secs" : 3 })", + R"({ "interval-width-secs": 3 })", false, 3, true, 300 }, { // Only stats-mgr-reporting", __LINE__, - R"({ "stats-mgr-reporting" : false })", + R"({ "stats-mgr-reporting": false })", false, 60, false, 300 }, { // Only alarm-report-secs", __LINE__, - R"({ "alarm-report-secs" : 77 })", + R"({ "alarm-report-secs": 77 })", false, 60, true, 77 }, { @@ -123,10 +123,10 @@ public: __LINE__, R"( { - "enable-monitoring" : true, - "interval-width-secs" : 2, - "stats-mgr-reporting" : false, - "alarm-report-secs" : 120 + "enable-monitoring": true, + "interval-width-secs": 2, + "stats-mgr-reporting": false, + "alarm-report-secs": 120 })", true, 2, false, 120 }, @@ -154,156 +154,156 @@ public: } } - /// @brief Exercises PerfMonConfig parameter parsing with invalid configuration - /// permutations. Duplicate alarms are tested elsewhere. - void testInvalidScenarios() { - // Describes a test scenario. - struct Scenario { - int line_; // Scenario line number - string json_; // JSON configuration to parse - string exp_message_; // Expected exception message - }; - - // List of test scenarios to run. Most scenario supply - // all valid parameters except one in error. This allows - // us to verify that no values are changed if any are in error. - list<Scenario> scenarios = { - { - // Unknown parameter - __LINE__, - R"( - { - "enable-monitoring" : false, - "interval-width-secs" : 3, - "stats-mgr-reporting" : false, - "alarm-report-secs" : 90, - "bogus" : false - })", - "spurious 'bogus' parameter" - }, - { - // Invalid type for enable-monitoring - __LINE__, - R"( - { - "enable-monitoring" : "not bool", - "interval-width-secs" : 3, - "stats-mgr-reporting" : false, - "alarm-report-secs" : 90 - })", - "'enable-monitoring' parameter is not a boolean" - }, - { - // Value of interval-width-secs is zero - __LINE__, - R"( - { - "enable-monitoring" : false, - "interval-width-secs" : 0, - "stats-mgr-reporting" : false, - "alarm-report-secs" : 90 - })", - "invalid interval-width-secs: '0', must be greater than 0" - }, - { - // Value of interval-width-secs less than zero - __LINE__, - R"( - { - "enable-monitoring" : false, - "interval-width-secs" : -2, - "stats-mgr-reporting" : false, - "alarm-report-secs" : 90 - })", - "invalid interval-width-secs: '-2', must be greater than 0" - }, - { - // Non-boolean type for stats-mgr-reporting - __LINE__, - R"( - { - "enable-monitoring" : false, - "interval-width-secs" : 1, - "stats-mgr-reporting" : "not bool", - "alarm-report-secs" : 90 - })", - "'stats-mgr-reporting' parameter is not a boolean" - }, - { - // Value of alarm-report-secs is zero - __LINE__, - R"( - { - "enable-monitoring" : false, - "interval-width-secs" : 1, - "stats-mgr-reporting" : false, - "alarm-report-secs" : -3 - })", - "invalid alarm-report-secs: '-3', cannot be less than 0" - }, - { - // Value of alarm-report-secs less than zero - __LINE__, - R"( - { - "enable-monitoring" : false, - "interval-width-secs" : 1, - "stats-mgr-reporting" : false, - "alarm-report-secs" : -3 - })", - "invalid alarm-report-secs: '-3', cannot be less than 0" - }, - { - // Value for alarms is not a list. - __LINE__, - R"( - { - "enable-monitoring" : false, - "interval-width-secs" : 60, - "stats-mgr-reporting" : false, - "alarm-report-secs" : 90, - "alarms": {} - })", - "'alarms' parameter is not a list" - }, - { - // Alarms list contains an invalid entry - __LINE__, - R"( - { - "enable-monitoring" : false, - "interval-width-secs" : 60, - "stats-mgr-reporting" : false, - "alarm-report-secs" : 90, - "alarms": [{ "bogus": "alarm" }] - })", - "cannot add Alarm to store: spurious 'bogus' parameter" - } - }; - - // Iterate over the scenarios. - PerfMonConfig default_config(family_); - for (auto const& scenario : scenarios) { - stringstream oss; - oss << "scenario at line: " << scenario.line_; - SCOPED_TRACE(oss.str()); - - // Convert JSON text to a map of parameters. - ConstElementPtr json_elements; - ASSERT_NO_THROW_LOG(json_elements = Element::fromJSON(scenario.json_)); - - // Parsing parameters should throw. - PerfMonConfig config(family_); - ASSERT_THROW_MSG(config.parse(json_elements), DhcpConfigError, - scenario.exp_message_); - - // Original values should be intact. - EXPECT_EQ(default_config.getEnableMonitoring(), config.getEnableMonitoring()); - EXPECT_EQ(default_config.getIntervalWidthSecs(), config.getIntervalWidthSecs()); - EXPECT_EQ(default_config.getStatsMgrReporting(), config.getStatsMgrReporting()); - EXPECT_EQ(default_config.getAlarmReportSecs(), config.getAlarmReportSecs()); - } - } + /// @brief Exercises PerfMonConfig parameter parsing with invalid configuration + /// permutations. Duplicate alarms are tested elsewhere. + void testInvalidScenarios() { + // Describes a test scenario. + struct Scenario { + int line_; // Scenario line number + string json_; // JSON configuration to parse + string exp_message_; // Expected exception message + }; + + // List of test scenarios to run. Most scenario supply + // all valid parameters except one in error. This allows + // us to verify that no values are changed if any are in error. + list<Scenario> scenarios = { + { + // Unknown parameter + __LINE__, + R"( + { + "enable-monitoring": false, + "interval-width-secs": 3, + "stats-mgr-reporting": false, + "alarm-report-secs": 90, + "bogus": false + })", + "spurious 'bogus' parameter" + }, + { + // Invalid type for enable-monitoring + __LINE__, + R"( + { + "enable-monitoring": "not bool", + "interval-width-secs": 3, + "stats-mgr-reporting": false, + "alarm-report-secs": 90 + })", + "'enable-monitoring' parameter is not a boolean" + }, + { + // Value of interval-width-secs is zero + __LINE__, + R"( + { + "enable-monitoring": false, + "interval-width-secs": 0, + "stats-mgr-reporting": false, + "alarm-report-secs": 90 + })", + "invalid interval-width-secs: '0', must be greater than 0" + }, + { + // Value of interval-width-secs less than zero + __LINE__, + R"( + { + "enable-monitoring": false, + "interval-width-secs": -2, + "stats-mgr-reporting": false, + "alarm-report-secs": 90 + })", + "invalid interval-width-secs: '-2', must be greater than 0" + }, + { + // Non-boolean type for stats-mgr-reporting + __LINE__, + R"( + { + "enable-monitoring": false, + "interval-width-secs": 1, + "stats-mgr-reporting": "not bool", + "alarm-report-secs": 90 + })", + "'stats-mgr-reporting' parameter is not a boolean" + }, + { + // Value of alarm-report-secs is zero + __LINE__, + R"( + { + "enable-monitoring": false, + "interval-width-secs": 1, + "stats-mgr-reporting": false, + "alarm-report-secs": -3 + })", + "invalid alarm-report-secs: '-3', cannot be less than 0" + }, + { + // Value of alarm-report-secs less than zero + __LINE__, + R"( + { + "enable-monitoring": false, + "interval-width-secs": 1, + "stats-mgr-reporting": false, + "alarm-report-secs": -3 + })", + "invalid alarm-report-secs: '-3', cannot be less than 0" + }, + { + // Value for alarms is not a list. + __LINE__, + R"( + { + "enable-monitoring": false, + "interval-width-secs": 60, + "stats-mgr-reporting": false, + "alarm-report-secs": 90, + "alarms": {} + })", + "'alarms' parameter is not a list" + }, + { + // Alarms list contains an invalid entry + __LINE__, + R"( + { + "enable-monitoring": false, + "interval-width-secs": 60, + "stats-mgr-reporting": false, + "alarm-report-secs": 90, + "alarms": [{ "bogus": "alarm" }] + })", + "cannot add Alarm to store: spurious 'bogus' parameter" + } + }; + + // Iterate over the scenarios. + PerfMonConfig default_config(family_); + for (auto const& scenario : scenarios) { + stringstream oss; + oss << "scenario at line: " << scenario.line_; + SCOPED_TRACE(oss.str()); + + // Convert JSON text to a map of parameters. + ConstElementPtr json_elements; + ASSERT_NO_THROW_LOG(json_elements = Element::fromJSON(scenario.json_)); + + // Parsing parameters should throw. + PerfMonConfig config(family_); + ASSERT_THROW_MSG(config.parse(json_elements), DhcpConfigError, + scenario.exp_message_); + + // Original values should be intact. + EXPECT_EQ(default_config.getEnableMonitoring(), config.getEnableMonitoring()); + EXPECT_EQ(default_config.getIntervalWidthSecs(), config.getIntervalWidthSecs()); + EXPECT_EQ(default_config.getStatsMgrReporting(), config.getStatsMgrReporting()); + EXPECT_EQ(default_config.getAlarmReportSecs(), config.getAlarmReportSecs()); + } + } /// @brief Creates a valid configuration with a list of alarms. /// @@ -311,29 +311,29 @@ public: /// in the list. /// /// @return JSON text for the configuration. - std::string makeConfigWithAlarms(std::vector<DurationKeyPtr> keys) { + std::string makeConfigWithAlarms(std::vector<DurationKeyPtr> keys) { // Create valid configuration test which includes an arbitrary number of // family-specific alarms from a set of DurationKeys. stringstream joss; - joss << R"( - { - "enable-monitoring" : false, - "interval-width-secs" : 60, - "stats-mgr-reporting" : false, - "alarm-report-secs" : 90, - "alarms": [ + joss << R"( + { + "enable-monitoring": false, + "interval-width-secs": 60, + "stats-mgr-reporting": false, + "alarm-report-secs": 90, + "alarms": [ )"; - std::string comma=""; + std::string comma = ""; for (auto const& key : keys) { joss << comma << "\t{"; - joss << R"("duration-key": )"; + joss << R"("duration-key": )"; auto key_elems = DurationKeyParser::toElement(key); key_elems->toJSON(joss); joss << R"(, - "high-water-ms": 500, - "low-water-ms": 25 - } + "high-water-ms": 500, + "low-water-ms": 25 + } )"; comma = ","; @@ -344,18 +344,18 @@ public: } /// @brief Verifies a valid configuration that includes a list of Alarms. - void testValidAlarmsList() { + void testValidAlarmsList() { // Create valid configuration test which includes an arbitrary number of // family-specific alarms from a pre-defined set of unique DurationKeys. std::string json_text = makeConfigWithAlarms(keys_); // Convert JSON text to a map of parameters. - ConstElementPtr json_elements; - ASSERT_NO_THROW_LOG(json_elements = Element::fromJSON(json_text)); + ConstElementPtr json_elements; + ASSERT_NO_THROW_LOG(json_elements = Element::fromJSON(json_text)); - // Parsing parameters should throw. - PerfMonConfig config(family_); - ASSERT_NO_THROW_LOG(config.parse(json_elements)); + // Parsing parameters should throw. + PerfMonConfig config(family_); + ASSERT_NO_THROW_LOG(config.parse(json_elements)); // Get all should retrieve the alarms in ascending order. AlarmCollectionPtr alarms = config.getAlarmStore()->getAll(); @@ -363,13 +363,13 @@ public: int idx = 0; for (auto const& d : *alarms) { - EXPECT_EQ(*d, *keys_[idx]) << "failed on pass :" << idx; + EXPECT_EQ(*d, *keys_[idx]) << "failed on pass: " << idx; ++idx; } - } + } /// @brief Verifies a valid configuration with a list duplicate Alarms. - void testDuplicateAlarms() { + void testDuplicateAlarms() { std::vector<DurationKeyPtr> duplicate_keys; duplicate_keys.push_back(keys_[0]); duplicate_keys.push_back(keys_[0]); @@ -379,32 +379,32 @@ public: std::string json_text = makeConfigWithAlarms(duplicate_keys); // Convert JSON text to a map of parameters. - ConstElementPtr json_elements; - ASSERT_NO_THROW_LOG(json_elements = Element::fromJSON(json_text)); + ConstElementPtr json_elements; + ASSERT_NO_THROW_LOG(json_elements = Element::fromJSON(json_text)); - // Parsing parameters should throw. - PerfMonConfig config(family_); + // Parsing parameters should throw. + PerfMonConfig config(family_); if (family_ == AF_INET) { - ASSERT_THROW_MSG(config.parse(json_elements), DhcpConfigError, + ASSERT_THROW_MSG(config.parse(json_elements), DhcpConfigError, "cannot add Alarm to store: AlarmStore::addAlarm:" " alarm already exists for:" " DHCPDISCOVER-DHCPOFFER.socket_received-buffer_read.0"); } else { - ASSERT_THROW_MSG(config.parse(json_elements), DhcpConfigError, + ASSERT_THROW_MSG(config.parse(json_elements), DhcpConfigError, "cannot add Alarm to store: AlarmStore::addAlarm:" " alarm already exists for:" " SOLICIT-REPLY.socket_received-buffer_read.0"); } - } + } - /// @brief Protocol family AF_INET or AF_INET6 + /// @brief Protocol family AF_INET or AF_INET6. uint16_t family_; /// @brief Collection of valid family-specific keys. std::vector<DurationKeyPtr> keys_; }; -/// @brief Test fixture for testing PerfMonConfig for DHCP(v4). +/// @brief Test fixture for testing PerfMonConfig for DHCPV4. class PerfMonConfigTest4: public PerfMonConfigTest { public: /// @brief Constructor. @@ -469,11 +469,11 @@ TEST_F(PerfMonConfigTest6, validAlarmsList) { } TEST_F(PerfMonConfigTest4, duplicateAlarms) { - testDuplicateAlarms(); + testDuplicateAlarms(); } TEST_F(PerfMonConfigTest6, duplicateAlarms) { - testDuplicateAlarms(); + testDuplicateAlarms(); } } // end of anonymous namespace diff --git a/src/hooks/dhcp/perfmon/tests/perfmon_mgr_unittests.cc b/src/hooks/dhcp/perfmon/tests/perfmon_mgr_unittests.cc index 676b4e54e9..30bd5af799 100644 --- a/src/hooks/dhcp/perfmon/tests/perfmon_mgr_unittests.cc +++ b/src/hooks/dhcp/perfmon/tests/perfmon_mgr_unittests.cc @@ -82,21 +82,21 @@ public: void testValidConfig() { std::string valid_config = R"({ - "enable-monitoring" : false, - "interval-width-secs" : 5, - "stats-mgr-reporting" : false, - "alarm-report-secs" : 600, + "enable-monitoring": false, + "interval-width-secs": 5, + "stats-mgr-reporting": false, + "alarm-report-secs": 600, "alarms": [{ "duration-key": { - "query-type" : "", - "response-type" : "", - "start-event" : "process-started", - "stop-event" : "process-completed", - "subnet-id" : 70 + "query-type": "", + "response-type": "", + "start-event": "process-started", + "stop-event": "process-completed", + "subnet-id": 70 }, - "enable-alarm" : true, - "high-water-ms" : 500, - "low-water-ms" : 25 + "enable-alarm": true, + "high-water-ms": 500, + "low-water-ms": 25 }] })"; @@ -139,10 +139,10 @@ public: void testInvalidConfig() { std::string valid_config = R"({ - "enable-monitoring" : false, - "interval-width-secs" : 5, - "stats-mgr-reporting" : false, - "alarm-report-secs" : 600, + "enable-monitoring": false, + "interval-width-secs": 5, + "stats-mgr-reporting": false, + "alarm-report-secs": 600, "alarms": "bogus" })"; @@ -175,7 +175,7 @@ public: uint16_t family_; }; -/// @brief Test fixture for testing PerfMonConfig for DHCP(v4). +/// @brief Test fixture for testing PerfMonConfig for DHCPV4. class PerfMonMgrTest4: public PerfMonMgrTest { public: /// @brief Constructor. |