当前位置:网站首页>TCP retransmission mechanism, flow control, congestion control

TCP retransmission mechanism, flow control, congestion control

2020-12-06 16:36:47 byte

tcp

Retransmission mechanism

The way

  • Over time retransmission

    • Concept

      • Set a timer when sending data , If no reply message is received within the specified time , It's going to resend the data
    • The timing of the timeout retransmission

      • Packet loss
      • Confirm that the answer is missing
    • Timeout time RTO choice

      • a little bigger than RTT
      • Retransmission timeout policy : Double the timeout interval
  • The fast retransmission

    • Concept

      • The sender can send more than one packet at a time , If one of the packets in the middle is lost , The receiver will always reply to the lost packet reply message , If the receiver receives three replies to the packet , We know that the message has not been received by the receiver , This packet can be retransmitted
    • problem

      • Because the receiver also returns the lost reply message to the subsequent packet , So the sender doesn't know if the subsequent packets are lost , I don't know whether to retransmit the lost packets or retransmit all subsequent packets
  • SACK

    • Concept

      • Selective retransmission , The retransmission problem is not known
    • Realization way

      • stay tcp Head “ Options ” Add a... To the field SACK, Send cached map to sender , In this way, the sender knows which data receivers have received , What data has not been received by the receiver , In order to retransmit data not received by the receiver
    • Parameters

      • To turn on SACK, Need both sender and receiver to support :net.ipv4.tcp_sack,linux2.4 Open by default
  • D-SACK

    • Concept

      • Yes SACK An extension of , adopt SACK Tell the sender what data has been received repeatedly
    • Realization way

      • If there is a sender sending packets repeatedly , Will pass SACK Tell the sender that the packet has been sent
    • benefits

      • The sender can know whether the sent packet is lost or sent by the receiver ACK lost

        • SACK If you tell me that the packet has been sent , So the instructions are sent by the receiver ACK lost
      • The sender can know whether the packet is delayed by the network

        • The sender will resend the packet after the delay , If the previous packet arrives at the receiver after a period of time , The data packet has been received in the reply message returned by the receiver , It's a duplicate message , It's delayed by the network , The retransmitted packets have been received

Serial number and confirmation response (ACK) To ensure the tcp Reliable transmission of

The sliding window

The reason for introducing

  • Every time a data is sent, a confirmation response is required , Send the next one when you receive it , Low efficiency . Within the window size limit , You don't have to wait for the last packet to reply , You can continue to send the next packet

Error handling

  • Cumulative response

    • Packet loss

      • If the sender sends a batch of packets , A packet in the middle is missing , Then when the receiver replies ACK Will reply to the lost packet , In this way, the receiver knows which packet is missing , So you can resend ;
    • Response message lost

      • If the receiver returns a set of packets , A reply message is missing , As long as the last reply message is sent successfully , The receiver knows that the packet is actually received

Window size

  • tcp The field in the head window

    • Through this field, the receiver tells the receiver how many buffers it has left to receive data , The sender can send data according to the receiver's processing , In order to avoid the receiver can not handle , So the size of the window is determined by the receiver
  • Windows for the receiver and sender

    • The window size of the receiver and the sender is basically equal , Because the window size of the sender depends on the receiver , When the receiver has fast processing power , The window becomes larger , adopt tcp In the message window Field tells the receiver , If there is a delay in transmission , So the two windows are not the same size

Congestion control

Concept

  • Flow control is to prevent the sender from filling the receiver's cache , But if the network congestion is caused by the communication between other hosts , There will be timeout and packet loss , This will cause retransmission , The burden on the Internet will be greater , Enter a vicious circle , therefore tcp You can't ignore what's happening on the Internet , When the network is congested , It reduces the amount of data sent . The purpose of congestion control is to prevent the sender's data from filling the whole network

