A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 does not have any limit based on the number
20 // of packets or number of bytes. It is, conceptually, infinite
21 // by default. Only subclasses define limitations.
22 // The base class implements tracing and basic statistics calculations.
23 
24 #ifndef QUEUE_H
25 #define QUEUE_H
26 
27 #include <string>
28 #include <list>
29 #include "ns3/packet.h"
30 #include "ns3/object.h"
31 #include "ns3/traced-callback.h"
32 
33 namespace ns3 {
34 
45 class Queue : public Object
46 {
47 public:
48  static TypeId GetTypeId (void);
49 
50  Queue ();
51  virtual ~Queue ();
52 
56  bool IsEmpty (void) const;
62  bool Enqueue (Ptr<Packet> p);
67  Ptr<Packet> Dequeue (void);
72  Ptr<const Packet> Peek (void) const;
73 
77  void DequeueAll (void);
81  uint32_t GetNPackets (void) const;
85  uint32_t GetNBytes (void) const;
86 
93  uint32_t GetTotalReceivedBytes (void) const;
99  uint32_t GetTotalReceivedPackets (void) const;
105  uint32_t GetTotalDroppedBytes (void) const;
111  uint32_t GetTotalDroppedPackets (void) const;
116  void ResetStatistics (void);
117 
123  {
126  };
127 
128 #if 0
129  // average calculation requires keeping around
130  // a buffer with the date of arrival of past received packets
131  // which are within the average window
132  // so, it is quite costly to do it all the time.
133  // Hence, it is disabled by default and must be explicitely
134  // enabled with this method which specifies the size
135  // of the average window in time units.
136  void EnableRunningAverage (Time averageWindow);
137  void DisableRunningAverage (void);
138  // average
139  double GetQueueSizeAverage (void);
140  double GetReceivedBytesPerSecondAverage (void);
141  double GetReceivedPacketsPerSecondAverage (void);
142  double GetDroppedBytesPerSecondAverage (void);
143  double GetDroppedPacketsPerSecondAverage (void);
144  // variance
145  double GetQueueSizeVariance (void);
146  double GetReceivedBytesPerSecondVariance (void);
147  double GetReceivedPacketsPerSecondVariance (void);
148  double GetDroppedBytesPerSecondVariance (void);
149  double GetDroppedPacketsPerSecondVariance (void);
150 #endif
151 
152 private:
153 
154  virtual bool DoEnqueue (Ptr<Packet> p) = 0;
155  virtual Ptr<Packet> DoDequeue (void) = 0;
156  virtual Ptr<const Packet> DoPeek (void) const = 0;
157 
158 protected:
164  void Drop (Ptr<Packet> packet);
165 
166 private:
170 
171  uint32_t m_nBytes;
173  uint32_t m_nPackets;
177 };
178 
179 } // namespace ns3
180 
181 #endif /* QUEUE_H */
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
Queue()
Definition: queue.cc:45
bool Enqueue(Ptr< Packet > p)
Place a packet into the rear of the Queue.
Definition: queue.cc:63
uint32_t m_nTotalDroppedBytes
Definition: queue.h:175
virtual Ptr< Packet > DoDequeue(void)=0
bool IsEmpty(void) const
Definition: queue.cc:142
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
uint32_t GetTotalDroppedPackets(void) const
Definition: queue.cc:174
uint32_t m_nTotalReceivedBytes
Definition: queue.h:172
void ResetStatistics(void)
Resets the counts for dropped packets, dropped bytes, received packets, and received bytes...
Definition: queue.cc:182
uint32_t m_nPackets
Definition: queue.h:173
Abstract base class for packet Queues.
Definition: queue.h:45
uint32_t GetTotalReceivedBytes(void) const
Definition: queue.cc:150
static TypeId GetTypeId(void)
Definition: queue.cc:31
virtual bool DoEnqueue(Ptr< Packet > p)=0
virtual ~Queue()
Definition: queue.cc:56
Ptr< Packet > Dequeue(void)
Remove a packet from the front of the Queue.
Definition: queue.cc:87
uint32_t GetNPackets(void) const
Definition: queue.cc:126
uint32_t m_nBytes
Definition: queue.h:171
Use number of bytes for maximum queue size.
Definition: queue.h:125
TracedCallback< Ptr< const Packet > > m_traceDequeue
Definition: queue.h:168
TracedCallback< Ptr< const Packet > > m_traceDrop
Definition: queue.h:169
uint32_t GetNBytes(void) const
Definition: queue.cc:134
QueueMode
Enumeration of the modes supported in the class.
Definition: queue.h:122
Ptr< const Packet > Peek(void) const
Get a copy of the item at the front of the queue without removing it.
Definition: queue.cc:118
Use number of packets for maximum queue size.
Definition: queue.h:124
uint32_t GetTotalReceivedPackets(void) const
Definition: queue.cc:158
uint32_t m_nTotalReceivedPackets
Definition: queue.h:174
uint32_t m_nTotalDroppedPackets
Definition: queue.h:176
void DequeueAll(void)
Flush the queue.
Definition: queue.cc:108
TracedCallback< Ptr< const Packet > > m_traceEnqueue
Definition: queue.h:167
virtual Ptr< const Packet > DoPeek(void) const =0
uint32_t GetTotalDroppedBytes(void) const
Definition: queue.cc:166
a base class which provides memory management and object aggregation
Definition: object.h:63
a unique identifier for an interface.
Definition: type-id.h:49
void Drop(Ptr< Packet > packet)
Drop a packet.
Definition: queue.cc:192