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 ("MaxSize",
39  "The max queue size",
40  QueueSizeValue (QueueSize ("100p")),
44  .AddTraceSource ("PacketsInQueue",
45  "Number of packets currently stored in the queue",
47  "ns3::TracedValueCallback::Uint32")
48  .AddTraceSource ("BytesInQueue",
49  "Number of bytes currently stored in the queue",
51  "ns3::TracedValueCallback::Uint32")
52  ;
53  return tid;
54 }
55 
57  m_nBytes (0),
58  m_nTotalReceivedBytes (0),
59  m_nPackets (0),
60  m_nTotalReceivedPackets (0),
61  m_nTotalDroppedBytes (0),
62  m_nTotalDroppedBytesBeforeEnqueue (0),
63  m_nTotalDroppedBytesAfterDequeue (0),
64  m_nTotalDroppedPackets (0),
65  m_nTotalDroppedPacketsBeforeEnqueue (0),
66  m_nTotalDroppedPacketsAfterDequeue (0)
67 {
68  NS_LOG_FUNCTION (this);
69 }
70 
72 {
73  NS_LOG_FUNCTION (this);
74 }
75 
76 void
77 QueueBase::AppendItemTypeIfNotPresent (std::string& typeId, const std::string& itemType)
78 {
79  if (typeId.back () != '>')
80  {
81  typeId.append ("<" + itemType + ">");
82  }
83 }
84 
85 bool
86 QueueBase::IsEmpty (void) const
87 {
88  NS_LOG_FUNCTION (this);
89  NS_LOG_LOGIC ("returns " << (m_nPackets.Get () == 0));
90  return m_nPackets.Get () == 0;
91 }
92 
93 uint32_t
95 {
96  NS_LOG_FUNCTION (this);
97  NS_LOG_LOGIC ("returns " << m_nPackets);
98  return m_nPackets;
99 }
100 
101 uint32_t
103 {
104  NS_LOG_FUNCTION (this);
105  NS_LOG_LOGIC (" returns " << m_nBytes);
106  return m_nBytes;
107 }
108 
109 QueueSize
111 {
112  NS_LOG_FUNCTION (this);
113 
115  {
117  }
119  {
121  }
122  NS_ABORT_MSG ("Unknown queue size unit");
123 }
124 
125 uint32_t
127 {
128  NS_LOG_FUNCTION (this);
129  NS_LOG_LOGIC ("returns " << m_nTotalReceivedBytes);
130  return m_nTotalReceivedBytes;
131 }
132 
133 uint32_t
135 {
136  NS_LOG_FUNCTION (this);
137  NS_LOG_LOGIC ("returns " << m_nTotalReceivedPackets);
139 }
140 
141 uint32_t
143 {
144  NS_LOG_FUNCTION (this);
145  NS_LOG_LOGIC ("returns " << m_nTotalDroppedBytes);
146  return m_nTotalDroppedBytes;
147 }
148 
149 uint32_t
151 {
152  NS_LOG_FUNCTION (this);
155 }
156 
157 uint32_t
159 {
160  NS_LOG_FUNCTION (this);
163 }
164 
165 uint32_t
167 {
168  NS_LOG_FUNCTION (this);
169  NS_LOG_LOGIC ("returns " << m_nTotalDroppedPackets);
170  return m_nTotalDroppedPackets;
171 }
172 
173 uint32_t
175 {
176  NS_LOG_FUNCTION (this);
179 }
180 
181 uint32_t
183 {
184  NS_LOG_FUNCTION (this);
187 }
188 
189 void
191 {
192  NS_LOG_FUNCTION (this);
201 }
202 
203 void
205 {
206  NS_LOG_FUNCTION (this << size);
207 
208  // do nothing if the size is null
209  if (!size.GetValue ())
210  {
211  return;
212  }
213 
214  m_maxSize = size;
215 
216  NS_ABORT_MSG_IF (size < GetCurrentSize (),
217  "The new maximum queue size cannot be less than the current size");
218 }
219 
220 QueueSize
222 {
223  NS_LOG_FUNCTION (this);
224  return m_maxSize;
225 }
226 
227 } // namespace ns3
uint32_t m_nTotalDroppedPacketsBeforeEnqueue
Total dropped packets before enqueue.
Definition: queue.h:214
uint32_t m_nTotalReceivedPackets
Total received packets.
Definition: queue.h:209
uint32_t m_nTotalDroppedPackets
Total dropped packets.
Definition: queue.h:213
#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:221
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
uint32_t GetTotalDroppedPacketsBeforeEnqueue(void) const
Definition: queue.cc:174
#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:142
uint32_t GetTotalReceivedPackets(void) const
Definition: queue.cc:134
uint32_t m_nTotalDroppedBytes
Total dropped bytes.
Definition: queue.h:210
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
uint32_t m_nTotalDroppedPacketsAfterDequeue
Total dropped packets after dequeue.
Definition: queue.h:215
uint32_t GetTotalDroppedBytesBeforeEnqueue(void) const
Definition: queue.cc:150
uint32_t m_nTotalDroppedBytesAfterDequeue
Total dropped bytes after dequeue.
Definition: queue.h:212
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Definition: queue.h:208
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:77
QueueSize m_maxSize
max queue size
Definition: queue.h:217
virtual ~QueueBase()
Definition: queue.cc:71
uint32_t GetTotalDroppedBytesAfterDequeue(void) const
Definition: queue.cc:158
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:102
uint32_t m_nTotalDroppedBytesBeforeEnqueue
Total dropped bytes before enqueue.
Definition: queue.h:211
Use number of packets for queue size.
Definition: queue-size.h:44
Ptr< const AttributeAccessor > MakeQueueSizeAccessor(T1 a1)
Definition: queue-size.h:221
Ptr< const AttributeChecker > MakeQueueSizeChecker(void)
Definition: queue-size.cc:29
uint32_t m_nTotalReceivedBytes
Total received bytes.
Definition: queue.h:207
void ResetStatistics(void)
Resets the counts for dropped packets, dropped bytes, received packets, and received bytes...
Definition: queue.cc:190
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t GetTotalDroppedPacketsAfterDequeue(void) const
Definition: queue.cc:182
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
QueueSizeUnit GetUnit() const
Get the underlying unit.
Definition: queue-size.cc:169
uint32_t GetTotalDroppedPackets(void) const
Definition: queue.cc:166
#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:218
#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:126
void SetMaxSize(QueueSize size)
Set the maximum size of this queue.
Definition: queue.cc:204
QueueSize GetCurrentSize(void) const
Definition: queue.cc:110
uint32_t GetNPackets(void) const
Definition: queue.cc:94
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:915
static TypeId GetTypeId(void)
Get the type ID.
Definition: queue.cc:33
bool IsEmpty(void) const
Definition: queue.cc:86
TracedValue< uint32_t > m_nBytes
Number of bytes in the queue.
Definition: queue.h:206