Congestion window cwnd

  • Send window swnd And receiving window rwnd It's about equal , With the concept of congestion window , Send window swnd=min(cwnd, rwnd)

    • There is no congestion in the network ,cwnd Will increase , On the contrary, it will decrease
  • How to judge network congestion

    • Timeout retransmission occurred
  • Related algorithms

    • Slow start

      • tcp Just set up the connection, done , There's going to be a slow start process , Bit by bit, increase the number of packets sent
      • Every time I receive one ack,cwnd The size will increase 1, On initialization ,cwnd The size is 1, namely cwnd The size grows exponentially
      • ssthreshold,slow start thresold, Slow start threshold

        • When cwnd < ssthreshold when , Will use slow start algorithm
        • When cwnd >= ssthreshold when , Will use congestion avoidance algorithm
    • Congestion avoidance

      • For every one received ack,cwnd increase 1/cwnd. That is, they hoard cwnd After so many bags , Send it all at once . And then it's sent like this ,cwnd Linear growth
      • When it's been growing like this , It's going to get into congestion , So packet loss began to appear , At this time, the lost data needs to be retransmitted , When the retransmission mechanism is triggered, the congestion generation algorithm is entered
    • Congestion occurs

      • Over time retransmission

        • ssthreshold Set to cwnd/2
        • cwnd Set to 1
        • In other words, once the timeout retransmission occurs, it will restart to slow start
      • The fast retransmission

        • When the receiver finds out that a tundish has been lost , It will send three lost packets ack, The sender will quickly retransmit the lost packet after receiving it
        • tcp I think the congestion is not serious at this time , Only a small part of the bag was lost , therefore

          • cwnd = cwnd/2
          • ssthreshold Turn into cwnd
        • Then go to the fast recovery algorithm
    • Fast recovery

      • cwnd = ssthresold+3
      • Retransmit lost packets
      • If you receive a duplicate ack, that cwnd+1
      • Receive new ack after ,cwnd Turn into ssthreshold, Then we enter the congestion avoidance algorithm

flow control

Concept

  • Flow control is based on sliding window ,tcp By having the receiver indicate the size of the data that you want to receive from the sender ( Window size ) To control the flow

problem

  • describe

    • The receiver received too much data , We can't receive data for now , So it goes back window The size is 0
    • The sender found window The size is 0, So we don't send packets anymore
    • The receiver has finished processing the data , We can continue to deal with , Then update the window size in the response message of the previously processed packet , But the reply message is missing , As a result, the receiver failed to receive , So no new packets are sent , There's a deadlock
  • resolvent

    • tcp Set a duration timer for each connection , Only the party initiating the connection receives a zero window notification from the other party , Just start the timer ; If the duration timer times out , The window probe message will be sent , The other party will give the size of the receiving window
    • The number of window probes is usually 3 Time , About every time 30-60 second , If the window is still 0, yes , we have tcp Implementation will initiate RST Message to interrupt connection

Confused window syndrome

  • The sender

    • The sender knows that the window is big , But only a small amount of data is sent each time
  • The receiving party

    • The receiver is too busy , You can only get it from window Very little data out of , Then inform the sender , In this way, the sender only sends a small amount of data at a time
  • problem

    • Every time it's just packets , Low efficiency
  • resolvent

    • Let the receiver not inform the sender of the small window

      • When the window size is less than min(mss,( Cache space /2)) when , The sender will be informed that the window is 0, Prevent the sender from sending data later

        • notes mss,Maximum Segment Size, Maximum message length ,MSS yes TCP Maximum length of data field in message segment , barring TCP The length of the head
    • Let the sender not send packets

      • Nagel Algorithm

        • Sending conditions

          • Wait until the window size >=mss Or data size >=mss
          • Send data before receiving ack The reply
        • Only two points that satisfy the sending condition will be sent
        • Set off

          • Nagel The algorithm is on by default , If you want to close , Need to be in socket Set up TCP_NODELAY To close . There are no global parameters , Each application needs to be closed according to its own characteristics

版权声明
本文为[byte]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/202012061634542349.html