TCP-IP: Sliding windows (Sliding window)

Source: Internet
Author: User
Tags ack

Reference book: Tcp-ip guide


Advantages of TCP

From the transmission of data, TCP/UDP and other protocols can complete the transmission of data, from one side to the other, TCP is superior to provide a reliable, flow-controlled data transmission, so it is more complex than other protocols, First look at the meanings of these two modifiers:

1. Reliability, to provide TCP reliability, TCP transmission to ensure that the data can accurately reach the destination, if not, need to be able to detect and resend the data.

2. Data flow control, provide TCP flow control characteristics, manage the rate of sending data, do not exceed the capacity of the device

In order to achieve the above 2 points, TCP realizes a lot of details of the function to ensure data transmission, such as sliding window adaptation system, time-out retransmission mechanism, cumulative ACK, etc., this time first introduce some of the sliding window knowledge points.


Sliding window Introduction

Read some articles when you see a Daniel do video, very good easy to understand the mechanism of sliding window, you can first look at:http://v.youku.com/v_show/id_XNDg1NDUyMDUy.html

IP layer protocol is not a reliable protocol, IP layer is not related to the data sent to the end, TCP through the confirmation mechanism to ensure the reliability of data transmission, in the earlier time using the send--wait--send mode, In fact, this mode is called stop-wait mode, the sending data will start the timer after sending the data, but if the data or ACK is lost, then after the timer expires, the receipt of the ACK will be considered to send the situation, to be re-transmitted. This reduces the efficiency of the communication, as shown in this way known as positive acknowledgment with retransmission (PAR)



Sliding window

Can be assumed, to optimize the disadvantage of low par efficiency, such as I let each packet sent to have an ID, the receiver must be a confirmation of each packet, so that device A to send a few fragments, instead of waiting for the ACK, and the receiving side to tell how much it can receive, so the sending side has a limit, Of course, we also need to ensure that the order, do not disorderly order, for the situation of disorderly order, we can allow to wait for a certain situation of the disorderly order, such as the first cache of data before, and then to wait for the required data, if a certain time did not come drop off, to ensure the order of the!

In the TCP/IP protocol stack, the introduction of sliding windows can solve this problem, first of all, the concept of the data into which classes

1. Sent and acknowledged: These data indicate that the data has been sent successfully and has been confirmed, compared to the first 31 bytes, the location of the data is outside the window, because the window within the lowest order of the confirmation, to remove the window, is actually the window to close, Open receive new sent data at the same time

2. Send but not yet acknowledged: this part of the data is called send but is not confirmed, the data is sent out, did not receive the receiving end of the ACK, think and did not complete the transmission, this belongs to the data in the window.

3. Not sent,recipient ready to receive: This part is sent as soon as possible data, this part of the data has been loaded into the cache, that is, the window, waiting to send, in fact, this window is completely informed by the receiver, the receiver told or can accept these packages, So the sender needs to send these packets as soon as possible.

4. Not sent,recipient does not have ready-to-receive: These data are not sent, and the receiving side is not allowed to send, because the data is beyond the range received by the sending side


For the receiving end there is also a receive window, similar to the sender side, the receiver end of the data has 3 categories, because the receiving side does not need to wait for ACK so it does not have a similar received and confirmed classification, the situation is as follows

1. Received and ACK not sent to Process: This part of the data belongs to the receiving data but has not yet been received by the upper layer of the application, is also cached in the window

2. Received not ACK: has received and, but has not replied to ACK, these packets may be lost in the category of delay ACK

3. Not Received: There is a vacancy and no data has been received.

Send window and available window

For the sender, the window contains two parts, that is, the sending window (has been sent, but did not receive an ACK), the available window, the receiving side is allowed to send but not send the part called the available window.

1. Send window:20 bytes This part of the value is a receiver in the three handshake when the notification, while in the receiving process also constantly advertise the size of the window can be sent to adapt

2. Window already Sent: The data has been sent, but no ACK is received.


Sliding window principle

TCP is not each message segment will reply Ack, may send an ACK to two message segments, may also send 1 ack " cumulative ack" to multiple message segments, for example, the sender has 1/2/3 3 message segments, first sent 2, 32 pieces of message, But the receiver expects to receive 1 pieces of the message, this time 2, 3 message segments can only be placed in the cache waiting for the message 1 hole is filled, if the message 1, has not come, the message 2/3 will be discarded, if the message comes, then send an ACK to the 3 messages to confirm.

Give an example of how the sliding window works:

1. Assuming that the 32~45 data is sent to TCP by the upper application, TCP divides it into four segment to send to the Internet

2. SEG1 32~34 seg3 35~36 seg3 37~41 seg4 42~45 These four fragments, sent out in turn, assuming that the receiving end received SEG1 SEG2 SEG4

3. At this point the behavior of the receiving end is to reply to an ACK packet stating that the 32~36 data has been received, and the SEG4 is cached (guaranteed order, resulting in a save seg3 hole)

4. After the sender receives an ACK, it will send the 32~36 packet from the sent and not confirm the cut to send has confirmed that the window, this time the window to move to the right

5. Assume that the window size advertised by the receiving end is still unchanged, and that the windows move to the right, creating some new slots, which are the categories that are allowed to be sent by the receiving end

6. For lost Seg3, if more than a certain time, TCP will be re-transmitted (retransmission mechanism), retransmission success will seg3 SEG4 a piece is confirmed, unsuccessful, SEG4 will also be discarded

is to repeat the above process, as the window continues to slide, the data stream to the receiving end, the actual receiver window size notice will also change, the receiving end based on this value to determine when and how much data, from the flow of data flow control. The schematic is shown in the following diagram:



sliding window Dynamic adjustment

The main is based on the receiving end of the receiving situation, dynamic to adjust window Size, and then to control the data traffic on the sending side

1. The client constantly sends the data quickly, the server receives relatively slowly, and looks at the results of the experiment

A. Package 175, send ack carry win = 384, tell the client, now only receive 384 bytes

B. Package 176, the client really only sent 384 bytes, Wireshark is also more intelligent, also declared TCP Window full

C. Package 177, the server replies with an ACK, and the notification window is 0, indicating that the receiver has received all the data, and saved to the buffer, but this time the application does not receive this data, resulting in buffer no more space , so the notification window is 0, which is called 0 window , 0 window, sender stops sending data

D. The client detects that the window is 0, and no longer sends the data to the receiving party

E. Package 178, the receiver sends a window notification informing the sender that it has the ability to receive data and can send a packet.

F. Package 179, after receiving the window notification, the data in the buffer is sent.


In summary, it is the receiver can advertise the window size according to their own condition, so as to control the reception of the sending side, flow control


Reference articles

1.http://www.cricode.com/2679.html

2.http://kb.cnblogs.com/page/209100/



TCP-IP: Sliding windows (Sliding window)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.