From 4f05b2b2fc09fc86b4e31ef44ff48bfe0c6baa2d Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 3 May 2007 15:24:34 +0200 Subject: [PATCH] remove Node::GetIpv4 --- SConstruct | 18 ++-- examples/simple-p2p.cc | 8 +- src/devices/p2p/p2p-topology.cc | 6 +- src/node/arp.cc | 4 +- src/node/i-ipv4-impl.cc | 144 ++++++++++++++++++++++++++++ src/node/i-ipv4-impl.h | 73 ++++++++++++++ src/node/i-ipv4-private.cc | 69 +++++++++++++ src/node/i-ipv4-private.h | 57 +++++++++++ src/node/i-ipv4.cc | 35 +++++++ src/node/i-ipv4.h | 138 ++++++++++++++++++++++++++ src/node/internet-node.cc | 25 +++-- src/node/internet-node.h | 3 - src/node/ipv4-loopback-interface.cc | 4 +- src/node/node.cc | 6 -- src/node/node.h | 13 --- src/node/udp.cc | 3 +- 16 files changed, 552 insertions(+), 54 deletions(-) create mode 100644 src/node/i-ipv4-impl.cc create mode 100644 src/node/i-ipv4-impl.h create mode 100644 src/node/i-ipv4-private.cc create mode 100644 src/node/i-ipv4-private.h create mode 100644 src/node/i-ipv4.cc create mode 100644 src/node/i-ipv4.h diff --git a/SConstruct b/SConstruct index 654f42176..c7c1fb3e1 100644 --- a/SConstruct +++ b/SConstruct @@ -224,6 +224,9 @@ node.add_sources ([ 'i-udp.cc', 'i-udp-impl.cc', 'i-arp-private.cc', + 'i-ipv4.cc', + 'i-ipv4-impl.cc', + 'i-ipv4-private.cc', ]) node.add_headers ([ 'ipv4-header.h', @@ -245,6 +248,14 @@ node.add_headers ([ 'i-udp-impl.h', 'udp.h', 'i-arp-private.h', + 'i-ipv4-impl.h', + 'i-ipv4-private.h', + 'ipv4.h', + 'l3-protocol.h', + 'ipv4-l4-protocol.h', + 'ipv4-l4-demux.h', + 'ipv4-end-point-demux.h', + 'ipv4-end-point.h', ]) node.add_inst_headers ([ 'node.h', @@ -253,8 +264,6 @@ node.add_inst_headers ([ 'net-device.h', 'ipv4-interface.h', 'mac-address.h', - 'ipv4.h', - 'l3-protocol.h', 'ipv4-route.h', 'queue.h', 'drop-tail.h', @@ -269,12 +278,9 @@ node.add_inst_headers ([ 'onoff-application.h', 'ascii-trace.h', 'socket.h', - 'ipv4-l4-protocol.h', - 'ipv4-l4-demux.h', - 'ipv4-end-point-demux.h', - 'ipv4-end-point.h', 'pcap-trace.h', 'i-udp.h', + 'i-ipv4.h', ]) p2p = build.Ns3Module ('p2p', 'src/devices/p2p') diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index 6b47212da..8adafb2a7 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -55,7 +55,7 @@ #include "ns3/p2p-net-device.h" #include "ns3/mac-address.h" #include "ns3/ipv4-address.h" -#include "ns3/ipv4.h" +#include "ns3/i-ipv4.h" #include "ns3/socket.h" #include "ns3/ipv4-route.h" #include "ns3/drop-tail.h" @@ -153,11 +153,11 @@ int main (int argc, char *argv[]) // Here, finish off packet routing configuration // This will likely set by some global StaticRouting object in the future - Ipv4 *ipv4; - ipv4 = n0->GetIpv4(); + IIpv4 *ipv4; + ipv4 = n0->QueryInterface (IIpv4::iid); ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); ipv4->Unref (); - ipv4 = n3->GetIpv4(); + ipv4 = n3->QueryInterface (IIpv4::iid); ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1); ipv4->Unref (); diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index 51b7c8c64..dfe442d81 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -30,7 +30,7 @@ #include "ns3/internet-node.h" #include "ns3/ipv4-address.h" #include "ns3/drop-tail.h" -#include "ns3/ipv4.h" +#include "ns3/i-ipv4.h" #include "p2p-channel.h" #include "p2p-net-device.h" @@ -60,7 +60,7 @@ PointToPointTopology::AddPointToPointLink( PointToPointNetDevice* net1 = new PointToPointNetDevice(n1); net1->AddQueue(Queue::Default().Copy()); n1->AddDevice (net1); - Ipv4 *ip1 = n1->GetIpv4 (); + IIpv4 *ip1 = n1->QueryInterface (IIpv4::iid); uint32_t index1 = ip1->AddInterface (net1); net1->Attach (channel); net1->Unref (); @@ -72,7 +72,7 @@ PointToPointTopology::AddPointToPointLink( PointToPointNetDevice* net2 = new PointToPointNetDevice(n2); net2->AddQueue(Queue::Default().Copy()); n2->AddDevice (net2); - Ipv4 *ip2 = n2->GetIpv4 (); + IIpv4 *ip2 = n2->QueryInterface (IIpv4::iid); uint32_t index2 = ip2->AddInterface (net2); net2->Attach (channel); net2->Unref (); diff --git a/src/node/arp.cc b/src/node/arp.cc index af7d7e456..e6d951b61 100644 --- a/src/node/arp.cc +++ b/src/node/arp.cc @@ -27,7 +27,7 @@ #include "net-device.h" #include "ipv4-interface.h" #include "node.h" -#include "ipv4.h" +#include "i-ipv4-private.h" NS_DEBUG_COMPONENT_DEFINE ("Arp"); @@ -79,7 +79,7 @@ Arp::FindCache (NetDevice *device) return *i; } } - Ipv4 *ipv4 = m_node->GetIpv4 (); + IIpv4Private *ipv4 = m_node->QueryInterface (IIpv4Private::iid); Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device); ipv4->Unref (); ArpCache * cache = new ArpCache (device, interface); diff --git a/src/node/i-ipv4-impl.cc b/src/node/i-ipv4-impl.cc new file mode 100644 index 000000000..82b5d0155 --- /dev/null +++ b/src/node/i-ipv4-impl.cc @@ -0,0 +1,144 @@ +/* -*- 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-ipv4-impl.h" +#include "ipv4.h" +#include "ns3/assert.h" + +namespace ns3 { + +IIpv4Impl::IIpv4Impl (Ipv4 *ipv4) + : m_ipv4 (ipv4) +{ + m_ipv4->Ref (); +} +IIpv4Impl::~IIpv4Impl () +{ + NS_ASSERT (m_ipv4 == 0); +} +void +IIpv4Impl::DoDispose (void) +{ + m_ipv4->Unref (); + m_ipv4 = 0; +} + +void +IIpv4Impl::AddHostRouteTo (Ipv4Address dest, + Ipv4Address nextHop, + uint32_t interface) +{ + m_ipv4->AddHostRouteTo (dest, nextHop, interface); +} +void +IIpv4Impl::AddHostRouteTo (Ipv4Address dest, + uint32_t interface) +{ + m_ipv4->AddHostRouteTo (dest, interface); +} +void +IIpv4Impl::AddNetworkRouteTo (Ipv4Address network, + Ipv4Mask networkMask, + Ipv4Address nextHop, + uint32_t interface) +{ + m_ipv4->AddNetworkRouteTo (network, networkMask, nextHop, interface); +} +void +IIpv4Impl::AddNetworkRouteTo (Ipv4Address network, + Ipv4Mask networkMask, + uint32_t interface) +{ + m_ipv4->AddNetworkRouteTo (network, networkMask, interface); +} +void +IIpv4Impl::SetDefaultRoute (Ipv4Address nextHop, + uint32_t interface) +{ + m_ipv4->SetDefaultRoute (nextHop, interface); +} +uint32_t +IIpv4Impl::GetNRoutes (void) +{ + return m_ipv4->GetNRoutes (); +} +Ipv4Route * +IIpv4Impl::GetRoute (uint32_t i) +{ + return m_ipv4->GetRoute (i); +} +void +IIpv4Impl::RemoveRoute (uint32_t i) +{ + return m_ipv4->RemoveRoute (i); +} +uint32_t +IIpv4Impl::AddInterface (NetDevice *device) +{ + return m_ipv4->AddInterface (device); +} +uint32_t +IIpv4Impl::GetNInterfaces (void) +{ + return m_ipv4->GetNInterfaces (); +} + +void +IIpv4Impl::SetAddress (uint32_t i, Ipv4Address address) +{ + m_ipv4->SetAddress (i, address); +} +void +IIpv4Impl::SetNetworkMask (uint32_t i, Ipv4Mask mask) +{ + m_ipv4->SetNetworkMask (i, mask); +} +Ipv4Mask +IIpv4Impl::GetNetworkMask (uint32_t i) const +{ + return m_ipv4->GetNetworkMask (i); +} +Ipv4Address +IIpv4Impl::GetAddress (uint32_t i) const +{ + return m_ipv4->GetAddress (i); +} +uint16_t +IIpv4Impl::GetMtu (uint32_t i) const +{ + return m_ipv4->GetMtu (i); +} +bool +IIpv4Impl::IsUp (uint32_t i) const +{ + return m_ipv4->IsUp (i); +} +void +IIpv4Impl::SetUp (uint32_t i) +{ + m_ipv4->SetUp (i); +} +void +IIpv4Impl::SetDown (uint32_t i) +{ + m_ipv4->SetDown (i); +} + +}//namespace ns3 diff --git a/src/node/i-ipv4-impl.h b/src/node/i-ipv4-impl.h new file mode 100644 index 000000000..2ab427422 --- /dev/null +++ b/src/node/i-ipv4-impl.h @@ -0,0 +1,73 @@ +/* -*- 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_IPV4_IMPL_H +#define I_IPV4_IMPL_H + +#include "i-ipv4.h" + +namespace ns3 { + +class Ipv4; + +class IIpv4Impl : public IIpv4 +{ +public: + IIpv4Impl (Ipv4 *ipv4); + + virtual ~IIpv4Impl (); + + virtual void AddHostRouteTo (Ipv4Address dest, + Ipv4Address nextHop, + uint32_t interface); + virtual void AddHostRouteTo (Ipv4Address dest, + uint32_t interface); + virtual void AddNetworkRouteTo (Ipv4Address network, + Ipv4Mask networkMask, + Ipv4Address nextHop, + uint32_t interface); + virtual void AddNetworkRouteTo (Ipv4Address network, + Ipv4Mask networkMask, + uint32_t interface); + virtual void SetDefaultRoute (Ipv4Address nextHop, + uint32_t interface); + virtual uint32_t GetNRoutes (void); + virtual Ipv4Route *GetRoute (uint32_t i); + virtual void RemoveRoute (uint32_t i); + virtual uint32_t AddInterface (NetDevice *device); + virtual uint32_t GetNInterfaces (void); + + virtual void SetAddress (uint32_t i, Ipv4Address address); + virtual void SetNetworkMask (uint32_t i, Ipv4Mask mask); + virtual Ipv4Mask GetNetworkMask (uint32_t t) const; + virtual Ipv4Address GetAddress (uint32_t i) const; + virtual uint16_t GetMtu (uint32_t i) const; + virtual bool IsUp (uint32_t i) const; + virtual void SetUp (uint32_t i); + virtual void SetDown (uint32_t i); +protected: + virtual void DoDispose (void); +private: + Ipv4 *m_ipv4; +}; + +} // namespace ns3 + +#endif /* I_IPV4_IMPL_H */ diff --git a/src/node/i-ipv4-private.cc b/src/node/i-ipv4-private.cc new file mode 100644 index 000000000..33d62094b --- /dev/null +++ b/src/node/i-ipv4-private.cc @@ -0,0 +1,69 @@ +/* -*- 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-ipv4-private.h" +#include "ipv4.h" +#include "ns3/assert.h" +#include "ns3/iid-manager.h" + +namespace ns3 { + +const uint32_t IIpv4Private::iid = IidManager::Allocate ("IIpv4Private"); + +IIpv4Private::IIpv4Private (Ipv4 *ipv4) + : NsUnknown (IIpv4Private::iid), + m_ipv4 (ipv4) +{ + m_ipv4->Ref (); +} +IIpv4Private::~IIpv4Private () +{ + NS_ASSERT (m_ipv4 == 0); +} +TraceResolver * +IIpv4Private::CreateTraceResolver (TraceContext const &context) +{ + return m_ipv4->CreateTraceResolver (context); +} +void +IIpv4Private::Send (Packet const &packet, Ipv4Address source, + Ipv4Address destination, uint8_t protocol) +{ + m_ipv4->Send (packet, source, destination, protocol); +} +Ipv4Interface * +IIpv4Private::FindInterfaceForDevice (NetDevice const*device) +{ + return m_ipv4->FindInterfaceForDevice (device); +} +void +IIpv4Private::Receive(Packet& p, NetDevice *device) +{ + m_ipv4->Receive (p, device); +} +void +IIpv4Private::DoDispose (void) +{ + m_ipv4->Unref (); + m_ipv4 = 0; + NsUnknown::DoDispose (); +} + +} // namespace ns3 diff --git a/src/node/i-ipv4-private.h b/src/node/i-ipv4-private.h new file mode 100644 index 000000000..4a7775625 --- /dev/null +++ b/src/node/i-ipv4-private.h @@ -0,0 +1,57 @@ +/* -*- 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_IPV4_PRIVATE_H +#define I_IPV4_PRIVATE_H + +#include "ns3/ns-unknown.h" +#include "ns3/ipv4-address.h" +#include + +namespace ns3 { + +class Packet; +class Ipv4; +class TraceContext; +class TraceResolver; +class Ipv4Interface; +class NetDevice; + +class IIpv4Private : public NsUnknown +{ +public: + static const uint32_t iid; + IIpv4Private (Ipv4 *ipv4); + virtual ~IIpv4Private (); + + TraceResolver *CreateTraceResolver (TraceContext const &context); + void Send (Packet const &packet, Ipv4Address source, + Ipv4Address destination, uint8_t protocol); + Ipv4Interface *FindInterfaceForDevice (NetDevice const*device); + void Receive(Packet& p, NetDevice *device); +protected: + virtual void DoDispose (void); +private: + Ipv4 *m_ipv4; +}; + +} // namespace ns3 + +#endif /* I_IPV4_PRIVATE_H */ diff --git a/src/node/i-ipv4.cc b/src/node/i-ipv4.cc new file mode 100644 index 000000000..f385d91ce --- /dev/null +++ b/src/node/i-ipv4.cc @@ -0,0 +1,35 @@ +/* -*- 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-ipv4.h" +#include "ns3/iid-manager.h" + +namespace ns3 { + +const uint32_t IIpv4::iid = IidManager::Allocate ("IIpv4"); + +IIpv4::IIpv4 () + : NsUnknown (IIpv4::iid) +{} + +IIpv4::~IIpv4 () +{} + +} // namespace ns3 diff --git a/src/node/i-ipv4.h b/src/node/i-ipv4.h new file mode 100644 index 000000000..0acb4a4e0 --- /dev/null +++ b/src/node/i-ipv4.h @@ -0,0 +1,138 @@ +/* -*- 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_IPV4_H +#define I_IPV4_H + +#include +#include "ns3/ipv4-address.h" +#include "ns3/ns-unknown.h" + +namespace ns3 { + +class NetDevice; +class Packet; +class Ipv4Route; + +class IIpv4 : public NsUnknown +{ +public: + static const uint32_t iid; + IIpv4 (); + virtual ~IIpv4 (); + + /** + * \param dest destination address + * \param nextHop address of next hop. + * \param interface interface of next hop. + * + * add route to host dest through host nextHop + * on interface. + */ + virtual void AddHostRouteTo (Ipv4Address dest, + Ipv4Address nextHop, + uint32_t interface) = 0; + /** + * \param dest destination address + * \param interface of next hop + * + * add route to host dest on interface. + */ + virtual void AddHostRouteTo (Ipv4Address dest, + uint32_t interface) = 0; + + /** + * \param network destination network + * \param networkMask netmask of destination network + * \param nextHop address of next hop + * \param interface interface of next hop + * + * add route to network dest with netmask + * through host nextHop on interface + */ + virtual void AddNetworkRouteTo (Ipv4Address network, + Ipv4Mask networkMask, + Ipv4Address nextHop, + uint32_t interface) = 0; + + /** + * \param network destination network + * \param networkMask netmask of destination network + * \param interface interface of next hop + * + * add route to network dest with netmask + * on interface + */ + virtual void AddNetworkRouteTo (Ipv4Address network, + Ipv4Mask networkMask, + uint32_t interface) = 0; + /** + * \param nextHop address of default next hop + * \param interface interface of default next hop. + * + * set the default route to host nextHop on + * interface. + */ + virtual void SetDefaultRoute (Ipv4Address nextHop, + uint32_t interface) = 0; + + /** + * \returns the number of entries in the routing table. + */ + virtual uint32_t GetNRoutes (void) = 0; + /** + * \param i index of route to return + * \returns the route whose index is i + */ + virtual Ipv4Route *GetRoute (uint32_t i) = 0; + /** + * \param i index of route to remove from routing table. + */ + virtual void RemoveRoute (uint32_t i) = 0; + + /** + * \param interface interface to add to the list of ipv4 interfaces + * which can be used as output interfaces during packet forwarding. + * \returns the index of the interface added. + * + * Once an interface has been added, it can never be removed: if you want + * to disable it, you can invoke Ipv4Interface::SetDown which will + * make sure that it is never used during packet forwarding. + */ + virtual uint32_t AddInterface (NetDevice *device) = 0; + /** + * \returns the number of interfaces added by the user. + */ + virtual uint32_t GetNInterfaces (void) = 0; + + virtual void SetAddress (uint32_t i, Ipv4Address address) = 0; + virtual void SetNetworkMask (uint32_t i, Ipv4Mask mask) = 0; + virtual Ipv4Mask GetNetworkMask (uint32_t t) const = 0; + virtual Ipv4Address GetAddress (uint32_t i) const = 0; + virtual uint16_t GetMtu (uint32_t i) const = 0; + virtual bool IsUp (uint32_t i) const = 0; + virtual void SetUp (uint32_t i) = 0; + virtual void SetDown (uint32_t i) = 0; + +}; + +} // namespace ns3 + +#endif /* I_IPV4_H */ diff --git a/src/node/internet-node.cc b/src/node/internet-node.cc index 1263be6ba..fe33d6421 100644 --- a/src/node/internet-node.cc +++ b/src/node/internet-node.cc @@ -33,6 +33,8 @@ #include "net-device.h" #include "i-udp-impl.h" #include "i-arp-private.h" +#include "i-ipv4-impl.h" +#include "i-ipv4-private.h" namespace ns3 { @@ -53,7 +55,11 @@ InternetNode::InternetNode() IUdpImpl *udpImpl = new IUdpImpl (udp); IArpPrivate *arpPrivate = new IArpPrivate (arp); + IIpv4Impl *ipv4Impl = new IIpv4Impl (ipv4); + IIpv4Private *ipv4Private = new IIpv4Private (ipv4); + NsUnknown::AddInterface (ipv4Private); + NsUnknown::AddInterface (ipv4Impl); NsUnknown::AddInterface (arpPrivate); NsUnknown::AddInterface (udpImpl); NsUnknown::AddInterface (applicationList); @@ -64,11 +70,13 @@ InternetNode::InternetNode() applicationList->Unref (); l3Demux->Unref (); ipv4L4Demux->Unref (); - ipv4->Unref (); arp->Unref (); + ipv4->Unref (); udp->Unref (); udpImpl->Unref (); arpPrivate->Unref (); + ipv4Impl->Unref (); + ipv4Private->Unref (); } InternetNode::~InternetNode () @@ -84,13 +92,12 @@ TraceResolver * InternetNode::CreateTraceResolver (TraceContext const &context) { CompositeTraceResolver *resolver = new CompositeTraceResolver (context); - Ipv4 *ipv4 = GetIpv4 (); + IIpv4Private *ipv4 = QueryInterface (IIpv4Private::iid); resolver->Add ("ipv4", - MakeCallback (&Ipv4::CreateTraceResolver, ipv4), + MakeCallback (&IIpv4Private::CreateTraceResolver, ipv4), InternetNode::IPV4); ipv4->Unref (); - return resolver; } @@ -100,16 +107,6 @@ InternetNode::DoDispose() Node::DoDispose (); } -Ipv4 * -InternetNode::GetIpv4 (void) const -{ - L3Demux *l3Demux = QueryInterface (L3Demux::iid); - Ipv4 *ipv4 = static_cast (l3Demux->PeekProtocol (Ipv4::PROT_NUMBER)); - l3Demux->Unref (); - ipv4->Ref (); - return ipv4; -} - void InternetNode::DoAddDevice (NetDevice *device) const { diff --git a/src/node/internet-node.h b/src/node/internet-node.h index bf33032d0..5e5f585b2 100644 --- a/src/node/internet-node.h +++ b/src/node/internet-node.h @@ -42,8 +42,6 @@ public: InternetNode(); virtual ~InternetNode (); virtual TraceResolver *CreateTraceResolver (TraceContext const &context); - // Capability access - virtual Ipv4 * GetIpv4 (void) const; void SetName(std::string name); protected: @@ -51,7 +49,6 @@ protected: private: virtual void DoAddDevice (NetDevice *device) const; bool ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const; - // Capabilities std::string m_name; }; diff --git a/src/node/ipv4-loopback-interface.cc b/src/node/ipv4-loopback-interface.cc index fd506fd01..8cb002efc 100644 --- a/src/node/ipv4-loopback-interface.cc +++ b/src/node/ipv4-loopback-interface.cc @@ -23,7 +23,7 @@ #include "ipv4-loopback-interface.h" #include "net-device.h" #include "node.h" -#include "ipv4.h" +#include "i-ipv4-private.h" namespace ns3 { @@ -47,7 +47,7 @@ Ipv4LoopbackInterface::DoCreateTraceResolver (TraceContext const &context) void Ipv4LoopbackInterface::SendTo (Packet packet, Ipv4Address dest) { - Ipv4 *ipv4 = m_node->GetIpv4 (); + IIpv4Private *ipv4 = m_node->QueryInterface (IIpv4Private::iid); ipv4->Receive (packet, PeekDevice ()); ipv4->Unref (); } diff --git a/src/node/node.cc b/src/node/node.cc index 930bd5e58..0b5abc25c 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -102,10 +102,4 @@ void Node::DoDispose() NsUnknown::DoDispose (); } -Ipv4 * -Node::GetIpv4 (void) const -{ - return 0; -} - }//namespace ns3 diff --git a/src/node/node.h b/src/node/node.h index b48762f29..a0fab0bb2 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -31,8 +31,6 @@ namespace ns3 { -class Ipv4; - class TraceContext; class TraceResolver; class NetDevice; @@ -61,17 +59,6 @@ protected: private: virtual void DoAddDevice (NetDevice *device) const = 0; -public: - // Virtual "Getters" for each capability. - // These exist to allow owners of a generic Node pointer to get - // a pointer to the underlying capability, a pointer to a "NULL" - // capability if one exists, or the nil pointer if not. - // Each of these has a default behavior of returning a null capability - // of the correct type if one exists, or the nil pointer if no - // null capability exists. - virtual Ipv4 * GetIpv4 (void) const; - -private: uint32_t m_id; // Node id for this node uint32_t m_sid; // System id for this node std::vector m_devices; diff --git a/src/node/udp.cc b/src/node/udp.cc index 4e5777390..19277e6fe 100644 --- a/src/node/udp.cc +++ b/src/node/udp.cc @@ -29,6 +29,7 @@ #include "ipv4-end-point.h" #include "node.h" #include "ipv4.h" +#include "i-ipv4-private.h" #include "l3-demux.h" #include "udp-socket.h" @@ -141,7 +142,7 @@ Udp::Send (Packet packet, packet.AddHeader (udpHeader); - Ipv4 *ipv4 = m_node->GetIpv4 (); + IIpv4Private *ipv4 = m_node->QueryInterface (IIpv4Private::iid); if (ipv4 != 0) { ipv4->Send (packet, saddr, daddr, PROT_NUMBER);