how to pre-populate ARP cache ?

1,314 views
Skip to first unread message

gglggl

unread,
Feb 10, 2010, 5:20:34 PM2/10/10
to ns-3-users
Does anyone have some code snippet that shows how to pre-populate the
ARP cache ?

Pavel Boyko

unread,
Feb 11, 2010, 1:23:02 AM2/11/10
to ns-3-...@googlegroups.com
On Thu, Feb 11, 2010 at 1:20 AM, gglggl <ggl...@gmail.com> wrote:
> Does anyone have some code snippet that shows how to pre-populate the
> ARP cache ?

void
PopulateArpCache ()
{
Ptr<ArpCache> arp = CreateObject<ArpCache> ();
arp->SetAliveTimeout (Seconds(3600 * 24 * 365));
for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
{
Ptr<Ipv4L3Protocol> ip = (*i)->GetObject<Ipv4L3Protocol> ();
NS_ASSERT(ip !=0);
ObjectVectorValue interfaces;
ip->GetAttribute("InterfaceList", interfaces);
for(ObjectVectorValue::Iterator j = interfaces.Begin(); j !=
interfaces.End (); j ++)
{
Ptr<Ipv4Interface> ipIface = (*j)->GetObject<Ipv4Interface> ();
NS_ASSERT(ipIface != 0);
Ptr<NetDevice> device = ipIface->GetDevice();
NS_ASSERT(device != 0);
Mac48Address addr = Mac48Address::ConvertFrom(device->GetAddress ());
for(uint32_t k = 0; k < ipIface->GetNAddresses (); k ++)
{
Ipv4Address ipAddr = ipIface->GetAddress (k).GetLocal();
if(ipAddr == Ipv4Address::GetLoopback())
continue;
ArpCache::Entry * entry = arp->Add(ipAddr);
entry->MarkWaitReply(0);
entry->MarkAlive(addr);
}
}
}
for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)
{
Ptr<Ipv4L3Protocol> ip = (*i)->GetObject<Ipv4L3Protocol> ();
NS_ASSERT(ip !=0);
ObjectVectorValue interfaces;
ip->GetAttribute("InterfaceList", interfaces);
for(ObjectVectorValue::Iterator j = interfaces.Begin(); j !=
interfaces.End (); j ++)
{
Ptr<Ipv4Interface> ipIface = (*j)->GetObject<Ipv4Interface> ();
ipIface->SetAttribute("ArpCache", PointerValue(arp));
}
}
}

Pavel

Grilo

unread,
Oct 16, 2014, 12:55:18 PM10/16/14
to ns-3-...@googlegroups.com, pavel...@gmail.com
Hello,

I get an error in line:

Ptr<Ipv4Interface> ipIface = (*j)->GetObject<Ipv4Interface> ();

The compiler reports:

../examples/udp-alarm-app/udp-fault-detection-app.cc:501:40: error: base operand of ‘->’ has non-pointer type ‘const std::pair<const unsigned int, ns3::Ptr<ns3::Object> >’
../examples/udp-alarm-app/udp-fault-detection-app.cc:501:65: error: expected primary-expression before ‘>’ token
../examples/udp-alarm-app/udp-fault-detection-app.cc:501:68: error: expected primary-expression before ‘)’ token

I'm using ns-3.21. Any ideas?

Regards,
António

Tommaso Pecorella

unread,
Oct 16, 2014, 1:57:31 PM10/16/14
to ns-3-...@googlegroups.com, pavel...@gmail.com
Hi,

may I suggest to read the error message ?
It's extremely clear, and I can't explain further without insulting your intelligence.

Cheers,

T.

Grilo

unread,
Oct 16, 2014, 7:15:06 PM10/16/14
to ns-3-...@googlegroups.com, pavel...@gmail.com
Well, thanks for not insulting my intelligence. It's indeed obvious. 


Grilo

unread,
Oct 17, 2014, 6:41:37 AM10/17/14
to ns-3-...@googlegroups.com, pavel...@gmail.com
Solved. Thanks.

Joon 호

unread,
Aug 20, 2017, 1:55:54 AM8/20/17
to ns-3-users, pavel...@gmail.com
Hi Pavel,
then where do I call PopulateArpCache() function ?

Regards,
Joon

2014년 10월 17일 금요일 오후 7시 41분 37초 UTC+9, Grilo 님의 말:
Solved. Thanks.

Konrad Pustelnik

unread,
Nov 1, 2018, 3:35:17 PM11/1/18
to ns-3-users
Hello I have one problem,
assert failed. cond="ip !=0", file=../scratch/wifiac-testing.cc, line=509
terminate called without an active exception

Could You help me ?
Reply all
Reply to author
Forward
0 new messages