Allow ARP resolution to work with broadcast IPv4 (dest=255.255.255.255) packets; Partially fixes bug #36.
--- a/src/internet-node/arp-cache.cc Thu Jul 26 12:05:31 2007 +0100
+++ b/src/internet-node/arp-cache.cc Thu Jul 26 12:12:51 2007 +0100
@@ -109,6 +109,8 @@
ArpCache::Entry *
ArpCache::Add (Ipv4Address to)
{
+ NS_ASSERT (m_arpCache.find (to) == m_arpCache.end ());
+
ArpCache::Entry *entry = new ArpCache::Entry (this);
m_arpCache[to] = entry;
return entry;
--- a/src/internet-node/arp-ipv4-interface.cc Thu Jul 26 12:05:31 2007 +0100
+++ b/src/internet-node/arp-ipv4-interface.cc Thu Jul 26 12:12:51 2007 +0100
@@ -21,6 +21,7 @@
*/
#include "ns3/packet.h"
+#include "ns3/debug.h"
#include "ns3/composite-trace-resolver.h"
#include "ns3/node.h"
#include "ns3/net-device.h"
@@ -60,7 +61,19 @@
{
Ptr<ArpPrivate> arp = m_node->QueryInterface<ArpPrivate> (ArpPrivate::iid);
MacAddress hardwareDestination;
- bool found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination);
+ bool found;
+
+ if (dest.IsBroadcast ())
+ {
+ hardwareDestination = GetDevice ()->GetBroadcast ();
+ found = true;
+ }
+ else
+ {
+ Ptr<ArpPrivate> arp = m_node->QueryInterface<ArpPrivate> (ArpPrivate::iid);
+ found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination);
+ }
+
if (found)
{
GetDevice ()->Send (p, hardwareDestination, Ipv4L3Protocol::PROT_NUMBER);
--- a/src/internet-node/arp-l3-protocol.cc Thu Jul 26 12:05:31 2007 +0100
+++ b/src/internet-node/arp-l3-protocol.cc Thu Jul 26 12:12:51 2007 +0100
@@ -87,6 +87,13 @@
ArpCache *cache = FindCache (device);
ArpHeader arp;
packet.RemoveHeader (arp);
+
+ NS_DEBUG ("ARP: received "<< (arp.IsRequest ()? "request" : "reply") <<
+ " node="<<m_node->GetId ()<<", got request from " <<
+ arp.GetSourceIpv4Address () << " for address " <<
+ arp.GetDestinationIpv4Address () << "; we have address " <<
+ cache->GetInterface ()->GetAddress ());
+
if (arp.IsRequest () &&
arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ())
{
@@ -128,6 +135,12 @@
// XXX report packet as dropped.
}
}
+ else
+ {
+ NS_DEBUG ("node="<<m_node->GetId ()<<", got request from " <<
+ arp.GetSourceIpv4Address () << " for unknown address " <<
+ arp.GetDestinationIpv4Address () << " -- drop");
+ }
}
bool
ArpL3Protocol::Lookup (Packet &packet, Ipv4Address destination,
@@ -203,6 +216,11 @@
ArpL3Protocol::SendArpRequest (ArpCache const *cache, Ipv4Address to)
{
ArpHeader arp;
+ NS_DEBUG ("ARP: sending request from node "<<m_node->GetId ()<<
+ " || src: " << cache->GetDevice ()->GetAddress () <<
+ " / " << cache->GetInterface ()->GetAddress () <<
+ " || dst: " << cache->GetDevice ()->GetBroadcast () <<
+ " / " << to);
arp.SetRequest (cache->GetDevice ()->GetAddress (),
cache->GetInterface ()->GetAddress (),
cache->GetDevice ()->GetBroadcast (),
@@ -216,6 +234,10 @@
ArpL3Protocol::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac)
{
ArpHeader arp;
+ NS_DEBUG ("ARP: sending reply from node "<<m_node->GetId ()<<
+ "|| src: " << cache->GetDevice ()->GetAddress () <<
+ " / " << cache->GetInterface ()->GetAddress () <<
+ " || dst: " << toMac << " / " << toIp);
arp.SetReply (cache->GetDevice ()->GetAddress (),
cache->GetInterface ()->GetAddress (),
toMac, toIp);