00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "propagation-loss-model.h"
00023 #include "ns3/log.h"
00024 #include "ns3/mobility-model.h"
00025 #include "ns3/static-mobility-model.h"
00026 #include "ns3/boolean.h"
00027 #include "ns3/double.h"
00028 #include <math.h>
00029
00030 NS_LOG_COMPONENT_DEFINE ("PropagationLossModel");
00031
00032 namespace ns3 {
00033
00034
00035
00036 NS_OBJECT_ENSURE_REGISTERED (PropagationLossModel);
00037
00038 TypeId
00039 PropagationLossModel::GetTypeId (void)
00040 {
00041 static TypeId tid = TypeId ("ns3::PropagationLossModel")
00042 .SetParent<Object> ()
00043 ;
00044 return tid;
00045 }
00046
00047 PropagationLossModel::PropagationLossModel ()
00048 : m_next (0)
00049 {}
00050
00051 PropagationLossModel::~PropagationLossModel ()
00052 {}
00053
00054 void
00055 PropagationLossModel::SetNext (Ptr<PropagationLossModel> next)
00056 {
00057 m_next = next;
00058 }
00059
00060 double
00061 PropagationLossModel::CalcRxPower (double txPowerDbm,
00062 Ptr<MobilityModel> a,
00063 Ptr<MobilityModel> b) const
00064 {
00065 double self = DoCalcRxPower (txPowerDbm, a, b);
00066 if (m_next != 0)
00067 {
00068 self = m_next->CalcRxPower (self, a, b);
00069 }
00070 return self;
00071 }
00072
00073
00074
00075 NS_OBJECT_ENSURE_REGISTERED (RandomPropagationLossModel);
00076
00077 TypeId
00078 RandomPropagationLossModel::GetTypeId (void)
00079 {
00080 static TypeId tid = TypeId ("ns3::RandomPropagationLossModel")
00081 .SetParent<PropagationLossModel> ()
00082 .AddConstructor<RandomPropagationLossModel> ()
00083 .AddAttribute ("Variable", "The random variable used to pick a loss everytime CalcRxPower is invoked.",
00084 RandomVariableValue (ConstantVariable (1.0)),
00085 MakeRandomVariableAccessor (&RandomPropagationLossModel::m_variable),
00086 MakeRandomVariableChecker ())
00087 ;
00088 return tid;
00089 }
00090 RandomPropagationLossModel::RandomPropagationLossModel ()
00091 : PropagationLossModel ()
00092 {}
00093
00094 RandomPropagationLossModel::~RandomPropagationLossModel ()
00095 {}
00096
00097 double
00098 RandomPropagationLossModel::DoCalcRxPower (double txPowerDbm,
00099 Ptr<MobilityModel> a,
00100 Ptr<MobilityModel> b) const
00101 {
00102 double rxc = -m_variable.GetValue ();
00103 NS_LOG_DEBUG ("attenuation coefficent="<<rxc<<"Db");
00104 return txPowerDbm + rxc;
00105 }
00106
00107
00108
00109 NS_OBJECT_ENSURE_REGISTERED (FriisPropagationLossModel);
00110
00111 const double FriisPropagationLossModel::PI = 3.1415;
00112
00113 TypeId
00114 FriisPropagationLossModel::GetTypeId (void)
00115 {
00116 static TypeId tid = TypeId ("ns3::FriisPropagationLossModel")
00117 .SetParent<PropagationLossModel> ()
00118 .AddConstructor<FriisPropagationLossModel> ()
00119 .AddAttribute ("Lambda",
00120 "The wavelength (default is 5.15 GHz at 300 000 km/s).",
00121 DoubleValue (300000000.0 / 5.150e9),
00122 MakeDoubleAccessor (&FriisPropagationLossModel::m_lambda),
00123 MakeDoubleChecker<double> ())
00124 .AddAttribute ("SystemLoss", "The system loss",
00125 DoubleValue (1.0),
00126 MakeDoubleAccessor (&FriisPropagationLossModel::m_systemLoss),
00127 MakeDoubleChecker<double> ())
00128 .AddAttribute ("MinDistance",
00129 "The distance under which the propagation model refuses to give results (m)",
00130 DoubleValue (0.5),
00131 MakeDoubleAccessor (&FriisPropagationLossModel::SetMinDistance,
00132 &FriisPropagationLossModel::GetMinDistance),
00133 MakeDoubleChecker<double> ())
00134 ;
00135 return tid;
00136 }
00137
00138 FriisPropagationLossModel::FriisPropagationLossModel ()
00139 {}
00140 void
00141 FriisPropagationLossModel::SetSystemLoss (double systemLoss)
00142 {
00143 m_systemLoss = systemLoss;
00144 }
00145 double
00146 FriisPropagationLossModel::GetSystemLoss (void) const
00147 {
00148 return m_systemLoss;
00149 }
00150 void
00151 FriisPropagationLossModel::SetMinDistance (double minDistance)
00152 {
00153 m_minDistance = minDistance;
00154 }
00155 double
00156 FriisPropagationLossModel::GetMinDistance (void) const
00157 {
00158 return m_minDistance;
00159 }
00160 void
00161 FriisPropagationLossModel::SetLambda (double frequency, double speed)
00162 {
00163 m_lambda = speed / frequency;
00164 }
00165 void
00166 FriisPropagationLossModel::SetLambda (double lambda)
00167 {
00168 m_lambda = lambda;
00169 }
00170 double
00171 FriisPropagationLossModel::GetLambda (void) const
00172 {
00173 return m_lambda;
00174 }
00175
00176 double
00177 FriisPropagationLossModel::DbmToW (double dbm) const
00178 {
00179 double mw = pow(10.0,dbm/10.0);
00180 return mw / 1000.0;
00181 }
00182
00183 double
00184 FriisPropagationLossModel::DbmFromW (double w) const
00185 {
00186 double dbm = log10 (w * 1000.0) * 10.0;
00187 return dbm;
00188 }
00189
00190 double
00191 FriisPropagationLossModel::DoCalcRxPower (double txPowerDbm,
00192 Ptr<MobilityModel> a,
00193 Ptr<MobilityModel> b) const
00194 {
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 double distance = a->GetDistanceFrom (b);
00225 if (distance <= m_minDistance)
00226 {
00227 return txPowerDbm;
00228 }
00229 double numerator = m_lambda * m_lambda;
00230 double denominator = 16 * PI * PI * distance * distance * m_systemLoss;
00231 double pr = 10 * log10 (numerator / denominator);
00232 NS_LOG_DEBUG ("distance="<<distance<<"m, attenuation coefficient="<<pr<<"dB");
00233 return txPowerDbm + pr;
00234 }
00235
00236
00237
00238 NS_OBJECT_ENSURE_REGISTERED (LogDistancePropagationLossModel);
00239
00240 TypeId
00241 LogDistancePropagationLossModel::GetTypeId (void)
00242 {
00243 static TypeId tid = TypeId ("ns3::LogDistancePropagationLossModel")
00244 .SetParent<PropagationLossModel> ()
00245 .AddConstructor<LogDistancePropagationLossModel> ()
00246 .AddAttribute ("Exponent",
00247 "The exponent of the Path Loss propagation model",
00248 DoubleValue (3.0),
00249 MakeDoubleAccessor (&LogDistancePropagationLossModel::m_exponent),
00250 MakeDoubleChecker<double> ())
00251 .AddAttribute ("ReferenceDistance",
00252 "The distance at which the reference loss is calculated (m)",
00253 DoubleValue (1.0),
00254 MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceDistance),
00255 MakeDoubleChecker<double> ())
00256 .AddAttribute ("ReferenceLoss",
00257 "The reference loss at reference distance (dB). (Default is Friis at 1m with 5.15 GHz)",
00258 DoubleValue (46.6777),
00259 MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceLoss),
00260 MakeDoubleChecker<double> ())
00261 ;
00262 return tid;
00263
00264 }
00265
00266 LogDistancePropagationLossModel::LogDistancePropagationLossModel ()
00267 {}
00268
00269 void
00270 LogDistancePropagationLossModel::SetPathLossExponent (double n)
00271 {
00272 m_exponent = n;
00273 }
00274 void
00275 LogDistancePropagationLossModel::SetReference (double referenceDistance, double referenceLoss)
00276 {
00277 m_referenceDistance = referenceDistance;
00278 m_referenceLoss = referenceLoss;
00279 }
00280 double
00281 LogDistancePropagationLossModel::GetPathLossExponent (void) const
00282 {
00283 return m_exponent;
00284 }
00285
00286 double
00287 LogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm,
00288 Ptr<MobilityModel> a,
00289 Ptr<MobilityModel> b) const
00290 {
00291 double distance = a->GetDistanceFrom (b);
00292 if (distance <= m_referenceDistance)
00293 {
00294 return txPowerDbm;
00295 }
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 double pathLossDb = 10 * m_exponent * log10 (distance / m_referenceDistance);
00311 double rxc = -m_referenceLoss - pathLossDb;
00312 NS_LOG_DEBUG ("distance="<<distance<<"m, reference-attenuation="<<-m_referenceLoss<<"dB, "<<
00313 "attenuation coefficient="<<rxc<<"db");
00314 return txPowerDbm + rxc;
00315 }
00316
00317
00318
00319 NS_OBJECT_ENSURE_REGISTERED (ThreeLogDistancePropagationLossModel);
00320
00321 TypeId
00322 ThreeLogDistancePropagationLossModel::GetTypeId (void)
00323 {
00324 static TypeId tid = TypeId ("ns3::ThreeLogDistancePropagationLossModel")
00325 .SetParent<PropagationLossModel> ()
00326 .AddConstructor<ThreeLogDistancePropagationLossModel> ()
00327 .AddAttribute ("Distance0",
00328 "Beginning of the first (near) distance field",
00329 DoubleValue (1.0),
00330 MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance0),
00331 MakeDoubleChecker<double> ())
00332 .AddAttribute ("Distance1",
00333 "Beginning of the second (middle) distance field.",
00334 DoubleValue (200.0),
00335 MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance1),
00336 MakeDoubleChecker<double> ())
00337 .AddAttribute ("Distance2",
00338 "Beginning of the third (far) distance field.",
00339 DoubleValue (500.0),
00340 MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance2),
00341 MakeDoubleChecker<double> ())
00342 .AddAttribute ("Exponent0",
00343 "The exponent for the first field.",
00344 DoubleValue (1.9),
00345 MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent0),
00346 MakeDoubleChecker<double> ())
00347 .AddAttribute ("Exponent1",
00348 "The exponent for the second field.",
00349 DoubleValue (3.8),
00350 MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent1),
00351 MakeDoubleChecker<double> ())
00352 .AddAttribute ("Exponent2",
00353 "The exponent for the third field.",
00354 DoubleValue (3.8),
00355 MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent2),
00356 MakeDoubleChecker<double> ())
00357 .AddAttribute ("ReferenceLoss",
00358 "The reference loss at distance d0 (dB). (Default is Friis at 1m with 5.15 GHz)",
00359 DoubleValue (46.6777),
00360 MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_referenceLoss),
00361 MakeDoubleChecker<double> ())
00362 ;
00363 return tid;
00364
00365 }
00366
00367 ThreeLogDistancePropagationLossModel::ThreeLogDistancePropagationLossModel ()
00368 {
00369 }
00370
00371 double
00372 ThreeLogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm,
00373 Ptr<MobilityModel> a,
00374 Ptr<MobilityModel> b) const
00375 {
00376 double distance = a->GetDistanceFrom (b);
00377 NS_ASSERT(distance >= 0);
00378
00379
00380
00381 double pathLossDb;
00382
00383 if (distance < m_distance0)
00384 {
00385 pathLossDb = 0;
00386 }
00387 else if (distance < m_distance1)
00388 {
00389 pathLossDb = m_referenceLoss
00390 + 10 * m_exponent0 * log10(distance / m_distance0);
00391 }
00392 else if (distance < m_distance2)
00393 {
00394 pathLossDb = m_referenceLoss
00395 + 10 * m_exponent0 * log10(m_distance1 / m_distance0)
00396 + 10 * m_exponent1 * log10(distance / m_distance1);
00397 }
00398 else
00399 {
00400 pathLossDb = m_referenceLoss
00401 + 10 * m_exponent0 * log10(m_distance1 / m_distance0)
00402 + 10 * m_exponent1 * log10(m_distance2 / m_distance1)
00403 + 10 * m_exponent2 * log10(distance / m_distance2);
00404 }
00405
00406 NS_LOG_DEBUG ("ThreeLogDistance distance=" << distance << "m, " <<
00407 "attenuation=" << pathLossDb << "dB");
00408
00409 return txPowerDbm - pathLossDb;
00410 }
00411
00412
00413
00414 NS_OBJECT_ENSURE_REGISTERED (NakagamiPropagationLossModel);
00415
00416 TypeId
00417 NakagamiPropagationLossModel::GetTypeId (void)
00418 {
00419 static TypeId tid = TypeId ("ns3::NakagamiPropagationLossModel")
00420 .SetParent<PropagationLossModel> ()
00421 .AddConstructor<NakagamiPropagationLossModel> ()
00422
00423 .AddAttribute ("Distance1",
00424 "Beginning of the second distance field. Default is 80m.",
00425 DoubleValue (80.0),
00426 MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance1),
00427 MakeDoubleChecker<double> ())
00428 .AddAttribute ("Distance2",
00429 "Beginning of the third distance field. Default is 200m.",
00430 DoubleValue (200.0),
00431 MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance2),
00432 MakeDoubleChecker<double> ())
00433
00434 .AddAttribute ("m0",
00435 "m0 for distances smaller than Distance1. Default is 1.5.",
00436 DoubleValue (1.5),
00437 MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m0),
00438 MakeDoubleChecker<double> ())
00439 .AddAttribute ("m1",
00440 "m1 for distances smaller than Distance2. Default is 0.75.",
00441 DoubleValue (0.75),
00442 MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m1),
00443 MakeDoubleChecker<double> ())
00444 .AddAttribute ("m2",
00445 "m2 for distances greater than Distance2. Default is 0.75.",
00446 DoubleValue (0.75),
00447 MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m2),
00448 MakeDoubleChecker<double> ())
00449 ;
00450 return tid;
00451
00452 }
00453
00454 NakagamiPropagationLossModel::NakagamiPropagationLossModel ()
00455 {}
00456
00457 double
00458 NakagamiPropagationLossModel::DoCalcRxPower (double txPowerDbm,
00459 Ptr<MobilityModel> a,
00460 Ptr<MobilityModel> b) const
00461 {
00462
00463
00464 double distance = a->GetDistanceFrom (b);
00465 NS_ASSERT(distance >= 0);
00466
00467 double m;
00468 if (distance < m_distance1)
00469 m = m_m0;
00470 else if (distance < m_distance2)
00471 m = m_m1;
00472 else
00473 m = m_m2;
00474
00475
00476
00477 double powerW = pow(10, (txPowerDbm - 30) / 10);
00478
00479 double resultPowerW;
00480
00481
00482
00483 unsigned int int_m = static_cast<unsigned int>(floor(m));
00484
00485 if (int_m == m)
00486 {
00487 resultPowerW = ErlangVariable::GetSingleValue(int_m, powerW / m);
00488 }
00489 else
00490 {
00491 resultPowerW = GammaVariable::GetSingleValue(m, powerW / m);
00492 }
00493
00494 double resultPowerDbm = 10 * log10(resultPowerW) + 30;
00495
00496 NS_LOG_DEBUG ("Nakagami distance=" << distance << "m, " <<
00497 "power=" << powerW <<"W, " <<
00498 "resultPower=" << resultPowerW << "W=" << resultPowerDbm << "dBm");
00499
00500 return resultPowerDbm;
00501 }
00502
00503
00504
00505 }