Node* -> Ptr<Node>

Raj Bhattacharjea 2007-05-09 13:26:21 -04:00
parent 4e32c8f56e
commit ecfcfa977d
15 changed files with 70 additions and 55 deletions

View File

@ -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<Node> n0 = new InternetNode ();
Ptr<Node> n1 = new InternetNode ();
Ptr<Node> n2 = new InternetNode ();
Ptr<Node> n3 = new InternetNode ();
// We create the channels first without any IP addressing information
PointToPointChannel *channel0 =

View File

@ -28,7 +28,7 @@ namespace ns3{
const Iid ApplicationList::iid ("ApplicationList");
ApplicationList::ApplicationList(Node* n)
ApplicationList::ApplicationList(Ptr<Node> n)
: NsUnknown (ApplicationList::iid)
{}
@ -49,7 +49,7 @@ ApplicationList::DoDispose (void)
ApplicationList::~ApplicationList()
{}
ApplicationList* ApplicationList::Copy(Node * n) const
ApplicationList* ApplicationList::Copy(Ptr<Node> 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<Node> n)
{
// Set the node pointer in each application
for (std::vector<Application *>::const_iterator i = m_apps.begin();

View File

@ -34,12 +34,12 @@ class ApplicationList : public NsUnknown
{
public:
static const Iid iid;
ApplicationList(Node*);
ApplicationList(Ptr<Node>);
// 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<Node>) const;
virtual void SetNode(Ptr<Node>); // Sets the node for all apps
virtual void Add(Application*); // Add an already new'ed app
// Manage the list
template <typename T> T* AddCopy(const T& t) // Add a new application

View File

@ -34,7 +34,7 @@ namespace ns3 {
// Application Methods
// \brief Application Constructor
Application::Application(Node * n)
Application::Application(Ptr<Node> 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<Node> n)
{
if (m_node != 0)
{
@ -157,7 +157,7 @@ void Application::SetNode(Node * n)
m_node->Ref ();
}
Node* Application::PeekNode() const
Ptr<Node> Application::PeekNode() const
{
return m_node;
}

View File

@ -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<Node>);
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<Node>);
// \brief Returns the pointer to the attached node.
Node* PeekNode() const;
Ptr<Node> PeekNode() const;
// Members
Node * m_node; // All applications have an associated node
Ptr<Node> 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

View File

@ -42,7 +42,7 @@ uint32_t OnOffApplication::g_defaultSize = 512;
// Constructors
OnOffApplication::OnOffApplication(Node * n,
OnOffApplication::OnOffApplication(Ptr<Node> 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<Node> n, const OnOffApplication& c)
: Application(n),
m_socket(0),
m_peerIP(c.m_peerIP),

View File

@ -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<Node> 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<Node> 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

View File

@ -254,8 +254,8 @@ PtrTest::RunTests (void)
m_nDestroyed = 0;
{
Ptr<NoCount> p = new NoCount (cb);
NoCount const&v1 = *p;
NoCount v2 = *p;
NoCount const&v1 = p.Peek();
NoCount v2 = p.Peek();
v1.Nothing ();
v2.Nothing ();
}

View File

@ -72,7 +72,8 @@ public:
Ptr (Ptr<U> const &o);
~Ptr () ;
Ptr<T> &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<T>::operator = (Ptr const& o)
template <typename T>
T const&
Ptr<T>::operator * () const
Ptr<T>::Peek () const
{
return *m_ptr;
}
template <typename T>
T *
Ptr<T>::Get () const
{
m_ptr->Ref();
return m_ptr;
}
template <typename T>
T *
Ptr<T>::operator -> ()
@ -219,7 +228,7 @@ Ptr<T>::Remove (void)
}
else
{
NS_ASSERT (m_ptr->IsSingle());
//NS_ASSERT (m_ptr->IsSingle());
T *retval = m_ptr;
m_ptr = 0;
return retval;

View File

@ -32,7 +32,7 @@ NS_DEBUG_COMPONENT_DEFINE ("PointToPointNetDevice");
namespace ns3 {
PointToPointNetDevice::PointToPointNetDevice (Node* node)
PointToPointNetDevice::PointToPointNetDevice (Ptr<Node> node)
:
NetDevice(node, MacAddress ("00:00:00:00:00:00")),
m_txMachineState (READY),

View File

@ -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> node);
/**
* Copy Construct a PointToPointNetDevice
*

View File

@ -40,8 +40,8 @@ namespace ns3 {
PointToPointChannel *
PointToPointTopology::AddPointToPointLink(
Node* n1,
Node* n2,
Ptr<Node> n1,
Ptr<Node> 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<Node> n1, const Ipv4Address& addr1,
Ptr<Node> 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<Node> n1, Ptr<Node> 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<Node> n1,
Ptr<Node> 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<Node> n1, Ptr<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)
Queue* PointToPointTopology::SetQueue(Ptr<Node> n1, Ptr<Node> 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<Node> n1, const IPAddr& ip1,
Ptr<Node> 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<Node> n1, Ptr<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)
Queue* Topology::GetQueue(Ptr<Node> n1, Ptr<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)
Queue* Topology::SetQueue(Ptr<Node> n1, Ptr<Node> n2, const Queue& q)
{
NetDevice* nd = GetNetDevice(n1, n2);
if (!nd) return 0; // No net device, can't set queue

View File

@ -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<Node>, Ptr<Node>, const DataRate&, const Time&);
static bool AddIpv4Addresses(
const PointToPointChannel*,
Node*, const Ipv4Address&,
Node*, const Ipv4Address&);
Ptr<Node>, const Ipv4Address&,
Ptr<Node>, const Ipv4Address&);
/**
* Get the connecting node n1 to node n2
*/
static PointToPointChannel* GetChannel(Node*, Node*);
static PointToPointChannel* GetChannel(Ptr<Node>, Ptr<Node>);
/**
* Get the NetDevice connecting node n1 to n2
*/
static PointToPointNetDevice* GetNetDevice(Node*, Node*);
static PointToPointNetDevice* GetNetDevice(Ptr<Node>, Ptr<Node>);
/**
* Get the queue associated with a link between two nodes
*/
static Queue* GetQueue(Node*, Node*);
static Queue* GetQueue(Ptr<Node>, Ptr<Node>);
/**
* Set the queue associated with a link between two nodes
*/
static Queue* SetQueue(Node*, Node*, const Queue&);
static Queue* SetQueue(Ptr<Node>, Ptr<Node>, const Queue&);
};
} // namespace ns3

View File

@ -29,7 +29,7 @@
namespace ns3 {
NetDevice::NetDevice(Node *node, const MacAddress& addr) :
NetDevice::NetDevice(Ptr<Node> node, const MacAddress& addr) :
m_node (node),
m_name(""),
m_ifIndex (0),
@ -228,7 +228,7 @@ NetDevice::NotifyLinkDown (void)
}
}
Node *
Ptr<Node>
NetDevice::PeekNode (void) const
{
return m_node;

View File

@ -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> 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<Node> 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<Node> m_node;
std::string m_name;
uint16_t m_ifIndex;
MacAddress m_address;