diff --git a/samples/main-p2p-net-device-if.cc b/samples/main-p2p-net-device-if.cc index 2043079c1..d61461672 100644 --- a/samples/main-p2p-net-device-if.cc +++ b/samples/main-p2p-net-device-if.cc @@ -80,7 +80,7 @@ protected: static void GenerateTraffic (Socket *socket, uint32_t size) { - std::cout << "Node: " << socket->GetNode()->GetId () + std::cout << "Node: " << socket->PeekNode()->GetId () << " at=" << Simulator::Now ().GetSeconds () << "s," << " tx bytes=" << size << std::endl; socket->Send (0, size); @@ -93,7 +93,7 @@ GenerateTraffic (Socket *socket, uint32_t size) static void SocketPrinter (Socket *socket, uint32_t size, const Ipv4Address &from, uint16_t fromPort) { - std::cout << "Node: " << socket->GetNode()->GetId () + std::cout << "Node: " << socket->PeekNode()->GetId () << " at=" << Simulator::Now ().GetSeconds () << "s," << " rx bytes=" << size << std::endl; } diff --git a/src/node/arp-ipv4-interface.cc b/src/node/arp-ipv4-interface.cc index 9c7ce8215..ae987b8d0 100644 --- a/src/node/arp-ipv4-interface.cc +++ b/src/node/arp-ipv4-interface.cc @@ -34,9 +34,13 @@ namespace ns3 { ArpIpv4Interface::ArpIpv4Interface (Node *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/node/arp.cc b/src/node/arp.cc index c3918fafb..b5de23595 100644 --- a/src/node/arp.cc +++ b/src/node/arp.cc @@ -38,7 +38,9 @@ const uint16_t Arp::PROT_NUMBER = 0x0806; Arp::Arp (Node *node) : L3Protocol (PROT_NUMBER, 0/* XXX: correct version number ? */ ), m_node (node) -{} +{ + m_node->Ref (); +} Arp::~Arp () { @@ -46,6 +48,7 @@ Arp::~Arp () { delete *i; } + m_node->Unref (); } Arp * diff --git a/src/node/ipv4-l4-demux.cc b/src/node/ipv4-l4-demux.cc index 3a2b9b986..e4051ca3e 100644 --- a/src/node/ipv4-l4-demux.cc +++ b/src/node/ipv4-l4-demux.cc @@ -26,12 +26,15 @@ #include "ns3/composite-trace-resolver.h" #include "ipv4-l4-demux.h" #include "ipv4-l4-protocol.h" +#include "node.h" namespace ns3 { Ipv4L4Demux::Ipv4L4Demux (Node *node) : m_node (node) -{} +{ + m_node->Ref (); +} Ipv4L4Demux::~Ipv4L4Demux() { @@ -39,6 +42,8 @@ Ipv4L4Demux::~Ipv4L4Demux() { delete *i; } + m_node->Unref (); + m_node = 0; } Ipv4L4Demux* Ipv4L4Demux::Copy(Node *node) const diff --git a/src/node/ipv4-loopback-interface.cc b/src/node/ipv4-loopback-interface.cc index 6c0ec5f53..4a2a968d0 100644 --- a/src/node/ipv4-loopback-interface.cc +++ b/src/node/ipv4-loopback-interface.cc @@ -31,14 +31,11 @@ Ipv4LoopbackInterface::Ipv4LoopbackInterface (Node *node) : Ipv4Interface (0), m_node (node) { + m_node->Ref (); } Ipv4LoopbackInterface::~Ipv4LoopbackInterface () -{} - -Node * -Ipv4LoopbackInterface::GetNode (void) const { - return m_node; + m_node->Unref (); } TraceResolver * diff --git a/src/node/ipv4-loopback-interface.h b/src/node/ipv4-loopback-interface.h index 476a72abd..c4dff8763 100644 --- a/src/node/ipv4-loopback-interface.h +++ b/src/node/ipv4-loopback-interface.h @@ -37,7 +37,6 @@ class Ipv4LoopbackInterface : public Ipv4Interface private: virtual void SendTo (Packet p, Ipv4Address dest); virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); - Node *GetNode (void) const; Node *m_node; }; diff --git a/src/node/ipv4.cc b/src/node/ipv4.cc index 8b8c2516b..9167bdd33 100644 --- a/src/node/ipv4.cc +++ b/src/node/ipv4.cc @@ -52,6 +52,7 @@ Ipv4::Ipv4(Node *node) m_node (node) { SetupLoopback (); + m_node->Ref (); } Ipv4::~Ipv4 () { @@ -72,6 +73,7 @@ Ipv4::~Ipv4 () delete (*j); } delete m_defaultRoute; + m_node->Unref (); } void diff --git a/src/node/l3-demux.cc b/src/node/l3-demux.cc index 8dae35096..74ee5be0b 100644 --- a/src/node/l3-demux.cc +++ b/src/node/l3-demux.cc @@ -25,12 +25,15 @@ #include "ns3/composite-trace-resolver.h" #include "l3-demux.h" #include "l3-protocol.h" +#include "node.h" namespace ns3 { L3Demux::L3Demux (Node *node) : m_node (node) -{} +{ + m_node->Ref (); +} L3Demux::~L3Demux() { // Delete each protocol in the map @@ -38,6 +41,8 @@ L3Demux::~L3Demux() { delete i->second; } + m_node->Unref (); + m_node = 0; } TraceResolver * diff --git a/src/node/net-device.cc b/src/node/net-device.cc index e7e25f589..221a2e68d 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -39,7 +39,15 @@ NetDevice::NetDevice(Node *node, const MacAddress& addr) : m_isBroadcast (false), m_isMulticast (false), m_isPointToPoint (false) -{} +{ + m_node->Ref (); +} + +NetDevice::~NetDevice () +{ + m_node->Unref (); + m_node = 0; +} MacAddress NetDevice::GetAddress (void) const @@ -209,7 +217,7 @@ NetDevice::NotifyLinkDown (void) } Node * -NetDevice::GetNode (void) const +NetDevice::PeekNode (void) const { return m_node; } diff --git a/src/node/net-device.h b/src/node/net-device.h index a8000526a..4d060e253 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -62,7 +62,7 @@ public: * \param addr MAC address of this device. */ NetDevice(Node* node, const MacAddress& addr); - virtual ~NetDevice() {} + virtual ~NetDevice(); /** * \param context the trace context to use to construct the @@ -205,7 +205,7 @@ public: * base class to print the nodeid for example, it can invoke * this method. */ - Node* GetNode (void) const; + Node* PeekNode (void) const; /** * \param p packet sent from below up to Network Device diff --git a/src/node/socket.h b/src/node/socket.h index f5a1b20a3..3041ea590 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -63,7 +63,7 @@ public: /** * \returns the node this socket is associated with. */ - virtual Node *GetNode (void) const = 0; + virtual Node *PeekNode (void) const = 0; /** * Allocate a free port number and diff --git a/src/node/udp-socket.cc b/src/node/udp-socket.cc index 211e8371f..fdc37623d 100644 --- a/src/node/udp-socket.cc +++ b/src/node/udp-socket.cc @@ -35,14 +35,17 @@ UdpSocket::UdpSocket (Node *node) m_connected (false) { NS_ASSERT (GetUdp () != 0); + m_node->Ref (); } UdpSocket::~UdpSocket () { delete m_endPoint; + m_node->Unref (); + m_node = 0; } Node * -UdpSocket::GetNode (void) const +UdpSocket::PeekNode (void) const { return m_node; } diff --git a/src/node/udp-socket.h b/src/node/udp-socket.h index 5eae43bd8..0e8ff1bb3 100644 --- a/src/node/udp-socket.h +++ b/src/node/udp-socket.h @@ -42,7 +42,7 @@ public: virtual ~UdpSocket (); virtual enum SocketErrno GetErrno (void) const; - virtual Node *GetNode (void) const; + virtual Node *PeekNode (void) const; virtual int Bind (void); virtual int Bind (Ipv4Address address); virtual int Bind (uint16_t port); diff --git a/src/node/udp.cc b/src/node/udp.cc index 0a14e8dd7..1cf3ab8a1 100644 --- a/src/node/udp.cc +++ b/src/node/udp.cc @@ -41,11 +41,15 @@ Udp::Udp (Node *node) : Ipv4L4Protocol (PROT_NUMBER, 2), m_node (node), m_endPoints (new Ipv4EndPointDemux ()) -{} +{ + m_node->Ref (); +} Udp::~Udp () { delete m_endPoints; + m_node->Unref (); + m_node = 0; } TraceResolver *