to avoid going down in congested line scenario, also need longer ping timeout
[pingcheck] / src / host / pingscheduler.cpp
index 72b084e..b272379 100644 (file)
@@ -44,6 +44,7 @@ using boost::posix_time::milliseconds;
 using boost::shared_ptr;
 using I2n::Logger::GlobalLogger;
 
+
 //-----------------------------------------------------------------------------
 // PingScheduler
 //-----------------------------------------------------------------------------
@@ -81,7 +82,8 @@ PingScheduler::PingScheduler(
         LinkStatusItem link_analyzer,
         const int first_delay,
         const int n_parallel_pings,
-        const int parallel_ping_delay
+        const int parallel_ping_delay,
+        const int ping_timeout_factor
 ) :
     IoService( io_serv ),
     NetworkInterfaceName( network_interface ),
@@ -95,6 +97,7 @@ PingScheduler::PingScheduler(
     NextPingTimer( *io_serv ),
     TimeSentLastPing( microsec_clock::universal_time() ),
     PingReplyTimeout( ping_reply_timeout ),
+    PingReplyTimeoutOrig( ping_reply_timeout ),
     HostAnalyzer( destination_address, ping_fail_percentage_limit,
                   ping_congestion_percentage_limit,
                   ping_congestion_duration_thresh, n_parallel_pings,
@@ -106,7 +109,8 @@ PingScheduler::PingScheduler(
     DelayedPingTimer( *io_serv ),
     WantToPing( false ),
     LogPrefix(),
-    ContinueOnOutdatedIps( false )
+    ContinueOnOutdatedIps( false ),
+    PingTimeoutFactor( ping_timeout_factor )
 {
     BOOST_ASSERT( !network_interface.empty() );
     BOOST_ASSERT( !destination_address.empty() );
@@ -378,6 +382,9 @@ void PingScheduler::update_ping_interval()
 
         GlobalLogger.debug() << LogPrefix << "- Speeding up ping interval to: "
                              << PingIntervalInSec << "s";
+        PingReplyTimeout = PingReplyTimeoutOrig * PingTimeoutFactor;
+        GlobalLogger.debug() << LogPrefix << "- Increase ping timeout to "
+                             << PingReplyTimeout << "s";
     }
     else
     {
@@ -385,6 +392,9 @@ void PingScheduler::update_ping_interval()
 
         GlobalLogger.debug() << LogPrefix << "- Stick to the original ping "
                              << "interval: " << PingIntervalInSec << "s";
+        PingReplyTimeout = PingReplyTimeoutOrig;
+        GlobalLogger.debug() << LogPrefix << "- Reset ping timeout to "
+                             << PingReplyTimeout << "s";
     }
 }