src/internet-stack/arp-l3-protocol.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 12 Jun 2009 13:44:19 -0700
changeset 4560 2f106fd728ab
parent 4472 e20a31541404
child 4571 2c9c600270e0
permissions -rw-r--r--
Remove static routing dependencies in code
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"
524
082ffdd8fbd7 move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 522
diff changeset
    26
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1167
diff changeset
    27
#include "ipv4-l3-protocol.h"
735
a3e48148c3ac arp.h -> arp-l3-protocol.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    28
#include "arp-l3-protocol.h"
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
#include "arp-header.h"
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
#include "arp-cache.h"
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
#include "ipv4-interface.h"
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
    33
NS_LOG_COMPONENT_DEFINE ("ArpL3Protocol");
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
namespace ns3 {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
736
a27d6bd2c291 Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 735
diff changeset
    37
const uint16_t ArpL3Protocol::PROT_NUMBER = 0x0806;
294
aba9a34108d2 remove ArpL3Protocol object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 287
diff changeset
    38
2249
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
    39
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
    40
2250
18f432098389 InterfaceId -> TypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2249
diff changeset
    41
TypeId 
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
    42
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
    43
{
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    44
  static TypeId tid = TypeId ("ns3::ArpL3Protocol")
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    45
    .SetParent<Object> ()
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    46
    .AddConstructor<ArpL3Protocol> ()
3146
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
    47
    .AddAttribute ("CacheList",
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
    48
                   "The list of ARP caches",
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
    49
                   ObjectVectorValue (),
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
    50
                   MakeObjectVectorAccessor (&ArpL3Protocol::m_cacheList),
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
    51
                   MakeObjectVectorChecker<ArpCache> ())
3152
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
    52
    .AddTraceSource ("Drop",
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
    53
                     "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
    54
                     MakeTraceSourceAccessor (&ArpL3Protocol::m_dropTrace))
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    55
    ;
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
    56
  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
    57
}
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    58
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    59
ArpL3Protocol::ArpL3Protocol ()
1178
a40440a4b2fa forgot to set the interface id
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1177
diff changeset
    60
{
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
    61
  NS_LOG_FUNCTION (this);
1178
a40440a4b2fa forgot to set the interface id
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1177
diff changeset
    62
}
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
736
a27d6bd2c291 Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 735
diff changeset
    64
ArpL3Protocol::~ArpL3Protocol ()
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
    65
{
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
    66
  NS_LOG_FUNCTION (this);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
    67
}
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    68
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    69
void 
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2498
diff changeset
    70
ArpL3Protocol::SetNode (Ptr<Node> node)
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2498
diff changeset
    71
{
3430
a8eb6b890f14 Add NS_LOG_FUNCTION calls in arp implementation
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
    72
  NS_LOG_FUNCTION (this);
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2498
diff changeset
    73
  m_node = node;
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2498
diff changeset
    74
}
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2498
diff changeset
    75
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    76
/*
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    77
 * 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
    78
 * 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
    79
 */
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    80
void
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    81
ArpL3Protocol::NotifyNewAggregate ()
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    82
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    83
  Ptr<Node>node = this->GetObject<Node> ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    84
  //verify that it's a valid node and that
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    85
  //the node was not set before
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    86
  if (node!= 0 && m_node == 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    87
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    88
      this->SetNode (node);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    89
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    90
  Object::NotifyNewAggregate ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    91
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    92
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2498
diff changeset
    93
void 
736
a27d6bd2c291 Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 735
diff changeset
    94
ArpL3Protocol::DoDispose (void)
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    95
{
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
    96
  NS_LOG_FUNCTION (this);
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
    97
  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
    98
    {
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
    99
      Ptr<ArpCache> cache = *i;
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   100
      cache->Dispose ();
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   101
    }
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   102
  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
   103
  m_node = 0;
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1167
diff changeset
   104
  Object::DoDispose ();
248
a912210e52ac fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   105
}
a912210e52ac fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   106
3147
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   107
Ptr<ArpCache> 
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   108
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
   109
{
3765
a2c60d47218b add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   110
  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
   111
  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
   112
  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
   113
  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
   114
  NS_ASSERT (device->IsBroadcast ());
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   115
  device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache));
3499
a18520551cdf revised patch to fix bug 253
Tom Henderson <tomh@tomh.org>
parents: 3462
diff changeset
   116
  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
   117
  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
   118
  return cache;
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   119
}
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   120
3146
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
   121
Ptr<ArpCache>
736
a27d6bd2c291 Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 735
diff changeset
   122
ArpL3Protocol::FindCache (Ptr<NetDevice> device)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   123
{
3765
a2c60d47218b add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   124
  NS_LOG_FUNCTION (this << device);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   125
  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
   126
    {
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 552
diff changeset
   127
      if ((*i)->GetDevice () == device)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   128
	{
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   129
	  return *i;
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   130
	}
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
    }
3147
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   132
  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
   133
  // quiet compiler
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3146
diff changeset
   134
  return 0;
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
}
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   137
void 
3548
e5ab96db540e bug 273: constify packet pointers.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3499
diff changeset
   138
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
   139
                       const Address &to, NetDevice::PacketType packetType)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
{
3765
a2c60d47218b add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   141
  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
   142
3548
e5ab96db540e bug 273: constify packet pointers.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3499
diff changeset
   143
  Ptr<Packet> packet = p->Copy ();
e5ab96db540e bug 273: constify packet pointers.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3499
diff changeset
   144
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
   145
  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
   146
3146
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
   147
  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
   148
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
  // 
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
  // 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
   151
  // 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
   152
  // 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
   153
  // 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
   154
  // 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
   155
  //
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
  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
   157
  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
   158
  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
   159
    {
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
   160
      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
   161
      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
   162
    }
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4170
diff changeset
   163
  // XXX multi-address case  
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   164
  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
   165
            " 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
   166
            arp.GetSourceIpv4Address () << " for 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
   167
            arp.GetDestinationIpv4Address () << "; we have address " <<
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4170
diff changeset
   168
            cache->GetInterface ()->GetAddress (0).GetLocal ());
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
   169
2919
d2d179640630 bug 107
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   170
  /**
d2d179640630 bug 107
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   171
   * 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
   172
   * from an unknown node. See bug #107
d2d179640630 bug 107
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   173
   */
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4170
diff changeset
   174
  // XXX multi-address case
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   175
  if (arp.IsRequest () && 
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4170
diff changeset
   176
      arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress (0).GetLocal ()) 
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   177
    {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   178
      NS_LOG_LOGIC ("node="<<m_node->GetId () <<", got request from " << 
321
452a9cdad112 improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 303
diff changeset
   179
                arp.GetSourceIpv4Address () << " -- send reply");
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   180
      SendArpReply (cache, arp.GetSourceIpv4Address (),
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   181
                    arp.GetSourceHardwareAddress ());
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
    } 
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4170
diff changeset
   183
  // XXX multi-address case
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
  else if (arp.IsReply () &&
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4170
diff changeset
   185
           arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress (0).GetLocal ()) &&
1161
bb72baff8b26 replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 746
diff changeset
   186
           arp.GetDestinationHardwareAddress () == device->GetAddress ()) 
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   187
    {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
      Ipv4Address from = arp.GetSourceIpv4Address ();
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   189
      ArpCache::Entry *entry = cache->Lookup (from);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   190
      if (entry != 0)
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   191
        {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   192
          if (entry->IsWaitReply ()) 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   193
            {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   194
              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got reply from " << 
321
452a9cdad112 improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 303
diff changeset
   195
                        arp.GetSourceIpv4Address ()
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   196
                     << " for waiting entry -- flush");
1161
bb72baff8b26 replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 746
diff changeset
   197
              Address from_mac = arp.GetSourceHardwareAddress ();
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   198
              entry->MarkAlive (from_mac);
3177
8ce20d798105 DequeuePending returns 0 upon error, not the other way round.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3152
diff changeset
   199
              Ptr<Packet> pending = entry->DequeuePending();
8ce20d798105 DequeuePending returns 0 upon error, not the other way round.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3152
diff changeset
   200
              while (pending != 0)
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   201
                {
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   202
                  cache->GetInterface ()->Send (pending,
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   203
                                                arp.GetSourceIpv4Address ());
3177
8ce20d798105 DequeuePending returns 0 upon error, not the other way round.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3152
diff changeset
   204
                  pending = entry->DequeuePending();
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   205
                }
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   206
            } 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   207
          else 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   208
            {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   209
              // ignore this reply which might well be an attempt 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   210
              // at poisening my arp cache.
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   211
              NS_LOG_LOGIC("node="<<m_node->GetId ()<<", got reply from " << 
321
452a9cdad112 improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 303
diff changeset
   212
                        arp.GetSourceIpv4Address () << 
452a9cdad112 improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 303
diff changeset
   213
                        " for non-waiting entry -- drop");
3152
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
   214
              m_dropTrace (packet);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   215
            }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   216
        } 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   217
      else 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   218
        {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   219
          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
   220
          m_dropTrace (packet);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   221
        }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   222
    }
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
   223
  else
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
   224
    {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   225
      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
   226
                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
   227
                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
   228
    }
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   229
}
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   230
bool 
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1505
diff changeset
   231
ArpL3Protocol::Lookup (Ptr<Packet> packet, Ipv4Address destination, 
1161
bb72baff8b26 replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 746
diff changeset
   232
                       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
   233
                       Ptr<ArpCache> cache,
1161
bb72baff8b26 replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 746
diff changeset
   234
                       Address *hardwareDestination)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   235
{
3765
a2c60d47218b add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   236
  NS_LOG_FUNCTION (this << packet << destination << device << cache);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   237
  ArpCache::Entry *entry = cache->Lookup (destination);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   238
  if (entry != 0)
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   239
    {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   240
      if (entry->IsExpired ()) 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   241
        {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   242
          if (entry->IsDead ()) 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   243
            {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   244
              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
321
452a9cdad112 improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 303
diff changeset
   245
                        ", dead entry for " << destination << " expired -- send arp request");
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   246
              entry->MarkWaitReply (packet);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   247
              SendArpRequest (cache, destination);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   248
            } 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   249
          else if (entry->IsAlive ()) 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   250
            {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   251
              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
321
452a9cdad112 improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 303
diff changeset
   252
                        ", alive entry for " << destination << " expired -- send arp request");
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   253
              entry->MarkWaitReply (packet);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   254
              SendArpRequest (cache, destination);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   255
            } 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   256
          else if (entry->IsWaitReply ()) 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   257
            {
3823
761f94afe2a2 Fix bug 362; cancel WaitReplyTimer when ArpCache is flushed
Tom Henderson <tomh@tomh.org>
parents: 3765
diff changeset
   258
              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
   259
            }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   260
        } 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   261
      else 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   262
        {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   263
          if (entry->IsDead ()) 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   264
            {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   265
              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   266
                            ", dead entry for " << destination << " valid -- drop");
3152
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
   267
              m_dropTrace (packet);
242
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->IsAlive ()) 
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   270
            {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   271
              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
3151
428f8ec6da29 fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
   272
                            ", alive entry for " << destination << " valid -- send");
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   273
	      *hardwareDestination = entry->GetMacAddress ();
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   274
              return true;
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
          else if (entry->IsWaitReply ()) 
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
                            ", 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
   280
              if (!entry->UpdateWaitReply (packet))
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
   281
                {
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
   282
                  m_dropTrace (packet);
4260de124c74 report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3151
diff changeset
   283
                }
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   284
            }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   285
        }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   286
    }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   287
  else
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
      // 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
   290
      NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
321
452a9cdad112 improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 303
diff changeset
   291
                ", no entry for " << destination << " -- send arp request");
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   292
      entry = cache->Add (destination);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   293
      entry->MarkWaitReply (packet);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   294
      SendArpRequest (cache, destination);
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   295
    }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   296
  return false;
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
void
3146
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
   300
ArpL3Protocol::SendArpRequest (Ptr<const ArpCache> cache, Ipv4Address to)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   301
{
3765
a2c60d47218b add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   302
  NS_LOG_FUNCTION (this << cache << to);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   303
  ArpHeader arp;
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   304
  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
   305
            " || src: " << cache->GetDevice ()->GetAddress () <<
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4170
diff changeset
   306
            " / " << cache->GetInterface ()->GetAddress (0).GetLocal () <<
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
   307
            " || 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
   308
            " / " << to);
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4170
diff changeset
   309
  // XXX multi-address case
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 552
diff changeset
   310
  arp.SetRequest (cache->GetDevice ()->GetAddress (),
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4170
diff changeset
   311
		  cache->GetInterface ()->GetAddress (0).GetLocal (), 
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 552
diff changeset
   312
                  cache->GetDevice ()->GetBroadcast (),
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   313
                  to);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1505
diff changeset
   314
  Ptr<Packet> packet = Create<Packet> ();
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1505
diff changeset
   315
  packet->AddHeader (arp);
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 552
diff changeset
   316
  cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), PROT_NUMBER);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   317
}
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   318
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   319
void
3146
98629e087bb1 add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2987
diff changeset
   320
ArpL3Protocol::SendArpReply (Ptr<const ArpCache> cache, Ipv4Address toIp, Address toMac)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   321
{
3765
a2c60d47218b add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   322
  NS_LOG_FUNCTION (this << cache << toIp << toMac);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   323
  ArpHeader arp;
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1412
diff changeset
   324
  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
   325
            "|| src: " << cache->GetDevice ()->GetAddress () << 
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4170
diff changeset
   326
            " / " << cache->GetInterface ()->GetAddress (0).GetLocal () <<
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
   327
            " || dst: " << toMac << " / " << toIp);
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4170
diff changeset
   328
  // XXX multi-address case
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 552
diff changeset
   329
  arp.SetReply (cache->GetDevice ()->GetAddress (),
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4170
diff changeset
   330
                cache->GetInterface ()->GetAddress (0).GetLocal (),
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   331
                toMac, toIp);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1505
diff changeset
   332
  Ptr<Packet> packet = Create<Packet> ();
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1505
diff changeset
   333
  packet->AddHeader (arp);
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 552
diff changeset
   334
  cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   335
}
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   336
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   337
}//namespace ns3