Study notes:
How to ensure reliable transmission of TCP protocol
- Application data is divided into data blocks that TCP considers best for sending.
- TCP numbers each packet it sends. The receiver sorts the packets and sends the ordered data to the application layer.
- Checksum: TCP keeps the checksum of its head and data. This is an end-to-end checksum to detect any changes in the data during transmission. TCP discards the segment and does not acknowledge the receipt of the segment if the segment is checked or incorrect.
- The TCP receiver discards duplicate data.
- Flow control: Each side of the TCP connection has a fixed buffer space. The TCP receiver only allows the sender to send data that the buffer of the receiver can accept. When the receiver does not have time to process the data of the sender, the sender can be prompted to reduce the sending rate to prevent packet loss. TCP uses a variable-size sliding window protocol for flow control. (TCP uses sliding Windows to achieve flow control)
- Congestion control: Reduces data transmission when the network is congested.
- ARQ protocol: It also aims to achieve reliable transmission. Its basic principle is to stop sending each packet and wait for the confirmation of the other party. Send the next packet after receiving confirmation.
- Timeout retransmission: When TCP sends a segment, it starts a timer and waits for the destination to acknowledge receipt of the segment. If an acknowledgement cannot be received in time, the packet segment is resend.
1.1 ARQ protocol
Automatic retransmission reQuest (ARQ) is one of the error correction protocols of the data link layer and transport layer in the OSI model. It implements reliable information transfer on the basis of unreliable services by using two mechanisms: acknowledgement and timeout. If the sender does not receive an acknowledgement frame within a period of time after sending it, it usually resends it. ARQ includes stop wait ARQ and continuous ARQ.
Stop waiting for ARQ
- The stop-wait protocol is designed to achieve reliable transmission. Its basic principle is to stop sending packets after each packet is sent and wait for ACK. If no ACK is received after a period of time (timeout period), the packet is not sent successfully. You need to send the packet again until the ACK is received.
- In the stop-wait protocol, if the receiver receives a duplicate packet, it discards the packet, but sends an acknowledgement at the same time.
Pros: Simplicity
Disadvantages: Low channel utilization and long waiting time
1) No errors:
The sender sends the packet, and the receiver receives the packet within the specified time, and replies for confirmation. The sender sends again.
2) Error (timeout retransmission) :
Timeout retransmission in the stop-wait protocol means that the packet that has been sent before is retransmitted if no confirmation is received within a period of time (the packet that has been sent before is considered lost). Therefore, a timeout timer should be set after each packet is sent, and the retransmission time should be longer than the average round trip time of packet transmission. This type of automatic retransmission is often called automatic retransmission request ARQ. In addition, if a duplicate packet is received in the stop-wait protocol, the packet is discarded, but an acknowledgement is sent at the same time. Continuous ARQ protocol can improve channel utilization. Send Maintains a send window in which packets can be sent consecutively without waiting for confirmation. The receiver generally uses cumulative acknowledgements, sending acknowledgements to the last packet arriving in sequence, indicating that all packets to that packet location have been correctly received.
3) Confirm loss and confirm lateness
- Acknowledgement loss: The acknowledgement message is lost during transmission. When USER A sends an M1 message, user B sends an M1 confirmation message to user A, which is lost during transmission. However, A did not know that after the timeout, A retransmitted M1 message, and B took the following two measures after receiving the message again: 1. The duplicate M1 message is discarded without delivery to the upper layer. 2. Send A confirmation message to USER A. (It doesn’t stop because it’s already been sent. If A can retransmit, B’s confirmation message is lost.
- Acknowledgement lateness: Acknowledgement message is late in transit. User A sends an M1 message, and user B receives and sends an acknowledgement. If no acknowledgement message is received within the timeout period, A retransmits the M1 message, and B still receives and continues to send the acknowledgement message (B has received two M1s). At this point, A receives the confirmation message sent by B for the second time. Then it sends other data. After A while, A received B’s first confirmation message to M1 (A also received two confirmation messages). The processing is as follows: 1. After receiving A duplicate acknowledgement, user A discards it. 2. After receiving the duplicate M1, B directly discards the duplicate M1.
Continuous ARQ protocol
Continuous ARQ protocol can improve channel utilization. The sender maintains a send window in which packets can be sent consecutively without waiting for confirmation. The receiver generally uses cumulative acknowledgements, sending acknowledgements to the last packet arriving in sequence, indicating that all packets up to that point have been correctly received.
Advantages: High channel utilization, easy to implement, even if confirmed loss, do not need to retransmit.
Disadvantages: Cannot reflect to the sender that the receiver has correctly received all packet information. For example, if the sender sends five messages, the third one is lost (number 3), and the receiver can only acknowledge the first two messages. The sender had no way of knowing the whereabouts of the last three packets and had to retransmit them all. This is also called go-back-n, which means you need to Go Back to retransmit N messages that have already been sent.
1.2 Sliding Windows and flow control
TCP uses sliding Windows for flow control. Traffic control is to control the sending rate of the sender and ensure that the receiver can receive data in time. The window field in the acknowledgement packet sent by the receiver can be used to control the size of the sender window, thus affecting the sending rate of the sender. If the window field is set to 0, the sender cannot send data.
1.3 Congestion control
At some point, if the demand for a resource in the network exceeds the available portion of the resource, the performance of the network deteriorates. This condition is called congestion. Congestion control is designed to prevent too much data from being injected into the network so that routers or links in the network are not overloaded. Congestion control must be done on the premise that the network can withstand the existing network load. Congestion control is a global process that involves all hosts, all routers, and all factors associated with reducing network traffic performance. In contrast, traffic control is often a point-to-point traffic control, an end-to-end problem. The purpose of flow control is to suppress the rate at which the sender sends data so that the receiver can receive it in time.
For congestion control, the TCP sender maintains a congestion window (CWND) state variable. The size of the congestion control window depends on the congestion level of the network and changes dynamically. The sender makes its send window the smaller of the congestion window and the receiver’s accept window.
TCP congestion control adopts four algorithms: slow start, congestion avoidance, fast retransmission and fast recovery. At the network layer, routers can also adopt appropriate packet discarding policies (such as active queue management AQM) to reduce network congestion.
- Slow start: The idea behind the slow start algorithm is that when the host starts sending data, if a large number of data bytes are immediately injected into the network, it may cause network congestion because network compliance is not yet known. Experience shows that the better method is to first detect, that is, gradually increase the sending window from small to large, that is, gradually increase the value of congestion window from small to large. The initial value of CWND is 1, and the CWND is doubled after each transmission cycle.
- Congestion avoidance: The idea of the congestion avoidance algorithm is to make the CWND of the congestion window increase slowly, that is, every round trip time RTT will add 1 to the CWND sent.
- Fast retransmit and Recovery: In TCP/IP, fast Retransmit and Recovery (FRR) is a congestion control algorithm that can quickly recover lost data packets. Without FRR, TCP will use a timer to suspend the transmission if the packet is lost. During this pause, no new or duplicated packets are sent. With FRR, if the receiver receives a piece of data out of order, it immediately sends a repeat acknowledgement to the transmitter. If the transmitter receives three duplicate acknowledgements, it assumes that the data segments indicated by the acknowledgements are missing and immediately retransmits those missing data segments. With FRR, there is no delay due to the pause required on retransmission. Fast retransmission and Recovery (FRR) works best when a single packet is lost. It does not work very effectively when multiple data packets are lost over a short period of time.