免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2107 | 回复: 1
打印 上一主题 下一主题

TCP Timestamp选项 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-01-12 13:52 |只看该作者 |倒序浏览
TCP Timestamp选项






Description

        Protocol suite: TCP/IP.

        Protocol type: Transport layer protocol.

        Option length: 10 bytes.

The TCP Timestamp option obsoletes the TCP Echo request and Echo reply options.

RFC 1323:

        The timestamps are used for two distinct mechanisms: RTTM (Round Trip Time Measurement)

and PAWS (Protected Against Wrapped Squences).



结构图






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.

Linux内核中的使用

如果支持Timestamp选项,那么可以用此选项来计算RTT。

[java] view plaincopyprint?
  1. static void tcp_ack_saw_tstamp(struct sock *sk , int flag)  
  2. {  
  3.         /* RTTM Rule: A TSecr value received in a segment is used to
  4.          * update the averaged RTT measurement only if the segment
  5.          * acknowledges some new data, i.e., only if it advances the
  6.          * left edge of the send window.
  7.          *  
  8.          * Changed: reset backoff as soon as we see the first valid
  9.          * sample. If we do not, we get strongly overestimated rto.
  10.          * With timestamps samples are accepted even from very
  11.          * old segments: f.e., when rtt=1 increases to 8, we retransmit
  12.          * 5 times and after 8 seconds delayed answer arrives rto
  13.          * becomes 120 seconds!  
  14.          */  
  15.          struct tcp_sock *tp = tcp_sk(sk);  
  16.          tcp_valid_rtt_meas(sk, tcp_time_stamp - tp->rx_opt.rcv_tsecr);  
  17. }  
  18. static void tcp_ack_saw_tstamp(struct sock *sk , int flag)
  19. {
  20.         /* RTTM Rule: A TSecr value received in a segment is used to
  21.          * update the averaged RTT measurement only if the segment
  22.          * acknowledges some new data, i.e., only if it advances the
  23.          * left edge of the send window.
  24.          *
  25.          * Changed: reset backoff as soon as we see the first valid
  26.          * sample. If we do not, we get strongly overestimated rto.
  27.          * With timestamps samples are accepted even from very
  28.          * old segments: f.e., when rtt=1 increases to 8, we retransmit
  29.          * 5 times and after 8 seconds delayed answer arrives rto
  30.          * becomes 120 seconds!
  31.          */
  32.          struct tcp_sock *tp = tcp_sk(sk);
  33.          tcp_valid_rtt_meas(sk, tcp_time_stamp - tp->rx_opt.rcv_tsecr);
  34. }
复制代码
rtt即等于现在的时间tcp_time_stamp减去Timestamp Echo Reply,即tp->rx_opt.rcv_tsecr。

论坛徽章:
0
2 [报告]
发表于 2012-01-12 13:54 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP