int backoff;
long long int last_received;
long long int last_connected;
+ long long int last_disconnected;
unsigned int max_tries;
/* These values are simply for statistics reporting, not otherwise used
fsm->backoff = 0;
fsm->last_received = now;
fsm->last_connected = now;
+ fsm->last_disconnected = now;
fsm->max_tries = UINT_MAX;
fsm->creation_time = now;
}
}
+ if (fsm->state & (S_ACTIVE | S_IDLE)) {
+ fsm->last_disconnected = now;
+ }
/* Back off. */
if (fsm->state & (S_ACTIVE | S_IDLE)
&& (fsm->last_received - fsm->last_connected >= fsm->backoff
return reconnect_is_connected(fsm) ? now - fsm->last_connected : 0;
}
+/* Returns the number of milliseconds for which 'fsm' has been continuously
+ * disconnected from its peer. (If 'fsm' is not currently connected,
+ * this is 0.) */
+unsigned int
+reconnect_get_disconnect_duration(const struct reconnect *fsm,
+ long long int now)
+{
+ return reconnect_is_connected(fsm) ? 0 : now - fsm->last_disconnected;
+}
+
/* Copies various statistics for 'fsm' into '*stats'. */
void
reconnect_get_stats(const struct reconnect *fsm, long long int now,
stats->creation_time = fsm->creation_time;
stats->last_received = fsm->last_received;
stats->last_connected = fsm->last_connected;
+ stats->last_disconnected = fsm->last_disconnected;
stats->backoff = fsm->backoff;
stats->seqno = fsm->seqno;
stats->is_connected = reconnect_is_connected(fsm);
stats->current_connection_duration
= reconnect_get_connection_duration(fsm, now);
+ stats->current_disconnect_duration
+ = reconnect_get_disconnect_duration(fsm, now);
stats->total_connected_duration = (stats->current_connection_duration
+ fsm->total_connected_duration);
stats->n_attempted_connections = fsm->n_attempted_connections;
in BACKOFF for 0 ms (1000 ms backoff)
1 successful connections out of 1 attempts, seqno 2
not connected (0 ms), total 10000 ms connected
+ disconnected at 11000 ms (0 ms ago)
])
######################################################################
### t=1500 ###
in CONNECT_IN_PROGRESS for 500 ms (0 ms backoff)
+ disconnected for 500 ms
run
connected
in ACTIVE for 0 ms (0 ms backoff)
created 1000, last received 1000, last connected 1500
1 successful connections out of 1 attempts, seqno 1
connected (0 ms), total 0 ms connected
+ disconnected for 0 ms
# Send inactivity probe.
timeout
in BACKOFF for 0 ms (1000 ms backoff)
1 successful connections out of 1 attempts, seqno 2
not connected (0 ms), total 10000 ms connected
+ disconnected at 11500 ms (0 ms ago)
])
######################################################################
### t=2000 ###
in CONNECT_IN_PROGRESS for 1000 ms (0 ms backoff)
+ disconnected for 1000 ms
run
should disconnect
connect-failed
### t=3000 ###
in BACKOFF for 1000 ms (1000 ms backoff)
+ disconnected for 2000 ms
run
should connect
### t=4000 ###
in CONNECT_IN_PROGRESS for 1000 ms (1000 ms backoff)
+ disconnected for 3000 ms
run
should disconnect
connect-failed
### t=6000 ###
in BACKOFF for 2000 ms (2000 ms backoff)
+ disconnected for 5000 ms
run
should connect
### t=8000 ###
in CONNECT_IN_PROGRESS for 2000 ms (2000 ms backoff)
+ disconnected for 7000 ms
run
should disconnect
connect-failed
### t=12000 ###
in BACKOFF for 4000 ms (4000 ms backoff)
+ disconnected for 11000 ms
run
should connect
### t=16000 ###
in CONNECT_IN_PROGRESS for 4000 ms (4000 ms backoff)
+ disconnected for 15000 ms
run
should disconnect
connect-failed
### t=24000 ###
in BACKOFF for 8000 ms (8000 ms backoff)
+ disconnected for 23000 ms
run
should connect
### t=32000 ###
in CONNECT_IN_PROGRESS for 8000 ms (8000 ms backoff)
+ disconnected for 31000 ms
run
should disconnect
connect-failed
### t=40000 ###
in BACKOFF for 8000 ms (8000 ms backoff)
+ disconnected for 39000 ms
run
should connect
### t=48000 ###
in CONNECT_IN_PROGRESS for 8000 ms (8000 ms backoff)
+ disconnected for 47000 ms
run
should disconnect
connect-failed
in BACKOFF for 0 ms (1000 ms backoff)
1 successful connections out of 1 attempts, seqno 2
not connected (0 ms), total 10000 ms connected
+ disconnected at 11000 ms (0 ms ago)
# Back off for 1000 ms.
timeout
### t=12000 ###
in BACKOFF for 1000 ms (1000 ms backoff)
+ disconnected for 1000 ms
run
should connect
created 1000, last received 1000, last connected 12000
2 successful connections out of 2 attempts, seqno 3
connected (0 ms), total 10000 ms connected
+ disconnected for 0 ms
timeout
advance 5000 ms
in BACKOFF for 0 ms (2000 ms backoff)
2 successful connections out of 2 attempts, seqno 4
not connected (0 ms), total 20000 ms connected
+ disconnected at 22000 ms (0 ms ago)
# Back off for 2000 ms.
timeout
### t=24000 ###
in BACKOFF for 2000 ms (2000 ms backoff)
+ disconnected for 2000 ms
run
should connect
created 1000, last received 1000, last connected 24000
3 successful connections out of 3 attempts, seqno 5
connected (0 ms), total 20000 ms connected
+ disconnected for 0 ms
timeout
advance 5000 ms
in BACKOFF for 0 ms (4000 ms backoff)
3 successful connections out of 3 attempts, seqno 6
not connected (0 ms), total 30000 ms connected
+ disconnected at 34000 ms (0 ms ago)
# Back off for 4000 ms.
timeout
### t=38000 ###
in BACKOFF for 4000 ms (4000 ms backoff)
+ disconnected for 4000 ms
])
######################################################################
### t=2000 ###
in CONNECT_IN_PROGRESS for 1000 ms (0 ms backoff)
+ disconnected for 1000 ms
run
should disconnect
connect-failed
### t=3000 ###
in BACKOFF for 1000 ms (1000 ms backoff)
+ disconnected for 2000 ms
run
should connect
### t=4000 ###
in CONNECT_IN_PROGRESS for 1000 ms (1000 ms backoff)
+ disconnected for 3000 ms
run
should disconnect
connect-failed
### t=6000 ###
in BACKOFF for 2000 ms (2000 ms backoff)
+ disconnected for 5000 ms
run
should connect
### t=6500 ###
in CONNECT_IN_PROGRESS for 500 ms (2000 ms backoff)
+ disconnected for 5500 ms
run
connected
in ACTIVE for 0 ms (2000 ms backoff)
created 1000, last received 1000, last connected 6500
1 successful connections out of 3 attempts, seqno 1
connected (0 ms), total 0 ms connected
+ disconnected for 0 ms
# Connection drops after another 250 ms.
advance 250
in BACKOFF for 0 ms (4000 ms backoff)
1 successful connections out of 3 attempts, seqno 2
not connected (0 ms), total 250 ms connected
+ disconnected at 6750 ms (0 ms ago)
run
# Back off for 4000 ms.
### t=10750 ###
in BACKOFF for 4000 ms (4000 ms backoff)
+ disconnected for 4000 ms
run
should connect
])
### t=2000 ###
in CONNECT_IN_PROGRESS for 1000 ms (0 ms backoff)
+ disconnected for 1000 ms
run
should disconnect
connect-failed
### t=3000 ###
in BACKOFF for 1000 ms (1000 ms backoff)
+ disconnected for 2000 ms
run
should connect
### t=4000 ###
in CONNECT_IN_PROGRESS for 1000 ms (1000 ms backoff)
+ disconnected for 3000 ms
run
should disconnect
connect-failed
### t=6000 ###
in BACKOFF for 2000 ms (2000 ms backoff)
+ disconnected for 5000 ms
run
should connect
### t=6500 ###
in CONNECT_IN_PROGRESS for 500 ms (2000 ms backoff)
+ disconnected for 5500 ms
run
connected
in ACTIVE for 0 ms (2000 ms backoff)
created 1000, last received 1000, last connected 6500
1 successful connections out of 3 attempts, seqno 1
connected (0 ms), total 0 ms connected
+ disconnected for 0 ms
# Connection receives 3 chunks of data spaced 250 ms apart.
advance 250
in BACKOFF for 0 ms (4000 ms backoff)
1 successful connections out of 3 attempts, seqno 2
not connected (0 ms), total 750 ms connected
+ disconnected at 7250 ms (0 ms ago)
run
# Back off for 4000 ms.
### t=11250 ###
in BACKOFF for 4000 ms (4000 ms backoff)
+ disconnected for 4000 ms
run
should connect
])
### t=2000 ###
in CONNECT_IN_PROGRESS for 1000 ms (0 ms backoff)
+ disconnected for 1000 ms
run
should disconnect
connect-failed
### t=3000 ###
in BACKOFF for 1000 ms (1000 ms backoff)
+ disconnected for 2000 ms
run
should connect
### t=4000 ###
in CONNECT_IN_PROGRESS for 1000 ms (1000 ms backoff)
+ disconnected for 3000 ms
run
should disconnect
connect-failed
### t=6000 ###
in BACKOFF for 2000 ms (2000 ms backoff)
+ disconnected for 5000 ms
run
should connect
### t=6500 ###
in CONNECT_IN_PROGRESS for 500 ms (2000 ms backoff)
+ disconnected for 5500 ms
run
connected
in ACTIVE for 0 ms (2000 ms backoff)
created 1000, last received 1000, last connected 6500
1 successful connections out of 3 attempts, seqno 1
connected (0 ms), total 0 ms connected
+ disconnected for 0 ms
# Connection receives 3 chunks of data spaced 2000 ms apart.
advance 2000
in BACKOFF for 0 ms (1000 ms backoff)
1 successful connections out of 3 attempts, seqno 2
not connected (0 ms), total 6000 ms connected
+ disconnected at 12500 ms (0 ms ago)
run
# Back off for 1000 ms.
### t=13500 ###
in BACKOFF for 1000 ms (1000 ms backoff)
+ disconnected for 1000 ms
run
should connect
])
### t=2000 ###
in BACKOFF for 1000 ms (1000 ms backoff)
+ disconnected for 1000 ms
# Connection fails quickly again.
run
### t=4000 ###
in BACKOFF for 2000 ms (2000 ms backoff)
+ disconnected for 3000 ms
])
######################################################################
in VOID for 0 ms (1000 ms backoff)
1 successful connections out of 1 attempts, seqno 2
not connected (0 ms), total 10000 ms connected
+ disconnected at 11000 ms (0 ms ago)
])
######################################################################
### t=2000 ###
in BACKOFF for 1000 ms (1000 ms backoff)
+ disconnected for 1000 ms
run
should connect
listening
created 1000, last received 1000, last connected 2000
1 successful connections out of 1 attempts, seqno 1
connected (0 ms), total 0 ms connected
+ disconnected for 0 ms
received
created 1000, last received 2000, last connected 2000
advance 1000
in BACKOFF for 0 ms (0 ms backoff)
1 successful connections out of 1 attempts, seqno 2
not connected (0 ms), total 11000 ms connected
+ disconnected at 13000 ms (0 ms ago)
# Start listening again.
timeout