author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Thu, 13 Mar 2008 12:56:49 -0700 | |
changeset 2602 | d9262bff6df2 |
parent 2592 | 3ebf97150166 |
child 2834 | 1aab57845b07 |
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" |
|
1505 | 22 |
#include "ns3/log.h" |
729
b5e744285e92
rename i-node to node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
728
diff
changeset
|
23 |
#include "ns3/node.h" |
524
082ffdd8fbd7
move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
522
diff
changeset
|
24 |
#include "ns3/net-device.h" |
082ffdd8fbd7
move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
522
diff
changeset
|
25 |
|
1176
4894ea885c0f
implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
26 |
#include "ipv4-l3-protocol.h" |
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" |
|
31 |
||
1505 | 32 |
NS_LOG_COMPONENT_DEFINE ("ArpL3Protocol"); |
242 | 33 |
|
34 |
namespace ns3 { |
|
35 |
||
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
36 |
const uint16_t ArpL3Protocol::PROT_NUMBER = 0x0806; |
294
aba9a34108d2
remove ArpL3Protocol object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
287
diff
changeset
|
37 |
|
2249
3a1da26d61dc
replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2238
diff
changeset
|
38 |
NS_OBJECT_ENSURE_REGISTERED (ArpL3Protocol); |
3a1da26d61dc
replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2238
diff
changeset
|
39 |
|
2250
18f432098389
InterfaceId -> TypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2249
diff
changeset
|
40 |
TypeId |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
41 |
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
|
42 |
{ |
2602
d9262bff6df2
add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2592
diff
changeset
|
43 |
static TypeId tid = TypeId ("ns3::ArpL3Protocol") |
2498
e01570293b98
convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
44 |
.SetParent<Object> () |
e01570293b98
convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
45 |
; |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
46 |
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
|
47 |
} |
9abd038ee588
replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2231
diff
changeset
|
48 |
|
2498
e01570293b98
convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
49 |
ArpL3Protocol::ArpL3Protocol () |
1178
a40440a4b2fa
forgot to set the interface id
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1177
diff
changeset
|
50 |
{ |
1505 | 51 |
NS_LOG_FUNCTION; |
1178
a40440a4b2fa
forgot to set the interface id
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1177
diff
changeset
|
52 |
} |
242 | 53 |
|
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
54 |
ArpL3Protocol::~ArpL3Protocol () |
1505 | 55 |
{ |
56 |
NS_LOG_FUNCTION; |
|
57 |
} |
|
496
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
58 |
|
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
59 |
void |
2592
3ebf97150166
get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2498
diff
changeset
|
60 |
ArpL3Protocol::SetNode (Ptr<Node> node) |
3ebf97150166
get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2498
diff
changeset
|
61 |
{ |
3ebf97150166
get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2498
diff
changeset
|
62 |
m_node = node; |
3ebf97150166
get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2498
diff
changeset
|
63 |
} |
3ebf97150166
get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2498
diff
changeset
|
64 |
|
3ebf97150166
get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2498
diff
changeset
|
65 |
void |
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
66 |
ArpL3Protocol::DoDispose (void) |
496
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
67 |
{ |
1505 | 68 |
NS_LOG_FUNCTION; |
248
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
69 |
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
|
70 |
{ |
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
71 |
delete *i; |
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
72 |
} |
496
894c8380d57b
use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
487
diff
changeset
|
73 |
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
|
74 |
m_node = 0; |
1176
4894ea885c0f
implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
75 |
Object::DoDispose (); |
248
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
76 |
} |
a912210e52ac
fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
77 |
|
242 | 78 |
ArpCache * |
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
79 |
ArpL3Protocol::FindCache (Ptr<NetDevice> device) |
242 | 80 |
{ |
1505 | 81 |
NS_LOG_FUNCTION; |
242 | 82 |
for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++) |
83 |
{ |
|
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
84 |
if ((*i)->GetDevice () == device) |
242 | 85 |
{ |
86 |
return *i; |
|
87 |
} |
|
88 |
} |
|
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
89 |
Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> (); |
1341
f685d4bf320f
use the Object::GetTraceResolver tracing support rather than the old adhoc tracing code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1333
diff
changeset
|
90 |
Ptr<Ipv4Interface> interface = ipv4->FindInterfaceForDevice (device); |
242 | 91 |
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
|
92 |
NS_ASSERT (device->IsBroadcast ()); |
242 | 93 |
device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache)); |
94 |
m_cacheList.push_back (cache); |
|
95 |
return cache; |
|
96 |
} |
|
97 |
||
98 |
void |
|
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1505
diff
changeset
|
99 |
ArpL3Protocol::Receive(Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol, const Address &from) |
242 | 100 |
{ |
1505 | 101 |
NS_LOG_FUNCTION; |
474
7457c2a417ba
manage NetDevice objects with refcounts
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
463
diff
changeset
|
102 |
ArpCache *cache = FindCache (device); |
242 | 103 |
ArpHeader arp; |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1505
diff
changeset
|
104 |
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
|
105 |
|
1505 | 106 |
NS_LOG_LOGIC ("ARP: received "<< (arp.IsRequest ()? "request" : "reply") << |
933
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
746
diff
changeset
|
107 |
" 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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
|
242 | 112 |
if (arp.IsRequest () && |
113 |
arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) |
|
114 |
{ |
|
1505 | 115 |
NS_LOG_LOGIC ("node="<<m_node->GetId () <<", got request from " << |
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
116 |
arp.GetSourceIpv4Address () << " -- send reply"); |
242 | 117 |
SendArpReply (cache, arp.GetSourceIpv4Address (), |
118 |
arp.GetSourceHardwareAddress ()); |
|
119 |
} |
|
120 |
else if (arp.IsReply () && |
|
121 |
arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress ()) && |
|
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
122 |
arp.GetDestinationHardwareAddress () == device->GetAddress ()) |
242 | 123 |
{ |
124 |
Ipv4Address from = arp.GetSourceIpv4Address (); |
|
125 |
ArpCache::Entry *entry = cache->Lookup (from); |
|
126 |
if (entry != 0) |
|
127 |
{ |
|
128 |
if (entry->IsWaitReply ()) |
|
129 |
{ |
|
1505 | 130 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got reply from " << |
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
131 |
arp.GetSourceIpv4Address () |
242 | 132 |
<< " for waiting entry -- flush"); |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
133 |
Address from_mac = arp.GetSourceHardwareAddress (); |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1505
diff
changeset
|
134 |
Ptr<Packet> waiting = entry->MarkAlive (from_mac); |
242 | 135 |
cache->GetInterface ()->Send (waiting, arp.GetSourceIpv4Address ()); |
136 |
} |
|
137 |
else |
|
138 |
{ |
|
139 |
// ignore this reply which might well be an attempt |
|
140 |
// at poisening my arp cache. |
|
1505 | 141 |
NS_LOG_LOGIC("node="<<m_node->GetId ()<<", got reply from " << |
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
142 |
arp.GetSourceIpv4Address () << |
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
143 |
" for non-waiting entry -- drop"); |
242 | 144 |
// XXX report packet as dropped. |
145 |
} |
|
146 |
} |
|
147 |
else |
|
148 |
{ |
|
1505 | 149 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got reply for unknown entry -- drop"); |
242 | 150 |
// XXX report packet as dropped. |
151 |
} |
|
152 |
} |
|
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
|
153 |
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
|
154 |
{ |
1505 | 155 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got request from " << |
933
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
746
diff
changeset
|
156 |
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
|
157 |
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
|
158 |
} |
242 | 159 |
} |
160 |
bool |
|
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1505
diff
changeset
|
161 |
ArpL3Protocol::Lookup (Ptr<Packet> packet, Ipv4Address destination, |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
162 |
Ptr<NetDevice> device, |
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
163 |
Address *hardwareDestination) |
242 | 164 |
{ |
1505 | 165 |
NS_LOG_FUNCTION; |
242 | 166 |
ArpCache *cache = FindCache (device); |
167 |
ArpCache::Entry *entry = cache->Lookup (destination); |
|
168 |
if (entry != 0) |
|
169 |
{ |
|
170 |
if (entry->IsExpired ()) |
|
171 |
{ |
|
172 |
if (entry->IsDead ()) |
|
173 |
{ |
|
1505 | 174 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
175 |
", dead entry for " << destination << " expired -- send arp request"); |
242 | 176 |
entry->MarkWaitReply (packet); |
177 |
SendArpRequest (cache, destination); |
|
178 |
} |
|
179 |
else if (entry->IsAlive ()) |
|
180 |
{ |
|
1505 | 181 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
182 |
", alive entry for " << destination << " expired -- send arp request"); |
242 | 183 |
entry->MarkWaitReply (packet); |
184 |
SendArpRequest (cache, destination); |
|
185 |
} |
|
186 |
else if (entry->IsWaitReply ()) |
|
187 |
{ |
|
1505 | 188 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
189 |
", wait reply for " << destination << " expired -- drop"); |
242 | 190 |
entry->MarkDead (); |
191 |
// XXX report packet as 'dropped' |
|
192 |
} |
|
193 |
} |
|
194 |
else |
|
195 |
{ |
|
196 |
if (entry->IsDead ()) |
|
197 |
{ |
|
1505 | 198 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
199 |
", dead entry for " << destination << " valid -- drop"); |
242 | 200 |
// XXX report packet as 'dropped' |
201 |
} |
|
202 |
else if (entry->IsAlive ()) |
|
203 |
{ |
|
1505 | 204 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
205 |
", alive entry for " << destination << " valid -- send"); |
242 | 206 |
*hardwareDestination = entry->GetMacAddress (); |
207 |
return true; |
|
208 |
} |
|
209 |
else if (entry->IsWaitReply ()) |
|
210 |
{ |
|
1505 | 211 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
212 |
", wait reply for " << destination << " valid -- drop previous"); |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1505
diff
changeset
|
213 |
Ptr<Packet> old = entry->UpdateWaitReply (packet); |
242 | 214 |
// XXX report 'old' packet as 'dropped' |
215 |
} |
|
216 |
} |
|
217 |
||
218 |
} |
|
219 |
else |
|
220 |
{ |
|
221 |
// This is our first attempt to transmit data to this destination. |
|
1505 | 222 |
NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
321
452a9cdad112
improve arp debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
303
diff
changeset
|
223 |
", no entry for " << destination << " -- send arp request"); |
242 | 224 |
entry = cache->Add (destination); |
225 |
entry->MarkWaitReply (packet); |
|
226 |
SendArpRequest (cache, destination); |
|
227 |
} |
|
228 |
return false; |
|
229 |
} |
|
230 |
||
231 |
void |
|
736
a27d6bd2c291
Arp -> ArpL3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
735
diff
changeset
|
232 |
ArpL3Protocol::SendArpRequest (ArpCache const *cache, Ipv4Address to) |
242 | 233 |
{ |
1505 | 234 |
NS_LOG_FUNCTION; |
242 | 235 |
ArpHeader arp; |
1505 | 236 |
NS_LOG_LOGIC ("ARP: sending request from node "<<m_node->GetId ()<< |
933
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
746
diff
changeset
|
237 |
" || 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
|
238 |
" / " << 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
|
239 |
" || 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
|
240 |
" / " << to); |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
241 |
arp.SetRequest (cache->GetDevice ()->GetAddress (), |
242 | 242 |
cache->GetInterface ()->GetAddress (), |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
243 |
cache->GetDevice ()->GetBroadcast (), |
242 | 244 |
to); |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1505
diff
changeset
|
245 |
Ptr<Packet> packet = Create<Packet> (); |
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1505
diff
changeset
|
246 |
packet->AddHeader (arp); |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
247 |
cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), PROT_NUMBER); |
242 | 248 |
} |
249 |
||
250 |
void |
|
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
746
diff
changeset
|
251 |
ArpL3Protocol::SendArpReply (ArpCache const *cache, Ipv4Address toIp, Address toMac) |
242 | 252 |
{ |
1505 | 253 |
NS_LOG_FUNCTION; |
242 | 254 |
ArpHeader arp; |
1505 | 255 |
NS_LOG_LOGIC ("ARP: sending reply from node "<<m_node->GetId ()<< |
933
df68dad55087
WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
746
diff
changeset
|
256 |
"|| 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
|
257 |
" / " << 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
|
258 |
" || dst: " << toMac << " / " << toIp); |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
259 |
arp.SetReply (cache->GetDevice ()->GetAddress (), |
242 | 260 |
cache->GetInterface ()->GetAddress (), |
261 |
toMac, toIp); |
|
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1505
diff
changeset
|
262 |
Ptr<Packet> packet = Create<Packet> (); |
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1505
diff
changeset
|
263 |
packet->AddHeader (arp); |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
552
diff
changeset
|
264 |
cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER); |
242 | 265 |
} |
266 |
||
267 |
}//namespace ns3 |