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"
87 int64_t currentStream = stream;
93 return (currentStream - stream);
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]"),
109 MakePointerChecker<RandomVariableStream> ())
129 return txPowerDbm + rxc;
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",
160 MakeDoubleChecker<double> ())
161 .AddAttribute (
"MinLoss",
162 "The minimum value (dB) of the total loss, used at short ranges. Note: ",
166 MakeDoubleChecker<double> ())
199 static const double C = 299792458.0;
212 double mw = std::pow (10.0,dbm/10.0);
219 double dbm = std::log10 (w * 1000.0) * 10.0;
260 NS_LOG_WARN (
"distance not within the far field region => inaccurate propagation loss value");
268 double lossDb = -10 * log10 (numerator / denominator);
269 NS_LOG_DEBUG (
"distance=" << distance<<
"m, loss=" << lossDb <<
"dB");
270 return txPowerDbm - std::max (lossDb,
m_minLoss);
289 static TypeId tid =
TypeId (
"ns3::TwoRayGroundPropagationLossModel")
291 .AddConstructor<TwoRayGroundPropagationLossModel> ()
292 .AddAttribute (
"Frequency",
293 "The carrier frequency (in Hz) at which propagation occurs (default is 5.15 GHz).",
297 MakeDoubleChecker<double> ())
298 .AddAttribute (
"SystemLoss",
"The system loss",
301 MakeDoubleChecker<double> ())
302 .AddAttribute (
"MinDistance",
303 "The distance under which the propagation model refuses to give results (m)",
307 MakeDoubleChecker<double> ())
308 .AddAttribute (
"HeightAboveZ",
309 "The height of the antenna (m) above the node's Z coordinate",
312 MakeDoubleChecker<double> ())
350 static const double C = 299792458.0;
363 double mw = std::pow (10.0,dbm / 10.0);
370 double dbm = std::log10 (w * 1000.0) * 10.0;
422 double dCross = (4 *
PI * txAntHeight * rxAntHeight) /
m_lambda;
424 if (distance <= dCross)
430 double pr = 10 * std::log10 (numerator / denominator);
431 NS_LOG_DEBUG (
"Receiver within crossover (" << dCross <<
"m) for Two_ray path; using Friis");
432 NS_LOG_DEBUG (
"distance=" << distance <<
"m, attenuation coefficient=" << pr <<
"dB");
433 return txPowerDbm + pr;
437 tmp = txAntHeight * rxAntHeight;
438 double rayNumerator = tmp * tmp;
439 tmp = distance * distance;
441 double rayPr = 10 * std::log10 (rayNumerator / rayDenominator);
442 NS_LOG_DEBUG (
"distance=" << distance <<
"m, attenuation coefficient=" << rayPr <<
"dB");
443 return txPowerDbm + rayPr;
461 static TypeId tid =
TypeId (
"ns3::LogDistancePropagationLossModel")
463 .AddConstructor<LogDistancePropagationLossModel> ()
464 .AddAttribute (
"Exponent",
465 "The exponent of the Path Loss propagation model",
468 MakeDoubleChecker<double> ())
469 .AddAttribute (
"ReferenceDistance",
470 "The distance at which the reference loss is calculated (m)",
473 MakeDoubleChecker<double> ())
474 .AddAttribute (
"ReferenceLoss",
475 "The reference loss at reference distance (dB). (Default is Friis at 1m with 5.15 GHz)",
478 MakeDoubleChecker<double> ())
532 "attenuation coefficient="<<rxc<<
"db");
533 return txPowerDbm + rxc;
549 static TypeId tid =
TypeId (
"ns3::ThreeLogDistancePropagationLossModel")
551 .AddConstructor<ThreeLogDistancePropagationLossModel> ()
552 .AddAttribute (
"Distance0",
553 "Beginning of the first (near) distance field",
556 MakeDoubleChecker<double> ())
557 .AddAttribute (
"Distance1",
558 "Beginning of the second (middle) distance field.",
561 MakeDoubleChecker<double> ())
562 .AddAttribute (
"Distance2",
563 "Beginning of the third (far) distance field.",
566 MakeDoubleChecker<double> ())
567 .AddAttribute (
"Exponent0",
568 "The exponent for the first field.",
571 MakeDoubleChecker<double> ())
572 .AddAttribute (
"Exponent1",
573 "The exponent for the second field.",
576 MakeDoubleChecker<double> ())
577 .AddAttribute (
"Exponent2",
578 "The exponent for the third field.",
581 MakeDoubleChecker<double> ())
582 .AddAttribute (
"ReferenceLoss",
583 "The reference loss at distance d0 (dB). (Default is Friis at 1m with 5.15 GHz)",
586 MakeDoubleChecker<double> ())
631 NS_LOG_DEBUG (
"ThreeLogDistance distance=" << distance <<
"m, " <<
632 "attenuation=" << pathLossDb <<
"dB");
634 return txPowerDbm - pathLossDb;
650 static TypeId tid =
TypeId (
"ns3::NakagamiPropagationLossModel")
652 .AddConstructor<NakagamiPropagationLossModel> ()
653 .AddAttribute (
"Distance1",
654 "Beginning of the second distance field. Default is 80m.",
657 MakeDoubleChecker<double> ())
658 .AddAttribute (
"Distance2",
659 "Beginning of the third distance field. Default is 200m.",
662 MakeDoubleChecker<double> ())
664 "m0 for distances smaller than Distance1. Default is 1.5.",
667 MakeDoubleChecker<double> ())
669 "m1 for distances smaller than Distance2. Default is 0.75.",
672 MakeDoubleChecker<double> ())
674 "m2 for distances greater than Distance2. Default is 0.75.",
677 MakeDoubleChecker<double> ())
678 .AddAttribute (
"ErlangRv",
679 "Access to the underlying ErlangRandomVariable",
682 MakePointerChecker<ErlangRandomVariable> ())
683 .AddAttribute (
"GammaRv",
684 "Access to the underlying GammaRandomVariable",
687 MakePointerChecker<GammaRandomVariable> ());
723 double powerW = std::pow (10, (txPowerDbm - 30) / 10);
729 unsigned int int_m =
static_cast<unsigned int>(std::floor (m));
740 double resultPowerDbm = 10 * std::log10 (resultPowerW) + 30;
742 NS_LOG_DEBUG (
"Nakagami distance=" << distance <<
"m, " <<
743 "power=" << powerW <<
"W, " <<
744 "resultPower=" << resultPowerW <<
"W=" << resultPowerDbm <<
"dBm");
746 return resultPowerDbm;
766 .AddConstructor<FixedRssLossModel> ()
767 .AddAttribute (
"Rss",
"The fixed receiver Rss.",
770 MakeDoubleChecker<double> ())
810 static TypeId tid =
TypeId (
"ns3::MatrixPropagationLossModel")
812 .AddConstructor<MatrixPropagationLossModel> ()
813 .AddAttribute (
"DefaultLoss",
"The default value for propagation loss, dB.",
816 MakeDoubleChecker<double> ())
842 std::map<MobilityPair, double>::iterator i =
m_loss.find (p);
846 m_loss.insert (std::make_pair (p, loss));
864 std::map<MobilityPair, double>::const_iterator i =
m_loss.find (std::make_pair (a, b));
868 return txPowerDbm - i->second;
889 static TypeId tid =
TypeId (
"ns3::RangePropagationLossModel")
891 .AddConstructor<RangePropagationLossModel> ()
892 .AddAttribute (
"MaxRange",
893 "Maximum Transmission Range (meters)",
896 MakeDoubleChecker<double> ())
void SetFrequency(double frequency)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
void SetDefaultLoss(double)
Set default loss (in dB, positive) to be used, infinity if not set.
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
double GetDistanceFrom(Ptr< const MobilityModel > position) const
void SetPathLossExponent(double n)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
void SetNext(Ptr< PropagationLossModel > next)
Enables a chain of loss models to act on the signal.
hold variables of type string
a Two-Ray Ground propagation loss model ported from NS2
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
double GetFrequency(void) const
Vector GetPosition(void) const
void SetMinLoss(double minLoss)
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) 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
Ptr< RandomVariableStream > m_variable
static TypeId GetTypeId(void)
static TypeId GetTypeId(void)
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
RandomPropagationLossModel()
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero. ...
virtual double GetValue(void)=0
Returns a random double from the underlying distribution.
A log distance path loss propagation model with three distance fields.
static TypeId GetTypeId(void)
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero. ...
Ptr< PropagationLossModel > GetNext()
Gets the next PropagationLossModel in the chain of loss models that act on the signal.
double DbmToW(double dbm) const
static TypeId GetTypeId(void)
virtual ~RandomPropagationLossModel()
static TypeId GetTypeId(void)
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const =0
static TypeId GetTypeId(void)
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
The propagation loss follows a random distribution.
ThreeLogDistancePropagationLossModel()
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero. ...
void SetMinDistance(double minDistance)
LogDistancePropagationLossModel()
a Friis propagation loss model
Ptr< GammaRandomVariable > m_gammaRandomVariable
virtual ~PropagationLossModel()
FriisPropagationLossModel()
NakagamiPropagationLossModel()
Ptr< PropagationLossModel > m_next
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero. ...
Nakagami-m fast fading propagation loss model.
Ptr< ErlangRandomVariable > m_erlangRandomVariable
void SetSystemLoss(double systemLoss)
virtual ~MatrixPropagationLossModel()
double m_referenceDistance
double GetSystemLoss(void) const
Modelize the propagation loss through a transmission medium.
static TypeId GetTypeId(void)
double GetSystemLoss(void) const
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
static TypeId GetTypeId(void)
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
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)
Subclasses must implement this; those not using random variables can return zero. ...
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero. ...
double DbmToW(double dbm) const
void SetFrequency(double frequency)
void SetHeightAboveZ(double heightAboveZ)
RangePropagationLossModel()
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero. ...
void SetReference(double referenceDistance, double referenceLoss)
a base class which provides memory management and object aggregation
std::pair< Ptr< MobilityModel >, Ptr< MobilityModel > > MobilityPair
static TypeId GetTypeId(void)
void SetSystemLoss(double systemLoss)
double GetMinLoss(void) const
a log distance propagation model.
Hold a floating point type.
MatrixPropagationLossModel()
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...
TwoRayGroundPropagationLossModel()
int64_t AssignStreams(int64_t stream)
If this loss model uses objects of type RandomVariableStream, set the stream numbers to the integers ...
double GetFrequency(void) const
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero. ...
double DbmFromW(double w) const
double DbmFromW(double w) const
std::map< MobilityPair, double > m_loss
Fixed loss between pair of nodes.
double z
z coordinate of vector
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
virtual int64_t DoAssignStreams(int64_t stream)=0
Subclasses must implement this; those not using random variables can return zero. ...