这章主要还是基础知识的介绍,更加详细的介绍TCP/IP相关协议。
经典的TCP header构成剖析。需要注意的就是header len只有4bits,因此最长支持60B(15*4B)
Src port: 16bits Dst port: 16bits
Seq num: 32bits
Ack num: 32bits
Header len: 4bits Unused: 6bits Flags: 6bits
Rwnd: 16bits
Check sum: 16bits Urgent pointers: 16bits
TCP Options (RFC 1323)
标准的option格式: Kind(1B) | Len(1B) | Value(Variable length)
常见option:
1. End of Option List: | kind = 0 |
2. No operation: | kind = 1 | <== 用于内存对齐
3. MSS: | kind = 2 | length = 4 | mss = 2B |
4. Window-Scaling: | kind = 3 | length = 3 | left shift count = 1B |
5. SACK-permit: | kind = 4 | lenght = 2 |
6. SACK: | kind = 5 | length = variable | Start = 4B | End = 4B | ...
7. Timestamp: | kind = 8 | length = 10| TS = 4B | TS echo = 4B |
书中较大的篇幅介绍了TCP的ACK机制,这里正常的ACK就不展开了,而是更关注书中提到的Delayed ACK和Nagle算法.前者通过在ACK包中携带数据避免small ack packet,后者是为了进一步避免发送数据太少导致small packet。
Nagle's algorithm: all the data that need to be sent out are
collected until the time we receive an ACK for the last sent data.
Sliding Window 机制就是rwnd的限制导致的,rwnd的存在是为了做flow control。另外cwnd的存在则是为了做congestion control。
TCP Timers是一个很重要的部分,常见的计时器有一下几种:
1. Retransmission Timer: 如果一个包在该计时器超时之前都没有收到ACK,则触发超时重传
2. Persistent Timer: 为了应对rwnd=0后,接收方发送通知rwnd>0的包丢失的情况。
具体就是发送发使用指数规避的方式增加persistent timer,
每次timer结束的时候发送一个不带数据的包试探对方的rwnd.
3. Keepalive Timer: 看名字就理解了,不解释
4. TIME_WAIT Timer: TCP状态转换机制中的一个重要结束状态
FACK如果启用,则认为SACK数据块之间空隙的包都丢失了,默认开启;DSACK是SACK的一个扩展。
DSACK is generated when both the original and retransmission
reach the receiver. This gives us an indication that we have
falsely entered into the fast retransmission and fast recovery
phase because the packet got delayed in the network or because
of excessive reordering.
IP及以下层相关的内容暂忽略。