Tcpip (18) TCP timeout and retransmission

Source: Internet
Author: User

1. Manage four timers for each connection over TCP:

(1) retransmission Timer: used to wait for confirmation from the other end;
(2) persist Timer: used to keep the window size information flowing, even if the other end closes its receiving window;
(3) keepalive Timer: used to check whether the other end of the idle connection is crashed or restarted;
(4) 2msl Timer: used to measure the time of a connection in the time_wait status.

2. Time-out and re-transmission interval

The timeout value can be applied.ProgramSet (so_rcvtimeo, so_sndtimeo), and the retry time adopts the Exponential Backoff method, that is, the interval of each Retry is twice that of the previous retry. In the current implementation, the first packet transmission and reset signal transmission interval is 9 minutes.

3. Round-trip RTT Measurement

Smooth RTT estimator: r = Alpha * r + (1-alpha) * m, where alpha = 0.9, M is the RTT measured by ack

Calculation of Retransmission timeout:

Initially RTO = r * beta, Beta = 2, but this method causes unnecessary retransmission when the RTT changes greatly.

Calculate RTO using mean and variance:

Err = M-A
A = a + Gerr
D = d + H * (| err |-d)
RTO = a + 4D
Where,
A and D are initialized to 0 and 3 respectively, and RTO is initialized to a + 2d = 6.
Only the data packet segment will be timing, not simply ack timing

4. Multi-aspect problem of retransmission (KarnAlgorithm)

When a timeout or retransmission occurs, the RTT estimator cannot be updated before the confirmation of the retransmission data arrives, because we do not know the corresponding transfer of ack. In addition, due to data retransmission, RTO has obtained an exponential backoff, which will be used in the next transmission. For a segment that is not re-transmitted, no new RTO is calculated unless a confirmation is received.

5. Congestion Avoidance Algorithm

The slow-START algorithm initiates data streams on a connection, but sometimes the packets reach the intermediate route limit. The congestion avoidance algorithm is a method for dealing with lost groups. This algorithm assumes that the loss caused by group damage is very small, so the loss of group means that the network of the source host and the target host is congested.

There are two types of group loss indicators: timeout and repeated confirmation.

Congestion avoidance algorithms are usually implemented at the same time as slow start algorithms. They need to maintain two variables for each connection: the congestion window cwnd and the slow start threshold ssthresh. In this way, the algorithm process is as follows:
1) for a given connection, the initial cwnd is a packet segment, and the ssthresh is 65535 bytes.
2) the output of the TCP output routine cannot exceed the size of the cwnd and receiver announcement window. Congestion avoidance is the traffic control used by the sender, while the notification window is the traffic control implemented by the receiver. The former is the estimation of network congestion felt by the sender, and the latter is related to the available cache size of the receiver on the connection.
3) when congestion occurs (timeout or repeated confirmation is received), ssthresh is set to half of the current window size (c w n d and the minimum value of the window size advertised by the receiver, but at least two packet segments ). In addition, if timeout causes congestion, cwnd is set to 1 packet segment (this is a slow start ).
4) when new data is confirmed by the other party, cwnd is added. However, the added method depends on whether we are performing slow start or congestion avoidance. If cwnd is less than or equal to ssthresh, a slow start is underway; otherwise, congestion is being avoided. The startup continues until we return to the half-hour when the congestion occurs (because we recorded half the size of the window that caused us trouble in step 2 ), then it is converted to congestion avoidance.

The slow start algorithm sets cwnd as one packet segment at the beginning, and Adds 1 each time a confirmation is received. This will increase the window exponentially: One packet segment is sent, followed by two, followed by four .......

The congestion avoidance algorithm requires that cwnd be increased by 1/cwnd each time a confirmation is received. Compared with the increase in the index of slow start, this is an additive increase ). We want to add up to one packet segment for cwnd in a round-trip time (no matter how many ACK packets are received in this rt t ), however, the slow start will increase cwnd according to the number of confirmations received during the round-trip time.

The term "slow start" is not completely correct. It only uses the packet transmission rate that is slower than causing congestion, but the rate of the number of groups entering the network during the slow start is still increasing. This increase rate will be slowed down only when ssthresh congestion is reached to prevent the algorithm from working.

Example:

6. Fast retransmission Algorithm

Recommendation for modifying the congestion avoidance algorithm: [Jacob 1990b] In.
Before introducing the changes, we realized that TCP immediately needs to generate an ACK (a duplicate ACK) when receiving an out-of-order packet segment ). The duplicate ack should not be delayed. The purpose of this duplicate Ack is to let the other party know that it has received an out-of-order packet segment and tell the other party the serial number they want to receive.
We do not know whether a duplicate Ack is caused by a lost packet segment or because only a few packets are reordered, so we are waiting for the arrival of a few duplicate ACK packets. If this is only the re-sorting of some packets, only 1 ~ may be generated before the re-sorting packets are processed and a new Ack is generated ~ Two Duplicate ack.
If a series of three or more duplicate ACK packets are received, it is very likely that a packet segment is lost. So we re-transmit the lost data packet segment without waiting for the timeout timer to overflow. This is the fast retransmission algorithm. The next step is not to run the slow start algorithm, but to avoid congestion. This is the quick recovery algorithm.

7. handle ICMP errors through TCP connections

(1) ICMP Origin Site suppression error: the congestion window cwnd is set to one packet segment to initiate a slow start, but the slow start threshold ssthresh remains unchanged;
(2) host or network failures: Ignore because these two errors are generally considered temporary.

8. Regroup

when TCP retransmission is performed, it is not necessary to re-transmit the same packet segment. In fact, TCP allows regrouping and sends a large packet segment, which helps improve performance.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.