Mathieu Lacage 2007-05-10 07:19:38 +02:00
commit 2eb20b5743
15 changed files with 67 additions and 74 deletions

View File

@ -184,10 +184,10 @@ 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

View File

@ -39,7 +39,6 @@ Application::Application(Ptr<Node> 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<Node> n)
{
if (m_node != 0)
{
m_node->Unref ();
}
m_node = n;
m_node->Ref ();
}
Ptr<Node> Application::PeekNode() const

View File

@ -24,6 +24,7 @@
#include <stdint.h>
#include <string>
#include "ns3/callback.h"
#include "ns3/ptr.h"
#include "trace-resolver.h"
namespace ns3 {
@ -81,13 +82,12 @@ public:
*/
ArrayTraceResolver (TraceContext const &context,
Callback<uint32_t> getSize,
Callback<T *, uint32_t> get);
Callback<Ptr<T>, uint32_t> get);
private:
virtual TraceResolverList DoLookup (std::string id) const;
Callback<uint32_t> m_getSize;
Callback<T *, uint32_t> m_get;
Callback<Ptr<T>, uint32_t> m_get;
};
}//namespace ns3
namespace ns3 {
@ -109,7 +109,7 @@ ArrayTraceResolver<T>::Index::operator uint32_t ()
template <typename T>
ArrayTraceResolver<T>::ArrayTraceResolver (TraceContext const &context,
Callback<uint32_t> getSize,
Callback<T *, uint32_t> get)
Callback<Ptr<T>, uint32_t> get)
: TraceResolver (context),
m_getSize (getSize),
m_get (get)

View File

@ -28,7 +28,7 @@
namespace ns3 {
ArpCache::ArpCache (NetDevice *device, Ipv4Interface *interface)
ArpCache::ArpCache (NetDevice *device, Ptr<Ipv4Interface> interface)
: m_device (device),
m_interface (interface),
m_aliveTimeout (Seconds (120)),
@ -50,7 +50,7 @@ ArpCache::PeekDevice (void) const
return m_device;
}
Ipv4Interface *
Ptr<Ipv4Interface>
ArpCache::GetInterface (void) const
{
return m_interface;

View File

@ -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<Ipv4Interface> interface);
~ArpCache ();
NetDevice *PeekDevice (void) const;
Ipv4Interface *GetInterface (void) const;
Ptr<Ipv4Interface> GetInterface (void) const;
void SetAliveTimeout (Time aliveTimeout);
void SetDeadTimeout (Time deadTimeout);
@ -92,7 +93,7 @@ private:
typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash>::iterator CacheI;
NetDevice *m_device;
Ipv4Interface *m_interface;
Ptr<Ipv4Interface> m_interface;
Time m_aliveTimeout;
Time m_deadTimeout;
Time m_waitReplyTimeout;

View File

@ -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> 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> (IIpv4Private::iid);
Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device);
Ptr<Ipv4Interface> interface = ipv4->FindInterfaceForDevice (device);
ipv4->Unref ();
ArpCache * cache = new ArpCache (device, interface);
NS_ASSERT (device->IsBroadcast ());

View File

@ -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> 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<Node> m_node;
};
}//namespace ns3

View File

