A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
queue.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#include "queue.h"
8
9#include "ns3/abort.h"
10#include "ns3/enum.h"
11#include "ns3/trace-source-accessor.h"
12#include "ns3/uinteger.h"
13
14namespace ns3
15{
16
18
21NS_OBJECT_TEMPLATE_CLASS_DEFINE(Queue, QueueDiscItem);
22
23TypeId
25{
26 static TypeId tid = TypeId("ns3::QueueBase")
28 .SetGroupName("Network")
29 .AddTraceSource("PacketsInQueue",
30 "Number of packets currently stored in the queue",
32 "ns3::TracedValueCallback::Uint32")
33 .AddTraceSource("BytesInQueue",
34 "Number of bytes currently stored in the queue",
36 "ns3::TracedValueCallback::Uint32");
37 return tid;
38}
39
41 : m_nBytes(0),
42 m_nTotalReceivedBytes(0),
43 m_nPackets(0),
44 m_nTotalReceivedPackets(0),
45 m_nTotalDroppedBytes(0),
46 m_nTotalDroppedBytesBeforeEnqueue(0),
47 m_nTotalDroppedBytesAfterDequeue(0),
48 m_nTotalDroppedPackets(0),
49 m_nTotalDroppedPacketsBeforeEnqueue(0),
50 m_nTotalDroppedPacketsAfterDequeue(0)
51{
52 NS_LOG_FUNCTION(this);
53 m_maxSize = QueueSize(QueueSizeUnit::PACKETS, std::numeric_limits<uint32_t>::max());
54}
55
60
61void
62QueueBase::AppendItemTypeIfNotPresent(std::string& typeId, const std::string& itemType)
63{
64 if (typeId.back() != '>')
65 {
66 typeId.append("<" + itemType + ">");
67 }
68}
69
70bool
72{
73 NS_LOG_FUNCTION(this);
74 NS_LOG_LOGIC("returns " << (m_nPackets.Get() == 0));
75 return m_nPackets.Get() == 0;
76}
77
80{
81 NS_LOG_FUNCTION(this);
82 NS_LOG_LOGIC("returns " << m_nPackets);
83 return m_nPackets;
84}
85
88{
89 NS_LOG_FUNCTION(this);
90 NS_LOG_LOGIC(" returns " << m_nBytes);
91 return m_nBytes;
92}
93
96{
97 NS_LOG_FUNCTION(this);
98
100 {
102 }
104 {
106 }
107 NS_ABORT_MSG("Unknown queue size unit");
108}
109
117
125
133
141
149
157
165
173
174void
187
188void
190{
191 NS_LOG_FUNCTION(this << size);
192
193 // do nothing if the size is null
194 if (!size.GetValue())
195 {
196 return;
197 }
198
199 m_maxSize = size;
200
202 "The new maximum queue size cannot be less than the current size");
203}
204
207{
208 NS_LOG_FUNCTION(this);
209 return m_maxSize;
210}
211
212bool
214{
216 {
217 return (m_nPackets + nPackets > m_maxSize.GetValue());
218 }
219 else
220 {
221 return (m_nBytes + nBytes > m_maxSize.GetValue());
222 }
223}
224
225} // namespace ns3
A base class which provides memory management and object aggregation.
Definition object.h:78
uint32_t m_nTotalDroppedBytesBeforeEnqueue
Total dropped bytes before enqueue.
Definition queue.h:212
uint32_t GetTotalDroppedPacketsAfterDequeue() const
Definition queue.cc:167
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Definition queue.h:209
uint32_t GetTotalDroppedPacketsBeforeEnqueue() const
Definition queue.cc:159
uint32_t m_nTotalDroppedPacketsAfterDequeue
Total dropped packets after dequeue.
Definition queue.h:216
uint32_t m_nTotalReceivedPackets
Total received packets.
Definition queue.h:210
uint32_t GetTotalDroppedBytesAfterDequeue() const
Definition queue.cc:143
QueueSize GetMaxSize() const
Definition queue.cc:206
uint32_t GetTotalReceivedBytes() const
Definition queue.cc:111
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...
Definition queue.cc:213
void ResetStatistics()
Resets the counts for dropped packets, dropped bytes, received packets, and received bytes.
Definition queue.cc:175
bool IsEmpty() const
Definition queue.cc:71
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 '>'.
Definition queue.cc:62
uint32_t GetTotalDroppedBytes() const
Definition queue.cc:127
static TypeId GetTypeId()
Get the type ID.
Definition queue.cc:24
uint32_t GetTotalDroppedBytesBeforeEnqueue() const
Definition queue.cc:135
uint32_t m_nTotalDroppedBytes
Total dropped bytes.
Definition queue.h:211
uint32_t GetNBytes() const
Definition queue.cc:87
uint32_t m_nTotalDroppedPacketsBeforeEnqueue
Total dropped packets before enqueue.
Definition queue.h:215
QueueSize m_maxSize
max queue size
Definition queue.h:218
uint32_t m_nTotalDroppedPackets
Total dropped packets.
Definition queue.h:214
uint32_t GetNPackets() const
Definition queue.cc:79
void SetMaxSize(QueueSize size)
Set the maximum size of this queue.
Definition queue.cc:189
uint32_t GetTotalReceivedPackets() const
Definition queue.cc:119
TracedValue< uint32_t > m_nBytes
Number of bytes in the queue.
Definition queue.h:207
~QueueBase() override
Definition queue.cc:56
uint32_t m_nTotalDroppedBytesAfterDequeue
Total dropped bytes after dequeue.
Definition queue.h:213
uint32_t GetTotalDroppedPackets() const
Definition queue.cc:151
uint32_t m_nTotalReceivedBytes
Total received bytes.
Definition queue.h:208
QueueSize GetCurrentSize() const
Definition queue.cc:95
Class for representing queue sizes.
Definition queue-size.h:85
QueueSizeUnit GetUnit() const
Get the underlying unit.
uint32_t GetValue() const
Get the underlying value.
T Get() const
Get the underlying value.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_TEMPLATE_CLASS_DEFINE(type, param)
Explicitly instantiate a template class with one template parameter and register the resulting instan...
Definition object-base.h:67
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
@ BYTES
Use number of bytes for queue size.
Definition queue-size.h:35
@ PACKETS
Use number of packets for queue size.
Definition queue-size.h:34
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.