--TCP computer network congestion control (ultra-detailed)

I. Introduction

  This blog Laijiangjiang TCPcongestion control mechanism, which is TCPa part of the complex, with its TCPmany elements have relevance, but the content here is not possible to say it again, so the following description will be built on the reader TCPmechanism have a certain understanding of the basis. This part is really a bit complicated, I try to involve at least TCPunder conditions other content will be described it clearly.


Second, the text

 2.1 What is congestion control

  We all know that complex network, in this complex network, there is little two hosts are directly connected. Nevertheless, we can still communicate with other hosts through the network, which is why? Because we send to the data network, when it reaches a node in the network (assuming a router), it contains the address of the data, forward the data to help us closer to the router from the destination, or forwarded directly to the destination ground. However, these routers can not directly forward, they need to first received data into its own memory (may need to do some processing), and then removed from forwarding.

  Here is facing a problem: the router's memory is limited, and if too much time to reach the same data a router, the router will not receive all of the data, only a portion of the discarded; or the same router too much data, reach behind the data will have to wait a long time before being forwarded . Too much data network, leading to a router or treatment process, but to be too slow, this is network congestion . For if TCPthere is a retransmission protocol such transmission mechanism, data loss occurs when data retransmission data arrival time will be extended; while retransmitting a high frequency, will also lead to network congestion, not reduced. Congestion control, when congestion is occurring in the network, reducing the speed of transmitting data to the network, to prevent a vicious cycle; when the network is idle at the same time, increase the speed of transmission data, to maximize the use of network resources . That's easy to spot, and traffic jams on almost so wide road to the car more naturally off slow, so when necessary to limit numbers.


 2.2 Congestion Control Method

  In theory, congestion control implemented in two ways:

  • End congestion control : In this congestion control method, the end system's own transmission data to determine whether congestion, then adjust the transmission rate. For example, the transmitted data has expired still not received confirmation packet data round-trip delay is too high, received repeated confirmation of the same data segment ...... can be considered to be network congestion phenomenon; if sent this phenomenon of the detector, it should reduce the rate of transmission data, if not, it is possible to slowly increase the rate;
  • Network-assisted congestion control : by the routers in the network to tell the sender, the congestion situation of the network. There are two general ways: (1) The router sends a direct message to the sender to inform network congestion; (2) change a router flag in the data segment, to prompt the congestion in the network, then the data will carry this flag to the destination host, and then based on this flag, the transmitting end transmits the packets to the destination host by the informing congestion (contained in the confirmation message);


 2.3 TCP congestion control method

  Because the network layer congestion feedback information is not provided, the TCP protocol is used in the first embodiment - is determined own network congestion . When the TCPdetected network congestion, the transmission rate of the data is reduced, or increase the transmission rate of the data. Here we will face three problems:

  1. TCPHow to limit the rate of data transmission;
  2. TCPHow to detect whether the network congestion;
  3. TCPWhat is the use of algorithms to adjust the rate (when to adjust how much adjustment);

  First, let's answer the first question. Learn TCPshould know TCPnot to transmit a data segment, the acknowledgment is received before sending another data segment, it uses a pipelined manner. TCPEach segment has a serial number, and TCPmaintains a send window to send the data, this window is a range . Serial numbers of all the data segments are located in this window are sent only once, instead of previously transmitted data segment needs to wait to be acknowledged. And when the first data segment is sent out confirmation window will move forward until it moves to the first serial number has not been confirmed, this time there will be new data segment number is included in the window, and then sent out. So the best way to limit the data transmission rate is limited by the size of the window . In the sender TCPwill track and maintain a program called the congestion window variables used for congestion control. Congestion window is called cwnd. At the TCPtransmitting end, all sent but not yet acknowledged data segments received this window must fall, all, network congestion, TCP program will be reduced cwnd, and smooth network, increased cwnd, in order to control the transmission of data rate.

  Then to answer the second question. TCPProgram to speculate whether the network is congested, such as data sent by a number of phenomena:

  • If after sending a data segment successfully received the acknowledgment message recipient, it is considered that the network is not congested;

  • If after sending out a data segment, no acknowledge packet is received within the specified time (delay or lost too much), it can be considered the emergence of network congestion;
  • If the continuous receive confirmation of the recipient with a message three times, it can be speculated that the piece of packet loss that occurred congestion;

  The third case above, with TCPa fast retransmission mechanisms, I do not explain in detail here, just tell us roughly. TCP data can not be guaranteed in order to reach the receiving end, so that the situation after the serial data reported by hand before arrival may occur. The TCPrecipient to which a message is not received, which of the acknowledgment message is sent to the sender, it should receive the current transmitted through the minimum number of packets acknowledged. for example:

  1. The sender simultaneously transmits a 1,2,3,4,5packet sequence number of five, the number is assumed that the recipient received 1the message, then the sender will send an acknowledgment number of 2acknowledgment packets (the TCPsender by the recipient to determine the acknowledgment number received message), tell the sender that I received 2the message before, and the next message I want 2;
  2. The recipient received 2after the number of the packet, send a confirmation number 3, I tell the sender receives the 3all messages before;
  3. This time because of the uncertainty of the network, in 3front does not reach the number, 4number of the packet first arrived, after the recipient receives, put it in the cache, and still return a confirmation number 3, which means it needs is No. 3 packets;
  4. However, after the arrival of yet 5, so it will be 5placed in the cache, and still return 3;
  5. Until 3the arrival of the delay, and this time the recipient receives 3, there is also found in the cache 4和5, then reply the sender confirmation number 6, he said he has received 6all the packets before, the next required 6;

  Here, the sender receives a total number of the three acknowledgment 3ACK packet (acknowledgment number of 3Is the 2acknowledgment number of the packet), the first normal, two redundant back. The so-called fast retransmit that means: If the sender receives a message on the same three redundancy confirmation (that is, four confirmed), they think this message has lost the next, so regardless of whether the timer is timed out , directly retransmit the next packets . The above example, the 2number of redundant packets are confirmed twice, the conditions do not constitute a fast retransmission. And why is three times, in fact, the probability and the length of time the trade-off.

  Back to the topic below, when the conditions are fast retransmit occurs, the sender would think there was congestion and packet loss. All the final analysis, TCP congestion judgment way is there to detect packet loss . So we can answer the third question, TCPhow to adjust the transmission rate - in the absence of loss slowly increase the size of the congestion window cwnd, when the loss event occurs, reducing the size of cwnd . Of course, the specific algorithm is much more complex, TCPthe main algorithm adjusts the congestion window has a slow start , congestion avoidance and fast recovery , in which the first two are TCPregulatory requirements that must be achieved, while the third recommendation is implemented, TCPin accordance with the situation switching between the three. Here I introduced one by one.


 2.4 Slow Start

  Prior to explain, first of all you have to know some of the terminology:

  • The MSS : maximum segment length, TCPfor packets sent from both sections, the maximum number of bytes contained in the data portion;
  • CWnd : congestion window, TCPsent but not yet acknowledged packets in the sequence number range;
  • The RTT : round trip time, the sender transmits a packet, packet receiving time to the acknowledgment packets experienced;
  • ssthresh : slow start threshold, a slow start phase, if cwndthe size reaches this value, converted into congestion avoidance mode;

  Slow start is to establish TCPthe connection, the first adjust the transmission rate of the algorithm (or call mode). At this stage, cwndusually it is initialized 1MSS, the value is relatively small, at this time, the network has enough surplus in general, and the purpose is to find the upper limit of the slow start as soon as possible . In the slow start phase, each sender receives a message, it will confirm the cwndincrease in 1MSSsize, then:

  • Initial cwnd=1MSS, so it can send a TCPmaximum segment, successfully confirmed, cwnd = 2MSS;
  • At this time, two may be transmitted TCPmaximum segment, the received successfully cwnd = 4 MSS;
  • At this point we can send four TCPafter the maximum segment, successfully received, cwnd = 8 MSS......

  Since TCP packets to be disposable within the window issued, so all packets and arrival acknowledgment time RTT is approximately equal to a (remember this conclusion, the later are based on this conclusion RTT) . So at this stage, the congestion window cwndlength will each RTTafter doubled, that is, the transmission rate will increase exponentially (so do not be misled by the name slow start). That change it when this process, which is divided into several situations:

  • The first: If the slow start process, the data transmission timeout occurs, then this time TCPthe ssthreshset value cwnd / 2, and then cwndreset 1MSS, to start the slow start, the process can be understood as tentative limit;
  • The second: tentative first step out of the upper limit ssthreshwill be used here. If cwndthe value increases >= ssthresh, the continued use of slow start this time doubling the growth may be somewhat reckless, so this time the end of the slow start, congestion avoidance mode changed;
  • Third: If the sender receives three redundant confirm a message (that is, the conditions for rapid triggering retransmission), then enter the fast recovery phase; the same time ssthresh = cwnd / 2, after all, happen fast retransmission can also be considered to be congested due to packet loss, then cwnd = ssthresh + 3MSS;

  These are the slow start of the process, let's introduce congestion avoidance.


 2.5 Congestion Avoidance

  Just enter this mode, cwndthe size is approximately equal to half the value of the congestion when the last time (which is determined by the condition of entering this mode), which means that the current cwndis very close to the value of the congestion. Therefore, congestion avoidance is a slow and linear growth rate of the process , in this mode, each going through a RTT(Please note 2.4about the RTTconclusions), cwndan increase in the size 1MSS, that is, assuming that cwndcontains 10a packet size, each receiving to a confirmation message, cwndincrease 1/10 MSS. When the linear growth process is completed, we divided into two cases:

  • The first: In this process, a timeout occurs, the network is congested, this time, ssthreshis modified cwnd / 2, then cwndis set to 1MSS, and enter the slow start-up phase;
  • The second: If the sender receives three redundant confirm a message (that is, the conditions for rapid triggering retransmission), also believes that this time congestion occurs, then, ssthreshis modified cwnd / 2, and cwndis set to ssthresh + 3MSS, and enter Quick recovery mode;

  We can see that the slow start and congestion avoidance Upon receipt of the three redundant confirmation message, treatment is the same: to determine the occurrence of congestion, and reduce ssthreshthe size, but cwndthe size was not necessarily reduce the number of this is puzzling. Personally, I think so, although the sender by receiving three redundant confirmation message, determine the possible presence of congestion, but since you can receive redundant confirmation message indicating congestion will not be too serious, or even no longer congested, so cwndthe decrease is not so intense.


 Quick Recovery 2.6

  Fast recovery and the above two modes are not the same, this model is not mandatory to achieve in the TCP specification, only a recommended mode to achieve. In the confirmation message fast recovery phase, each received a redundancy, cwndincreased 1MSS, remaining unchanged, and when two things happens, will exit quick recovery mode:

  • The first: in the fast recovery process, the timer times out, this time, ssthreshis modified cwnd / 2, then cwndis set to 1MSS, and enter the slow start-up phase;
  • The second: If the sender receives an acknowledgment message of the new (not redundant acknowledgment), then cwndis set ssthresh, and then enters the congestion avoidance mode;

  There is a question, conditions for entering this mode is received three times redundant acknowledgment packet, determine packet loss, then why again received confirmation packet redundancy, cwndor to increase it? I searched online blog, only to find an argument in a blog post, I think it was a grain of truth: this time receive a confirmation message redundant again, indicating that the message sent by the sender but also leave a network We arrived at the receiving end (though not currently receiving end of a want), indicating that the network make room for a single message, so the sender again allow the network to send a message. However, due to the current minimum number of packets lost, resulting in congestion window cwndcan not be moved forward, so he had to be cwndincreased 1MSS, so the sender and can send a data segment, improve the utilization of the network.


 2.7 three modes conversion state of FIG.

  Here are three modes mutually converting a state diagram, the arrow is on the way of conversion conditions, conditions two parts, the top horizontal line is an event caused by the above conversion, while the bottom is the operation in the transition.


Third, the summary

  Congestion control should be TCPin a relatively complex part, and not so easy to understand. Before writing this blog, for the above mentioned three models, I only know the specific process, there are a lot of places do not know why. However, when writing this blog, repeated reading books, reading process to find a blog for me to slowly understand their intentions. This is the reason I wrote the blog, by retelling, to deepen their own understanding, but also hope that this blog help people to see.


Fourth, the reference

Guess you like

Origin www.cnblogs.com/tuyang1129/p/12439862.html