Add test for propagation loss and fix bugs

This commit is contained in:
Tim Schubert 2020-08-11 18:14:43 +02:00
parent 090ef28e99
commit 2f94c15455
3 changed files with 121 additions and 14 deletions

View file

@ -28,7 +28,7 @@ LeoPropagationLossModel::GetTypeId (void)
MakeDoubleChecker<double> ()) MakeDoubleChecker<double> ())
.AddAttribute ("ElevationAngle", .AddAttribute ("ElevationAngle",
"Cut-off angle for signal propagation", "Cut-off angle for signal propagation",
DoubleValue (20.0), DoubleValue (M_PI / 9),
MakeDoubleAccessor (&LeoPropagationLossModel::m_elevationAngle), MakeDoubleAccessor (&LeoPropagationLossModel::m_elevationAngle),
MakeDoubleChecker<double> ()) MakeDoubleChecker<double> ())
.AddAttribute ("AtmosphericLoss", .AddAttribute ("AtmosphericLoss",
@ -39,7 +39,7 @@ LeoPropagationLossModel::GetTypeId (void)
.AddAttribute ("FreeSpacePathLoss", .AddAttribute ("FreeSpacePathLoss",
"Free space path loss in dB", "Free space path loss in dB",
DoubleValue (0.0), DoubleValue (0.0),
MakeDoubleAccessor (&LeoPropagationLossModel::m_atmosphericLoss), MakeDoubleAccessor (&LeoPropagationLossModel::m_freeSpacePathLoss),
MakeDoubleChecker<double> ()) MakeDoubleChecker<double> ())
.AddAttribute ("LinkMargin", .AddAttribute ("LinkMargin",
"Link margin in dB", "Link margin in dB",
@ -76,7 +76,7 @@ LeoPropagationLossModel::DoCalcRxPower (double txPowerDbm,
Ptr<MobilityModel> a, Ptr<MobilityModel> a,
Ptr<MobilityModel> b) const Ptr<MobilityModel> b) const
{ {
if (a->GetDistanceFrom (b) > m_cutoffDistance && GetAngle (a, b) > m_elevationAngle / 2.0) if (a->GetDistanceFrom (b) > m_cutoffDistance || GetAngle (a, b) > m_elevationAngle / 2.0)
{ {
return 0.0; return 0.0;
} }

View file

@ -1,5 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include "math.h"
#include "ns3/core-module.h" #include "ns3/core-module.h"
#include "ns3/test.h" #include "ns3/test.h"
@ -103,10 +104,119 @@ LeoPropagationAngleTestCase3::DoRun (void)
NS_TEST_ASSERT_MSG_EQ (isnan(angle), true, "Angle should be NaN"); NS_TEST_ASSERT_MSG_EQ (isnan(angle), true, "Angle should be NaN");
} }
// The TestSuite class names the TestSuite, identifies what type of TestSuite, class LeoPropagationRxNoLosTestCase : public TestCase
// and enables the TestCases to be run. Typically, only the constructor for {
// this class must be defined public:
// LeoPropagationRxNoLosTestCase ()
: TestCase ("Test RxNoLos for without LOS")
{}
virtual ~LeoPropagationRxNoLosTestCase ()
{}
private:
virtual void DoRun (void);
};
void
LeoPropagationRxNoLosTestCase::DoRun ()
{
Ptr<ConstantPositionMobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
a->SetPosition (Vector3D (1000000.0, 0, 0));
Ptr<ConstantPositionMobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
b->SetPosition (Vector3D (-1000000.0, 0, 0));
Ptr<LeoPropagationLossModel> model = CreateObject<LeoPropagationLossModel> ();
model->SetAttribute ("MaxDistance", DoubleValue (1000000.0));
NS_TEST_ASSERT_MSG_EQ (model->CalcRxPower (1.0, a, b), 0.0, "0 Rx power without LOS");
}
class LeoPropagationRxLosTestCase : public TestCase
{
public:
LeoPropagationRxLosTestCase ()
: TestCase ("Test Rx with LOS")
{}
virtual ~LeoPropagationRxLosTestCase ()
{}
private:
virtual void DoRun (void);
};
void
LeoPropagationRxLosTestCase::DoRun ()
{
Ptr<ConstantPositionMobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
a->SetPosition (Vector3D (1000000.0, 0, 0));
Ptr<ConstantPositionMobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
b->SetPosition (Vector3D (1000001.0, 0, 0));
Ptr<LeoPropagationLossModel> model = CreateObject<LeoPropagationLossModel> ();
model->SetAttribute ("ElevationAngle", DoubleValue (10.0));
model->SetAttribute ("AtmosphericLoss", DoubleValue (0.0));
model->SetAttribute ("FreeSpacePathLoss", DoubleValue (0.0));
model->SetAttribute ("LinkMargin", DoubleValue (0.0));
NS_TEST_ASSERT_MSG_EQ (model->CalcRxPower (1.0, a, b), 1.0, "Tx same as Rx power without losses and LOS");
}
class LeoPropagationBadAngleTestCase : public TestCase
{
public:
LeoPropagationBadAngleTestCase ()
: TestCase ("Test Rx with too large elevation angle")
{}
virtual ~LeoPropagationBadAngleTestCase ()
{}
private:
virtual void DoRun (void);
};
void
LeoPropagationBadAngleTestCase::DoRun ()
{
Ptr<ConstantPositionMobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
a->SetPosition (Vector3D (1000000.0, 0, 0));
Ptr<ConstantPositionMobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
b->SetPosition (Vector3D (1000000.0, sin (M_PI / 9) * 1000000.0, 0));
Ptr<LeoPropagationLossModel> model = CreateObject<LeoPropagationLossModel> ();
model->SetAttribute ("ElevationAngle", DoubleValue (M_PI / 9));
NS_TEST_ASSERT_MSG_EQ (model->CalcRxPower (1.0, a, b), 0.0, "Tx must be 0 if elevation is too large");
}
class LeoPropagationLossTestCase : public TestCase
{
public:
LeoPropagationLossTestCase ()
: TestCase ("Test Rx with some losses")
{}
virtual ~LeoPropagationLossTestCase ()
{}
private:
virtual void DoRun (void);
};
void
LeoPropagationLossTestCase::DoRun ()
{
Ptr<ConstantPositionMobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
a->SetPosition (Vector3D (1000000.0, 0, 0));
Ptr<ConstantPositionMobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
b->SetPosition (Vector3D (1000001.0, 0, 0));
Ptr<LeoPropagationLossModel> model = CreateObject<LeoPropagationLossModel> ();
model->SetAttribute ("AtmosphericLoss", DoubleValue (0.1));
model->SetAttribute ("FreeSpacePathLoss", DoubleValue (0.1));
model->SetAttribute ("LinkMargin", DoubleValue (0.3));
NS_TEST_ASSERT_MSG_EQ (model->CalcRxPower (1.0, a, b), 0.5, "Tx must be smaller with some losses");
}
class LeoPropagationTestSuite : public TestSuite class LeoPropagationTestSuite : public TestSuite
{ {
public: public:
@ -120,6 +230,10 @@ LeoPropagationTestSuite::LeoPropagationTestSuite ()
AddTestCase (new LeoPropagationAngleTestCase1, TestCase::QUICK); AddTestCase (new LeoPropagationAngleTestCase1, TestCase::QUICK);
AddTestCase (new LeoPropagationAngleTestCase2, TestCase::QUICK); AddTestCase (new LeoPropagationAngleTestCase2, TestCase::QUICK);
AddTestCase (new LeoPropagationAngleTestCase3, TestCase::QUICK); AddTestCase (new LeoPropagationAngleTestCase3, TestCase::QUICK);
AddTestCase (new LeoPropagationRxNoLosTestCase, TestCase::QUICK);
AddTestCase (new LeoPropagationRxLosTestCase, TestCase::QUICK);
AddTestCase (new LeoPropagationBadAngleTestCase, TestCase::QUICK);
AddTestCase (new LeoPropagationLossTestCase, TestCase::QUICK);
} }
// Do not forget to allocate an instance of this TestSuite // Do not forget to allocate an instance of this TestSuite

View file

@ -78,7 +78,6 @@ LeoTestCase1::DoRun (void)
islCh.SetDeviceAttribute ("ReceiveErrorModel", StringValue ("ns3::BurstErrorModel")); islCh.SetDeviceAttribute ("ReceiveErrorModel", StringValue ("ns3::BurstErrorModel"));
islCh.SetChannelAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); islCh.SetChannelAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel"));
islCh.SetDeviceAttribute ("InterframeGap", TimeValue (Seconds (0.001))); islCh.SetDeviceAttribute ("InterframeGap", TimeValue (Seconds (0.001)));
//// TODO propagation loss from mobility model
islCh.SetChannelAttribute ("PropagationLoss", StringValue ("ns3::IslPropagationLossModel")); islCh.SetChannelAttribute ("PropagationLoss", StringValue ("ns3::IslPropagationLossModel"));
islNet = islCh.Install (satellites); islNet = islCh.Install (satellites);
@ -90,7 +89,6 @@ LeoTestCase1::DoRun (void)
utCh.SetChannelAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); utCh.SetChannelAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel"));
utCh.SetSatDeviceAttribute ("InterframeGap", TimeValue (Seconds (0.001))); utCh.SetSatDeviceAttribute ("InterframeGap", TimeValue (Seconds (0.001)));
utCh.SetGndDeviceAttribute ("InterframeGap", TimeValue (Seconds (0.001))); utCh.SetGndDeviceAttribute ("InterframeGap", TimeValue (Seconds (0.001)));
// TODO propagation loss from mobility model
utCh.SetChannelAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel")); utCh.SetChannelAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel"));
utCh.SetChannelAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); utCh.SetChannelAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel"));
utNet = utCh.Install (satellites, terminals); utNet = utCh.Install (satellites, terminals);
@ -109,11 +107,6 @@ LeoTestCase1::DoRun (void)
ipv4.SetBase ("10.3.0.0", "255.255.0.0"); ipv4.SetBase ("10.3.0.0", "255.255.0.0");
Ipv4InterfaceContainer utIp = ipv4.Assign (utNet); Ipv4InterfaceContainer utIp = ipv4.Assign (utNet);
// TODO do not add UTs to cache of other UTs
//ArpCacheHelper arpCache;
//arpCache.Install (islNet, islIp);
//arpCache.Install (utNet, utIp);
// we want to ping terminals // we want to ping terminals
UdpEchoServerHelper echoServer (9); UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (terminals.Get (1)); ApplicationContainer serverApps = echoServer.Install (terminals.Get (1));