OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2006 INRIA | 3 * Copyright (c) 2006 INRIA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 ArpCache::Entry *entry = cache->Lookup (from); | 222 ArpCache::Entry *entry = cache->Lookup (from); |
223 if (entry != 0) | 223 if (entry != 0) |
224 { | 224 { |
225 if (entry->IsWaitReply ())· | 225 if (entry->IsWaitReply ())· |
226 { | 226 { |
227 NS_LOG_LOGIC ("node="<< m_node->GetId () <<· | 227 NS_LOG_LOGIC ("node="<< m_node->GetId () <<· |
228 ", got reply from " << arp.GetSourceIpv4Address
() | 228 ", got reply from " << arp.GetSourceIpv4Address
() |
229 << " for waiting entry -- flush"); | 229 << " for waiting entry -- flush"); |
230 Address from_mac = arp.GetSourceHardwareAddress (); | 230 Address from_mac = arp.GetSourceHardwareAddress (); |
231 entry->MarkAlive (from_mac); | 231 entry->MarkAlive (from_mac); |
232 Ptr<Packet> pending = entry->DequeuePending (); | 232 ArpCache::PacketWithIpv4Header pending = entry->DequeuePending
(); |
233 while (pending != 0) | 233 while (pending.first != 0) |
234 { | 234 { |
235 cache->GetInterface ()->Send (pending, | 235 cache->GetInterface ()->Send (pending.first, pending.secon
d, |
236 arp.GetSourceIpv4Address ())
; | 236 arp.GetSourceIpv4Address ())
; |
237 pending = entry->DequeuePending (); | 237 pending = entry->DequeuePending (); |
238 } | 238 } |
239 }· | 239 }· |
240 else· | 240 else· |
241 { | 241 { |
242 // ignore this reply which might well be an attempt· | 242 // ignore this reply which might well be an attempt· |
243 // at poisening my arp cache. | 243 // at poisening my arp cache. |
244 NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got reply from " <
< | 244 NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got reply from " <
< |
245 arp.GetSourceIpv4Address () << | 245 arp.GetSourceIpv4Address () << |
(...skipping 11 matching lines...) Expand all Loading... |
257 } | 257 } |
258 if (found == false) | 258 if (found == false) |
259 { | 259 { |
260 NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got request from " << | 260 NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got request from " << |
261 arp.GetSourceIpv4Address () << " for unknown address " << | 261 arp.GetSourceIpv4Address () << " for unknown address " << |
262 arp.GetDestinationIpv4Address () << " -- drop"); | 262 arp.GetDestinationIpv4Address () << " -- drop"); |
263 } | 263 } |
264 } | 264 } |
265 | 265 |
266 bool· | 266 bool· |
267 ArpL3Protocol::Lookup (Ptr<Packet> packet, Ipv4Address destination, | 267 ArpL3Protocol::Lookup (Ptr<Packet> packet, const Ipv4Header & ipHeader, Ipv4Addr
ess destination, |
268 Ptr<NetDevice> device, | 268 Ptr<NetDevice> device, |
269 Ptr<ArpCache> cache, | 269 Ptr<ArpCache> cache, |
270 Address *hardwareDestination) | 270 Address *hardwareDestination) |
271 { | 271 { |
272 NS_LOG_FUNCTION (this << packet << destination << device << cache << hardwareD
estination); | 272 NS_LOG_FUNCTION (this << packet << destination << device << cache << hardwareD
estination); |
273 ArpCache::Entry *entry = cache->Lookup (destination); | 273 ArpCache::Entry *entry = cache->Lookup (destination); |
274 if (entry != 0) | 274 if (entry != 0) |
275 { | 275 { |
276 if (entry->IsExpired ())· | 276 if (entry->IsExpired ())· |
277 { | 277 { |
278 if (entry->IsDead ())· | 278 if (entry->IsDead ())· |
279 { | 279 { |
280 NS_LOG_LOGIC ("node="<<m_node->GetId ()<< | 280 NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
281 ", dead entry for " << destination << " expired -- s
end arp request"); | 281 ", dead entry for " << destination << " expired -- s
end arp request"); |
282 entry->MarkWaitReply (packet); | 282 entry->MarkWaitReply (ArpCache::PacketWithIpv4Header (packet, ipHe
ader)); |
283 Simulator::Schedule (Time (MilliSeconds (m_requestJitter->GetValue
())), &ArpL3Protocol::SendArpRequest, this, cache, destination); | 283 Simulator::Schedule (Time (MilliSeconds (m_requestJitter->GetValue
())), &ArpL3Protocol::SendArpRequest, this, cache, destination); |
284 }· | 284 }· |
285 else if (entry->IsAlive ())· | 285 else if (entry->IsAlive ())· |
286 { | 286 { |
287 NS_LOG_LOGIC ("node="<<m_node->GetId ()<< | 287 NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
288 ", alive entry for " << destination << " expired --
send arp request"); | 288 ", alive entry for " << destination << " expired --
send arp request"); |
289 entry->MarkWaitReply (packet); | 289 entry->MarkWaitReply (ArpCache::PacketWithIpv4Header (packet, ipHe
ader)); |
290 Simulator::Schedule (Time (MilliSeconds (m_requestJitter->GetValue
())), &ArpL3Protocol::SendArpRequest, this, cache, destination); | 290 Simulator::Schedule (Time (MilliSeconds (m_requestJitter->GetValue
())), &ArpL3Protocol::SendArpRequest, this, cache, destination); |
291 }· | 291 }· |
292 else | 292 else |
293 { | 293 { |
294 NS_FATAL_ERROR ("Test for possibly unreachable code-- please file
a bug report, with a test case, if this is ever hit"); | 294 NS_FATAL_ERROR ("Test for possibly unreachable code-- please file
a bug report, with a test case, if this is ever hit"); |
295 } | 295 } |
296 }· | 296 }· |
297 else· | 297 else· |
298 { | 298 { |
299 if (entry->IsDead ())· | 299 if (entry->IsDead ())· |
300 { | 300 { |
301 NS_LOG_LOGIC ("node="<<m_node->GetId ()<< | 301 NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
302 ", dead entry for " << destination << " valid -- dro
p"); | 302 ", dead entry for " << destination << " valid -- dro
p"); |
| 303 // add the Ipv4 header for tracing purposes |
| 304 packet->AddHeader (ipHeader); |
303 m_dropTrace (packet); | 305 m_dropTrace (packet); |
304 }· | 306 }· |
305 else if (entry->IsAlive ())· | 307 else if (entry->IsAlive ())· |
306 { | 308 { |
307 NS_LOG_LOGIC ("node="<<m_node->GetId ()<< | 309 NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
308 ", alive entry for " << destination << " valid -- se
nd"); | 310 ", alive entry for " << destination << " valid -- se
nd"); |
309 *hardwareDestination = entry->GetMacAddress (); | 311 *hardwareDestination = entry->GetMacAddress (); |
310 return true; | 312 return true; |
311 }· | 313 }· |
312 else if (entry->IsWaitReply ())· | 314 else if (entry->IsWaitReply ())· |
313 { | 315 { |
314 NS_LOG_LOGIC ("node="<<m_node->GetId ()<< | 316 NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
315 ", wait reply for " << destination << " valid -- dro
p previous"); | 317 ", wait reply for " << destination << " valid -- dro
p previous"); |
316 if (!entry->UpdateWaitReply (packet)) | 318 if (!entry->UpdateWaitReply (ArpCache::PacketWithIpv4Header (packe
t, ipHeader))) |
317 { | 319 { |
| 320 // add the Ipv4 header for tracing purposes |
| 321 packet->AddHeader (ipHeader); |
318 m_dropTrace (packet); | 322 m_dropTrace (packet); |
319 } | 323 } |
320 } | 324 } |
321 else if (entry-> IsPermanent ()) | 325 else if (entry-> IsPermanent ()) |
322 { | 326 { |
323 NS_LOG_LOGIC ("node="<<m_node->GetId ()<< | 327 NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
324 ", permanent for " << destination << "valid -- send"
); | 328 ", permanent for " << destination << "valid -- send"
); |
325 *hardwareDestination = entry->GetMacAddress (); | 329 *hardwareDestination = entry->GetMacAddress (); |
326 return true; | 330 return true; |
327 } | 331 } |
328 else | 332 else |
329 { | 333 { |
330 NS_LOG_LOGIC ("Test for possibly unreachable code-- please file a
bug report, with a test case, if this is ever hit"); | 334 NS_LOG_LOGIC ("Test for possibly unreachable code-- please file a
bug report, with a test case, if this is ever hit"); |
331 } | 335 } |
332 } | 336 } |
333 } | 337 } |
334 else | 338 else |
335 { | 339 { |
336 // This is our first attempt to transmit data to this destination. | 340 // This is our first attempt to transmit data to this destination. |
337 NS_LOG_LOGIC ("node="<<m_node->GetId ()<< | 341 NS_LOG_LOGIC ("node="<<m_node->GetId ()<< |
338 ", no entry for " << destination << " -- send arp request"); | 342 ", no entry for " << destination << " -- send arp request"); |
339 entry = cache->Add (destination); | 343 entry = cache->Add (destination); |
340 entry->MarkWaitReply (packet); | 344 entry->MarkWaitReply (ArpCache::PacketWithIpv4Header (packet, ipHeader)); |
341 Simulator::Schedule (Time (MilliSeconds (m_requestJitter->GetValue ())), &
ArpL3Protocol::SendArpRequest, this, cache, destination); | 345 Simulator::Schedule (Time (MilliSeconds (m_requestJitter->GetValue ())), &
ArpL3Protocol::SendArpRequest, this, cache, destination); |
342 } | 346 } |
343 return false; | 347 return false; |
344 } | 348 } |
345 | 349 |
346 void | 350 void |
347 ArpL3Protocol::SendArpRequest (Ptr<const ArpCache> cache, Ipv4Address to) | 351 ArpL3Protocol::SendArpRequest (Ptr<const ArpCache> cache, Ipv4Address to) |
348 { | 352 { |
349 NS_LOG_FUNCTION (this << cache << to); | 353 NS_LOG_FUNCTION (this << cache << to); |
350 ArpHeader arp; | 354 ArpHeader arp; |
(...skipping 22 matching lines...) Expand all Loading... |
373 "|| src: " << cache->GetDevice ()->GetAddress () << | 377 "|| src: " << cache->GetDevice ()->GetAddress () << |
374 " / " << myIp << | 378 " / " << myIp << |
375 " || dst: " << toMac << " / " << toIp); | 379 " || dst: " << toMac << " / " << toIp); |
376 arp.SetReply (cache->GetDevice ()->GetAddress (), myIp, toMac, toIp); | 380 arp.SetReply (cache->GetDevice ()->GetAddress (), myIp, toMac, toIp); |
377 Ptr<Packet> packet = Create<Packet> (); | 381 Ptr<Packet> packet = Create<Packet> (); |
378 packet->AddHeader (arp); | 382 packet->AddHeader (arp); |
379 cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER); | 383 cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER); |
380 } | 384 } |
381 | 385 |
382 } // namespace ns3 | 386 } // namespace ns3 |
OLD | NEW |