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.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!