In a TCP connection, it is assumed that the sender sends multiple segments of the packet to the network at the outset until the window size advertised by the receiver is reached. This is possible when both the sender and the receiver are in the same area network segment. However, if there are multiple routers and slow links between the sender and the receiver, problems may occur.
Some intermediate routers must cache packets and potentially run out of memory space.
Now, TCP needs to support an algorithm called slow start. The algorithm works by observing that the rate at which the new packet enters the network should be the same as the rate at which the other end returns confirmation.
The slow start of TCP for the sender adds another window: the Congestion window (congestion windows), which is remembered as CWnd. When a TCP connection is established with the host of another network, the congestion window is initialized to 1 segments (that is, the packet size advertised at the other end). Each time an ACK is received, the Congestion window adds a segment of the message (CWnd in bytes, but the slow-start algorithm increases in the packet size). the sender takes the congestion window with the minimum value in the notification window as the sending upper limit. The Congestion window is the traffic control used by the sender, and the advertisement window is the traffic control used by the receiver.
The sender begins by sending a segment of the message, and then waits for an ACK. When the ACK is received, the congestion window increases from 1 to 2, which means that two segments of the message can be sent. When the ACK of these two segments is received, the congestion window is increased to 4. This is an exponential increase relationship.
Congestion avoidance algorithm ( main processing timeout problem):
The slow-start algorithm is the way to initiate data flow on a connection, but sometimes we reach the limit of the intermediate routers, where the groupings are lost. Congestion Avoidance algorithm is a method for processing lost packets.
The algorithm assumes that the loss due to packet corruption is very small, so packet loss means that there is a congestion on a network somewhere between the source and destination hosts. There are two types of packet loss indications: A timeout occurred and a duplicate acknowledgment was received.
The congestion avoidance algorithm and the slow start algorithm are two different and independent algorithms. But when congestion occurs, we want to reduce the rate at which packets go into the network so we can call slow start to do this. In practice, these two algorithms are usually implemented together.
The congestion avoidance algorithm and the slow-start algorithm require two variables to be maintained for each connection: a congested window CWnd and a slow-start threshold Ssthresh. The working process of the algorithm obtained is as follows:
1) for a given connection, initialize CWnd as a message segment ,ssthresh to 65,535 bytes.
2) The output of the TCP output routine cannot exceed the size of the CWnd and receiver advertisement Windows. congestion avoidance is the traffic control used by the sender, and the notification window is the traffic control performed by the receiver. The former is an estimate of the network congestion perceived by relaxation, while the latter is related to the cache size available to the receiver on the link.
3) When congestion occurs ( timeout ), Ssthresh is set to half the current window size (CWnd and receiver advertise the minimum value of the window size, but at least two segment). In addition, if the timeout causes congestion, the CWnd is set to 1 segments of the message. the time-out message is then re-sent.
4) When the new data is confirmed by the other party, it increases the CWnd, but the increased method depends on whether we are doing slow start or congestion avoidance. If CWnd is less than or equal to Ssthresh, a slow start is in progress, or congestion avoidance is in progress. The slow start continues until we return to half the position where the congestion occurred (because we recorded half the size of the window that gave us trouble in step 3), and then we switched to congestion avoidance.
The slow start algorithm initially sets the CWnd to 1 segments, and then adds 1 for each additional acknowledgment. This causes the window to grow exponentially: Send 1 message segments, then 2, then 4 ...
The congestion avoidance algorithm requires that CWnd be incremented 1/cwnd each time a confirmation is received (the CWnd records bytes rather than the number of packets). This is an additive increase compared to the exponential increase of the slow start. We want to add up to CWnd a segment (no matter how many ACK is received in this RTT) within a round trip time, and the slow start will increase CWnd based on the number of acknowledgments received in this round trip time.
Fast retransmission and fast recovery (mainly dealing with message segment disorder issues):
We know that when an out-of-sequence message segment is received, TCP immediately needs to generate an ACK (a duplicate ACK). This repeated ACK should not be delayed. The purpose of this duplicate ACK is to let the other party know that a sequence of messages is received, and tell the other person what serial number they wish to receive.
Since we do not know whether a duplicate ACK was caused by a missing segment or because only a few segments of the message were reordered, we waited for a small number of duplicate ACK arrivals. If this is just a reordering of some segments, it is possible to generate a duplicate ACK only if the reordered message segment is processed and a new ACK is generated. if a series of 3 or more than 3 duplicate ACK is received, it is very likely a missing segment of the message. We then retransmit the missing data segment without waiting for the timeout timer to overflow. This is the fast retransmission algorithm.
In this case, the reason for not performing a slow start is because receiving duplicate ACK not only tells us that a packet is missing. Because the receiver generates a duplicate ACK only when it receives another segment of the message, the segment has left the network and entered the receiver's cache. That is, there is still data flowing between the two ends of the transceiver, and we do not want to perform a slow start to suddenly reduce the flow of data.
This algorithm is usually implemented as follows:
1) When a 3rd duplicate ACK is received, the Ssthresh is set to half the current size of the congested window in CWnd. Re-transmit the missing message segment. Set CWnd to Ssthresh plus 3 times times the size of the message segment.
2) Each time an ACK is received from another reply, CWnd adds a segment size and sends a packet (if the new CWnd allows sending)
3) The next time a ACK arrives confirming the new data, set CWnd to Ssthresh (set this value in the first step). This ACK should be an acknowledgment of the retransmission in step 1 after a return time after the retransmission. In addition, this ACK is also due to the acknowledgment of all intermediate message segments between the missing packet and the 1th duplicate ACK received. This step uses congestion avoidance, so we halve the current rate when the packet is lost.
Resources:
1. "TCP/IP Detailed volume-Volume 1 Agreement" mechanical Industry Press
"TCP" Timeout and retransmission