Skip to content

Commit

Permalink
Implement probe moderation and delaying algorithm.
Browse files Browse the repository at this point in the history
This should meet the following requirements:
  - only one probe in flight,
  - not too often (500ms delay min),
  - increase SRTT on idle flows.
  • Loading branch information
Matthieu Boutier committed Nov 23, 2014
1 parent ccb00cb commit 3b66586
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/network/network.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,21 @@ Packet Connection::new_packet( Flow *flow, uint16_t flags, string &s_payload )
flow->saved_timestamp_received_at = 0;
}

if ( !server ) {
unsigned int delay = MAX( (int)flow->SRTT + 4 * flow->RTTVAR, MIN_PROBE_INTERVAL );
if ( flow->first_sent_message_since_reply <= flow->last_heard ) {
flow->first_sent_message_since_reply = now;
} else if ( delay < now - flow->first_sent_message_since_reply ) {
flow->SRTT = now - flow->first_sent_message_since_reply;
log_dbg( LOG_DEBUG_COMMON, "Flow %hu seems idle: SRTT = %dms.\n",
flow->flow_id, (int)flow->SRTT );
}

if ( flags & PROBE_FLAG ) {
flow->next_probe = now + delay;
}
}

Packet p( flow->next_seq++, direction, timestamp16(), outgoing_timestamp_reply,
flow->flow_id, flags, s_payload );

Expand Down Expand Up @@ -272,6 +287,9 @@ Connection::Flow::Flow( const Addr &s_src, const Addr &s_dst )
expected_receiver_seq( defaults.expected_receiver_seq ),
saved_timestamp( defaults.saved_timestamp ),
saved_timestamp_received_at( defaults.saved_timestamp_received_at ),
first_sent_message_since_reply( defaults.first_sent_message_since_reply ),
last_heard( defaults.last_heard ),
next_probe( defaults.next_probe ),
RTT_hit( defaults.RTT_hit ),
SRTT( defaults.SRTT ),
RTTVAR( defaults.RTTVAR ),
Expand All @@ -291,6 +309,9 @@ Connection::Flow::Flow( const Addr &s_src, const Addr &s_dst, uint16_t id )
expected_receiver_seq( defaults.expected_receiver_seq ),
saved_timestamp( defaults.saved_timestamp ),
saved_timestamp_received_at( defaults.saved_timestamp_received_at ),
first_sent_message_since_reply( defaults.first_sent_message_since_reply ),
last_heard( defaults.last_heard ),
next_probe( defaults.next_probe ),
RTT_hit( defaults.RTT_hit ),
SRTT( defaults.SRTT ),
RTTVAR( defaults.RTTVAR ),
Expand Down Expand Up @@ -582,8 +603,9 @@ void Connection::send_probes( void )
for ( std::map< uint16_t, Flow* >::iterator it = flows.begin();
it != flows.end();
it++ ) {
if ( it->second != last_flow ) {
send_probe( it->second );
Flow *flow = it->second;
if ( flow != last_flow && flow->next_probe <= timestamp() ) {
send_probe( flow );
}
}
}
Expand Down Expand Up @@ -1022,7 +1044,7 @@ string Connection::recv_one( int sock_to_recv )
}

/* auto-adjust to remote host */
last_heard = timestamp();
flow_info->last_heard = last_heard = timestamp();

if ( server ) { /* only client can roam */
bool has_roam = last_flow != flow_info;
Expand Down
5 changes: 5 additions & 0 deletions src/network/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ namespace Network {
static const unsigned int SERVER_ASSOCIATION_TIMEOUT = 40000;
static const unsigned int PORT_HOP_INTERVAL = 10000;
static const unsigned int MAX_ADDR_REQUEST_INTERVAL = 10000;
static const unsigned int MIN_PROBE_INTERVAL = 500;

static const unsigned int MAX_PORTS_OPEN = 10;
static const unsigned int MAX_OLD_SOCKET_AGE = 60000;
Expand All @@ -116,6 +117,7 @@ namespace Network {
Flow( void )
: src( Addr() ), dst( Addr() ), MTU( DEFAULT_SEND_MTU ), next_seq( 0 ),
expected_receiver_seq( 0 ), saved_timestamp( -1 ), saved_timestamp_received_at( 0 ),
first_sent_message_since_reply( 0 ), last_heard( 0 ), next_probe( 0 ),
RTT_hit( false ), SRTT( 1000 ), RTTVAR( 500 ), flow_id( 0 )
{}

Expand All @@ -128,6 +130,9 @@ namespace Network {
uint64_t expected_receiver_seq;
uint16_t saved_timestamp;
uint64_t saved_timestamp_received_at;
uint64_t first_sent_message_since_reply;
uint64_t last_heard;
uint64_t next_probe;
bool RTT_hit;
double SRTT;
double RTTVAR;
Expand Down

0 comments on commit 3b66586

Please sign in to comment.