src/internet-stack/arp-l3-protocol.cc
author Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
Tue, 08 Sep 2009 06:29:26 +0200
changeset 4764 e90e1ef585b0
parent 4696 5ef92ccda11a
child 5703 9cf2221d92ec
permissions -rw-r--r--
[Bug 653] NetDevice link change callback (SetLinkChangeCallback -> AddLinkChangeCallback).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2006 INRIA
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 */
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
#include "ns3/packet.h"
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
    21
#include "ns3/log.h"
729
b5e744285e92 rename i-node to node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
    22
#include "ns3/node.h"
524
082ffdd8fbd7 move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 522
diff changeset
    23
#include "ns3/net-device.h"
3146
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
    24
#include "ns3/object-vector.h"
3152
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
    25
#include "ns3/trace-source-accessor.h"
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
    26
#include "ns3/ipv4-route.h"
524
082ffdd8fbd7 move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 522
diff changeset
    27
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1167
diff changeset
    28
#include "ipv4-l3-protocol.h"
735
a3e48148c3ac arp.h -> arp-l3-protocol.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    29
#include "arp-l3-protocol.h"
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
#include "arp-header.h"
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
#include "arp-cache.h"
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
#include "ipv4-interface.h"
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
    34
NS_LOG_COMPONENT_DEFINE ("ArpL3Protocol");
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
namespace ns3 {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
736
a27d6bd2c291 Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 735
diff changeset
    38
const uint16_t ArpL3Protocol::PROT_NUMBER = 0x0806;
294
aba9a34108d2 remove ArpL3Protocol object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 287
diff changeset
    39
2249
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
    40
NS_OBJECT_ENSURE_REGISTERED (ArpL3Protocol);
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
    41
2250
18f432098389 InterfaceId -> TypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2249
diff changeset
    42
TypeId 
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
    43
ArpL3Protocol::GetTypeId (void)
2232
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    44
{
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    45
  static TypeId tid = TypeId ("ns3::ArpL3Protocol")
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    46
    .SetParent<Object> ()
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    47
    .AddConstructor<ArpL3Protocol> ()
3146
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
    48
    .AddAttribute ("CacheList",
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
    49
                   "The list of ARP caches",
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
    50
                   ObjectVectorValue (),
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
    51
                   MakeObjectVectorAccessor (&ArpL3Protocol::m_cacheList),
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
    52
                   MakeObjectVectorChecker<ArpCache> ())
3152
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
    53
    .AddTraceSource ("Drop",
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
    54
                     "Packet dropped because not enough room in pending queue for a specific cache entry.",
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
    55
                     MakeTraceSourceAccessor (&ArpL3Protocol::m_dropTrace))
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    56
    ;
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
    57
  return tid;
2232
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    58
}
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    59
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    60
ArpL3Protocol::ArpL3Protocol ()
1178
a40440a4b2fa forgot to set the interface id
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1177
diff changeset
    61
{
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
    62
  NS_LOG_FUNCTION (this);
1178
a40440a4b2fa forgot to set the interface id
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1177
diff changeset
    63
}
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
736
a27d6bd2c291 Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 735
diff changeset
    65
ArpL3Protocol::~ArpL3Protocol ()
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
    66
{
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
    67
  NS_LOG_FUNCTION (this);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
    68
}
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    69
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    70
void 
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2498
diff changeset
    71
ArpL3Protocol::SetNode (Ptr<Node> node)
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2498
diff changeset
    72
{
3430
a8eb6b890f14 Add NS_LOG_FUNCTION calls in arp implementation
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
    73
  NS_LOG_FUNCTION (this);
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2498
diff changeset
    74
  m_node = node;
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2498
diff changeset
    75
}
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2498
diff changeset
    76
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    77
/*
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    78
 * This method is called by AddAgregate and completes the aggregation
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    79
 * by setting the node in the ipv4 stack
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    80
 */
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    81
void
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    82
ArpL3Protocol::NotifyNewAggregate ()
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    83
{
4669
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4603
diff changeset
    84
  if (m_node == 0)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    85
    {
4669
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4603
diff changeset
    86
      Ptr<Node>node = this->GetObject<Node> ();
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4603
diff changeset
    87
      //verify that it's a valid node and that
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4603
diff changeset
    88
      //the node was not set before
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4603
diff changeset
    89
      if (node != 0)
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4603
diff changeset
    90
        {
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4603
diff changeset
    91
          this->SetNode (node);
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4603
diff changeset
    92
        }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    93
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    94
  Object::NotifyNewAggregate ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    95
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    96
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2498
diff changeset
    97
void 
736
a27d6bd2c291 Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 735
diff changeset
    98
ArpL3Protocol::DoDispose (void)
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    99
{
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   100
  NS_LOG_FUNCTION (this);
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   101
  for (CacheList::iterator i = m_cacheList.begin (); i != m_cacheList.end (); ++i)
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   102
    {
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   103
      Ptr<ArpCache> cache = *i;
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   104
      cache->Dispose ();
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   105
    }
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   106
  m_cacheList.clear ();
552
b5f29caf9d8c convert Arp code to use Ptr<Node> instead of Node *
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 551
diff changeset
   107
  m_node = 0;
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1167
diff changeset
   108
  Object::DoDispose ();
248
a912210e52ac fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   109
}
a912210e52ac fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   110
3147
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   111
Ptr<ArpCache> 
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   112
ArpL3Protocol::CreateCache (Ptr<NetDevice> device, Ptr<Ipv4Interface> interface)
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   113
{
3765
a2c60d47218b add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   114
  NS_LOG_FUNCTION (this << device << interface);
3147
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   115
  Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   116
  Ptr<ArpCache> cache = CreateObject<ArpCache> ();
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   117
  cache->SetDevice (device, interface);
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   118
  NS_ASSERT (device->IsBroadcast ());
4764
e90e1ef585b0 [Bug 653] NetDevice link change callback (SetLinkChangeCallback -> AddLinkChangeCallback).
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 4696
diff changeset
   119
  device->AddLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache));
3499
a18520551cdf revised patch to fix bug 253
Tom Henderson <tomh@tomh.org>
parents: 3462
diff changeset
   120
  cache->SetArpRequestCallback (MakeCallback (&ArpL3Protocol::SendArpRequest, this));
3147
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   121
  m_cacheList.push_back (cache);
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   122
  return cache;
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   123
}
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   124
3146
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
   125
Ptr<ArpCache>
736
a27d6bd2c291 Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 735
diff changeset
   126
ArpL3Protocol::FindCache (Ptr<NetDevice> device)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   127
{
3765
a2c60d47218b add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   128
  NS_LOG_FUNCTION (this << device);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   129
  for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++)
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   130
    {
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 552
diff changeset
   131
      if ((*i)->GetDevice () == device)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
	{
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
	  return *i;
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   134
	}
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
    }
3147
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   136
  NS_ASSERT (false);
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   137
  // quiet compiler
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   138
  return 0;
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
}
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
void 
3548
e5ab96db540e bug 273: constify packet pointers.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3499
diff changeset
   142
