/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ #include "ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/internet-module.h" #include "ns3/log.h" #include "../model/leo-mock-net-device.h" #include "arp-cache-helper.h" namespace ns3 { NS_LOG_COMPONENT_DEFINE ("ArpCacheHelper"); void ArpCacheHelper::Install (NetDeviceContainer &devices, Ipv4InterfaceContainer &interfaces) const { NS_LOG_FUNCTION (this); for (size_t i = 0; i < devices.GetN (); i ++) { Ptr dev = devices.Get (i); Ptr node = dev->GetNode (); NS_LOG_INFO ("Preparing ARP cache of " << node); Ptr ipv4 = node->GetObject (); int32_t ifIndex = ipv4->GetInterfaceForDevice (dev); Ptr interface = ipv4->GetInterface (ifIndex); Ptr cache = interface->GetArpCache (); for (uint32_t j = 0; j < devices.GetN (); j++) { // every other device, that is not of same "type" Ptr otherDevice = devices.Get (j); Ptr leoDev = DynamicCast (dev); Ptr otherLeoDev = DynamicCast (otherDevice); if (i == j || (leoDev != 0 && otherLeoDev != 0 && leoDev->GetDeviceType () == otherLeoDev->GetDeviceType ())) { continue; } Address address = otherDevice->GetAddress (); // MAC // and associated address uint32_t otherIfIndex = otherDevice->GetIfIndex (); Ipv4Address ipaddr = interfaces.GetAddress (otherIfIndex, 0); // IP // update cache ArpCache::Entry* entry = cache->Lookup (ipaddr); if (entry == 0) { entry = cache->Add (ipaddr); } entry->SetMacAddress (address); NS_LOG_DEBUG ("Added entry for " << address); } } } };