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