# HG changeset patch # User Mathieu Lacage # Date 1181639040 -7200 # Node ID e2f6fe585ab877a2f70162f4e7bae67f8bff6beb # Parent f4a677b1f7532101a0a4865ea81c98d47fd4cd01 fix bug 29 diff -r f4a677b1f753 -r e2f6fe585ab8 SConstruct --- a/SConstruct Tue Jun 12 10:53:38 2007 +0200 +++ b/SConstruct Tue Jun 12 11:04:00 2007 +0200 @@ -234,7 +234,7 @@ 'llc-snap-header.cc', 'ipv4-route.cc', 'queue.cc', - 'drop-tail.cc', + 'drop-tail-queue.cc', 'channel.cc', 'node-list.cc', 'socket.cc', @@ -250,7 +250,7 @@ 'mac-address.h', 'ipv4-route.h', 'queue.h', - 'drop-tail.h', + 'drop-tail-queue.h', 'llc-snap-header.h', 'channel.h', 'node-list.h', diff -r f4a677b1f753 -r e2f6fe585ab8 examples/simple-p2p.cc --- a/examples/simple-p2p.cc Tue Jun 12 10:53:38 2007 +0200 +++ b/examples/simple-p2p.cc Tue Jun 12 11:04:00 2007 +0200 @@ -42,10 +42,10 @@ #include #include -#include "ns3/debug.h" #include "ns3/command-line.h" #include "ns3/default-value.h" #include "ns3/ptr.h" +#include "ns3/random-variable.h" #include "ns3/simulator.h" #include "ns3/nstime.h" @@ -61,12 +61,8 @@ #include "ns3/ipv4.h" #include "ns3/socket.h" #include "ns3/ipv4-route.h" -#include "ns3/drop-tail.h" -#include "ns3/node-list.h" -#include "ns3/trace-root.h" #include "ns3/p2p-topology.h" #include "ns3/onoff-application.h" -#include "ns3/random-variable.h" using namespace ns3; diff -r f4a677b1f753 -r e2f6fe585ab8 src/node/drop-tail-queue.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/node/drop-tail-queue.cc Tue Jun 12 11:04:00 2007 +0200 @@ -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-queue.h" + +NS_DEBUG_COMPONENT_DEFINE ("DropTailQueue"); + +namespace ns3 { + +const ClassId DropTailQueue::cid = + MakeClassId ("DropTailQueue", Queue::iid); + + +DropTailQueue::DropTailQueue () : + Queue (), + m_packets (), + m_maxPackets(DTQ_NPACKETS_MAX_DEFAULT) +{ + NS_DEBUG("DropTailQueue::DropTailQueue ()"); +} + +DropTailQueue::~DropTailQueue () +{ + NS_DEBUG("DropTailQueue::~DropTailQueue ()"); +} + +void +DropTailQueue::SetMaxPackets (uint32_t npackets) +{ + NS_DEBUG("DropTailQueue::SetMaxPackets (" << npackets << ")"); + + m_maxPackets = npackets; +} + +uint32_t +DropTailQueue::GetMaxPackets (void) +{ + NS_DEBUG("DropTailQueue::GetMaxPackets () <= " << m_maxPackets); + + return m_maxPackets; +} + +bool +DropTailQueue::DoEnqueue (const Packet& p) +{ + NS_DEBUG("DropTailQueue::DoEnqueue (" << &p << ")"); + + if (m_packets.size () >= m_maxPackets) + { + NS_DEBUG("DropTailQueue::DoEnqueue (): Queue full -- droppping pkt"); + Drop (p); + return false; + } + + m_packets.push(p); + return true; +} + +bool +DropTailQueue::DoDequeue (Packet& p) +{ + NS_DEBUG("DropTailQueue::DoDequeue (" << &p << ")"); + + if (m_packets.empty()) + { + NS_DEBUG("DropTailQueue::DoDequeue (): Queue empty"); + return false; + } + + p = m_packets.front (); + m_packets.pop (); + + NS_DEBUG("DropTailQueue::DoDequeue (): Popped " << &p << " <= true"); + + return true; +} + +bool +DropTailQueue::DoPeek (Packet& p) +{ + NS_DEBUG("DropTailQueue::DoPeek (" << &p << ")"); + + if (m_packets.empty()) + { + NS_DEBUG("DropTailQueue::DoPeek (): Queue empty"); + return false; + } + + p = m_packets.front (); + + return true; +} + +}; // namespace ns3 diff -r f4a677b1f753 -r e2f6fe585ab8 src/node/drop-tail-queue.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/node/drop-tail-queue.h Tue Jun 12 11:04:00 2007 +0200 @@ -0,0 +1,71 @@ +/* -*- 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 +#include "ns3/packet.h" +#include "ns3/queue.h" +#include "ns3/component-manager.h" + +namespace ns3 { + +class TraceContainer; + +const int DTQ_NPACKETS_MAX_DEFAULT = 100; + +/** + * \brief A FIFO packet queue that drops tail-end packets on overflow + */ +class DropTailQueue : public Queue { +public: + static const ClassId cid; + /** + * \brief DropTailQueue Constructor + * + * Creates a droptail queue with a maximum size of 100 packets by default + */ + DropTailQueue (); + + virtual ~DropTailQueue(); + /** + * \param npackets The maximum number of packets this queue will hold before + * dropping packets. + */ + void SetMaxPackets (uint32_t npackets); + /** + * \return The maximum number of packets this queue will hold before dropping + * packets. + */ + uint32_t GetMaxPackets (void); + +private: + virtual bool DoEnqueue (const Packet& p); + virtual bool DoDequeue (Packet &p); + virtual bool DoPeek (Packet &p); + +private: + std::queue m_packets; + uint32_t m_maxPackets; +}; + +}; // namespace ns3 + +#endif /* DROPTAIL_H */ diff -r f4a677b1f753 -r e2f6fe585ab8 src/node/drop-tail.cc --- a/src/node/drop-tail.cc Tue Jun 12 10:53:38 2007 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -/* -*- 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" - -NS_DEBUG_COMPONENT_DEFINE ("DropTailQueue"); - -namespace ns3 { - -const ClassId DropTailQueue::cid = - MakeClassId ("DropTailQueue", Queue::iid); - - -DropTailQueue::DropTailQueue () : - Queue (), - m_packets (), - m_maxPackets(DTQ_NPACKETS_MAX_DEFAULT) -{ - NS_DEBUG("DropTailQueue::DropTailQueue ()"); -} - -DropTailQueue::~DropTailQueue () -{ - NS_DEBUG("DropTailQueue::~DropTailQueue ()"); -} - -void -DropTailQueue::SetMaxPackets (uint32_t npackets) -{ - NS_DEBUG("DropTailQueue::SetMaxPackets (" << npackets << ")"); - - m_maxPackets = npackets; -} - -uint32_t -DropTailQueue::GetMaxPackets (void) -{ - NS_DEBUG("DropTailQueue::GetMaxPackets () <= " << m_maxPackets); - - return m_maxPackets; -} - -bool -DropTailQueue::DoEnqueue (const Packet& p) -{ - NS_DEBUG("DropTailQueue::DoEnqueue (" << &p << ")"); - - if (m_packets.size () >= m_maxPackets) - { - NS_DEBUG("DropTailQueue::DoEnqueue (): Queue full -- droppping pkt"); - Drop (p); - return false; - } - - m_packets.push(p); - return true; -} - -bool -DropTailQueue::DoDequeue (Packet& p) -{ - NS_DEBUG("DropTailQueue::DoDequeue (" << &p << ")"); - - if (m_packets.empty()) - { - NS_DEBUG("DropTailQueue::DoDequeue (): Queue empty"); - return false; - } - - p = m_packets.front (); - m_packets.pop (); - - NS_DEBUG("DropTailQueue::DoDequeue (): Popped " << &p << " <= true"); - - return true; -} - -bool -DropTailQueue::DoPeek (Packet& p) -{ - NS_DEBUG("DropTailQueue::DoPeek (" << &p << ")"); - - if (m_packets.empty()) - { - NS_DEBUG("DropTailQueue::DoPeek (): Queue empty"); - return false; - } - - p = m_packets.front (); - - return true; -} - -}; // namespace ns3 diff -r f4a677b1f753 -r e2f6fe585ab8 src/node/drop-tail.h --- a/src/node/drop-tail.h Tue Jun 12 10:53:38 2007 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* -*- 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 -#include "ns3/packet.h" -#include "ns3/queue.h" -#include "ns3/component-manager.h" - -namespace ns3 { - -class TraceContainer; - -const int DTQ_NPACKETS_MAX_DEFAULT = 100; - -/** - * \brief A FIFO packet queue that drops tail-end packets on overflow - */ -class DropTailQueue : public Queue { -public: - static const ClassId cid; - /** - * \brief DropTailQueue Constructor - * - * Creates a droptail queue with a maximum size of 100 packets by default - */ - DropTailQueue (); - - virtual ~DropTailQueue(); - /** - * \param npackets The maximum number of packets this queue will hold before - * dropping packets. - */ - void SetMaxPackets (uint32_t npackets); - /** - * \return The maximum number of packets this queue will hold before dropping - * packets. - */ - uint32_t GetMaxPackets (void); - -private: - virtual bool DoEnqueue (const Packet& p); - virtual bool DoDequeue (Packet &p); - virtual bool DoPeek (Packet &p); - -private: - std::queue m_packets; - uint32_t m_maxPackets; -}; - -}; // namespace ns3 - -#endif /* DROPTAIL_H */