Computer network-3 transport layer

Coming this week, the third chapter of the book "Self-Calculating Network From Top to Down" is the study of the transport layer.

The relationship between the transport layer and the network layer

In the protocol stack, we all know that the transport layer is above the network layer. The network layer provides communication between hosts, while the transport layer provides logical communication between different processes located on the host.

Multiplexing and demultiplexing

First of all, we need to make it clear that a process has one or more sockets, which is equivalent to a portal for transferring data from the network to the process and from the process to the network. The transport layer on the receiving host does not actually hand the datagram directly to the process, but hands the datagram to an intermediate socket.
Now we can consider how the receiving host transmits a transport layer segment to the appropriate socket. For this purpose, there are several fields in the segment of each transport layer. The transport layer at the receiving end checks these fields to indicate that the data is directed to the specified socket. The correct delivery of the transport layer segment to the socket is called demultiplexing .
Correspondingly, the source host collects data blocks from different sockets, and encapsulates the header information to generate a message segment for each data block, and then transfers this message segment to the network layer. All these tasks are called multiplexing .

How to direct the message segment identification to the corresponding socket in the host is identified by the port number .
Summary: Each socket on the host can be assigned a corresponding port number. When the message segment reaches the host, the transport layer checks the destination port number in the message segment and directs it to the corresponding socket. Finally, it enters the connected process through the socket.

Connectionless transmission: UDP

The UDP protocol is a transmission that does not need to establish a connection, that is, it does not need a three-way handshake. It is an unreliable transmission and does not provide congestion control.

All UDP-based application clients have no flow control, which may exhaust the entire link traffic bandwidth. The high packet loss rate of other UDP clients may also make TCP applications have no bandwidth available because of its congestion. Control will limit the sending of datagrams.

UDP provides a checksum to verify the correctness of a datagram. The reason for providing this method is that it cannot guarantee that all links between the source and the destination provide error checking; that is, there may be some of these links A protocol that uses no error checking. In addition, even if the message is correctly transmitted through the link, when the message segment is stored in the memory of a router, bit errors may be introduced. Therefore, UDP provides error checking at the transport layer on an end-to-end basis.

Principle of Reliable Data Transmission

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-UXIdZuiF-1579249553906)(http://media.coderluo.top/computer network/kj2u4.png)]

In the reliable transport protocol in order to improve the efficiency of the transmission line is generally used, i.e., without waiting for acknowledgment response, continue to send the next packet, two basic methods pipeline error recovery solution under the following record: Press Back-N (Go_Back_N, GBN) , and selection Retransmission (Selective Repeat, SR)

Back N steps

In the fallback N-step protocol, the sender is allowed to send multiple packets (when multiple packets are available) without waiting for confirmation, but it is also limited by the number of unconfirmed packets in the pipeline cannot exceed a certain maximum allowed Number N.

[External link image transfer failed. The origin site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-6OyeAfTd-1579249553908)(http://media.coderluo.top/computer network/k07p7.png)]

In the above figure, the sequence number range of the GBN protocol seen by the sender is shown. If we define the base sequence number (base) as the earliest unconfirmed group sequence number, and the next sequence number (nextseqnum) as the smallest unused sequence number (ie, the next group number to be sent), then the sequence number range can be divided into 4 segments:

  1. The sequence number in the [0,base-1] section corresponds to the packet that has been sent b and confirmed.
  2. The [base,nextseqnum-1] section corresponds to the packets that have been sent but not confirmed.
  3. The sequence number in the [nextseqnum,base+N-1] section can be used for those packets to be sent immediately, if there is data from the upper layer.
  4. Finally, a sequence number greater than or equal to base+N cannot be used until the unconfirmed packet in the current pipeline has been confirmed.

GBN protocol is also known as sliding window protocol

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-n6TPQiIa-1579249553909)(http://media.coderluo.top/computer network/csxo3.png)]

TCP connection

TCP is a full-duplex communication model, which is briefly summarized as shown in the figure below:
[External link image transfer failed, the source site may have an anti-leech link mechanism, it is recommended to save the image and upload it directly (img-0ghxgwEP-1579249553910)(http:/ /media.coderluo.top/computer network/a3e21.png)]

TCP segment structure

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-67cwIKbq-1579249553911)(http://media.coderluo.top/computer network/jl4qk.png)]

  1. Sequence number and confirmation number The
    most important fields in the header of a TCP message segment are sequence number and confirmation number. Because they are a key part of TCP's reliable transmission service.

TCP treats data as an unstructured, ordered stream of bytes. It needs to be emphasized here that the sequence number is based on the transmitted byte stream, not on the sequence of the transmitted message segment.

The number of a segment is the byte stream number of the first byte of the segment.

File data is divided into TCP message segments

The confirmation number is the sequence number of the next byte that the receiving host expects to receive from the sending host.

Reliable data transmission

After TCP sends the data, it assumes that the packet loss adopts cumulative acknowledgment. If the latter is confirmed, the previous unconfirmed are considered to have been received and will not be retransmitted.

TCP three-way handshake-message exchange

Close a TCP connection

Typical TCP state sequence experienced by client TCP

Typical TCP state sequence experienced by server TCP

TCP congestion control

TCP uses end-to-end congestion control instead of network-assisted congestion control, because the IP layer does not provide explicit network congestion feedback to the end system.

TCP congestion control algorithm:

  1. Slow start
  2. Congestion avoidance
  3. Fast recovery

Summary: TCP control is: cwnd in each RTT increases linearly (additive) by 1MSS, and then cwnd is halved (multiplicative subtraction) when there are 3 redundant ACK events. Thus, TCP congestion control is often called additive increase, multiplicative decrease congestion control.

TCP is very complex, it involves connection management (three handshake, four wave of hands), flow control (sliding window), round trip time estimation (RTT weighting), and reliable data transmission (acknowledgement, timer, retransmission and sequence number mechanism) )

Guess you like

Origin blog.csdn.net/taurus_7c/article/details/104021356