19#include "ns3/object.h"
20#include "ns3/packet.h"
21#include "ns3/traced-callback.h"
22#include "ns3/traced-value.h"
190 void EnableRunningAverage(
Time averageWindow);
191 void DisableRunningAverage();
193 double GetQueueSizeAverage();
194 double GetReceivedBytesPerSecondAverage();
195 double GetReceivedPacketsPerSecondAverage();
196 double GetDroppedBytesPerSecondAverage();
197 double GetDroppedPacketsPerSecondAverage();
199 double GetQueueSizeVariance();
200 double GetReceivedBytesPerSecondVariance();
201 double GetReceivedPacketsPerSecondVariance();
202 double GetDroppedBytesPerSecondVariance();
203 double GetDroppedPacketsPerSecondVariance();
255template <
typename Item,
typename Container>
388 template <
class,
class =
void>
410 std::void_t<decltype(std::declval<T>().GetItem(std::declval<ConstIterator>()))>>
419 return container.GetItem(it);
442template <
typename Item,
typename Container>
447 auto startPos = name.find(
'<') + 1;
448 auto endPos = name.find_first_of(
",>", startPos);
449 std::string tcbName =
"ns3::" + name.substr(startPos, endPos - startPos) +
"::TracedCallback";
454 .SetGroupName(
"Network")
455 .AddTraceSource(
"Enqueue",
456 "Enqueue a packet in the queue.",
459 .AddTraceSource(
"Dequeue",
460 "Dequeue a packet from the queue.",
463 .AddTraceSource(
"Drop",
464 "Drop a packet (for whatever reason).",
469 "Drop a packet before enqueue.",
474 "Drop a packet after dequeue.",
480template <
typename Item,
typename Container>
486template <
typename Item,
typename Container>
491template <
typename Item,
typename Container>
498template <
typename Item,
typename Container>
503 return DoEnqueue(pos, item, ret);
506template <
typename Item,
typename Container>
512 if (GetCurrentSize() + item > GetMaxSize())
515 DropBeforeEnqueue(item);
519 ret = m_packets.insert(pos, item);
523 m_nTotalReceivedBytes += size;
526 m_nTotalReceivedPackets++;
529 m_traceEnqueue(item);
534template <
typename Item,
typename Container>
540 if (m_nPackets.Get() == 0)
550 m_packets.erase(pos);
551 NS_ASSERT(m_nBytes.Get() >= item->GetSize());
554 m_nBytes -= item->GetSize();
558 m_traceDequeue(item);
563template <
typename Item,
typename Container>
569 if (m_nPackets.Get() == 0)
579 m_packets.erase(pos);
580 NS_ASSERT(m_nBytes.Get() >= item->GetSize());
583 m_nBytes -= item->GetSize();
588 m_traceDequeue(item);
590 DropAfterDequeue(item);
595template <
typename Item,
typename Container>
606template <
typename Item,
typename Container>
615template <
typename Item,
typename Container>
621 if (m_nPackets.Get() == 0)
630template <
typename Item,
typename Container>
636 m_nTotalDroppedPackets++;
637 m_nTotalDroppedPacketsBeforeEnqueue++;
638 m_nTotalDroppedBytes += item->GetSize();
639 m_nTotalDroppedBytesBeforeEnqueue += item->GetSize();
643 m_traceDropBeforeEnqueue(item);
646template <
typename Item,
typename Container>
652 m_nTotalDroppedPackets++;
653 m_nTotalDroppedPacketsAfterDequeue++;
654 m_nTotalDroppedBytes += item->GetSize();
655 m_nTotalDroppedBytesAfterDequeue += item->GetSize();
659 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.
std::string GetTemplateClassName()
Helper function to get the name (as a string) of the type of a template class.
Forward declaration of template class Queue.
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)