Author: vamei Source: http://www.cnblogs.com/vamei welcome reprint, please also keep this statement. Thank you!
In the TCP protocol, we use connections to record the statuses at both ends of TCP, use numbers and segments to achieve the order of TCP transmission, and use advertised window to match the processing capabilities of the sender and receiver, the reliability of TCP transmission is also achieved through repeated transmission. We only need to package the TCP segment into an IP package and drop it into the network. Relevant modules of the TCP protocol will help us deal with various possible problems (such as sorting, such as TCP segment loss ). The original TCP protocol was composed of the preceding blocks.
However, in the 1980s S, the Network began to become busy. Congestion occurs in many networks ). Congestion is similar to actual congestion. The network is called "information highway ". Many cars (IP packets) are driving in the network and passing through an intersection (router) until they reach their destination. If a router is too busy, some IP packets will be discarded. The UDP protocol does not guarantee the transmission reliability, so the loss is lost. The TCP protocol needs to ensure the transmission reliability. When an IP packet containing a TCP segment is lost, the TCP protocol will repeatedly send the TCP segment. As a result, more "cars" Enter the road, the original busy vrouters become more busy, and more IP packets are lost. This forms a vicious circle. This situation is calledCongestion and crash(Congestion collapse ). To ensure the quality of sending, each sender ignores the status quo in the public domain, which is the main cause of congestion and crash. At that time, up to 90% of the transmission resources on the network could be congested and crashed.
To solve this problem, TCP has been added since 1980s.Congestion Control(Congestion control) function to avoid blocking the appearance of crashes. MultipleAlgorithmProposed and implemented, greatly improving the network traffic conditions. Today, congestion control is still an active area of Internet research.
Public Morality
In reality, when we encounter traffic jams, we may want to build overpasses and elevated lines, or we want a traffic police to guide the traffic. TCP congestion control is implemented throughConstraint yourself. When the TCP sender detects network congestionControlThe speed at which fragments are sent by yourself to ease the network traffic and avoid congestion and crash. In short, the TCP protocol specifies the "Public Morality" that the sender must abide ".
Let's first explain how blocking works.Probe. In TCP resend, We have summarized two methods to predict the loss of TCP Fragments:Ack timeoutAndDuplicate ACK. Once the sender thinksTCP segment lossIs considered to be blocked in the network.
On the other hand, how does the TCP sender ControlTransmission RateWhat about it? TCP controls the transmission rate by controlling the size of the sliding window. In TCP sliding window management, we have seen a window restriction, that isAdvertised window sizeTo achieve TCP traffic control. TCP also maintainsCongestion window sizeTo adjust the size of the sliding window according to the network conditions. The actual sliding window size is the minimum value of these two sliding windows, so that the two restrictions are met simultaneously (Traffic Control and congestion control ).
Advertised window vs congestion window
We will focus on the congestion window. (Hulk, Smash !)
Congestion window
The congestion window is always in either of the two States. The two statuses are:Slow Start(Slow start)AndCongestion prevention(Congestion avoidance ).
Is conceptual. The actual implementation is more complex, and different versions are available based on different algorithms.CwndCongestion window size. We use the number of segments as the unit to indicate the size of the cwnd (also conceptual ).
The congestion window starts from the slow start state. Slow Start is characterized by a low initial rate but a doubling of the speed. Each time you enter the slow start state, cwnd needs to be reset to the initial value 1. Each time the sender receives a correct ACK, the congestion window is increased by 1 to achieve the speedMultiply(Due to accumulated ACK, the rate growth may be less than doubled).
When the size of the congestion window reaches a threshold value of ssthresh, the congestion enters the congestion avoidance state. The sending rate will continue to grow. After the sender successfully transmits all the fragments in each window, increase the size of the window by 1 (in fact, increase the size of each RTT by 1 ). Therefore, in congestion avoidance, cwndLinear growth, Slow growth rate.
If a segment is lost under congestion avoidance, return to the slow start state and update ssthresh to half of cwnd.
We can see that sshthresh is the switching point from slow start to congestion avoidance. The loss of fragments is the switching point from congestion avoidance to slow start. The sshthresh value is generally large at the beginning, so the slow start may lose the segment before switching to congestion avoidance. In this case, slow start starts again, And ssthresh is updated to half of cwnd.
In general, the sending rate is always increasing. If the segment is lost, the Reset rate is 1 and it increases rapidly. To a certain extent, it enters chronic growth. Sshthred is updated with network conditions (when fragments are lost. Through the above mechanism, the transmission rate is dynamically balanced and more values are continuously attempted. Initial Growth blocks, but slow growth when approaching saturation. However, if you try too much, You can reset it quickly to avoid network burden.
Summary
Blocking control effectively improves the Internet utilization. Blocking control algorithms are diverse and incomplete. A common problem is that cwnd grows linearly when it approaches saturation, so it is not sensitive to new network bandwidth.
The Internet uses "Public Morality" to achieve efficiency. Public Morality and efficiency seem to coexist.
So far, the introduction of the TCP protocol has come to an end. We can recall several major TCP modules: segmentation and stream, sliding windows, connections, traffic control, re-transmission, and congestion control.
Welcome to the "protocol Forest" Series