From 5cb92847c4c858a70ebedbdcf6bb27a953dc0bdd Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 19:15:28 +0200 Subject: [PATCH] make Queue derive from Interface --- src/devices/p2p/p2p-net-device.cc | 8 +++----- src/devices/p2p/p2p-net-device.h | 6 +++--- src/devices/p2p/p2p-topology.cc | 14 ++++++++------ src/node/queue.cc | 3 +++ src/node/queue.h | 5 ++++- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/devices/p2p/p2p-net-device.cc b/src/devices/p2p/p2p-net-device.cc index 6fb6edac9..9542d951b 100644 --- a/src/devices/p2p/p2p-net-device.cc +++ b/src/devices/p2p/p2p-net-device.cc @@ -55,8 +55,6 @@ PointToPointNetDevice::PointToPointNetDevice (Ptr node) PointToPointNetDevice::~PointToPointNetDevice() { NS_DEBUG ("PointToPointNetDevice::~PointToPointNetDevice ()"); - - delete m_queue; m_queue = 0; } @@ -286,7 +284,7 @@ PointToPointNetDevice::DoCreateTraceResolver (TraceContext const &context) { CompositeTraceResolver *resolver = new CompositeTraceResolver (context); resolver->Add ("queue", - MakeCallback (&Queue::CreateTraceResolver, m_queue), + MakeCallback (&Queue::CreateTraceResolver, PeekPointer (m_queue)), PointToPointNetDevice::QUEUE); resolver->Add ("rx", m_rxTrace, @@ -318,7 +316,7 @@ PointToPointNetDevice::Attach (Ptr ch) } void -PointToPointNetDevice::AddQueue (Queue* q) +PointToPointNetDevice::AddQueue (Ptr q) { NS_DEBUG ("PointToPointNetDevice::AddQueue (" << q << ")"); @@ -335,7 +333,7 @@ PointToPointNetDevice::Receive (Packet& p) ForwardUp (p); } -Queue* +Ptr PointToPointNetDevice::GetQueue(void) const { return m_queue; diff --git a/src/devices/p2p/p2p-net-device.h b/src/devices/p2p/p2p-net-device.h index fc4ece354..e1eb8a666 100644 --- a/src/devices/p2p/p2p-net-device.h +++ b/src/devices/p2p/p2p-net-device.h @@ -155,7 +155,7 @@ public: * @param queue a pointer to the queue for which object is assuming * ownership. */ - void AddQueue(Queue* queue); + void AddQueue(Ptr queue); /** * Receive a packet from a connected PointToPointChannel. * @@ -179,7 +179,7 @@ protected: * @see PointToPointTopology * @returns a pointer to the queue. */ - Queue* GetQueue(void) const; + Ptr GetQueue(void) const; /** * Get a copy of the attached Channel * @@ -296,7 +296,7 @@ private: * @see class Queue * @see class DropTailQueue */ - Queue* m_queue; + Ptr m_queue; /** * The trace source for the packet reception events that the device can * fire. diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index 730c7e74f..95a681d02 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -49,13 +49,15 @@ PointToPointTopology::AddPointToPointLink( Ptr net1 = MakeNewObject (n1); - net1->AddQueue(Queue::Default().Copy()); + Ptr q = MakeNewObject (); + net1->AddQueue(q); n1->AddDevice (net1); net1->Attach (channel); Ptr net2 = MakeNewObject (n2); - net2->AddQueue(Queue::Default().Copy()); + q = MakeNewObject (); + net2->AddQueue(q); n2->AddDevice (net2); net2->Attach (channel); @@ -137,14 +139,14 @@ Ptr PointToPointTopology::GetChannel( return nd->GetChannel(); } -Queue* PointToPointTopology::GetQueue(Ptr n1, Ptr n2) +Ptr PointToPointTopology::GetQueue(Ptr n1, Ptr n2) { Ptr nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, so in queue return nd->GetQueue(); } -Queue* PointToPointTopology::SetQueue(Ptr n1, Ptr n2, const Queue& q) +void PointToPointTopology::SetQueue(Ptr n1, Ptr n2, Ptr q) { Ptr nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, can't set queue @@ -190,14 +192,14 @@ Ptr Topology::GetChannel(Ptr n1, Ptr n2) return nd->GetChannel(); } -Queue* Topology::GetQueue(Ptr n1, Ptr n2) +Ptr Topology::GetQueue(Ptr n1, Ptr n2) { Ptr nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, so in queue return nd->GetQueue(); } -Queue* Topology::SetQueue(Ptr n1, Ptr n2, const Queue& q) +void Topology::SetQueue(Ptr n1, Ptr n2, Ptr q) { Ptr nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, can't set queue diff --git a/src/node/queue.cc b/src/node/queue.cc index ac4fcdff8..5b3d808bf 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -26,9 +26,12 @@ NS_DEBUG_COMPONENT_DEFINE ("Queue"); namespace ns3 { +const InterfaceId Queue::iid ("Queue"); + Queue* Queue::defaultQueue = 0; Queue::Queue() : + Interface (Queue::iid), m_nBytes(0), m_nTotalReceivedBytes(0), m_nPackets(0), diff --git a/src/node/queue.h b/src/node/queue.h index 9119832a9..7d96a6c5e 100644 --- a/src/node/queue.h +++ b/src/node/queue.h @@ -28,6 +28,7 @@ #include #include #include "ns3/packet.h" +#include "ns3/interface.h" #include "ns3/callback-trace-source.h" #include "ns3/trace-resolver.h" @@ -35,9 +36,11 @@ namespace ns3 { class StringEnumDefaultValue; -class Queue +class Queue : public Interface { public: + static const InterfaceId iid; + enum TraceType { ENQUEUE, DEQUEUE,