Files
unison/src/node/queue.cc

199 lines
3.9 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
* 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
*/
2007-09-13 21:36:32 -07:00
#include "ns3/log.h"
#include "ns3/trace-source-accessor.h"
#include "queue.h"
2007-02-15 16:52:39 -08:00
2007-09-13 21:36:32 -07:00
NS_LOG_COMPONENT_DEFINE ("Queue");
2007-02-15 16:52:39 -08:00
namespace ns3 {
2007-02-15 16:52:39 -08:00
NS_OBJECT_ENSURE_REGISTERED (Queue);
2007-05-11 19:15:28 +02:00
2008-01-15 12:36:22 +01:00
TypeId
2008-01-15 12:43:07 +01:00
Queue::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::Queue")
2008-03-02 21:57:51 +01:00
.SetParent<Object> ()
.AddTraceSource ("Enqueue", "XXX",
MakeTraceSourceAccessor (&Queue::m_traceEnqueue))
.AddTraceSource ("Dequeue", "XXX",
MakeTraceSourceAccessor (&Queue::m_traceDequeue))
.AddTraceSource ("Drop", "XXX",
MakeTraceSourceAccessor (&Queue::m_traceDrop))
2008-03-02 21:57:51 +01:00
;
2008-01-15 12:44:09 +01:00
return tid;
}
Queue::Queue() :
2007-02-15 16:52:39 -08:00
m_nBytes(0),
m_nTotalReceivedBytes(0),
m_nPackets(0),
m_nTotalReceivedPackets(0),
m_nTotalDroppedBytes(0),
m_nTotalDroppedPackets(0)
2007-02-15 16:52:39 -08:00
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
2007-02-15 16:52:39 -08:00
}
Queue::~Queue()
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
2007-02-15 16:52:39 -08:00
}
2007-02-21 17:06:19 +01:00
bool
Queue::Enqueue (Ptr<Packet> p)
2007-02-15 16:52:39 -08:00
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
2007-11-22 10:30:29 +01:00
NS_LOG_PARAMS (this << p);
2007-09-13 21:36:32 -07:00
NS_LOG_LOGIC ("m_traceEnqueue (p)");
m_traceEnqueue (p);
2007-02-15 16:52:39 -08:00
2007-03-07 22:26:20 -08:00
bool retval = DoEnqueue (p);
2007-02-15 16:52:39 -08:00
if (retval)
{
m_nBytes += p->GetSize ();
2007-02-15 16:52:39 -08:00
m_nPackets++;
}
return retval;
}
Ptr<Packet>
Queue::Dequeue (void)
2007-02-15 16:52:39 -08:00
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
2007-11-22 10:30:29 +01:00
NS_LOG_PARAMS (this);
2007-02-15 16:52:39 -08:00
Ptr<Packet> packet = DoDequeue ();
2007-02-15 16:52:39 -08:00
if (packet != 0)
2007-02-15 16:52:39 -08:00
{
m_nBytes -= packet->GetSize ();
2007-02-15 16:52:39 -08:00
m_nPackets--;
NS_ASSERT (m_nBytes >= 0);
NS_ASSERT (m_nPackets >= 0);
2007-02-15 16:52:39 -08:00
2007-11-22 10:30:29 +01:00
NS_LOG_LOGIC("m_traceDequeue (packet)");
m_traceDequeue (packet);
2007-02-15 16:52:39 -08:00
}
return packet;
2007-02-15 16:52:39 -08:00
}
2007-02-21 17:06:19 +01:00
void
2007-03-07 22:26:20 -08:00
Queue::DequeueAll (void)
2007-02-15 16:52:39 -08:00
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
NS_ASSERT_MSG (0, "Don't know what to do with dequeued packets!");
2007-02-15 16:52:39 -08:00
}
Ptr<Packet>
2007-11-22 10:30:29 +01:00
Queue::Peek (void) const
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
2007-11-22 10:30:29 +01:00
NS_LOG_PARAMS (this);
return DoPeek ();
}
2007-02-21 17:06:19 +01:00
uint32_t
Queue::GetNPackets (void) const
2007-02-15 16:52:39 -08:00
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
NS_LOG_LOGIC ("returns " << m_nPackets);
2007-02-15 16:52:39 -08:00
return m_nPackets;
}
2007-02-21 17:06:19 +01:00
uint32_t
Queue::GetNBytes (void) const
2007-02-15 16:52:39 -08:00
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
NS_LOG_LOGIC (" returns " << m_nBytes);
2007-02-15 16:52:39 -08:00
return m_nBytes;
}
2007-02-21 17:06:19 +01:00
bool
Queue::IsEmpty (void) const
2007-02-15 16:52:39 -08:00
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
2007-09-13 22:17:29 -07:00
NS_LOG_LOGIC ("returns " << (m_nPackets == 0));
2007-02-15 16:52:39 -08:00
return m_nPackets == 0;
}
2007-02-21 17:06:19 +01:00
uint32_t
Queue::GetTotalReceivedBytes (void) const
2007-02-15 16:52:39 -08:00
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
NS_LOG_LOGIC("returns " << m_nTotalReceivedBytes);
2007-02-15 16:52:39 -08:00
return m_nTotalReceivedBytes;
}
2007-02-21 17:06:19 +01:00
uint32_t
Queue::GetTotalReceivedPackets (void) const
2007-02-15 16:52:39 -08:00
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
NS_LOG_LOGIC ("returns " << m_nTotalReceivedPackets);
2007-02-15 16:52:39 -08:00
return m_nTotalReceivedPackets;
}
2007-02-21 17:06:19 +01:00
uint32_t
Queue:: GetTotalDroppedBytes (void) const
2007-02-15 16:52:39 -08:00
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
NS_LOG_LOGIC ("returns " << m_nTotalDroppedBytes);
2007-02-15 16:52:39 -08:00
return m_nTotalDroppedBytes;
}
2007-02-21 17:06:19 +01:00
uint32_t
Queue::GetTotalDroppedPackets (void) const
2007-02-15 16:52:39 -08:00
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
NS_LOG_LOGIC("returns " << m_nTotalDroppedPackets);
2007-02-15 16:52:39 -08:00
return m_nTotalDroppedPackets;
}
2007-02-21 17:06:19 +01:00
void
2007-02-15 16:52:39 -08:00
Queue::ResetStatistics (void)
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
2007-02-15 16:52:39 -08:00
m_nTotalReceivedBytes = 0;
m_nTotalReceivedPackets = 0;
m_nTotalDroppedBytes = 0;
m_nTotalDroppedPackets = 0;
}
2007-02-21 16:30:08 +01:00
void
Queue::Drop (Ptr<Packet> p)
2007-02-15 16:52:39 -08:00
{
2007-09-13 21:36:32 -07:00
NS_LOG_FUNCTION;
2007-11-22 10:30:29 +01:00
NS_LOG_PARAMS (this << p);
2007-02-15 16:52:39 -08:00
m_nTotalDroppedPackets++;
m_nTotalDroppedBytes += p->GetSize ();
2007-02-15 16:52:39 -08:00
2007-09-13 21:36:32 -07:00
NS_LOG_LOGIC ("m_traceDrop (p)");
m_traceDrop (p);
2007-02-15 16:52:39 -08:00
}
2008-03-02 21:57:51 +01:00
} // namespace ns3