Blog.csdn.net/yao5hed/art…

An overview of the



Sliding Windows implement TCP flow control. TCP is a duplex protocol. Both sides of a session can receive and send data at the same time. Both sides of a TCP session maintain a send window and a receive window. The size of each receiving window depends on the application, system, and hardware. (The TCP transfer rate cannot be greater than the application’s data processing rate.) The respective send window requirements depend on the receiving window of the peer notification, and the requirements are the same.

Sliding Windows solve the problem of flow control, that is, how to make the two sides reach an agreement if the speed of packet processing is different between the receiver and the sender. The cache at the receiving end transmits data to the application layer, but this process is not necessarily instantaneous. If the sending speed is too fast, the receiver will overflow. Flow control solves this problem.

The concept of window the data in the sending cache of the sender can be divided into four categories: 1. Sent, received ACK 2. Sent, not received ACK 3. Not sent, but allowed to send 4. Not sent, but not allowed to send

Types 2 and 3 belong to the send window.

The cache data of the receiver is classified into three types: 1. Received 2. Not received but ready to receive 3. Not received and not intended to receive

Type 2 belongs to the receive window.

The window size represents how much data the device can process from the peer end at one time before passing it on to the application layer. The data cached to the application layer cannot be out of order, and the window mechanism ensures this. In reality, the application layer may not be able to read data from the cache immediately.

A sliding sending window moves the left edge of the sending window only after receiving an ACK acknowledgement of the bytes in the sending window.

The receive window will only move the left boundary if all previous segments are confirmed. The window does not move and does not acknowledge subsequent bytes when previous bytes are not received. This ensures that the peer end retransmits the data.

Follow the rules of fast retransmission, cumulative confirmation, selection confirmation, etc.

Window size = 8192; The maximum number of bytes sent by the receiver is 8192, which is generally the size of the receiver cache.

Emulated animation Emulated animation features found a emulated TCP window to send the animation address, slightly flawed: 1. If the packet loss rate is set too high, sometimes it will not return to normal no matter how many times it is resent. 2

Clear sender and receiver, send A~S packets, we will not analyze from beginning to end, because the process is relatively long. 2. Set a certain packet loss rate, otherwise there is nothing worth analyzing, including packets sent by sender and ACK packets replied by receiver. 3. Simplify the retransmission mechanism. In case of packet loss, retransmission is performed directly, with no need for three redundant ACKS and timeout. 4. Neither retransmission nor N step back is selected. Retransmitted packets are randomly sent

Analysis of sliding window mechanism: firstly, the sender sends four packets A,B,C and D, but A and B are lost, and only C and D reach the receiver.



The receiver did not receive an ACK packet because it did not receive an ACK packet. The sender retransmits packets A,B,C and D, and all arrived this time.



The receiving end obtains A first and sends ACK packet A, but loses it halfway. After B is obtained, the ACK package of D is sent according to the principle of cumulative confirmation, and then the window slides. After C and D are obtained again, two ACK packets of D are returned. The ACK packet corresponding to C is lost.



The sender receives two ACK packets of D, indicating that the sender has received the four packets. The window slides and sends E,F,G, and H packets. The G packet is lost. Now the status of the whole sequence: ABCD is sent and confirmed, EFGH is sent and unconfirmed, I~S is not sent.



The receiving end receives E first and sends an ACK packet. Send ACK packet of F after receiving F; If G is not received, the ACK package of F is still sent. Received H, or send the ACK package of F? Unfortunately, all three ACK packages are missing.



The sender receives the ACK packet from E, and the window slides one bit to the right. Then it sends F,G,H,I, where F is lost.



The receiver receives an ACK packet from F because there is no G. G and H packets were received successively.



The receiving end sends two I packets consecutively based on accumulative confirmation, and the corresponding H packet is lost. The window slides to the right.



After receiving the ACK packet of I, the sender slides four bits to the right. Send J,K,L,M packets, no further analysis.



From the above process, we can draw the following conclusions:

1. TCP connection is realized through packets and ACK. As a third party, we can see the process of sending packets from both sides.

If the sender does not receive an ACK from the receiver, it cannot swipe right. If the sender sends ABCD to the receiver and slides, as long as the receiver does not receive A, it cannot slide, then the two will be out of sync.

The sliding window improves the channel utilization rate. TCP is sent by packet segment. If we wait for ACK for each packet, the waiting time is too long for large packets. As long as the sent message is in the sliding window, you can swipe right without waiting for each ACK to come back. In this case, AB is empty at the start receiving end, only CD is available. After receiving EF and H, slide 2 places to the right without waiting for G to arrive.

The window size cannot be more than half the ordinal space size. The purpose is to avoid overlapping of the two Windows. For example, if the total size is 7 and the window size is 4, the receiving window should slide 4, but there are only 3 serial numbers, resulting in overlapping of the two Windows.

One thing that doesn’t happen is that the sender sends an ABCD, the recipients all receive it and swipe right, but all ACK packets are lost. The sender does not receive any ACK. After timeout, ABCD will be resend. In this case, the recipient will resend only THE ACK of D after receiving ABCD according to the principle of cumulative acknowledgement.

Comparison sliding window and congestion window Sliding window is to control the received and synchronized data range, notify the sender of the current received data range, for flow control, the receiver used. Congestion window is used to control the sending rate to avoid sending too many packets. Because TCP is full-duplex, there are sliding Windows on both sides. The maintenance of the two Windows is independent. The sliding window is mainly maintained by the cache feedback from the receiver, while the congestion window is mainly determined by the network congestion detected by the congestion control algorithm of the sender.

The congestion window controls the rate at which the sender transfers data to the Connection, making this rate a function of network congestion.

Reference: the sliding window size of a TCP flow control, TCP (on) — those things — — — — — — — — — — — — — — — — — — — the author: SilentAssassin source: CSDN, blog.csdn.net/yao5hed/art… Copyright notice: This article is the blogger’s original article, reprint please attach the blog link!