30 #include "ns3/uinteger.h"
31 #include "ns3/abort.h"
41 return (uint32_t)(((uint64_t)A * R) >> 32);
64 virtual void Print (std::ostream &os)
const;
81 .AddConstructor<CoDelTimestampTag> ()
82 .AddAttribute (
"CreationTime",
83 "The time at which the timestamp was created",
129 .AddConstructor<CoDelQueue> ()
130 .AddAttribute (
"Mode",
131 "Whether to use Bytes (see MaxBytes) or Packets (see MaxPackets) as the maximum queue size metric.",
136 .AddAttribute (
"MaxPackets",
137 "The maximum number of packets accepted by this CoDelQueue.",
140 MakeUintegerChecker<uint32_t> ())
141 .AddAttribute (
"MaxBytes",
142 "The maximum number of bytes accepted by this CoDelQueue.",
145 MakeUintegerChecker<uint32_t> ())
146 .AddAttribute (
"MinBytes",
147 "The CoDel algorithm minbytes parameter.",
150 MakeUintegerChecker<uint32_t> ())
151 .AddAttribute (
"Interval",
152 "The CoDel algorithm interval",
156 .AddAttribute (
"Target",
157 "The CoDel algorithm target queue delay",
161 .AddTraceSource (
"Count",
164 .AddTraceSource (
"DropCount",
167 .AddTraceSource (
"LastCount",
170 .AddTraceSource (
"DropState",
173 .AddTraceSource (
"BytesInQueue",
174 "Number of bytes in the queue",
176 .AddTraceSource (
"Sojourn",
179 .AddTraceSource (
"DropNext",
180 "Time until next packet drop",
197 m_firstAboveTime (0),
219 uint32_t invsqrt2 = ((uint64_t) invsqrt * invsqrt) >> 32;
220 uint64_t val = (3ll << 32) - ((uint64_t)
m_count * invsqrt2);
223 val = (val * invsqrt) >> (32 - 2 + 1);
255 NS_LOG_LOGIC (
"Queue full (at max packets) -- droppping pkt");
263 NS_LOG_LOGIC (
"Queue full (packet would exceed max bytes) -- droppping pkt");
290 NS_ASSERT_MSG (found,
"found a packet without an input timestamp tag");
301 NS_LOG_LOGIC (
"Sojourn time is below target or number of bytes in queue is less than minBytes; packet should not be dropped");
311 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. ");
317 NS_LOG_LOGIC (
"Sojourn time has been above target for at least q->interval; it's OK to (possibly) drop packet.");
352 NS_LOG_LOGIC (
"In dropping state, check if it's OK to leave or next drop should occur");
356 NS_LOG_LOGIC (
"Sojourn time goes below target, it's OK to leave dropping state.");
371 NS_LOG_LOGIC (
"Sojourn time is still above target and it's time for next drop; dropping " << p);
411 NS_LOG_LOGIC (
"Not in dropping state; decide if we have to enter the state and drop the first packet");
415 NS_LOG_LOGIC (
"Sojourn time goes above target, dropping the first packet " << p <<
" and entering the dropping state");
456 NS_LOG_LOGIC (
"Running ControlLaw for input now: " << (
double)now);
458 NS_LOG_LOGIC (
"Scheduled next drop at " << (
double)
m_dropNext / 1000000 <<
" now " << (
double)now / 1000000);
535 return ((
int)(a) - (
int)(b) > 0);
541 return ((
int)(a) - (
int)(b) >= 0);
547 return ((
int)(a) - (
int)(b) < 0);
553 return ((
int)(a) - (
int)(b) <= 0);
uint32_t GetDropOverLimit(void)
Get the number of packets dropped when packets arrive at a full queue and cannot be enqueued...
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
bool CoDelTimeAfter(uint32_t a, uint32_t b)
Simulation virtual time values and global simulation resolution.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
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)
bool CoDelTimeAfterEq(uint32_t a, uint32_t b)
Control the scheduling of simulation events.
#define NS_ABORT_MSG(msg)
Abnormal program termination.
virtual bool DoEnqueue(Ptr< Packet > p)
Add a packet to the queue.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
hold variables of type string
void WriteU64(uint64_t v)
uint32_t m_state1
Number of times packet sojourn goes above target for interval.
uint32_t m_minBytes
Minimum bytes in queue to allow a packet drop.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
std::queue< Ptr< Packet > > m_packets
The packet queue.
TracedValue< uint32_t > m_dropNext
Time to drop next packet.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
TracedValue< uint32_t > m_lastCount
TracedValue< bool > m_dropping
True if in dropping state.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
uint32_t m_states
Total number of times we are in state 1, state 2, or state 3.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
uint32_t GetDropCount(void)
Get the number of packets dropped according to CoDel algorithm.
uint32_t ControlLaw(uint32_t t)
Determine the time for next drop CoDel control law is t + m_interval/sqrt(m_count).
uint32_t m_state2
Number of times we perform next drop while in dropping state.
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.
uint16_t m_recInvSqrt
Reciprocal inverse square root.
Time m_interval
100 ms sliding minimum time window width
Time GetTarget(void)
Get the target queue delay.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
virtual uint32_t GetSerializedSize(void) const
CoDelQueue::QueueMode GetMode(void)
Get the encapsulation mode of this device.
static TypeId GetTypeId(void)
bool OkToDrop(Ptr< Packet > p, uint32_t now)
Determine whether a packet is OK to be dropped.
hold variables of type 'enum'
uint32_t GetQueueSize(void)
Get the current value of the queue in bytes or packets.
TracedValue< uint32_t > m_dropCount
Number of dropped packets according CoDel algorithm.
Hold an unsigned integer type.
bool CoDelTimeBefore(uint32_t a, uint32_t b)
virtual void Deserialize(TagBuffer i)
uint32_t m_dropOverLimit
The number of packets dropped due to full queue.
virtual void Serialize(TagBuffer i) const
uint32_t m_maxBytes
Max # of bytes accepted by the queue.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
CoDelQueue()
CoDelQueue Constructor.
tag a set of bytes in a packet
Use number of bytes for maximum queue size.
uint32_t m_firstAboveTime
Time to declare sojourn time above target.
Time m_target
5 ms target queue delay
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
uint32_t m_maxPackets
Max # of packets accepted by the queue.
bool CoDelTimeBeforeEq(uint32_t a, uint32_t b)
Time TimeStep(uint64_t ts)
uint32_t GetDropNext(void)
Get the time for next packet drop while in the dropping state.
static const int CODEL_SHIFT
static TypeId GetTypeId(void)
static Time Now(void)
Return the "current simulation time".
QueueMode m_mode
The operating mode (Bytes or packets)
QueueMode
Enumeration of the modes supported in the class.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
virtual TypeId GetInstanceTypeId(void) const
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)
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
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 uint32_t ReciprocalDivide(uint32_t A, uint32_t R)
void SetMode(CoDelQueue::QueueMode mode)
Set the operating mode of this device.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
static uint32_t CoDelGetTime(void)
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
uint32_t Time2CoDel(Time t)
returned unsigned 32-bit integer representation of the input Time object units are microseconds ...
virtual Ptr< const Packet > DoPeek(void) const
Peek the front packet in the queue.
virtual void Print(std::ostream &os) const
Time GetInterval(void)
Get the interval.
uint32_t m_state3
Number of times we enter drop state and drop the fist packet.
Time GetTxTime(void) const
TracedValue< uint32_t > m_bytesInQueue
The total number of bytes in queue.
static const int DEFAULT_CODEL_LIMIT
TracedValue< uint32_t > m_count
Number of packets dropped since entering drop state.
virtual Ptr< Packet > 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.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
void Drop(Ptr< Packet > packet)
Drop a packet.
#define REC_INV_SQRT_SHIFT
TracedValue< Time > m_sojourn
Time in queue.