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"))
45  .AddAttribute ("MaxPackets",
46  "The maximum number of packets accepted by this queue.",
47  UintegerValue (100),
50  MakeUintegerChecker<uint32_t> ())
51  .AddAttribute ("MaxBytes",
52  "The maximum number of bytes accepted by this queue.",
53  UintegerValue (100 * 65535),
56  MakeUintegerChecker<uint32_t> ())
57  .AddTraceSource ("PacketsInQueue",
58  "Number of packets currently stored in the queue",
60  "ns3::TracedValueCallback::Uint32")
61  .AddTraceSource ("BytesInQueue",
62  "Number of bytes currently stored in the queue",
64  "ns3::TracedValueCallback::Uint32")
65  ;
66  return tid;
67 }
68 
70  m_nBytes (0),
71  m_nTotalReceivedBytes (0),
72  m_nPackets (0),
73  m_nTotalReceivedPackets (0),
74  m_nTotalDroppedBytes (0),
75  m_nTotalDroppedBytesBeforeEnqueue (0),
76  m_nTotalDroppedBytesAfterDequeue (0),
77  m_nTotalDroppedPackets (0),
78  m_nTotalDroppedPacketsBeforeEnqueue (0),
79  m_nTotalDroppedPacketsAfterDequeue (0),
80  m_mode (QUEUE_MODE_PACKETS)
81 {
82  NS_LOG_FUNCTION (this);
83 }
84 
86 {
87  NS_LOG_FUNCTION (this);
88 }
89 
90 void
91 QueueBase::AppendItemTypeIfNotPresent (std::string& typeId, const std::string& itemType)
92 {
93  if (typeId.back () != '>')
94  {
95  typeId.append ("<" + itemType + ">");
96  }
97 }
98 
99 bool
100 QueueBase::IsEmpty (void) const
101 {
102  NS_LOG_FUNCTION (this);
103  NS_LOG_LOGIC ("returns " << (m_nPackets.Get () == 0));
104  return m_nPackets.Get () == 0;
105 }
106 
107 uint32_t
109 {
110  NS_LOG_FUNCTION (this);
111  NS_LOG_LOGIC ("returns " << m_nPackets);
112  return m_nPackets;
113 }
114 
115 uint32_t
117 {
118  NS_LOG_FUNCTION (this);
119  NS_LOG_LOGIC (" returns " << m_nBytes);
120  return m_nBytes;
121 }
122 
123 uint32_t
125 {
126  NS_LOG_FUNCTION (this);
127  NS_LOG_LOGIC ("returns " << m_nTotalReceivedBytes);
128  return m_nTotalReceivedBytes;
129 }
130 
131 uint32_t
133 {
134  NS_LOG_FUNCTION (this);
135  NS_LOG_LOGIC ("returns " << m_nTotalReceivedPackets);
137 }
138 
139 uint32_t
141 {
142  NS_LOG_FUNCTION (this);
143  NS_LOG_LOGIC ("returns " << m_nTotalDroppedBytes);
144  return m_nTotalDroppedBytes;
145 }
146 
147 uint32_t
149 {
150  NS_LOG_FUNCTION (this);
153 }
154 
155 uint32_t
157 {
158  NS_LOG_FUNCTION (this);
161 }
162 
163 uint32_t
165 {
166  NS_LOG_FUNCTION (this);
167  NS_LOG_LOGIC ("returns " << m_nTotalDroppedPackets);
168  return m_nTotalDroppedPackets;
169 }
170 
171 uint32_t
173 {
174  NS_LOG_FUNCTION (this);
177 }
178 
179 uint32_t
181 {
182  NS_LOG_FUNCTION (this);
185 }
186 
187 void
189 {
190  NS_LOG_FUNCTION (this);
199 }
200 
201 void
203 {
204  NS_LOG_FUNCTION (this << mode);
205 
206  if (mode == QUEUE_MODE_BYTES && m_mode == QUEUE_MODE_PACKETS)
207  {
208  NS_ABORT_MSG_IF (m_nPackets.Get () != 0,
209  "Cannot change queue mode in a queue with packets.");
210  }
211  else if (mode == QUEUE_MODE_PACKETS && m_mode == QUEUE_MODE_BYTES)
212  {
213  NS_ABORT_MSG_IF (m_nBytes.Get () != 0,
214  "Cannot change queue mode in a queue with packets.");
215  }
216 
217  m_mode = mode;
218 }
219 
221 QueueBase::GetMode (void) const
222 {
223  NS_LOG_FUNCTION (this);
224  return m_mode;
225 }
226 
227 void
228 QueueBase::SetMaxPackets (uint32_t maxPackets)
229 {
230  NS_LOG_FUNCTION (this << maxPackets);
231 
232  if (m_mode == QUEUE_MODE_PACKETS)
233  {
234  NS_ABORT_MSG_IF (maxPackets < m_nPackets.Get (),
235  "The new queue size cannot be less than the number of currently stored packets.");
236  }
237 
238  m_maxPackets = maxPackets;
239 }
240 
241 uint32_t
243 {
244  NS_LOG_FUNCTION (this);
245  return m_maxPackets;
246 }
247 
248 void
249 QueueBase::SetMaxBytes (uint32_t maxBytes)
250 {
251  NS_LOG_FUNCTION (this << maxBytes);
252 
253  if (m_mode == QUEUE_MODE_BYTES)
254  {
255  NS_ABORT_MSG_IF (maxBytes < m_nBytes.Get (),
256  "The new queue size cannot be less than the amount of bytes of currently stored packets.");
257  }
258 
259  m_maxBytes = maxBytes;
260 }
261 
262 uint32_t
264 {
265  NS_LOG_FUNCTION (this);
266  return m_maxBytes;
267 }
268 
269 } // namespace ns3
uint32_t m_nTotalDroppedPacketsBeforeEnqueue
Total dropped packets before enqueue.
Definition: queue.h:241
uint32_t m_nTotalReceivedPackets
Total received packets.
Definition: queue.h:236
uint32_t m_nTotalDroppedPackets
Total dropped packets.
Definition: queue.h:240
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint32_t m_maxBytes
max bytes in the queue
Definition: queue.h:245
#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:237
#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:242
uint32_t m_nTotalDroppedBytesAfterDequeue
Total dropped bytes after dequeue.
Definition: queue.h:239
uint32_t GetTotalDroppedPacketsBeforeEnqueue(void) const
Definition: queue.cc:172
QueueBase::QueueMode GetMode(void) const
Get the operating mode of this device.
Definition: queue.cc:221
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
QueueMode m_mode
queue mode (packets or bytes)
Definition: queue.h:246
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Definition: queue.h:235
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:91
Use number of packets for maximum queue size.
Definition: queue.h:166
virtual ~QueueBase()
Definition: queue.cc:85
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:116
uint32_t m_maxPackets
max packets in the queue
Definition: queue.h:244
void SetMode(QueueBase::QueueMode mode)
Set the operating mode of this device.
Definition: queue.cc:202
uint32_t m_nTotalDroppedBytesBeforeEnqueue
Total dropped bytes before enqueue.
Definition: queue.h:238
Hold variables of type enum.
Definition: enum.h:54
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:228
uint32_t GetMaxPackets(void) const
Definition: queue.cc:242
uint32_t GetTotalDroppedBytes(void) const
Definition: queue.cc:140
uint32_t m_nTotalReceivedBytes
Total received bytes.
Definition: queue.h:234
void ResetStatistics(void)
Resets the counts for dropped packets, dropped bytes, received packets, and received bytes...
Definition: queue.cc:188
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t GetTotalDroppedBytesAfterDequeue(void) const
Definition: queue.cc:156
void SetMaxBytes(uint32_t maxBytes)
Set the maximum amount of bytes that can be stored in this queue.
Definition: queue.cc:249
Use number of bytes for maximum queue size.
Definition: queue.h:167
uint32_t GetTotalReceivedPackets(void) const
Definition: queue.cc:132
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
uint32_t GetMaxBytes(void) const
Definition: queue.cc:263
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:100
uint32_t GetNPackets(void) const
Definition: queue.cc:108
uint32_t GetTotalDroppedPacketsAfterDequeue(void) const
Definition: queue.cc:180
#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:164
A base class which provides memory management and object aggregation.
Definition: object.h:87
QueueMode
Enumeration of the modes supported in the class.
Definition: queue.h:164
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
a unique identifier for an interface.
Definition: type-id.h:58
uint32_t GetTotalReceivedBytes(void) const
Definition: queue.cc:124
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
static TypeId GetTypeId(void)
Get the type ID.
Definition: queue.cc:33
uint32_t GetTotalDroppedBytesBeforeEnqueue(void) const
Definition: queue.cc:148
TracedValue< uint32_t > m_nBytes
Number of bytes in the queue.
Definition: queue.h:233