author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Fri, 10 Aug 2007 15:47:13 +0200 | |
changeset 1333 | c0d66de933e9 |
parent 1325 | f3be9eed2d90 |
child 1341 | f685d4bf320f |
permissions | -rw-r--r-- |
242 | 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2006 INRIA |
|
4 |
* All rights reserved. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License version 2 as |
|
8 |
* published by the Free Software Foundation; |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 |
* |
|
19 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
|
20 |
*/ |
|
21 |
#include "ns3/packet.h" |
|
287
692ddac3794c
convert old TRACE code to use new NS_DEBUG macro
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
286
diff
changeset
|
22 |
#include "ns3/debug.h" |
345
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
321
diff
changeset
|
23 |
#include "ns3/empty-trace-resolver.h" |
729
b5e744285e92
rename i-node to node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
728
diff
changeset
|
24 |
#include "ns3/node.h" |
524
082ffdd8fbd7
move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
522
diff
changeset
|
25 |
#include "ns3/net-device.h" |
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 | 29 |
#include "arp-header.h" |
30 |
#include "arp-cache.h" |
|
31 |
#include "ipv4-interface.h" |
|
32 |
||
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
33 |
NS_DEBUG_COMPONENT_DEFINE ("ArpL3Protocol"); |
242 | 34 |
|
35 |
namespace ns3 { |
|
36 |
||
1177
c7bf3cf186ac
remove now-unused ArpPrivate class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1176
diff
changeset
|
37 |
const InterfaceId ArpL3Protocol::iid = MakeInterfaceId ("ArpL3Protocol", Object::iid); |
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
38 |
const uint16_t ArpL3Protocol::PROT_NUMBER = 0x0806; |
294
aba9a34108d2
remove ArpL3Protocol object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
287
diff
changeset
|
39 |
|
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
40 |
ArpL3Protocol::ArpL3Protocol (Ptr<Node> node) |
1176
4894ea885c0f
implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
41 |
: m_node (node) |
1178
a40440a4b2fa
forgot to set the interface id
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1177
diff
changeset
|
42 |
{ |
a40440a4b2fa
forgot to set the interface id
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1177
diff
changeset
|
43 |
SetInterfaceId (ArpL3Protocol::iid); |
a40440a4b2fa
forgot to set the interface id
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1177
diff
changeset
|
44 |
} |
242 | 45 |
|
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
46 |
ArpL3Protocol::~ArpL3Protocol () |
552
b5f29caf9d8c
convert Arp code to use Ptr<Node> instead of Node *
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
551
diff
changeset
|
47 |
{} |
496
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
48 |
|
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
49 |
void |
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
50 |
ArpL3Protocol::DoDispose (void) |
496
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
51 |
{ |
248
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
52 |
for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++) |
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
53 |
{ |
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
54 |
delete *i; |
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
55 |
} |
496
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
56 |
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
|
57 |
m_node = 0; |
1176
4894ea885c0f
implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
58 |
Object::DoDispose (); |
248
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
59 |
} |
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
60 |
|
1333
c0d66de933e9
convert TraceResolver * to Ptr<TraceResolver>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1325
diff
changeset
|
61 |
Ptr<TraceResolver> |
1325
f3be9eed2d90
remove TraceContext argument from TraceResolver constructor and move it to Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1186
diff
changeset
|
62 |
ArpL3Protocol::CreateTraceResolver (void) |
345
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
321
diff
changeset
|
63 |
{ |
1333
c0d66de933e9
convert TraceResolver * to Ptr<TraceResolver>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1325
diff
changeset
|
64 |
return Create<EmptyTraceResolver> (); |
345
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
321
diff
changeset
|
65 |
} |
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
321
diff
changeset
|
66 |
|
242 | 67 |
ArpCache * |
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
68 |
ArpL3Protocol::FindCache (Ptr<NetDevice> device) |
242 | 69 |
{ |
70 |
for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++) |
|
71 |
{ |
|
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
72 |
if ((*i)->GetDevice () == device) |
242 | 73 |
{ |
74 |
return *i; |
|
75 |
} |
|
76 |
} |
|
1176
4894ea885c0f
implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
77 |
Ptr<Ipv4L3Protocol> ipv4 = m_node->QueryInterface<Ipv4L3Protocol> (Ipv4L3Protocol::iid); |
551
12ed30c77cab
revert Ipv4Interface * -> Ptr<Ipv4Interface>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
548
diff
changeset
|
78 |
Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device); |
242 | 79 |
ArpCache * cache = new ArpCache (device, interface); |
286
57e6a2006962
convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
261
diff
changeset
|
80 |
NS_ASSERT (device->IsBroadcast ()); |
242 | 81 |
device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache)); |
82 |
m_cacheList.push_back (cache); |
|
83 |
return cache; |
|
84 |
} |
|
85 |
||
86 |
void |
|
1186
909e9eb2124e
rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1178
diff
changeset
|
87 |
ArpL3Protocol::Receive(Ptr<NetDevice> device, const Packet& p, uint16_t protocol, const Address &from) |
242 | 88 |
{ |
474
7457c2a417ba
manage NetDevice objects with refcounts
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
463
diff
changeset
|
89 |
ArpCache *cache = FindCache (device); |
242 | 90 |
ArpHeader arp; |
1176
4894ea885c0f
implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
91 |
Packet packet = p; |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
92 |
packet.RemoveHeader (arp); |
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
|
93 |
|
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
|
94 |
NS_DEBUG ("ARP: received "<< (arp.IsRequest ()? "request" : "reply") << |
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
|
95 |
" 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
|
96 |
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
|
97 |
arp.GetDestinationIpv4Address () << "; we have 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
|
98 |
cache->GetInterface ()->GetAddress ()); |
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
|
99 |
|
242 | 100 |
if (arp.IsRequest () && |
101 |
arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) |
|
102 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
103 |
NS_DEBUG ("node="<<m_node->GetId () <<", got request from " << |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
104 |
arp.GetSourceIpv4Address () << " -- send reply"); |
242 | 105 |
SendArpReply (cache, arp.GetSourceIpv4Address (), |
106 |
arp.GetSourceHardwareAddress ()); |
|
107 |
} |
|
108 |
else if (arp.IsReply () && |
|
109 |
arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress ()) && |
|
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
110 |
arp.GetDestinationHardwareAddress () == device->GetAddress ()) |
242 | 111 |
{ |
112 |
Ipv4Address from = arp.GetSourceIpv4Address (); |
|
113 |
ArpCache::Entry *entry = cache->Lookup (from); |
|
114 |
if (entry != 0) |
|
115 |
{ |
|
116 |
if (entry->IsWaitReply ()) |
|
117 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
118 |
NS_DEBUG ("node="<<m_node->GetId ()<<", got reply from " << |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
119 |
arp.GetSourceIpv4Address () |
242 | 120 |
<< " for waiting entry -- flush"); |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
121 |
Address from_mac = arp.GetSourceHardwareAddress (); |
242 | 122 |
Packet waiting = entry->MarkAlive (from_mac); |
123 |
cache->GetInterface ()->Send (waiting, arp.GetSourceIpv4Address ()); |
|
124 |
} |
|
125 |
else |
|
126 |
{ |
|
127 |
// ignore this reply which might well be an attempt |
|
128 |
// at poisening my arp cache. |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
129 |
NS_DEBUG ("node="<<m_node->GetId ()<<", got reply from " << |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
130 |
arp.GetSourceIpv4Address () << |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
131 |
" for non-waiting entry -- drop"); |
242 | 132 |
// XXX report packet as dropped. |
133 |
} |
|
134 |
} |
|
135 |
else |
|
136 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
137 |
NS_DEBUG ("node="<<m_node->GetId ()<<", got reply for unknown entry -- drop"); |
242 | 138 |
// XXX report packet as dropped. |
139 |
} |
|
140 |
} |
|
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
|
141 |
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
|
142 |
{ |
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
|
143 |
NS_DEBUG ("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
|
144 |
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
|
145 |
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
|
146 |
} |
242 | 147 |
} |
148 |
bool |
|
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
149 |
ArpL3Protocol::Lookup (Packet &packet, Ipv4Address destination, |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
150 |
Ptr<NetDevice> device, |
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
151 |
Address *hardwareDestination) |
242 | 152 |
{ |
153 |
ArpCache *cache = FindCache (device); |
|
154 |
ArpCache::Entry *entry = cache->Lookup (destination); |
|
155 |
if (entry != 0) |
|
156 |
{ |
|
157 |
if (entry->IsExpired ()) |
|
158 |
{ |
|
159 |
if (entry->IsDead ()) |
|
160 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
161 |
NS_DEBUG ("node="<<m_node->GetId ()<< |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
162 |
", dead entry for " << destination << " expired -- send arp request"); |
242 | 163 |
entry->MarkWaitReply (packet); |
164 |
SendArpRequest (cache, destination); |
|
165 |
} |
|
166 |
else if (entry->IsAlive ()) |
|
167 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
168 |
NS_DEBUG ("node="<<m_node->GetId ()<< |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
169 |
", alive entry for " << destination << " expired -- send arp request"); |
242 | 170 |
entry->MarkWaitReply (packet); |
171 |
SendArpRequest (cache, destination); |
|
172 |
} |
|
173 |
else if (entry->IsWaitReply ()) |
|
174 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
175 |
NS_DEBUG ("node="<<m_node->GetId ()<< |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
176 |
", wait reply for " << destination << " expired -- drop"); |
242 | 177 |
entry->MarkDead (); |
178 |
// XXX report packet as 'dropped' |
|
179 |
} |
|
180 |
} |
|
181 |
else |
|
182 |
{ |
|
183 |
if (entry->IsDead ()) |
|
184 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
185 |
NS_DEBUG ("node="<<m_node->GetId ()<< |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
186 |
", dead entry for " << destination << " valid -- drop"); |
242 | 187 |
// XXX report packet as 'dropped' |
188 |
} |
|
189 |
else if (entry->IsAlive ()) |
|
190 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
191 |
NS_DEBUG ("node="<<m_node->GetId ()<< |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
192 |
", alive entry for " << destination << " valid -- send"); |
242 | 193 |
*hardwareDestination = entry->GetMacAddress (); |
194 |
return true; |
|
195 |
} |
|
196 |
else if (entry->IsWaitReply ()) |
|
197 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
198 |
NS_DEBUG ("node="<<m_node->GetId ()<< |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
199 |
", wait reply for " << destination << " valid -- drop previous"); |
242 | 200 |
Packet old = entry->UpdateWaitReply (packet); |
201 |
// XXX report 'old' packet as 'dropped' |
|
202 |
} |
|
203 |
} |
|
204 |
||
205 |
} |
|
206 |
else |
|
207 |
{ |
|
208 |
// This is our first attempt to transmit data to this destination. |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
209 |
NS_DEBUG ("node="<<m_node->GetId ()<< |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
210 |
", no entry for " << destination << " -- send arp request"); |
242 | 211 |
entry = cache->Add (destination); |
212 |
entry->MarkWaitReply (packet); |
|
213 |
SendArpRequest (cache, destination); |
|
214 |
} |
|
215 |
return false; |
|
216 |
} |
|
217 |
||
218 |
void |
|
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
219 |
ArpL3Protocol::SendArpRequest (ArpCache const *cache, Ipv4Address to) |
242 | 220 |
{ |
221 |
ArpHeader arp; |
|
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
|
222 |
NS_DEBUG ("ARP: sending request from node "<<m_node->GetId ()<< |
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 |
" || src: " << cache->GetDevice ()->GetAddress () << |
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 |
" / " << cache->GetInterface ()->GetAddress () << |
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
|
225 |
" || 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
|
226 |
" / " << to); |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
227 |
arp.SetRequest (cache->GetDevice ()->GetAddress (), |
242 | 228 |
cache->GetInterface ()->GetAddress (), |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
229 |
cache->GetDevice ()->GetBroadcast (), |
242 | 230 |
to); |
231 |
Packet packet; |
|
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
232 |
packet.AddHeader (arp); |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
233 |
cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), PROT_NUMBER); |
242 | 234 |
} |
235 |
||
236 |
void |
|
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
237 |
ArpL3Protocol::SendArpReply (ArpCache const *cache, Ipv4Address toIp, Address toMac) |
242 | 238 |
{ |
239 |
ArpHeader arp; |
|
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
|
240 |
NS_DEBUG ("ARP: sending reply from node "<<m_node->GetId ()<< |
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
|
241 |
"|| src: " << cache->GetDevice ()->GetAddress () << |
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
|
242 |
" / " << cache->GetInterface ()->GetAddress () << |
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
|
243 |
" || dst: " << toMac << " / " << toIp); |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
244 |
arp.SetReply (cache->GetDevice ()->GetAddress (), |
242 | 245 |
cache->GetInterface ()->GetAddress (), |
246 |
toMac, toIp); |
|
247 |
Packet packet; |
|
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
248 |
packet.AddHeader (arp); |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
249 |
cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER); |
242 | 250 |
} |
251 |
||
252 |
}//namespace ns3 |