author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Mon, 30 Jul 2007 10:35:03 +0200 | |
changeset 1167 | 2cb083ff04c6 |
parent 1161 | bb72baff8b26 |
parent 933 | df68dad55087 |
child 1176 | 4894ea885c0f |
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 |
|
735
a3e48148c3ac
arp.h -> arp-l3-protocol.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
729
diff
changeset
|
27 |
#include "arp-l3-protocol.h" |
242 | 28 |
#include "arp-header.h" |
29 |
#include "arp-cache.h" |
|
30 |
#include "ipv4-interface.h" |
|
738
2c105723d191
i-ipv4-private.h ipv4-private.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
736
diff
changeset
|
31 |
#include "ipv4-private.h" |
242 | 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 |
||
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 |
|
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
39 |
ArpL3Protocol::ArpL3Protocol (Ptr<Node> node) |
294
aba9a34108d2
remove ArpL3Protocol object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
287
diff
changeset
|
40 |
: L3Protocol (PROT_NUMBER, 0/* XXX: correct version number ? */ ), |
aba9a34108d2
remove ArpL3Protocol object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
287
diff
changeset
|
41 |
m_node (node) |
552
b5f29caf9d8c
convert Arp code to use Ptr<Node> instead of Node *
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
551
diff
changeset
|
42 |
{} |
242 | 43 |
|
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
44 |
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
|
45 |
{} |
496
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
46 |
|
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
47 |
void |
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
48 |
ArpL3Protocol::DoDispose (void) |
496
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
49 |
{ |
248
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
50 |
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
|
51 |
{ |
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
52 |
delete *i; |
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
53 |
} |
496
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
54 |
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
|
55 |
m_node = 0; |
513
b7c7ea629de9
make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
504
diff
changeset
|
56 |
L3Protocol::DoDispose (); |
248
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
57 |
} |
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
58 |
|
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
|
59 |
TraceResolver * |
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
60 |
ArpL3Protocol::CreateTraceResolver (TraceContext const &context) |
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
|
61 |
{ |
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
321
diff
changeset
|
62 |
return new EmptyTraceResolver (context); |
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 |
} |
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
321
diff
changeset
|
64 |
|
242 | 65 |
ArpCache * |
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
66 |
ArpL3Protocol::FindCache (Ptr<NetDevice> device) |
242 | 67 |
{ |
68 |
for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++) |
|
69 |
{ |
|
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
70 |
if ((*i)->GetDevice () == device) |
242 | 71 |
{ |
72 |
return *i; |
|
73 |
} |
|
74 |
} |
|
746
a037131de577
IIpv4Private -> Ipv4Private
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
738
diff
changeset
|
75 |
Ptr<Ipv4Private> ipv4 = m_node->QueryInterface<Ipv4Private> (Ipv4Private::iid); |
551
12ed30c77cab
revert Ipv4Interface * -> Ptr<Ipv4Interface>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
548
diff
changeset
|
76 |
Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device); |
242 | 77 |
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
|
78 |
NS_ASSERT (device->IsBroadcast ()); |
242 | 79 |
device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache)); |
80 |
m_cacheList.push_back (cache); |
|
81 |
return cache; |
|
82 |
} |
|
83 |
||
84 |
void |
|
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
85 |
ArpL3Protocol::Receive(Packet& packet, Ptr<NetDevice> device) |
242 | 86 |
{ |
474
7457c2a417ba
manage NetDevice objects with refcounts
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
463
diff
changeset
|
87 |
ArpCache *cache = FindCache (device); |
242 | 88 |
ArpHeader arp; |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
89 |
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
|
90 |
|
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
|
91 |
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
|
92 |
" 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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
|
242 | 97 |
if (arp.IsRequest () && |
98 |
arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) |
|
99 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
100 |
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
|
101 |
arp.GetSourceIpv4Address () << " -- send reply"); |
242 | 102 |
SendArpReply (cache, arp.GetSourceIpv4Address (), |
103 |
arp.GetSourceHardwareAddress ()); |
|
104 |
} |
|
105 |
else if (arp.IsReply () && |
|
106 |
arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress ()) && |
|
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
107 |
arp.GetDestinationHardwareAddress () == device->GetAddress ()) |
242 | 108 |
{ |
109 |
Ipv4Address from = arp.GetSourceIpv4Address (); |
|
110 |
ArpCache::Entry *entry = cache->Lookup (from); |
|
111 |
if (entry != 0) |
|
112 |
{ |
|
113 |
if (entry->IsWaitReply ()) |
|
114 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
115 |
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
|
116 |
arp.GetSourceIpv4Address () |
242 | 117 |
<< " for waiting entry -- flush"); |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
118 |
Address from_mac = arp.GetSourceHardwareAddress (); |
242 | 119 |
Packet waiting = entry->MarkAlive (from_mac); |
120 |
cache->GetInterface ()->Send (waiting, arp.GetSourceIpv4Address ()); |
|
121 |
} |
|
122 |
else |
|
123 |
{ |
|
124 |
// ignore this reply which might well be an attempt |
|
125 |
// at poisening my arp cache. |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
126 |
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
|
127 |
arp.GetSourceIpv4Address () << |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
128 |
" for non-waiting entry -- drop"); |
242 | 129 |
// XXX report packet as dropped. |
130 |
} |
|
131 |
} |
|
132 |
else |
|
133 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
134 |
NS_DEBUG ("node="<<m_node->GetId ()<<", got reply for unknown entry -- drop"); |
242 | 135 |
// XXX report packet as dropped. |
136 |
} |
|
137 |
} |
|
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
|
138 |
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
|
139 |
{ |
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
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
} |
242 | 144 |
} |
145 |
bool |
|
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
146 |
ArpL3Protocol::Lookup (Packet &packet, Ipv4Address destination, |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
147 |
Ptr<NetDevice> device, |
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
148 |
Address *hardwareDestination) |
242 | 149 |
{ |
150 |
ArpCache *cache = FindCache (device); |
|
151 |
ArpCache::Entry *entry = cache->Lookup (destination); |
|
152 |
if (entry != 0) |
|
153 |
{ |
|
154 |
if (entry->IsExpired ()) |
|
155 |
{ |
|
156 |
if (entry->IsDead ()) |
|
157 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
158 |
NS_DEBUG ("node="<<m_node->GetId ()<< |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
159 |
", dead entry for " << destination << " expired -- send arp request"); |
242 | 160 |
entry->MarkWaitReply (packet); |
161 |
SendArpRequest (cache, destination); |
|
162 |
} |
|
163 |
else if (entry->IsAlive ()) |
|
164 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
165 |
NS_DEBUG ("node="<<m_node->GetId ()<< |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
166 |
", alive entry for " << destination << " expired -- send arp request"); |
242 | 167 |
entry->MarkWaitReply (packet); |
168 |
SendArpRequest (cache, destination); |
|
169 |
} |
|
170 |
else if (entry->IsWaitReply ()) |
|
171 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
172 |
NS_DEBUG ("node="<<m_node->GetId ()<< |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
173 |
", wait reply for " << destination << " expired -- drop"); |
242 | 174 |
entry->MarkDead (); |
175 |
// XXX report packet as 'dropped' |
|
176 |
} |
|
177 |
} |
|
178 |
else |
|
179 |
{ |
|
180 |
if (entry->IsDead ()) |
|
181 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
182 |
NS_DEBUG ("node="<<m_node->GetId ()<< |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
183 |
", dead entry for " << destination << " valid -- drop"); |
242 | 184 |
// XXX report packet as 'dropped' |
185 |
} |
|
186 |
else if (entry->IsAlive ()) |
|
187 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
188 |
NS_DEBUG ("node="<<m_node->GetId ()<< |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
189 |
", alive entry for " << destination << " valid -- send"); |
242 | 190 |
*hardwareDestination = entry->GetMacAddress (); |
191 |
return true; |
|
192 |
} |
|
193 |
else if (entry->IsWaitReply ()) |
|
194 |
{ |
|
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
195 |
NS_DEBUG ("node="<<m_node->GetId ()<< |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
196 |
", wait reply for " << destination << " valid -- drop previous"); |
242 | 197 |
Packet old = entry->UpdateWaitReply (packet); |
198 |
// XXX report 'old' packet as 'dropped' |
|
199 |
} |
|
200 |
} |
|
201 |
||
202 |
} |
|
203 |
else |
|
204 |
{ |
|
205 |
// 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
|
206 |
NS_DEBUG ("node="<<m_node->GetId ()<< |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
207 |
", no entry for " << destination << " -- send arp request"); |
242 | 208 |
entry = cache->Add (destination); |
209 |
entry->MarkWaitReply (packet); |
|
210 |
SendArpRequest (cache, destination); |
|
211 |
} |
|
212 |
return false; |
|
213 |
} |
|
214 |
||
215 |
void |
|
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
216 |
ArpL3Protocol::SendArpRequest (ArpCache const *cache, Ipv4Address to) |
242 | 217 |
{ |
218 |
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
|
219 |
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
|
220 |
" || 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
|
221 |
" / " << 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
|
222 |
" || 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
|
223 |
" / " << to); |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
224 |
arp.SetRequest (cache->GetDevice ()->GetAddress (), |
242 | 225 |
cache->GetInterface ()->GetAddress (), |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
226 |
cache->GetDevice ()->GetBroadcast (), |
242 | 227 |
to); |
228 |
Packet packet; |
|
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
229 |
packet.AddHeader (arp); |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
230 |
cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), PROT_NUMBER); |
242 | 231 |
} |
232 |
||
233 |
void |
|
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
234 |
ArpL3Protocol::SendArpReply (ArpCache const *cache, Ipv4Address toIp, Address toMac) |
242 | 235 |
{ |
236 |
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
|
237 |
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
|
238 |
"|| 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
|
239 |
" / " << 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
|
240 |
" || dst: " << toMac << " / " << toIp); |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
241 |
arp.SetReply (cache->GetDevice ()->GetAddress (), |
242 | 242 |
cache->GetInterface ()->GetAddress (), |
243 |
toMac, toIp); |
|
244 |
Packet packet; |
|
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
245 |
packet.AddHeader (arp); |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
246 |
cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER); |
242 | 247 |
} |
248 |
||
249 |
}//namespace ns3 |