From ed80214449195de124257e6d03fc7ffd3b512264 Mon Sep 17 00:00:00 2001 From: Tim Schubert Date: Thu, 2 Jul 2020 10:27:15 +0200 Subject: [PATCH] Add helper for pre-filling ND cache --- examples/isl-example.cc | 40 ++-------------------------------------- wscript | 2 ++ 2 files changed, 4 insertions(+), 38 deletions(-) diff --git a/examples/isl-example.cc b/examples/isl-example.cc index b9708e9..74501c6 100644 --- a/examples/isl-example.cc +++ b/examples/isl-example.cc @@ -12,43 +12,6 @@ using namespace ns3; 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 = nodes.Get (i); - Ptr dev = node->GetDevice (1); // TODO right index? - uint32_t ifIndex = dev->GetIfIndex (); - Ptr ipv6 = node->GetObject (); - Ptr interface = ipv6->GetInterface (ifIndex); - Ptr cache = interface->GetNdiscCache (); - for (uint32_t j = 0; j < nodes.GetN (); j++) - { - // every other device - if (i == j) - { - continue; - } - Ptr 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 main (int argc, char *argv[]) { @@ -79,7 +42,8 @@ main (int argc, char *argv[]) Ipv6InterfaceContainer interfaces = address.Assign (devices); - PrepareNds (nodes, interfaces); + NdCacheHelper nsHelper; + nsHelper.Install (nodes, interfaces); UdpEchoServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (nodes); diff --git a/wscript b/wscript index 3e8e7c0..2ab04d5 100644 --- a/wscript +++ b/wscript @@ -20,6 +20,7 @@ def build(bld): 'helper/leo-helper.cc', 'model/mock-net-device.cc', 'model/mock-channel.cc', + 'helper/nd-cache-helper.cc', ] module_test = bld.create_ns3_module_test_library('leo') @@ -41,6 +42,7 @@ def build(bld): 'helper/leo-helper.h', 'model/mock-net-device.h', 'model/mock-channel.h', + 'helper/nd-cache-helper.h', ] if bld.env.ENABLE_EXAMPLES: