--- a/SConstruct Mon Jun 04 16:51:59 2007 +0200
+++ b/SConstruct Mon Jun 04 16:54:36 2007 +0200
@@ -269,7 +269,7 @@
'arp-header.cc',
'arp-cache.cc',
'arp-ipv4-interface.cc',
- 'arp.cc',
+ 'arp-l3-protocol.cc',
'ipv4-loopback-interface.cc',
'header-utils.cc',
'udp-socket.cc',
@@ -287,7 +287,7 @@
'ipv4-checksum.h',
'arp-header.h',
'arp-cache.h',
- 'arp.h',
+ 'arp-l3-protocol.h',
'ipv4-loopback-interface.h',
'l3-demux.h',
'header-utils.h',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/arp-l3-protocol.cc Mon Jun 04 16:54:36 2007 +0200
@@ -0,0 +1,227 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006 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 <mathieu.lacage@sophia.inria.fr>
+ */
+#include "ns3/packet.h"
+#include "ns3/debug.h"
+#include "ns3/empty-trace-resolver.h"
+#include "ns3/node.h"
+#include "ns3/net-device.h"
+
+#include "arp-l3-protocol.h"
+#include "arp-header.h"
+#include "arp-cache.h"
+#include "ipv4-interface.h"
+#include "i-ipv4-private.h"
+
+NS_DEBUG_COMPONENT_DEFINE ("Arp");
+
+namespace ns3 {
+
+const uint16_t Arp::PROT_NUMBER = 0x0806;
+
+Arp::Arp (Ptr<Node> node)
+ : L3Protocol (PROT_NUMBER, 0/* XXX: correct version number ? */ ),
+ m_node (node)
+{}
+
+Arp::~Arp ()
+{}
+
+void
+Arp::DoDispose (void)
+{
+ for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++)
+ {
+ delete *i;
+ }
+ m_cacheList.clear ();
+ m_node = 0;
+ L3Protocol::DoDispose ();
+}
+
+TraceResolver *
+Arp::CreateTraceResolver (TraceContext const &context)
+{
+ return new EmptyTraceResolver (context);
+}
+
+ArpCache *
+Arp::FindCache (Ptr<NetDevice> device)
+{
+ for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++)
+ {
+ if ((*i)->GetDevice () == device)
+ {
+ return *i;
+ }
+ }
+ Ptr<IIpv4Private> ipv4 = m_node->QueryInterface<IIpv4Private> (IIpv4Private::iid);
+ Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device);
+ ArpCache * cache = new ArpCache (device, interface);
+ NS_ASSERT (device->IsBroadcast ());
+ device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache));
+ m_cacheList.push_back (cache);
+ return cache;
+}
+
+void
+Arp::Receive(Packet& packet, Ptr<NetDevice> device)
+{
+ ArpCache *cache = FindCache (device);
+ ArpHeader arp;
+ packet.RemoveHeader (arp);
+ if (arp.IsRequest () &&
+ arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ())
+ {
+ NS_DEBUG ("node="<<m_node->GetId () <<", got request from " <<
+ arp.GetSourceIpv4Address () << " -- send reply");
+ SendArpReply (cache, arp.GetSourceIpv4Address (),
+ arp.GetSourceHardwareAddress ());
+ }
+ else if (arp.IsReply () &&
+ arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress ()) &&
+ arp.GetDestinationHardwareAddress ().IsEqual (device->GetAddress ()))
+ {
+ Ipv4Address from = arp.GetSourceIpv4Address ();
+ ArpCache::Entry *entry = cache->Lookup (from);
+ if (entry != 0)
+ {
+ if (entry->IsWaitReply ())
+ {
+ NS_DEBUG ("node="<<m_node->GetId ()<<", got reply from " <<
+ arp.GetSourceIpv4Address ()
+ << " for waiting entry -- flush");
+ MacAddress from_mac = arp.GetSourceHardwareAddress ();
+ Packet waiting = entry->MarkAlive (from_mac);
+ cache->GetInterface ()->Send (waiting, arp.GetSourceIpv4Address ());
+ }
+ else
+ {
+ // ignore this reply which might well be an attempt
+ // at poisening my arp cache.
+ NS_DEBUG ("node="<<m_node->GetId ()<<", got reply from " <<
+ arp.GetSourceIpv4Address () <<
+ " for non-waiting entry -- drop");
+ // XXX report packet as dropped.
+ }
+ }
+ else
+ {
+ NS_DEBUG ("node="<<m_node->GetId ()<<", got reply for unknown entry -- drop");
+ // XXX report packet as dropped.
+ }
+ }
+}
+bool
+Arp::Lookup (Packet &packet, Ipv4Address destination,
+ Ptr<NetDevice> device,
+ MacAddress *hardwareDestination)
+{
+ ArpCache *cache = FindCache (device);
+ ArpCache::Entry *entry = cache->Lookup (destination);
+ if (entry != 0)
+ {
+ if (entry->IsExpired ())
+ {
+ if (entry->IsDead ())
+ {
+ NS_DEBUG ("node="<<m_node->GetId ()<<
+ ", dead entry for " << destination << " expired -- send arp request");
+ entry->MarkWaitReply (packet);
+ SendArpRequest (cache, destination);
+ }
+ else if (entry->IsAlive ())
+ {
+ NS_DEBUG ("node="<<m_node->GetId ()<<
+ ", alive entry for " << destination << " expired -- send arp request");
+ entry->MarkWaitReply (packet);
+ SendArpRequest (cache, destination);
+ }
+ else if (entry->IsWaitReply ())
+ {
+ NS_DEBUG ("node="<<m_node->GetId ()<<
+ ", wait reply for " << destination << " expired -- drop");
+ entry->MarkDead ();
+ // XXX report packet as 'dropped'
+ }
+ }
+ else
+ {
+ if (entry->IsDead ())
+ {
+ NS_DEBUG ("node="<<m_node->GetId ()<<
+ ", dead entry for " << destination << " valid -- drop");
+ // XXX report packet as 'dropped'
+ }
+ else if (entry->IsAlive ())
+ {
+ NS_DEBUG ("node="<<m_node->GetId ()<<
+ ", alive entry for " << destination << " valid -- send");
+ *hardwareDestination = entry->GetMacAddress ();
+ return true;
+ }
+ else if (entry->IsWaitReply ())
+ {
+ NS_DEBUG ("node="<<m_node->GetId ()<<
+ ", wait reply for " << destination << " valid -- drop previous");
+ Packet old = entry->UpdateWaitReply (packet);
+ // XXX report 'old' packet as 'dropped'
+ }
+ }
+
+ }
+ else
+ {
+ // This is our first attempt to transmit data to this destination.
+ NS_DEBUG ("node="<<m_node->GetId ()<<
+ ", no entry for " << destination << " -- send arp request");
+ entry = cache->Add (destination);
+ entry->MarkWaitReply (packet);
+ SendArpRequest (cache, destination);
+ }
+ return false;
+}
+
+void
+Arp::SendArpRequest (ArpCache const *cache, Ipv4Address to)
+{
+ ArpHeader arp;
+ arp.SetRequest (cache->GetDevice ()->GetAddress (),
+ cache->GetInterface ()->GetAddress (),
+ cache->GetDevice ()->GetBroadcast (),
+ to);
+ Packet packet;
+ packet.AddHeader (arp);
+ cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), PROT_NUMBER);
+}
+
+void
+Arp::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac)
+{
+ ArpHeader arp;
+ arp.SetReply (cache->GetDevice ()->GetAddress (),
+ cache->GetInterface ()->GetAddress (),
+ toMac, toIp);
+ Packet packet;
+ packet.AddHeader (arp);
+ cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER);
+}
+
+}//namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/arp-l3-protocol.h Mon Jun 04 16:54:36 2007 +0200
@@ -0,0 +1,82 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006 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 <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef ARP_H
+#define ARP_H
+
+#include <list>
+#include "ns3/ipv4-address.h"
+#include "ns3/mac-address.h"
+#include "ns3/ptr.h"
+#include "l3-protocol.h"
+
+namespace ns3 {
+
+class ArpCache;
+class NetDevice;
+class Node;
+class Packet;
+class TraceResolver;
+class TraceContext;
+/**
+ * \brief An implementation of the ARP protocol
+ */
+class Arp : public L3Protocol
+{
+public:
+ static const uint16_t PROT_NUMBER;
+ /**
+ * \brief Constructor
+ * \param node The node which this ARP object is associated with
+ */
+ Arp (Ptr<Node> node);
+ ~Arp ();
+
+ virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
+ /**
+ * \brief Recieve a packet
+ */
+ virtual void Receive(Packet& p, Ptr<NetDevice> device);
+ /**
+ * \brief Perform an ARP lookup
+ * \param p
+ * \param destination
+ * \param device
+ * \param hardwareDestination
+ * \return
+ */
+ bool Lookup (Packet &p, Ipv4Address destination,
+ Ptr<NetDevice> device,
+ MacAddress *hardwareDestination);
+protected:
+ virtual void DoDispose (void);
+private:
+ typedef std::list<ArpCache *> CacheList;
+ ArpCache *FindCache (Ptr<NetDevice> device);
+ void SendArpRequest (ArpCache const *cache, Ipv4Address to);
+ void SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac);
+ CacheList m_cacheList;
+ Ptr<Node> m_node;
+};
+
+}//namespace ns3
+
+
+#endif /* ARP_H */
--- a/src/internet-node/arp.cc Mon Jun 04 16:51:59 2007 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,227 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2006 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 <mathieu.lacage@sophia.inria.fr>
- */
-#include "ns3/packet.h"
-#include "ns3/debug.h"
-#include "ns3/empty-trace-resolver.h"
-#include "ns3/node.h"
-#include "ns3/net-device.h"
-
-#include "arp.h"
-#include "arp-header.h"
-#include "arp-cache.h"
-#include "ipv4-interface.h"
-#include "i-ipv4-private.h"
-
-NS_DEBUG_COMPONENT_DEFINE ("Arp");
-
-namespace ns3 {
-
-const uint16_t Arp::PROT_NUMBER = 0x0806;
-
-Arp::Arp (Ptr<Node> node)
- : L3Protocol (PROT_NUMBER, 0/* XXX: correct version number ? */ ),
- m_node (node)
-{}
-
-Arp::~Arp ()
-{}
-
-void
-Arp::DoDispose (void)
-{
- for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++)
- {
- delete *i;
- }
- m_cacheList.clear ();
- m_node = 0;
- L3Protocol::DoDispose ();
-}
-
-TraceResolver *
-Arp::CreateTraceResolver (TraceContext const &context)
-{
- return new EmptyTraceResolver (context);
-}
-
-ArpCache *
-Arp::FindCache (Ptr<NetDevice> device)
-{
- for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++)
- {
- if ((*i)->GetDevice () == device)
- {
- return *i;
- }
- }
- Ptr<IIpv4Private> ipv4 = m_node->QueryInterface<IIpv4Private> (IIpv4Private::iid);
- Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device);
- ArpCache * cache = new ArpCache (device, interface);
- NS_ASSERT (device->IsBroadcast ());
- device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache));
- m_cacheList.push_back (cache);
- return cache;
-}
-
-void
-Arp::Receive(Packet& packet, Ptr<NetDevice> device)
-{
- ArpCache *cache = FindCache (device);
- ArpHeader arp;
- packet.RemoveHeader (arp);
- if (arp.IsRequest () &&
- arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ())
- {
- NS_DEBUG ("node="<<m_node->GetId () <<", got request from " <<
- arp.GetSourceIpv4Address () << " -- send reply");
- SendArpReply (cache, arp.GetSourceIpv4Address (),
- arp.GetSourceHardwareAddress ());
- }
- else if (arp.IsReply () &&
- arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress ()) &&
- arp.GetDestinationHardwareAddress ().IsEqual (device->GetAddress ()))
- {
- Ipv4Address from = arp.GetSourceIpv4Address ();
- ArpCache::Entry *entry = cache->Lookup (from);
- if (entry != 0)
- {
- if (entry->IsWaitReply ())
- {
- NS_DEBUG ("node="<<m_node->GetId ()<<", got reply from " <<
- arp.GetSourceIpv4Address ()
- << " for waiting entry -- flush");
- MacAddress from_mac = arp.GetSourceHardwareAddress ();
- Packet waiting = entry->MarkAlive (from_mac);
- cache->GetInterface ()->Send (waiting, arp.GetSourceIpv4Address ());
- }
- else
- {
- // ignore this reply which might well be an attempt
- // at poisening my arp cache.
- NS_DEBUG ("node="<<m_node->GetId ()<<", got reply from " <<
- arp.GetSourceIpv4Address () <<
- " for non-waiting entry -- drop");
- // XXX report packet as dropped.
- }
- }
- else
- {
- NS_DEBUG ("node="<<m_node->GetId ()<<", got reply for unknown entry -- drop");
- // XXX report packet as dropped.
- }
- }
-}
-bool
-Arp::Lookup (Packet &packet, Ipv4Address destination,
- Ptr<NetDevice> device,
- MacAddress *hardwareDestination)
-{
- ArpCache *cache = FindCache (device);
- ArpCache::Entry *entry = cache->Lookup (destination);
- if (entry != 0)
- {
- if (entry->IsExpired ())
- {
- if (entry->IsDead ())
- {
- NS_DEBUG ("node="<<m_node->GetId ()<<
- ", dead entry for " << destination << " expired -- send arp request");
- entry->MarkWaitReply (packet);
- SendArpRequest (cache, destination);
- }
- else if (entry->IsAlive ())
- {
- NS_DEBUG ("node="<<m_node->GetId ()<<
- ", alive entry for " << destination << " expired -- send arp request");
- entry->MarkWaitReply (packet);
- SendArpRequest (cache, destination);
- }
- else if (entry->IsWaitReply ())
- {
- NS_DEBUG ("node="<<m_node->GetId ()<<
- ", wait reply for " << destination << " expired -- drop");
- entry->MarkDead ();
- // XXX report packet as 'dropped'
- }
- }
- else
- {
- if (entry->IsDead ())
- {
- NS_DEBUG ("node="<<m_node->GetId ()<<
- ", dead entry for " << destination << " valid -- drop");
- // XXX report packet as 'dropped'
- }
- else if (entry->IsAlive ())
- {
- NS_DEBUG ("node="<<m_node->GetId ()<<
- ", alive entry for " << destination << " valid -- send");
- *hardwareDestination = entry->GetMacAddress ();
- return true;
- }
- else if (entry->IsWaitReply ())
- {
- NS_DEBUG ("node="<<m_node->GetId ()<<
- ", wait reply for " << destination << " valid -- drop previous");
- Packet old = entry->UpdateWaitReply (packet);
- // XXX report 'old' packet as 'dropped'
- }
- }
-
- }
- else
- {
- // This is our first attempt to transmit data to this destination.
- NS_DEBUG ("node="<<m_node->GetId ()<<
- ", no entry for " << destination << " -- send arp request");
- entry = cache->Add (destination);
- entry->MarkWaitReply (packet);
- SendArpRequest (cache, destination);
- }
- return false;
-}
-
-void
-Arp::SendArpRequest (ArpCache const *cache, Ipv4Address to)
-{
- ArpHeader arp;
- arp.SetRequest (cache->GetDevice ()->GetAddress (),
- cache->GetInterface ()->GetAddress (),
- cache->GetDevice ()->GetBroadcast (),
- to);
- Packet packet;
- packet.AddHeader (arp);
- cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), PROT_NUMBER);
-}
-
-void
-Arp::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac)
-{
- ArpHeader arp;
- arp.SetReply (cache->GetDevice ()->GetAddress (),
- cache->GetInterface ()->GetAddress (),
- toMac, toIp);
- Packet packet;
- packet.AddHeader (arp);
- cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER);
-}
-
-}//namespace ns3
--- a/src/internet-node/arp.h Mon Jun 04 16:51:59 2007 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2006 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 <mathieu.lacage@sophia.inria.fr>
- */
-#ifndef ARP_H
-#define ARP_H
-
-#include <list>
-#include "ns3/ipv4-address.h"
-#include "ns3/mac-address.h"
-#include "ns3/ptr.h"
-#include "l3-protocol.h"
-
-namespace ns3 {
-
-class ArpCache;
-class NetDevice;
-class Node;
-class Packet;
-class TraceResolver;
-class TraceContext;
-/**
- * \brief An implementation of the ARP protocol
- */
-class Arp : public L3Protocol
-{
-public:
- static const uint16_t PROT_NUMBER;
- /**
- * \brief Constructor
- * \param node The node which this ARP object is associated with
- */
- Arp (Ptr<Node> node);
- ~Arp ();
-
- virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
- /**
- * \brief Recieve a packet
- */
- virtual void Receive(Packet& p, Ptr<NetDevice> device);
- /**
- * \brief Perform an ARP lookup
- * \param p
- * \param destination
- * \param device
- * \param hardwareDestination
- * \return
- */
- bool Lookup (Packet &p, Ipv4Address destination,
- Ptr<NetDevice> device,
- MacAddress *hardwareDestination);
-protected:
- virtual void DoDispose (void);
-private:
- typedef std::list<ArpCache *> CacheList;
- ArpCache *FindCache (Ptr<NetDevice> device);
- void SendArpRequest (ArpCache const *cache, Ipv4Address to);
- void SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac);
- CacheList m_cacheList;
- Ptr<Node> m_node;
-};
-
-}//namespace ns3
-
-
-#endif /* ARP_H */
--- a/src/internet-node/i-arp-private.cc Mon Jun 04 16:51:59 2007 +0200
+++ b/src/internet-node/i-arp-private.cc Mon Jun 04 16:54:36 2007 +0200
@@ -19,7 +19,7 @@
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "i-arp-private.h"
-#include "arp.h"
+#include "arp-l3-protocol.h"
#include "ns3/assert.h"
#include "ns3/net-device.h"
--- a/src/internet-node/internet-node.cc Mon Jun 04 16:51:59 2007 +0200
+++ b/src/internet-node/internet-node.cc Mon Jun 04 16:54:36 2007 +0200
@@ -29,7 +29,7 @@
#include "internet-node.h"
#include "udp.h"
#include "ipv4-l3-protocol.h"
-#include "arp.h"
+#include "arp-l3-protocol.h"
#include "i-udp-impl.h"
#include "i-arp-private.h"
#include "i-ipv4-impl.h"