Transport Layer Protocols UDP and TCP

Comparison of UDP and TCP:

UDP TCP

UDP is connectionless

UDP provides unreliable service

UDP supports both point-to-point and multipoint communication

UDP is packet oriented

UDP header 8 bytes

TCP is connection oriented

TCP provides reliable service

TCP can only communicate point-to-point

TCP is byte-oriented

TCP header 20 bytes

TCP connection management:

Connection establishment (three-way handshake):

Note: When the SYN and FIN of the TCP message header are set, a sequence number needs to be consumed, and the sequence number is not consumed when only the ACK is set.

Connection release (four-way handshake):

TCP reliable transmission

TCP is a reliable transport layer protocol, mainly through the confirmation mechanism and the supermarket retransmission mechanism to achieve reliable transmission.

Confirmation mechanism:

The establishment and release of the connection uses the confirmation mechanism.

TCP and acknowledgment are the highest sequence number received to indicate acknowledgment. But the returned confirmation sequence number is the highest sequence number of the received data plus one. That is to say, the confirmation sequence number indicates the sequence number of the data byte expected to be received next time. Confirmation has cumulative confirmation effect.

Timeout retransmission mechanism:

The most critical factor of the timeout retransmission mechanism is the timing setting of the retransmission timer, but it is quite difficult to determine the appropriate round-trip delay RTT.

TCP uses an adaptive algorithm. The algorithm idea is described as follows: record the time when each segment is sent and the time when the corresponding acknowledgment segment is received. The difference between these two times is the round-trip delay of the segment. The average round-trip delay RTT of each segment is obtained by weighting and averaging the round-trip delay samples of each segment.

  • RTT new value = RTT sample (first measurement)
  • RTT new value = α*RTT old value + (1-α)*new RTT sample

TCP has three types of timers: retransmission timer, persistence timer, and keepalive timer.

TCP flow control

Implemented by the receiver's receive window rwnd. During the communication process, the receiver can dynamically adjust its receiving window according to its own acceptance, and then tell the sender to make the sender's sending window consistent with its own receiving window.

TCP congestion control

The basic function of congestion control is to avoid network congestion. The congestion control mechanism of TCP/IP is mainly implemented at the transport layer. The precondition of congestion control is that the network can bear the existing network load.

Congestion control is implemented through the congestion window cwnd. Note: The value of the sending window is based on the smaller value of the congestion window and the receiving window, namely Min[rwnd,cwnd]. The principle that the sender controls the congestion window is: as long as the network is not blocked, the congestion window can be larger; but as long as there is congestion, the congestion window will be reduced.

For better congestion control, four techniques are used: slow start, congestion avoidance, fast retransmission, and fast recovery.

  • Slow start : When the TCP connection is just established or when the network congestion timeout occurs, the congestion window is set to a segment size, and when cwnd<=ssthresh, the cwnd is increased exponentially.
  • Congestion avoidance : When cwnd>=ssthresh, in order to avoid network congestion, the congestion avoidance algorithm is entered, and cwnd is increased linearly (one segment each time). When the network is congested, the threshold value ssthresh should be set to half of the sender's cwnd when congestion occurs (but not less than 2), and then reset the congestion window to 1 and execute the slow start algorithm.
  • Fast retransmission : If the sender receives three consecutive ACKs for the same segment, it immediately retransmits the segment without waiting for the retransmission timer to expire.
  • Fast recovery : When the fast retransmission algorithm is used, the congestion avoidance algorithm is directly executed. This can improve transmission efficiency.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325447835&siteId=291194637