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<const QueueItem> Peek (void) const;
76 
80  void DequeueAll (void);
84  uint32_t GetNPackets (void) const;
88  uint32_t GetNBytes (void) const;
89 
96  uint32_t GetTotalReceivedBytes (void) const;
102  uint32_t GetTotalReceivedPackets (void) const;
108  uint32_t GetTotalDroppedBytes (void) const;
114  uint32_t GetTotalDroppedPackets (void) const;
119  void ResetStatistics (void);
120 
126  {
129  };
130 
136  void SetMode (Queue::QueueMode mode);
137 
143  Queue::QueueMode GetMode (void) const;
144 
150  void SetMaxPackets (uint32_t maxPackets);
151 
155  uint32_t GetMaxPackets (void) const;
156 
162  void SetMaxBytes (uint32_t maxBytes);
163 
167  uint32_t GetMaxBytes (void) const;
168 
169 #if 0
170  // average calculation requires keeping around
171  // a buffer with the date of arrival of past received packets
172  // which are within the average window
173  // so, it is quite costly to do it all the time.
174  // Hence, it is disabled by default and must be explicitely
175  // enabled with this method which specifies the size
176  // of the average window in time units.
177  void EnableRunningAverage (Time averageWindow);
178  void DisableRunningAverage (void);
179  // average
180  double GetQueueSizeAverage (void);
181  double GetReceivedBytesPerSecondAverage (void);
182  double GetReceivedPacketsPerSecondAverage (void);
183  double GetDroppedBytesPerSecondAverage (void);
184  double GetDroppedPacketsPerSecondAverage (void);
185  // variance
186  double GetQueueSizeVariance (void);
187  double GetReceivedBytesPerSecondVariance (void);
188  double GetReceivedPacketsPerSecondVariance (void);
189  double GetDroppedBytesPerSecondVariance (void);
190  double GetDroppedPacketsPerSecondVariance (void);
191 #endif
192 
193 protected:
202  void Drop (Ptr<Packet> p);
203 
204 private:
210  virtual bool DoEnqueue (Ptr<QueueItem> item) = 0;
215  virtual Ptr<QueueItem> DoDequeue (void) = 0;
220  virtual Ptr<const QueueItem> DoPeek (void) const = 0;
221 
228 
235 
236  uint32_t m_maxPackets;
237  uint32_t m_maxBytes;
239 };
240 
241 } // namespace ns3
242 
243 #endif /* QUEUE_H */
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:238
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
uint32_t m_nTotalDroppedBytes
Total dropped bytes.
Definition: queue.h:233
void SetMaxBytes(uint32_t maxBytes)
Set the maximum amount of bytes that can be stored in this queue.
Definition: queue.cc:301
Use number of bytes for maximum queue size.
Definition: queue.h:128
bool IsEmpty(void) const
Definition: queue.cc:204
Forward calls to a chain of Callback.
uint32_t GetTotalDroppedPackets(void) const
Definition: queue.cc:236
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Definition: queue.h:231
uint32_t m_nTotalReceivedBytes
Total received bytes.
Definition: queue.h:230
void ResetStatistics(void)
Resets the counts for dropped packets, dropped bytes, received packets, and received bytes...
Definition: queue.cc:244
uint32_t m_maxPackets
max packets in the queue
Definition: queue.h:236
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:229
Abstract base class for packet Queues.
Definition: queue.h:44
uint32_t GetTotalReceivedBytes(void) const
Definition: queue.cc:212
QueueMode
Enumeration of the modes supported in the class.
Definition: queue.h:125
static TypeId GetTypeId(void)
Get the type ID.
Definition: queue.cc:33
uint32_t GetMaxPackets(void) const
Definition: queue.cc:294
virtual ~Queue()
Definition: queue.cc:90
uint32_t GetNPackets(void) const
Definition: queue.cc:188
uint32_t GetMaxBytes(void) const
Definition: queue.cc:315
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:225
Queue::QueueMode GetMode(void) const
Get the encapsulation mode of this device.
Definition: queue.cc:273
TracedCallback< Ptr< const Packet > > m_traceDrop
Traced callback: fired when a packet is dropped.
Definition: queue.h:227
uint32_t m_maxBytes
max bytes in the queue
Definition: queue.h:237
uint32_t GetNBytes(void) const
Definition: queue.cc:196
void Drop(Ptr< Packet > p)
Drop a packet.
Definition: queue.cc:322
void SetMode(Queue::QueueMode mode)
Set the operating mode of this device.
Definition: queue.cc:254
uint32_t GetTotalReceivedPackets(void) const
Definition: queue.cc:220
virtual Ptr< QueueItem > DoDequeue(void)=0
Pull an item from the queue.
uint32_t m_nTotalReceivedPackets
Total received packets.
Definition: queue.h:232
void SetMaxPackets(uint32_t maxPackets)
Set the maximum amount of packets that can be stored in this queue.
Definition: queue.cc:280
uint32_t m_nTotalDroppedPackets
Total dropped packets.
Definition: queue.h:234
void DequeueAll(void)
Flush the queue.
Definition: queue.cc:163
TracedCallback< Ptr< const Packet > > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
Definition: queue.h:223
Ptr< const QueueItem > Peek(void) const
Get a copy of the item at the front of the queue without removing it.
Definition: queue.cc:173
Use number of packets for maximum queue size.
Definition: queue.h:127
uint32_t GetTotalDroppedBytes(void) const
Definition: queue.cc:228
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.
Definition: queue.cc:136