diff --git a/model/isl-propagation-loss-model.cc b/model/isl-propagation-loss-model.cc index 86b8cb7..2d123ef 100644 --- a/model/isl-propagation-loss-model.cc +++ b/model/isl-propagation-loss-model.cc @@ -24,6 +24,7 @@ #include "ns3/log.h" #include "ns3/mobility-model.h" +#include "math.h" #include "isl-propagation-loss-model.h" @@ -52,6 +53,31 @@ IslPropagationLossModel::~IslPropagationLossModel () { } + +const double +IslPropagationLossModel::EARTH_RAD = 6.3781E6; + +bool +IslPropagationLossModel::GetLos (Ptr a, Ptr b) +{ + // origin of LOS + Vector3D o = a->GetPosition (); + double ol = o.GetLength (); + + // second point of LOS + Vector3D bp = b->GetPosition (); + double bl = bp.GetLength (); + + // unit vector + Vector3D u = Vector3D ((o.x-bp.x)/bl, (o.y-bp.y)/bl, (o.z-bp.z)/bl); + + // center point of sphere is 0 + double uo = (u.x*o.x) + (u.y*o.y) + (u.z*o.z); + double delta = (uo*uo) - (ol*ol - (EARTH_RAD*EARTH_RAD)); + + return delta < 0; +} + double IslPropagationLossModel::DoCalcRxPower (double txPowerDbm, Ptr a, @@ -62,7 +88,7 @@ IslPropagationLossModel::DoCalcRxPower (double txPowerDbm, // curvature + distance) // primitivec cut-of at 1000 km - if (a->GetDistanceFrom (b) > 1000000.0) + if (!GetLos (a, b)) { return 0; } diff --git a/model/isl-propagation-loss-model.h b/model/isl-propagation-loss-model.h index f98bbea..3eba95c 100644 --- a/model/isl-propagation-loss-model.h +++ b/model/isl-propagation-loss-model.h @@ -33,9 +33,22 @@ namespace ns3 { class IslPropagationLossModel : public PropagationLossModel { public: + static const double EARTH_RAD; + static TypeId GetTypeId (void); IslPropagationLossModel (); virtual ~IslPropagationLossModel (); + + /** + * true if there is at least one intersection of ISL line-of-sight with earth + * (LOS is blocked by earth) + * + * Assumes earth is sperical. + * + * \param a first node + * \param b second node + */ + static bool GetLos (Ptr a, Ptr b); private: /** * Returns the Rx Power taking into account only the particular diff --git a/test/isl-propagation-test-suite.cc b/test/isl-propagation-test-suite.cc new file mode 100644 index 0000000..d17152b --- /dev/null +++ b/test/isl-propagation-test-suite.cc @@ -0,0 +1,85 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#include "ns3/core-module.h" +#include "ns3/test.h" + +#include "ns3/leo-module.h" + +using namespace ns3; + +class IslPropagationAngleTestCase1 : public TestCase +{ +public: + IslPropagationAngleTestCase1 (); + virtual ~IslPropagationAngleTestCase1 (); + +private: + virtual void DoRun (void); +}; + +IslPropagationAngleTestCase1::IslPropagationAngleTestCase1 () + : TestCase ("Test LOS computation neighboring sats") +{ +} + +IslPropagationAngleTestCase1::~IslPropagationAngleTestCase1 () +{ +} + +void +IslPropagationAngleTestCase1::DoRun (void) +{ + Ptr a = CreateObject (); + a->SetPosition (Vector3D (IslPropagationLossModel::EARTH_RAD + 1000.0, 10, 0)); + Ptr b = CreateObject (); + b->SetPosition (Vector3D (IslPropagationLossModel::EARTH_RAD + 1000.0, 0, 0)); + + NS_TEST_ASSERT_MSG_EQ (IslPropagationLossModel::GetLos (a, b), true, "LOS of neighboring satellites"); +} + +class IslPropagationAngleTestCase2 : public TestCase +{ +public: + IslPropagationAngleTestCase2 (); + virtual ~IslPropagationAngleTestCase2 (); + +private: + virtual void DoRun (void); +}; + +IslPropagationAngleTestCase2::IslPropagationAngleTestCase2 () + : TestCase ("Test LOS of sats without LOS") +{ +} + +IslPropagationAngleTestCase2::~IslPropagationAngleTestCase2 () +{ +} + +void +IslPropagationAngleTestCase2::DoRun (void) +{ + Ptr a = CreateObject (); + a->SetPosition (Vector3D (IslPropagationLossModel::EARTH_RAD + 1000.0, 0, 0)); + Ptr b = CreateObject (); + b->SetPosition (Vector3D (- (IslPropagationLossModel::EARTH_RAD + 1000.0), 0, 0)); + + NS_TEST_ASSERT_MSG_EQ (IslPropagationLossModel::GetLos (a, b), false, "LOS of opposing"); +} + +class IslPropagationTestSuite : public TestSuite +{ +public: + IslPropagationTestSuite (); +}; + +IslPropagationTestSuite::IslPropagationTestSuite () + : TestSuite ("isl-propagation", UNIT) +{ + // TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER + AddTestCase (new IslPropagationAngleTestCase1, TestCase::QUICK); + AddTestCase (new IslPropagationAngleTestCase2, TestCase::QUICK); +} + +// Do not forget to allocate an instance of this TestSuite +static IslPropagationTestSuite leoTestSuite; diff --git a/wscript b/wscript index 4b2b619..f122895 100644 --- a/wscript +++ b/wscript @@ -28,16 +28,17 @@ def build(bld): module_test = bld.create_ns3_module_test_library('leo') module_test.source = [ - 'test/leo-test-suite.cc', - 'test/leo-propagation-test-suite.cc', - 'test/isl-test-suite.cc', + 'test/ground-node-helper-test-suite.cc', 'test/isl-mock-channel-test-suite.cc', - 'test/leo-mock-channel-test-suite.cc', + 'test/isl-propagation-test-suite.cc', + 'test/isl-test-suite.cc', 'test/leo-input-fstream-container-test-suite.cc', 'test/leo-mobility-test-suite.cc', + 'test/leo-mock-channel-test-suite.cc', + 'test/leo-propagation-test-suite.cc', + 'test/leo-test-suite.cc', 'test/satellite-node-helper-test-suite.cc', - 'test/ground-node-helper-test-suite.cc', - ] + ] headers = bld(features='ns3header') headers.module = 'leo'