ArpL3Protocol::Receive(Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
3448
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3260
diff changeset
   143
                       const Address &to, NetDevice::PacketType packetType)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   144
{
3765
a2c60d47218b add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   145
  NS_LOG_FUNCTION (this << device << p->GetSize () << protocol << from << to << packetType);
3448
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3260
diff changeset
   146
3548
e5ab96db540e bug 273: constify packet pointers.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3499
diff changeset
   147
  Ptr<Packet> packet = p->Copy ();
e5ab96db540e bug 273: constify packet pointers.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3499
diff changeset
   148
4170
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   149
  NS_LOG_LOGIC ("ARP: received packet of size "<< packet->GetSize ());
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   150
3146
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
   151
  Ptr<ArpCache> cache = FindCache (device);
4170
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   152
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   153
  // 
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   154
  // If we're connected to a real world network, then some of the fields sizes 
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   155
  // in an ARP packet can vary in ways not seen in simulations.  We need to be
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   156
  // able to detect ARP packets with headers we don't recongnize and not process
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   157
  // them instead of crashing.  The ArpHeader will return 0 if it can't deal
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   158
  // with the received header.
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   159
  //
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   160
  ArpHeader arp;
4170
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   161
  uint32_t size = packet->RemoveHeader (arp);
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   162
  if (size == 0)
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   163
    {
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   164
      NS_LOG_LOGIC ("ARP: Cannot remove ARP header");
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   165
      return;
8e5bdeb6a71b turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents: 3823
diff changeset
   166
    }
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   167
  NS_LOG_LOGIC ("ARP: received "<< (arp.IsRequest ()? "request" : "reply") <<
933
df68dad55087 WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   168
            " node="<<m_node->GetId ()<<", got request from " <<
df68dad55087 WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   169
            arp.GetSourceIpv4Address () << " for address " <<
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   170
            arp.GetDestinationIpv4Address () << "; we have addresses: ");
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   171
  for (uint32_t i = 0; i < cache->GetInterface ()->GetNAddresses (); i++)
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   172
    {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   173
      NS_LOG_LOGIC (cache->GetInterface ()->GetAddress (i).GetLocal () << ", ");
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   174
    }
933
df68dad55087 WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   175
2919
d2d179640630 bug 107
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   176
  /**
d2d179640630 bug 107
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   177
   * Note: we do not update the ARP cache when we receive an ARP request
d2d179640630 bug 107
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   178
   * from an unknown node. See bug #107
d2d179640630 bug 107
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   179
   */
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   180
  bool found = false;
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   181
  for (uint32_t i = 0; i < cache->GetInterface ()->GetNAddresses (); i++)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
    {
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   183
      if (arp.IsRequest () && arp.GetDestinationIpv4Address () == 
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   184
        cache->GetInterface ()->GetAddress (i).GetLocal ()) 
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   185
        {
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   186
          found = true;
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   187
          NS_LOG_LOGIC ("node="<<m_node->GetId () <<", got request from " << 
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   188
                arp.GetSourceIpv4Address () << " -- send reply");
4696
5ef92ccda11a Route lookup removed in ARP request (see bug 606)
Pavel Boyko <boyko@iitp.ru>
parents: 4669
diff changeset
   189
          SendArpReply (cache, arp.GetDestinationIpv4Address (), arp.GetSourceIpv4Address (),
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   190
                    arp.GetSourceHardwareAddress ());
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   191
          break;
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   192
        } 
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   193
      else if (arp.IsReply () && 
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   194
        arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress (i).GetLocal ()) &&
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   195
        arp.GetDestinationHardwareAddress () == device->GetAddress ()) 
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   196
        {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   197
          found = true;
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   198
          Ipv4Address from = arp.GetSourceIpv4Address ();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   199
          ArpCache::Entry *entry = cache->Lookup (from);
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   200
          if (entry != 0)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   201
            {
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   202
              if (entry->IsWaitReply ()) 
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   203
                {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   204
                  NS_LOG_LOGIC ("node="<< m_node->GetId () << 
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   205
                    ", got reply from " << arp.GetSourceIpv4Address ()
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   206
                     << " for waiting entry -- flush");
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   207
                  Address from_mac = arp.GetSourceHardwareAddress ();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   208
                  entry->MarkAlive (from_mac);
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   209
                  Ptr<Packet> pending = entry->DequeuePending();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   210
                  while (pending != 0)
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   211
                    {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   212
                      cache->GetInterface ()->Send (pending,
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   213
                                                arp.GetSourceIpv4Address ());
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   214
                      pending = entry->DequeuePending();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   215
                    }
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   216
                } 
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   217
              else 
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   218
                {
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   219
                  // ignore this reply which might well be an attempt 
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   220
                  // at poisening my arp cache.
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   221
                  NS_LOG_LOGIC("node="<<m_node->GetId ()<<", got reply from " << 
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   222
                        arp.GetSourceIpv4Address () << 
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   223
                        " for non-waiting entry -- drop");
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   224
                  m_dropTrace (packet);
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   225
                }
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
            } 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   227
          else 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   228
            {
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   229
              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got reply for unknown entry -- drop");
3152
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
   230
              m_dropTrace (packet);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   231
            }
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   232
          break;
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   233
        }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   234
    }
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   235
  if (found == false)
