From df2fa959700daea39a32d4b8c885f98bbcbdefa0 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Tue, 8 Mar 2016 10:44:03 -0800 Subject: [PATCH] network: Make Queue store QueueItem objects A QueueItem base class is introduced to represent the items stored in a Queue. The base class only contains a Ptr. Derived classes can store additional information. DropTailQueue, RedQueue and CodelQueue, along with their examples and testsuits, have been adapted. Objects using such queues have been adapted too. --- src/csma/model/csma-net-device.cc | 17 ++-- src/internet/model/codel-queue.cc | 46 ++++++----- src/internet/model/codel-queue.h | 10 +-- src/internet/test/codel-queue-test-suite.cc | 66 +++++++-------- src/network/model/net-device.cc | 38 +++++++++ src/network/model/net-device.h | 82 +++++++++++++++++++ .../test/drop-tail-queue-test-suite.cc | 32 ++++---- src/network/test/red-queue-test-suite.cc | 52 ++++++------ src/network/utils/drop-tail-queue.cc | 27 +++--- src/network/utils/drop-tail-queue.h | 8 +- src/network/utils/queue.cc | 25 +++--- src/network/utils/queue.h | 43 +++++----- src/network/utils/red-queue.cc | 29 +++---- src/network/utils/red-queue.h | 8 +- src/network/utils/simple-net-device.cc | 6 +- .../model/point-to-point-net-device.cc | 9 +- src/spectrum/model/aloha-noack-net-device.cc | 9 +- 17 files changed, 319 insertions(+), 188 deletions(-) diff --git a/src/csma/model/csma-net-device.cc b/src/csma/model/csma-net-device.cc index 03581965c..37d15455d 100644 --- a/src/csma/model/csma-net-device.cc +++ b/src/csma/model/csma-net-device.cc @@ -564,8 +564,9 @@ CsmaNetDevice::TransmitAbort (void) } else { - m_currentPkt = m_queue->Dequeue (); - NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::TransmitAbort(): IsEmpty false but no Packet on queue?"); + Ptr item = m_queue->Dequeue (); + NS_ASSERT_MSG (item != 0, "CsmaNetDevice::TransmitAbort(): IsEmpty false but no Packet on queue?"); + m_currentPkt = item->GetPacket (); m_snifferTrace (m_currentPkt); m_promiscSnifferTrace (m_currentPkt); TransmitStart (); @@ -632,8 +633,9 @@ CsmaNetDevice::TransmitReadyEvent (void) } else { - m_currentPkt = m_queue->Dequeue (); - NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::TransmitReadyEvent(): IsEmpty false but no Packet on queue?"); + Ptr item = m_queue->Dequeue (); + NS_ASSERT_MSG (item != 0, "CsmaNetDevice::TransmitReadyEvent(): IsEmpty false but no Packet on queue?"); + m_currentPkt = item->GetPacket (); m_snifferTrace (m_currentPkt); m_promiscSnifferTrace (m_currentPkt); TransmitStart (); @@ -968,7 +970,7 @@ CsmaNetDevice::SendFrom (Ptr packet, const Address& src, const Address& // Place the packet to be sent on the send queue. Note that the // queue may fire a drop trace, but we will too. // - if (m_queue->Enqueue (packet) == false) + if (m_queue->Enqueue (Create (packet)) == false) { m_macTxDropTrace (packet); return false; @@ -983,8 +985,9 @@ CsmaNetDevice::SendFrom (Ptr packet, const Address& src, const Address& { if (m_queue->IsEmpty () == false) { - m_currentPkt = m_queue->Dequeue (); - NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::SendFrom(): IsEmpty false but no Packet on queue?"); + Ptr item = m_queue->Dequeue (); + NS_ASSERT_MSG (item != 0, "CsmaNetDevice::SendFrom(): IsEmpty false but no Packet on queue?"); + m_currentPkt = item->GetPacket (); m_promiscSnifferTrace (m_currentPkt); m_snifferTrace (m_currentPkt); TransmitStart (); diff --git a/src/internet/model/codel-queue.cc b/src/internet/model/codel-queue.cc index 3c897230a..ed95e5fa2 100644 --- a/src/internet/model/codel-queue.cc +++ b/src/internet/model/codel-queue.cc @@ -276,9 +276,10 @@ CoDelQueue::GetMode (void) } bool -CoDelQueue::DoEnqueue (Ptr p) +CoDelQueue::DoEnqueue (Ptr item) { - NS_LOG_FUNCTION (this << p); + NS_LOG_FUNCTION (this << item); + Ptr p = item->GetPacket (); if (m_mode == QUEUE_MODE_PACKETS && (m_packets.size () + 1 > m_maxPackets)) { @@ -288,7 +289,7 @@ CoDelQueue::DoEnqueue (Ptr p) return false; } - if (m_mode == QUEUE_MODE_BYTES && (m_bytesInQueue + p->GetSize () > m_maxBytes)) + 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); @@ -300,8 +301,8 @@ CoDelQueue::DoEnqueue (Ptr p) CoDelTimestampTag tag; p->AddPacketTag (tag); - m_bytesInQueue += p->GetSize (); - m_packets.push (p); + m_bytesInQueue += item->GetPacketSize (); + m_packets.push (item); NS_LOG_LOGIC ("Number packets " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue); @@ -351,7 +352,7 @@ CoDelQueue::OkToDrop (Ptr p, uint32_t now) return okToDrop; } -Ptr +Ptr CoDelQueue::DoDequeue (void) { NS_LOG_FUNCTION (this); @@ -365,11 +366,12 @@ CoDelQueue::DoDequeue (void) return 0; } uint32_t now = CoDelGetTime (); - Ptr p = m_packets.front (); + Ptr item = m_packets.front (); m_packets.pop (); - m_bytesInQueue -= p->GetSize (); + Ptr p = item->GetPacket (); + m_bytesInQueue -= item->GetPacketSize (); - NS_LOG_LOGIC ("Popped " << p); + NS_LOG_LOGIC ("Popped " << item); NS_LOG_LOGIC ("Number packets remaining " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes remaining " << m_bytesInQueue); @@ -403,7 +405,7 @@ CoDelQueue::DoDequeue (void) // p was in queue, trace dequeue and update stats manually m_traceDequeue (p); - m_nBytes -= p->GetSize (); + m_nBytes -= item->GetPacketSize (); m_nPackets--; ++m_dropCount; @@ -416,11 +418,12 @@ CoDelQueue::DoDequeue (void) ++m_states; return 0; } - p = m_packets.front (); + item = m_packets.front (); m_packets.pop (); - m_bytesInQueue -= p->GetSize (); + p = item ->GetPacket (); + m_bytesInQueue -= item->GetPacketSize (); - NS_LOG_LOGIC ("Popped " << p); + NS_LOG_LOGIC ("Popped " << item); NS_LOG_LOGIC ("Number packets remaining " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes remaining " << m_bytesInQueue); @@ -454,7 +457,7 @@ CoDelQueue::DoDequeue (void) // p was in queue, trace the dequeue and update stats manually m_traceDequeue (p); - m_nBytes -= p->GetSize (); + m_nBytes -= item->GetPacketSize (); m_nPackets--; if (m_packets.empty ()) @@ -466,11 +469,12 @@ CoDelQueue::DoDequeue (void) } else { - p = m_packets.front (); + item = m_packets.front (); m_packets.pop (); - m_bytesInQueue -= p->GetSize (); + p = item->GetPacket (); + m_bytesInQueue -= item->GetPacketSize (); - NS_LOG_LOGIC ("Popped " << p); + NS_LOG_LOGIC ("Popped " << item); NS_LOG_LOGIC ("Number packets remaining " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes remaining " << m_bytesInQueue); @@ -501,7 +505,7 @@ CoDelQueue::DoDequeue (void) } } ++m_states; - return p; + return item; } uint32_t @@ -552,7 +556,7 @@ CoDelQueue::GetDropNext (void) return m_dropNext; } -Ptr +Ptr CoDelQueue::DoPeek (void) const { NS_LOG_FUNCTION (this); @@ -563,12 +567,12 @@ CoDelQueue::DoPeek (void) const return 0; } - Ptr p = m_packets.front (); + Ptr item = m_packets.front (); NS_LOG_LOGIC ("Number packets " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue); - return p; + return item; } bool diff --git a/src/internet/model/codel-queue.h b/src/internet/model/codel-queue.h index 3dfe666a6..0519c25ff 100644 --- a/src/internet/model/codel-queue.h +++ b/src/internet/model/codel-queue.h @@ -142,10 +142,10 @@ private: /** * \brief Add a packet to the queue * - * \param p The packet to be added + * \param item The item to be added * \returns True if the packet can be added, False if the packet is dropped due to full queue */ - virtual bool DoEnqueue (Ptr p); + virtual bool DoEnqueue (Ptr item); /** * \brief Remove a packet from queue based on the current state @@ -156,9 +156,9 @@ private: * * \returns The packet that is examined */ - virtual Ptr DoDequeue (void); + virtual Ptr DoDequeue (void); - virtual Ptr DoPeek (void) const; + virtual Ptr DoPeek (void) const; /** * \brief Calculate the reciprocal square root of m_count by using Newton's method @@ -223,7 +223,7 @@ private: */ uint32_t Time2CoDel (Time t); - std::queue > m_packets; //!< The packet queue + std::queue > m_packets; //!< The packet queue uint32_t m_maxPackets; //!< Max # of packets accepted by the queue uint32_t m_maxBytes; //!< Max # of bytes accepted by the queue TracedValue m_bytesInQueue; //!< The total number of bytes in queue diff --git a/src/internet/test/codel-queue-test-suite.cc b/src/internet/test/codel-queue-test-suite.cc index c96388619..5f7cf29d0 100644 --- a/src/internet/test/codel-queue-test-suite.cc +++ b/src/internet/test/codel-queue-test-suite.cc @@ -125,55 +125,55 @@ CoDelQueueBasicEnqueueDequeue::DoRun (void) p6 = Create (pktSize); QueueTestSize (queue, 0 * modeSize, "There should be no packets in queue"); - queue->Enqueue (p1); + queue->Enqueue (Create (p1)); QueueTestSize (queue, 1 * modeSize, "There should be one packet in queue"); - queue->Enqueue (p2); + queue->Enqueue (Create (p2)); QueueTestSize (queue, 2 * modeSize, "There should be two packets in queue"); - queue->Enqueue (p3); + queue->Enqueue (Create (p3)); QueueTestSize (queue, 3 * modeSize, "There should be three packets in queue"); - queue->Enqueue (p4); + queue->Enqueue (Create (p4)); QueueTestSize (queue, 4 * modeSize, "There should be four packets in queue"); - queue->Enqueue (p5); + queue->Enqueue (Create (p5)); QueueTestSize (queue, 5 * modeSize, "There should be five packets in queue"); - queue->Enqueue (p6); + queue->Enqueue (Create (p6)); QueueTestSize (queue, 6 * modeSize, "There should be six packets in queue"); NS_TEST_EXPECT_MSG_EQ (queue->GetDropOverLimit (), 0, "There should be no packets being dropped due to full queue"); - Ptr p; + Ptr item; - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the first packet"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the first packet"); QueueTestSize (queue, 5 * modeSize, "There should be five packets in queue"); - NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p1->GetUid (), "was this the first packet ?"); + NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p1->GetUid (), "was this the first packet ?"); - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the second packet"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the second packet"); QueueTestSize (queue, 4 * modeSize, "There should be four packets in queue"); - NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p2->GetUid (), "Was this the second packet ?"); + NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p2->GetUid (), "Was this the second packet ?"); - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the third packet"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the third packet"); QueueTestSize (queue, 3 * modeSize, "There should be three packets in queue"); - NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p3->GetUid (), "Was this the third packet ?"); + NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p3->GetUid (), "Was this the third packet ?"); - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the forth packet"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the forth packet"); QueueTestSize (queue, 2 * modeSize, "There should be two packets in queue"); - NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p4->GetUid (), "Was this the fourth packet ?"); + NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p4->GetUid (), "Was this the fourth packet ?"); - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the fifth packet"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the fifth packet"); QueueTestSize (queue, 1 * modeSize, "There should be one packet in queue"); - NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p5->GetUid (), "Was this the fifth packet ?"); + NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p5->GetUid (), "Was this the fifth packet ?"); - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the last packet"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the last packet"); QueueTestSize (queue, 0 * modeSize, "There should be zero packet in queue"); - NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p6->GetUid (), "Was this the sixth packet ?"); + NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p6->GetUid (), "Was this the sixth packet ?"); - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p == 0), true, "There are really no packets in queue"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item == 0), true, "There are really no packets in queue"); NS_TEST_EXPECT_MSG_EQ (queue->GetDropCount (), 0, "There should be no packet drops according to CoDel algorithm"); } @@ -242,9 +242,9 @@ CoDelQueueBasicOverflow::DoRun (void) "Verify that we can actually set the attribute MinBytes"); Enqueue (queue, pktSize, 500); - queue->Enqueue (p1); - queue->Enqueue (p2); - queue->Enqueue (p3); + queue->Enqueue (Create (p1)); + queue->Enqueue (Create (p2)); + queue->Enqueue (Create (p3)); QueueTestSize (queue, 500 * modeSize, "There should be 500 packets in queue"); NS_TEST_EXPECT_MSG_EQ (queue->GetDropOverLimit (), 3, "There should be three packets being dropped due to full queue"); @@ -255,7 +255,7 @@ CoDelQueueBasicOverflow::Enqueue (Ptr queue, uint32_t size, uint32_t { for (uint32_t i = 0; i < nPkt; i++) { - queue->Enqueue (Create (size)); + queue->Enqueue (Create (Create (size))); } } @@ -435,7 +435,7 @@ CoDelQueueBasicDrop::Enqueue (Ptr queue, uint32_t size, uint32_t nPk { for (uint32_t i = 0; i < nPkt; i++) { - queue->Enqueue (Create (size)); + queue->Enqueue (Create (Create (size))); } } @@ -455,7 +455,7 @@ CoDelQueueBasicDrop::Dequeue (Ptr queue, uint32_t modeSize) if (initialQSize != 0) { - Ptr p = queue->Dequeue (); + Ptr item = queue->Dequeue (); if (initialDropCount == 0 && currentTime > queue->GetTarget ()) { if (currentTime < queue->GetInterval ()) diff --git a/src/network/model/net-device.cc b/src/network/model/net-device.cc index e854a4fb3..de8e9e13b 100644 --- a/src/network/model/net-device.cc +++ b/src/network/model/net-device.cc @@ -22,11 +22,49 @@ #include "ns3/log.h" #include "ns3/uinteger.h" #include "net-device.h" +#include "packet.h" namespace ns3 { NS_LOG_COMPONENT_DEFINE ("NetDevice"); +QueueItem::QueueItem (Ptr p) +{ + m_packet = p; +} + +QueueItem::~QueueItem() +{ + NS_LOG_FUNCTION (this); + m_packet = 0; +} + +Ptr +QueueItem::GetPacket (void) const +{ + return m_packet; +} + +uint32_t +QueueItem::GetPacketSize (void) const +{ + NS_ASSERT (m_packet != 0); + return m_packet->GetSize (); +} + +void +QueueItem::Print (std::ostream& os) const +{ + os << GetPacket(); +} + +std::ostream & operator << (std::ostream &os, const QueueItem &item) +{ + item.Print (os); + return os; +} + + NS_OBJECT_ENSURE_REGISTERED (NetDevice); TypeId NetDevice::GetTypeId (void) diff --git a/src/network/model/net-device.h b/src/network/model/net-device.h index c4599c7a5..969194af8 100644 --- a/src/network/model/net-device.h +++ b/src/network/model/net-device.h @@ -40,6 +40,88 @@ class Packet; * \ingroup network * \defgroup netdevice Network Device */ + +/** + * \ingroup netdevice + * \brief Base class to represent items of packet Queues + * + * An item stored in an ns-3 packet Queue contains a packet and possibly other + * information. An item of the base class only contains a packet. Subclasses + * can be derived from this base class to allow items to contain additional + * information. + */ +class QueueItem : public SimpleRefCount +{ +public: + /** + * \brief Create a queue item containing a packet. + * \param p the packet included in the created item. + */ + QueueItem (Ptr p); + + virtual ~QueueItem (); + + /** + * \return the packet included in this item. + */ + Ptr GetPacket (void) const; + + /** + * \brief Use this method (instead of GetPacket ()->GetSize ()) to get the packet size + * + * Subclasses may keep header and payload separate to allow manipulating the header, + * so using this method ensures that the correct packet size is returned. + * + * \return the size of the packet included in this item. + */ + virtual uint32_t GetPacketSize (void) const; + + /** + * \brief Print the item contents. + * \param os output stream in which the data should be printed. + */ + virtual void Print (std::ostream &os) const; + + /** + * TracedCallback signature for Ptr + * + * \param [in] item The queue item. + */ + typedef void (* TracedCallback) (Ptr item); + +private: + /** + * \brief Default constructor + * + * Defined and unimplemented to avoid misuse + */ + QueueItem (); + /** + * \brief Copy constructor + * + * Defined and unimplemented to avoid misuse + */ + QueueItem (const QueueItem &); + /** + * \brief Assignment operator + * + * Defined and unimplemented to avoid misuse + * \returns + */ + QueueItem &operator = (const QueueItem &); + + Ptr m_packet; +}; + +/** + * \brief Stream insertion operator. + * + * \param os the stream + * \param item the item + * \returns a reference to the stream + */ +std::ostream& operator<< (std::ostream& os, const QueueItem &item); + /** * \ingroup netdevice * diff --git a/src/network/test/drop-tail-queue-test-suite.cc b/src/network/test/drop-tail-queue-test-suite.cc index 56eff386a..1edb03b98 100644 --- a/src/network/test/drop-tail-queue-test-suite.cc +++ b/src/network/test/drop-tail-queue-test-suite.cc @@ -47,34 +47,34 @@ DropTailQueueTestCase::DoRun (void) p4 = Create (); NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 0, "There should be no packets in there"); - queue->Enqueue (p1); + queue->Enqueue (Create (p1)); NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there"); - queue->Enqueue (p2); + queue->Enqueue (Create (p2)); NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there"); - queue->Enqueue (p3); + queue->Enqueue (Create (p3)); NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be three packets in there"); - queue->Enqueue (p4); // will be dropped + queue->Enqueue (Create (p4)); // will be dropped NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be still three packets in there"); - Ptr p; + Ptr item; - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the first packet"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the first packet"); NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there"); - NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p1->GetUid (), "was this the first packet ?"); + NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p1->GetUid (), "was this the first packet ?"); - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the second packet"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the second packet"); NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there"); - NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p2->GetUid (), "Was this the second packet ?"); + NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p2->GetUid (), "Was this the second packet ?"); - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the third packet"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the third packet"); NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 0, "There should be no packets in there"); - NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p3->GetUid (), "Was this the third packet ?"); + NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p3->GetUid (), "Was this the third packet ?"); - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p == 0), true, "There are really no packets in there"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item == 0), true, "There are really no packets in there"); } static class DropTailQueueTestSuite : public TestSuite diff --git a/src/network/test/red-queue-test-suite.cc b/src/network/test/red-queue-test-suite.cc index 17110721d..880d3eaae 100644 --- a/src/network/test/red-queue-test-suite.cc +++ b/src/network/test/red-queue-test-suite.cc @@ -86,43 +86,43 @@ RedQueueTestCase::RunRedTest (StringValue mode) p8 = Create (pktSize); NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 0 * modeSize, "There should be no packets in there"); - queue->Enqueue (p1); + queue->Enqueue (Create (p1)); NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 1 * modeSize, "There should be one packet in there"); - queue->Enqueue (p2); + queue->Enqueue (Create (p2)); NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 2 * modeSize, "There should be two packets in there"); - queue->Enqueue (p3); - queue->Enqueue (p4); - queue->Enqueue (p5); - queue->Enqueue (p6); - queue->Enqueue (p7); - queue->Enqueue (p8); + queue->Enqueue (Create (p3)); + queue->Enqueue (Create (p4)); + queue->Enqueue (Create (p5)); + queue->Enqueue (Create (p6)); + queue->Enqueue (Create (p7)); + queue->Enqueue (Create (p8)); NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 8 * modeSize, "There should be eight packets in there"); - Ptr p; + Ptr item; - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the first packet"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the first packet"); NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 7 * modeSize, "There should be seven packets in there"); - NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p1->GetUid (), "was this the first packet ?"); + NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p1->GetUid (), "was this the first packet ?"); - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the second packet"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the second packet"); NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 6 * modeSize, "There should be six packet in there"); - NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p2->GetUid (), "Was this the second packet ?"); + NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p2->GetUid (), "Was this the second packet ?"); - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the third packet"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the third packet"); NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 5 * modeSize, "There should be five packets in there"); - NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p3->GetUid (), "Was this the third packet ?"); + NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p3->GetUid (), "Was this the third packet ?"); - p = queue->Dequeue (); - p = queue->Dequeue (); - p = queue->Dequeue (); - p = queue->Dequeue (); - p = queue->Dequeue (); + item = queue->Dequeue (); + item = queue->Dequeue (); + item = queue->Dequeue (); + item = queue->Dequeue (); + item = queue->Dequeue (); - p = queue->Dequeue (); - NS_TEST_EXPECT_MSG_EQ ((p == 0), true, "There are really no packets in there"); + item = queue->Dequeue (); + NS_TEST_EXPECT_MSG_EQ ((item == 0), true, "There are really no packets in there"); // test 2: more data, but with no drops @@ -257,7 +257,7 @@ RedQueueTestCase::Enqueue (Ptr queue, uint32_t size, uint32_t nPkt) { for (uint32_t i = 0; i < nPkt; i++) { - queue->Enqueue (Create (size)); + queue->Enqueue (Create (Create (size))); } } diff --git a/src/network/utils/drop-tail-queue.cc b/src/network/utils/drop-tail-queue.cc index 9e68e7358..ce137a166 100644 --- a/src/network/utils/drop-tail-queue.cc +++ b/src/network/utils/drop-tail-queue.cc @@ -83,9 +83,10 @@ DropTailQueue::GetMode (void) const } bool -DropTailQueue::DoEnqueue (Ptr p) +DropTailQueue::DoEnqueue (Ptr item) { - NS_LOG_FUNCTION (this << p); + NS_LOG_FUNCTION (this << item); + Ptr p = item->GetPacket (); if (m_mode == QUEUE_MODE_PACKETS && (m_packets.size () >= m_maxPackets)) { @@ -94,15 +95,15 @@ DropTailQueue::DoEnqueue (Ptr p) return false; } - if (m_mode == QUEUE_MODE_BYTES && (m_bytesInQueue + p->GetSize () >= m_maxBytes)) + 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 += p->GetSize (); - m_packets.push (p); + m_bytesInQueue += item->GetPacketSize (); + m_packets.push (item); NS_LOG_LOGIC ("Number packets " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue); @@ -110,7 +111,7 @@ DropTailQueue::DoEnqueue (Ptr p) return true; } -Ptr +Ptr DropTailQueue::DoDequeue (void) { NS_LOG_FUNCTION (this); @@ -121,19 +122,19 @@ DropTailQueue::DoDequeue (void) return 0; } - Ptr p = m_packets.front (); + Ptr item = m_packets.front (); m_packets.pop (); - m_bytesInQueue -= p->GetSize (); + m_bytesInQueue -= item->GetPacketSize (); - NS_LOG_LOGIC ("Popped " << p); + NS_LOG_LOGIC ("Popped " << item); NS_LOG_LOGIC ("Number packets " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue); - return p; + return item; } -Ptr +Ptr DropTailQueue::DoPeek (void) const { NS_LOG_FUNCTION (this); @@ -144,12 +145,12 @@ DropTailQueue::DoPeek (void) const return 0; } - Ptr p = m_packets.front (); + Ptr item = m_packets.front (); NS_LOG_LOGIC ("Number packets " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue); - return p; + return item; } } // namespace ns3 diff --git a/src/network/utils/drop-tail-queue.h b/src/network/utils/drop-tail-queue.h index d5de0cefe..64457b307 100644 --- a/src/network/utils/drop-tail-queue.h +++ b/src/network/utils/drop-tail-queue.h @@ -64,11 +64,11 @@ public: DropTailQueue::QueueMode GetMode (void) const; private: - virtual bool DoEnqueue (Ptr p); - virtual Ptr DoDequeue (void); - virtual Ptr DoPeek (void) const; + virtual bool DoEnqueue (Ptr item); + virtual Ptr DoDequeue (void); + virtual Ptr DoPeek (void) const; - std::queue > m_packets; //!< the packets in the queue + 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 diff --git a/src/network/utils/queue.cc b/src/network/utils/queue.cc index 2f72b3813..44781cab0 100644 --- a/src/network/utils/queue.cc +++ b/src/network/utils/queue.cc @@ -63,20 +63,20 @@ Queue::~Queue() bool -Queue::Enqueue (Ptr p) +Queue::Enqueue (Ptr item) { - NS_LOG_FUNCTION (this << p); + NS_LOG_FUNCTION (this << item); // // If DoEnqueue fails, Queue::Drop is called by the subclass // - bool retval = DoEnqueue (p); + bool retval = DoEnqueue (item); if (retval) { NS_LOG_LOGIC ("m_traceEnqueue (p)"); - m_traceEnqueue (p); + m_traceEnqueue (item->GetPacket ()); - uint32_t size = p->GetSize (); + uint32_t size = item->GetPacketSize (); m_nBytes += size; m_nTotalReceivedBytes += size; @@ -86,25 +86,26 @@ Queue::Enqueue (Ptr p) return retval; } -Ptr +Ptr Queue::Dequeue (void) { NS_LOG_FUNCTION (this); - Ptr packet = DoDequeue (); + Ptr item = DoDequeue (); - if (packet != 0) + if (item != 0) { - NS_ASSERT (m_nBytes >= packet->GetSize ()); + Ptr packet = item->GetPacket (); + NS_ASSERT (m_nBytes >= item->GetPacketSize ()); NS_ASSERT (m_nPackets > 0); - m_nBytes -= packet->GetSize (); + m_nBytes -= item->GetPacketSize (); m_nPackets--; NS_LOG_LOGIC ("m_traceDequeue (packet)"); m_traceDequeue (packet); } - return packet; + return item; } void @@ -117,7 +118,7 @@ Queue::DequeueAll (void) } } -Ptr +Ptr Queue::Peek (void) const { NS_LOG_FUNCTION (this); diff --git a/src/network/utils/queue.h b/src/network/utils/queue.h index 7f7c8c638..f933a9d36 100644 --- a/src/network/utils/queue.h +++ b/src/network/utils/queue.h @@ -24,11 +24,10 @@ #ifndef QUEUE_H #define QUEUE_H -#include -#include #include "ns3/packet.h" #include "ns3/object.h" #include "ns3/traced-callback.h" +#include "ns3/net-device.h" namespace ns3 { @@ -59,21 +58,21 @@ public: */ bool IsEmpty (void) const; /** - * Place a packet into the rear of the Queue - * \param p packet to enqueue + * Place a queue item into the rear of the Queue + * \param item item to enqueue * \return True if the operation was successful; false otherwise */ - bool Enqueue (Ptr p); + bool Enqueue (Ptr item); /** - * Remove a packet from the front of the Queue - * \return 0 if the operation was not successful; the packet otherwise. + * Remove an item from the front of the Queue + * \return 0 if the operation was not successful; the item otherwise. */ - Ptr Dequeue (void); + Ptr Dequeue (void); /** * Get a copy of the item at the front of the queue without removing it - * \return 0 if the operation was not successful; the packet otherwise. + * \return 0 if the operation was not successful; the item otherwise. */ - Ptr Peek (void) const; + Ptr Peek (void) const; /** * Flush the queue. @@ -156,29 +155,29 @@ public: private: /** - * Push a packet in the queue - * \param p the packet to enqueue + * Push an item in the queue + * \param item the item to enqueue * \return true if success, false if the packet has been dropped. */ - virtual bool DoEnqueue (Ptr p) = 0; + virtual bool DoEnqueue (Ptr item) = 0; /** - * Pull a packet from the queue - * \return the packet. + * Pull an item from the queue + * \return the item. */ - virtual Ptr DoDequeue (void) = 0; + virtual Ptr DoDequeue (void) = 0; /** - * Peek the front packet in the queue - * \return the packet. + * Peek the front item in the queue + * \return the item. */ - virtual Ptr DoPeek (void) const = 0; + virtual Ptr DoPeek (void) const = 0; protected: /** - * \brief Drop a packet - * \param packet packet that was dropped + * \brief Drop a packet + * \param p packet that was dropped * This method is called by subclasses to notify parent (this class) of packet drops. */ - void Drop (Ptr packet); + void Drop (Ptr p); /// Traced callback: fired when a packet is enqueued TracedCallback > m_traceEnqueue; diff --git a/src/network/utils/red-queue.cc b/src/network/utils/red-queue.cc index 6f0993afc..c2c29168e 100644 --- a/src/network/utils/red-queue.cc +++ b/src/network/utils/red-queue.cc @@ -209,9 +209,10 @@ RedQueue::AssignStreams (int64_t stream) } bool -RedQueue::DoEnqueue (Ptr p) +RedQueue::DoEnqueue (Ptr item) { - NS_LOG_FUNCTION (this << p); + NS_LOG_FUNCTION (this << item); + Ptr p = item->GetPacket (); if (!m_hasRedStarted ) { @@ -260,7 +261,7 @@ RedQueue::DoEnqueue (Ptr p) NS_LOG_DEBUG ("\t packetsInQueue " << m_packets.size () << "\tQavg " << m_qAvg); m_count++; - m_countBytes += p->GetSize (); + m_countBytes += item->GetPacketSize (); uint32_t dropType = DTYPE_NONE; if (m_qAvg >= m_minTh && nQueued > 1) @@ -280,7 +281,7 @@ RedQueue::DoEnqueue (Ptr p) * above "minthresh" with a nonempty queue. */ m_count = 1; - m_countBytes = p->GetSize (); + m_countBytes = item->GetPacketSize (); m_old = 1; } else if (DropEarly (p, nQueued)) @@ -323,8 +324,8 @@ RedQueue::DoEnqueue (Ptr p) return false; } - m_bytesInQueue += p->GetSize (); - m_packets.push_back (p); + m_bytesInQueue += item->GetPacketSize (); + m_packets.push_back (item); NS_LOG_LOGIC ("Number packets " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue); @@ -603,7 +604,7 @@ RedQueue::GetQueueSize (void) } } -Ptr +Ptr RedQueue::DoDequeue (void) { NS_LOG_FUNCTION (this); @@ -619,20 +620,20 @@ RedQueue::DoDequeue (void) else { m_idle = 0; - Ptr p = m_packets.front (); + Ptr item = m_packets.front (); m_packets.pop_front (); - m_bytesInQueue -= p->GetSize (); + m_bytesInQueue -= item->GetPacketSize (); - NS_LOG_LOGIC ("Popped " << p); + NS_LOG_LOGIC ("Popped " << item); NS_LOG_LOGIC ("Number packets " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue); - return p; + return item; } } -Ptr +Ptr RedQueue::DoPeek (void) const { NS_LOG_FUNCTION (this); @@ -642,12 +643,12 @@ RedQueue::DoPeek (void) const return 0; } - Ptr p = m_packets.front (); + Ptr item = m_packets.front (); NS_LOG_LOGIC ("Number packets " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue); - return p; + return item; } } // namespace ns3 diff --git a/src/network/utils/red-queue.h b/src/network/utils/red-queue.h index 4e0e92328..15a14307d 100644 --- a/src/network/utils/red-queue.h +++ b/src/network/utils/red-queue.h @@ -177,9 +177,9 @@ public: int64_t AssignStreams (int64_t stream); private: - virtual bool DoEnqueue (Ptr p); - virtual Ptr DoDequeue (void); - virtual Ptr DoPeek (void) const; + virtual bool DoEnqueue (Ptr item); + virtual Ptr DoDequeue (void); + virtual Ptr DoPeek (void) const; /** * \brief Initialize the queue parameters. @@ -233,7 +233,7 @@ private: double ModifyP (double p, uint32_t count, uint32_t countBytes, uint32_t meanPktSize, bool wait, uint32_t size); - std::list > m_packets; //!< packets in the queue + std::list > m_packets; //!< packets in the queue uint32_t m_bytesInQueue; //!< bytes in the queue bool m_hasRedStarted; //!< True if RED has started diff --git a/src/network/utils/simple-net-device.cc b/src/network/utils/simple-net-device.cc index 3633e5acc..e227efda8 100644 --- a/src/network/utils/simple-net-device.cc +++ b/src/network/utils/simple-net-device.cc @@ -444,11 +444,11 @@ SimpleNetDevice::SendFrom (Ptr p, const Address& source, const Address& p->AddPacketTag (tag); - if (m_queue->Enqueue (p)) + if (m_queue->Enqueue (Create (p))) { if (m_queue->GetNPackets () == 1 && !TransmitCompleteEvent.IsRunning ()) { - p = m_queue->Dequeue (); + p = m_queue->Dequeue ()->GetPacket (); p->RemovePacketTag (tag); Time txTime = Time (0); if (m_bps > DataRate (0)) @@ -477,7 +477,7 @@ SimpleNetDevice::TransmitComplete () return; } - Ptr packet = m_queue->Dequeue (); + Ptr packet = m_queue->Dequeue ()->GetPacket (); SimpleTag tag; packet->RemovePacketTag (tag); diff --git a/src/point-to-point/model/point-to-point-net-device.cc b/src/point-to-point/model/point-to-point-net-device.cc index b941bdf7e..bfa31fff6 100644 --- a/src/point-to-point/model/point-to-point-net-device.cc +++ b/src/point-to-point/model/point-to-point-net-device.cc @@ -280,8 +280,8 @@ PointToPointNetDevice::TransmitComplete (void) m_phyTxEndTrace (m_currentPkt); m_currentPkt = 0; - Ptr p = m_queue->Dequeue (); - if (p == 0) + Ptr item = m_queue->Dequeue (); + if (item == 0) { // // No packet was on the queue, so we just exit. @@ -292,6 +292,7 @@ PointToPointNetDevice::TransmitComplete (void) // // Got another packet off of the queue, so start the transmit process agin. // + Ptr p = item->GetPacket (); m_snifferTrace (p); m_promiscSnifferTrace (p); TransmitStart (p); @@ -535,14 +536,14 @@ PointToPointNetDevice::Send ( // // We should enqueue and dequeue the packet to hit the tracing hooks. // - if (m_queue->Enqueue (packet)) + if (m_queue->Enqueue (Create (packet))) { // // If the channel is ready for transition we send the packet right now // if (m_txMachineState == READY) { - packet = m_queue->Dequeue (); + packet = m_queue->Dequeue ()->GetPacket (); m_snifferTrace (packet); m_promiscSnifferTrace (packet); return TransmitStart (packet); diff --git a/src/spectrum/model/aloha-noack-net-device.cc b/src/spectrum/model/aloha-noack-net-device.cc index 68fb30a0f..dba6eb766 100644 --- a/src/spectrum/model/aloha-noack-net-device.cc +++ b/src/spectrum/model/aloha-noack-net-device.cc @@ -378,7 +378,7 @@ AlohaNoackNetDevice::SendFrom (Ptr packet, const Address& src, const Add else { NS_LOG_LOGIC ("enqueueing new packet"); - if (m_queue->Enqueue (packet) == false) + if (m_queue->Enqueue (Create (packet)) == false) { m_macTxDropTrace (packet); sendOk = false; @@ -389,7 +389,7 @@ AlohaNoackNetDevice::SendFrom (Ptr packet, const Address& src, const Add { NS_LOG_LOGIC ("deferring TX, enqueueing new packet"); NS_ASSERT (m_queue); - if (m_queue->Enqueue (packet) == false) + if (m_queue->Enqueue (Create (packet)) == false) { m_macTxDropTrace (packet); sendOk = false; @@ -434,8 +434,9 @@ AlohaNoackNetDevice::NotifyTransmissionEnd (Ptr) NS_ASSERT (m_queue); if (m_queue->IsEmpty () == false) { - m_currentPkt = m_queue->Dequeue (); - NS_ASSERT (m_currentPkt); + Ptr item = m_queue->Dequeue (); + NS_ASSERT (item); + m_currentPkt = item->GetPacket (); NS_LOG_LOGIC ("scheduling transmission now"); Simulator::ScheduleNow (&AlohaNoackNetDevice::StartTransmission, this); }