Transport Layer

# TCP Congestion Control

TCP implements its own congestion control mechanism. To do that it needs an additional variable, the congestion-window $cwnd$, that limits the rate at which data can be sent on the network.

The protocol ensure that $LastByteSent-LastByteAcked \leq \min(rwnd, cwnd)$

If the sender was to send $cwnd$ byte of data, in the best case (where all segment are acknowledged) it will receive acknowledgments at a rate of $\frac{cwnd}{RTT}$. So by adjusting the $cwnd$ the sender can adjust the sending rate. If the rate at wich TCP receive acknowledgements it means that the network is congested and can decrease the sending rate.

TCP uses acknowledgement to trigger (to clock) its increase in congestion window size, so it’s said to be self-clocking. To choose the actual rate at which sending segment TCP utilize the following mechanism

### Slow Start

In the slow-start state, the value of $cwnd$ begins at 1 MSS (MaximumSegment Size) and increases it by 1 MSS every time a transmitted segment its first acknowledged. As soon a loss segment is detected the $cwnd$ increase should be stopped, the value $ssthresh_1 = \dfrac{cwnd}{2}$ is stored, sets back $cwnd = 1$ and the process starts again. On the next iteration, when $cwnd = ssthresh_1$ TCP enters in congestion avoidance.

### Congestion Avoidance

In the congestion avoidance state, rather than doubling $cwnd$ TCP increase it by 1 MSS every RTT. To do that it actually increases $cwnd$ by the amount $\dfrac{MSS}{cwnd}$ whenever an acknowledgement is received. When a packet loss is detected because of a timeout occur the new value $ssthresh_2$ is set to $\dfrac{cwnd}{2}$ and $cwnd$ is set to $1$ and TCP enter the slow start state again.

However, if the packet loss is detected because of a triple ACK, the protocol still sets $ssthresh_2 = \dfrac{cwnd}{2}$, it the sets $cwnd = ssthresh + 3 \cdot MMS$ (accounting for the corrected $3$ ACK received) and enters fast-recovery.

### Fast Recovery

In this state, TCP quickly retransmits the missing packet (fast-retransmit) that was signaled by three duplicate ACKs. Each time another duplicate ACK arrives (one specific to a packet belonging to the old transmit window that was previously received out-of order), it increases $cwnd$ by $1$ MSS. If there is no acknowledgment, TCP experiences a timeout and enters the slow start state.

On the other hand if it receives a new ACK (specific to a segments belonging to the new transmit window sent between the lost packet and the receipt of the first duplicate ACK), TCP exit fast recovery, sets $cwnd = ssthresh_2$ and enters congestion avoidance.

TCP’s congestion control consists of linear (additive) increase in $cwnd$ of 1 MSS per RTT and then a halving (multiplicative decrease) of $cwnd$ on a triple duplicate-ACK event. For this reason, TCP congestion control is often referred to as an additive-increase, multiplicative-decrease (AIMD) form of congestion control.