A Discrete-Event Network Simulator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
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  */
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.
24 #ifndef QUEUE_H
25 #define QUEUE_H
27 #include <string>
28 #include <list>
29 #include "ns3/packet.h"
30 #include "ns3/object.h"
31 #include "ns3/traced-callback.h"
33 namespace ns3 {
45 class Queue : public Object
46 {
47 public:
52  static TypeId GetTypeId (void);
54  Queue ();
55  virtual ~Queue ();
60  bool IsEmpty (void) const;
66  bool Enqueue (Ptr<Packet> p);
71  Ptr<Packet> Dequeue (void);
76  Ptr<const Packet> Peek (void) const;
81  void DequeueAll (void);
85  uint32_t GetNPackets (void) const;
89  uint32_t GetNBytes (void) const;
97  uint32_t GetTotalReceivedBytes (void) const;
103  uint32_t GetTotalReceivedPackets (void) const;
109  uint32_t GetTotalDroppedBytes (void) const;
115  uint32_t GetTotalDroppedPackets (void) const;
120  void ResetStatistics (void);
127  {
130  };
132 #if 0
133  // average calculation requires keeping around
134  // a buffer with the date of arrival of past received packets
135  // which are within the average window
136  // so, it is quite costly to do it all the time.
137  // Hence, it is disabled by default and must be explicitely
138  // enabled with this method which specifies the size
139  // of the average window in time units.
140  void EnableRunningAverage (Time averageWindow);
141  void DisableRunningAverage (void);
142  // average
143  double GetQueueSizeAverage (void);
144  double GetReceivedBytesPerSecondAverage (void);
145  double GetReceivedPacketsPerSecondAverage (void);
146  double GetDroppedBytesPerSecondAverage (void);
147  double GetDroppedPacketsPerSecondAverage (void);
148  // variance
149  double GetQueueSizeVariance (void);
150  double GetReceivedBytesPerSecondVariance (void);
151  double GetReceivedPacketsPerSecondVariance (void);
152  double GetDroppedBytesPerSecondVariance (void);
153  double GetDroppedPacketsPerSecondVariance (void);
154 #endif
156 private:
163  virtual bool DoEnqueue (Ptr<Packet> p) = 0;
168  virtual Ptr<Packet> DoDequeue (void) = 0;
173  virtual Ptr<const Packet> DoPeek (void) const = 0;
175 protected:
181  void Drop (Ptr<Packet> packet);
183 private:
191  uint32_t m_nBytes;
193  uint32_t m_nPackets;
197 };
199 } // namespace ns3
201 #endif /* QUEUE_H */
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
Definition: queue.cc:44
bool Enqueue(Ptr< Packet > p)
Place a packet into the rear of the Queue.
Definition: queue.cc:62
uint32_t m_nTotalDroppedBytes
Total dropped bytes.
Definition: queue.h:195
virtual Ptr< Packet > DoDequeue(void)=0
Pull a packet from the queue.
bool IsEmpty(void) const
Definition: queue.cc:141
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:173
uint32_t m_nTotalReceivedBytes
Total received bytes.
Definition: queue.h:192
void ResetStatistics(void)
Resets the counts for dropped packets, dropped bytes, received packets, and received bytes...
Definition: queue.cc:181
uint32_t m_nPackets
Number of packets in the queue.
Definition: queue.h:193
Abstract base class for packet Queues.
Definition: queue.h:45
uint32_t GetTotalReceivedBytes(void) const
Definition: queue.cc:149
static TypeId GetTypeId(void)
Get the type ID.
Definition: queue.cc:30
virtual bool DoEnqueue(Ptr< Packet > p)=0
Push a packet in the queue.
virtual ~Queue()
Definition: queue.cc:55
Ptr< Packet > Dequeue(void)
Remove a packet from the front of the Queue.
Definition: queue.cc:86
uint32_t GetNPackets(void) const
Definition: queue.cc:125
uint32_t m_nBytes
Number of bytes in the queue.
Definition: queue.h:191
Use number of bytes for maximum queue size.
Definition: queue.h:129
TracedCallback< Ptr< const Packet > > m_traceDequeue
Traced callback: fired when a packet is dequeued.
Definition: queue.h:187
TracedCallback< Ptr< const Packet > > m_traceDrop
Traced callback: fired when a packet is dropped.
Definition: queue.h:189
uint32_t GetNBytes(void) const
Definition: queue.cc:133
Enumeration of the modes supported in the class.
Definition: queue.h:126
Ptr< const Packet > Peek(void) const
Get a copy of the item at the front of the queue without removing it.
Definition: queue.cc:117
Use number of packets for maximum queue size.
Definition: queue.h:128
uint32_t GetTotalReceivedPackets(void) const
Definition: queue.cc:157
uint32_t m_nTotalReceivedPackets
Total received packets.
Definition: queue.h:194
uint32_t m_nTotalDroppedPackets
Total dropped packets.
Definition: queue.h:196
void DequeueAll(void)
Flush the queue.
Definition: queue.cc:107
TracedCallback< Ptr< const Packet > > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
Definition: queue.h:185
virtual Ptr< const Packet > DoPeek(void) const =0
Peek the front packet in the queue.
uint32_t GetTotalDroppedBytes(void) const
Definition: queue.cc:165
a base class which provides memory management and object aggregation
Definition: object.h:64
a unique identifier for an interface.
Definition: type-id.h:49
void Drop(Ptr< Packet > packet)
Drop a packet.
Definition: queue.cc:191