Computer Network 05 - Transport Layer

transport layer

Learning reference materials:

  1. Hunan University of Science and Technology - Computer Network
  2. Xie Xiren Computer Network (7th Edition)

1 Overview

The transport layer provides logical communication for application processes that communicate with each other. The communication between two hosts means that the application processes in the two hosts communicate with each other.

insert image description here

The transport layer shields the high-level users from the details of the underlying network core. It makes the application process see as if there is an end-to-end logical communication channel between two transport layer entities.

insert image description here

1.1 Two main agreements

  • User Datagram Protocol UDP (User Datagram Protocol)
  • Transmission Control Protocol TCP (Transmission Control Protocol)

insert image description here

The data unit transmitted by two peer transport entities during communication is called Transport Protocol Data Unit TPDU (Transport Protocol Data Unit).

  • The data unit protocol transmitted by TCP is TCP segment (segment).
  • The data unit protocol transmitted by UDP is UDP message or user datagram.

insert image description here

insert image description here

1.2 Ports

To communicate with each other, processes in two computers must not only know each other's IP address (in order to find each other's computer), but also know each other's port number (communication between application processes).

insert image description here

insert image description here

insert image description here

2. User Datagram Protocol UDP

UDP adds very little functionality over IP's datagram services:

  • multiplexing and demultiplexing functions
  • Error detection function

Has the following characteristics:

  • UDP 是无连接的, there is no need to establish a connection before sending data, thus reducing overhead and delay before sending data.
  • UDP 使用尽最大努力交付, that is, reliable delivery is not guaranteed, so the host does not need to maintain complex connection state tables.UDP 是面向报文的。
  • UDP 没有拥塞控制, so network congestion will not slow down the sending rate of the source host. This is important for some real-time applications. It is very suitable for the requirements of multimedia communication.
  • UDP 支持一对一、一对多、多对一和多对多的交互通信。
  • UDP 的首部开销小, only 8 bytes, shorter than TCP's 20-byte header.

UDP header format:

  • User datagram UDP has two fields: data field and header field.
  • The header field has 8 bytes and consists of 4 fields, each of which is 2 bytes.

insert image description here

  • The 12-byte "pseudo-header" is temporarily concatenated with the UDP user datagram when calculating the checksum. The dummy header is just for calculating the checksum.

insert image description here

3. Transmission Control Protocol TCP

3.1 Overview

insert image description here

insert image description here

3.2 Reliable transport

insert image description here

insert image description here

Reliable transport adopts pipeline protocol. 流水线传输That is, the sender can send multiple packets continuously, without having to stop and wait for the other party's confirmation every time a packet is sent. This allows data to be transmitted uninterruptedly on the channel. Since there is always uninterrupted transmission of data on the channel, this transmission method can obtain a high channel utilization rate.

3.3 The header format of the TCP segment

insert image description here

Although TCP is byte-oriented, the data unit transmitted by TCP is a segment.

The first 20 bytes of the TCP segment header are fixed, and the following 4n bytes are optional options (n ​​is an integer). Therefore the minimum length of the TCP header is 20 bytes.

insert image description here

  • Source port: 16 bits, used to write the source port number 标识发送该TCP报文段的应用进程.
  • Destination port: occupying 16 bits, written into the destination port, used for 标识接收该TCP报文段的应用进程.
  • Sequence number: Occupying 32 bits, each byte in the data stream transmitted in the TCP connection is coded with a sequence number. The value of the sequence number field refers to the sequence number of the first byte of the data sent in this message segment.

insert image description here

  • Confirmation number: Occupying 32 bits, it is the sequence number of the first byte of the data expected to receive the next segment of the other party, and it is also the confirmation of all the data received before.如果确认号为n,则表明到序号n-1为止的所有数据都已经正确接收,期望接收序号为n的数据。
  • Data offset: occupy 4 bits, and take 4 bytes as the unit. It indicates how far the beginning of the data of the TCP segment is from the beginning of the TCP segment. The minimum value is 5 and the maximum value is 15.
  • Reserved: occupying 6 bits, reserved for future use, but should be set to 0 at present.
  • Urgent URG: When URG is 1, it indicates that the urgent pointer field is valid. It tells the system that there is urgent data in this segment and should be transmitted as soon as possible (equivalent to high-priority data).
  • Confirmation ACK: The confirmation number field is valid only when ACK is 1; the confirmation number field is invalid when ACK is 0.
  • Push PSH (PuSH): When the receiving TCP receives a segment with PSH = 1, it will deliver it to the receiving application process as soon as possible, instead of waiting until the entire cache is full before delivering it upwards.
  • Reset RST (ReSeT): When RST=1, it indicates that a serious error has occurred in the TCP connection (eg, due to a host crash or other reasons), and the connection must be released and then the transport connection must be re-established.
  • Synchronous SYN: Synchronous SYN = 1 indicates that this is a connection request or connection acceptance message.
  • Terminate FIN (FINish): Used to release a connection. FIN=1 indicates that the data at the sending end of this segment has been sent and requests to release the transport connection.
  • Window: 16 bits, in bytes. Indicates the receiving window of the party sending this segment.窗口值作为接收方让发送方设置其发送窗口的依据。这是以接收方的接收能力来控制发送方的发送能力,称为流量控制。
  • Checksum: 16 bits, the scope of the checksum field check includes the header and data. When calculating the checksum, a 12-byte pseudo-header should be added in front of the TCP segment.
  • Urgent pointer: occupying 16 bits, in bytes, used to indicate the length of urgent data.
  • Options: variable length. TCP originally specified only one option, the maximum segment length MSS.
  • Padding: make the entire header length an integer multiple of 4 bytes.

