Chapter 3 Transport Layer

Section 1 Basic services for transport layer

1.1 Transport Layer Functions

  1. The core task of the transport layer is to provide end-to-end logical communication services between application processes.

  2. The real endpoint of communication is not the host, but the application process running on the host.


The main function

  • Transport layer addressing
  • Segmented and reassembled application-layer packets
  • Error detection of packets
  • End-to-end reliable data transfer control between processes
  • Implement reuse and decomposition for application layer
  • End-to-end flow control
  • Congestion control


1.2 Transport layer addressing and ports

  1. Identify the application process with a unified addressing method – port number.

  2. The IP address and port number are used to uniquely identify a communication endpoint on the whole network.


Three categories of port

  • Know port numbers, the value ranges from 0 to 1023.
  • Register port number, the value ranges from 1024 to 49151, and is used by applications that are not familiar with port numbers. Port numbers using this range must be registered with IANA to prevent duplication.
  • Client port number or transient port number. The value ranges from 49,152 to 65535, which is reserved for the customer process to use temporarily.


Common protocol port number

  • FTP: 21 (TCP)
  • HTTP: 80 (TCP)
  • SMTP: 25 (TCP)
  • Pop3:110 (TCP)
  • DNS: 53 (UDP)


1.3 Connectionless Service For connection-oriented service

Services provided by transport layer can be divided into connectionless services and connection-oriented services.


Connectionless Service (UDP)

Before data transmission, a transport layer packet segment is directly constructed and sent to the receiver without any information exchange (handshake) with the peer end.


Connection-oriented Services (TCP)

Before data transmission, both parties need to exchange some control information, establish a logical connection, and then transfer data. After data transmission, the connection needs to be removed.


The second section is the reuse and decomposition of transport layer

Multiplexing and multiplex decomposition

It is a basic function of the transport layer, enabling multiple application processes to share the same transport layer protocol and accurately deliver the received data to different application processes.


Connectionless multiplexing and multiplexing decomposition

The UDP socket port number is an important basis for UDP reuse and decomposition.

UDP identifies a UDP socket according to the binary destination IP address, destination port number.


Connection-oriented multiplexing and multiplexing decomposition

TCP identifies a TCP socket based on the quintuple source IP address, source port number, destination IP address, and destination port number, that is, identifies a TCP connection.


Section 3 Stop-wait protocol and sliding window protocol

Reliable data transmission protocols include stop-wait protocol and sliding window protocol.


Basic principles of reliable data transmission

  1. Error detection: use error coding to realize bit error detection in packet transmission.
  2. Confirm: The receiver reports the receiving status to the sender.
  3. Retransmission: The sender resends data that the receiver did not receive correctly.
  4. Serial number: Ensure data is submitted in order.
  5. Timers: Solve data loss problems.


Stop. – Wait for the protocol

The main feature of stop-equal protocol is that it stops to wait for the acknowledgement of the receiver after each packet segment is sent.


Stop-wait the basic working process of the agreement

  1. The sender sends the error-coded and numbered message segment and waits for the receiver’s confirmation.(Send and wait for confirmation)
  2. If the receiver receives the packet segment correctly, that is, the error detection is correct and the serial number is correct, the receiver receives the packet segment and sends an ACK to the sender. Otherwise, the receiver discards the packet segment and sends an NAK to the sender.(Accept and confirm/deny)
  3. If the sender receives an ACK, the sender continues to send subsequent packets. Otherwise, the sender resends the previously sent packet.(Continue/resend)


Sliding window protocol

Due to the mechanism of stop-equal protocol, channel utilization will be reduced. To solve this problem, pipelined or pipelined protocols were designed to allow the sender to send multiple packets in succession without receiving an acknowledgement.

Typical pipeline protocol: sliding window protocol

The two most representative sliding window protocols are:

GBN protocol (Go-back-n, N steps Back)

The size of the sender window is large, and multiple packets can be sent consecutively before confirmation. However, the size of the receiving window is only 1, and only one packet can be received. If a packet is not arrived sequentially or a packet error occurs, the sender will resend this packet and all subsequent packets.

