24 #include "propagation-loss-model.h"
26 #include "ns3/mobility-model.h"
27 #include "ns3/boolean.h"
28 #include "ns3/double.h"
29 #include "ns3/string.h"
30 #include "ns3/pointer.h"
39 NS_OBJECT_ENSURE_REGISTERED (PropagationLossModel);
42 PropagationLossModel::GetTypeId (
void)
44 static TypeId tid = TypeId (
"ns3::PropagationLossModel")
50 PropagationLossModel::PropagationLossModel ()
55 PropagationLossModel::~PropagationLossModel ()
66 PropagationLossModel::GetNext ()
72 PropagationLossModel::CalcRxPower (
double txPowerDbm,
76 double self = DoCalcRxPower (txPowerDbm, a, b);
79 self = m_next->CalcRxPower (
self, a, b);
85 PropagationLossModel::AssignStreams (int64_t stream)
87 int64_t currentStream = stream;
88 currentStream += DoAssignStreams (stream);
91 currentStream += m_next->AssignStreams (currentStream);
93 return (currentStream - stream);
101 RandomPropagationLossModel::GetTypeId (
void)
103 static TypeId tid =
TypeId (
"ns3::RandomPropagationLossModel")
105 .AddConstructor<RandomPropagationLossModel> ()
106 .AddAttribute (
"Variable",
"The random variable used to pick a loss everytime CalcRxPower is invoked.",
107 StringValue (
"ns3::ConstantRandomVariable[Constant=1.0]"),
108 MakePointerAccessor (&RandomPropagationLossModel::m_variable),
109 MakePointerChecker<RandomVariableStream> ())
113 RandomPropagationLossModel::RandomPropagationLossModel ()
114 : PropagationLossModel ()
118 RandomPropagationLossModel::~RandomPropagationLossModel ()
123 RandomPropagationLossModel::DoCalcRxPower (
double txPowerDbm,
124 Ptr<MobilityModel> a,
125 Ptr<MobilityModel> b)
const
127 double rxc = -m_variable->
GetValue ();
129 return txPowerDbm + rxc;
143 const double FriisPropagationLossModel::PI = 3.14159265358979323846;
146 FriisPropagationLossModel::GetTypeId (
void)
148 static TypeId tid =
TypeId (
"ns3::FriisPropagationLossModel")
150 .AddConstructor<FriisPropagationLossModel> ()
151 .AddAttribute (
"Frequency",
152 "The carrier frequency (in Hz) at which propagation occurs (default is 5.15 GHz).",
156 MakeDoubleChecker<double> ())
157 .AddAttribute (
"SystemLoss",
"The system loss",
159 MakeDoubleAccessor (&FriisPropagationLossModel::m_systemLoss),
160 MakeDoubleChecker<double> ())
161 .AddAttribute (
"MinDistance",
162 "The distance under which the propagation model refuses to give results (m)",
166 MakeDoubleChecker<double> ())
171 FriisPropagationLossModel::FriisPropagationLossModel ()
177 m_systemLoss = systemLoss;
187 m_minDistance = minDistance;
192 return m_minDistance;
198 m_frequency = frequency;
199 static const double C = 299792458.0;
200 m_lambda = C / frequency;
210 FriisPropagationLossModel::DbmToW (
double dbm)
const
212 double mw = std::pow (10.0,dbm/10.0);
217 FriisPropagationLossModel::DbmFromW (
double w)
const
219 double dbm = std::log10 (w * 1000.0) * 10.0;
224 FriisPropagationLossModel::DoCalcRxPower (
double txPowerDbm,
225 Ptr<MobilityModel> a,
226 Ptr<MobilityModel> b)
const
257 double distance = a->GetDistanceFrom (b);
258 if (distance <= m_minDistance)
262 double numerator = m_lambda * m_lambda;
263 double denominator = 16 * PI * PI * distance * distance * m_systemLoss;
264 double pr = 10 * std::log10 (numerator / denominator);
265 NS_LOG_DEBUG (
"distance="<<distance<<
"m, attenuation coefficient="<<pr<<
"dB");
266 return txPowerDbm + pr;
280 const double TwoRayGroundPropagationLossModel::PI = 3.14159265358979323846;
283 TwoRayGroundPropagationLossModel::GetTypeId (
void)
285 static TypeId tid =
TypeId (
"ns3::TwoRayGroundPropagationLossModel")
287 .AddConstructor<TwoRayGroundPropagationLossModel> ()
288 .AddAttribute (
"Frequency",
289 "The carrier frequency (in Hz) at which propagation occurs (default is 5.15 GHz).",
293 MakeDoubleChecker<double> ())
294 .AddAttribute (
"SystemLoss",
"The system loss",
296 MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_systemLoss),
297 MakeDoubleChecker<double> ())
298 .AddAttribute (
"MinDistance",
299 "The distance under which the propagation model refuses to give results (m)",
303 MakeDoubleChecker<double> ())
304 .AddAttribute (
"HeightAboveZ",
305 "The height of the antenna (m) above the node's Z coordinate",
307 MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_heightAboveZ),
308 MakeDoubleChecker<double> ())
313 TwoRayGroundPropagationLossModel::TwoRayGroundPropagationLossModel ()
319 m_systemLoss = systemLoss;
329 m_minDistance = minDistance;
334 return m_minDistance;
339 m_heightAboveZ = heightAboveZ;
345 m_frequency = frequency;
346 static const double C = 299792458.0;
347 m_lambda = C / frequency;
357 TwoRayGroundPropagationLossModel::DbmToW (
double dbm)
const
359 double mw = std::pow (10.0,dbm / 10.0);
364 TwoRayGroundPropagationLossModel::DbmFromW (
double w)
const
366 double dbm = std::log10 (w * 1000.0) * 10.0;
371 TwoRayGroundPropagationLossModel::DoCalcRxPower (
double txPowerDbm,
372 Ptr<MobilityModel> a,
373 Ptr<MobilityModel> b)
const
401 double distance = a->GetDistanceFrom (b);
402 if (distance <= m_minDistance)
408 double txAntHeight = a->GetPosition ().z + m_heightAboveZ;
409 double rxAntHeight = b->GetPosition ().z + m_heightAboveZ;
418 double dCross = (4 * PI * txAntHeight * rxAntHeight) / m_lambda;
420 if (distance <= dCross)
423 double numerator = m_lambda * m_lambda;
425 double denominator = 16 * tmp * tmp * m_systemLoss;
426 double pr = 10 * std::log10 (numerator / denominator);
427 NS_LOG_DEBUG (
"Receiver within crossover (" << dCross <<
"m) for Two_ray path; using Friis");
428 NS_LOG_DEBUG (
"distance=" << distance <<
"m, attenuation coefficient=" << pr <<
"dB");
429 return txPowerDbm + pr;
433 tmp = txAntHeight * rxAntHeight;
434 double rayNumerator = tmp * tmp;
435 tmp = distance * distance;
436 double rayDenominator = tmp * tmp * m_systemLoss;
437 double rayPr = 10 * std::log10 (rayNumerator / rayDenominator);
438 NS_LOG_DEBUG (
"distance=" << distance <<
"m, attenuation coefficient=" << rayPr <<
"dB");
439 return txPowerDbm + rayPr;
455 LogDistancePropagationLossModel::GetTypeId (
void)
457 static TypeId tid =
TypeId (
"ns3::LogDistancePropagationLossModel")
459 .AddConstructor<LogDistancePropagationLossModel> ()
460 .AddAttribute (
"Exponent",
461 "The exponent of the Path Loss propagation model",
463 MakeDoubleAccessor (&LogDistancePropagationLossModel::m_exponent),
464 MakeDoubleChecker<double> ())
465 .AddAttribute (
"ReferenceDistance",
466 "The distance at which the reference loss is calculated (m)",
468 MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceDistance),
469 MakeDoubleChecker<double> ())
470 .AddAttribute (
"ReferenceLoss",
471 "The reference loss at reference distance (dB). (Default is Friis at 1m with 5.15 GHz)",
473 MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceLoss),
474 MakeDoubleChecker<double> ())
480 LogDistancePropagationLossModel::LogDistancePropagationLossModel ()
490 LogDistancePropagationLossModel::SetReference (
double referenceDistance,
double referenceLoss)
492 m_referenceDistance = referenceDistance;
493 m_referenceLoss = referenceLoss;
507 if (distance <= m_referenceDistance)
525 double pathLossDb = 10 * m_exponent * std::log10 (distance / m_referenceDistance);
526 double rxc = -m_referenceLoss - pathLossDb;
527 NS_LOG_DEBUG (
"distance="<<distance<<
"m, reference-attenuation="<< -m_referenceLoss<<
"dB, "<<
528 "attenuation coefficient="<<rxc<<
"db");
529 return txPowerDbm + rxc;
543 ThreeLogDistancePropagationLossModel::GetTypeId (
void)
545 static TypeId tid =
TypeId (
"ns3::ThreeLogDistancePropagationLossModel")
547 .AddConstructor<ThreeLogDistancePropagationLossModel> ()
548 .AddAttribute (
"Distance0",
549 "Beginning of the first (near) distance field",
551 MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance0),
552 MakeDoubleChecker<double> ())
553 .AddAttribute (
"Distance1",
554 "Beginning of the second (middle) distance field.",
556 MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance1),
557 MakeDoubleChecker<double> ())
558 .AddAttribute (
"Distance2",
559 "Beginning of the third (far) distance field.",
561 MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance2),
562 MakeDoubleChecker<double> ())
563 .AddAttribute (
"Exponent0",
564 "The exponent for the first field.",
566 MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent0),
567 MakeDoubleChecker<double> ())
568 .AddAttribute (
"Exponent1",
569 "The exponent for the second field.",
571 MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent1),
572 MakeDoubleChecker<double> ())
573 .AddAttribute (
"Exponent2",
574 "The exponent for the third field.",
576 MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent2),
577 MakeDoubleChecker<double> ())
578 .AddAttribute (
"ReferenceLoss",
579 "The reference loss at distance d0 (dB). (Default is Friis at 1m with 5.15 GHz)",
581 MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_referenceLoss),
582 MakeDoubleChecker<double> ())
588 ThreeLogDistancePropagationLossModel::ThreeLogDistancePropagationLossModel ()
593 ThreeLogDistancePropagationLossModel::DoCalcRxPower (
double txPowerDbm,
594 Ptr<MobilityModel> a,
595 Ptr<MobilityModel> b)
const
597 double distance = a->GetDistanceFrom (b);
604 if (distance < m_distance0)
608 else if (distance < m_distance1)
610 pathLossDb = m_referenceLoss
611 + 10 * m_exponent0 * std::log10 (distance / m_distance0);
613 else if (distance < m_distance2)
615 pathLossDb = m_referenceLoss
616 + 10 * m_exponent0 * std::log10 (m_distance1 / m_distance0)
617 + 10 * m_exponent1 * std::log10 (distance / m_distance1);
621 pathLossDb = m_referenceLoss
622 + 10 * m_exponent0 * std::log10 (m_distance1 / m_distance0)
623 + 10 * m_exponent1 * std::log10 (m_distance2 / m_distance1)
624 + 10 * m_exponent2 * std::log10 (distance / m_distance2);
627 NS_LOG_DEBUG (
"ThreeLogDistance distance=" << distance <<
"m, " <<
628 "attenuation=" << pathLossDb <<
"dB");
630 return txPowerDbm - pathLossDb;
644 NakagamiPropagationLossModel::GetTypeId (
void)
646 static TypeId tid =
TypeId (
"ns3::NakagamiPropagationLossModel")
648 .AddConstructor<NakagamiPropagationLossModel> ()
649 .AddAttribute (
"Distance1",
650 "Beginning of the second distance field. Default is 80m.",
652 MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance1),
653 MakeDoubleChecker<double> ())
654 .AddAttribute (
"Distance2",
655 "Beginning of the third distance field. Default is 200m.",
657 MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance2),
658 MakeDoubleChecker<double> ())
660 "m0 for distances smaller than Distance1. Default is 1.5.",
662 MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m0),
663 MakeDoubleChecker<double> ())
665 "m1 for distances smaller than Distance2. Default is 0.75.",
667 MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m1),
668 MakeDoubleChecker<double> ())
670 "m2 for distances greater than Distance2. Default is 0.75.",
672 MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m2),
673 MakeDoubleChecker<double> ())
674 .AddAttribute (
"ErlangRv",
675 "Access to the underlying ErlangRandomVariable",
677 MakePointerAccessor (&NakagamiPropagationLossModel::m_erlangRandomVariable),
678 MakePointerChecker<ErlangRandomVariable> ())
679 .AddAttribute (
"GammaRv",
680 "Access to the underlying GammaRandomVariable",
682 MakePointerAccessor (&NakagamiPropagationLossModel::m_gammaRandomVariable),
683 MakePointerChecker<GammaRandomVariable> ());
689 NakagamiPropagationLossModel::NakagamiPropagationLossModel ()
694 NakagamiPropagationLossModel::DoCalcRxPower (
double txPowerDbm,
695 Ptr<MobilityModel> a,
696 Ptr<MobilityModel> b)
const
700 double distance = a->GetDistanceFrom (b);
704 if (distance < m_distance1)
708 else if (distance < m_distance2)
719 double powerW = std::pow (10, (txPowerDbm - 30) / 10);
725 unsigned int int_m =
static_cast<unsigned int>(std::floor (m));
729 resultPowerW = m_erlangRandomVariable->GetValue (int_m, powerW / m);
733 resultPowerW = m_gammaRandomVariable->GetValue (m, powerW / m);
736 double resultPowerDbm = 10 * std::log10 (resultPowerW) + 30;
738 NS_LOG_DEBUG (
"Nakagami distance=" << distance <<
"m, " <<
739 "power=" << powerW <<
"W, " <<
740 "resultPower=" << resultPowerW <<
"W=" << resultPowerDbm <<
"dBm");
742 return resultPowerDbm;
748 m_erlangRandomVariable->SetStream (stream);
749 m_gammaRandomVariable->SetStream (stream + 1);
758 FixedRssLossModel::GetTypeId (
void)
762 .AddConstructor<FixedRssLossModel> ()
763 .AddAttribute (
"Rss",
"The fixed receiver Rss.",
765 MakeDoubleAccessor (&FixedRssLossModel::m_rss),
766 MakeDoubleChecker<double> ())
770 FixedRssLossModel::FixedRssLossModel ()
771 : PropagationLossModel ()
775 FixedRssLossModel::~FixedRssLossModel ()
786 FixedRssLossModel::DoCalcRxPower (
double txPowerDbm,
804 MatrixPropagationLossModel::GetTypeId (
void)
806 static TypeId tid =
TypeId (
"ns3::MatrixPropagationLossModel")
808 .AddConstructor<MatrixPropagationLossModel> ()
809 .AddAttribute (
"DefaultLoss",
"The default value for propagation loss, dB.",
812 MakeDoubleChecker<double> ())
817 MatrixPropagationLossModel::MatrixPropagationLossModel ()
818 : PropagationLossModel (), m_default (std::numeric_limits<double>::max ())
822 MatrixPropagationLossModel::~MatrixPropagationLossModel ()
837 MobilityPair p = std::make_pair (ma, mb);
838 std::map<MobilityPair, double>::iterator i =
m_loss.find (p);
842 m_loss.insert (std::make_pair (p, loss));
856 MatrixPropagationLossModel::DoCalcRxPower (
double txPowerDbm,
860 std::map<MobilityPair, double>::const_iterator i =
m_loss.find (std::make_pair (a, b));
864 return txPowerDbm - i->second;
883 RangePropagationLossModel::GetTypeId (
void)
885 static TypeId tid =
TypeId (
"ns3::RangePropagationLossModel")
887 .AddConstructor<RangePropagationLossModel> ()
888 .AddAttribute (
"MaxRange",
889 "Maximum Transmission Range (meters)",
891 MakeDoubleAccessor (&RangePropagationLossModel::m_range),
892 MakeDoubleChecker<double> ())
897 RangePropagationLossModel::RangePropagationLossModel ()
902 RangePropagationLossModel::DoCalcRxPower (
double txPowerDbm,
903 Ptr<MobilityModel> a,
904 Ptr<MobilityModel> b)
const
906 double distance = a->GetDistanceFrom (b);
907 if (distance <= m_range)
void SetFrequency(double frequency)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
void SetDefaultLoss(double)
Set default loss (in dB, positive) to be used, infinity if not set.
double GetDistanceFrom(Ptr< const MobilityModel > position) const
void SetPathLossExponent(double n)
hold variables of type string
a Two-Ray Ground propagation loss model ported from NS2
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
double GetFrequency(void) const
double GetMinDistance(void) const
The propagation loss depends only on the distance (range) between transmitter and receiver...
double m_default
default loss
double GetPathLossExponent(void) const
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
virtual int64_t DoAssignStreams(int64_t stream)
virtual double GetValue(void)=0
Returns a random double from the underlying distribution.
A log distance path loss propagation model with three distance fields. This model is the same as ns3:...
void SetMinDistance(double minDistance)
virtual int64_t DoAssignStreams(int64_t stream)
The propagation loss follows a random distribution.
virtual int64_t DoAssignStreams(int64_t stream)
void SetMinDistance(double minDistance)
a Friis propagation loss model
virtual int64_t DoAssignStreams(int64_t stream)
Nakagami-m fast fading propagation loss model.
void SetSystemLoss(double systemLoss)
double GetMinDistance(void) const
double GetSystemLoss(void) const
Modelize the propagation loss through a transmission medium.
double GetSystemLoss(void) const
#define NS_LOG_DEBUG(msg)
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).
virtual int64_t DoAssignStreams(int64_t stream)
virtual int64_t DoAssignStreams(int64_t stream)
void SetFrequency(double frequency)
void SetHeightAboveZ(double heightAboveZ)
virtual int64_t DoAssignStreams(int64_t stream)
void SetSystemLoss(double systemLoss)
a log distance propagation model.
Hold an floating point type.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
The propagation loss is fixed for each pair of nodes and doesn't depend on their actual positions...
double GetFrequency(void) const
virtual int64_t DoAssignStreams(int64_t stream)
std::map< MobilityPair, double > m_loss
Fixed loss between pair of nodes.