TCP服务必须能够重传超时时间内未收到确认的TCP报文段。为此,TCP模块为每个TCP报文段都维护一个重传定时器,该定时器在TCP报文段第一个被发送时启动。如果超时时间内未收到接收方的应答,TCP模块将重传TCP报文段并重置定时器。至于下次重传的超时时间如何选择,以及最多执行多少次重传,就是TCP的重传策略。
我们在10.0.0.199上启动iperf服务器程序:

在10.0.0.200上执行telnet命令登录该服务器程序。接下来从客户端发送一些数据,列如说”1234“给服务器,然后断开服务器的网线并再次从客户端发送一些数据给服务器,列如说“12”。同时用tcpdump抓取这一过程中客户端和服务器交换的TCP报文段。

iperf是一个测试网络状况额工具, -s选项表明将其作为服务器运行。iperf默认监听5001端口,并将丢弃该端口上接收到的所有数据,相当于一个discard服务器。

10:51:31.893687 IP 10.0.0.200.50526 > 10.0.0.199.5001: Flags [S], seq 2771493100, win 64240, options [mss 1460,sackOK,TS val 2430561549 ecr 0,nop,wscale 7], length 0
10:51:31.894259 IP 10.0.0.199.5001 > 10.0.0.200.50526: Flags [S.], seq 3253025746, ack 2771493101, win 65160, options [mss 1460,sackOK,TS val 3111943303 ecr 2430561549,nop,wscale 7], length 0
10:51:31.894334 IP 10.0.0.200.50526 > 10.0.0.199.5001: Flags [.], ack 1, win 502, options [nop,nop,TS val 2430561550 ecr 3111943303], length 0
10:51:40.678329 IP 10.0.0.200.50526 > 10.0.0.199.5001: Flags [P.], seq 1:7, ack 1, win 502, options [nop,nop,TS val 2430570334 ecr 3111943303], length 6
10:51:40.678784 IP 10.0.0.199.5001 > 10.0.0.200.50526: Flags [.], ack 7, win 510, options [nop,nop,TS val 3111952087 ecr 2430570334], length 0
10:52:06.810346 IP 10.0.0.200.50526 > 10.0.0.199.5001: Flags [P.], seq 7:11, ack 1, win 502, options [nop,nop,TS val 2430596465 ecr 3111952087], length 4
10:52:07.016883 IP 10.0.0.200.50526 > 10.0.0.199.5001: Flags [P.], seq 7:11, ack 1, win 502, options [nop,nop,TS val 2430596671 ecr 3111952087], length 4
10:52:07.225083 IP 10.0.0.200.50526 > 10.0.0.199.5001: Flags [P.], seq 7:11, ack 1, win 502, options [nop,nop,TS val 2430596879 ecr 3111952087], length 4
10:52:07.652886 IP 10.0.0.200.50526 > 10.0.0.199.5001: Flags [P.], seq 7:11, ack 1, win 502, options [nop,nop,TS val 2430597307 ecr 3111952087], length 4
10:52:08.484902 IP 10.0.0.200.50526 > 10.0.0.199.5001: Flags [P.], seq 7:11, ack 1, win 502, options [nop,nop,TS val 2430598139 ecr 3111952087], length 4
10:52:10.149013 IP 10.0.0.200.50526 > 10.0.0.199.5001: Flags [P.], seq 7:11, ack 1, win 502, options [nop,nop,TS val 2430599803 ecr 3111952087], length 4
10:52:13.444994 IP 10.0.0.200.50526 > 10.0.0.199.5001: Flags [P.], seq 7:11, ack 1, win 502, options [nop,nop,TS val 2430603099 ecr 3111952087], length 4
10:52:20.101008 IP 10.0.0.200.50526 > 10.0.0.199.5001: Flags [P.], seq 7:11, ack 1, win 502, options [nop,nop,TS val 2430609755 ecr 3111952087], length 4
10:52:33.413007 IP 10.0.0.200.50526 > 10.0.0.199.5001: Flags [P.], seq 7:11, ack 1, win 502, options [nop,nop,TS val 2430623067 ecr 3111952087], length 4
10:53:01.317119 IP 10.0.0.200.50526 > 10.0.0.199.5001: Flags [P.], seq 7:11, ack 1, win 502, options [nop,nop,TS val 2430650970 ecr 3111952087], length 4
TCP报文段的前个是三次握手建立连接的过程,第四和第五是客户端发送数据“1234”(应用程序数据长度为6,包括回车、换行两个字符,后同)及服务器确认的过程。
从第六个报文段开始是客户端第一次发送数据“12”的过程,由于服务器的网线被断开,所以客户端无法收到TCP报文段6的确认报文段。观察TCP接下来报文段的发送时间间隔,它们分别是:
0.2s,0.4s,0.8s,1.6s,3.2s,6.4s,12.8s,35.6s。
由此可见,TCP报文段一共执行了9次重传,每次重传超时时间都增加一倍。

上图中,前者指定的是底层IP接管之前TCP最少执行的重传次数,默认值是3.
后者指定链接放弃前TCP最多可以执行的冲传次数,默认值是15(一般对应13~30min)。


