diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index e97cb147f..a01b2cc54 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -126,10 +126,13 @@ int main (int argc, char *argv[]) DataRate(448000), 210); // Add to Node's ApplicationList (takes ownership of pointer) - n0->GetApplicationList()->Add(ooff0); + ApplicationList *apl0 = n0->GetApplicationList(); + apl0->Add(ooff0); + apl0->Unref (); // 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( @@ -141,15 +144,23 @@ int main (int argc, char *argv[]) DataRate(448000), 210); // Add to Node's ApplicationList (takes ownership of pointer) - n3->GetApplicationList()->Add(ooff1); + ApplicationList *apl3 = n3->GetApplicationList(); + apl3->Add(ooff1); + apl3->Unref (); // 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 - n0->GetIpv4()->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); - n3->GetIpv4()->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1); + Ipv4 *ipv4; + ipv4 = n0->GetIpv4(); + ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); + ipv4->Unref (); + ipv4 = n3->GetIpv4(); + ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1); + ipv4->Unref (); n0->Unref (); n1->Unref (); diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index 1562428e7..51b7c8c64 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -84,6 +84,9 @@ PointToPointTopology::AddPointToPointLink( ip1->AddHostRouteTo (addr2, index1); ip2->AddHostRouteTo (addr1, index2); + ip1->Unref (); + ip2->Unref (); + return channel; } diff --git a/src/node/application-list.cc b/src/node/application-list.cc index f13c16815..2a8f3ddd6 100644 --- a/src/node/application-list.cc +++ b/src/node/application-list.cc @@ -56,6 +56,7 @@ ApplicationList* ApplicationList::Copy(Node * n) const void ApplicationList::Add(Application* a) { + a->Ref (); m_apps.push_back(a); } diff --git a/src/node/internet-node.cc b/src/node/internet-node.cc index 15aeb565b..eaa5473b1 100644 --- a/src/node/internet-node.cc +++ b/src/node/internet-node.cc @@ -41,9 +41,17 @@ InternetNode::InternetNode() m_applicationList = new ApplicationList(this); m_l3Demux = new L3Demux(this); m_ipv4L4Demux = new Ipv4L4Demux(this); - m_l3Demux->Insert (Ipv4 (this)); - m_l3Demux->Insert (Arp (this)); - m_ipv4L4Demux->Insert (Udp (this)); + Ipv4 *ipv4 = new Ipv4 (this); + Arp *arp = new Arp (this); + Udp *udp = new Udp (this); + + m_l3Demux->Insert (ipv4); + m_l3Demux->Insert (arp); + m_ipv4L4Demux->Insert (udp); + + ipv4->Unref (); + arp->Unref (); + udp->Unref (); } InternetNode::~InternetNode () @@ -161,7 +169,9 @@ InternetNode::DoAddDevice (NetDevice *device) const bool InternetNode::ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const { - L3Protocol *target = GetL3Demux()->PeekProtocol (protocolNumber); + L3Demux *demux = GetL3Demux(); + L3Protocol *target = demux->PeekProtocol (protocolNumber); + demux->Unref (); if (target != 0) { Packet packet = p; diff --git a/src/node/ipv4-l4-demux.cc b/src/node/ipv4-l4-demux.cc index ba37dc6a3..4d05e4c2d 100644 --- a/src/node/ipv4-l4-demux.cc +++ b/src/node/ipv4-l4-demux.cc @@ -56,16 +56,6 @@ Ipv4L4Demux::Dispose (void) } } -Ipv4L4Demux* -Ipv4L4Demux::Copy(Node *node) const -{ - Ipv4L4Demux * copy = new Ipv4L4Demux(node); - for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) - { - copy->Insert(*(*i)); - } - return copy; -} TraceResolver * Ipv4L4Demux::CreateTraceResolver (TraceContext const &context) { @@ -83,12 +73,11 @@ Ipv4L4Demux::CreateTraceResolver (TraceContext const &context) } return resolver; } -Ipv4L4Protocol* -Ipv4L4Demux::Insert(const Ipv4L4Protocol&protocol) +void +Ipv4L4Demux::Insert(Ipv4L4Protocol *protocol) { - Ipv4L4Protocol* copy = protocol.Copy(m_node); // Make a copy of the protocol - m_protocols.push_back (copy); - return copy; + protocol->Ref (); + m_protocols.push_back (protocol); } Ipv4L4Protocol* Ipv4L4Demux::PeekProtocol(int protocolNumber) diff --git a/src/node/ipv4-l4-demux.h b/src/node/ipv4-l4-demux.h index c8fba5454..bd347d8b6 100644 --- a/src/node/ipv4-l4-demux.h +++ b/src/node/ipv4-l4-demux.h @@ -47,12 +47,6 @@ public: void Dispose (void); - /** - * \param node the node on which the returned copy will run. - * \returns a deep copy of this L4 Demux. - */ - Ipv4L4Demux* Copy(Node *node) const; - /** * \param context the trace context to use to construct the * TraceResolver to return @@ -71,7 +65,7 @@ public: * a working L4 Protocol and returned from this method. * The caller does not get ownership of the returned pointer. */ - Ipv4L4Protocol* Insert(const Ipv4L4Protocol&protocol); + void Insert(Ipv4L4Protocol *protocol); /** * \param protocolNumber number of protocol to lookup * in this L4 Demux diff --git a/src/node/ipv4-l4-protocol.h b/src/node/ipv4-l4-protocol.h index eaf28be83..782b64791 100644 --- a/src/node/ipv4-l4-protocol.h +++ b/src/node/ipv4-l4-protocol.h @@ -62,13 +62,6 @@ public: */ int GetVersion() const; - /** - * \param node the node on which the copy should be running - * \returns a new instance of this L4 Protocol. - * - * Perform a deep copy of the L4 Protocol - */ - virtual Ipv4L4Protocol* Copy(Node *node) const = 0; virtual TraceResolver *CreateTraceResolver (TraceContext const &context) = 0; /** diff --git a/src/node/l3-demux.cc b/src/node/l3-demux.cc index 7bee2bffd..630f03a64 100644 --- a/src/node/l3-demux.cc +++ b/src/node/l3-demux.cc @@ -73,22 +73,10 @@ L3Demux::CreateTraceResolver (TraceContext const &context) const return resolver; } -L3Demux* L3Demux::Copy(Node *node) const +void L3Demux::Insert(L3Protocol *p) { - L3Demux *copy = new L3Demux (node); - for (L3Map_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) - { - copy->Insert(*i->second); - } - - return copy; -} - -L3Protocol* L3Demux::Insert(const L3Protocol& l3p) -{ - L3Protocol* l = l3p.Copy(m_node); // Make a copy of the protocol - m_protocols.insert(L3Map_t::value_type(l3p.GetProtocolNumber (), l)); - return l; + p->Ref (); + m_protocols.insert(L3Map_t::value_type(p->GetProtocolNumber (), p)); } L3Protocol* diff --git a/src/node/l3-demux.h b/src/node/l3-demux.h index 72b5adaff..71ab0df2f 100644 --- a/src/node/l3-demux.h +++ b/src/node/l3-demux.h @@ -49,12 +49,6 @@ public: void Dispose (void); - /** - * \param node the node on which the returned copy will run. - * \returns a deep copy of this L3 Demux. - */ - L3Demux* Copy(Node *node) const; - /** * \param context the trace context to use to construct the * TraceResolver to return @@ -67,7 +61,6 @@ public: /** * \param protocol a template for the protocol to add to this L3 Demux. - * \returns the L3Protocol effectively added. * * Invoke Copy on the input template to get a copy of the input * protocol which can be used on the Node on which this L3 Demux @@ -75,7 +68,7 @@ public: * a working L3 Protocol and returned from this method. * The caller does not get ownership of the returned pointer. */ - ns3::L3Protocol* Insert(const ns3::L3Protocol& protocol); + void Insert(ns3::L3Protocol * protocol); /** * \param protocolNumber number of protocol to lookup * in this L4 Demux diff --git a/src/node/l3-protocol.h b/src/node/l3-protocol.h index 56ae25ccf..26d195fe5 100644 --- a/src/node/l3-protocol.h +++ b/src/node/l3-protocol.h @@ -48,8 +48,6 @@ public: virtual void Dispose (void) = 0; - virtual L3Protocol* Copy(Node *node) const = 0; - virtual TraceResolver *CreateTraceResolver (TraceContext const &context) = 0; /** * Lower layer calls this method after calling L3Demux::Lookup diff --git a/src/node/udp-socket.cc b/src/node/udp-socket.cc index 77966214a..e940dfa51 100644 --- a/src/node/udp-socket.cc +++ b/src/node/udp-socket.cc @@ -34,8 +34,8 @@ UdpSocket::UdpSocket (Node *node) m_shutdownRecv (false), m_connected (false) { - NS_ASSERT (m_node->GetUdp () != 0); m_udp = m_node->GetUdp (); + NS_ASSERT (m_udp != 0); m_node->Ref (); } UdpSocket::~UdpSocket ()