11180 views|0 replies

661

Posts

18

Resources
The OP
 

20-TCP protocol (sliding window - basics) [Copy link]

I believe everyone has encountered such a scenario: Your classmate Luffy calls you and asks you to write down a mobile phone number, but your memory is not very good. You and Luffy agree that you can only report 4 digits at most at a time. Luffy reads it once, and if you hear it, you repeat it. Next: You: You can only report 4 digits at most at a time. I can't remember more than that! Luffy: 139 You: 139 (Luffy knows you heard it) Luffy: 7548 You: 7538 (Obviously you heard it wrong) Luffy: No, it's 7548 You: 7548 Luffy: 2669 You: 2669 Finally, the complete number you received is 139-7548-2669. 1. Sliding Window In the above scenario, you can only receive 4 digits at most at a time, which means that your sliding window size is 4. In the TCP protocol, there is also such a sliding window, and its size indicates how many bytes of data can be received at present. Each time TCP receives a message from the other party, it checks the window size field, as shown in Figure 1. Write a picture description here Figure 1 There is a field in the TCP header - 16-bit window size After knowing the other party's window size, you know how much data the other party can currently receive. The byte number of the received data is the value of ACK in the TCP segment to ACK + window size, that is, [ACK, ACK + window size). For example, you sent a segment to the other party with data with byte number [400, 500). The other party sent back a TCP segment with ack = 500, win = 100, which means that I have received data with byte number [400, 500). I can also receive data with byte number [500, 600), as shown in Figure 2. Write a picture description here Figure 2 Sliding window If the other party sends back a TCP segment with ack = 500, win = 0, it means that I have received data with byte number [400, 500), but I can no longer receive data now. You can send it later. Write a picture description here Figure 3 The other party sends back a window of size 0, and the receiver's reaction 2. The purpose of the sliding window Recall the example of making a phone call at the beginning of this article. Why do you tell the other party that you can only report 4 numbers at most at a time? The reason is that your ability to receive is limited. It does not mean that you cannot remember many numbers, but you cannot remember them in the short term. You need to remember them one by one (put the data into the buffer one by one). Therefore, in TCP, the sliding window is used to achieve flow control. If the other party sends data too fast, the receiver will not have time to receive it (you will not have time to remember it), and the receiver needs to notify the other party to slow down the sending of data (Figure 3). It should be noted that when learning the sliding window, we assume that the network is infinitely good and not congested. As long as you send data, the other party will definitely receive it. Let me explain the meaning of network congestion. It means that the data you send is stuck in the network and has not reached the receiver for a long time. 3. Sliding Window Simulation Write a picture description here Figure 4 Sliding Window Simulation Correction: The last small picture in Figure 4 should be corrected. It should be "The sender receives ack = 41, win = 10, and knows that the other party wants to receive data with sequence number [41, 51)" The sender receives the message ack = 33, win = 10 sent by the other party, and knows that the other party has received data before number 33, and now expects to receive data number [33, 43). The sender sends 4 segments in succession, assuming they are A, B, C, and D, carrying data numbers [33, 35), [35, 36), [36, 38), and [38, 41) respectively. The receiver receives segments A and C, but does not receive segments B and D, that is, it only receives data numbers [33, 35) and [36, 38). The receiver sends back an acknowledgment of segment A: ack = 35, win = 10. The sender received ack = 35, win = 10, and the other party expected to receive data [35, 45). Then it sent a segment E, which carried data [41, 44). The receiver received segments B: [35, 36), D: [38, 41), and the receiver sent a confirmation for D: ack = 41, win = 10. (This is a cumulative confirmation) The sender received ack = 41, win = 10, and the other party expected to receive data [41, 51). ... It should be noted that the order in which the receiver receives TCP messages is uncertain. It is not necessarily that 35 is received first and then 36. It may also be that 36, 37, and then 35 are received. 4. Summarize and understand the working process of the sliding window. What is the purpose of the sliding window?

This post is from Embedded System

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list