diff --git a/examples/leo-delay-tracing-example.cc b/examples/leo-delay-tracing-example.cc index ae77c2e..a58fb84 100644 --- a/examples/leo-delay-tracing-example.cc +++ b/examples/leo-delay-tracing-example.cc @@ -133,6 +133,7 @@ int main (int argc, char *argv[]) if (routingProto == "epidemic") { EpidemicHelper epidemic; + //epidemic.Set ("BeaconInterval", TimeValue (MilliSeconds (100))); stack.SetRoutingHelper (epidemic); } else diff --git a/model/leo-circular-orbit-mobility-model.cc b/model/leo-circular-orbit-mobility-model.cc index 08cbad2..20a1f65 100644 --- a/model/leo-circular-orbit-mobility-model.cc +++ b/model/leo-circular-orbit-mobility-model.cc @@ -42,7 +42,7 @@ LeoCircularOrbitMobilityModel::GetTypeId () return tid; } -LeoCircularOrbitMobilityModel::LeoCircularOrbitMobilityModel() : MobilityModel (), m_latitude (0.0), m_offset (0.0), m_position () +LeoCircularOrbitMobilityModel::LeoCircularOrbitMobilityModel() : MobilityModel (), m_longitude (0.0), m_offset (0.0), m_position () { NS_LOG_FUNCTION_NOARGS (); } @@ -123,7 +123,7 @@ LeoCircularOrbitMobilityModel::RotatePlane (double a, const Vector3D &x) const double LeoCircularOrbitMobilityModel::CalcLatitude () const { - return m_latitude + ((Simulator::Now ().GetDouble () / Hours (24).GetDouble ()) * 2 * M_PI); + return m_longitude + ((Simulator::Now ().GetDouble () / Hours (24).GetDouble ()) * 2 * M_PI); } Vector @@ -169,7 +169,7 @@ LeoCircularOrbitMobilityModel::DoSetPosition (const Vector &position) // this works nicely with MobilityHelper and GetPostion will still get the // correct position, but be aware that it will not be the same as supplied to // SetPostion - m_latitude = position.x; + m_longitude = position.x; m_offset = position.y; Update (); } diff --git a/model/leo-circular-orbit-mobility-model.h b/model/leo-circular-orbit-mobility-model.h index 7589a17..779490c 100644 --- a/model/leo-circular-orbit-mobility-model.h +++ b/model/leo-circular-orbit-mobility-model.h @@ -56,9 +56,9 @@ private: double m_inclination; /** - * Latitude in rad + * Longitudinal offset in rad */ - double m_latitude; + double m_longitude; /** * Offset on the orbital plane in rad diff --git a/test/leo-mock-channel-test-suite.cc b/test/leo-mock-channel-test-suite.cc index 70000b0..97e14f1 100644 --- a/test/leo-mock-channel-test-suite.cc +++ b/test/leo-mock-channel-test-suite.cc @@ -14,137 +14,99 @@ using namespace ns3; class LeoMockChannelTransmitUnknownTestCase : public TestCase { public: - LeoMockChannelTransmitUnknownTestCase (); - virtual ~LeoMockChannelTransmitUnknownTestCase (); + LeoMockChannelTransmitUnknownTestCase () : TestCase ("transmission from unknown source fails") {} + virtual ~LeoMockChannelTransmitUnknownTestCase () {} private: - virtual void DoRun (void); + virtual void DoRun (void) + { + Ptr channel = CreateObject (); + Packet *packet = new Packet (); + Ptr p = Ptr(packet); + Address destAddr; + Time txTime; + channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); + channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel")); + bool result = channel->TransmitStart (p, 10000, destAddr, txTime); + + NS_TEST_ASSERT_MSG_EQ (result, false, "unknown source fails to deliver"); + } }; -LeoMockChannelTransmitUnknownTestCase::LeoMockChannelTransmitUnknownTestCase () - : TestCase ("Test transmission to unkown destination") -{ -} - -LeoMockChannelTransmitUnknownTestCase::~LeoMockChannelTransmitUnknownTestCase () -{ -} - -void -LeoMockChannelTransmitUnknownTestCase::DoRun (void) -{ - Ptr channel = CreateObject (); - Packet *packet = new Packet (); - Ptr p = Ptr(packet); - Address destAddr; - Time txTime; - channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); - channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel")); - bool result = channel->TransmitStart (p, 10000, destAddr, txTime); - - NS_TEST_ASSERT_MSG_EQ (result, false, "Unknown source fails to deliver"); -} - class LeoMockChannelTransmitKnownTestCase : public TestCase { public: - LeoMockChannelTransmitKnownTestCase (); - virtual ~LeoMockChannelTransmitKnownTestCase (); - + LeoMockChannelTransmitKnownTestCase () : TestCase ("transmission from known source succeeds") {} + virtual ~LeoMockChannelTransmitKnownTestCase () {} private: - virtual void DoRun (void); + virtual void DoRun (void) + { + Ptr channel = CreateObject (); + channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); + channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel")); + + Packet *packet = new Packet (); + Ptr p = Ptr(packet); + + Ptr srcNode = CreateObject (); + Ptr srcDev = CreateObject (); + srcDev->SetNode (srcNode); + srcDev->SetDeviceType (LeoMockNetDevice::GND); + srcDev->SetAddress (Mac48Address::Allocate ()); + int32_t srcId = channel->Attach (srcDev); + + Ptr dstNode = CreateObject (); + Ptr dstDev = CreateObject (); + dstDev->SetNode (dstNode); + dstDev->SetDeviceType (LeoMockNetDevice::SAT); + dstDev->SetAddress (Mac48Address::Allocate ()); + channel->Attach (dstDev); + + Address destAddr = dstDev->GetAddress (); + Time txTime; + bool result = channel->TransmitStart (p, srcId, destAddr, txTime); + + NS_TEST_ASSERT_MSG_EQ (result, true, "known source does not deliver"); + } }; -LeoMockChannelTransmitKnownTestCase::LeoMockChannelTransmitKnownTestCase () - : TestCase ("Test transmission to known destination") -{ -} - -LeoMockChannelTransmitKnownTestCase::~LeoMockChannelTransmitKnownTestCase () -{ -} - -void -LeoMockChannelTransmitKnownTestCase::DoRun (void) -{ - Ptr channel = CreateObject (); - channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); - channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel")); - - Packet *packet = new Packet (); - Ptr p = Ptr(packet); - - Ptr srcNode = CreateObject (); - Ptr srcDev = CreateObject (); - srcDev->SetNode (srcNode); - srcDev->SetDeviceType (LeoMockNetDevice::GND); - srcDev->SetAddress (Mac48Address::Allocate ()); - int32_t srcId = channel->Attach (srcDev); - - Ptr dstNode = CreateObject (); - Ptr dstDev = CreateObject (); - dstDev->SetNode (dstNode); - dstDev->SetDeviceType (LeoMockNetDevice::SAT); - dstDev->SetAddress (Mac48Address::Allocate ()); - channel->Attach (dstDev); - - Address destAddr = dstDev->GetAddress (); - Time txTime; - bool result = channel->TransmitStart (p, srcId, destAddr, txTime); - - NS_TEST_ASSERT_MSG_EQ (result, true, "Known source delivers"); -} - class LeoMockChannelTransmitSpaceGroundTestCase : public TestCase { public: - LeoMockChannelTransmitSpaceGroundTestCase (); - virtual ~LeoMockChannelTransmitSpaceGroundTestCase (); - + LeoMockChannelTransmitSpaceGroundTestCase () : TestCase ("space to ground transmission succeeds") {} + virtual ~LeoMockChannelTransmitSpaceGroundTestCase () {} private: - virtual void DoRun (void); + virtual void DoRun (void) + { + Ptr channel = CreateObject (); + channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); + channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel")); + + Packet *packet = new Packet (); + Ptr p = Ptr(packet); + + Ptr srcNode = CreateObject (); + Ptr srcDev = CreateObject (); + srcDev->SetNode (srcNode); + srcDev->SetDeviceType (LeoMockNetDevice::SAT); + srcDev->SetAddress (Mac48Address::Allocate ()); + int32_t srcId = channel->Attach (srcDev); + + Ptr dstNode = CreateObject (); + Ptr dstDev = CreateObject (); + dstDev->SetNode (dstNode); + dstDev->SetDeviceType (LeoMockNetDevice::GND); + dstDev->SetAddress (Mac48Address::Allocate ()); + channel->Attach (dstDev); + + Address destAddr = dstDev->GetAddress (); + Time txTime; + bool result = channel->TransmitStart (p, srcId, destAddr, txTime); + + NS_TEST_ASSERT_MSG_EQ (result, true, "space to ground transmission failed"); + } }; -LeoMockChannelTransmitSpaceGroundTestCase::LeoMockChannelTransmitSpaceGroundTestCase () - : TestCase ("Test transmission to known destination") -{ -} - -LeoMockChannelTransmitSpaceGroundTestCase::~LeoMockChannelTransmitSpaceGroundTestCase () -{ -} - -void -LeoMockChannelTransmitSpaceGroundTestCase::DoRun (void) -{ - Ptr channel = CreateObject (); - channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); - channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel")); - - Packet *packet = new Packet (); - Ptr p = Ptr(packet); - - Ptr srcNode = CreateObject (); - Ptr srcDev = CreateObject (); - srcDev->SetNode (srcNode); - srcDev->SetDeviceType (LeoMockNetDevice::SAT); - srcDev->SetAddress (Mac48Address::Allocate ()); - int32_t srcId = channel->Attach (srcDev); - - Ptr dstNode = CreateObject (); - Ptr dstDev = CreateObject (); - dstDev->SetNode (dstNode); - dstDev->SetDeviceType (LeoMockNetDevice::GND); - dstDev->SetAddress (Mac48Address::Allocate ()); - channel->Attach (dstDev); - - Address destAddr = dstDev->GetAddress (); - Time txTime; - bool result = channel->TransmitStart (p, srcId, destAddr, txTime); - - NS_TEST_ASSERT_MSG_EQ (result, true, "Space to ground destination delivers"); -} - class LeoMockChannelTestSuite : public TestSuite { public: @@ -154,11 +116,9 @@ public: LeoMockChannelTestSuite::LeoMockChannelTestSuite () : TestSuite ("leo-mock-channel", UNIT) { - // TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER AddTestCase (new LeoMockChannelTransmitUnknownTestCase, TestCase::QUICK); AddTestCase (new LeoMockChannelTransmitKnownTestCase, TestCase::QUICK); AddTestCase (new LeoMockChannelTransmitSpaceGroundTestCase, TestCase::QUICK); } -// Do not forget to allocate an instance of this TestSuite static LeoMockChannelTestSuite islMockChannelTestSuite; diff --git a/test/leo-orbit-test-suite.cc b/test/leo-orbit-test-suite.cc index 0e92f80..0045619 100644 --- a/test/leo-orbit-test-suite.cc +++ b/test/leo-orbit-test-suite.cc @@ -14,7 +14,7 @@ using namespace ns3; class LeoOrbitSpeedTestCase : public TestCase { public: - LeoOrbitSpeedTestCase () : TestCase ("Test speed for 0 altitude") {} + LeoOrbitSpeedTestCase () : TestCase ("speed at 0 altitude is earth rotation speed") {} virtual ~LeoOrbitSpeedTestCase () {} private: virtual void DoRun (void) @@ -22,14 +22,14 @@ private: Ptr mob = CreateObject (); mob->SetAttribute ("Altitude", DoubleValue (0.0)); - NS_TEST_ASSERT_MSG_EQ ((uint64_t) mob->GetSpeed (), (uint64_t) 7909.79, "Unexpected velocity at earths surface"); + NS_TEST_ASSERT_MSG_EQ ((uint64_t) mob->GetSpeed (), (uint64_t) 7909.79, "postion at 0 altitude is on surface"); } }; class LeoOrbitPositionTestCase : public TestCase { public: - LeoOrbitPositionTestCase () : TestCase ("Test position for 0 altitude and 1.0 inclination") {} + LeoOrbitPositionTestCase () : TestCase ("position is on surface") {} virtual ~LeoOrbitPositionTestCase () {} private: virtual void DoRun (void) @@ -38,21 +38,21 @@ private: mob->SetAttribute ("Altitude", DoubleValue (0.0)); mob->SetAttribute ("Inclination", DoubleValue (1.0)); - NS_TEST_ASSERT_MSG_EQ_TOL (mob->GetPosition ().GetLength() / 1000, LEO_EARTH_RAD_KM, 0.1, "Unexpected position on earths surface for 1 deg inclination"); + NS_TEST_ASSERT_MSG_EQ_TOL (mob->GetPosition ().GetLength() / 1000, LEO_EARTH_RAD_KM, 0.1, "unexpected position on earths surface for 1 deg inclination"); } }; class LeoOrbitProgressTestCase : public TestCase { public: - LeoOrbitProgressTestCase () : TestCase ("Test position shoudl not be the same after some time") {} + LeoOrbitProgressTestCase () : TestCase ("position changes over time") {} virtual ~LeoOrbitProgressTestCase () {} private: void TestLengthPosition (double expl, double expx, Ptr mob) { Vector pos = mob->GetPosition (); NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (pos.GetLength () / 1000, expl, 0.001, "Distance to earth should be the same", __FILE__, __LINE__); - NS_TEST_EXPECT_MSG_NE_INTERNAL (pos.x, expx, "Position should not be equal", __FILE__, __LINE__); + NS_TEST_EXPECT_MSG_NE_INTERNAL (pos.x, expx, "position should not be equal", __FILE__, __LINE__); } virtual void DoRun (void) @@ -72,7 +72,7 @@ private: class LeoOrbitLatitudeTestCase : public TestCase { public: - LeoOrbitLatitudeTestCase () : TestCase ("Test offset between neighboring satellites planes") {} + LeoOrbitLatitudeTestCase () : TestCase ("neighboring satellite planes have offset") {} virtual ~LeoOrbitLatitudeTestCase () {} private: virtual void DoRun (void) @@ -86,14 +86,14 @@ private: mob->SetPosition (Vector3D (20.0, 0, 0)); Vector pos2 = mob->GetPosition (); - NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "Neighboring satellite should have different position"); + NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "neighboring satellite planes should have different position"); } }; class LeoOrbitOffsetTestCase : public TestCase { public: - LeoOrbitOffsetTestCase () : TestCase ("Test offset between neighboring satellites") {} + LeoOrbitOffsetTestCase () : TestCase ("neighboring satellites have offset") {} virtual ~LeoOrbitOffsetTestCase () {} private: virtual void DoRun (void) @@ -107,21 +107,19 @@ private: mob->SetPosition (Vector3D (0, 20.0, 0)); Vector pos2 = mob->GetPosition (); - NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "Neighboring satellite should have different position"); + NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "neighboring satellite should have different position"); } }; class LeoOrbitTracingTestCase : public TestCase { public: - LeoOrbitTracingTestCase () : TestCase ("Test tracing of position changes") {} + LeoOrbitTracingTestCase () : TestCase ("position changes are traced") {} virtual ~LeoOrbitTracingTestCase () {} - static void CourseChange (std::string context, Ptr position) - { - Vector pos = position->GetPosition (); - std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y - << ", z=" << pos.z << std::endl; - } + + static uint64_t traced; + + static void CourseChange (std::string context, Ptr position); private: virtual void DoRun (void) { @@ -142,13 +140,27 @@ private: Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", MakeCallback (&CourseChange)); + traced = 0; Simulator::Stop (Seconds (100.0)); Simulator::Run (); + + NS_TEST_ASSERT_MSG_GT (traced, 8, "position not every time"); + Simulator::Destroy (); } }; +uint64_t LeoOrbitTracingTestCase::traced = 0; + +void LeoOrbitTracingTestCase::CourseChange (std::string context, Ptr position) + { + traced ++; + Vector pos = position->GetPosition (); + std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y + << ", z=" << pos.z << std::endl; + } + class LeoOrbitTestSuite : TestSuite {