Files
unison/src/network/utils/queue.h

201 lines
6.2 KiB
C
Raw Normal View History

2007-02-15 16:52:39 -08:00
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// The queue base class does not have any limit based on the number
// of packets or number of bytes. It is, conceptually, infinite
// by default. Only subclasses define limitations.
// The base class implements tracing and basic statistics calculations.
#ifndef QUEUE_H
#define QUEUE_H
2007-02-21 17:06:19 +01:00
#include <string>
#include <list>
2007-02-15 16:52:39 -08:00
#include "ns3/packet.h"
2007-05-25 10:56:03 +02:00
#include "ns3/object.h"
2008-03-02 21:57:51 +01:00
#include "ns3/traced-callback.h"
2007-02-15 16:52:39 -08:00
namespace ns3 {
2007-05-14 14:56:39 -04:00
/**
* \ingroup network
2008-05-30 10:36:02 -07:00
* \defgroup queue Queue
*/
/**
* \ingroup queue
2007-05-14 14:56:39 -04:00
* \brief Abstract base class for packet Queues
*
* This class defines the base APIs for packet queues in the ns-3 system
*/
2007-05-25 10:56:03 +02:00
class Queue : public Object
2007-02-15 16:52:39 -08:00
{
public:
2014-03-13 09:29:47 +01:00
/**
* \brief Get the type ID.
* \return the object TypeId
*/
2008-01-15 12:43:07 +01:00
static TypeId GetTypeId (void);
2007-05-11 19:15:28 +02:00
Queue ();
2007-02-15 16:52:39 -08:00
virtual ~Queue ();
2011-05-13 14:57:43 -04:00
2007-05-14 14:56:39 -04:00
/**
* \return true if the queue is empty; false otherwise
*/
bool IsEmpty (void) const;
2007-05-14 14:56:39 -04:00
/**
* Place a packet into the rear of the Queue
* \param p packet to enqueue
2007-05-14 14:56:39 -04:00
* \return True if the operation was successful; false otherwise
*/
bool Enqueue (Ptr<Packet> p);
2007-05-14 14:56:39 -04:00
/**
* Remove a packet from the front of the Queue
* \return 0 if the operation was not successful; the packet otherwise.
2007-05-14 14:56:39 -04:00
*/
Ptr<Packet> Dequeue (void);
2007-05-14 14:56:39 -04:00
/**
* Get a copy of the item at the front of the queue without removing it
* \return 0 if the operation was not successful; the packet otherwise.
2007-05-14 14:56:39 -04:00
*/
Ptr<const Packet> Peek (void) const;
2007-02-15 16:52:39 -08:00
2007-05-14 14:56:39 -04:00
/**
2008-06-04 09:22:37 -07:00
* Flush the queue.
2007-05-14 14:56:39 -04:00
*/
2007-03-07 22:26:20 -08:00
void DequeueAll (void);
2007-05-14 14:56:39 -04:00
/**
* \return The number of packets currently stored in the Queue
*/
uint32_t GetNPackets (void) const;
2007-05-14 14:56:39 -04:00
/**
* \return The number of bytes currently occupied by the packets in the Queue
*/
uint32_t GetNBytes (void) const;
2007-02-15 16:52:39 -08:00
2007-05-14 14:56:39 -04:00
/**
2010-04-23 15:09:31 +04:00
* \return The total number of bytes received by this Queue since the
2007-05-14 14:56:39 -04:00
* simulation began, or since ResetStatistics was called, according to
* whichever happened more recently
*
*/
uint32_t GetTotalReceivedBytes (void) const;
2007-05-14 14:56:39 -04:00
/**
2010-04-23 15:09:31 +04:00
* \return The total number of packets received by this Queue since the
2007-05-14 14:56:39 -04:00
* simulation began, or since ResetStatistics was called, according to
* whichever happened more recently
*/
uint32_t GetTotalReceivedPackets (void) const;
2007-05-14 14:56:39 -04:00
/**
* \return The total number of bytes dropped by this Queue since the
* simulation began, or since ResetStatistics was called, according to
* whichever happened more recently
*/
uint32_t GetTotalDroppedBytes (void) const;
2007-05-14 14:56:39 -04:00
/**
* \return The total number of bytes dropped by this Queue since the
* simulation began, or since ResetStatistics was called, according to
* whichever happened more recently
*/
uint32_t GetTotalDroppedPackets (void) const;
2007-05-14 14:56:39 -04:00
/**
2010-04-23 15:09:31 +04:00
* Resets the counts for dropped packets, dropped bytes, received packets, and
* received bytes.
2007-05-14 14:56:39 -04:00
*/
2007-02-15 16:52:39 -08:00
void ResetStatistics (void);
/**
* \brief Enumeration of the modes supported in the class.
*
*/
enum QueueMode
{
QUEUE_MODE_PACKETS, /**< Use number of packets for maximum queue size */
QUEUE_MODE_BYTES, /**< Use number of bytes for maximum queue size */
};
2007-02-15 16:52:39 -08:00
#if 0
// average calculation requires keeping around
// a buffer with the date of arrival of past received packets
// which are within the average window
// so, it is quite costly to do it all the time.
// Hence, it is disabled by default and must be explicitely
// enabled with this method which specifies the size
// of the average window in time units.
void EnableRunningAverage (Time averageWindow);
void DisableRunningAverage (void);
// average
double GetQueueSizeAverage (void);
double GetReceivedBytesPerSecondAverage (void);
double GetReceivedPacketsPerSecondAverage (void);
double GetDroppedBytesPerSecondAverage (void);
double GetDroppedPacketsPerSecondAverage (void);
// variance
double GetQueueSizeVariance (void);
double GetReceivedBytesPerSecondVariance (void);
double GetReceivedPacketsPerSecondVariance (void);
double GetDroppedBytesPerSecondVariance (void);
double GetDroppedPacketsPerSecondVariance (void);
#endif
private:
2007-05-14 14:56:39 -04:00
2014-03-13 09:29:47 +01:00
/**
* Push a packet in the queue
* \param p the packet to enqueue
* \return true if success, false if the packet has been dropped.
*/
virtual bool DoEnqueue (Ptr<Packet> p) = 0;
2014-03-13 09:29:47 +01:00
/**
* Pull a packet from the queue
* \return the packet.
*/
virtual Ptr<Packet> DoDequeue (void) = 0;
2014-03-13 09:29:47 +01:00
/**
* Peek the front packet in the queue
* \return the packet.
*/
virtual Ptr<const Packet> DoPeek (void) const = 0;
2007-02-15 16:52:39 -08:00
protected:
2013-11-15 16:20:58 -05:00
/**
* \brief Drop a packet
* \param packet packet that was dropped
* This method is called by subclasses to notify parent (this class) of packet drops.
*/
void Drop (Ptr<Packet> packet);
2007-02-21 17:06:19 +01:00
2014-03-13 09:29:47 +01:00
/// Traced callback: fired when a packet is enqueued
2008-03-02 21:57:51 +01:00
TracedCallback<Ptr<const Packet> > m_traceEnqueue;
2014-03-13 09:29:47 +01:00
/// Traced callback: fired when a packet is dequeued
2008-03-02 21:57:51 +01:00
TracedCallback<Ptr<const Packet> > m_traceDequeue;
2014-03-13 09:29:47 +01:00
/// Traced callback: fired when a packet is dropped
2008-03-02 21:57:51 +01:00
TracedCallback<Ptr<const Packet> > m_traceDrop;
2007-02-15 16:52:39 -08:00
2014-03-13 09:29:47 +01:00
uint32_t m_nBytes; //!< Number of bytes in the queue
uint32_t m_nTotalReceivedBytes; //!< Total received bytes
uint32_t m_nPackets; //!< Number of packets in the queue
uint32_t m_nTotalReceivedPackets; //!< Total received packets
uint32_t m_nTotalDroppedBytes; //!< Total dropped bytes
uint32_t m_nTotalDroppedPackets; //!< Total dropped packets
2007-02-15 16:52:39 -08:00
};
} // namespace ns3
2007-02-15 16:52:39 -08:00
#endif /* QUEUE_H */