20 #include "ns3/abort.h"
22 #include "ns3/config.h"
23 #include "ns3/double.h"
24 #include "ns3/propagation-loss-model.h"
25 #include "ns3/constant-position-mobility-model.h"
26 #include "ns3/simulator.h"
44 virtual void DoRun (
void);
56 FriisPropagationLossModelTestCase::FriisPropagationLossModelTestCase ()
57 :
TestCase (
"Check to see that the ns-3 Friis propagation loss model provides correct received power"), m_testVectors ()
61 FriisPropagationLossModelTestCase::~FriisPropagationLossModelTestCase ()
73 Config::SetDefault (
"ns3::FriisPropagationLossModel::Frequency",
DoubleValue (2398339664.0));
74 Config::SetDefault (
"ns3::FriisPropagationLossModel::SystemLoss",
DoubleValue (1.0));
78 double txPowerW = 0.05035702;
79 double txPowerdBm = 10 * std::log10 (txPowerW) + 30;
92 testVector.m_position =
Vector (100, 0, 0);
93 testVector.m_pt = txPowerdBm;
94 testVector.m_pr = 4.98265e-10;
95 testVector.m_tolerance = 5e-16;
96 m_testVectors.Add (testVector);
98 testVector.m_position =
Vector (500, 0, 0);
99 testVector.m_pt = txPowerdBm;
100 testVector.m_pr = 1.99306e-11;
101 testVector.m_tolerance = 5e-17;
102 m_testVectors.Add (testVector);
104 testVector.m_position =
Vector (1000, 0, 0);
105 testVector.m_pt = txPowerdBm;
106 testVector.m_pr = 4.98265e-12;
107 testVector.m_tolerance = 5e-18;
108 m_testVectors.Add (testVector);
110 testVector.m_position =
Vector (2000, 0, 0);
111 testVector.m_pt = txPowerdBm;
112 testVector.m_pr = 1.24566e-12;
113 testVector.m_tolerance = 5e-18;
114 m_testVectors.Add (testVector);
123 for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
125 testVector = m_testVectors.Get (i);
127 double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
128 double resultW = std::pow (10.0, resultdBm/10.0)/1000;
129 NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance,
"Got unexpected rcv power");
142 virtual void DoRun (
void);
155 TwoRayGroundPropagationLossModelTestCase::TwoRayGroundPropagationLossModelTestCase ()
156 :
TestCase (
"Check to see that the ns-3 TwoRayGround propagation loss model provides correct received power"),
161 TwoRayGroundPropagationLossModelTestCase::~TwoRayGroundPropagationLossModelTestCase ()
170 Config::SetDefault (
"ns3::TwoRayGroundPropagationLossModel::Frequency",
DoubleValue (2398339664.0));
171 Config::SetDefault (
"ns3::TwoRayGroundPropagationLossModel::SystemLoss",
DoubleValue (1.0));
174 Config::SetDefault (
"ns3::TwoRayGroundPropagationLossModel::HeightAboveZ",
DoubleValue (1.5));
178 double txPowerW = 0.05035702;
179 double txPowerdBm = 10 * std::log10 (txPowerW) + 30;
193 testVector.m_position =
Vector (100, 0, 0);
194 testVector.m_pt = txPowerdBm;
195 testVector.m_pr = 4.98265e-10;
196 testVector.m_tolerance = 5e-16;
197 m_testVectors.Add (testVector);
201 testVector.m_position =
Vector (500, 0, 0);
202 testVector.m_pt = txPowerdBm;
203 testVector.m_pr = 4.07891862e-12;
204 testVector.m_tolerance = 5e-16;
205 m_testVectors.Add (testVector);
207 testVector.m_position =
Vector (1000, 0, 0);
208 testVector.m_pt = txPowerdBm;
209 testVector.m_pr = 2.5493241375e-13;
210 testVector.m_tolerance = 5e-16;
211 m_testVectors.Add (testVector);
213 testVector.m_position =
Vector (2000, 0, 0);
214 testVector.m_pt = txPowerdBm;
215 testVector.m_pr = 1.593327585938e-14;
216 testVector.m_tolerance = 5e-16;
217 m_testVectors.Add (testVector);
223 testVector.m_position =
Vector (500, 0, 1);
224 testVector.m_pt = txPowerdBm;
225 testVector.m_pr = 1.13303295e-11;
226 testVector.m_tolerance = 5e-16;
227 m_testVectors.Add (testVector);
231 testVector.m_position =
Vector (1000, 0, 4);
232 testVector.m_pt = txPowerdBm;
233 testVector.m_pr = 3.42742467375e-12;
234 testVector.m_tolerance = 5e-16;
235 m_testVectors.Add (testVector);
239 testVector.m_position =
Vector (2000, 0, 10);
240 testVector.m_pt = txPowerdBm;
241 testVector.m_pr = 9.36522547734e-13;
242 testVector.m_tolerance = 5e-16;
243 m_testVectors.Add (testVector);
253 for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
255 testVector = m_testVectors.Get (i);
257 double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
258 double resultW = std::pow (10.0, resultdBm / 10.0) / 1000;
259 NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance,
"Got unexpected rcv power");
271 virtual void DoRun (
void);
283 LogDistancePropagationLossModelTestCase::LogDistancePropagationLossModelTestCase ()
284 :
TestCase (
"Check to see that the ns-3 Log Distance propagation loss model provides correct received power"), m_testVectors ()
288 LogDistancePropagationLossModelTestCase::~LogDistancePropagationLossModelTestCase ()
296 Config::SetDefault (
"ns3::LogDistancePropagationLossModel::ReferenceLoss",
DoubleValue (40.045997));
297 Config::SetDefault (
"ns3::LogDistancePropagationLossModel::Exponent",
DoubleValue (3));
301 double txPowerW = 0.05035702;
302 double txPowerdBm = 10 * std::log10 (txPowerW) + 30;
312 testVector.m_position =
Vector (10, 0, 0);
313 testVector.m_pt = txPowerdBm;
314 testVector.m_pr = 4.98265e-9;
315 testVector.m_tolerance = 5e-15;
316 m_testVectors.Add (testVector);
318 testVector.m_position =
Vector (20, 0, 0);
319 testVector.m_pt = txPowerdBm;
320 testVector.m_pr = 6.22831e-10;
321 testVector.m_tolerance = 5e-16;
322 m_testVectors.Add (testVector);
324 testVector.m_position =
Vector (40, 0, 0);
325 testVector.m_pt = txPowerdBm;
326 testVector.m_pr = 7.78539e-11;
327 testVector.m_tolerance = 5e-17;
328 m_testVectors.Add (testVector);
330 testVector.m_position =
Vector (80, 0, 0);
331 testVector.m_pt = txPowerdBm;
332 testVector.m_pr = 9.73173e-12;
333 testVector.m_tolerance = 5e-17;
334 m_testVectors.Add (testVector);
341 for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
343 testVector = m_testVectors.Get (i);
345 double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
346 double resultW = std::pow (10.0, resultdBm/10.0)/1000;
347 NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance,
"Got unexpected rcv power");
358 virtual void DoRun (
void);
361 MatrixPropagationLossModelTestCase::MatrixPropagationLossModelTestCase ()
362 :
TestCase (
"Test MatrixPropagationLossModel")
366 MatrixPropagationLossModelTestCase::~MatrixPropagationLossModelTestCase ()
374 for (
int i = 0; i < 3; ++i)
376 m[i] = CreateObject<ConstantPositionMobilityModel> ();
385 loss.
SetLoss (m[0], m[2], 30,
false);
386 loss.
SetLoss (m[2], m[0], 100,
false);
389 NS_TEST_ASSERT_MSG_EQ (loss.
CalcRxPower (0, m[0], m[1]), -10,
"Loss 0 -> 1 incorrect");
390 NS_TEST_ASSERT_MSG_EQ (loss.
CalcRxPower (0, m[1], m[0]), -10,
"Loss 1 -> 0 incorrect");
391 NS_TEST_ASSERT_MSG_EQ (loss.
CalcRxPower (0, m[0], m[2]), -30,
"Loss 0 -> 2 incorrect");
392 NS_TEST_ASSERT_MSG_EQ (loss.
CalcRxPower (0, m[2], m[0]), -100,
"Loss 2 -> 0 incorrect");
393 NS_TEST_ASSERT_MSG_EQ (loss.
CalcRxPower (0, m[1], m[2]), 0,
"Loss 1 -> 2 incorrect");
394 NS_TEST_ASSERT_MSG_EQ (loss.
CalcRxPower (0, m[2], m[1]), 0,
"Loss 2 -> 1 incorrect");
396 Simulator::Destroy ();
406 virtual void DoRun (
void);
409 RangePropagationLossModelTestCase::RangePropagationLossModelTestCase ()
410 :
TestCase (
"Test RangePropagationLossModel")
414 RangePropagationLossModelTestCase::~RangePropagationLossModelTestCase ()
421 Config::SetDefault (
"ns3::RangePropagationLossModel::MaxRange",
DoubleValue (127.2));
429 double txPwrdBm = -80.0;
430 double tolerance = 1e-6;
431 double resultdBm = lossModel->
CalcRxPower (txPwrdBm, a, b);
432 NS_TEST_EXPECT_MSG_EQ_TOL (resultdBm, txPwrdBm, tolerance,
"Got unexpected rcv power");
434 resultdBm = lossModel->
CalcRxPower (txPwrdBm, a, b);
435 NS_TEST_EXPECT_MSG_EQ_TOL (resultdBm, -1000.0, tolerance,
"Got unexpected rcv power");
436 Simulator::Destroy ();
445 PropagationLossModelsTestSuite::PropagationLossModelsTestSuite ()
446 :
TestSuite (
"propagation-loss-model", UNIT)
void SetDefaultLoss(double)
Set default loss (in dB, positive) to be used, infinity if not set.
#define NS_LOG_COMPONENT_DEFINE(name)
virtual void DoRun(void)
Implementation to actually run this test case.
A simple way to store test vectors (for stimulus or from responses)
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
void SetPosition(const Vector &position)
virtual void DoRun(void)
Implementation to actually run this test case.
void SetLoss(Ptr< MobilityModel > a, Ptr< MobilityModel > b, double loss, bool symmetric=true)
Set loss (in dB, positive) between pair of ns-3 objects (typically, nodes).
Hold an floating point type.
virtual void DoRun(void)
Implementation to actually run this test case.
The propagation loss is fixed for each pair of nodes and doesn't depend on their actual positions...
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void DoRun(void)
Implementation to actually run this test case.