Thumbnail: logo

TCP congestion avoidance in a nutshell

by on under blog

TCP is well known to offer more reliability than the any protocol and employs it throughout many different mechanisms. Congestion Avoidance is obtained by Flow Control and Congestion Control, and their respective “windows”.

_Flow Control _has the goal to adjust the amount of flow received by a TCP speaker: an end host dictates how much traffic a sender can send to him, in order to avoid potential memory buffer shortage.

This feature is implemented through the use of the Receive window (rwnd)  which states the amount of data that can be transmitted without expecting an ACK. The receive window size is imposed by the OS and is dynamically changed according to the number of TCP flows and available memory. TCP RFCs don’t stipulate any default value for this, and so every OS has its own different one (which can be used as a trace for OS fingerprinting).

However problems occur as well inside a high subscribed network path,  and that is where Congestion Window _(cwnd) comes to the aid. While the _rcwd is a value handled exclusively by the TCP flow receiver and dependable to its local system resources, on the other hand, the cwnd size relies on external events such ACKs, timers and Explicit Congestion Notification (ECN).

If an outgoing interface buffer is full, a router can decide to drop the packet or, instead, adopt an Active Queue Management algorithm (like WRED) and transmit the datagram with a CE (Congestion Experienced) value into the IP header. CE is set by using the last two bits of the ToS byte, in addition to the six used by the DSCP field [see RFC3168].

Upon reception of IP data marked with CE, A TCP receiver will echo back the reported congestion by including into the TCP header an ECE flag  [_ECN-Echo, RFC5681]. _Once the TCP sender gets an incoming ECN flag, it will change its congestion window value as it was for a dropped packet.

ECN is an optional enhancement in addition to the regular TCP congestion avoidance algorithm, by letting layer 3 devices participate actively in the data loss prevention and as you may expect, ECN can be the most effective only if the whole network path is AQM enabled.



© 2018 Matteo Malvica. Illustrations by Sergio Kalisiak.