mirror of
https://gitlab.ibr.cs.tu-bs.de/tschuber/ns-3-leo.git
synced 2025-06-08 01:53:58 +02:00
refactor stuff
This commit is contained in:
parent
57b04d6424
commit
97de8c9d24
15 changed files with 135 additions and 88 deletions
|
@ -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<NetDevice> dev = devices.Get (i);
|
||||
Ptr<Node> node = dev->GetNode ();
|
||||
NS_LOG_INFO ("Preparing ARP cache of " << node);
|
||||
Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol> ();
|
||||
int32_t ifIndex = ipv4->GetInterfaceForDevice (dev);
|
||||
Ptr<Ipv4Interface> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,4 +20,4 @@ public:
|
|||
|
||||
}; /* namespace ns3 */
|
||||
|
||||
#endif /* ARP_CACHE_HELPER */
|
||||
#endif /* ARP_CACHE_HELPER_H */
|
||||
|
|
|
@ -224,12 +224,15 @@ IslHelper::Install (NodeContainer c)
|
|||
NetDeviceContainer
|
||||
IslHelper::Install (std::vector<Ptr<Node> > &nodes)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
|
||||
Ptr<MockChannel> channel = m_channelFactory.Create<MockChannel> ();
|
||||
|
||||
NetDeviceContainer container;
|
||||
|
||||
for (Ptr<Node> node: nodes)
|
||||
{
|
||||
NS_LOG_DEBUG ("Adding device for node " << node->GetId ());
|
||||
Ptr<MockNetDevice> dev = m_deviceFactory.Create<MockNetDevice> ();
|
||||
dev->SetAddress (Mac48Address::Allocate ());
|
||||
node->AddDevice (dev);
|
||||
|
|
|
@ -230,6 +230,8 @@ LeoChannelHelper::EnableAsciiInternal (
|
|||
NetDeviceContainer
|
||||
LeoChannelHelper::Install (std::vector<Ptr<Node> > &satellites, std::vector<Ptr<Node> > &stations)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
|
||||
Ptr<LeoMockChannel> channel = m_channelFactory.Create<LeoMockChannel> ();
|
||||
|
||||
NetDeviceContainer container;
|
||||
|
@ -243,6 +245,8 @@ LeoChannelHelper::Install (std::vector<Ptr<Node> > &satellites, std::vector<Ptr<
|
|||
dev->SetQueue (queue);
|
||||
dev->Attach (channel);
|
||||
container.Add (dev);
|
||||
|
||||
NS_LOG_DEBUG ("Added device for node " << node->GetId ());
|
||||
}
|
||||
|
||||
for (Ptr<Node> node : stations)
|
||||
|
@ -254,6 +258,8 @@ LeoChannelHelper::Install (std::vector<Ptr<Node> > &satellites, std::vector<Ptr<
|
|||
dev->SetQueue (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<std::string> &satellites, std::vector<std::string> &stations)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
|
||||
std::vector<Ptr<Node> > sats;
|
||||
std::vector<Ptr<Node> > stats;
|
||||
for (std::string name : satellites)
|
||||
{
|
||||
NS_LOG_DEBUG ("Adding node " << name);
|
||||
Ptr<Node> node = Names::Find<Node>(name);
|
||||
sats.push_back (node);
|
||||
}
|
||||
for (std::string name : stations)
|
||||
{
|
||||
NS_LOG_DEBUG ("Adding node " << name);
|
||||
Ptr<Node> node = Names::Find<Node>(name);
|
||||
stats.push_back (node);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ LeoSatNodeHelper::SetAttribute (string name, const AttributeValue &value)
|
|||
NodeContainer
|
||||
LeoSatNodeHelper::Install (vector<string> &wpFiles)
|
||||
{
|
||||
NS_LOG_FUNCTION (wpFiles);
|
||||
NS_LOG_FUNCTION (this);
|
||||
|
||||
NodeContainer nodes;
|
||||
for (size_t i = 0; i < wpFiles.size (); i ++)
|
||||
|
|
|
@ -74,6 +74,7 @@ IslMockChannel::TransmitStart (
|
|||
{
|
||||
if (i == srcId) continue;
|
||||
dst = DynamicCast<MockNetDevice> (GetDevice (i));
|
||||
// TODO check LOS using mobility model
|
||||
Deliver (p, src, dst, txTime);
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -41,6 +41,8 @@ LeoMockChannel::TransmitStart (Ptr<const Packet> p,
|
|||
Address dst,
|
||||
Time txTime)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << p << devId << dst << txTime);
|
||||
|
||||
// Find devices joined to channel
|
||||
Ptr<MockNetDevice> srcDev = DynamicCast<MockNetDevice> (GetDevice (devId));
|
||||
if (srcDev == 0)
|
||||
|
@ -50,36 +52,29 @@ LeoMockChannel::TransmitStart (Ptr<const Packet> 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;
|
||||
|
|
|
@ -115,7 +115,7 @@ MockChannel::GetDevice (std::size_t i) const
|
|||
Time
|
||||
MockChannel::GetDelay (Ptr<const MockNetDevice> src, Ptr<const MockNetDevice> dst, Time txTime) const
|
||||
{
|
||||
NS_LOG_DEBUG ("Get delay from " << src << " to " << dst);
|
||||
NS_LOG_FUNCTION (this << src << dst << txTime);
|
||||
|
||||
Ptr<MobilityModel> modSrc = src->GetNode ()->GetObject<MobilityModel> ();
|
||||
Ptr<MobilityModel> modDst = dst->GetNode ()->GetObject<MobilityModel> ();
|
||||
|
@ -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<MobilityModel> (), dst->GetNode ()->GetObject<MobilityModel> ()) > 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
|
||||
|
|
|
@ -30,7 +30,6 @@ EmptyGndNodeHelperTestCase::EmptyGndNodeHelperTestCase ()
|
|||
|
||||
EmptyGndNodeHelperTestCase::~EmptyGndNodeHelperTestCase ()
|
||||
{
|
||||
Simulator::Destroy ();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -63,7 +62,6 @@ SomeGndNodeHelperTestCase::SomeGndNodeHelperTestCase ()
|
|||
|
||||
SomeGndNodeHelperTestCase::~SomeGndNodeHelperTestCase ()
|
||||
{
|
||||
Simulator::Destroy ();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -30,13 +30,12 @@ LeoTestCase1::LeoTestCase1 ()
|
|||
|
||||
LeoTestCase1::~LeoTestCase1 ()
|
||||
{
|
||||
Simulator::Destroy ();
|
||||
}
|
||||
|
||||
void
|
||||
LeoTestCase1::DoRun (void)
|
||||
{
|
||||
Time::SetResolution (Time::NS);
|
||||
Time::SetResolution (Time::MS);
|
||||
|
||||
std::vector<std::string> 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<Ipv4> ()->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,
|
||||
|
|
|
@ -29,7 +29,6 @@ EmptySatNodeHelperTestCase::EmptySatNodeHelperTestCase ()
|
|||
|
||||
EmptySatNodeHelperTestCase::~EmptySatNodeHelperTestCase ()
|
||||
{
|
||||
Simulator::Destroy ();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -62,7 +61,6 @@ SingleSatNodeHelperTestCase::SingleSatNodeHelperTestCase ()
|
|||
|
||||
SingleSatNodeHelperTestCase::~SingleSatNodeHelperTestCase ()
|
||||
{
|
||||
Simulator::Destroy ();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
2
wscript
2
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',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue