A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
queue.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */
17 
18 #include "queue.h"
19 
20 #include "ns3/abort.h"
21 #include "ns3/enum.h"
22 #include "ns3/trace-source-accessor.h"
23 #include "ns3/uinteger.h"
24 
25 namespace ns3
26 {
27 
29 
31 NS_OBJECT_TEMPLATE_CLASS_DEFINE(Queue, Packet);
32 NS_OBJECT_TEMPLATE_CLASS_DEFINE(Queue, QueueDiscItem);
33 
34 TypeId
36 {
37  static TypeId tid = TypeId("ns3::QueueBase")
38  .SetParent<Object>()
39  .SetGroupName("Network")
40  .AddTraceSource("PacketsInQueue",
41  "Number of packets currently stored in the queue",
43  "ns3::TracedValueCallback::Uint32")
44  .AddTraceSource("BytesInQueue",
45  "Number of bytes currently stored in the queue",
47  "ns3::TracedValueCallback::Uint32");
48  return tid;
49 }
50 
52  : m_nBytes(0),
53  m_nTotalReceivedBytes(0),
54  m_nPackets(0),
55  m_nTotalReceivedPackets(0),
56  m_nTotalDroppedBytes(0),
57  m_nTotalDroppedBytesBeforeEnqueue(0),
58  m_nTotalDroppedBytesAfterDequeue(0),
59  m_nTotalDroppedPackets(0),
60  m_nTotalDroppedPacketsBeforeEnqueue(0),
61  m_nTotalDroppedPacketsAfterDequeue(0)
62 {
63  NS_LOG_FUNCTION(this);
65 }
66 
68 {
69  NS_LOG_FUNCTION(this);
70 }
71 
72 void
73 QueueBase::AppendItemTypeIfNotPresent(std::string& typeId, const std::string& itemType)
74 {
75  if (typeId.back() != '>')
76  {
77  typeId.append("<" + itemType + ">");
78  }
79 }
80 
81 bool
83 {
84  NS_LOG_FUNCTION(this);
85  NS_LOG_LOGIC("returns " << (m_nPackets.Get() == 0));
86  return m_nPackets.Get() == 0;
87 }
88 
89 uint32_t
91 {
92  NS_LOG_FUNCTION(this);
93  NS_LOG_LOGIC("returns " << m_nPackets);
94  return m_nPackets;
95 }
96 
97 uint32_t
99 {
100  NS_LOG_FUNCTION(this);
101  NS_LOG_LOGIC(" returns " << m_nBytes);
102  return m_nBytes;
103 }
104 
105 QueueSize
107 {
108  NS_LOG_FUNCTION(this);
109 
111  {
113  }
115  {
117  }
118  NS_ABORT_MSG("Unknown queue size unit");
119 }
120 
121 uint32_t
123 {
124  NS_LOG_FUNCTION(this);
125  NS_LOG_LOGIC("returns " << m_nTotalReceivedBytes);
126  return m_nTotalReceivedBytes;
127 }
128 
129 uint32_t
131 {
132  NS_LOG_FUNCTION(this);
133  NS_LOG_LOGIC("returns " << m_nTotalReceivedPackets);
135 }
136 
137 uint32_t
139 {
140  NS_LOG_FUNCTION(this);
141  NS_LOG_LOGIC("returns " << m_nTotalDroppedBytes);
142  return m_nTotalDroppedBytes;
143 }
144 
145 uint32_t
147 {
148  NS_LOG_FUNCTION(this);
151 }
152 
153 uint32_t
155 {
156  NS_LOG_FUNCTION(this);
159 }
160 
161 uint32_t
163 {
164  NS_LOG_FUNCTION(this);
165  NS_LOG_LOGIC("returns " << m_nTotalDroppedPackets);
166  return m_nTotalDroppedPackets;
167 }
168 
169 uint32_t
171 {
172  NS_LOG_FUNCTION(this);
175 }
176 
177 uint32_t
179 {
180  NS_LOG_FUNCTION(this);
183 }
184 
185 void
187 {
188  NS_LOG_FUNCTION(this);
197 }
198 
199 void
201 {
202  NS_LOG_FUNCTION(this << size);
203 
204  // do nothing if the size is null
205  if (!size.GetValue())
206  {
207  return;
208  }
209 
210  m_maxSize = size;
211 
213  "The new maximum queue size cannot be less than the current size");
214 }
215 
216 QueueSize
218 {
219  NS_LOG_FUNCTION(this);
220  return m_maxSize;
221 }
222 
223 bool
224 QueueBase::WouldOverflow(uint32_t nPackets, uint32_t nBytes) const
225 {
227  {
228  return (m_nPackets + nPackets > m_maxSize.GetValue());
229  }
230  else
231  {
232  return (m_nBytes + nBytes > m_maxSize.GetValue());
233  }
234 }
235 
236 } // namespace ns3
#define max(a, b)
Definition: 80211b.c:42
A base class which provides memory management and object aggregation.
Definition: object.h:89
uint32_t m_nTotalDroppedBytesBeforeEnqueue
Total dropped bytes before enqueue.
Definition: queue.h:223
uint32_t GetTotalDroppedPacketsAfterDequeue() const
Definition: queue.cc:178
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Definition: queue.h:220
uint32_t GetTotalDroppedPacketsBeforeEnqueue() const
Definition: queue.cc:170
uint32_t m_nTotalDroppedPacketsAfterDequeue
Total dropped packets after dequeue.
Definition: queue.h:227
uint32_t m_nTotalReceivedPackets
Total received packets.
Definition: queue.h:221
uint32_t GetTotalDroppedBytesAfterDequeue() const
Definition: queue.cc:154
QueueSize GetMaxSize() const
Definition: queue.cc:217
uint32_t GetTotalReceivedBytes() const
Definition: queue.cc:122
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:224
void ResetStatistics()
Resets the counts for dropped packets, dropped bytes, received packets, and received bytes.
Definition: queue.cc:186
bool IsEmpty() const
Definition: queue.cc:82
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:73
uint32_t GetTotalDroppedBytes() const
Definition: queue.cc:138
static TypeId GetTypeId()
Get the type ID.
Definition: queue.cc:35
uint32_t GetTotalDroppedBytesBeforeEnqueue() const
Definition: queue.cc:146
uint32_t m_nTotalDroppedBytes
Total dropped bytes.
Definition: queue.h:222
uint32_t GetNBytes() const
Definition: queue.cc:98
uint32_t m_nTotalDroppedPacketsBeforeEnqueue
Total dropped packets before enqueue.
Definition: queue.h:226
QueueSize m_maxSize
max queue size
Definition: queue.h:229
uint32_t m_nTotalDroppedPackets
Total dropped packets.
Definition: queue.h:225
uint32_t GetNPackets() const
Definition: queue.cc:90
void SetMaxSize(QueueSize size)
Set the maximum size of this queue.
Definition: queue.cc:200
uint32_t GetTotalReceivedPackets() const
Definition: queue.cc:130
TracedValue< uint32_t > m_nBytes
Number of bytes in the queue.
Definition: queue.h:218
~QueueBase() override
Definition: queue.cc:67
uint32_t m_nTotalDroppedBytesAfterDequeue
Total dropped bytes after dequeue.
Definition: queue.h:224
uint32_t GetTotalDroppedPackets() const
Definition: queue.cc:162
uint32_t m_nTotalReceivedBytes
Total received bytes.
Definition: queue.h:219
QueueSize GetCurrentSize() const
Definition: queue.cc:106
Class for representing queue sizes.
Definition: queue-size.h:96
QueueSizeUnit GetUnit() const
Get the underlying unit.
Definition: queue-size.cc:176
uint32_t GetValue() const
Get the underlying value.
Definition: queue-size.cc:183
T Get() const
Get the underlying value.
Definition: traced-value.h:249
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:49
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#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:78
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
@ BYTES
Use number of bytes for queue size.
Definition: queue-size.h:46
@ PACKETS
Use number of packets for queue size.
Definition: queue-size.h:45
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.