SR protocol (Selective Repeat)

Increase the cache capability of the receiver (receiving window > 1), cache correctly arrived but out of order packets, and only require the sender to retransmit the packets that are not confirmed by the receiver. After the missing packets arrive, they are submitted to the upper layer in order.


Section 4 User Data Packet Protocol (UDP)

User data packet protocol (UDP) is an Internet transport layer protocol that provides connectionless, unreliable, and datagram transmission services. Such as DNS.

UDP datagram structure

A datagram contains a header and data. The UDP header has only four fields, each consisting of two bytes.

The datagram structure is shown below:

  1. Source port and destination port: used for UDP reuse and decomposition.
  2. Length field: Indicates the number of bytes (the sum of header and data) in the UDP packet segment.
  3. Checksum: Used by the receiver to detect errors in the packet segment.

UDP checksum.

UDP checksum provides error detection.

Computing checksum

  1. Sum all the contents of the operation by 16 bits;
  2. Any overflow (i.e., carry) encountered during the summation is rewound (i.e., add the least significant of the carry and sum);
  3. The final sum is the inverse;

How binary addition works:

Binary Large integer Addition


Section 5 Transmission Control Protocol (TCP)

  • TCP provides the full-duplex communication service, that is, TCP allows application processes on both sides of the communication to send and receive data at any time.
  • Both ends of the TCP connection are configured with send and receive caches to temporarily store bidirectional communication data.
  • MSS refers to the maximum length of application-layer data encapsulated in a packet segment rather than the maximum length of the TCP packet segment including the TCP header.


TCP packet segment structure

1️ source port number and destination port number (16 bits) :

Identifies the source and destination ports that send the packet segment for multiplexing/decomposing data from or to upper-layer applications.

2️ serial number field and confirmation serial number (32 bits) :

The ordinal field is the ordinal number of the first byte of application-layer data encapsulated in the segment. The acknowledgement sequence number is the sequence number of the byte expected to receive data from the peer party. That is, the corresponding bytes of the sequence number have not been received, and all the bytes before the sequence number have been correctly received. That is, TCP uses the cumulative acknowledgement mechanism.

3️ head length (4th) :

Indicates the length of the TCP segment header, in unit of 4 bytes. For example, if the value of this field is 5, it indicates that the length of the TCP segment header is 20 bytes.

4️ URG, ACK, PSH, RST, SYN and FIN occupy 1 position each (6 positions in total) :

  • URG = 1: indicates that the emergency pointer field is valid and informs the system that urgent data exists in this packet segment and should be transmitted as soon as possible.
  • ACK = 1: indicates that the serial number field is valid.
  • PSH = 1: The data in the packet segment is delivered to the receiving application process as soon as possible.
  • RST = 1: indicates that a serious error occurs in the TCP connection. You must release the connection and re-establish the TCP connection.
  • SYN =1: indicates that the TCP packet segment is a control segment for establishing a new connection or an acknowledgment segment for establishing a new connection (ACK=1).
  • FIN = 1: Indicates that data on the source end of the TCP packet segment is sent and requests to release the TCP connection.

5️ reception window (16 bits) :

Notifies the peer party of the size of the receiving window and implements TCP traffic control.

6️ check sum (16bit) :

Checksum field validation is similar in scope to UDP and provides error detection.

7️ emergency indicator (16 bits) :

This field is valid only when URG is 1. It indicates the total number of bytes of emergency data in the TCP packet segment. Note that emergency data can be sent even when the receive window size is zero.

8️ filler field (0~3 bytes) :

The value is 0 so that the entire header length is a multiple of 4 bytes.


TCP Connection Management

TCP connection includes connection establishment and disconnection.


Connection is established

The three-way handshake for establishing a TCP connection is as follows:

🕐 The TCP of host A sends A connection request packet to host B. First handshake

🕑 Host B receives a connection request packet and returns a confirmation packet if host B agrees. Second handshake

🕒 Host A sends an acknowledgement packet to host B after receiving the acknowledgement packet from host B. Third handshake