933
df68dad55087 WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   236
    {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   237
      NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got request from " <<
933
df68dad55087 WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   238
                arp.GetSourceIpv4Address () << " for unknown address " <<
df68dad55087 WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   239
                arp.GetDestinationIpv4Address () << " -- drop");
df68dad55087 WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   240
    }
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   241
}
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   242
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   243
bool 
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1505
diff changeset
   244
ArpL3Protocol::Lookup (Ptr<Packet> packet, Ipv4Address destination, 
1161
bb72baff8b26 replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 746
diff changeset
   245
                       Ptr<NetDevice> device,
3147
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   246
                       Ptr<ArpCache> cache,
1161
bb72baff8b26 replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 746
diff changeset
   247
                       Address *hardwareDestination)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   248
{
3765
a2c60d47218b add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   249
  NS_LOG_FUNCTION (this << packet << destination << device << cache);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   250
  ArpCache::Entry *entry = cache->Lookup (destination);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   251
  if (entry != 0)
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   252
    {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   253
      if (entry->IsExpired ()) 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   254
        {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   255
          if (entry->IsDead ()) 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   256
            {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   257
              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
321
452a9cdad112 improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 303
diff changeset
   258
                        ", dead entry for " << destination << " expired -- send arp request");
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   259
              entry->MarkWaitReply (packet);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   260
              SendArpRequest (cache, destination);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   261
            } 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   262
          else if (entry->IsAlive ()) 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   263
            {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   264
              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
321
452a9cdad112 improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 303
diff changeset
   265
                        ", alive entry for " << destination << " expired -- send arp request");
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   266
              entry->MarkWaitReply (packet);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   267
              SendArpRequest (cache, destination);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   268
            } 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   269
          else if (entry->IsWaitReply ()) 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   270
            {
3823
761f94afe2a2 Fix bug 362; cancel WaitReplyTimer when ArpCache is flushed
Tom Henderson <tomh@tomh.org>
parents: 3765
diff changeset
   271
              NS_FATAL_ERROR ("Test for possibly unreachable code-- please file a bug report, with a test case, if this is ever hit");
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   272
            }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   273
        } 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   274
      else 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   275
        {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   276
          if (entry->IsDead ()) 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   277
            {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   278
              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   279
                            ", dead entry for " << destination << " valid -- drop");
3152
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
   280
              m_dropTrace (packet);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   281
            } 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   282
          else if (entry->IsAlive ()) 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   283
            {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   284
              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   285
                            ", alive entry for " << destination << " valid -- send");
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   286
	      *hardwareDestination = entry->GetMacAddress ();
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   287
              return true;
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   288
            } 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   289
          else if (entry->IsWaitReply ()) 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   290
            {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   291
              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   292
                            ", wait reply for " << destination << " valid -- drop previous");
