TCP/IP Study Notes (12)-TCP timeout and retransmission

Source: Internet
Author: User

Timeout retransmission is another important mechanism for TCP to ensure data reliability. Its principle is to enable a timer after a certain data is sent, if the ACK packet of the sent datagram is not received within a certain period of time, the data will be resent until the message is sent successfully.
 
1. Timeout
Timeout calculation is the core part of timeout. TCP requires this algorithm to roughly estimate the current network condition, although this is indeed very difficult. There are two reasons for the accuracy: (1) the network utilization rate is not high for a long time. (2) timing is too short, which may cause multiple retransmission and cause network congestion. Therefore, the book provides a set of empirical formulas and other measures to ensure the accuracy of the timer.
 
1. recursive formula Overview
The earliest TCP used a very simple formula to estimate the current network condition, as shown below:
 
R <-aR + (1-a) M
RTP = Rb
A is an empirical coefficient of 0.1, and B is usually 2. Note that this is experience and there is no derivation process. This value can be modified. This formula combines the old RTT (R) and the new RTT (M) to consider the size of the new RTT (R. However, we can see that this kind of estimation is completely unable to make a "sensitive response" when the network is greatly changed (not even mentioned by Jacob boson ), the following formula is provided:
 
Err = M-A
A <-A + gErr
D <-D + h (| Err |-D)
RTO = A + 4D
For specific explanations, please read the 228 page. This recursive formula even uses the statistical concept of variance to make the deviation smaller. In addition, it must be noted that the two groups of formulas are updated only when data is transmitted successfully. In the case of data re-transmission, the above formula is not used for network estimation. The reason is very simple. Because the program is no longer in normal state, the estimated data is meaningless.
 
1.2.RTO Initialization
RTO Initialization is determined by the formula. For example, the initial formula should be 1. In the formula for correction, the initial RTO should be A + 4D.
 
1.3.RTO update
When data is transmitted normally, we will use the above formula to update each data and re-run the timer to ensure the next data is transmitted smoothly. Note that RTO does not use the formula above for re-transmission, but uses an exponential backoff method. For example, when RTO is 1 S and data is re-transmitted, we use the RTO = 2 S timer to re-transmit data. The next time we use 4 S. Until 64 s.
 
. Initialization of the Estimator
Here, the initialization of the SYN estimator seems to be different from that of the transport estimator (I am not sure). In the correction formula, in the case of SYN, A is initialized to 0, and D is initialized to 3 S.
 
When we get the ACK for transmitting the first data, we should initialize it according to the following formula:
 
A = MB + 0.5
D = A/2
1. 5. Update the Estimator
It is similar to the above discussion, that is, under normal circumstances, the above formula is used to calculate, in the case of retransmission, various parameters of the estimator are not updated. The reason is that the estimation is inaccurate.
 
1.6.Karn Algorithm
This is not an algorithm. This should be a strategy. It is about the timing of updating the values of RTO and estimator. 1. 3. and 1. 5. the Update time is the Karn algorithm.
 
1. 7. Timer usage
Two sentences:
 
In one connection, only one measurement timer is used. That is to say, if TCP sends three sets of data consecutively, only one group of data will be measured.
ACK datagram is not measured for a simple reason. ACK responses without ACK can be used to end the timer measurement.
2. retransmission
When timeout occurs, retransmission is required, but even retransmission is implemented, instead of simply sending data.
 
2. 1. Size of data sent during re-transmission
As mentioned above, data cannot only use one window protocol during transmission. We also need a congestion window to control data traffic, this makes the data not all run into the network at once, causing "congestion ". It has also been mentioned that the congestion window initially uses the exponential growth rate to increase its own window until timeout retransmission occurs, and then fine-tune it again. But I didn't mention how to fine-tune it. Congestion avoidance algorithms and slow start thresholds are generated for this.
 
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. Therefore, this standard is called a threshold. Generally, the congestion window is recorded as cwnd, and the slow start threshold is recorded as ssthresh. Next let's take a look at how congestion avoidance and slow startup work together.
 
Algorithm Overview (directly copy from the book)
 
For a given connection, the initial cwnd is a packet segment, and the ssthresh is 65535 bytes.
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.
When congestion occurs (timeout or repeated confirmation is received), ssthresh is set to half of the current window size (cwnd and the receiver advertise the minimum value of the window size, but at least two packet segments ). In addition, if timeout causes congestion, cwnd is set to 1 packet segment (this is a slow start ).
Cwnd is added when new data is confirmed by the other party, but 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. Slow Start continues until we return to the position where congestion occurs (because we recorded half of the window size that caused us trouble in step 2 ), then it is converted to congestion avoidance.
Supplement the above congestion avoidance formula on page P238. This entire process reminds me of the shift by car.
 
2. Fast retransmission and fast recovery Algorithms
This is a repair mechanism provided when data packet loss occurs. Generally, retransmission occurs after timeout, but if the sender receives more than three duplicate ACK packets, it should be aware that the data is lost and needs to be re-transmitted. This mechanism does not need to wait until the retransmission timer overflows, so it is called fast retransmission. After re-transmission, it is called a fast recovery algorithm because it does not take a slow start but congestion avoidance algorithm. The process is as follows:
 
When 3rd duplicate ACK packets are received, set ssthresh to half of the cwnd in the current congestion window. Retransmission of the lost packet segment. Set cwnd to ssthresh plus a 3-fold packet segment size.
Each time you receive another duplicate ACK, cwnd increases the size of one segment and sends one group (if the new cwnd allows sending ).
When the next ACK confirms that the new data arrives, set cwnd to ssthresh (the value set in step 1 ). This ACK should be used to confirm the re-transfer in step 1 within a round-trip time after retransmission. In addition, this ACK should also be used to confirm all intermediate packet segments between the lost group and the 1st duplicate ACK packets received. This step avoids congestion because we will cut the current rate by half when the group is lost.
2.3.will ICMP cause re-transmission?
The answer is: no, TCP will stick to its own timer, but TCP will keep the ICMP error and notify the user.
 
2. 4. Regroup
To improve the efficiency of TCP, when re-transmission is allowed, you only need to transmit packets that contain retransmission data packets, instead of simply re-transmitting the packets that need to be transmitted.

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.