23#include "ns3/net-device-queue-interface.h"
24#include "ns3/object-vector.h"
25#include "ns3/packet.h"
26#include "ns3/pointer.h"
28#include "ns3/simulator.h"
29#include "ns3/socket.h"
30#include "ns3/uinteger.h"
44 .SetGroupName(
"TrafficControl")
46 .AddAttribute(
"QueueDisc",
47 "The queue disc attached to the class",
50 MakePointerChecker<QueueDisc>());
84 "Cannot set the queue disc on a class already having an attached queue disc");
89 : nTotalReceivedPackets(0),
90 nTotalReceivedBytes(0),
93 nTotalEnqueuedPackets(0),
94 nTotalEnqueuedBytes(0),
95 nTotalDequeuedPackets(0),
96 nTotalDequeuedBytes(0),
97 nTotalDroppedPackets(0),
98 nTotalDroppedPacketsBeforeEnqueue(0),
99 nTotalDroppedPacketsAfterDequeue(0),
100 nTotalDroppedBytes(0),
101 nTotalDroppedBytesBeforeEnqueue(0),
102 nTotalDroppedBytesAfterDequeue(0),
103 nTotalRequeuedPackets(0),
104 nTotalRequeuedBytes(0),
105 nTotalMarkedPackets(0),
114 auto it = nDroppedPacketsBeforeEnqueue.find(reason);
116 if (it != nDroppedPacketsBeforeEnqueue.end())
121 it = nDroppedPacketsAfterDequeue.find(reason);
123 if (it != nDroppedPacketsAfterDequeue.end())
135 auto it = nDroppedBytesBeforeEnqueue.find(reason);
137 if (it != nDroppedBytesBeforeEnqueue.end())
142 it = nDroppedBytesAfterDequeue.find(reason);
144 if (it != nDroppedBytesAfterDequeue.end())
155 auto it = nMarkedPackets.find(reason);
157 if (it != nMarkedPackets.end())
168 auto it = nMarkedBytes.find(reason);
170 if (it != nMarkedBytes.end())
181 std::map<std::string, uint32_t>::const_iterator itp;
182 std::map<std::string, uint64_t>::const_iterator itb;
185 <<
"Packets/Bytes received: " << nTotalReceivedPackets <<
" / " << nTotalReceivedBytes
187 <<
"Packets/Bytes enqueued: " << nTotalEnqueuedPackets <<
" / " << nTotalEnqueuedBytes
189 <<
"Packets/Bytes dequeued: " << nTotalDequeuedPackets <<
" / " << nTotalDequeuedBytes
191 <<
"Packets/Bytes requeued: " << nTotalRequeuedPackets <<
" / " << nTotalRequeuedBytes
193 <<
"Packets/Bytes dropped: " << nTotalDroppedPackets <<
" / " << nTotalDroppedBytes
195 <<
"Packets/Bytes dropped before enqueue: " << nTotalDroppedPacketsBeforeEnqueue <<
" / "
196 << nTotalDroppedBytesBeforeEnqueue;
198 itp = nDroppedPacketsBeforeEnqueue.begin();
199 itb = nDroppedBytesBeforeEnqueue.begin();
201 while (itp != nDroppedPacketsBeforeEnqueue.end() && itb != nDroppedBytesBeforeEnqueue.end())
204 os << std::endl <<
" " << itp->first <<
": " << itp->second <<
" / " << itb->second;
210 <<
"Packets/Bytes dropped after dequeue: " << nTotalDroppedPacketsAfterDequeue <<
" / "
211 << nTotalDroppedBytesAfterDequeue;
213 itp = nDroppedPacketsAfterDequeue.begin();
214 itb = nDroppedBytesAfterDequeue.begin();
216 while (itp != nDroppedPacketsAfterDequeue.end() && itb != nDroppedBytesAfterDequeue.end())
219 os << std::endl <<
" " << itp->first <<
": " << itp->second <<
" / " << itb->second;
225 <<
"Packets/Bytes sent: " << nTotalSentPackets <<
" / " << nTotalSentBytes << std::endl
226 <<
"Packets/Bytes marked: " << nTotalMarkedPackets <<
" / " << nTotalMarkedBytes;
228 itp = nMarkedPackets.begin();
229 itb = nMarkedBytes.begin();
231 while (itp != nMarkedPackets.end() && itb != nMarkedBytes.end())
234 os << std::endl <<
" " << itp->first <<
": " << itp->second <<
" / " << itb->second;
257 .SetGroupName(
"TrafficControl")
258 .AddAttribute(
"Quota",
259 "The maximum number of packets dequeued in a qdisc run",
262 MakeUintegerChecker<uint32_t>())
263 .AddAttribute(
"InternalQueueList",
264 "The list of internal queues.",
267 MakeObjectVectorChecker<InternalQueue>())
268 .AddAttribute(
"PacketFilterList",
269 "The list of packet filters.",
272 MakeObjectVectorChecker<PacketFilter>())
273 .AddAttribute(
"QueueDiscClassList",
274 "The list of queue disc classes.",
277 MakeObjectVectorChecker<QueueDiscClass>())
278 .AddTraceSource(
"Enqueue",
279 "Enqueue a packet in the queue disc",
281 "ns3::QueueDiscItem::TracedCallback")
282 .AddTraceSource(
"Dequeue",
283 "Dequeue a packet from the queue disc",
285 "ns3::QueueDiscItem::TracedCallback")
286 .AddTraceSource(
"Requeue",
287 "Requeue a packet in the queue disc",
289 "ns3::QueueDiscItem::TracedCallback")
290 .AddTraceSource(
"Drop",
291 "Drop a packet stored in the queue disc",
293 "ns3::QueueDiscItem::TracedCallback")
294 .AddTraceSource(
"DropBeforeEnqueue",
295 "Drop a packet before enqueue",
297 "ns3::QueueDiscItem::TracedCallback")
298 .AddTraceSource(
"DropAfterDequeue",
299 "Drop a packet after dequeue",
301 "ns3::QueueDiscItem::TracedCallback")
302 .AddTraceSource(
"Mark",
303 "Mark a packet stored in the queue disc",
305 "ns3::QueueDiscItem::TracedCallback")
306 .AddTraceSource(
"PacketsInQueue",
307 "Number of packets currently stored in the queue disc",
309 "ns3::TracedValueCallback::Uint32")
310 .AddTraceSource(
"BytesInQueue",
311 "Number of bytes currently stored in the queue disc",
313 "ns3::TracedValueCallback::Uint32")
314 .AddTraceSource(
"SojournTime",
315 "Sojourn time of the last packet dequeued from the queue disc",
317 "ns3::Time::TracedCallback");
402 NS_ASSERT_MSG(ok,
"The queue disc configuration is not correct");
409 (*cl)->GetQueueDisc()->Initialize();
490 NS_LOG_DEBUG(
"Changing the mode of this queue disc is prohibited");
585 queue->TraceConnectWithoutContext(
588 queue->TraceConnectWithoutContext(
631 NS_ABORT_MSG_IF(!qdClass->GetQueueDisc(),
"Cannot add a class with no attached queue disc");
635 "A queue disc with WAKE_CHILD as wake mode can only be a root queue disc");
639 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
642 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
645 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
648 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
651 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
680 ret = (*f)->Classify(item);
736 std::map<std::string, uint32_t>::iterator itp =
750 itb->second += item->GetSize();
757 NS_LOG_DEBUG(
"Total packets/bytes dropped before enqueue: "
776 std::map<std::string, uint32_t>::iterator itp =
790 itb->second += item->GetSize();
808 NS_LOG_DEBUG(
"Total packets/bytes dropped after dequeue: "
821 bool retval = item->Mark();
845 itb->second += item->GetSize();
1090 item->GetPacket()->RemovePacketTag(priorityTag);
double f(double x, void *params)
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.
Hold objects of type Ptr<T>.
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
QueueSize GetCurrentSize()
Get the current size of the queue disc in bytes, if operating in bytes mode, or packets,...
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.
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...
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
#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)
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...
std::ostream & operator<<(std::ostream &os, const Angles &a)
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.