satellite-fsl-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Sami Rantanen <sami.rantanen@magister.fi>
19  */
20 
27 #include "../helper/satellite-helper.h"
28 #include "../model/satellite-free-space-loss.h"
29 #include "../model/satellite-mobility-model.h"
30 #include "../utils/satellite-env-variables.h"
31 
32 #include "ns3/log.h"
33 #include "ns3/simulator.h"
34 #include "ns3/singleton.h"
35 #include "ns3/test.h"
36 
37 using namespace ns3;
38 
53 class SatFreeSpaceLossTestCase : public TestCase
54 {
55  public:
57  virtual ~SatFreeSpaceLossTestCase();
58 
59  private:
60  virtual void DoRun(void);
61 };
62 
64  : TestCase("Test satellite free space loss model.")
65 {
66 }
67 
69 {
70 }
71 
72 void
74 {
75  // Set simulation output details
76  Singleton<SatEnvVariables>::Get()->DoInitialize();
77  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-fsl", "", true);
78 
79  SatFreeSpaceLoss fsl;
80  double frequency = 17.9 * std::pow(10.0, 9); // reference frequency
81 
82  // Create simple scenario
83 
84  // Creating the reference system.
85  Ptr<SatHelper> helper = CreateObject<SatHelper>();
86 
87  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
88 
89  NodeContainer gw = helper->GwNodes();
90  NodeContainer ut = helper->UtNodes();
91  Ptr<Node> geo = helper->GeoSatNodes().Get(0);
92 
93  // get mobilities
94  Ptr<SatMobilityModel> gwMob = gw.Get(0)->GetObject<SatMobilityModel>();
95  Ptr<SatMobilityModel> utMob = ut.Get(0)->GetObject<SatMobilityModel>();
96  Ptr<SatMobilityModel> geoMob = geo->GetObject<SatMobilityModel>();
97 
98  // set reference positions for test
99  gwMob->SetGeoPosition(GeoCoordinate(25.28, 54.689444, 0.0));
100  utMob->SetGeoPosition(GeoCoordinate(25.00, -26.20, 230.0));
101  geoMob->SetGeoPosition(GeoCoordinate(0.0, 33.0, 35786000.0));
102 
103  // test fsl calculation in path UT - Geo Satellite
104  // double fsl_ratio = fsl.GetFsl(utMob, geoMob, frequency);
105  double fsl_dB = fsl.GetFsldB(utMob, geoMob, frequency);
106 
107  // Calculations with big double numbers there will produce results
108  // with different precisions when compiled with optimized and debug flags.
109  // TODO: check whether we could change e.g. the waf configure to avoid the precision problem.
110  // NS_TEST_ASSERT_MSG_EQ_TOL( fsl_ratio, 883122910318077150000.0, 1.1, "FSL (UT-GEO) ratio
111  // incorrect");
112  NS_TEST_ASSERT_MSG_EQ_TOL(fsl_dB, 209.460211515483, 0.1, "FSL (UT-GEO) in dBs incorrect");
113 
114  // test fsl calculation in path GW - Geo Satellite
115  // fsl_ratio = fsl.GetFsl(gwMob, geoMob, frequency);
116  fsl_dB = fsl.GetFsldB(gwMob, geoMob, frequency);
117 
118  // Calculations with big double numbers there will produce results
119  // with different precisions when compiled with optimized and debug flags.
120  // TODO: check whether we could change e.g. the waf configure to avoid the precision problem.
121  // NS_TEST_ASSERT_MSG_EQ_TOL( fsl_ratio, 769159080122215960000.0, 1.1, "FSL (GW-GEO) ratio
122  // incorrect");
123  NS_TEST_ASSERT_MSG_EQ_TOL(fsl_dB, 208.86016171367487, 0.1, "FSL (GW-GEO) in dBs incorrect");
124 
125  Simulator::Destroy();
126 
127  Singleton<SatEnvVariables>::Get()->DoDispose();
128 }
129 
133 class SatFreeSpaceLossTestSuite : public TestSuite
134 {
135  public:
137 };
138 
140  : TestSuite("sat-fsl-test", UNIT)
141 {
142  AddTestCase(new SatFreeSpaceLossTestCase, TestCase::QUICK);
143 }
144 
145 // Do allocate an instance of this TestSuite
Test case to unit test satellite free space loss (FSL) model.
Test suite for Satellite free space loss unit test cases.
GeoCoordinate class is used to store and operate with geodetic coordinates.
This class is responsible of calculating the free space loss (FSL) based on two given node positions ...
virtual double GetFsldB(Ptr< MobilityModel > a, Ptr< MobilityModel > b, double frequencyHz) const
Calculate the free-space loss in dB.
Keep track of the current position and velocity of an object in satellite network.
void SetGeoPosition(const GeoCoordinate &position)
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static SatFreeSpaceLossTestSuite satFslTestSuite