In-depth understanding of TCP traffic control

This article is participating in the “Network protocol must know must know” essay contest

TCP flow control

In network communication, due to the uncontrollable sending/receiving efficiency of both parties (refers to the probability of the network speed and memory write speed being unequal), if the sender keeps sending files but the receiver has no space to store them, the receiver will directly discard the contents. Imagine trying to download 1GB of content on a 10-megabyte hard drive, which would cause a lot of data packets to be discarded in the process. Therefore, before data transmission, the receiver should inform the sender of the maximum storage space in advance, control the sender’s transmission rate, and control the transmission efficiency within the receiver’s controllable range. The transmission efficiency control for the sender is called flow control.

Flow control concept

Before introducing flow control, we need to introduce several flow control concepts, which are easy to understand and can be better substituted into specific cases.

  • Sliding window Sliding window is divided into two parts: send window and receive window (RWND); Represents the data flow of sender and receiver respectively. A sliding window stores the data contents of a data request.

  • Data status changes dynamically in the transmission process, so the data in the sliding window will also be divided into:

    1. Received content
    2. Transferring content
    3. Content awaiting transmission
    4. Content that exceeds the maximum value of the receiver (this part of the content must wait for the receiver to receive the sent data from the cache, wait for the application to process, and release space before continuing to send.)

The essence of TCP is that the sender puts data into its cache and sends it to the receiver’s cache in the form of packets. The receiver stores and processes the packets after receiving them. What traffic control does is that when the receiver’s cache is full, the sender should stop sending data to prevent the risk that too much data will not be received and will eventually be discarded. Therefore, when the receiver requests data, it informs the sender of the remaining space of its cache in advance, and the sender calculates the remaining space of the receiver after sending data each time. When the remaining space is 0, it can stop sending and enter the waiting state. After waiting for the receiver to reconnect and bring the latest remaining control value, it can calculate again according to the window value and send the unfinished content.

Special cases in flow control

In flow control, it is generally the case that the memory occupation of the sending window of the sender is synchronized with the receiving window of the receiver and the window size is updated, but there are also extreme cases.

  • TCP Window Full During packet capture using the Wireshark, when the sent data of the sender is equal to the remaining space of the cache of the receiver, the last sent data is marked as Window Full, indicating that the remaining space of the receiver has reached the limit. Wait for the recipient to process, and update the remaining cache space before continuing storage. However, if the receiver is always busy or the packet is lost in transmission, the sender may have to wait forever, so in order to avoid a long wait, TCP designed a Zero Window(0 Window detection) function.

  • The specific logic of the TCP Zero Window function is that after the sender triggers the maximum storage space of the receiver, in order to improve transmission efficiency, It will send len=0,win=0,Seq= receiver ACK-1 at intervals (last sending time *2), and send probe packets at most 16 times to remind the receiver of feedback and remind the receiver to send packets to update its latest remaining cache space.

The above is the whole content of TCP flow control, personal understanding, if there is an error or deviation, also hope we point out the axes, thank you for taking the time to read here.