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 NS_OBJECT_TEMPLATE_CLASS_DEFINE (Queue,QueueDiscItem);
32 
33 TypeId
35 {
36  static TypeId tid = TypeId ("ns3::QueueBase")
37  .SetParent<Object> ()
38  .SetGroupName ("Network")
39  .AddTraceSource ("PacketsInQueue",
40  "Number of packets currently stored in the queue",
42  "ns3::TracedValueCallback::Uint32")
43  .AddTraceSource ("BytesInQueue",
44  "Number of bytes currently stored in the queue",
46  "ns3::TracedValueCallback::Uint32")
47  ;
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
82 QueueBase::IsEmpty (void) const
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 
212  NS_ABORT_MSG_IF (size < GetCurrentSize (),
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 } // namespace ns3
uint32_t m_nTotalDroppedPacketsBeforeEnqueue
Total dropped packets before enqueue.
Definition: queue.h:215
uint32_t m_nTotalReceivedPackets
Total received packets.
Definition: queue.h:210
uint32_t m_nTotalDroppedPackets
Total dropped packets.
Definition: queue.h:214
#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
QueueSize GetMaxSize(void) const
Definition: queue.cc:217
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
uint32_t GetTotalDroppedPacketsBeforeEnqueue(void) const
Definition: queue.cc:170
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
uint32_t GetValue() const
Get the underlying value.
Definition: queue-size.cc:175
uint32_t GetTotalDroppedBytes(void) const
Definition: queue.cc:138
uint32_t GetTotalReceivedPackets(void) const
Definition: queue.cc:130
uint32_t m_nTotalDroppedBytes
Total dropped bytes.
Definition: queue.h:211
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
uint32_t m_nTotalDroppedPacketsAfterDequeue
Total dropped packets after dequeue.
Definition: queue.h:216
uint32_t GetTotalDroppedBytesBeforeEnqueue(void) const
Definition: queue.cc:146
uint32_t m_nTotalDroppedBytesAfterDequeue
Total dropped bytes after dequeue.
Definition: queue.h:213
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Definition: queue.h:209
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 &#39;>&#39;. ...
Definition: queue.cc:73
QueueSize m_maxSize
max queue size
Definition: queue.h:218
virtual ~QueueBase()
Definition: queue.cc:67
uint32_t GetTotalDroppedBytesAfterDequeue(void) const
Definition: queue.cc:154
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:98
uint32_t m_nTotalDroppedBytesBeforeEnqueue
Total dropped bytes before enqueue.
Definition: queue.h:212
#define max(a, b)
Definition: 80211b.c:43
Use number of packets for queue size.
Definition: queue-size.h:44
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
uint32_t m_nTotalReceivedBytes
Total received bytes.
Definition: queue.h:208
void ResetStatistics(void)
Resets the counts for dropped packets, dropped bytes, received packets, and received bytes...
Definition: queue.cc:186
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t GetTotalDroppedPacketsAfterDequeue(void) const
Definition: queue.cc:178
QueueSizeUnit GetUnit() const
Get the underlying unit.
Definition: queue-size.cc:169
uint32_t GetTotalDroppedPackets(void) const
Definition: queue.cc:162
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
T Get(void) const
Get the underlying value.
Definition: traced-value.h:229
#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
A base class which provides memory management and object aggregation.
Definition: object.h:87
uint32_t GetTotalReceivedBytes(void) const
Definition: queue.cc:122
void SetMaxSize(QueueSize size)
Set the maximum size of this queue.
Definition: queue.cc:200
QueueSize GetCurrentSize(void) const
Definition: queue.cc:106
uint32_t GetNPackets(void) const
Definition: queue.cc:90
Use number of bytes for queue size.
Definition: queue-size.h:45
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
static TypeId GetTypeId(void)
Get the type ID.
Definition: queue.cc:34
bool IsEmpty(void) const
Definition: queue.cc:82
TracedValue< uint32_t > m_nBytes
Number of bytes in the queue.
Definition: queue.h:207