Open In App
Related Articles

Random Early Detection (RED) Queue Discipline

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

RED is among the first Active Queue Management (AQM) algorithms. RED was proposed in 1993 by Sally Floyd. RED is called by three different names; a.k.a Random Early Discard or Random Early Drop and Random Early Detection (so there are 3 possible full forms of RED). The main goal of RED is to:

  • Avoid congestion: Passive Queue Management suffers from this problem. AQM detects the congestion beforehand and avoids it.
  • Avoid the problem of global synchronization: Passive Queue Management suffers from this problem. AQM avoids this problem.
  • Avoid the problem of lockout: The short-lived flows suffer the problem of lockout when long-lasting flows occupy the buffers of routers all the time. AQM solves this problem, now short-lived flows can get space in the buffer.
  • Maximize the ‘Power’ function, which is the ratio of throughput to delay: AQM handles the buffer queue properly, therefore there will no packet loss, as a result, there will be no retransmission of packets. The flow will be fluent and the delay will be minimum.

Note: RED was proposed in 1993 and the term ‘Bufferbloat’ was coined in 2011. Still, AQM solves the problem of bufferbloat. Nevertheless, RED is considered suitable for resolving the issue of Bufferbloat because it controls the ‘queue length’ within specified thresholds. It never allows the buffer to fill completely. So, naturally, it is preventing the problem of bufferbloat. A lot of work has been done on this algorithm just like TCP. Several variants of RED have been proposed in the literature: Gentle RED, Nonlinear RED (NLRED), Adaptive RED (ARED), and many others.

Working of RED Algorithm:

RED operates during the ‘enqueue’ time. It works at the output port during enqueue time, do not confuse this with ‘input port’ in the router architecture. RED runs on the ‘output port’, but during the ‘enqueue’ time! RED operates ‘on the arrival of every packet’. Hence, there is no periodic time interval in which RED is invoked. If packets are arriving at a lower speed then RED is invoked at a lower speed. If packets do not arrive, RED algorithm is not invoked. RED decides whether the incoming packet should be enqueued or dropped. When a new packet arrives, RED makes a decision; whether this packet should be enqueued or dropped? It makes this decision even if there is space in the queue. It makes this decision because if enqueuing the packet increases overall delay or makes the queue full then it will cause the congestion to occur. If RED drops the packet before the queue is full then the sender will know about it indirectly and it will reduce its congestion window size and thus it avoids the congestion to happen in the future.

The RED algorithm contains the following components:

  • Calculation of average queue length.
  • Calculation of drop probability, whether the packet will be enqueued or dropped depends on this probability.
  • Decision-making logic (helps to decide whether the incoming packet should be enqueued or dropped).

Calculation of Average Queue Length:

On arrival of every packet, RED calculates the average queue length using Eq. (1). This mathematical model is known as ‘Exponential Weighted Moving Average’ or EWMA.

=> newavg = (1 – wq) x oldavg + wq x current_queue_len Eq. (1)

=> where, newavg = new average queue length being calculated in this sample

=> oldavg = old average queue length obtained during the previous sample

=> current_queue_len = ‘instantaneous’ queue length at the router

=> wq = weight associated with the ‘current_queue_len’. Default value: 0.002

Later on Sally Floyd, the author of RED made the wq variable adaptive. It was no longer the hard-coded value. But, here since we are discussing the original RED algorithm, its value is taken as 0.002.

Calculation of drop probability

Once the ‘newavg’ is calculated, RED uses the following logic to calculate the drop probability (Pd), where minth represents the minimum threshold for ‘average queue length’ and maxth represents the maximum threshold for ‘average queue length’. minth and maxth are in the context of average queue length, not the instantaneous queue length. This is an important takeaway before we go into further depth.

=> if (newavg ≤ minth)        // default value of minth in the paper is 5 packets 

=> enqueue the incoming packet  // it means Pd= 0

=> else if (newavg > maxth)     // default value of maxth in the paper is 15 packets

=> drop the incoming packet    // it means Pd= 1

=> else Calculate Pd as shown in Eq. (2)

=> Pd= maxp x [(newavg – minth) ÷ (maxth – minth)] Eq. (2)

=> The slope of the linear function will depend on this maxp value.

=> where, maxp = maximum drop probability. Default: 0.5 (previously, it was 0.02)

When the new average length of the queue is less than equal to the minimum threshold value of the queue size which is 5, then the drop probability of the packet is 0. 0 means the packet will not be dropped, but it will be enqueued. When the new average length of the queue is greater than the maximum threshold value of the queue size which is 15, then the drop probability of the packet is 1. 1 means the packet will be dropped. Now comes the intermediate case, when the new average length of the queue is in between the minimum and maximum threshold value, then drop probability will be calculated using a formula, given above in equation 2.

What do we do with Pd, this is what we are going to do in the next step.

Decision-making logic

Once the ‘Pd’ is calculated, RED uses the following logic to decide whether the incoming packet must be enqueued or dropped:

=> if (Pd≤ R) enqueue the incoming packet

=> else drop the incoming packet

=> where, R = uniformly distributed random number generated between [0, 1]

Note: It is important that a well-known random number generator is used to generate R. If the implementation of the random number generator is not correct, RED’s performance might get affected. 

RED Model

The left part is the “No drop” region. If the average queue length is less than equal to the minimum threshold value then the packet will be enqueued. The right part is the “drop all” region. If the average queue length is greater than the maximum threshold value then the packet will be dropped. If the average queue length is in between min and max threshold values then the drop probability of that packet will be calculated. Based on that value, the final decision will be made about enqueue or discard.

Is Pd sufficient to enable a uniform random drop pattern?

When the average queue size becomes constant, the number of arriving packets ‘between’ dropped packets becomes a geometric random variable with Pd. It implies that packet drops are not uniformly distributed because sometimes more packets arrive and sometimes fewer packets arrive between two packet drops. Hence, a new equation is provided to calculate the drop probability (Pa). 

=> Pa = Pd ÷ (1 – count x Pd) Eq. (3) where, count = number of packets enqueued since last drop

What happens to ‘average queue size’ when no packets arrive at the router?

Since RED is invoked only when packets arrive, there is a possibility that the ‘average queue size’ value incorrectly indicates heavy congestion even when the queue is actually ‘empty’. If this happens, an incoming packet might get dropped even if the queue is totally empty. The basic problem is that the value of ‘average queue size’ does not ‘decay’ when the queue is idle. 

=> When a first packet arrives at an empty queue, the ‘newavg’ is calculated as shown in Eq. (4)

=> newavg = (1 – wq)m x oldavg Eq. (4) where, m = the number of packets that ‘might’ have

=> been transmitted by the router if it was not idle. m is calculated as shown in Eq. (5)

=> m = (idle_stop_time – idle_start_time) ÷ (average transmission  time of a packet) Eq. (5)

=> where, average transmission time of a packet = mean packet size ÷ bandwidth

=> Note: packets can be of different sizes in the network! 

Pseudocode for RED Algorithm:

On arrival of every packet:

Step 1: if (the queue is empty) newavg = (1 – wq)m x oldavg.

             else newavg = (1 – wq) x oldavg + wq x current_queue_len.

Step 2: if (newavg ≤ month) enqueue the incoming packet.

             else if (newavg > maxth).

             drop the incoming packet.

             else Calculate Pd and Pa.

Step 3: if (Pa≤ R) enqueue the incoming packet.

            else drop the incoming packet.

Configurable knobs in RED:

  • wq
  • minth
  • maxth
  • maxp
  • mean packet size


Last Updated : 24 Mar, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads