author | Peter D. Barnes, Jr. <barnes26@llnl.gov> |
Fri, 26 Sep 2014 15:51:00 -0700 | |
changeset 10968 | 2d29fee2b7b8 |
parent 10652 | dc18deba4502 |
child 11046 | e62bccfbe56e |
permissions | -rw-r--r-- |
7385
10beb0e53130
standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents:
7256
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
242 | 2 |
/* |
3 |
* Copyright (c) 2006 INRIA |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License version 2 as |
|
7 |
* published by the Free Software Foundation; |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 |
* |
|
18 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
|
19 |
*/ |
|
20 |
#include "ns3/packet.h" |
|
1505 | 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" |
10151
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
26 |
#include "ns3/pointer.h" |
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
27 |
#include "ns3/string.h" |
524
082ffdd8fbd7
move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
522
diff
changeset
|
28 |
|
1176
4894ea885c0f
implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
29 |
#include "ipv4-l3-protocol.h" |
735
a3e48148c3ac
arp.h -> arp-l3-protocol.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
729
diff
changeset
|
30 |
#include "arp-l3-protocol.h" |
242 | 31 |
#include "arp-header.h" |
32 |
#include "arp-cache.h" |
|
33 |
#include "ipv4-interface.h" |
|
34 |
||
10968
2d29fee2b7b8
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10652
diff
changeset
|
35 |
namespace ns3 { |
242 | 36 |
|
10968
2d29fee2b7b8
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10652
diff
changeset
|
37 |
NS_LOG_COMPONENT_DEFINE ("ArpL3Protocol"); |
242 | 38 |
|
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
39 |
const uint16_t ArpL3Protocol::PROT_NUMBER = 0x0806; |
294
aba9a34108d2
remove ArpL3Protocol object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
287
diff
changeset
|
40 |
|
10652
dc18deba4502
[doxygen] Revert r10410, r10411, r10412
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10410
diff
changeset
|
41 |
NS_OBJECT_ENSURE_REGISTERED (ArpL3Protocol); |
2249
3a1da26d61dc
replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2238
diff
changeset
|
42 |
|
2250
18f432098389
InterfaceId -> TypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2249
diff
changeset
|
43 |
TypeId |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
44 |
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
|
45 |
{ |
2602
d9262bff6df2
add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2592
diff
changeset
|
46 |
static TypeId tid = TypeId ("ns3::ArpL3Protocol") |
2498
e01570293b98
convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
47 |
.SetParent<Object> () |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
48 |
.AddConstructor<ArpL3Protocol> () |
3146
98629e087bb1
add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2987
diff
changeset
|
49 |
.AddAttribute ("CacheList", |
98629e087bb1
add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2987
diff
changeset
|
50 |
"The list of ARP caches", |
98629e087bb1
add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2987
diff
changeset
|
51 |
ObjectVectorValue (), |
98629e087bb1
add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2987
diff
changeset
|
52 |
MakeObjectVectorAccessor (&ArpL3Protocol::m_cacheList), |
98629e087bb1
add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2987
diff
changeset
|
53 |
MakeObjectVectorChecker<ArpCache> ()) |
10151
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
54 |
.AddAttribute ("RequestJitter", "The jitter in ms a node is allowed to wait before sending an ARP request. Some jitter aims to prevent collisions. By default, the model will wait for a duration in ms defined by a uniform random-variable between 0 and RequestJitter", |
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
55 |
StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=10.0]"), |
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
56 |
MakePointerAccessor (&ArpL3Protocol::m_requestJitter), |
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
57 |
MakePointerChecker<RandomVariableStream> ()) |
3152
4260de124c74
report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3151
diff
changeset
|
58 |
.AddTraceSource ("Drop", |
4260de124c74
report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3151
diff
changeset
|
59 |
"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
|
60 |
MakeTraceSourceAccessor (&ArpL3Protocol::m_dropTrace)) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
61 |
; |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
62 |
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
|
63 |
} |
9abd038ee588
replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2231
diff
changeset
|
64 |
|
2498
e01570293b98
convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
65 |
ArpL3Protocol::ArpL3Protocol () |
1178
a40440a4b2fa
forgot to set the interface id
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1177
diff
changeset
|
66 |
{ |
3151
428f8ec6da29
fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3147
diff
changeset
|
67 |
NS_LOG_FUNCTION (this); |
1178
a40440a4b2fa
forgot to set the interface id
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1177
diff
changeset
|
68 |
} |
242 | 69 |
|
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
70 |
ArpL3Protocol::~ArpL3Protocol () |
1505 | 71 |
{ |
3151
428f8ec6da29
fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3147
diff
changeset
|
72 |
NS_LOG_FUNCTION (this); |
1505 | 73 |
} |
496
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
74 |
|
10151
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
75 |
int64_t |
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
76 |
ArpL3Protocol::AssignStreams (int64_t stream) |
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
77 |
{ |
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
78 |
NS_LOG_FUNCTION (this << stream); |
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
79 |
m_requestJitter->SetStream (stream); |
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
80 |
return 1; |
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
81 |
} |
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
82 |
|
496
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
83 |
void |
2592
3ebf97150166
get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2498
diff
changeset
|
84 |
ArpL3Protocol::SetNode (Ptr<Node> node) |
3ebf97150166
get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2498
diff
changeset
|
85 |
{ |
9704
1db7690f8e8f
Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents:
7386
diff
changeset
|
86 |
NS_LOG_FUNCTION (this << node); |
2592
3ebf97150166
get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2498
diff
changeset
|
87 |
m_node = node; |
3ebf97150166
get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2498
diff
changeset
|
88 |
} |
3ebf97150166
get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2498
diff
changeset
|
89 |
|
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
90 |
/* |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
91 |
* 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
|
92 |
* 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
|
93 |
*/ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
94 |
void |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
95 |
ArpL3Protocol::NotifyNewAggregate () |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
96 |
{ |
9704
1db7690f8e8f
Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents:
7386
diff
changeset
|
97 |
NS_LOG_FUNCTION (this); |
4669
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4603
diff
changeset
|
98 |
if (m_node == 0) |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
99 |
{ |
4669
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4603
diff
changeset
|
100 |
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
|
101 |
//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
|
102 |
//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
|
103 |
if (node != 0) |
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4603
diff
changeset
|
104 |
{ |
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4603
diff
changeset
|
105 |
this->SetNode (node); |
8aaa5e83939e
avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4603
diff
changeset
|
106 |
} |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
107 |
} |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
108 |
Object::NotifyNewAggregate (); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
109 |
} |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
110 |
|
2592
3ebf97150166
get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2498
diff
changeset
|
111 |
void |
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
112 |
ArpL3Protocol::DoDispose (void) |
496
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
113 |
{ |
3151
428f8ec6da29
fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3147
diff
changeset
|
114 |
NS_LOG_FUNCTION (this); |
428f8ec6da29
fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3147
diff
changeset
|
115 |
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
|
116 |
{ |
428f8ec6da29
fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3147
diff
changeset
|
117 |
Ptr<ArpCache> cache = *i; |
428f8ec6da29
fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3147
diff
changeset
|
118 |
cache->Dispose (); |
428f8ec6da29
fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3147
diff
changeset
|
119 |
} |
496
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
120 |
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
|
121 |
m_node = 0; |
1176
4894ea885c0f
implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
122 |
Object::DoDispose (); |
248
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
123 |
} |
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
124 |
|
3147
e0c2a7c2eb5f
re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3146
diff
changeset
|
125 |
Ptr<ArpCache> |
e0c2a7c2eb5f
re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3146
diff
changeset
|
126 |
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
|
127 |
{ |
3765
a2c60d47218b
add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3548
diff
changeset
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
device->AddLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache)); |
3499
a18520551cdf
revised patch to fix bug 253
Tom Henderson <tomh@tomh.org>
parents:
3462
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
return cache; |
e0c2a7c2eb5f
re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3146
diff
changeset
|
137 |
} |
e0c2a7c2eb5f
re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3146
diff
changeset
|
138 |
|
3146
98629e087bb1
add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2987
diff
changeset
|
139 |
Ptr<ArpCache> |
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
140 |
ArpL3Protocol::FindCache (Ptr<NetDevice> device) |
242 | 141 |
{ |
3765
a2c60d47218b
add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3548
diff
changeset
|
142 |
NS_LOG_FUNCTION (this << device); |
242 | 143 |
for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++) |
144 |
{ |
|
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
145 |
if ((*i)->GetDevice () == device) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
146 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
147 |
return *i; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
148 |
} |
242 | 149 |
} |
3147
e0c2a7c2eb5f
re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3146
diff
changeset
|
150 |
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
|
151 |
// quiet compiler |
e0c2a7c2eb5f
re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3146
diff
changeset
|
152 |
return 0; |
242 | 153 |
} |
154 |
||
155 |
void |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
156 |
ArpL3Protocol::Receive (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from, |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
157 |
const Address &to, NetDevice::PacketType packetType) |
242 | 158 |
{ |
3765
a2c60d47218b
add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3548
diff
changeset
|
159 |
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
|
160 |
|
3548
e5ab96db540e
bug 273: constify packet pointers.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3499
diff
changeset
|
161 |
Ptr<Packet> packet = p->Copy (); |
e5ab96db540e
bug 273: constify packet pointers.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3499
diff
changeset
|
162 |
|
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
|
163 |
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
|
164 |
|
3146
98629e087bb1
add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2987
diff
changeset
|
165 |
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
|
166 |
|
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
|
167 |
// |
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
|
168 |
// 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
|
169 |
// 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
|
170 |
// 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
|
171 |
// 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
|
172 |
// 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
|
173 |
// |
242 | 174 |
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
|
175 |
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
|
176 |
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
|
177 |
{ |
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
|
178 |
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
|
179 |
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
|
180 |
} |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
181 |
NS_LOG_LOGIC ("ARP: received "<< (arp.IsRequest () ? "request" : "reply") << |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
182 |
" node="<<m_node->GetId ()<<", got request from " << |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
183 |
arp.GetSourceIpv4Address () << " for address " << |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
184 |
arp.GetDestinationIpv4Address () << "; we have addresses: "); |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
185 |
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
|
186 |
{ |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
187 |
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
|
188 |
} |
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
|
189 |
|
10157
02e3d2d7d7e1
Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10151
diff
changeset
|
190 |
/** \internal |
2919 | 191 |
* Note: we do not update the ARP cache when we receive an ARP request |
10157
02e3d2d7d7e1
Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10151
diff
changeset
|
192 |
* from an unknown node. See \bugid{107} |
2919 | 193 |
*/ |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
194 |
bool found = false; |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
195 |
for (uint32_t i = 0; i < cache->GetInterface ()->GetNAddresses (); i++) |
242 | 196 |
{ |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
197 |
if (arp.IsRequest () && arp.GetDestinationIpv4Address () == |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
198 |
cache->GetInterface ()->GetAddress (i).GetLocal ()) |
242 | 199 |
{ |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
200 |
found = true; |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
201 |
NS_LOG_LOGIC ("node="<<m_node->GetId () <<", got request from " << |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
202 |
arp.GetSourceIpv4Address () << " -- send reply"); |
4696
5ef92ccda11a
Route lookup removed in ARP request (see bug 606)
Pavel Boyko <boyko@iitp.ru>
parents:
4669
diff
changeset
|
203 |
SendArpReply (cache, arp.GetDestinationIpv4Address (), arp.GetSourceIpv4Address (), |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
204 |
arp.GetSourceHardwareAddress ()); |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
205 |
break; |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
206 |
} |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
207 |
else if (arp.IsReply () && |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
208 |
arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress (i).GetLocal ()) && |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
209 |
arp.GetDestinationHardwareAddress () == device->GetAddress ()) |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
210 |
{ |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
211 |
found = true; |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
212 |
Ipv4Address from = arp.GetSourceIpv4Address (); |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
213 |
ArpCache::Entry *entry = cache->Lookup (from); |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
214 |
if (entry != 0) |
242 | 215 |
{ |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
216 |
if (entry->IsWaitReply ()) |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
217 |
{ |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
218 |
NS_LOG_LOGIC ("node="<< m_node->GetId () << |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
219 |
", got reply from " << arp.GetSourceIpv4Address () |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
220 |
<< " for waiting entry -- flush"); |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
221 |
Address from_mac = arp.GetSourceHardwareAddress (); |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
222 |
entry->MarkAlive (from_mac); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
223 |
Ptr<Packet> pending = entry->DequeuePending (); |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
224 |
while (pending != 0) |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
225 |
{ |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
226 |
cache->GetInterface ()->Send (pending, |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
227 |
arp.GetSourceIpv4Address ()); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
228 |
pending = entry->DequeuePending (); |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
229 |
} |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
230 |
} |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
231 |
else |
3151
428f8ec6da29
fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3147
diff
changeset
|
232 |
{ |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
233 |
// 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
|
234 |
// at poisening my arp cache. |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
235 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got reply from " << |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
236 |
arp.GetSourceIpv4Address () << |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
237 |
" for non-waiting entry -- drop"); |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
238 |
m_dropTrace (packet); |
3151
428f8ec6da29
fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3147
diff
changeset
|
239 |
} |
242 | 240 |
} |
241 |
else |
|
242 |
{ |
|
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
243 |
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
|
244 |
m_dropTrace (packet); |
242 | 245 |
} |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
246 |
break; |
242 | 247 |
} |
248 |
} |
|
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
249 |
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
|
250 |
{ |
1505 | 251 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got request from " << |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
252 |
arp.GetSourceIpv4Address () << " for unknown address " << |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
253 |
arp.GetDestinationIpv4Address () << " -- drop"); |
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
|
254 |
} |
242 | 255 |
} |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
256 |
|
242 | 257 |
bool |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1505
diff
changeset
|
258 |
ArpL3Protocol::Lookup (Ptr<Packet> packet, Ipv4Address destination, |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
259 |
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
|
260 |
Ptr<ArpCache> cache, |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
261 |
Address *hardwareDestination) |
242 | 262 |
{ |
9704
1db7690f8e8f
Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents:
7386
diff
changeset
|
263 |
NS_LOG_FUNCTION (this << packet << destination << device << cache << hardwareDestination); |
242 | 264 |
ArpCache::Entry *entry = cache->Lookup (destination); |
265 |
if (entry != 0) |
|
266 |
{ |
|
267 |
if (entry->IsExpired ()) |
|
268 |
{ |
|
269 |
if (entry->IsDead ()) |
|
270 |
{ |
|
1505 | 271 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
272 |
", dead entry for " << destination << " expired -- send arp request"); |
242 | 273 |
entry->MarkWaitReply (packet); |
10151
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
274 |
Simulator::Schedule (Time (MilliSeconds (m_requestJitter->GetValue ())), &ArpL3Protocol::SendArpRequest, this, cache, destination); |
242 | 275 |
} |
276 |
else if (entry->IsAlive ()) |
|
277 |
{ |
|
1505 | 278 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
279 |
", alive entry for " << destination << " expired -- send arp request"); |
242 | 280 |
entry->MarkWaitReply (packet); |
10151
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
281 |
Simulator::Schedule (Time (MilliSeconds (m_requestJitter->GetValue ())), &ArpL3Protocol::SendArpRequest, this, cache, destination); |
242 | 282 |
} |
283 |
else if (entry->IsWaitReply ()) |
|
284 |
{ |
|
3823
761f94afe2a2
Fix bug 362; cancel WaitReplyTimer when ArpCache is flushed
Tom Henderson <tomh@tomh.org>
parents:
3765
diff
changeset
|
285 |
NS_FATAL_ERROR ("Test for possibly unreachable code-- please file a bug report, with a test case, if this is ever hit"); |
242 | 286 |
} |
287 |
} |
|
288 |
else |
|
289 |
{ |
|
290 |
if (entry->IsDead ()) |
|
291 |
{ |
|
1505 | 292 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
3151
428f8ec6da29
fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3147
diff
changeset
|
293 |
", dead entry for " << destination << " valid -- drop"); |
3152
4260de124c74
report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3151
diff
changeset
|
294 |
m_dropTrace (packet); |
242 | 295 |
} |
296 |
else if (entry->IsAlive ()) |
|
297 |
{ |
|
1505 | 298 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
3151
428f8ec6da29
fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3147
diff
changeset
|
299 |
", alive entry for " << destination << " valid -- send"); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
300 |
*hardwareDestination = entry->GetMacAddress (); |
242 | 301 |
return true; |
302 |
} |
|
303 |
else if (entry->IsWaitReply ()) |
|
304 |
{ |
|
1505 | 305 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
3151
428f8ec6da29
fix bug 185
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3147
diff
changeset
|
306 |
", 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
|
307 |
if (!entry->UpdateWaitReply (packet)) |
4260de124c74
report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3151
diff
changeset
|
308 |
{ |
4260de124c74
report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3151
diff
changeset
|
309 |
m_dropTrace (packet); |
4260de124c74
report packet drops in ARP.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3151
diff
changeset
|
310 |
} |
242 | 311 |
} |
312 |
} |
|
313 |
} |
|
314 |
else |
|
315 |
{ |
|
316 |
// This is our first attempt to transmit data to this destination. |
|
1505 | 317 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
318 |
", no entry for " << destination << " -- send arp request"); |
242 | 319 |
entry = cache->Add (destination); |
320 |
entry->MarkWaitReply (packet); |
|
10151
5d5dd1b12bfc
Bug 1522 - Hidden node scenario leads to ARP failure
John Abraham <john.abraham.in@gmail.com>
parents:
9704
diff
changeset
|
321 |
Simulator::Schedule (Time (MilliSeconds (m_requestJitter->GetValue ())), &ArpL3Protocol::SendArpRequest, this, cache, destination); |
242 | 322 |
} |
323 |
return false; |
|
324 |
} |
|
325 |
||
326 |
void |
|
3146
98629e087bb1
add attributes to ArpCache
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2987
diff
changeset
|
327 |
ArpL3Protocol::SendArpRequest (Ptr<const ArpCache> cache, Ipv4Address to) |
242 | 328 |
{ |
3765
a2c60d47218b
add debugging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3548
diff
changeset
|
329 |
NS_LOG_FUNCTION (this << cache << to); |
242 | 330 |
ArpHeader arp; |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
331 |
// 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
|
332 |
Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> (); |
5855
eb24725b9a95
Fix debug compilation for all platforms
Tom Henderson <tomh@tomh.org>
parents:
5854
diff
changeset
|
333 |
Ptr<NetDevice> device = cache->GetDevice (); |
eb24725b9a95
Fix debug compilation for all platforms
Tom Henderson <tomh@tomh.org>
parents:
5854
diff
changeset
|
334 |
NS_ASSERT (device != 0); |
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
335 |
Ipv4Header header; |
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
4472
diff
changeset
|
336 |
header.SetDestination (to); |
4603
67a0a49c1db4
bug 592: Ipv4RoutingProtocol::RouteOutput needs a packet pointer argument for reactive protocols
Josh Pelkey <joshpelkey@gmail.com>
parents:
4571
diff
changeset
|
337 |
Ptr<Packet> packet = Create<Packet> (); |
5855
eb24725b9a95
Fix debug compilation for all platforms
Tom Henderson <tomh@tomh.org>
parents:
5854
diff
changeset
|
338 |
Ipv4Address source = ipv4->SelectSourceAddress (device, to, Ipv4InterfaceAddress::GLOBAL); |
1505 | 339 |
NS_LOG_LOGIC ("ARP: sending request from node "<<m_node->GetId ()<< |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
340 |
" || src: " << device->GetAddress () << " / " << source << |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
341 |
" || dst: " << device->GetBroadcast () << " / " << to); |
5855
eb24725b9a95
Fix debug compilation for all platforms
Tom Henderson <tomh@tomh.org>
parents:
5854
diff
changeset
|
342 |
arp.SetRequest (device->GetAddress (), source, device->GetBroadcast (), to); |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1505
diff
changeset
|
343 |
packet->AddHeader (arp); |
5855
eb24725b9a95
Fix debug compilation for all platforms
Tom Henderson <tomh@tomh.org>
parents:
5854
diff
changeset
|
344 |
cache->GetDevice ()->Send (packet, device->GetBroadcast (), PROT_NUMBER); |
242 | 345 |
} |
346 |
||
347 |
void |
|
4696
5ef92ccda11a
Route lookup removed in ARP request (see bug 606)
Pavel Boyko <boyko@iitp.ru>
parents:
4669
diff
changeset
|
348 |
ArpL3Protocol::SendArpReply (Ptr<const ArpCache> cache, Ipv4Address myIp, Ipv4Address toIp, Address toMac) |
242 | 349 |
{ |
9704
1db7690f8e8f
Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents:
7386
diff
changeset
|
350 |
NS_LOG_FUNCTION (this << cache << myIp << toIp << toMac); |
242 | 351 |
ArpHeader arp; |
1505 | 352 |
NS_LOG_LOGIC ("ARP: sending reply from node "<<m_node->GetId ()<< |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
353 |
"|| src: " << cache->GetDevice ()->GetAddress () << |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
354 |
" / " << myIp << |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
355 |
" || dst: " << toMac << " / " << toIp); |
4696
5ef92ccda11a
Route lookup removed in ARP request (see bug 606)
Pavel Boyko <boyko@iitp.ru>
parents:
4669
diff
changeset
|
356 |
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
|
357 |
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
|
358 |
packet->AddHeader (arp); |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
359 |
cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER); |
242 | 360 |
} |
361 |
||
7386
2310ed220a61
standardize ns-3 namespace declaration format
Vedran Miletić <rivanvx@gmail.com>
parents:
7385
diff
changeset
|
362 |
} // namespace ns3 |