“This is the 14th day of my participation in the First Challenge 2022. For details: First Challenge 2022.”

As a transport layer protocol, TCP’s core capability is transmission. Transmission needs to ensure reliability and control flow rate, both of which are provided by sliding Windows.

1. Request/response model

Every request sent in TCP requires a response. If a request does not receive a response, the sender will assume that there was a failure in the send and will trigger a resend.

As shown below: After each request receives a response, the next request is sent, and throughput is very low. Because such design, will produce network idle time, waste bandwidth. Bandwidth is not full, which means more requests can be sent and more responses received at the same time.Improved: let the sender send a request instead of waiting for a response. In this way, the sent data is linked together, and the response data is linked together, increasing throughput. But what if there’s a lot of data that can be sent simultaneously? For example, if hundreds or thousands of TCP segments need to be sent, bandwidth may be insufficient.

2. Queuing

Implement a queue at the TCP layer. The new element is queued from one end of the queue (left) as an unsent data packet. Start sending data packets, leaving the right side of the queue.

The problem: Multiple queues are required to do this, and unsent data is fetched from the queue and added to the sending queue. Then send the data, received ACK part out, into the received queue. When a packet is being sent, it is uncertain when it will receive an ACK, so using queues seems to be problematic.

3. Sliding Window

  • Dark green represents segments that have received an ACK
  • Light green represents segments that sent but did not receive an ACK
  • White represents segments that were not sent
  • Purple represents segments that cannot be sent for the time being

Suppose we send a maximum of five packets at the same time, i.e. the window size = 5. The data in the window is sent simultaneously and then waits for ACK. If a packet ACK arrives, we mark it as received (dark green).

As shown in the figure below, there are two packets of ACKS arriving, so they are marked green.At this time, the slide window can slide to the right, as shown below:

4, the retransmission

If some data fails to receive ACK during transmission, retransmission may occur.

If the following scenario occurs, segment 4 does not receive an ACK.

At this time, the sliding window can only move one position right, as shown below:

During this process, if segment 4 is retransmitted successfully (receiving an ACK), the window continues to move right. If segment 4 fails to send and still does not receive an ACK, the receiver will discard segments 5, 6, and 7 as well. In this case, all data from segment 4 onwards will need to be retransmitted.

5. Fast retransmission

In TCP, if the receiver wants to discard a certain segment, it can choose not to send an ACK. If the sender times out, the TCP segment is resend. In other cases, the receiver wants to urge the sender to resend a TCP segment as soon as possible. This is when the fast retransmission capability can be used.

For example, segments 1, 2, and 4 arrive, but segment 3 does not. The recipient can send multiple ACKS of segment 3. If the sender receives multiple ACKS for segment 3, it resends segment 3. This mechanism is called fast retransmission. This is not the same as timeout retransmission; it is a rush mechanism.

In order not to make the sender think that segment 3 has been received, in the case of fast retransmission, the receiver will still send an ACK for segment 3 (no ACK for segment 4) even after receiving segment 4 until the sender retransmits segment 3.

In practice, the size of each TCP segment is different, and limiting the number makes the buffer on the receiving end harder to work with, so in practice the window size is in bytes.

6. Flow rate control

The size of the sending and receiving Windows can be used to control the TCP flow rate. The larger the window, the more data can be sent and received at the same time, and the greater the throughput supported. Of course, the larger the window, the greater the loss if data errors occur, because more data needs to be retransmitted.

In practice, you can’t really run out of bandwidth, so we end up using a compromise between latency, packet loss rate, and throughput, because you can’t have your cake and eat it.

7,

To improve the transmission rate, TCP sends multiple segments at the same time. To prevent the segments from being rejected by the receiver, both parties need to negotiate the transmission rate before sending the packets. But it’s impossible to be absolutely certain about the speed of the network, so the negotiation becomes about the size of the window.

8, subject

What about sliding Windows and flow control?

Sliding window is the core of TCP protocol control reliability. The sender unpacks the data into multiple packets. The data is then placed into an array with a sliding window and sent sequentially, still in a first-in, first-out (FIFO) order, but the subsets in the window are sent at once. If the group with the smallest sequence number in the window receives an ACK, the window will slide; If the group with the smallest ordinal number has not received an ACK for a long time, the data resend of the entire window is triggered.