26#include "ns3/object.h"
27#include "ns3/packet.h"
28#include "ns3/queue-fwd.h"
29#include "ns3/queue-item.h"
30#include "ns3/queue-size.h"
31#include "ns3/traced-callback.h"
32#include "ns3/traced-value.h"
200 void EnableRunningAverage(
Time averageWindow);
201 void DisableRunningAverage();
203 double GetQueueSizeAverage();
204 double GetReceivedBytesPerSecondAverage();
205 double GetReceivedPacketsPerSecondAverage();
206 double GetDroppedBytesPerSecondAverage();
207 double GetDroppedPacketsPerSecondAverage();
209 double GetQueueSizeVariance();
210 double GetReceivedBytesPerSecondVariance();
211 double GetReceivedPacketsPerSecondVariance();
212 double GetDroppedBytesPerSecondVariance();
213 double GetDroppedPacketsPerSecondVariance();
265template <
typename Item,
typename Container>
398 template <
class,
class =
void>
420 std::void_t<decltype(std::declval<T>().GetItem(std::declval<ConstIterator>()))>>
429 return container.GetItem(it);
452template <
typename Item,
typename Container>
456 std::string name = GetTemplateClassName<Queue<Item, Container>>();
457 auto startPos = name.find(
'<') + 1;
458 auto endPos = name.find_first_of(
",>", startPos);
459 std::string tcbName =
"ns3::" + name.substr(startPos, endPos - startPos) +
"::TracedCallback";
464 .SetGroupName(
"Network")
465 .AddTraceSource(
"Enqueue",
466 "Enqueue a packet in the queue.",
469 .AddTraceSource(
"Dequeue",
470 "Dequeue a packet from the queue.",
473 .AddTraceSource(
"Drop",
474 "Drop a packet (for whatever reason).",
479 "Drop a packet before enqueue.",
484 "Drop a packet after dequeue.",
490template <
typename Item,
typename Container>
496template <
typename Item,
typename Container>
501template <
typename Item,
typename Container>
508template <
typename Item,
typename Container>
513 return DoEnqueue(pos, item, ret);
516template <
typename Item,
typename Container>
522 if (GetCurrentSize() + item > GetMaxSize())
525 DropBeforeEnqueue(item);
529 ret = m_packets.insert(pos, item);
533 m_nTotalReceivedBytes += size;
536 m_nTotalReceivedPackets++;
539 m_traceEnqueue(item);
544template <
typename Item,
typename Container>
550 if (m_nPackets.Get() == 0)
560 m_packets.erase(pos);
561 NS_ASSERT(m_nBytes.Get() >= item->GetSize());
564 m_nBytes -= item->GetSize();
568 m_traceDequeue(item);
573template <
typename Item,
typename Container>
579 if (m_nPackets.Get() == 0)
589 m_packets.erase(pos);
590 NS_ASSERT(m_nBytes.Get() >= item->GetSize());
593 m_nBytes -= item->GetSize();
598 m_traceDequeue(item);
600 DropAfterDequeue(item);
605template <
typename Item,
typename Container>
616template <
typename Item,
typename Container>
625template <
typename Item,
typename Container>
631 if (m_nPackets.Get() == 0)
640template <
typename Item,
typename Container>
646 m_nTotalDroppedPackets++;
647 m_nTotalDroppedPacketsBeforeEnqueue++;
648 m_nTotalDroppedBytes += item->GetSize();
649 m_nTotalDroppedBytesBeforeEnqueue += item->GetSize();
653 m_traceDropBeforeEnqueue(item);
656template <
typename Item,
typename Container>
662 m_nTotalDroppedPackets++;
663 m_nTotalDroppedPacketsAfterDequeue++;
664 m_nTotalDroppedBytes += item->GetSize();
665 m_nTotalDroppedBytesAfterDequeue += item->GetSize();
669 m_traceDropAfterDequeue(item);
A base class which provides memory management and object aggregation.
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
Abstract base class for packet Queues.
uint32_t m_nTotalDroppedBytesBeforeEnqueue
Total dropped bytes before enqueue.
uint32_t GetTotalDroppedPacketsAfterDequeue() const
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
uint32_t GetTotalDroppedPacketsBeforeEnqueue() const
uint32_t m_nTotalDroppedPacketsAfterDequeue
Total dropped packets after dequeue.
uint32_t m_nTotalReceivedPackets
Total received packets.
uint32_t GetTotalDroppedBytesAfterDequeue() const
QueueSize GetMaxSize() const
uint32_t GetTotalReceivedBytes() const
bool WouldOverflow(uint32_t nPackets, uint32_t nBytes) const
Check if the queue would overflow with additional bytes or packets Note: the check is performed accor...
void ResetStatistics()
Resets the counts for dropped packets, dropped bytes, received packets, and received bytes.
static void AppendItemTypeIfNotPresent(std::string &typeId, const std::string &itemType)
Append the item type to the provided type ID if the latter does not end with '>'.
uint32_t GetTotalDroppedBytes() const
static TypeId GetTypeId()
Get the type ID.
uint32_t GetTotalDroppedBytesBeforeEnqueue() const
uint32_t m_nTotalDroppedBytes
Total dropped bytes.
uint32_t GetNBytes() const
uint32_t m_nTotalDroppedPacketsBeforeEnqueue
Total dropped packets before enqueue.
QueueSize m_maxSize
max queue size
uint32_t m_nTotalDroppedPackets
Total dropped packets.
uint32_t GetNPackets() const
void SetMaxSize(QueueSize size)
Set the maximum size of this queue.
uint32_t GetTotalReceivedPackets() const
TracedValue< uint32_t > m_nBytes
Number of bytes in the queue.
uint32_t m_nTotalDroppedBytesAfterDequeue
Total dropped bytes after dequeue.
uint32_t GetTotalDroppedPackets() const
uint32_t m_nTotalReceivedBytes
Total received bytes.
QueueSize GetCurrentSize() const
Template class for packet Queues.
virtual Ptr< const Item > Peek() const =0
Get a copy of an item in the queue (each subclass defines the position) without removing it.
Ptr< Item > DoRemove(ConstIterator pos)
Pull the item to drop from the queue.
bool DoEnqueue(ConstIterator pos, Ptr< Item > item, Iterator &ret)
Push an item in the queue.
TracedCallback< Ptr< const Item > > m_traceDrop
Traced callback: fired when a packet is dropped.
Ptr< Item > DoDequeue(ConstIterator pos)
Pull the item to dequeue from the queue.
void Flush()
Flush the queue by calling Remove() on each item enqueued.
Container m_packets
the items in the queue
TracedCallback< Ptr< const Item > > m_traceDropAfterDequeue
Traced callback: fired when a packet is dropped after dequeue.
bool DoEnqueue(ConstIterator pos, Ptr< Item > item)
Push an item in the queue.
Ptr< const Item > DoPeek(ConstIterator pos) const
Peek the front item in the queue.
void DropAfterDequeue(Ptr< Item > item)
Drop a packet after dequeue.
void DoDispose() override
Destructor implementation.
TracedCallback< Ptr< const Item > > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
virtual bool Enqueue(Ptr< Item > item)=0
Place an item into the Queue (each subclass defines the position)
const Container & GetContainer() const
Get a const reference to the container of queue items.
TracedCallback< Ptr< const Item > > m_traceDequeue
Traced callback: fired when a packet is dequeued.
virtual Ptr< Item > Remove()=0
Remove an item from the Queue (each subclass defines the position), counting it and tracing it as bot...
void DropBeforeEnqueue(Ptr< Item > item)
Drop a packet before enqueue.
static TypeId GetTypeId()
Get the type ID.
Container::iterator Iterator
Iterator.
TracedCallback< Ptr< const Item > > m_traceDropBeforeEnqueue
Traced callback: fired when a packet is dropped before enqueue.
Container::const_iterator ConstIterator
Const iterator.
virtual Ptr< Item > Dequeue()=0
Remove an item from the Queue (each subclass defines the position), counting it and tracing it as deq...
Item ItemType
Define ItemType as the type of the stored elements.
NS_LOG_TEMPLATE_DECLARE
the log component
Class for representing queue sizes.
Simulation virtual time values and global simulation resolution.
Forward calls to a chain of Callback.
Trace classes with value semantics.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_LOG_TEMPLATE_DEFINE(name)
Initialize a reference to a Log component.
#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 ",...
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static Ptr< Item > GetItem(const Container &container, const ConstIterator it)
Struct providing a static method returning the object stored within the queue that is included in the...
static Ptr< Item > GetItem(const Container &, const ConstIterator it)