2016年3月28日 星期一

TCP RTO計算方式




When TCP sends a segment it maintains a timer, waiting for the other end to acknowledge reception of the segment. If an acknowledgment isn't received in time, the segment is retransmitted.


這個timer 就是RTO (Retransmission TimeOut) ,它的時間並不是固定的, 而是依當下的網路擁塞程度做動態的調整。


To compute the current RTO, a TCP sender maintains two state variables, SRTT (smoothed round-trip time) and RTTVAR (round-trip time variation).

init : RTO=3 秒

1) 取得第一個RTT後, RTO 計算如下

SRTT <- R
RTTVAR <- R/2 
RTO <- SRTT + max (G, K*RTTVAR)

其中 K = 4 , clock granularity of G seconds. (G: 100ms~500ms )

2) 之後每收到一個RTT,  RTO 計算如下

RTTVAR <- (1 - beta) * RTTVAR + beta * |SRTT - R'|
SRTT <- (1 - alpha) * SRTT + alpha * R'
RTO <- SRTT + max( G, K * RTTVAR )
其中 alpha = 1/8, beta = 1/4,
若 RTO小於1s, 則進位至1秒


When segment 4 is transmitted 2.4 ms later, it cannot be timed, since the timer for this connection is already in use. 


  1. 在TCP中,同一時間下只能處理一個 RTT 的量測程序。
  2. Retransmission Timer只有一組
  3. 有重送(retransmit)過的封包的RTT不可以拿來計算, 因為沒有辦法知道所收到的確認封包(Ack) 第一次送出的封包回覆的還是重送的封包回覆的
https://tools.ietf.org/html/rfc2988
   (5.1) Every time a packet containing data is sent (including a
         retransmission), if the timer is not running, start it running
         so that it will expire after RTO seconds (for the current value
         of RTO).
         每次送出封包,若當時timer沒啓動,則要啓動

   (5.2) When all outstanding data has been acknowledged, turn off the
         retransmission timer.
         若送出的全都封包, 已全部都有ACK回來, 關閉 timer
(5.3) When an ACK is received that acknowledges new data, restart the retransmission timer so that it will expire after RTO seconds (for the current value of RTO).
        若有ACK回來是回應新封包 (即非dup ACK), 則 timer須更新,使得再經過RTO秒後會發生timeout


   When the retransmission timer expires, do the following:
   (5.4) Retransmit the earliest segment that has not been acknowledged
         by the TCP receiver.
        timeout 發生了, 把Window還沒被ACK的(Outstanding Packet)全部重送
            

   (5.5) The host MUST set RTO <- RTO * 2 ("back off the timer").  The
         maximum value discussed in (2.5) above may be used to provide an
         upper bound to this doubling operation.
          把RTO乘以2 (RTO <- RTO * 2 )

   (5.6) Start the retransmission timer, such that it expires after RTO
         seconds (for the value of RTO after the doubling operation
         outlined in 5.5).
      timer再重新啓動,使得再經過RTO秒後會發生timeout

例子, 


當SYN區段傳送出去時,RTTM、RTTS、及 RTTD 尚未有值,而 RTO 的值被設定為 3 秒。

2.當SYN+ACK區段抵達,其 R 被量測後為 1.5 秒,其變數的值如下所示:


R = 1.5
SRTT = 1.5
RTTVAR = 1.5 / 2 = 0.75 
RTO = 1.5 + 4 . 0.75 = 4.5



3.當第一個資料區段傳送出去時,一個新的 RTT 量測程序被啟動。請注意,當傳送端傳送ACK區段時並不會啟動 RTT 量測程序,因為它不會消耗序號也不會啟動計時器。第二個資料區段也不會啟動 RTT 量測程序,因為已經有一個量測程序正在進行中。最後一個ACK區段的抵達被用來計算下一個 RTTM 的值。儘管最後一個ACK區段是用來回應兩個資料區段 ( 累計式 ),它的抵達完成了第一個區段之R的值。其變數的值如下所示:


RTT = 2.5
SRTT = 7/8 (1.5) + 1/8 (2.5) = 1.625
RTTVAR = 3/4 (0.75) + 1/4 |1.625 − 2.5| = 0.78
RTO = 1.625 + 4 (0.78) = 4.74


沒有留言 :

張貼留言