tcp.h中定义的5种状态:

状态机的具体实现在tcp_fastretrans_alert()函数中,每种状态转换的过程如下分析;

1、5种状态之间的转换

1)OPEN到其他状态的转换

This is the normal state in which the TCP sender follows the fast path of execution optimized for
the common case in processing incoming acknowledgements.
When an acknowledgement arrives, the sender increases the congestion window according to
either slow start or congestion avoidance, depending on whether the congestion window is
smaller or larger than the slow start threshold, respectively.

2)CWR到其他状态的转换

The TCP sender may receive congestion notification either by Explicit Congestion Notification,
ICMP source quench, or from a local device. When receiving a congestion notification, the Linux
sender does not reduce the congestion window at once, but by one segment for every second
incoming ACK until the window size is halved. When the sender is in process of reducing the
congestion window size and it does not have outstanding retransmissions, it is in CWR(Congestion
Window Reduced) state. CWR state can be interrupted by Recovery or Loss state.

 

3)DISORDER到其他状态的转换

When the sender detects duplicate ACKs or selective acknowledgements, it moves to the Disorder
state. In this state the congestion window is not adjusted, but each incoming packet triggers
transmission of a new segment. Therefore, the TCP sender follows the packet conservation
principle, which states that a new packet is not send out until an old packet has left the network.

4)RECOVERY状态

After a sufficient amount of successive duplicate ACKs arrive at the sender, it retransmits the first
unacknowledged segment and enters the Recovery state. By default, the threshold for entering
Recovery is three successive duplicate ACKs, a value recommended by the TCP congestion
control specification. During the Recovery state, the congestion window size is reduced by one
segment for every second incoming acknowledgement, similar to the CWR state. The window
reduction ends when the congestion window size is equal to ssthresh, i.e. half of the window
size when entering the Recovery state. The congestion window is not increased during the
recovery state, and the sender either retransmits the segments marked lost, or makes forward
transmissions on new data according to the packet conservation principle. The sender stays in
the Recovery state until all of the segments outstanding when the Recovery state was entered
are successfully acknowledged. After this the sender goes back to the Open state. A retrans-
mission timeout can also interrupt the Recovery state.

5)LOSS到其他状态的转换

When an RTO expires, the sender enters the Loss state. All outstanding segments are marked
lost, and the congestion window is set to one segment, hence the sender starts increasing the
congestion window using the slow start algorithm. A major difference between the Loss and
Recovery states is that in the Loss state the congestion window is increased after the sender
has reset it to one segment, but in the Recovery state the congestion window size can only be
reduced. The Loss state cannot be interrupted by any other state, thus the sender exits to the
Open state only after all data outstanding when the Loss state began have successfully been
acknowledged. For example, fast retransmit cannot be triggered during the Loss state, which
is in conformance with the NewReno specification.

 

2、状态改变与拥塞控制方法在协议栈中的调用位置

主要在tcp_ack,tcp_fastretrans_alert和重传定时器中被调用;

1)tcp_ack()

2)tcp_fastretrans_alert()

3)tcp_timer