re-organize the ARP code to expose arp cache attributes.
This commit is contained in:
@@ -24,16 +24,34 @@
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/net-device.h"
|
||||
#include "ns3/address.h"
|
||||
#include "ns3/pointer.h"
|
||||
|
||||
#include "arp-ipv4-interface.h"
|
||||
#include "ipv4-l3-protocol.h"
|
||||
#include "arp-l3-protocol.h"
|
||||
#include "arp-cache.h"
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("ArpIpv4Interface");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
TypeId
|
||||
ArpIpv4Interface::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::ArpIpv4Interface")
|
||||
.SetParent<Ipv4Interface> ()
|
||||
.AddAttribute ("ArpCache",
|
||||
"The arp cache for this ipv4 interface",
|
||||
PointerValue (0),
|
||||
MakePointerAccessor (&ArpIpv4Interface::m_cache),
|
||||
MakePointerChecker<ArpIpv4Interface> ())
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
ArpIpv4Interface::ArpIpv4Interface ()
|
||||
: m_node (0),
|
||||
m_device (0)
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
}
|
||||
@@ -48,17 +66,20 @@ ArpIpv4Interface::DoDispose (void)
|
||||
{
|
||||
m_node = 0;
|
||||
m_device = 0;
|
||||
m_cache = 0;
|
||||
}
|
||||
|
||||
void
|
||||
ArpIpv4Interface::SetNode (Ptr<Node> node)
|
||||
{
|
||||
m_node = node;
|
||||
DoSetup ();
|
||||
}
|
||||
void
|
||||
ArpIpv4Interface::SetDevice (Ptr<NetDevice> device)
|
||||
{
|
||||
m_device = device;
|
||||
DoSetup ();
|
||||
}
|
||||
|
||||
Ptr<NetDevice>
|
||||
@@ -67,13 +88,24 @@ ArpIpv4Interface::GetDevice (void) const
|
||||
return m_device;
|
||||
}
|
||||
|
||||
void
|
||||
ArpIpv4Interface::DoSetup (void)
|
||||
{
|
||||
if (m_node == 0 || m_device == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Ptr<ArpL3Protocol> arp = m_node->GetObject<ArpL3Protocol> ();
|
||||
m_cache = arp->CreateCache (m_device, this);
|
||||
}
|
||||
|
||||
void
|
||||
ArpIpv4Interface::SendTo (Ptr<Packet> p, Ipv4Address dest)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << p << dest);
|
||||
|
||||
NS_ASSERT (GetDevice () != 0);
|
||||
if (GetDevice ()->NeedsArp ())
|
||||
if (m_device->NeedsArp ())
|
||||
{
|
||||
NS_LOG_LOGIC ("Needs ARP");
|
||||
Ptr<ArpL3Protocol> arp =
|
||||
@@ -101,7 +133,7 @@ ArpIpv4Interface::SendTo (Ptr<Packet> p, Ipv4Address dest)
|
||||
else
|
||||
{
|
||||
NS_LOG_LOGIC ("ARP Lookup");
|
||||
found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination);
|
||||
found = arp->Lookup (p, dest, GetDevice (), m_cache, &hardwareDestination);
|
||||
}
|
||||
|
||||
if (found)
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
namespace ns3 {
|
||||
|
||||
class Node;
|
||||
class ArpCache;
|
||||
|
||||
/**
|
||||
* \brief an Ipv4 Interface which uses ARP
|
||||
@@ -37,7 +38,9 @@ class Node;
|
||||
*/
|
||||
class ArpIpv4Interface : public Ipv4Interface
|
||||
{
|
||||
public:
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
|
||||
ArpIpv4Interface ();
|
||||
virtual ~ArpIpv4Interface ();
|
||||
|
||||
@@ -49,8 +52,10 @@ class ArpIpv4Interface : public Ipv4Interface
|
||||
private:
|
||||
virtual void SendTo (Ptr<Packet> p, Ipv4Address dest);
|
||||
virtual void DoDispose (void);
|
||||
void DoSetup (void);
|
||||
Ptr<Node> m_node;
|
||||
Ptr<NetDevice> m_device;
|
||||
Ptr<ArpCache> m_cache;
|
||||
};
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
@@ -76,6 +76,18 @@ ArpL3Protocol::DoDispose (void)
|
||||
Object::DoDispose ();
|
||||
}
|
||||
|
||||
Ptr<ArpCache>
|
||||
ArpL3Protocol::CreateCache (Ptr<NetDevice> device, Ptr<Ipv4Interface> interface)
|
||||
{
|
||||
Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
|
||||
Ptr<ArpCache> cache = CreateObject<ArpCache> ();
|
||||
cache->SetDevice (device, interface);
|
||||
NS_ASSERT (device->IsBroadcast ());
|
||||
device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache));
|
||||
m_cacheList.push_back (cache);
|
||||
return cache;
|
||||
}
|
||||
|
||||
Ptr<ArpCache>
|
||||
ArpL3Protocol::FindCache (Ptr<NetDevice> device)
|
||||
{
|
||||
@@ -87,14 +99,9 @@ ArpL3Protocol::FindCache (Ptr<NetDevice> device)
|
||||
return *i;
|
||||
}
|
||||
}
|
||||
Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
|
||||
Ptr<Ipv4Interface> interface = ipv4->FindInterfaceForDevice (device);
|
||||
Ptr<ArpCache> cache = CreateObject<ArpCache> ();
|
||||
cache->SetDevice (device, interface);
|
||||
NS_ASSERT (device->IsBroadcast ());
|
||||
device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache));
|
||||
m_cacheList.push_back (cache);
|
||||
return cache;
|
||||
NS_ASSERT (false);
|
||||
// quiet compiler
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -167,10 +174,10 @@ ArpL3Protocol::Receive(Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t proto
|
||||
bool
|
||||
ArpL3Protocol::Lookup (Ptr<Packet> packet, Ipv4Address destination,
|
||||
Ptr<NetDevice> device,
|
||||
Ptr<ArpCache> cache,
|
||||
Address *hardwareDestination)
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
Ptr<ArpCache> cache = FindCache (device);
|
||||
ArpCache::Entry *entry = cache->Lookup (destination);
|
||||
if (entry != 0)
|
||||
{
|
||||
|
||||
@@ -46,6 +46,8 @@ public:
|
||||
|
||||
void SetNode (Ptr<Node> node);
|
||||
|
||||
Ptr<ArpCache> CreateCache (Ptr<NetDevice> device, Ptr<Ipv4Interface> interface);
|
||||
|
||||
/**
|
||||
* \brief Recieve a packet
|
||||
*/
|
||||
@@ -60,6 +62,7 @@ public:
|
||||
*/
|
||||
bool Lookup (Ptr<Packet> p, Ipv4Address destination,
|
||||
Ptr<NetDevice> device,
|
||||
Ptr<ArpCache> cache,
|
||||
Address *hardwareDestination);
|
||||
protected:
|
||||
virtual void DoDispose (void);
|
||||
|
||||
@@ -31,6 +31,15 @@ NS_LOG_COMPONENT_DEFINE ("Ipv4LoopbackInterface");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
TypeId
|
||||
Ipv4LoopbackInterface::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::Ipv4LoopbackInterface")
|
||||
.SetParent<Ipv4Interface> ()
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
Ipv4LoopbackInterface::Ipv4LoopbackInterface ()
|
||||
: m_node (0)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,8 @@ class Node;
|
||||
*/
|
||||
class Ipv4LoopbackInterface : public Ipv4Interface
|
||||
{
|
||||
public:
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
Ipv4LoopbackInterface ();
|
||||
virtual ~Ipv4LoopbackInterface ();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user