zoukankan      html  css  js  c++  java
  • TCP中RTT的测量和RTO的计算

    https://blog.csdn.net/zhangskd/article/details/7196707

    •   tcp传输往返时间是指:发送方发送tcp断开时, 到发送方接收到改段立即响应的所耗费的时间。

    (1)重传队列中数据包的TCP控制块
    在TCP重传队列中保存着发送而未被确认的数据包,数据包skb中的TCP控制块包含着一个变量,
    tcp_skb_cb->when,记录了该数据包的第一次发送时间。
    RTT = 当前时间 - when

    •   如果tcp支持时间戳选项。发送方可以再tcp option里面记录发送方发送的时间, 同时发送方记录在tcp opt选项的时间戳会被接收方反射回来, 这样就可以利用反射时间计算 往返RTT。

      (2)TCP Timestamp选项
    在前面的blog中有详细的介绍过这个选项,TCP时间戳选项可以用来精确的测量RTT。
    RTT = 当前时间 -  数据包中Timestamp选项的回显时间
    这个回显时间是该数据包发出去的时间,知道了数据包的接收时间(当前时间)和发送时间
    (回显时间),就可以轻松的得到RTT的一个测量值。

      每次确认都会产生一个RTT, 所以为了防止RTT随机抖动, 需要作出平滑处理。为了避免浮点运算,RTT---->SRTT = RTT << 3;

    发送方每接收到一个ACK,都会调用tcp_ack()来处理。
    tcp_ack()中会调用tcp_clean_rtx_queue()来删除重传队列中已经被确认的数据段。
    在tcp_clean_rtx_queue()中:
    如果ACK确认了重传的数据包,则不会更新;否则,seq_rtt = now - scb->when;
    然后调用 tcp_ack_update_rtt(sk, flag, seq_rtt_us, sack_rtt_us, ca_rtt_us);来更新RTT和RTO。

     Kind. 8 bits. Set to 8.
    Length. 8 bits. Set to 10.
    Timestamp Value (TSval). 32 bits.

    This field contains the current value of the timestamp clock of the TCP sending the option. TImestamp Echo Reply (TSecr). 32 bits.


    This field only valid if the ACK bit is set in the TCP header. If it is valid, it echos a timestamp value that was sent by the remote TCP in the TSval field of a Timestamps option. When TSecr is not valid,
    its value must be zero. The TSecr value will generally be from the most recent Timestamp option that was received; however, there are exceptions that are explained below. A TCP may send the
    Timestamp option in an initial SYN segment(i.e., segment containing a SYN bit and no ACK bit), and may send a TSopt in other segments only if it received a TSopt in the initial SYN segment for the connection.


  • 相关阅读:
    7.6实战练习
    构造方法的主要应用
    6.0字符串String
    数组冒泡排序
    数组(二维数组)
    5.1数组(一维部分)
    4个方位的三角形和菱形
    4.3循环语句
    控制台输入输出
    4 java语句 4.2条件语句
  • 原文地址:https://www.cnblogs.com/codestack/p/11919697.html
Copyright © 2011-2022 走看看