@ -47,7 +47,7 @@ IIpv4Private::Send (Packet const &packet, Ipv4Address source,
{
m_ipv4->Send (packet, source, destination, protocol);
}
Ipv4Interface *
Ptr<Ipv4Interface>
IIpv4Private::FindInterfaceForDevice (NetDevice const*device)
{
return m_ipv4->FindInterfaceForDevice (device);

View File

@ -23,6 +23,7 @@
#include "ns3/ns-unknown.h"
#include "ns3/ipv4-address.h"
#include "ns3/ptr.h"
#include <stdint.h>
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<Ipv4Interface> FindInterfaceForDevice (NetDevice const*device);
void Receive(Packet& p, NetDevice *device);
protected:
virtual void DoDispose (void);

View File

@ -25,6 +25,7 @@
#include <list>
#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:
/**

View File

@ -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<Ipv4Interface> interface = new ArpIpv4Interface (m_node, device);
return AddIpv4Interface (interface);
}
uint32_t
Ipv4::AddIpv4Interface (Ipv4Interface *interface)
Ipv4::AddIpv4Interface (Ptr<Ipv4Interface> interface)
{
uint32_t index = m_nInterfaces;
m_interfaces.push_back (interface);
m_nInterfaces++;
return index;
}
Ipv4Interface *
Ptr<Ipv4Interface>
Ipv4::GetInterface (uint32_t index) const
{
uint32_t tmp = 0;
@ -350,7 +350,7 @@ Ipv4::GetNInterfaces (void) const
return m_nInterfaces;
}
Ipv4Interface *
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);
Ipv4Interface *outInterface = GetInterface (route.GetInterface ());
Ptr<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++)
{
Ipv4Interface *interface = *i;
Ptr<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)
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
interface->SetAddress (address);
}
void
Ipv4::SetNetworkMask (uint32_t i, Ipv4Mask mask)
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
interface->SetNetworkMask (mask);
}
Ipv4Mask
Ipv4::GetNetworkMask (uint32_t i) const
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
return interface->GetNetworkMask ();
}
Ipv4Address
Ipv4::GetAddress (uint32_t i) const
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
return interface->GetAddress ();
}
uint16_t
Ipv4::GetMtu (uint32_t i) const
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
return interface->GetMtu ();
}
bool
Ipv4::IsUp (uint32_t i) const
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
return interface->IsUp ();
}
void
Ipv4::SetUp (uint32_t i)
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
interface->SetUp ();
}
void
Ipv4::SetDown (uint32_t i)
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
interface->SetDown ();
}

View File

@ -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<Ipv4Interface> 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<Ipv4Interface> 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<Ipv4Interface> interface);
void SetupLoopback (void);
TraceResolver *InterfacesCreateTraceResolver (TraceContext const &context) const;
typedef std::list<Ipv4Interface*> Ipv4InterfaceList;
typedef std::list<Ptr<Ipv4Interface> > Ipv4InterfaceList;
typedef std::list<Ipv4Route *> HostRoutes;
typedef std::list<Ipv4Route *>::const_iterator HostRoutesCI;
typedef std::list<Ipv4Route *>::iterator HostRoutesI;

View File

@ -40,12 +40,10 @@ NetDevice::NetDevice(Ptr<Node> node, const MacAddress& addr) :
m_isMulticast (false),
m_isPointToPoint (false)
{
m_node->Ref ();
}
NetDevice::~NetDevice ()
{
m_node->Unref ();
m_node = 0;
}

View File

@ -49,37 +49,37 @@ public:
NodeListPriv ();
~NodeListPriv ();
uint32_t Add (Node *node);
uint32_t Add (Ptr<Node> node);
NodeList::Iterator Begin (void);
NodeList::Iterator End (void);
TraceResolver *CreateTraceResolver (TraceContext const &context);
Node *PeekNode (uint32_t n);
Ptr<Node> PeekNode (uint32_t n);
uint32_t GetNNodes (void);
private:
std::vector<Node *> m_nodes;
std::vector<Ptr<Node> > m_nodes;
};
NodeListPriv::NodeListPriv ()
{}
NodeListPriv::~NodeListPriv ()
{
for (std::vector<Node *>::iterator i = m_nodes.begin ();
for (std::vector<Ptr<Node> >::iterator i = m_nodes.begin ();
i != m_nodes.end (); i++)
{
Node *node = *i;
Ptr<Node> 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> 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<Node>
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> node)
{
return SimulationSingleton<NodeListPriv>::Get ()->Add (node);
}
@ -145,7 +145,7 @@ NodeList::CreateTraceResolver (TraceContext const &context)
{
return SimulationSingleton<NodeListPriv>::Get ()->CreateTraceResolver (context);
}
Node *
Ptr<Node>
NodeList::PeekNode (uint32_t n)
{
return SimulationSingleton<NodeListPriv>::Get ()->PeekNode (n);

View File

@ -24,6 +24,7 @@
#include <vector>
#include "ns3/array-trace-resolver.h"
#include "ns3/ptr.h"
namespace ns3 {
@ -35,14 +36,14 @@ class NodeList
{
public:
typedef ArrayTraceResolver<Node>::Index NodeIndex;
typedef std::vector<Node *>::iterator Iterator;
typedef std::vector< Ptr<Node> >::iterator Iterator;
static uint32_t Add (Node *node);
static uint32_t Add (Ptr<Node> node);
static Iterator Begin (void);
static Iterator End (void);
static TraceResolver *CreateTraceResolver (TraceContext const &context);
static Node *PeekNode (uint32_t n);
static Ptr<Node> PeekNode (uint32_t n);
};
}//namespace ns3