## 4 Congestion Control Based on the RED Algorithm  
### Principle of the CRED Algorithm  
The random early detection (RED) algorithm, widely used in network routers and switches, is a network traffic management algorithm for congestion control. Key parameters of the RED algorithm include minimum and maximum thresholds. When the number of packets in the queue is below the minimum threshold, no packets are dropped. When the number of packets is between the minimum and maximum thresholds, packets are dropped probabilistically based on a certain probability. When the number of packets in the queue exceeds the maximum threshold, more packets are discarded. It is important to note that the RED algorithm is a passive congestion control mechanism. It takes action only when network congestion has already occurred, rather than actively predicting and avoiding congestion. Therefore, in practical networks, it is common to combine other congestion control algorithms (such as TCP congestion control) to provide better performance and stability. The RED algorithm is designed to overcome the global synchronization issue inherent in traditional TCP congestion control algorithms and alleviate biases against burst traffic. To comprehend the subsequently improve the model, it is essential to grasp the underlying principles of the original RED algorithm [29]. The core of the RED algorithm comprises two main components: calculating the average queue length in routers and determining the packet drop probability [30]. (1) Calculate the average queue length  
\[\text{avg}=(1-\text{Wq})\times\text{avg}+\text{Wq}\times\text{Lsamp} \tag{4}\]  
where avg represents the average length of the weighted dynamic queue. Wq is the weight factor that represents the weight of the latest sample. It typically ranges from 0 to 1. Lsamp represents the current length of the queue. This formula calculates the average length of the weighted dynamic queue by performing a weighted average between the length of the latest sample and the previous average length. The weight factor Wq determines the influence of the latest sample, with larger weights giving more importance to the latest sample, while smaller weights provide a more averaged result. Weighted dynamic averaging analyses congestion by measuring the queue length over a specific period, rather than relying on the instantaneous queue length. This approach provides a more comprehensive understanding of congestion and its fluctuations, as illustrated in Figure 3.  
(2) How to discard packets  
The RED algorithm utilizes minimum minth and maximum threshold maxth values as benchmarks to determine the appropriate handling of incoming packets [31]. Additionally, a discard probability \(P\) is established. The following rules outline the specific guidelines:  
If avg \(\leq\min_{\text{th}}\), there is no packet processing and arrival is normal. When the number of packets in the queue is below the minth, no packet loss occurs;  
Figure 3: Average length of a weighted dynamic queue. If \(\max_{\text{th}}\leq\text{avg}\), all incoming packet data is discarded. When the number of packets in the queue surpasses \(\max_{\text{th}}\), a greater number of packets are discarded;  
If \(\min_{\text{th}}<\text{avg}<\max_{\text{th}}\), packets are discarded according to the discard probability \(P\). The discard probability \(P\) determines how packets are discarded. The schematic diagram illustrates the relationship between the discard probability \(P\) and the average length of packets. (3) Calculate discarding probability  
As mentioned above, the RED algorithm assigns a dropping probability \(P\) to the router when the average length of packets falls within the range of the minimum and maximum thresholds [32]. This allows the router to make informed decisions on packet dropping based on the assigned probability.