Commit | Line | Data |
---|---|---|
91fcc471 TJ |
1 | /* |
2 | The software in this package is distributed under the GNU General | |
3 | Public License version 2 (with a special exception described below). | |
4 | ||
5 | A copy of GNU General Public License (GPL) is included in this distribution, | |
6 | in the file COPYING.GPL. | |
7 | ||
8 | As a special exception, if other files instantiate templates or use macros | |
9 | or inline functions from this file, or you compile this file and link it | |
10 | with other works to produce a work based on this file, this file | |
11 | does not by itself cause the resulting work to be covered | |
12 | by the GNU General Public License. | |
13 | ||
14 | However the source code for this file must still be made available | |
15 | in accordance with section (3) of the GNU General Public License. | |
16 | ||
17 | This exception does not invalidate any other reasons why a work based | |
18 | on this file might be covered by the GNU General Public License. | |
19 | */ | |
6c14bbee GMF |
20 | #ifndef HOST_STATUS_H |
21 | #define HOST_STATUS_H | |
ddf41c89 GMF |
22 | |
23 | #include <string> | |
24 | ||
96c4e7a4 | 25 | #include "host/pingstatus.h" |
72e54d1c | 26 | #include "link/linkstatus.h" |
ddf41c89 GMF |
27 | |
28 | //----------------------------------------------------------------------------- | |
6c14bbee | 29 | // HostStatus |
ddf41c89 GMF |
30 | //----------------------------------------------------------------------------- |
31 | ||
c5e4bfa1 | 32 | /** |
c01a6023 GMF |
33 | * @brief This class analyze the host status (up or down) based on the pings |
34 | * responses (success or failure). And notifies its status. | |
c5e4bfa1 GMF |
35 | * Scope: one object per host. |
36 | */ | |
6c14bbee | 37 | class HostStatus |
ddf41c89 GMF |
38 | { |
39 | public: | |
6c14bbee | 40 | HostStatus( |
ddf41c89 | 41 | const std::string &host_address, |
cd4048df | 42 | const int ping_fail_limit_percentage, |
a7b15639 | 43 | const int ping_congestion_limit_percentage, |
941b5e25 | 44 | const int congest_caused_by_fail_limit_percentage, |
a7b15639 | 45 | const int ping_duration_congestion_thresh, |
91aa83f9 | 46 | const int n_parallel_pings, |
c6c54dfb | 47 | const LinkStatusItem link_analyzer |
ddf41c89 | 48 | ); |
6c14bbee | 49 | ~HostStatus(); |
ddf41c89 GMF |
50 | |
51 | void set_resolved_ip_count( const int resolved_ip_count ); | |
a341119a | 52 | bool exceeded_ping_failed_limit() const; |
a7b15639 | 53 | bool exceeded_ping_congestion_limit() const; |
96c4e7a4 CH |
54 | void update_ping_statistics( const PingStatus &ping_success, |
55 | const long ping_duration_us ); | |
242e5fb3 | 56 | void set_n_parallel_pings(const int n_parallel_pings); |
ddf41c89 GMF |
57 | |
58 | private: | |
4d7db1af CH |
59 | void update_fail_stats( const PingStatus &ping_success, |
60 | const bool failed_because_congested ); | |
61 | bool update_congestion_stats( const PingStatus &ping_success, | |
a7b15639 | 62 | const long ping_duration_us ); |
d8a91bd6 GMF |
63 | bool tried_all_resolved_ip() const; |
64 | void analyze_ping_statistics(); | |
c1fff16a | 65 | void reset_ping_counters(); |
c5e4bfa1 GMF |
66 | void increase_ping_performed_count(); |
67 | void increase_ping_failed_count(); | |
a7b15639 | 68 | void increase_ping_congestion_count(); |
6827496c | 69 | void analyze_ping_failed_count(); |
a7b15639 | 70 | void analyze_ping_congestion_count(); |
216a9c6e | 71 | void log_status_count(); |
a7b15639 CH |
72 | |
73 | std::string log_prefix(); | |
ddf41c89 GMF |
74 | |
75 | private: | |
d3e8a9f9 | 76 | /// the DNS address of the host to analyze |
c1fff16a | 77 | std::string HostAddress; |
d3e8a9f9 | 78 | /// the object responsible to analyze the link |
c6c54dfb | 79 | const LinkStatusItem LinkAnalyzer; |
d3e8a9f9 | 80 | /// the maximum amount of pings that can fail without warning |
cd4048df | 81 | int PingFailLimitPercentage; |
a7b15639 CH |
82 | /// the maximum amount of pings that can be congested without warning |
83 | int PingCongestionLimitPercentage; | |
941b5e25 CH |
84 | /// threshold to decide when congestion is caused by failed connection |
85 | int CongestCausedByFailLimitPercentage; | |
a7b15639 CH |
86 | /// the threshold in micro seconds that ping can take with/out congestion |
87 | long PingDurationCongestionsThresh; | |
d3e8a9f9 | 88 | /// the amount of IPs that are aliases to the host DNS |
ddf41c89 | 89 | int ResolvedIpCount; |
d3e8a9f9 | 90 | /// the amount of pings sent until now |
ddf41c89 | 91 | int PingsPerformedCount; |
d3e8a9f9 | 92 | /// the amount of pings sent that failed until now |
ddf41c89 | 93 | int PingsFailedCount; |
a7b15639 CH |
94 | /// the amount of pings sent that indicate congestion until now |
95 | int PingCongestionCount; | |
d3e8a9f9 GMF |
96 | /// boolean flag that indicate if the last set of failed pings exceed the |
97 | /// limit | |
a341119a | 98 | bool ExceededPingFailedLimit; |
a7b15639 CH |
99 | /// boolean flag that indicate if the last set of congested pings exceed the |
100 | /// limit | |
101 | bool ExceededPingCongestionLimit; | |
91aa83f9 CH |
102 | /// number of pingers that ping the same IP in parallel |
103 | int NParallelPingers; | |
4d7db1af CH |
104 | /// flag whether we performed a greater number of pings because line seems |
105 | /// congested | |
106 | bool InBurstMode; | |
ddf41c89 GMF |
107 | |
108 | }; | |
109 | ||
6c14bbee | 110 | #endif // HOST_STATUS_H |