diff --git a/helper/arp-cache-helper.cc b/helper/arp-cache-helper.cc index c1bb392..f957561 100644 --- a/helper/arp-cache-helper.cc +++ b/helper/arp-cache-helper.cc @@ -3,6 +3,7 @@ #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" @@ -10,13 +11,18 @@ 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); @@ -47,6 +53,8 @@ ArpCacheHelper::Install (NetDeviceContainer &devices, Ipv4InterfaceContainer &in entry = cache->Add (ipaddr); } entry->SetMacAddress (address); + + NS_LOG_DEBUG ("Added entry for " << address); } } } diff --git a/helper/arp-cache-helper.h b/helper/arp-cache-helper.h index 7349c9f..2d03b74 100644 --- a/helper/arp-cache-helper.h +++ b/helper/arp-cache-helper.h @@ -20,4 +20,4 @@ public: }; /* namespace ns3 */ -#endif /* ARP_CACHE_HELPER */ +#endif /* ARP_CACHE_HELPER_H */ diff --git a/helper/isl-helper.cc b/helper/isl-helper.cc index fdd89e5..26bd92e 100644 --- a/helper/isl-helper.cc +++ b/helper/isl-helper.cc @@ -224,12 +224,15 @@ IslHelper::Install (NodeContainer c) NetDeviceContainer IslHelper::Install (std::vector > &nodes) { + NS_LOG_FUNCTION (this); + Ptr channel = m_channelFactory.Create (); NetDeviceContainer container; for (Ptr node: nodes) { + NS_LOG_DEBUG ("Adding device for node " << node->GetId ()); Ptr dev = m_deviceFactory.Create (); dev->SetAddress (Mac48Address::Allocate ()); node->AddDevice (dev); diff --git a/helper/leo-channel-helper.cc b/helper/leo-channel-helper.cc index 19a419b..70eaff4 100644 --- a/helper/leo-channel-helper.cc +++ b/helper/leo-channel-helper.cc @@ -230,6 +230,8 @@ LeoChannelHelper::EnableAsciiInternal ( NetDeviceContainer LeoChannelHelper::Install (std::vector > &satellites, std::vector > &stations) { + NS_LOG_FUNCTION (this); + Ptr channel = m_channelFactory.Create (); NetDeviceContainer container; @@ -243,6 +245,8 @@ LeoChannelHelper::Install (std::vector > &satellites, std::vectorSetQueue (queue); dev->Attach (channel); container.Add (dev); + + NS_LOG_DEBUG ("Added device for node " << node->GetId ()); } for (Ptr node : stations) @@ -254,6 +258,8 @@ LeoChannelHelper::Install (std::vector > &satellites, std::vectorSetQueue (queue); dev->Attach (channel); container.Add (dev); + + NS_LOG_DEBUG ("Added device for node " << node->GetId ()); } return container; @@ -270,15 +276,19 @@ LeoChannelHelper::Install (NodeContainer &satellites, NodeContainer &stations) NetDeviceContainer LeoChannelHelper::Install (std::vector &satellites, std::vector &stations) { + NS_LOG_FUNCTION (this); + std::vector > sats; std::vector > stats; for (std::string name : satellites) { + NS_LOG_DEBUG ("Adding node " << name); Ptr node = Names::Find(name); sats.push_back (node); } for (std::string name : stations) { + NS_LOG_DEBUG ("Adding node " << name); Ptr node = Names::Find(name); stats.push_back (node); } diff --git a/helper/leo-helper.cc b/helper/leo-helper.cc index aa584de..5fe2cc7 100644 --- a/helper/leo-helper.cc +++ b/helper/leo-helper.cc @@ -29,17 +29,17 @@ LeoHelper::Install (NodeContainer &satellites, NodeContainer &gateways, NodeCont m_stackHelper.Install (gateways); m_stackHelper.Install (terminals); - // Make all networks addressable - Ipv6AddressHelper address; - Ipv6InterfaceContainer islAddrs = address.Assign (islNet); - Ipv6InterfaceContainer gwAddrs = address.Assign (gwNet); - Ipv6InterfaceContainer utAddrs = address.Assign (utNet); + //// Make all networks addressable + //Ipv6AddressHelper address; + //Ipv6InterfaceContainer islAddrs = address.Assign (islNet); + //Ipv6InterfaceContainer gwAddrs = address.Assign (gwNet); + //Ipv6InterfaceContainer utAddrs = address.Assign (utNet); - // Pre-fill the ND caches of networks - NdCacheHelper ndCache; - ndCache.Install (islNet, islAddrs); - ndCache.Install (gwNet, gwAddrs); - ndCache.Install (utNet, utAddrs); + //// Pre-fill the ND caches of networks + //NdCacheHelper ndCache; + //ndCache.Install (islNet, islAddrs); + //ndCache.Install (gwNet, gwAddrs); + //ndCache.Install (utNet, utAddrs); // Make all networks addressable for legacy protocol Ipv4AddressHelper legacy; diff --git a/helper/nd-cache-helper.cc b/helper/nd-cache-helper.cc index 882db2f..96198e4 100644 --- a/helper/nd-cache-helper.cc +++ b/helper/nd-cache-helper.cc @@ -3,6 +3,7 @@ #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 "nd-cache-helper.h" @@ -10,9 +11,13 @@ namespace ns3 { +NS_LOG_COMPONENT_DEFINE ("NdCacheHelper"); + void NdCacheHelper::Install (NetDeviceContainer &devices, Ipv6InterfaceContainer &interfaces) const { + NS_LOG_FUNCTION (this); + // prepare NDS cache for (uint32_t i = 0; i < devices.GetN (); i++) { @@ -47,6 +52,8 @@ NdCacheHelper::Install (NetDeviceContainer &devices, Ipv6InterfaceContainer &int entry = cache->Add (ipaddr); } entry->SetMacAddress (address); + + NS_LOG_DEBUG ("Added entry for " << address); } } } diff --git a/helper/satellite-node-helper.cc b/helper/satellite-node-helper.cc index 16a6f96..8cdd4b0 100644 --- a/helper/satellite-node-helper.cc +++ b/helper/satellite-node-helper.cc @@ -28,7 +28,7 @@ LeoSatNodeHelper::SetAttribute (string name, const AttributeValue &value) NodeContainer LeoSatNodeHelper::Install (vector &wpFiles) { - NS_LOG_FUNCTION (wpFiles); + NS_LOG_FUNCTION (this); NodeContainer nodes; for (size_t i = 0; i < wpFiles.size (); i ++) diff --git a/model/isl-mock-channel.cc b/model/isl-mock-channel.cc index 76fd592..1bc86b1 100644 --- a/model/isl-mock-channel.cc +++ b/model/isl-mock-channel.cc @@ -74,6 +74,7 @@ IslMockChannel::TransmitStart ( { if (i == srcId) continue; dst = DynamicCast (GetDevice (i)); + // TODO check LOS using mobility model Deliver (p, src, dst, txTime); } return true; diff --git a/model/leo-mock-channel.cc b/model/leo-mock-channel.cc index 004ab6c..75d4f9d 100644 --- a/model/leo-mock-channel.cc +++ b/model/leo-mock-channel.cc @@ -41,6 +41,8 @@ LeoMockChannel::TransmitStart (Ptr p, Address dst, Time txTime) { + NS_LOG_FUNCTION (this << p << devId << dst << txTime); + // Find devices joined to channel Ptr srcDev = DynamicCast (GetDevice (devId)); if (srcDev == 0) @@ -50,36 +52,29 @@ LeoMockChannel::TransmitStart (Ptr p, } bool fromGround = m_groundDevices.find (srcDev->GetAddress ()) != m_groundDevices.end (); + bool fromSpace = m_satelliteDevices.find (srcDev->GetAddress ()) != m_satelliteDevices.end (); + NS_ASSERT_MSG (!(fromGround && fromSpace), "Source device can not be both on ground and in space"); + + DeviceIndex *dests; if (fromGround) { - // Satellites can always directly be addresses - // Assume beams are narrow enough to not also receive the signal at other - // satellites for performance reasons. - DeviceIndex::iterator it = m_satelliteDevices.find (dst); - if (it == m_satelliteDevices.end ()) - { - NS_LOG_ERROR ("unable to find satellite with address " << dst); - return false; - } - return Deliver (p, srcDev, it->second, txTime); + dests = &m_satelliteDevices; } - else if (srcDev->IsBroadcast () || srcDev->IsMulticast ()) - // space to ground delivers to everything within the beam + else if (fromSpace) { - DeviceIndex::iterator it = m_groundDevices.find (dst); - if (it == m_groundDevices.end ()) - { - NS_LOG_ERROR ("unable to find satellite with address " << dst); - return false; - } - for (DeviceIndex::iterator it = m_groundDevices.begin (); - it != m_groundDevices.end (); - it++) - { - // TODO deliver only to devices in the same beam - Deliver (p, srcDev, it->second, txTime); - } + dests = &m_groundDevices; + } + else + { + NS_LOG_ERROR ("unable to find satellite with address " << dst); + return false; + } + + for (DeviceIndex::iterator it = dests->begin (); it != dests->end (); it ++) + { + // TODO deliver only to devices in the same beam + Deliver (p, srcDev, it->second, txTime); } return true; diff --git a/model/mock-channel.cc b/model/mock-channel.cc index 2e20166..4dde7e9 100644 --- a/model/mock-channel.cc +++ b/model/mock-channel.cc @@ -115,7 +115,7 @@ MockChannel::GetDevice (std::size_t i) const Time MockChannel::GetDelay (Ptr src, Ptr dst, Time txTime) const { - NS_LOG_DEBUG ("Get delay from " << src << " to " << dst); + NS_LOG_FUNCTION (this << src << dst << txTime); Ptr modSrc = src->GetNode ()->GetObject (); Ptr modDst = dst->GetNode ()->GetObject (); @@ -160,29 +160,19 @@ MockChannel::Deliver ( Time txTime) { NS_LOG_FUNCTION (this << p << src->GetAddress () << dst->GetAddress () << txTime); + Time delay = GetDelay (src, dst, txTime); - /* Check if there is LOS between the source and destination */ - if (GetPropagationLoss ()->CalcRxPower(1, src->GetNode ()->GetObject (), dst->GetNode ()->GetObject ()) > 0) - { - Simulator::ScheduleWithContext (dst->GetNode ()->GetId (), - delay, - &MockNetDevice::Receive, - dst, - p->Copy (), - src); + Simulator::ScheduleWithContext (dst->GetNode ()->GetId (), + delay, + &MockNetDevice::Receive, + dst, + p->Copy (), + src); - // Call the tx anim callback on the net device - m_txrxMock (p, src, dst, txTime, delay); - return true; - } - else - { - NS_LOG_LOGIC (dst << " unreachable from " << src); - - return false; - } + // Call the tx anim callback on the net device + m_txrxMock (p, src, dst, txTime, delay); + return true; } - } // namespace ns3 diff --git a/test/ground-node-helper-test-suite.cc b/test/ground-node-helper-test-suite.cc index bf9e4f2..8ae1b3f 100644 --- a/test/ground-node-helper-test-suite.cc +++ b/test/ground-node-helper-test-suite.cc @@ -30,7 +30,6 @@ EmptyGndNodeHelperTestCase::EmptyGndNodeHelperTestCase () EmptyGndNodeHelperTestCase::~EmptyGndNodeHelperTestCase () { - Simulator::Destroy (); } void @@ -63,7 +62,6 @@ SomeGndNodeHelperTestCase::SomeGndNodeHelperTestCase () SomeGndNodeHelperTestCase::~SomeGndNodeHelperTestCase () { - Simulator::Destroy (); } void diff --git a/test/isl-test-suite.cc b/test/isl-test-suite.cc index 4df4be6..1d10439 100644 --- a/test/isl-test-suite.cc +++ b/test/isl-test-suite.cc @@ -28,7 +28,6 @@ IslIcmpTestCase::IslIcmpTestCase () IslIcmpTestCase::~IslIcmpTestCase () { - Simulator::Destroy (); } void @@ -80,6 +79,7 @@ IslIcmpTestCase::DoRun (void) serverApps.Stop (Seconds (10.0)); Simulator::Run (); + Simulator::Destroy (); } class IslTestSuite : public TestSuite diff --git a/test/leo-test-suite.cc b/test/leo-test-suite.cc index 7789f6f..5ff244e 100644 --- a/test/leo-test-suite.cc +++ b/test/leo-test-suite.cc @@ -30,13 +30,12 @@ LeoTestCase1::LeoTestCase1 () LeoTestCase1::~LeoTestCase1 () { - Simulator::Destroy (); } void LeoTestCase1::DoRun (void) { - Time::SetResolution (Time::NS); + Time::SetResolution (Time::MS); std::vector satWps = { @@ -52,38 +51,78 @@ LeoTestCase1::DoRun (void) NodeContainer gateways = gndHelper.Install ("contrib/leo/data/test/ground-stations.txt"); NodeContainer terminals = gndHelper.Install ("contrib/leo/data/test/ground-stations.txt"); - LeoHelper leo; - leo.SetDeviceAttribute ("DataRate", StringValue ("10Mbps")); - leo.SetChannelAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); - AodvHelper aodv; - leo.SetRoutingHelper (aodv); + NetDeviceContainer islNet, gwNet, utNet; - NetDeviceContainer allDevices = leo.Install (satellites, gateways, terminals); + IslHelper islCh; + islCh.SetDeviceAttribute ("DataRate", StringValue ("10Mbps")); + islCh.SetDeviceAttribute ("ReceiveErrorModel", StringValue ("ns3::BurstErrorModel")); + islCh.SetChannelAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); + //// TODO propagation loss from mobility model + islCh.SetChannelAttribute ("PropagationLoss", StringValue ("ns3::RangePropagationLossModel")); + islNet = islCh.Install (satellites); + + LeoChannelHelper gwCh; + gwCh.SetGndDeviceAttribute ("DataRate", StringValue ("10Mbps")); + gwCh.SetGndDeviceAttribute ("ReceiveErrorModel", StringValue ("ns3::BurstErrorModel")); + gwCh.SetSatDeviceAttribute ("DataRate", StringValue ("10Mbps")); + gwCh.SetSatDeviceAttribute ("ReceiveErrorModel", StringValue ("ns3::BurstErrorModel")); + gwCh.SetChannelAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); + // TODO propagation loss from mobility model + gwCh.SetChannelAttribute ("PropagationLoss", StringValue ("ns3::RangePropagationLossModel")); + gwNet = gwCh.Install (satellites, gateways); + + LeoChannelHelper utCh; + utCh.SetGndDeviceAttribute ("DataRate", StringValue ("10Mbps")); + utCh.SetGndDeviceAttribute ("ReceiveErrorModel", StringValue ("ns3::BurstErrorModel")); + utCh.SetSatDeviceAttribute ("DataRate", StringValue ("10Mbps")); + utCh.SetSatDeviceAttribute ("ReceiveErrorModel", StringValue ("ns3::BurstErrorModel")); + utCh.SetChannelAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); + // TODO propagation loss from mobility model + utCh.SetChannelAttribute ("PropagationLoss", StringValue ("ns3::RangePropagationLossModel")); + utNet = utCh.Install (satellites, terminals); + + // Install internet stack on nodes + InternetStackHelper stack; + AodvHelper aodv; + stack.SetRoutingHelper (aodv); + stack.Install (satellites); + stack.Install (gateways); + stack.Install (terminals); + + // Make all networks addressable for legacy protocol + Ipv4AddressHelper ipv4; + ipv4.SetBase ("10.1.0.0", "255.255.0.0"); + Ipv4InterfaceContainer islIp = ipv4.Assign (islNet); + ipv4.SetBase ("10.2.0.0", "255.255.0.0"); + Ipv4InterfaceContainer gwIp = ipv4.Assign (gwNet); + ipv4.SetBase ("10.3.0.0", "255.255.0.0"); + Ipv4InterfaceContainer utIp = ipv4.Assign (utNet); + + ArpCacheHelper arpCache; + arpCache.Install (islNet, islIp); + arpCache.Install (gwNet, gwIp); + arpCache.Install (utNet, utIp); // we want to ping terminals UdpEchoServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (terminals); - // install a client on each of the terminals + // install a client on one of the terminals ApplicationContainer clientApps; - for (uint32_t i = 1; i < terminals.GetN (); i++) - { - Address remote = terminals.Get (i)->GetObject ()->GetAddress (1, 0).GetLocal (); - UdpEchoClientHelper echoClient (remote, 9); - echoClient.SetAttribute ("MaxPackets", UintegerValue (1)); - echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0))); - echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); - - clientApps.Add (echoClient.Install (terminals.Get (i-1))); - } - - clientApps.Start (Seconds (2.0)); - clientApps.Stop (Seconds (10.0)); + Address remote = utIp.GetAddress (1, 0); + UdpEchoClientHelper echoClient (remote, 9); + echoClient.SetAttribute ("MaxPackets", UintegerValue (3)); + echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0))); + echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); + clientApps.Add (echoClient.Install (terminals.Get (0))); serverApps.Start (Seconds (1.0)); - serverApps.Stop (Seconds (10.0)); + clientApps.Start (Seconds (2.0)); + clientApps.Stop (Seconds (9.0)); + serverApps.Stop (Seconds (10)); Simulator::Run (); + Simulator::Destroy (); } // The TestSuite class names the TestSuite, identifies what type of TestSuite, diff --git a/test/satellite-node-helper-test-suite.cc b/test/satellite-node-helper-test-suite.cc index 506da25..51bcc0c 100644 --- a/test/satellite-node-helper-test-suite.cc +++ b/test/satellite-node-helper-test-suite.cc @@ -29,7 +29,6 @@ EmptySatNodeHelperTestCase::EmptySatNodeHelperTestCase () EmptySatNodeHelperTestCase::~EmptySatNodeHelperTestCase () { - Simulator::Destroy (); } void @@ -62,7 +61,6 @@ SingleSatNodeHelperTestCase::SingleSatNodeHelperTestCase () SingleSatNodeHelperTestCase::~SingleSatNodeHelperTestCase () { - Simulator::Destroy (); } void diff --git a/wscript b/wscript index 2229324..4030384 100644 --- a/wscript +++ b/wscript @@ -12,7 +12,6 @@ def build(bld): 'helper/arp-cache-helper.cc', 'helper/isl-helper.cc', 'helper/leo-channel-helper.cc', - 'helper/leo-helper.cc', 'helper/nd-cache-helper.cc', 'helper/ground-node-helper.cc', 'helper/satellite-node-helper.cc', @@ -45,7 +44,6 @@ def build(bld): 'helper/arp-cache-helper.h', 'helper/isl-helper.h', 'helper/leo-channel-helper.h', - 'helper/leo-helper.h', 'helper/nd-cache-helper.h', 'helper/ground-node-helper.h', 'helper/satellite-node-helper.h',