❗ The TCP packet segments of the first and second handshakes do not carry data. The TCP packet segments of the third handshake can carry data.

🎨 Connection establishment process diagram:


The connection to dismantle

The four-wave release process of TCP connections is as follows:

🕐 Host A sends A connection release packet to host B. First wave

🕑 Host B sends an acknowledgement packet to host A. Second wave

🕒 Host B sends A connection release packet to host A. Third wave

🕓 Host A sends an acknowledgement packet to host B. Host B can release the connection immediately after receiving the confirmation packet. Host A releases the connection after sending an acknowledgement packet. Fourth wave


❗ The main reasons why TCP uses four waves to disconnect:

In order to ensure the reliability of the disconnection process, the reliable data transmission of TCP will not be destroyed due to the unreliable disconnection. The TCP quadruple wave disconnection is a symmetric disconnection. Both ends of the TCP quadruple wave disconnection request the TCP quadruple wave disconnection request. In this way, both ends of the TCP quadruple wave disconnection request the TCP quadruple wave disconnection request the TCP quadruple wave disconnection request the TCP quadruple wave disconnection request the TCP quadruple wave disconnection request the TCP quadruple wave disconnection request is a symmetric disconnection request.

🎨 Connection removal process diagram:


TCP Reliable data transmission

  • TCP’s reliable data transmission mechanism includes error coding, acknowledgement, serial number, retransmission, timer, etc.
  • The reliable data transmission of TCP is based on the sliding window protocol, but the size of the sending window is dynamically changing. The sending window depends on the size of the notification window of the receiving end of flow control and the size of the congestion window to realize congestion control. The minimum value of the two Windows is taken by the TCP sending window at any time.


The reliable data transmission service of TCP is realized by the following working mechanism:

1️ application data is segmented into data blocks (usually MSS), encapsulated into TCP message segments and transmitted to IP.

2️ Start a timer after sending a message segment. If confirmation (loss) cannot be received in time, the message segment will be retransmitted.

3️ check whether errors occur during data transmission through checksum field.

4️ reorder received data and discard repeated message segments according to serial number.

5️ provides flow control to control the speed of transmitting data at the sender end and prevent buffer overflow at the receiving end.


TCP flow control

Purpose of flow control

Coordinate the data sending and receiving speed between the sender and the receiver to prevent data being discarded by the receiver because the sender sends data too fast.


How does TCP implement traffic control

There are many methods to realize flow control. The basic principle can be realized by stop-wait protocol or sliding window protocol. Although TCP protocol to achieve flow control is also using window protocol, but not a simple sliding window protocol.

1️ Use window protocol to limit the data transmission rate of sender.

2️ when establishing TCP connection, both parties allocate a fixed size buffer space for it. The TCP receiver allows the sender to send only as much data as the receiver buffer can accept.

  • The receiver notifies the sender of the size of the receiving window when sending an acknowledgement packet to the sender.
  • When sending subsequent data packets, the sender ensures that the total amount of data at the application layer in the unacknowledged packet segment does not exceed the size of the receiving window advertised by the receiver to prevent cache overflow.


TCP congestion control

congestion

Congestion refers to the phenomenon that too many hosts send too much data to the network at too high a speed, which exceeds the network processing capacity. As a result, a large number of data packets are crowded in queues of intermediate devices (such as routers) waiting for forwarding, and the network performance deteriorates significantly.


Congestion control

Congestion control is to avoid congestion or eliminate congestion as soon as possible by reasonably scheduling, standardizing, and adjusting the number, rate, or amount of hosts that send data to the network.


TCP congestion control mechanism:

1️ window mechanism: the adjustment of data transmission rate can be realized by adjusting the size of window

2 basic strategy of ️ window adjustment: additive increase and multiplicative decrease: when no network congestion occurs, gradually “additive” increase the window size, and multiplicative rapidly reduce the window size when network congestion occurs.

3️ congestion control algorithm: including slow start, congestion avoidance, fast retransmission and fast recovery.