# Random Early Detection (RED) Queue Discipline

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 – w

_{q}) x oldavg + w_{q}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

=> w

_{q}= 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 (P_{d}), where min_{th} represents the minimum threshold for ‘average queue length’ and max_{th} represents the maximum threshold for ‘average queue length’. min_{th }and max_{th} 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 ≤ min

_{th}) // default value of minth in the paper is 5 packets=> enqueue the incoming packet // it means Pd= 0

=> else if (newavg > max

_{th}) // 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= max

_{p}x [(newavg – min_{th}) ÷ (max_{th}– min_{th})] Eq. (2)=> The slope of the linear function will depend on this max

_{p}value.=> where, max

_{p}= 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 P_{d}, 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.

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 P_{d} 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 P_{d}. 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 (P_{a}).

=> P

_{a}= P_{d}÷ (1 – count x P_{d}) 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 – w

_{q})^{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 – w_{q})^{m} x oldavg.

else newavg = (1 – w_{q}) x oldavg + w_{q} x current_queue_len.

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

else if (newavg > max_{th}).

drop the incoming packet.

else Calculate P_{d} and P_{a.}

**Step 3: **if (P_{a}≤ R) enqueue the incoming packet.

else drop the incoming packet.

#### Configurable knobs in RED:

- w
_{q} - min
_{th} - max
_{th} - max
_{p} - mean packet size

## Please

Loginto comment...