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

@ -1,5 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include "math.h"
#include "ns3/core-module.h"
#include "ns3/test.h"
@ -103,10 +104,119 @@ LeoPropagationAngleTestCase3::DoRun (void)
NS_TEST_ASSERT_MSG_EQ (isnan(angle), true, "Angle should be NaN");
}
// The TestSuite class names the TestSuite, identifies what type of TestSuite,
// and enables the TestCases to be run. Typically, only the constructor for
// this class must be defined
//
class LeoPropagationRxNoLosTestCase : public TestCase
{
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
{
public:
@ -120,6 +230,10 @@ LeoPropagationTestSuite::LeoPropagationTestSuite ()
AddTestCase (new LeoPropagationAngleTestCase1, TestCase::QUICK);
AddTestCase (new LeoPropagationAngleTestCase2, 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