Kernel version: 3.2.12
This article mainly analyzes: RTT measurement, RTO calculation
Author: zhangskd @ csdn
Link: http://blog.csdn.net/zhangskd/ article/details/7196707
Overview
RTO (Retransmission TimeOut) is the retransmission timeout.
A very important part of TCP timeouts and retransmissions is the measurement of the round trip time (RTT) for a given connection. Due to changes in network traffic,
this time will change accordingly, and TCP needs to track these changes and dynamically adjust the timeout RTO.
RTO is described in this way in RFC2988:
“The Transmission Control Protocol (TCP) uses a retransmission timer to ensure
data delivery in the absence of any feedback from the remote data receiver. The
duration of this timer is referred to as RTO (retransmission timeout).”
RTT (Round Trip Time) consists of three parts: link Propagation delay, processing time in end systems,
queuing and processing time in router caches (queuing delay).
Among them, the values of the first two parts are relatively fixed for a TCP connection, and the queuing and processing time in the router cache will change with the change of the entire network congestion
. Therefore, the change of RTT reflects the degree of network congestion to a certain extent.
average Deviation
Mean deviation, abbreviated as mdev.
It is the mean of the distances between each value and the mean. It gives us an idea of how to spread
out from the center the set of values is.
Here’s the formula.
By calculating the average deviation, you can know the fluctuation of a set of data.
Here, the average deviation can be used to measure the jitter of RTT.
RTT Measuring principle
There are two ways to measure RTT:
(1) TCP Timestamp option
In the previous blog This option has been introduced in detail, and the TCP timestamp option can be used to accurately measure RTT.
RTT = current time – the echo time of the Timestamp option in the data packet
This echo time is the time when the data packet is sent out, and the receiving time (current time) and sending time of the data packet are known
(echo time), you can easily get a measured value of RTT.
(2) TCP control block of packets in the retransmission queue
In the TCP retransmission queue, the data packets sent but not confirmed are saved. The TCP control block in the data packet skb contains a variable,
tcp_skb_cb->when, which records the first sending of the data packet time.
RTT = current time – when
Someone may ask: Since the TCP Timestamp option can be measured RTT, why bother?
This is becauseMethod 1 is more powerful than method 2, and they are different.
“TCP must use Karn’s algorithm for taking RTT samples. That is, RTT samples MUST NOT
be made using segments that were retransmitted (and thus for which it is ambiguous whether
the reply was for the first instance of the packet or a later instance). The only case when TCP
can safely take RTT samples from retransmitted segments is when the TCP timestamp option
is employed, since the timestamp option removes the ambiguity regarding which instance of
> the data segment triggered the acknowledgment.”
For the response of the retransmitted data packet, method 1 can use it to collect a new RTT measurement sample, while method 2 cannot. Because the
TCP Timestamp option can distinguish whether the response is triggered by the original data packet or the retransmission data packet, so as to calculate the accurate
RTT value.
RTT Measurement implementation
Every time the sender receives an ACK, it will call tcp_ack() to deal with.
tcp_clean_rtx_queue() will be called in tcp_ack() to delete the confirmed data segments in the retransmission queue.
In tcp_clean_rtx_queue():
If ACK confirms the retransmitted data packet, then seq_rtt = -1;
Otherwise, seq_rtt = now – scb->when;
Then call tcp_ack_update_rtt(sk , flag, seq_rtt) to update RTT and RTO.
[java]
view plain
copy
- static inline void tcp_ack_update_rtt (struct sock *sk, const in flag,
- const s32 seq_rtt)
- {
- const struct tcp_sock *tp = tcp_sk(sk);
- /* Note that peer MAY send zero echo .In this case it is ignored. (rfc1323) */
- /* If the TCP Timestamp option is enabled, And the echo of the receiver is not 0*/
- if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr)
- tcp_ack_saw_tstamp(sk, flag); /* Method 1*/
- else if ( seq_rtt >= 0) /* Cannot be the ACK of the retransmitted data packet */
- static inline u32 __tcp_set_rto(const struct tcp_sock *tp)
- {
- return (tp->srtt >> 3) + tp->rttvar;
- }
- static inline void tcp_bound_rto(const struct sock *sk)
- {
- if (inet_csk(sk)->icsk_rto > TCP_RTO_MAX)
- inet_csk(sk)->icsk_rto = TCP_RTO_MAX;
- }
function call
The function calls involved above are as follows:
Summary
Early RTT measurements were made using coarse-grained timers (Coarse grained timer), which will have a relatively large error.
Now due to the use of the TCP Timestamp option, RTT can be measured more accurately, and thus a more accurate RTO can be calculated.
Reference
RFC 2988
n:0px; padding:0px; border:none; color:rgb(0,102,153); background-color:inherit; font-weight:bold”>if (inet_csk(sk)->icsk_rto > TCP_RTO_MAX)
function call
The function calls involved above are as follows:
Summary
Early RTT measurements were made using coarse-grained timers (Coarse grained timer), which will have a relatively large error.
Now due to the use of the TCP Timestamp option, RTT can be measured more accurately, and thus a more accurate RTO can be calculated.
Reference
RFC 2988