/* -*- 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 */ #include "ns3/log.h" #include "ns3/enum.h" #include "ns3/uinteger.h" #include "drop-tail-queue.h" namespace ns3 { NS_LOG_COMPONENT_DEFINE ("DropTailQueue"); NS_OBJECT_ENSURE_REGISTERED (DropTailQueue); TypeId DropTailQueue::GetTypeId (void) { static TypeId tid = TypeId ("ns3::DropTailQueue") .SetParent () .SetGroupName("Network") .AddConstructor () .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")) .AddAttribute ("MaxPackets", "The maximum number of packets accepted by this DropTailQueue.", UintegerValue (100), MakeUintegerAccessor (&DropTailQueue::m_maxPackets), MakeUintegerChecker ()) .AddAttribute ("MaxBytes", "The maximum number of bytes accepted by this DropTailQueue.", UintegerValue (100 * 65535), MakeUintegerAccessor (&DropTailQueue::m_maxBytes), MakeUintegerChecker ()) ; return tid; } DropTailQueue::DropTailQueue () : Queue (), m_packets (), m_bytesInQueue (0) { NS_LOG_FUNCTION (this); } DropTailQueue::~DropTailQueue () { NS_LOG_FUNCTION (this); } void DropTailQueue::SetMode (DropTailQueue::QueueMode mode) { NS_LOG_FUNCTION (this << mode); m_mode = mode; } DropTailQueue::QueueMode DropTailQueue::GetMode (void) const { NS_LOG_FUNCTION (this); return m_mode; } bool DropTailQueue::DoEnqueue (Ptr item) { NS_LOG_FUNCTION (this << item); Ptr p = item->GetPacket (); if (m_mode == QUEUE_MODE_PACKETS && (m_packets.size () >= m_maxPackets)) { NS_LOG_LOGIC ("Queue full (at max packets) -- droppping pkt"); Drop (p); return false; } if (m_mode == QUEUE_MODE_BYTES && (m_bytesInQueue + item->GetPacketSize () >= m_maxBytes)) { NS_LOG_LOGIC ("Queue full (packet would exceed max bytes) -- droppping pkt"); Drop (p); return false; } m_bytesInQueue += item->GetPacketSize (); m_packets.push (item); NS_LOG_LOGIC ("Number packets " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue); return true; } Ptr DropTailQueue::DoDequeue (void) { NS_LOG_FUNCTION (this); if (m_packets.empty ()) { NS_LOG_LOGIC ("Queue empty"); return 0; } Ptr item = m_packets.front (); m_packets.pop (); m_bytesInQueue -= item->GetPacketSize (); NS_LOG_LOGIC ("Popped " << item); NS_LOG_LOGIC ("Number packets " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue); return item; } Ptr DropTailQueue::DoPeek (void) const { NS_LOG_FUNCTION (this); if (m_packets.empty ()) { NS_LOG_LOGIC ("Queue empty"); return 0; } Ptr item = m_packets.front (); NS_LOG_LOGIC ("Number packets " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue); return item; } } // namespace ns3