61 #include "ns3/uinteger.h"
62 #include "ns3/double.h"
63 #include "ns3/simulator.h"
64 #include "ns3/abort.h"
65 #include "ns3/random-variable-stream.h"
78 .SetGroupName(
"Network")
80 .AddAttribute (
"Mode",
81 "Determines unit for QueueLimit",
86 .AddAttribute (
"MeanPktSize",
87 "Average of packet size",
90 MakeUintegerChecker<uint32_t> ())
91 .AddAttribute (
"IdlePktSize",
92 "Average packet size used during idle times. Used when m_cautions = 3",
95 MakeUintegerChecker<uint32_t> ())
96 .AddAttribute (
"Wait",
97 "True for waiting between dropped packets",
101 .AddAttribute (
"Gentle",
102 "True to increases dropping probability slowly when average queue exceeds maxthresh",
106 .AddAttribute (
"MinTh",
107 "Minimum average length threshold in packets/bytes",
110 MakeDoubleChecker<double> ())
111 .AddAttribute (
"MaxTh",
112 "Maximum average length threshold in packets/bytes",
115 MakeDoubleChecker<double> ())
116 .AddAttribute (
"QueueLimit",
117 "Queue limit in bytes/packets",
120 MakeUintegerChecker<uint32_t> ())
122 "Queue weight related to the exponential weighted moving average (EWMA)",
125 MakeDoubleChecker <double> ())
126 .AddAttribute (
"LInterm",
127 "The maximum probability of dropping a packet",
130 MakeDoubleChecker <double> ())
131 .AddAttribute (
"Ns1Compat",
132 "NS-1 compatibility",
136 .AddAttribute (
"LinkBandwidth",
137 "The RED link bandwidth",
141 .AddAttribute (
"LinkDelay",
142 "The RED link delay",
155 m_hasRedStarted (false)
158 m_uv = CreateObject<UniformRandomVariable> ();
223 uint32_t nQueued = 0;
247 m = uint32_t (ptc * (now -
m_idleTime).GetSeconds ());
301 NS_LOG_DEBUG (
"\t Dropping due to Queue Full " << nQueued);
365 m_vA = 1.0 / th_diff;
393 else if (
m_qW == -1.0)
401 m_qW = 1.0 - std::exp (-1.0 / (10 * rtt *
m_ptc));
403 else if (
m_qW == -2.0)
413 <<
"; m_isGentle " <<
m_isGentle <<
"; th_diff " << th_diff
414 <<
"; lInterm " <<
m_lInterm <<
"; va " <<
m_vA <<
"; cur_max_p "
432 newAve += qW * nQueued;
455 double pkts =
m_ptc * 0.05;
456 double fraction = std::pow ((1 -
m_qW), pkts);
458 if ((
double) qSize < fraction *
m_qAvg)
475 double pkts =
m_ptc * 0.05;
476 double fraction = std::pow ((1 -
m_qW), pkts);
477 double ratio = qSize / (fraction *
m_qAvg);
503 double vB,
double vC,
double vD,
double maxP)
505 NS_LOG_FUNCTION (
this << qAvg << maxTh << isGentle << vA << vB << vC << vD << maxP);
508 if (isGentle && qAvg >= maxTh)
514 else if (!isGentle && qAvg >= maxTh)
544 uint32_t meanPktSize,
bool isWait, uint32_t size)
546 NS_LOG_FUNCTION (
this << p << count << countBytes << meanPktSize << isWait << size);
547 double count1 = (double) count;
551 count1 = (double) (countBytes / meanPktSize);
556 if (count1 * p < 1.0)
560 else if (count1 * p < 2.0)
562 p /= (2.0 - count1 * p);
571 if (count1 * p < 1.0)
573 p /= (1.0 - count1 * p);
583 p = (p * size) / meanPktSize;
uint32_t m_bytesInQueue
bytes in the queue
uint32_t qLimDrop
Drops due to queue limits.
Ptr< UniformRandomVariable > m_uv
rng stream
QueueMode m_mode
Mode (Bytes or packets)
An "unforced" (random) drop.
Simulation virtual time values and global simulation resolution.
uint32_t DropEarly(Ptr< Packet > p, uint32_t qSize)
Check if packet p needs to be dropped due to probability mark.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
AttributeValue implementation for Boolean.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
virtual ~RedQueue()
Destructor.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
void SetMode(RedQueue::QueueMode mode)
Set the operating mode of this queue.
Use number of bytes for maximum queue size.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
double m_ptc
packet time constant in packets/second
void SetQueueLimit(uint32_t lim)
Set the limit of the queue.
virtual Ptr< Packet > DoDequeue(void)
Pull a packet from the queue.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
uint32_t m_cautious
0 for default RED 1 experimental (see red-queue.cc) 2 experimental (see red-queue.cc) 3 use Idle packet size in the ptc
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
virtual bool DoEnqueue(Ptr< Packet > p)
Push a packet in the queue.
DataRate m_linkBandwidth
Link bandwidth.
uint32_t m_queueLimit
Queue limit in bytes / packets.
Stats m_stats
RED statistics.
Ptr< const AttributeChecker > MakeDataRateChecker(void)
Abstract base class for packet Queues.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Class for representing data rates.
bool m_isGentle
True to increases dropping prob.
uint32_t GetQueueSize(void)
Get the current value of the queue in bytes or packets.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
QueueMode
Enumeration of the modes supported in the class.
Time m_linkDelay
Link delay.
std::list< Ptr< Packet > > m_packets
packets in the queue
double m_vA
1.0 / (m_maxTh - m_minTh)
RedQueue::QueueMode GetMode(void)
Get the encapsulation mode of this queue.
Hold variables of type enum.
Stats GetStats()
Get the RED statistics after running.
uint32_t m_countBytes
Number of bytes since last drop.
AttributeValue implementation for Time.
virtual Ptr< const Packet > DoPeek(void) const
Peek the front packet in the queue.
uint32_t m_meanPktSize
Avg pkt size.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Hold an unsigned integer type.
RedQueue()
RedQueue Constructor.
bool m_isNs1Compat
Ns-1 compatibility.
Ptr< const AttributeAccessor > MakeDataRateAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
double m_lInterm
The max probability of dropping a packet.
static TypeId GetTypeId(void)
Get the type ID.
double Estimator(uint32_t nQueued, uint32_t m, double qAvg, double qW)
Compute the average queue size.
void SetTh(double minTh, double maxTh)
Set the thresh limits of RED.
double CalculatePNew(double qAvg, double, bool gentle, double vA, double vB, double vC, double vD, double maxP)
Returns a probability using these function parameters for the DropEarly function. ...
uint32_t m_count
Number of packets since last random number generation.
uint32_t m_idle
0/1 idle status
double ModifyP(double p, uint32_t count, uint32_t countBytes, uint32_t meanPktSize, bool wait, uint32_t size)
Returns a probability using these function parameters for the DropEarly function. ...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void InitializeParams(void)
Initialize the queue parameters.
bool m_isWait
True for waiting between dropped packets.
uint32_t m_old
0 when average queue first exceeds threshold
Ptr< const AttributeChecker > MakeBooleanChecker(void)
uint64_t GetBitRate() const
Get the underlying bitrate.
bool m_hasRedStarted
True if RED has started.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
static Time Now(void)
Return the current simulation virtual time.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
uint32_t m_idlePktSize
Avg pkt size used during idle times.
Time m_idleTime
Start of current idle period.
uint32_t forcedDrop
Forced drops, qavg > max threshold.
AttributeValue implementation for DataRate.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
double m_qW
Queue weight given to cur queue size sample.
double m_qAvg
Average queue length.
double m_vB
-m_minTh / (m_maxTh - m_minTh)
uint32_t unforcedDrop
Early probability drops.
double m_vC
(1.0 - m_curMaxP) / m_maxTh - used in "gentle" mode
Use number of packets for maximum queue size.
double m_maxTh
Max avg length threshold (bytes), should be >= 2*minTh.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
double m_curMaxP
Current max_p.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
double m_minTh
Min avg length threshold (bytes)
void Drop(Ptr< Packet > packet)
Drop a packet.
double m_vD
2.0 * m_curMaxP - 1.0 - used in "gentle" mode