queues, trace-writer, debug
This commit is contained in:
1 parent
9bd43c40d5
commit
245fcefd3a
10 files changed
+938
-2
No files matched your search
@@ -0,0 +1,111 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 University of Washington
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "ns3/debug.h"
|
||||
#include "drop-tail.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
namespace {
|
||||
int dtqDebug = 0;
|
||||
}
|
||||
|
||||
DropTailQueue::DropTailQueue () :
|
||||
m_packets (),
|
||||
m_maxPackets(DTQ_NPACKETS_MAX_DEFAULT)
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
"DropTailQueue::DropTailQueue ()")
|
||||
}
|
||||
|
||||
DropTailQueue::DropTailQueue (TraceContainer &traceContainer) :
|
||||
m_packets(),
|
||||
m_maxPackets(DTQ_NPACKETS_MAX_DEFAULT)
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
"DropTailQueue::DropTailQueue (" << &traceContainer << ")")
|
||||
|
||||
RegisterTraces(traceContainer);
|
||||
}
|
||||
|
||||
DropTailQueue::~DropTailQueue ()
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
"DropTailQueue::~DropTailQueue ()")
|
||||
}
|
||||
|
||||
void
|
||||
DropTailQueue::SetMaxPackets (uint32_t npackets)
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
"DropTailQueue::SetMaxPackets (" << npackets << ")")
|
||||
|
||||
m_maxPackets = npackets;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
DropTailQueue::GetMaxPackets (void)
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
"DropTailQueue::GetMaxPackets () <= " << m_maxPackets)
|
||||
|
||||
return m_maxPackets;
|
||||
}
|
||||
|
||||
bool
|
||||
DropTailQueue::DoEnque (const Packet& p)
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
"DropTailQueue::DoEnque (" << &p << ")")
|
||||
|
||||
if (m_nPackets >= m_maxPackets)
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
"DropTailQueue::DoEnque (): Queue full -- droppping pkt")
|
||||
Drop (p);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_packets.push(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
DropTailQueue::DoDeque (Packet& p)
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
"DropTailQueue::DoDeque (" << &p << ")")
|
||||
|
||||
if (m_packets.empty())
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
"DropTailQueue::DoDeque (): Queue empty")
|
||||
return false;
|
||||
}
|
||||
|
||||
p = m_packets.front ();
|
||||
m_packets.pop ();
|
||||
|
||||
NS3_TRACE(dtqDebug,
|
||||
"DropTailQueue::DoDeque (): Popped " << &p << " <= true")
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}; // namespace ns3
|
||||
@@ -0,0 +1,53 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 University of Washington
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef DROPTAIL_H
|
||||
#define DROPTAIL_H
|
||||
|
||||
#include <queue>
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/queue.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
const int DTQ_NPACKETS_MAX_DEFAULT = 100;
|
||||
|
||||
class DropTailQueue : public Queue {
|
||||
public:
|
||||
DropTailQueue ();
|
||||
|
||||
DropTailQueue (TraceContainer &traceContainer);
|
||||
|
||||
virtual ~DropTailQueue();
|
||||
|
||||
void SetMaxPackets (uint32_t npackets);
|
||||
uint32_t GetMaxPackets (void);
|
||||
|
||||
protected:
|
||||
bool DoEnque (const Packet& p);
|
||||
bool DoDeque (Packet &p);
|
||||
|
||||
private:
|
||||
std::queue<Packet> m_packets;
|
||||
uint32_t m_maxPackets;
|
||||
};
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
#endif /* DROPTAIL_H */
|
||||
@@ -0,0 +1,185 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 University of Washington
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "ns3/debug.h"
|
||||
#include "queue.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
namespace {
|
||||
int qDebug = 0;
|
||||
}
|
||||
|
||||
Queue::Queue() :
|
||||
m_nBytes(0),
|
||||
m_nTotalReceivedBytes(0),
|
||||
m_nPackets(0),
|
||||
m_nTotalReceivedPackets(0),
|
||||
m_nTotalDroppedBytes(0),
|
||||
m_nTotalDroppedPackets(0)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::Queue ()")
|
||||
}
|
||||
|
||||
Queue::~Queue()
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::~Queue ()")
|
||||
}
|
||||
|
||||
bool
|
||||
Queue::Enque (const Packet& p)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::Enque (" << &p << ")")
|
||||
|
||||
NS3_TRACE(qDebug, "Queue::Enque (): m_traceEnque (p)")
|
||||
m_traceEnque ("+ <timestamp> ", p);
|
||||
|
||||
bool retval = DoEnque (p);
|
||||
if (retval)
|
||||
{
|
||||
m_nBytes += p.GetSize ();
|
||||
m_nPackets++;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool
|
||||
Queue::Deque (Packet &p)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::Deque (" << &p << ")")
|
||||
|
||||
bool retval = DoDeque (p);
|
||||
|
||||
if (retval)
|
||||
{
|
||||
m_nBytes -= p.GetSize ();
|
||||
m_nPackets--;
|
||||
|
||||
assert(m_nBytes >= 0);
|
||||
assert(m_nPackets >= 0);
|
||||
|
||||
NS3_TRACE(qDebug, "Queue::Deque (): m_traceDeque (p)")
|
||||
m_traceDeque ("+ <timestamp> ", static_cast<const Packet &>(p));
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
Queue::DequeAll (void)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::DequeAll ()")
|
||||
|
||||
assert (!"Don't know what to do with dequeued packets!");
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Queue::GetNPackets (void)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::GetNPackets () <= " << m_nPackets)
|
||||
|
||||
return m_nPackets;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Queue::GetNBytes (void)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::GetNBytes () <= " << m_nBytes)
|
||||
|
||||
return m_nBytes;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Queue::IsEmpty (void)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::IsEmpty () <= " << (m_nPackets == 0))
|
||||
return m_nPackets == 0;
|
||||
}
|
||||
|
||||
void
|
||||
Queue::RegisterTraces (TraceContainer &container)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::RegisterTraces (" << &container << ")")
|
||||
|
||||
container.RegisterCallback ("Queue::Enque", &m_traceEnque);
|
||||
container.RegisterCallback ("Queue::Deque", &m_traceDeque);
|
||||
container.RegisterCallback ("Queue::Drop", &m_traceDrop);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Queue::GetTotalReceivedBytes (void)
|
||||
{
|
||||
NS3_TRACE(qDebug,
|
||||
"Queue::GetTotalReceivedBytes () <= " << m_nTotalReceivedBytes)
|
||||
|
||||
return m_nTotalReceivedBytes;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Queue::GetTotalReceivedPackets (void)
|
||||
{
|
||||
NS3_TRACE(qDebug,
|
||||
"Queue::GetTotalReceivedPackets () <= " << m_nTotalReceivedPackets)
|
||||
|
||||
return m_nTotalReceivedPackets;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Queue:: GetTotalDroppedBytes (void)
|
||||
{
|
||||
NS3_TRACE(qDebug,
|
||||
"Queue::GetTotalDroppedBytes () <= " << m_nTotalDroppedBytes
|
||||
)
|
||||
return m_nTotalDroppedBytes;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Queue::GetTotalDroppedPackets (void)
|
||||
{
|
||||
NS3_TRACE(qDebug,
|
||||
"Queue::GetTotalDroppedPackets () <= " << m_nTotalDroppedPackets)
|
||||
|
||||
return m_nTotalDroppedPackets;
|
||||
}
|
||||
|
||||
void
|
||||
Queue::ResetStatistics (void)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::ResetStatistics ()")
|
||||
|
||||
m_nTotalReceivedBytes = 0;
|
||||
m_nTotalReceivedPackets = 0;
|
||||
m_nTotalDroppedBytes = 0;
|
||||
m_nTotalDroppedPackets = 0;
|
||||
}
|
||||
|
||||
void
|
||||
Queue::Drop (const Packet& p)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::Drop (" << &p << ")")
|
||||
|
||||
m_nTotalDroppedPackets++;
|
||||
m_nTotalDroppedBytes += p.GetSize ();
|
||||
|
||||
NS3_TRACE(qDebug, "Queue::Drop (): m_traceDrop (p)")
|
||||
m_traceEnque ("d <timestamp> ", p);
|
||||
}
|
||||
|
||||
}; // namespace ns3
|
||||
@@ -0,0 +1,115 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 University of Washington
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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
|
||||
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/callback-tracer.h"
|
||||
#include "ns3/trace-container.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Queue
|
||||
{
|
||||
public:
|
||||
Queue ();
|
||||
virtual ~Queue ();
|
||||
|
||||
bool Enque (const Packet& p);
|
||||
bool Deque (Packet &p);
|
||||
|
||||
void DequeAll (void);
|
||||
uint32_t GetNPackets (void);
|
||||
uint32_t GetNBytes (void);
|
||||
|
||||
bool IsEmpty (void);
|
||||
|
||||
void RegisterTraces (TraceContainer &container);
|
||||
|
||||
uint32_t GetTotalReceivedBytes (void);
|
||||
uint32_t GetTotalReceivedPackets (void);
|
||||
uint32_t GetTotalDroppedBytes (void);
|
||||
uint32_t GetTotalDroppedPackets (void);
|
||||
|
||||
void ResetStatistics (void);
|
||||
|
||||
#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:
|
||||
virtual bool DoEnque (const Packet& p) = 0;
|
||||
virtual bool DoDeque (Packet &p) = 0;
|
||||
|
||||
protected:
|
||||
// called by subclasses to notify parent of packet drops.
|
||||
void Drop (const Packet& p);
|
||||
|
||||
uint32_t m_nBytes;
|
||||
uint32_t m_nTotalReceivedBytes;
|
||||
uint32_t m_nPackets;
|
||||
uint32_t m_nTotalReceivedPackets;
|
||||
uint32_t m_nTotalDroppedBytes;
|
||||
uint32_t m_nTotalDroppedPackets;
|
||||
|
||||
private:
|
||||
CallbackTracer<const char *, const Packet &> m_traceEnque;
|
||||
CallbackTracer<const char *, const Packet &> m_traceDeque;
|
||||
CallbackTracer<const char *, const Packet &> m_traceDrop;
|
||||
|
||||
#if 0
|
||||
// Static methods to manage queue default
|
||||
// Set desired queue default
|
||||
static void Default(const Queue& q);
|
||||
// Return reference to the current default queue type
|
||||
static Queue& Default();
|
||||
// Static variable pointing to current default queue
|
||||
static Queue* defaultQueue;
|
||||
#endif
|
||||
};
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
#endif /* QUEUE_H */
|
||||
Reference in new issue
Block a user