diff -r 509c35cf49ae examples/csma-one-subnet.cc --- a/examples/csma-one-subnet.cc Sun May 25 05:35:22 2008 -0700 +++ b/examples/csma-one-subnet.cc Sun May 25 09:51:23 2008 -0700 @@ -80,6 +80,7 @@ main (int argc, char *argv[]) NetDeviceContainer nd0 = csma.Install (c); InternetStackHelper internet; + internet.UseGodArp (); internet.Install (c); // We've got the "hardware" in place. Now we need to add IP addresses. diff -r 509c35cf49ae src/helper/internet-stack-helper.cc --- a/src/helper/internet-stack-helper.cc Sun May 25 05:35:22 2008 -0700 +++ b/src/helper/internet-stack-helper.cc Sun May 25 09:53:40 2008 -0700 @@ -47,6 +47,22 @@ InternetStackHelper::Cleanup (void) m_traces.clear (); } +InternetStackHelper::InternetStackHelper () + : m_godArp (false) +{} + +void +InternetStackHelper::UseGodArp (void) +{ + m_godArp = true; +} +void +InternetStackHelper::UseRealArp (void) +{ + m_godArp = false; +} + + void InternetStackHelper::Install (NodeContainer c) { @@ -58,8 +74,19 @@ InternetStackHelper::Install (NodeContai NS_FATAL_ERROR ("InternetStackHelper::Install(): Aggregating " "an InternetStack to a node with an existing Ipv4 object"); return; - } - AddInternetStack (node); + } + if (m_godArp) + { + InternetStack::AddGodArp (node); + } + else + { + InternetStack::AddRealArp (node); + } + InternetStack::AddIpv4 (node); + InternetStack::AddUdp (node); + InternetStack::AddTcp (node); + Ptr factory = CreateObject (); node->AggregateObject (factory); } diff -r 509c35cf49ae src/helper/internet-stack-helper.h --- a/src/helper/internet-stack-helper.h Sun May 25 05:35:22 2008 -0700 +++ b/src/helper/internet-stack-helper.h Sun May 25 09:27:12 2008 -0700 @@ -33,6 +33,22 @@ class InternetStackHelper class InternetStackHelper { public: + InternetStackHelper (); + /** + * Every internet stack created with Install after calling this + * method will contain a 'God' ARP implementation. + * + * \sa ns3::GodArp + */ + void UseGodArp (void); + /* + * Every internet stack created with Install after calling this + * method will contain a 'Real' ARP implementation. + * + * \sa ns3::Ipv4L3Protocol + */ + void UseRealArp (void); + /** * \param c the set of nodes * @@ -72,6 +88,7 @@ private: static std::string m_pcapBaseFilename; static uint32_t GetNodeIndex (std::string context); static std::vector m_traces; + bool m_godArp; }; } // namespace ns3 diff -r 509c35cf49ae src/internet-node/arp-ipv4-interface.cc --- a/src/internet-node/arp-ipv4-interface.cc Sun May 25 05:35:22 2008 -0700 +++ b/src/internet-node/arp-ipv4-interface.cc Sun May 25 09:05:17 2008 -0700 @@ -76,8 +76,8 @@ ArpIpv4Interface::SendTo (Ptr p, if (GetDevice ()->NeedsArp ()) { NS_LOG_LOGIC ("Needs ARP"); - Ptr arp = - m_node->GetObject (); + Ptr arp = + m_node->GetObject (); Address hardwareDestination; bool found; diff -r 509c35cf49ae src/internet-node/arp-l3-protocol.cc --- a/src/internet-node/arp-l3-protocol.cc Sun May 25 05:35:22 2008 -0700 +++ b/src/internet-node/arp-l3-protocol.cc Sun May 25 09:00:59 2008 -0700 @@ -40,7 +40,7 @@ ArpL3Protocol::GetTypeId (void) ArpL3Protocol::GetTypeId (void) { static TypeId tid = TypeId ("ns3::ArpL3Protocol") - .SetParent () + .SetParent () ; return tid; } diff -r 509c35cf49ae src/internet-node/arp-l3-protocol.h --- a/src/internet-node/arp-l3-protocol.h Sun May 25 05:35:22 2008 -0700 +++ b/src/internet-node/arp-l3-protocol.h Sun May 25 09:04:15 2008 -0700 @@ -21,6 +21,7 @@ #define ARP_L3_PROTOCOL_H #include +#include "arp.h" #include "ns3/ipv4-address.h" #include "ns3/address.h" #include "ns3/ptr.h" @@ -35,7 +36,7 @@ class Packet; /** * \brief An implementation of the ARP protocol */ -class ArpL3Protocol : public Object +class ArpL3Protocol : public Arp { public: static TypeId GetTypeId (void); @@ -50,17 +51,10 @@ public: * \brief Recieve a packet */ void Receive(Ptr device, Ptr p, uint16_t protocol, const Address &from); - /** - * \brief Perform an ARP lookup - * \param p - * \param destination - * \param device - * \param hardwareDestination - * \return - */ - bool Lookup (Ptr p, Ipv4Address destination, - Ptr device, - Address *hardwareDestination); + + virtual bool Lookup (Ptr p, Ipv4Address destination, + Ptr device, + Address *hardwareDestination); protected: virtual void DoDispose (void); private: diff -r 509c35cf49ae src/internet-node/arp.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/internet-node/arp.cc Sun May 25 09:13:41 2008 -0700 @@ -0,0 +1,36 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006 INRIA + * + * 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 "arp.h" + +namespace ns3 { + +TypeId +Arp::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::Arp") + .SetParent () + ; + return tid; +} + +Arp::~Arp () +{} + +} // namespace ns3 diff -r 509c35cf49ae src/internet-node/arp.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/internet-node/arp.h Sun May 25 09:02:37 2008 -0700 @@ -0,0 +1,62 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006 INRIA + * + * 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 ARP_H +#define ARP_H + +#include +#include "ns3/object.h" +#include "ns3/ipv4-address.h" +#include "ns3/ptr.h" + +namespace ns3 { + +class NetDevice; +class Node; +class Packet; +class Address; + +/** + * \brief An interface to access the functionality provided + * by the ARP layer. + */ +class Arp : public Object +{ +public: + static TypeId GetTypeId (void); + + virtual ~Arp (); + + /** + * \brief Perform an ARP lookup + * \param p + * \param destination + * \param device + * \param hardwareDestination + * \return + */ + virtual bool Lookup (Ptr p, Ipv4Address destination, + Ptr device, + Address *hardwareDestination) = 0; +}; + +}//namespace ns3 + + +#endif /* ARP_H */ diff -r 509c35cf49ae src/internet-node/god-arp.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/internet-node/god-arp.cc Sun May 25 09:13:19 2008 -0700 @@ -0,0 +1,66 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2008 INRIA + * + * 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 "god-arp.h" +#include "ns3/ipv4.h" +#include "ns3/channel.h" +#include "ns3/net-device.h" +#include "ns3/node.h" + +namespace ns3 { + +TypeId +GodArp::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::GodArp") + .SetParent () + ; + return tid; +} + +GodArp::GodArp () +{} + +bool +GodArp::Lookup (Ptr p, Ipv4Address destination, + Ptr device, + Address *hardwareDestination) +{ + Ptr channel = device->GetChannel (); + for (uint32_t i = 0; i < channel->GetNDevices (); ++i) + { + Ptr remote = channel->GetDevice (i); + Ptr remoteNode = remote->GetNode (); + Ptr remoteIpv4 = remoteNode->GetObject (); + if (remoteIpv4 == 0) + { + continue; + } + int32_t index = remoteIpv4->FindInterfaceForDevice (remote); + if (index == -1) + { + continue; + } + *hardwareDestination = remote->GetAddress (); + return true; + } + return false; +} + +} // namespace ns3 diff -r 509c35cf49ae src/internet-node/god-arp.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/internet-node/god-arp.h Sun May 25 09:12:23 2008 -0700 @@ -0,0 +1,41 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2008 INRIA + * + * 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 GOD_ARP_H +#define GOD_ARP_H + +#include "arp.h" + +namespace ns3 { + +class GodArp : public Arp +{ +public: + static TypeId GetTypeId (void); + GodArp (); + + virtual bool Lookup (Ptr p, Ipv4Address destination, + Ptr device, + Address *hardwareDestination); +}; + + +} // namespace ns3 + +#endif /* GOD_ARP_H */ diff -r 509c35cf49ae src/internet-node/internet-stack.cc --- a/src/internet-node/internet-stack.cc Sun May 25 05:35:22 2008 -0700 +++ b/src/internet-node/internet-stack.cc Sun May 25 09:41:58 2008 -0700 @@ -27,51 +27,98 @@ #include "tcp-l4-protocol.h" #include "ipv4-l3-protocol.h" #include "arp-l3-protocol.h" +#include "god-arp.h" #include "udp-impl.h" #include "tcp-impl.h" #include "ipv4-impl.h" namespace ns3 { +namespace InternetStack { + +static Ptr +AddIpv4L4Demux (Ptr node) +{ + + Ptr ipv4L4Demux = node->GetObject (); + if (ipv4L4Demux != 0) + { + return ipv4L4Demux; + } + ipv4L4Demux = CreateObject (); + ipv4L4Demux->SetNode (node); + node->AggregateObject (ipv4L4Demux); + return ipv4L4Demux; +} + +void +AddTcp (Ptr node) +{ + Ptr tcp = CreateObject (); + tcp->SetNode (node); + Ptr ipv4L4Demux = AddIpv4L4Demux (node); + ipv4L4Demux->Insert (tcp); + Ptr tcpImpl = CreateObject (); + tcpImpl->SetTcp (tcp); + node->AggregateObject (tcpImpl); +} + +void +AddUdp (Ptr node) +{ + Ptr udp = CreateObject (); + udp->SetNode (node); + Ptr ipv4L4Demux = AddIpv4L4Demux (node); + ipv4L4Demux->Insert (udp); + Ptr udpImpl = CreateObject (); + udpImpl->SetUdp (udp); + node->AggregateObject (udpImpl); +} + void -AddInternetStack (Ptr node) +AddIpv4 (Ptr node) { Ptr ipv4 = CreateObject (); - Ptr arp = CreateObject (); ipv4->SetNode (node); - arp->SetNode (node); // XXX remove the PeekPointer below. node->RegisterProtocolHandler (MakeCallback (&Ipv4L3Protocol::Receive, PeekPointer (ipv4)), Ipv4L3Protocol::PROT_NUMBER, 0); - node->RegisterProtocolHandler (MakeCallback (&ArpL3Protocol::Receive, PeekPointer (arp)), - ArpL3Protocol::PROT_NUMBER, 0); - - Ptr ipv4L4Demux = CreateObject (); - Ptr udp = CreateObject (); - Ptr tcp = CreateObject (); - - ipv4L4Demux->SetNode (node); - udp->SetNode (node); - tcp->SetNode (node); - - ipv4L4Demux->Insert (udp); - ipv4L4Demux->Insert (tcp); - - Ptr udpImpl = CreateObject (); - Ptr tcpImpl = CreateObject (); Ptr ipv4Impl = CreateObject (); - - udpImpl->SetUdp (udp); - tcpImpl->SetTcp (tcp); ipv4Impl->SetIpv4 (ipv4); node->AggregateObject (ipv4); - node->AggregateObject (arp); node->AggregateObject (ipv4Impl); - node->AggregateObject (udpImpl); - node->AggregateObject (tcpImpl); - node->AggregateObject (ipv4L4Demux); } +void +AddGodArp (Ptr node) +{ + Ptr arp = CreateObject (); + node->AggregateObject (arp); +} + +void +AddRealArp (Ptr node) +{ + // XXX remove the PeekPointer below. + Ptr arp = CreateObject (); + arp->SetNode (node); + node->RegisterProtocolHandler (MakeCallback (&ArpL3Protocol::Receive, PeekPointer (arp)), + ArpL3Protocol::PROT_NUMBER, 0); + node->AggregateObject (arp); +} + +void +AddAll (Ptr node) +{ + AddRealArp (node); + AddIpv4 (node); + AddUdp (node); + AddTcp (node); +} + + +} // namespace InternetStack + }//namespace ns3 diff -r 509c35cf49ae src/internet-node/internet-stack.h --- a/src/internet-node/internet-stack.h Sun May 25 05:35:22 2008 -0700 +++ b/src/internet-node/internet-stack.h Sun May 25 09:29:21 2008 -0700 @@ -26,7 +26,16 @@ namespace ns3 { class Node; -void AddInternetStack (Ptr node); +namespace InternetStack { + +void AddAll (Ptr node); +void AddGodArp (Ptr node); +void AddRealArp (Ptr node); +void AddIpv4 (Ptr node); +void AddUdp (Ptr node); +void AddTcp (Ptr node); + +} // namespace InternetStack }//namespace ns3 diff -r 509c35cf49ae src/internet-node/udp-socket.cc --- a/src/internet-node/udp-socket.cc Sun May 25 05:35:22 2008 -0700 +++ b/src/internet-node/udp-socket.cc Sun May 25 09:31:01 2008 -0700 @@ -393,7 +393,7 @@ UdpSocketTest::RunTests (void) // Receiver Node Ptr rxNode = CreateObject (); - AddInternetStack (rxNode); + InternetStack::AddAll (rxNode); Ptr rxDev1, rxDev2; { // first interface rxDev1 = CreateObject (); @@ -419,7 +419,7 @@ UdpSocketTest::RunTests (void) // Sender Node Ptr txNode = CreateObject (); - AddInternetStack (txNode); + InternetStack::AddAll (txNode); Ptr txDev1; { txDev1 = CreateObject (); diff -r 509c35cf49ae src/internet-node/wscript --- a/src/internet-node/wscript Sun May 25 05:35:22 2008 -0700 +++ b/src/internet-node/wscript Sun May 25 09:12:35 2008 -0700 @@ -17,6 +17,8 @@ def build(bld): 'ipv4-end-point.cc', 'udp-l4-protocol.cc', 'tcp-l4-protocol.cc', + 'arp.cc', + 'god-arp.cc', 'arp-header.cc', 'arp-cache.cc', 'arp-ipv4-interface.cc',