Commit | Line | Data |
---|---|---|
6f19218c GMF |
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 | */ | |
20 | ||
a72f06b6 | 21 | #define BOOST_TEST_MAIN |
6f19218c | 22 | #define BOOST_TEST_DYN_LINK |
6f19218c GMF |
23 | |
24 | #include <streambuf> | |
25 | ||
26 | #include <boost/asio.hpp> | |
27 | #include <boost/test/unit_test.hpp> | |
28 | ||
216a9c6e CH |
29 | #include <logfunc.hpp> |
30 | ||
72e54d1c | 31 | #include "mock_linkstatus.h" |
6f19218c | 32 | |
6c14bbee | 33 | #include "host/hoststatus.h" |
96c4e7a4 | 34 | #include "host/pingstatus.h" |
6f19218c | 35 | |
6c14bbee | 36 | BOOST_AUTO_TEST_SUITE( TestHostStatus ) |
6f19218c GMF |
37 | |
38 | BOOST_AUTO_TEST_CASE( fail_percentage_10 ) | |
39 | { | |
216a9c6e CH |
40 | I2n::Logger::enable_stderr_log( true ); |
41 | I2n::Logger::set_log_level( I2n::Logger::LogLevel::Debug ); | |
42 | I2n::Logger::GlobalLogger.info() << "Logging enabled for testing"; | |
43 | ||
6f19218c | 44 | int ping_fail_percentage_limit = 10; |
a7b15639 | 45 | int ping_congestion_percentage_limit = 75; |
941b5e25 | 46 | int congest_caused_by_fail_percentage_limit = 90; |
a7b15639 CH |
47 | int ping_congestion_duration_thresh = 5; |
48 | int n_parallel_pings = 1; | |
6f19218c | 49 | int resolved_ip_count = 10; |
216a9c6e | 50 | long duration = 1000; // microseconds |
6f19218c | 51 | |
72e54d1c | 52 | LinkStatusItem link_status( new LinkStatus ); |
a7b15639 CH |
53 | HostStatus host_status( "localhost", |
54 | ping_fail_percentage_limit, | |
55 | ping_congestion_percentage_limit, | |
941b5e25 | 56 | congest_caused_by_fail_percentage_limit, |
a7b15639 CH |
57 | ping_congestion_duration_thresh, |
58 | n_parallel_pings, | |
91aa83f9 | 59 | link_status ); |
6f19218c GMF |
60 | host_status.set_resolved_ip_count( resolved_ip_count ); |
61 | ||
216a9c6e | 62 | host_status.update_ping_statistics( PingStatus_SuccessReply, duration ); |
6f19218c GMF |
63 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
64 | ||
216a9c6e | 65 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
66 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
67 | ||
216a9c6e | 68 | host_status.update_ping_statistics( PingStatus_FailureOther, duration); |
6f19218c GMF |
69 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
70 | ||
216a9c6e | 71 | host_status.update_ping_statistics( PingStatus_SuccessReply, duration ); |
6f19218c GMF |
72 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
73 | ||
216a9c6e | 74 | host_status.update_ping_statistics( PingStatus_SuccessReply, duration ); |
6f19218c GMF |
75 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
76 | ||
216a9c6e | 77 | host_status.update_ping_statistics( PingStatus_SuccessReply, duration ); |
6f19218c GMF |
78 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
79 | ||
216a9c6e | 80 | host_status.update_ping_statistics( PingStatus_SuccessReply, duration ); |
6f19218c GMF |
81 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
82 | ||
216a9c6e | 83 | host_status.update_ping_statistics( PingStatus_SuccessReply, duration ); |
6f19218c GMF |
84 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
85 | ||
216a9c6e | 86 | host_status.update_ping_statistics( PingStatus_SuccessReply, duration ); |
6f19218c GMF |
87 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
88 | ||
216a9c6e | 89 | host_status.update_ping_statistics( PingStatus_SuccessReply, duration ); |
6f19218c GMF |
90 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
91 | } | |
92 | ||
93 | BOOST_AUTO_TEST_CASE( fail_percentage_50 ) | |
94 | { | |
95 | int ping_fail_percentage_limit = 50; | |
a7b15639 | 96 | int ping_congestion_percentage_limit = 75; |
941b5e25 | 97 | int congest_caused_by_fail_percentage_limit = 90; |
a7b15639 CH |
98 | int ping_congestion_duration_thresh = 5; |
99 | int n_parallel_pings = 1; | |
6f19218c | 100 | int resolved_ip_count = 10; |
216a9c6e | 101 | long duration = 1000; // microseconds |
6f19218c | 102 | |
72e54d1c | 103 | LinkStatusItem link_status( new LinkStatus ); |
a7b15639 CH |
104 | HostStatus host_status( "localhost", |
105 | ping_fail_percentage_limit, | |
106 | ping_congestion_percentage_limit, | |
941b5e25 | 107 | congest_caused_by_fail_percentage_limit, |
a7b15639 CH |
108 | ping_congestion_duration_thresh, |
109 | n_parallel_pings, | |
91aa83f9 | 110 | link_status ); |
6f19218c GMF |
111 | host_status.set_resolved_ip_count( resolved_ip_count ); |
112 | ||
216a9c6e | 113 | host_status.update_ping_statistics( PingStatus_SuccessReply, duration ); |
6f19218c GMF |
114 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
115 | ||
216a9c6e | 116 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
117 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
118 | ||
216a9c6e | 119 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
120 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
121 | ||
216a9c6e | 122 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
123 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
124 | ||
216a9c6e | 125 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
126 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
127 | ||
216a9c6e | 128 | host_status.update_ping_statistics( PingStatus_SuccessReply, duration ); |
6f19218c GMF |
129 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
130 | ||
216a9c6e | 131 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
132 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
133 | ||
216a9c6e | 134 | host_status.update_ping_statistics( PingStatus_SuccessReply, duration ); |
6f19218c GMF |
135 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
136 | ||
216a9c6e | 137 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
138 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
139 | ||
216a9c6e | 140 | host_status.update_ping_statistics( PingStatus_SuccessReply, duration ); |
6f19218c GMF |
141 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
142 | } | |
143 | ||
144 | BOOST_AUTO_TEST_CASE( fail_percentage_80 ) | |
145 | { | |
146 | int ping_fail_percentage_limit = 80; | |
a7b15639 | 147 | int ping_congestion_percentage_limit = 75; |
941b5e25 | 148 | int congest_caused_by_fail_percentage_limit = 90; |
a7b15639 CH |
149 | int ping_congestion_duration_thresh = 5; |
150 | int n_parallel_pings = 1; | |
6f19218c | 151 | int resolved_ip_count = 10; |
216a9c6e | 152 | long duration = 1000; // microseconds |
6f19218c | 153 | |
72e54d1c | 154 | LinkStatusItem link_status( new LinkStatus ); |
a7b15639 CH |
155 | HostStatus host_status( "localhost", |
156 | ping_fail_percentage_limit, | |
157 | ping_congestion_percentage_limit, | |
941b5e25 | 158 | congest_caused_by_fail_percentage_limit, |
a7b15639 CH |
159 | ping_congestion_duration_thresh, |
160 | n_parallel_pings, | |
91aa83f9 | 161 | link_status ); |
6f19218c GMF |
162 | host_status.set_resolved_ip_count( resolved_ip_count ); |
163 | ||
216a9c6e | 164 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
165 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
166 | ||
216a9c6e | 167 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
168 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
169 | ||
216a9c6e | 170 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
171 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
172 | ||
216a9c6e | 173 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
174 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
175 | ||
216a9c6e | 176 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
177 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
178 | ||
216a9c6e | 179 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
180 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
181 | ||
216a9c6e | 182 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
183 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
184 | ||
216a9c6e | 185 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
186 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
187 | ||
216a9c6e | 188 | host_status.update_ping_statistics( PingStatus_FailureOther, duration ); |
6f19218c GMF |
189 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
190 | ||
216a9c6e | 191 | host_status.update_ping_statistics( PingStatus_SuccessReply, duration ); |
6f19218c GMF |
192 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
193 | } | |
194 | ||
195 | BOOST_AUTO_TEST_SUITE_END() |