[Reserved] resolution TCP's sliding window (Animation)

Original link: https: //blog.csdn.net/yao5hed/article/details/81046945

The resolution TCP sliding window (Animation)

TCP sliding window flow control is achieved. First clear sliding window category: TCP is duplex protocol, both sides of the conversation can receive and transmit data simultaneously. The two sides have each TCP session maintains a 发送窗口and a 接收窗口. The respective 接收窗口size limit depends on the application, system, hardware (TCP transmission rate is not greater than the data processing rate applications). Each 发送窗口is required depends on the end of the advertisement 接收窗口, the same requirements.

The solution is a sliding window flow control problem, that is, if the receiver and the sender of the packet processing speeds are different, how to make the two sides reach an agreement. Cache data transmission to the receiving end of the application layer, but this process is not necessarily immediate, if the transmission speed is too fast, there will be a reception side data overflow, flow control solution is the problem.

The concept of window

Data in the transmission buffer of the sender can be divided into four categories:
1 has been sent, have been received the ACK
2. sent, does not receive the ACK
3. not transmitted, but allow the transmission
4 is not transmitted, but not send

Wherein the type 2 and 3 belong to the send window.

Recipient buffer data into three categories:
1. Received
2 but does not receive a ready to receive
3 is not received and is not ready to receive

Wherein the type 2 belonging to the receiver window.

Window size from the number represents a data device side processing, then pass, after the application layer. Data buffer passed to the application layer can not be out of order, window mechanism to ensure this. In reality, the application layer may not be immediately read the data from the cache.

Sliding mechanism

  1. Transmitting window only after receiving ACK acknowledgment bytes of transmitting window, which will shift the left edge of the send window.

  2. The receiving window will only move the left margin in the case of all previous segments are identified. In the case where the front of the byte is not received but also the following bytes received, the window does not move, does not confirm the subsequent byte. In order to ensure that these data will end retransmission.

  3. Follow the fast retransmission, cumulative confirmed, select OK and other rules.

  4. Issued sender window size = 8192; that is, the receiving end sends up to 8192 bytes, the sender 8192 is generally the size of the receive buffer.

Analog animation

Analog Features

Found a simulation of the TCP send window address animation , a little flawed: 1. If the packet loss rate is set too high, sometimes no matter how many times retransmission can not return to normal 2. window can be up to 10, in fact, should be 9

Clear transmission and receiving ends, transmits packets A ~ S, we do not start to finish the analysis, because the process is relatively long.
1. simplify the window size, window size has been both 4
2. Set a certain packet loss rate, otherwise nothing worthy of analysis, including packet sender receiver ACK packets sent and reply.
3. Simplified retransmission, the retransmission packet loss occurs directly, and ranging from 3 redundant ACK timeout.
4. Select neither retransmission nor returned to the step N, the retransmission packet is random
hair

Analysis sliding window mechanism

  1. First sending end A, B, C, D four packages, but the A, B is lost, only the C, D arrive at the receiving end.

  2. Receiver does not receive A, the ACK packet not reply. Sending end retransmits A, B, C, D four packets, all the arrived.

  3. To obtain the receiving end A, send an ACK packet A, but lost halfway; B After obtaining, according to the principle of delayed acknowledgment, ACK packet D hair, and then sliding window. After obtaining the C, D again successive reply ACK packet 2 D, wherein C corresponds to an ACK packet loss.

  4. Even received ACK packet sending end 2 D, indicating that the other four packets have been received, sliding window, send E, F, G, H package, wherein G packet loss. Now the state of the entire sequence: ABCD is sent acknowledged, EFGH is sent unacknowledged, I ~ S is not transmitted.

  5. The receiving terminal receives the first E, send an ACK packet; ACK packet after receiving the F F hair; not received G, F, or ACK packet is sent; received H, F or an ACK packet is sent. Unfortunately, all three ACK packet loss.

  6. E sender receives an ACK packet, a sliding window to the right; and then send the F, G, H, I, where F is lost.

  7. The receiving end to obtain I, since no G, F had a reply ACK packet. We have received G, H package.

  8. The delayed acknowledgment receiving end, two bursts of packets I, where H corresponds to the loss. Sliding window to the right.

  9. After transmitting end receives an ACK packet I, four slide rightward. Transmission J, K, L, M four packets, not later analysis.

From the above process, we can get the following conclusions:
1. TCP connection is via ACK packet and implementation, we can see that both the process as a third party contract, but before receiving the recipient does not know the sender sent What is the same, the sender before receiving ACK not know if they successfully received.

  1. The recipient does not receive the sender sends back ACK, it can not slide to the right. Assuming that send to the recipient made ABCD to slide, as long as the other party did not receive the A, it can not slide, then both of sync situation occurs.

  2. Sliding window to improve channel utilization, TCP segments are transmitted in units of packets, each made if one would have to wait the ACK packet, then for large data packets, waiting time is too long. As long as the message transmitted in a sliding window which, without waiting for each ACK can slide back to the right. In the present embodiment, the receiving terminal starts empty AB, only the CD, can not slide at this time; after receiving the EF and H, two right sliding directly, without having to wait G in place.

  3. Window size can not be greater than one half the size of the sequence number space. The purpose is to prevent two overlapping window, such as the total size of 7, the window size are 4, the receiving window should slide 4, but only 3 number, resulting in two overlapping windows.

  4. There is a case of no-show: ABCD sender sent, then the receiver can receive the slide to the right, but the full reply ACK packet lost. The sender does not receive any of the ACK, the retransmission timeout will ABCD, this time by the recipient to confirm the cumulative principle, only after receiving the retransmitted ACK D ABCD, the sender receives the slide rightward.

Comparative sliding window and the congestion window

Sliding window is received and the synchronization control data range, the range of the transmission end notification data received at present, for flow control, receiving end. Congestion window is a transmission rate is controlled to avoid excessive hair, sender uses. Because tcp is full duplex, so that on both sides of the sliding window.
Maintains two independent windows, sliding window feedback mainly by the recipient buffer to maintain the situation, the congestion window main network congestion degree is detected by the algorithm congestion control sender determined.

Sender to the congestion window controls data transmission rate connection, so that this rate is a function of network congestion status.

Reference: TCP flow control, sliding window size
TCP those things (on)

Published 171 original articles · won praise 386 · views 160 000 +

Guess you like

Origin blog.csdn.net/weixin_42837024/article/details/102739256