12#include "ns3/net-device-queue-interface.h"
13#include "ns3/object-vector.h"
14#include "ns3/packet.h"
15#include "ns3/pointer.h"
17#include "ns3/simulator.h"
18#include "ns3/socket.h"
19#include "ns3/uinteger.h"
33 .SetGroupName(
"TrafficControl")
35 .AddAttribute(
"QueueDisc",
36 "The queue disc attached to the class",
73 "Cannot set the queue disc on a class already having an attached queue disc");
78 : nTotalReceivedPackets(0),
79 nTotalReceivedBytes(0),
82 nTotalEnqueuedPackets(0),
83 nTotalEnqueuedBytes(0),
84 nTotalDequeuedPackets(0),
85 nTotalDequeuedBytes(0),
86 nTotalDroppedPackets(0),
87 nTotalDroppedPacketsBeforeEnqueue(0),
88 nTotalDroppedPacketsAfterDequeue(0),
89 nTotalDroppedBytes(0),
90 nTotalDroppedBytesBeforeEnqueue(0),
91 nTotalDroppedBytesAfterDequeue(0),
92 nTotalRequeuedPackets(0),
93 nTotalRequeuedBytes(0),
94 nTotalMarkedPackets(0),
103 auto it = nDroppedPacketsBeforeEnqueue.find(reason);
105 if (it != nDroppedPacketsBeforeEnqueue.end())
110 it = nDroppedPacketsAfterDequeue.find(reason);
112 if (it != nDroppedPacketsAfterDequeue.end())
124 auto it = nDroppedBytesBeforeEnqueue.find(reason);
126 if (it != nDroppedBytesBeforeEnqueue.end())
131 it = nDroppedBytesAfterDequeue.find(reason);
133 if (it != nDroppedBytesAfterDequeue.end())
144 auto it = nMarkedPackets.find(reason);
146 if (it != nMarkedPackets.end())
157 auto it = nMarkedBytes.find(reason);
159 if (it != nMarkedBytes.end())
171 <<
"Packets/Bytes received: " << nTotalReceivedPackets <<
" / " << nTotalReceivedBytes
173 <<
"Packets/Bytes enqueued: " << nTotalEnqueuedPackets <<
" / " << nTotalEnqueuedBytes
175 <<
"Packets/Bytes dequeued: " << nTotalDequeuedPackets <<
" / " << nTotalDequeuedBytes
177 <<
"Packets/Bytes requeued: " << nTotalRequeuedPackets <<
" / " << nTotalRequeuedBytes
179 <<
"Packets/Bytes dropped: " << nTotalDroppedPackets <<
" / " << nTotalDroppedBytes
181 <<
"Packets/Bytes dropped before enqueue: " << nTotalDroppedPacketsBeforeEnqueue <<
" / "
182 << nTotalDroppedBytesBeforeEnqueue;
184 auto itp = nDroppedPacketsBeforeEnqueue.begin();
185 auto itb = nDroppedBytesBeforeEnqueue.begin();
187 while (itp != nDroppedPacketsBeforeEnqueue.end() && itb != nDroppedBytesBeforeEnqueue.end())
190 os << std::endl <<
" " << itp->first <<
": " << itp->second <<
" / " << itb->second;
196 <<
"Packets/Bytes dropped after dequeue: " << nTotalDroppedPacketsAfterDequeue <<
" / "
197 << nTotalDroppedBytesAfterDequeue;
199 itp = nDroppedPacketsAfterDequeue.begin();
200 itb = nDroppedBytesAfterDequeue.begin();
202 while (itp != nDroppedPacketsAfterDequeue.end() && itb != nDroppedBytesAfterDequeue.end())
205 os << std::endl <<
" " << itp->first <<
": " << itp->second <<
" / " << itb->second;
211 <<
"Packets/Bytes sent: " << nTotalSentPackets <<
" / " << nTotalSentBytes << std::endl
212 <<
"Packets/Bytes marked: " << nTotalMarkedPackets <<
" / " << nTotalMarkedBytes;
214 itp = nMarkedPackets.begin();
215 itb = nMarkedBytes.begin();
217 while (itp != nMarkedPackets.end() && itb != nMarkedBytes.end())
220 os << std::endl <<
" " << itp->first <<
": " << itp->second <<
" / " << itb->second;
243 .SetGroupName(
"TrafficControl")
244 .AddAttribute(
"Quota",
245 "The maximum number of packets dequeued in a qdisc run",
249 .AddAttribute(
"InternalQueueList",
250 "The list of internal queues.",
254 .AddAttribute(
"PacketFilterList",
255 "The list of packet filters.",
259 .AddAttribute(
"QueueDiscClassList",
260 "The list of queue disc classes.",
264 .AddTraceSource(
"Enqueue",
265 "Enqueue a packet in the queue disc",
267 "ns3::QueueDiscItem::TracedCallback")
268 .AddTraceSource(
"Dequeue",
269 "Dequeue a packet from the queue disc",
271 "ns3::QueueDiscItem::TracedCallback")
272 .AddTraceSource(
"Requeue",
273 "Requeue a packet in the queue disc",
275 "ns3::QueueDiscItem::TracedCallback")
276 .AddTraceSource(
"Drop",
277 "Drop a packet stored in the queue disc",
279 "ns3::QueueDiscItem::TracedCallback")
280 .AddTraceSource(
"DropBeforeEnqueue",
281 "Drop a packet before enqueue",
283 "ns3::QueueDiscItem::TracedCallback")
284 .AddTraceSource(
"DropAfterDequeue",
285 "Drop a packet after dequeue",
287 "ns3::QueueDiscItem::TracedCallback")
288 .AddTraceSource(
"Mark",
289 "Mark a packet stored in the queue disc",
291 "ns3::QueueDiscItem::TracedCallback")
292 .AddTraceSource(
"PacketsInQueue",
293 "Number of packets currently stored in the queue disc",
295 "ns3::TracedValueCallback::Uint32")
296 .AddTraceSource(
"BytesInQueue",
297 "Number of bytes currently stored in the queue disc",
299 "ns3::TracedValueCallback::Uint32")
300 .AddTraceSource(
"SojournTime",
301 "Sojourn time of the last packet dequeued from the queue disc",
303 "ns3::Time::TracedCallback");
388 NS_ASSERT_MSG(ok,
"The queue disc configuration is not correct");
394 (*cl)->GetQueueDisc()->Initialize();
475 NS_LOG_DEBUG(
"Changing the mode of this queue disc is prohibited");
570 queue->TraceConnectWithoutContext(
573 queue->TraceConnectWithoutContext(
616 NS_ABORT_MSG_IF(!qdClass->GetQueueDisc(),
"Cannot add a class with no attached queue disc");
620 "A queue disc with WAKE_CHILD as wake mode can only be a root queue disc");
624 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
627 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
630 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
633 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
636 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
663 ret = (*f)->Classify(item);
732 itb->second += item->GetSize();
739 NS_LOG_DEBUG(
"Total packets/bytes dropped before enqueue: "
771 itb->second += item->GetSize();
789 NS_LOG_DEBUG(
"Total packets/bytes dropped after dequeue: "
802 bool retval = item->Mark();
826 itb->second += item->GetSize();
1071 item->GetPacket()->RemovePacketTag(priorityTag);
A base class which provides memory management and object aggregation.
virtual void DoInitialize()
Initialize() implementation.
virtual void DoDispose()
Destructor implementation.
static const int PF_NO_MATCH
Standard value used by packet filters to indicate that no match was possible.
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
QueueDiscClass is the base class for classes that are included in a queue disc.
~QueueDiscClass() override
Ptr< QueueDisc > GetQueueDisc() const
Get the queue disc attached to this class.
static TypeId GetTypeId()
Get the type ID.
void DoDispose() override
Dispose of the object.
void SetQueueDisc(Ptr< QueueDisc > qd)
Set the queue disc attached to this class.
Ptr< QueueDisc > m_queueDisc
Queue disc attached to this class.
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
std::vector< Ptr< PacketFilter > > m_filters
Packet filters.
std::vector< Ptr< QueueDiscClass > > m_classes
Classes.
static const uint32_t DEFAULT_QUOTA
Default quota (as in /proc/sys/net/core/dev_weight)
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
virtual uint32_t GetQuota() const
Get the maximum number of dequeue operations following a packet enqueue.
WakeMode
Used to determine whether the queue disc itself or its children must be activated when a netdevice wa...
void SetNetDeviceQueueInterface(Ptr< NetDeviceQueueInterface > ndqi)
void AddQueueDiscClass(Ptr< QueueDiscClass > qdClass)
Add a queue disc class to the tail of the list of classes.
QueueSize m_maxSize
max queue size
SendCallback GetSendCallback() const
TracedCallback< Ptr< const QueueDiscItem > > m_traceDequeue
Traced callback: fired when a packet is dequeued.
uint32_t GetNPackets() const
Get the number of packets stored by the queue disc.
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)=0
This function actually enqueues a packet into the queue disc.
Ptr< NetDeviceQueueInterface > m_devQueueIface
NetDevice queue interface.
bool Transmit(Ptr< QueueDiscItem > item)
Modelled after the Linux function sch_direct_xmit (net/sched/sch_generic.c) Sends a packet to the dev...
static constexpr const char * CHILD_QUEUE_DISC_MARK
Packet marked by a child queue disc.
uint32_t GetNBytes() const
Get the amount of bytes stored by the queue disc.
static constexpr const char * INTERNAL_QUEUE_DROP
Packet dropped by an internal queue.
QueueDisc(QueueDiscSizePolicy policy=QueueDiscSizePolicy::SINGLE_INTERNAL_QUEUE)
Constructor.
Ptr< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
Ptr< QueueDiscItem > m_requeued
The last packet that failed to be transmitted.
void Requeue(Ptr< QueueDiscItem > item)
Modelled after the Linux function dev_requeue_skb (net/sched/sch_generic.c) Requeues a packet whose t...
void AddPacketFilter(Ptr< PacketFilter > filter)
Add a packet filter to the tail of the list of filters used to classify packets.
TracedCallback< Ptr< const QueueDiscItem > > m_traceDrop
Traced callback: fired when a packet is dropped.
QueueSize GetCurrentSize() const
Get the current size of the queue disc in bytes, if operating in bytes mode, or packets,...
uint32_t m_quota
Maximum number of packets dequeued in a qdisc run.
virtual Ptr< const QueueDiscItem > DoPeek()
Return a copy of the next packet the queue disc will extract.
int32_t Classify(Ptr< QueueDiscItem > item)
Classify a packet by calling the packet filters, one at a time, until either a filter able to classif...
TracedCallback< Ptr< const QueueDiscItem > > m_traceRequeue
Traced callback: fired when a packet is requeued.
TracedValue< uint32_t > m_nBytes
Number of bytes in the queue.
void PacketEnqueued(Ptr< const QueueDiscItem > item)
Perform the actions required when the queue disc is notified of a packet enqueue.
bool m_prohibitChangeMode
True if changing mode is prohibited.
void DoInitialize() override
Check whether the configuration is correct and initialize parameters.
bool m_peeked
A packet was dequeued because Peek was called.
std::function< void(Ptr< QueueDiscItem >)> SendCallback
Callback invoked to send a packet to the receiving object when Run is called.
QueueDiscSizePolicy m_sizePolicy
The queue disc size policy.
bool m_running
The queue disc is performing multiple dequeue operations.
virtual bool CheckConfig()=0
Check whether the current configuration is correct.
TracedCallback< Ptr< const QueueDiscItem > > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
Ptr< NetDeviceQueueInterface > GetNetDeviceQueueInterface() const
void Run()
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets,...
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
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.
ChildQueueDiscMarkFunctor m_childQueueDiscMarkFunctor
Function object called when a child queue disc marked a packet.
void RunEnd()
Modelled after the Linux function qdisc_run_end (include/net/sch_generic.h).
std::size_t GetNQueueDiscClasses() const
Get the number of queue disc classes.
virtual void InitializeParams()=0
Initialize parameters (if any) before the first packet is enqueued.
Stats m_stats
The collected statistics.
const Stats & GetStats()
Retrieve all the collected statistics.
bool Restart()
Modelled after the Linux function qdisc_restart (net/sched/sch_generic.c) Dequeue a packet (by callin...
QueueSize GetMaxSize() const
Get the maximum size of the queue disc.
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
ChildQueueDiscDropFunctor m_childQueueDiscDbeFunctor
Function object called when a child queue disc dropped a packet before enqueue.
std::size_t GetNPacketFilters() const
Get the number of packet filters.
std::string m_childQueueDiscMarkMsg
Reason why a packet was marked by a child queue disc.
virtual void SetQuota(const uint32_t quota)
Set the maximum number of dequeue operations following a packet enqueue.
bool RunBegin()
Modelled after the Linux function qdisc_run_begin (include/net/sch_generic.h).
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
std::string m_childQueueDiscDropMsg
Reason why a packet was dropped by a child queue disc.
InternalQueueDropFunctor m_internalQueueDbeFunctor
Function object called when an internal queue dropped a packet before enqueue.
std::size_t GetNInternalQueues() const
Get the number of internal queues.
static TypeId GetTypeId()
Get the type ID.
void DoDispose() override
Dispose of the object.
SendCallback m_send
Callback used to send a packet to the receiving object.
virtual WakeMode GetWakeMode() const
When setting up the wake callbacks on the netdevice queues, it is necessary to determine which queue ...
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceDropBeforeEnqueue
Traced callback: fired when a packet is dropped before enqueue.
TracedCallback< Time > m_sojourn
Sojourn time of the latest dequeued packet.
static constexpr const char * CHILD_QUEUE_DISC_DROP
Packet dropped by a child queue disc.
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceMark
Traced callback: fired when a packet is marked.
Ptr< QueueDiscItem > DequeuePacket()
Modelled after the Linux function dequeue_skb (net/sched/sch_generic.c)
Ptr< QueueDiscItem > Dequeue()
Extract from the queue disc the packet that has been dequeued by calling Peek, if any,...
std::vector< Ptr< InternalQueue > > m_queues
Internal queues.
Ptr< const QueueDiscItem > Peek()
Get a copy of the next packet the queue discipline will extract.
ChildQueueDiscDropFunctor m_childQueueDiscDadFunctor
Function object called when a child queue disc dropped a packet after dequeue.
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceDropAfterDequeue
Traced callback: fired when a packet is dropped after dequeue.
InternalQueueDropFunctor m_internalQueueDadFunctor
Function object called when an internal queue dropped a packet after dequeue.
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.
Ptr< PacketFilter > GetPacketFilter(std::size_t i) const
Get the i-th packet filter.
void PacketDequeued(Ptr< const QueueDiscItem > item)
Perform the actions required when the queue disc is notified of a packet dequeue.
virtual Ptr< QueueDiscItem > DoDequeue()=0
This function actually extracts a packet from the queue disc.
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
void SetSendCallback(SendCallback func)
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
Class for representing queue sizes.
QueueSizeUnit GetUnit() const
Get the underlying unit.
uint32_t GetValue() const
Get the underlying value.
static Time Now()
Return the current simulation virtual time.
indicates whether the socket has a priority set.
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,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#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_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
QueueSizeUnit
Enumeration of the operating modes of queues.
@ BYTES
Use number of bytes for queue size.
@ PACKETS
Use number of packets 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.
@ SINGLE_CHILD_QUEUE_DISC
Used by queue discs with single child queue disc.
@ MULTIPLE_QUEUES
Used by queue discs with multiple internal queues/child queue discs.
@ NO_LIMITS
Used by queue discs with unlimited size.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
Ptr< const AttributeChecker > MakeUintegerChecker()
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
std::ostream & operator<<(std::ostream &os, const Angles &a)
Ptr< const AttributeChecker > MakeObjectVectorChecker()
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Structure that keeps the queue disc statistics.
std::map< std::string, uint64_t, std::less<> > nDroppedBytesAfterDequeue
Bytes dropped after dequeue, for each reason.
uint32_t GetNDroppedPackets(std::string reason) const
Get the number of packets dropped for the given reason.
uint64_t nTotalRequeuedBytes
Total requeued bytes.
std::map< std::string, uint32_t, std::less<> > nDroppedPacketsBeforeEnqueue
Packets dropped before enqueue, for each reason.
uint32_t nTotalEnqueuedPackets
Total enqueued packets.
uint64_t nTotalReceivedBytes
Total received bytes.
uint32_t nTotalRequeuedPackets
Total requeued packets.
uint64_t nTotalDroppedBytesBeforeEnqueue
Total bytes dropped before enqueue.
uint32_t nTotalDequeuedPackets
Total dequeued packets.
uint32_t nTotalDroppedPackets
Total dropped packets.
uint64_t GetNDroppedBytes(std::string reason) const
Get the amount of bytes dropped for the given reason.
uint64_t nTotalEnqueuedBytes
Total enqueued bytes.
uint32_t nTotalSentPackets
Total sent packets – this value is not kept up to date, call GetStats first.
uint32_t nTotalMarkedBytes
Total marked bytes.
uint32_t nTotalMarkedPackets
Total marked packets.
uint64_t GetNMarkedBytes(std::string reason) const
Get the amount of bytes marked for the given reason.
uint64_t nTotalDroppedBytesAfterDequeue
Total bytes dropped after dequeue.
std::map< std::string, uint64_t, std::less<> > nMarkedBytes
Marked bytes, for each reason.
std::map< std::string, uint64_t, std::less<> > nDroppedBytesBeforeEnqueue
Bytes dropped before enqueue, for each reason.
uint32_t nTotalDroppedPacketsBeforeEnqueue
Total packets dropped before enqueue.
uint64_t nTotalDroppedBytes
Total dropped bytes.
void Print(std::ostream &os) const
Print the statistics.
uint32_t nTotalReceivedPackets
Total received packets.
uint32_t GetNMarkedPackets(std::string reason) const
Get the number of packets marked for the given reason.
std::map< std::string, uint32_t, std::less<> > nDroppedPacketsAfterDequeue
Packets dropped after dequeue, for each reason.
std::map< std::string, uint32_t, std::less<> > nMarkedPackets
Marked packets, for each reason.
uint64_t nTotalSentBytes
Total sent bytes – this value is not kept up to date, call GetStats first.
uint32_t nTotalDroppedPacketsAfterDequeue
Total packets dropped after dequeue.
uint64_t nTotalDequeuedBytes
Total dequeued bytes.