The Wayback Machine - https://web.archive.org/web/20240930145649/https://www.geeksforgeeks.org/random-early-detection-red-queue-discipline/
Open In App

Random Early Detection (RED) Queue Discipline

Last Updated : 24 Mar, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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


Similar Reads

Controlled Delay (CoDel) Queue Discipline
AQM stands for Active Queue Management; these are the algorithms that take care of the router queues. RED and its variants are the active queue management algorithms. There have been proposed some other algorithms for actively handling the queues at the router. Controlled Delay is such AQM. CoDel was proposed in RFC 8289 by Van Jacobson and the tea
9 min read
Methods of Line Discipline
Line Discipline : Line discipline is the foundation of data link layer that determines which device can send data at a given time out of various connected devices in network and when it can send that data. Thus line discipline coordinate link system. It also used to make sure that data sent by sender is received by a particular receiver. It may be
3 min read
Line Discipline in Data Link Layer
Line Discipline is function of Data link layer. It simply determines and identifies the direction of communication. It is simply process of coordinating half-duplex transmission i.e. data can be transmitted in both directions on network of data communication but not at the same time just by establishing and developing continuity among sender and re
3 min read
Types of RED Queue Disciplines
Random early detection (RED), also known as random early discard or random early drop is a queuing discipline for a network scheduler suited for congestion avoidance. There are different types of RED Queue Disciplines: Gentle REDNonlinear REDSelf Configuring REDAdaptive RED Queue DisciplineGentle RED:Random Early Detection algorithm increases the d
10 min read
Early Evidence of Steganography
Steganography can be referred as an art of invisible communication. It hides the very presence of communication without leaving any apparent evidence. In other words, steganography is a technique to hide secret information in such a way that an outsider cannot even sense the presence of the embedded message. The medium used to hide the information
4 min read
Difference between Early and Delayed Token Release
Prerequisite - Token Ring 1. Early Token Release : Sender does not wait for the data packet to complete revolution before releasing the token. Token is released as soon as the data is transmitted. Multiple packets present in the ring. Less reliable than Delayed Token Release. 2. Delayed Token Release : In this, the sender transmit the data packet a
2 min read
Display the red, green and blue color planes of a color image in MATLAB
Prerequisite - RGB image representation A colored image can be represented as a 3 order matrix. The first order is for the rows, the second order is for the columns and the third order is for specifying the color of the corresponding pixel. Here we use the RGB color format, so the third order will take 3 values of Red, Green ans Blue respectively.
2 min read
Left Leaning Red Black Tree (Insertion)
Prerequisites : Red - Black Trees.A left leaning Red Black Tree or (LLRB), is a variant of red black tree, which is a lot easier to implement than Red black tree itself and guarantees all the search, delete and insert operations in O(logn) time. Which nodes are RED and Which are Black ? Nodes which have double incoming edge are RED in color. Nodes
15+ min read
What is Red Teaming in Cyber Security?
Red Teaming in the line of cybersecurity is the dynamic and essentially effective mechanism designed to actively assess and strengthen an organization’s security position. It refers to the process of conducting an exercise in which a specific demand is set to get an understanding of real-life threats in an organization’s IT structure, networks, per
11 min read
Python | Document field detection using Template Matching
Template matching is an image processing technique which is used to find the location of small-parts/template of a large image. This technique is widely used for object detection projects, like product quality, vehicle tracking, robotics etc. In this article, we will learn how to use template matching for detecting the related fields in a document
2 min read
MATLAB - Image Edge Detection using Prewitt Operator from Scratch
Prewitt Operator: It is a gradient-based operator. It is one of the best ways to detect the orientation and magnitude of an image. It computes the gradient approximation of image intensity function for image edge detection. At the pixels of an image, the Prewitt operator produces either the normal to a vector or the corresponding gradient vector. I
3 min read
MATLAB - Image Edge Detection using Sobel Operator from Scratch
Sobel Operator: It is a discrete differentiation gradient-based operator. It computes the gradient approximation of image intensity function for image edge detection. At the pixels of an image, the Sobel operator produces either the normal to a vector or the corresponding gradient vector. It uses two 3 x 3 kernels or masks which are convolved with
3 min read
MATLAB - Image Edge Detection using Robert Operator from Scratch
Robert Operator: This gradient-based operator computes the sum of squares of the differences between diagonally adjacent pixels in an image through discrete differentiation. Then the gradient approximation is made. It uses the following 2 x 2 kernels or masks – [Tex]\[M_{x}=\left[\begin{array}{ccc}1 & 0 \\ 0 & -1\end{array}\right] \quad M_{
2 min read
Image Edge Detection Operators in Digital Image Processing
Edges are significant local changes of intensity in a digital image. An edge can be defined as a set of connected pixels that forms a boundary between two disjoint regions. There are three types of edges: Horizontal edgesVertical edgesDiagonal edges Edge Detection is a method of segmenting an image into regions of discontinuity. It is a widely used
4 min read
Edge detection using in-built function in MATLAB
Edge detection: In an image, an edge is a curve that follows a path of rapid change in intensity of that image. Edges are often associated with the boundaries of the object in a scene environment. Edge detection is used to identify the edges in an image to make image processing easy. Edge detection works by detecting discontinuities in brightness.
2 min read
Approaches to Intrusion Detection and Prevention
Prerequisites - Intrusion Detection System (IDS)Intrusion Prevention System (IPS) IDS stands for Intrusion Detection System (IDS). It is device or software application that monitors network or systems for malicious activity or policy violations. There are six basic approaches to Intrusion Detection and Prevention. Some of these methods are implemen
6 min read
Packet Loss Detection Algorithms
TCP uses retransmission for the lost packets during any transmission, but how does packet loss happens and how TCP can detect it. In this article, we are going to discuss packet loss detection algorithms. When does a packet loss happen?Packet loss happens due to the following reasons: When the receiver's buffer is full but the sender is sending the
5 min read
Which Layer Called Error Detection Layer?
Answer: The Data Link layer is often referred to as the error detection layer.And, Transport Layer is also responsible for error detection and recovery in data communication. Error DetectionThe Data Link layer is responsible for transferring data frames between adjacent network nodes. During this process, it employs error detection techniques to en
1 min read
Matlab | Edge Detection of an image without using in-built function
Problem Statement: Write a matlab code for edge detection of a grayscale image without using in-built function of edge detection. About Edge Detection: Edge detection is an image processing technique for finding the boundaries of objects within images. It works by detecting discontinuities in brightness. Edge detection is used for image segmentatio
3 min read
ML | Training Image Classifier using Tensorflow Object Detection API
This article aims to learn how to build an object detector using Tensorflow's object detection API. Requirement :  Python ProgrammingBasics of Machine LearningBasics of neural networks (Not Mandatory)An enthusiasm to build a Cool project(Mandatory) :pEven though if you don't have the first three essentials, you're welcome to the adventure. Don't wo
11 min read
Intrusion Detection System (IDS)
An Intrusion Detection System (IDS) is a security tool that monitors a computer network or systems for malicious activities or policy violations. It helps detect unauthorized access, potential threats, and abnormal activities by analyzing traffic and alerting administrators to take action. An IDS is crucial for maintaining network security and prot
10 min read
Advanced Persistent Threat ( APT) : Working, Characteristics, Detection and Protection
Advanced Persistent Threat (APT) is a prolonged and targeted cyberattack where hackers gain unauthorized access to a network and remain undetected for an extended period. Advanced Persistent Threat (APT) is like a stealthy burglar who breaks into a house and stays hidden for a long time, carefully stealing valuable items without being noticed. Thes
8 min read
Error Detection in Computer Networks
Error is a condition when the receiver's information does not match the sender's. Digital signals suffer from noise during transmission that can introduce errors in the binary bits traveling from sender to receiver. That means a 0 bit may change to 1 or a 1 bit may change to 0.  Data (Implemented either at the Data link layer or Transport Layer of
7 min read
Collision Detection in CSMA/CD
CSMA/CD (Carrier Sense Multiple Access/ Collision Detection) is a media access control method that was widely used in Early Ethernet technology/LANs when there used to be shared Bus Topology and each node ( Computers) was connected by Coaxial Cables. Nowadays Ethernet is Full Duplex and Topology is either Star (connected via Switch or Router) or po
7 min read
Error Detection Code - Checksum
Checksum is the error detection method used by upper layer protocols and is considered to be more reliable than LRC, VRC and CRC. This method makes the use of Checksum Generator on Sender side and Checksum Checker on Receiver side. At the Sender side, the data is divided into equal subunits of n bit length by the checksum generator. This bit is gen
2 min read
What is Anomaly Detection?
Anomaly Detection, additionally known as outlier detection, is a technique in records analysis and machine studying that detects statistics points, activities, or observations that vary drastically from the dataset's ordinary behavior. These abnormalities may sign extreme conditions which include mistakes, flaws, or fraud. Anomaly Detection is crit
15 min read
Passive Queue Management in Router
Congestion occurs when packets' arriving rate is faster than packets forwarding speed. The router has input and output ports. Thus congestion can happen at any port depending upon the speed of switching fabric. Congestion at Input PortsSuppose the router has N input ports and N output ports. If the speed of switching fabric is less than N times the
6 min read
Proportional Integral (PI) Controller and PI Controller Enhanced (PIE) Queue Disciplines
The proportional Integral (PI) Controller is the AQM algorithm. It manages the queue at the output port of the router. It includes the major features which were absent in RED. The proportional Integral (PI) controller was designed to overcome the problems of RED. It uses ‘instantaneous queue length’ as a congestion metric. PI operates during the ‘e
7 min read
Introduction of Message Queue Telemetry Transport Protocol (MQTT)
Message Queuing Telemetry Transport, or MQTT, is a communications protocol designed for Internet of Things devices with extremely high latency and restricted low bandwidth. Message Queuing Telemetry Transport is a perfect protocol for machine-to-machine (M2M) communication since it is designed specifically for low-bandwidth, high-latency settings.
9 min read
Random-Scan Display
In Random-Scan Display electron beam is directed only to the areas of screen where a picture has to be drawn. It is also called vector display, as it draws picture one line at time. It can draw and refresh component lines of a picture in any specified sequence. A Pen plotter is an example of random-scan device. The number of lines regulates refresh
2 min read