A Discrete-Event Network Simulator
API
queue.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 
19 #include "ns3/abort.h"
20 #include "ns3/enum.h"
21 #include "ns3/uinteger.h"
22 #include "ns3/trace-source-accessor.h"
23 #include "queue.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("Queue");
28 
29 NS_OBJECT_ENSURE_REGISTERED (QueueBase);
30 NS_OBJECT_TEMPLATE_CLASS_DEFINE (Queue,Packet);
31 
32 TypeId
34 {
35  static TypeId tid = TypeId ("ns3::QueueBase")
36  .SetParent<Object> ()
37  .SetGroupName ("Network")
38  .AddAttribute ("Mode",
39  "Whether to use bytes (see MaxBytes) or packets (see MaxPackets) as the maximum queue size metric.",
43  MakeEnumChecker (QUEUE_MODE_BYTES, "QUEUE_MODE_BYTES",
44  QUEUE_MODE_PACKETS, "QUEUE_MODE_PACKETS"),
46  "Use the MaxSize attribute instead")
47  .AddAttribute ("MaxPackets",
48  "The maximum number of packets accepted by this queue.",
49  UintegerValue (100),
52  MakeUintegerChecker<uint32_t> (),
54  "Use the MaxSize attribute instead")
55  .AddAttribute ("MaxBytes",
56  "The maximum number of bytes accepted by this queue.",
57  UintegerValue (100 * 65535),
60  MakeUintegerChecker<uint32_t> (),
62  "Use the MaxSize attribute instead")
63  .AddAttribute ("MaxSize",
64  "The max queue size",
65  QueueSizeValue (QueueSize ("0p")),
69  .AddTraceSource ("PacketsInQueue",
70  "Number of packets currently stored in the queue",
72  "ns3::TracedValueCallback::Uint32")
73  .AddTraceSource ("BytesInQueue",
74  "Number of bytes currently stored in the queue",
76  "ns3::TracedValueCallback::Uint32")
77  ;
78  return tid;
79 }
80 
82  m_nBytes (0),
83  m_nTotalReceivedBytes (0),
84  m_nPackets (0),
85  m_nTotalReceivedPackets (0),
86  m_nTotalDroppedBytes (0),
87  m_nTotalDroppedBytesBeforeEnqueue (0),
88  m_nTotalDroppedBytesAfterDequeue (0),
89  m_nTotalDroppedPackets (0),
90  m_nTotalDroppedPacketsBeforeEnqueue (0),
91  m_nTotalDroppedPacketsAfterDequeue (0),
92  m_maxPackets (1), // to avoid that setting the mode at construction time is ignored
93  m_maxBytes (1) // to avoid that setting the mode at construction time is ignored
94 {
95  NS_LOG_FUNCTION (this);
96 }
97 
99 {
100  NS_LOG_FUNCTION (this);
101 }
102 
103 void
104 QueueBase::AppendItemTypeIfNotPresent (std::string& typeId, const std::string& itemType)
105 {
106  if (typeId.back () != '>')
107  {
108  typeId.append ("<" + itemType + ">");
109  }
110 }
111 
112 bool
113 QueueBase::IsEmpty (void) const
114 {
115  NS_LOG_FUNCTION (this);
116  NS_LOG_LOGIC ("returns " << (m_nPackets.Get () == 0));
117  return m_nPackets.Get () == 0;
118 }
119 
120 uint32_t
122 {
123  NS_LOG_FUNCTION (this);
124  NS_LOG_LOGIC ("returns " << m_nPackets);
125  return m_nPackets;
126 }
127 
128 uint32_t
130 {
131  NS_LOG_FUNCTION (this);
132  NS_LOG_LOGIC (" returns " << m_nBytes);
133  return m_nBytes;
134 }
135 
136 QueueSize
138 {
139  NS_LOG_FUNCTION (this);
140 
142  {
144  }
146  {
148  }
149  NS_ABORT_MSG ("Unknown queue size unit");
150 }
151 
152 uint32_t
154 {
155  NS_LOG_FUNCTION (this);
156  NS_LOG_LOGIC ("returns " << m_nTotalReceivedBytes);
157  return m_nTotalReceivedBytes;
158 }
159 
160 uint32_t
162 {
163  NS_LOG_FUNCTION (this);
164  NS_LOG_LOGIC ("returns " << m_nTotalReceivedPackets);
166 }
167 
168 uint32_t
170 {
171  NS_LOG_FUNCTION (this);
172  NS_LOG_LOGIC ("returns " << m_nTotalDroppedBytes);
173  return m_nTotalDroppedBytes;
174 }
175 
176 uint32_t
178 {
179  NS_LOG_FUNCTION (this);
182 }
183 
184 uint32_t
186 {
187  NS_LOG_FUNCTION (this);
190 }
191 
192 uint32_t
194 {
195  NS_LOG_FUNCTION (this);
196  NS_LOG_LOGIC ("returns " << m_nTotalDroppedPackets);
197  return m_nTotalDroppedPackets;
198 }
199 
200 uint32_t
202 {
203  NS_LOG_FUNCTION (this);
206 }
207 
208 uint32_t
210 {
211  NS_LOG_FUNCTION (this);
214 }
215 
216 void
218 {
219  NS_LOG_FUNCTION (this);
228 }
229 
230 void
232 {
233  NS_LOG_FUNCTION (this << mode);
234 
235  if (mode == QUEUE_MODE_BYTES)
236  {
238  }
239  else if (mode == QUEUE_MODE_PACKETS)
240  {
242  }
243  else
244  {
245  NS_ABORT_MSG ("Unknown queue size unit");
246  }
247 }
248 
250 QueueBase::GetMode (void) const
251 {
252  NS_LOG_FUNCTION (this);
254 }
255 
256 void
257 QueueBase::SetMaxPackets (uint32_t maxPackets)
258 {
259  NS_LOG_FUNCTION (this << maxPackets);
260 
261  m_maxPackets = maxPackets;
262 
264  {
266  }
267 }
268 
269 uint32_t
271 {
272  NS_LOG_FUNCTION (this);
273  return m_maxPackets;
274 }
275 
276 void
277 QueueBase::SetMaxBytes (uint32_t maxBytes)
278 {
279  NS_LOG_FUNCTION (this << maxBytes);
280 
281  m_maxBytes = maxBytes;
282 
284  {
286  }
287 }
288 
289 uint32_t
291 {
292  NS_LOG_FUNCTION (this);
293  return m_maxBytes;
294 }
295 
296 void
298 {
299  NS_LOG_FUNCTION (this << size);
300 
301  // do nothing if the size is null
302  if (!size.GetValue ())
303  {
304  return;
305  }
306 
307  m_maxSize = size;
308 
309  NS_ABORT_MSG_IF (size < GetCurrentSize (),
310  "The new maximum queue size cannot be less than the current size");
311 
312  if (size.GetUnit () == QueueSizeUnit::PACKETS)
313  {
314  m_maxPackets = size.GetValue ();
315  }
316  else if (size.GetUnit () == QueueSizeUnit::BYTES)
317  {
318  m_maxBytes = size.GetValue ();
319  }
320 }
321 
322 QueueSize
324 {
325  NS_LOG_FUNCTION (this);
326  return m_maxSize;
327 }
328 
329 } // namespace ns3
uint32_t m_nTotalDroppedPacketsBeforeEnqueue
Total dropped packets before enqueue.
Definition: queue.h:275
uint32_t m_nTotalReceivedPackets
Total received packets.
Definition: queue.h:270
uint32_t m_nTotalDroppedPackets
Total dropped packets.
Definition: queue.h:274
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Class for representing queue sizes.
Definition: queue-size.h:94
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
uint32_t m_maxBytes
max bytes in the queue
Definition: queue.h:279
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: enum.h:209
uint32_t m_nTotalDroppedBytes
Total dropped bytes.
Definition: queue.h:271
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint32_t m_nTotalDroppedPacketsAfterDequeue
Total dropped packets after dequeue.
Definition: queue.h:276
uint32_t m_nTotalDroppedBytesAfterDequeue
Total dropped bytes after dequeue.
Definition: queue.h:273
QueueSizeUnit GetUnit() const
Get the underlying unit.
Definition: queue-size.cc:169
uint32_t GetTotalDroppedPacketsBeforeEnqueue(void) const
Definition: queue.cc:201
QueueBase::QueueMode GetMode(void) const
Get the operating mode of this device.
Definition: queue.cc:250
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Definition: queue.h:269
uint32_t GetValue() const
Get the underlying value.
Definition: queue-size.cc:175
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:104
QueueSize m_maxSize
max queue size
Definition: queue.h:280
Use number of packets for maximum queue size.
Definition: queue.h:174
virtual ~QueueBase()
Definition: queue.cc:98
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
uint32_t GetNBytes(void) const
Definition: queue.cc:129
uint32_t m_maxPackets
max packets in the queue
Definition: queue.h:278
void SetMode(QueueBase::QueueMode mode)
Set the operating mode of this device.
Definition: queue.cc:231
uint32_t m_nTotalDroppedBytesBeforeEnqueue
Total dropped bytes before enqueue.
Definition: queue.h:272
Hold variables of type enum.
Definition: enum.h:54
QueueSize GetCurrentSize(void) const
Definition: queue.cc:137
Hold an unsigned integer type.
Definition: uinteger.h:44
void SetMaxPackets(uint32_t maxPackets)
Set the maximum amount of packets that can be stored in this queue.
Definition: queue.cc:257
Use number of packets for queue size.
Definition: queue-size.h:44
uint32_t GetMaxPackets(void) const
Definition: queue.cc:270
uint32_t GetTotalDroppedBytes(void) const
Definition: queue.cc:169
Ptr< const AttributeAccessor > MakeQueueSizeAccessor(T1 a1)
Definition: queue-size.h:221
Attribute or trace source is deprecated; user is warned.
Definition: type-id.h:72
Ptr< const AttributeChecker > MakeQueueSizeChecker(void)
Definition: queue-size.cc:29
uint32_t m_nTotalReceivedBytes
Total received bytes.
Definition: queue.h:268
void ResetStatistics(void)
Resets the counts for dropped packets, dropped bytes, received packets, and received bytes...
Definition: queue.cc:217
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t GetTotalDroppedBytesAfterDequeue(void) const
Definition: queue.cc:185
void SetMaxBytes(uint32_t maxBytes)
Set the maximum amount of bytes that can be stored in this queue.
Definition: queue.cc:277
Use number of bytes for maximum queue size.
Definition: queue.h:175
uint32_t GetTotalReceivedPackets(void) const
Definition: queue.cc:161
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
uint32_t GetMaxBytes(void) const
Definition: queue.cc:290
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.cc:184
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
bool IsEmpty(void) const
Definition: queue.cc:113
uint32_t GetNPackets(void) const
Definition: queue.cc:121
uint32_t GetTotalDroppedPacketsAfterDequeue(void) const
Definition: queue.cc:209
#define NS_OBJECT_TEMPLATE_CLASS_DEFINE(type, param)
Explicitly instantiate a template class and register the resulting instance with the TypeId system...
Definition: object-base.h:67
uint32_t GetTotalDroppedPackets(void) const
Definition: queue.cc:193
A base class which provides memory management and object aggregation.
Definition: object.h:87
void SetMaxSize(QueueSize size)
Set the maximum size of this queue.
Definition: queue.cc:297
QueueMode
Enumeration of the modes supported in the class.
Definition: queue.h:172
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
Use number of bytes for queue size.
Definition: queue-size.h:45
a unique identifier for an interface.
Definition: type-id.h:58
uint32_t GetTotalReceivedBytes(void) const
Definition: queue.cc:153
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
QueueSize GetMaxSize(void) const
Definition: queue.cc:323
static TypeId GetTypeId(void)
Get the type ID.
Definition: queue.cc:33
uint32_t GetTotalDroppedBytesBeforeEnqueue(void) const
Definition: queue.cc:177
TracedValue< uint32_t > m_nBytes
Number of bytes in the queue.
Definition: queue.h:267