3152
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
   293
              if (!entry->UpdateWaitReply (packet))
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
   294
                {
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
   295
                  m_dropTrace (packet);
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
   296
                }
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   297
            }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   298
        }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   299
    }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   300
  else
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   301
    {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   302
      // This is our first attempt to transmit data to this destination.
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   303
      NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
321
452a9cdad112 improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 303
diff changeset
   304
                ", no entry for " << destination << " -- send arp request");
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   305
      entry = cache->Add (destination);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   306
      entry->MarkWaitReply (packet);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   307
      SendArpRequest (cache, destination);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   308
    }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   309
  return false;
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   310
}
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   311
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   312
void
3146
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
   313
ArpL3Protocol::SendArpRequest (Ptr<const ArpCache> cache, Ipv4Address to)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   314
{
3765
a2c60d47218b add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   315
  NS_LOG_FUNCTION (this << cache << to);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   316
  ArpHeader arp;
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   317
  // need to pick a source address; use routing implementation to select
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   318
  Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   319
  int32_t interface = ipv4->GetInterfaceForDevice (cache->GetDevice ());
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   320
  NS_ASSERT (interface >= 0);
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   321
  Ipv4Header header;
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   322
  header.SetDestination (to);
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   323
  Socket::SocketErrno errno_;
4603
67a0a49c1db4 bug 592: Ipv4RoutingProtocol::RouteOutput needs a packet pointer argument for reactive protocols
Josh Pelkey <joshpelkey@gmail.com>
parents: 4571
diff changeset
   324
  Ptr<Packet> packet = Create<Packet> ();
67a0a49c1db4 bug 592: Ipv4RoutingProtocol::RouteOutput needs a packet pointer argument for reactive protocols
Josh Pelkey <joshpelkey@gmail.com>
parents: 4571
diff changeset
   325
  Ptr<Ipv4Route> route = ipv4->GetRoutingProtocol ()->RouteOutput (packet, header, interface, errno_);
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   326
  NS_ASSERT (route != 0);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   327
  NS_LOG_LOGIC ("ARP: sending request from node "<<m_node->GetId ()<<
933
df68dad55087 WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   328
            " || src: " << cache->GetDevice ()->GetAddress () <<
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   329
            " / " << route->GetSource () <<
933
df68dad55087 WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   330
            " || dst: " << cache->GetDevice ()->GetBroadcast () <<
df68dad55087 WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   331
            " / " << to);
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 552
diff changeset
   332
  arp.SetRequest (cache->GetDevice ()->GetAddress (),
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   333
		  route->GetSource (),
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 552
diff changeset
   334
                  cache->GetDevice ()->GetBroadcast (),
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   335
                  to);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1505
diff changeset
   336
  packet->AddHeader (arp);
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 552
diff changeset
   337
  cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), PROT_NUMBER);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   338
}
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   339
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   340
void
4696
5ef92ccda11a Route lookup removed in ARP request (see bug 606)
Pavel Boyko <boyko@iitp.ru>
parents: 4669
diff changeset
   341
