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/pinger.h"
34 #include "host/pinginterval.h"
35 #include "host/pingprotocol.h"
36 #include "host/pingrotate.h"
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
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.
51 const IoServiceItem io_service,
52 const std::string &network_interface,
53 const std::string &destination_address,
54 const uint16_t destination_port,
55 const PingProtocolList &ping_protocol_list,
56 const long ping_interval_in_sec,
57 const int ping_fail_percentage_limit,
58 const int ping_reply_timeout,
59 const int resolved_ip_ttl_threshold,
60 LinkStatusItem link_analyzer,
73 void resolve_and_ping(const boost::system::error_code &error);
76 void ping_done_handler(const bool ping_success);
77 void update_ping_interval();
78 void update_ping_elapsed_time();
84 /// Timer to trigger the next ping
85 boost::asio::deadline_timer NextPingTimer;
86 /// Timer to trigger the next attempt to resolve addresses
87 boost::asio::deadline_timer NextAddressTimer;
88 /// Keeps track of the time when the last ping was send
89 boost::posix_time::ptime TimeSentLastPing;
90 /// Interval between each ping to the same host
91 PingInterval PingIntervalInSec;
92 /// Interval between attempts to resolve host address
93 PingInterval AddressResolveIntervalInSec;
94 /// Object responsible to evaluate the status of the host
95 HostStatus HostAnalyzer;
96 /// delay for very first ping to avoid lots of simultaneous pings
98 /// number of attempts at Address Resolution
99 int AddressResolutionAttempts;
100 /// flag whether any DNS lookup succeeded
101 // (comparing get_ip_count to 0 might violate assertion in dnsresolver.cpp)
103 /// Internal boost pinger object
107 //-----------------------------------------------------------------------------
109 //-----------------------------------------------------------------------------
111 typedef boost::shared_ptr<PingScheduler> PingSchedulerItem;
113 //-----------------------------------------------------------------------------
115 //-----------------------------------------------------------------------------
117 typedef std::vector< PingSchedulerItem > PingSchedulerList;
119 #endif // PING_SCHEDULER_H