LEFT | RIGHT |
(no file at all) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2015 Portland state university |
| 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: Farnoosh Moshir <moshir2@cs.pdx.edu> |
| 19 * Suresh Singh <singh@cs.pdx.edu> |
| 20 */ |
| 21 |
| 22 #include "ns3/log.h" |
| 23 #include "ns3/abort.h" |
| 24 #include "ns3/test.h" |
| 25 #include "ns3/thz-propagation-loss-model.h" |
| 26 #include "ns3/config.h" |
| 27 #include "ns3/double.h" |
| 28 #include "ns3/uinteger.h" |
| 29 #include "ns3/constant-position-mobility-model.h" |
| 30 #include "ns3/simulator.h" |
| 31 |
| 32 using namespace ns3; |
| 33 |
| 34 NS_LOG_COMPONENT_DEFINE ("ThzPropagationLossModelsTest"); |
| 35 |
| 36 |
| 37 // Added for directional THz channels |
| 38 class ThzDirectionalPropagationLossModelTestCase : public TestCase |
| 39 { |
| 40 public: |
| 41 ThzDirectionalPropagationLossModelTestCase (); |
| 42 virtual ~ThzDirectionalPropagationLossModelTestCase (); |
| 43 ···· |
| 44 private: |
| 45 virtual void DoRun (void); |
| 46 ···· |
| 47 typedef struct { |
| 48 Vector m_position; |
| 49 double m_pt; // dBm |
| 50 double m_pr; // W |
| 51 double m_tolerance; |
| 52 |
| 53 } TestVector; |
| 54 ···· |
| 55 TestVectors<TestVector> m_testVectors; |
| 56 }; |
| 57 |
| 58 ThzDirectionalPropagationLossModelTestCase::ThzDirectionalPropagationLossModelTe
stCase () |
| 59 : TestCase ("Check to see that the ns-3 THz directional propagation loss model p
rovides correct received power"), m_testVectors () |
| 60 { |
| 61 } |
| 62 |
| 63 ThzDirectionalPropagationLossModelTestCase::~ThzDirectionalPropagationLossModelT
estCase () |
| 64 { |
| 65 } |
| 66 |
| 67 void |
| 68 ThzDirectionalPropagationLossModelTestCase::DoRun (void) |
| 69 { |
| 70 // Set few defaults. |
| 71 |
| 72 Config::SetDefault ("ns3::ThzDirectionalPropagationLossModel::Frequency", Do
ubleValue (237.5e9)); |
| 73 Config::SetDefault ("ns3::ThzDirectionalPropagationLossModel::Humidity", Uin
tegerValue (40)); |
| 74 Config::SetDefault ("ns3::ThzDirectionalPropagationLossModel::SystemLoss", D
oubleValue (1.0)); |
| 75 ···· |
| 76 |
| 77 double txPowerW = 0.05035702; |
| 78 double txPowerdBm = 10 * std::log10 (txPowerW) + 30; |
| 79 ···· |
| 80 // Test the value of the propagation loss model for few distances |
| 81 // and compare the result with the values calculated manually |
| 82 TestVector testVector; |
| 83 ···· |
| 84 testVector.m_position = Vector (10, 0, 0); |
| 85 testVector.m_pt = txPowerdBm; |
| 86 testVector.m_pr = 0.0504; |
| 87 testVector.m_tolerance = 5e-5; |
| 88 m_testVectors.Add (testVector); |
| 89 ···· |
| 90 testVector.m_position = Vector (100, 0, 0); |
| 91 testVector.m_pt = txPowerdBm; |
| 92 testVector.m_pr = 0.0503; |
| 93 testVector.m_tolerance = 5e-5; |
| 94 m_testVectors.Add (testVector); |
| 95 ···· |
| 96 testVector.m_position = Vector (1000, 0, 0); |
| 97 testVector.m_pt = txPowerdBm; |
| 98 testVector.m_pr = 0.0502; |
| 99 testVector.m_tolerance = 5e-5; |
| 100 m_testVectors.Add (testVector); |
| 101 ···· |
| 102 ···· |
| 103 // Now, check that the received power values are expected |
| 104 ···· |
| 105 Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> (); |
| 106 a->SetPosition (Vector (0,0,0)); |
| 107 Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> (); |
| 108 ···· |
| 109 Ptr<ThzDirectionalPropagationLossModel> lossModel = CreateObject<ThzDirectio
nalPropagationLossModel> (); |
| 110 for (uint32_t i = 0; i < m_testVectors.GetN (); ++i) |
| 111 { |
| 112 testVector = m_testVectors.Get (i); |
| 113 b->SetPosition (testVector.m_position); |
| 114 double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b); |
| 115 double resultW = std::pow (10.0, resultdBm/10.0)/1000; |
| 116 NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolera
nce, "Got unexpected received power"); |
| 117 } |
| 118 } |
| 119 |
| 120 |
| 121 // Added for omni directional THz channels |
| 122 class ThzOmniDirectionalPropagationLossModelTestCase : public TestCase |
| 123 { |
| 124 public: |
| 125 ThzOmniDirectionalPropagationLossModelTestCase (); |
| 126 virtual ~ThzOmniDirectionalPropagationLossModelTestCase (); |
| 127 ···· |
| 128 private: |
| 129 virtual void DoRun (void); |
| 130 ···· |
| 131 typedef struct { |
| 132 Vector m_position; |
| 133 double m_pt; // dBm |
| 134 double m_pr; // W |
| 135 double m_tolerance; |
| 136 ········ |
| 137 } TestVector; |
| 138 ···· |
| 139 TestVectors<TestVector> m_testVectors; |
| 140 }; |
| 141 |
| 142 ThzOmniDirectionalPropagationLossModelTestCase::ThzOmniDirectionalPropagationLos
sModelTestCase () |
| 143 : TestCase ("Check to see that the ns-3 THz omni directional propagation loss mo
del provides correct received power"), m_testVectors () |
| 144 { |
| 145 } |
| 146 |
| 147 ThzOmniDirectionalPropagationLossModelTestCase::~ThzOmniDirectionalPropagationLo
ssModelTestCase () |
| 148 { |
| 149 } |
| 150 |
| 151 void |
| 152 ThzOmniDirectionalPropagationLossModelTestCase::DoRun (void) |
| 153 { |
| 154 // Set few defaults. |
| 155 |
| 156 Config::SetDefault ("ns3::ThzOmniDirectionalPropagationLossModel::Frequency"
, DoubleValue (237.5e9)); |
| 157 Config::SetDefault ("ns3::ThzOmniDirectionalPropagationLossModel::Humidity",
UintegerValue (40)); |
| 158 Config::SetDefault ("ns3::ThzOmniDirectionalPropagationLossModel::SystemLoss
", DoubleValue (1.0)); |
| 159 ···· |
| 160 double txPowerW = 0.05035702; |
| 161 double txPowerdBm = 10 * std::log10 (txPowerW) + 30; |
| 162 ···· |
| 163 ···· |
| 164 // Test the value of the propagation loss model for few distances |
| 165 // and compare the result with the values calculated manually |
| 166 ···· |
| 167 TestVector testVector; |
| 168 ···· |
| 169 testVector.m_position = Vector (5, 0, 0); |
| 170 testVector.m_pt = txPowerdBm; |
| 171 testVector.m_pr = 2.0324e-11; |
| 172 testVector.m_tolerance = 5e-16; |
| 173 m_testVectors.Add (testVector); |
| 174 ···· |
| 175 ···· |
| 176 testVector.m_position = Vector (10, 0, 0); |
| 177 testVector.m_pt = txPowerdBm; |
| 178 testVector.m_pr = 5.0809e-12; |
| 179 testVector.m_tolerance = 5e-17; |
| 180 m_testVectors.Add (testVector); |
| 181 |
| 182 testVector.m_position = Vector (100, 0, 0); |
| 183 testVector.m_pt = txPowerdBm; |
| 184 testVector.m_pr = 5.0796e-14; |
| 185 testVector.m_tolerance = 5e-19; |
| 186 m_testVectors.Add (testVector); |
| 187 ···· |
| 188 ···· |
| 189 // Now, check that the received power values are expected |
| 190 ···· |
| 191 Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> (); |
| 192 a->SetPosition (Vector (0,0,0)); |
| 193 Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> (); |
| 194 ···· |
| 195 Ptr<ThzOmniDirectionalPropagationLossModel> lossModel = CreateObject<ThzOmni
DirectionalPropagationLossModel> (); |
| 196 for (uint32_t i = 0; i < m_testVectors.GetN (); ++i) |
| 197 { |
| 198 testVector = m_testVectors.Get (i); |
| 199 b->SetPosition (testVector.m_position); |
| 200 double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b); |
| 201 double resultW = std::pow (10.0, resultdBm/10.0)/1000; |
| 202 NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolera
nce, "Got unexpected received power"); |
| 203 } |
| 204 } |
| 205 |
| 206 |
| 207 |
| 208 class ThzPropagationLossModelsTestSuite : public TestSuite |
| 209 { |
| 210 public: |
| 211 ThzPropagationLossModelsTestSuite (); |
| 212 }; |
| 213 |
| 214 ThzPropagationLossModelsTestSuite::ThzPropagationLossModelsTestSuite () |
| 215 : TestSuite ("thz-propagation-loss-model", UNIT) |
| 216 { |
| 217 AddTestCase (new ThzDirectionalPropagationLossModelTestCase, TestCase::QUICK); |
| 218 AddTestCase (new ThzOmniDirectionalPropagationLossModelTestCase, TestCase::QUI
CK); |
| 219 } |
| 220 |
| 221 static ThzPropagationLossModelsTestSuite thzPropagationLossModelsTestSuite; |
LEFT | RIGHT |