21 #include "ns3/abort.h"
22 #include "ns3/uinteger.h"
23 #include "ns3/pointer.h"
24 #include "ns3/object-vector.h"
25 #include "ns3/packet.h"
26 #include "ns3/socket.h"
27 #include "ns3/simulator.h"
29 #include "ns3/net-device-queue-interface.h"
30 #include "ns3/queue.h"
43 .SetGroupName (
"TrafficControl")
45 .AddAttribute (
"QueueDisc",
"The queue disc attached to the class",
48 MakePointerChecker<QueueDisc> ())
87 : nTotalReceivedPackets (0),
88 nTotalReceivedBytes (0),
89 nTotalSentPackets (0),
91 nTotalEnqueuedPackets (0),
92 nTotalEnqueuedBytes (0),
93 nTotalDequeuedPackets (0),
94 nTotalDequeuedBytes (0),
95 nTotalDroppedPackets (0),
96 nTotalDroppedPacketsBeforeEnqueue (0),
97 nTotalDroppedPacketsAfterDequeue (0),
98 nTotalDroppedBytes (0),
99 nTotalDroppedBytesBeforeEnqueue (0),
100 nTotalDroppedBytesAfterDequeue (0),
101 nTotalRequeuedPackets (0),
102 nTotalRequeuedBytes (0),
103 nTotalMarkedPackets (0),
104 nTotalMarkedBytes (0)
112 auto it = nDroppedPacketsBeforeEnqueue.find (reason);
114 if (it != nDroppedPacketsBeforeEnqueue.end ())
119 it = nDroppedPacketsAfterDequeue.find (reason);
121 if (it != nDroppedPacketsAfterDequeue.end ())
133 auto it = nDroppedBytesBeforeEnqueue.find (reason);
135 if (it != nDroppedBytesBeforeEnqueue.end ())
140 it = nDroppedBytesAfterDequeue.find (reason);
142 if (it != nDroppedBytesAfterDequeue.end ())
153 auto it = nMarkedPackets.find (reason);
155 if (it != nMarkedPackets.end ())
166 auto it = nMarkedBytes.find (reason);
168 if (it != nMarkedBytes.end ())
179 std::map<std::string, uint32_t>::const_iterator itp;
180 std::map<std::string, uint64_t>::const_iterator itb;
182 os << std::endl <<
"Packets/Bytes received: "
183 << nTotalReceivedPackets <<
" / "
184 << nTotalReceivedBytes
185 << std::endl <<
"Packets/Bytes enqueued: "
186 << nTotalEnqueuedPackets <<
" / "
187 << nTotalEnqueuedBytes
188 << std::endl <<
"Packets/Bytes dequeued: "
189 << nTotalDequeuedPackets <<
" / "
190 << nTotalDequeuedBytes
191 << std::endl <<
"Packets/Bytes requeued: "
192 << nTotalRequeuedPackets <<
" / "
193 << nTotalRequeuedBytes
194 << std::endl <<
"Packets/Bytes dropped: "
195 << nTotalDroppedPackets <<
" / "
196 << nTotalDroppedBytes
197 << std::endl <<
"Packets/Bytes dropped before enqueue: "
198 << nTotalDroppedPacketsBeforeEnqueue <<
" / "
199 << nTotalDroppedBytesBeforeEnqueue;
201 itp = nDroppedPacketsBeforeEnqueue.begin ();
202 itb = nDroppedBytesBeforeEnqueue.begin ();
204 while (itp != nDroppedPacketsBeforeEnqueue.end () &&
205 itb != nDroppedBytesBeforeEnqueue.end ())
207 NS_ASSERT (itp->first.compare (itb->first) == 0);
208 os << std::endl <<
" " << itp->first <<
": "
209 << itp->second <<
" / " << itb->second;
214 os << std::endl <<
"Packets/Bytes dropped after dequeue: "
215 << nTotalDroppedPacketsAfterDequeue <<
" / "
216 << nTotalDroppedBytesAfterDequeue;
218 itp = nDroppedPacketsAfterDequeue.begin ();
219 itb = nDroppedBytesAfterDequeue.begin ();
221 while (itp != nDroppedPacketsAfterDequeue.end () &&
222 itb != nDroppedBytesAfterDequeue.end ())
224 NS_ASSERT (itp->first.compare (itb->first) == 0);
225 os << std::endl <<
" " << itp->first <<
": "
226 << itp->second <<
" / " << itb->second;
231 os << std::endl <<
"Packets/Bytes sent: "
232 << nTotalSentPackets <<
" / "
234 << std::endl <<
"Packets/Bytes marked: "
235 << nTotalMarkedPackets <<
" / "
236 << nTotalMarkedBytes;
238 itp = nMarkedPackets.begin ();
239 itb = nMarkedBytes.begin ();
241 while (itp != nMarkedPackets.end () &&
242 itb != nMarkedBytes.end ())
244 NS_ASSERT (itp->first.compare (itb->first) == 0);
245 os << std::endl <<
" " << itp->first <<
": "
246 << itp->second <<
" / " << itb->second;
266 .SetGroupName (
"TrafficControl")
267 .AddAttribute (
"Quota",
"The maximum number of packets dequeued in a qdisc run",
271 MakeUintegerChecker<uint32_t> ())
272 .AddAttribute (
"InternalQueueList",
"The list of internal queues.",
275 MakeObjectVectorChecker<InternalQueue> ())
276 .AddAttribute (
"PacketFilterList",
"The list of packet filters.",
279 MakeObjectVectorChecker<PacketFilter> ())
280 .AddAttribute (
"QueueDiscClassList",
"The list of queue disc classes.",
283 MakeObjectVectorChecker<QueueDiscClass> ())
284 .AddTraceSource (
"Enqueue",
"Enqueue a packet in the queue disc",
286 "ns3::QueueDiscItem::TracedCallback")
287 .AddTraceSource (
"Dequeue",
"Dequeue a packet from the queue disc",
289 "ns3::QueueDiscItem::TracedCallback")
290 .AddTraceSource (
"Requeue",
"Requeue a packet in the queue disc",
292 "ns3::QueueDiscItem::TracedCallback")
293 .AddTraceSource (
"Drop",
"Drop a packet stored in the queue disc",
295 "ns3::QueueDiscItem::TracedCallback")
296 .AddTraceSource (
"DropBeforeEnqueue",
"Drop a packet before enqueue",
298 "ns3::QueueDiscItem::TracedCallback")
299 .AddTraceSource (
"DropAfterDequeue",
"Drop a packet after dequeue",
301 "ns3::QueueDiscItem::TracedCallback")
302 .AddTraceSource (
"Mark",
"Mark a packet stored in the queue disc",
304 "ns3::QueueDiscItem::TracedCallback")
305 .AddTraceSource (
"PacketsInQueue",
306 "Number of packets currently stored in the queue disc",
308 "ns3::TracedValueCallback::Uint32")
309 .AddTraceSource (
"BytesInQueue",
310 "Number of bytes currently stored in the queue disc",
312 "ns3::TracedValueCallback::Uint32")
313 .AddTraceSource (
"SojournTime",
314 "Sojourn time of the last packet dequeued from the queue disc",
316 "ns3::Time::TracedCallback")
405 NS_ASSERT_MSG (ok,
"The queue disc configuration is not correct");
412 (*cl)->GetQueueDisc ()->Initialize ();
492 NS_LOG_DEBUG (
"Changing the mode of this queue disc is prohibited");
585 queue->TraceConnectWithoutContext (
"Enqueue",
587 queue->TraceConnectWithoutContext (
"Dequeue",
589 queue->TraceConnectWithoutContext (
"DropBeforeEnqueue",
592 queue->TraceConnectWithoutContext (
"DropAfterDequeue",
635 NS_ABORT_MSG_IF (qdClass->GetQueueDisc () == 0,
"Cannot add a class with no attached queue disc");
639 "A queue disc with WAKE_CHILD as wake mode can only be a root queue disc");
643 qdClass->GetQueueDisc ()->TraceConnectWithoutContext (
"Enqueue",
645 qdClass->GetQueueDisc ()->TraceConnectWithoutContext (
"Dequeue",
647 qdClass->GetQueueDisc ()->TraceConnectWithoutContext (
"DropBeforeEnqueue",
650 qdClass->GetQueueDisc ()->TraceConnectWithoutContext (
"DropAfterDequeue",
653 qdClass->GetQueueDisc ()->TraceConnectWithoutContext (
"Mark",
681 ret = (*f)->Classify (item);
750 itb->second += item->GetSize ();
757 NS_LOG_DEBUG (
"Total packets/bytes dropped before enqueue: "
789 itb->second += item->GetSize ();
807 NS_LOG_DEBUG (
"Total packets/bytes dropped after dequeue: "
820 bool retval = item->Mark ();
844 itb->second += item->GetSize ();
1089 item->GetPacket ()->RemovePacketTag (priorityTag);
double f(double x, void *params)
A base class which provides memory management and object aggregation.
virtual void DoDispose(void)
Destructor implementation.
virtual void DoInitialize(void)
Initialize() implementation.
Container for a set of ns3::Object pointers.
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.
virtual ~QueueDiscClass()
static TypeId GetTypeId(void)
Get the type ID.
Ptr< QueueDisc > GetQueueDisc(void) const
Get the queue disc attached to this class.
void SetQueueDisc(Ptr< QueueDisc > qd)
Set the queue disc attached to this class.
virtual void DoDispose(void)
Dispose of the object.
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...
bool Restart(void)
Modelled after the Linux function qdisc_restart (net/sched/sch_generic.c) Dequeue a packet (by callin...
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.
QueueSize GetCurrentSize(void)
Get the current size of the queue disc in bytes, if operating in bytes mode, or packets,...
WakeMode
Used to determine whether the queue disc itself or its children must be activated when a netdevice wa...
void RunEnd(void)
Modelled after the Linux function qdisc_run_end (include/net/sch_generic.h).
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
TracedCallback< Ptr< const QueueDiscItem > > m_traceDequeue
Traced callback: fired when a packet is dequeued.
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)=0
This function actually enqueues a packet into the queue disc.
uint32_t GetNBytes(void) const
Get the amount of bytes stored by 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.
QueueSize GetMaxSize(void) const
Get the maximum size of the queue disc.
static constexpr const char * INTERNAL_QUEUE_DROP
Packet dropped by an internal queue.
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceDropBeforeEnqueue
Traced callback: fired when a packet is dropped before enqueue.
QueueDisc(QueueDiscSizePolicy policy=QueueDiscSizePolicy::SINGLE_INTERNAL_QUEUE)
Constructor.
virtual WakeMode GetWakeMode(void) const
When setting up the wake callbacks on the netdevice queues, it is necessary to determine which queue ...
Ptr< const QueueDiscItem > Peek(void)
Get a copy of the next packet the queue discipline will extract.
Ptr< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
void Run(void)
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets,...
static TypeId GetTypeId(void)
Get the type ID.
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.
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.
virtual void InitializeParams(void)=0
Initialize parameters (if any) before the first packet is enqueued.
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.
bool m_peeked
A packet was dequeued because Peek was called.
QueueDiscSizePolicy m_sizePolicy
The queue disc size policy.
Ptr< QueueDiscItem > Dequeue(void)
Extract from the queue disc the packet that has been dequeued by calling Peek, if any,...
bool m_running
The queue disc is performing multiple dequeue operations.
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceMark
Traced callback: fired when a packet is marked.
TracedCallback< Ptr< const QueueDiscItem > > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
void DoInitialize(void)
Check whether the configuration is correct and initialize parameters.
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.
Ptr< NetDeviceQueueInterface > GetNetDeviceQueueInterface(void) const
std::size_t GetNPacketFilters(void) const
Get the number of packet filters.
Stats m_stats
The collected statistics.
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
bool RunBegin(void)
Modelled after the Linux function qdisc_run_begin (include/net/sch_generic.h).
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
std::size_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
virtual Ptr< const QueueDiscItem > DoPeek(void)
Return a copy of the next packet the queue disc will extract.
virtual uint32_t GetQuota(void) const
Get the maximum number of dequeue operations following a packet enqueue.
Ptr< QueueDiscItem > DequeuePacket(void)
Modelled after the Linux function dequeue_skb (net/sched/sch_generic.c)
ChildQueueDiscDropFunctor m_childQueueDiscDbeFunctor
Function object called when a child queue disc dropped a packet before enqueue.
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 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::function< void(Ptr< QueueDiscItem >)> SendCallback
Callback invoked to send a packet to the receiving object when Run is called.
virtual bool CheckConfig(void)=0
Check whether the current configuration is correct.
virtual void DoDispose(void)
Dispose of the object.
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceDropAfterDequeue
Traced callback: fired when a packet is dropped after dequeue.
SendCallback GetSendCallback(void) const
SendCallback m_send
Callback used to send a packet to the receiving object.
const Stats & GetStats(void)
Retrieve all the collected statistics.
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.
std::size_t GetNInternalQueues(void) const
Get the number of internal queues.
std::vector< Ptr< InternalQueue > > m_queues
Internal queues.
ChildQueueDiscDropFunctor m_childQueueDiscDadFunctor
Function object called when a child queue disc dropped a packet 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.
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
void SetSendCallback(SendCallback func)
virtual Ptr< QueueDiscItem > DoDequeue(void)=0
This function actually extracts a packet from the queue disc.
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(void)
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 > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#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.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
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.