2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
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.
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.
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.
20 #ifndef PING_SCHEDULER_H
21 #define PING_SCHEDULER_H
28 #include <boost/asio.hpp>
29 #include <boost/shared_ptr.hpp>
31 #include "link/linkstatus.h"
32 #include "host/hoststatus.h"
33 #include "host/pingstatus.h"
34 #include "host/pinger.h"
35 #include "host/pinginterval.h"
36 #include "host/pingprotocol.h"
37 #include "dns/resolverbase.h"
39 typedef std::list<PingerItem> pinger_list;
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
46 * @brief This class is responsible to control whether to ping a host. It
47 * schedules periodic pings to a host.
48 * Scope: one object per host.
54 const IoServiceItem io_service,
55 const std::string &network_interface,
56 const std::string &destination_address,
57 const uint16_t destination_port,
58 const PingProtocolList &ping_protocol_list,
59 const long ping_interval_in_sec,
60 const int ping_fail_percentage_limit,
61 const int ping_reply_timeout,
62 LinkStatusItem link_analyzer,
63 const int first_delay,
64 const int n_parallel_pings,
65 const int parallel_ping_delay
77 void ping(const boost::system::error_code &error);
78 void ping_done_handler(const PingStatus &result,
79 const long ping_duration_us);
80 void update_ping_interval();
82 void init_ping_protocol();
83 void update_ping_protocol();
84 void get_next_ping_protocol();
85 bool can_change_ping_protocol() const;
87 void prepare_next_ping();
88 void update_dns_resolver( PingProtocol current_protocol );
90 void ping_when_ready();
91 void dns_resolve_callback(const bool was_success,
92 const int recursion_count);
93 void start_resolving_ping_address();
95 void update_log_prefix();
96 void cancel_resolve(const bool force_cancel);
103 /// The IO service object, which has the loop event
104 IoServiceItem IoService;
105 /// The network interface name
106 std::string NetworkInterfaceName;
107 /// The address to ping
108 std::string DestinationAddress;
109 /// The port to ping at destination host (same for all protocols)
110 uint16_t DestinationPort;
111 /// The list of protocols to ping and iterator over them
112 PingProtocolList Protocols;
113 PingProtocolList::const_iterator ProtocolIter;
114 /// Interval between each ping to the same host
115 PingInterval PingIntervalInSec;
116 /// delay for very first ping to avoid lots of simultaneous pings at startup
118 /// Timer to trigger the next ping
119 boost::asio::deadline_timer NextPingTimer;
120 /// Keeps track of the time when the last ping was send
121 boost::posix_time::ptime TimeSentLastPing;
122 /// time threshold for ping
123 const int PingReplyTimeout;
124 /// Object responsible to evaluate the status of the host
125 HostStatus HostAnalyzer;
127 ResolverItem Resolver;
128 /// vector of pingers
130 /// number of pingers that work in parallel
132 /// number of results from pingers
134 /// delay (in ms) between pings to same IP
135 int ParallelPingDelay;
136 /// a flag whether we should ping as soon as dns is ready
138 /// Prefix to log messages for quicker analysis/debugging
139 std::string LogPrefix;
140 /// Flag whether DNS resolution has failed so we have to run on outdated IPs
141 bool ContinueOnOutdatedIps;
144 //-----------------------------------------------------------------------------
146 //-----------------------------------------------------------------------------
148 typedef boost::shared_ptr<PingScheduler> PingSchedulerItem;
150 //-----------------------------------------------------------------------------
152 //-----------------------------------------------------------------------------
154 typedef std::vector< PingSchedulerItem > PingSchedulerList;
156 #endif // PING_SCHEDULER_H