Transport layer: TCP sliding window

Generally speaking, we always want data to be transferred faster. But if the sender sends faster, the receiver may not have time to receive it, which will cause data loss. The so-called flow control is to prevent the sender from sending too fast, so that the receiver can receive it in time.
The sliding window is used to implement flow control. You can see the following example of sliding window flow control:

Insert image description here
In the above figure, A serves as the sender and B serves as the receiver. When A sends three datagrams (the third datagram is lost), each datagram is 100 bytes in length, and B does After the first flow control, the size of the receiving window through the returned rwnd (receiver window) is 300 bytes, which tells the sender that it can send another 300 bytes. Since the data of 201-300 bytes is temporarily Not received, so ack=201, that is, the starting byte sequence number expected to be received next is 201, until 500. And the ACK is set to 1, indicating that the receipt is confirmed. At this time, the confirmation number field ack only has significance.
In the same way, there are two flow controls later. Every time the receiver sends a datagram to the receiver, there will be three key fields of information. One is to confirm the ACK, and to set the The confirmation number field is only valid when it is 1. The second is the confirmation number field ack, which indicates the starting byte sequence number of the next datagram expected to be received. The third rwnd indicates the range of data segment bytes that the receiver can still send.

Consider a special case: If the receiver sends a datagram with rwnd=0 to the sender (perhaps because there is no buffer space to receive it yet), but then there is extra buffer space, and it wants to receive more data from Sender's data. Then B sends a datagram with rwnd=400 to A, but this datagram happens to be lost during the transmission process. At this time, A is waiting for B's non-zero window notification, and B is waiting for the data sent by A. In this case, they are waiting for each other. A deadlock situation formed.
The solution is: TCP has a continuous timer for each connection. As long as A receives the zero window notification, the continuous timer is started. When the time expires, A will send a zero window detection message segment to B, and B can send a window value to A. If it is still 0, then reset the continuous timer. If If it is not 0, the deadlock situation is broken and A can send data.
My understanding: Because a TCP connection is established, data must be sent most of the time, otherwise the connection can be closed, so even if sometimes the receiver sets the receiving window to 0, then Many times it is because the cache is not too crowded, so the sender has reason to believe that it will be able to send information after a while, because as in the above situation, the message intended for the sender to send data may be lost.

Reference book: "Computer Network (Seventh Edition)" by Xie Xiren

Guess you like

Origin blog.csdn.net/qq_43847153/article/details/126810363