61#include "ns3/double.h"
62#include "ns3/drop-tail-queue.h"
65#include "ns3/simulator.h"
66#include "ns3/uinteger.h"
79 TypeId(
"ns3::RedQueueDisc")
81 .SetGroupName(
"TrafficControl")
83 .AddAttribute(
"MeanPktSize",
84 "Average of packet size",
87 MakeUintegerChecker<uint32_t>())
88 .AddAttribute(
"IdlePktSize",
89 "Average packet size used during idle times. Used when m_cautions = 3",
92 MakeUintegerChecker<uint32_t>())
94 "True for waiting between dropped packets",
98 .AddAttribute(
"Gentle",
99 "True to increases dropping probability slowly when average queue "
104 .AddAttribute(
"ARED",
105 "True to enable ARED",
109 .AddAttribute(
"AdaptMaxP",
110 "True to adapt m_curMaxP",
114 .AddAttribute(
"FengAdaptive",
115 "True to enable Feng's Adaptive RED",
119 .AddAttribute(
"NLRED",
120 "True to enable Nonlinear RED",
124 .AddAttribute(
"MinTh",
125 "Minimum average length threshold in packets/bytes",
128 MakeDoubleChecker<double>())
129 .AddAttribute(
"MaxTh",
130 "Maximum average length threshold in packets/bytes",
133 MakeDoubleChecker<double>())
134 .AddAttribute(
"MaxSize",
135 "The maximum number of packets accepted by this queue disc",
138 MakeQueueSizeChecker())
140 "Queue weight related to the exponential weighted moving average (EWMA)",
143 MakeDoubleChecker<double>())
144 .AddAttribute(
"LInterm",
145 "The maximum probability of dropping a packet",
148 MakeDoubleChecker<double>())
149 .AddAttribute(
"TargetDelay",
150 "Target average queuing delay in ARED",
154 .AddAttribute(
"Interval",
155 "Time interval to update m_curMaxP",
160 "Upper bound for m_curMaxP in ARED",
163 MakeDoubleChecker<double>(0, 1))
164 .AddAttribute(
"Bottom",
165 "Lower bound for m_curMaxP in ARED",
168 MakeDoubleChecker<double>(0, 1))
169 .AddAttribute(
"Alpha",
170 "Increment parameter for m_curMaxP in ARED",
173 MakeDoubleChecker<double>(0, 1))
174 .AddAttribute(
"Beta",
175 "Decrement parameter for m_curMaxP in ARED",
178 MakeDoubleChecker<double>(0, 1))
179 .AddAttribute(
"FengAlpha",
180 "Decrement parameter for m_curMaxP in Feng's Adaptive RED",
183 MakeDoubleChecker<double>())
184 .AddAttribute(
"FengBeta",
185 "Increment parameter for m_curMaxP in Feng's Adaptive RED",
188 MakeDoubleChecker<double>())
189 .AddAttribute(
"LastSet",
190 "Store the last time m_curMaxP was updated",
195 "Round Trip Time to be considered while automatically setting m_bottom",
199 .AddAttribute(
"Ns1Compat",
200 "NS-1 compatibility",
204 .AddAttribute(
"LinkBandwidth",
205 "The RED link bandwidth",
208 MakeDataRateChecker())
209 .AddAttribute(
"LinkDelay",
210 "The RED link delay",
214 .AddAttribute(
"UseEcn",
215 "True to use ECN (packets are marked instead of being dropped)",
219 .AddAttribute(
"UseHardDrop",
220 "True to always drop packets above max threshold",
232 m_uv = CreateObject<UniformRandomVariable>();
256 NS_LOG_WARN(
"Alpha value is above the recommended bound!");
275 NS_LOG_WARN(
"Beta value is below the recommended bound!");
294 NS_LOG_WARN(
"Alpha value does not follow the recommendations!");
313 NS_LOG_WARN(
"Beta value does not follow the recommendations!");
488 if (
m_minTh < targetqueue / 2.0)
515 m_vA = 1.0 / th_diff;
543 else if (
m_qW == -1.0)
551 m_qW = 1.0 - std::exp(-1.0 / (10 * rtt *
m_ptc));
553 else if (
m_qW == -2.0)
574 <<
"; th_diff " << th_diff <<
"; lInterm " <<
m_lInterm <<
"; va "
576 <<
"; m_vC " <<
m_vC <<
"; m_vD " <<
m_vD);
612 if (newAve < m_minTh + m_part && m_curMaxP >
m_bottom)
637 double newAve = qAvg * std::pow(1.0 - qW, m);
638 newAve += qW * nQueued;
670 double pkts =
m_ptc * 0.05;
671 double fraction = std::pow((1 -
m_qW), pkts);
673 if ((
double)qSize < fraction *
m_qAvg)
690 double pkts =
m_ptc * 0.05;
691 double fraction = std::pow((1 -
m_qW), pkts);
692 double ratio = qSize / (fraction *
m_qAvg);
775 if (count1 * p < 1.0)
779 else if (count1 * p < 2.0)
781 p /= (2.0 - count1 * p);
790 if (count1 * p < 1.0)
792 p /= (1.0 - count1 * p);
870 NS_LOG_ERROR(
"RedQueueDisc cannot have packet filters");
890 NS_LOG_ERROR(
"m_isAdaptMaxP and m_isFengAdaptive cannot be simultaneously true");
AttributeValue implementation for Boolean.
Class for representing data rates.
uint64_t GetBitRate() const
Get the underlying bitrate.
AttributeValue implementation for DataRate.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
A FIFO packet queue that drops tail-end packets on overflow.
Smart pointer class similar to boost::intrusive_ptr.
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
uint32_t GetNPackets() const
Get the number of packets stored by the queue disc.
uint32_t GetNBytes() const
Get the amount of bytes stored by the queue disc.
Ptr< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
std::size_t GetNQueueDiscClasses() const
Get the number of queue disc classes.
QueueSize GetMaxSize() const
Get the maximum size of the queue disc.
std::size_t GetNPacketFilters() const
Get the number of packet filters.
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
std::size_t GetNInternalQueues() const
Get the number of internal queues.
void DoDispose() override
Dispose of the object.
bool Mark(Ptr< QueueDiscItem > item, const char *reason)
Marks the given packet and, if successful, updates the counters associated with the given reason.
void DropBeforeEnqueue(Ptr< const QueueDiscItem > item, const char *reason)
Perform the actions required when the queue disc is notified of a packet dropped before enqueue.
Class for representing queue sizes.
QueueSizeUnit GetUnit() const
Get the underlying unit.
AttributeValue implementation for QueueSize.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Time m_idleTime
Start of current idle period.
Time m_linkDelay
Link delay.
RedQueueDisc()
RedQueueDisc Constructor.
void UpdateMaxPFeng(double newAve)
Update m_curMaxP based on Feng's Adaptive RED.
DataRate m_linkBandwidth
Link bandwidth.
double m_vA
1.0 / (m_maxTh - m_minTh)
void SetFengAdaptiveB(double b)
Set the beta value to adapt m_curMaxP in Feng's Adaptive RED.
Time m_rtt
Rtt to be considered while automatically setting m_bottom in ARED.
static constexpr const char * FORCED_DROP
Forced drops, m_qAvg > m_maxTh.
@ Above
When m_qAvg > m_maxTh.
@ Between
When m_maxTh < m_qAvg < m_minTh.
@ Below
When m_qAvg < m_minTh.
static constexpr const char * UNFORCED_DROP
Early probability drops.
bool DoEnqueue(Ptr< QueueDiscItem > item) override
This function actually enqueues a packet into the queue disc.
double GetAredAlpha()
Get the alpha value to adapt m_curMaxP.
double ModifyP(double p, uint32_t size)
Returns a probability using these function parameters for the DropEarly function.
double m_a
Decrement parameter for m_curMaxP in Feng's Adaptive RED.
double GetFengAdaptiveB()
Get the beta value to adapt m_curMaxP in Feng's Adaptive RED.
void SetAredBeta(double beta)
Set the beta value to adapt m_curMaxP.
bool m_isAdaptMaxP
True to adapt m_curMaxP.
void SetTh(double minTh, double maxTh)
Set the thresh limits of RED.
uint32_t m_cautious
0 for default RED 1 experimental (see red-queue-disc.cc) 2 experimental (see red-queue-disc....
double m_alpha
Increment parameter for m_curMaxP in ARED.
bool m_isARED
True to enable Adaptive RED.
Time m_interval
Time interval to update m_curMaxP.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
bool CheckConfig() override
Check whether the current configuration is correct.
FengStatus m_fengStatus
For use in Feng's Adaptive RED.
bool m_useHardDrop
True if packets are always dropped above max threshold.
static constexpr const char * UNFORCED_MARK
Early probability marks.
double GetAredBeta()
Get the beta value to adapt m_curMaxP.
uint32_t m_old
0 when average queue first exceeds threshold
void SetFengAdaptiveA(double a)
Set the alpha value to adapt m_curMaxP in Feng's Adaptive RED.
Ptr< QueueDiscItem > DoDequeue() override
This function actually extracts a packet from the queue disc.
bool m_isWait
True for waiting between dropped packets.
bool m_useEcn
True if ECN is used (packets are marked instead of being dropped)
double m_maxTh
Maximum threshold for m_qAvg (bytes or packets), should be >= 2 * m_minTh.
static constexpr const char * FORCED_MARK
Forced marks, m_qAvg > m_maxTh.
bool m_isNonlinear
True to enable Nonlinear RED.
double m_minTh
Minimum threshold for m_qAvg (bytes or packets)
double m_top
Upper bound for m_curMaxP in ARED.
uint32_t m_meanPktSize
Avg pkt size.
double m_beta
Decrement parameter for m_curMaxP in ARED.
double m_lInterm
The max probability of dropping a packet.
uint32_t m_countBytes
Number of bytes since last drop.
uint32_t DropEarly(Ptr< QueueDiscItem > item, uint32_t qSize)
Check if a packet needs to be dropped due to probability mark.
void SetAredAlpha(double alpha)
Set the alpha value to adapt m_curMaxP.
bool m_isNs1Compat
Ns-1 compatibility.
double Estimator(uint32_t nQueued, uint32_t m, double qAvg, double qW)
Compute the average queue size.
double m_vB
-m_minTh / (m_maxTh - m_minTh)
double m_b
Increment parameter for m_curMaxP in Feng's Adaptive RED.
double m_bottom
Lower bound for m_curMaxP in ARED.
Time m_lastSet
Last time m_curMaxP was updated.
Time m_targetDelay
Target average queuing delay in ARED.
double m_ptc
packet time constant in packets/second
void InitializeParams() override
Initialize the queue parameters.
double CalculatePNew()
Returns a probability using these function parameters for the DropEarly function.
void UpdateMaxP(double newAve)
Update m_curMaxP.
bool m_isFengAdaptive
True to enable Feng's Adaptive RED.
static TypeId GetTypeId()
Get the type ID.
uint32_t m_count
Number of packets since last random number generation.
void DoDispose() override
Dispose of the object.
Ptr< const QueueDiscItem > DoPeek() override
Return a copy of the next packet the queue disc will extract.
uint32_t m_idle
0/1 idle status
Ptr< UniformRandomVariable > m_uv
rng stream
double GetFengAdaptiveA()
Get the alpha value to adapt m_curMaxP in Feng's Adaptive RED.
~RedQueueDisc() override
Destructor.
double m_vD
2.0 * m_curMaxP - 1.0 - used in "gentle" mode
double m_qAvg
Average queue length.
@ DTYPE_UNFORCED
An "unforced" (random) drop.
@ DTYPE_FORCED
A "forced" drop.
bool m_isGentle
True to increase dropping prob.
double m_vC
(1.0 - m_curMaxP) / m_maxTh - used in "gentle" mode
uint32_t m_idlePktSize
Avg pkt size used during idle times.
double m_qW
Queue weight given to cur queue size sample.
double m_curMaxP
Current max_p.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
AttributeValue implementation for Time.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > CreateObjectWithAttributes(Args... args)
Allocate an Object on the heap and initialize with a set of attributes.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
@ BYTES
Use number of bytes for queue size.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
@ SINGLE_INTERNAL_QUEUE
Used by queue discs with single internal queue.
Every class exported by the ns3 library is enclosed in the ns3 namespace.