21 #include "ns3/abort.h"
23 #include "ns3/net-device-queue-interface.h"
24 #include "ns3/object-vector.h"
25 #include "ns3/packet.h"
26 #include "ns3/pointer.h"
27 #include "ns3/queue.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())
182 <<
"Packets/Bytes received: " << nTotalReceivedPackets <<
" / " << nTotalReceivedBytes
184 <<
"Packets/Bytes enqueued: " << nTotalEnqueuedPackets <<
" / " << nTotalEnqueuedBytes
186 <<
"Packets/Bytes dequeued: " << nTotalDequeuedPackets <<
" / " << nTotalDequeuedBytes
188 <<
"Packets/Bytes requeued: " << nTotalRequeuedPackets <<
" / " << nTotalRequeuedBytes
190 <<
"Packets/Bytes dropped: " << nTotalDroppedPackets <<
" / " << nTotalDroppedBytes
192 <<
"Packets/Bytes dropped before enqueue: " << nTotalDroppedPacketsBeforeEnqueue <<
" / "
193 << nTotalDroppedBytesBeforeEnqueue;
195 auto itp = nDroppedPacketsBeforeEnqueue.begin();
196 auto itb = nDroppedBytesBeforeEnqueue.begin();
198 while (itp != nDroppedPacketsBeforeEnqueue.end() && itb != nDroppedBytesBeforeEnqueue.end())
201 os << std::endl <<
" " << itp->first <<
": " << itp->second <<
" / " << itb->second;
207 <<
"Packets/Bytes dropped after dequeue: " << nTotalDroppedPacketsAfterDequeue <<
" / "
208 << nTotalDroppedBytesAfterDequeue;
210 itp = nDroppedPacketsAfterDequeue.begin();
211 itb = nDroppedBytesAfterDequeue.begin();
213 while (itp != nDroppedPacketsAfterDequeue.end() && itb != nDroppedBytesAfterDequeue.end())
216 os << std::endl <<
" " << itp->first <<
": " << itp->second <<
" / " << itb->second;
222 <<
"Packets/Bytes sent: " << nTotalSentPackets <<
" / " << nTotalSentBytes << std::endl
223 <<
"Packets/Bytes marked: " << nTotalMarkedPackets <<
" / " << nTotalMarkedBytes;
225 itp = nMarkedPackets.begin();
226 itb = nMarkedBytes.begin();
228 while (itp != nMarkedPackets.end() && itb != nMarkedBytes.end())
231 os << std::endl <<
" " << itp->first <<
": " << itp->second <<
" / " << itb->second;
254 .SetGroupName(
"TrafficControl")
255 .AddAttribute(
"Quota",
256 "The maximum number of packets dequeued in a qdisc run",
259 MakeUintegerChecker<uint32_t>())
260 .AddAttribute(
"InternalQueueList",
261 "The list of internal queues.",
264 MakeObjectVectorChecker<InternalQueue>())
265 .AddAttribute(
"PacketFilterList",
266 "The list of packet filters.",
269 MakeObjectVectorChecker<PacketFilter>())
270 .AddAttribute(
"QueueDiscClassList",
271 "The list of queue disc classes.",
274 MakeObjectVectorChecker<QueueDiscClass>())
275 .AddTraceSource(
"Enqueue",
276 "Enqueue a packet in the queue disc",
278 "ns3::QueueDiscItem::TracedCallback")
279 .AddTraceSource(
"Dequeue",
280 "Dequeue a packet from the queue disc",
282 "ns3::QueueDiscItem::TracedCallback")
283 .AddTraceSource(
"Requeue",
284 "Requeue a packet in the queue disc",
286 "ns3::QueueDiscItem::TracedCallback")
287 .AddTraceSource(
"Drop",
288 "Drop a packet stored in the queue disc",
290 "ns3::QueueDiscItem::TracedCallback")
291 .AddTraceSource(
"DropBeforeEnqueue",
292 "Drop a packet before enqueue",
294 "ns3::QueueDiscItem::TracedCallback")
295 .AddTraceSource(
"DropAfterDequeue",
296 "Drop a packet after dequeue",
298 "ns3::QueueDiscItem::TracedCallback")
299 .AddTraceSource(
"Mark",
300 "Mark a packet stored in the queue disc",
302 "ns3::QueueDiscItem::TracedCallback")
303 .AddTraceSource(
"PacketsInQueue",
304 "Number of packets currently stored in the queue disc",
306 "ns3::TracedValueCallback::Uint32")
307 .AddTraceSource(
"BytesInQueue",
308 "Number of bytes currently stored in the queue disc",
310 "ns3::TracedValueCallback::Uint32")
311 .AddTraceSource(
"SojournTime",
312 "Sojourn time of the last packet dequeued from the queue disc",
314 "ns3::Time::TracedCallback");
399 NS_ASSERT_MSG(ok,
"The queue disc configuration is not correct");
405 (*cl)->GetQueueDisc()->Initialize();
486 NS_LOG_DEBUG(
"Changing the mode of this queue disc is prohibited");
581 queue->TraceConnectWithoutContext(
584 queue->TraceConnectWithoutContext(
627 NS_ABORT_MSG_IF(!qdClass->GetQueueDisc(),
"Cannot add a class with no attached queue disc");
631 "A queue disc with WAKE_CHILD as wake mode can only be a root queue disc");
635 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
638 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
641 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
644 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
647 qdClass->GetQueueDisc()->TraceConnectWithoutContext(
674 ret = (*f)->Classify(item);
743 itb->second += item->GetSize();
750 NS_LOG_DEBUG(
"Total packets/bytes dropped before enqueue: "
782 itb->second += item->GetSize();
800 NS_LOG_DEBUG(
"Total packets/bytes dropped after dequeue: "
813 bool retval = item->Mark();
837 itb->second += item->GetSize();
1082 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>.
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.
virtual Ptr< QueueDiscItem > DoDequeue()=0
This function actually extracts a packet from the queue disc.
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.
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...
#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.
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 > MakePointerAccessor(T1 a1)
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
std::ostream & operator<<(std::ostream &os, const Angles &a)
U * PeekPointer(const Ptr< U > &p)
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.