|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
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/unused.h"
28 #include "ns3/simulator.h"
30 #include "ns3/net-device-queue-interface.h"
31 #include "ns3/queue.h"
44 .SetGroupName (
"TrafficControl")
46 .AddAttribute (
"QueueDisc",
"The queue disc attached to the class",
49 MakePointerChecker<QueueDisc> ())
88 : nTotalReceivedPackets (0),
89 nTotalReceivedBytes (0),
90 nTotalSentPackets (0),
92 nTotalEnqueuedPackets (0),
93 nTotalEnqueuedBytes (0),
94 nTotalDequeuedPackets (0),
95 nTotalDequeuedBytes (0),
96 nTotalDroppedPackets (0),
97 nTotalDroppedPacketsBeforeEnqueue (0),
98 nTotalDroppedPacketsAfterDequeue (0),
99 nTotalDroppedBytes (0),
100 nTotalDroppedBytesBeforeEnqueue (0),
101 nTotalDroppedBytesAfterDequeue (0),
102 nTotalRequeuedPackets (0),
103 nTotalRequeuedBytes (0),
104 nTotalMarkedPackets (0),
105 nTotalMarkedBytes (0)
113 auto it = nDroppedPacketsBeforeEnqueue.find (reason);
115 if (it != nDroppedPacketsBeforeEnqueue.end ())
120 it = nDroppedPacketsAfterDequeue.find (reason);
122 if (it != nDroppedPacketsAfterDequeue.end ())
134 auto it = nDroppedBytesBeforeEnqueue.find (reason);
136 if (it != nDroppedBytesBeforeEnqueue.end ())
141 it = nDroppedBytesAfterDequeue.find (reason);
143 if (it != nDroppedBytesAfterDequeue.end ())
154 auto it = nMarkedPackets.find (reason);
156 if (it != nMarkedPackets.end ())
167 auto it = nMarkedBytes.find (reason);
169 if (it != nMarkedBytes.end ())
180 std::map<std::string, uint32_t>::const_iterator itp;
181 std::map<std::string, uint64_t>::const_iterator itb;
183 os << std::endl <<
"Packets/Bytes received: "
184 << nTotalReceivedPackets <<
" / "
185 << nTotalReceivedBytes
186 << std::endl <<
"Packets/Bytes enqueued: "
187 << nTotalEnqueuedPackets <<
" / "
188 << nTotalEnqueuedBytes
189 << std::endl <<
"Packets/Bytes dequeued: "
190 << nTotalDequeuedPackets <<
" / "
191 << nTotalDequeuedBytes
192 << std::endl <<
"Packets/Bytes requeued: "
193 << nTotalRequeuedPackets <<
" / "
194 << nTotalRequeuedBytes
195 << std::endl <<
"Packets/Bytes dropped: "
196 << nTotalDroppedPackets <<
" / "
197 << nTotalDroppedBytes
198 << std::endl <<
"Packets/Bytes dropped before enqueue: "
199 << nTotalDroppedPacketsBeforeEnqueue <<
" / "
200 << nTotalDroppedBytesBeforeEnqueue;
202 itp = nDroppedPacketsBeforeEnqueue.begin ();
203 itb = nDroppedBytesBeforeEnqueue.begin ();
205 while (itp != nDroppedPacketsBeforeEnqueue.end () &&
206 itb != nDroppedBytesBeforeEnqueue.end ())
208 NS_ASSERT (itp->first.compare (itb->first) == 0);
209 os << std::endl <<
" " << itp->first <<
": "
210 << itp->second <<
" / " << itb->second;
215 os << std::endl <<
"Packets/Bytes dropped after dequeue: "
216 << nTotalDroppedPacketsAfterDequeue <<
" / "
217 << nTotalDroppedBytesAfterDequeue;
219 itp = nDroppedPacketsAfterDequeue.begin ();
220 itb = nDroppedBytesAfterDequeue.begin ();
222 while (itp != nDroppedPacketsAfterDequeue.end () &&
223 itb != nDroppedBytesAfterDequeue.end ())
225 NS_ASSERT (itp->first.compare (itb->first) == 0);
226 os << std::endl <<
" " << itp->first <<
": "
227 << itp->second <<
" / " << itb->second;
232 os << std::endl <<
"Packets/Bytes sent: "
233 << nTotalSentPackets <<
" / "
235 << std::endl <<
"Packets/Bytes marked: "
236 << nTotalMarkedPackets <<
" / "
237 << nTotalMarkedBytes;
239 itp = nMarkedPackets.begin ();
240 itb = nMarkedBytes.begin ();
242 while (itp != nMarkedPackets.end () &&
243 itb != nMarkedBytes.end ())
245 NS_ASSERT (itp->first.compare (itb->first) == 0);
246 os << std::endl <<
" " << itp->first <<
": "
247 << itp->second <<
" / " << itb->second;
267 .SetGroupName (
"TrafficControl")
268 .AddAttribute (
"Quota",
"The maximum number of packets dequeued in a qdisc run",
272 MakeUintegerChecker<uint32_t> ())
273 .AddAttribute (
"InternalQueueList",
"The list of internal queues.",
276 MakeObjectVectorChecker<InternalQueue> ())
277 .AddAttribute (
"PacketFilterList",
"The list of packet filters.",
280 MakeObjectVectorChecker<PacketFilter> ())
281 .AddAttribute (
"QueueDiscClassList",
"The list of queue disc classes.",
284 MakeObjectVectorChecker<QueueDiscClass> ())
285 .AddTraceSource (
"Enqueue",
"Enqueue a packet in the queue disc",
287 "ns3::QueueDiscItem::TracedCallback")
288 .AddTraceSource (
"Dequeue",
"Dequeue a packet from the queue disc",
290 "ns3::QueueDiscItem::TracedCallback")
291 .AddTraceSource (
"Requeue",
"Requeue a packet in the queue disc",
293 "ns3::QueueDiscItem::TracedCallback")
294 .AddTraceSource (
"Drop",
"Drop a packet stored in the queue disc",
296 "ns3::QueueDiscItem::TracedCallback")
297 .AddTraceSource (
"DropBeforeEnqueue",
"Drop a packet before enqueue",
299 "ns3::QueueDiscItem::TracedCallback")
300 .AddTraceSource (
"DropAfterDequeue",
"Drop a packet after dequeue",
302 "ns3::QueueDiscItem::TracedCallback")
303 .AddTraceSource (
"Mark",
"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")
406 NS_ASSERT_MSG (ok,
"The queue disc configuration is not correct");
414 (*cl)->GetQueueDisc ()->Initialize ();
494 NS_LOG_DEBUG (
"Changing the mode of this queue disc is prohibited");
587 queue->TraceConnectWithoutContext (
"Enqueue",
589 queue->TraceConnectWithoutContext (
"Dequeue",
591 queue->TraceConnectWithoutContext (
"DropBeforeEnqueue",
594 queue->TraceConnectWithoutContext (
"DropAfterDequeue",
637 NS_ABORT_MSG_IF (qdClass->GetQueueDisc () == 0,
"Cannot add a class with no attached queue disc");
641 "A queue disc with WAKE_CHILD as wake mode can only be a root queue disc");
645 qdClass->GetQueueDisc ()->TraceConnectWithoutContext (
"Enqueue",
647 qdClass->GetQueueDisc ()->TraceConnectWithoutContext (
"Dequeue",
649 qdClass->GetQueueDisc ()->TraceConnectWithoutContext (
"DropBeforeEnqueue",
652 qdClass->GetQueueDisc ()->TraceConnectWithoutContext (
"DropAfterDequeue",
655 qdClass->GetQueueDisc ()->TraceConnectWithoutContext (
"Mark",
683 ret = (*f)->Classify (item);
752 itb->second += item->GetSize ();
759 NS_LOG_DEBUG (
"Total packets/bytes dropped before enqueue: "
791 itb->second += item->GetSize ();
809 NS_LOG_DEBUG (
"Total packets/bytes dropped after dequeue: "
822 bool retval = item->Mark ();
846 itb->second += item->GetSize ();
1091 item->GetPacket ()->RemovePacketTag (priorityTag);
a unique identifier for an interface.
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void RunEnd(void)
Modelled after the Linux function qdisc_run_end (include/net/sch_generic.h).
std::map< std::string, uint32_t > nDroppedPacketsBeforeEnqueue
Packets dropped before enqueue, for each reason.
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
std::map< std::string, uint32_t > nDroppedPacketsAfterDequeue
Packets dropped after dequeue, for each reason.
@ MULTIPLE_QUEUES
Used by queue discs with multiple internal queues/child queue discs.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
virtual bool CheckConfig(void)=0
Check whether the current configuration is correct.
virtual uint32_t GetQuota(void) const
Get the maximum number of dequeue operations following a packet enqueue.
TracedCallback< Time > m_sojourn
Sojourn time of the latest dequeued packet.
Structure that keeps the queue disc statistics.
static constexpr const char * CHILD_QUEUE_DISC_MARK
Packet marked by a child queue disc.
void Run(void)
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets,...
uint32_t nTotalMarkedPackets
Total marked packets.
uint32_t m_quota
Maximum number of packets dequeued in a qdisc run.
static TypeId GetTypeId(void)
Get the type ID.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
TracedCallback< Ptr< const QueueDiscItem > > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
static Time Now(void)
Return the current simulation virtual time.
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t nTotalRequeuedPackets
Total requeued packets.
Ptr< QueueDisc > GetQueueDisc(void) const
Get the queue disc attached to this class.
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
QueueSize GetMaxSize(void) const
Get the maximum size of the queue disc.
uint32_t nTotalDequeuedPackets
Total dequeued packets.
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
Ptr< QueueDisc > m_queueDisc
Queue disc attached to this class.
uint32_t nTotalDroppedPackets
Total dropped packets.
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
uint32_t nTotalSentPackets
Total sent packets – this value is not kept up to date, call GetStats first.
std::vector< Ptr< PacketFilter > > m_filters
Packet filters.
Ptr< PacketFilter > GetPacketFilter(std::size_t i) const
Get the i-th packet filter.
@ NO_LIMITS
Used by queue discs with unlimited size.
Hold objects of type Ptr<T>.
static TypeId GetTypeId(void)
Get the type ID.
Container for a set of ns3::Object pointers.
uint32_t GetNBytes(void) const
Get the amount of bytes stored by the queue disc.
@ PACKETS
Use number of packets for queue size.
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceDropBeforeEnqueue
Traced callback: fired when a packet is dropped before enqueue.
void AddQueueDiscClass(Ptr< QueueDiscClass > qdClass)
Add a queue disc class to the tail of the list of classes.
bool m_peeked
A packet was dequeued because Peek was called.
QueueSize m_maxSize
max queue size
virtual void SetQuota(const uint32_t quota)
Set the maximum number of dequeue operations following a packet enqueue.
uint64_t GetNMarkedBytes(std::string reason) const
Get the amount of bytes marked for the given reason.
void DoInitialize(void)
Check whether the configuration is correct and initialize parameters.
std::size_t GetNPacketFilters(void) const
Get the number of packet filters.
void SetQueueDisc(Ptr< QueueDisc > qd)
Set the queue disc attached to this class.
U * PeekPointer(const Ptr< U > &p)
TypeId SetParent(TypeId tid)
Set the parent TypeId.
WakeMode
Used to determine whether the queue disc itself or its children must be activated when a netdevice wa...
uint64_t nTotalDroppedBytesBeforeEnqueue
Total bytes dropped before enqueue.
TracedCallback< Ptr< const QueueDiscItem > > m_traceRequeue
Traced callback: fired when a packet is requeued.
bool Mark(Ptr< QueueDiscItem > item, const char *reason)
Marks the given packet and, if successful, updates the counters associated with the given reason.
static constexpr const char * CHILD_QUEUE_DISC_DROP
Packet dropped by a child queue disc.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Ptr< const QueueDiscItem > Peek(void)
Get a copy of the next packet the queue discipline will extract.
QueueDiscClass is the base class for classes that are included in a queue disc.
uint64_t nTotalEnqueuedBytes
Total enqueued bytes.
void PacketEnqueued(Ptr< const QueueDiscItem > item)
Perform the actions required when the queue disc is notified of a packet enqueue.
InternalQueueDropFunctor m_internalQueueDadFunctor
Function object called when an internal queue dropped a packet after dequeue.
bool Transmit(Ptr< QueueDiscItem > item)
Modelled after the Linux function sch_direct_xmit (net/sched/sch_generic.c) Sends a packet to the dev...
Ptr< NetDeviceQueueInterface > GetNetDeviceQueueInterface(void) const
uint32_t nTotalDroppedPacketsBeforeEnqueue
Total packets dropped before enqueue.
void Requeue(Ptr< QueueDiscItem > item)
Modelled after the Linux function dev_requeue_skb (net/sched/sch_generic.c) Requeues a packet whose t...
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceMark
Traced callback: fired when a packet is marked.
uint32_t nTotalDroppedPacketsAfterDequeue
Total packets dropped after dequeue.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
virtual void DoDispose(void)
Dispose of the object.
virtual void DoDispose(void)
Dispose of the object.
uint32_t nTotalMarkedBytes
Total marked bytes.
virtual void InitializeParams(void)=0
Initialize parameters (if any) before the first packet is enqueued.
uint32_t GetNMarkedPackets(std::string reason) const
Get the number of packets marked for the given reason.
bool m_running
The queue disc is performing multiple dequeue operations.
A base class which provides memory management and object aggregation.
std::string m_childQueueDiscDropMsg
Reason why a packet was dropped by a child queue disc.
uint32_t GetNDroppedPackets(std::string reason) const
Get the number of packets dropped for the given reason.
#define NS_UNUSED(x)
Mark a local variable as unused.
@ SINGLE_INTERNAL_QUEUE
Used by queue discs with single internal queue.
uint64_t nTotalRequeuedBytes
Total requeued bytes.
uint64_t nTotalSentBytes
Total sent bytes – this value is not kept up to date, call GetStats first.
virtual Ptr< const QueueDiscItem > DoPeek(void)
Return a copy of the next packet the queue disc will extract.
QueueSizeUnit GetUnit() const
Get the underlying unit.
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
std::size_t GetNInternalQueues(void) const
Get the number of internal queues.
uint64_t nTotalReceivedBytes
Total received bytes.
QueueSize GetCurrentSize(void)
Get the current size of the queue disc in bytes, if operating in bytes mode, or packets,...
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
std::map< std::string, uint32_t > nMarkedPackets
Marked packets, for each reason.
virtual void DoInitialize(void)
Initialize() implementation.
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceDropAfterDequeue
Traced callback: fired when a packet is dropped after dequeue.
std::map< std::string, uint64_t > nDroppedBytesAfterDequeue
Bytes dropped after dequeue, for each reason.
QueueDiscSizePolicy m_sizePolicy
The queue disc size policy.
virtual ~QueueDiscClass()
QueueDisc(QueueDiscSizePolicy policy=QueueDiscSizePolicy::SINGLE_INTERNAL_QUEUE)
Constructor.
uint32_t nTotalEnqueuedPackets
Total enqueued packets.
static constexpr const char * INTERNAL_QUEUE_DROP
Packet dropped by an internal queue.
std::map< std::string, uint64_t > nDroppedBytesBeforeEnqueue
Bytes dropped before enqueue, for each reason.
@ SINGLE_CHILD_QUEUE_DISC
Used by queue discs with single child queue disc.
uint32_t nTotalReceivedPackets
Total received packets.
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...
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< QueueDiscItem > Dequeue(void)
Extract from the queue disc the packet that has been dequeued by calling Peek, if any,...
bool RunBegin(void)
Modelled after the Linux function qdisc_run_begin (include/net/sch_generic.h).
SendCallback m_send
Callback used to send a packet to the receiving object.
TracedValue< uint32_t > m_nBytes
Number of bytes in the queue.
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
ChildQueueDiscMarkFunctor m_childQueueDiscMarkFunctor
Function object called when a child queue disc marked a packet.
indicates whether the socket has a priority set.
uint64_t GetNDroppedBytes(std::string reason) const
Get the amount of bytes dropped for the given reason.
virtual Ptr< QueueDiscItem > DoDequeue(void)=0
This function actually extracts a packet from the queue disc.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
void AddPacketFilter(Ptr< PacketFilter > filter)
Add a packet filter to the tail of the list of filters used to classify packets.
static const int PF_NO_MATCH
Standard value used by packet filters to indicate that no match was possible.
void Print(std::ostream &os) const
Print the statistics.
ChildQueueDiscDropFunctor m_childQueueDiscDbeFunctor
Function object called when a child queue disc dropped a packet before enqueue.
TracedCallback< Ptr< const QueueDiscItem > > m_traceDequeue
Traced callback: fired when a packet is dequeued.
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.
ChildQueueDiscDropFunctor m_childQueueDiscDadFunctor
Function object called when a child queue disc dropped a packet after dequeue.
bool m_prohibitChangeMode
True if changing mode is prohibited.
double f(double x, void *params)
uint64_t nTotalDequeuedBytes
Total dequeued bytes.
@ BYTES
Use number of bytes for queue size.
std::string m_childQueueDiscMarkMsg
Reason why a packet was marked by a child queue disc.
static const uint32_t DEFAULT_QUOTA
Default quota (as in /proc/sys/net/core/dev_weight)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)=0
This function actually enqueues a packet into the queue disc.
QueueSizeUnit
Enumeration of the operating modes of queues.
uint64_t nTotalDroppedBytes
Total dropped bytes.
Ptr< QueueDiscItem > DequeuePacket(void)
Modelled after the Linux function dequeue_skb (net/sched/sch_generic.c)
uint64_t nTotalDroppedBytesAfterDequeue
Total bytes dropped after dequeue.
virtual WakeMode GetWakeMode(void) const
When setting up the wake callbacks on the netdevice queues, it is necessary to determine which queue ...
Hold an unsigned integer type.
TracedCallback< Ptr< const QueueDiscItem > > m_traceDrop
Traced callback: fired when a packet is dropped.
std::function< void(Ptr< QueueDiscItem >)> SendCallback
Callback invoked to send a packet to the receiving object when Run is called.
std::map< std::string, uint64_t > nMarkedBytes
Marked bytes, for each reason.
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...
const Stats & GetStats(void)
Retrieve all the collected statistics.
uint32_t GetValue() const
Get the underlying value.
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Ptr< NetDeviceQueueInterface > m_devQueueIface
NetDevice queue interface.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
std::size_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
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< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
std::ostream & operator<<(std::ostream &os, const Angles &a)
void SetSendCallback(SendCallback func)
SendCallback GetSendCallback(void) const
Class for representing queue sizes.
Stats m_stats
The collected statistics.
std::vector< Ptr< QueueDiscClass > > m_classes
Classes.
virtual void DoDispose(void)
Destructor implementation.
InternalQueueDropFunctor m_internalQueueDbeFunctor
Function object called when an internal queue dropped a packet before enqueue.
void PacketDequeued(Ptr< const QueueDiscItem > item)
Perform the actions required when the queue disc is notified of a packet dequeue.
void SetNetDeviceQueueInterface(Ptr< NetDeviceQueueInterface > ndqi)
Ptr< QueueDiscItem > m_requeued
The last packet that failed to be transmitted.
std::vector< Ptr< InternalQueue > > m_queues
Internal queues.
bool Restart(void)
Modelled after the Linux function qdisc_restart (net/sched/sch_generic.c) Dequeue a packet (by callin...
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.