mirror of
https://gitlab.ibr.cs.tu-bs.de/tschuber/ns-3-leo.git
synced 2025-06-08 18:13:57 +02:00
Add helper for pre-filling ND cache
This commit is contained in:
parent
efa52f8e51
commit
ed80214449
2 changed files with 4 additions and 38 deletions
|
@ -12,43 +12,6 @@ using namespace ns3;
|
||||||
|
|
||||||
NS_LOG_COMPONENT_DEFINE ("IslExample");
|
NS_LOG_COMPONENT_DEFINE ("IslExample");
|
||||||
|
|
||||||
void PrepareNds (NodeContainer &nodes, Ipv6InterfaceContainer &interfaces)
|
|
||||||
{
|
|
||||||
// prepare NDS cache
|
|
||||||
for (uint32_t i = 0; i < nodes.GetN (); i++)
|
|
||||||
{
|
|
||||||
Ptr<Node> node = nodes.Get (i);
|
|
||||||
Ptr<NetDevice> dev = node->GetDevice (1); // TODO right index?
|
|
||||||
uint32_t ifIndex = dev->GetIfIndex ();
|
|
||||||
Ptr<Ipv6L3Protocol> ipv6 = node->GetObject<Ipv6L3Protocol> ();
|
|
||||||
Ptr<Ipv6Interface> interface = ipv6->GetInterface (ifIndex);
|
|
||||||
Ptr<NdiscCache> cache = interface->GetNdiscCache ();
|
|
||||||
for (uint32_t j = 0; j < nodes.GetN (); j++)
|
|
||||||
{
|
|
||||||
// every other device
|
|
||||||
if (i == j)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Ptr<NetDevice> otherDevice = nodes.Get (j)->GetDevice (1);
|
|
||||||
Address address = otherDevice->GetAddress (); // MAC
|
|
||||||
|
|
||||||
// and associated address
|
|
||||||
uint32_t otherIfIndex = otherDevice->GetIfIndex ();
|
|
||||||
// TODO which address to use? site-local, global, link?
|
|
||||||
Ipv6Address ipaddr = interfaces.GetAddress (otherIfIndex, 1); // IP
|
|
||||||
|
|
||||||
// update cache
|
|
||||||
NdiscCache::Entry* entry = cache->Lookup (ipaddr);
|
|
||||||
if (entry == 0)
|
|
||||||
{
|
|
||||||
entry = cache->Add (ipaddr);
|
|
||||||
}
|
|
||||||
entry->SetMacAddress (address);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -79,7 +42,8 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
Ipv6InterfaceContainer interfaces = address.Assign (devices);
|
Ipv6InterfaceContainer interfaces = address.Assign (devices);
|
||||||
|
|
||||||
PrepareNds (nodes, interfaces);
|
NdCacheHelper nsHelper;
|
||||||
|
nsHelper.Install (nodes, interfaces);
|
||||||
|
|
||||||
UdpEchoServerHelper echoServer (9);
|
UdpEchoServerHelper echoServer (9);
|
||||||
ApplicationContainer serverApps = echoServer.Install (nodes);
|
ApplicationContainer serverApps = echoServer.Install (nodes);
|
||||||
|
|
2
wscript
2
wscript
|
@ -20,6 +20,7 @@ def build(bld):
|
||||||
'helper/leo-helper.cc',
|
'helper/leo-helper.cc',
|
||||||
'model/mock-net-device.cc',
|
'model/mock-net-device.cc',
|
||||||
'model/mock-channel.cc',
|
'model/mock-channel.cc',
|
||||||
|
'helper/nd-cache-helper.cc',
|
||||||
]
|
]
|
||||||
|
|
||||||
module_test = bld.create_ns3_module_test_library('leo')
|
module_test = bld.create_ns3_module_test_library('leo')
|
||||||
|
@ -41,6 +42,7 @@ def build(bld):
|
||||||
'helper/leo-helper.h',
|
'helper/leo-helper.h',
|
||||||
'model/mock-net-device.h',
|
'model/mock-net-device.h',
|
||||||
'model/mock-channel.h',
|
'model/mock-channel.h',
|
||||||
|
'helper/nd-cache-helper.h',
|
||||||
]
|
]
|
||||||
|
|
||||||
if bld.env.ENABLE_EXAMPLES:
|
if bld.env.ENABLE_EXAMPLES:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue