1 Congestion concept

Here I quote the concept above baidu Encyclopedia:

Congestion means that too many packets arrive in a certain part of the subnet. As a result, the network or even the whole network performance deteriorates. In severe cases, the network communication services stop, that is, deadlock. This phenomenon as often seen in road network traffic congestion, when the holiday is a massive increase in road network in the car, the various kinds of interference between the direction of the traffic, to make every car time relative to the destination increase increase (delay), and sometimes in a certain period of highway vehicles due to the congestion cannot start (i.e., local deadlocks occur).

The well-known TCP module also has an important task, which is to improve the network utilization, reduce the packet loss rate, and ensure the fairness of network resources for each data flow. This is called congestion control, and before I talk about congestion control, I have to mention TCP’s flow control, sliding Windows.

2. Flow control: sliding window

In general, we want to send data quickly and in large quantities. But this way, the receiver can not receive in time. So flow control.

The sliding window mechanism is as simple as setting the size of the sliding window to determine the amount of data sent at a time.

For example, our current sliding window size is 6, so this will mean that the host can send up to 6 data segments at a time.

The first six data segments are sent for the first time and must wait for host B’s confirmation after sending.

If the added host receives only segments 1, 2 and 5, host A receives segment 3 of the acknowledgement packet from host B for acknowledgment, and only segments 1 and 2 are acknowledged. At this point, the sliding window of the sending host slides two segments to the right to add 7 and 8 to enter the second sending.

We assume that the current 6 segments are sent normally and received normally. Then, when receiving, remember that there are segments (*** = 9) in the packet sent back for confirmation, that is, the first 9 segments are accepted successfully. At this point, the slide window slides 6 segments to the right to enter the next send.

The above three steps are a very specific overview of the sliding window mechanism.

After understanding the sliding window, we can have a deeper understanding of congestion control, because the sliding window determines the size of the data sent, and congestion control is mainly based on the sliding window.

3 Congestion control

First of all, a few abbreviations, in the following articles can be contrasted:

CWND: Congestion window

SMSS: indicates the maximum length of a TCP packet segment (only the data segment).

Ssthresh: indicates the slow start threshold, which is equivalent to a threshold.

RTT: round trip time (from the time when the sender sends the data to the time when the sender receives the acknowledgement from the receiver (the receiver sends the acknowledgement immediately after receiving the data, excluding the data transmission time).

Slow start and congestion are avoided together, and fast retransmission and fast recovery are used together.

3.1 slow start

The mechanism of slow start is as follows: Add a window for TCP transmission: congestion Window, known as CWND. When a TCP connection is established, the size of CWND is initialized to the size of one maximum segment. Each time the sender receives an ACK acknowledgement, it increases the size of the CWND by a segment (note: a segment can contain more than one message).

Add rules as follows:

cwnd += min(N,SMSS)

N indicates the number of bytes confirmed last time sent.

If the initial size of the CWND is 1, then the size becomes 2 after one send and 4 after two send.

CWND is equivalent to the sender’s flow control.

The receiver also has a window called the notification window, which acts as the receiver’s flow control.

The size of the data sent by the sender is the minimum of the sender’s congestion window and the receiver’s notification window. Set the size of the sender sliding window to the minimum size of the congestion control window and the notification window.

The reason for the slow start is that TCP doesn’t know what the network actually is at first, and needs to increase the size of CWND smoothly in a tentative way. The slow start algorithm increases the congestion window, which can reflect the whole situation of the network, while the sliding window can only reflect the individual situation of the host.

As you can see from the CWND increment rule above, the size of the CWND increases exponentially in slow start, so slow start is not slow. If not controlled, slow start will eventually lead to network congestion. To prevent this from happening, TCP adds a variable ssthresh to congestion control. The size of the CWND should follow the following rules:

When CWND < SSthRESH: Performs the slow start algorithm

When CWND > SSTHRESH: Performs the congestion avoidance algorithm

When CWND == SSthRESH: : Both are available

3.2 Congestion avoidance

Congestion avoidance is to allow THE CWND to grow slowly and increase the size of the CWND by 1 in an RTT time, that is, to increase the initial size of the CWND. In this way, the size of the CWND has gone from growing exponentially to growing linearly.

Provisions when passed:

Regardless of slow start or congestion avoidance, as long as the network is blocked, the value of SSthRESH and new is half of CWND, but not less than 2. Set the size of CWND to 1, which is the initial size of CWND.

3.3 Fast retransmission

When TCP segments are lost or the receiving end receives TCP segments out of order, the sending end receives repeated acknowledgement segments.

When the sender receives three consecutive end segments of the acknowledgement packet, TCP considers that congestion occurs. The lost segment is immediately retransmitted.

This is the mechanism for fast retransmission.

3.4 Quick Recovery

The quick recovery mechanism is used together with the fast retransmission mechanism. The quick recovery mechanism is as follows:

When the sender receives the third repeated acknowledgement packet, it updates the VALUE of SSthRESH and immediately retransmits the lost packet segment and sets CWND = SSThRESH +3*SMSS to enter the congestion avoidance phase. When a duplicate acknowledgement packet is received, set CWND to CWND +SMSS. In this case, the sender can send new TCP packets (if the new CWND allows). When receiving acknowledgement of new data, set CWND = SSthRESH. Enter the congestion avoidance phase. New data here represents new packets, not lost packets.

In the old TCP congestion control algorithm, the fast retransmission will enter the slow start phase, while the new TCP congestion control algorithm enters the fast recovery phase after the fast retransmission.