"TCP/IP detailed" Reading notes (Chapter 21)-tcp Timeout and retransmission

Source: Internet
Author: User

TCP provides a reliable transport layer. One of the methods it uses is to confirm the data received from the other end. But data and confirmations are likely to be lost. TCP solves this problem by setting a timer at the time of sending. If the timer does not receive a confirmation when it overflows, it will retransmit the data.

The key to implementation is the time-out and retransmission strategy, that is, how to determine the time-out interval and how often to determine retransmission.

TCP manages 4 different timers:

    • Retransmission timer: Used when you want to receive confirmation from the other end.
    • Hold the timer: keep the window information flowing, even if the other end closes its receive window.
    • KeepAlive Timer: Detects when the other end of an idle connection crashes or restarts.
    • 2MSL Timer: Measure When a connection is in the Time_wati state.

Exponential Backoff: The book examines the different time differences between successive retransmissions, they are 1, 3, 6, 12, 24, 48, and more than 64 seconds after rounding, where the timeout set after the first send is set to 1.5 seconds. (2 of N times * 1.5 seconds)

1. Round-Trip Time measurement

RTT (Round trip time): Refers to the time that the sending side sends a TCP message segment to start to receive the confirmation of the other party.

The most important part of TCP timeouts and re-crosses is testing the round-trip time for a given connection. Because routers and network traffic change, we think that this time may change frequently, and TCP should track these changes and change its time-out accordingly.

RTO (Time-out retransmission): After sending a TCP segment, the sender does not receive a confirmation from the other party within the RTO time, that is, the message segment is re-transmitted.

The earliest TCP used a very simple formula to estimate the current state of the network, as follows:

r<-ar+ (1-a) M Rtp=rb

Where a is an empirical coefficient of 0.9, called the smoothing factor, B is usually 2. This value can be modified. This formula is said to combine the old RTT (R) with the new RTT (M) to consider the size of the new RTT (R). This smoothed RTT will be updated each time a new measurement is made. Each new estimate of 90% comes from the previous estimate, while 10% is taken from the new test.

However, when the range of RTT varies greatly, using this method cannot keep up with this change, thus causing unnecessary retransmission. When the network is already saturated, unnecessary and retransmission increases the load on the network, which is like adding fuel to the network. Then there is the following correction formula:

Err=m-a A<-a+gerr D<-d+h (| err|-d) Rto=a+4d

    • A smooth RTT (mean estimator)
    • D-Smoothed Variance
    • G Increment
    • The gain of the H-variance

The RTO value is based on the mean and variance of the RTT, which better responds to changes in the RTT.


Karn algorithm (retransmission ambiguity)

If a packet is sent, when a timeout occurs, the RTO index is Backoff, the packet is re-transmitted, and then an ACK is received. At this point, however, it is not certain that the ACK is for the first group or retransmission group, which is the retransmission ambiguity problem.

The Karn algorithm addresses this problem

(1) The RTT is not updated for the acknowledgement of the datagram that timed out retransmission.
(2) It is important to note that: In the case of retransmission, the RTO is not calculated using the formula above, but in a way called "exponential avoidance". RTO Index Backoff, the RTO value is used for the next transmission.
(3) After retransmission data confirmation, the data sent again if normal is determined, restore Jacobson 1988 formula, update RTO and RTT.

2. Congestion Avoidance algorithm

The algorithm assumes that the loss due to packet corruption is very small, so packet loss means that there is a congestion on a network somewhere between the source and destination hosts. There are two types of packet loss instructions:

    • Timeout occurred
    • Duplicate acknowledgement received

Data in the transmission of the time can not only use a window protocol, we also need to have a congestion window to control the flow of data, so that the data does not run into the network suddenly caused "congestion." It has also been mentioned that the congestion window initially uses exponential growth to increase its own window until a time-out retransmission occurs and a fine tune is made. However, there is no mention of how to fine-tune the congestion avoidance algorithm and slow-start thresholds for this purpose.

The so-called slow-start threshold means that when the congestion window exceeds this threshold, the congestion avoidance algorithm is used, and the slow-start algorithm is used within the threshold. So this standard is called threshold , usually, congestion window to do CWnd, slow start threshold to do Ssthresh. Let's take a look at how congestion avoidance and slow start work together.

The congestion avoidance algorithm and the slow start algorithm are two different and independent algorithms. We want to reduce the transfer rate of packets into the network, so we can call slow boot to do this, and the congestion avoidance algorithm and the slow-start algorithm are usually used together:
Maintain two variables per connection: Congestion window (CWnd) slow start threshold (Ssthresh)

Algorithm Overview:

    1. for a given connection, the CWnd is initialized to 1 message segments, Ssthresh is 65,535 bytes.
    2. tcp output routines cannot exceed CWnd and receiver pass The size of the window. Congestion avoidance is the traffic control used by the sender, and the notification window is the traffic control performed by the receiver. The former is an estimate of the network congestion that the sender feels, while the latter is related to the cache size available to the receiver on the connection.

CWnd Add Way
Slow start the initial CWnd is 1, each received a definite increase of 1, into exponential growth.
The congestion avoidance algorithm adds 1/cwnd packets within each RTT, increasing linearly.
Slow start increases CWnd based on the number of ACK received, while congestion avoidance algorithms are incremented only once in a RTT regardless of how many ack is received.


3. Fast retransmission and fast recovery algorithm

If you receive 3 duplicate ACK, you can think that the message segment has been lost, there is no need to wait for time-out timer overflow, directly retransmit the lost packets, this is called fast retransmission algorithm. Instead of slow start, the next step is to avoid the congestion avoidance algorithm, which is called the Fast Recovery algorithm.
(1) When the 3rd duplicate ACK is received, the Ssthresh is set to half of the current congestion window CWnd, retransmission the missing segment, set the CWnd to Ssthresh plus 3 times times the message segment size.
(2) Each time another duplicate ACK is received, CWnd adds 1 segment sizes and sends 1 packets (if the new CWnd is allowed to send).
(3) The next time a ACK arrives confirming the new data, set CWnd to Ssthresh (the value set in step 1th). This ACK should be the confirmation of retransmission in step 1 within a round trip time after the retransmission. In addition, this ACK should also be the acknowledgment of all intermediate segments between the missing packet and the 1th duplicate ACK received. This step uses congestion avoidance because we halve the current rate when the packet is lost.


4.ICMP Error

The most common ICMP errors that TCP can encounter are source station suppression, host unreachable, and network unreachable.

(1) The source station suppresses ICMP to set the congestion window CWnd to 1 segment, and initiates the slow start, the slow start threshold ssthresh unchanged, the window will open until all paths are opened (subject to window size and round-trip time limit) or congestion occurs.

(2) ICMP, which is unreachable by the host or unreachable by the network, is ignored because both errors are considered short-lived.

5. Re-grouping

When the TCP timeout is re-transmitted, it does not necessarily need to retransmit the same message segment. Conversely, TCP allows for the re-grouping to send a larger segment, which will help improve performance (of course, this larger segment is not capable of exceeding the MSS declared by the receiving party)

Author original, reprint please mark the same place: http://blog.csdn.net/xifeijian/article/details/44261821


"TCP/IP detailed" Reading notes (Chapter 21)-tcp Timeout and retransmission

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.