Computer network—4 transport layers (TCP connection management, flow control, congestion control)

table of Contents

One, TCP connection management

    1. TCP connection establishment (three-way handshake to establish a connection)

    2. TCP connection release (four-way handshake to release the connection)

    3. Summary of connection establishment and release

Two, TCP flow control

Three, TCP congestion control

    1. Slow start and congestion avoidance

    2. Fast retransmission and fast recovery

    3. Other


One, TCP connection management

1. TCP: Connection-oriented protocol.

2. A TCP connection has 3 stages: connection establishment, data transmission, and connection release.

3. During the TCP connection establishment process, there are 3 problems to be solved:

  • 1) To enable each party to notify the other party's existence
  • 2) To allow both parties to negotiate some parameters (such as the maximum window size... etc.)
  • 3) Ability to allocate transportation entity resources (such as cache size... etc.).

4. Each TCP connection is uniquely determined by two endpoints (ie, two sockets) at both ends of the communication.

5. Definition of some fields

  • Sequence number field . Accounted for 4B, TCP is byte-oriented (that is, it is transmitted byte by byte when TCP is transmitted), so each byte in the data stream transmitted by the TCP connection is assigned a serial number. The value of the sequence number field refers to the sequence number of the first byte of the data sent in this segment . For example, the sequence number field value of a message segment is 301, and the data carried is 100B, indicating that the sequence number of the last byte of the data of this message segment is 400, so the data sequence number of the next message segment should start from 401.
  • Confirmation number field . Accounted for 4B, it is the sequence number of the first byte expecting 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 have been received correctly.
  • Acknowledge bit ACK . The confirmation number field is valid only when ACK=1. When ACK=0, the confirmation number is invalid. TCP stipulates that ACK must be set to 1 in all message segments transmitted after the connection is established.
  • Synchronization bit SYN , synchronization SYN=1 means this is a connection request or connection reception message . When SYN=1 and ACK=0, it indicates that this is a connection request message. If the other party agrees to establish a connection, SYN=1 and ACK=1 are used in the response message. That is, SYN=1 means that this is a connection request or connection reception message.
  • The termination bit FIN (Finish) is 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.

 

1. TCP connection establishment (three-way handshake to establish a connection)

      

The process of TCP connection establishment is usually called a three-way handshake.

first step:

  • The client's TCP first sends a connection request segment to the server's TCP
  • This special message segment does not contain application layer data. SYN flag = 1 , the client will randomly select a starting sequence number seq=x
  • (The connection request message does not carry data , but it consumes a serial number )

The second step:

  • After the server's TCP receives the connection request segment, if it agrees to establish a connection, it sends back an acknowledgement to the client, and allocates TCP buffers and variables to the TCP connection.
  • In the confirmation message segment, SYN bit=1 , ACK bit=1 , the value of the confirmation number field is x+1 , and the server randomly generates the starting sequence number seq=y
  • (The confirmation message does not carry data , but it also consumes a serial number )

third step:

  • When the client receives the confirmation message segment, it must give a confirmation to the server, and also allocate buffers and variables to the connection.
  • In this segment, the ACK bit=1 , the sequence number field=x+1 , and the confirmation number field=y+1 .
  • The message segment can carry data, if it does not carry data, the sequence number is not consumed.

After successfully performing the above three steps, a TCP connection is established, and then application layer data can be transmitted. TCP provides full-duplex communication, so the application processes on both sides of the communication can send data at any time.

In addition, it is worth noting that the resources on the server side are allocated when the second handshake is completed, while the resources on the client side are allocated when the third handshake is completed, which makes the server vulnerable to SYN flooding attacks.

 

2. TCP connection release (four-way handshake to release the connection)

Either of the two processes participating in the TCP connection can terminate the connection.

The process of TCP connection release is usually called a four-way handshake.

    

 

3. Summary of connection establishment and release

 

Two, TCP flow control

TCP provides flow control services to eliminate the possibility of the sender overflowing the receiver's buffer . (So ​​it can be said that flow control is a speed matching service that matches the sending rate of the sender with the reading rate of the receiver .)

TCP提供流量控制服务来**消除发送方使接收方缓冲区溢出的可能性**。
(因此可以说流量控制是一个速度匹配服务,匹配发送方的发送速率与接收方的读取速率。)

