Linux内核中的使用
如果支持Timestamp选项,那么可以用此选项来计算RTT。
static void tcp_ack_saw_tstamp(struct sock *sk , int flag)
{
/* RTTM Rule: A TSecr value received in a segment is used to
* update the averaged RTT measurement only if the segment
* acknowledges some new data, i.e., only if it advances the
* left edge of the send window.
*
* Changed: reset backoff as soon as we see the first valid
* sample. If we do not, we get strongly overestimated rto.
* With timestamps samples are accepted even from very
* old segments: f.e., when rtt=1 increases to 8, we retransmit
* 5 times and after 8 seconds delayed answer arrives rto
* becomes 120 seconds!
*/
struct tcp_sock *tp = tcp_sk(sk);
tcp_valid_rtt_meas(sk, tcp_time_stamp - tp->rx_opt.rcv_tsecr);
}
rtt即等于现在的时间tcp_time_stamp减去Timestamp Echo Reply,即tp->rx_opt.rcv_tsecr。
TCP timestamp option的作用:
1)allow more accurate round-trip time measurements for deriving the retransmission timeout estimator.
2)protect against old segments from the previous incarnations of the TCP connection.
3)allow detection of unnecessary retransmissions.
tcp_tw_recycle/tcp_timestamps都开启的条件下,60s内同一源ip主机的socket connect请求中的timestamp必须是递增的。
本文如未解决您的问题请添加抖音号:51dongshi(抖音搜索懂视),直接咨询即可。