A Discrete-Event Network Simulator
API
queue.h
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 // The queue base class has a limit on its size, in terms of number of
20 // packets or number of bytes depending on the operating mode.
21 // The base class implements tracing and basic statistics calculations.
22 
23 #ifndef QUEUE_H
24 #define QUEUE_H
25 
26 #include "ns3/packet.h"
27 #include "ns3/object.h"
28 #include "ns3/traced-callback.h"
29 #include "ns3/net-device.h"
30 #include "ns3/traced-value.h"
31 
32 namespace ns3 {
33 
44 class Queue : public Object
45 {
46 public:
51  static TypeId GetTypeId (void);
52 
53  Queue ();
54  virtual ~Queue ();
55 
59  bool IsEmpty (void) const;
65  bool Enqueue (Ptr<QueueItem> item);
70  Ptr<QueueItem> Dequeue (void);
75  Ptr<QueueItem> Remove (void);
80  Ptr<const QueueItem> Peek (void) const;
81 
85  void DequeueAll (void);
89  uint32_t GetNPackets (void) const;
93  uint32_t GetNBytes (void) const;
94 
101  uint32_t GetTotalReceivedBytes (void) const;
107  uint32_t GetTotalReceivedPackets (void) const;
113  uint32_t GetTotalDroppedBytes (void) const;
119  uint32_t GetTotalDroppedPackets (void) const;
124  void ResetStatistics (void);
125 
131  {
134  };
135 
141  void SetMode (Queue::QueueMode mode);
142 
148  Queue::QueueMode GetMode (void) const;
149 
155  void SetMaxPackets (uint32_t maxPackets);
156 
160  uint32_t GetMaxPackets (void) const;
161 
167  void SetMaxBytes (uint32_t maxBytes);
168 
172  uint32_t GetMaxBytes (void) const;
173 
174 #if 0
175  // average calculation requires keeping around
176  // a buffer with the date of arrival of past received packets
177  // which are within the average window
178  // so, it is quite costly to do it all the time.
179  // Hence, it is disabled by default and must be explicitely
180  // enabled with this method which specifies the size
181  // of the average window in time units.
182  void EnableRunningAverage (Time averageWindow);
183  void DisableRunningAverage (void);
184  // average
185  double GetQueueSizeAverage (void);
186  double GetReceivedBytesPerSecondAverage (void);
187  double GetReceivedPacketsPerSecondAverage (void);
188  double GetDroppedBytesPerSecondAverage (void);
189  double GetDroppedPacketsPerSecondAverage (void);
190  // variance
191  double GetQueueSizeVariance (void);
192  double GetReceivedBytesPerSecondVariance (void);
193  double GetReceivedPacketsPerSecondVariance (void);
194  double GetDroppedBytesPerSecondVariance (void);
195  double GetDroppedPacketsPerSecondVariance (void);
196 #endif
197 
200 
208  virtual void SetDropCallback (DropCallback cb);
209 
210 protected:
219  void Drop (Ptr<QueueItem> item);
220 
221 private:
227  virtual bool DoEnqueue (Ptr<QueueItem> item) = 0;
232  virtual Ptr<QueueItem> DoDequeue (void) = 0;
237  virtual Ptr<QueueItem> DoRemove (void) = 0;
242  virtual Ptr<const QueueItem> DoPeek (void) const = 0;
243 
248  void NotifyDrop (Ptr<QueueItem> item);
249 
256 
263 
264  uint32_t m_maxPackets;
265  uint32_t m_maxBytes;
267  DropCallback m_dropCallback;
268 };
269 
270 } // namespace ns3
271 
272 #endif /* QUEUE_H */
void NotifyDrop(Ptr< QueueItem > item)
Notification of a packet drop.
Definition: queue.cc:353
virtual bool DoEnqueue(Ptr< QueueItem > item)=0
Push an item in the queue.
QueueMode m_mode
queue mode (packets or bytes limited)
Definition: queue.h:266
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Queue()
Definition: queue.cc:78
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Callback template class.
Definition: callback.h:1176
uint32_t m_nTotalDroppedBytes
Total dropped bytes.
Definition: queue.h:261
void SetMaxBytes(uint32_t maxBytes)
Set the maximum amount of bytes that can be stored in this queue.
Definition: queue.cc:326
Use number of bytes for maximum queue size.
Definition: queue.h:133
Callback< void, Ptr< QueueItem > > DropCallback
Callback set by the object (e.g., a queue disc) that wants to be notified of a packet drop...
Definition: queue.h:199
bool IsEmpty(void) const
Definition: queue.cc:229
Forward calls to a chain of Callback.
uint32_t GetTotalDroppedPackets(void) const
Definition: queue.cc:261
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Definition: queue.h:259
uint32_t m_nTotalReceivedBytes
Total received bytes.
Definition: queue.h:258
virtual void SetDropCallback(DropCallback cb)
Set the drop callback.
Definition: queue.cc:347
void ResetStatistics(void)
Resets the counts for dropped packets, dropped bytes, received packets, and received bytes...
Definition: queue.cc:269
uint32_t m_maxPackets
max packets in the queue
Definition: queue.h:264
virtual Ptr< const QueueItem > DoPeek(void) const =0
Peek the front item in the queue.
TracedValue< uint32_t > m_nBytes
Number of bytes in the queue.
Definition: queue.h:257
Abstract base class for packet Queues.
Definition: queue.h:44
virtual Ptr< QueueItem > DoRemove(void)=0
Pull the item to drop from the queue.
uint32_t GetTotalReceivedBytes(void) const
Definition: queue.cc:237
QueueMode
Enumeration of the modes supported in the class.
Definition: queue.h:130
static TypeId GetTypeId(void)
Get the type ID.
Definition: queue.cc:33
void Drop(Ptr< QueueItem > item)
Drop a packet.
Definition: queue.cc:364
uint32_t GetMaxPackets(void) const
Definition: queue.cc:319
virtual ~Queue()
Definition: queue.cc:90
Ptr< QueueItem > Remove(void)
Remove an item from the front of the Queue, counting it as dropped.
Definition: queue.cc:162
uint32_t GetNPackets(void) const
Definition: queue.cc:213
uint32_t GetMaxBytes(void) const
Definition: queue.cc:340
Every class exported by the ns3 library is enclosed in the ns3 namespace.
TracedCallback< Ptr< const Packet > > m_traceDequeue
Traced callback: fired when a packet is dequeued.
Definition: queue.h:253
Queue::QueueMode GetMode(void) const
Get the encapsulation mode of this device.
Definition: queue.cc:298
TracedCallback< Ptr< const Packet > > m_traceDrop
Traced callback: fired when a packet is dropped.
Definition: queue.h:255
uint32_t m_maxBytes
max bytes in the queue
Definition: queue.h:265
uint32_t GetNBytes(void) const
Definition: queue.cc:221
DropCallback m_dropCallback
drop callback
Definition: queue.h:267
void SetMode(Queue::QueueMode mode)
Set the operating mode of this device.
Definition: queue.cc:279
uint32_t GetTotalReceivedPackets(void) const
Definition: queue.cc:245
virtual Ptr< QueueItem > DoDequeue(void)=0
Pull the item to dequeue from the queue.
uint32_t m_nTotalReceivedPackets
Total received packets.
Definition: queue.h:260
void SetMaxPackets(uint32_t maxPackets)
Set the maximum amount of packets that can be stored in this queue.
Definition: queue.cc:305
uint32_t m_nTotalDroppedPackets
Total dropped packets.
Definition: queue.h:262
void DequeueAll(void)
Flush the queue.
Definition: queue.cc:188
TracedCallback< Ptr< const Packet > > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
Definition: queue.h:251
Ptr< const QueueItem > Peek(void) const
Get a copy of the item at the front of the queue without removing it.
Definition: queue.cc:198
Use number of packets for maximum queue size.
Definition: queue.h:132
uint32_t GetTotalDroppedBytes(void) const
Definition: queue.cc:253
A base class which provides memory management and object aggregation.
Definition: object.h:87
a unique identifier for an interface.
Definition: type-id.h:58
bool Enqueue(Ptr< QueueItem > item)
Place a queue item into the rear of the Queue.
Definition: queue.cc:97
Ptr< QueueItem > Dequeue(void)
Remove an item from the front of the Queue, counting it as dequeued.
Definition: queue.cc:135