Table of contents
Timeout retransmission mechanism
2.1 Increase the amount of data sent by itself
The send buffer of the sliding window is a circular queue
Will the size of the sliding window change?
Sliding window packet loss problem
2.2 Acceptance of the other party
2.3 Network Forwarding Capability
3. Strategies when congestion occurs
TCP keep-alive timer (heartbeat packet)
1. Reliable
Confirmation response mechanism: ensure that data arrives at the peer end in a reliable and orderly manner
The principle behind the confirmation response mechanism: It is essentially a confirmation of the serial number. The computer does not know what is sent, it only knows the serial number
reliable:
orderly:
Timeout retransmission mechanism
When the sender starts the timeout retransmission timer, when the time exceeds the "timeout retransmission time" and has not received a confirmation response, the message will be retransmitted
Scenes:
overtime time:
Can it be written as a fixed time? No, it needs to be dynamically changed according to network transmission conditions
RTO = 2RTT
RTO: timeout retransmission time
RTT: message round-trip time (can be calculated according to the time of sending data each time and the time of confirming return)
2. Efficiency
TCP needs to consider the issue of transmission efficiency, which needs to be considered from three aspects
1. The amount of data sent by itself , in other words, the more data you send at one time, the more you transmit
MSS: Determines the online delivery of data for one-time delivery (this cannot be changed)
The confirmation response mechanism determines that every TCP packet needs to be confirmed (this can be broken) - the sliding window mechanism mentioned later
2. The receiving capability of the other party , in other words, the size of the receiving buffer of the other party
3. Network forwarding capability , in other words, is the load on the forwarding device on the network link from host A to host B heavy?
2.1 Increase the amount of data sent by itself
Sliding window mechanism:
Allow window-sized data (without waiting for the confirmation of the last data) to be sent to the network for transmission, improving data throughput
Advantages: without considering the network, the amount of data sent can be increased. Because the more you send, the more you transmit
Disadvantages: It is necessary to guard against data loss and trigger timeout retransmission. Once timeout retransmission is triggered, the data needs to be resent. That is to say, the sender needs to cache the data before receiving the confirmation (this is the sending buffer of TCP)
The send buffer of the sliding window is a circular queue
Will the size of the sliding window change?
dynamically changing
Who is affecting the size of the sliding window?
Conclusion: The size of the receiver's receive buffer affects the size of the sliding window
The nb of the sliding window
If an acknowledgment of a group in the middle is received, even if the previous acknowledgment has not been received, it will be processed directly as received (the meaning of the confirmation sequence number)
That is to say, the sliding window can slide a lot at one time
Sliding window packet loss problem
1. Packet ACK loss:
2. Data loss
The fast charging here is not because of timeout retransmission, but because of receiving 3 repeated confirmation responses
2.2 Acceptance of the other party
Limit the amount of data sent by the sender through the acceptability of the other party
Illustration:
flow control mechanism
Scenes:
The sender sends a large amount of window data (packet data in the sliding window), and after being received by the receiver, it is first cached in the receiving buffer maintained by tcp. Due to the large amount of data cached, it will cause the receiving buffer to Therefore, the receiver controls the amount of data sent by the sender through the window size in the response.
Window 0 (notification of window 0): the receiver and the sender send data with a window size of 0, which is called window 0 notification
Extended meaning : the receiver tells the sender that he can't accept it anymore, and the sender should stop sending data
So when will it resume?
1. The receiver actively sends a window update notification (essentially sending a tcp packet with a window size of 0)
2. The sender sends a window detection packet
Delayed response mechanism
After receiving the data, the receiver waits for a while before replying to the sender for confirmation
Essentially, the application layer program of the receiver calls recv to read the data from the receiving buffer of tcp
2.3 Network Forwarding Capability
1. TCP does flow control through sliding windows, but TCP thinks this is not enough.
Because the sliding window needs to depend on the sender and receiver of the connection, it does not know what is happening in the middle of the network. The designers of TCP feel that flow control is not enough for a great and powerful protocol , because flow control is only a matter of layer 4 or above of the network model, and TCP should also be smarter about things on the entire network.
2. TCP is not a selfish protocol. When congestion occurs, self-sacrifice is required. Just like a traffic jam, every car should give way instead of grabbing the way
Congestion control mechanism: Control the amount of data sent by tcp through the degree of network congestion
The amount of data sent by tcp = min (send window, congestion window)
The congestion control mechanism has three phases:
Diagram of early tcp congestion control mechanism
The diagram of the current tcp congestion control mechanism
The difference from the early days is the way to deal with network congestion, because the early network was relatively poor, but now a lot of network congestion is just due to network interruptions, and it doesn’t need to be reduced to such a low level.
1. Slow start (start)
2. Congestion avoidance
3. Strategies when congestion occurs
piggyback mechanism
TCP keep-alive timer (heartbeat packet)
TCP has a total of three timers: timeout retransmission timer, TIME_WAIT timer, keep-alive timer