3.4 Flow Control

  • Generally speaking, we always want data to be transferred faster. But if the sender sends the data too fast, the receiver may not have time to receive it, which will cause data loss.
  • Flow control (flow control) is to make the sending rate of the sender not too fast, so that the receiver can receive in time, and the network should not be congested.
  • Using the sliding window mechanism can easily implement flow control on TCP connections.

The initial receiving window of host A is 400. During the sending process, the data with serial number 201-300 is lost; the confirmation number in the message returned by host B is 201 (that is, the serial number of the message that has not been received), and Tell host A to adjust the receive window to 300.

insert image description here

After host A receives B's message, it adjusts the size of its receiving window, because host A has not received the acknowledgment message of 201-300 data, so the receiving window cannot continue to move forward. At this time, the data with serial numbers 301-500 can be sent to host B in the receiving window, and host B will save these data. After the retransmission timer expires, host A retransmits the data of 201-300, and when host B successfully receives the data of 201-300, it delivers the data of 201-500 to the upper layer for processing, and the confirmation number in the returned confirmation message is 501 , and tell host A to adjust the receiving window to 100.

insert image description here

3.5 Congestion Control

insert image description here

Causes of congestion:

insert image description here

insert image description here

The difference between congestion control and flow control:

insert image description here

The general principle of congestion control:

insert image description here

insert image description here

3.5.1 TCP congestion control method

insert image description here

The principle of controlling the congestion window:

  • As long as there is no congestion in the network, the congestion window can be increased to send more packets, thus improving the utilization of the network.
  • However, as long as the network is congested or may be congested, the congestion window must be reduced to reduce the number of packets injected into the network, so as to alleviate the network congestion.

Judgment of congestion:

  • Retransmission timer timed out: The network has been congested.
  • Received three repeated ACKs: It indicates that the network may be congested (congestion may not actually occur).

Four congestion control algorithms:

  • slow start
  • congestion avoidance
  • fast retransmit
  • fast recovery

insert image description here

insert image description here

Slow start phase:

  • When the host just starts to send the message segment, the congestion window cwnd can be set to the value of the maximum message segment MSS.
  • After each acknowledgment for a new segment is received, the congestion window is increased by at most one MSS value.
  • Using this method to gradually increase the congestion window cwnd at the sending end can make the rate at which packets are injected into the network more reasonable.

Congestion avoidance phase:

  • Additive increase: After performing congestion avoidance, when the confirmation of all segments is received, the congestion window cwnd will be increased by one MSS size, so that the congestion window will increase slowly to prevent premature network congestion.
  • Multiplicative reduction: It means that no matter in the slow start phase or the congestion avoidance phase, as long as a timeout occurs (that is, a network congestion occurs), the slow start threshold ssthresh is set to the current congestion window value multiplied by 0.5.
  • When the network is frequently congested, the ssthresh value drops quickly to greatly reduce the number of packets injected into the network.

insert image description here

insert image description here

insert image description here

insert image description here

3.6 Establishment and release of TCP connection

insert image description here

3.6.1 Establishing a connection

insert image description here

The establishment of the TCP connection adopts the client server method:

  • The application process that actively initiates connection establishment is called a client.
  • An application process that passively waits for a connection to be established is called a server.

The process of TCP establishing a connection is called handshaking. The handshake requires the exchange of three TCP segments between the client and server. call it 三报文握手(三次握手). The main purpose of using the three-message handshake is to prevent the invalid connection request segment from being transmitted suddenly, resulting in an error.

insert image description here

If there is no acknowledgment of the TCP connection request acknowledgment:

insert image description here

Notice:

  • The TCP standard stipulates that a segment with SYN=1 cannot carry data, but consumes a sequence number.
  • The TCP standard stipulates that if the ordinary confirmation segment does not carry data, the sequence number will not be consumed.

3.6.2 Release connection

After the data transmission is over, both communicating parties can release the connection. The TCP connection release process is a four-packet handshake.

insert image description here

Do I have to wait for the 2MSL time?

  • In order to ensure that the last ACK segment sent by the client can reach the server.
  • Prevent "invalid connection request segment" from appearing in this connection.

insert image description here

How to discover that the client fails?

insert image description here

Guess you like

Origin blog.csdn.net/weixin_46003347/article/details/123999706