TCP congestion avoidance mechanisms determine methods by which a source adjusts its window size according to network conditions. Although network calculus has been utilized to study window flow control, the use of network calculus to determine an optimal window controller and to provide analytical guidance to TCP congestion avoidance has persisted as an open problem. For the first time within a network calculus setting, we determine an optimal window size control method for general flow control problems. We also show that the basic TCP congestion avoidance mechanisms in TCP Vegas, Enhanced TCP Vegas and Fast TCP can be viewed as different approaches to approximating the optimal NC controller, with each TCP variant making different assumptions in terms of parameter estimation and control implementation strategy. Therefore, the network calculus controller reveals the inherent underlying structure in TCP congestion avoidance. Furthermore, we demonstrate through ns-2 simulations that an approximation of a particular NC controller achieves performance gains in terms of link throughput and source node throughput fairness with respect to TCP Vegas, Enhanced TCP Vegas and Fast TCP.