发送方**不能发送太多、太快的数据让接收方缓冲区溢出**。

 TCP提供一种基于滑动窗口协议的流量控制机制,TCP使用**滑动窗口机制**来实现流量控制。

 1)谁控制谁?流量控制是为了控制发送方发送速率保证接收方来得及接收。

 2)怎样控制?接收方发送的确认报文中的窗口字段可以用来控制发送方窗口大小,从而影响发送方地发送速率。将窗口字段设置位0,则发送方不能发送数据。

 

Three, TCP congestion control

拥塞控制:是指**防止过多的数据注入网络,保证网络中的路由器或链路不致过载**。

拥塞控制和流量控制的**相似之处**:它们都通过控制发送方发送数据的速率来达到控制效果。

拥塞控制与流量控制的**区别**:
拥塞控制是让网络能够承受现有的网络负荷,是一个全局性的过程,涉及所有的主机、所有的路由器,以及与降低网络传输性能有关的所有因素。
相反,流量控制往往是指点对点的通信量的控制,即接收端控制发送端,它所要做的是抑制发送端发送数据的速率,以便使接收端来得及接收。

**流量控制**是为了**让接收方能来得及接收**,而**拥塞控制**是为了**能降低整个网络的拥塞程度**。(!)


例如,某个链路的传输速率为10Gb/s,某巨型机向一台PC以1Gb/s的速率传送文件,
显然网络的带宽是足够大的,不存在拥塞问题,但如此高的发送速率将导致PC可能来不及接收,因此必须进行**流量控制**。
但若有100万台PC在此链路上以1Mb/s的速率传送文件,则现在的问题就变为网络的负载是否超过了现有网络所能承受的范围。

 

In order to better control congestion at the transport layer , the Internet Recommendation Standard defines the following four algorithms :

  • Slow start
  • Congestion avoidance
  • Fast retransmission
  • Quick recovery

 

When determining the rate of sending message segments, the sender must not only consider the receiving capability of the receiver, but also consider not congesting the network from the overall perspective.

Therefore, the TCP protocol requires the sender to maintain the following two windows :

  • 1) The receiving window rwnd , the receiving party reflects the capacity of the receiving party according to the latest window value promised by the current receiving buffer size . The receiver informs the sender based on the window field placed in the header of the TCP message.
  • 2) 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 . As long as there is no congestion in the network, the congestion window is increased a bit to send more packets. But 1 as long as the network is congested, the congestion window is reduced to reduce the number of packets injected into the network.

The upper limit should be taken transmitting window and a receiving window, the congestion window cwnd rwnd smaller, i.e., the upper limit of the transmission window = min [rwnd, cwnd]

 

The size of the receiving window can be notified to the sender according to the window field in the header of the TCP message, and how does the sender maintain the congestion window ? This is the slow start and congestion avoidance algorithm explained below.

 

1. Slow start and congestion avoidance

  • Slow start: The congestion window cwnd increases exponentially, multiplied by 2 each time.

    When cwnd reaches the slow start threshold ssthresh (threshold), the congestion avoidance algorithm starts

  • Congestion avoidance:
    • The congestion window cwnd increases linearly, increasing by 1 each time. ( That is, the addition increases )
    • When a timeout occurs (network congestion), make the slow start threshold ssthresh equal to half of the current cwnd . ( That is, the multiplication is reduced ), the congestion window cwnd is set to 1

 

2. Fast retransmission and fast recovery

  • When 3 repeated confirmations are received continuously , the fast retransmission and fast recovery algorithms are executed.
  • Quick recovery:
    • When letting receives 3 repeated confirmations in succession , the slow start threshold ssthresh is equal to half of the current cwnd . ( That is, the multiplication is reduced ), the value of cwnd is set to the value after the slow start threshold ssthresh is changed (this is different from the slow start algorithm).
    • Then start to execute the congestion avoidance algorithm, adding 1 each time. ( That is, the addition increases )

 

    1) When the sender detects a timeout , it uses slow start and congestion avoidance ;

    2) When the sender receives 3 redundant ACKs ( 3 repeated acknowledgments ), fast retransmission and fast recovery are used .

      The actual size of the transmitting window (jointly decided by the traffic control and congestion control) = the receiving side window and the congestion window in that a smaller

 

3. Other

How does the sender perceive network congestion?

  • Lost event (packet loss) = timeout or 3 repeated ACKs
  • After a loss event occurs, the TCP sender reduces the rate (congestion window)
     

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_39450145/article/details/112675390