From 4e32c8f56e6f4c18cdfe147516d863bf0bbc8c6e Mon Sep 17 00:00:00 2001 From: Raj Bhattacharjea Date: Tue, 8 May 2007 11:44:04 -0400 Subject: [PATCH 01/59] Ptr changed to use Object's refcounts --- samples/main-ptr.cc | 3 ++- src/core/ptr.cc | 3 ++- src/core/ptr.h | 62 ++++++++------------------------------------- 3 files changed, 15 insertions(+), 53 deletions(-) diff --git a/samples/main-ptr.cc b/samples/main-ptr.cc index aa350f040..3dc2fb246 100644 --- a/samples/main-ptr.cc +++ b/samples/main-ptr.cc @@ -1,10 +1,11 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ #include "ns3/ptr.h" +#include "ns3/object.h" #include using namespace ns3; -class A +class A : public Object { public: A (); diff --git a/src/core/ptr.cc b/src/core/ptr.cc index a9ba89970..28608f62b 100644 --- a/src/core/ptr.cc +++ b/src/core/ptr.cc @@ -24,10 +24,11 @@ #include "test.h" #include "callback.h" +#include "object.h" namespace ns3 { -class NoCount +class NoCount : public Object { public: NoCount (Callback cb); diff --git a/src/core/ptr.h b/src/core/ptr.h index 889e0386e..ce49f3a4b 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -46,13 +46,10 @@ class Ptr { private: T *m_ptr; - uint32_t *m_count; class Tester { private: void operator delete (void *); }; - static uint32_t *AllocCount (void); - static void DeallocCount (uint32_t *count); friend class Ptr; public: /** @@ -115,59 +112,34 @@ public: T *Remove (void); }; -template -uint32_t * -Ptr::AllocCount (void) -{ - return new uint32_t [1] (); -} -template -void -Ptr::DeallocCount (uint32_t *count) -{ - delete [] count; -} - template Ptr::Ptr () - : m_ptr (0), - m_count (0) + : m_ptr (0) {} template Ptr::Ptr (T *ptr) - : m_ptr (ptr), - m_count (0) -{ - if (m_ptr != 0) - { - m_count = Ptr::AllocCount (); - *m_count = 1; - } -} + : m_ptr (ptr) +{} template Ptr::Ptr (Ptr const&o) - : m_ptr (o.m_ptr), - m_count (0) + : m_ptr (o.m_ptr) { if (m_ptr != 0) { - m_count = o.m_count; - (*m_count)++; + m_ptr->Ref(); } } template template Ptr::Ptr (Ptr const &o) - : m_ptr (o.m_ptr), - m_count (0) + : m_ptr (o.m_ptr) { if (m_ptr != 0) { NS_ASSERT (o.m_ptr != 0); - m_count = o.m_count; - (*m_count)++; + m_ptr->Ref(); } } @@ -176,12 +148,7 @@ Ptr::~Ptr () { if (m_ptr != 0) { - (*m_count)--; - if ((*m_count) == 0) - { - delete m_ptr; - Ptr::DeallocCount (m_count); - } + m_ptr->Unref(); } } @@ -193,18 +160,12 @@ Ptr::operator = (Ptr const& o) return *this; if (m_ptr != 0) { - (*m_count)--; - if ((*m_count) == 0) - { - delete m_ptr; - Ptr::DeallocCount (m_count); - } + m_ptr->Unref(); } m_ptr = o.m_ptr; if (m_ptr != 0) { - m_count = o.m_count; - (*m_count)++; + m_ptr->Ref(); } return *this; } @@ -258,8 +219,7 @@ Ptr::Remove (void) } else { - NS_ASSERT ((*m_count) == 1); - Ptr::DeallocCount (m_count); + NS_ASSERT (m_ptr->IsSingle()); T *retval = m_ptr; m_ptr = 0; return retval; From ecfcfa977d4413ae36e319024413daa2e2c26462 Mon Sep 17 00:00:00 2001 From: Raj Bhattacharjea Date: Wed, 9 May 2007 13:26:21 -0400 Subject: [PATCH 02/59] Node* -> Ptr --- examples/simple-p2p.cc | 9 +++++---- src/applications/application-list.cc | 6 +++--- src/applications/application-list.h | 6 +++--- src/applications/application.cc | 6 +++--- src/applications/application.h | 10 ++++++---- src/applications/onoff-application.cc | 4 ++-- src/applications/onoff-application.h | 5 +++-- src/core/ptr.cc | 4 ++-- src/core/ptr.h | 15 +++++++++++--- src/devices/p2p/p2p-net-device.cc | 2 +- src/devices/p2p/p2p-net-device.h | 3 ++- src/devices/p2p/p2p-topology.cc | 28 +++++++++++++-------------- src/devices/p2p/p2p-topology.h | 16 +++++++-------- src/node/net-device.cc | 4 ++-- src/node/net-device.h | 7 ++++--- 15 files changed, 70 insertions(+), 55 deletions(-) diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index fb4f91311..2ec17cf80 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -45,6 +45,7 @@ #include "ns3/debug.h" #include "ns3/command-line.h" #include "ns3/default-value.h" +#include "ns3/ptr.h" #include "ns3/simulator.h" #include "ns3/nstime.h" @@ -100,10 +101,10 @@ int main (int argc, char *argv[]) // Here, we will explicitly create four nodes. In more sophisticated // topologies, we could configure a node factory. - Node* n0 = new InternetNode (); - Node* n1 = new InternetNode (); - Node* n2 = new InternetNode (); - Node* n3 = new InternetNode (); + Ptr n0 = new InternetNode (); + Ptr n1 = new InternetNode (); + Ptr n2 = new InternetNode (); + Ptr n3 = new InternetNode (); // We create the channels first without any IP addressing information PointToPointChannel *channel0 = diff --git a/src/applications/application-list.cc b/src/applications/application-list.cc index 068b29581..1c9059c8b 100644 --- a/src/applications/application-list.cc +++ b/src/applications/application-list.cc @@ -28,7 +28,7 @@ namespace ns3{ const Iid ApplicationList::iid ("ApplicationList"); -ApplicationList::ApplicationList(Node* n) +ApplicationList::ApplicationList(Ptr n) : NsUnknown (ApplicationList::iid) {} @@ -49,7 +49,7 @@ ApplicationList::DoDispose (void) ApplicationList::~ApplicationList() {} -ApplicationList* ApplicationList::Copy(Node * n) const +ApplicationList* ApplicationList::Copy(Ptr n) const { // Copy this app list ApplicationList* r = new ApplicationList(n); return r; @@ -62,7 +62,7 @@ ApplicationList::Add(Application* a) m_apps.push_back(a); } -void ApplicationList::SetNode(Node * n) +void ApplicationList::SetNode(Ptr n) { // Set the node pointer in each application for (std::vector::const_iterator i = m_apps.begin(); diff --git a/src/applications/application-list.h b/src/applications/application-list.h index 4e37f5aa0..8a30b2de5 100644 --- a/src/applications/application-list.h +++ b/src/applications/application-list.h @@ -34,12 +34,12 @@ class ApplicationList : public NsUnknown { public: static const Iid iid; - ApplicationList(Node*); + ApplicationList(Ptr); // Copy constructor not needed, default one is correct virtual ~ApplicationList(); // Inherited from Capabilty - virtual ApplicationList* Copy(Node*) const; - virtual void SetNode(Node *); // Sets the node for all apps + virtual ApplicationList* Copy(Ptr) const; + virtual void SetNode(Ptr); // Sets the node for all apps virtual void Add(Application*); // Add an already new'ed app // Manage the list template T* AddCopy(const T& t) // Add a new application diff --git a/src/applications/application.cc b/src/applications/application.cc index c44075b27..9379c87e4 100644 --- a/src/applications/application.cc +++ b/src/applications/application.cc @@ -34,7 +34,7 @@ namespace ns3 { // Application Methods // \brief Application Constructor -Application::Application(Node * n) +Application::Application(Ptr n) : m_node (n), m_startVar(0), m_stopVar(0), m_start(false), m_stop(false) @@ -147,7 +147,7 @@ void Application::Stop(const RandomVariable& stopVar) // \brief Assign this application to a given node // Called by the application manager capability when adding // an application to a node. -void Application::SetNode(Node * n) +void Application::SetNode(Ptr n) { if (m_node != 0) { @@ -157,7 +157,7 @@ void Application::SetNode(Node * n) m_node->Ref (); } -Node* Application::PeekNode() const +Ptr Application::PeekNode() const { return m_node; } diff --git a/src/applications/application.h b/src/applications/application.h index 9d6c4cb4d..a85bfbf40 100644 --- a/src/applications/application.h +++ b/src/applications/application.h @@ -50,6 +50,8 @@ #include "ns3/event-id.h" #include "ns3/nstime.h" #include "ns3/object.h" +#include "ns3/ptr.h" +#include "ns3/node.h" namespace ns3 { @@ -59,7 +61,7 @@ class RandomVariable; class Application : public Object { public: - Application(Node *); + Application(Ptr); Application(const Application&); // Copy constructor Application& operator=(const Application&); // Assignment operator virtual ~Application(); @@ -100,13 +102,13 @@ void Start(const RandomVariable&); // \brief Attaches an application to a specific node // Specifies which node object this application is associated with. // \param Node object to associate with this application. - void SetNode(Node *); + void SetNode(Ptr); // \brief Returns the pointer to the attached node. - Node* PeekNode() const; + Ptr PeekNode() const; // Members - Node * m_node; // All applications have an associated node + Ptr m_node; // All applications have an associated node RandomVariable* m_startVar; // Random variable for start time RandomVariable* m_stopVar; // Random variable for stop time EventId m_startEvent;// Event identifier for start event diff --git a/src/applications/onoff-application.cc b/src/applications/onoff-application.cc index 7682faa4b..ac74ef13e 100644 --- a/src/applications/onoff-application.cc +++ b/src/applications/onoff-application.cc @@ -42,7 +42,7 @@ uint32_t OnOffApplication::g_defaultSize = 512; // Constructors - OnOffApplication::OnOffApplication(Node * n, + OnOffApplication::OnOffApplication(Ptr n, const Ipv4Address rip, // Remote IP addr uint16_t rport, // Remote port const RandomVariable& ontime, @@ -67,7 +67,7 @@ uint32_t OnOffApplication::g_defaultSize = 512; { } -OnOffApplication::OnOffApplication(Node * n, const OnOffApplication& c) +OnOffApplication::OnOffApplication(Ptr n, const OnOffApplication& c) : Application(n), m_socket(0), m_peerIP(c.m_peerIP), diff --git a/src/applications/onoff-application.h b/src/applications/onoff-application.h index b259f7682..ff19e7458 100644 --- a/src/applications/onoff-application.h +++ b/src/applications/onoff-application.h @@ -29,6 +29,7 @@ #include "application.h" #include "ns3/event-id.h" +#include "ns3/ptr.h" namespace ns3 { @@ -40,7 +41,7 @@ class DataRate; class OnOffApplication : public Application { public: - OnOffApplication(Node * n, + OnOffApplication(Ptr n, const Ipv4Address, // Peer IP address uint16_t, // Peer port const RandomVariable&, // Random variable for On time @@ -48,7 +49,7 @@ public: DataRate = g_defaultRate, // Data rate when on uint32_t = g_defaultSize); // Size of packets - OnOffApplication(Node * n, const OnOffApplication&); // Copy constructor + OnOffApplication(Ptr n, const OnOffApplication&); // Copy constructor virtual ~OnOffApplication(); // Destructor virtual void StartApplication(); // Called at time specified by Start virtual void StopApplication(); // Called at time specified by Stop diff --git a/src/core/ptr.cc b/src/core/ptr.cc index 28608f62b..a0d37633c 100644 --- a/src/core/ptr.cc +++ b/src/core/ptr.cc @@ -254,8 +254,8 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p = new NoCount (cb); - NoCount const&v1 = *p; - NoCount v2 = *p; + NoCount const&v1 = p.Peek(); + NoCount v2 = p.Peek(); v1.Nothing (); v2.Nothing (); } diff --git a/src/core/ptr.h b/src/core/ptr.h index ce49f3a4b..7af3440bd 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -72,7 +72,8 @@ public: Ptr (Ptr const &o); ~Ptr () ; Ptr &operator = (Ptr const& o); - T const& operator * () const; + T const& Peek () const; + T * Get () const; T *operator -> () const; T *operator -> (); // allow if (!sp) @@ -172,11 +173,19 @@ Ptr::operator = (Ptr const& o) template T const& -Ptr::operator * () const +Ptr::Peek () const { return *m_ptr; } +template +T * +Ptr::Get () const +{ + m_ptr->Ref(); + return m_ptr; +} + template T * Ptr::operator -> () @@ -219,7 +228,7 @@ Ptr::Remove (void) } else { - NS_ASSERT (m_ptr->IsSingle()); + //NS_ASSERT (m_ptr->IsSingle()); T *retval = m_ptr; m_ptr = 0; return retval; diff --git a/src/devices/p2p/p2p-net-device.cc b/src/devices/p2p/p2p-net-device.cc index ae322c4fa..06d8fb269 100644 --- a/src/devices/p2p/p2p-net-device.cc +++ b/src/devices/p2p/p2p-net-device.cc @@ -32,7 +32,7 @@ NS_DEBUG_COMPONENT_DEFINE ("PointToPointNetDevice"); namespace ns3 { -PointToPointNetDevice::PointToPointNetDevice (Node* node) +PointToPointNetDevice::PointToPointNetDevice (Ptr node) : NetDevice(node, MacAddress ("00:00:00:00:00:00")), m_txMachineState (READY), diff --git a/src/devices/p2p/p2p-net-device.h b/src/devices/p2p/p2p-net-device.h index 2826f6f1b..2d27921c4 100644 --- a/src/devices/p2p/p2p-net-device.h +++ b/src/devices/p2p/p2p-net-device.h @@ -30,6 +30,7 @@ #include "ns3/callback-trace-source.h" #include "ns3/nstime.h" #include "ns3/data-rate.h" +#include "ns3/ptr.h" namespace ns3 { @@ -79,7 +80,7 @@ public: * @see PointToPointTopology::AddPointToPointLink () * @param node the Node to which this device is connected. */ - PointToPointNetDevice (Node* node); + PointToPointNetDevice (Ptr node); /** * Copy Construct a PointToPointNetDevice * diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index 6ff05eab9..ff4f9e3bf 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -40,8 +40,8 @@ namespace ns3 { PointToPointChannel * PointToPointTopology::AddPointToPointLink( - Node* n1, - Node* n2, + Ptr n1, + Ptr n2, const DataRate& bps, const Time& delay) { @@ -65,8 +65,8 @@ PointToPointTopology::AddPointToPointLink( bool PointToPointTopology::AddIpv4Addresses( const PointToPointChannel *chan, - Node* n1, const Ipv4Address& addr1, - Node* n2, const Ipv4Address& addr2) + Ptr n1, const Ipv4Address& addr1, + Ptr n2, const Ipv4Address& addr2) { // Duplex link is assumed to be subnetted as a /30 @@ -116,7 +116,7 @@ PointToPointTopology::AddIpv4Addresses( // there are possibly multiple devices connecting n1 and n2 (for example // wireless with two devices on different channels) this will return // the first one found. -PointToPointNetDevice* PointToPointTopology::GetNetDevice(Node* n1, Node* n2) +PointToPointNetDevice* PointToPointTopology::GetNetDevice(Ptr n1, Ptr n2) { // First get the NetDeviceList capability from node 1 NetDeviceList* ndl1 = n1->GetNetDeviceList(); @@ -136,8 +136,8 @@ PointToPointNetDevice* PointToPointTopology::GetNetDevice(Node* n1, Node* n2) // Get the channel connecting node n1 to node n2 PointToPointChannel* PointToPointTopology::GetChannel( - Node* n1, - Node* n2 + Ptr n1, + Ptr n2 ) { NetDevice* nd = GetNetDevice(n1, n2); @@ -145,14 +145,14 @@ PointToPointChannel* PointToPointTopology::GetChannel( return nd->GetChannel(); } -Queue* PointToPointTopology::GetQueue(Node* n1, Node* n2) +Queue* PointToPointTopology::GetQueue(Ptr n1, Ptr n2) { NetDevice* nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, so in queue return nd->GetQueue(); } -Queue* PointToPointTopology::SetQueue(Node* n1, Node* n2, const Queue& q) +Queue* PointToPointTopology::SetQueue(Ptr n1, Ptr n2, const Queue& q) { NetDevice* nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, can't set queue @@ -163,8 +163,8 @@ Queue* PointToPointTopology::SetQueue(Node* n1, Node* n2, const Queue& q) #endif #ifdef GFR -P2PChannel* Topology::AddDuplexLink(Node* n1, const IPAddr& ip1, - Node* n2, const IPAddr& ip2, +P2PChannel* Topology::AddDuplexLink(Ptr n1, const IPAddr& ip1, + Ptr n2, const IPAddr& ip2, const Rate& rate, const Time& delay) { // First get the NetDeviceList capability from each node @@ -195,21 +195,21 @@ P2PChannel* Topology::AddDuplexLink(Node* n1, const IPAddr& ip1, } // Get the channel connecting node n1 to node n2 -Channel* Topology::GetChannel(Node* n1, Node* n2) +Channel* Topology::GetChannel(Ptr n1, Ptr n2) { NetDevice* nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, so no channel return nd->GetChannel(); } -Queue* Topology::GetQueue(Node* n1, Node* n2) +Queue* Topology::GetQueue(Ptr n1, Ptr n2) { NetDevice* nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, so in queue return nd->GetQueue(); } -Queue* Topology::SetQueue(Node* n1, Node* n2, const Queue& q) +Queue* Topology::SetQueue(Ptr n1, Ptr n2, const Queue& q) { NetDevice* nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, can't set queue diff --git a/src/devices/p2p/p2p-topology.h b/src/devices/p2p/p2p-topology.h index dc8cbb88d..ac43f1918 100644 --- a/src/devices/p2p/p2p-topology.h +++ b/src/devices/p2p/p2p-topology.h @@ -19,7 +19,7 @@ // // Topology helper for ns3. // George F. Riley, Georgia Tech, Spring 2007 - +#include "ns3/ptr.h" #ifndef __POINT_TO_POINT_TOPOLOGY_H__ #define __POINT_TO_POINT_TOPOLOGY_H__ @@ -51,29 +51,29 @@ public: * and propagation delay. */ static PointToPointChannel* AddPointToPointLink( - Node*, Node*, const DataRate&, const Time&); + Ptr, Ptr, const DataRate&, const Time&); static bool AddIpv4Addresses( const PointToPointChannel*, - Node*, const Ipv4Address&, - Node*, const Ipv4Address&); + Ptr, const Ipv4Address&, + Ptr, const Ipv4Address&); /** * Get the connecting node n1 to node n2 */ - static PointToPointChannel* GetChannel(Node*, Node*); + static PointToPointChannel* GetChannel(Ptr, Ptr); /** * Get the NetDevice connecting node n1 to n2 */ - static PointToPointNetDevice* GetNetDevice(Node*, Node*); + static PointToPointNetDevice* GetNetDevice(Ptr, Ptr); /** * Get the queue associated with a link between two nodes */ - static Queue* GetQueue(Node*, Node*); + static Queue* GetQueue(Ptr, Ptr); /** * Set the queue associated with a link between two nodes */ - static Queue* SetQueue(Node*, Node*, const Queue&); + static Queue* SetQueue(Ptr, Ptr, const Queue&); }; } // namespace ns3 diff --git a/src/node/net-device.cc b/src/node/net-device.cc index 40ecc59ae..401fb2a52 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -29,7 +29,7 @@ namespace ns3 { -NetDevice::NetDevice(Node *node, const MacAddress& addr) : +NetDevice::NetDevice(Ptr node, const MacAddress& addr) : m_node (node), m_name(""), m_ifIndex (0), @@ -228,7 +228,7 @@ NetDevice::NotifyLinkDown (void) } } -Node * +Ptr NetDevice::PeekNode (void) const { return m_node; diff --git a/src/node/net-device.h b/src/node/net-device.h index cfb4a40e9..a0414ee7d 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -27,6 +27,7 @@ #include "ns3/packet.h" #include "ns3/object.h" #include "mac-address.h" +#include "ns3/ptr.h" namespace ns3 { @@ -61,7 +62,7 @@ public: * \param node base class node pointer of device's node * \param addr MAC address of this device. */ - NetDevice(Node* node, const MacAddress& addr); + NetDevice(Ptr node, const MacAddress& addr); virtual ~NetDevice(); /** @@ -169,7 +170,7 @@ public: * base class to print the nodeid for example, it can invoke * this method. */ - Node* PeekNode (void) const; + Ptr PeekNode (void) const; bool NeedsArp (void) const; @@ -241,7 +242,7 @@ public: virtual bool DoNeedsArp (void) const = 0; virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0; virtual Channel *DoGetChannel (void) const = 0; - Node* m_node; + Ptr m_node; std::string m_name; uint16_t m_ifIndex; MacAddress m_address; From de3b9c78f3c695861b9b5f8916dc522e60914923 Mon Sep 17 00:00:00 2001 From: Raj Bhattacharjea Date: Wed, 9 May 2007 14:50:14 -0400 Subject: [PATCH 03/59] Removed manual ref/unref calls for Ptr --- examples/simple-p2p.cc | 10 +++++----- src/applications/application.cc | 11 ----------- src/node/net-device.cc | 2 -- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index 2ec17cf80..43dfb5303 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -184,11 +184,11 @@ int main (int argc, char *argv[]) ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1); ipv4->Unref (); - n0->Unref (); - n1->Unref (); - n2->Unref (); - n3->Unref (); - + n0 = 0; + n1 = 0; + n2 = 0; + n3 = 0; + // Configure tracing of all enqueue, dequeue, and NetDevice receive events // Trace output will be sent to the simple-p2p.tr file AsciiTrace asciitrace ("simple-p2p.tr"); diff --git a/src/applications/application.cc b/src/applications/application.cc index 9379c87e4..6c62fe5ba 100644 --- a/src/applications/application.cc +++ b/src/applications/application.cc @@ -39,7 +39,6 @@ Application::Application(Ptr n) m_startVar(0), m_stopVar(0), m_start(false), m_stop(false) { - m_node->Ref (); } Application::Application(const Application& o) @@ -47,7 +46,6 @@ Application::Application(const Application& o) m_start(false), m_stop(false) { // Copy constructor m_node = o.m_node; - m_node->Ref (); // Copy the start and stop random variables if they exist if (o.m_startVar) m_startVar = o.m_startVar->Copy(); if (o.m_stopVar) m_stopVar = o.m_stopVar->Copy(); @@ -65,7 +63,6 @@ Application::DoDispose (void) { if (m_node != 0) { - m_node->Unref (); m_node = 0; } if (m_start) @@ -87,10 +84,7 @@ Application::DoDispose (void) Application& Application::operator=(const Application& rhs) { if (this == &rhs) return *this; // Self assignment - m_node->Unref (); - m_node = 0; m_node = rhs.m_node; - m_node->Ref (); delete m_startVar; m_startVar = 0; @@ -149,12 +143,7 @@ void Application::Stop(const RandomVariable& stopVar) // an application to a node. void Application::SetNode(Ptr n) { - if (m_node != 0) - { - m_node->Unref (); - } m_node = n; - m_node->Ref (); } Ptr Application::PeekNode() const diff --git a/src/node/net-device.cc b/src/node/net-device.cc index 401fb2a52..1f626d0f5 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -40,12 +40,10 @@ NetDevice::NetDevice(Ptr node, const MacAddress& addr) : m_isMulticast (false), m_isPointToPoint (false) { - m_node->Ref (); } NetDevice::~NetDevice () { - m_node->Unref (); m_node = 0; } From bd73c92bb562e3e80a84d2d98b7dd83bacac3c7c Mon Sep 17 00:00:00 2001 From: Raj Bhattacharjea Date: Wed, 9 May 2007 16:56:33 -0400 Subject: [PATCH 04/59] Hacked arraytraceresolver to compile, but segfaults upon running simple-p2p --- src/common/array-trace-resolver.h | 15 ++++++++++++++- src/node/node-list.cc | 22 +++++++++++----------- src/node/node-list.h | 7 ++++--- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/common/array-trace-resolver.h b/src/common/array-trace-resolver.h index af4e231bd..4374df6ce 100644 --- a/src/common/array-trace-resolver.h +++ b/src/common/array-trace-resolver.h @@ -24,6 +24,7 @@ #include #include #include "ns3/callback.h" +#include "ns3/ptr.h" #include "trace-resolver.h" namespace ns3 { @@ -82,12 +83,15 @@ public: ArrayTraceResolver (TraceContext const &context, Callback getSize, Callback get); + ArrayTraceResolver (TraceContext const &context, + Callback getSize, + Callback, uint32_t> get); private: virtual TraceResolverList DoLookup (std::string id) const; Callback m_getSize; Callback m_get; + Callback, uint32_t> m_get2; }; - }//namespace ns3 namespace ns3 { @@ -115,6 +119,14 @@ ArrayTraceResolver::ArrayTraceResolver (TraceContext const &context, m_get (get) {} template +ArrayTraceResolver::ArrayTraceResolver (TraceContext const &context, + Callback getSize, + Callback, uint32_t> get) + : TraceResolver (context), + m_getSize (getSize), + m_get2 (get) +{} +template TraceResolver::TraceResolverList ArrayTraceResolver::DoLookup (std::string id) const { @@ -127,6 +139,7 @@ ArrayTraceResolver::DoLookup (std::string id) const typename ArrayTraceResolver::Index index = typename ArrayTraceResolver::Index (i); context.Add (index); list.push_back (m_get (i)->CreateTraceResolver (context)); + } } return list; diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 5ea7d3a8b..889117ea3 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -49,37 +49,37 @@ public: NodeListPriv (); ~NodeListPriv (); - uint32_t Add (Node *node); + uint32_t Add (Ptr node); NodeList::Iterator Begin (void); NodeList::Iterator End (void); TraceResolver *CreateTraceResolver (TraceContext const &context); - Node *PeekNode (uint32_t n); + Ptr PeekNode (uint32_t n); uint32_t GetNNodes (void); private: - std::vector m_nodes; + std::vector > m_nodes; }; NodeListPriv::NodeListPriv () {} NodeListPriv::~NodeListPriv () { - for (std::vector::iterator i = m_nodes.begin (); + for (std::vector >::iterator i = m_nodes.begin (); i != m_nodes.end (); i++) { - Node *node = *i; + Ptr node = *i; node->Dispose (); - node->Unref (); + //node->Unref (); } m_nodes.erase (m_nodes.begin (), m_nodes.end ()); } uint32_t -NodeListPriv::Add (Node *node) +NodeListPriv::Add (Ptr node) { uint32_t index = m_nodes.size (); - node->Ref (); + //node->Ref (); m_nodes.push_back (node); return index; @@ -99,7 +99,7 @@ NodeListPriv::GetNNodes (void) { return m_nodes.size (); } -Node * +Ptr NodeListPriv::PeekNode (uint32_t n) { return m_nodes[n]; @@ -126,7 +126,7 @@ NodeListPriv::CreateTraceResolver (TraceContext const &context) namespace ns3 { uint32_t -NodeList::Add (Node *node) +NodeList::Add (Ptr node) { return SimulationSingleton::Get ()->Add (node); } @@ -145,7 +145,7 @@ NodeList::CreateTraceResolver (TraceContext const &context) { return SimulationSingleton::Get ()->CreateTraceResolver (context); } -Node * +Ptr NodeList::PeekNode (uint32_t n) { return SimulationSingleton::Get ()->PeekNode (n); diff --git a/src/node/node-list.h b/src/node/node-list.h index 57d8bf663..cbc19f250 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -24,6 +24,7 @@ #include #include "ns3/array-trace-resolver.h" +#include "ns3/ptr.h" namespace ns3 { @@ -35,14 +36,14 @@ class NodeList { public: typedef ArrayTraceResolver::Index NodeIndex; - typedef std::vector::iterator Iterator; + typedef std::vector< Ptr >::iterator Iterator; - static uint32_t Add (Node *node); + static uint32_t Add (Ptr node); static Iterator Begin (void); static Iterator End (void); static TraceResolver *CreateTraceResolver (TraceContext const &context); - static Node *PeekNode (uint32_t n); + static Ptr PeekNode (uint32_t n); }; }//namespace ns3 From 80854a2c39e81cbab26a473e2c67081a41403eea Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 9 May 2007 19:48:33 +0200 Subject: [PATCH 05/59] remove ptr::Remove, make ptr::Peek share the same signature as ptr::Get --- samples/main-ptr.cc | 3 ++- src/core/ptr.cc | 13 ++++++----- src/core/ptr.h | 53 ++++++++++++++++----------------------------- 3 files changed, 28 insertions(+), 41 deletions(-) diff --git a/samples/main-ptr.cc b/samples/main-ptr.cc index 3dc2fb246..fc6f97551 100644 --- a/samples/main-ptr.cc +++ b/samples/main-ptr.cc @@ -67,7 +67,8 @@ int main (int argc, char *argv[]) // remove the raw pointer from its smart pointer. // we can do this because the refcount is exactly one // here - A *raw = prev.Remove (); + A *raw = prev.Get (); + prev = 0; raw->Method (); delete raw; } diff --git a/src/core/ptr.cc b/src/core/ptr.cc index a0d37633c..610f535b2 100644 --- a/src/core/ptr.cc +++ b/src/core/ptr.cc @@ -241,7 +241,8 @@ PtrTest::RunTests (void) { Ptr p1 = p; } - raw = p.Remove (); + raw = p.Get (); + p = 0; } if (m_nDestroyed != 0) { @@ -254,12 +255,12 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p = new NoCount (cb); - NoCount const&v1 = p.Peek(); - NoCount v2 = p.Peek(); - v1.Nothing (); - v2.Nothing (); + const NoCount *v1 = p.Peek(); + NoCount *v2 = p.Peek(); + v1->Nothing (); + v2->Nothing (); } - if (m_nDestroyed != 2) + if (m_nDestroyed != 1) { ok = false; } diff --git a/src/core/ptr.h b/src/core/ptr.h index 7af3440bd..7ebe43af6 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -72,7 +72,23 @@ public: Ptr (Ptr const &o); ~Ptr () ; Ptr &operator = (Ptr const& o); - T const& Peek () const; + + /** + * \return the pointer managed by this smart pointer. + * + * The underlying refcount is not incremented prior + * to returning to the caller so the caller is not + * responsible for calling Unref himself. + */ + T * Peek () const; + + /** + * \return the pointer managed by this smart pointer. + * + * The underlying refcount is incremented prior + * to returning to the caller so the caller is + * responsible for calling Unref himself. + */ T * Get () const; T *operator -> () const; T *operator -> (); @@ -97,20 +113,6 @@ public: inline friend Ptr const_pointer_cast (Ptr const&p); - /** - * \returns raw pointer - * - * It is a programming error to invoke this method when - * the reference count of the smart pointer is not one. - * If you try to do it anyway, an assert will be triggered. - * If asserts are disabled, bad things will happen. - * Once you have successfully called Ptr::Remove on - * a smart pointer, the smart pointer will forget - * about the raw pointer and will stop managing it. As such, - * you, as the caller, become responsible for invoking - * operator delete on the returned raw pointer. - */ - T *Remove (void); }; template @@ -172,10 +174,10 @@ Ptr::operator = (Ptr const& o) } template -T const& +T * Ptr::Peek () const { - return *m_ptr; + return m_ptr; } template @@ -218,23 +220,6 @@ Ptr::operator Tester * () const return &test; } -template -T * -Ptr::Remove (void) -{ - if (m_ptr == 0) - { - return (T *) 0; - } - else - { - //NS_ASSERT (m_ptr->IsSingle()); - T *retval = m_ptr; - m_ptr = 0; - return retval; - } -} - // non-member friend functions. template bool From a82cf78743c953933a0bcc7f20e724eb7046ec3d Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 9 May 2007 19:48:33 +0200 Subject: [PATCH 06/59] remove ptr::Remove, make ptr::Peek share the same signature as ptr::Get --- samples/main-ptr.cc | 3 ++- src/core/ptr.cc | 13 ++++++----- src/core/ptr.h | 53 ++++++++++++++++----------------------------- 3 files changed, 28 insertions(+), 41 deletions(-) diff --git a/samples/main-ptr.cc b/samples/main-ptr.cc index 3dc2fb246..fc6f97551 100644 --- a/samples/main-ptr.cc +++ b/samples/main-ptr.cc @@ -67,7 +67,8 @@ int main (int argc, char *argv[]) // remove the raw pointer from its smart pointer. // we can do this because the refcount is exactly one // here - A *raw = prev.Remove (); + A *raw = prev.Get (); + prev = 0; raw->Method (); delete raw; } diff --git a/src/core/ptr.cc b/src/core/ptr.cc index a0d37633c..610f535b2 100644 --- a/src/core/ptr.cc +++ b/src/core/ptr.cc @@ -241,7 +241,8 @@ PtrTest::RunTests (void) { Ptr p1 = p; } - raw = p.Remove (); + raw = p.Get (); + p = 0; } if (m_nDestroyed != 0) { @@ -254,12 +255,12 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p = new NoCount (cb); - NoCount const&v1 = p.Peek(); - NoCount v2 = p.Peek(); - v1.Nothing (); - v2.Nothing (); + const NoCount *v1 = p.Peek(); + NoCount *v2 = p.Peek(); + v1->Nothing (); + v2->Nothing (); } - if (m_nDestroyed != 2) + if (m_nDestroyed != 1) { ok = false; } diff --git a/src/core/ptr.h b/src/core/ptr.h index 7af3440bd..7ebe43af6 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -72,7 +72,23 @@ public: Ptr (Ptr const &o); ~Ptr () ; Ptr &operator = (Ptr const& o); - T const& Peek () const; + + /** + * \return the pointer managed by this smart pointer. + * + * The underlying refcount is not incremented prior + * to returning to the caller so the caller is not + * responsible for calling Unref himself. + */ + T * Peek () const; + + /** + * \return the pointer managed by this smart pointer. + * + * The underlying refcount is incremented prior + * to returning to the caller so the caller is + * responsible for calling Unref himself. + */ T * Get () const; T *operator -> () const; T *operator -> (); @@ -97,20 +113,6 @@ public: inline friend Ptr const_pointer_cast (Ptr const&p); - /** - * \returns raw pointer - * - * It is a programming error to invoke this method when - * the reference count of the smart pointer is not one. - * If you try to do it anyway, an assert will be triggered. - * If asserts are disabled, bad things will happen. - * Once you have successfully called Ptr::Remove on - * a smart pointer, the smart pointer will forget - * about the raw pointer and will stop managing it. As such, - * you, as the caller, become responsible for invoking - * operator delete on the returned raw pointer. - */ - T *Remove (void); }; template @@ -172,10 +174,10 @@ Ptr::operator = (Ptr const& o) } template -T const& +T * Ptr::Peek () const { - return *m_ptr; + return m_ptr; } template @@ -218,23 +220,6 @@ Ptr::operator Tester * () const return &test; } -template -T * -Ptr::Remove (void) -{ - if (m_ptr == 0) - { - return (T *) 0; - } - else - { - //NS_ASSERT (m_ptr->IsSingle()); - T *retval = m_ptr; - m_ptr = 0; - return retval; - } -} - // non-member friend functions. template bool From a70e279787ade042c763589426a76fcddaadb598 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 9 May 2007 23:23:05 -0400 Subject: [PATCH 07/59] some Ipv4Interface* -> Ptr, and unhack arraytraceresolver, still segfaults --- src/common/array-trace-resolver.h | 25 ++++++------------------ src/internet-node/arp-cache.cc | 4 ++-- src/internet-node/arp-cache.h | 9 +++++---- src/internet-node/arp.cc | 6 +++--- src/internet-node/arp.h | 5 +++-- src/internet-node/i-ipv4-private.cc | 2 +- src/internet-node/i-ipv4-private.h | 3 ++- src/internet-node/ipv4-interface.h | 3 ++- src/internet-node/ipv4.cc | 30 ++++++++++++++--------------- src/internet-node/ipv4.h | 11 ++++++----- 10 files changed, 45 insertions(+), 53 deletions(-) diff --git a/src/common/array-trace-resolver.h b/src/common/array-trace-resolver.h index 4374df6ce..5a3a44c05 100644 --- a/src/common/array-trace-resolver.h +++ b/src/common/array-trace-resolver.h @@ -80,17 +80,13 @@ public: * a pointer to a TraceResolver. i.e. the signature is: * TraceResolver * (*) (TraceContext const &) */ - ArrayTraceResolver (TraceContext const &context, - Callback getSize, - Callback get); ArrayTraceResolver (TraceContext const &context, Callback getSize, Callback, uint32_t> get); private: virtual TraceResolverList DoLookup (std::string id) const; Callback m_getSize; - Callback m_get; - Callback, uint32_t> m_get2; + Callback, uint32_t> m_get; }; }//namespace ns3 @@ -110,21 +106,13 @@ ArrayTraceResolver::Index::operator uint32_t () return m_index; } -template -ArrayTraceResolver::ArrayTraceResolver (TraceContext const &context, - Callback getSize, - Callback get) - : TraceResolver (context), - m_getSize (getSize), - m_get (get) -{} template ArrayTraceResolver::ArrayTraceResolver (TraceContext const &context, Callback getSize, Callback, uint32_t> get) : TraceResolver (context), m_getSize (getSize), - m_get2 (get) + m_get (get) {} template TraceResolver::TraceResolverList @@ -132,16 +120,15 @@ ArrayTraceResolver::DoLookup (std::string id) const { TraceResolverList list; if (id == "*") + { + for (uint32_t i = 0; i < m_getSize (); i++) { - for (uint32_t i = 0; i < m_getSize (); i++) - { TraceContext context = GetContext (); - typename ArrayTraceResolver::Index index = typename ArrayTraceResolver::Index (i); + typename ArrayTraceResolver::Index index = typename ArrayTraceResolver::Index (i); context.Add (index); list.push_back (m_get (i)->CreateTraceResolver (context)); - - } } + } return list; } diff --git a/src/internet-node/arp-cache.cc b/src/internet-node/arp-cache.cc index 6a6f71bc9..ff886f430 100644 --- a/src/internet-node/arp-cache.cc +++ b/src/internet-node/arp-cache.cc @@ -28,7 +28,7 @@ namespace ns3 { -ArpCache::ArpCache (NetDevice *device, Ipv4Interface *interface) +ArpCache::ArpCache (NetDevice *device, Ptr interface) : m_device (device), m_interface (interface), m_aliveTimeout (Seconds (120)), @@ -50,7 +50,7 @@ ArpCache::PeekDevice (void) const return m_device; } -Ipv4Interface * +Ptr ArpCache::GetInterface (void) const { return m_interface; diff --git a/src/internet-node/arp-cache.h b/src/internet-node/arp-cache.h index 5923d2ca9..70c094154 100644 --- a/src/internet-node/arp-cache.h +++ b/src/internet-node/arp-cache.h @@ -28,21 +28,22 @@ #include "ns3/ipv4-address.h" #include "ns3/mac-address.h" #include "sgi-hashmap.h" +#include "ns3/ptr.h" +#include "ipv4-interface.h" namespace ns3 { class NetDevice; -class Ipv4Interface; class ArpCache { public: class Entry; - ArpCache (NetDevice *device, Ipv4Interface *interface); + ArpCache (NetDevice *device, Ptr interface); ~ArpCache (); NetDevice *PeekDevice (void) const; - Ipv4Interface *GetInterface (void) const; + Ptr GetInterface (void) const; void SetAliveTimeout (Time aliveTimeout); void SetDeadTimeout (Time deadTimeout); @@ -92,7 +93,7 @@ private: typedef sgi::hash_map::iterator CacheI; NetDevice *m_device; - Ipv4Interface *m_interface; + Ptr m_interface; Time m_aliveTimeout; Time m_deadTimeout; Time m_waitReplyTimeout; diff --git a/src/internet-node/arp.cc b/src/internet-node/arp.cc index 8c702adf4..5fdd5d96b 100644 --- a/src/internet-node/arp.cc +++ b/src/internet-node/arp.cc @@ -23,6 +23,7 @@ #include "ns3/empty-trace-resolver.h" #include "ns3/node.h" #include "ns3/net-device.h" +#include "ns3/ptr.h" #include "arp.h" #include "arp-header.h" @@ -36,11 +37,10 @@ namespace ns3 { const uint16_t Arp::PROT_NUMBER = 0x0806; -Arp::Arp (Node *node) + Arp::Arp (Ptr node) : L3Protocol (PROT_NUMBER, 0/* XXX: correct version number ? */ ), m_node (node) { - m_node->Ref (); } Arp::~Arp () @@ -81,7 +81,7 @@ Arp::FindCache (NetDevice *device) } } IIpv4Private *ipv4 = m_node->QueryInterface (IIpv4Private::iid); - Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device); + Ptr interface = ipv4->FindInterfaceForDevice (device); ipv4->Unref (); ArpCache * cache = new ArpCache (device, interface); NS_ASSERT (device->IsBroadcast ()); diff --git a/src/internet-node/arp.h b/src/internet-node/arp.h index ef909b2c8..67d61dce1 100644 --- a/src/internet-node/arp.h +++ b/src/internet-node/arp.h @@ -25,6 +25,7 @@ #include "ns3/ipv4-address.h" #include "ns3/mac-address.h" #include "l3-protocol.h" +#include "ns3/ptr.h" namespace ns3 { @@ -40,7 +41,7 @@ class Arp : public L3Protocol public: static const uint16_t PROT_NUMBER; - Arp (Node *node); + Arp (Ptr node); ~Arp (); virtual TraceResolver *CreateTraceResolver (TraceContext const &context); @@ -57,7 +58,7 @@ private: void SendArpRequest (ArpCache const *cache, Ipv4Address to); void SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac); CacheList m_cacheList; - Node *m_node; + Ptr m_node; }; }//namespace ns3 diff --git a/src/internet-node/i-ipv4-private.cc b/src/internet-node/i-ipv4-private.cc index 2921d5262..7bc2ec609 100644 --- a/src/internet-node/i-ipv4-private.cc +++ b/src/internet-node/i-ipv4-private.cc @@ -47,7 +47,7 @@ IIpv4Private::Send (Packet const &packet, Ipv4Address source, { m_ipv4->Send (packet, source, destination, protocol); } -Ipv4Interface * +Ptr IIpv4Private::FindInterfaceForDevice (NetDevice const*device) { return m_ipv4->FindInterfaceForDevice (device); diff --git a/src/internet-node/i-ipv4-private.h b/src/internet-node/i-ipv4-private.h index a300f725f..e595f2f42 100644 --- a/src/internet-node/i-ipv4-private.h +++ b/src/internet-node/i-ipv4-private.h @@ -23,6 +23,7 @@ #include "ns3/ns-unknown.h" #include "ns3/ipv4-address.h" +#include "ns3/ptr.h" #include namespace ns3 { @@ -44,7 +45,7 @@ public: TraceResolver *CreateTraceResolver (TraceContext const &context); void Send (Packet const &packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol); - Ipv4Interface *FindInterfaceForDevice (NetDevice const*device); + Ptr FindInterfaceForDevice (NetDevice const*device); void Receive(Packet& p, NetDevice *device); protected: virtual void DoDispose (void); diff --git a/src/internet-node/ipv4-interface.h b/src/internet-node/ipv4-interface.h index ef2b56408..ffee9f001 100644 --- a/src/internet-node/ipv4-interface.h +++ b/src/internet-node/ipv4-interface.h @@ -25,6 +25,7 @@ #include #include "ns3/ipv4-address.h" +#include "ns3/object.h" namespace ns3 { @@ -61,7 +62,7 @@ class TraceContext; * - Ipv4Interface::SendTo * - Ipv4Interface::DoCreateTraceResolver */ -class Ipv4Interface +class Ipv4Interface : public Object { public: /** diff --git a/src/internet-node/ipv4.cc b/src/internet-node/ipv4.cc index d049edcd7..c0567742c 100644 --- a/src/internet-node/ipv4.cc +++ b/src/internet-node/ipv4.cc @@ -63,7 +63,7 @@ Ipv4::DoDispose (void) { for (Ipv4InterfaceList::iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) { - delete (*i); + ::delete (*i); } m_interfaces.clear (); for (HostRoutesI i = m_hostRoutes.begin (); @@ -319,18 +319,18 @@ Ipv4::RemoveRoute (uint32_t index) uint32_t Ipv4::AddInterface (NetDevice *device) { - Ipv4Interface *interface = new ArpIpv4Interface (m_node, device); + Ptr interface = new ArpIpv4Interface (m_node, device); return AddIpv4Interface (interface); } uint32_t -Ipv4::AddIpv4Interface (Ipv4Interface *interface) +Ipv4::AddIpv4Interface (Ptr interface) { uint32_t index = m_nInterfaces; m_interfaces.push_back (interface); m_nInterfaces++; return index; } -Ipv4Interface * +Ptr Ipv4::GetInterface (uint32_t index) const { uint32_t tmp = 0; @@ -350,7 +350,7 @@ Ipv4::GetNInterfaces (void) const return m_nInterfaces; } -Ipv4Interface * +Ptr Ipv4::FindInterfaceForDevice (NetDevice const*device) { for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) @@ -434,7 +434,7 @@ Ipv4::SendRealOut (Packet const &p, Ipv4Header const &ip, Ipv4Route const &route { Packet packet = p; packet.AddHeader (ip); - Ipv4Interface *outInterface = GetInterface (route.GetInterface ()); + Ptr outInterface = GetInterface (route.GetInterface ()); NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ()); m_txTrace (packet, route.GetInterface ()); if (route.IsGateway ()) @@ -464,7 +464,7 @@ Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device) for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) { - Ipv4Interface *interface = *i; + Ptr interface = *i; if (interface->PeekDevice () == device) { if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ())) @@ -520,49 +520,49 @@ Ipv4::ForwardUp (Packet p, Ipv4Header const&ip) void Ipv4::SetAddress (uint32_t i, Ipv4Address address) { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); interface->SetAddress (address); } void Ipv4::SetNetworkMask (uint32_t i, Ipv4Mask mask) { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); interface->SetNetworkMask (mask); } Ipv4Mask Ipv4::GetNetworkMask (uint32_t i) const { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); return interface->GetNetworkMask (); } Ipv4Address Ipv4::GetAddress (uint32_t i) const { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); return interface->GetAddress (); } uint16_t Ipv4::GetMtu (uint32_t i) const { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); return interface->GetMtu (); } bool Ipv4::IsUp (uint32_t i) const { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); return interface->IsUp (); } void Ipv4::SetUp (uint32_t i) { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); interface->SetUp (); } void Ipv4::SetDown (uint32_t i) { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); interface->SetDown (); } diff --git a/src/internet-node/ipv4.h b/src/internet-node/ipv4.h index 84b63bf95..b84d9005f 100644 --- a/src/internet-node/ipv4.h +++ b/src/internet-node/ipv4.h @@ -28,12 +28,13 @@ #include "ns3/array-trace-resolver.h" #include "ns3/ipv4-address.h" #include "l3-protocol.h" +#include "ns3/ptr.h" +#include "ipv4-interface.h" namespace ns3 { class Packet; class NetDevice; -class Ipv4Interface; class Ipv4Address; class Ipv4Header; class Ipv4Route; @@ -169,7 +170,7 @@ public: * \param i index of interface to return * \returns the requested interface */ - Ipv4Interface * GetInterface (uint32_t i) const; + Ptr GetInterface (uint32_t i) const; /** * \returns the number of interfaces added by the user. */ @@ -181,7 +182,7 @@ public: * Try to find an Ipv4Interface whose NetDevice is equal to * the input NetDevice. */ - Ipv4Interface *FindInterfaceForDevice (NetDevice const*device); + Ptr FindInterfaceForDevice (NetDevice const*device); /** @@ -221,11 +222,11 @@ private: void SendRealOut (Packet const &packet, Ipv4Header const &ip, Ipv4Route const &route); bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device); void ForwardUp (Packet p, Ipv4Header const&ip); - uint32_t AddIpv4Interface (Ipv4Interface *interface); + uint32_t AddIpv4Interface (Ptr interface); void SetupLoopback (void); TraceResolver *InterfacesCreateTraceResolver (TraceContext const &context) const; - typedef std::list Ipv4InterfaceList; + typedef std::list > Ipv4InterfaceList; typedef std::list HostRoutes; typedef std::list::const_iterator HostRoutesCI; typedef std::list::iterator HostRoutesI; From 90a0cb3ad24bcfd9ee71c29e784349c24d955d88 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 07:25:47 +0200 Subject: [PATCH 08/59] remove ptr from ArrayTraceResolver --- src/common/array-trace-resolver.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/common/array-trace-resolver.h b/src/common/array-trace-resolver.h index 5a3a44c05..572df6e57 100644 --- a/src/common/array-trace-resolver.h +++ b/src/common/array-trace-resolver.h @@ -24,7 +24,6 @@ #include #include #include "ns3/callback.h" -#include "ns3/ptr.h" #include "trace-resolver.h" namespace ns3 { @@ -82,11 +81,11 @@ public: */ ArrayTraceResolver (TraceContext const &context, Callback getSize, - Callback, uint32_t> get); + Callback get); private: virtual TraceResolverList DoLookup (std::string id) const; Callback m_getSize; - Callback, uint32_t> m_get; + Callback m_get; }; }//namespace ns3 @@ -108,8 +107,8 @@ ArrayTraceResolver::Index::operator uint32_t () template ArrayTraceResolver::ArrayTraceResolver (TraceContext const &context, - Callback getSize, - Callback, uint32_t> get) + Callback getSize, + Callback get) : TraceResolver (context), m_getSize (getSize), m_get (get) From c12d5a114277cfafc9cbc5d7d4385e71b9c9937a Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 07:30:37 +0200 Subject: [PATCH 09/59] revert Ipv4Interface * -> Ptr --- src/internet-node/arp-cache.cc | 4 ++-- src/internet-node/arp-cache.h | 9 ++++----- src/internet-node/arp.cc | 6 +++--- src/internet-node/arp.h | 5 ++--- src/internet-node/i-ipv4-private.cc | 2 +- src/internet-node/i-ipv4-private.h | 3 +-- src/internet-node/ipv4-interface.h | 3 +-- src/internet-node/ipv4.cc | 30 ++++++++++++++--------------- src/internet-node/ipv4.h | 11 +++++------ src/node/node-list.cc | 9 ++++----- 10 files changed, 38 insertions(+), 44 deletions(-) diff --git a/src/internet-node/arp-cache.cc b/src/internet-node/arp-cache.cc index ff886f430..6a6f71bc9 100644 --- a/src/internet-node/arp-cache.cc +++ b/src/internet-node/arp-cache.cc @@ -28,7 +28,7 @@ namespace ns3 { -ArpCache::ArpCache (NetDevice *device, Ptr interface) +ArpCache::ArpCache (NetDevice *device, Ipv4Interface *interface) : m_device (device), m_interface (interface), m_aliveTimeout (Seconds (120)), @@ -50,7 +50,7 @@ ArpCache::PeekDevice (void) const return m_device; } -Ptr +Ipv4Interface * ArpCache::GetInterface (void) const { return m_interface; diff --git a/src/internet-node/arp-cache.h b/src/internet-node/arp-cache.h index 70c094154..5923d2ca9 100644 --- a/src/internet-node/arp-cache.h +++ b/src/internet-node/arp-cache.h @@ -28,22 +28,21 @@ #include "ns3/ipv4-address.h" #include "ns3/mac-address.h" #include "sgi-hashmap.h" -#include "ns3/ptr.h" -#include "ipv4-interface.h" namespace ns3 { class NetDevice; +class Ipv4Interface; class ArpCache { public: class Entry; - ArpCache (NetDevice *device, Ptr interface); + ArpCache (NetDevice *device, Ipv4Interface *interface); ~ArpCache (); NetDevice *PeekDevice (void) const; - Ptr GetInterface (void) const; + Ipv4Interface *GetInterface (void) const; void SetAliveTimeout (Time aliveTimeout); void SetDeadTimeout (Time deadTimeout); @@ -93,7 +92,7 @@ private: typedef sgi::hash_map::iterator CacheI; NetDevice *m_device; - Ptr m_interface; + Ipv4Interface *m_interface; Time m_aliveTimeout; Time m_deadTimeout; Time m_waitReplyTimeout; diff --git a/src/internet-node/arp.cc b/src/internet-node/arp.cc index 5fdd5d96b..8c702adf4 100644 --- a/src/internet-node/arp.cc +++ b/src/internet-node/arp.cc @@ -23,7 +23,6 @@ #include "ns3/empty-trace-resolver.h" #include "ns3/node.h" #include "ns3/net-device.h" -#include "ns3/ptr.h" #include "arp.h" #include "arp-header.h" @@ -37,10 +36,11 @@ namespace ns3 { const uint16_t Arp::PROT_NUMBER = 0x0806; - Arp::Arp (Ptr node) +Arp::Arp (Node *node) : L3Protocol (PROT_NUMBER, 0/* XXX: correct version number ? */ ), m_node (node) { + m_node->Ref (); } Arp::~Arp () @@ -81,7 +81,7 @@ Arp::FindCache (NetDevice *device) } } IIpv4Private *ipv4 = m_node->QueryInterface (IIpv4Private::iid); - Ptr interface = ipv4->FindInterfaceForDevice (device); + Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device); ipv4->Unref (); ArpCache * cache = new ArpCache (device, interface); NS_ASSERT (device->IsBroadcast ()); diff --git a/src/internet-node/arp.h b/src/internet-node/arp.h index 67d61dce1..ef909b2c8 100644 --- a/src/internet-node/arp.h +++ b/src/internet-node/arp.h @@ -25,7 +25,6 @@ #include "ns3/ipv4-address.h" #include "ns3/mac-address.h" #include "l3-protocol.h" -#include "ns3/ptr.h" namespace ns3 { @@ -41,7 +40,7 @@ class Arp : public L3Protocol public: static const uint16_t PROT_NUMBER; - Arp (Ptr node); + Arp (Node *node); ~Arp (); virtual TraceResolver *CreateTraceResolver (TraceContext const &context); @@ -58,7 +57,7 @@ private: void SendArpRequest (ArpCache const *cache, Ipv4Address to); void SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac); CacheList m_cacheList; - Ptr m_node; + Node *m_node; }; }//namespace ns3 diff --git a/src/internet-node/i-ipv4-private.cc b/src/internet-node/i-ipv4-private.cc index 7bc2ec609..2921d5262 100644 --- a/src/internet-node/i-ipv4-private.cc +++ b/src/internet-node/i-ipv4-private.cc @@ -47,7 +47,7 @@ IIpv4Private::Send (Packet const &packet, Ipv4Address source, { m_ipv4->Send (packet, source, destination, protocol); } -Ptr +Ipv4Interface * IIpv4Private::FindInterfaceForDevice (NetDevice const*device) { return m_ipv4->FindInterfaceForDevice (device); diff --git a/src/internet-node/i-ipv4-private.h b/src/internet-node/i-ipv4-private.h index e595f2f42..a300f725f 100644 --- a/src/internet-node/i-ipv4-private.h +++ b/src/internet-node/i-ipv4-private.h @@ -23,7 +23,6 @@ #include "ns3/ns-unknown.h" #include "ns3/ipv4-address.h" -#include "ns3/ptr.h" #include namespace ns3 { @@ -45,7 +44,7 @@ public: TraceResolver *CreateTraceResolver (TraceContext const &context); void Send (Packet const &packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol); - Ptr FindInterfaceForDevice (NetDevice const*device); + Ipv4Interface *FindInterfaceForDevice (NetDevice const*device); void Receive(Packet& p, NetDevice *device); protected: virtual void DoDispose (void); diff --git a/src/internet-node/ipv4-interface.h b/src/internet-node/ipv4-interface.h index ffee9f001..ef2b56408 100644 --- a/src/internet-node/ipv4-interface.h +++ b/src/internet-node/ipv4-interface.h @@ -25,7 +25,6 @@ #include #include "ns3/ipv4-address.h" -#include "ns3/object.h" namespace ns3 { @@ -62,7 +61,7 @@ class TraceContext; * - Ipv4Interface::SendTo * - Ipv4Interface::DoCreateTraceResolver */ -class Ipv4Interface : public Object +class Ipv4Interface { public: /** diff --git a/src/internet-node/ipv4.cc b/src/internet-node/ipv4.cc index c0567742c..d049edcd7 100644 --- a/src/internet-node/ipv4.cc +++ b/src/internet-node/ipv4.cc @@ -63,7 +63,7 @@ Ipv4::DoDispose (void) { for (Ipv4InterfaceList::iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) { - ::delete (*i); + delete (*i); } m_interfaces.clear (); for (HostRoutesI i = m_hostRoutes.begin (); @@ -319,18 +319,18 @@ Ipv4::RemoveRoute (uint32_t index) uint32_t Ipv4::AddInterface (NetDevice *device) { - Ptr interface = new ArpIpv4Interface (m_node, device); + Ipv4Interface *interface = new ArpIpv4Interface (m_node, device); return AddIpv4Interface (interface); } uint32_t -Ipv4::AddIpv4Interface (Ptr interface) +Ipv4::AddIpv4Interface (Ipv4Interface *interface) { uint32_t index = m_nInterfaces; m_interfaces.push_back (interface); m_nInterfaces++; return index; } -Ptr +Ipv4Interface * Ipv4::GetInterface (uint32_t index) const { uint32_t tmp = 0; @@ -350,7 +350,7 @@ Ipv4::GetNInterfaces (void) const return m_nInterfaces; } -Ptr +Ipv4Interface * Ipv4::FindInterfaceForDevice (NetDevice const*device) { for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) @@ -434,7 +434,7 @@ Ipv4::SendRealOut (Packet const &p, Ipv4Header const &ip, Ipv4Route const &route { Packet packet = p; packet.AddHeader (ip); - Ptr outInterface = GetInterface (route.GetInterface ()); + Ipv4Interface *outInterface = GetInterface (route.GetInterface ()); NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ()); m_txTrace (packet, route.GetInterface ()); if (route.IsGateway ()) @@ -464,7 +464,7 @@ Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device) for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) { - Ptr interface = *i; + Ipv4Interface *interface = *i; if (interface->PeekDevice () == device) { if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ())) @@ -520,49 +520,49 @@ Ipv4::ForwardUp (Packet p, Ipv4Header const&ip) void Ipv4::SetAddress (uint32_t i, Ipv4Address address) { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); interface->SetAddress (address); } void Ipv4::SetNetworkMask (uint32_t i, Ipv4Mask mask) { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); interface->SetNetworkMask (mask); } Ipv4Mask Ipv4::GetNetworkMask (uint32_t i) const { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); return interface->GetNetworkMask (); } Ipv4Address Ipv4::GetAddress (uint32_t i) const { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); return interface->GetAddress (); } uint16_t Ipv4::GetMtu (uint32_t i) const { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); return interface->GetMtu (); } bool Ipv4::IsUp (uint32_t i) const { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); return interface->IsUp (); } void Ipv4::SetUp (uint32_t i) { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); interface->SetUp (); } void Ipv4::SetDown (uint32_t i) { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); interface->SetDown (); } diff --git a/src/internet-node/ipv4.h b/src/internet-node/ipv4.h index b84d9005f..84b63bf95 100644 --- a/src/internet-node/ipv4.h +++ b/src/internet-node/ipv4.h @@ -28,13 +28,12 @@ #include "ns3/array-trace-resolver.h" #include "ns3/ipv4-address.h" #include "l3-protocol.h" -#include "ns3/ptr.h" -#include "ipv4-interface.h" namespace ns3 { class Packet; class NetDevice; +class Ipv4Interface; class Ipv4Address; class Ipv4Header; class Ipv4Route; @@ -170,7 +169,7 @@ public: * \param i index of interface to return * \returns the requested interface */ - Ptr GetInterface (uint32_t i) const; + Ipv4Interface * GetInterface (uint32_t i) const; /** * \returns the number of interfaces added by the user. */ @@ -182,7 +181,7 @@ public: * Try to find an Ipv4Interface whose NetDevice is equal to * the input NetDevice. */ - Ptr FindInterfaceForDevice (NetDevice const*device); + Ipv4Interface *FindInterfaceForDevice (NetDevice const*device); /** @@ -222,11 +221,11 @@ private: void SendRealOut (Packet const &packet, Ipv4Header const &ip, Ipv4Route const &route); bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device); void ForwardUp (Packet p, Ipv4Header const&ip); - uint32_t AddIpv4Interface (Ptr interface); + uint32_t AddIpv4Interface (Ipv4Interface *interface); void SetupLoopback (void); TraceResolver *InterfacesCreateTraceResolver (TraceContext const &context) const; - typedef std::list > Ipv4InterfaceList; + typedef std::list Ipv4InterfaceList; typedef std::list HostRoutes; typedef std::list::const_iterator HostRoutesCI; typedef std::list::iterator HostRoutesI; diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 889117ea3..d9640136a 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -53,7 +53,7 @@ public: NodeList::Iterator Begin (void); NodeList::Iterator End (void); TraceResolver *CreateTraceResolver (TraceContext const &context); - Ptr PeekNode (uint32_t n); + Node *PeekNode (uint32_t n); uint32_t GetNNodes (void); private: @@ -69,7 +69,7 @@ NodeListPriv::~NodeListPriv () { Ptr node = *i; node->Dispose (); - //node->Unref (); + *i = 0; } m_nodes.erase (m_nodes.begin (), m_nodes.end ()); } @@ -79,7 +79,6 @@ uint32_t NodeListPriv::Add (Ptr node) { uint32_t index = m_nodes.size (); - //node->Ref (); m_nodes.push_back (node); return index; @@ -99,10 +98,10 @@ NodeListPriv::GetNNodes (void) { return m_nodes.size (); } -Ptr +Node * NodeListPriv::PeekNode (uint32_t n) { - return m_nodes[n]; + return m_nodes[n].Peek (); } TraceResolver * From b67d39897642c43d5ae08a4a42f260183a3fa403 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 07:33:26 +0200 Subject: [PATCH 10/59] convert Arp code to use Ptr instead of Node * --- src/internet-node/arp.cc | 16 ++++------------ src/internet-node/arp.h | 5 +++-- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/internet-node/arp.cc b/src/internet-node/arp.cc index 8c702adf4..feb3ed6a0 100644 --- a/src/internet-node/arp.cc +++ b/src/internet-node/arp.cc @@ -36,17 +36,13 @@ namespace ns3 { const uint16_t Arp::PROT_NUMBER = 0x0806; -Arp::Arp (Node *node) +Arp::Arp (Ptr node) : L3Protocol (PROT_NUMBER, 0/* XXX: correct version number ? */ ), m_node (node) -{ - m_node->Ref (); -} +{} Arp::~Arp () -{ - Dispose (); -} +{} void Arp::DoDispose (void) @@ -56,11 +52,7 @@ Arp::DoDispose (void) delete *i; } m_cacheList.clear (); - if (m_node != 0) - { - m_node->Unref (); - m_node = 0; - } + m_node = 0; L3Protocol::DoDispose (); } diff --git a/src/internet-node/arp.h b/src/internet-node/arp.h index ef909b2c8..d436a99a2 100644 --- a/src/internet-node/arp.h +++ b/src/internet-node/arp.h @@ -24,6 +24,7 @@ #include #include "ns3/ipv4-address.h" #include "ns3/mac-address.h" +#include "ns3/ptr.h" #include "l3-protocol.h" namespace ns3 { @@ -40,7 +41,7 @@ class Arp : public L3Protocol public: static const uint16_t PROT_NUMBER; - Arp (Node *node); + Arp (Ptr node); ~Arp (); virtual TraceResolver *CreateTraceResolver (TraceContext const &context); @@ -57,7 +58,7 @@ private: void SendArpRequest (ArpCache const *cache, Ipv4Address to); void SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac); CacheList m_cacheList; - Node *m_node; + Ptr m_node; }; }//namespace ns3 From 5bd6229ac14654d5ff873f2ccfd5267d2d9fffc6 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 07:35:53 +0200 Subject: [PATCH 11/59] convert more code to use Ptr instead of Node * --- src/internet-node/arp-ipv4-interface.cc | 10 +++------- src/internet-node/arp-ipv4-interface.h | 5 +++-- src/internet-node/ipv4-loopback-interface.cc | 10 +++------- src/internet-node/ipv4-loopback-interface.h | 5 +++-- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/internet-node/arp-ipv4-interface.cc b/src/internet-node/arp-ipv4-interface.cc index ee168bfd8..bf80bfe71 100644 --- a/src/internet-node/arp-ipv4-interface.cc +++ b/src/internet-node/arp-ipv4-interface.cc @@ -31,16 +31,12 @@ namespace ns3 { -ArpIpv4Interface::ArpIpv4Interface (Node *node, NetDevice *device) +ArpIpv4Interface::ArpIpv4Interface (Ptr node, NetDevice *device) : Ipv4Interface (device), m_node (node) -{ - m_node->Ref (); -} +{} ArpIpv4Interface::~ArpIpv4Interface () -{ - m_node->Unref (); -} +{} TraceResolver * ArpIpv4Interface::DoCreateTraceResolver (TraceContext const &context) diff --git a/src/internet-node/arp-ipv4-interface.h b/src/internet-node/arp-ipv4-interface.h index 7b92b2234..d75e7a491 100644 --- a/src/internet-node/arp-ipv4-interface.h +++ b/src/internet-node/arp-ipv4-interface.h @@ -23,6 +23,7 @@ #define ARP_IPV4_INTERFACE_H #include "ipv4-interface.h" +#include "ns3/ptr.h" namespace ns3 { @@ -42,13 +43,13 @@ class ArpIpv4Interface : public Ipv4Interface NETDEVICE, ARP, }; - ArpIpv4Interface (Node *node, NetDevice *device); + ArpIpv4Interface (Ptr node, NetDevice *device); virtual ~ArpIpv4Interface (); private: virtual void SendTo (Packet p, Ipv4Address dest); virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); - Node *m_node; + Ptr m_node; }; }//namespace ns3 diff --git a/src/internet-node/ipv4-loopback-interface.cc b/src/internet-node/ipv4-loopback-interface.cc index 37a4eaf37..6b68dc871 100644 --- a/src/internet-node/ipv4-loopback-interface.cc +++ b/src/internet-node/ipv4-loopback-interface.cc @@ -27,16 +27,12 @@ namespace ns3 { -Ipv4LoopbackInterface::Ipv4LoopbackInterface (Node *node) +Ipv4LoopbackInterface::Ipv4LoopbackInterface (Ptr node) : Ipv4Interface (0), m_node (node) -{ - m_node->Ref (); -} +{} Ipv4LoopbackInterface::~Ipv4LoopbackInterface () -{ - m_node->Unref (); -} +{} TraceResolver * Ipv4LoopbackInterface::DoCreateTraceResolver (TraceContext const &context) diff --git a/src/internet-node/ipv4-loopback-interface.h b/src/internet-node/ipv4-loopback-interface.h index c4dff8763..cc7609b4a 100644 --- a/src/internet-node/ipv4-loopback-interface.h +++ b/src/internet-node/ipv4-loopback-interface.h @@ -23,6 +23,7 @@ #define IPV4_LOOPBACK_INTERFACE_H #include "ipv4-interface.h" +#include "ns3/ptr.h" namespace ns3 { @@ -31,14 +32,14 @@ class Node; class Ipv4LoopbackInterface : public Ipv4Interface { public: - Ipv4LoopbackInterface (Node *node); + Ipv4LoopbackInterface (Ptr node); virtual ~Ipv4LoopbackInterface (); private: virtual void SendTo (Packet p, Ipv4Address dest); virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); - Node *m_node; + Ptr m_node; }; }//namespace ns3 From 4d1c0647c8e229a0da7881d21ab186f5db1c2d7f Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 07:42:31 +0200 Subject: [PATCH 12/59] remove useless forward declaration --- src/internet-node/l3-protocol.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/internet-node/l3-protocol.h b/src/internet-node/l3-protocol.h index d309aca9a..00d780568 100644 --- a/src/internet-node/l3-protocol.h +++ b/src/internet-node/l3-protocol.h @@ -31,7 +31,6 @@ namespace ns3 { class Packet; class NetDevice; -class Node; class TraceResolver; class TraceContext; From 817876d6fe64f4fb47412c792e524c6c61880cfa Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 07:43:52 +0200 Subject: [PATCH 13/59] convert Node * to Ptr --- src/internet-node/ipv4.cc | 13 +++---------- src/internet-node/ipv4.h | 5 +++-- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/internet-node/ipv4.cc b/src/internet-node/ipv4.cc index d049edcd7..6a0697290 100644 --- a/src/internet-node/ipv4.cc +++ b/src/internet-node/ipv4.cc @@ -42,7 +42,7 @@ namespace ns3 { const uint16_t Ipv4::PROT_NUMBER = 0x0800; -Ipv4::Ipv4(Node *node) +Ipv4::Ipv4(Ptr node) : L3Protocol (PROT_NUMBER, 4), m_nInterfaces (0), m_defaultTtl (64), @@ -51,12 +51,9 @@ Ipv4::Ipv4(Node *node) m_node (node) { SetupLoopback (); - m_node->Ref (); } Ipv4::~Ipv4 () -{ - DoDispose (); -} +{} void Ipv4::DoDispose (void) @@ -83,11 +80,7 @@ Ipv4::DoDispose (void) delete m_defaultRoute; m_defaultRoute = 0; } - if (m_node != 0) - { - m_node->Unref (); - m_node = 0; - } + m_node = 0; L3Protocol::DoDispose (); } diff --git a/src/internet-node/ipv4.h b/src/internet-node/ipv4.h index 84b63bf95..b041b0e78 100644 --- a/src/internet-node/ipv4.h +++ b/src/internet-node/ipv4.h @@ -27,6 +27,7 @@ #include "ns3/callback-trace-source.h" #include "ns3/array-trace-resolver.h" #include "ns3/ipv4-address.h" +#include "ns3/ptr.h" #include "l3-protocol.h" namespace ns3 { @@ -58,7 +59,7 @@ public: }; typedef ArrayTraceResolver::Index InterfaceIndex; - Ipv4(Node *node); + Ipv4(Ptr node); virtual ~Ipv4 (); /** @@ -240,7 +241,7 @@ private: HostRoutes m_hostRoutes; NetworkRoutes m_networkRoutes; Ipv4Route *m_defaultRoute; - Node *m_node; + Ptr m_node; CallbackTraceSource m_txTrace; CallbackTraceSource m_rxTrace; CallbackTraceSource m_dropTrace; From ad8424e6d102e04e5eeae864b4e9713965f35310 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 07:44:18 +0200 Subject: [PATCH 14/59] convert Node * to Ptr --- src/internet-node/l3-demux.cc | 12 +++--------- src/internet-node/l3-demux.h | 5 +++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/internet-node/l3-demux.cc b/src/internet-node/l3-demux.cc index 5f261aca5..8f5ddc56f 100644 --- a/src/internet-node/l3-demux.cc +++ b/src/internet-node/l3-demux.cc @@ -31,12 +31,10 @@ namespace ns3 { const Iid L3Demux::iid ("L3Demux"); -L3Demux::L3Demux (Node *node) +L3Demux::L3Demux (Ptr node) : NsUnknown (L3Demux::iid), m_node (node) -{ - m_node->Ref (); -} +{} L3Demux::~L3Demux() {} @@ -50,11 +48,7 @@ L3Demux::DoDispose (void) i->second->Unref (); } m_protocols.clear (); - if (m_node != 0) - { - m_node->Unref (); - m_node = 0; - } + m_node = 0; NsUnknown::DoDispose (); } diff --git a/src/internet-node/l3-demux.h b/src/internet-node/l3-demux.h index 40f8318f5..9e3ffdc0a 100644 --- a/src/internet-node/l3-demux.h +++ b/src/internet-node/l3-demux.h @@ -29,6 +29,7 @@ #include #include "ns3/ns-unknown.h" +#include "ns3/ptr.h" namespace ns3 { @@ -45,7 +46,7 @@ class L3Demux : public NsUnknown public: static const Iid iid; typedef int ProtocolTraceType; - L3Demux(Node *node); + L3Demux(Ptr node); virtual ~L3Demux(); /** @@ -90,7 +91,7 @@ protected: private: typedef std::map L3Map_t; - Node *m_node; + Ptr m_node; L3Map_t m_protocols; }; From 96e58ed70865a5be2fc24c81f12f52a6bf1c113f Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 07:51:59 +0200 Subject: [PATCH 15/59] convert UdpSocket and Udp to Ptr --- src/internet-node/udp-socket.cc | 19 +++++-------------- src/internet-node/udp-socket.h | 7 ++++--- src/internet-node/udp.cc | 12 +++--------- src/internet-node/udp.h | 5 +++-- src/node/socket.h | 3 ++- 5 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 3ef89a090..52f0a749d 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -26,7 +26,7 @@ namespace ns3 { -UdpSocket::UdpSocket (Node *node, Udp *udp) +UdpSocket::UdpSocket (Ptr node, Udp *udp) : m_endPoint (0), m_node (node), m_udp (udp), @@ -36,15 +36,10 @@ UdpSocket::UdpSocket (Node *node, Udp *udp) m_connected (false) { m_udp->Ref (); - m_node->Ref (); } UdpSocket::~UdpSocket () { - if (m_node != 0) - { - m_node->Unref (); - m_node = 0; - } + m_node = 0; if (m_endPoint != 0) { NS_ASSERT (m_udp != 0); @@ -67,8 +62,8 @@ UdpSocket::~UdpSocket () } } -Node * -UdpSocket::PeekNode (void) const +Ptr +UdpSocket::GetNode (void) const { return m_node; } @@ -76,11 +71,7 @@ UdpSocket::PeekNode (void) const void UdpSocket::Destroy (void) { - if (m_node != 0) - { - m_node->Unref (); - m_node = 0; - } + m_node = 0; m_endPoint = 0; if (m_udp != 0) { diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket.h index c75ff9ae6..cab448b13 100644 --- a/src/internet-node/udp-socket.h +++ b/src/internet-node/udp-socket.h @@ -24,6 +24,7 @@ #include #include "ns3/callback.h" #include "ns3/socket.h" +#include "ns3/ptr.h" namespace ns3 { @@ -38,11 +39,11 @@ public: /** * Create an unbound udp socket. */ - UdpSocket (Node *node, Udp *udp); + UdpSocket (Ptr node, Udp *udp); virtual ~UdpSocket (); virtual enum SocketErrno GetErrno (void) const; - virtual Node *PeekNode (void) const; + virtual Ptr GetNode (void) const; virtual int Bind (void); virtual int Bind (Ipv4Address address); virtual int Bind (uint16_t port); @@ -81,7 +82,7 @@ private: ns3::Callback dataSent); Ipv4EndPoint *m_endPoint; - Node *m_node; + Ptr m_node; Udp *m_udp; Ipv4Address m_defaultAddress; uint16_t m_defaultPort; diff --git a/src/internet-node/udp.cc b/src/internet-node/udp.cc index 9261aa9a6..0fd2ae18f 100644 --- a/src/internet-node/udp.cc +++ b/src/internet-node/udp.cc @@ -38,13 +38,11 @@ namespace ns3 { /* see http://www.iana.org/assignments/protocol-numbers */ const uint8_t Udp::PROT_NUMBER = 17; -Udp::Udp (Node *node) +Udp::Udp (Ptr node) : Ipv4L4Protocol (PROT_NUMBER, 2), m_node (node), m_endPoints (new Ipv4EndPointDemux ()) -{ - m_node->Ref (); -} +{} Udp::~Udp () {} @@ -63,11 +61,7 @@ Udp::DoDispose (void) delete m_endPoints; m_endPoints = 0; } - if (m_node != 0) - { - m_node->Unref (); - m_node = 0; - } + m_node = 0; Ipv4L4Protocol::DoDispose (); } diff --git a/src/internet-node/udp.h b/src/internet-node/udp.h index 191dd2b73..5413f1bca 100644 --- a/src/internet-node/udp.h +++ b/src/internet-node/udp.h @@ -26,6 +26,7 @@ #include "ns3/packet.h" #include "ns3/ipv4-address.h" +#include "ns3/ptr.h" #include "ipv4-end-point-demux.h" #include "ipv4-l4-protocol.h" @@ -40,7 +41,7 @@ class Udp : public Ipv4L4Protocol { public: static const uint8_t PROT_NUMBER; - Udp (Node *node); + Udp (Ptr node); virtual ~Udp (); virtual TraceResolver *CreateTraceResolver (TraceContext const &context); @@ -67,7 +68,7 @@ public: protected: virtual void DoDispose (void); private: - Node *m_node; + Ptr m_node; Ipv4EndPointDemux *m_endPoints; }; diff --git a/src/node/socket.h b/src/node/socket.h index 950318505..396b79d71 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -22,6 +22,7 @@ #define __SOCKET_H__ #include "ns3/callback.h" +#include "ns3/ptr.h" #include "ipv4-address.h" #include "ns3/object.h" #include @@ -65,7 +66,7 @@ public: /** * \returns the node this socket is associated with. */ - virtual Node *PeekNode (void) const = 0; + virtual Ptr GetNode (void) const = 0; /** * Allocate a free port number and From 66bc2db9d1787796f0eeb544cfa597a7f7c4ab39 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 07:58:18 +0200 Subject: [PATCH 16/59] convert Node * to Ptr --- src/internet-node/ipv4-l4-demux.cc | 12 +++--------- src/internet-node/ipv4-l4-demux.h | 5 +++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index 3547e239f..2a026de36 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -32,12 +32,10 @@ namespace ns3 { const Iid Ipv4L4Demux::iid ("Ipv4L4Demux"); -Ipv4L4Demux::Ipv4L4Demux (Node *node) +Ipv4L4Demux::Ipv4L4Demux (Ptr node) : NsUnknown (Ipv4L4Demux::iid), m_node (node) -{ - m_node->Ref (); -} +{} Ipv4L4Demux::~Ipv4L4Demux() {} @@ -51,11 +49,7 @@ Ipv4L4Demux::DoDispose (void) (*i)->Unref (); } m_protocols.clear (); - if (m_node != 0) - { - m_node->Unref (); - m_node = 0; - } + m_node = 0; NsUnknown::DoDispose (); } diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index 3e70ad9d7..d52ce34b9 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -27,6 +27,7 @@ #include #include "ns3/ns-unknown.h" +#include "ns3/ptr.h" namespace ns3 { @@ -43,7 +44,7 @@ class Ipv4L4Demux : public NsUnknown public: static const Iid iid; typedef int Ipv4L4ProtocolTraceType; - Ipv4L4Demux (Node *node); + Ipv4L4Demux (Ptr node); virtual ~Ipv4L4Demux(); /** @@ -86,7 +87,7 @@ private: virtual void DoDispose (void); typedef std::list L4List_t; L4List_t m_protocols; - Node *m_node; + Ptr m_node; }; } //namespace ns3 From 11d883f2a6f09616015cbbf3e2ac6beffb9fa356 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 07:58:31 +0200 Subject: [PATCH 17/59] remove useless forward declaration --- src/internet-node/ipv4-l4-protocol.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/internet-node/ipv4-l4-protocol.h b/src/internet-node/ipv4-l4-protocol.h index 8e1b4397e..f23aa510b 100644 --- a/src/internet-node/ipv4-l4-protocol.h +++ b/src/internet-node/ipv4-l4-protocol.h @@ -29,7 +29,6 @@ namespace ns3 { -class Node; class Packet; class Ipv4Address; class TraceResolver; From 96f4b45eab0ba43472ce53d1ed9c606ccd930cc7 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 08:03:07 +0200 Subject: [PATCH 18/59] remove some dead code --- src/applications/application-list.cc | 19 +------------------ src/applications/application-list.h | 2 -- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/src/applications/application-list.cc b/src/applications/application-list.cc index 1c9059c8b..b75f007eb 100644 --- a/src/applications/application-list.cc +++ b/src/applications/application-list.cc @@ -49,29 +49,12 @@ ApplicationList::DoDispose (void) ApplicationList::~ApplicationList() {} -ApplicationList* ApplicationList::Copy(Ptr n) const -{ // Copy this app list - ApplicationList* r = new ApplicationList(n); - return r; -} - void ApplicationList::Add(Application* a) { a->Ref (); m_apps.push_back(a); -} - -void ApplicationList::SetNode(Ptr n) -{ - // Set the node pointer in each application - for (std::vector::const_iterator i = m_apps.begin(); - i != m_apps.end(); ++i) - { // Set correct node pointer in each app - (*i)->SetNode(n); - } -} - +} uint32_t ApplicationList::Count() const { diff --git a/src/applications/application-list.h b/src/applications/application-list.h index 8a30b2de5..78205b843 100644 --- a/src/applications/application-list.h +++ b/src/applications/application-list.h @@ -38,8 +38,6 @@ public: // Copy constructor not needed, default one is correct virtual ~ApplicationList(); // Inherited from Capabilty - virtual ApplicationList* Copy(Ptr) const; - virtual void SetNode(Ptr); // Sets the node for all apps virtual void Add(Application*); // Add an already new'ed app // Manage the list template T* AddCopy(const T& t) // Add a new application From e322d7f1df515ee0ac48a06b34fc3410e1879ada Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 08:18:41 +0200 Subject: [PATCH 19/59] implement properly NetDevice::DoDispose and rename NetDevice::PeekNode to NetDevice::GetNode --- src/devices/p2p/p2p-topology.cc | 8 ++++---- src/devices/p2p/p2p-topology.h | 3 ++- src/node/net-device.cc | 13 ++++++------- src/node/net-device.h | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index ff4f9e3bf..9a1daa9cf 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -79,13 +79,13 @@ PointToPointTopology::AddIpv4Addresses( NetDevice* nd1 = chan->GetDevice (0); NetDevice* nd2 = chan->GetDevice (1); // Make sure that nd1 belongs to n1 and nd2 to n2 - if ( (nd1->PeekNode ()->GetId () == n2->GetId () ) && - (nd2->PeekNode ()->GetId () == n1->GetId () ) ) + if ( (nd1->GetNode ()->GetId () == n2->GetId () ) && + (nd2->GetNode ()->GetId () == n1->GetId () ) ) { std::swap(nd1, nd2); } - NS_ASSERT (nd1->PeekNode ()->GetId () == n1->GetId ()); - NS_ASSERT (nd2->PeekNode ()->GetId () == n2->GetId ()); + NS_ASSERT (nd1->GetNode ()->GetId () == n1->GetId ()); + NS_ASSERT (nd2->GetNode ()->GetId () == n2->GetId ()); IIpv4 *ip1 = n1->QueryInterface (IIpv4::iid); uint32_t index1 = ip1->AddInterface (nd1); diff --git a/src/devices/p2p/p2p-topology.h b/src/devices/p2p/p2p-topology.h index ac43f1918..ecd927ff3 100644 --- a/src/devices/p2p/p2p-topology.h +++ b/src/devices/p2p/p2p-topology.h @@ -19,10 +19,11 @@ // // Topology helper for ns3. // George F. Riley, Georgia Tech, Spring 2007 -#include "ns3/ptr.h" #ifndef __POINT_TO_POINT_TOPOLOGY_H__ #define __POINT_TO_POINT_TOPOLOGY_H__ +#include "ns3/ptr.h" + // The topology class consists of only static methods thar are used to // create the topology and data flows for an ns3 simulation diff --git a/src/node/net-device.cc b/src/node/net-device.cc index 1f626d0f5..67054e03a 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -39,13 +39,10 @@ NetDevice::NetDevice(Ptr node, const MacAddress& addr) : m_isBroadcast (false), m_isMulticast (false), m_isPointToPoint (false) -{ -} +{} NetDevice::~NetDevice () -{ - m_node = 0; -} +{} MacAddress NetDevice::GetAddress (void) const @@ -227,7 +224,7 @@ NetDevice::NotifyLinkDown (void) } Ptr -NetDevice::PeekNode (void) const +NetDevice::GetNode (void) const { return m_node; } @@ -246,6 +243,8 @@ NetDevice::SetReceiveCallback (Callback PeekNode (void) const; + Ptr GetNode (void) const; bool NeedsArp (void) const; From f5451f5bced9944a21326ee7bce6956f0075cce5 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 08:19:19 +0200 Subject: [PATCH 20/59] rename NodeList::PeekNode to NodeList::GetNode --- src/internet-node/ascii-trace.cc | 4 ++-- src/internet-node/pcap-trace.cc | 2 +- src/node/node-list.cc | 5 +++-- src/node/node-list.h | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/internet-node/ascii-trace.cc b/src/internet-node/ascii-trace.cc index 761dcdfb0..9b1a69d01 100644 --- a/src/internet-node/ascii-trace.cc +++ b/src/internet-node/ascii-trace.cc @@ -110,7 +110,7 @@ AsciiTrace::LogDevQueue (TraceContext const &context, Packet const &packet) m_os << Simulator::Now ().GetSeconds () << " "; NodeList::NodeIndex nodeIndex; context.Get (nodeIndex); - m_os << "node=" << NodeList::PeekNode (nodeIndex)->GetId () << " "; + m_os << "node=" << NodeList::GetNode (nodeIndex)->GetId () << " "; Ipv4::InterfaceIndex interfaceIndex; context.Get (interfaceIndex); m_os << "interface=" << interfaceIndex << " "; @@ -124,7 +124,7 @@ AsciiTrace::LogDevRx (TraceContext const &context, Packet &p) m_os << "r " << Simulator::Now ().GetSeconds () << " "; NodeList::NodeIndex nodeIndex; context.Get (nodeIndex); - m_os << "node=" << NodeList::PeekNode (nodeIndex)->GetId () << " "; + m_os << "node=" << NodeList::GetNode (nodeIndex)->GetId () << " "; Ipv4::InterfaceIndex interfaceIndex; context.Get (interfaceIndex); m_os << "interface=" << interfaceIndex << " "; diff --git a/src/internet-node/pcap-trace.cc b/src/internet-node/pcap-trace.cc index e3263fd4c..8ffe86555 100644 --- a/src/internet-node/pcap-trace.cc +++ b/src/internet-node/pcap-trace.cc @@ -84,7 +84,7 @@ PcapTrace::LogIp (TraceContext const &context, Packet const &p, uint32_t interfa { NodeList::NodeIndex nodeIndex; context.Get (nodeIndex); - uint32_t nodeId = NodeList::PeekNode (nodeIndex)->GetId (); + uint32_t nodeId = NodeList::GetNode (nodeIndex)->GetId (); PcapWriter *writer = GetStream (nodeId, interfaceIndex); writer->WritePacket (p); } diff --git a/src/node/node-list.cc b/src/node/node-list.cc index d9640136a..13b9ead85 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -145,9 +145,10 @@ NodeList::CreateTraceResolver (TraceContext const &context) return SimulationSingleton::Get ()->CreateTraceResolver (context); } Ptr -NodeList::PeekNode (uint32_t n) +NodeList::GetNode (uint32_t n) { - return SimulationSingleton::Get ()->PeekNode (n); + Node *node = SimulationSingleton::Get ()->PeekNode (n); + return node; } diff --git a/src/node/node-list.h b/src/node/node-list.h index cbc19f250..2ef7bf9dd 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -43,7 +43,7 @@ public: static Iterator End (void); static TraceResolver *CreateTraceResolver (TraceContext const &context); - static Ptr PeekNode (uint32_t n); + static Ptr GetNode (uint32_t n); }; }//namespace ns3 From 60734cd2db96a0405f128cdd6869714b7bebbbde Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 08:19:53 +0200 Subject: [PATCH 21/59] implement properly Application::DoDispose and rename Application::PeekNOde to Application::GetNode --- src/applications/application.cc | 15 ++------------- src/applications/application.h | 4 +--- src/applications/onoff-application.cc | 2 +- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/applications/application.cc b/src/applications/application.cc index 6c62fe5ba..2d4badcd6 100644 --- a/src/applications/application.cc +++ b/src/applications/application.cc @@ -61,10 +61,7 @@ Application::~Application() void Application::DoDispose (void) { - if (m_node != 0) - { - m_node = 0; - } + m_node = 0; if (m_start) { Simulator::Cancel(m_startEvent); @@ -137,16 +134,8 @@ void Application::Stop(const RandomVariable& stopVar) m_stopVar = stopVar.Copy(); ScheduleStop(); } - -// \brief Assign this application to a given node -// Called by the application manager capability when adding -// an application to a node. -void Application::SetNode(Ptr n) -{ - m_node = n; -} -Ptr Application::PeekNode() const +Ptr Application::GetNode() const { return m_node; } diff --git a/src/applications/application.h b/src/applications/application.h index a85bfbf40..83c16a31f 100644 --- a/src/applications/application.h +++ b/src/applications/application.h @@ -102,10 +102,8 @@ void Start(const RandomVariable&); // \brief Attaches an application to a specific node // Specifies which node object this application is associated with. // \param Node object to associate with this application. - void SetNode(Ptr); - // \brief Returns the pointer to the attached node. - Ptr PeekNode() const; + Ptr GetNode() const; // Members Ptr m_node; // All applications have an associated node diff --git a/src/applications/onoff-application.cc b/src/applications/onoff-application.cc index ac74ef13e..6c6e6f847 100644 --- a/src/applications/onoff-application.cc +++ b/src/applications/onoff-application.cc @@ -170,7 +170,7 @@ void OnOffApplication::StartApplication() // Called at time specified by Star this)); #endif - IUdp *udp = PeekNode ()->QueryInterface (IUdp::iid); + IUdp *udp = GetNode ()->QueryInterface (IUdp::iid); m_socket = udp->CreateSocket (); udp->Unref (); m_socket->Connect (m_peerIP, m_peerPort); From 2d66e7e804f2d24468ca18bb0163dca5537014d8 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 08:34:32 +0200 Subject: [PATCH 22/59] make sure that NodeList::GetNode is correctly implemented --- src/node/node-list.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 13b9ead85..c70cd3d20 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -54,6 +54,7 @@ public: NodeList::Iterator End (void); TraceResolver *CreateTraceResolver (TraceContext const &context); Node *PeekNode (uint32_t n); + Ptr GetNode (uint32_t n); uint32_t GetNNodes (void); private: @@ -104,6 +105,13 @@ NodeListPriv::PeekNode (uint32_t n) return m_nodes[n].Peek (); } +Ptr +NodeListPriv::GetNode (uint32_t n) +{ + return m_nodes[n]; +} + + TraceResolver * NodeListPriv::CreateTraceResolver (TraceContext const &context) { @@ -147,8 +155,7 @@ NodeList::CreateTraceResolver (TraceContext const &context) Ptr NodeList::GetNode (uint32_t n) { - Node *node = SimulationSingleton::Get ()->PeekNode (n); - return node; + return SimulationSingleton::Get ()->GetNode (n); } From db94cb694139f1419820cd33130b6234db9a4c4b Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 09:57:32 +0200 Subject: [PATCH 23/59] use the NS_DEBUG env var rather than NS3_DEBUG, as explained by the documentation. --- src/core/debug.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/debug.cc b/src/core/debug.cc index 5d57b64cd..abd91b504 100644 --- a/src/core/debug.cc +++ b/src/core/debug.cc @@ -48,7 +48,7 @@ void DebugComponentEnableEnvVar (void) { #ifdef HAVE_GETENV - char *envVar = getenv("NS3_DEBUG"); + char *envVar = getenv("NS_DEBUG"); if (envVar == 0) { return; From 01a20c0a827de88b28f5c2ac71810cd63965d846 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 09:57:46 +0200 Subject: [PATCH 24/59] add some refcount debugging --- src/core/ns-unknown.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/ns-unknown.cc b/src/core/ns-unknown.cc index d31b61fba..27a5702b0 100644 --- a/src/core/ns-unknown.cc +++ b/src/core/ns-unknown.cc @@ -25,6 +25,9 @@ #include #include #include "assert.h" +#include "debug.h" + +NS_DEBUG_COMPONENT_DEFINE ("NsUnknown"); namespace ns3 { @@ -80,6 +83,7 @@ void NsUnknownImpl::Ref (void) { m_ref++; + NS_DEBUG ("inc " << this << " ref=" << m_ref); } void NsUnknownImpl::RefAll (NsUnknownImpl *other) @@ -90,6 +94,7 @@ void NsUnknownImpl::Unref (void) { m_ref--; + NS_DEBUG ("dec " << this << " ref=" << m_ref); if (m_ref == 0) { delete this; From 349f970d82005248fbd9c4457bc4b9817162711c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 18:33:52 +0200 Subject: [PATCH 25/59] remove leaks and rework the Ptr class to work with a new refcount mechanism --- examples/simple-p2p.cc | 6 +-- samples/main-simple.cc | 13 ++++-- src/applications/application-list.cc | 18 ++++---- src/applications/application-list.h | 17 +++----- src/core/ns-unknown.cc | 12 ++++-- src/core/ns-unknown.h | 4 +- src/core/object.cc | 13 +++--- src/core/ptr.cc | 16 +++++++ src/core/ptr.h | 62 ++++++++++++++++++++-------- src/devices/p2p/p2p-topology.cc | 5 +++ src/internet-node/internet-node.cc | 13 ++++++ src/internet-node/udp.cc | 4 +- 12 files changed, 126 insertions(+), 57 deletions(-) diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index 43dfb5303..998256168 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -137,7 +137,7 @@ int main (int argc, char *argv[]) // Create the OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s - OnOffApplication* ooff0 = new OnOffApplication( + Ptr ooff0 = new OnOffApplication( n0, Ipv4Address("10.1.3.2"), 80, @@ -154,10 +154,9 @@ int main (int argc, char *argv[]) // Start the application ooff0->Start(Seconds(1.0)); ooff0->Stop (Seconds(10.0)); - ooff0->Unref (); // Create a similar flow from n3 to n1, starting at time 1.1 seconds - OnOffApplication* ooff1 = new OnOffApplication( + Ptr ooff1 = new OnOffApplication( n3, Ipv4Address("10.1.2.1"), 80, @@ -172,7 +171,6 @@ int main (int argc, char *argv[]) // Start the application ooff1->Start(Seconds(1.1)); ooff1->Stop (Seconds(10.0)); - ooff1->Unref (); // Here, finish off packet routing configuration // This will likely set by some global StaticRouting object in the future diff --git a/samples/main-simple.cc b/samples/main-simple.cc index 675a3d16e..9505f0f16 100644 --- a/samples/main-simple.cc +++ b/samples/main-simple.cc @@ -35,9 +35,10 @@ PrintTraffic (Socket *socket) socket->RecvDummy (MakeCallback (&SocketPrinter)); } -int main (int argc, char *argv[]) +void +RunSimulation (void) { - InternetNode *a = new InternetNode (); + Ptr a = new InternetNode (); IUdp *udp; udp = a->QueryInterface (IUdp::iid); @@ -60,7 +61,13 @@ int main (int argc, char *argv[]) sink->Unref (); source->Unref (); - a->Unref (); + + std::cout << "o" << std::endl; +} + +int main (int argc, char *argv[]) +{ + RunSimulation (); return 0; } diff --git a/src/applications/application-list.cc b/src/applications/application-list.cc index b75f007eb..33980b840 100644 --- a/src/applications/application-list.cc +++ b/src/applications/application-list.cc @@ -35,12 +35,12 @@ ApplicationList::ApplicationList(Ptr n) void ApplicationList::DoDispose (void) { - for (std::vector::const_iterator i = m_apps.begin(); + for (std::vector >::iterator i = m_apps.begin(); i != m_apps.end(); ++i) { - Application *app = *i; + Ptr app = *i; app->Dispose (); - app->Unref (); + *i = 0; } m_apps.clear (); NsUnknown::DoDispose (); @@ -50,9 +50,8 @@ ApplicationList::~ApplicationList() {} void -ApplicationList::Add(Application* a) +ApplicationList::Add(Ptr a) { - a->Ref (); m_apps.push_back(a); } @@ -61,9 +60,12 @@ uint32_t ApplicationList::Count() const return m_apps.size(); } -Application* ApplicationList::Get(uint32_t i) const -{ // Get the i'th application. Note, this is linear time in N - if (m_apps.empty()) return 0; // List is empty +Ptr ApplicationList::Get(uint32_t i) const +{ + if (m_apps.empty()) + { + return 0; + } return m_apps[i]; } diff --git a/src/applications/application-list.h b/src/applications/application-list.h index 78205b843..46576ecf3 100644 --- a/src/applications/application-list.h +++ b/src/applications/application-list.h @@ -26,6 +26,7 @@ #include "application.h" #include "ns3/ns-unknown.h" +#include "ns3/ptr.h" #include namespace ns3 { @@ -37,23 +38,15 @@ public: ApplicationList(Ptr); // Copy constructor not needed, default one is correct virtual ~ApplicationList(); - // Inherited from Capabilty - virtual void Add(Application*); // Add an already new'ed app - // Manage the list - template T* AddCopy(const T& t) // Add a new application - { - T* a = t.Copy(); - m_apps.push_back(a); - return a; - } - void Remove(Application*); // Application has finished + virtual void Add(Ptr application); + uint32_t Count() const; // Number of applications - Application* Get(uint32_t i) const; // Get app by index + Ptr Get(uint32_t i) const; // Get app by index protected: virtual void DoDispose (void); private: - std::vector m_apps; + std::vector > m_apps; }; }//namespace ns3 diff --git a/src/core/ns-unknown.cc b/src/core/ns-unknown.cc index 27a5702b0..b3edea6ad 100644 --- a/src/core/ns-unknown.cc +++ b/src/core/ns-unknown.cc @@ -65,9 +65,10 @@ private: }; NsUnknownImpl::NsUnknownImpl (Iid iid, NsUnknown *interface) - : m_ref (1), + : m_ref (0), m_disposed (false) { + NS_DEBUG ("new " << this << " ref=" << m_ref); m_list.push_back (std::make_pair (iid, interface)); } NsUnknownImpl::~NsUnknownImpl () @@ -89,10 +90,12 @@ void NsUnknownImpl::RefAll (NsUnknownImpl *other) { m_ref += other->m_ref; + NS_DEBUG ("inc all " << this << " o=" << other->m_ref << " ref=" << m_ref); } void NsUnknownImpl::Unref (void) { + NS_ASSERT (m_ref > 0); m_ref--; NS_DEBUG ("dec " << this << " ref=" << m_ref); if (m_ref == 0) @@ -103,8 +106,10 @@ NsUnknownImpl::Unref (void) void NsUnknownImpl::UnrefAll (void) { + NS_ASSERT (m_ref > 0); m_ref = 0; delete this; + NS_DEBUG ("dec all " << this); } void NsUnknownImpl::DoDisposeAll (void) @@ -159,14 +164,15 @@ NsUnknown::NsUnknown (Iid iid) NsUnknown::~NsUnknown () { m_impl = 0; + m_ref = -1; } void -NsUnknown::Ref (void) +NsUnknown::Ref (void) const { m_impl->Ref (); } void -NsUnknown::Unref (void) +NsUnknown::Unref (void) const { m_impl->Unref (); } diff --git a/src/core/ns-unknown.h b/src/core/ns-unknown.h index c5c6af1e4..046407a34 100644 --- a/src/core/ns-unknown.h +++ b/src/core/ns-unknown.h @@ -49,8 +49,8 @@ class NsUnknown { public: virtual ~NsUnknown (); - void Ref (void); - void Unref (void); + void Ref (void) const; + void Unref (void) const; /** * \param iid the NsUnknown id of the requested interface diff --git a/src/core/object.cc b/src/core/object.cc index 9c7e8d83e..77bfbe76f 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -27,9 +27,11 @@ NS_DEBUG_COMPONENT_DEFINE ("Object"); namespace ns3 { Object::Object () - : m_count (1), + : m_count (0), m_disposed (false) -{} +{ + NS_DEBUG ("Object::Object: m_count=0"); +} Object::~Object () {} @@ -37,17 +39,16 @@ Object::~Object () void Object::Ref (void) const { - NS_DEBUG("Object::Ref (): this == 0x" << this); m_count++; - NS_DEBUG("Object::Ref (): m_count bumped to " << m_count); + NS_DEBUG("Object::Ref (): this == 0x" << this << " m_count=" << m_count); } void Object::Unref (void) const { - NS_DEBUG("Object::Unref (): this == 0x" << this); + NS_ASSERT (m_count > 0); m_count--; - NS_DEBUG("Object::Ref (): m_count dropped to " << m_count); + NS_DEBUG("Object::Unref (): this == 0x" << this << " m_count=" << m_count); if (m_count == 0) { diff --git a/src/core/ptr.cc b/src/core/ptr.cc index 610f535b2..f488c51f9 100644 --- a/src/core/ptr.cc +++ b/src/core/ptr.cc @@ -264,6 +264,22 @@ PtrTest::RunTests (void) { ok = false; } + + { + Ptr p0 = new NoCount (cb); + Ptr p1 = new NoCount (cb); + if (p0 == p1) + { + ok = false; + } + if (p0 != p1) + { + } + else + { + ok = false; + } + } return ok; diff --git a/src/core/ptr.h b/src/core/ptr.h index 7ebe43af6..b95ce9c5d 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -51,6 +51,7 @@ private: void operator delete (void *); }; friend class Ptr; + void Acquire (void) const; public: /** * Create an empty smart pointer @@ -109,12 +110,29 @@ public: template inline friend bool operator != (T1 const *lhs, Ptr &rhs); + // allow if (sp0 == sp1) + template + inline friend bool operator == (Ptr const &lhs, Ptr const &rhs); + // allow if (sp0 != sp1) + template + inline friend bool operator != (Ptr const &lhs, Ptr const &rhs); + template inline friend Ptr const_pointer_cast (Ptr const&p); }; +template +void +Ptr::Acquire (void) const +{ + if (m_ptr != 0) + { + m_ptr->Ref (); + } +} + template Ptr::Ptr () : m_ptr (0) @@ -123,27 +141,22 @@ Ptr::Ptr () template Ptr::Ptr (T *ptr) : m_ptr (ptr) -{} +{ + Acquire (); +} template Ptr::Ptr (Ptr const&o) - : m_ptr (o.m_ptr) + : m_ptr (o.Peek ()) { - if (m_ptr != 0) - { - m_ptr->Ref(); - } + Acquire (); } template template Ptr::Ptr (Ptr const &o) - : m_ptr (o.m_ptr) + : m_ptr (o.Peek ()) { - if (m_ptr != 0) - { - NS_ASSERT (o.m_ptr != 0); - m_ptr->Ref(); - } + Acquire (); } template @@ -160,16 +173,15 @@ Ptr & Ptr::operator = (Ptr const& o) { if (&o == this) - return *this; + { + return *this; + } if (m_ptr != 0) { m_ptr->Unref(); } m_ptr = o.m_ptr; - if (m_ptr != 0) - { - m_ptr->Ref(); - } + Acquire (); return *this; } @@ -184,7 +196,7 @@ template T * Ptr::Get () const { - m_ptr->Ref(); + Acquire (); return m_ptr; } @@ -246,6 +258,20 @@ operator != (T1 const *lhs, Ptr &rhs) return lhs != rhs.m_ptr; } +template +bool +operator == (Ptr const &lhs, Ptr const &rhs) +{ + return lhs.Get () == rhs.Get (); +} +template +bool +operator != (Ptr const &lhs, Ptr const &rhs) +{ + return lhs.Get () != rhs.Get (); +} + + template Ptr const_pointer_cast (Ptr const&p) diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index 9a1daa9cf..5f024a668 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -46,14 +46,19 @@ PointToPointTopology::AddPointToPointLink( const Time& delay) { PointToPointChannel* channel = new PointToPointChannel(bps, delay); + channel->Ref (); PointToPointNetDevice* net1 = new PointToPointNetDevice(n1); + net1->Ref (); + net1->AddQueue(Queue::Default().Copy()); n1->AddDevice (net1); net1->Attach (channel); net1->Unref (); PointToPointNetDevice* net2 = new PointToPointNetDevice(n2); + net2->Ref (); + net2->AddQueue(Queue::Default().Copy()); n2->AddDevice (net2); net2->Attach (channel); diff --git a/src/internet-node/internet-node.cc b/src/internet-node/internet-node.cc index 2f18becea..abe48a41d 100644 --- a/src/internet-node/internet-node.cc +++ b/src/internet-node/internet-node.cc @@ -45,10 +45,18 @@ InternetNode::InternetNode() Arp *arp = new Arp (this); Udp *udp = new Udp (this); + ipv4->Ref (); + arp->Ref (); + udp->Ref (); + ApplicationList *applicationList = new ApplicationList(this); L3Demux *l3Demux = new L3Demux(this); Ipv4L4Demux *ipv4L4Demux = new Ipv4L4Demux(this); + applicationList->Ref (); + l3Demux->Ref (); + ipv4L4Demux->Ref (); + l3Demux->Insert (ipv4); l3Demux->Insert (arp); ipv4L4Demux->Insert (udp); @@ -58,6 +66,11 @@ InternetNode::InternetNode() IIpv4Impl *ipv4Impl = new IIpv4Impl (ipv4); IIpv4Private *ipv4Private = new IIpv4Private (ipv4); + udpImpl->Ref (); + arpPrivate->Ref (); + ipv4Impl->Ref (); + ipv4Private->Ref (); + NsUnknown::AddInterface (ipv4Private); NsUnknown::AddInterface (ipv4Impl); NsUnknown::AddInterface (arpPrivate); diff --git a/src/internet-node/udp.cc b/src/internet-node/udp.cc index 0fd2ae18f..96bc58056 100644 --- a/src/internet-node/udp.cc +++ b/src/internet-node/udp.cc @@ -68,7 +68,9 @@ Udp::DoDispose (void) Socket * Udp::CreateSocket (void) { - return new UdpSocket (m_node, this); + Socket *socket = new UdpSocket (m_node, this); + socket->Ref (); + return socket; } Ipv4EndPoint * From 4bd2abebd217538b8c1844e5728553a78d13cbd4 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 20:19:26 +0200 Subject: [PATCH 26/59] use Ptr<> everywhere Object or NsUnknown are used --- examples/simple-p2p.cc | 20 ++---- samples/main-simple.cc | 20 ++---- src/applications/onoff-application.cc | 13 ++-- src/applications/onoff-application.h | 8 +-- src/core/ns-unknown-manager.cc | 23 ++----- src/core/ns-unknown-manager.h | 72 ++++++++++---------- src/core/ns-unknown.cc | 57 ++++++---------- src/core/ns-unknown.h | 16 ++--- src/devices/p2p/p2p-channel.cc | 12 ++-- src/devices/p2p/p2p-channel.h | 15 ++-- src/devices/p2p/p2p-net-device.cc | 28 ++------ src/devices/p2p/p2p-net-device.h | 6 +- src/devices/p2p/p2p-topology.cc | 69 +++++++------------ src/devices/p2p/p2p-topology.h | 8 +-- src/internet-node/arp-cache.cc | 11 ++- src/internet-node/arp-cache.h | 7 +- src/internet-node/arp-ipv4-interface.cc | 19 +++--- src/internet-node/arp-ipv4-interface.h | 2 +- src/internet-node/arp.cc | 21 +++--- src/internet-node/arp.h | 6 +- src/internet-node/i-arp-private.cc | 10 ++- src/internet-node/i-arp-private.h | 6 +- src/internet-node/i-ipv4-impl.cc | 10 ++- src/internet-node/i-ipv4-impl.h | 7 +- src/internet-node/i-ipv4-private.cc | 12 ++-- src/internet-node/i-ipv4-private.h | 9 +-- src/internet-node/i-udp-impl.cc | 15 ++-- src/internet-node/i-udp-impl.h | 7 +- src/internet-node/internet-node.cc | 59 +++++----------- src/internet-node/internet-node.h | 4 +- src/internet-node/ipv4-interface.cc | 20 ++---- src/internet-node/ipv4-interface.h | 7 +- src/internet-node/ipv4-l4-demux.cc | 17 +++-- src/internet-node/ipv4-l4-demux.h | 8 +-- src/internet-node/ipv4-loopback-interface.cc | 5 +- src/internet-node/ipv4.cc | 20 +++--- src/internet-node/ipv4.h | 8 +-- src/internet-node/l3-demux.cc | 16 +++-- src/internet-node/l3-demux.h | 8 +-- src/internet-node/l3-protocol.h | 3 +- src/internet-node/udp-socket.cc | 42 +++++------- src/internet-node/udp-socket.h | 32 ++++----- src/internet-node/udp.cc | 8 +-- src/internet-node/udp.h | 2 +- src/node/channel.h | 3 +- src/node/i-ipv4.h | 2 +- src/node/i-udp.h | 3 +- src/node/net-device.cc | 4 +- src/node/net-device.h | 8 +-- src/node/node.cc | 11 ++- src/node/node.h | 8 +-- src/node/socket.cc | 34 ++++----- src/node/socket.h | 56 +++++++-------- 53 files changed, 379 insertions(+), 518 deletions(-) diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index 998256168..461782eef 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -107,15 +107,15 @@ int main (int argc, char *argv[]) Ptr n3 = new InternetNode (); // We create the channels first without any IP addressing information - PointToPointChannel *channel0 = + Ptr channel0 = PointToPointTopology::AddPointToPointLink ( n0, n2, DataRate(5000000), MilliSeconds(2)); - PointToPointChannel *channel1 = + Ptr channel1 = PointToPointTopology::AddPointToPointLink ( n1, n2, DataRate(5000000), MilliSeconds(2)); - PointToPointChannel *channel2 = + Ptr channel2 = PointToPointTopology::AddPointToPointLink ( n2, n3, DataRate(1500000), MilliSeconds(10)); @@ -123,17 +123,14 @@ int main (int argc, char *argv[]) PointToPointTopology::AddIpv4Addresses ( channel0, n0, Ipv4Address("10.1.1.1"), n2, Ipv4Address("10.1.1.2")); - channel0->Unref (); PointToPointTopology::AddIpv4Addresses ( channel1, n1, Ipv4Address("10.1.2.1"), n2, Ipv4Address("10.1.2.2")); - channel1->Unref (); PointToPointTopology::AddIpv4Addresses ( channel2, n2, Ipv4Address("10.1.3.1"), n3, Ipv4Address("10.1.3.2")); - channel2->Unref (); // Create the OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s @@ -146,10 +143,8 @@ int main (int argc, char *argv[]) DataRate(448000), 210); // Add to Node's ApplicationList (takes ownership of pointer) - ApplicationList *apl0 = n0->QueryInterface - (ApplicationList::iid); + Ptr apl0 = n0->QueryInterface (ApplicationList::iid); apl0->Add(ooff0); - apl0->Unref (); // Start the application ooff0->Start(Seconds(1.0)); @@ -165,22 +160,19 @@ int main (int argc, char *argv[]) DataRate(448000), 210); // Add to Node's ApplicationList (takes ownership of pointer) - ApplicationList *apl3 = n3->QueryInterface (ApplicationList::iid); + Ptr apl3 = n3->QueryInterface (ApplicationList::iid); apl3->Add(ooff1); - apl3->Unref (); // Start the application ooff1->Start(Seconds(1.1)); ooff1->Stop (Seconds(10.0)); // Here, finish off packet routing configuration // This will likely set by some global StaticRouting object in the future - IIpv4 *ipv4; + Ptr ipv4; ipv4 = n0->QueryInterface (IIpv4::iid); ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); - ipv4->Unref (); ipv4 = n3->QueryInterface (IIpv4::iid); ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1); - ipv4->Unref (); n0 = 0; n1 = 0; diff --git a/samples/main-simple.cc b/samples/main-simple.cc index 9505f0f16..db6f57736 100644 --- a/samples/main-simple.cc +++ b/samples/main-simple.cc @@ -9,7 +9,7 @@ using namespace ns3; static void -GenerateTraffic (Socket *socket, uint32_t size) +GenerateTraffic (Ptr socket, uint32_t size) { std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, tx bytes=" << size << std::endl; socket->Send (0, size); @@ -24,13 +24,13 @@ GenerateTraffic (Socket *socket, uint32_t size) } static void -SocketPrinter (Socket *socket, uint32_t size, const Ipv4Address &from, uint16_t fromPort) +SocketPrinter (Ptr socket, uint32_t size, const Ipv4Address &from, uint16_t fromPort) { std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, rx bytes=" << size << std::endl; } static void -PrintTraffic (Socket *socket) +PrintTraffic (Ptr socket) { socket->RecvDummy (MakeCallback (&SocketPrinter)); } @@ -40,17 +40,14 @@ RunSimulation (void) { Ptr a = new InternetNode (); - IUdp *udp; - udp = a->QueryInterface (IUdp::iid); + Ptr udp = a->QueryInterface (IUdp::iid); - Socket *sink = udp->CreateSocket (); + Ptr sink = udp->CreateSocket (); sink->Bind (80); - Socket *source = udp->CreateSocket (); + Ptr source = udp->CreateSocket (); source->Connect (Ipv4Address::GetLoopback (), 80); - udp->Unref (); - GenerateTraffic (source, 500); PrintTraffic (sink); @@ -58,11 +55,6 @@ RunSimulation (void) Simulator::Run (); Simulator::Destroy (); - - sink->Unref (); - source->Unref (); - - std::cout << "o" << std::endl; } int main (int argc, char *argv[]) diff --git a/src/applications/onoff-application.cc b/src/applications/onoff-application.cc index 6c6e6f847..347399791 100644 --- a/src/applications/onoff-application.cc +++ b/src/applications/onoff-application.cc @@ -92,11 +92,7 @@ OnOffApplication::~OnOffApplication() void OnOffApplication::DoDispose (void) { - if (m_socket != 0) - { - m_socket->Unref (); - m_socket = 0; - } + m_socket = 0; delete m_onTime; delete m_offTime; @@ -170,9 +166,8 @@ void OnOffApplication::StartApplication() // Called at time specified by Star this)); #endif - IUdp *udp = GetNode ()->QueryInterface (IUdp::iid); + Ptr udp = GetNode ()->QueryInterface (IUdp::iid); m_socket = udp->CreateSocket (); - udp->Unref (); m_socket->Connect (m_peerIP, m_peerPort); } StopApplication(); // Insure no pending event @@ -263,13 +258,13 @@ void OnOffApplication::SendPacket() ScheduleNextTx(); } -void OnOffApplication::ConnectionSucceeded(Socket*) +void OnOffApplication::ConnectionSucceeded(Ptr) { m_connected = true; ScheduleStartEvent(); } -void OnOffApplication::ConnectionFailed(Socket*) +void OnOffApplication::ConnectionFailed(Ptr) { cout << "OnOffApplication, Connection Failed" << endl; } diff --git a/src/applications/onoff-application.h b/src/applications/onoff-application.h index ff19e7458..0902a2885 100644 --- a/src/applications/onoff-application.h +++ b/src/applications/onoff-application.h @@ -71,7 +71,7 @@ public: // Static methods static void DefaultSize(uint32_t s) { g_defaultSize = s;} public: - Socket * m_socket; // Associated socket + Ptr m_socket; // Associated socket Ipv4Address m_peerIP; // Peer IP address uint16_t m_peerPort; // Peer port bool m_connected; // True if connected @@ -97,9 +97,9 @@ private: void ScheduleNextTx(); void ScheduleStartEvent(); void ScheduleStopEvent(); - void ConnectionSucceeded(Socket*); - void ConnectionFailed(Socket*); - void Ignore(Socket*); + void ConnectionSucceeded(Ptr); + void ConnectionFailed(Ptr); + void Ignore(Ptr); protected: }; diff --git a/src/core/ns-unknown-manager.cc b/src/core/ns-unknown-manager.cc index f20438d4c..6f4ab3bfb 100644 --- a/src/core/ns-unknown-manager.cc +++ b/src/core/ns-unknown-manager.cc @@ -49,10 +49,10 @@ bool operator == (const ClassId &a, const ClassId &b) return a.m_classId == b.m_classId; } -NsUnknown * +Ptr NsUnknownManager::Create (ClassId classId) { - Callback callback = DoGetCallback (classId); + Callback > callback = DoGetCallback (classId); return callback (); } @@ -141,9 +141,8 @@ A::A () m_oneBoolInvoked (false), m_oneUi32Invoked (false) { - B *b = new B (); + ns3::Ptr b = new B (); AddInterface (b); - b->Unref (); } A::A (bool bo) @@ -153,9 +152,8 @@ A::A (bool bo) m_oneUi32Invoked (false), m_bool (bo) { - B *b = new B (); + ns3::Ptr b = new B (); AddInterface (b); - b->Unref (); } A::A (uint32_t i) @@ -165,9 +163,8 @@ A::A (uint32_t i) m_oneUi32Invoked (true), m_ui32 (i) { - B *b = new B (); + ns3::Ptr b = new B (); AddInterface (b); - b->Unref (); } } @@ -189,14 +186,13 @@ NsUnknownManagerTest::RunTests (void) { bool ok = true; - A *a = 0; + Ptr a = 0; a = NsUnknownManager::Create (A::cidZero, A::iid); if (a == 0 || !a->m_zeroInvoked) { ok = false; } - a->Unref (); a = NsUnknownManager::Create (A::cidOneBool, A::iid, true); if (a == 0 || @@ -205,7 +201,6 @@ NsUnknownManagerTest::RunTests (void) { ok = false; } - a->Unref (); a = NsUnknownManager::Create (A::cidOneBool, A::iid, false); if (a == 0 || @@ -214,7 +209,6 @@ NsUnknownManagerTest::RunTests (void) { ok = false; } - a->Unref (); a = NsUnknownManager::Create (A::cidOneUi32, A::iid, 10); if (a == 0 || @@ -223,7 +217,6 @@ NsUnknownManagerTest::RunTests (void) { ok = false; } - a->Unref (); a = NsUnknownManager::Create (A::cidOneUi32, A::iid, (uint32_t)10); if (a == 0 || @@ -232,14 +225,12 @@ NsUnknownManagerTest::RunTests (void) { ok = false; } - a->Unref (); - B *b = NsUnknownManager::Create (A::cidOneUi32, B::iid, 10); + Ptr b = NsUnknownManager::Create (A::cidOneUi32, B::iid, 10); if (b == 0) { ok = false; } - b->Unref (); return ok; } diff --git a/src/core/ns-unknown-manager.h b/src/core/ns-unknown-manager.h index 34440e3ed..c2941b830 100644 --- a/src/core/ns-unknown-manager.h +++ b/src/core/ns-unknown-manager.h @@ -27,6 +27,7 @@ #include "callback.h" #include "ns-unknown.h" #include "fatal-error.h" +#include "ptr.h" namespace ns3 { @@ -82,51 +83,51 @@ public: * Create an instance of the object identified by its * ClassId. This method invokes the default constructor. */ - static NsUnknown *Create (ClassId classId); + static Ptr Create (ClassId classId); /** * \param classId class id of the constructor to invoke. * \param a1 argument to pass to the constructor. * \return a pointer to the instance created. - * \overload NsUnknown *Create (ClassId) + * \overload Create (ClassId) * * Create an instance of the object identified by its * ClassId. */ template - static NsUnknown *Create (ClassId classId, T1 a1); + static Ptr Create (ClassId classId, T1 a1); /** * \param classId class id of the constructor to invoke. * \param a1 first argument to pass to the constructor. * \param a2 second argument to pass to the constructor. * \return a pointer to the instance created. - * \overload NsUnknown *Create (ClassId) + * \overload Create (ClassId) * * Create an instance of the object identified by its * ClassId. */ template - static NsUnknown *Create (ClassId classId, T1 a1, T2 a2); + static Ptr Create (ClassId classId, T1 a1, T2 a2); /** * \param classId class id of the constructor to invoke. * \param iid interface id to query for * \return a pointer to the instance created. - * \overload NsUnknown *Create (ClassId) + * \overload Create (ClassId) * * Create an instance of the object identified by its * ClassId, call QueryInterface on it, and return the * result. */ template - static T *Create (ClassId classId, Iid iid); + static Ptr Create (ClassId classId, Iid iid); template - static T *Create (ClassId classId, Iid iid, T1 a1); + static Ptr Create (ClassId classId, Iid iid, T1 a1); template - static T *Create (ClassId classId, Iid iid, T1 a1, T2 a2); + static Ptr Create (ClassId classId, Iid iid, T1 a1, T2 a2); /** * \param name the symbolic name to associate to this @@ -136,7 +137,7 @@ public: template static ClassId RegisterConstructor (std::string name) { - static Callback callback = + static Callback > callback = MakeCallback (&NsUnknownManager::MakeObjectZero); return NsUnknownManager::Register (name, &callback); } @@ -150,7 +151,7 @@ public: template static ClassId RegisterConstructor (std::string name) { - static Callback callback = MakeCallback (&NsUnknownManager::MakeObjectOne); + static Callback ,T1> callback = MakeCallback (&NsUnknownManager::MakeObjectOne); return NsUnknownManager::Register (name, &callback); } @@ -163,7 +164,7 @@ public: template static ClassId RegisterConstructor (std::string name) { - static Callback callback = MakeCallback (&NsUnknownManager::MakeObjectTwo); + static Callback,T1,T2> callback = MakeCallback (&NsUnknownManager::MakeObjectTwo); return NsUnknownManager::Register (name, &callback); } private: @@ -172,16 +173,16 @@ private: template - static Callback DoGetCallback (ClassId classId); + static Callback,T1,T2,T3,T4,T5> DoGetCallback (ClassId classId); template - static NsUnknown *MakeObjectZero (void); + static Ptr MakeObjectZero (void); template - static NsUnknown *MakeObjectOne (T1 a1); + static Ptr MakeObjectOne (T1 a1); template - static NsUnknown *MakeObjectTwo (T1 a1, T2 a2); + static Ptr MakeObjectTwo (T1 a1, T2 a2); typedef std::vector > List; static List *GetList (void); @@ -196,7 +197,7 @@ namespace ns3 { template -Callback +Callback,T1,T2,T3,T4,T5> NsUnknownManager::DoGetCallback (ClassId classId) { CallbackBase *callback = Lookup (classId); @@ -204,73 +205,70 @@ NsUnknownManager::DoGetCallback (ClassId classId) { NS_FATAL_ERROR ("Invalid Class Id."); } - Callback reference; + Callback, T1,T2,T3,T4,T5> reference; reference.Assign (*callback); return reference; } template -NsUnknown * +Ptr NsUnknownManager::Create (ClassId classId, T1 a1) { - Callback callback = DoGetCallback (classId); + Callback, T1> callback = DoGetCallback (classId); return callback (a1); } template -NsUnknown * +Ptr NsUnknownManager::Create (ClassId classId, T1 a1, T2 a2) { - Callback callback = DoGetCallback (classId); + Callback , T1,T2> callback = DoGetCallback (classId); return callback (a1, a2); } template -T * +Ptr NsUnknownManager::Create (ClassId classId, Iid iid) { - NsUnknown *obj = Create (classId); - T *i = obj->QueryInterface (iid); - obj->Unref (); + Ptr obj = Create (classId); + Ptr i = obj->QueryInterface (iid); return i; } template -T * +Ptr NsUnknownManager::Create (ClassId classId, Iid iid, T1 a1) { - NsUnknown *obj = Create (classId, a1); - T *i = obj->QueryInterface (iid); - obj->Unref (); + Ptr obj = Create (classId, a1); + Ptr i = obj->QueryInterface (iid); return i; } template -T * +Ptr NsUnknownManager::Create (ClassId classId, Iid iid, T1 a1, T2 a2) { - NsUnknown *obj = Create (classId, a1, a2); - T *i = obj->QueryInterface (iid); - obj->Unref (); + Ptr obj = Create (classId, a1, a2); + Ptr i = obj->QueryInterface (iid); return i; } template -NsUnknown * +Ptr NsUnknownManager::MakeObjectZero (void) { return new T (); } template -NsUnknown * +Ptr NsUnknownManager::MakeObjectOne (T1 a1) { return new T (a1); } template -NsUnknown * +Ptr NsUnknownManager::MakeObjectTwo (T1 a1, T2 a2) { return new T (a1, a2); diff --git a/src/core/ns-unknown.cc b/src/core/ns-unknown.cc index b3edea6ad..05d384929 100644 --- a/src/core/ns-unknown.cc +++ b/src/core/ns-unknown.cc @@ -53,9 +53,9 @@ public: void RefAll (NsUnknownImpl *other); void Unref (void); void UnrefAll (void); - NsUnknown *DoQueryInterface (Iid iid) const; + NsUnknown *PeekQueryInterface (Iid iid) const; void DoDisposeAll (void); - void AddInterface (NsUnknown *interface); + void AddInterface (NsUnknown * interface); void AddSelfInterface (Iid iid, NsUnknown *interface); private: typedef std::list > List; @@ -64,7 +64,7 @@ private: bool m_disposed; }; -NsUnknownImpl::NsUnknownImpl (Iid iid, NsUnknown *interface) +NsUnknownImpl::NsUnknownImpl (Iid iid, NsUnknown * interface) : m_ref (0), m_disposed (false) { @@ -124,14 +124,13 @@ NsUnknownImpl::DoDisposeAll (void) m_disposed = true; } NsUnknown * -NsUnknownImpl::DoQueryInterface (Iid iid) const +NsUnknownImpl::PeekQueryInterface (Iid iid) const { for (List::const_iterator i = m_list.begin (); i != m_list.end (); i++) { if (i->first == iid) { - i->second->Ref (); return i->second; } } @@ -206,25 +205,26 @@ NsUnknown::UnrefInternal (void) } } -NsUnknown * +Ptr NsUnknown::DoQueryInterface (Iid iid) const { - return m_impl->DoQueryInterface (iid); + return m_impl->PeekQueryInterface (iid); } void -NsUnknown::AddInterface (NsUnknown *interface) +NsUnknown::AddInterface (Ptr interface) { - m_impl->AddInterface (interface); - m_impl->RefAll (interface->m_impl); - interface->m_impl->UnrefAll (); - interface->m_impl = m_impl; + NsUnknown *p = interface.Peek (); + m_impl->AddInterface (p); + m_impl->RefAll (p->m_impl); + p->m_impl->UnrefAll (); + p->m_impl = m_impl; } void -NsUnknown::AddSelfInterface (Iid iid, NsUnknown *interface) +NsUnknown::AddSelfInterface (Iid iid, Ptr interface) { - m_impl->AddSelfInterface (iid, interface); + m_impl->AddSelfInterface (iid, interface.Peek ()); } @@ -316,31 +316,26 @@ InterfaceTest::RunTests (void) //DerivedAB *derivedAB; - A *a = new A (); - a->Unref (); + Ptr a = new A (); a = new A (); - A *a1 = a->QueryInterface (A::iid); + Ptr a1 = a->QueryInterface (A::iid); if (a1 == 0 || a1 != a) { ok = false; } - a1->Unref (); a1 = a->QueryInterface (A::iid); if (a1 == 0 || a1 != a) { ok = false; } - a1->Unref (); - a->Unref (); - B *b = new B (); - B *b1 = b->QueryInterface (B::iid); + Ptr b = new B (); + Ptr b1 = b->QueryInterface (B::iid); if (b1 == 0 || b1 != b) { ok = false; } - b1->Unref (); a = new A (); a->AddInterface (b); @@ -349,43 +344,33 @@ InterfaceTest::RunTests (void) { ok = false; } - b1->Unref (); a1 = b->QueryInterface (A::iid); if (a1 == 0 || a1 != a) { ok = false; } - a1->Unref (); a1 = a->QueryInterface (A::iid); if (a1 == 0 || a1 != a) { ok = false; } - a1->Unref (); b1 = a->QueryInterface (B::iid); if (b1 == 0 || b1 != b) { ok = false; } - b1->Unref (); - - a->Unref (); - b->Unref (); - Derived *derived = new Derived (); - Base *base = derived->QueryInterface (Base::iid); + Ptr derived = new Derived (); + Ptr base = derived->QueryInterface (Base::iid); if (base == 0) { ok = false; } - Derived *derived1 = base->QueryInterface (Derived::iid); + Ptr derived1 = base->QueryInterface (Derived::iid); if (derived1 == 0 || derived1 != derived) { ok = false; } - derived1->Unref (); - base->Unref (); - derived->Unref (); return ok; } diff --git a/src/core/ns-unknown.h b/src/core/ns-unknown.h index 046407a34..5637d0101 100644 --- a/src/core/ns-unknown.h +++ b/src/core/ns-unknown.h @@ -22,7 +22,7 @@ #define INTERFACE_H #include - +#include "ptr.h" namespace ns3 { @@ -56,7 +56,7 @@ public: * \param iid the NsUnknown id of the requested interface */ template - T *QueryInterface (Iid iid) const; + Ptr QueryInterface (Iid iid) const; /** * \param interface another interface @@ -66,7 +66,7 @@ public: * will be able to perform QI on each other and their lifetimes * will be found by the same reference count. */ - void AddInterface (NsUnknown *interface); + void AddInterface (Ptr interface); void Dispose (void); protected: @@ -87,7 +87,7 @@ protected: * (typically, your subclass has added API), you need to call * this method to associate an interface id to your interface. */ - void AddSelfInterface (Iid iid, NsUnknown *interface); + void AddSelfInterface (Iid iid, Ptr interface); protected: /** * Subclasses who want to handle the "dispose" event should @@ -99,7 +99,7 @@ protected: private: friend class NsUnknownImpl; NsUnknown (); - NsUnknown *DoQueryInterface (Iid iid) const; + Ptr DoQueryInterface (Iid iid) const; void RefInternal (void); void UnrefInternal (void); NsUnknownImpl *m_impl; @@ -111,13 +111,13 @@ private: namespace ns3 { template -T * +Ptr NsUnknown::QueryInterface (Iid iid) const { - NsUnknown *found = DoQueryInterface (iid); + Ptr found = DoQueryInterface (iid); if (found != 0) { - return dynamic_cast (found); + return Ptr (dynamic_cast (found.Peek ())); } return 0; } diff --git a/src/devices/p2p/p2p-channel.cc b/src/devices/p2p/p2p-channel.cc index c0a8342b7..2833c8bb1 100644 --- a/src/devices/p2p/p2p-channel.cc +++ b/src/devices/p2p/p2p-channel.cc @@ -70,11 +70,11 @@ PointToPointChannel::PointToPointChannel( } void -PointToPointChannel::Attach(PointToPointNetDevice *device) +PointToPointChannel::Attach(Ptr device) { NS_DEBUG("PointToPointChannel::Attach (" << device << ")"); NS_ASSERT(m_nDevices < N_DEVICES && "Only two devices permitted"); - NS_ASSERT(device); + NS_ASSERT(device != 0); m_link[m_nDevices].m_src = device; ++m_nDevices; @@ -92,7 +92,7 @@ PointToPointChannel::Attach(PointToPointNetDevice *device) } bool -PointToPointChannel::TransmitStart(Packet& p, PointToPointNetDevice* src) +PointToPointChannel::TransmitStart(Packet& p, Ptr src) { NS_DEBUG ("PointToPointChannel::TransmitStart (" << &p << ", " << src << ")"); @@ -117,7 +117,7 @@ PointToPointChannel::TransmitStart(Packet& p, PointToPointNetDevice* src) } bool -PointToPointChannel::TransmitEnd(Packet& p, PointToPointNetDevice* src) +PointToPointChannel::TransmitEnd(Packet& p, Ptr src) { NS_DEBUG("PointToPointChannel::TransmitEnd (" << &p << ", " << src << ")"); NS_DEBUG ("PointToPointChannel::TransmitEnd (): UID is " << @@ -147,7 +147,7 @@ PointToPointChannel::TransmitEnd(Packet& p, PointToPointNetDevice* src) void PointToPointChannel::PropagationCompleteEvent( Packet p, - PointToPointNetDevice *src) + Ptr src) { NS_DEBUG("PointToPointChannel::PropagationCompleteEvent (" << &p << ", " << src << ")"); @@ -169,7 +169,7 @@ PointToPointChannel::GetNDevices (void) const return m_nDevices; } -NetDevice * +Ptr PointToPointChannel::GetDevice (uint32_t i) const { NS_ASSERT(i < 2); diff --git a/src/devices/p2p/p2p-channel.h b/src/devices/p2p/p2p-channel.h index 13256a2d7..dacdc9c0b 100644 --- a/src/devices/p2p/p2p-channel.h +++ b/src/devices/p2p/p2p-channel.h @@ -21,6 +21,7 @@ #include #include "ns3/channel.h" +#include "ns3/ptr.h" #include "ns3/packet.h" #include "ns3/nstime.h" #include "ns3/data-rate.h" @@ -62,13 +63,13 @@ public: PointToPointChannel (const std::string& name, const DataRate& bps, const Time& delay); - void Attach (PointToPointNetDevice* device); - bool TransmitStart (Packet& p, PointToPointNetDevice *src); - bool TransmitEnd (Packet &p, PointToPointNetDevice *src); - void PropagationCompleteEvent(Packet p, PointToPointNetDevice *src); + void Attach (Ptr device); + bool TransmitStart (Packet& p, Ptr src); + bool TransmitEnd (Packet &p, Ptr src); + void PropagationCompleteEvent(Packet p, Ptr src); virtual uint32_t GetNDevices (void) const; - virtual NetDevice *GetDevice (uint32_t i) const; + virtual Ptr GetDevice (uint32_t i) const; virtual DataRate GetDataRate (void); virtual Time GetDelay (void); @@ -92,8 +93,8 @@ private: public: Link() : m_state (INITIALIZING), m_src (0), m_dst (0) {} WireState m_state; - PointToPointNetDevice *m_src; - PointToPointNetDevice *m_dst; + Ptr m_src; + Ptr m_dst; }; Link m_link[N_DEVICES]; diff --git a/src/devices/p2p/p2p-net-device.cc b/src/devices/p2p/p2p-net-device.cc index 06d8fb269..6fb6edac9 100644 --- a/src/devices/p2p/p2p-net-device.cc +++ b/src/devices/p2p/p2p-net-device.cc @@ -81,18 +81,12 @@ PointToPointNetDevice::PointToPointNetDevice (const PointToPointNetDevice& nd) m_txMachineState(READY), m_bps (nd.m_bps), m_tInterframeGap (nd.m_tInterframeGap), - m_channel(0), + m_channel(nd.m_channel), m_queue(0), m_rxTrace () { NS_DEBUG ("PointToPointNetDevice::PointToPointNetDevice (" << &nd << ")"); - if (nd.m_channel) - { - m_channel = nd.m_channel; - m_channel->Ref (); - } - if (nd.m_queue) { m_queue = nd.m_queue; @@ -102,12 +96,8 @@ PointToPointNetDevice::PointToPointNetDevice (const PointToPointNetDevice& nd) void PointToPointNetDevice::DoDispose() { - if (m_channel != 0) - { - m_channel->Unref (); - m_channel = 0; - } - NetDevice::DoDispose (); + m_channel = 0; + NetDevice::DoDispose (); } // @@ -305,18 +295,11 @@ PointToPointNetDevice::DoCreateTraceResolver (TraceContext const &context) } bool -PointToPointNetDevice::Attach (PointToPointChannel* ch) +PointToPointNetDevice::Attach (Ptr ch) { NS_DEBUG ("PointToPointNetDevice::Attach (" << &ch << ")"); - if (m_channel) - { - m_channel->Unref (); - m_channel = 0; - } - m_channel = ch; - m_channel->Ref (); m_channel->Attach(this); m_bps = m_channel->GetDataRate (); @@ -358,10 +341,9 @@ PointToPointNetDevice::GetQueue(void) const return m_queue; } -Channel* +Ptr PointToPointNetDevice::DoGetChannel(void) const { - m_channel->Ref(); return m_channel; } diff --git a/src/devices/p2p/p2p-net-device.h b/src/devices/p2p/p2p-net-device.h index 2d27921c4..fc4ece354 100644 --- a/src/devices/p2p/p2p-net-device.h +++ b/src/devices/p2p/p2p-net-device.h @@ -140,7 +140,7 @@ public: * @see SetInterframeGap () * @param ch a pointer to the channel to which this object is being attached. */ - bool Attach(PointToPointChannel* ch); + bool Attach(Ptr ch); /** * Attach a queue to the PointToPointNetDevice. * @@ -189,7 +189,7 @@ protected: * @see PointToPointChannel * @returns a pointer to the channel */ - virtual Channel *DoGetChannel(void) const; + virtual Ptr DoGetChannel(void) const; private: /** * Send a Packet Down the Wire. @@ -288,7 +288,7 @@ private: * attached. * @see class PointToPointChannel */ - PointToPointChannel* m_channel; + Ptr m_channel; /** * The Queue which this PointToPointNetDevice uses as a packet source. * Management of this Queue has been delegated to the PointToPointNetDevice diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index 5f024a668..d06093fd4 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -38,38 +38,33 @@ namespace ns3 { -PointToPointChannel * +Ptr PointToPointTopology::AddPointToPointLink( Ptr n1, Ptr n2, const DataRate& bps, const Time& delay) { - PointToPointChannel* channel = new PointToPointChannel(bps, delay); - channel->Ref (); + Ptr channel = new PointToPointChannel(bps, delay); - PointToPointNetDevice* net1 = new PointToPointNetDevice(n1); - net1->Ref (); + Ptr net1 = new PointToPointNetDevice(n1); net1->AddQueue(Queue::Default().Copy()); n1->AddDevice (net1); net1->Attach (channel); - net1->Unref (); - PointToPointNetDevice* net2 = new PointToPointNetDevice(n2); - net2->Ref (); + Ptr net2 = new PointToPointNetDevice(n2); net2->AddQueue(Queue::Default().Copy()); n2->AddDevice (net2); net2->Attach (channel); - net2->Unref (); return channel; } bool PointToPointTopology::AddIpv4Addresses( - const PointToPointChannel *chan, + Ptr chan, Ptr n1, const Ipv4Address& addr1, Ptr n2, const Ipv4Address& addr2) { @@ -81,8 +76,8 @@ PointToPointTopology::AddIpv4Addresses( // The PointToPoint channel is used to find the relevant NetDevices NS_ASSERT (chan->GetNDevices () == 2); - NetDevice* nd1 = chan->GetDevice (0); - NetDevice* nd2 = chan->GetDevice (1); + Ptr nd1 = chan->GetDevice (0); + Ptr nd2 = chan->GetDevice (1); // Make sure that nd1 belongs to n1 and nd2 to n2 if ( (nd1->GetNode ()->GetId () == n2->GetId () ) && (nd2->GetNode ()->GetId () == n1->GetId () ) ) @@ -92,14 +87,14 @@ PointToPointTopology::AddIpv4Addresses( NS_ASSERT (nd1->GetNode ()->GetId () == n1->GetId ()); NS_ASSERT (nd2->GetNode ()->GetId () == n2->GetId ()); - IIpv4 *ip1 = n1->QueryInterface (IIpv4::iid); + Ptr ip1 = n1->QueryInterface (IIpv4::iid); uint32_t index1 = ip1->AddInterface (nd1); ip1->SetAddress (index1, addr1); ip1->SetNetworkMask (index1, netmask); ip1->SetUp (index1); - IIpv4 *ip2 = n2->QueryInterface (IIpv4::iid); + Ptr ip2 = n2->QueryInterface (IIpv4::iid); uint32_t index2 = ip2->AddInterface (nd2); ip2->SetAddress (index2, addr2); @@ -108,10 +103,7 @@ PointToPointTopology::AddIpv4Addresses( ip1->AddHostRouteTo (addr2, index1); ip2->AddHostRouteTo (addr1, index2); - - ip1->Unref (); - ip2->Unref (); - + return true; } @@ -121,18 +113,13 @@ PointToPointTopology::AddIpv4Addresses( // there are possibly multiple devices connecting n1 and n2 (for example // wireless with two devices on different channels) this will return // the first one found. -PointToPointNetDevice* PointToPointTopology::GetNetDevice(Ptr n1, Ptr n2) +Ptr PointToPointTopology::GetNetDevice(Ptr n1, Ptr n2) { - // First get the NetDeviceList capability from node 1 - NetDeviceList* ndl1 = n1->GetNetDeviceList(); - if (!ndl1) return 0; // No devices, return nil - // Get the list of devices - const NetDeviceList::NetDevices_t& dlist = ndl1->GetAll(); for (NetDeviceList::NetDevices_t::const_iterator i = dlist.Begin(); i != dlist.End(); ++i) { // Check each device - NetDevice* nd = *i; // next device - Channel* c = nd->GetChannel(); + Ptr nd = *i; // next device + Ptr c = nd->GetChannel(); if (!c) continue; // No channel if (c->NodeIsPeer(n2)) return nd; // found it } @@ -140,26 +127,26 @@ PointToPointNetDevice* PointToPointTopology::GetNetDevice(Ptr n1, Ptr PointToPointTopology::GetChannel( Ptr n1, Ptr n2 ) { - NetDevice* nd = GetNetDevice(n1, n2); + Ptr nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, so no channel return nd->GetChannel(); } Queue* PointToPointTopology::GetQueue(Ptr n1, Ptr n2) { - NetDevice* nd = GetNetDevice(n1, 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) { - NetDevice* nd = GetNetDevice(n1, n2); + Ptr nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, can't set queue // Add the specified queue to the netdevice return nd->SetQueue(q); @@ -168,22 +155,18 @@ Queue* PointToPointTopology::SetQueue(Ptr n1, Ptr n2, const Queue& q #endif #ifdef GFR -P2PChannel* Topology::AddDuplexLink(Ptr n1, const IPAddr& ip1, +P2PChannel Topology::AddDuplexLink(Ptr n1, const IPAddr& ip1, Ptr n2, const IPAddr& ip2, const Rate& rate, const Time& delay) { - // First get the NetDeviceList capability from each node - NetDeviceList* ndl1 = n1->GetNetDeviceList(); - NetDeviceList* ndl2 = n2->GetNetDeviceList(); - if (!ndl1 || !ndl2) return nil; // Both ends must have NetDeviceList // Get the net devices P2PNetDevice* nd1 = ndl1->Add(P2PNetDevice(n1, rate, nil)); P2PNetDevice* nd2 = ndl2->Add(P2PNetDevice(n1, rate, nd1->GetChannel())); // Not implemented yet. Add appropriate layer 2 protocol for // the net devices. // Get the L3 proto for node 1 and configure it with this device - L3Demux* l3demux1 = n1->GetL3Demux(); - L3Protocol* l3proto1 = nil; + Ptr l3demux1 = n1->GetL3Demux(); + Ptr l3proto1 = nil; // If the node 1 l3 demux exists, find the coresponding l3 protocol if (l3demux1) l3proto1 = l3demux1->Lookup(ip1.L3Proto()); // If the l3 protocol exists, configure this net device. Use a mask @@ -191,8 +174,8 @@ P2PChannel* Topology::AddDuplexLink(Ptr n1, const IPAddr& ip1, // of this link if (l3proto1) l3proto1->AddNetDevice(nd1, ip1, ip1.GetMask(ip1.Size()*8)); // Same for node 2 - L3Demux* l3demux2 = n2->GetL3Demux(); - L3Protocol* l3proto2 = nil; + Ptr l3demux2 = n2->GetL3Demux(); + Ptr l3proto2 = nil; // If the node 2 l3 demux exists, find the coresponding l3 protocol if (l3demux2) l3proto2 = l3demux2->Lookup(ip2.L3Proto()); if (l3proto2) l3proto2->AddNetDevice(nd2, ip2, ip2.GetMask(ip2.Size()*8)); @@ -200,23 +183,23 @@ P2PChannel* Topology::AddDuplexLink(Ptr n1, const IPAddr& ip1, } // Get the channel connecting node n1 to node n2 -Channel* Topology::GetChannel(Ptr n1, Ptr n2) +Ptr Topology::GetChannel(Ptr n1, Ptr n2) { - NetDevice* nd = GetNetDevice(n1, n2); + Ptr nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, so no channel return nd->GetChannel(); } Queue* Topology::GetQueue(Ptr n1, Ptr n2) { - NetDevice* nd = GetNetDevice(n1, 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) { - NetDevice* nd = GetNetDevice(n1, n2); + Ptr nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, can't set queue // Add the specified queue to the netdevice return nd->SetQueue(q); diff --git a/src/devices/p2p/p2p-topology.h b/src/devices/p2p/p2p-topology.h index ecd927ff3..282c3a0a3 100644 --- a/src/devices/p2p/p2p-topology.h +++ b/src/devices/p2p/p2p-topology.h @@ -51,22 +51,22 @@ public: * with the specified IP addresses, with specified maximum transmission rate * and propagation delay. */ - static PointToPointChannel* AddPointToPointLink( + static Ptr AddPointToPointLink( Ptr, Ptr, const DataRate&, const Time&); static bool AddIpv4Addresses( - const PointToPointChannel*, + Ptr, Ptr, const Ipv4Address&, Ptr, const Ipv4Address&); /** * Get the connecting node n1 to node n2 */ - static PointToPointChannel* GetChannel(Ptr, Ptr); + static Ptr GetChannel(Ptr, Ptr); /** * Get the NetDevice connecting node n1 to n2 */ - static PointToPointNetDevice* GetNetDevice(Ptr, Ptr); + static Ptr GetNetDevice(Ptr, Ptr); /** * Get the queue associated with a link between two nodes */ diff --git a/src/internet-node/arp-cache.cc b/src/internet-node/arp-cache.cc index 6a6f71bc9..e9f48561d 100644 --- a/src/internet-node/arp-cache.cc +++ b/src/internet-node/arp-cache.cc @@ -28,24 +28,21 @@ namespace ns3 { -ArpCache::ArpCache (NetDevice *device, Ipv4Interface *interface) +ArpCache::ArpCache (Ptr device, Ipv4Interface *interface) : m_device (device), m_interface (interface), m_aliveTimeout (Seconds (120)), m_deadTimeout (Seconds (100)), m_waitReplyTimeout (Seconds (1)) -{ - m_device->Ref (); -} +{} ArpCache::~ArpCache () { - m_device->Unref (); Flush (); } -NetDevice * -ArpCache::PeekDevice (void) const +Ptr +ArpCache::GetDevice (void) const { return m_device; } diff --git a/src/internet-node/arp-cache.h b/src/internet-node/arp-cache.h index 5923d2ca9..6a1d182be 100644 --- a/src/internet-node/arp-cache.h +++ b/src/internet-node/arp-cache.h @@ -27,6 +27,7 @@ #include "ns3/net-device.h" #include "ns3/ipv4-address.h" #include "ns3/mac-address.h" +#include "ns3/ptr.h" #include "sgi-hashmap.h" namespace ns3 { @@ -38,10 +39,10 @@ class ArpCache { public: class Entry; - ArpCache (NetDevice *device, Ipv4Interface *interface); + ArpCache (Ptr device, Ipv4Interface *interface); ~ArpCache (); - NetDevice *PeekDevice (void) const; + Ptr GetDevice (void) const; Ipv4Interface *GetInterface (void) const; void SetAliveTimeout (Time aliveTimeout); @@ -91,7 +92,7 @@ private: typedef sgi::hash_map Cache; typedef sgi::hash_map::iterator CacheI; - NetDevice *m_device; + Ptr m_device; Ipv4Interface *m_interface; Time m_aliveTimeout; Time m_deadTimeout; diff --git a/src/internet-node/arp-ipv4-interface.cc b/src/internet-node/arp-ipv4-interface.cc index bf80bfe71..509bd241f 100644 --- a/src/internet-node/arp-ipv4-interface.cc +++ b/src/internet-node/arp-ipv4-interface.cc @@ -31,7 +31,7 @@ namespace ns3 { -ArpIpv4Interface::ArpIpv4Interface (Ptr node, NetDevice *device) +ArpIpv4Interface::ArpIpv4Interface (Ptr node, Ptr device) : Ipv4Interface (device), m_node (node) {} @@ -42,10 +42,10 @@ TraceResolver * ArpIpv4Interface::DoCreateTraceResolver (TraceContext const &context) { CompositeTraceResolver *resolver = new CompositeTraceResolver (context); - if (PeekDevice () != 0) + if (GetDevice () != 0) { resolver->Add ("netdevice", - MakeCallback (&NetDevice::CreateTraceResolver, PeekDevice ()), + MakeCallback (&NetDevice::CreateTraceResolver, GetDevice ().Peek ()), ArpIpv4Interface::NETDEVICE); } @@ -55,21 +55,20 @@ ArpIpv4Interface::DoCreateTraceResolver (TraceContext const &context) void ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest) { - NS_ASSERT (PeekDevice () != 0); - if (PeekDevice ()->NeedsArp ()) + NS_ASSERT (GetDevice () != 0); + if (GetDevice ()->NeedsArp ()) { - IArpPrivate * arp = m_node->QueryInterface (IArpPrivate::iid); + Ptr arp = m_node->QueryInterface (IArpPrivate::iid); MacAddress hardwareDestination; - bool found = arp->Lookup (p, dest, PeekDevice (), &hardwareDestination); + bool found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination); if (found) { - PeekDevice ()->Send (p, hardwareDestination, Ipv4::PROT_NUMBER); + GetDevice ()->Send (p, hardwareDestination, Ipv4::PROT_NUMBER); } - arp->Unref (); } else { - PeekDevice ()->Send (p, PeekDevice ()->GetBroadcast (), Ipv4::PROT_NUMBER); + GetDevice ()->Send (p, GetDevice ()->GetBroadcast (), Ipv4::PROT_NUMBER); } } diff --git a/src/internet-node/arp-ipv4-interface.h b/src/internet-node/arp-ipv4-interface.h index d75e7a491..b1c0698f1 100644 --- a/src/internet-node/arp-ipv4-interface.h +++ b/src/internet-node/arp-ipv4-interface.h @@ -43,7 +43,7 @@ class ArpIpv4Interface : public Ipv4Interface NETDEVICE, ARP, }; - ArpIpv4Interface (Ptr node, NetDevice *device); + ArpIpv4Interface (Ptr node, Ptr device); virtual ~ArpIpv4Interface (); private: diff --git a/src/internet-node/arp.cc b/src/internet-node/arp.cc index feb3ed6a0..3a085793e 100644 --- a/src/internet-node/arp.cc +++ b/src/internet-node/arp.cc @@ -63,18 +63,17 @@ Arp::CreateTraceResolver (TraceContext const &context) } ArpCache * -Arp::FindCache (NetDevice *device) +Arp::FindCache (Ptr device) { for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++) { - if ((*i)->PeekDevice () == device) + if ((*i)->GetDevice () == device) { return *i; } } - IIpv4Private *ipv4 = m_node->QueryInterface (IIpv4Private::iid); + Ptr ipv4 = m_node->QueryInterface (IIpv4Private::iid); Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device); - ipv4->Unref (); ArpCache * cache = new ArpCache (device, interface); NS_ASSERT (device->IsBroadcast ()); device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache)); @@ -83,7 +82,7 @@ Arp::FindCache (NetDevice *device) } void -Arp::Receive(Packet& packet, NetDevice *device) +Arp::Receive(Packet& packet, Ptr device) { ArpCache *cache = FindCache (device); ArpHeader arp; @@ -132,7 +131,7 @@ Arp::Receive(Packet& packet, NetDevice *device) } bool Arp::Lookup (Packet &packet, Ipv4Address destination, - NetDevice *device, + Ptr device, MacAddress *hardwareDestination) { ArpCache *cache = FindCache (device); @@ -204,25 +203,25 @@ void Arp::SendArpRequest (ArpCache const *cache, Ipv4Address to) { ArpHeader arp; - arp.SetRequest (cache->PeekDevice ()->GetAddress (), + arp.SetRequest (cache->GetDevice ()->GetAddress (), cache->GetInterface ()->GetAddress (), - cache->PeekDevice ()->GetBroadcast (), + cache->GetDevice ()->GetBroadcast (), to); Packet packet; packet.AddHeader (arp); - cache->PeekDevice ()->Send (packet, cache->PeekDevice ()->GetBroadcast (), PROT_NUMBER); + cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), PROT_NUMBER); } void Arp::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac) { ArpHeader arp; - arp.SetReply (cache->PeekDevice ()->GetAddress (), + arp.SetReply (cache->GetDevice ()->GetAddress (), cache->GetInterface ()->GetAddress (), toMac, toIp); Packet packet; packet.AddHeader (arp); - cache->PeekDevice ()->Send (packet, toMac, PROT_NUMBER); + cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER); } }//namespace ns3 diff --git a/src/internet-node/arp.h b/src/internet-node/arp.h index d436a99a2..0273d5e3b 100644 --- a/src/internet-node/arp.h +++ b/src/internet-node/arp.h @@ -46,15 +46,15 @@ public: virtual TraceResolver *CreateTraceResolver (TraceContext const &context); - virtual void Receive(Packet& p, NetDevice *device); + virtual void Receive(Packet& p, Ptr device); bool Lookup (Packet &p, Ipv4Address destination, - NetDevice *device, + Ptr device, MacAddress *hardwareDestination); protected: virtual void DoDispose (void); private: typedef std::list CacheList; - ArpCache *FindCache (NetDevice *device); + ArpCache *FindCache (Ptr device); void SendArpRequest (ArpCache const *cache, Ipv4Address to); void SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac); CacheList m_cacheList; diff --git a/src/internet-node/i-arp-private.cc b/src/internet-node/i-arp-private.cc index 89b628c27..28cf56f7c 100644 --- a/src/internet-node/i-arp-private.cc +++ b/src/internet-node/i-arp-private.cc @@ -21,17 +21,16 @@ #include "i-arp-private.h" #include "arp.h" #include "ns3/assert.h" +#include "ns3/net-device.h" namespace ns3 { const Iid IArpPrivate::iid ("IArpPrivate"); -IArpPrivate::IArpPrivate (Arp *arp) +IArpPrivate::IArpPrivate (Ptr arp) : NsUnknown (IArpPrivate::iid), m_arp (arp) -{ - m_arp->Ref (); -} +{} IArpPrivate::~IArpPrivate () { NS_ASSERT (m_arp == 0); @@ -39,7 +38,7 @@ IArpPrivate::~IArpPrivate () bool IArpPrivate::Lookup (Packet &p, Ipv4Address destination, - NetDevice *device, + Ptr device, MacAddress *hardwareDestination) { return m_arp->Lookup (p, destination, device, hardwareDestination); @@ -48,7 +47,6 @@ IArpPrivate::Lookup (Packet &p, Ipv4Address destination, void IArpPrivate::DoDispose (void) { - m_arp->Unref (); m_arp = 0; NsUnknown::DoDispose (); } diff --git a/src/internet-node/i-arp-private.h b/src/internet-node/i-arp-private.h index 39aeb04eb..7b3647601 100644 --- a/src/internet-node/i-arp-private.h +++ b/src/internet-node/i-arp-private.h @@ -35,15 +35,15 @@ class IArpPrivate : public NsUnknown { public: static const Iid iid; - IArpPrivate (Arp *arp); + IArpPrivate (Ptr arp); virtual ~IArpPrivate (); bool Lookup (Packet &p, Ipv4Address destination, - NetDevice *device, + Ptr device, MacAddress *hardwareDestination); protected: virtual void DoDispose (void); private: - Arp *m_arp; + Ptr m_arp; }; } // namespace ns3 diff --git a/src/internet-node/i-ipv4-impl.cc b/src/internet-node/i-ipv4-impl.cc index 82b5d0155..6ac4a58cd 100644 --- a/src/internet-node/i-ipv4-impl.cc +++ b/src/internet-node/i-ipv4-impl.cc @@ -21,14 +21,13 @@ #include "i-ipv4-impl.h" #include "ipv4.h" #include "ns3/assert.h" +#include "ns3/net-device.h" namespace ns3 { -IIpv4Impl::IIpv4Impl (Ipv4 *ipv4) +IIpv4Impl::IIpv4Impl (Ptr ipv4) : m_ipv4 (ipv4) -{ - m_ipv4->Ref (); -} +{} IIpv4Impl::~IIpv4Impl () { NS_ASSERT (m_ipv4 == 0); @@ -36,7 +35,6 @@ IIpv4Impl::~IIpv4Impl () void IIpv4Impl::DoDispose (void) { - m_ipv4->Unref (); m_ipv4 = 0; } @@ -90,7 +88,7 @@ IIpv4Impl::RemoveRoute (uint32_t i) return m_ipv4->RemoveRoute (i); } uint32_t -IIpv4Impl::AddInterface (NetDevice *device) +IIpv4Impl::AddInterface (Ptr device) { return m_ipv4->AddInterface (device); } diff --git a/src/internet-node/i-ipv4-impl.h b/src/internet-node/i-ipv4-impl.h index b3240a089..3c9fc1b66 100644 --- a/src/internet-node/i-ipv4-impl.h +++ b/src/internet-node/i-ipv4-impl.h @@ -22,6 +22,7 @@ #define I_IPV4_IMPL_H #include "ns3/i-ipv4.h" +#include "ns3/ptr.h" namespace ns3 { @@ -30,7 +31,7 @@ class Ipv4; class IIpv4Impl : public IIpv4 { public: - IIpv4Impl (Ipv4 *ipv4); + IIpv4Impl (Ptr ipv4); virtual ~IIpv4Impl (); @@ -51,7 +52,7 @@ public: virtual uint32_t GetNRoutes (void); virtual Ipv4Route *GetRoute (uint32_t i); virtual void RemoveRoute (uint32_t i); - virtual uint32_t AddInterface (NetDevice *device); + virtual uint32_t AddInterface (Ptr device); virtual uint32_t GetNInterfaces (void); virtual void SetAddress (uint32_t i, Ipv4Address address); @@ -65,7 +66,7 @@ public: protected: virtual void DoDispose (void); private: - Ipv4 *m_ipv4; + Ptr m_ipv4; }; } // namespace ns3 diff --git a/src/internet-node/i-ipv4-private.cc b/src/internet-node/i-ipv4-private.cc index 2921d5262..95fe4249f 100644 --- a/src/internet-node/i-ipv4-private.cc +++ b/src/internet-node/i-ipv4-private.cc @@ -21,17 +21,16 @@ #include "i-ipv4-private.h" #include "ipv4.h" #include "ns3/assert.h" +#include "ns3/net-device.h" namespace ns3 { const Iid IIpv4Private::iid ("IIpv4Private"); -IIpv4Private::IIpv4Private (Ipv4 *ipv4) +IIpv4Private::IIpv4Private (Ptr ipv4) : NsUnknown (IIpv4Private::iid), m_ipv4 (ipv4) -{ - m_ipv4->Ref (); -} +{} IIpv4Private::~IIpv4Private () { NS_ASSERT (m_ipv4 == 0); @@ -48,19 +47,18 @@ IIpv4Private::Send (Packet const &packet, Ipv4Address source, m_ipv4->Send (packet, source, destination, protocol); } Ipv4Interface * -IIpv4Private::FindInterfaceForDevice (NetDevice const*device) +IIpv4Private::FindInterfaceForDevice (Ptrdevice) { return m_ipv4->FindInterfaceForDevice (device); } void -IIpv4Private::Receive(Packet& p, NetDevice *device) +IIpv4Private::Receive(Packet& p, Ptr device) { m_ipv4->Receive (p, device); } void IIpv4Private::DoDispose (void) { - m_ipv4->Unref (); m_ipv4 = 0; NsUnknown::DoDispose (); } diff --git a/src/internet-node/i-ipv4-private.h b/src/internet-node/i-ipv4-private.h index a300f725f..61df90c96 100644 --- a/src/internet-node/i-ipv4-private.h +++ b/src/internet-node/i-ipv4-private.h @@ -23,6 +23,7 @@ #include "ns3/ns-unknown.h" #include "ns3/ipv4-address.h" +#include "ns3/ptr.h" #include namespace ns3 { @@ -38,18 +39,18 @@ class IIpv4Private : public NsUnknown { public: static const Iid iid; - IIpv4Private (Ipv4 *ipv4); + IIpv4Private (Ptr ipv4); virtual ~IIpv4Private (); TraceResolver *CreateTraceResolver (TraceContext const &context); void Send (Packet const &packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol); - Ipv4Interface *FindInterfaceForDevice (NetDevice const*device); - void Receive(Packet& p, NetDevice *device); + Ipv4Interface *FindInterfaceForDevice (Ptrdevice); + void Receive(Packet& p, Ptr device); protected: virtual void DoDispose (void); private: - Ipv4 *m_ipv4; + Ptr m_ipv4; }; } // namespace ns3 diff --git a/src/internet-node/i-udp-impl.cc b/src/internet-node/i-udp-impl.cc index 00b522f83..b0b094f44 100644 --- a/src/internet-node/i-udp-impl.cc +++ b/src/internet-node/i-udp-impl.cc @@ -20,21 +20,20 @@ */ #include "i-udp-impl.h" #include "udp.h" +#include "ns3/socket.h" #include "ns3/assert.h" namespace ns3 { -IUdpImpl::IUdpImpl (Udp *udp) +IUdpImpl::IUdpImpl (Ptr udp) : m_udp (udp) -{ - m_udp->Ref (); -} +{} IUdpImpl::~IUdpImpl () { NS_ASSERT (m_udp == 0); } -Socket * +Ptr IUdpImpl::CreateSocket (void) { return m_udp->CreateSocket (); @@ -43,11 +42,7 @@ IUdpImpl::CreateSocket (void) void IUdpImpl::DoDispose (void) { - if (m_udp != 0) - { - m_udp->Unref (); - m_udp = 0; - } + m_udp = 0; IUdp::DoDispose (); } diff --git a/src/internet-node/i-udp-impl.h b/src/internet-node/i-udp-impl.h index 5acbac900..7bd9c4bae 100644 --- a/src/internet-node/i-udp-impl.h +++ b/src/internet-node/i-udp-impl.h @@ -22,6 +22,7 @@ #define I_UDP_IMPL_H #include "ns3/i-udp.h" +#include "ns3/ptr.h" namespace ns3 { @@ -30,15 +31,15 @@ class Udp; class IUdpImpl : public IUdp { public: - IUdpImpl (Udp *udp); + IUdpImpl (Ptr udp); virtual ~IUdpImpl (); - virtual Socket *CreateSocket (void); + virtual Ptr CreateSocket (void); protected: virtual void DoDispose (void); private: - Udp *m_udp; + Ptr m_udp; }; } // namespace ns3 diff --git a/src/internet-node/internet-node.cc b/src/internet-node/internet-node.cc index abe48a41d..33902fecf 100644 --- a/src/internet-node/internet-node.cc +++ b/src/internet-node/internet-node.cc @@ -41,35 +41,22 @@ namespace ns3 { InternetNode::InternetNode() { - Ipv4 *ipv4 = new Ipv4 (this); - Arp *arp = new Arp (this); - Udp *udp = new Udp (this); + Ptr ipv4 = new Ipv4 (this); + Ptr arp = new Arp (this); + Ptr udp = new Udp (this); - ipv4->Ref (); - arp->Ref (); - udp->Ref (); - - ApplicationList *applicationList = new ApplicationList(this); - L3Demux *l3Demux = new L3Demux(this); - Ipv4L4Demux *ipv4L4Demux = new Ipv4L4Demux(this); - - applicationList->Ref (); - l3Demux->Ref (); - ipv4L4Demux->Ref (); + Ptr applicationList = new ApplicationList(this); + Ptr l3Demux = new L3Demux(this); + Ptr ipv4L4Demux = new Ipv4L4Demux(this); l3Demux->Insert (ipv4); l3Demux->Insert (arp); ipv4L4Demux->Insert (udp); - IUdpImpl *udpImpl = new IUdpImpl (udp); - IArpPrivate *arpPrivate = new IArpPrivate (arp); - IIpv4Impl *ipv4Impl = new IIpv4Impl (ipv4); - IIpv4Private *ipv4Private = new IIpv4Private (ipv4); - - udpImpl->Ref (); - arpPrivate->Ref (); - ipv4Impl->Ref (); - ipv4Private->Ref (); + Ptr udpImpl = new IUdpImpl (udp); + Ptr arpPrivate = new IArpPrivate (arp); + Ptr ipv4Impl = new IIpv4Impl (ipv4); + Ptr ipv4Private = new IIpv4Private (ipv4); NsUnknown::AddInterface (ipv4Private); NsUnknown::AddInterface (ipv4Impl); @@ -78,18 +65,6 @@ InternetNode::InternetNode() NsUnknown::AddInterface (applicationList); NsUnknown::AddInterface (l3Demux); NsUnknown::AddInterface (ipv4L4Demux); - - - applicationList->Unref (); - l3Demux->Unref (); - ipv4L4Demux->Unref (); - arp->Unref (); - ipv4->Unref (); - udp->Unref (); - udpImpl->Unref (); - arpPrivate->Unref (); - ipv4Impl->Unref (); - ipv4Private->Unref (); } InternetNode::~InternetNode () @@ -105,11 +80,10 @@ TraceResolver * InternetNode::CreateTraceResolver (TraceContext const &context) { CompositeTraceResolver *resolver = new CompositeTraceResolver (context); - IIpv4Private *ipv4 = QueryInterface (IIpv4Private::iid); + Ptr ipv4 = QueryInterface (IIpv4Private::iid); resolver->Add ("ipv4", - MakeCallback (&IIpv4Private::CreateTraceResolver, ipv4), + MakeCallback (&IIpv4Private::CreateTraceResolver, ipv4.Peek ()), InternetNode::IPV4); - ipv4->Unref (); return resolver; } @@ -121,17 +95,16 @@ InternetNode::DoDispose() } void -InternetNode::DoAddDevice (NetDevice *device) const +InternetNode::DoAddDevice (Ptr device) const { device->SetReceiveCallback (MakeCallback (&InternetNode::ReceiveFromDevice, this)); } bool -InternetNode::ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const +InternetNode::ReceiveFromDevice (Ptr device, const Packet &p, uint16_t protocolNumber) const { - L3Demux *demux = QueryInterface (L3Demux::iid); - L3Protocol *target = demux->PeekProtocol (protocolNumber); - demux->Unref (); + Ptr demux = QueryInterface (L3Demux::iid); + Ptr target = demux->GetProtocol (protocolNumber); if (target != 0) { Packet packet = p; diff --git a/src/internet-node/internet-node.h b/src/internet-node/internet-node.h index 835acb870..04da92036 100644 --- a/src/internet-node/internet-node.h +++ b/src/internet-node/internet-node.h @@ -47,8 +47,8 @@ public: protected: virtual void DoDispose(void); private: - virtual void DoAddDevice (NetDevice *device) const; - bool ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const; + virtual void DoAddDevice (Ptr device) const; + bool ReceiveFromDevice (Ptr device, const Packet &p, uint16_t protocolNumber) const; std::string m_name; }; diff --git a/src/internet-node/ipv4-interface.cc b/src/internet-node/ipv4-interface.cc index e8bc9b116..cfc398582 100644 --- a/src/internet-node/ipv4-interface.cc +++ b/src/internet-node/ipv4-interface.cc @@ -31,26 +31,16 @@ namespace ns3 { * becoming useable, the user must invoke SetUp on them * once the final Ipv4 address and mask has been set. */ -Ipv4Interface::Ipv4Interface (NetDevice *nd) +Ipv4Interface::Ipv4Interface (Ptr nd) : m_netdevice (nd), m_ifup(false) -{ - if (m_netdevice != 0) - { - m_netdevice->Ref (); - } -} +{} Ipv4Interface::~Ipv4Interface () -{ - if (m_netdevice != 0) - { - m_netdevice->Unref (); - } -} +{} -NetDevice* -Ipv4Interface::PeekDevice (void) const +Ptr +Ipv4Interface::GetDevice (void) const { return m_netdevice; } diff --git a/src/internet-node/ipv4-interface.h b/src/internet-node/ipv4-interface.h index ef2b56408..1098c567c 100644 --- a/src/internet-node/ipv4-interface.h +++ b/src/internet-node/ipv4-interface.h @@ -25,6 +25,7 @@ #include #include "ns3/ipv4-address.h" +#include "ns3/ptr.h" namespace ns3 { @@ -69,7 +70,7 @@ public: * This value can be zero in which case the MTU * of this interface will be 2^(16-1). */ - Ipv4Interface (NetDevice *nd); + Ipv4Interface (Ptr nd); virtual ~Ipv4Interface(); /** @@ -87,7 +88,7 @@ public: * \returns the underlying NetDevice. This method can return * zero if this interface has no associated NetDevice. */ - NetDevice *PeekDevice (void) const; + Ptr GetDevice (void) const; /** * \param a set the ipv4 address of this interface. @@ -153,7 +154,7 @@ public: private: virtual void SendTo (Packet p, Ipv4Address dest) = 0; virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0; - NetDevice* m_netdevice; + Ptr m_netdevice; bool m_ifup; Ipv4Address m_address; Ipv4Mask m_netmask; diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index 2a026de36..36549a1ee 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -43,10 +43,10 @@ Ipv4L4Demux::~Ipv4L4Demux() void Ipv4L4Demux::DoDispose (void) { - for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) + for (L4List_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) { (*i)->Dispose (); - (*i)->Unref (); + *i = 0; } m_protocols.clear (); m_node = 0; @@ -59,25 +59,24 @@ Ipv4L4Demux::CreateTraceResolver (TraceContext const &context) CompositeTraceResolver *resolver = new CompositeTraceResolver (context); for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) { - Ipv4L4Protocol *protocol = *i; + Ptr protocol = *i; std::string protValue; std::ostringstream oss (protValue); oss << (*i)->GetProtocolNumber (); Ipv4L4ProtocolTraceType protocolNumber = (*i)->GetProtocolNumber (); resolver->Add (protValue, - MakeCallback (&Ipv4L4Protocol::CreateTraceResolver, protocol), + MakeCallback (&Ipv4L4Protocol::CreateTraceResolver, protocol.Peek ()), protocolNumber); } return resolver; } void -Ipv4L4Demux::Insert(Ipv4L4Protocol *protocol) +Ipv4L4Demux::Insert(Ptr protocol) { - protocol->Ref (); m_protocols.push_back (protocol); } -Ipv4L4Protocol* -Ipv4L4Demux::PeekProtocol(int protocolNumber) +Ptr +Ipv4L4Demux::GetProtocol(int protocolNumber) { for (L4List_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) { @@ -89,7 +88,7 @@ Ipv4L4Demux::PeekProtocol(int protocolNumber) return 0; } void -Ipv4L4Demux::Erase(Ipv4L4Protocol*protocol) +Ipv4L4Demux::Erase(Ptr protocol) { m_protocols.remove (protocol); } diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index d52ce34b9..193addab5 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -65,7 +65,7 @@ public: * a working L4 Protocol and returned from this method. * The caller does not get ownership of the returned pointer. */ - void Insert(Ipv4L4Protocol *protocol); + void Insert(Ptr protocol); /** * \param protocolNumber number of protocol to lookup * in this L4 Demux @@ -75,17 +75,17 @@ public: * to forward packets up the stack to the right protocol. * It is also called from InternetNode::GetUdp for example. */ - Ipv4L4Protocol* PeekProtocol(int protocolNumber); + Ptr GetProtocol(int protocolNumber); /** * \param protocol protocol to remove from this demux. * * The input value to this method should be the value * returned from the Ipv4L4Protocol::Insert method. */ - void Erase(Ipv4L4Protocol*protocol); + void Erase (Ptr protocol); private: virtual void DoDispose (void); - typedef std::list L4List_t; + typedef std::list > L4List_t; L4List_t m_protocols; Ptr m_node; }; diff --git a/src/internet-node/ipv4-loopback-interface.cc b/src/internet-node/ipv4-loopback-interface.cc index 6b68dc871..97bffb066 100644 --- a/src/internet-node/ipv4-loopback-interface.cc +++ b/src/internet-node/ipv4-loopback-interface.cc @@ -43,9 +43,8 @@ Ipv4LoopbackInterface::DoCreateTraceResolver (TraceContext const &context) void Ipv4LoopbackInterface::SendTo (Packet packet, Ipv4Address dest) { - IIpv4Private *ipv4 = m_node->QueryInterface (IIpv4Private::iid); - ipv4->Receive (packet, PeekDevice ()); - ipv4->Unref (); + Ptr ipv4 = m_node->QueryInterface (IIpv4Private::iid); + ipv4->Receive (packet, GetDevice ()); } }//namespace ns3 diff --git a/src/internet-node/ipv4.cc b/src/internet-node/ipv4.cc index 6a0697290..14f58f99e 100644 --- a/src/internet-node/ipv4.cc +++ b/src/internet-node/ipv4.cc @@ -27,6 +27,7 @@ #include "ns3/ipv4-address.h" #include "ns3/ipv4-route.h" #include "ns3/node.h" +#include "ns3/net-device.h" #include "ipv4.h" #include "ipv4-l4-protocol.h" @@ -310,7 +311,7 @@ Ipv4::RemoveRoute (uint32_t index) uint32_t -Ipv4::AddInterface (NetDevice *device) +Ipv4::AddInterface (Ptr device) { Ipv4Interface *interface = new ArpIpv4Interface (m_node, device); return AddIpv4Interface (interface); @@ -344,11 +345,11 @@ Ipv4::GetNInterfaces (void) const } Ipv4Interface * -Ipv4::FindInterfaceForDevice (NetDevice const*device) +Ipv4::FindInterfaceForDevice (Ptr device) { for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) { - if ((*i)->PeekDevice () == device) + if ((*i)->GetDevice () == device) { return *i; } @@ -357,12 +358,12 @@ Ipv4::FindInterfaceForDevice (NetDevice const*device) } void -Ipv4::Receive(Packet& packet, NetDevice *device) +Ipv4::Receive(Packet& packet, Ptr device) { uint32_t index = 0; for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) { - if ((*i)->PeekDevice () == device) + if ((*i)->GetDevice () == device) { m_rxTrace (packet, index); break; @@ -442,7 +443,7 @@ Ipv4::SendRealOut (Packet const &p, Ipv4Header const &ip, Ipv4Route const &route bool -Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device) +Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr device) { for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) @@ -458,7 +459,7 @@ Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device) i != m_interfaces.end (); i++) { Ipv4Interface *interface = *i; - if (interface->PeekDevice () == device) + if (interface->GetDevice () == device) { if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ())) { @@ -504,9 +505,8 @@ Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device) void Ipv4::ForwardUp (Packet p, Ipv4Header const&ip) { - Ipv4L4Demux *demux = m_node->QueryInterface (Ipv4L4Demux::iid); - Ipv4L4Protocol *protocol = demux->PeekProtocol (ip.GetProtocol ()); - demux->Unref (); + Ptr demux = m_node->QueryInterface (Ipv4L4Demux::iid); + Ptr protocol = demux->GetProtocol (ip.GetProtocol ()); protocol->Receive (p, ip.GetSource (), ip.GetDestination ()); } diff --git a/src/internet-node/ipv4.h b/src/internet-node/ipv4.h index b041b0e78..1b88f1863 100644 --- a/src/internet-node/ipv4.h +++ b/src/internet-node/ipv4.h @@ -165,7 +165,7 @@ public: * to disable it, you can invoke Ipv4Interface::SetDown which will * make sure that it is never used during packet forwarding. */ - uint32_t AddInterface (NetDevice *device); + uint32_t AddInterface (Ptr device); /** * \param i index of interface to return * \returns the requested interface @@ -182,7 +182,7 @@ public: * Try to find an Ipv4Interface whose NetDevice is equal to * the input NetDevice. */ - Ipv4Interface *FindInterfaceForDevice (NetDevice const*device); + Ipv4Interface *FindInterfaceForDevice (Ptr device); /** @@ -192,7 +192,7 @@ public: * - implement a per-NetDevice ARP cache * - send back arp replies on the right device */ - virtual void Receive(Packet& p, NetDevice *device); + virtual void Receive(Packet& p, Ptr device); /** * \param packet packet to send @@ -220,7 +220,7 @@ protected: virtual void DoDispose (void); private: void SendRealOut (Packet const &packet, Ipv4Header const &ip, Ipv4Route const &route); - bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device); + bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr device); void ForwardUp (Packet p, Ipv4Header const&ip); uint32_t AddIpv4Interface (Ipv4Interface *interface); void SetupLoopback (void); diff --git a/src/internet-node/l3-demux.cc b/src/internet-node/l3-demux.cc index 8f5ddc56f..1388ebb9b 100644 --- a/src/internet-node/l3-demux.cc +++ b/src/internet-node/l3-demux.cc @@ -45,7 +45,7 @@ L3Demux::DoDispose (void) for (L3Map_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) { i->second->Dispose (); - i->second->Unref (); + i->second = 0; } m_protocols.clear (); m_node = 0; @@ -63,23 +63,25 @@ L3Demux::CreateTraceResolver (TraceContext const &context) const oss << i->second->GetProtocolNumber (); ProtocolTraceType context = i->second->GetProtocolNumber (); resolver->Add (protValue, - MakeCallback (&L3Protocol::CreateTraceResolver, i->second), + MakeCallback (&L3Protocol::CreateTraceResolver, i->second.Peek ()), context); } return resolver; } -void L3Demux::Insert(L3Protocol *p) +void L3Demux::Insert(Ptr p) { - p->Ref (); m_protocols.insert(L3Map_t::value_type(p->GetProtocolNumber (), p)); } -L3Protocol* -L3Demux::PeekProtocol (int p) +Ptr +L3Demux::GetProtocol (int p) { // Look up a protocol by protocol number L3Map_t::iterator i = m_protocols.find(p); - if (i == m_protocols.end()) return 0; // Not found + if (i == m_protocols.end()) + { + return 0; + } return i->second; // Return the protocol } diff --git a/src/internet-node/l3-demux.h b/src/internet-node/l3-demux.h index 9e3ffdc0a..18f1cd962 100644 --- a/src/internet-node/l3-demux.h +++ b/src/internet-node/l3-demux.h @@ -68,7 +68,7 @@ public: * a working L3 Protocol and returned from this method. * The caller does not get ownership of the returned pointer. */ - void Insert(ns3::L3Protocol * protocol); + void Insert(Ptr protocol); /** * \param protocolNumber number of protocol to lookup * in this L4 Demux @@ -78,18 +78,18 @@ public: * to forward packets up the stack to the right protocol. * It is also called from InternetNode::GetIpv4 for example. */ - ns3::L3Protocol* PeekProtocol (int protocolNumber); + Ptr GetProtocol (int protocolNumber); /** * \param protocol protocol to remove from this demux. * * The input value to this method should be the value * returned from the L3Protocol::Insert method. */ - void Erase(ns3::L3Protocol*protocol); + void Erase(Ptr protocol); protected: virtual void DoDispose (void); private: - typedef std::map L3Map_t; + typedef std::map > L3Map_t; Ptr m_node; L3Map_t m_protocols; diff --git a/src/internet-node/l3-protocol.h b/src/internet-node/l3-protocol.h index 00d780568..56c6a5914 100644 --- a/src/internet-node/l3-protocol.h +++ b/src/internet-node/l3-protocol.h @@ -26,6 +26,7 @@ #define L3_PROTOCOL_H #include "ns3/object.h" +#include "ns3/ptr.h" namespace ns3 { @@ -53,7 +54,7 @@ public: * - implement a per-NetDevice ARP cache * - send back arp replies on the right device */ - virtual void Receive(Packet& p, NetDevice *device) = 0; + virtual void Receive(Packet& p, Ptr device) = 0; protected: virtual void DoDispose (void); diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 52f0a749d..233376318 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -26,7 +26,7 @@ namespace ns3 { -UdpSocket::UdpSocket (Ptr node, Udp *udp) +UdpSocket::UdpSocket (Ptr node, Ptr udp) : m_endPoint (0), m_node (node), m_udp (udp), @@ -34,9 +34,7 @@ UdpSocket::UdpSocket (Ptr node, Udp *udp) m_shutdownSend (false), m_shutdownRecv (false), m_connected (false) -{ - m_udp->Ref (); -} +{} UdpSocket::~UdpSocket () { m_node = 0; @@ -55,11 +53,7 @@ UdpSocket::~UdpSocket () m_udp->DeAllocate (m_endPoint); NS_ASSERT (m_endPoint == 0); } - if (m_udp != 0) - { - m_udp->Unref (); - m_udp = 0; - } + m_udp = 0; } Ptr @@ -73,11 +67,7 @@ UdpSocket::Destroy (void) { m_node = 0; m_endPoint = 0; - if (m_udp != 0) - { - m_udp->Unref (); - m_udp = 0; - } + m_udp = 0; } int UdpSocket::FinishBind (void) @@ -135,7 +125,7 @@ UdpSocket::ShutdownRecv (void) } void -UdpSocket::DoClose(ns3::Callback closeCompleted) +UdpSocket::DoClose(ns3::Callback > closeCompleted) { // XXX: we should set the close state and check it in all API methods. if (!closeCompleted.IsNull ()) @@ -146,9 +136,9 @@ UdpSocket::DoClose(ns3::Callback closeCompleted) void UdpSocket::DoConnect(const Ipv4Address & address, uint16_t portNumber, - ns3::Callback connectionSucceeded, - ns3::Callback connectionFailed, - ns3::Callback halfClose) + ns3::Callback > connectionSucceeded, + ns3::Callback > connectionFailed, + ns3::Callback > halfClose) { m_defaultAddress = address; m_defaultPort = portNumber; @@ -159,9 +149,9 @@ UdpSocket::DoConnect(const Ipv4Address & address, m_connected = true; } int -UdpSocket::DoAccept(ns3::Callback connectionRequest, - ns3::Callback newConnectionCreated, - ns3::Callback closeRequested) +UdpSocket::DoAccept(ns3::Callback, const Ipv4Address&, uint16_t> connectionRequest, + ns3::Callback, const Ipv4Address&, uint16_t> newConnectionCreated, + ns3::Callback > closeRequested) { // calling accept on a udp socket is a programming error. m_errno = EOPNOTSUPP; @@ -170,7 +160,7 @@ UdpSocket::DoAccept(ns3::Callback c int UdpSocket::DoSend (const uint8_t* buffer, uint32_t size, - ns3::Callback dataSent) + ns3::Callback, uint32_t> dataSent) { if (!m_connected) { @@ -190,7 +180,7 @@ UdpSocket::DoSend (const uint8_t* buffer, } int UdpSocket::DoSendPacketTo (const Packet &p, Ipv4Address daddr, uint16_t dport, - ns3::Callback dataSent) + ns3::Callback, uint32_t> dataSent) { if (m_endPoint == 0) { @@ -219,7 +209,7 @@ UdpSocket::DoSendTo(const Ipv4Address &address, uint16_t port, const uint8_t *buffer, uint32_t size, - ns3::Callback dataSent) + ns3::Callback, uint32_t> dataSent) { if (m_connected) { @@ -238,12 +228,12 @@ UdpSocket::DoSendTo(const Ipv4Address &address, return DoSendPacketTo (p, address, port, dataSent); } void -UdpSocket::DoRecv(ns3::Callback callback) +UdpSocket::DoRecv(ns3::Callback, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> callback) { m_rxCallback = callback; } void -UdpSocket::DoRecvDummy(ns3::Callback callback) +UdpSocket::DoRecvDummy(ns3::Callback, uint32_t,const Ipv4Address&, uint16_t> callback) { m_dummyRxCallback = callback; } diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket.h index cab448b13..9d2d5805e 100644 --- a/src/internet-node/udp-socket.h +++ b/src/internet-node/udp-socket.h @@ -39,7 +39,7 @@ public: /** * Create an unbound udp socket. */ - UdpSocket (Ptr node, Udp *udp); + UdpSocket (Ptr node, Ptr udp); virtual ~UdpSocket (); virtual enum SocketErrno GetErrno (void) const; @@ -52,25 +52,25 @@ public: virtual int ShutdownRecv (void); private: - virtual void DoClose(ns3::Callback closeCompleted); + virtual void DoClose(ns3::Callback > closeCompleted); virtual void DoConnect(const Ipv4Address & address, uint16_t portNumber, - ns3::Callback connectionSucceeded, - ns3::Callback connectionFailed, - ns3::Callback halfClose); - virtual int DoAccept(ns3::Callback connectionRequest, - ns3::Callback newConnectionCreated, - ns3::Callback closeRequested); + ns3::Callback > connectionSucceeded, + ns3::Callback > connectionFailed, + ns3::Callback > halfClose); + virtual int DoAccept(ns3::Callback, const Ipv4Address&, uint16_t> connectionRequest, + ns3::Callback, const Ipv4Address&, uint16_t> newConnectionCreated, + ns3::Callback > closeRequested); virtual int DoSend (const uint8_t* buffer, uint32_t size, - ns3::Callback dataSent); + ns3::Callback, uint32_t> dataSent); virtual int DoSendTo(const Ipv4Address &address, uint16_t port, const uint8_t *buffer, uint32_t size, - ns3::Callback dataSent); - virtual void DoRecv(ns3::Callback); - virtual void DoRecvDummy(ns3::Callback); + ns3::Callback, uint32_t> dataSent); + virtual void DoRecv(ns3::Callback, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t>); + virtual void DoRecvDummy(ns3::Callback, uint32_t,const Ipv4Address&, uint16_t>); private: friend class Udp; @@ -79,15 +79,15 @@ private: void ForwardUp (const Packet &p, Ipv4Address saddr, uint16_t sport); void Destroy (void); int DoSendPacketTo (const Packet &p, Ipv4Address daddr, uint16_t dport, - ns3::Callback dataSent); + ns3::Callback, uint32_t> dataSent); Ipv4EndPoint *m_endPoint; Ptr m_node; - Udp *m_udp; + Ptr m_udp; Ipv4Address m_defaultAddress; uint16_t m_defaultPort; - Callback m_dummyRxCallback; - Callback m_rxCallback; + Callback,uint32_t,const Ipv4Address &,uint16_t> m_dummyRxCallback; + Callback,uint8_t const*,uint32_t,const Ipv4Address &,uint16_t> m_rxCallback; enum SocketErrno m_errno; bool m_shutdownSend; bool m_shutdownRecv; diff --git a/src/internet-node/udp.cc b/src/internet-node/udp.cc index 96bc58056..cc6eef871 100644 --- a/src/internet-node/udp.cc +++ b/src/internet-node/udp.cc @@ -65,11 +65,10 @@ Udp::DoDispose (void) Ipv4L4Protocol::DoDispose (); } -Socket * +Ptr Udp::CreateSocket (void) { - Socket *socket = new UdpSocket (m_node, this); - socket->Ref (); + Ptr socket = new UdpSocket (m_node, this); return socket; } @@ -138,11 +137,10 @@ Udp::Send (Packet packet, packet.AddHeader (udpHeader); - IIpv4Private *ipv4 = m_node->QueryInterface (IIpv4Private::iid); + Ptr ipv4 = m_node->QueryInterface (IIpv4Private::iid); if (ipv4 != 0) { ipv4->Send (packet, saddr, daddr, PROT_NUMBER); - ipv4->Unref (); } } diff --git a/src/internet-node/udp.h b/src/internet-node/udp.h index 5413f1bca..fdb707230 100644 --- a/src/internet-node/udp.h +++ b/src/internet-node/udp.h @@ -46,7 +46,7 @@ public: virtual TraceResolver *CreateTraceResolver (TraceContext const &context); - Socket *CreateSocket (void); + Ptr CreateSocket (void); Ipv4EndPoint *Allocate (void); Ipv4EndPoint *Allocate (Ipv4Address address); diff --git a/src/node/channel.h b/src/node/channel.h index 0afb4da0b..aefbf98b3 100644 --- a/src/node/channel.h +++ b/src/node/channel.h @@ -25,6 +25,7 @@ #include #include #include "ns3/object.h" +#include "ns3/ptr.h" namespace ns3 { @@ -57,7 +58,7 @@ public: * * This method must be implemented by subclasses. */ - virtual NetDevice *GetDevice (uint32_t i) const = 0; + virtual Ptr GetDevice (uint32_t i) const = 0; protected: virtual ~Channel (); diff --git a/src/node/i-ipv4.h b/src/node/i-ipv4.h index 11197de90..27fc31dd8 100644 --- a/src/node/i-ipv4.h +++ b/src/node/i-ipv4.h @@ -116,7 +116,7 @@ public: * to disable it, you can invoke Ipv4Interface::SetDown which will * make sure that it is never used during packet forwarding. */ - virtual uint32_t AddInterface (NetDevice *device) = 0; + virtual uint32_t AddInterface (Ptr device) = 0; /** * \returns the number of interfaces added by the user. */ diff --git a/src/node/i-udp.h b/src/node/i-udp.h index 85163935a..32a92c7ce 100644 --- a/src/node/i-udp.h +++ b/src/node/i-udp.h @@ -22,6 +22,7 @@ #define I_UDP_H #include "ns3/ns-unknown.h" +#include "ns3/ptr.h" namespace ns3 { @@ -34,7 +35,7 @@ public: IUdp (); - virtual Socket *CreateSocket (void) = 0; + virtual Ptr CreateSocket (void) = 0; }; } // namespace ns3 diff --git a/src/node/net-device.cc b/src/node/net-device.cc index 67054e03a..bd5b2946f 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -183,7 +183,7 @@ NetDevice::CreateTraceResolver (TraceContext const &context) return DoCreateTraceResolver (context); } -Channel * +Ptr NetDevice::GetChannel (void) const { return DoGetChannel (); @@ -236,7 +236,7 @@ NetDevice::NeedsArp (void) const } void -NetDevice::SetReceiveCallback (Callback cb) +NetDevice::SetReceiveCallback (Callback,const Packet &,uint16_t> cb) { m_receiveCallback = cb; } diff --git a/src/node/net-device.h b/src/node/net-device.h index 2b7506f1a..78ed233d5 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -79,7 +79,7 @@ public: * returned can be zero if the NetDevice is not yet connected * to any channel. */ - Channel *GetChannel (void) const; + Ptr GetChannel (void) const; /** * \return the current MacAddress of this interface. @@ -174,7 +174,7 @@ public: bool NeedsArp (void) const; - void SetReceiveCallback (Callback cb); + void SetReceiveCallback (Callback,const Packet &,uint16_t> cb); protected: /** @@ -241,7 +241,7 @@ public: virtual bool SendTo (Packet& p, const MacAddress& dest) = 0; virtual bool DoNeedsArp (void) const = 0; virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0; - virtual Channel *DoGetChannel (void) const = 0; + virtual Ptr DoGetChannel (void) const = 0; Ptr m_node; std::string m_name; uint16_t m_ifIndex; @@ -253,7 +253,7 @@ public: bool m_isMulticast; bool m_isPointToPoint; Callback m_linkChangeCallback; - Callback m_receiveCallback; + Callback,const Packet &,uint16_t> m_receiveCallback; }; }; // namespace ns3 diff --git a/src/node/node.cc b/src/node/node.cc index baf74d17c..a23fdde35 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -69,16 +69,15 @@ Node::SetSystemId(uint32_t s ) } uint32_t -Node::AddDevice (NetDevice *device) +Node::AddDevice (Ptr device) { - device->Ref (); uint32_t index = m_devices.size (); m_devices.push_back (device); DoAddDevice (device); device->SetIfIndex(index); return index; } -NetDevice * +Ptr Node::GetDevice (uint32_t index) const { return m_devices[index]; @@ -91,12 +90,12 @@ Node::GetNDevices (void) const void Node::DoDispose() { - for (std::vector::iterator i = m_devices.begin (); + for (std::vector >::iterator i = m_devices.begin (); i != m_devices.end (); i++) { - NetDevice *device = *i; + Ptr device = *i; device->Dispose (); - device->Unref (); + *i = 0; } m_devices.clear (); NsUnknown::DoDispose (); diff --git a/src/node/node.h b/src/node/node.h index 4b072cc3e..e5b30e1da 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -50,18 +50,18 @@ public: uint32_t GetSystemId (void) const; void SetSystemId(uint32_t s); - uint32_t AddDevice (NetDevice *device); - NetDevice *GetDevice (uint32_t index) const; + uint32_t AddDevice (Ptr device); + Ptr GetDevice (uint32_t index) const; uint32_t GetNDevices (void) const; protected: virtual void DoDispose (void); private: - virtual void DoAddDevice (NetDevice *device) const = 0; + virtual void DoAddDevice (Ptr device) const = 0; uint32_t m_id; // Node id for this node uint32_t m_sid; // System id for this node - std::vector m_devices; + std::vector > m_devices; }; } //namespace ns3 diff --git a/src/node/socket.cc b/src/node/socket.cc index 577bb8bae..75cd3a023 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -6,7 +6,7 @@ Socket::~Socket () {} void -Socket::Close(Callback closeCompleted) +Socket::Close(Callback > closeCompleted) { DoClose (closeCompleted); } @@ -14,23 +14,23 @@ Socket::Close(Callback closeCompleted) void Socket::Connect(const Ipv4Address & address, uint16_t portNumber, - Callback connectionSucceeded, - Callback connectionFailed, - Callback halfClose) + Callback > connectionSucceeded, + Callback > connectionFailed, + Callback > halfClose) { DoConnect (address, portNumber, connectionSucceeded, connectionFailed, halfClose); } int -Socket::Accept(Callback connectionRequest, - Callback newConnectionCreated, - Callback closeRequested) +Socket::Accept(Callback, const Ipv4Address&, uint16_t> connectionRequest, + Callback, const Ipv4Address&, uint16_t> newConnectionCreated, + Callback > closeRequested) { return DoAccept (connectionRequest, newConnectionCreated, closeRequested); } int Socket::Send (const uint8_t* buffer, uint32_t size, - Callback dataSent) + Callback, uint32_t> dataSent) { return DoSend (buffer, size, dataSent); } @@ -39,42 +39,42 @@ Socket::SendTo(const Ipv4Address &address, uint16_t port, const uint8_t *buffer, uint32_t size, - Callback dataSent) + Callback, uint32_t> dataSent) { return DoSendTo (address, port, buffer, size, dataSent); } void -Socket::Recv(Callback callback) +Socket::Recv(Callback, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> callback) { DoRecv (callback); } void -Socket::RecvDummy(Callback callback) +Socket::RecvDummy(Callback, uint32_t,const Ipv4Address&, uint16_t> callback) { DoRecvDummy (callback); } bool -Socket::RefuseAllConnections (Socket* socket, const Ipv4Address& address, uint16_t port) +Socket::RefuseAllConnections (Ptr socket, const Ipv4Address& address, uint16_t port) { return false; } void -Socket::DummyCallbackVoidSocket (Socket *socket) +Socket::DummyCallbackVoidSocket (Ptr socket) {} void -Socket::DummyCallbackVoidSocketUi32 (Socket *socket, uint32_t) +Socket::DummyCallbackVoidSocketUi32 (Ptr socket, uint32_t) {} void -Socket::DummyCallbackVoidSocketUi32Ipv4AddressUi16 (Socket *socket, uint32_t, const Ipv4Address &, uint16_t) +Socket::DummyCallbackVoidSocketUi32Ipv4AddressUi16 (Ptr socket, uint32_t, const Ipv4Address &, uint16_t) {} void -Socket::DummyCallbackVoidSocketBufferUi32Ipv4AddressUi16 (Socket *socket, const uint8_t *, uint32_t, +Socket::DummyCallbackVoidSocketBufferUi32Ipv4AddressUi16 (Ptr socket, const uint8_t *, uint32_t, const Ipv4Address &, uint16_t) {} void -Socket::DummyCallbackVoidSocketIpv4AddressUi16 (Socket *socket, const Ipv4Address &, uint16_t) +Socket::DummyCallbackVoidSocketIpv4AddressUi16 (Ptr socket, const Ipv4Address &, uint16_t) {} diff --git a/src/node/socket.h b/src/node/socket.h index 396b79d71..82769b405 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -114,7 +114,7 @@ public: * After the Close call, the socket is no longer valid, and cannot * safely be used for subsequent operations. */ - void Close(Callback closeCompleted = MakeCallback (&Socket::DummyCallbackVoidSocket)); + void Close(Callback > closeCompleted = MakeCallback (&Socket::DummyCallbackVoidSocket)); /** * \returns zero on success, -1 on failure. @@ -147,9 +147,9 @@ public: */ void Connect(const Ipv4Address & address, uint16_t portNumber, - Callback connectionSucceeded = MakeCallback(&Socket::DummyCallbackVoidSocket), - Callback connectionFailed = MakeCallback(&Socket::DummyCallbackVoidSocket), - Callback halfClose = MakeCallback(&Socket::DummyCallbackVoidSocket)); + Callback > connectionSucceeded = MakeCallback(&Socket::DummyCallbackVoidSocket), + Callback > connectionFailed = MakeCallback(&Socket::DummyCallbackVoidSocket), + Callback > halfClose = MakeCallback(&Socket::DummyCallbackVoidSocket)); /** * \brief Accept connection requests from remote hosts @@ -170,11 +170,11 @@ public: * \param closeRequested Callback for connection close request from peer. * XXX: when is this callback invoked ? */ - int Accept(Callback connectionRequest = + int Accept(Callback, const Ipv4Address&, uint16_t> connectionRequest = MakeCallback(&Socket::RefuseAllConnections), - Callback newConnectionCreated = + Callback, const Ipv4Address&, uint16_t> newConnectionCreated = MakeCallback (&Socket::DummyCallbackVoidSocketIpv4AddressUi16), - Callback closeRequested = MakeCallback (&Socket::DummyCallbackVoidSocket)); + Callback > closeRequested = MakeCallback (&Socket::DummyCallbackVoidSocket)); /** * \brief Send data (or dummy data) to the remote host @@ -186,7 +186,7 @@ public: */ int Send (const uint8_t* buffer, uint32_t size, - Callback dataSent = MakeCallback (&Socket::DummyCallbackVoidSocketUi32)); + Callback, uint32_t> dataSent = MakeCallback (&Socket::DummyCallbackVoidSocketUi32)); /** * \brief Send data to a specified peer. @@ -202,7 +202,7 @@ public: uint16_t port, const uint8_t *buffer, uint32_t size, - Callback dataSent = MakeCallback (&Socket::DummyCallbackVoidSocketUi32)); + Callback, uint32_t> dataSent = MakeCallback (&Socket::DummyCallbackVoidSocketUi32)); /** * \brief Receive data @@ -213,7 +213,7 @@ public: * allocation to hold the dummy memory into a buffer which can be passed * to the user. Instead, consider using the RecvDummy method. */ - void Recv(Callback = + void Recv(Callback, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> = MakeCallback (&Socket::DummyCallbackVoidSocketBufferUi32Ipv4AddressUi16)); /** @@ -223,38 +223,38 @@ public: * This method is included because it is vastly more efficient than the * Recv method when you use dummy payload. */ - void RecvDummy(Callback = + void RecvDummy(Callback, uint32_t,const Ipv4Address&, uint16_t> = MakeCallback (&Socket::DummyCallbackVoidSocketUi32Ipv4AddressUi16)); private: - virtual void DoClose(Callback closeCompleted) = 0; + virtual void DoClose(Callback > closeCompleted) = 0; virtual void DoConnect(const Ipv4Address & address, uint16_t portNumber, - Callback connectionSucceeded, - Callback connectionFailed, - Callback halfClose) = 0; - virtual int DoAccept(Callback connectionRequest, - Callback newConnectionCreated, - Callback closeRequested) = 0; + Callback > connectionSucceeded, + Callback > connectionFailed, + Callback > halfClose) = 0; + virtual int DoAccept(Callback, const Ipv4Address&, uint16_t> connectionRequest, + Callback, const Ipv4Address&, uint16_t> newConnectionCreated, + Callback > closeRequested) = 0; virtual int DoSend (const uint8_t* buffer, uint32_t size, - Callback dataSent) = 0; + Callback, uint32_t> dataSent) = 0; virtual int DoSendTo(const Ipv4Address &address, uint16_t port, const uint8_t *buffer, uint32_t size, - Callback dataSent) = 0; - virtual void DoRecv(Callback receive) = 0; - virtual void DoRecvDummy(Callback) = 0; + Callback, uint32_t> dataSent) = 0; + virtual void DoRecv(Callback, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> receive) = 0; + virtual void DoRecvDummy(Callback, uint32_t,const Ipv4Address&, uint16_t>) = 0; - static bool RefuseAllConnections (Socket* socket, const Ipv4Address& address, uint16_t port); - static void DummyCallbackVoidSocket (Socket *socket); - static void DummyCallbackVoidSocketUi32 (Socket *socket, uint32_t); - static void DummyCallbackVoidSocketUi32Ipv4AddressUi16 (Socket *socket, uint32_t, const Ipv4Address &, uint16_t); - static void DummyCallbackVoidSocketBufferUi32Ipv4AddressUi16 (Socket *socket, const uint8_t *, uint32_t, + static bool RefuseAllConnections (Ptr socket, const Ipv4Address& address, uint16_t port); + static void DummyCallbackVoidSocket (Ptr socket); + static void DummyCallbackVoidSocketUi32 (Ptr socket, uint32_t); + static void DummyCallbackVoidSocketUi32Ipv4AddressUi16 (Ptr socket, uint32_t, const Ipv4Address &, uint16_t); + static void DummyCallbackVoidSocketBufferUi32Ipv4AddressUi16 (Ptr socket, const uint8_t *, uint32_t, const Ipv4Address &, uint16_t); - static void DummyCallbackVoidSocketIpv4AddressUi16 (Socket *socket, const Ipv4Address &, uint16_t); + static void DummyCallbackVoidSocketIpv4AddressUi16 (Ptr socket, const Ipv4Address &, uint16_t); }; } //namespace ns3 From 0e1388a2fdb9b69c28d63fb4678a294ba5947859 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 08:35:41 +0200 Subject: [PATCH 27/59] add MakeNewObject template function and fix operator == (T1,T2) --- src/core/ptr.cc | 36 +++++++++++------------ src/core/ptr.h | 78 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 94 insertions(+), 20 deletions(-) diff --git a/src/core/ptr.cc b/src/core/ptr.cc index f488c51f9..ff94eaeca 100644 --- a/src/core/ptr.cc +++ b/src/core/ptr.cc @@ -93,7 +93,7 @@ PtrTest::RunTests (void) Callback cb = MakeCallback (&PtrTest::DestroyNotify, this); m_nDestroyed = false; { - Ptr p = new NoCount (cb); + Ptr p = MakeNewObject (cb); } if (m_nDestroyed != 1) { @@ -103,7 +103,7 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p; - p = new NoCount (cb); + p = MakeNewObject (cb); p = p; } if (m_nDestroyed != 1) @@ -114,7 +114,7 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p1; - p1 = new NoCount (cb); + p1 = MakeNewObject (cb); Ptr p2 = p1; } if (m_nDestroyed != 1) @@ -125,7 +125,7 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p1; - p1 = new NoCount (cb); + p1 = MakeNewObject (cb); Ptr p2; p2 = p1; } @@ -137,8 +137,8 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p1; - p1 = new NoCount (cb); - Ptr p2 = new NoCount (cb); + p1 = MakeNewObject (cb); + Ptr p2 = MakeNewObject (cb); p2 = p1; } if (m_nDestroyed != 2) @@ -149,9 +149,9 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p1; - p1 = new NoCount (cb); + p1 = MakeNewObject (cb); Ptr p2; - p2 = new NoCount (cb); + p2 = MakeNewObject (cb); p2 = p1; } if (m_nDestroyed != 2) @@ -162,8 +162,8 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p1; - p1 = new NoCount (cb); - p1 = new NoCount (cb); + p1 = MakeNewObject (cb); + p1 = MakeNewObject (cb); } if (m_nDestroyed != 2) { @@ -175,8 +175,8 @@ PtrTest::RunTests (void) Ptr p1; { Ptr p2; - p1 = new NoCount (cb); - p2 = new NoCount (cb); + p1 = MakeNewObject (cb); + p2 = MakeNewObject (cb); p2 = p1; } if (m_nDestroyed != 1) @@ -194,8 +194,8 @@ PtrTest::RunTests (void) Ptr p1; { Ptr p2; - p1 = new NoCount (cb); - p2 = new NoCount (cb); + p1 = MakeNewObject (cb); + p2 = MakeNewObject (cb); p2 = CallTest (p1); } if (m_nDestroyed != 1) @@ -237,7 +237,7 @@ PtrTest::RunTests (void) { NoCount *raw; { - Ptr p = new NoCount (cb); + Ptr p = MakeNewObject (cb); { Ptr p1 = p; } @@ -254,7 +254,7 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { - Ptr p = new NoCount (cb); + Ptr p = MakeNewObject (cb); const NoCount *v1 = p.Peek(); NoCount *v2 = p.Peek(); v1->Nothing (); @@ -266,8 +266,8 @@ PtrTest::RunTests (void) } { - Ptr p0 = new NoCount (cb); - Ptr p1 = new NoCount (cb); + Ptr p0 = MakeNewObject (cb); + Ptr p1 = MakeNewObject (cb); if (p0 == p1) { ok = false; diff --git a/src/core/ptr.h b/src/core/ptr.h index b95ce9c5d..7be684ea5 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -123,6 +123,80 @@ public: }; +template +Ptr MakeNewObject (void); + +template +Ptr MakeNewObject (T1 a1); + +template +Ptr MakeNewObject (T1 a1, T2 a2); + +template +Ptr MakeNewObject (T1 a1, T2 a2, T3 a3); + +template +Ptr MakeNewObject (T1 a1, T2 a2, T3 a3, T4 a4); + +template +Ptr MakeNewObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + + +template +Ptr MakeNewObject (void) +{ + T *obj = new T (); + Ptr p = obj; + obj->Unref (); + return p; +} + +template +Ptr MakeNewObject (T1 a1) +{ + T *obj = new T (a1); + Ptr p = obj; + obj->Unref (); + return p; +} + +template +Ptr MakeNewObject (T1 a1, T2 a2) +{ + T *obj = new T (a1, a2); + Ptr p = obj; + obj->Unref (); + return p; +} + +template +Ptr MakeNewObject (T1 a1, T2 a2, T3 a3) +{ + T *obj = new T (a1, a2, a3); + Ptr p = obj; + obj->Unref (); + return p; +} + +template +Ptr MakeNewObject (T1 a1, T2 a2, T3 a3, T4 a4) +{ + T *obj = new T (a1, a2, a3, a4); + Ptr p = obj; + obj->Unref (); + return p; +} + +template +Ptr MakeNewObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) +{ + T *obj = new T (a1, a2, a3, a4, a5); + Ptr p = obj; + obj->Unref (); + return p; +} + + template void Ptr::Acquire (void) const @@ -262,13 +336,13 @@ template bool operator == (Ptr const &lhs, Ptr const &rhs) { - return lhs.Get () == rhs.Get (); + return lhs.Peek () == rhs.Peek (); } template bool operator != (Ptr const &lhs, Ptr const &rhs) { - return lhs.Get () != rhs.Get (); + return lhs.Peek () != rhs.Peek (); } From d82a6d11f922df18f980da75f0cf1cdd77494ec9 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 08:59:11 +0200 Subject: [PATCH 28/59] add MakeNewObject template with more arguments --- src/core/ptr.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/core/ptr.h b/src/core/ptr.h index 7be684ea5..ffbc1e7fd 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -141,6 +141,12 @@ Ptr MakeNewObject (T1 a1, T2 a2, T3 a3, T4 a4); template Ptr MakeNewObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); +template +Ptr MakeNewObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6); + +template +Ptr MakeNewObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7); + template Ptr MakeNewObject (void) @@ -196,6 +202,24 @@ Ptr MakeNewObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) return p; } +template +Ptr MakeNewObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) +{ + T *obj = new T (a1, a2, a3, a4, a5, a6); + Ptr p = obj; + obj->Unref (); + return p; +} + +template +Ptr MakeNewObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7) +{ + T *obj = new T (a1, a2, a3, a4, a5, a6, a7); + Ptr p = obj; + obj->Unref (); + return p; +} + template void From 720fae1bbef433608efd7b1ff66193a541e5a85f Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 08:59:49 +0200 Subject: [PATCH 29/59] rework the refcounting framework to use the MakeNewObject function --- examples/simple-p2p.cc | 12 ++++++------ samples/main-simple.cc | 2 +- src/core/ns-unknown-manager.cc | 6 +++--- src/core/ns-unknown-manager.h | 6 +++--- src/core/ns-unknown.cc | 12 ++++++------ src/core/object.cc | 2 +- src/devices/p2p/p2p-topology.cc | 6 +++--- src/internet-node/internet-node.cc | 20 ++++++++++---------- src/internet-node/udp.cc | 2 +- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index 461782eef..09f8721d8 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -101,10 +101,10 @@ int main (int argc, char *argv[]) // Here, we will explicitly create four nodes. In more sophisticated // topologies, we could configure a node factory. - Ptr n0 = new InternetNode (); - Ptr n1 = new InternetNode (); - Ptr n2 = new InternetNode (); - Ptr n3 = new InternetNode (); + Ptr n0 = MakeNewObject (); + Ptr n1 = MakeNewObject (); + Ptr n2 = MakeNewObject (); + Ptr n3 = MakeNewObject (); // We create the channels first without any IP addressing information Ptr channel0 = @@ -134,7 +134,7 @@ int main (int argc, char *argv[]) // Create the OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s - Ptr ooff0 = new OnOffApplication( + Ptr ooff0 = MakeNewObject ( n0, Ipv4Address("10.1.3.2"), 80, @@ -151,7 +151,7 @@ int main (int argc, char *argv[]) ooff0->Stop (Seconds(10.0)); // Create a similar flow from n3 to n1, starting at time 1.1 seconds - Ptr ooff1 = new OnOffApplication( + Ptr ooff1 = MakeNewObject ( n3, Ipv4Address("10.1.2.1"), 80, diff --git a/samples/main-simple.cc b/samples/main-simple.cc index db6f57736..186035b97 100644 --- a/samples/main-simple.cc +++ b/samples/main-simple.cc @@ -38,7 +38,7 @@ PrintTraffic (Ptr socket) void RunSimulation (void) { - Ptr a = new InternetNode (); + Ptr a = MakeNewObject (); Ptr udp = a->QueryInterface (IUdp::iid); diff --git a/src/core/ns-unknown-manager.cc b/src/core/ns-unknown-manager.cc index 6f4ab3bfb..46dbb2a12 100644 --- a/src/core/ns-unknown-manager.cc +++ b/src/core/ns-unknown-manager.cc @@ -141,7 +141,7 @@ A::A () m_oneBoolInvoked (false), m_oneUi32Invoked (false) { - ns3::Ptr b = new B (); + ns3::Ptr b = ns3::MakeNewObject (); AddInterface (b); } @@ -152,7 +152,7 @@ A::A (bool bo) m_oneUi32Invoked (false), m_bool (bo) { - ns3::Ptr b = new B (); + ns3::Ptr b = ns3::MakeNewObject (); AddInterface (b); } @@ -163,7 +163,7 @@ A::A (uint32_t i) m_oneUi32Invoked (true), m_ui32 (i) { - ns3::Ptr b = new B (); + ns3::Ptr b = ns3::MakeNewObject (); AddInterface (b); } diff --git a/src/core/ns-unknown-manager.h b/src/core/ns-unknown-manager.h index c2941b830..85987fb5a 100644 --- a/src/core/ns-unknown-manager.h +++ b/src/core/ns-unknown-manager.h @@ -259,19 +259,19 @@ template Ptr NsUnknownManager::MakeObjectZero (void) { - return new T (); + return MakeNewObject (); } template Ptr NsUnknownManager::MakeObjectOne (T1 a1) { - return new T (a1); + return MakeNewObject (a1); } template Ptr NsUnknownManager::MakeObjectTwo (T1 a1, T2 a2) { - return new T (a1, a2); + return MakeNewObject (a1, a2); } } // namespace ns3 diff --git a/src/core/ns-unknown.cc b/src/core/ns-unknown.cc index 05d384929..15f433c1b 100644 --- a/src/core/ns-unknown.cc +++ b/src/core/ns-unknown.cc @@ -65,7 +65,7 @@ private: }; NsUnknownImpl::NsUnknownImpl (Iid iid, NsUnknown * interface) - : m_ref (0), + : m_ref (1), m_disposed (false) { NS_DEBUG ("new " << this << " ref=" << m_ref); @@ -316,9 +316,9 @@ InterfaceTest::RunTests (void) //DerivedAB *derivedAB; - Ptr a = new A (); + Ptr a = MakeNewObject (); - a = new A (); + a = MakeNewObject (); Ptr a1 = a->QueryInterface (A::iid); if (a1 == 0 || a1 != a) { @@ -330,14 +330,14 @@ InterfaceTest::RunTests (void) ok = false; } - Ptr b = new B (); + Ptr b = MakeNewObject (); Ptr b1 = b->QueryInterface (B::iid); if (b1 == 0 || b1 != b) { ok = false; } - a = new A (); + a = MakeNewObject (); a->AddInterface (b); b1 = b->QueryInterface (B::iid); if (b1 == 0 || b1 != b) @@ -360,7 +360,7 @@ InterfaceTest::RunTests (void) ok = false; } - Ptr derived = new Derived (); + Ptr derived = MakeNewObject (); Ptr base = derived->QueryInterface (Base::iid); if (base == 0) { diff --git a/src/core/object.cc b/src/core/object.cc index 77bfbe76f..6dc61b4b7 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -27,7 +27,7 @@ NS_DEBUG_COMPONENT_DEFINE ("Object"); namespace ns3 { Object::Object () - : m_count (0), + : m_count (1), m_disposed (false) { NS_DEBUG ("Object::Object: m_count=0"); diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index d06093fd4..730c7e74f 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -45,15 +45,15 @@ PointToPointTopology::AddPointToPointLink( const DataRate& bps, const Time& delay) { - Ptr channel = new PointToPointChannel(bps, delay); + Ptr channel = MakeNewObject (bps, delay); - Ptr net1 = new PointToPointNetDevice(n1); + Ptr net1 = MakeNewObject (n1); net1->AddQueue(Queue::Default().Copy()); n1->AddDevice (net1); net1->Attach (channel); - Ptr net2 = new PointToPointNetDevice(n2); + Ptr net2 = MakeNewObject (n2); net2->AddQueue(Queue::Default().Copy()); n2->AddDevice (net2); diff --git a/src/internet-node/internet-node.cc b/src/internet-node/internet-node.cc index 33902fecf..d2e8d2ae4 100644 --- a/src/internet-node/internet-node.cc +++ b/src/internet-node/internet-node.cc @@ -41,22 +41,22 @@ namespace ns3 { InternetNode::InternetNode() { - Ptr ipv4 = new Ipv4 (this); - Ptr arp = new Arp (this); - Ptr udp = new Udp (this); + Ptr ipv4 = MakeNewObject (this); + Ptr arp = MakeNewObject (this); + Ptr udp = MakeNewObject (this); - Ptr applicationList = new ApplicationList(this); - Ptr l3Demux = new L3Demux(this); - Ptr ipv4L4Demux = new Ipv4L4Demux(this); + Ptr applicationList = MakeNewObject (this); + Ptr l3Demux = MakeNewObject (this); + Ptr ipv4L4Demux = MakeNewObject (this); l3Demux->Insert (ipv4); l3Demux->Insert (arp); ipv4L4Demux->Insert (udp); - Ptr udpImpl = new IUdpImpl (udp); - Ptr arpPrivate = new IArpPrivate (arp); - Ptr ipv4Impl = new IIpv4Impl (ipv4); - Ptr ipv4Private = new IIpv4Private (ipv4); + Ptr udpImpl = MakeNewObject (udp); + Ptr arpPrivate = MakeNewObject (arp); + Ptr ipv4Impl = MakeNewObject (ipv4); + Ptr ipv4Private = MakeNewObject (ipv4); NsUnknown::AddInterface (ipv4Private); NsUnknown::AddInterface (ipv4Impl); diff --git a/src/internet-node/udp.cc b/src/internet-node/udp.cc index cc6eef871..8a0ffc55a 100644 --- a/src/internet-node/udp.cc +++ b/src/internet-node/udp.cc @@ -68,7 +68,7 @@ Udp::DoDispose (void) Ptr Udp::CreateSocket (void) { - Ptr socket = new UdpSocket (m_node, this); + Ptr socket = MakeNewObject (m_node, this); return socket; } From bc15f7157e94b918b995884da1fcd49fc3013746 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 09:11:49 +0200 Subject: [PATCH 30/59] remove useless assignments --- examples/simple-p2p.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index 09f8721d8..ca2bd1e78 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -173,11 +173,6 @@ int main (int argc, char *argv[]) ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); ipv4 = n3->QueryInterface (IIpv4::iid); ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1); - - n0 = 0; - n1 = 0; - n2 = 0; - n3 = 0; // Configure tracing of all enqueue, dequeue, and NetDevice receive events // Trace output will be sent to the simple-p2p.tr file From 24d19e29c0ec0e141cbd942b76c08037b97b9acb Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 09:46:01 +0200 Subject: [PATCH 31/59] rename Ptr::Get and Ptr::Peek to GetPointer and PeekPointer --- samples/main-ptr.cc | 12 +- src/core/ns-unknown.cc | 4 +- src/core/ns-unknown.h | 2 +- src/core/ptr.cc | 6 +- src/core/ptr.h | 261 +++++++++++++----------- src/internet-node/arp-ipv4-interface.cc | 2 +- src/internet-node/internet-node.cc | 2 +- src/internet-node/ipv4-l4-demux.cc | 2 +- src/internet-node/l3-demux.cc | 2 +- src/node/node-list.cc | 2 +- 10 files changed, 163 insertions(+), 132 deletions(-) diff --git a/samples/main-ptr.cc b/samples/main-ptr.cc index fc6f97551..67f20df04 100644 --- a/samples/main-ptr.cc +++ b/samples/main-ptr.cc @@ -49,7 +49,7 @@ int main (int argc, char *argv[]) { // Create a new object of type A, store it in global // variable g_a - Ptr a = new A (); + Ptr a = MakeNewObject (); a->Method (); Ptr prev = StoreA (a); NS_ASSERT (prev == 0); @@ -58,19 +58,17 @@ int main (int argc, char *argv[]) { // Create a new object of type A, store it in global // variable g_a, get a hold on the previous A object. - Ptr a = new A (); + Ptr a = MakeNewObject (); Ptr prev = StoreA (a); // call method on object prev->Method (); // Clear the currently-stored object ClearA (); - // remove the raw pointer from its smart pointer. - // we can do this because the refcount is exactly one - // here - A *raw = prev.Get (); + // get the raw pointer and release it. + A *raw = GetPointer (prev); prev = 0; raw->Method (); - delete raw; + raw->Unref (); } diff --git a/src/core/ns-unknown.cc b/src/core/ns-unknown.cc index 15f433c1b..a7fef9a28 100644 --- a/src/core/ns-unknown.cc +++ b/src/core/ns-unknown.cc @@ -214,7 +214,7 @@ NsUnknown::DoQueryInterface (Iid iid) const void NsUnknown::AddInterface (Ptr interface) { - NsUnknown *p = interface.Peek (); + NsUnknown *p = PeekPointer (interface); m_impl->AddInterface (p); m_impl->RefAll (p->m_impl); p->m_impl->UnrefAll (); @@ -224,7 +224,7 @@ NsUnknown::AddInterface (Ptr interface) void NsUnknown::AddSelfInterface (Iid iid, Ptr interface) { - m_impl->AddSelfInterface (iid, interface.Peek ()); + m_impl->AddSelfInterface (iid, PeekPointer (interface)); } diff --git a/src/core/ns-unknown.h b/src/core/ns-unknown.h index 5637d0101..e22107675 100644 --- a/src/core/ns-unknown.h +++ b/src/core/ns-unknown.h @@ -117,7 +117,7 @@ NsUnknown::QueryInterface (Iid iid) const Ptr found = DoQueryInterface (iid); if (found != 0) { - return Ptr (dynamic_cast (found.Peek ())); + return Ptr (dynamic_cast (PeekPointer (found))); } return 0; } diff --git a/src/core/ptr.cc b/src/core/ptr.cc index ff94eaeca..77b19fcd9 100644 --- a/src/core/ptr.cc +++ b/src/core/ptr.cc @@ -241,7 +241,7 @@ PtrTest::RunTests (void) { Ptr p1 = p; } - raw = p.Get (); + raw = GetPointer (p); p = 0; } if (m_nDestroyed != 0) @@ -255,8 +255,8 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p = MakeNewObject (cb); - const NoCount *v1 = p.Peek(); - NoCount *v2 = p.Peek(); + const NoCount *v1 = PeekPointer (p); + NoCount *v2 = PeekPointer (p); v1->Nothing (); v2->Nothing (); } diff --git a/src/core/ptr.h b/src/core/ptr.h index ffbc1e7fd..60d94a18a 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -28,18 +28,26 @@ namespace ns3 { /** - * \brief smart pointer class similar to boost::shared_ptr + * \brief smart pointer class similar to boost::intrusive_ptr + * + * This smart-pointer class assumes that the underlying + * type provides a pair of Ref and Unref methods which are + * expected to increment and decrement the internal refcount + * of the object instance. * - * This smart-pointer class is supposed to be used to manage - * heap-allocated objects: when it decides it does not need - * the object it references, it invokes operator delete on it. * This implementation allows you to manipulate the smart pointer * as if it was a normal pointer: you can compare it with zero, - * compare it against other pointers, etc. However, the only - * operation we are careful to avoid is the conversion back to - * raw pointers: if you need to convert back, you need to invoke - * the Ptr::Remove method which returns a raw pointer and - * makes the smart pointer forget about the raw pointer. + * compare it against other pointers, assign zero to it, etc. + * + * It is possible to extract the raw pointer from this + * smart pointer with the GetPointer and PeekPointer methods. + * + * If you want to store a newed object into a smart pointer, + * we recommend you to use the MakeNewObject template functions + * to create the object and store it in a smart pointer to avoid + * memory leaks. These functions are really small conveniance + * functions and their goal is just is save you a small + * bit of typing. */ template class Ptr @@ -51,6 +59,11 @@ private: void operator delete (void *); }; friend class Ptr; + template + friend U *GetPointer (const Ptr &p); + template + friend U *PeekPointer (const Ptr &p); + void Acquire (void) const; public: /** @@ -74,53 +87,12 @@ public: ~Ptr () ; Ptr &operator = (Ptr const& o); - /** - * \return the pointer managed by this smart pointer. - * - * The underlying refcount is not incremented prior - * to returning to the caller so the caller is not - * responsible for calling Unref himself. - */ - T * Peek () const; - - /** - * \return the pointer managed by this smart pointer. - * - * The underlying refcount is incremented prior - * to returning to the caller so the caller is - * responsible for calling Unref himself. - */ - T * Get () const; T *operator -> () const; T *operator -> (); // allow if (!sp) bool operator! (); // allow if (sp) operator Tester * () const; - // allow if (sp == 0) - template - inline friend bool operator == (Ptr const &lhs, T2 const *rhs); - // allow if (0 == sp) - template - inline friend bool operator == (T1 const *lhs, Ptr &rhs); - // allow if (sp != 0) - template - inline friend bool operator != (Ptr const &lhs, T2 const *rhs); - // allow if (0 != sp) - template - inline friend bool operator != (T1 const *lhs, Ptr &rhs); - - // allow if (sp0 == sp1) - template - inline friend bool operator == (Ptr const &lhs, Ptr const &rhs); - // allow if (sp0 != sp1) - template - inline friend bool operator != (Ptr const &lhs, Ptr const &rhs); - - template - inline friend Ptr const_pointer_cast (Ptr const&p); - - }; template @@ -147,6 +119,62 @@ Ptr MakeNewObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6); template Ptr MakeNewObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7); +/** + * \return the pointer managed by this smart pointer. + * + * The underlying refcount is not incremented prior + * to returning to the caller so the caller is not + * responsible for calling Unref himself. + */ +template +T * PeekPointer (const Ptr &p); + +/** + * \return the pointer managed by this smart pointer. + * + * The underlying refcount is incremented prior + * to returning to the caller so the caller is + * responsible for calling Unref himself. + */ +template +T * GetPointer (const Ptr &p); + + +// allow if (sp == 0) +template +bool operator == (Ptr const &lhs, T2 const *rhs); + +// allow if (0 == sp) +template +bool operator == (T1 const *lhs, Ptr &rhs); + +// allow if (sp != 0) +template +bool operator != (Ptr const &lhs, T2 const *rhs); + +// allow if (0 != sp) +template +bool operator != (T1 const *lhs, Ptr &rhs); + +// allow if (sp0 == sp1) +template +bool operator == (Ptr const &lhs, Ptr const &rhs); + +// allow if (sp0 != sp1) +template +bool operator != (Ptr const &lhs, Ptr const &rhs); + +template +Ptr const_pointer_cast (Ptr const&p); + +} // namespace ns3 + + +namespace ns3 { + + /************************************************* + * friend non-member function implementations + ************************************************/ template Ptr MakeNewObject (void) @@ -220,6 +248,73 @@ Ptr MakeNewObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7) return p; } +template +T * PeekPointer (const Ptr &p) +{ + return p.m_ptr; +} + +template +T * GetPointer (const Ptr &p) +{ + p.Acquire (); + return p.m_ptr; +} + +template +bool +operator == (Ptr const &lhs, T2 const *rhs) +{ + return PeekPointer (lhs) == rhs; +} + +template +bool +operator == (T1 const *lhs, Ptr &rhs) +{ + return lhs == PeekPointer (rhs); +} + +template +bool +operator != (Ptr const &lhs, T2 const *rhs) +{ + return PeekPointer (lhs) != rhs; +} + +template +bool +operator != (T1 const *lhs, Ptr &rhs) +{ + return lhs != PeekPointer (rhs); +} + +template +bool +operator == (Ptr const &lhs, Ptr const &rhs) +{ + return PeekPointer (lhs) == PeekPointer (rhs); +} + +template +bool +operator != (Ptr const &lhs, Ptr const &rhs) +{ + return PeekPointer (lhs) != PeekPointer (rhs); +} + + +template +Ptr +const_pointer_cast (Ptr const&p) +{ + return Ptr (const_cast (PeekPointer (p))); +} + + +/**************************************************** + * Member method implementations. + ***************************************************/ template void @@ -245,14 +340,14 @@ Ptr::Ptr (T *ptr) template Ptr::Ptr (Ptr const&o) - : m_ptr (o.Peek ()) + : m_ptr (PeekPointer (o)) { Acquire (); } template template Ptr::Ptr (Ptr const &o) - : m_ptr (o.Peek ()) + : m_ptr (PeekPointer (o)) { Acquire (); } @@ -283,21 +378,6 @@ Ptr::operator = (Ptr const& o) return *this; } -template -T * -Ptr::Peek () const -{ - return m_ptr; -} - -template -T * -Ptr::Get () const -{ - Acquire (); - return m_ptr; -} - template T * Ptr::operator -> () @@ -330,53 +410,6 @@ Ptr::operator Tester * () const return &test; } -// non-member friend functions. -template -bool -operator == (Ptr const &lhs, T2 const *rhs) -{ - return lhs.m_ptr == rhs; -} -template -bool -operator == (T1 const *lhs, Ptr &rhs) -{ - return lhs == rhs.m_ptr; -} -template -bool -operator != (Ptr const &lhs, T2 const *rhs) -{ - return lhs.m_ptr != rhs; -} -template -bool -operator != (T1 const *lhs, Ptr &rhs) -{ - return lhs != rhs.m_ptr; -} - -template -bool -operator == (Ptr const &lhs, Ptr const &rhs) -{ - return lhs.Peek () == rhs.Peek (); -} -template -bool -operator != (Ptr const &lhs, Ptr const &rhs) -{ - return lhs.Peek () != rhs.Peek (); -} - - -template -Ptr -const_pointer_cast (Ptr const&p) -{ - return Ptr (const_cast (p.m_ptr)); -} - }; // namespace ns3 diff --git a/src/internet-node/arp-ipv4-interface.cc b/src/internet-node/arp-ipv4-interface.cc index 509bd241f..a4742d04c 100644 --- a/src/internet-node/arp-ipv4-interface.cc +++ b/src/internet-node/arp-ipv4-interface.cc @@ -45,7 +45,7 @@ ArpIpv4Interface::DoCreateTraceResolver (TraceContext const &context) if (GetDevice () != 0) { resolver->Add ("netdevice", - MakeCallback (&NetDevice::CreateTraceResolver, GetDevice ().Peek ()), + MakeCallback (&NetDevice::CreateTraceResolver, PeekPointer (GetDevice ())), ArpIpv4Interface::NETDEVICE); } diff --git a/src/internet-node/internet-node.cc b/src/internet-node/internet-node.cc index d2e8d2ae4..376797828 100644 --- a/src/internet-node/internet-node.cc +++ b/src/internet-node/internet-node.cc @@ -82,7 +82,7 @@ InternetNode::CreateTraceResolver (TraceContext const &context) CompositeTraceResolver *resolver = new CompositeTraceResolver (context); Ptr ipv4 = QueryInterface (IIpv4Private::iid); resolver->Add ("ipv4", - MakeCallback (&IIpv4Private::CreateTraceResolver, ipv4.Peek ()), + MakeCallback (&IIpv4Private::CreateTraceResolver, PeekPointer (ipv4)), InternetNode::IPV4); return resolver; diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index 36549a1ee..5b26983f1 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -65,7 +65,7 @@ Ipv4L4Demux::CreateTraceResolver (TraceContext const &context) oss << (*i)->GetProtocolNumber (); Ipv4L4ProtocolTraceType protocolNumber = (*i)->GetProtocolNumber (); resolver->Add (protValue, - MakeCallback (&Ipv4L4Protocol::CreateTraceResolver, protocol.Peek ()), + MakeCallback (&Ipv4L4Protocol::CreateTraceResolver, PeekPointer (protocol)), protocolNumber); } return resolver; diff --git a/src/internet-node/l3-demux.cc b/src/internet-node/l3-demux.cc index 1388ebb9b..9bf3dffc6 100644 --- a/src/internet-node/l3-demux.cc +++ b/src/internet-node/l3-demux.cc @@ -63,7 +63,7 @@ L3Demux::CreateTraceResolver (TraceContext const &context) const oss << i->second->GetProtocolNumber (); ProtocolTraceType context = i->second->GetProtocolNumber (); resolver->Add (protValue, - MakeCallback (&L3Protocol::CreateTraceResolver, i->second.Peek ()), + MakeCallback (&L3Protocol::CreateTraceResolver, PeekPointer (i->second)), context); } return resolver; diff --git a/src/node/node-list.cc b/src/node/node-list.cc index c70cd3d20..4fed7eb5e 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -102,7 +102,7 @@ NodeListPriv::GetNNodes (void) Node * NodeListPriv::PeekNode (uint32_t n) { - return m_nodes[n].Peek (); + return PeekPointer (m_nodes[n]); } Ptr From 2d8ed8d4006268edf3c948a45bcf13ddd98f0453 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 09:55:51 +0200 Subject: [PATCH 32/59] add small comment --- src/core/ptr.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/ptr.h b/src/core/ptr.h index 60d94a18a..80f191378 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -92,6 +92,7 @@ public: // allow if (!sp) bool operator! (); // allow if (sp) + // disable delete sp operator Tester * () const; }; From 6c2e4c823c28544ffa59a6a0dc4e8685277ff240 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 09:55:59 +0200 Subject: [PATCH 33/59] add disabled test --- src/core/ns-unknown.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/ns-unknown.cc b/src/core/ns-unknown.cc index a7fef9a28..92be9cbfd 100644 --- a/src/core/ns-unknown.cc +++ b/src/core/ns-unknown.cc @@ -372,6 +372,9 @@ InterfaceTest::RunTests (void) ok = false; } + // the following cannot work and it is on purpose + // delete derived; + return ok; } From 9be459e22f0466547bcd0bf9d687402f294895fa Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 10:10:46 +0200 Subject: [PATCH 34/59] remove un-implemented method --- src/internet-node/l3-demux.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/internet-node/l3-demux.h b/src/internet-node/l3-demux.h index 18f1cd962..7774a165e 100644 --- a/src/internet-node/l3-demux.h +++ b/src/internet-node/l3-demux.h @@ -79,13 +79,6 @@ public: * It is also called from InternetNode::GetIpv4 for example. */ Ptr GetProtocol (int protocolNumber); - /** - * \param protocol protocol to remove from this demux. - * - * The input value to this method should be the value - * returned from the L3Protocol::Insert method. - */ - void Erase(Ptr protocol); protected: virtual void DoDispose (void); private: From 95280cac61c9027c76112711d628e984c123e899 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 10:11:06 +0200 Subject: [PATCH 35/59] rename Erase to Remove as suggested by Tom --- src/internet-node/ipv4-l4-demux.cc | 2 +- src/internet-node/ipv4-l4-demux.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index 5b26983f1..26c181e8b 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -88,7 +88,7 @@ Ipv4L4Demux::GetProtocol(int protocolNumber) return 0; } void -Ipv4L4Demux::Erase(Ptr protocol) +Ipv4L4Demux::Remove (Ptr protocol) { m_protocols.remove (protocol); } diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index 193addab5..62477593e 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -82,7 +82,7 @@ public: * The input value to this method should be the value * returned from the Ipv4L4Protocol::Insert method. */ - void Erase (Ptr protocol); + void Remove (Ptr protocol); private: virtual void DoDispose (void); typedef std::list > L4List_t; From 6495c220a9abffafd9e78aee14fc334d6da178b5 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 18:42:39 +0200 Subject: [PATCH 36/59] rename ns-unknown.h/cc ns-unknown-manager.h/cc --- SConstruct | 8 ++++---- src/applications/application-list.h | 2 +- src/core/{ns-unknown-manager.cc => component-manager.cc} | 4 ++-- src/core/{ns-unknown-manager.h => component-manager.h} | 2 +- src/core/{ns-unknown.cc => interface.cc} | 2 +- src/core/{ns-unknown.h => interface.h} | 0 src/internet-node/i-arp-private.h | 2 +- src/internet-node/i-ipv4-private.h | 2 +- src/internet-node/ipv4-l4-demux.h | 2 +- src/internet-node/l3-demux.h | 2 +- src/node/i-ipv4.h | 2 +- src/node/i-udp.h | 2 +- src/node/node.h | 2 +- 13 files changed, 16 insertions(+), 16 deletions(-) rename src/core/{ns-unknown-manager.cc => component-manager.cc} (98%) rename src/core/{ns-unknown-manager.h => component-manager.h} (99%) rename src/core/{ns-unknown.cc => interface.cc} (99%) rename src/core/{ns-unknown.h => interface.h} (100%) diff --git a/SConstruct b/SConstruct index 7faa5a2af..607dcb1ce 100644 --- a/SConstruct +++ b/SConstruct @@ -25,12 +25,12 @@ core.add_sources([ 'test.cc', 'random-variable.cc', 'rng-stream.cc', - 'ns-unknown.cc', + 'interface.cc', 'uid-manager.cc', 'default-value.cc', 'command-line.cc', 'type-name.cc', - 'ns-unknown-manager.cc', + 'component-manager.cc', ]) env = Environment() if env['PLATFORM'] == 'posix' or env['PLATFORM'] == 'darwin' or env['PLATFORM'] == 'cygwin': @@ -58,11 +58,11 @@ core.add_inst_headers([ 'test.h', 'random-variable.h', 'rng-stream.h', - 'ns-unknown.h', + 'interface.h', 'default-value.h', 'command-line.h', 'type-name.h', - 'ns-unknown-manager.h', + 'component-manager.h', ]) def config_core (env, config): diff --git a/src/applications/application-list.h b/src/applications/application-list.h index 46576ecf3..acfa6ae07 100644 --- a/src/applications/application-list.h +++ b/src/applications/application-list.h @@ -25,7 +25,7 @@ #define __APPLICATION_LIST_H__ #include "application.h" -#include "ns3/ns-unknown.h" +#include "ns3/interface.h" #include "ns3/ptr.h" #include diff --git a/src/core/ns-unknown-manager.cc b/src/core/component-manager.cc similarity index 98% rename from src/core/ns-unknown-manager.cc rename to src/core/component-manager.cc index 46dbb2a12..a194499df 100644 --- a/src/core/ns-unknown-manager.cc +++ b/src/core/component-manager.cc @@ -18,7 +18,7 @@ * * Author: Mathieu Lacage */ -#include "ns-unknown-manager.h" +#include "component-manager.h" #include "uid-manager.h" #include "singleton.h" @@ -91,7 +91,7 @@ NsUnknownManager::Register (std::string name, CallbackBase *callback) #ifdef RUN_SELF_TESTS #include "test.h" -#include "ns-unknown.h" +#include "interface.h" namespace { diff --git a/src/core/ns-unknown-manager.h b/src/core/component-manager.h similarity index 99% rename from src/core/ns-unknown-manager.h rename to src/core/component-manager.h index 85987fb5a..edcb4e4ad 100644 --- a/src/core/ns-unknown-manager.h +++ b/src/core/component-manager.h @@ -25,7 +25,7 @@ #include #include #include "callback.h" -#include "ns-unknown.h" +#include "interface.h" #include "fatal-error.h" #include "ptr.h" diff --git a/src/core/ns-unknown.cc b/src/core/interface.cc similarity index 99% rename from src/core/ns-unknown.cc rename to src/core/interface.cc index 92be9cbfd..33aa47182 100644 --- a/src/core/ns-unknown.cc +++ b/src/core/interface.cc @@ -18,7 +18,7 @@ * * Author: Mathieu Lacage */ -#include "ns-unknown.h" +#include "interface.h" #include "singleton.h" #include "uid-manager.h" #include diff --git a/src/core/ns-unknown.h b/src/core/interface.h similarity index 100% rename from src/core/ns-unknown.h rename to src/core/interface.h diff --git a/src/internet-node/i-arp-private.h b/src/internet-node/i-arp-private.h index 7b3647601..4d7b10b97 100644 --- a/src/internet-node/i-arp-private.h +++ b/src/internet-node/i-arp-private.h @@ -21,7 +21,7 @@ #ifndef I_ARP_PRIVATE_H #define I_ARP_PRIVATE_H -#include "ns3/ns-unknown.h" +#include "ns3/interface.h" #include "ns3/ipv4-address.h" namespace ns3 { diff --git a/src/internet-node/i-ipv4-private.h b/src/internet-node/i-ipv4-private.h index 61df90c96..fb0a43ade 100644 --- a/src/internet-node/i-ipv4-private.h +++ b/src/internet-node/i-ipv4-private.h @@ -21,7 +21,7 @@ #ifndef I_IPV4_PRIVATE_H #define I_IPV4_PRIVATE_H -#include "ns3/ns-unknown.h" +#include "ns3/interface.h" #include "ns3/ipv4-address.h" #include "ns3/ptr.h" #include diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index 62477593e..ca696530d 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -26,7 +26,7 @@ #define IPV4_L4_DEMUX_H #include -#include "ns3/ns-unknown.h" +#include "ns3/interface.h" #include "ns3/ptr.h" namespace ns3 { diff --git a/src/internet-node/l3-demux.h b/src/internet-node/l3-demux.h index 7774a165e..6ab1e6410 100644 --- a/src/internet-node/l3-demux.h +++ b/src/internet-node/l3-demux.h @@ -28,7 +28,7 @@ #define L3_DEMUX_H #include -#include "ns3/ns-unknown.h" +#include "ns3/interface.h" #include "ns3/ptr.h" namespace ns3 { diff --git a/src/node/i-ipv4.h b/src/node/i-ipv4.h index 27fc31dd8..65a10ae38 100644 --- a/src/node/i-ipv4.h +++ b/src/node/i-ipv4.h @@ -23,7 +23,7 @@ #include #include "ns3/ipv4-address.h" -#include "ns3/ns-unknown.h" +#include "ns3/interface.h" namespace ns3 { diff --git a/src/node/i-udp.h b/src/node/i-udp.h index 32a92c7ce..11ec15ba8 100644 --- a/src/node/i-udp.h +++ b/src/node/i-udp.h @@ -21,7 +21,7 @@ #ifndef I_UDP_H #define I_UDP_H -#include "ns3/ns-unknown.h" +#include "ns3/interface.h" #include "ns3/ptr.h" namespace ns3 { diff --git a/src/node/node.h b/src/node/node.h index e5b30e1da..ed13fbcd0 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -27,7 +27,7 @@ #include -#include "ns3/ns-unknown.h" +#include "ns3/interface.h" namespace ns3 { From e22e6188cf382cbc49a478060626131cdb2cbdb1 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 18:52:05 +0200 Subject: [PATCH 37/59] rename NsUnknown to Interface and NsUnknownManager to ComponentManager --- src/applications/application-list.cc | 4 +- src/applications/application-list.h | 2 +- src/core/component-manager.cc | 54 ++++++++-------- src/core/component-manager.h | 78 +++++++++++------------ src/core/interface.cc | 92 ++++++++++++++-------------- src/core/interface.h | 28 ++++----- src/internet-node/i-arp-private.cc | 4 +- src/internet-node/i-arp-private.h | 2 +- src/internet-node/i-ipv4-private.cc | 4 +- src/internet-node/i-ipv4-private.h | 2 +- src/internet-node/internet-node.cc | 14 ++--- src/internet-node/ipv4-l4-demux.cc | 4 +- src/internet-node/ipv4-l4-demux.h | 2 +- src/internet-node/l3-demux.cc | 4 +- src/internet-node/l3-demux.h | 2 +- src/node/i-ipv4.cc | 2 +- src/node/i-ipv4.h | 2 +- src/node/i-udp.cc | 2 +- src/node/i-udp.h | 2 +- src/node/node.cc | 6 +- src/node/node.h | 2 +- 21 files changed, 156 insertions(+), 156 deletions(-) diff --git a/src/applications/application-list.cc b/src/applications/application-list.cc index 33980b840..d860290b6 100644 --- a/src/applications/application-list.cc +++ b/src/applications/application-list.cc @@ -29,7 +29,7 @@ namespace ns3{ const Iid ApplicationList::iid ("ApplicationList"); ApplicationList::ApplicationList(Ptr n) - : NsUnknown (ApplicationList::iid) + : Interface (ApplicationList::iid) {} void @@ -43,7 +43,7 @@ ApplicationList::DoDispose (void) *i = 0; } m_apps.clear (); - NsUnknown::DoDispose (); + Interface::DoDispose (); } ApplicationList::~ApplicationList() diff --git a/src/applications/application-list.h b/src/applications/application-list.h index acfa6ae07..689c4325b 100644 --- a/src/applications/application-list.h +++ b/src/applications/application-list.h @@ -31,7 +31,7 @@ namespace ns3 { -class ApplicationList : public NsUnknown +class ApplicationList : public Interface { public: static const Iid iid; diff --git a/src/core/component-manager.cc b/src/core/component-manager.cc index a194499df..54cc60afb 100644 --- a/src/core/component-manager.cc +++ b/src/core/component-manager.cc @@ -49,15 +49,15 @@ bool operator == (const ClassId &a, const ClassId &b) return a.m_classId == b.m_classId; } -Ptr -NsUnknownManager::Create (ClassId classId) +Ptr +ComponentManager::Create (ClassId classId) { - Callback > callback = DoGetCallback (classId); + Callback > callback = DoGetCallback (classId); return callback (); } CallbackBase * -NsUnknownManager::Lookup (ClassId classId) +ComponentManager::Lookup (ClassId classId) { List *list = Singleton::Get (); for (List::const_iterator i = list->begin (); i != list->end (); i++) @@ -71,13 +71,13 @@ NsUnknownManager::Lookup (ClassId classId) } ClassId -NsUnknownManager::LookupByName (std::string name) +ComponentManager::LookupByName (std::string name) { return ClassId (Singleton::Get ()->LookupByName (name)); } ClassId -NsUnknownManager::Register (std::string name, CallbackBase *callback) +ComponentManager::Register (std::string name, CallbackBase *callback) { ClassId classId = ClassId (name); List *list = Singleton::Get (); @@ -96,7 +96,7 @@ NsUnknownManager::Register (std::string name, CallbackBase *callback) namespace { -class B : public ns3::NsUnknown +class B : public ns3::Interface { public: static const ns3::Iid iid; @@ -106,11 +106,11 @@ public: const ns3::Iid B::iid ("IB"); B::B () - : NsUnknown (B::iid) + : Interface (B::iid) {} -class A : public ns3::NsUnknown +class A : public ns3::Interface { public: static const ns3::ClassId cidZero; @@ -130,13 +130,13 @@ public: int m_ui32; }; -const ns3::ClassId A::cidZero = ns3::NsUnknownManager::RegisterConstructor ("A"); -const ns3::ClassId A::cidOneBool = ns3::NsUnknownManager::RegisterConstructor ("ABool"); -const ns3::ClassId A::cidOneUi32 = ns3::NsUnknownManager::RegisterConstructor ("AUi32"); +const ns3::ClassId A::cidZero = ns3::ComponentManager::RegisterConstructor ("A"); +const ns3::ClassId A::cidOneBool = ns3::ComponentManager::RegisterConstructor ("ABool"); +const ns3::ClassId A::cidOneUi32 = ns3::ComponentManager::RegisterConstructor ("AUi32"); const ns3::Iid A::iid ("IA"); A::A () - : NsUnknown (A::iid), + : Interface (A::iid), m_zeroInvoked (true), m_oneBoolInvoked (false), m_oneUi32Invoked (false) @@ -146,7 +146,7 @@ A::A () } A::A (bool bo) - : NsUnknown (A::iid), + : Interface (A::iid), m_zeroInvoked (false), m_oneBoolInvoked (true), m_oneUi32Invoked (false), @@ -157,7 +157,7 @@ A::A (bool bo) } A::A (uint32_t i) - : NsUnknown (A::iid), + : Interface (A::iid), m_zeroInvoked (false), m_oneBoolInvoked (false), m_oneUi32Invoked (true), @@ -171,30 +171,30 @@ A::A (uint32_t i) namespace ns3 { -class NsUnknownManagerTest : public Test +class ComponentManagerTest : public Test { public: - NsUnknownManagerTest (); + ComponentManagerTest (); virtual bool RunTests (void); }; -NsUnknownManagerTest::NsUnknownManagerTest () - : Test ("NsUnknownManager") +ComponentManagerTest::ComponentManagerTest () + : Test ("ComponentManager") {} bool -NsUnknownManagerTest::RunTests (void) +ComponentManagerTest::RunTests (void) { bool ok = true; Ptr a = 0; - a = NsUnknownManager::Create (A::cidZero, A::iid); + a = ComponentManager::Create (A::cidZero, A::iid); if (a == 0 || !a->m_zeroInvoked) { ok = false; } - a = NsUnknownManager::Create (A::cidOneBool, A::iid, true); + a = ComponentManager::Create (A::cidOneBool, A::iid, true); if (a == 0 || !a->m_oneBoolInvoked || !a->m_bool) @@ -202,7 +202,7 @@ NsUnknownManagerTest::RunTests (void) ok = false; } - a = NsUnknownManager::Create (A::cidOneBool, A::iid, false); + a = ComponentManager::Create (A::cidOneBool, A::iid, false); if (a == 0 || !a->m_oneBoolInvoked || a->m_bool) @@ -210,7 +210,7 @@ NsUnknownManagerTest::RunTests (void) ok = false; } - a = NsUnknownManager::Create (A::cidOneUi32, A::iid, 10); + a = ComponentManager::Create (A::cidOneUi32, A::iid, 10); if (a == 0 || !a->m_oneUi32Invoked || a->m_ui32 != 10) @@ -218,7 +218,7 @@ NsUnknownManagerTest::RunTests (void) ok = false; } - a = NsUnknownManager::Create (A::cidOneUi32, A::iid, (uint32_t)10); + a = ComponentManager::Create (A::cidOneUi32, A::iid, (uint32_t)10); if (a == 0 || !a->m_oneUi32Invoked || a->m_ui32 != 10) @@ -226,7 +226,7 @@ NsUnknownManagerTest::RunTests (void) ok = false; } - Ptr b = NsUnknownManager::Create (A::cidOneUi32, B::iid, 10); + Ptr b = ComponentManager::Create (A::cidOneUi32, B::iid, 10); if (b == 0) { ok = false; @@ -236,7 +236,7 @@ NsUnknownManagerTest::RunTests (void) } -static NsUnknownManagerTest g_unknownManagerTest; +static ComponentManagerTest g_unknownManagerTest; } // namespace ns3 diff --git a/src/core/component-manager.h b/src/core/component-manager.h index edcb4e4ad..135b8faac 100644 --- a/src/core/component-manager.h +++ b/src/core/component-manager.h @@ -52,22 +52,22 @@ public: private: ClassId (std::string name); ClassId (uint32_t classId); - friend class NsUnknownManager; + friend class ComponentManager; friend bool operator == (const ClassId &a, const ClassId &b); uint32_t m_classId; }; /** - * \brief Create any NsUnknown + * \brief Create any Interface * * This class keeps track of a set of ClassId, each * of which uniquely identifies the constructor of an - * object which derives from the NsUnknown base class. + * object which derives from the Interface base class. * This class can also create an instance of any of * the objects tracked through any of their tracked * constructor/ClassId. */ -class NsUnknownManager +class ComponentManager { public: /** @@ -83,7 +83,7 @@ public: * Create an instance of the object identified by its * ClassId. This method invokes the default constructor. */ - static Ptr Create (ClassId classId); + static Ptr Create (ClassId classId); /** * \param classId class id of the constructor to invoke. @@ -95,7 +95,7 @@ public: * ClassId. */ template - static Ptr Create (ClassId classId, T1 a1); + static Ptr Create (ClassId classId, T1 a1); /** * \param classId class id of the constructor to invoke. @@ -108,7 +108,7 @@ public: * ClassId. */ template - static Ptr Create (ClassId classId, T1 a1, T2 a2); + static Ptr Create (ClassId classId, T1 a1, T2 a2); /** * \param classId class id of the constructor to invoke. @@ -137,9 +137,9 @@ public: template static ClassId RegisterConstructor (std::string name) { - static Callback > callback = - MakeCallback (&NsUnknownManager::MakeObjectZero); - return NsUnknownManager::Register (name, &callback); + static Callback > callback = + MakeCallback (&ComponentManager::MakeObjectZero); + return ComponentManager::Register (name, &callback); } /** @@ -151,8 +151,8 @@ public: template static ClassId RegisterConstructor (std::string name) { - static Callback ,T1> callback = MakeCallback (&NsUnknownManager::MakeObjectOne); - return NsUnknownManager::Register (name, &callback); + static Callback ,T1> callback = MakeCallback (&ComponentManager::MakeObjectOne); + return ComponentManager::Register (name, &callback); } /** @@ -164,8 +164,8 @@ public: template static ClassId RegisterConstructor (std::string name) { - static Callback,T1,T2> callback = MakeCallback (&NsUnknownManager::MakeObjectTwo); - return NsUnknownManager::Register (name, &callback); + static Callback,T1,T2> callback = MakeCallback (&ComponentManager::MakeObjectTwo); + return ComponentManager::Register (name, &callback); } private: static ClassId Register (std::string name, CallbackBase *callback); @@ -173,16 +173,16 @@ private: template - static Callback,T1,T2,T3,T4,T5> DoGetCallback (ClassId classId); + static Callback,T1,T2,T3,T4,T5> DoGetCallback (ClassId classId); template - static Ptr MakeObjectZero (void); + static Ptr MakeObjectZero (void); template - static Ptr MakeObjectOne (T1 a1); + static Ptr MakeObjectOne (T1 a1); template - static Ptr MakeObjectTwo (T1 a1, T2 a2); + static Ptr MakeObjectTwo (T1 a1, T2 a2); typedef std::vector > List; static List *GetList (void); @@ -197,79 +197,79 @@ namespace ns3 { template -Callback,T1,T2,T3,T4,T5> -NsUnknownManager::DoGetCallback (ClassId classId) +Callback,T1,T2,T3,T4,T5> +ComponentManager::DoGetCallback (ClassId classId) { CallbackBase *callback = Lookup (classId); if (callback == 0) { NS_FATAL_ERROR ("Invalid Class Id."); } - Callback, T1,T2,T3,T4,T5> reference; + Callback, T1,T2,T3,T4,T5> reference; reference.Assign (*callback); return reference; } template -Ptr -NsUnknownManager::Create (ClassId classId, T1 a1) +Ptr +ComponentManager::Create (ClassId classId, T1 a1) { - Callback, T1> callback = DoGetCallback (classId); + Callback, T1> callback = DoGetCallback (classId); return callback (a1); } template -Ptr -NsUnknownManager::Create (ClassId classId, T1 a1, T2 a2) +Ptr +ComponentManager::Create (ClassId classId, T1 a1, T2 a2) { - Callback , T1,T2> callback = DoGetCallback (classId); + Callback , T1,T2> callback = DoGetCallback (classId); return callback (a1, a2); } template Ptr -NsUnknownManager::Create (ClassId classId, Iid iid) +ComponentManager::Create (ClassId classId, Iid iid) { - Ptr obj = Create (classId); + Ptr obj = Create (classId); Ptr i = obj->QueryInterface (iid); return i; } template Ptr -NsUnknownManager::Create (ClassId classId, Iid iid, T1 a1) +ComponentManager::Create (ClassId classId, Iid iid, T1 a1) { - Ptr obj = Create (classId, a1); + Ptr obj = Create (classId, a1); Ptr i = obj->QueryInterface (iid); return i; } template Ptr -NsUnknownManager::Create (ClassId classId, Iid iid, T1 a1, T2 a2) +ComponentManager::Create (ClassId classId, Iid iid, T1 a1, T2 a2) { - Ptr obj = Create (classId, a1, a2); + Ptr obj = Create (classId, a1, a2); Ptr i = obj->QueryInterface (iid); return i; } template -Ptr -NsUnknownManager::MakeObjectZero (void) +Ptr +ComponentManager::MakeObjectZero (void) { return MakeNewObject (); } template -Ptr -NsUnknownManager::MakeObjectOne (T1 a1) +Ptr +ComponentManager::MakeObjectOne (T1 a1) { return MakeNewObject (a1); } template -Ptr -NsUnknownManager::MakeObjectTwo (T1 a1, T2 a2) +Ptr +ComponentManager::MakeObjectTwo (T1 a1, T2 a2) { return MakeNewObject (a1, a2); } diff --git a/src/core/interface.cc b/src/core/interface.cc index 33aa47182..ac7413e2b 100644 --- a/src/core/interface.cc +++ b/src/core/interface.cc @@ -27,7 +27,7 @@ #include "assert.h" #include "debug.h" -NS_DEBUG_COMPONENT_DEFINE ("NsUnknown"); +NS_DEBUG_COMPONENT_DEFINE ("Interface"); namespace ns3 { @@ -44,34 +44,34 @@ bool operator == (const Iid &a, const Iid &b) } -class NsUnknownImpl +class InterfaceImpl { public: - NsUnknownImpl (Iid iid, NsUnknown *interface); - ~NsUnknownImpl (); + InterfaceImpl (Iid iid, Interface *interface); + ~InterfaceImpl (); void Ref (void); - void RefAll (NsUnknownImpl *other); + void RefAll (InterfaceImpl *other); void Unref (void); void UnrefAll (void); - NsUnknown *PeekQueryInterface (Iid iid) const; + Interface *PeekQueryInterface (Iid iid) const; void DoDisposeAll (void); - void AddInterface (NsUnknown * interface); - void AddSelfInterface (Iid iid, NsUnknown *interface); + void AddInterface (Interface * interface); + void AddSelfInterface (Iid iid, Interface *interface); private: - typedef std::list > List; + typedef std::list > List; uint32_t m_ref; List m_list; bool m_disposed; }; -NsUnknownImpl::NsUnknownImpl (Iid iid, NsUnknown * interface) +InterfaceImpl::InterfaceImpl (Iid iid, Interface * interface) : m_ref (1), m_disposed (false) { NS_DEBUG ("new " << this << " ref=" << m_ref); m_list.push_back (std::make_pair (iid, interface)); } -NsUnknownImpl::~NsUnknownImpl () +InterfaceImpl::~InterfaceImpl () { for (List::const_iterator i = m_list.begin (); i != m_list.end (); i++) @@ -81,19 +81,19 @@ NsUnknownImpl::~NsUnknownImpl () m_list.clear (); } void -NsUnknownImpl::Ref (void) +InterfaceImpl::Ref (void) { m_ref++; NS_DEBUG ("inc " << this << " ref=" << m_ref); } void -NsUnknownImpl::RefAll (NsUnknownImpl *other) +InterfaceImpl::RefAll (InterfaceImpl *other) { m_ref += other->m_ref; NS_DEBUG ("inc all " << this << " o=" << other->m_ref << " ref=" << m_ref); } void -NsUnknownImpl::Unref (void) +InterfaceImpl::Unref (void) { NS_ASSERT (m_ref > 0); m_ref--; @@ -104,7 +104,7 @@ NsUnknownImpl::Unref (void) } } void -NsUnknownImpl::UnrefAll (void) +InterfaceImpl::UnrefAll (void) { NS_ASSERT (m_ref > 0); m_ref = 0; @@ -112,19 +112,19 @@ NsUnknownImpl::UnrefAll (void) NS_DEBUG ("dec all " << this); } void -NsUnknownImpl::DoDisposeAll (void) +InterfaceImpl::DoDisposeAll (void) { NS_ASSERT (!m_disposed); for (List::const_iterator i = m_list.begin (); i != m_list.end (); i++) { - NsUnknown *interface = i->second; + Interface *interface = i->second; interface->DoDispose (); } m_disposed = true; } -NsUnknown * -NsUnknownImpl::PeekQueryInterface (Iid iid) const +Interface * +InterfaceImpl::PeekQueryInterface (Iid iid) const { for (List::const_iterator i = m_list.begin (); i != m_list.end (); i++) @@ -137,7 +137,7 @@ NsUnknownImpl::PeekQueryInterface (Iid iid) const return 0; } void -NsUnknownImpl::AddInterface (NsUnknown *interface) +InterfaceImpl::AddInterface (Interface *interface) { for (List::const_iterator i = interface->m_impl->m_list.begin (); i != interface->m_impl->m_list.end (); i++) @@ -149,53 +149,53 @@ NsUnknownImpl::AddInterface (NsUnknown *interface) } } void -NsUnknownImpl::AddSelfInterface (Iid iid, NsUnknown *interface) +InterfaceImpl::AddSelfInterface (Iid iid, Interface *interface) { interface->RefInternal (); m_list.push_back (std::make_pair (iid, interface)); } -NsUnknown::NsUnknown (Iid iid) - : m_impl (new NsUnknownImpl (iid, this)), +Interface::Interface (Iid iid) + : m_impl (new InterfaceImpl (iid, this)), m_ref (1) {} -NsUnknown::~NsUnknown () +Interface::~Interface () { m_impl = 0; m_ref = -1; } void -NsUnknown::Ref (void) const +Interface::Ref (void) const { m_impl->Ref (); } void -NsUnknown::Unref (void) const +Interface::Unref (void) const { m_impl->Unref (); } void -NsUnknown::Dispose (void) +Interface::Dispose (void) { m_impl->DoDisposeAll (); } void -NsUnknown::DoDispose (void) +Interface::DoDispose (void) { // we do not do anything by default. } void -NsUnknown::RefInternal (void) +Interface::RefInternal (void) { m_ref++; } void -NsUnknown::UnrefInternal (void) +Interface::UnrefInternal (void) { NS_ASSERT (m_ref != 0); m_ref--; @@ -205,16 +205,16 @@ NsUnknown::UnrefInternal (void) } } -Ptr -NsUnknown::DoQueryInterface (Iid iid) const +Ptr +Interface::DoQueryInterface (Iid iid) const { return m_impl->PeekQueryInterface (iid); } void -NsUnknown::AddInterface (Ptr interface) +Interface::AddInterface (Ptr interface) { - NsUnknown *p = PeekPointer (interface); + Interface *p = PeekPointer (interface); m_impl->AddInterface (p); m_impl->RefAll (p->m_impl); p->m_impl->UnrefAll (); @@ -222,7 +222,7 @@ NsUnknown::AddInterface (Ptr interface) } void -NsUnknown::AddSelfInterface (Iid iid, Ptr interface) +Interface::AddSelfInterface (Iid iid, Ptr interface) { m_impl->AddSelfInterface (iid, PeekPointer (interface)); } @@ -236,44 +236,44 @@ NsUnknown::AddSelfInterface (Iid iid, Ptr interface) namespace { -class A : public ns3::NsUnknown +class A : public ns3::Interface { public: static const ns3::Iid iid; A () - : NsUnknown (A::iid) + : Interface (A::iid) {} }; -class B : public ns3::NsUnknown +class B : public ns3::Interface { public: static const ns3::Iid iid; B () - : NsUnknown (B::iid) + : Interface (B::iid) {} }; -class BaseA : public ns3::NsUnknown +class BaseA : public ns3::Interface { public: static const ns3::Iid iid; BaseA () - : NsUnknown (BaseA::iid) + : Interface (BaseA::iid) {} }; -class BaseB : public ns3::NsUnknown +class BaseB : public ns3::Interface { public: static const ns3::Iid iid; BaseB () - : NsUnknown (BaseB::iid) + : Interface (BaseB::iid) {} }; -class Base : public ns3::NsUnknown +class Base : public ns3::Interface { public: static const ns3::Iid iid; Base () - : NsUnknown (Base::iid) + : Interface (Base::iid) {} }; class Derived : public Base @@ -306,7 +306,7 @@ public: }; InterfaceTest::InterfaceTest () - : Test ("NsUnknown") + : Test ("Interface") {} bool InterfaceTest::RunTests (void) diff --git a/src/core/interface.h b/src/core/interface.h index e22107675..7e8e6573d 100644 --- a/src/core/interface.h +++ b/src/core/interface.h @@ -26,7 +26,7 @@ namespace ns3 { -class NsUnknownImpl; +class InterfaceImpl; class Iid { @@ -45,15 +45,15 @@ private: * inheritance where this base class is at the top of the dreaded * "diamond" shape is not allowed. */ -class NsUnknown +class Interface { public: - virtual ~NsUnknown (); + virtual ~Interface (); void Ref (void) const; void Unref (void) const; /** - * \param iid the NsUnknown id of the requested interface + * \param iid the Interface id of the requested interface */ template Ptr QueryInterface (Iid iid) const; @@ -66,7 +66,7 @@ public: * will be able to perform QI on each other and their lifetimes * will be found by the same reference count. */ - void AddInterface (Ptr interface); + void AddInterface (Ptr interface); void Dispose (void); protected: @@ -77,17 +77,17 @@ protected: * If you are a direct subclass of this class, you _must_ register * the name of your interface with this constructor. */ - NsUnknown (Iid iid); + Interface (Iid iid); /** * \param iid the Interface id of the interface * \param a pointer to the interface object * - * If you are not a direct subclass of the ns3::NsUnknown base class, + * If you are not a direct subclass of the ns3::Interface base class, * and if you want to register yourself as another accessible interface * (typically, your subclass has added API), you need to call * this method to associate an interface id to your interface. */ - void AddSelfInterface (Iid iid, Ptr interface); + void AddSelfInterface (Iid iid, Ptr interface); protected: /** * Subclasses who want to handle the "dispose" event should @@ -97,12 +97,12 @@ protected: */ virtual void DoDispose (void); private: - friend class NsUnknownImpl; - NsUnknown (); - Ptr DoQueryInterface (Iid iid) const; + friend class InterfaceImpl; + Interface (); + Ptr DoQueryInterface (Iid iid) const; void RefInternal (void); void UnrefInternal (void); - NsUnknownImpl *m_impl; + InterfaceImpl *m_impl; uint32_t m_ref; }; @@ -112,9 +112,9 @@ namespace ns3 { template Ptr -NsUnknown::QueryInterface (Iid iid) const +Interface::QueryInterface (Iid iid) const { - Ptr found = DoQueryInterface (iid); + Ptr found = DoQueryInterface (iid); if (found != 0) { return Ptr (dynamic_cast (PeekPointer (found))); diff --git a/src/internet-node/i-arp-private.cc b/src/internet-node/i-arp-private.cc index 28cf56f7c..815bd9cec 100644 --- a/src/internet-node/i-arp-private.cc +++ b/src/internet-node/i-arp-private.cc @@ -28,7 +28,7 @@ namespace ns3 { const Iid IArpPrivate::iid ("IArpPrivate"); IArpPrivate::IArpPrivate (Ptr arp) - : NsUnknown (IArpPrivate::iid), + : Interface (IArpPrivate::iid), m_arp (arp) {} IArpPrivate::~IArpPrivate () @@ -48,7 +48,7 @@ void IArpPrivate::DoDispose (void) { m_arp = 0; - NsUnknown::DoDispose (); + Interface::DoDispose (); } diff --git a/src/internet-node/i-arp-private.h b/src/internet-node/i-arp-private.h index 4d7b10b97..5e87b214c 100644 --- a/src/internet-node/i-arp-private.h +++ b/src/internet-node/i-arp-private.h @@ -31,7 +31,7 @@ class MacAddress; class Packet; class Arp; -class IArpPrivate : public NsUnknown +class IArpPrivate : public Interface { public: static const Iid iid; diff --git a/src/internet-node/i-ipv4-private.cc b/src/internet-node/i-ipv4-private.cc index 95fe4249f..22d853877 100644 --- a/src/internet-node/i-ipv4-private.cc +++ b/src/internet-node/i-ipv4-private.cc @@ -28,7 +28,7 @@ namespace ns3 { const Iid IIpv4Private::iid ("IIpv4Private"); IIpv4Private::IIpv4Private (Ptr ipv4) - : NsUnknown (IIpv4Private::iid), + : Interface (IIpv4Private::iid), m_ipv4 (ipv4) {} IIpv4Private::~IIpv4Private () @@ -60,7 +60,7 @@ void IIpv4Private::DoDispose (void) { m_ipv4 = 0; - NsUnknown::DoDispose (); + Interface::DoDispose (); } } // namespace ns3 diff --git a/src/internet-node/i-ipv4-private.h b/src/internet-node/i-ipv4-private.h index fb0a43ade..d1c2d8bd9 100644 --- a/src/internet-node/i-ipv4-private.h +++ b/src/internet-node/i-ipv4-private.h @@ -35,7 +35,7 @@ class TraceResolver; class Ipv4Interface; class NetDevice; -class IIpv4Private : public NsUnknown +class IIpv4Private : public Interface { public: static const Iid iid; diff --git a/src/internet-node/internet-node.cc b/src/internet-node/internet-node.cc index 376797828..0e54800d9 100644 --- a/src/internet-node/internet-node.cc +++ b/src/internet-node/internet-node.cc @@ -58,13 +58,13 @@ InternetNode::InternetNode() Ptr ipv4Impl = MakeNewObject (ipv4); Ptr ipv4Private = MakeNewObject (ipv4); - NsUnknown::AddInterface (ipv4Private); - NsUnknown::AddInterface (ipv4Impl); - NsUnknown::AddInterface (arpPrivate); - NsUnknown::AddInterface (udpImpl); - NsUnknown::AddInterface (applicationList); - NsUnknown::AddInterface (l3Demux); - NsUnknown::AddInterface (ipv4L4Demux); + Interface::AddInterface (ipv4Private); + Interface::AddInterface (ipv4Impl); + Interface::AddInterface (arpPrivate); + Interface::AddInterface (udpImpl); + Interface::AddInterface (applicationList); + Interface::AddInterface (l3Demux); + Interface::AddInterface (ipv4L4Demux); } InternetNode::~InternetNode () diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index 26c181e8b..3e01cb4d7 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -33,7 +33,7 @@ namespace ns3 { const Iid Ipv4L4Demux::iid ("Ipv4L4Demux"); Ipv4L4Demux::Ipv4L4Demux (Ptr node) - : NsUnknown (Ipv4L4Demux::iid), + : Interface (Ipv4L4Demux::iid), m_node (node) {} @@ -50,7 +50,7 @@ Ipv4L4Demux::DoDispose (void) } m_protocols.clear (); m_node = 0; - NsUnknown::DoDispose (); + Interface::DoDispose (); } TraceResolver * diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index ca696530d..645309abc 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -39,7 +39,7 @@ class TraceContext; /** * \brief L4 Ipv4 Demux */ -class Ipv4L4Demux : public NsUnknown +class Ipv4L4Demux : public Interface { public: static const Iid iid; diff --git a/src/internet-node/l3-demux.cc b/src/internet-node/l3-demux.cc index 9bf3dffc6..6b58d6c43 100644 --- a/src/internet-node/l3-demux.cc +++ b/src/internet-node/l3-demux.cc @@ -32,7 +32,7 @@ namespace ns3 { const Iid L3Demux::iid ("L3Demux"); L3Demux::L3Demux (Ptr node) - : NsUnknown (L3Demux::iid), + : Interface (L3Demux::iid), m_node (node) {} @@ -49,7 +49,7 @@ L3Demux::DoDispose (void) } m_protocols.clear (); m_node = 0; - NsUnknown::DoDispose (); + Interface::DoDispose (); } TraceResolver * diff --git a/src/internet-node/l3-demux.h b/src/internet-node/l3-demux.h index 6ab1e6410..a0c9713b1 100644 --- a/src/internet-node/l3-demux.h +++ b/src/internet-node/l3-demux.h @@ -41,7 +41,7 @@ class TraceContext; /** * \brief L3 Demux */ -class L3Demux : public NsUnknown +class L3Demux : public Interface { public: static const Iid iid; diff --git a/src/node/i-ipv4.cc b/src/node/i-ipv4.cc index d3b41abcf..bfb6e2c0b 100644 --- a/src/node/i-ipv4.cc +++ b/src/node/i-ipv4.cc @@ -25,7 +25,7 @@ namespace ns3 { const Iid IIpv4::iid ("IIpv4"); IIpv4::IIpv4 () - : NsUnknown (IIpv4::iid) + : Interface (IIpv4::iid) {} IIpv4::~IIpv4 () diff --git a/src/node/i-ipv4.h b/src/node/i-ipv4.h index 65a10ae38..121a6e6ea 100644 --- a/src/node/i-ipv4.h +++ b/src/node/i-ipv4.h @@ -31,7 +31,7 @@ class NetDevice; class Packet; class Ipv4Route; -class IIpv4 : public NsUnknown +class IIpv4 : public Interface { public: static const Iid iid; diff --git a/src/node/i-udp.cc b/src/node/i-udp.cc index 6f825e9a7..92263ce34 100644 --- a/src/node/i-udp.cc +++ b/src/node/i-udp.cc @@ -25,7 +25,7 @@ namespace ns3 { const Iid IUdp::iid ("IUdp"); IUdp::IUdp () - : NsUnknown (IUdp::iid) + : Interface (IUdp::iid) {} } // namespace ns3 diff --git a/src/node/i-udp.h b/src/node/i-udp.h index 11ec15ba8..0e7c08b00 100644 --- a/src/node/i-udp.h +++ b/src/node/i-udp.h @@ -28,7 +28,7 @@ namespace ns3 { class Socket; -class IUdp : public NsUnknown +class IUdp : public Interface { public: static const Iid iid; diff --git a/src/node/node.cc b/src/node/node.cc index a23fdde35..ea57ddb2c 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -32,7 +32,7 @@ namespace ns3{ const Iid Node::iid ("Node"); Node::Node() - : NsUnknown (Node::iid), + : Interface (Node::iid), m_id(0), m_sid(0) { @@ -40,7 +40,7 @@ Node::Node() } Node::Node(uint32_t sid) - : NsUnknown (Node::iid), + : Interface (Node::iid), m_id(0), m_sid(sid) { @@ -98,7 +98,7 @@ void Node::DoDispose() *i = 0; } m_devices.clear (); - NsUnknown::DoDispose (); + Interface::DoDispose (); } }//namespace ns3 diff --git a/src/node/node.h b/src/node/node.h index ed13fbcd0..0ea49fcfd 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -35,7 +35,7 @@ class TraceContext; class TraceResolver; class NetDevice; -class Node : public NsUnknown +class Node : public Interface { public: static const Iid iid; From 666e00b0979e4c49e68cac3adf2681b339cee889 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 18:57:45 +0200 Subject: [PATCH 38/59] rename Iid to InterfaceId --- src/applications/application-list.cc | 2 +- src/applications/application-list.h | 2 +- src/core/component-manager.cc | 8 ++--- src/core/component-manager.h | 12 +++---- src/core/interface.cc | 48 ++++++++++++++-------------- src/core/interface.h | 16 +++++----- src/internet-node/i-arp-private.cc | 2 +- src/internet-node/i-arp-private.h | 2 +- src/internet-node/i-ipv4-private.cc | 2 +- src/internet-node/i-ipv4-private.h | 2 +- src/internet-node/ipv4-l4-demux.cc | 2 +- src/internet-node/ipv4-l4-demux.h | 2 +- src/internet-node/l3-demux.cc | 2 +- src/internet-node/l3-demux.h | 2 +- src/node/i-ipv4.cc | 2 +- src/node/i-ipv4.h | 2 +- src/node/i-udp.cc | 2 +- src/node/i-udp.h | 2 +- src/node/node.cc | 2 +- src/node/node.h | 2 +- 20 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/applications/application-list.cc b/src/applications/application-list.cc index d860290b6..576f1fc4a 100644 --- a/src/applications/application-list.cc +++ b/src/applications/application-list.cc @@ -26,7 +26,7 @@ namespace ns3{ -const Iid ApplicationList::iid ("ApplicationList"); +const InterfaceId ApplicationList::iid ("ApplicationList"); ApplicationList::ApplicationList(Ptr n) : Interface (ApplicationList::iid) diff --git a/src/applications/application-list.h b/src/applications/application-list.h index 689c4325b..2f4d0226a 100644 --- a/src/applications/application-list.h +++ b/src/applications/application-list.h @@ -34,7 +34,7 @@ namespace ns3 { class ApplicationList : public Interface { public: - static const Iid iid; + static const InterfaceId iid; ApplicationList(Ptr); // Copy constructor not needed, default one is correct virtual ~ApplicationList(); diff --git a/src/core/component-manager.cc b/src/core/component-manager.cc index 54cc60afb..497a39264 100644 --- a/src/core/component-manager.cc +++ b/src/core/component-manager.cc @@ -99,11 +99,11 @@ namespace { class B : public ns3::Interface { public: - static const ns3::Iid iid; + static const ns3::InterfaceId iid; B (); }; -const ns3::Iid B::iid ("IB"); +const ns3::InterfaceId B::iid ("IB"); B::B () : Interface (B::iid) @@ -116,7 +116,7 @@ public: static const ns3::ClassId cidZero; static const ns3::ClassId cidOneBool; static const ns3::ClassId cidOneUi32; - static const ns3::Iid iid; + static const ns3::InterfaceId iid; A (); A (bool); @@ -133,7 +133,7 @@ public: const ns3::ClassId A::cidZero = ns3::ComponentManager::RegisterConstructor ("A"); const ns3::ClassId A::cidOneBool = ns3::ComponentManager::RegisterConstructor ("ABool"); const ns3::ClassId A::cidOneUi32 = ns3::ComponentManager::RegisterConstructor ("AUi32"); -const ns3::Iid A::iid ("IA"); +const ns3::InterfaceId A::iid ("IA"); A::A () : Interface (A::iid), diff --git a/src/core/component-manager.h b/src/core/component-manager.h index 135b8faac..13d42fa57 100644 --- a/src/core/component-manager.h +++ b/src/core/component-manager.h @@ -121,13 +121,13 @@ public: * result. */ template - static Ptr Create (ClassId classId, Iid iid); + static Ptr Create (ClassId classId, InterfaceId iid); template - static Ptr Create (ClassId classId, Iid iid, T1 a1); + static Ptr Create (ClassId classId, InterfaceId iid, T1 a1); template - static Ptr Create (ClassId classId, Iid iid, T1 a1, T2 a2); + static Ptr Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2); /** * \param name the symbolic name to associate to this @@ -229,7 +229,7 @@ ComponentManager::Create (ClassId classId, T1 a1, T2 a2) template Ptr -ComponentManager::Create (ClassId classId, Iid iid) +ComponentManager::Create (ClassId classId, InterfaceId iid) { Ptr obj = Create (classId); Ptr i = obj->QueryInterface (iid); @@ -238,7 +238,7 @@ ComponentManager::Create (ClassId classId, Iid iid) template Ptr -ComponentManager::Create (ClassId classId, Iid iid, T1 a1) +ComponentManager::Create (ClassId classId, InterfaceId iid, T1 a1) { Ptr obj = Create (classId, a1); Ptr i = obj->QueryInterface (iid); @@ -247,7 +247,7 @@ ComponentManager::Create (ClassId classId, Iid iid, T1 a1) template Ptr -ComponentManager::Create (ClassId classId, Iid iid, T1 a1, T2 a2) +ComponentManager::Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2) { Ptr obj = Create (classId, a1, a2); Ptr i = obj->QueryInterface (iid); diff --git a/src/core/interface.cc b/src/core/interface.cc index ac7413e2b..030c5a031 100644 --- a/src/core/interface.cc +++ b/src/core/interface.cc @@ -34,11 +34,11 @@ namespace ns3 { class IidManager : public UidManager {}; -Iid::Iid (std::string name) +InterfaceId::InterfaceId (std::string name) : m_iid (Singleton::Get ()->Allocate (name)) {} -bool operator == (const Iid &a, const Iid &b) +bool operator == (const InterfaceId &a, const InterfaceId &b) { return a.m_iid == b.m_iid; } @@ -47,24 +47,24 @@ bool operator == (const Iid &a, const Iid &b) class InterfaceImpl { public: - InterfaceImpl (Iid iid, Interface *interface); + InterfaceImpl (InterfaceId iid, Interface *interface); ~InterfaceImpl (); void Ref (void); void RefAll (InterfaceImpl *other); void Unref (void); void UnrefAll (void); - Interface *PeekQueryInterface (Iid iid) const; + Interface *PeekQueryInterface (InterfaceId iid) const; void DoDisposeAll (void); void AddInterface (Interface * interface); - void AddSelfInterface (Iid iid, Interface *interface); + void AddSelfInterface (InterfaceId iid, Interface *interface); private: - typedef std::list > List; + typedef std::list > List; uint32_t m_ref; List m_list; bool m_disposed; }; -InterfaceImpl::InterfaceImpl (Iid iid, Interface * interface) +InterfaceImpl::InterfaceImpl (InterfaceId iid, Interface * interface) : m_ref (1), m_disposed (false) { @@ -124,7 +124,7 @@ InterfaceImpl::DoDisposeAll (void) m_disposed = true; } Interface * -InterfaceImpl::PeekQueryInterface (Iid iid) const +InterfaceImpl::PeekQueryInterface (InterfaceId iid) const { for (List::const_iterator i = m_list.begin (); i != m_list.end (); i++) @@ -149,14 +149,14 @@ InterfaceImpl::AddInterface (Interface *interface) } } void -InterfaceImpl::AddSelfInterface (Iid iid, Interface *interface) +InterfaceImpl::AddSelfInterface (InterfaceId iid, Interface *interface) { interface->RefInternal (); m_list.push_back (std::make_pair (iid, interface)); } -Interface::Interface (Iid iid) +Interface::Interface (InterfaceId iid) : m_impl (new InterfaceImpl (iid, this)), m_ref (1) {} @@ -206,7 +206,7 @@ Interface::UnrefInternal (void) } Ptr -Interface::DoQueryInterface (Iid iid) const +Interface::DoQueryInterface (InterfaceId iid) const { return m_impl->PeekQueryInterface (iid); } @@ -222,7 +222,7 @@ Interface::AddInterface (Ptr interface) } void -Interface::AddSelfInterface (Iid iid, Ptr interface) +Interface::AddSelfInterface (InterfaceId iid, Ptr interface) { m_impl->AddSelfInterface (iid, PeekPointer (interface)); } @@ -239,7 +239,7 @@ namespace { class A : public ns3::Interface { public: - static const ns3::Iid iid; + static const ns3::InterfaceId iid; A () : Interface (A::iid) {} @@ -247,7 +247,7 @@ public: class B : public ns3::Interface { public: - static const ns3::Iid iid; + static const ns3::InterfaceId iid; B () : Interface (B::iid) {} @@ -255,7 +255,7 @@ public: class BaseA : public ns3::Interface { public: - static const ns3::Iid iid; + static const ns3::InterfaceId iid; BaseA () : Interface (BaseA::iid) {} @@ -263,7 +263,7 @@ public: class BaseB : public ns3::Interface { public: - static const ns3::Iid iid; + static const ns3::InterfaceId iid; BaseB () : Interface (BaseB::iid) {} @@ -271,7 +271,7 @@ public: class Base : public ns3::Interface { public: - static const ns3::Iid iid; + static const ns3::InterfaceId iid; Base () : Interface (Base::iid) {} @@ -279,19 +279,19 @@ public: class Derived : public Base { public: - static const ns3::Iid iid; + static const ns3::InterfaceId iid; Derived () { AddSelfInterface (Derived::iid, this); } }; -const ns3::Iid A::iid ("A"); -const ns3::Iid B::iid ("B"); -const ns3::Iid BaseA::iid ("BaseA"); -const ns3::Iid BaseB::iid ("BaseB"); -const ns3::Iid Base::iid ("Base"); -const ns3::Iid Derived::iid ("Derived"); +const ns3::InterfaceId A::iid ("A"); +const ns3::InterfaceId B::iid ("B"); +const ns3::InterfaceId BaseA::iid ("BaseA"); +const ns3::InterfaceId BaseB::iid ("BaseB"); +const ns3::InterfaceId Base::iid ("Base"); +const ns3::InterfaceId Derived::iid ("Derived"); }//namespace diff --git a/src/core/interface.h b/src/core/interface.h index 7e8e6573d..be5ace7a9 100644 --- a/src/core/interface.h +++ b/src/core/interface.h @@ -28,12 +28,12 @@ namespace ns3 { class InterfaceImpl; -class Iid +class InterfaceId { public: - Iid (std::string name); + InterfaceId (std::string name); private: - friend bool operator == (const Iid &a, const Iid &b); + friend bool operator == (const InterfaceId &a, const InterfaceId &b); uint32_t m_iid; }; @@ -56,7 +56,7 @@ public: * \param iid the Interface id of the requested interface */ template - Ptr QueryInterface (Iid iid) const; + Ptr QueryInterface (InterfaceId iid) const; /** * \param interface another interface @@ -77,7 +77,7 @@ protected: * If you are a direct subclass of this class, you _must_ register * the name of your interface with this constructor. */ - Interface (Iid iid); + Interface (InterfaceId iid); /** * \param iid the Interface id of the interface * \param a pointer to the interface object @@ -87,7 +87,7 @@ protected: * (typically, your subclass has added API), you need to call * this method to associate an interface id to your interface. */ - void AddSelfInterface (Iid iid, Ptr interface); + void AddSelfInterface (InterfaceId iid, Ptr interface); protected: /** * Subclasses who want to handle the "dispose" event should @@ -99,7 +99,7 @@ protected: private: friend class InterfaceImpl; Interface (); - Ptr DoQueryInterface (Iid iid) const; + Ptr DoQueryInterface (InterfaceId iid) const; void RefInternal (void); void UnrefInternal (void); InterfaceImpl *m_impl; @@ -112,7 +112,7 @@ namespace ns3 { template Ptr -Interface::QueryInterface (Iid iid) const +Interface::QueryInterface (InterfaceId iid) const { Ptr found = DoQueryInterface (iid); if (found != 0) diff --git a/src/internet-node/i-arp-private.cc b/src/internet-node/i-arp-private.cc index 815bd9cec..0071b86bd 100644 --- a/src/internet-node/i-arp-private.cc +++ b/src/internet-node/i-arp-private.cc @@ -25,7 +25,7 @@ namespace ns3 { -const Iid IArpPrivate::iid ("IArpPrivate"); +const InterfaceId IArpPrivate::iid ("IArpPrivate"); IArpPrivate::IArpPrivate (Ptr arp) : Interface (IArpPrivate::iid), diff --git a/src/internet-node/i-arp-private.h b/src/internet-node/i-arp-private.h index 5e87b214c..1d78b07fb 100644 --- a/src/internet-node/i-arp-private.h +++ b/src/internet-node/i-arp-private.h @@ -34,7 +34,7 @@ class Arp; class IArpPrivate : public Interface { public: - static const Iid iid; + static const InterfaceId iid; IArpPrivate (Ptr arp); virtual ~IArpPrivate (); bool Lookup (Packet &p, Ipv4Address destination, diff --git a/src/internet-node/i-ipv4-private.cc b/src/internet-node/i-ipv4-private.cc index 22d853877..8928a363b 100644 --- a/src/internet-node/i-ipv4-private.cc +++ b/src/internet-node/i-ipv4-private.cc @@ -25,7 +25,7 @@ namespace ns3 { -const Iid IIpv4Private::iid ("IIpv4Private"); +const InterfaceId IIpv4Private::iid ("IIpv4Private"); IIpv4Private::IIpv4Private (Ptr ipv4) : Interface (IIpv4Private::iid), diff --git a/src/internet-node/i-ipv4-private.h b/src/internet-node/i-ipv4-private.h index d1c2d8bd9..70695f150 100644 --- a/src/internet-node/i-ipv4-private.h +++ b/src/internet-node/i-ipv4-private.h @@ -38,7 +38,7 @@ class NetDevice; class IIpv4Private : public Interface { public: - static const Iid iid; + static const InterfaceId iid; IIpv4Private (Ptr ipv4); virtual ~IIpv4Private (); diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index 3e01cb4d7..a60ed9629 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -30,7 +30,7 @@ namespace ns3 { -const Iid Ipv4L4Demux::iid ("Ipv4L4Demux"); +const InterfaceId Ipv4L4Demux::iid ("Ipv4L4Demux"); Ipv4L4Demux::Ipv4L4Demux (Ptr node) : Interface (Ipv4L4Demux::iid), diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index 645309abc..f6b199be9 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -42,7 +42,7 @@ class TraceContext; class Ipv4L4Demux : public Interface { public: - static const Iid iid; + static const InterfaceId iid; typedef int Ipv4L4ProtocolTraceType; Ipv4L4Demux (Ptr node); virtual ~Ipv4L4Demux(); diff --git a/src/internet-node/l3-demux.cc b/src/internet-node/l3-demux.cc index 6b58d6c43..e5912c64c 100644 --- a/src/internet-node/l3-demux.cc +++ b/src/internet-node/l3-demux.cc @@ -29,7 +29,7 @@ namespace ns3 { -const Iid L3Demux::iid ("L3Demux"); +const InterfaceId L3Demux::iid ("L3Demux"); L3Demux::L3Demux (Ptr node) : Interface (L3Demux::iid), diff --git a/src/internet-node/l3-demux.h b/src/internet-node/l3-demux.h index a0c9713b1..477a43e92 100644 --- a/src/internet-node/l3-demux.h +++ b/src/internet-node/l3-demux.h @@ -44,7 +44,7 @@ class TraceContext; class L3Demux : public Interface { public: - static const Iid iid; + static const InterfaceId iid; typedef int ProtocolTraceType; L3Demux(Ptr node); virtual ~L3Demux(); diff --git a/src/node/i-ipv4.cc b/src/node/i-ipv4.cc index bfb6e2c0b..c0fea96a8 100644 --- a/src/node/i-ipv4.cc +++ b/src/node/i-ipv4.cc @@ -22,7 +22,7 @@ namespace ns3 { -const Iid IIpv4::iid ("IIpv4"); +const InterfaceId IIpv4::iid ("IIpv4"); IIpv4::IIpv4 () : Interface (IIpv4::iid) diff --git a/src/node/i-ipv4.h b/src/node/i-ipv4.h index 121a6e6ea..2f064b2d3 100644 --- a/src/node/i-ipv4.h +++ b/src/node/i-ipv4.h @@ -34,7 +34,7 @@ class Ipv4Route; class IIpv4 : public Interface { public: - static const Iid iid; + static const InterfaceId iid; IIpv4 (); virtual ~IIpv4 (); diff --git a/src/node/i-udp.cc b/src/node/i-udp.cc index 92263ce34..5bf31aa0d 100644 --- a/src/node/i-udp.cc +++ b/src/node/i-udp.cc @@ -22,7 +22,7 @@ namespace ns3 { -const Iid IUdp::iid ("IUdp"); +const InterfaceId IUdp::iid ("IUdp"); IUdp::IUdp () : Interface (IUdp::iid) diff --git a/src/node/i-udp.h b/src/node/i-udp.h index 0e7c08b00..8fc071371 100644 --- a/src/node/i-udp.h +++ b/src/node/i-udp.h @@ -31,7 +31,7 @@ class Socket; class IUdp : public Interface { public: - static const Iid iid; + static const InterfaceId iid; IUdp (); diff --git a/src/node/node.cc b/src/node/node.cc index ea57ddb2c..7d57305ab 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -29,7 +29,7 @@ namespace ns3{ -const Iid Node::iid ("Node"); +const InterfaceId Node::iid ("Node"); Node::Node() : Interface (Node::iid), diff --git a/src/node/node.h b/src/node/node.h index 0ea49fcfd..42fa0b4fe 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -38,7 +38,7 @@ class NetDevice; class Node : public Interface { public: - static const Iid iid; + static const InterfaceId iid; Node(); Node(uint32_t); // Specify which system for a distributed simulation From 5cb92847c4c858a70ebedbdcf6bb27a953dc0bdd Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 19:15:28 +0200 Subject: [PATCH 39/59] 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, From b3aee2deb2548a987b5796f8f41c842f8feac2c2 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 19:26:01 +0200 Subject: [PATCH 40/59] NetDevice and Channel now derive from Interface rather than Object --- src/node/channel.cc | 8 ++++++-- src/node/channel.h | 5 +++-- src/node/net-device.cc | 6 +++++- src/node/net-device.h | 7 ++++--- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/node/channel.cc b/src/node/channel.cc index 690da0ce8..c5875b82e 100644 --- a/src/node/channel.cc +++ b/src/node/channel.cc @@ -27,14 +27,18 @@ NS_DEBUG_COMPONENT_DEFINE ("Channel"); namespace ns3 { +const InterfaceId Channel::iid ("Channel"); + Channel::Channel () - : m_name("Channel") + : Interface (Channel::iid), + m_name("Channel") { NS_DEBUG("Channel::Channel ()"); } Channel::Channel (std::string name) - : m_name(name) + : Interface (Channel::iid), + m_name(name) { NS_DEBUG("Channel::Channel (" << name << ")"); } diff --git a/src/node/channel.h b/src/node/channel.h index aefbf98b3..20671f9d5 100644 --- a/src/node/channel.h +++ b/src/node/channel.h @@ -24,7 +24,7 @@ #include #include -#include "ns3/object.h" +#include "ns3/interface.h" #include "ns3/ptr.h" namespace ns3 { @@ -37,9 +37,10 @@ class NetDevice; * A channel is a logical path over which information flows. The path can * be as simple as a short piece of wire, or as complicated as space-time. */ -class Channel : public Object +class Channel : public Interface { public: + static const InterfaceId iid; Channel (); Channel (std::string name); diff --git a/src/node/net-device.cc b/src/node/net-device.cc index bd5b2946f..86b25d2de 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -21,15 +21,19 @@ #include #include "ns3/assert.h" +#include "ns3/interface.h" +#include "channel.h" #include "net-device.h" #include "llc-snap-header.h" #include "node.h" -#include "ns3/channel.h" namespace ns3 { +const InterfaceId NetDevice::iid ("NetDevice"); + NetDevice::NetDevice(Ptr node, const MacAddress& addr) : + Interface (NetDevice::iid), m_node (node), m_name(""), m_ifIndex (0), diff --git a/src/node/net-device.h b/src/node/net-device.h index 78ed233d5..92289d5e0 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -25,9 +25,9 @@ #include #include "ns3/callback.h" #include "ns3/packet.h" -#include "ns3/object.h" -#include "mac-address.h" +#include "ns3/interface.h" #include "ns3/ptr.h" +#include "mac-address.h" namespace ns3 { @@ -55,9 +55,10 @@ class Channel; * this base class and implement your own version of the * NetDevice::SendTo method. */ -class NetDevice : public Object +class NetDevice : public Interface { public: + static const InterfaceId iid; /** * \param node base class node pointer of device's node * \param addr MAC address of this device. From 3834d248de669eb23a43ed19ed0f5db6078fccce Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 11 May 2007 22:33:51 +0200 Subject: [PATCH 41/59] add a small comment --- src/core/uid-manager.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/uid-manager.h b/src/core/uid-manager.h index 5cc6c1adc..e4648e31a 100644 --- a/src/core/uid-manager.h +++ b/src/core/uid-manager.h @@ -27,6 +27,9 @@ namespace ns3 { +/** + * zero is never a valid uid value. + */ class UidManager { public: From 5c5ad7b16a5081367f65280a9f6f149807efad2f Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 11 May 2007 22:28:12 -0700 Subject: [PATCH 42/59] Removing superseded code for p2p --- src/devices/p2p-gfr/p2p-channel.cc | 98 --------------------------- src/devices/p2p-gfr/p2p-channel.h | 56 --------------- src/devices/p2p-gfr/p2p-net-device.cc | 80 ---------------------- src/devices/p2p-gfr/p2p-net-device.h | 54 --------------- src/devices/p2p-gfr/wscript | 23 ------- 5 files changed, 311 deletions(-) delete mode 100644 src/devices/p2p-gfr/p2p-channel.cc delete mode 100644 src/devices/p2p-gfr/p2p-channel.h delete mode 100644 src/devices/p2p-gfr/p2p-net-device.cc delete mode 100644 src/devices/p2p-gfr/p2p-net-device.h delete mode 100644 src/devices/p2p-gfr/wscript diff --git a/src/devices/p2p-gfr/p2p-channel.cc b/src/devices/p2p-gfr/p2p-channel.cc deleted file mode 100644 index 09e338cdc..000000000 --- a/src/devices/p2p-gfr/p2p-channel.cc +++ /dev/null @@ -1,98 +0,0 @@ -// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// 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 -// -// Author: George F. Riley -// - -// Implementation of simple point-to-point channel -// George F. Riley, Georgia Tech, Spring 2007 - -#include "ns3/simulator.h" -#include "ns3/packet.h" -#include "ns3/node.h" -#include "p2p-channel.h" -#include "p2p-net-device.h" - -namespace ns3 { - -P2PChannel::P2PChannel(const Time& delay, double maxRate) - : m_nd1(0), m_nd2(0), - m_delay (delay), - m_maxRate (maxRate) -{ -} - -P2PChannel::~P2PChannel () -{} - -// Channels create compatible net devices -P2PNetDevice* P2PChannel::CreateNetDevice(Node *node, MacAddress address) -{ - // Create a new point-to-point network device - P2PNetDevice* nd = new P2PNetDevice(node, address); - nd->Connect (this); - // Add to list of peers - if (!m_nd1) m_nd1 = nd; - else m_nd2 = nd; - return nd; -} - -void P2PChannel::RemoveNetDevice(NetDevice* nd) -{ - if (nd == m_nd1) m_nd1 = 0; - if (nd == m_nd2) m_nd2 = 0; - // Now if all removed, remove the channel as well - if (!m_nd1 && !m_nd2) - { - delete this; - } -} - -void P2PChannel::Send(P2PNetDevice *device, Packet& p, double rate) -{ // Schedule a receive event at receiver - // First calculate time in future - double maxRate; - if (rate < m_maxRate) - { - maxRate = rate; - } - else - { - maxRate = m_maxRate; - } - Time txTime = Seconds (p.GetSize() * 8 / maxRate); - Time rxTime = m_delay + txTime; - P2PNetDevice *to, *from; - if (device == m_nd1) - { - from = m_nd1; - to = m_nd2; - } - else - { - from = m_nd2; - to = m_nd1; - } - // Schedule the receive event at receiver - Simulator::Schedule(rxTime, &P2PNetDevice::Receive, to, p); - // Schedule the link free event - Simulator::Schedule(txTime, &P2PNetDevice::TxComplete, from); - -} - -}//namespace ns3 diff --git a/src/devices/p2p-gfr/p2p-channel.h b/src/devices/p2p-gfr/p2p-channel.h deleted file mode 100644 index 891d3826f..000000000 --- a/src/devices/p2p-gfr/p2p-channel.h +++ /dev/null @@ -1,56 +0,0 @@ -// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// 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 -// -// Author: George F. Riley -// - -// Definition of a simple point-to-point channel -// George F. Riley, Georgia Tech, Spring 2007 - -#ifndef P2P_CHANNEL_H -#define P2P_CHANNEL_H - -#include "ns3/nstime.h" -#include "ns3/mac-address.h" - -namespace ns3 { - -class P2PNetDevice; -class NetDevice; -class Node; -class Packet; - -class P2PChannel { -public: - P2PChannel(const Time& delay, double maxRate /* bits/s */); - ~P2PChannel(); - - P2PNetDevice* CreateNetDevice(Node *node, MacAddress address); - void RemoveNetDevice (NetDevice *device); - void Send (P2PNetDevice *device, Packet&p, double rate /* bits/s */); -private: - // The two endpoints of this channel - P2PNetDevice* m_nd1; - P2PNetDevice* m_nd2; - Time m_delay; - double m_maxRate; -}; - -}//namespace ns3 - -#endif diff --git a/src/devices/p2p-gfr/p2p-net-device.cc b/src/devices/p2p-gfr/p2p-net-device.cc deleted file mode 100644 index fe81c2f64..000000000 --- a/src/devices/p2p-gfr/p2p-net-device.cc +++ /dev/null @@ -1,80 +0,0 @@ -// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// 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 -// -// Author: George F. Riley -// - -// Implementation of a point-to-point network device -// George F. Riley, Georgia Tech, Spring 2007 - -#include "ns3/empty-trace-resolver.h" -#include "p2p-net-device.h" -#include "p2p-channel.h" - -namespace ns3 { - -P2PNetDevice::P2PNetDevice (Node *node, MacAddress const &addr) - : NetDevice (node, addr), - m_rate (1000000) -{ - SetMtu (2300); - EnableBroadcast (MacAddress ("ff:ff:ff:ff:ff:ff")); -} - -P2PNetDevice::~P2PNetDevice() -{ // Inform channel that we are destroyed - m_channel->RemoveNetDevice(this); -} - -void -P2PNetDevice::SetRate (double rate) -{ - m_rate = rate; -} - -void -P2PNetDevice::Connect (P2PChannel *channel) -{ - m_channel = channel; - NotifyLinkUp (); -} - -bool -P2PNetDevice::SendTo (Packet& p, const MacAddress&) -{ - m_channel->Send (this, p, m_rate); - return true; -} - -TraceResolver * -P2PNetDevice::DoCreateTraceResolver (TraceContext const &context) -{ - return new EmptyTraceResolver (context); -} - -void -P2PNetDevice::Receive(Packet p) -{ - ForwardUp (p); -} - -void -P2PNetDevice::TxComplete (void) -{} - -}//namespace ns3 diff --git a/src/devices/p2p-gfr/p2p-net-device.h b/src/devices/p2p-gfr/p2p-net-device.h deleted file mode 100644 index 4809ea738..000000000 --- a/src/devices/p2p-gfr/p2p-net-device.h +++ /dev/null @@ -1,54 +0,0 @@ -// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// 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 -// -// Author: George F. Riley -// - -// Definition for a Point-to-Point network device -// George F. Riley, Georgia Tech, Spring 2007 - -#ifndef P2P_NET_DEVICE_H -#define P2P_NET_DEVICE_H - -#include "ns3/net-device.h" - -namespace ns3 { - -class P2PChannel; - -class P2PNetDevice : public NetDevice { -public: - P2PNetDevice(Node *node, MacAddress const &addr); - virtual ~P2PNetDevice(); - - void SetRate (double rate); - void Connect (P2PChannel *channel); - void Receive(Packet p); - void TxComplete (void); - private: - virtual bool SendTo (Packet& p, const MacAddress& dest); - virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); - - double m_rate; - P2PChannel *m_channel; -}; - -}//namespace ns3 - -#endif /* P2P_NET_DEVICE_H */ - diff --git a/src/devices/p2p-gfr/wscript b/src/devices/p2p-gfr/wscript deleted file mode 100644 index 8b92512bf..000000000 --- a/src/devices/p2p-gfr/wscript +++ /dev/null @@ -1,23 +0,0 @@ -## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- - - -def build(bld): - p2p = bld.create_obj('cpp', 'objects') - p2p.name = 'ns3-p2p-gfr' - p2p.source = [ - 'p2p-net-device.cc', - 'p2p-channel.cc', - 'p2p-topology.cc', - 'p2p-phy.cc', - 'layer-connector.cc', - ] - headers = bld.create_obj('ns3header') - headers.name = 'ns3-p2p-gfr-headers' - headers.source = [ - 'p2p-net-device.h', - 'p2p-channel.h', - 'p2p-topology.h', - 'p2p-phy.h', - 'layer-connector.h', - ] - From dc01b2136ec7c8d92768b80201a8c9f6bc09303e Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sat, 12 May 2007 15:31:40 -0700 Subject: [PATCH 43/59] Separate address assignment from routing in PointToPoint topology code --- examples/simple-p2p.cc | 13 +++++- src/devices/p2p/p2p-topology.cc | 79 ++++++++++++++++++++++++++++++-- src/devices/p2p/p2p-topology.h | 49 ++++++++++++++------ src/internet-node/i-ipv4-impl.cc | 6 +++ src/internet-node/i-ipv4-impl.h | 1 + src/node/i-ipv4.h | 5 ++ 6 files changed, 132 insertions(+), 21 deletions(-) diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index fb4f91311..bc44cd0f0 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -122,16 +122,25 @@ int main (int argc, char *argv[]) PointToPointTopology::AddIpv4Addresses ( channel0, n0, Ipv4Address("10.1.1.1"), n2, Ipv4Address("10.1.1.2")); - channel0->Unref (); PointToPointTopology::AddIpv4Addresses ( channel1, n1, Ipv4Address("10.1.2.1"), n2, Ipv4Address("10.1.2.2")); - channel1->Unref (); PointToPointTopology::AddIpv4Addresses ( channel2, n2, Ipv4Address("10.1.3.1"), n3, Ipv4Address("10.1.3.2")); + + // Finally, we add static routes. These three steps (Channel and + // NetDevice creation, IP Address assignment, and routing) are + // separated because there may be a need to postpone IP Address + // assignment (emulation) or modify to use dynamic routing + PointToPointTopology::AddIpv4Routes(n0, n2, channel0); + PointToPointTopology::AddIpv4Routes(n1, n2, channel1); + PointToPointTopology::AddIpv4Routes(n2, n3, channel2); + + channel0->Unref (); + channel1->Unref (); channel2->Unref (); // Create the OnOff application to send UDP datagrams of size diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index 6ff05eab9..84b02528b 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -24,6 +24,8 @@ #include #include "ns3/assert.h" +#include "ns3/debug.h" +#include "ns3/fatal-error.h" #include "ns3/nstime.h" @@ -62,7 +64,7 @@ PointToPointTopology::AddPointToPointLink( return channel; } -bool +void PointToPointTopology::AddIpv4Addresses( const PointToPointChannel *chan, Node* n1, const Ipv4Address& addr1, @@ -101,15 +103,82 @@ PointToPointTopology::AddIpv4Addresses( ip2->SetNetworkMask (index2, netmask); ip2->SetUp (index2); - ip1->AddHostRouteTo (addr2, index1); - ip2->AddHostRouteTo (addr1, index2); - ip1->Unref (); ip2->Unref (); - return true; } +void +PointToPointTopology::AddIpv4Routes ( + Node* n1, Node* n2, const PointToPointChannel* chan) +{ + // The PointToPoint channel is used to find the relevant NetDevices + NS_ASSERT (chan->GetNDevices () == 2); + NetDevice* nd1 = chan->GetDevice (0); + NetDevice* nd2 = chan->GetDevice (1); + // XXX nd1, nd2 should be reference counted + + // Assert that n1 is the Node owning one of the two NetDevices + // and make sure that nd1 corresponds to it + if (nd1->PeekNode ()->GetId () == n1->GetId ()) + { + ; // Do nothing + } + else if (nd2->PeekNode ()->GetId () == n1->GetId ()) + { + std::swap(nd1, nd2); + } + else + { + NS_FATAL_ERROR("P2PTopo: Node does not contain an interface on Channel"); + } + + // Assert that n2 is the Node owning one of the two NetDevices + // and make sure that nd2 corresponds to it + if (nd2->PeekNode ()->GetId () != n2->GetId ()) + { + NS_FATAL_ERROR("P2PTopo: Node does not contain an interface on Channel"); + } + + // Assert that both are Ipv4 nodes + IIpv4 *ip1 = nd1->PeekNode ()->QueryInterface (IIpv4::iid); + IIpv4 *ip2 = nd2->PeekNode ()->QueryInterface (IIpv4::iid); + NS_ASSERT(ip1 && ip2); + + // Get interface indexes for both nodes corresponding to the right channel + uint32_t index1 = 0; + bool found = false; + for (uint32_t i = 0; i < ip1->GetNInterfaces (); i++) + { + if (ip1 ->PeekNetDevice (i) == nd1) + { + index1 = i; + found = true; + } + } + NS_ASSERT(found); + + uint32_t index2 = 0; + found = false; + for (uint32_t i = 0; i < ip2->GetNInterfaces (); i++) + { + if (ip2 ->PeekNetDevice (i) == nd2) + { + index2 = i; + found = true; + } + } + NS_ASSERT(found); + + ip1->AddHostRouteTo (ip2-> GetAddress (index2), index1); + ip2->AddHostRouteTo (ip1-> GetAddress (index1), index2); + + ip1->Unref (); + ip2->Unref (); + +} + + #ifdef NOTYET // Get the net device connecting node n1 to n2. For topologies where diff --git a/src/devices/p2p/p2p-topology.h b/src/devices/p2p/p2p-topology.h index dc8cbb88d..1a1ed9870 100644 --- a/src/devices/p2p/p2p-topology.h +++ b/src/devices/p2p/p2p-topology.h @@ -33,30 +33,51 @@ class Node; class IPAddr; class DataRate; class Queue; -//class Time; /** - * \brief A helper class to create Topologies based on the ns3::PointToPointNetDevice and - * ns3::PointToPointChannel objects. - * - * XXX ?? - * I think that some of the methods below are not implemented. - * If so, remove them. + * \brief A helper class to create Topologies based on the + * ns3::PointToPointNetDevice and ns3::PointToPointChannel objects. */ class PointToPointTopology { public: /** + * \param n1 Node + * \param n2 Node + * \param rate Maximum transmission link rate + * \param delay one-way propagation delay + * \return Pointer to the underlying PointToPointChannel + * * Add a full-duplex point-to-point link between two nodes - * with the specified IP addresses, with specified maximum transmission rate - * and propagation delay. + * and attach PointToPointNetDevices to the resulting + * PointToPointChannel. */ static PointToPointChannel* AddPointToPointLink( - Node*, Node*, const DataRate&, const Time&); + Node* n1, Node* n2, const DataRate& rate, const Time& delay); - static bool AddIpv4Addresses( - const PointToPointChannel*, - Node*, const Ipv4Address&, - Node*, const Ipv4Address&); + /** + * \param chan PointToPointChannel to use + * \param n1 Node + * \param addr1 Ipv4 Address for n1 + * \param n2 Node + * \param addr2 Ipv4 Address for n2 + * + * Add Ipv4Addresses to the Ipv4 interfaces associated with the + * two PointToPointNetDevices on the provided PointToPointChannel + */ + static void AddIpv4Addresses( + const PointToPointChannel* chan, + Node* n1, const Ipv4Address& addr1, + Node* n2, const Ipv4Address& addr2); + + /** + * \param chan PointToPointChannel to use + * \param n1 Node + * \param n2 Node + * + * For the given PointToPointChannel, for each Node, add an + * IPv4 host route to the IPv4 address of the peer node. + */ + static void AddIpv4Routes (Node*, Node*, const PointToPointChannel*); /** * Get the connecting node n1 to node n2 diff --git a/src/internet-node/i-ipv4-impl.cc b/src/internet-node/i-ipv4-impl.cc index 82b5d0155..df612b2d1 100644 --- a/src/internet-node/i-ipv4-impl.cc +++ b/src/internet-node/i-ipv4-impl.cc @@ -20,6 +20,7 @@ */ #include "i-ipv4-impl.h" #include "ipv4.h" +#include "ipv4-interface.h" #include "ns3/assert.h" namespace ns3 { @@ -99,6 +100,11 @@ IIpv4Impl::GetNInterfaces (void) { return m_ipv4->GetNInterfaces (); } +NetDevice* +IIpv4Impl::PeekNetDevice (uint32_t i) +{ + return m_ipv4->GetInterface (i)-> PeekDevice(); +} void IIpv4Impl::SetAddress (uint32_t i, Ipv4Address address) diff --git a/src/internet-node/i-ipv4-impl.h b/src/internet-node/i-ipv4-impl.h index b3240a089..52ca9869e 100644 --- a/src/internet-node/i-ipv4-impl.h +++ b/src/internet-node/i-ipv4-impl.h @@ -53,6 +53,7 @@ public: virtual void RemoveRoute (uint32_t i); virtual uint32_t AddInterface (NetDevice *device); virtual uint32_t GetNInterfaces (void); + virtual NetDevice* PeekNetDevice(uint32_t i); virtual void SetAddress (uint32_t i, Ipv4Address address); virtual void SetNetworkMask (uint32_t i, Ipv4Mask mask); diff --git a/src/node/i-ipv4.h b/src/node/i-ipv4.h index 11197de90..20ec3394f 100644 --- a/src/node/i-ipv4.h +++ b/src/node/i-ipv4.h @@ -122,6 +122,11 @@ public: */ virtual uint32_t GetNInterfaces (void) = 0; + /** + * Return address of the NetDevice associated with the Ipv4Interface + */ + virtual NetDevice* PeekNetDevice (uint32_t i) = 0; + virtual void SetAddress (uint32_t i, Ipv4Address address) = 0; virtual void SetNetworkMask (uint32_t i, Ipv4Mask mask) = 0; virtual Ipv4Mask GetNetworkMask (uint32_t t) const = 0; From bca528b89ac62cc93cbcbd9fcee63886c3c6acfe Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sat, 12 May 2007 15:36:41 -0700 Subject: [PATCH 44/59] Remove unused code --- examples/simple-p2p.cc | 3 +- src/devices/p2p/p2p-topology.cc | 110 -------------------------------- src/devices/p2p/p2p-topology.h | 17 ----- 3 files changed, 2 insertions(+), 128 deletions(-) diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index bc44cd0f0..3d44e314e 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -205,7 +205,8 @@ int main (int argc, char *argv[]) // Also configure some tcpdump traces; each interface will be traced // The output files will be named simple-p2p.pcap-- - // and can be read by the "tcpdump -r" command + // and can be read by the "tcpdump -r" command (use "-tt" option to + // display timestamps correctly) PcapTrace pcaptrace ("simple-p2p.pcap"); pcaptrace.TraceAllIp (); diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index 84b02528b..f748b87a3 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -178,115 +178,5 @@ PointToPointTopology::AddIpv4Routes ( } - -#ifdef NOTYET - -// Get the net device connecting node n1 to n2. For topologies where -// there are possibly multiple devices connecting n1 and n2 (for example -// wireless with two devices on different channels) this will return -// the first one found. -PointToPointNetDevice* PointToPointTopology::GetNetDevice(Node* n1, Node* n2) -{ - // First get the NetDeviceList capability from node 1 - NetDeviceList* ndl1 = n1->GetNetDeviceList(); - if (!ndl1) return 0; // No devices, return nil - // Get the list of devices - const NetDeviceList::NetDevices_t& dlist = ndl1->GetAll(); - for (NetDeviceList::NetDevices_t::const_iterator i = dlist.Begin(); - i != dlist.End(); ++i) - { // Check each device - NetDevice* nd = *i; // next device - Channel* c = nd->GetChannel(); - if (!c) continue; // No channel - if (c->NodeIsPeer(n2)) return nd; // found it - } - return 0; // None found -} - -// Get the channel connecting node n1 to node n2 -PointToPointChannel* PointToPointTopology::GetChannel( - Node* n1, - Node* n2 -) -{ - NetDevice* nd = GetNetDevice(n1, n2); - if (!nd) return 0; // No net device, so no channel - return nd->GetChannel(); -} - -Queue* PointToPointTopology::GetQueue(Node* n1, Node* n2) -{ - NetDevice* nd = GetNetDevice(n1, n2); - if (!nd) return 0; // No net device, so in queue - return nd->GetQueue(); -} - -Queue* PointToPointTopology::SetQueue(Node* n1, Node* n2, const Queue& q) -{ - NetDevice* nd = GetNetDevice(n1, n2); - if (!nd) return 0; // No net device, can't set queue - // Add the specified queue to the netdevice - return nd->SetQueue(q); -} - -#endif - -#ifdef GFR -P2PChannel* Topology::AddDuplexLink(Node* n1, const IPAddr& ip1, - Node* n2, const IPAddr& ip2, - const Rate& rate, const Time& delay) -{ - // First get the NetDeviceList capability from each node - NetDeviceList* ndl1 = n1->GetNetDeviceList(); - NetDeviceList* ndl2 = n2->GetNetDeviceList(); - if (!ndl1 || !ndl2) return nil; // Both ends must have NetDeviceList - // Get the net devices - P2PNetDevice* nd1 = ndl1->Add(P2PNetDevice(n1, rate, nil)); - P2PNetDevice* nd2 = ndl2->Add(P2PNetDevice(n1, rate, nd1->GetChannel())); - // Not implemented yet. Add appropriate layer 2 protocol for - // the net devices. - // Get the L3 proto for node 1 and configure it with this device - L3Demux* l3demux1 = n1->GetL3Demux(); - L3Protocol* l3proto1 = nil; - // If the node 1 l3 demux exists, find the coresponding l3 protocol - if (l3demux1) l3proto1 = l3demux1->Lookup(ip1.L3Proto()); - // If the l3 protocol exists, configure this net device. Use a mask - // of all ones, since there is only one device on the remote end - // of this link - if (l3proto1) l3proto1->AddNetDevice(nd1, ip1, ip1.GetMask(ip1.Size()*8)); - // Same for node 2 - L3Demux* l3demux2 = n2->GetL3Demux(); - L3Protocol* l3proto2 = nil; - // If the node 2 l3 demux exists, find the coresponding l3 protocol - if (l3demux2) l3proto2 = l3demux2->Lookup(ip2.L3Proto()); - if (l3proto2) l3proto2->AddNetDevice(nd2, ip2, ip2.GetMask(ip2.Size()*8)); - return dynamic_cast(nd1->GetChannel()); // Always succeeds -} - -// Get the channel connecting node n1 to node n2 -Channel* Topology::GetChannel(Node* n1, Node* n2) -{ - NetDevice* nd = GetNetDevice(n1, n2); - if (!nd) return 0; // No net device, so no channel - return nd->GetChannel(); -} - -Queue* Topology::GetQueue(Node* n1, Node* n2) -{ - NetDevice* nd = GetNetDevice(n1, n2); - if (!nd) return 0; // No net device, so in queue - return nd->GetQueue(); -} - -Queue* Topology::SetQueue(Node* n1, Node* n2, const Queue& q) -{ - NetDevice* nd = GetNetDevice(n1, n2); - if (!nd) return 0; // No net device, can't set queue - // Add the specified queue to the netdevice - return nd->SetQueue(q); -} - -#endif - } // namespace ns3 diff --git a/src/devices/p2p/p2p-topology.h b/src/devices/p2p/p2p-topology.h index 1a1ed9870..2f5e4c75b 100644 --- a/src/devices/p2p/p2p-topology.h +++ b/src/devices/p2p/p2p-topology.h @@ -78,23 +78,6 @@ public: * IPv4 host route to the IPv4 address of the peer node. */ static void AddIpv4Routes (Node*, Node*, const PointToPointChannel*); - - /** - * Get the connecting node n1 to node n2 - */ - static PointToPointChannel* GetChannel(Node*, Node*); - /** - * Get the NetDevice connecting node n1 to n2 - */ - static PointToPointNetDevice* GetNetDevice(Node*, Node*); - /** - * Get the queue associated with a link between two nodes - */ - static Queue* GetQueue(Node*, Node*); - /** - * Set the queue associated with a link between two nodes - */ - static Queue* SetQueue(Node*, Node*, const Queue&); }; } // namespace ns3 From a37a1569772e855303698e34afad64fe79feefbb Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 09:35:03 +0200 Subject: [PATCH 45/59] make Queue::CreateDefault use the ComponentManager. --- src/devices/p2p/p2p-topology.cc | 8 ++---- src/node/drop-tail.cc | 12 +++----- src/node/drop-tail.h | 3 +- src/node/queue.cc | 50 ++++++--------------------------- src/node/queue.h | 17 ++--------- 5 files changed, 20 insertions(+), 70 deletions(-) diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index 95a681d02..2143b946d 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -24,13 +24,11 @@ #include #include "ns3/assert.h" - #include "ns3/nstime.h" - #include "ns3/internet-node.h" #include "ns3/ipv4-address.h" -#include "ns3/drop-tail.h" #include "ns3/i-ipv4.h" +#include "ns3/queue.h" #include "p2p-channel.h" #include "p2p-net-device.h" @@ -49,14 +47,14 @@ PointToPointTopology::AddPointToPointLink( Ptr net1 = MakeNewObject (n1); - Ptr q = MakeNewObject (); + Ptr q = Queue::CreateDefault (); net1->AddQueue(q); n1->AddDevice (net1); net1->Attach (channel); Ptr net2 = MakeNewObject (n2); - q = MakeNewObject (); + q = Queue::CreateDefault (); net2->AddQueue(q); n2->AddDevice (net2); net2->Attach (channel); diff --git a/src/node/drop-tail.cc b/src/node/drop-tail.cc index db7a3bcab..8571bfe8a 100644 --- a/src/node/drop-tail.cc +++ b/src/node/drop-tail.cc @@ -27,12 +27,13 @@ namespace ns3 { static class QueueStackInitializationClass { public: QueueStackInitializationClass () { - Queue::Default (DropTailQueue ()); - static DropTailQueue queue; - Queue::AddDefault (queue, "DropTailQueue"); + Queue::AddDefault ("DropTailQueue"); } } queue_stack_initialization_class; +const ClassId DropTailQueue::cid = + ComponentManager::RegisterConstructor ("DropTailQueue"); + DropTailQueue::DropTailQueue () : Queue (), @@ -47,11 +48,6 @@ 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 99e52e4f9..ae79b2350 100644 --- a/src/node/drop-tail.h +++ b/src/node/drop-tail.h @@ -23,6 +23,7 @@ #include #include "ns3/packet.h" #include "ns3/queue.h" +#include "ns3/component-manager.h" namespace ns3 { @@ -32,10 +33,10 @@ const int DTQ_NPACKETS_MAX_DEFAULT = 100; class DropTailQueue : public Queue { public: + static const ClassId cid; 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 5b3d808bf..b63d9d7b3 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -19,8 +19,9 @@ #include "ns3/debug.h" #include "ns3/composite-trace-resolver.h" -#include "queue.h" #include "ns3/default-value.h" +#include "ns3/component-manager.h" +#include "queue.h" NS_DEBUG_COMPONENT_DEFINE ("Queue"); @@ -28,8 +29,6 @@ namespace ns3 { const InterfaceId Queue::iid ("Queue"); -Queue* Queue::defaultQueue = 0; - Queue::Queue() : Interface (Queue::iid), m_nBytes(0), @@ -197,50 +196,23 @@ 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; -} - - -Queue * +Ptr Queue::CreateDefault (void) { std::string defaultValue = GetDefault ()->GetValue (); - for (List::iterator i = GetList ()->begin (); - i != GetList ()->end (); i++) - { - if (i->second == defaultValue) - { - return i->first->Copy (); - } - } - NS_ASSERT (false); - // quiet compiler - return 0; + ClassId classId = ComponentManager::LookupByName (defaultValue); + Ptr queue = ComponentManager::Create (classId, Queue::iid); + return queue; } void -Queue::Add (Queue &queue, const std::string &name) +Queue::Add (const std::string &name) { GetDefault ()->AddPossibleValue (name); - GetList ()->push_back (std::make_pair (&queue, name)); } void -Queue::AddDefault (Queue &queue, const std::string &name) +Queue::AddDefault (const std::string &name) { GetDefault ()->AddDefaultValue (name); - GetList ()->push_back (std::make_pair (&queue, name)); } StringEnumDefaultValue * Queue::GetDefault (void) @@ -248,12 +220,6 @@ Queue::GetDefault (void) static StringEnumDefaultValue value ("Queue", "Packet Queue"); return &value; } -Queue::List * -Queue::GetList (void) -{ - static List list; - return &list; -} }; // namespace ns3 diff --git a/src/node/queue.h b/src/node/queue.h index 7d96a6c5e..cafd3808c 100644 --- a/src/node/queue.h +++ b/src/node/queue.h @@ -49,8 +49,6 @@ public: Queue (); virtual ~Queue (); - virtual Queue* Copy() const = 0; - TraceResolver *CreateTraceResolver (TraceContext const &context); bool IsEmpty (void); @@ -115,22 +113,13 @@ private: uint32_t m_nTotalDroppedPackets; public: - static Queue *CreateDefault (void); - static void Add (Queue &queue, const std::string &name); - static void AddDefault (Queue &queue, const std::string &name); + static Ptr CreateDefault (void); + static void Add (const std::string &name); + static void AddDefault (const std::string &name); private: typedef std::list > List; static StringEnumDefaultValue *GetDefault (void); static List *GetList (void); - -public: - // Static methods to manage queue default - // Set desired queue default - static void Default(const Queue& q); - // Return reference to the current default queue type - static Queue& Default(); - // Static variable pointing to current default queue - static Queue* defaultQueue; }; }; // namespace ns3 From 26c628e81a826662038fa1c726f8a5b302486632 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 09:46:38 +0200 Subject: [PATCH 46/59] remove ApplicationList. Move functionality to Node class --- SConstruct | 8 +-- examples/simple-p2p.cc | 19 ++---- src/applications/application-list.cc | 72 ----------------------- src/applications/application-list.h | 54 ----------------- src/applications/onoff-application.h | 2 +- src/internet-node/internet-node.cc | 3 - src/{applications => node}/application.cc | 1 + src/{applications => node}/application.h | 0 src/node/node.cc | 28 +++++++++ src/node/node.h | 6 ++ 10 files changed, 45 insertions(+), 148 deletions(-) delete mode 100644 src/applications/application-list.cc delete mode 100644 src/applications/application-list.h rename src/{applications => node}/application.cc (99%) rename src/{applications => node}/application.h (100%) diff --git a/SConstruct b/SConstruct index 607dcb1ce..1f0d3fef0 100644 --- a/SConstruct +++ b/SConstruct @@ -209,6 +209,7 @@ node.add_sources ([ 'socket.cc', 'i-udp.cc', 'i-ipv4.cc', + 'application.cc', ]) node.add_inst_headers ([ 'node.h', @@ -224,25 +225,22 @@ node.add_inst_headers ([ 'socket.h', 'i-udp.h', 'i-ipv4.h', + 'application.h', ]) applications = build.Ns3Module ('applications', 'src/applications') ns3.add (applications) applications.add_deps (['node']) applications.add_sources ([ - 'application-list.cc', - 'application.cc', 'onoff-application.cc', ]) applications.add_inst_headers ([ - 'application-list.h', - 'application.h', 'onoff-application.h', ]) inode = build.Ns3Module ('internet-node', 'src/internet-node') ns3.add (inode) -inode.add_deps (['node', 'applications']) +inode.add_deps (['node']) inode.add_sources ([ 'internet-node.cc', 'l3-demux.cc', diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index ca2bd1e78..b767febbb 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -134,7 +134,7 @@ int main (int argc, char *argv[]) // Create the OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s - Ptr ooff0 = MakeNewObject ( + Ptr ooff = MakeNewObject ( n0, Ipv4Address("10.1.3.2"), 80, @@ -142,16 +142,12 @@ int main (int argc, char *argv[]) ConstantVariable(0), DataRate(448000), 210); - // Add to Node's ApplicationList (takes ownership of pointer) - Ptr apl0 = n0->QueryInterface (ApplicationList::iid); - apl0->Add(ooff0); - // Start the application - ooff0->Start(Seconds(1.0)); - ooff0->Stop (Seconds(10.0)); + ooff->Start(Seconds(1.0)); + ooff->Stop (Seconds(10.0)); // Create a similar flow from n3 to n1, starting at time 1.1 seconds - Ptr ooff1 = MakeNewObject ( + ooff = MakeNewObject ( n3, Ipv4Address("10.1.2.1"), 80, @@ -159,12 +155,9 @@ int main (int argc, char *argv[]) ConstantVariable(0), DataRate(448000), 210); - // Add to Node's ApplicationList (takes ownership of pointer) - Ptr apl3 = n3->QueryInterface (ApplicationList::iid); - apl3->Add(ooff1); // Start the application - ooff1->Start(Seconds(1.1)); - ooff1->Stop (Seconds(10.0)); + ooff->Start(Seconds(1.1)); + ooff->Stop (Seconds(10.0)); // Here, finish off packet routing configuration // This will likely set by some global StaticRouting object in the future diff --git a/src/applications/application-list.cc b/src/applications/application-list.cc deleted file mode 100644 index 576f1fc4a..000000000 --- a/src/applications/application-list.cc +++ /dev/null @@ -1,72 +0,0 @@ -// -*- Mode:NS3 -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// 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 -// -// Author: George F. Riley -// -// Implement the application list capability for NS3 nodes -// George F. Riley, Georgia Tech, Spring 2007 - -#include "application.h" -#include "application-list.h" - -namespace ns3{ - -const InterfaceId ApplicationList::iid ("ApplicationList"); - -ApplicationList::ApplicationList(Ptr n) - : Interface (ApplicationList::iid) -{} - -void -ApplicationList::DoDispose (void) -{ - for (std::vector >::iterator i = m_apps.begin(); - i != m_apps.end(); ++i) - { - Ptr app = *i; - app->Dispose (); - *i = 0; - } - m_apps.clear (); - Interface::DoDispose (); -} - -ApplicationList::~ApplicationList() -{} - -void -ApplicationList::Add(Ptr a) -{ - m_apps.push_back(a); -} - -uint32_t ApplicationList::Count() const -{ - return m_apps.size(); -} - -Ptr ApplicationList::Get(uint32_t i) const -{ - if (m_apps.empty()) - { - return 0; - } - return m_apps[i]; -} - -}//namespace ns3 diff --git a/src/applications/application-list.h b/src/applications/application-list.h deleted file mode 100644 index 2f4d0226a..000000000 --- a/src/applications/application-list.h +++ /dev/null @@ -1,54 +0,0 @@ -// -*- Mode:NS3 -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// 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 -// -// Author: George F. Riley -// -// Manages the list of applications associated with a node. -// George F. Riley, Georgia Tech, Spring 2007 - -#ifndef __APPLICATION_LIST_H__ -#define __APPLICATION_LIST_H__ - -#include "application.h" -#include "ns3/interface.h" -#include "ns3/ptr.h" -#include - -namespace ns3 { - -class ApplicationList : public Interface -{ -public: - static const InterfaceId iid; - ApplicationList(Ptr); - // Copy constructor not needed, default one is correct - virtual ~ApplicationList(); - virtual void Add(Ptr application); - - uint32_t Count() const; // Number of applications - Ptr Get(uint32_t i) const; // Get app by index - -protected: - virtual void DoDispose (void); -private: - std::vector > m_apps; -}; - -}//namespace ns3 -#endif - diff --git a/src/applications/onoff-application.h b/src/applications/onoff-application.h index 0902a2885..66fff3916 100644 --- a/src/applications/onoff-application.h +++ b/src/applications/onoff-application.h @@ -27,7 +27,7 @@ #ifndef __onoff_application_h__ #define __onoff_application_h__ -#include "application.h" +#include "ns3/application.h" #include "ns3/event-id.h" #include "ns3/ptr.h" diff --git a/src/internet-node/internet-node.cc b/src/internet-node/internet-node.cc index 0e54800d9..15b95c675 100644 --- a/src/internet-node/internet-node.cc +++ b/src/internet-node/internet-node.cc @@ -22,7 +22,6 @@ // George F. Riley, Georgia Tech, Fall 2006 #include "ns3/composite-trace-resolver.h" -#include "ns3/application-list.h" #include "ns3/net-device.h" #include "l3-demux.h" @@ -45,7 +44,6 @@ InternetNode::InternetNode() Ptr arp = MakeNewObject (this); Ptr udp = MakeNewObject (this); - Ptr applicationList = MakeNewObject (this); Ptr l3Demux = MakeNewObject (this); Ptr ipv4L4Demux = MakeNewObject (this); @@ -62,7 +60,6 @@ InternetNode::InternetNode() Interface::AddInterface (ipv4Impl); Interface::AddInterface (arpPrivate); Interface::AddInterface (udpImpl); - Interface::AddInterface (applicationList); Interface::AddInterface (l3Demux); Interface::AddInterface (ipv4L4Demux); } diff --git a/src/applications/application.cc b/src/node/application.cc similarity index 99% rename from src/applications/application.cc rename to src/node/application.cc index 2d4badcd6..ed4fc7ecd 100644 --- a/src/applications/application.cc +++ b/src/node/application.cc @@ -39,6 +39,7 @@ Application::Application(Ptr n) m_startVar(0), m_stopVar(0), m_start(false), m_stop(false) { + m_node->AddApplication (this); } Application::Application(const Application& o) diff --git a/src/applications/application.h b/src/node/application.h similarity index 100% rename from src/applications/application.h rename to src/node/application.h diff --git a/src/node/node.cc b/src/node/node.cc index 7d57305ab..81ba3e678 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -25,6 +25,7 @@ #include "node.h" #include "node-list.h" #include "net-device.h" +#include "application.h" #include "ns3/simulator.h" namespace ns3{ @@ -88,6 +89,25 @@ Node::GetNDevices (void) const return m_devices.size (); } +uint32_t +Node::AddApplication (Ptr application) +{ + uint32_t index = m_applications.size (); + m_applications.push_back (application); + return index; +} +Ptr +Node::GetApplication (uint32_t index) const +{ + return m_applications[index]; +} +uint32_t +Node::GetNApplications (void) const +{ + return m_applications.size (); +} + + void Node::DoDispose() { for (std::vector >::iterator i = m_devices.begin (); @@ -98,6 +118,14 @@ void Node::DoDispose() *i = 0; } m_devices.clear (); + for (std::vector >::iterator i = m_applications.begin (); + i != m_applications.end (); i++) + { + Ptr application = *i; + application->Dispose (); + *i = 0; + } + m_applications.clear (); Interface::DoDispose (); } diff --git a/src/node/node.h b/src/node/node.h index 42fa0b4fe..f0c7d142e 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -34,6 +34,7 @@ namespace ns3 { class TraceContext; class TraceResolver; class NetDevice; +class Application; class Node : public Interface { @@ -54,6 +55,10 @@ public: Ptr GetDevice (uint32_t index) const; uint32_t GetNDevices (void) const; + uint32_t AddApplication (Ptr application); + Ptr GetApplication (uint32_t index) const; + uint32_t GetNApplications (void) const; + protected: virtual void DoDispose (void); private: @@ -62,6 +67,7 @@ private: uint32_t m_id; // Node id for this node uint32_t m_sid; // System id for this node std::vector > m_devices; + std::vector > m_applications; }; } //namespace ns3 From 87112f46f71228805f04ca56a250d5756a414cfe Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 09:58:53 +0200 Subject: [PATCH 47/59] call Node::AddDevice from NetDevice::NetDevice --- SConstruct | 2 +- src/devices/p2p/p2p-topology.cc | 2 -- src/node/net-device.cc | 4 +++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SConstruct b/SConstruct index 1f0d3fef0..e191b5b4e 100644 --- a/SConstruct +++ b/SConstruct @@ -416,7 +416,7 @@ sample_default_value.add_source('main-default-value.cc') example_simple_p2p = build.Ns3Module('simple-p2p', 'examples') example_simple_p2p.set_executable() ns3.add(example_simple_p2p) -example_simple_p2p.add_deps(['core', 'simulator', 'node', 'p2p', 'internet-node']) +example_simple_p2p.add_deps(['core', 'simulator', 'node', 'p2p', 'internet-node', 'applications']) example_simple_p2p.add_source('simple-p2p.cc') ns3.generate_dependencies() diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index 2143b946d..720d5d513 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -49,14 +49,12 @@ PointToPointTopology::AddPointToPointLink( Ptr q = Queue::CreateDefault (); net1->AddQueue(q); - n1->AddDevice (net1); net1->Attach (channel); Ptr net2 = MakeNewObject (n2); q = Queue::CreateDefault (); net2->AddQueue(q); - n2->AddDevice (net2); net2->Attach (channel); return channel; diff --git a/src/node/net-device.cc b/src/node/net-device.cc index 86b25d2de..7f5033ba4 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -43,7 +43,9 @@ NetDevice::NetDevice(Ptr node, const MacAddress& addr) : m_isBroadcast (false), m_isMulticast (false), m_isPointToPoint (false) -{} +{ + m_node->AddDevice (this); +} NetDevice::~NetDevice () {} From b1574fba1aa4fea6f0ef5c555f04a5bda749d43a Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 10:02:10 +0200 Subject: [PATCH 48/59] remove Application::Copy --- src/applications/onoff-application.cc | 5 ---- src/applications/onoff-application.h | 1 - src/node/application.cc | 35 +-------------------------- src/node/application.h | 4 --- 4 files changed, 1 insertion(+), 44 deletions(-) diff --git a/src/applications/onoff-application.cc b/src/applications/onoff-application.cc index 347399791..cd7cd492f 100644 --- a/src/applications/onoff-application.cc +++ b/src/applications/onoff-application.cc @@ -194,11 +194,6 @@ void OnOffApplication::StopApplication() // Called at time specified by Stop } } -OnOffApplication* OnOffApplication::Copy() const -{ - return new OnOffApplication(*this); -} - // Event handlers void OnOffApplication::StartSending() { diff --git a/src/applications/onoff-application.h b/src/applications/onoff-application.h index 66fff3916..661fa225e 100644 --- a/src/applications/onoff-application.h +++ b/src/applications/onoff-application.h @@ -53,7 +53,6 @@ public: virtual ~OnOffApplication(); // Destructor virtual void StartApplication(); // Called at time specified by Start virtual void StopApplication(); // Called at time specified by Stop - virtual OnOffApplication* Copy() const;// Make a copy of the application // Event handlers void StartSending(); diff --git a/src/node/application.cc b/src/node/application.cc index ed4fc7ecd..399c4322c 100644 --- a/src/node/application.cc +++ b/src/node/application.cc @@ -41,19 +41,6 @@ Application::Application(Ptr n) { m_node->AddApplication (this); } - -Application::Application(const Application& o) - : m_node(0), m_startVar(0), m_stopVar(0), - m_start(false), m_stop(false) -{ // Copy constructor - m_node = o.m_node; - // Copy the start and stop random variables if they exist - if (o.m_startVar) m_startVar = o.m_startVar->Copy(); - if (o.m_stopVar) m_stopVar = o.m_stopVar->Copy(); - if (o.m_start) ScheduleStart(); - if (o.m_stop) ScheduleStop(); -} - // \brief Application Destructor Application::~Application() @@ -77,27 +64,7 @@ Application::DoDispose (void) m_startVar = 0; delete m_stopVar; m_stopVar = 0; -} - -Application& Application::operator=(const Application& rhs) -{ - if (this == &rhs) return *this; // Self assignment - m_node = rhs.m_node; - - delete m_startVar; - m_startVar = 0; - if (rhs.m_startVar) m_startVar = rhs.m_startVar->Copy(); - - delete m_stopVar; - m_stopVar = 0; - if (rhs.m_stopVar) m_stopVar = rhs.m_stopVar->Copy(); - - m_start = false; - if (rhs.m_start) ScheduleStart(); - if (rhs.m_stop) ScheduleStop(); - return *this; -} - +} // \brief Specify application start time // The virtual method STartApp will be called at the time diff --git a/src/node/application.h b/src/node/application.h index 83c16a31f..204591696 100644 --- a/src/node/application.h +++ b/src/node/application.h @@ -62,12 +62,8 @@ class Application : public Object { public: Application(Ptr); - Application(const Application&); // Copy constructor - Application& operator=(const Application&); // Assignment operator virtual ~Application(); - virtual Application* Copy() const = 0; // All applications must provide - // \brief Specify application start time // Applications start at various times in the simulation scenario. // The Start method specifies when the application should be From 05b444ae8a46392ab6cacec54b35e381ea1deb61 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 10:24:35 +0200 Subject: [PATCH 49/59] fix the doxygen comments and simplify the implementation --- src/node/application.cc | 66 +++++++--------------- src/node/application.h | 119 ++++++++++++++++++++++------------------ 2 files changed, 86 insertions(+), 99 deletions(-) diff --git a/src/node/application.cc b/src/node/application.cc index 399c4322c..3346da3c2 100644 --- a/src/node/application.cc +++ b/src/node/application.cc @@ -35,9 +35,7 @@ namespace ns3 { // \brief Application Constructor Application::Application(Ptr n) - : m_node (n), - m_startVar(0), m_stopVar(0), - m_start(false), m_stop(false) + : m_node (n) { m_node->AddApplication (this); } @@ -50,57 +48,33 @@ void Application::DoDispose (void) { m_node = 0; - if (m_start) - { - Simulator::Cancel(m_startEvent); - m_start = false; - } - if (m_stop) - { - Simulator::Cancel(m_stopEvent); - m_stop = false; - } - delete m_startVar; - m_startVar = 0; - delete m_stopVar; - m_stopVar = 0; + Simulator::Cancel(m_startEvent); + Simulator::Cancel(m_stopEvent); } -// \brief Specify application start time -// The virtual method STartApp will be called at the time -// specified by startTime. -// \param Time to start application (absolute time, from start of simulation) void Application::Start(const Time& startTime) { - delete m_startVar; - m_startVar = new ConstantVariable(startTime.GetSeconds()); - ScheduleStart(); + ScheduleStart (startTime); } void Application::Start(const RandomVariable& startVar) -{ // Start at random time - delete m_startVar; - m_startVar = startVar.Copy(); - ScheduleStart(); +{ + RandomVariable *v = startVar.Copy (); + ScheduleStart (Seconds (v->GetValue ())); + delete v; } -// \brief Specify application stop time -// The virtual method StopApp will be called at the time -// specified by stopTime. -// \param Time to stop application (absolute time, from start of simulation) void Application::Stop(const Time& stopTime) { - delete m_stopVar; - m_stopVar = new ConstantVariable(stopTime.GetSeconds()); - ScheduleStop(); + ScheduleStop (stopTime); } void Application::Stop(const RandomVariable& stopVar) -{ // Stop at random time - delete m_stopVar; - m_stopVar = stopVar.Copy(); - ScheduleStop(); +{ + RandomVariable *v = stopVar.Copy (); + ScheduleStop (Seconds (v->GetValue ())); + delete v; } Ptr Application::GetNode() const @@ -120,20 +94,18 @@ void Application::StopApplication() // Private helpers -void Application::ScheduleStart() +void Application::ScheduleStart (const Time &startTime) { - m_startEvent = Simulator::Schedule(Seconds(m_startVar->GetValue()) - + m_startEvent = Simulator::Schedule(startTime - Simulator::Now(), &Application::StartApplication, this); - m_start = true; } -void Application::ScheduleStop() +void Application::ScheduleStop (const Time &stopTime) { - m_stopEvent = Simulator::Schedule(Seconds(m_stopVar->GetValue()) - - Simulator::Now(), - &Application::StopApplication, this); - m_stop = true; + m_stopEvent = Simulator::Schedule(stopTime - + Simulator::Now(), + &Application::StopApplication, this); } } //namespace ns3 diff --git a/src/node/application.h b/src/node/application.h index 204591696..bc6a097ec 100644 --- a/src/node/application.h +++ b/src/node/application.h @@ -57,77 +57,92 @@ namespace ns3 { class Node; class RandomVariable; - + +/** + * \brief a model for userspace applications. + */ class Application : public Object { public: Application(Ptr); virtual ~Application(); - // \brief Specify application start time - // Applications start at various times in the simulation scenario. - // The Start method specifies when the application should be - // started. The application subclasses should override the - // private "StartApplication" method defined below, which is called at the - // time specified, to cause the application to begin. - // \param Start time for this application, relative to the - // current simulation time. - void Start(const Time&); + /** + * \brief Specify application start time + * Applications start at various times in the simulation scenario. + * The Start method specifies when the application should be + * started. The application subclasses should override the + * private "StartApplication" method defined below, which is called at the + * time specified, to cause the application to begin. + * \param startTime Start time for this application, absolute time, + * relative to the start of the simulation. + */ + void Start(const Time& startTime); - // \brief Same as above, but uses a random variable for start time - // The random variable returns the desired start time in units of - // Seconds. + /** + * \brief Same as above, but uses a random variable for start time + * The random variable returns the desired start time in units of + * Seconds. + * \param startVariable the random variable to use to pick + * the real start time as an absolute time, relative to + * the start of the simulation. + */ + void Start(const RandomVariable& startVariable); -void Start(const RandomVariable&); - - // \brief Specify application stop time - // Once an application has started, it is sometimes useful - // to stop the application. The Stop method specifies when an - // application is to stop. The application subclasses should override - // the private StopApplication method defined below, to cause the application - // to stop. - // \param Stop time for this application, relative to the - // current simulation time. - void Stop(const Time&); + /** + * \brief Specify application stop time + * Once an application has started, it is sometimes useful + * to stop the application. The Stop method specifies when an + * application is to stop. The application subclasses should override + * the private StopApplication method defined below, to cause the application + * to stop. + * \param stopTime Stop time for this application, relative to the + * start of the simulation. + */ + void Stop(const Time& stopTime); - // \brief Same as above, but uses a random variable for stop time - // The random variable returns the desired stop time in units of - // Seconds. - void Stop(const RandomVariable&); - - // \brief Attaches an application to a specific node - // Specifies which node object this application is associated with. - // \param Node object to associate with this application. - // \brief Returns the pointer to the attached node. + /** + * \brief Same as above, but uses a random variable for stop time + * The random variable returns the desired stop time in units of + * Seconds. + * \param stopVariable the random variable to use to pick + * the real stop time, relative to the start of the simulation. + */ + void Stop(const RandomVariable& stopVariable); + + /** + * \returns the Node to which this Application object is attached. + */ Ptr GetNode() const; +private: // Members Ptr m_node; // All applications have an associated node - RandomVariable* m_startVar; // Random variable for start time - RandomVariable* m_stopVar; // Random variable for stop time EventId m_startEvent;// Event identifier for start event EventId m_stopEvent; // Event identifier for the stop event - bool m_start; // True if start event scheduled - bool m_stop; // True if stop event scheduled - + +private: + /** + * \brief Application specific startup code + * The StartApplication method is called at the start time specifed by Start + * This method should be overridden by all or most application + * subclasses. + */ + virtual void StartApplication (void); + + /** + * \brief Application specific shutdown code + * The StopApplication method is called at the stop time specifed by Stop + * This method should be overridden by all or most application + * subclasses. + */ + virtual void StopApplication (void); protected: - // \brief Application specific startup code - // The StartApplication method is called at the start time specifed by Start - // This method should be overridden by all or most application - // subclasses. - virtual void StartApplication(); - - // \brief Application specific shutdown code - // The StopApplication method is called at the stop time specifed by Stop - // This method should be overridden by all or most application - // subclasses. - virtual void StopApplication(); - virtual void DoDispose (void); private: // Helpers - void ScheduleStart(); - void ScheduleStop(); + void ScheduleStart (const Time &time); + void ScheduleStop (const Time &time); }; } //namespace ns3 From 293fb9005783d8433b20dbd4c8498fe31623c29c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 10:42:42 +0200 Subject: [PATCH 50/59] improve doxygen output --- src/node/application.h | 46 ++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/node/application.h b/src/node/application.h index bc6a097ec..952679bbc 100644 --- a/src/node/application.h +++ b/src/node/application.h @@ -69,44 +69,47 @@ public: /** * \brief Specify application start time + * \param startTime Start time for this application, absolute time, + * relative to the start of the simulation. + * * Applications start at various times in the simulation scenario. * The Start method specifies when the application should be * started. The application subclasses should override the * private "StartApplication" method defined below, which is called at the * time specified, to cause the application to begin. - * \param startTime Start time for this application, absolute time, - * relative to the start of the simulation. */ void Start(const Time& startTime); /** - * \brief Same as above, but uses a random variable for start time - * The random variable returns the desired start time in units of - * Seconds. + * \brief Specify application start time. * \param startVariable the random variable to use to pick - * the real start time as an absolute time, relative to - * the start of the simulation. + * the real start time as an absolute time, in units of + * seconds, relative to the start of the simulation. + * \overload Start (const Time &) + * */ void Start(const RandomVariable& startVariable); /** * \brief Specify application stop time + * \param stopTime Stop time for this application, relative to the + * start of the simulation. + * * Once an application has started, it is sometimes useful * to stop the application. The Stop method specifies when an * application is to stop. The application subclasses should override - * the private StopApplication method defined below, to cause the application - * to stop. - * \param stopTime Stop time for this application, relative to the - * start of the simulation. + * the private StopApplication method, to be notified when that + * time has come. */ void Stop(const Time& stopTime); /** - * \brief Same as above, but uses a random variable for stop time - * The random variable returns the desired stop time in units of - * Seconds. + * \brief Specify application stop time * \param stopVariable the random variable to use to pick - * the real stop time, relative to the start of the simulation. + * the real stop time, in units of seconds, + * relative to the start of the simulation. + * \overload Stop (const Time &) + * */ void Stop(const RandomVariable& stopVariable); @@ -115,15 +118,10 @@ public: */ Ptr GetNode() const; -private: - // Members - Ptr m_node; // All applications have an associated node - EventId m_startEvent;// Event identifier for start event - EventId m_stopEvent; // Event identifier for the stop event - private: /** * \brief Application specific startup code + * * The StartApplication method is called at the start time specifed by Start * This method should be overridden by all or most application * subclasses. @@ -132,6 +130,7 @@ private: /** * \brief Application specific shutdown code + * * The StopApplication method is called at the stop time specifed by Stop * This method should be overridden by all or most application * subclasses. @@ -140,9 +139,12 @@ private: protected: virtual void DoDispose (void); private: - // Helpers void ScheduleStart (const Time &time); void ScheduleStop (const Time &time); + + EventId m_startEvent; + EventId m_stopEvent; + Ptr m_node; }; } //namespace ns3 From d83bde7b0f31fc8856e50a8338f3ac8101fbf4f3 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 10:46:25 +0200 Subject: [PATCH 51/59] improve doxygen output --- src/node/application.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/node/application.h b/src/node/application.h index 952679bbc..5cc1809fc 100644 --- a/src/node/application.h +++ b/src/node/application.h @@ -85,8 +85,6 @@ public: * \param startVariable the random variable to use to pick * the real start time as an absolute time, in units of * seconds, relative to the start of the simulation. - * \overload Start (const Time &) - * */ void Start(const RandomVariable& startVariable); @@ -108,8 +106,6 @@ public: * \param stopVariable the random variable to use to pick * the real stop time, in units of seconds, * relative to the start of the simulation. - * \overload Stop (const Time &) - * */ void Stop(const RandomVariable& stopVariable); From a8bc213609682457592688013bae99bfca4e498c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 10:46:44 +0200 Subject: [PATCH 52/59] remove doxygen warnings --- src/core/component-manager.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/core/component-manager.h b/src/core/component-manager.h index 13d42fa57..f69648d16 100644 --- a/src/core/component-manager.h +++ b/src/core/component-manager.h @@ -89,7 +89,6 @@ public: * \param classId class id of the constructor to invoke. * \param a1 argument to pass to the constructor. * \return a pointer to the instance created. - * \overload Create (ClassId) * * Create an instance of the object identified by its * ClassId. @@ -102,7 +101,6 @@ public: * \param a1 first argument to pass to the constructor. * \param a2 second argument to pass to the constructor. * \return a pointer to the instance created. - * \overload Create (ClassId) * * Create an instance of the object identified by its * ClassId. @@ -114,7 +112,6 @@ public: * \param classId class id of the constructor to invoke. * \param iid interface id to query for * \return a pointer to the instance created. - * \overload Create (ClassId) * * Create an instance of the object identified by its * ClassId, call QueryInterface on it, and return the @@ -146,7 +143,6 @@ public: * \param name the symbolic name to associate to this * constructor * \returns a ClassId which uniquely identifies this constructor. - * \overload ClassId RegisterConstructor (std::string) */ template static ClassId RegisterConstructor (std::string name) @@ -159,7 +155,6 @@ public: * \param name the symbolic name to associate to this * constructor * \returns a ClassId which uniquely identifies this constructor. - * \overload ClassId RegisterConstructor (std::string) */ template static ClassId RegisterConstructor (std::string name) From f1612bbc2cc137a847e4f90fa805e95253972685 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 10:57:43 +0200 Subject: [PATCH 53/59] fix dox warnings --- src/core/interface.h | 2 +- src/core/random-variable.h | 1 + src/node/net-device.h | 2 +- src/node/socket.h | 8 ++++---- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/interface.h b/src/core/interface.h index be5ace7a9..307152a9d 100644 --- a/src/core/interface.h +++ b/src/core/interface.h @@ -80,7 +80,7 @@ protected: Interface (InterfaceId iid); /** * \param iid the Interface id of the interface - * \param a pointer to the interface object + * \param interface a pointer to the interface object * * If you are not a direct subclass of the ns3::Interface base class, * and if you want to register yourself as another accessible interface diff --git a/src/core/random-variable.h b/src/core/random-variable.h index b5076ca5f..9901b665a 100644 --- a/src/core/random-variable.h +++ b/src/core/random-variable.h @@ -200,6 +200,7 @@ protected: * UniformVariable x(0,10); * x.GetValue(); //will always return numbers [0,10] * UniformVariable::GetSingleValue(100,1000); //returns a value [100,1000] + * \endcode */ class UniformVariable : public RandomVariable { public: diff --git a/src/node/net-device.h b/src/node/net-device.h index 92289d5e0..b5e45860b 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -111,7 +111,7 @@ public: /** * \param index ifIndex of the device */ - void SetIfIndex(const uint32_t); + void SetIfIndex(const uint32_t index); /** * \return index ifIndex of the device */ diff --git a/src/node/socket.h b/src/node/socket.h index 82769b405..aacafc8f1 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -206,24 +206,24 @@ public: /** * \brief Receive data - * \param Received data callback. Invoked whenever new data is received. + * \param receivedData Invoked whenever new data is received. * * If you wish to transport only dummy packets, this method is not a very * efficient way to receive these dummy packets: it will trigger a memory * allocation to hold the dummy memory into a buffer which can be passed * to the user. Instead, consider using the RecvDummy method. */ - void Recv(Callback, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> = + void Recv(Callback, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> receivedData = MakeCallback (&Socket::DummyCallbackVoidSocketBufferUi32Ipv4AddressUi16)); /** * \brief Receive data - * \param Received data callback. Invoked whenever new data is received. + * \param receivedData Invoked whenever new data is received. * * This method is included because it is vastly more efficient than the * Recv method when you use dummy payload. */ - void RecvDummy(Callback, uint32_t,const Ipv4Address&, uint16_t> = + void RecvDummy(Callback, uint32_t,const Ipv4Address&, uint16_t> receivedData = MakeCallback (&Socket::DummyCallbackVoidSocketUi32Ipv4AddressUi16)); private: From 88c5dfecb0d97e2342a8c6bfedf1eeacddb53838 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 11:30:15 +0200 Subject: [PATCH 54/59] make the Node API more consistent --- src/internet-node/internet-node.cc | 2 +- src/internet-node/internet-node.h | 2 +- src/node/node.cc | 6 ++++++ src/node/node.h | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/internet-node/internet-node.cc b/src/internet-node/internet-node.cc index 15b95c675..bcda19190 100644 --- a/src/internet-node/internet-node.cc +++ b/src/internet-node/internet-node.cc @@ -74,7 +74,7 @@ InternetNode::SetName (std::string name) } TraceResolver * -InternetNode::CreateTraceResolver (TraceContext const &context) +InternetNode::DoCreateTraceResolver (TraceContext const &context) { CompositeTraceResolver *resolver = new CompositeTraceResolver (context); Ptr ipv4 = QueryInterface (IIpv4Private::iid); diff --git a/src/internet-node/internet-node.h b/src/internet-node/internet-node.h index 04da92036..63d04ed6d 100644 --- a/src/internet-node/internet-node.h +++ b/src/internet-node/internet-node.h @@ -41,13 +41,13 @@ public: }; InternetNode(); virtual ~InternetNode (); - virtual TraceResolver *CreateTraceResolver (TraceContext const &context); void SetName(std::string name); protected: virtual void DoDispose(void); private: virtual void DoAddDevice (Ptr device) const; + virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); bool ReceiveFromDevice (Ptr device, const Packet &p, uint16_t protocolNumber) const; std::string m_name; }; diff --git a/src/node/node.cc b/src/node/node.cc index 81ba3e678..a4f5cf693 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -51,6 +51,12 @@ Node::Node(uint32_t sid) Node::~Node () {} +TraceResolver * +Node::CreateTraceResolver (TraceContext const &context) +{ + return DoCreateTraceResolver (context); +} + uint32_t Node::GetId (void) const { diff --git a/src/node/node.h b/src/node/node.h index f0c7d142e..d2e63cad6 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -45,7 +45,7 @@ public: Node(uint32_t); // Specify which system for a distributed simulation virtual ~Node(); - virtual TraceResolver *CreateTraceResolver (TraceContext const &context) = 0; + TraceResolver *CreateTraceResolver (TraceContext const &context); uint32_t GetId (void) const; uint32_t GetSystemId (void) const; @@ -62,6 +62,7 @@ public: protected: virtual void DoDispose (void); private: + virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0; virtual void DoAddDevice (Ptr device) const = 0; uint32_t m_id; // Node id for this node From 52d60ea049aabf52e33c38f6eaf2a798d820ab93 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 11:46:11 +0200 Subject: [PATCH 55/59] add dox documentation for Node --- src/node/node.cc | 6 --- src/node/node.h | 105 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 101 insertions(+), 10 deletions(-) diff --git a/src/node/node.cc b/src/node/node.cc index a4f5cf693..ca8871080 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -69,12 +69,6 @@ Node::GetSystemId (void) const return m_sid; } -void -Node::SetSystemId(uint32_t s ) -{ - m_sid = s; -} - uint32_t Node::AddDevice (Ptr device) { diff --git a/src/node/node.h b/src/node/node.h index d2e63cad6..d8d5ffecc 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -36,33 +36,130 @@ class TraceResolver; class NetDevice; class Application; +/** + * \brief A network Node. + * + * This class holds together: + * - a list of NetDevice objects which represent the network interfaces + * of this node which are connected to other Node instances through + * Channel instances. + * - a list of Application objects which represent the userspace + * traffic generation applications which interact with the Node + * through the Socket API. + * - a node Id: a unique per-node identifier. + * - a system Id: a unique Id used for parallel simulations. + * - a trace resolver which can be used to connect user trace sinks + * to the node's trace sources. + * + * Every Node created is added to the NodeList automatically. + */ class Node : public Interface { public: static const InterfaceId iid; - Node(); - Node(uint32_t); // Specify which system for a distributed simulation virtual ~Node(); + /** + * \param context the trace context for the TraceResolver to create + * \returns a newly-created TraceResolver. The caller takes + * ownership of the returned pointer. + * + * Request the Node to create a trace resolver. This method + * could be used directly by a user who needs access to very low-level + * trace configuration. + */ TraceResolver *CreateTraceResolver (TraceContext const &context); + /** + * \returns the unique id of this node. + * + * This unique id happens to be also the index of the Node into + * the NodeList. + */ uint32_t GetId (void) const; - uint32_t GetSystemId (void) const; - void SetSystemId(uint32_t s); + /** + * \returns the system id for parallel simulations associated + * to this node. + */ + uint32_t GetSystemId (void) const; + + /** + * \param device NetDevice to associate to this node. + * \returns the index of the NetDevice into the Node's list of + * NetDevice. + * + * Associate this device to this node. + * This method is called automatically from NetDevice::NetDevice + * so the user has little reason to call this method himself. + */ uint32_t AddDevice (Ptr device); + /** + * \param index the index of the requested NetDevice + * \returns the requested NetDevice associated to this Node. + */ Ptr GetDevice (uint32_t index) const; + /** + * \returns the number of NetDevice instances associated + * to this Node. + */ uint32_t GetNDevices (void) const; + /** + * \param application Application to associate to this node. + * \returns the index of the Application within the Node's list + * of Application. + * + * Associated this Application to this Node. This method is called + * automatically from Application::Application so the user + * has little reasons to call this method directly. + */ uint32_t AddApplication (Ptr application); + /** + * \param index + * \returns the application associated to this requested index + * within this Node. + */ Ptr GetApplication (uint32_t index) const; + /** + * \returns the number of applications associated to this Node. + */ uint32_t GetNApplications (void) const; protected: + /** + * Must be invoked by subclasses only. + */ + Node(); + /** + * \param systemId a unique integer used for parallel simulations. + * + * Must be invoked by subclasses only. + */ + Node(uint32_t systemId); + /** + * The dispose method. Subclasses must override this method + * and must chain up to it by calling Node::DoDispose at the + * end of their own DoDispose method. + */ virtual void DoDispose (void); private: + /** + * \param context the trace context + * \returns a trace resolver to the user. The user must delete it. + * + * Subclasses must implement this method. + */ virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0; + /** + * \param device the device added to this Node. + * + * This method is invoked whenever a user calls Node::AddDevice. + * Subclasses are expected to call NetDevice::SetReceiveCallback + * at this point to setup the node's receive function for + * the NetDevice packets. + */ virtual void DoAddDevice (Ptr device) const = 0; uint32_t m_id; // Node id for this node From 36b222360049995e2461eee6602a04aaccf91a02 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 11:51:01 +0200 Subject: [PATCH 56/59] add dox documentation --- src/node/node-list.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/node/node-list.h b/src/node/node-list.h index 2ef7bf9dd..607a47d71 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -32,17 +32,47 @@ class Node; class TraceResolver; class TraceContext; +/** + * \brief the list of simulation nodes. + * + * Every Node created is automatically added to this list. + */ class NodeList { public: typedef ArrayTraceResolver::Index NodeIndex; typedef std::vector< Ptr >::iterator Iterator; + /** + * \param node node to add + * \returns index of node in list. + * + * This method is called automatically from Node::Node so + * the user has little reason to call it himself. + */ static uint32_t Add (Ptr node); + /** + * \returns a C++ iterator located at the beginning of this + * list. + */ static Iterator Begin (void); + /** + * \returns a C++ iterator located at the end of this + * list. + */ static Iterator End (void); + /** + * \param context trace context to use for trace resolver + * to create. + * \returns the requested trace resolver. The caller + * takes ownership of the returned pointer. + */ static TraceResolver *CreateTraceResolver (TraceContext const &context); + /** + * \param n index of requested node. + * \returns the Node associated to index n. + */ static Ptr GetNode (uint32_t n); }; From a9ffc5d23b163b607b9fd9697a226d17954b96c8 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 11:57:27 +0200 Subject: [PATCH 57/59] complete dox doc --- src/node/net-device.h | 46 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src/node/net-device.h b/src/node/net-device.h index b5e45860b..e85709f79 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -59,11 +59,6 @@ class NetDevice : public Interface { public: static const InterfaceId iid; - /** - * \param node base class node pointer of device's node - * \param addr MAC address of this device. - */ - NetDevice(Ptr node, const MacAddress& addr); virtual ~NetDevice(); /** @@ -173,11 +168,26 @@ public: */ Ptr GetNode (void) const; + /** + * \returns true if ARP is needed, false otherwise. + * + * Called by higher-layers to check if this NetDevice requires + * ARP to be used. + */ bool NeedsArp (void) const; + /** + * \param cb callback to invoke whenever a packet has been received and must + * be forwarded to the higher layers. + */ void SetReceiveCallback (Callback,const Packet &,uint16_t> cb); protected: + /** + * \param node base class node pointer of device's node + * \param addr MAC address of this device. + */ + NetDevice(Ptr node, const MacAddress& addr); /** * Enable broadcast support. This method should be * called by subclasses from their constructor @@ -226,6 +236,12 @@ public: */ bool ForwardUp (Packet& p); + /** + * The dispose method for this NetDevice class. + * Subclasses are expected to override this method _and_ + * to chain up to it by calling NetDevice::DoDispose + * at the end of their own DoDispose method. + */ virtual void DoDispose (void); private: @@ -240,9 +256,29 @@ public: * subclasses to forward packets. Subclasses MUST override this method. */ virtual bool SendTo (Packet& p, const MacAddress& dest) = 0; + /** + * \returns true if this NetDevice needs the higher-layers + * to perform ARP over it, false otherwise. + * + * Subclasses must implement this method. + */ virtual bool DoNeedsArp (void) const = 0; + /** + * \param context the trace context to associated to the + * trace resolver. + * \returns a trace resolver associated to the input context. + * the caller takes ownership of the pointer returned. + * + * Subclasses must implement this method. + */ virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0; + /** + * \returns the channel associated to this NetDevice. + * + * Subclasses must implement this method. + */ virtual Ptr DoGetChannel (void) const = 0; + Ptr m_node; std::string m_name; uint16_t m_ifIndex; From ec20424afb8aabf2a52659e95db665af10b78a46 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 11:57:40 +0200 Subject: [PATCH 58/59] remove useless comment --- src/node/mac-address.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/node/mac-address.h b/src/node/mac-address.h index 84ecf6ae5..4a88da1d0 100644 --- a/src/node/mac-address.h +++ b/src/node/mac-address.h @@ -19,10 +19,6 @@ * Author: Mathieu Lacage */ -/* - * This implementation borrowed from yans - */ - #ifndef MAC_ADDRESS_H #define MAC_ADDRESS_H From 19696ec37ff233c0c246215d4575ae59e483c4c5 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 13 May 2007 12:00:56 +0200 Subject: [PATCH 59/59] add license header --- src/core/command-line.cc | 19 +++++++++++++++++++ src/core/command-line.h | 19 +++++++++++++++++++ src/core/default-value.cc | 18 ++++++++++++++++++ src/core/default-value.h | 18 ++++++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/src/core/command-line.cc b/src/core/command-line.cc index 88a14263b..481c925b4 100644 --- a/src/core/command-line.cc +++ b/src/core/command-line.cc @@ -1,4 +1,23 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 Georgia Tech University, INRIA + * + * 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 + * + * Authors: Raj Bhattacharjea , + * Mathieu Lacage + */ #include "command-line.h" #include diff --git a/src/core/command-line.h b/src/core/command-line.h index 046058dd4..a7ec9f5be 100644 --- a/src/core/command-line.h +++ b/src/core/command-line.h @@ -1,4 +1,23 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 Georgia Tech University, INRIA + * + * 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 + * + * Authors: Raj Bhattacharjea , + * Mathieu Lacage + */ #ifndef COMMAND_LINE_H #define COMMAND_LINE_H diff --git a/src/core/default-value.cc b/src/core/default-value.cc index 163497baf..fa0a2406d 100644 --- a/src/core/default-value.cc +++ b/src/core/default-value.cc @@ -1,4 +1,22 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * + * 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 + * + * Author: Mathieu Lacage + */ #include "default-value.h" #include "fatal-error.h" diff --git a/src/core/default-value.h b/src/core/default-value.h index f64e691fb..eea46dc39 100644 --- a/src/core/default-value.h +++ b/src/core/default-value.h @@ -1,4 +1,22 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * + * 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 + * + * Author: Mathieu Lacage + */ #ifndef DEFAULT_VALUE_H #define DEFAULT_VALUE_H