00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2007 University of Washington 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 */ 00018 00019 // The queue base class does not have any limit based on the number 00020 // of packets or number of bytes. It is, conceptually, infinite 00021 // by default. Only subclasses define limitations. 00022 // The base class implements tracing and basic statistics calculations. 00023 00024 #ifndef QUEUE_H 00025 #define QUEUE_H 00026 00027 #include <string> 00028 #include <list> 00029 #include "ns3/packet.h" 00030 #include "ns3/object.h" 00031 #include "ns3/traced-callback.h" 00032 00033 namespace ns3 { 00034 00035 /** 00036 * \ingroup node 00037 * \defgroup queue Queue 00038 */ 00039 /** 00040 * \ingroup queue 00041 * \brief Abstract base class for packet Queues 00042 * 00043 * This class defines the base APIs for packet queues in the ns-3 system 00044 */ 00045 class Queue : public Object 00046 { 00047 public: 00048 static TypeId GetTypeId (void); 00049 00050 Queue (); 00051 virtual ~Queue (); 00052 00053 /** 00054 * \return true if the queue is empty; false otherwise 00055 */ 00056 bool IsEmpty (void) const; 00057 /** 00058 * Place a packet into the rear of the Queue 00059 * \return True if the operation was successful; false otherwise 00060 */ 00061 bool Enqueue (Ptr<Packet> p); 00062 /** 00063 * Remove a packet from the front of the Queue 00064 * \return 0 if the operation was not successful; the packet otherwise. 00065 */ 00066 Ptr<Packet> Dequeue (void); 00067 /** 00068 * Get a copy of the item at the front of the queue without removing it 00069 * \return 0 if the operation was not successful; the packet otherwise. 00070 */ 00071 Ptr<const Packet> Peek (void) const; 00072 00073 /** 00074 * Flush the queue. 00075 */ 00076 void DequeueAll (void); 00077 /** 00078 * \return The number of packets currently stored in the Queue 00079 */ 00080 uint32_t GetNPackets (void) const; 00081 /** 00082 * \return The number of bytes currently occupied by the packets in the Queue 00083 */ 00084 uint32_t GetNBytes (void) const; 00085 00086 /** 00087 * \return The total number of bytes recieved by this Queue since the 00088 * simulation began, or since ResetStatistics was called, according to 00089 * whichever happened more recently 00090 * 00091 */ 00092 uint32_t GetTotalReceivedBytes (void) const; 00093 /** 00094 * \return The total number of packets recieved by this Queue since the 00095 * simulation began, or since ResetStatistics was called, according to 00096 * whichever happened more recently 00097 */ 00098 uint32_t GetTotalReceivedPackets (void) const; 00099 /** 00100 * \return The total number of bytes dropped by this Queue since the 00101 * simulation began, or since ResetStatistics was called, according to 00102 * whichever happened more recently 00103 */ 00104 uint32_t GetTotalDroppedBytes (void) const; 00105 /** 00106 * \return The total number of bytes dropped by this Queue since the 00107 * simulation began, or since ResetStatistics was called, according to 00108 * whichever happened more recently 00109 */ 00110 uint32_t GetTotalDroppedPackets (void) const; 00111 /** 00112 * Resets the counts for dropped packets, dropped bytes, recieved packets, and 00113 * recieved bytes. 00114 */ 00115 void ResetStatistics (void); 00116 00117 #if 0 00118 // average calculation requires keeping around 00119 // a buffer with the date of arrival of past received packets 00120 // which are within the average window 00121 // so, it is quite costly to do it all the time. 00122 // Hence, it is disabled by default and must be explicitely 00123 // enabled with this method which specifies the size 00124 // of the average window in time units. 00125 void EnableRunningAverage (Time averageWindow); 00126 void DisableRunningAverage (void); 00127 // average 00128 double GetQueueSizeAverage (void); 00129 double GetReceivedBytesPerSecondAverage (void); 00130 double GetReceivedPacketsPerSecondAverage (void); 00131 double GetDroppedBytesPerSecondAverage (void); 00132 double GetDroppedPacketsPerSecondAverage (void); 00133 // variance 00134 double GetQueueSizeVariance (void); 00135 double GetReceivedBytesPerSecondVariance (void); 00136 double GetReceivedPacketsPerSecondVariance (void); 00137 double GetDroppedBytesPerSecondVariance (void); 00138 double GetDroppedPacketsPerSecondVariance (void); 00139 #endif 00140 00141 private: 00142 00143 virtual bool DoEnqueue (Ptr<Packet> p) = 0; 00144 virtual Ptr<Packet> DoDequeue (void) = 0; 00145 virtual Ptr<const Packet> DoPeek (void) const = 0; 00146 00147 protected: 00148 // called by subclasses to notify parent of packet drops. 00149 void Drop (Ptr<Packet> packet); 00150 00151 private: 00152 TracedCallback<Ptr<const Packet> > m_traceEnqueue; 00153 TracedCallback<Ptr<const Packet> > m_traceDequeue; 00154 TracedCallback<Ptr<const Packet> > m_traceDrop; 00155 00156 uint32_t m_nBytes; 00157 uint32_t m_nTotalReceivedBytes; 00158 uint32_t m_nPackets; 00159 uint32_t m_nTotalReceivedPackets; 00160 uint32_t m_nTotalDroppedBytes; 00161 uint32_t m_nTotalDroppedPackets; 00162 }; 00163 00164 }; // namespace ns3 00165 00166 #endif /* QUEUE_H */