Computer network study notes-transport layer

Transport layer

1. Services provided by the transport layer

1.1, the function of the transport layer

  1. The transport layer provides communication between processes (ie end-to-end communication)
  2. Multiplexing and demultiplexing
  3. Error detection (header and data part) , the network layer only performs header detection
  4. Provide two different communication protocols

1.2. Addressing and ports of the transport layer

Socket


2. UDP protocol

2.1, UDP datagram

UDP just adds two most basic services to the IP datagram service: multiplexing and demultiplexing, and error detection .

UDP provides best-effort delivery, that is, reliable delivery is not guaranteed, so the work of maintaining transmission reliability requires users to complete the application layer .

UDP is message-oriented . Complete a complete message at a time, and the message is the smallest unit of UDP transmission.

2.2, UDP header format

Insert picture description here

2.3, UDP verification

When calculating the checksum, a pseudo header of 12B should be added before the UDP datagram .

Throw it away if you make a mistake .


3. TCP protocol

TCP is a reliable data transmission protocol implemented on top of the unreliable IP layer. It mainly solves the problems of reliability, order, no loss and no duplication of transmission . Features:

  1. Connection-oriented
  2. Provide reliable delivery services;
  3. Full duplex communication, with sending buffer and receiving buffer;
  4. TCP is oriented towards byte streams.

3.1, TCP segment

The data unit transmitted by TCP is called a message segment . A TCP message segment is divided into two parts: TCP header and TCP data . The entire TCP segment is encapsulated in the IP datagram as the data part of the IP datagram. The 20B of the header is fixed .

Insert picture description here

Field name Number of digits Description
Source port number and destination port number 16 positions each Source port number and destination port number
Sequence number field seq 32nd place Each byte in the data stream transmitted by 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 segment
Confirmation number field ack 32nd place It is the sequence number of the first byte expected to receive the data of the next segment of the other party . If the confirmation number is N, it means that all data up to the sequence number N-1 has been received correctly
Data offset 4th It points out how far the data start of the TCP segment is from the start of the TCP segment
ACK First place The acknowledgment number field is valid only when ACK=1 . TCP stipulates that ACK must be set to 1 in all message segments transmitted after the connection is established.
Sync bit SYN First place Synchronous SYN=1 means that this is a connection request (SYN=1, ACK=0) or connection reception message (SYN=1, ACK=1)
Stop bit FIN First place Used to release a connection . FIN=1 indicates that the data of the sender of this segment has been sent, and the transmission connection is required to be released
Checksum 16th place Also add the pseudo header of 12B in front

3.2, TCP connection management

3.2.1, TCP connection establishment (three-way handshake)

Insert picture description here

  1. SYN=1 seq=x
  2. SYN = 1 ACK = 1 seq = y ack = x + 1
  3. ACK = 1 seq = x + 1 ack = y + 1

3.2.2, TCP connection release (four waves of hands)

Insert picture description here

  1. FIN=1 seq=u
  2. ACK = 1 seq = v ack = u + 1
  3. FIN = 1 ACK = 1 seq = w ack = u + 1
  4. ACK = 1 seq = u + 1 ack = w + 1

3.3, TCP reliable transmission

TCP uses mechanisms such as verification, sequence number, confirmation, and retransmission to ensure reliable transmission .

3.3.1, verification

Same as UDP

3.3.2, serial number

The sequence number field of the TCP header ensures that the data can be submitted to the application layer in an orderly manner. TCP treats the data as an unstructured but ordered byte stream, and the sequence number is established on the transmitted byte stream .

3.3.3, confirmation

The acknowledgment number of the TCP header is the sequence number of the first byte expecting to receive the data of the next segment of the other party .

TCP uses cumulative confirmation by default .

3.3.4, retransmission

Two events that cause TCP retransmission: timeout and (3) redundant ACKs .

3.4, TCP flow control

TCP provides a flow control mechanism based on a sliding window to eliminate the possibility of overflowing the receiver's buffer.

The receiver dynamically adjusts the size of the sender's sending window according to the size of its receiving buffer, which is called the receive window rwnd ; at the same time, the sender determines the window value based on its estimation of network congestion, which is called congestion Window cwnd . The sending window of the sender is usually equal to the minimum of rwnd and cwnd .

3.5, TCP congestion control

The TCP protocol requires the sender to maintain two windows:

Receive window rwnd : The latest window value promised by the receiver according to the current receiving buffer size, reflecting the receiver's capacity . The receiver informs the sender according to the window field placed in the header of the TCP message

Congestion window cwnd : The window value set by the sender according to the degree of network congestion estimated by the sender, reflecting the current capacity of the network.

The upper limit of the sending window should be the smaller of rwnd and cwnd, that is: the upper limit of the sending window=min[rwnd,cwnd]

3.5.1, slow start and congestion avoidance

Insert picture description here

3.5.2, fast retransmission and fast recovery

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_36879493/article/details/107836029