diff --git a/src/devices/csma-cd/csma-cd-net-device.cc b/src/devices/csma-cd/csma-cd-net-device.cc index e587bb089..fe5c0ba26 100644 --- a/src/devices/csma-cd/csma-cd-net-device.cc +++ b/src/devices/csma-cd/csma-cd-net-device.cc @@ -450,19 +450,18 @@ CsmaCdNetDevice::TransmitReadyEvent (void) } Ptr -CsmaCdNetDevice::DoCreateTraceResolver (void) +CsmaCdNetDevice::GetTraceResolver (void) { Ptr resolver = Create (); - resolver->Add ("queue", - MakeCallback (&Queue::CreateTraceResolver, - PeekPointer (m_queue))); + resolver->AddChild ("queue", m_queue); resolver->Add ("rx", m_rxTrace, CsmaCdTraceType (CsmaCdTraceType::RX)); resolver->Add ("drop", m_dropTrace, CsmaCdTraceType (CsmaCdTraceType::DROP)); - return resolver; + resolver->SetParent (NetDevice::GetTraceResolver ()); + return resolver; } bool diff --git a/src/devices/csma-cd/csma-cd-net-device.h b/src/devices/csma-cd/csma-cd-net-device.h index 42b85f3b5..5de056109 100644 --- a/src/devices/csma-cd/csma-cd-net-device.h +++ b/src/devices/csma-cd/csma-cd-net-device.h @@ -191,6 +191,13 @@ enum CsmaCdEncapsulationMode { protected: virtual bool DoNeedsArp (void) const; virtual void DoDispose (void); + /** + * Create a Trace Resolver for events in the net device. + * (NOT TESTED) + * @see class TraceResolver + */ + virtual Ptr GetTraceResolver (void); + /** * Get a copy of the attached Queue. * @@ -306,12 +313,6 @@ private: * @see TransmitStart () */ void TransmitReadyEvent (void); - /** - * Create a Trace Resolver for events in the net device. - * (NOT TESTED) - * @see class TraceResolver - */ - virtual Ptr DoCreateTraceResolver (void); /** * Aborts the transmission of the current packet diff --git a/src/devices/point-to-point/point-to-point-net-device.cc b/src/devices/point-to-point/point-to-point-net-device.cc index 5275b6209..633fbe5c6 100644 --- a/src/devices/point-to-point/point-to-point-net-device.cc +++ b/src/devices/point-to-point/point-to-point-net-device.cc @@ -189,14 +189,14 @@ void PointToPointNetDevice::TransmitComplete (void) } Ptr -PointToPointNetDevice::DoCreateTraceResolver (void) +PointToPointNetDevice::GetTraceResolver (void) { Ptr resolver = Create (); - resolver->Add ("queue", - MakeCallback (&Queue::CreateTraceResolver, PeekPointer (m_queue))); + resolver->AddChild ("queue", m_queue); resolver->Add ("rx", m_rxTrace, PointToPointTraceType ()); + resolver->SetParent (NetDevice::GetTraceResolver ()); return resolver; } diff --git a/src/devices/point-to-point/point-to-point-net-device.h b/src/devices/point-to-point/point-to-point-net-device.h index 3a1bc1e0e..5cee2cf70 100644 --- a/src/devices/point-to-point/point-to-point-net-device.h +++ b/src/devices/point-to-point/point-to-point-net-device.h @@ -152,6 +152,12 @@ public: */ void Receive (Packet& p); protected: + /** + * Create a Trace Resolver for events in the net device. + * + * @see class TraceResolver + */ + virtual Ptr GetTraceResolver (void); virtual void DoDispose (void); /** * Get a copy of the attached Queue. @@ -238,12 +244,6 @@ private: * */ void TransmitComplete(void); - /** - * Create a Trace Resolver for events in the net device. - * - * @see class TraceResolver - */ - virtual Ptr DoCreateTraceResolver (void); virtual bool DoNeedsArp (void) const; /** * Enumeration of the states of the transmit machine of the net device. diff --git a/src/internet-node/arp-cache.cc b/src/internet-node/arp-cache.cc index b4987daef..15a1d9316 100644 --- a/src/internet-node/arp-cache.cc +++ b/src/internet-node/arp-cache.cc @@ -19,16 +19,16 @@ * Author: Mathieu Lacage */ #include "ns3/assert.h" - #include "ns3/packet.h" #include "ns3/simulator.h" #include "arp-cache.h" #include "arp-header.h" +#include "ipv4-interface.h" namespace ns3 { -ArpCache::ArpCache (Ptr device, Ipv4Interface *interface) +ArpCache::ArpCache (Ptr device, Ptr interface) : m_device (device), m_interface (interface), m_aliveTimeout (Seconds (120)), @@ -47,7 +47,7 @@ ArpCache::GetDevice (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 2cd88c85f..adf106009 100644 --- a/src/internet-node/arp-cache.h +++ b/src/internet-node/arp-cache.h @@ -48,7 +48,7 @@ public: * \param device The hardware NetDevice associated with this ARP chache * \param interface the Ipv4Interface associated with this ARP chache */ - ArpCache (Ptr device, Ipv4Interface *interface); + ArpCache (Ptr device, Ptr interface); ~ArpCache (); /** * \return The NetDevice that this ARP cache is associated with @@ -57,7 +57,7 @@ public: /** * \return the Ipv4Interface that this ARP cache is associated with */ - Ipv4Interface *GetInterface (void) const; + Ptr GetInterface (void) const; void SetAliveTimeout (Time aliveTimeout); void SetDeadTimeout (Time deadTimeout); @@ -152,7 +152,7 @@ private: typedef sgi::hash_map::iterator CacheI; Ptr m_device; - Ipv4Interface *m_interface; + Ptr m_interface; Time m_aliveTimeout; Time m_deadTimeout; Time m_waitReplyTimeout; diff --git a/src/internet-node/arp-ipv4-interface.cc b/src/internet-node/arp-ipv4-interface.cc index 3c353efe6..2648c5ec4 100644 --- a/src/internet-node/arp-ipv4-interface.cc +++ b/src/internet-node/arp-ipv4-interface.cc @@ -41,15 +41,14 @@ ArpIpv4Interface::~ArpIpv4Interface () {} Ptr -ArpIpv4Interface::DoCreateTraceResolver (void) +ArpIpv4Interface::GetTraceResolver (void) { Ptr resolver = Create (); if (GetDevice () != 0) { - resolver->Add ("netdevice", - MakeCallback (&NetDevice::CreateTraceResolver, PeekPointer (GetDevice ()))); + resolver->AddChild ("netdevice", GetDevice ()); } - + resolver->SetParent (Ipv4Interface::GetTraceResolver ()); return resolver; } diff --git a/src/internet-node/arp-ipv4-interface.h b/src/internet-node/arp-ipv4-interface.h index a31039478..73bf4f462 100644 --- a/src/internet-node/arp-ipv4-interface.h +++ b/src/internet-node/arp-ipv4-interface.h @@ -42,9 +42,10 @@ class ArpIpv4Interface : public Ipv4Interface ArpIpv4Interface (Ptr node, Ptr device); virtual ~ArpIpv4Interface (); - private: +protected: + virtual Ptr GetTraceResolver (void); +private: virtual void SendTo (Packet p, Ipv4Address dest); - virtual Ptr DoCreateTraceResolver (void); Ptr m_node; }; diff --git a/src/internet-node/arp-l3-protocol.cc b/src/internet-node/arp-l3-protocol.cc index b116ce648..b4d346e60 100644 --- a/src/internet-node/arp-l3-protocol.cc +++ b/src/internet-node/arp-l3-protocol.cc @@ -58,12 +58,6 @@ ArpL3Protocol::DoDispose (void) Object::DoDispose (); } -Ptr -ArpL3Protocol::CreateTraceResolver (void) -{ - return Create (); -} - ArpCache * ArpL3Protocol::FindCache (Ptr device) { @@ -75,7 +69,7 @@ ArpL3Protocol::FindCache (Ptr device) } } Ptr ipv4 = m_node->QueryInterface (Ipv4L3Protocol::iid); - Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device); + Ptr interface = ipv4->FindInterfaceForDevice (device); ArpCache * cache = new ArpCache (device, interface); NS_ASSERT (device->IsBroadcast ()); device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache)); diff --git a/src/internet-node/arp-l3-protocol.h b/src/internet-node/arp-l3-protocol.h index 468c301b6..5f6819df6 100644 --- a/src/internet-node/arp-l3-protocol.h +++ b/src/internet-node/arp-l3-protocol.h @@ -48,8 +48,6 @@ public: */ ArpL3Protocol (Ptr node); virtual ~ArpL3Protocol (); - - virtual Ptr CreateTraceResolver (void); /** * \brief Recieve a packet */ diff --git a/src/internet-node/internet-node.cc b/src/internet-node/internet-node.cc index 5c2a3de72..7bc9cd3c8 100644 --- a/src/internet-node/internet-node.cc +++ b/src/internet-node/internet-node.cc @@ -74,13 +74,14 @@ InternetNode::Construct (void) Object::AddInterface (ipv4L4Demux); } -void -InternetNode::DoFillTraceResolver (CompositeTraceResolver &resolver) +Ptr +InternetNode::GetTraceResolver () { - Node::DoFillTraceResolver (resolver); + Ptr resolver = Create (); Ptr ipv4 = QueryInterface (Ipv4L3Protocol::iid); - resolver.Add ("ipv4", - MakeCallback (&Ipv4L3Protocol::CreateTraceResolver, PeekPointer (ipv4))); + resolver->AddChild ("ipv4", ipv4); + resolver->SetParent (Node::GetTraceResolver ()); + return resolver; } void diff --git a/src/internet-node/internet-node.h b/src/internet-node/internet-node.h index deabd20eb..d54714a8b 100644 --- a/src/internet-node/internet-node.h +++ b/src/internet-node/internet-node.h @@ -42,8 +42,8 @@ public: protected: virtual void DoDispose(void); + virtual Ptr GetTraceResolver (void); private: - virtual void DoFillTraceResolver (CompositeTraceResolver &resolver); bool ReceiveFromDevice (Ptr device, const Packet &p, uint16_t protocolNumber) const; void Construct (void); }; diff --git a/src/internet-node/ipv4-interface.cc b/src/internet-node/ipv4-interface.cc index 699d6109d..3ea9120d2 100644 --- a/src/internet-node/ipv4-interface.cc +++ b/src/internet-node/ipv4-interface.cc @@ -40,18 +40,19 @@ Ipv4Interface::Ipv4Interface (Ptr nd) Ipv4Interface::~Ipv4Interface () {} +void +Ipv4Interface::DoDispose (void) +{ + m_netdevice = 0; + Object::DoDispose (); +} + Ptr Ipv4Interface::GetDevice (void) const { return m_netdevice; } -Ptr -Ipv4Interface::CreateTraceResolver (void) -{ - return DoCreateTraceResolver (); -} - void Ipv4Interface::SetAddress (Ipv4Address a) { diff --git a/src/internet-node/ipv4-interface.h b/src/internet-node/ipv4-interface.h index a462d5be5..1836aa3b7 100644 --- a/src/internet-node/ipv4-interface.h +++ b/src/internet-node/ipv4-interface.h @@ -26,6 +26,7 @@ #include #include "ns3/ipv4-address.h" #include "ns3/ptr.h" +#include "ns3/object.h" namespace ns3 { @@ -60,9 +61,8 @@ class TraceContext; * * Subclasses must implement the two methods: * - Ipv4Interface::SendTo - * - Ipv4Interface::DoCreateTraceResolver */ -class Ipv4Interface +class Ipv4Interface : public Object { public: /** @@ -73,17 +73,6 @@ public: Ipv4Interface (Ptr nd); virtual ~Ipv4Interface(); - /** - * \param context the trace context to use to construct the - * TraceResolver to return - * \returns a TraceResolver which can resolve all traces - * performed in this object. The caller must - * delete the returned object. - * - * This method will delegate the work to the private DoCreateTraceResolver - * method which is supposed to be implemented by subclasses. - */ - Ptr CreateTraceResolver (void); /** * \returns the underlying NetDevice. This method can return * zero if this interface has no associated NetDevice. @@ -150,10 +139,10 @@ public: */ void Send(Packet p, Ipv4Address dest); - - private: +protected: + virtual void DoDispose (void); +private: virtual void SendTo (Packet p, Ipv4Address dest) = 0; - virtual Ptr DoCreateTraceResolver (void) = 0; Ptr m_netdevice; bool m_ifup; Ipv4Address m_address; diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index df97fafc0..75320e886 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -22,7 +22,6 @@ #include "ns3/packet.h" #include "ns3/debug.h" #include "ns3/composite-trace-resolver.h" -#include "ns3/array-trace-resolver.h" #include "ns3/callback.h" #include "ns3/ipv4-address.h" #include "ns3/ipv4-route.h" @@ -90,26 +89,26 @@ Ipv4L3ProtocolTraceContextElement::GetUid (void) } -Ipv4l3ProtocolInterfaceIndex::Ipv4l3ProtocolInterfaceIndex () +Ipv4L3ProtocolInterfaceIndex::Ipv4L3ProtocolInterfaceIndex () : m_index (0) {} -Ipv4l3ProtocolInterfaceIndex::Ipv4l3ProtocolInterfaceIndex (uint32_t index) +Ipv4L3ProtocolInterfaceIndex::Ipv4L3ProtocolInterfaceIndex (uint32_t index) : m_index (index) {} uint32_t -Ipv4l3ProtocolInterfaceIndex::Get (void) const +Ipv4L3ProtocolInterfaceIndex::Get (void) const { return m_index; } void -Ipv4l3ProtocolInterfaceIndex::Print (std::ostream &os) const +Ipv4L3ProtocolInterfaceIndex::Print (std::ostream &os) const { os << "ipv4-interface=" << m_index; } uint16_t -Ipv4l3ProtocolInterfaceIndex::GetUid (void) +Ipv4L3ProtocolInterfaceIndex::GetUid (void) { - static uint16_t uid = AllocateUid ("Ipv4l3ProtocolInterfaceIndex"); + static uint16_t uid = AllocateUid ("Ipv4L3ProtocolInterfaceIndex"); return uid; } @@ -131,10 +130,6 @@ Ipv4L3Protocol::~Ipv4L3Protocol () void Ipv4L3Protocol::DoDispose (void) { - for (Ipv4InterfaceList::iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) - { - delete (*i); - } m_interfaces.clear (); m_node = 0; m_staticRouting->Dispose (); @@ -145,7 +140,7 @@ Ipv4L3Protocol::DoDispose (void) void Ipv4L3Protocol::SetupLoopback (void) { - Ipv4LoopbackInterface * interface = new Ipv4LoopbackInterface (m_node); + Ptr interface = Create (m_node); interface->SetAddress (Ipv4Address::GetLoopback ()); interface->SetNetworkMask (Ipv4Mask::GetLoopback ()); uint32_t index = AddIpv4Interface (interface); @@ -154,24 +149,15 @@ Ipv4L3Protocol::SetupLoopback (void) } Ptr -Ipv4L3Protocol::CreateTraceResolver (void) +Ipv4L3Protocol::GetTraceResolver (void) { Ptr resolver = Create (); resolver->Add ("tx", m_txTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::TX)); resolver->Add ("rx", m_rxTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::RX)); resolver->Add ("drop", m_dropTrace, Ipv4L3ProtocolTraceContextElement (Ipv4L3ProtocolTraceContextElement::DROP)); - resolver->Add ("interfaces", - MakeCallback (&Ipv4L3Protocol::InterfacesCreateTraceResolver, this)); - return resolver; -} - -Ptr -Ipv4L3Protocol::InterfacesCreateTraceResolver (void) const -{ - Ptr >resolver = - Create > - (MakeCallback (&Ipv4L3Protocol::GetNInterfaces, this), - MakeCallback (&Ipv4L3Protocol::GetInterface, this)); + resolver->AddArray ("interfaces", + m_interfaces.begin (), m_interfaces.end (), + Ipv4L3ProtocolInterfaceIndex ()); return resolver; } @@ -264,18 +250,18 @@ Ipv4L3Protocol::RemoveRoute (uint32_t index) uint32_t Ipv4L3Protocol::AddInterface (Ptr device) { - Ipv4Interface *interface = new ArpIpv4Interface (m_node, device); + Ptr interface = Create (m_node, device); return AddIpv4Interface (interface); } uint32_t -Ipv4L3Protocol::AddIpv4Interface (Ipv4Interface *interface) +Ipv4L3Protocol::AddIpv4Interface (Ptrinterface) { uint32_t index = m_nInterfaces; m_interfaces.push_back (interface); m_nInterfaces++; return index; } -Ipv4Interface * +Ptr Ipv4L3Protocol::GetInterface (uint32_t index) const { uint32_t tmp = 0; @@ -295,7 +281,7 @@ Ipv4L3Protocol::GetNInterfaces (void) const return m_nInterfaces; } -Ipv4Interface * +Ptr Ipv4L3Protocol::FindInterfaceForDevice (Ptr device) { for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) @@ -363,7 +349,7 @@ Ipv4L3Protocol::Send (Packet const &packet, for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin (); ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++) { - Ipv4Interface *outInterface = *ifaceIter; + Ptr outInterface = *ifaceIter; Packet packetCopy = packet; NS_ASSERT (packetCopy.GetSize () <= outInterface->GetMtu ()); @@ -400,7 +386,7 @@ Ipv4L3Protocol::SendRealOut (bool found, return; } packet.AddHeader (ipHeader); - Ipv4Interface *outInterface = GetInterface (route.GetInterface ()); + Ptr outInterface = GetInterface (route.GetInterface ()); NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ()); m_txTrace (packet, route.GetInterface ()); if (route.IsGateway ()) @@ -430,7 +416,7 @@ Ipv4L3Protocol::Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr interface = *i; if (interface->GetDevice () == device) { if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ())) @@ -480,43 +466,43 @@ Ipv4L3Protocol::ForwardUp (Packet p, Ipv4Header const&ip) void Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address) { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); interface->SetAddress (address); } void Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask) { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); interface->SetNetworkMask (mask); } Ipv4Mask Ipv4L3Protocol::GetNetworkMask (uint32_t i) const { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); return interface->GetNetworkMask (); } Ipv4Address Ipv4L3Protocol::GetAddress (uint32_t i) const { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); return interface->GetAddress (); } uint16_t Ipv4L3Protocol::GetMtu (uint32_t i) const { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); return interface->GetMtu (); } bool Ipv4L3Protocol::IsUp (uint32_t i) const { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); return interface->IsUp (); } void Ipv4L3Protocol::SetUp (uint32_t i) { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); interface->SetUp (); // If interface address and network mask have been set, add a route @@ -532,7 +518,7 @@ Ipv4L3Protocol::SetUp (uint32_t i) void Ipv4L3Protocol::SetDown (uint32_t ifaceIndex) { - Ipv4Interface *interface = GetInterface (ifaceIndex); + Ptr interface = GetInterface (ifaceIndex); interface->SetDown (); // Remove all routes that are going through this interface diff --git a/src/internet-node/ipv4-l3-protocol.h b/src/internet-node/ipv4-l3-protocol.h index f6fcec7a7..0866861c0 100644 --- a/src/internet-node/ipv4-l3-protocol.h +++ b/src/internet-node/ipv4-l3-protocol.h @@ -63,11 +63,11 @@ private: enum Type m_type; }; -class Ipv4l3ProtocolInterfaceIndex : public TraceContextElement +class Ipv4L3ProtocolInterfaceIndex : public TraceContextElement { public: - Ipv4l3ProtocolInterfaceIndex (); - Ipv4l3ProtocolInterfaceIndex (uint32_t index); + Ipv4L3ProtocolInterfaceIndex (); + Ipv4L3ProtocolInterfaceIndex (uint32_t index); uint32_t Get (void) const; void Print (std::ostream &os) const; static uint16_t GetUid (void); @@ -85,15 +85,6 @@ public: Ipv4L3Protocol(Ptr node); virtual ~Ipv4L3Protocol (); - /** - * \param context the trace context to use to construct the - * TraceResolver to return - * \returns a TraceResolver which can resolve all traces - * performed in this object. The caller must - * delete the returned object. - */ - virtual Ptr CreateTraceResolver (void); - /** * \param ttl default ttl to use * @@ -109,7 +100,7 @@ public: * Try to find an Ipv4Interface whose NetDevice is equal to * the input NetDevice. */ - Ipv4Interface *FindInterfaceForDevice (Ptr device); + Ptr FindInterfaceForDevice (Ptr device); /** * Lower layer calls this method after calling L3Demux::Lookup @@ -159,7 +150,7 @@ public: void RemoveRoute (uint32_t i); uint32_t AddInterface (Ptr device); - Ipv4Interface * GetInterface (uint32_t i) const; + Ptr GetInterface (uint32_t i) const; uint32_t GetNInterfaces (void) const; @@ -178,6 +169,7 @@ public: protected: virtual void DoDispose (void); + virtual Ptr GetTraceResolver (void); private: @@ -187,11 +179,10 @@ private: Ipv4Header const &ipHeader); bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr device); void ForwardUp (Packet p, Ipv4Header const&ip); - uint32_t AddIpv4Interface (Ipv4Interface *interface); + uint32_t AddIpv4Interface (Ptr interface); void SetupLoopback (void); - Ptr InterfacesCreateTraceResolver (void) const; - typedef std::list Ipv4InterfaceList; + typedef std::list > Ipv4InterfaceList; typedef std::list< std::pair< int, Ptr > > Ipv4RoutingProtocolList; Ipv4InterfaceList m_interfaces; diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index 56ee9eb9a..74ee536b5 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -79,7 +79,7 @@ Ipv4L4Demux::DoDispose (void) } Ptr -Ipv4L4Demux::CreateTraceResolver (void) +Ipv4L4Demux::GetTraceResolver (void) { Ptr resolver = Create (); for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) @@ -89,10 +89,9 @@ Ipv4L4Demux::CreateTraceResolver (void) std::ostringstream oss (protValue); oss << (*i)->GetProtocolNumber (); Ipv4L4ProtocolTraceContextElement protocolNumber = (*i)->GetProtocolNumber (); - resolver->Add (protValue, - MakeCallback (&Ipv4L4Protocol::CreateTraceResolver, PeekPointer (protocol)), - protocolNumber); + resolver->AddChild (protValue, protocol, protocolNumber); } + resolver->SetParent (Object::GetTraceResolver ()); return resolver; } void diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index 0b4755435..4700ec697 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -59,14 +59,6 @@ public: Ipv4L4Demux (Ptr node); virtual ~Ipv4L4Demux(); - /** - * \param context the trace context to use to construct the - * TraceResolver to return - * \returns a TraceResolver which can resolve all traces - * performed in this object. The caller must - * delete the returned object. - */ - Ptr CreateTraceResolver (void); /** * \param protocol a template for the protocol to add to this L4 Demux. * \returns the L4Protocol effectively added. @@ -95,8 +87,10 @@ public: * returned from the Ipv4L4Protocol::Insert method. */ void Remove (Ptr protocol); -private: +protected: + Ptr GetTraceResolver (void); virtual void DoDispose (void); +private: typedef std::list > L4List_t; L4List_t m_protocols; Ptr m_node; diff --git a/src/internet-node/ipv4-l4-protocol.h b/src/internet-node/ipv4-l4-protocol.h index c658318a1..e54dfcc97 100644 --- a/src/internet-node/ipv4-l4-protocol.h +++ b/src/internet-node/ipv4-l4-protocol.h @@ -37,10 +37,6 @@ class TraceContext; /** * \brief L4 Protocol base class * - * All subclasses must implement: - * - Ipv4L4Protocol::Copy - * - Ipv4L4Protocol::CreateTraceResolver - * * If you want to implement a new L4 protocol, all you have to do is * implement a subclass of this base class and add it to an L4Demux. */ @@ -59,8 +55,6 @@ public: */ int GetVersion() const; - virtual Ptr CreateTraceResolver () = 0; - /** * \param p packet to forward up * \param source source address of packet received diff --git a/src/internet-node/ipv4-loopback-interface.cc b/src/internet-node/ipv4-loopback-interface.cc index 1364e2daf..307533d6e 100644 --- a/src/internet-node/ipv4-loopback-interface.cc +++ b/src/internet-node/ipv4-loopback-interface.cc @@ -33,13 +33,6 @@ Ipv4LoopbackInterface::Ipv4LoopbackInterface (Ptr node) {} Ipv4LoopbackInterface::~Ipv4LoopbackInterface () {} - -Ptr -Ipv4LoopbackInterface::DoCreateTraceResolver (void) -{ - return Create (); -} - void Ipv4LoopbackInterface::SendTo (Packet packet, Ipv4Address dest) { diff --git a/src/internet-node/ipv4-loopback-interface.h b/src/internet-node/ipv4-loopback-interface.h index e9df32007..8e33f81d7 100644 --- a/src/internet-node/ipv4-loopback-interface.h +++ b/src/internet-node/ipv4-loopback-interface.h @@ -43,7 +43,6 @@ class Ipv4LoopbackInterface : public Ipv4Interface private: virtual void SendTo (Packet p, Ipv4Address dest); - virtual Ptr DoCreateTraceResolver (void); Ptr m_node; }; diff --git a/src/internet-node/udp-l4-protocol.cc b/src/internet-node/udp-l4-protocol.cc index 13e937d3c..d9b5afe23 100644 --- a/src/internet-node/udp-l4-protocol.cc +++ b/src/internet-node/udp-l4-protocol.cc @@ -45,12 +45,6 @@ UdpL4Protocol::UdpL4Protocol (Ptr node) UdpL4Protocol::~UdpL4Protocol () {} -Ptr -UdpL4Protocol::CreateTraceResolver (void) -{ - return Create (); -} - void UdpL4Protocol::DoDispose (void) { diff --git a/src/internet-node/udp-l4-protocol.h b/src/internet-node/udp-l4-protocol.h index da2cd0e2d..46fe62761 100644 --- a/src/internet-node/udp-l4-protocol.h +++ b/src/internet-node/udp-l4-protocol.h @@ -49,7 +49,6 @@ public: UdpL4Protocol (Ptr node); virtual ~UdpL4Protocol (); - virtual Ptr CreateTraceResolver (void); /** * \return A smart Socket pointer to a UdpSocket, allocated by this instance * of the UDP protocol diff --git a/src/node/net-device.cc b/src/node/net-device.cc index cdc1f63f3..8ec8b0992 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -184,12 +184,6 @@ NetDevice::Send(Packet& p, const Address& dest, uint16_t protocolNumber) } } -Ptr -NetDevice::CreateTraceResolver (void) -{ - return DoCreateTraceResolver (); -} - Ptr NetDevice::GetChannel (void) const { diff --git a/src/node/net-device.h b/src/node/net-device.h index af63be5b4..7516345d8 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -62,14 +62,6 @@ public: static const InterfaceId iid; virtual ~NetDevice(); - /** - * \param context the trace context to use to construct the - * TraceResolver to return - * \returns a TraceResolver which can resolve all traces - * performed in this object. The caller must - * delete the returned object. - */ - Ptr CreateTraceResolver (void); /** * \return the channel this NetDevice is connected to. The value @@ -282,15 +274,6 @@ public: * 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 Ptr DoCreateTraceResolver (void) = 0; /** * \returns the channel associated to this NetDevice. * diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 823b92a0c..1b74dbe86 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -33,7 +33,7 @@ static class Initialization public: Initialization () { - ns3::TraceRoot::Register ("nodes", ns3::MakeCallback (&ns3::NodeList::CreateTraceResolver)); + ns3::TraceRoot::Register ("nodes", ns3::MakeCallback (&ns3::NodeList::GetTraceResolver)); } } g_initialization; } @@ -76,7 +76,7 @@ public: uint32_t Add (Ptr node); NodeList::Iterator Begin (void); NodeList::Iterator End (void); - Ptr CreateTraceResolver (void); + Ptr GetTraceResolver (void); Ptr GetNode (uint32_t n); uint32_t GetNNodes (void); @@ -131,12 +131,11 @@ NodeListPriv::GetNode (uint32_t n) Ptr -NodeListPriv::CreateTraceResolver (void) +NodeListPriv::GetTraceResolver (void) { - Ptr, NodeListIndex> >resolver = - Create, NodeListIndex> > - (MakeCallback (&NodeListPriv::GetNNodes, this), - MakeCallback (&NodeListPriv::GetNode, this)); + Ptr >resolver = + Create > (); + resolver->SetIterators (Begin (), End ()); return resolver; } @@ -165,9 +164,9 @@ NodeList::End (void) return SimulationSingleton::Get ()->End (); } Ptr -NodeList::CreateTraceResolver (void) +NodeList::GetTraceResolver (void) { - return SimulationSingleton::Get ()->CreateTraceResolver (); + return SimulationSingleton::Get ()->GetTraceResolver (); } Ptr NodeList::GetNode (uint32_t n) diff --git a/src/node/node-list.h b/src/node/node-list.h index 66cd6965d..8af457b88 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -79,7 +79,7 @@ public: * \returns the requested trace resolver. The caller * takes ownership of the returned pointer. */ - static Ptr CreateTraceResolver (void); + static Ptr GetTraceResolver (void); /** * \param n index of requested node. diff --git a/src/node/node.cc b/src/node/node.cc index 554431db1..031ed34ab 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -25,7 +25,6 @@ #include "packet-socket-factory.h" #include "ns3/simulator.h" #include "ns3/composite-trace-resolver.h" -#include "ns3/array-trace-resolver.h" namespace ns3{ @@ -83,10 +82,11 @@ Node::~Node () {} Ptr -Node::CreateTraceResolver (void) +Node::GetTraceResolver (void) { Ptr resolver = Create (); - DoFillTraceResolver (*PeekPointer (resolver)); + resolver->AddArray ("devices", m_devices.begin (), m_devices.end (), NodeNetDeviceIndex ()); + resolver->SetParent (Object::GetTraceResolver ()); return resolver; } @@ -141,24 +141,6 @@ Node::GetNApplications (void) const return m_applications.size (); } -Ptr -Node::CreateDevicesTraceResolver (void) -{ - Ptr,NodeNetDeviceIndex> >resolver = - Create,NodeNetDeviceIndex> > - (MakeCallback (&Node::GetNDevices, this), - MakeCallback (&Node::GetDevice, this)); - - return resolver; -} - -void -Node::DoFillTraceResolver (CompositeTraceResolver &resolver) -{ - resolver.Add ("devices", - MakeCallback (&Node::CreateDevicesTraceResolver, this)); -} - void Node::DoDispose() { diff --git a/src/node/node.h b/src/node/node.h index 7931dd001..0066bf319 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -84,16 +84,6 @@ public: virtual ~Node(); - /** - * \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. - */ - Ptr CreateTraceResolver (void); - /** * \returns the unique id of this node. * @@ -182,23 +172,15 @@ public: void UnregisterProtocolHandler (ProtocolHandler handler); protected: + virtual Ptr GetTraceResolver (void); /** * 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); - /** - * \param resolver the resolver to store trace sources in. - * - * If a subclass wants to add new traces to a Node, it needs - * to override this method and record the new trace sources - * in the input resolver. Subclasses also _must_ chain up to - * their parent's DoFillTraceResolver method prior - * to recording they own trace sources. - */ - virtual void DoFillTraceResolver (CompositeTraceResolver &resolver); private: + /** * \param device the device added to this Node. * @@ -212,7 +194,6 @@ private: bool ReceiveFromDevice (Ptr device, const Packet &packet, uint16_t protocol, const Address &from); void Construct (void); - Ptr CreateDevicesTraceResolver (void); struct ProtocolHandlerEntry { ProtocolHandler handler; diff --git a/src/node/queue.cc b/src/node/queue.cc index 8a6725e4e..78ad9369c 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -95,12 +95,13 @@ Queue::~Queue() } Ptr -Queue::CreateTraceResolver (void) +Queue::GetTraceResolver (void) { Ptr resolver = Create (); resolver->Add ("enqueue", m_traceEnqueue, QueueTraceType (QueueTraceType::ENQUEUE)); resolver->Add ("dequeue", m_traceDequeue, QueueTraceType (QueueTraceType::DEQUEUE)); resolver->Add ("drop", m_traceDrop, QueueTraceType (QueueTraceType::DROP)); + resolver->SetParent (Object::GetTraceResolver ()); return resolver; } diff --git a/src/node/queue.h b/src/node/queue.h index bf2c6a2d6..c10795c67 100644 --- a/src/node/queue.h +++ b/src/node/queue.h @@ -69,8 +69,6 @@ public: Queue (); virtual ~Queue (); - - Ptr CreateTraceResolver (void); /** * \return true if the queue is empty; false otherwise @@ -167,6 +165,7 @@ private: virtual bool DoPeek (Packet &p) = 0; protected: + Ptr GetTraceResolver (void); // called by subclasses to notify parent of packet drops. void Drop (const Packet& p);