From b4810cc153a7978281b7bc3d8b46d60b77d99bf1 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 3 May 2007 14:39:37 +0200 Subject: [PATCH] remove Node::GetArp --- SConstruct | 2 ++ src/node/arp-ipv4-interface.cc | 4 +-- src/node/i-arp-private.cc | 58 ++++++++++++++++++++++++++++++++++ src/node/i-arp-private.h | 51 ++++++++++++++++++++++++++++++ src/node/internet-node.cc | 21 +++--------- src/node/internet-node.h | 2 -- src/node/node.cc | 6 ---- src/node/node.h | 2 -- 8 files changed, 117 insertions(+), 29 deletions(-) create mode 100644 src/node/i-arp-private.cc create mode 100644 src/node/i-arp-private.h diff --git a/SConstruct b/SConstruct index 6d83d47ad..654f42176 100644 --- a/SConstruct +++ b/SConstruct @@ -223,6 +223,7 @@ node.add_sources ([ 'ipv4-end-point-demux.cc', 'i-udp.cc', 'i-udp-impl.cc', + 'i-arp-private.cc', ]) node.add_headers ([ 'ipv4-header.h', @@ -243,6 +244,7 @@ node.add_headers ([ 'udp-socket.h', 'i-udp-impl.h', 'udp.h', + 'i-arp-private.h', ]) node.add_inst_headers ([ 'node.h', diff --git a/src/node/arp-ipv4-interface.cc b/src/node/arp-ipv4-interface.cc index 71c8165ae..20c0360a3 100644 --- a/src/node/arp-ipv4-interface.cc +++ b/src/node/arp-ipv4-interface.cc @@ -24,7 +24,7 @@ #include "ns3/composite-trace-resolver.h" #include "arp-ipv4-interface.h" -#include "arp.h" +#include "i-arp-private.h" #include "node.h" #include "net-device.h" #include "ipv4.h" @@ -62,7 +62,7 @@ ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest) NS_ASSERT (PeekDevice () != 0); if (PeekDevice ()->NeedsArp ()) { - Arp * arp = m_node->GetArp (); + IArpPrivate * arp = m_node->QueryInterface (IArpPrivate::iid); MacAddress hardwareDestination; bool found = arp->Lookup (p, dest, PeekDevice (), &hardwareDestination); if (found) diff --git a/src/node/i-arp-private.cc b/src/node/i-arp-private.cc new file mode 100644 index 000000000..574a10b8a --- /dev/null +++ b/src/node/i-arp-private.cc @@ -0,0 +1,58 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ +#include "i-arp-private.h" +#include "ns3/iid-manager.h" +#include "arp.h" +#include "ns3/assert.h" + +namespace ns3 { + +const uint32_t IArpPrivate::iid = IidManager::Allocate ("IArpPrivate"); + +IArpPrivate::IArpPrivate (Arp *arp) + : NsUnknown (IArpPrivate::iid), + m_arp (arp) +{ + m_arp->Ref (); +} +IArpPrivate::~IArpPrivate () +{ + NS_ASSERT (m_arp == 0); +} + +bool +IArpPrivate::Lookup (Packet &p, Ipv4Address destination, + NetDevice *device, + MacAddress *hardwareDestination) +{ + return m_arp->Lookup (p, destination, device, hardwareDestination); +} + +void +IArpPrivate::DoDispose (void) +{ + m_arp->Unref (); + m_arp = 0; + NsUnknown::DoDispose (); +} + + +} // namespace ns3 diff --git a/src/node/i-arp-private.h b/src/node/i-arp-private.h new file mode 100644 index 000000000..4d8641d15 --- /dev/null +++ b/src/node/i-arp-private.h @@ -0,0 +1,51 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ +#ifndef I_ARP_PRIVATE_H +#define I_ARP_PRIVATE_H + +#include "ns3/ns-unknown.h" +#include "ipv4-address.h" + +namespace ns3 { + +class NetDevice; +class MacAddress; +class Packet; +class Arp; + +class IArpPrivate : public NsUnknown +{ +public: + static const uint32_t iid; + IArpPrivate (Arp *arp); + virtual ~IArpPrivate (); + bool Lookup (Packet &p, Ipv4Address destination, + NetDevice *device, + MacAddress *hardwareDestination); +protected: + virtual void DoDispose (void); +private: + Arp *m_arp; +}; + +} // namespace ns3 + +#endif /* I_ARP_PRIVATE_H */ diff --git a/src/node/internet-node.cc b/src/node/internet-node.cc index aefa220a5..1263be6ba 100644 --- a/src/node/internet-node.cc +++ b/src/node/internet-node.cc @@ -32,6 +32,7 @@ #include "arp.h" #include "net-device.h" #include "i-udp-impl.h" +#include "i-arp-private.h" namespace ns3 { @@ -42,8 +43,6 @@ InternetNode::InternetNode() Arp *arp = new Arp (this); Udp *udp = new Udp (this); - - // Instantiate the capabilities ApplicationList *applicationList = new ApplicationList(this); L3Demux *l3Demux = new L3Demux(this); Ipv4L4Demux *ipv4L4Demux = new Ipv4L4Demux(this); @@ -53,7 +52,9 @@ InternetNode::InternetNode() ipv4L4Demux->Insert (udp); IUdpImpl *udpImpl = new IUdpImpl (udp); + IArpPrivate *arpPrivate = new IArpPrivate (arp); + NsUnknown::AddInterface (arpPrivate); NsUnknown::AddInterface (udpImpl); NsUnknown::AddInterface (applicationList); NsUnknown::AddInterface (l3Demux); @@ -67,6 +68,7 @@ InternetNode::InternetNode() arp->Unref (); udp->Unref (); udpImpl->Unref (); + arpPrivate->Unref (); } InternetNode::~InternetNode () @@ -88,11 +90,6 @@ InternetNode::CreateTraceResolver (TraceContext const &context) InternetNode::IPV4); ipv4->Unref (); - Arp *arp = GetArp (); - resolver->Add ("arp", - MakeCallback (&Arp::CreateTraceResolver, arp), - InternetNode::ARP); - arp->Unref (); return resolver; } @@ -113,16 +110,6 @@ InternetNode::GetIpv4 (void) const return ipv4; } -Arp * -InternetNode::GetArp (void) const -{ - L3Demux *l3Demux = QueryInterface (L3Demux::iid); - Arp *arp = static_cast (l3Demux->PeekProtocol (Arp::PROT_NUMBER)); - l3Demux->Unref (); - arp->Ref (); - return arp; -} - void InternetNode::DoAddDevice (NetDevice *device) const { diff --git a/src/node/internet-node.h b/src/node/internet-node.h index 45ef3de39..bf33032d0 100644 --- a/src/node/internet-node.h +++ b/src/node/internet-node.h @@ -38,14 +38,12 @@ class InternetNode : public Node public: enum TraceType { IPV4, - ARP, }; InternetNode(); virtual ~InternetNode (); virtual TraceResolver *CreateTraceResolver (TraceContext const &context); // Capability access virtual Ipv4 * GetIpv4 (void) const; - virtual Arp * GetArp (void) const; void SetName(std::string name); protected: diff --git a/src/node/node.cc b/src/node/node.cc index d48e84732..930bd5e58 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -108,10 +108,4 @@ Node::GetIpv4 (void) const return 0; } -Arp * -Node::GetArp (void) const -{ - return 0; -} - }//namespace ns3 diff --git a/src/node/node.h b/src/node/node.h index c15ff577f..b48762f29 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -32,7 +32,6 @@ namespace ns3 { class Ipv4; -class Arp; class TraceContext; class TraceResolver; @@ -71,7 +70,6 @@ public: // of the correct type if one exists, or the nil pointer if no // null capability exists. virtual Ipv4 * GetIpv4 (void) const; - virtual Arp * GetArp (void) const; private: uint32_t m_id; // Node id for this node