some Ipv4Interface* -> Ptr<Ipv4Interface>, and unhack arraytraceresolver, still segfaults
authorRaj@rajib-bhattacharjeas-computer.local
Wed, 09 May 2007 23:23:05 -0400
changeset 548 85c56883f1c6
parent 547 fc6c84abb832
child 549 e973db5b60ac
some Ipv4Interface* -> Ptr<Ipv4Interface>, and unhack arraytraceresolver, still segfaults
src/common/array-trace-resolver.h
src/internet-node/arp-cache.cc
src/internet-node/arp-cache.h
src/internet-node/arp.cc
src/internet-node/arp.h
src/internet-node/i-ipv4-private.cc
src/internet-node/i-ipv4-private.h
src/internet-node/ipv4-interface.h
src/internet-node/ipv4.cc
src/internet-node/ipv4.h
--- a/src/common/array-trace-resolver.h	Wed May 09 19:48:33 2007 +0200
+++ b/src/common/array-trace-resolver.h	Wed May 09 23:23:05 2007 -0400
@@ -82,15 +82,11 @@
    */
   ArrayTraceResolver (TraceContext const &context,
                       Callback<uint32_t> getSize, 
-                      Callback<T *, uint32_t> get);
-  ArrayTraceResolver (TraceContext const &context,
-                      Callback<uint32_t> getSize, 
                       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_get2;
+  Callback<Ptr<T>, uint32_t> m_get;
 };
 }//namespace ns3
 
@@ -113,35 +109,26 @@
 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)
 {}
 template <typename T>
-ArrayTraceResolver<T>::ArrayTraceResolver (TraceContext const &context,
-                                                   Callback<uint32_t> getSize, 
-						   Callback<Ptr<T>, uint32_t> get)
-  : TraceResolver (context),
-    m_getSize (getSize),
-    m_get2 (get)
-{}
-template <typename T>
 TraceResolver::TraceResolverList 
 ArrayTraceResolver<T>::DoLookup (std::string id) const
 {
   TraceResolverList list;
   if (id == "*")
+  {
+    for (uint32_t i = 0; i < m_getSize (); i++)
     {
-      for (uint32_t i = 0; i < m_getSize (); i++)
-	{
 	  TraceContext context = GetContext ();
-          typename ArrayTraceResolver<T>::Index index = typename ArrayTraceResolver<T>::Index (i);
+      typename ArrayTraceResolver<T>::Index index = typename ArrayTraceResolver<T>::Index (i);
 	  context.Add (index);
 	  list.push_back (m_get (i)->CreateTraceResolver (context));
-
-	}
     }
+  }
   return list;
 }
 
--- a/src/internet-node/arp-cache.cc	Wed May 09 19:48:33 2007 +0200
+++ b/src/internet-node/arp-cache.cc	Wed May 09 23:23:05 2007 -0400
@@ -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 @@
   return m_device;
 }
 
-Ipv4Interface *
+Ptr<Ipv4Interface>
 ArpCache::GetInterface (void) const
 {
   return m_interface;
--- a/src/internet-node/arp-cache.h	Wed May 09 19:48:33 2007 +0200
+++ b/src/internet-node/arp-cache.h	Wed May 09 23:23:05 2007 -0400
@@ -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 @@
   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;
--- a/src/internet-node/arp.cc	Wed May 09 19:48:33 2007 +0200
+++ b/src/internet-node/arp.cc	Wed May 09 23:23:05 2007 -0400
@@ -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 @@
 
 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 @@
 	}
     }
   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 ());
--- a/src/internet-node/arp.h	Wed May 09 19:48:33 2007 +0200
+++ b/src/internet-node/arp.h	Wed May 09 23:23:05 2007 -0400
@@ -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 @@
 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 @@
   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
--- a/src/internet-node/i-ipv4-private.cc	Wed May 09 19:48:33 2007 +0200
+++ b/src/internet-node/i-ipv4-private.cc	Wed May 09 23:23:05 2007 -0400
@@ -47,7 +47,7 @@
 {
   m_ipv4->Send (packet, source, destination, protocol);
 }
-Ipv4Interface *
+Ptr<Ipv4Interface>
 IIpv4Private::FindInterfaceForDevice (NetDevice const*device)
 {
   return m_ipv4->FindInterfaceForDevice (device);
--- a/src/internet-node/i-ipv4-private.h	Wed May 09 19:48:33 2007 +0200
+++ b/src/internet-node/i-ipv4-private.h	Wed May 09 23:23:05 2007 -0400
@@ -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 @@
   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);
--- a/src/internet-node/ipv4-interface.h	Wed May 09 19:48:33 2007 +0200
+++ b/src/internet-node/ipv4-interface.h	Wed May 09 23:23:05 2007 -0400
@@ -25,6 +25,7 @@
 
 #include <list>
 #include "ns3/ipv4-address.h"
+#include "ns3/object.h"
 
 namespace ns3 {
 
@@ -61,7 +62,7 @@
  *   - Ipv4Interface::SendTo
  *   - Ipv4Interface::DoCreateTraceResolver
  */
-class Ipv4Interface 
+class Ipv4Interface : public Object
 {
 public:
   /**
--- a/src/internet-node/ipv4.cc	Wed May 09 19:48:33 2007 +0200
+++ b/src/internet-node/ipv4.cc	Wed May 09 23:23:05 2007 -0400
@@ -63,7 +63,7 @@
 {
   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 @@
 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 @@
   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 @@
 {
   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 @@
   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 @@
 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 ();
 }
 
--- a/src/internet-node/ipv4.h	Wed May 09 19:48:33 2007 +0200
+++ b/src/internet-node/ipv4.h	Wed May 09 23:23:05 2007 -0400
@@ -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 @@
    * \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 @@
    * 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 @@
   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;