/* The software in this package is distributed under the GNU General Public License version 2 (with a special exception described below). A copy of GNU General Public License (GPL) is included in this distribution, in the file COPYING.GPL. As a special exception, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other works to produce a work based on this file, this file does not by itself cause the resulting work to be covered by the GNU General Public License. However the source code for this file must still be made available in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. */ #ifndef HOST_STATUS_H #define HOST_STATUS_H #include #include "host/pingstatus.h" #include "link/linkstatus.h" //----------------------------------------------------------------------------- // HostStatus //----------------------------------------------------------------------------- /** * @brief This class analyze the host status (up or down) based on the pings * responses (success or failure). And notifies its status. * Scope: one object per host. */ class HostStatus { public: HostStatus( const std::string &host_address, const int ping_fail_limit_percentage, const int ping_congestion_limit_percentage, const int congest_caused_by_fail_limit_percentage, const int ping_duration_congestion_thresh, const int n_parallel_pings, const LinkStatusItem link_analyzer ); ~HostStatus(); void set_resolved_ip_count( const int resolved_ip_count ); bool exceeded_ping_failed_limit() const; bool exceeded_ping_congestion_limit() const; void update_ping_statistics( const PingStatus &ping_success, const long ping_duration_us ); void set_n_parallel_pings(const int n_parallel_pings); private: void update_fail_stats( const PingStatus &ping_success, const bool failed_because_congested ); bool update_congestion_stats( const PingStatus &ping_success, const long ping_duration_us ); bool tried_all_resolved_ip() const; void analyze_ping_statistics(); void reset_ping_counters(); void increase_ping_performed_count(); void increase_ping_failed_count(); void increase_ping_congestion_count(); void analyze_ping_failed_count(); void analyze_ping_congestion_count(); void log_status_count(); std::string log_prefix(); private: /// the DNS address of the host to analyze std::string HostAddress; /// the object responsible to analyze the link const LinkStatusItem LinkAnalyzer; /// the maximum amount of pings that can fail without warning int PingFailLimitPercentage; /// the maximum amount of pings that can be congested without warning int PingCongestionLimitPercentage; /// threshold to decide when congestion is caused by failed connection int CongestCausedByFailLimitPercentage; /// the threshold in micro seconds that ping can take with/out congestion long PingDurationCongestionsThresh; /// the amount of IPs that are aliases to the host DNS int ResolvedIpCount; /// the amount of pings sent until now int PingsPerformedCount; /// the amount of pings sent that failed until now int PingsFailedCount; /// the amount of pings sent that indicate congestion until now int PingCongestionCount; /// boolean flag that indicate if the last set of failed pings exceed the /// limit bool ExceededPingFailedLimit; /// boolean flag that indicate if the last set of congested pings exceed the /// limit bool ExceededPingCongestionLimit; /// number of pingers that ping the same IP in parallel int NParallelPingers; /// flag whether we performed a greater number of pings because line seems /// congested bool InBurstMode; }; #endif // HOST_STATUS_H