30 #include "ns3/uinteger.h"
31 #include "ns3/abort.h"
33 #include "ns3/object-factory.h"
34 #include "ns3/drop-tail-queue.h"
50 return (uint32_t)(((uint64_t)A * R) >> 32);
84 virtual void Print (std::ostream &os)
const;
105 .AddConstructor<CoDelTimestampTag> ()
106 .AddAttribute (
"CreationTime",
107 "The time at which the timestamp was created",
153 .SetGroupName (
"TrafficControl")
155 .AddAttribute (
"Mode",
156 "Whether to use Bytes (see MaxBytes) or Packets (see MaxPackets) as the maximum queue size metric.",
161 .AddAttribute (
"MaxPackets",
162 "The maximum number of packets accepted by this CoDelQueueDisc.",
165 MakeUintegerChecker<uint32_t> ())
166 .AddAttribute (
"MaxBytes",
167 "The maximum number of bytes accepted by this CoDelQueueDisc.",
170 MakeUintegerChecker<uint32_t> ())
171 .AddAttribute (
"MinBytes",
172 "The CoDel algorithm minbytes parameter.",
175 MakeUintegerChecker<uint32_t> ())
176 .AddAttribute (
"Interval",
177 "The CoDel algorithm interval",
181 .AddAttribute (
"Target",
182 "The CoDel algorithm target queue delay",
186 .AddTraceSource (
"Count",
189 "ns3::TracedValueCallback::Uint32")
190 .AddTraceSource (
"DropCount",
193 "ns3::TracedValueCallback::Uint32")
194 .AddTraceSource (
"LastCount",
197 "ns3::TracedValueCallback::Uint32")
198 .AddTraceSource (
"DropState",
201 "ns3::TracedValueCallback::Bool")
202 .AddTraceSource (
"Sojourn",
205 "ns3::Time::TracedValueCallback")
206 .AddTraceSource (
"DropNext",
207 "Time until next packet drop",
209 "ns3::TracedValueCallback::Uint32")
223 m_firstAboveTime (0),
245 uint32_t invsqrt2 = ((uint64_t) invsqrt * invsqrt) >> 32;
246 uint64_t val = (3ll << 32) - ((uint64_t)
m_count * invsqrt2);
249 val = (val * invsqrt) >> (32 - 2 + 1);
282 NS_LOG_LOGIC (
"Queue full (at max packets) -- droppping pkt");
290 NS_LOG_LOGIC (
"Queue full (packet would exceed max bytes) -- droppping pkt");
319 NS_ASSERT_MSG (found,
"found a packet without an input timestamp tag");
330 NS_LOG_LOGIC (
"Sojourn time is below target or number of bytes in queue is less than minBytes; packet should not be dropped");
340 NS_LOG_LOGIC (
"Sojourn time has just gone above target from below, need to stay above for at least q->interval before packet can be dropped. ");
346 NS_LOG_LOGIC (
"Sojourn time has been above target for at least q->interval; it's OK to (possibly) drop packet.");
380 NS_LOG_LOGIC (
"In dropping state, check if it's OK to leave or next drop should occur");
384 NS_LOG_LOGIC (
"Sojourn time goes below target, it's OK to leave dropping state.");
399 NS_LOG_LOGIC (
"Sojourn time is still above target and it's time for next drop; dropping " << p);
413 p = item ->GetPacket ();
439 NS_LOG_LOGIC (
"Not in dropping state; decide if we have to enter the state and drop the first packet");
443 NS_LOG_LOGIC (
"Sojourn time goes above target, dropping the first packet " << p <<
" and entering the dropping state");
457 p = item->GetPacket ();
484 NS_LOG_LOGIC (
"Running ControlLaw for input now: " << (
double)now);
486 NS_LOG_LOGIC (
"Scheduled next drop at " << (
double)
m_dropNext / 1000000 <<
" now " << (
double)now / 1000000);
563 return ((
int)(a) - (
int)(b) > 0);
569 return ((
int)(a) - (
int)(b) >= 0);
575 return ((
int)(a) - (
int)(b) < 0);
581 return ((
int)(a) - (
int)(b) <= 0);
602 NS_LOG_ERROR (
"CoDelQueueDisc cannot have packet filters");
629 NS_LOG_ERROR (
"The mode of the provided queue does not match the mode set on the CoDelQueueDisc");
636 NS_LOG_ERROR (
"The size of the internal queue is less than the queue disc limit");
virtual void InitializeParams(void)
Initialize parameters (if any) before the first packet is enqueued.
virtual Ptr< const QueueDiscItem > DoPeek(void) const
This function returns a copy of the next packet the queue disc will extract.
Queue::QueueMode m_mode
The operating mode (Bytes or packets)
Simulation virtual time values and global simulation resolution.
uint32_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)
Add a packet to the queue.
uint32_t m_maxBytes
Max # of bytes accepted by the queue.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Control the scheduling of simulation events.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
TracedValue< uint32_t > m_dropCount
Number of dropped packets according CoDel algorithm.
uint32_t m_maxPackets
Max # of packets accepted by the queue.
uint32_t GetDropOverLimit(void)
Get the number of packets dropped when packets arrive at a full queue and cannot be enqueued...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
TracedValue< Time > m_sojourn
Time in queue.
Hold variables of type string.
void WriteU64(uint64_t v)
uint32_t GetDropNext(void)
Get the time for next packet drop while in the dropping state.
Ptr< Queue > GetInternalQueue(uint32_t i) const
Get the i-th internal queue.
uint32_t GetNBytes(void) const
Get the amount of bytes stored by the queue disc.
TracedValue< uint32_t > m_count
Number of packets dropped since entering drop state.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
void AddPacketTag(const Tag &tag) const
Add a packet tag.
virtual bool CheckConfig(void)
Check whether the current configuration is correct.
bool OkToDrop(Ptr< Packet > p, uint32_t now)
Determine whether a packet is OK to be dropped.
Time GetInterval(void)
Get the interval.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_UNUSED(x)
Mark a local variable as unused.
bool CoDelTimeAfterEq(uint32_t a, uint32_t b)
Check if CoDel time a is successive or equal to b.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
uint32_t ControlLaw(uint32_t t)
Determine the time for next drop CoDel control law is t + m_interval/sqrt(m_count).
bool CoDelTimeAfter(uint32_t a, uint32_t b)
Check if CoDel time a is successive to b.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
TracedValue< bool > m_dropping
True if in dropping state.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
virtual uint32_t GetSerializedSize(void) const
static TypeId GetTypeId(void)
Get the type ID.
uint32_t GetNInternalQueues(void) const
Get the number of internal queues.
void Drop(Ptr< QueueItem > item)
Drop a packet.
uint32_t m_dropOverLimit
The number of packets dropped due to full queue.
Queue::QueueMode GetMode(void)
Get the encapsulation mode of this device.
Hold variables of type enum.
CoDel time stamp, used to carry CoDel time informations.
uint32_t m_states
Total number of times we are in state 1, state 2, or state 3.
uint32_t m_firstAboveTime
Time to declare sojourn time above target.
uint32_t m_state2
Number of times we perform next drop while in dropping state.
bool CoDelTimeBefore(uint32_t a, uint32_t b)
Check if CoDel time a is preceding b.
Hold an unsigned integer type.
void AddInternalQueue(Ptr< Queue > queue)
Add an internal queue to the tail of the list of queues.
Time m_target
5 ms target queue delay
virtual void Deserialize(TagBuffer i)
CoDelQueueDisc()
CoDelQueueDisc Constructor.
virtual ~CoDelQueueDisc()
uint32_t GetQueueSize(void)
Get the current value of the queue in bytes or packets.
virtual void Serialize(TagBuffer i) const
uint32_t GetDropCount(void)
Get the number of packets dropped according to CoDel algorithm.
uint32_t GetNPacketFilters(void) const
Get the number of packet filters.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
TracedValue< uint32_t > m_lastCount
Last number of packets dropped since entering drop state.
Time m_interval
100 ms sliding minimum time window width
virtual Ptr< QueueDiscItem > DoDequeue(void)
Remove a packet from queue based on the current state If we are in dropping state, check if we could leave the dropping state or if we should perform next drop If we are not currently in dropping state, check if we need to enter the state and drop the first packet.
tag a set of bytes in a packet
Use number of bytes for maximum queue size.
uint16_t m_recInvSqrt
Reciprocal inverse square root.
#define REC_INV_SQRT_SHIFT
uint64_t m_creationTime
Tag creation time.
Time GetTarget(void)
Get the target queue delay.
#define DEFAULT_CODEL_LIMIT
Time TimeStep(uint64_t ts)
void NewtonStep(void)
Calculate the reciprocal square root of m_count by using Newton's method http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Iterative_methods_for_reciprocal_square_roots m_recInvSqrt (new) = (m_recInvSqrt (old) / 2) * (3 - m_count * m_recInvSqrt^2)
A CoDel packet queue disc.
static const int CODEL_SHIFT
Number of bits discarded from the time representation.
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.
QueueMode
Enumeration of the modes supported in the class.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
uint32_t m_state3
Number of times we enter drop state and drop the fist packet.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
uint32_t Time2CoDel(Time t)
returned unsigned 32-bit integer representation of the input Time object units are microseconds ...
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Use number of packets for maximum queue size.
static TypeId GetTypeId(void)
Get the type ID.
bool CoDelTimeBeforeEq(uint32_t a, uint32_t b)
Check if CoDel time a is preceding or equal to b.
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_minBytes
Minimum bytes in queue to allow a packet drop.
static uint32_t ReciprocalDivide(uint32_t A, uint32_t R)
Performs a reciprocal divide, similar to the Linux kernel reciprocal_divide function.
static uint32_t CoDelGetTime(void)
Returns the current time translated in CoDel time representation.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
void SetMode(Queue::QueueMode mode)
Set the operating mode of this device.
virtual void Print(std::ostream &os) const
uint32_t m_state1
Number of times packet sojourn goes above target for interval.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Time GetTxTime(void) const
Gets the Tag creation time.
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)
Set the parent TypeId.
TracedValue< uint32_t > m_dropNext
Time to drop next packet.
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.