|
25 |
#include "ns3/node.h" |
25 |
#include "ns3/node.h" |
26 |
#include "ns3/trace-source-accessor.h" |
26 |
#include "ns3/trace-source-accessor.h" |
27 |
#include "ns3/names.h" |
27 |
#include "ns3/names.h" |
|
|
28 |
#include "ns3/node-list.h" |
29 |
#include "ns3/ipv4-l3-protocol.h" |
30 |
#include "ns3/object-vector.h" |
31 |
#include "ns3/pointer.h" |
28 |
|
32 |
|
29 |
#include "arp-cache.h" |
33 |
#include "arp-cache.h" |
30 |
#include "arp-header.h" |
34 |
#include "arp-header.h" |
|
535 |
m_retries = 0; |
539 |
m_retries = 0; |
536 |
} |
540 |
} |
537 |
|
541 |
|
|
|
542 |
void |
543 |
ArpCache::PopulateArpCache () |
544 |
{ |
545 |
Ptr<Packet> dummy = Create<Packet> (); |
546 |
Ptr<ArpCache> arp = CreateObject<ArpCache> (); |
547 |
arp->SetAliveTimeout (Seconds (3600 * 24 * 365)); |
548 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); |
549 |
++i) |
550 |
{ |
551 |
Ptr<Ipv4L3Protocol> ip = (*i)->GetObject<Ipv4L3Protocol> (); |
552 |
NS_ASSERT (ip != 0); |
553 |
ObjectVectorValue interfaces; |
554 |
ip->GetAttribute ("InterfaceList", interfaces); |
555 |
for (ObjectVectorValue::Iterator j = interfaces.Begin (); j != |
556 |
interfaces.End (); j++) |
557 |
{ |
558 |
Ptr<Ipv4Interface> ipIface = |
559 |
j->second->GetObject<Ipv4Interface> (); |
560 |
NS_ASSERT (ipIface != 0); |
561 |
Ptr<NetDevice> device = ipIface->GetDevice (); |
562 |
NS_ASSERT (device != 0); |
563 |
Mac48Address addr = Mac48Address::ConvertFrom |
564 |
(device->GetAddress ()); |
565 |
for (uint32_t k = 0; k < ipIface->GetNAddresses (); k ++) |
566 |
{ |
567 |
Ipv4Address ipAddr = ipIface->GetAddress (k).GetLocal (); |
568 |
if (ipAddr == Ipv4Address::GetLoopback ()) |
569 |
{ |
570 |
continue; |
571 |
} |
572 |
Ipv4Header ipHeader; |
573 |
ArpCache::Entry *entry = arp->Add (ipAddr); |
574 |
entry->MarkWaitReply (Ipv4PayloadHeaderPair(dummy,ipHeader)); |
575 |
entry->MarkAlive (addr); |
576 |
entry->ClearPendingPacket(); |
577 |
entry->MarkPermanent (); |
578 |
} |
579 |
} |
580 |
} |
581 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); |
582 |
++i) |
583 |
{ |
584 |
Ptr<Ipv4L3Protocol> ip = (*i)->GetObject<Ipv4L3Protocol> (); |
585 |
NS_ASSERT (ip != 0); |
586 |
ObjectVectorValue interfaces; |
587 |
ip->GetAttribute ("InterfaceList", interfaces); |
588 |
for (ObjectVectorValue::Iterator j = interfaces.Begin (); j != |
589 |
interfaces.End (); j ++) |
590 |
{ |
591 |
Ptr<Ipv4Interface> ipIface = |
592 |
j->second->GetObject<Ipv4Interface> (); |
593 |
ipIface->SetAttribute ("ArpCache", PointerValue (arp)); |
594 |
} |
595 |
} |
596 |
} |
597 |
|
538 |
} // namespace ns3 |
598 |
} // namespace ns3 |
539 |
|
599 |
|