Stop waiting protocol
“Stop waiting” is when the sender stops sending a packet and waits for the receiver’s confirmation before continuing.
Timeout retransmission
If the sender has not received the confirmation from the receiver after waiting for a certain period of time, the sender will consider that the packet has not been delivered and resend the packet.
TCP implements timeout retransmission in the following ways:
- Timeout timer: TCP sets a timeout timer after each packet is sent. The timeout period of the timeout timer is longer than the average round-trip time of packets.
- Packet copy: After a packet is sent, TCP retains the packet copy and clears it only after receiving the packet confirmation
- Packet number: TCP numbers each packet and confirms that the packet number is the same as the sent packet number.
Continuous ARQ protocol
If TCP waits for each packet to be sent, it will waste a lot of time and reduce network utilization. So TCP uses continuous ARQ, which means sending multiple packets at a time and then using cumulative acknowledgment.
- Cumulative acknowledgement: The receiver sends acknowledgement only to the last packet that arrives in sequence.
If the sender sends five packets [1,2,3,4,5] at one time, the receiver receives only four packets [1,2,4,5]. According to the last-in-order rule, the receiver will only send the confirmation of the number 2 packet. The sender will not receive confirmation for the next three groups, so it will retransmit 3,4,5.
Cumulative validation is implemented using a sliding window, which has the advantage of reducing network overhead by eliminating the need to send validation to each group. The disadvantage is that it cannot truly reflect the received packet information to the sender. For example, in the above example, the sender thinks that the packet no. 3 has not been received, but the receiver actually received the packet no. 4 and 5.
A sliding window in bytes
The sender and the receiver respectively maintain two sliding Windows: the send window and the receive window.
The send window maintains three Pointers p1, P2, and P3, which divide the region of the send window:
- [P1, P2) : Waiting for confirmation area, record sent but did not receive confirmation packet.
- [P2, P3] : Available window, packets that are allowed to be sent but not yet sent.
Since it is a sliding window, its left and right boundaries should be able to move. The following is to analyze the movement of the left and right boundaries of the sending window.
The p2 forward
The P2 pointer points to the first packet that is allowed to be sent but has not yet been sent, so the p2 forward is the sender sending the new packet.
P1 forward
The P1 pointer moves to the next group of the confirmed group only after the acknowledgement is received.
Because of the cumulative acknowledgement method, the recipient will only send the acknowledgement that reaches the last group in order, so the advance of P1 may be more than one group.
For example, in the case of the graph above, if the receiver receives 31,32, and 33 packets, it will only send acknowledgements that arrive in order to the last packet, that is, packet number 33. At this point, the p1 pointer of the sender will move directly from position 31 to position 34, which is the next to receive the confirmation packet.
P3 forward
The move forward of P3 is controlled by the window field of the acknowledgement packet sent by the recipient.
The window value represents the amount of data (bytes) from the confirmation packet number to P3. For example, if the packet number is 101 and the window value is 200, the send window can be expanded by 200 bytes.
The receiver controls the size of the sending window by window values also known as flow control, which is not covered here.
TCP cache
Since TCP can hold unacknowledged packets and send acknowledgements sequentially, it definitely needs a memory space as a cache, rather than directly using the memory of the application process.
As shown in the figure, the receiver and sender each maintain a cache in which both the sending and receiving Windows reside. First, TCP cache has the following characteristics:
- Because of the limited cache space and ordinal number, the TCP cache is used in a circular structure.
- The sliding window is only part of the cache, and confirmed data is deleted.
Send and receive caches have the same structure but different functions.
Send the cache
- The cache application tells TCP to send data
- Hold data that has been sent but has not been acknowledged
Receive buffer
- Temporarily store data that does not arrive in sequence
- Cache data that arrives sequentially but is not read by the application
conclusion
- The principle of TCP reliable transmission is to stop wait protocol and continuous ARQ
- The timeout retransmission time is greater than the average group round trip time
- Continuous ARQ uses cumulative confirmation to send confirmation
- TCP implements reliable transmission through the send window and receive window
- The size of the sending window is controlled by the receiver’s window value, which is in bytes
- The sliding window is part of the TCP cache, a circular structure that also caches application data