From c12d5a114277cfafc9cbc5d7d4385e71b9c9937a Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 10 May 2007 07:30:37 +0200 Subject: [PATCH] revert Ipv4Interface * -> Ptr --- src/internet-node/arp-cache.cc | 4 ++-- src/internet-node/arp-cache.h | 9 ++++----- src/internet-node/arp.cc | 6 +++--- src/internet-node/arp.h | 5 ++--- src/internet-node/i-ipv4-private.cc | 2 +- src/internet-node/i-ipv4-private.h | 3 +-- src/internet-node/ipv4-interface.h | 3 +-- src/internet-node/ipv4.cc | 30 ++++++++++++++--------------- src/internet-node/ipv4.h | 11 +++++------ src/node/node-list.cc | 9 ++++----- 10 files changed, 38 insertions(+), 44 deletions(-) diff --git a/src/internet-node/arp-cache.cc b/src/internet-node/arp-cache.cc index ff886f430..6a6f71bc9 100644 --- a/src/internet-node/arp-cache.cc +++ b/src/internet-node/arp-cache.cc @@ -28,7 +28,7 @@ namespace ns3 { -ArpCache::ArpCache (NetDevice *device, Ptr interface) +ArpCache::ArpCache (NetDevice *device, Ipv4Interface *interface) : m_device (device), m_interface (interface), m_aliveTimeout (Seconds (120)), @@ -50,7 +50,7 @@ ArpCache::PeekDevice (void) const return m_device; } -Ptr +Ipv4Interface * ArpCache::GetInterface (void) const { return m_interface; diff --git a/src/internet-node/arp-cache.h b/src/internet-node/arp-cache.h index 70c094154..5923d2ca9 100644 --- a/src/internet-node/arp-cache.h +++ b/src/internet-node/arp-cache.h @@ -28,22 +28,21 @@ #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, Ptr interface); + ArpCache (NetDevice *device, Ipv4Interface *interface); ~ArpCache (); NetDevice *PeekDevice (void) const; - Ptr GetInterface (void) const; + Ipv4Interface *GetInterface (void) const; void SetAliveTimeout (Time aliveTimeout); void SetDeadTimeout (Time deadTimeout); @@ -93,7 +92,7 @@ private: typedef sgi::hash_map::iterator CacheI; NetDevice *m_device; - Ptr m_interface; + Ipv4Interface *m_interface; Time m_aliveTimeout; Time m_deadTimeout; Time m_waitReplyTimeout; diff --git a/src/internet-node/arp.cc b/src/internet-node/arp.cc index 5fdd5d96b..8c702adf4 100644 --- a/src/internet-node/arp.cc +++ b/src/internet-node/arp.cc @@ -23,7 +23,6 @@ #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" @@ -37,10 +36,11 @@ namespace ns3 { const uint16_t Arp::PROT_NUMBER = 0x0806; - Arp::Arp (Ptr node) +Arp::Arp (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::iid); - Ptr interface = ipv4->FindInterfaceForDevice (device); + Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device); ipv4->Unref (); ArpCache * cache = new ArpCache (device, interface); NS_ASSERT (device->IsBroadcast ()); diff --git a/src/internet-node/arp.h b/src/internet-node/arp.h index 67d61dce1..ef909b2c8 100644 --- a/src/internet-node/arp.h +++ b/src/internet-node/arp.h @@ -25,7 +25,6 @@ #include "ns3/ipv4-address.h" #include "ns3/mac-address.h" #include "l3-protocol.h" -#include "ns3/ptr.h" namespace ns3 { @@ -41,7 +40,7 @@ class Arp : public L3Protocol public: static const uint16_t PROT_NUMBER; - Arp (Ptr node); + Arp (Node *node); ~Arp (); virtual TraceResolver *CreateTraceResolver (TraceContext const &context); @@ -58,7 +57,7 @@ private: void SendArpRequest (ArpCache const *cache, Ipv4Address to); void SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac); CacheList m_cacheList; - Ptr m_node; + Node *m_node; }; }//namespace ns3 diff --git a/src/internet-node/i-ipv4-private.cc b/src/internet-node/i-ipv4-private.cc index 7bc2ec609..2921d5262 100644 --- a/src/internet-node/i-ipv4-private.cc +++ b/src/internet-node/i-ipv4-private.cc @@ -47,7 +47,7 @@ IIpv4Private::Send (Packet const &packet, Ipv4Address source, { m_ipv4->Send (packet, source, destination, protocol); } -Ptr +Ipv4Interface * IIpv4Private::FindInterfaceForDevice (NetDevice const*device) { return m_ipv4->FindInterfaceForDevice (device); diff --git a/src/internet-node/i-ipv4-private.h b/src/internet-node/i-ipv4-private.h index e595f2f42..a300f725f 100644 --- a/src/internet-node/i-ipv4-private.h +++ b/src/internet-node/i-ipv4-private.h @@ -23,7 +23,6 @@ #include "ns3/ns-unknown.h" #include "ns3/ipv4-address.h" -#include "ns3/ptr.h" #include namespace ns3 { @@ -45,7 +44,7 @@ public: TraceResolver *CreateTraceResolver (TraceContext const &context); void Send (Packet const &packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol); - Ptr FindInterfaceForDevice (NetDevice const*device); + Ipv4Interface *FindInterfaceForDevice (NetDevice const*device); void Receive(Packet& p, NetDevice *device); protected: virtual void DoDispose (void); diff --git a/src/internet-node/ipv4-interface.h b/src/internet-node/ipv4-interface.h index ffee9f001..ef2b56408 100644 --- a/src/internet-node/ipv4-interface.h +++ b/src/internet-node/ipv4-interface.h @@ -25,7 +25,6 @@ #include #include "ns3/ipv4-address.h" -#include "ns3/object.h" namespace ns3 { @@ -62,7 +61,7 @@ class TraceContext; * - Ipv4Interface::SendTo * - Ipv4Interface::DoCreateTraceResolver */ -class Ipv4Interface : public Object +class Ipv4Interface { public: /** diff --git a/src/internet-node/ipv4.cc b/src/internet-node/ipv4.cc index c0567742c..d049edcd7 100644 --- a/src/internet-node/ipv4.cc +++ b/src/internet-node/ipv4.cc @@ -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) { - Ptr interface = new ArpIpv4Interface (m_node, device); + Ipv4Interface *interface = new ArpIpv4Interface (m_node, device); return AddIpv4Interface (interface); } uint32_t -Ipv4::AddIpv4Interface (Ptr interface) +Ipv4::AddIpv4Interface (Ipv4Interface *interface) { uint32_t index = m_nInterfaces; m_interfaces.push_back (interface); m_nInterfaces++; return index; } -Ptr +Ipv4Interface * Ipv4::GetInterface (uint32_t index) const { uint32_t tmp = 0; @@ -350,7 +350,7 @@ Ipv4::GetNInterfaces (void) const return m_nInterfaces; } -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); - Ptr outInterface = GetInterface (route.GetInterface ()); + 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++) { - Ptr interface = *i; + 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) { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); interface->SetAddress (address); } void Ipv4::SetNetworkMask (uint32_t i, Ipv4Mask mask) { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); interface->SetNetworkMask (mask); } Ipv4Mask Ipv4::GetNetworkMask (uint32_t i) const { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); return interface->GetNetworkMask (); } Ipv4Address Ipv4::GetAddress (uint32_t i) const { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); return interface->GetAddress (); } uint16_t Ipv4::GetMtu (uint32_t i) const { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); return interface->GetMtu (); } bool Ipv4::IsUp (uint32_t i) const { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); return interface->IsUp (); } void Ipv4::SetUp (uint32_t i) { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); interface->SetUp (); } void Ipv4::SetDown (uint32_t i) { - Ptr interface = GetInterface (i); + Ipv4Interface *interface = GetInterface (i); interface->SetDown (); } diff --git a/src/internet-node/ipv4.h b/src/internet-node/ipv4.h index b84d9005f..84b63bf95 100644 --- a/src/internet-node/ipv4.h +++ b/src/internet-node/ipv4.h @@ -28,13 +28,12 @@ #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; @@ -170,7 +169,7 @@ public: * \param i index of interface to return * \returns the requested interface */ - Ptr GetInterface (uint32_t i) const; + Ipv4Interface * GetInterface (uint32_t i) const; /** * \returns the number of interfaces added by the user. */ @@ -182,7 +181,7 @@ public: * Try to find an Ipv4Interface whose NetDevice is equal to * the input NetDevice. */ - Ptr FindInterfaceForDevice (NetDevice const*device); + Ipv4Interface *FindInterfaceForDevice (NetDevice const*device); /** @@ -222,11 +221,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 (Ptr interface); + uint32_t AddIpv4Interface (Ipv4Interface *interface); void SetupLoopback (void); TraceResolver *InterfacesCreateTraceResolver (TraceContext const &context) const; - typedef std::list > Ipv4InterfaceList; + typedef std::list Ipv4InterfaceList; typedef std::list HostRoutes; typedef std::list::const_iterator HostRoutesCI; typedef std::list::iterator HostRoutesI; diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 889117ea3..d9640136a 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -53,7 +53,7 @@ public: NodeList::Iterator Begin (void); NodeList::Iterator End (void); TraceResolver *CreateTraceResolver (TraceContext const &context); - Ptr PeekNode (uint32_t n); + Node *PeekNode (uint32_t n); uint32_t GetNNodes (void); private: @@ -69,7 +69,7 @@ NodeListPriv::~NodeListPriv () { Ptr node = *i; node->Dispose (); - //node->Unref (); + *i = 0; } m_nodes.erase (m_nodes.begin (), m_nodes.end ()); } @@ -79,7 +79,6 @@ uint32_t NodeListPriv::Add (Ptr node) { uint32_t index = m_nodes.size (); - //node->Ref (); m_nodes.push_back (node); return index; @@ -99,10 +98,10 @@ NodeListPriv::GetNNodes (void) { return m_nodes.size (); } -Ptr +Node * NodeListPriv::PeekNode (uint32_t n) { - return m_nodes[n]; + return m_nodes[n].Peek (); } TraceResolver *