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 | */ | |
a9c88e1c GMF |
20 | #ifndef PING_SCHEDULER_H |
21 | #define PING_SCHEDULER_H | |
ced28dc7 | 22 | |
238da857 GMF |
23 | #include <stdint.h> |
24 | ||
9c55ecd3 | 25 | #include <string> |
5624490d | 26 | #include <vector> |
9c55ecd3 | 27 | |
e39cc3da GMF |
28 | #include <boost/asio.hpp> |
29 | #include <boost/shared_ptr.hpp> | |
ced28dc7 | 30 | |
72e54d1c | 31 | #include "link/linkstatus.h" |
6c14bbee | 32 | #include "host/hoststatus.h" |
51cbc790 | 33 | #include "host/pinger.h" |
8f66f529 | 34 | #include "host/pinginterval.h" |
3fd74a53 | 35 | #include "host/pingprotocol.h" |
26b0f687 | 36 | #include "dns/resolverbase.h" |
ced28dc7 | 37 | |
4c2a5ab5 | 38 | //----------------------------------------------------------------------------- |
4bb97b45 | 39 | // PingScheduler |
4c2a5ab5 GMF |
40 | //----------------------------------------------------------------------------- |
41 | ||
c5e4bfa1 GMF |
42 | /** |
43 | * @brief This class is responsible to control whether to ping a host. It | |
44 | * schedules periodic pings to a host. | |
45 | * Scope: one object per host. | |
46 | */ | |
4bb97b45 | 47 | class PingScheduler |
ced28dc7 GMF |
48 | { |
49 | public: | |
4bb97b45 | 50 | PingScheduler( |
365036be | 51 | const IoServiceItem io_service, |
2bf8720f GMF |
52 | const std::string &network_interface, |
53 | const std::string &destination_address, | |
238da857 | 54 | const uint16_t destination_port, |
fe6a2f80 | 55 | const PingProtocolList &ping_protocol_list, |
c15a722d | 56 | const long ping_interval_in_sec, |
a341119a | 57 | const int ping_fail_percentage_limit, |
079d19ab | 58 | const int ping_reply_timeout, |
59733431 CH |
59 | LinkStatusItem link_analyzer, |
60 | const int first_delay | |
e39cc3da | 61 | ); |
a86e8ddc | 62 | ~PingScheduler(); |
ced28dc7 | 63 | |
365036be CH |
64 | void start_pinging(); |
65 | void stop_pinging(); | |
88714861 GMF |
66 | |
67 | private: | |
010b8519 GMF |
68 | // |
69 | // Methods | |
70 | // | |
71 | ||
26b0f687 | 72 | void ping(const boost::system::error_code &error); |
c1d776ba | 73 | void ping_done_handler(const bool ping_success); |
d8a91bd6 | 74 | void update_ping_interval(); |
09de3c4b | 75 | void update_ping_elapsed_time(); |
ced28dc7 | 76 | |
23f51766 CH |
77 | void init_ping_protocol(); |
78 | void update_ping_protocol(); | |
79 | void get_next_ping_protocol(); | |
80 | bool can_change_ping_protocol() const; | |
81 | ||
82 | void update_dns_resolver( PingProtocol current_protocol ); | |
83 | ||
8d26221d | 84 | void ping_when_ready(); |
23f51766 | 85 | void dns_resolve_callback(const bool was_success, const int cname_count); |
26b0f687 CH |
86 | void start_resolving_ping_address(); |
87 | ||
88 | void update_log_prefix(); | |
23f51766 | 89 | |
010b8519 GMF |
90 | // |
91 | // Attributes | |
92 | // | |
93 | ||
23f51766 CH |
94 | /// The IO service object, which has the loop event |
95 | IoServiceItem IoService; | |
96 | /// The network interface name | |
97 | std::string NetworkInterfaceName; | |
23f51766 CH |
98 | /// The address to ping |
99 | std::string DestinationAddress; | |
26b0f687 | 100 | /// The port to ping at destination host (same for all protocols) |
23f51766 | 101 | uint16_t DestinationPort; |
26b0f687 CH |
102 | /// The list of protocols to ping and iterator over them |
103 | PingProtocolList Protocols; | |
104 | PingProtocolList::const_iterator ProtocolIter; | |
105 | /// Interval between each ping to the same host | |
106 | PingInterval PingIntervalInSec; | |
107 | /// delay for very first ping to avoid lots of simultaneous pings at startup | |
108 | int FirstDelay; | |
109 | /// Timer to trigger the next ping | |
110 | boost::asio::deadline_timer NextPingTimer; | |
111 | /// Keeps track of the time when the last ping was send | |
112 | boost::posix_time::ptime TimeSentLastPing; | |
113 | /// time threshold for ping | |
23f51766 | 114 | const int PingReplyTimeout; |
26b0f687 CH |
115 | /// Object responsible to evaluate the status of the host |
116 | HostStatus HostAnalyzer; | |
117 | /// The Dns resolver | |
118 | ResolverItem Resolver; | |
119 | /// The actual pinger | |
23f51766 CH |
120 | PingerItem Ping; |
121 | /// a flag whether we should ping as soon as dns is ready | |
122 | bool WantToPing; | |
26b0f687 CH |
123 | /// Prefix to log messages for quicker analysis/debugging |
124 | std::string LogPrefix; | |
125 | /// Flag whether DNS resolution has failed so we have to run on outdated IPs | |
126 | bool ContinueOnOutdatedIps; | |
ced28dc7 GMF |
127 | }; |
128 | ||
e39cc3da | 129 | //----------------------------------------------------------------------------- |
4bb97b45 | 130 | // PingSchedulerItem |
e39cc3da GMF |
131 | //----------------------------------------------------------------------------- |
132 | ||
4bb97b45 | 133 | typedef boost::shared_ptr<PingScheduler> PingSchedulerItem; |
e39cc3da | 134 | |
5624490d GMF |
135 | //----------------------------------------------------------------------------- |
136 | // PingSchedulerList | |
137 | //----------------------------------------------------------------------------- | |
138 | ||
139 | typedef std::vector< PingSchedulerItem > PingSchedulerList; | |
140 | ||
a9c88e1c | 141 | #endif // PING_SCHEDULER_H |