Home>Article>Operation and Maintenance> Understand the reliable transmission principle of TCP in one article
The IP layer below TCP is a best-effort delivery and is unreliable, so TCP needs to complete reliable transmission on its own. Next, we start with a simple stop-and-wait protocol to explain how to implement reliable transmission. We need to pay attention to several characteristics of reliable transmission: no loss, no duplication, and in-order arrival.
Note that TCP does not use the stop-and-wait protocol to achieve reliable transmission.
Stop Waiting Protocol
The data transmission unit of the transport layer is called a segment. Below, for convenience, they are all called groups.
The principle of the stop-and-wait protocol is very simple. After sending a packet, it stops sending, waits for the confirmation of the previous packet, and then continues to send the following packets.
The following is analyzed through several different situations:
No error situation
The no error situation is very simple, as shown below . After each packet is sent, it stops sending and waits for confirmation of the packet before continuing to send subsequent packets.
Error occurs
There are two situations when an error occurs. The first is that the packet sent does not The delivery is successful to the destination address. Another situation is that there is an error in the transmitted data packet. Through the illustration, let's analyze the two situations
First let's look at the operation of B: A sends the M1 packet. If the packet is Wrong, B will discard the packet after receiving it, and then do nothing (A will not be notified that it received the wrong packet). If B does not receive the M1 packet, then it knows nothing and will not take any action.
Let’s see what A does next: After A sends the packet, but fails to receive B’s confirmation of the M1 packet, when the waiting time times out, the M1 packet needs to be resent. To implement timeout retransmission, you need to set a timeout timer. When a sent packet is confirmed before the timeout period, the timeout timer is reset, otherwise the packet needs to be retransmitted.
There are several points to note:
#After sending a packet, A must also save a copy of the packet in order to timeout and retransmit it. When an acknowledgment for this packet is received, the copy of the packet can be discarded.
You need to number each group so that you can know the arrival status of each group.
The timeout should be set slightly longer than the average transmission time to avoid unnecessary retransmissions.
Confirmation loss and late confirmation
In addition to errors during packet transmission, when the confirmation is returned , errors will also occur - lost confirmations and late confirmations.
First look at the confirmation loss situation. A's packet B received it and sent a confirmation to A, but the confirmation was lost and A did not receive it. Because A has not received the confirmation from M1, it will retransmit M1 to B after waiting for more than the timeout. At this time, B receives the duplicate packet M1 and needs to do two operations:
Discard the duplicate packet M1
Send M1 to A confirmation. Because since A retransmitted M1, it means that A did not receive the packet of M1. So B needs to continue sending confirmations to M1.
Looking at another situation, the packet confirmation for M1 is late (received after the timeout period). After receiving the duplicate confirmation, A will discard it and do nothing else.
Through the above timeout retransmission mechanism, reliable transmission can be achieved on unreliable network transmission.
Channel Utilization
The above stop-and-wait protocol is simple, but it has a very big shortcoming-the channel utilization is too low . During the period of time waiting for the confirmation to be received, the channel is completely idle, which is very wasteful.
In order to improve channel utilization, pipeline transmission can be used. Pipeline transmission can continuously send multiple packets, which can greatly improve channel utilization.
The protocols that use pipeline transmission includeContinuous ARQ protocolandWindow sliding protocol. TCP uses the sliding window protocol to complete reliable transmission.
The above is the detailed content of Understand the reliable transmission principle of TCP in one article. For more information, please follow other related articles on the PHP Chinese website!