TCP Sliding Window Mechanism

Source: Internet
Author: User

 

(1). Window Mechanism

The basic principle of the sliding window protocol is that at any time, the sender maintains a continuous sequence number of frames allowed to be sent, which is called the sending window. At the same time, the receiver also maintains a continuous sequence number of frames allowed to receive, which is called the Receiving Window. The serial numbers of the sending and receiving windows do not have to be the same in the upper and lower bounds, or even in different sizes. Different Sliding Window Protocol window sizes are generally different. The serial number in the sender window represents the frames that have been sent but not confirmed, or those that can be sent. The following is an example (assume that the size of the sending window is 2 and the size of the receiving window is 1 ):

 

Analysis: ① In the initial state, the sender does not send frames, and the front and back sides of the sending window overlap. The receiver's 0th window opens, waiting for receiving frames 0; ② the sender opens the 0th window, indicating that 0 frames have been sent but the message is still returned. At this time, the receiving window status remains unchanged; ③ the sender opens the 0 and 1 windows, indicating that frames 0 and 1 are waiting for confirmation. At this point, the number of windows opened by the sender has reached the prescribed limit. before receiving a new confirmation response frame, the sender will suspend sending the new data frame. The receiving window status remains unchanged. ④ the receiver has received frame 0, the window 0 is closed, and the window 1 is opened, indicating that the receiver is ready to receive frame 1. At this time, the sending window status remains unchanged; ⑤ the sender receives the message sent by the receiver for confirmation of frame 0. closing the window 0 indicates deleting frame 0 from the resend. At this time, the status of the Receiving Window remains unchanged; 6. The sender continues to send frame 2. The window opened on Frame 2 indicates that frame 2 is also included in the column to be confirmed. At this point, the window opened by the sender has reached the prescribed limit. before receiving a new confirmation return frame, the sender will suspend sending the new data frame, and the receiving window status will remain unchanged; 7. The receiver has received frame 1, window 1 is closed, and window 2 is opened, indicating that the receiver is ready to receive frame 2. At this time, the sending window status remains unchanged. The sender receives the confirmation message sent from the receiver for the completion of frame 1. closing the window for frame 1 indicates that frames 1 will be deleted from the re-publication. The status of the Receiving Window remains unchanged.

If we look at one-bit sliding window, back n, and re-transmission from the perspective of sliding window, the difference is that the size of the window is different. 1 bit Sliding Window Protocol: sending window = 1, receiving window = 1; backend n Protocol: sending WINDOW> 1, receiving WINDOW> 1; selection of retransmission Protocol: sending WINDOW> 1, receiving Window> 1.

(2). 1 bit Sliding Window Protocol

When the size of the sending and receiving windows is fixed to 1, the sliding window protocol degrades to the stop-and-wait protocol ). This Protocol requires the sender to stop after each frame is sent and wait until the recipient has correctly received the confirmation (acknowledgement) to continue sending the next frame. The receiver must determine whether the received frame is a new frame or a resend frame. Therefore, the sender must add an serial number for each frame. As the stop Protocol stipulates that only one frame can be sent after it is completely successfully sent, it is enough to use only one bit for numbering. The flowchart of the sender and receiver.

 

(3). backend n Protocol

Since the stop Protocol needs to confirm each frame before sending the next frame, the channel utilization is greatly reduced, and the back n protocol is proposed. In the backend n protocol, after sending a data frame, the sender does not stop waiting for the response frame, but sends several data frames consecutively, even if the response frame sent by the receiver is received during the continuous sending process, you can also continue sending. The sender must set a time-out timer for each data frame sent. As long as you still receive the confirmation frame within the specified timeout period, You Need To resend the corresponding data frame. For example, if the sender finds that the previous frame of the N frame does not return the confirmation information after the timer times out after the N frames are sent, the frame is judged to be wrong or lost, at this time, the sender has to resend the error frame and the next N frames.

 

From this point, it is not difficult to see that the back n protocol improves the efficiency by continuously sending data frames, but on the other hand, during re-transmission, you must re-transmit the data frames that have been correctly transmitted (only because there is an error in the data frames before these data frames), which reduces the transmission efficiency. It can be seen that if the transmission quality of the transmission channel is very poor and the error rate is large, the continuous test protocol is not necessarily better than the Stop wait protocol. The size of the sending window in this protocol is K, and the receiving window is still 1.

(4) Select the retransmission Protocol

In the backend n protocol, if the receiver finds an incorrect frame, it will not receive subsequent frames, even if it is the correct frame, which is obviously a waste. Another more efficient method is that when the receiver finds that a frame has an error, the correct frame that is sent later cannot be submitted to the receiver's upper layer immediately, but the receiver can still accept it, it is stored in a buffer and the sender is required to re-transmit the frame with an error. Once the frame is received again, the rest of the frames originally stored in the buffer can be submitted to the upper layer in the correct order. This method is called selectice repeat. Obviously, resend reduces the waste, but requires the receiver to have enough buffer space.

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.