diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index 4cd3a39d8..5410c7606 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -209,9 +209,17 @@ int main (int argc, char *argv[]) DebugComponentEnable("PointToPointNetDevice"); DebugComponentEnable("PointToPointPhy"); #endif - ObjectContainer container; + // Optionally, specify some default values for Queue objects. + // For this example, we specify that we want each queue to + // be a DropTail queue, with a limit of 30 packets. + // Specify DropTail for default queue type (note. this is actually + // the default, but included here as an example). + Queue::Default(DropTailQueue()); + // Specify limit of 30 in units of packets. + // Queue::Default().SetLimitPackets(30); + // The node factory is designed to allow user specification // of the "type" of node desired for each node creation. This // is done by creating a node object (the inNode below), configuring diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index 0ca2dd5b8..327eacae9 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -57,10 +57,8 @@ PointToPointTopology::AddPointToPointLink( Ipv4Mask netmask("255.255.255.252"); NS_ASSERT (netmask.IsMatch(addra,addrb)); - DropTailQueue* dtqa = new DropTailQueue(); - PointToPointNetDevice* neta = new PointToPointNetDevice(a); - neta->AddQueue(dtqa); + neta->AddQueue(Queue::Default().Copy()); Ipv4Interface *interfA = new ArpIpv4Interface (a, neta); uint32_t indexA = a->GetIpv4 ()->AddInterface (interfA); neta->Attach (channel); @@ -69,10 +67,8 @@ PointToPointTopology::AddPointToPointLink( interfA->SetNetworkMask (netmask); interfA->SetUp (); - DropTailQueue* dtqb = new DropTailQueue(); - PointToPointNetDevice* netb = new PointToPointNetDevice(b); - netb->AddQueue(dtqb); + netb->AddQueue(Queue::Default().Copy()); Ipv4Interface *interfB = new ArpIpv4Interface (b, netb); uint32_t indexB = b->GetIpv4 ()->AddInterface (interfB); netb->Attach (channel); diff --git a/src/node/drop-tail.cc b/src/node/drop-tail.cc index c3dc4f79f..b65c4d828 100644 --- a/src/node/drop-tail.cc +++ b/src/node/drop-tail.cc @@ -24,6 +24,14 @@ NS_DEBUG_COMPONENT_DEFINE ("DropTailQueue"); namespace ns3 { +static class QueueStackInitializationClass { +public: + QueueStackInitializationClass () { + Queue::Default (DropTailQueue ()); + } +} queue_stack_initialization_class; + + DropTailQueue::DropTailQueue () : Queue (), m_packets (), @@ -37,6 +45,11 @@ DropTailQueue::~DropTailQueue () NS_DEBUG("DropTailQueue::~DropTailQueue ()"); } +DropTailQueue* DropTailQueue::Copy() const +{ + return new DropTailQueue(*this); +} + void DropTailQueue::SetMaxPackets (uint32_t npackets) { diff --git a/src/node/drop-tail.h b/src/node/drop-tail.h index 8ac8ab47a..da3749833 100644 --- a/src/node/drop-tail.h +++ b/src/node/drop-tail.h @@ -35,6 +35,7 @@ public: DropTailQueue (); virtual ~DropTailQueue(); + virtual DropTailQueue* Copy() const; void SetMaxPackets (uint32_t npackets); uint32_t GetMaxPackets (void); diff --git a/src/node/queue.cc b/src/node/queue.cc index 26ba3bbe8..5567f9041 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -25,6 +25,8 @@ NS_DEBUG_COMPONENT_DEFINE ("Queue"); namespace ns3 { +Queue* Queue::defaultQueue = 0; + Queue::Queue() : m_nBytes(0), m_nTotalReceivedBytes(0), @@ -182,4 +184,20 @@ Queue::Drop (const Packet& p) m_traceDrop (p); } +// Static methods for managing default queue + +// Set new default +void Queue::Default(const Queue& q) +{ + delete defaultQueue; // delete previous (if any) + defaultQueue = q.Copy(); // set new default +} + +// Get current default +Queue& Queue::Default() +{ + // ! Need to schedule an "at end" event to delete the default + return *defaultQueue; +} + }; // namespace ns3 diff --git a/src/node/queue.h b/src/node/queue.h index 799c682ff..ba7cd6e62 100644 --- a/src/node/queue.h +++ b/src/node/queue.h @@ -43,6 +43,8 @@ public: Queue (); virtual ~Queue (); + virtual Queue* Copy() const = 0; + TraceResolver *CreateTraceResolver (TraceContext const &context); bool IsEmpty (void); @@ -104,7 +106,7 @@ private: uint32_t m_nTotalDroppedBytes; uint32_t m_nTotalDroppedPackets; -#if 0 +public: // Static methods to manage queue default // Set desired queue default static void Default(const Queue& q); @@ -112,7 +114,6 @@ private: static Queue& Default(); // Static variable pointing to current default queue static Queue* defaultQueue; -#endif }; }; // namespace ns3