diff --git a/examples/leo-example.cc b/examples/leo-example.cc index cc25d77..d28ad4e 100644 --- a/examples/leo-example.cc +++ b/examples/leo-example.cc @@ -1,4 +1,5 @@ /* -*- 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" @@ -6,7 +7,7 @@ #include "ns3/node-container.h" #include "ns3/core-module.h" -#include "../helper/leo-helper.h" +#include "ns3/leo-module.h" using namespace ns3; @@ -40,17 +41,7 @@ main (int argc, char *argv[]) leo.SetChannelAttribute ("PropagationLoss", StringValue ("ns3::IslPropagationLossModel")); leo.SetDeviceAttribute ("MobilityModel", StringValue ("ns3::LeoMobilityModel")); - NetDeviceContainer devices; - devices = leo.Install (satellites, gateways, terminals); - - InternetStackHelper stack; - stack.Install (satellites); - stack.Install (gateways); - stack.Install (terminals); - - // make all devices addressable - Ipv6AddressHelper address; - Ipv6InterfaceContainer interfaces = address.Assign (devices); + leo.Install (satellites, gateways, terminals); // we want to ping terminals UdpEchoServerHelper echoServer (9); diff --git a/helper/leo-helper.cc b/helper/leo-helper.cc index d1232b1..cb405e7 100644 --- a/helper/leo-helper.cc +++ b/helper/leo-helper.cc @@ -1,5 +1,7 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +#include "nd-cache-helper.h" + #include "leo-helper.h" namespace ns3 { @@ -10,35 +12,38 @@ LeoHelper::LeoHelper() // TODO use template? NetDeviceContainer -LeoHelper::Install (NodeContainer satellites, NodeContainer gateways, NodeContainer terminals) +LeoHelper::Install (NodeContainer &satellites, NodeContainer &gateways, NodeContainer &terminals) { - NetDeviceContainer container = m_islChannelHelper.Install (satellites); - container.Add (m_gwChannelHelper.Install (satellites, gateways)); - container.Add (m_utChannelHelper.Install (satellites, terminals)); + NetDeviceContainer container; - return container; -} + // Create sets of net devices for individual networks + NetDeviceContainer islNet, gwNet, utNet; + islNet = m_islChannelHelper.Install (satellites); + gwNet = m_gwChannelHelper.Install (satellites, gateways); + utNet = m_utChannelHelper.Install (satellites, terminals); -NetDeviceContainer -LeoHelper::Install (std::vector > &satellites, - std::vector > &gateways, - std::vector > &terminals) -{ - NetDeviceContainer container = m_islChannelHelper.Install (satellites); - container.Add (m_gwChannelHelper.Install (satellites, gateways)); - container.Add (m_utChannelHelper.Install (satellites, terminals)); + // Install internet stack on nodes + InternetStackHelper stack; + stack.Install (satellites); + stack.Install (gateways); + stack.Install (terminals); - return container; -} + // Make all networks addressable + Ipv6AddressHelper address; + Ipv6InterfaceContainer islAddrs = address.Assign (islNet); + Ipv6InterfaceContainer gwAddrs = address.Assign (gwNet); + Ipv6InterfaceContainer utAddrs = address.Assign (utNet); -NetDeviceContainer -LeoHelper::Install (std::vector &satellites, - std::vector &gateways, - std::vector &terminals) -{ - NetDeviceContainer container = m_islChannelHelper.Install (satellites); - container.Add (m_gwChannelHelper.Install (satellites, gateways)); - container.Add (m_utChannelHelper.Install (satellites, terminals)); + // Pre-fill the ND caches of networks + NdCacheHelper ndCache; + ndCache.Install (islNet, islAddrs); + ndCache.Install (gwNet, gwAddrs); + ndCache.Install (utNet, utAddrs); + + // Add to resulting container of net devices + container.Add (islNet); + container.Add (gwNet); + container.Add (utNet); return container; } diff --git a/helper/leo-helper.h b/helper/leo-helper.h index 019222b..c38df8d 100644 --- a/helper/leo-helper.h +++ b/helper/leo-helper.h @@ -53,27 +53,10 @@ public: * * Same is done with each satellite and terminal node. */ - NetDeviceContainer Install (NodeContainer satellites, NodeContainer gateways, NodeContainer terminals); + NetDeviceContainer Install (NodeContainer &satellites, + NodeContainer &gateways, + NodeContainer &terminals); - /** - * \param nodes Nodes - * \return a NetDeviceContainer for nodes - * - * Saves you from having to construct a temporary NodeContainer. - */ - NetDeviceContainer Install (std::vector > &satellites, - std::vector > &gateways, - std::vector > &terminals); - - /** - * \param nodes Names of the nodes - * \return a NetDeviceContainer for nodes - * - * Saves you from having to construct a temporary NodeContainer. - */ - NetDeviceContainer Install (std::vector &satellites, - std::vector &gateways, - std::vector &terminals); /** * Each point to point net device must have a queue to pass packets through. * This method allows one to set the type of the queue that is automatically diff --git a/helper/nd-cache-helper.cc b/helper/nd-cache-helper.cc new file mode 100644 index 0000000..36c98a4 --- /dev/null +++ b/helper/nd-cache-helper.cc @@ -0,0 +1,52 @@ +#include "ns3/core-module.h" +#include "ns3/network-module.h" +#include "ns3/internet-module.h" +#include "../model/leo-mock-net-device.h" + +#include "nd-cache-helper.h" + +namespace ns3 +{ + +void +NdCacheHelper::Install (NetDeviceContainer &devices, Ipv6InterfaceContainer &interfaces) const +{ + // prepare NDS cache + for (uint32_t i = 0; i < devices.GetN (); i++) + { + Ptr dev = devices.Get (i); + Ptr node = dev->GetNode (); + uint32_t ifIndex = dev->GetIfIndex (); + Ptr ipv6 = node->GetObject (); + Ptr interface = ipv6->GetInterface (ifIndex); + Ptr cache = interface->GetNdiscCache (); + 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 (); + 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); + } + } +} + +}; /* namespace ns3 */ diff --git a/helper/nd-cache-helper.h b/helper/nd-cache-helper.h new file mode 100644 index 0000000..2b20e77 --- /dev/null +++ b/helper/nd-cache-helper.h @@ -0,0 +1,23 @@ +/* -*- 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/applications-module.h" +#include "ns3/node-container.h" + +#ifndef NDS_CACHE_HELPER_ +#define NDS_CACHE_HELPER_ + +namespace ns3 { + +class NdCacheHelper +{ +public: + void Install (NetDeviceContainer &devices, Ipv6InterfaceContainer &interfaces) const; + void Install (NetDeviceContainer &devicesSrc, NetDeviceContainer &devicesDst, Ipv6InterfaceContainer &interfaces) const; +}; + +}; /* namespace ns3 */ + +#endif /* NDS_CACHE_HELPER */