How to understand the transport layer?

Now consider two families, H1 and H2, two families with 12 children who like to write letters to each other, C1 from H1 and C2 from H2 are responsible for collecting letters and sending them to the post office, from which they are picked up and distributed to other people.

In this example, application-layer packets = characters on the envelope, processes = children, hosts = families, transport-layer protocols = C1 and C2, network-layer protocols = postal services.

Transport layer protocols provide logical communication between application processes running on different end systems, and transport layer protocols work only in the end system, where transport layer protocols move messages from application processes to the edge of the network (the network layer) and vice versa.

The transport layer protocols are UDP (User Datagram Protocol) and TCP (Transmission Control Protocol), which are responsible for extending the IP delivery service between two end systems to the delivery service between two processes running on the end system.

Process-to-process data delivery and error checking are two minimal transport-layer services, and the only ones UDP can provide. TCP provides reliable data transmission and congestion control on top of this.

Multiplexing & multiplexing

Multiplexing and multiplexing extend the host-to-host delivery services provided by the network layer to process-to-process delivery services for applications running on the host.

When C1 receives a batch of letters from the postman and hand-delivers them to its siblings by checking the recipient’s name, it performs a multiplex decomposition operation. When C2 collects letters from siblings and hands them to the postman, it performs a multiplexing operation.

A process has one or more sockets, and the transport layer in the receiving host does not actually deliver data directly to the process, but to an intermediate socket. There may be more than one socket on the receiving host at any one time, so each socket has a unique identifier, the format of which depends on TCP or UDP.

The work of delivering data from segments of the transport layer to the correct socket is called multiplexing, where the source host collects blocks of data from different sockets, encapsulates header information for each block to generate segments, and then passes the segments to the network layer, all of which is called multiplexing.

A UDP socket is comprehensively identified by a binary that contains a destination IP address and a destination port number. A TCP socket is identified by a quad (source IP address, source port number, destination IP address, and destination port number).

UDP

The UDP header has four fields (source port number, destination port number, length, check and), each of which contains two bytes. The length refers to the number of bytes in the entire UDP packet (header + data). The receiver uses check and to check whether errors exist in the packet.

Although UDP provides error detection, it is helpless for error recovery. Some implementations of UDP simply discard the damaged segment; others hand the damaged segment to the application with a warning.

Reliable data transmission

The automatic retransmission request (ARQ) protocol, by controlling messages, allows the receiver to let the sender know what was received correctly and what was received incorrectly and therefore needs to be repeated.

ARQ also needs error detection (bit error, checksum), receiver feedback (affirmative acknowledgement ACK, negative acknowledgement NAK), and retransmission to handle the case of bit error.

Stop-wait protocol: When the sender is in a state waiting for an ACK or NAK, it cannot get more data from the upper layer. This event only occurs when it receives an ACK and leaves the state. So the sender will not send a new piece of data unless the sender is confident that the recipient has received the current packet correctly.

A more serious problem is that the ACK or damaged NAK group may, a simple way to solve the problem, is to add a new field in the data packet, the sender to its data packet Numbers, the sending data packet sequence number in the field, so the receiver can check the serial number to determine whether the received packet retransmission at a time.

For the stop protocol, if the sender cannot understand the ACK/NAK of the receiver, the receiver determines whether the packet is a retransmission group or a new one based on the sequence number.

But in addition to solving the problem of bit damage, we also need to consider the packet loss problem of the underlying channel, that is, how to detect the packet loss and what to do after the packet loss occurs?

We are working to restore the sender is responsible for the detection and packet loss, assuming that sends an ACK packet loss or the receiver is missing, the sender should not receive the arrival of the recipient’s response, we can let the sender wait for a round-trip + grouping processing delay, but the time delay in the worst case means that the sender will wait for a long time.

Therefore, a timeout period needs to be set. If no ACK is received within this time, the packet will be retransmitted, even if the recipient has already received the packet. This means that redundant data packets are introduced in the channel from sender to receiver. For redundant data grouping, we can still use the ordinal mechanism above to deal with it.

For the sender, whether a data packet loss, or lost a ACK, timeout, or a group or an ACK is weighed by coming to solve, in order to achieve the retransmission mechanism based on time and need a count down timer: (1) every time to send a packet (including new grouping and retransmission packet), start a timer; ② The response timer is interrupted; ③ Stop the timer.

By examining the techniques of sum, sequence number, timer, and affirmative and negative confirmation grouping, we have come up with a reliable data transfer protocol, which we call RDT3.0 or bit-alternate protocol.

Pipelined reliable data transfer protocol

At the heart of rdT3.0’s performance issues are a stop and wait protocol, the underlying protocol processing times for both sender and receiver, and processing and queuing delays for any intermediate routers that may occur between sender and receiver.

The solution is not to run in a wait mode, allowing the sender to send multiple packets without waiting for confirmation, because many packets sent from the sender to the receiver can be thought of as being filled into a pipeline, hence this technique is called pipelining.

  • The ordinal range must be increased because each packet in the transport (excluding retransmission) must have a unique sequence number, and there may be multiple unacknowledged messages in the transport.
  • The sender and receiver of the protocol may have to cache multiple packets, the sender should at least be able to cache packets that have been sent but not acknowledged, and the receiver may need to cache packets that have been properly accepted.
  • The required serial number range and buffering requirements depend on how the data transmission protocol deals with the missing, damaged and delayed groups. There are two basic methods to solve the pipeline error recovery: N step back and selective retransmission.

