src/internet-node/arp-l3-protocol.cc
changeset 1176 4894ea885c0f
parent 1167 2cb083ff04c6
child 1177 c7bf3cf186ac
equal deleted inserted replaced
1175:00ad4ec69939 1176:4894ea885c0f
    22 #include "ns3/debug.h"
    22 #include "ns3/debug.h"
    23 #include "ns3/empty-trace-resolver.h"
    23 #include "ns3/empty-trace-resolver.h"
    24 #include "ns3/node.h"
    24 #include "ns3/node.h"
    25 #include "ns3/net-device.h"
    25 #include "ns3/net-device.h"
    26 
    26 
       
    27 #include "ipv4-l3-protocol.h"
    27 #include "arp-l3-protocol.h"
    28 #include "arp-l3-protocol.h"
    28 #include "arp-header.h"
    29 #include "arp-header.h"
    29 #include "arp-cache.h"
    30 #include "arp-cache.h"
    30 #include "ipv4-interface.h"
    31 #include "ipv4-interface.h"
    31 #include "ipv4-private.h"
       
    32 
    32 
    33 NS_DEBUG_COMPONENT_DEFINE ("ArpL3Protocol");
    33 NS_DEBUG_COMPONENT_DEFINE ("ArpL3Protocol");
    34 
    34 
    35 namespace ns3 {
    35 namespace ns3 {
    36 
    36 
    37 const uint16_t ArpL3Protocol::PROT_NUMBER = 0x0806;
    37 const uint16_t ArpL3Protocol::PROT_NUMBER = 0x0806;
    38 
    38 
    39 ArpL3Protocol::ArpL3Protocol (Ptr<Node> node)
    39 ArpL3Protocol::ArpL3Protocol (Ptr<Node> node)
    40   : L3Protocol (PROT_NUMBER, 0/* XXX: correct version number ? */ ),
    40   : m_node (node)
    41     m_node (node)
       
    42 {}
    41 {}
    43 
    42 
    44 ArpL3Protocol::~ArpL3Protocol ()
    43 ArpL3Protocol::~ArpL3Protocol ()
    45 {}
    44 {}
    46 
    45 
    51     {
    50     {
    52       delete *i;
    51       delete *i;
    53     }
    52     }
    54   m_cacheList.clear ();
    53   m_cacheList.clear ();
    55   m_node = 0;
    54   m_node = 0;
    56   L3Protocol::DoDispose ();
    55   Object::DoDispose ();
    57 }
    56 }
    58 
    57 
    59 TraceResolver *
    58 TraceResolver *
    60 ArpL3Protocol::CreateTraceResolver (TraceContext const &context)
    59 ArpL3Protocol::CreateTraceResolver (TraceContext const &context)
    61 {
    60 {
    70       if ((*i)->GetDevice () == device)
    69       if ((*i)->GetDevice () == device)
    71 	{
    70 	{
    72 	  return *i;
    71 	  return *i;
    73 	}
    72 	}
    74     }
    73     }
    75   Ptr<Ipv4Private> ipv4 = m_node->QueryInterface<Ipv4Private> (Ipv4Private::iid);
    74   Ptr<Ipv4L3Protocol> ipv4 = m_node->QueryInterface<Ipv4L3Protocol> (Ipv4L3Protocol::iid);
    76   Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device);
    75   Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device);
    77   ArpCache * cache = new ArpCache (device, interface);
    76   ArpCache * cache = new ArpCache (device, interface);
    78   NS_ASSERT (device->IsBroadcast ());
    77   NS_ASSERT (device->IsBroadcast ());
    79   device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache));
    78   device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache));
    80   m_cacheList.push_back (cache);
    79   m_cacheList.push_back (cache);
    81   return cache;
    80   return cache;
    82 }
    81 }
    83 
    82 
    84 void 
    83 void 
    85 ArpL3Protocol::Receive(Packet& packet, Ptr<NetDevice> device)
    84 ArpL3Protocol::Receive(const Packet& p, uint16_t protocol, Ptr<NetDevice> device)
    86 {
    85 {
    87   ArpCache *cache = FindCache (device);
    86   ArpCache *cache = FindCache (device);
    88   ArpHeader arp;
    87   ArpHeader arp;
       
    88   Packet packet = p;
    89   packet.RemoveHeader (arp);
    89   packet.RemoveHeader (arp);
    90   
    90   
    91   NS_DEBUG ("ARP: received "<< (arp.IsRequest ()? "request" : "reply") <<
    91   NS_DEBUG ("ARP: received "<< (arp.IsRequest ()? "request" : "reply") <<
    92             " node="<<m_node->GetId ()<<", got request from " <<
    92             " node="<<m_node->GetId ()<<", got request from " <<
    93             arp.GetSourceIpv4Address () << " for address " <<
    93             arp.GetSourceIpv4Address () << " for address " <<