Files
unison/src/network/utils/drop-tail-queue.cc

158 lines
4.1 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
*/
2007-09-13 21:36:32 -07:00
#include "ns3/log.h"
2009-02-18 22:19:20 -08:00
#include "ns3/enum.h"
2008-02-21 19:09:05 +01:00
#include "ns3/uinteger.h"
2007-06-12 11:04:00 +02:00
#include "drop-tail-queue.h"
2007-02-15 16:52:39 -08:00
namespace ns3 {
2007-02-15 16:52:39 -08:00
NS_LOG_COMPONENT_DEFINE ("DropTailQueue");
NS_OBJECT_ENSURE_REGISTERED (DropTailQueue);
2008-01-15 12:43:07 +01:00
TypeId DropTailQueue::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::DropTailQueue")
.SetParent<Queue> ()
2015-03-27 07:03:58 -07:00
.SetGroupName("Network")
2008-02-14 19:47:19 +01:00
.AddConstructor<DropTailQueue> ()
2009-02-18 22:19:20 -08:00
.AddAttribute ("Mode",
"Whether to use bytes (see MaxBytes) or packets (see MaxPackets) as the maximum queue size metric.",
EnumValue (QUEUE_MODE_PACKETS),
MakeEnumAccessor (&DropTailQueue::SetMode,
&DropTailQueue::GetMode),
MakeEnumChecker (QUEUE_MODE_BYTES, "QUEUE_MODE_BYTES",
QUEUE_MODE_PACKETS, "QUEUE_MODE_PACKETS"))
2009-02-18 22:19:20 -08:00
.AddAttribute ("MaxPackets",
"The maximum number of packets accepted by this DropTailQueue.",
UintegerValue (100),
MakeUintegerAccessor (&DropTailQueue::m_maxPackets),
MakeUintegerChecker<uint32_t> ())
2009-02-18 22:19:20 -08:00
.AddAttribute ("MaxBytes",
"The maximum number of bytes accepted by this DropTailQueue.",
UintegerValue (100 * 65535),
MakeUintegerAccessor (&DropTailQueue::m_maxBytes),
MakeUintegerChecker<uint32_t> ())
2011-05-13 14:57:43 -04:00
;
2008-01-15 12:44:09 +01:00
return tid;
}
2007-02-15 16:52:39 -08:00
DropTailQueue::DropTailQueue () :
Queue (),
2010-04-15 15:11:49 -07:00
m_packets (),
m_bytesInQueue (0)
2007-02-15 16:52:39 -08:00
{
NS_LOG_FUNCTION (this);
2007-02-15 16:52:39 -08:00
}
2007-02-21 17:06:19 +01:00
DropTailQueue::~DropTailQueue ()
{
NS_LOG_FUNCTION (this);
}
2011-05-13 14:57:43 -04:00
void
DropTailQueue::SetMode (DropTailQueue::QueueMode mode)
2009-02-18 22:19:20 -08:00
{
NS_LOG_FUNCTION (this << mode);
2009-02-18 22:19:20 -08:00
m_mode = mode;
}
DropTailQueue::QueueMode
DropTailQueue::GetMode (void) const
2009-02-18 22:19:20 -08:00
{
NS_LOG_FUNCTION (this);
2009-02-18 22:19:20 -08:00
return m_mode;
}
2011-05-13 14:57:43 -04:00
bool
DropTailQueue::DoEnqueue (Ptr<QueueItem> item)
2007-02-15 16:52:39 -08:00
{
NS_LOG_FUNCTION (this << item);
Ptr<Packet> p = item->GetPacket ();
2007-02-15 16:52:39 -08:00
if (m_mode == QUEUE_MODE_PACKETS && (m_packets.size () >= m_maxPackets))
2007-02-15 16:52:39 -08:00
{
2009-02-18 22:19:20 -08:00
NS_LOG_LOGIC ("Queue full (at max packets) -- droppping pkt");
2007-02-15 16:52:39 -08:00
Drop (p);
return false;
}
if (m_mode == QUEUE_MODE_BYTES && (m_bytesInQueue + item->GetPacketSize () >= m_maxBytes))
2009-02-18 22:19:20 -08:00
{
NS_LOG_LOGIC ("Queue full (packet would exceed max bytes) -- droppping pkt");
Drop (p);
return false;
}
m_bytesInQueue += item->GetPacketSize ();
m_packets.push (item);
2009-02-18 22:19:20 -08:00
NS_LOG_LOGIC ("Number packets " << m_packets.size ());
NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);
2007-02-15 16:52:39 -08:00
return true;
}
Ptr<QueueItem>
DropTailQueue::DoDequeue (void)
2007-02-15 16:52:39 -08:00
{
NS_LOG_FUNCTION (this);
if (m_packets.empty ())
{
2007-09-13 21:36:32 -07:00
NS_LOG_LOGIC ("Queue empty");
2010-03-24 08:49:24 +01:00
return 0;
}
Ptr<QueueItem> item = m_packets.front ();
2007-02-15 16:52:39 -08:00
m_packets.pop ();
m_bytesInQueue -= item->GetPacketSize ();
2007-02-15 16:52:39 -08:00
NS_LOG_LOGIC ("Popped " << item);
2007-02-15 16:52:39 -08:00
2009-02-18 22:19:20 -08:00
NS_LOG_LOGIC ("Number packets " << m_packets.size ());
NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);
return item;
2007-02-15 16:52:39 -08:00
}
Ptr<const QueueItem>
2007-11-22 10:30:29 +01:00
DropTailQueue::DoPeek (void) const
{
NS_LOG_FUNCTION (this);
if (m_packets.empty ())
{
2007-09-13 21:36:32 -07:00
NS_LOG_LOGIC ("Queue empty");
2010-03-24 08:49:24 +01:00
return 0;
}
Ptr<QueueItem> item = m_packets.front ();
2009-02-18 22:19:20 -08:00
NS_LOG_LOGIC ("Number packets " << m_packets.size ());
NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);
return item;
}
2007-11-15 15:42:07 +00:00
} // namespace ns3