remove ArpL3Protocol object

This commit is contained in:
Mathieu Lacage
2007-02-17 09:35:50 +01:00
parent e4166af294
commit d7a398bc11
6 changed files with 18 additions and 120 deletions

View File

@@ -187,7 +187,6 @@ node.add_sources ([
'udp-socket.cc',
'udp.cc',
'arp-header.cc',
'arp-l3-protocol.cc',
'arp-cache.cc',
'arp-ipv4-interface.cc',
'arp.cc',
@@ -205,7 +204,6 @@ node.add_headers ([
'udp.h',
'ipv4-l4-protocol.h',
'udp-ipv4-l4-protocol.h',
'arp-l3-protocol.h',
'arp-header.h',
'arp-cache-cache.h',
'arp.h',

View File

@@ -1,53 +0,0 @@
// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
//
// Copyright (c) 2006 Georgia Tech Research Corporation
// 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: George F. Riley<riley@ece.gatech.edu>
//
// NS3 - Layer 3 Protocol base class
// George F. Riley, Georgia Tech, Spring 2007
#include "arp-l3-protocol.h"
#include "arp.h"
#include "node.h"
namespace ns3 {
ArpL3Protocol::ArpL3Protocol (Node *node)
: L3Protocol (0x0806, 0/* XXX: correct version number ? */ ),
m_node (node)
{}
ArpL3Protocol::~ArpL3Protocol ()
{}
ArpL3Protocol *
ArpL3Protocol::Copy (Node *node) const
{
return new ArpL3Protocol (node);
}
void
ArpL3Protocol::Receive(Packet& p, NetDevice &device)
{
Arp * arp = m_node->GetArp ();
if (arp != 0)
{
arp->Receive (p, &device);
}
}
}//namespace ns3

View File

@@ -1,49 +0,0 @@
// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
//
// Copyright (c) 2006 Georgia Tech Research Corporation
// 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: George F. Riley<riley@ece.gatech.edu>
//
// NS3 - Layer 3 Protocol base class
// George F. Riley, Georgia Tech, Spring 2007
#ifndef ARP_L3_PROTOCOL_H
#define ARP_L3_PROTOCOL_H
#include "l3-protocol.h"
namespace ns3 {
class Node;
class NetDevice;
class Packet;
class ArpL3Protocol : public L3Protocol
{
public:
ArpL3Protocol (Node *node);
virtual ~ArpL3Protocol ();
virtual ArpL3Protocol *Copy (Node *node) const;
virtual void Receive(Packet& p, NetDevice &device);
private:
Node *m_node;
};
}//namespace ns3
#endif /* ARP_L3_PROTOCOL_H */

View File

@@ -32,8 +32,11 @@ NS_DEBUG_COMPONENT_DEFINE ("Arp");
namespace ns3 {
const uint16_t Arp::PROT_NUMBER = 0x0806;
Arp::Arp (Node *node)
: m_node (node)
: L3Protocol (PROT_NUMBER, 0/* XXX: correct version number ? */ ),
m_node (node)
{}
Arp::~Arp ()
@@ -45,7 +48,7 @@ Arp::~Arp ()
}
Arp *
Arp::Copy (Node *node)
Arp::Copy (Node *node) const
{
return new Arp (node);
}
@@ -69,9 +72,9 @@ Arp::FindCache (NetDevice *device)
}
void
Arp::Receive(Packet& packet, NetDevice *device)
Arp::Receive(Packet& packet, NetDevice &device)
{
ArpCache *cache = FindCache (device);
ArpCache *cache = FindCache (&device);
ArpHeader arp;
packet.Peek (arp);
packet.Remove (arp);
@@ -84,7 +87,7 @@ Arp::Receive(Packet& packet, NetDevice *device)
}
else if (arp.IsReply () &&
arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress ()) &&
arp.GetDestinationHardwareAddress ().IsEqual (device->GetAddress ()))
arp.GetDestinationHardwareAddress ().IsEqual (device.GetAddress ()))
{
Ipv4Address from = arp.GetSourceIpv4Address ();
ArpCache::Entry *entry = cache->Lookup (from);
@@ -187,7 +190,7 @@ Arp::SendArpRequest (ArpCache const *cache, Ipv4Address to)
to);
Packet packet;
packet.Add (arp);
cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), 0x0806);
cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), PROT_NUMBER);
}
void
@@ -199,7 +202,7 @@ Arp::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac)
toMac, toIp);
Packet packet;
packet.Add (arp);
cache->GetDevice ()->Send (packet, toMac, 0x0806);
cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER);
}
}//namespace ns3

View File

@@ -24,6 +24,7 @@
#include <list>
#include "ipv4-address.h"
#include "mac-address.h"
#include "l3-protocol.h"
namespace ns3 {
@@ -32,14 +33,16 @@ class NetDevice;
class Node;
class Packet;
class Arp
class Arp : public L3Protocol
{
public:
static const uint16_t PROT_NUMBER;
Arp (Node *node);
~Arp ();
Arp *Copy (Node *node);
virtual Arp *Copy (Node *node) const;
void Receive(Packet& p, NetDevice *device);
virtual void Receive(Packet& p, NetDevice &device);
bool Lookup (Packet &p, Ipv4Address destination,
NetDevice *device,
MacAddress *hardwareDestination);

View File

@@ -29,7 +29,6 @@
#include "ipv4.h"
#include "arp.h"
#include "udp-ipv4-l4-protocol.h"
#include "arp-l3-protocol.h"
#include "ipv4-loopback-interface.h"
namespace ns3 {
@@ -41,9 +40,8 @@ InternetNode::InternetNode()
m_l3Demux = new L3Demux(this);
m_ipv4L4Demux = new Ipv4L4Demux(this);
m_udp = new Udp (this);
m_arp = new Arp (this);
m_l3Demux->Insert (Ipv4 (this));
m_l3Demux->Insert (ArpL3Protocol (this));
m_l3Demux->Insert (Arp (this));
m_ipv4L4Demux->Insert (UdpIpv4L4Protocol (this));
SetupLoopback ();
}
@@ -54,7 +52,6 @@ InternetNode::InternetNode (InternetNode const &o)
m_l3Demux = o.m_l3Demux->Copy (this);
m_ipv4L4Demux = o.m_ipv4L4Demux->Copy (this);
m_udp = o.m_udp->Copy (this);
m_arp = o.m_arp->Copy (this);
SetupLoopback ();
}
@@ -64,7 +61,6 @@ InternetNode::~InternetNode ()
delete m_l3Demux;
delete m_ipv4L4Demux;
delete m_udp;
delete m_arp;
}
void
@@ -119,7 +115,7 @@ InternetNode::GetUdp (void) const
Arp *
InternetNode::GetArp (void) const
{
return m_arp;
return static_cast<Arp*> (m_l3Demux->Lookup (Arp::PROT_NUMBER));
}