Rollback N step (GBN) protocol

The GBN protocol allows the sender to send multiple packets without waiting for confirmation, but it is also limited that the number of unconfirmed packets cannot exceed a certain maximum allowed number N in the pipeline.

Assuming that the serial number range of THE GBN protocol is 0-K, the serial number range can be divided into four segments (sent and confirmed, sent but not confirmed, to be sent, and unusable serial number).

The length of the sent but unconfirmed packet and the packet to be sent is the window length N. With the running of the protocol, the window slides forward in the ordinal space, so GBN protocol is often called the sliding window protocol.

The ordinal number of a group is carried in a fixed-length field at the head of the group. If the field is K bits long, the ordinal number range is [0, 2^ K-1]. All operations involving Ordinal Numbers must use modular 2^ K operations, so the ordinal space can be considered as a ring of length 2^ K.

The sender of the GBN must respond to three types of events.

  • Upper-level calls. Only when the window is full will a group be generated and sent, as well as the corresponding variables updated.
  • Received an ACK. Cumulative confirmation is adopted for the packet numbered N, indicating that the recipient has correctly received all packets numbered N and before.
  • Timeout event. Rollback n step refers to the behavior of the sender when a packet is lost or with a long delay. If the packet times out, the sender retransmits all packets that have been sent but have not been confirmed.

GBN receiver If a packet numbered N is received correctly and in order, the receiver sends an ACK for packet N and delivers the data portion of the packet to the upper layer. In all other cases, the receiver discards the group and resends an ACK for the last group received in sequence. It may seem silly to discard a properly received but out-of-order group, but the receiver does not need to cache an out-of-order group because the discarded fragment will be sent again by the sender due to the retransmission rule.

Select the retransmission

The GBN protocol allows multiple packets to be sent, avoiding the channel utilization problem in the stop and wait protocol. However, in THE GBN protocol, the error of a single packet can cause a large number of packets to be retransmitted, and many of them are not necessary to be retransmitted at all. As the error rate increases, the pipeline may be flooded with unnecessary retransmitted packets.

The selective retransmission (SR) protocol avoids unnecessary retransmission by allowing the sender to retransmit only packets suspected of having gone wrong at the receiver. The SR receiver will acknowledge a correctly received packet regardless of whether it is ordered or not, and out-of-order packets will be cached until all previous missing packets (smaller ones) have been received, at which point a batch of packets can be delivered to the upper layer in order.

SR sender action:

  1. After receiving data from the upper layer, the SR sends to check the next sequence number available for the group. If the serial number is in the window, the data is packaged and sent. Otherwise, like GBN, the data is cached or returned to the upper layer for later transmission.
  2. Timers were again used to prevent loss of packets, but now each packet has its own logical timer, since only a single packet is sent after a timeout occurs.
  3. If an ACK is received and the group number is in the window, the group is marked as received. If the ordinal number is at the beginning of the window, then the window moves right to the unconfirmed group with the minimum ordinal number, and if the window moves and the order number falls on the unsent group of the window, these groups are sent.

SR receiver action:

  1. The packet whose serial number is in the window is received correctly, and the received packet is placed in the window of the receiver, and a select ACK is sent back to the sender. If the group has not been received before, the group is cached. If the group number is at the beginning of the window, the group is delivered to the upper layer in successive groups, along with previously cached numbers, and the window moves to the right.
  2. The group in the previous window was received correctly and needs to generate an ACK, even if the group was previously acknowledged.
  3. Otherwise, this grouping is ignored.

For serial number space is a practical problem, the serial number range is limited, the problem that the receiver is unable to determine a group is the new grouping or retransmission packet, so for the SR protocol window length must be less than or equal to half of the largest number, such ability won’t in continuous two Windows have the same serial number of the group.

Summary of Reliable mechanisms

  • Checksum: Used to detect bit errors in a transport packet.
  • Timer: Used for timeout retransmission, data packet timeout, or ACK packet timeout (the receiver will have redundant copies).
  • Serial number: The sent packets are numbered sequentially. The gap between the serial number of the received packets enables the receiver to detect the missing packet. A packet with the same serial number enables the receiver to detect a redundant copy of the packet.
  • Acknowledgement: Used by the receiver to tell the sender that a packet or group of packets has been correctly received. An acknowledgement packet usually carries the serial number of the confirmed packet or multiple packets. Validation can be individual or cumulative, depending on the type of protocol.
  • Negative confirmation: Used by the receiver to tell the sender that a packet or group of packets has not been received correctly. The negation acknowledgement message usually carries the sequence number of the packet that was not received correctly.
  • Window, pipeline: senders may be restricted to sending only groups whose serial numbers fall within a specified range. The window length can be set based on the receiver’s ability to receive and cache packets, the level of congestion in the network, or both.

TCP

TCP is a reliable transport protocol for connections at the Internet transport level. To provide reliable data transmission, TCP relies on the principles of reliable data transmission described above, including error detection, retransmission, cumulative confirmation, timers, and header fields for serial numbers and confirmation numbers.

TCP is so complex and important that a new article will be written specifically about TCP in order to avoid getting too long.