From c6e5ecc1912f3d2a67349175d93ac308be128542 Mon Sep 17 00:00:00 2001
From: Pasquale Imputato
Date: Tue, 8 Mar 2016 10:45:36 -0800
Subject: [PATCH] network: The Queue base class holds mode, maxPackets and
maxBytes ...so that all the subclasses have such attributes. This allows
queue discs to have attributes specifying the mode and size of their queue(s)
and to create queues using their own attributes.
This commit is heavily inspired by Natale's queue rework patch:
https://codereview.appspot.com/270540044/
---
src/network/utils/drop-tail-queue.cc | 86 +-----------
src/network/utils/drop-tail-queue.h | 25 +---
src/network/utils/queue.cc | 144 +++++++++++++++++++--
src/network/utils/queue.h | 72 +++++++++--
src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc | 2 +-
src/test/ns3tcp/ns3tcp-state-test-suite.cc | 2 +-
6 files changed, 204 insertions(+), 127 deletions(-)
diff --git a/src/network/utils/drop-tail-queue.cc b/src/network/utils/drop-tail-queue.cc
index ce137a166..5a8785a7c 100644
--- a/src/network/utils/drop-tail-queue.cc
+++ b/src/network/utils/drop-tail-queue.cc
@@ -17,8 +17,6 @@
*/
#include "ns3/log.h"
-#include "ns3/enum.h"
-#include "ns3/uinteger.h"
#include "drop-tail-queue.h"
namespace ns3 {
@@ -27,38 +25,19 @@ NS_LOG_COMPONENT_DEFINE ("DropTailQueue");
NS_OBJECT_ENSURE_REGISTERED (DropTailQueue);
-TypeId DropTailQueue::GetTypeId (void)
+TypeId DropTailQueue::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::DropTailQueue")
.SetParent ()
- .SetGroupName("Network")
+ .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)
+ m_packets ()
{
NS_LOG_FUNCTION (this);
}
@@ -68,46 +47,14 @@ 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 ();
+ NS_ASSERT (m_packets.size () == GetNPackets ());
- 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;
}
@@ -115,22 +62,13 @@ Ptr
DropTailQueue::DoDequeue (void)
{
NS_LOG_FUNCTION (this);
-
- if (m_packets.empty ())
- {
- NS_LOG_LOGIC ("Queue empty");
- return 0;
- }
+ NS_ASSERT (m_packets.size () == GetNPackets ());
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;
}
@@ -138,19 +76,9 @@ Ptr
DropTailQueue::DoPeek (void) const
{
NS_LOG_FUNCTION (this);
+ NS_ASSERT (m_packets.size () == GetNPackets ());
- 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;
+ return m_packets.front ();
}
} // namespace ns3
diff --git a/src/network/utils/drop-tail-queue.h b/src/network/utils/drop-tail-queue.h
index 64457b307..8f796ecda 100644
--- a/src/network/utils/drop-tail-queue.h
+++ b/src/network/utils/drop-tail-queue.h
@@ -20,19 +20,17 @@
#define DROPTAIL_H
#include
-#include "ns3/packet.h"
#include "ns3/queue.h"
namespace ns3 {
-class TraceContainer;
-
/**
* \ingroup queue
*
* \brief A FIFO packet queue that drops tail-end packets on overflow
*/
-class DropTailQueue : public Queue {
+class DropTailQueue : public Queue
+{
public:
/**
* \brief Get the type ID.
@@ -48,31 +46,12 @@ public:
virtual ~DropTailQueue();
- /**
- * Set the operating mode of this device.
- *
- * \param mode The operating mode of this device.
- *
- */
- void SetMode (DropTailQueue::QueueMode mode);
-
- /**
- * Get the encapsulation mode of this device.
- *
- * \returns The encapsulation mode of this device.
- */
- DropTailQueue::QueueMode GetMode (void) const;
-
private:
virtual bool DoEnqueue (Ptr item);
virtual Ptr DoDequeue (void);
virtual Ptr DoPeek (void) const;
std::queue > m_packets; //!< the items in the queue
- uint32_t m_maxPackets; //!< max packets in the queue
- uint32_t m_maxBytes; //!< max bytes in the queue
- uint32_t m_bytesInQueue; //!< actual bytes in the queue
- QueueMode m_mode; //!< queue mode (packets or bytes limited)
};
} // namespace ns3
diff --git a/src/network/utils/queue.cc b/src/network/utils/queue.cc
index 44781cab0..477d992a2 100644
--- a/src/network/utils/queue.cc
+++ b/src/network/utils/queue.cc
@@ -17,6 +17,9 @@
*/
#include "ns3/log.h"
+#include "ns3/abort.h"
+#include "ns3/enum.h"
+#include "ns3/uinteger.h"
#include "ns3/trace-source-accessor.h"
#include "queue.h"
@@ -31,16 +34,43 @@ Queue::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::Queue")
.SetParent