ArpL3Protocol::SendArpReply (Ptr<const ArpCache> cache, Ipv4Address myIp, Ipv4Address toIp, Address toMac)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   342
{
3765
a2c60d47218b add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   343
  NS_LOG_FUNCTION (this << cache << toIp << toMac);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   344
  ArpHeader arp;
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   345
  NS_LOG_LOGIC ("ARP: sending reply from node "<<m_node->GetId ()<<
933
df68dad55087 WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   346
            "|| src: " << cache->GetDevice ()->GetAddress () << 
4696
5ef92ccda11a Route lookup removed in ARP request (see bug 606)
Pavel Boyko <boyko@iitp.ru>
parents: 4669
diff changeset
   347
            " / " << myIp <<
933
df68dad55087 WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   348
            " || dst: " << toMac << " / " << toIp);
4696
5ef92ccda11a Route lookup removed in ARP request (see bug 606)
Pavel Boyko <boyko@iitp.ru>
parents: 4669
diff changeset
   349
  arp.SetReply (cache->GetDevice ()->GetAddress (), myIp, toMac, toIp);
5ef92ccda11a Route lookup removed in ARP request (see bug 606)
Pavel Boyko <boyko@iitp.ru>
parents: 4669
diff changeset
   350
  Ptr<Packet> packet = Create<Packet> ();
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1505
diff changeset
   351
  packet->AddHeader (arp);
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 552
diff changeset
   352
  cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   353
}
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   354
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   355
}//namespace ns3