30 #include "ns3/abort.h"
31 #include "ns3/drop-tail-queue.h"
34 #include "ns3/object-factory.h"
35 #include "ns3/uinteger.h"
50 static inline uint32_t
53 return (uint32_t)(((uint64_t)A * R) >> 32);
77 TypeId(
"ns3::CoDelQueueDisc")
79 .SetGroupName(
"TrafficControl")
81 .AddAttribute(
"UseEcn",
82 "True to use ECN (packets are marked instead of being dropped)",
86 .AddAttribute(
"UseL4s",
87 "True to use L4S (only ECT1 packets are marked at CE threshold)",
93 "The maximum number of packets/bytes accepted by this queue disc.",
96 MakeQueueSizeChecker())
97 .AddAttribute(
"MinBytes",
98 "The CoDel algorithm minbytes parameter.",
101 MakeUintegerChecker<uint32_t>())
102 .AddAttribute(
"Interval",
103 "The CoDel algorithm interval",
107 .AddAttribute(
"Target",
108 "The CoDel algorithm target queue delay",
112 .AddAttribute(
"CeThreshold",
113 "The CoDel CE threshold for marking packets",
117 .AddTraceSource(
"Count",
120 "ns3::TracedValueCallback::Uint32")
121 .AddTraceSource(
"LastCount",
124 "ns3::TracedValueCallback::Uint32")
125 .AddTraceSource(
"DropState",
128 "ns3::TracedValueCallback::Bool")
129 .AddTraceSource(
"DropNext",
130 "Time until next packet drop",
132 "ns3::TracedValueCallback::Uint32");
159 uint32_t invsqrt2 = ((uint64_t)invsqrt * invsqrt) >> 32;
160 uint64_t val = (3LL << 32) - ((uint64_t)count * invsqrt2);
163 val = (val * invsqrt) >> (32 - 2 + 1);
217 NS_LOG_LOGIC(
"Sojourn time is below target or number of bytes in queue is less than "
218 "minBytes; packet should not be dropped");
228 NS_LOG_LOGIC(
"Sojourn time has just gone above target from below, need to stay above for "
229 "at least q->interval before packet can be dropped. ");
234 NS_LOG_LOGIC(
"Sojourn time has been above target for at least q->interval; it's OK to "
235 "(possibly) drop packet.");
259 (((tosByte & 0x3) == 1) || (tosByte & 0x3) == 3))
261 if ((tosByte & 0x3) == 1)
263 NS_LOG_DEBUG(
"ECT1 packet " <<
static_cast<uint16_t
>(tosByte & 0x3));
267 NS_LOG_DEBUG(
"CE packet " <<
static_cast<uint16_t
>(tosByte & 0x3));
286 bool okToDrop =
OkToDrop(item, now);
287 bool isMarked =
false;
292 NS_LOG_LOGIC(
"In dropping state, check if it's OK to leave or next drop should occur");
296 NS_LOG_LOGIC(
"Sojourn time goes below target, it's OK to leave dropping state.");
314 NS_LOG_LOGIC(
"Sojourn time is still above target and it's time for next drop "
324 "Sojourn time is still above target and it's time for next drop; dropping "
358 NS_LOG_LOGIC(
"Not in dropping state; decide if we have to enter the state and drop the "
365 NS_LOG_LOGIC(
"Sojourn time goes above target, marking the first packet "
366 << item <<
" and entering the dropping state");
371 NS_LOG_LOGIC(
"Sojourn time goes above target, dropping the first packet "
372 << item <<
" and entering the dropping state");
401 NS_LOG_LOGIC(
"Running ControlLaw for input now: " << (
double)now);
404 << (
double)now / 1000000);
442 return ((int64_t)(a) - (int64_t)(b) > 0);
448 return ((int64_t)(a) - (int64_t)(b) >= 0);
454 return ((int64_t)(a) - (int64_t)(b) < 0);
460 return ((int64_t)(a) - (int64_t)(b) <= 0);
481 NS_LOG_ERROR(
"CoDelQueueDisc cannot have packet filters");
A CoDel packet queue disc.
bool CheckConfig() override
Check whether the current configuration is correct.
uint32_t GetDropNext()
Get the time for next packet drop while in the dropping state.
static uint16_t NewtonStep(uint16_t recInvSqrt, uint32_t count)
Calculate the reciprocal square root of m_count by using Newton's method http://en....
static constexpr const char * OVERLIMIT_DROP
Overlimit dropped packet.
static uint32_t ControlLaw(uint32_t t, uint32_t interval, uint32_t recInvSqrt)
Determine the time for next drop CoDel control law is t + m_interval/sqrt(m_count).
static constexpr const char * TARGET_EXCEEDED_DROP
Sojourn time above target.
uint16_t m_recInvSqrt
Reciprocal inverse square root.
bool CoDelTimeBeforeEq(uint32_t a, uint32_t b)
Check if CoDel time a is preceding or equal to b.
void InitializeParams() override
Initialize parameters (if any) before the first packet is enqueued.
Time m_ceThreshold
Threshold above which to CE mark.
Time GetInterval()
Get the interval.
Ptr< QueueDiscItem > DoDequeue() override
Remove a packet from queue based on the current state If we are in dropping state,...
uint32_t m_minBytes
Minimum bytes in queue to allow a packet drop.
bool CoDelTimeAfterEq(uint32_t a, uint32_t b)
Check if CoDel time a is successive or equal to b.
static constexpr const char * CE_THRESHOLD_EXCEEDED_MARK
Sojourn time above CE threshold.
TracedValue< uint32_t > m_count
Number of packets dropped since entering drop state.
bool m_useL4s
True if L4S is used (ECT1 packets are marked at CE threshold)
bool OkToDrop(Ptr< QueueDiscItem > item, uint32_t now)
Determine whether a packet is OK to be dropped.
~CoDelQueueDisc() override
TracedValue< uint32_t > m_lastCount
Last number of packets dropped since entering drop state.
Time m_target
5 ms target queue delay
uint32_t Time2CoDel(Time t)
Return the unsigned 32-bit integer representation of the input Time object.
CoDelQueueDisc()
CoDelQueueDisc Constructor.
uint32_t m_firstAboveTime
Time to declare sojourn time above target.
Time GetTarget()
Get the target queue delay.
bool m_useEcn
True if ECN is used (packets are marked instead of being dropped)
TracedValue< bool > m_dropping
True if in dropping state.
bool CoDelTimeAfter(uint32_t a, uint32_t b)
Check if CoDel time a is successive to b.
bool CoDelTimeBefore(uint32_t a, uint32_t b)
Check if CoDel time a is preceding b.
bool DoEnqueue(Ptr< QueueDiscItem > item) override
Add a packet to the queue.
static constexpr const char * TARGET_EXCEEDED_MARK
Sojourn time above target.
Time m_interval
100 ms sliding minimum time window width
TracedValue< uint32_t > m_dropNext
Time to drop next packet.
static TypeId GetTypeId()
Get the type ID.
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.
QueueSize GetCurrentSize() const
Get the current size of the queue disc in bytes, if operating in bytes mode, or packets,...
void DropAfterDequeue(Ptr< const QueueDiscItem > item, const char *reason)
Perform the actions required when the queue disc is notified of a packet dropped after dequeue.
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.
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.
static Time Now()
Return the current simulation virtual time.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#define DEFAULT_CODEL_LIMIT
#define REC_INV_SQRT_SHIFT
#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_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#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.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
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.
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
static int64_t CoDelGetTime()
Returns the current time translated in CoDel time representation.
static const int CODEL_SHIFT
Number of bits discarded from the time representation.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
static uint32_t ReciprocalDivide(uint32_t A, uint32_t R)
Performs a reciprocal divide, similar to the Linux kernel reciprocal_divide function.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)