Allow ARP resolution to work with broadcast IPv4 (dest=255.255.255.255) packets; Partially fixes bug #36.
This commit is contained in:
@@ -109,6 +109,8 @@ ArpCache::Lookup (Ipv4Address to)
|
||||
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;
|
||||
|
||||
@@ -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 @@ ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest)
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -87,6 +87,13 @@ ArpL3Protocol::Receive(Packet& packet, Ptr<NetDevice> device)
|
||||
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 @@ ArpL3Protocol::Receive(Packet& packet, Ptr<NetDevice> device)
|
||||
// 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 @@ void
|
||||
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 @@ void
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user