25 #include "ns3/boolean.h"
26 #include "ns3/double.h"
28 #include "ns3/mobility-model.h"
29 #include "ns3/pointer.h"
30 #include "ns3/string.h"
88 int64_t currentStream = stream;
94 return (currentStream - stream);
105 TypeId(
"ns3::RandomPropagationLossModel")
107 .SetGroupName(
"Propagation")
111 "The random variable used to pick a loss every time CalcRxPower is invoked.",
112 StringValue(
"ns3::ConstantRandomVariable[Constant=1.0]"),
114 MakePointerChecker<RandomVariableStream>());
133 NS_LOG_DEBUG(
"attenuation coefficient=" << rxc <<
"Db");
134 return txPowerDbm + rxc;
152 TypeId(
"ns3::FriisPropagationLossModel")
154 .SetGroupName(
"Propagation")
158 "The carrier frequency (in Hz) at which propagation occurs (default is 5.15 GHz).",
162 MakeDoubleChecker<double>())
163 .AddAttribute(
"SystemLoss",
167 MakeDoubleChecker<double>())
168 .AddAttribute(
"MinLoss",
169 "The minimum value (dB) of the total loss, used at short ranges.",
173 MakeDoubleChecker<double>());
209 static const double C = 299792458.0;
222 double mw = std::pow(10.0, dbm / 10.0);
229 double dbm = std::log10(w * 1000.0) * 10.0;
271 "distance not within the far field region => inaccurate propagation loss value");
278 double denominator = 16 * M_PI * M_PI * distance * distance *
m_systemLoss;
279 double lossDb = -10 * log10(numerator / denominator);
280 NS_LOG_DEBUG(
"distance=" << distance <<
"m, loss=" << lossDb <<
"dB");
299 TypeId(
"ns3::TwoRayGroundPropagationLossModel")
301 .SetGroupName(
"Propagation")
305 "The carrier frequency (in Hz) at which propagation occurs (default is 5.15 GHz).",
309 MakeDoubleChecker<double>())
310 .AddAttribute(
"SystemLoss",
314 MakeDoubleChecker<double>())
317 "The distance under which the propagation model refuses to give results (m)",
321 MakeDoubleChecker<double>())
322 .AddAttribute(
"HeightAboveZ",
323 "The height of the antenna (m) above the node's Z coordinate",
326 MakeDoubleChecker<double>());
368 static const double C = 299792458.0;
381 double mw = std::pow(10.0, dbm / 10.0);
388 double dbm = std::log10(w * 1000.0) * 10.0;
440 double dCross = (4 * M_PI * txAntHeight * rxAntHeight) /
m_lambda;
442 if (distance <= dCross)
446 tmp = M_PI * distance;
448 double pr = 10 * std::log10(numerator / denominator);
449 NS_LOG_DEBUG(
"Receiver within crossover (" << dCross <<
"m) for Two_ray path; using Friis");
450 NS_LOG_DEBUG(
"distance=" << distance <<
"m, attenuation coefficient=" << pr <<
"dB");
451 return txPowerDbm + pr;
455 tmp = txAntHeight * rxAntHeight;
456 double rayNumerator = tmp * tmp;
457 tmp = distance * distance;
459 double rayPr = 10 * std::log10(rayNumerator / rayDenominator);
460 NS_LOG_DEBUG(
"distance=" << distance <<
"m, attenuation coefficient=" << rayPr <<
"dB");
461 return txPowerDbm + rayPr;
479 TypeId(
"ns3::LogDistancePropagationLossModel")
481 .SetGroupName(
"Propagation")
483 .AddAttribute(
"Exponent",
484 "The exponent of the Path Loss propagation model",
487 MakeDoubleChecker<double>())
488 .AddAttribute(
"ReferenceDistance",
489 "The distance at which the reference loss is calculated (m)",
492 MakeDoubleChecker<double>())
493 .AddAttribute(
"ReferenceLoss",
494 "The reference loss at reference distance (dB). (Default is Friis at 1m "
498 MakeDoubleChecker<double>());
553 <<
"attenuation coefficient=" << rxc <<
"db");
554 return txPowerDbm + rxc;
571 TypeId(
"ns3::ThreeLogDistancePropagationLossModel")
573 .SetGroupName(
"Propagation")
575 .AddAttribute(
"Distance0",
576 "Beginning of the first (near) distance field",
579 MakeDoubleChecker<double>())
580 .AddAttribute(
"Distance1",
581 "Beginning of the second (middle) distance field.",
584 MakeDoubleChecker<double>())
585 .AddAttribute(
"Distance2",
586 "Beginning of the third (far) distance field.",
589 MakeDoubleChecker<double>())
590 .AddAttribute(
"Exponent0",
591 "The exponent for the first field.",
594 MakeDoubleChecker<double>())
595 .AddAttribute(
"Exponent1",
596 "The exponent for the second field.",
599 MakeDoubleChecker<double>())
600 .AddAttribute(
"Exponent2",
601 "The exponent for the third field.",
604 MakeDoubleChecker<double>())
607 "The reference loss at distance d0 (dB). (Default is Friis at 1m with 5.15 GHz)",
610 MakeDoubleChecker<double>());
650 NS_LOG_DEBUG(
"ThreeLogDistance distance=" << distance <<
"m, "
651 <<
"attenuation=" << pathLossDb <<
"dB");
653 return txPowerDbm - pathLossDb;
670 TypeId(
"ns3::NakagamiPropagationLossModel")
672 .SetGroupName(
"Propagation")
674 .AddAttribute(
"Distance1",
675 "Beginning of the second distance field. Default is 80m.",
678 MakeDoubleChecker<double>())
679 .AddAttribute(
"Distance2",
680 "Beginning of the third distance field. Default is 200m.",
683 MakeDoubleChecker<double>())
685 "m0 for distances smaller than Distance1. Default is 1.5.",
688 MakeDoubleChecker<double>())
690 "m1 for distances smaller than Distance2. Default is 0.75.",
693 MakeDoubleChecker<double>())
695 "m2 for distances greater than Distance2. Default is 0.75.",
698 MakeDoubleChecker<double>())
701 "Access to the underlying ErlangRandomVariable",
704 MakePointerChecker<ErlangRandomVariable>())
705 .AddAttribute(
"GammaRv",
706 "Access to the underlying GammaRandomVariable",
709 MakePointerChecker<GammaRandomVariable>());
744 double powerW = std::pow(10, (txPowerDbm - 30) / 10);
750 auto int_m =
static_cast<unsigned int>(std::floor(
m));
761 double resultPowerDbm = 10 * std::log10(resultPowerW) + 30;
764 <<
"power=" << powerW <<
"W, "
765 <<
"resultPower=" << resultPowerW <<
"W=" << resultPowerDbm
768 return resultPowerDbm;
788 .SetGroupName(
"Propagation")
791 "The fixed receiver Rss.",
794 MakeDoubleChecker<double>());
835 TypeId(
"ns3::MatrixPropagationLossModel")
837 .SetGroupName(
"Propagation")
839 .AddAttribute(
"DefaultLoss",
840 "The default value for propagation loss, dB.",
843 MakeDoubleChecker<double>());
849 m_default(std::numeric_limits<double>::
max())
876 m_loss.insert(std::make_pair(p, loss));
894 auto i =
m_loss.find(std::make_pair(a, b));
898 return txPowerDbm - i->second;
919 static TypeId tid =
TypeId(
"ns3::RangePropagationLossModel")
921 .SetGroupName(
"Propagation")
923 .AddAttribute(
"MaxRange",
924 "Maximum Transmission Range (meters)",
927 MakeDoubleChecker<double>());
This class can be used to hold variables of floating point type such as 'double' or 'float'.
a Friis propagation loss model
double GetFrequency() const
double m_lambda
the carrier wavelength
double DbmFromW(double w) const
Transforms a Watt value to Dbm.
double m_frequency
the carrier frequency
int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
void SetSystemLoss(double systemLoss)
void SetFrequency(double frequency)
double DbmToW(double dbm) const
Transforms a Dbm value to Watt.
double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const override
PropagationLossModel.
double GetMinLoss() const
double GetSystemLoss() const
static TypeId GetTypeId()
Get the type ID.
FriisPropagationLossModel()
void SetMinLoss(double minLoss)
double m_systemLoss
the system loss
double m_minLoss
the minimum loss
a log distance propagation model.
double m_referenceDistance
reference distance
double GetPathLossExponent() const
void SetReference(double referenceDistance, double referenceLoss)
Set the reference path loss at a given distance.
double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const override
PropagationLossModel.
LogDistancePropagationLossModel()
static TypeId GetTypeId()
Get the type ID.
double m_exponent
model exponent
int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
double m_referenceLoss
reference loss
void SetPathLossExponent(double n)
The propagation loss is fixed for each pair of nodes and doesn't depend on their actual positions.
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).
void SetDefaultLoss(double defaultLoss)
Set the default propagation loss (in dB, positive) to be used, infinity if not set.
std::unordered_map< MobilityPair, double, MobilityPairHasher > m_loss
Propagation loss between pair of nodes.
MatrixPropagationLossModel()
int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
std::pair< const Ptr< MobilityModel >, const Ptr< MobilityModel > > MobilityPair
Typedef: Mobility models pair.
double m_default
default loss
~MatrixPropagationLossModel() override
double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const override
PropagationLossModel.
static TypeId GetTypeId()
Get the type ID.
double GetDistanceFrom(Ptr< const MobilityModel > position) const
Vector GetPosition() const
Nakagami-m fast fading propagation loss model.
Ptr< ErlangRandomVariable > m_erlangRandomVariable
Erlang random variable.
double m_m0
m for distances smaller than Distance1
Ptr< GammaRandomVariable > m_gammaRandomVariable
Gamma random variable.
double m_distance1
Distance1.
int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
double m_distance2
Distance2.
NakagamiPropagationLossModel()
double m_m1
m for distances smaller than Distance2
double m_m2
m for distances greater than Distance2
double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const override
PropagationLossModel.
static TypeId GetTypeId()
Get the type ID.
A base class which provides memory management and object aggregation.
Models the propagation loss through a transmission medium.
virtual int64_t DoAssignStreams(int64_t stream)=0
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< PropagationLossModel > m_next
Next propagation loss model in the list.
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account all the PropagationLossModel(s) chained to the current one.
static TypeId GetTypeId()
Get the type ID.
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const =0
PropagationLossModel.
int64_t AssignStreams(int64_t stream)
If this loss model uses objects of type RandomVariableStream, set the stream numbers to the integers ...
~PropagationLossModel() override
void SetNext(Ptr< PropagationLossModel > next)
Enables a chain of loss models to act on the signal.
Ptr< PropagationLossModel > GetNext()
Gets the next PropagationLossModel in the chain of loss models that act on the signal.
The propagation loss follows a random distribution.
RandomPropagationLossModel()
static TypeId GetTypeId()
Get the type ID.
double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const override
PropagationLossModel.
~RandomPropagationLossModel() override
Ptr< RandomVariableStream > m_variable
random generator
int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
virtual double GetValue()=0
Get the next random value drawn from the distribution.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
The propagation loss depends only on the distance (range) between transmitter and receiver.
RangePropagationLossModel()
static TypeId GetTypeId()
Get the type ID.
int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const override
PropagationLossModel.
double m_range
Maximum Transmission Range (meters)
Hold variables of type string.
A log distance path loss propagation model with three distance fields.
double m_referenceLoss
The reference loss at distance d0 (dB).
int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
double m_distance0
Beginning of the first (near) distance field.
double m_distance2
Beginning of the third (far) distance field.
double m_exponent2
The exponent for the third field.
double m_distance1
Beginning of the second (middle) distance field.
static TypeId GetTypeId()
Get the type ID.
ThreeLogDistancePropagationLossModel()
double m_exponent0
The exponent for the first field.
double m_exponent1
The exponent for the second field.
double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const override
PropagationLossModel.
a Two-Ray Ground propagation loss model ported from NS2
double DbmToW(double dbm) const
Transforms a Dbm value to Watt.
double m_minDistance
minimum distance for the model
double GetMinDistance() const
double m_heightAboveZ
antenna height above the node's Z coordinate
TwoRayGroundPropagationLossModel()
static TypeId GetTypeId()
Get the type ID.
double DbmFromW(double w) const
Transforms a Watt value to Dbm.
void SetSystemLoss(double systemLoss)
void SetMinDistance(double minDistance)
double GetFrequency() const
double GetSystemLoss() const
void SetFrequency(double frequency)
int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
double m_systemLoss
the system loss
double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const override
PropagationLossModel.
double m_frequency
the carrier frequency
void SetHeightAboveZ(double heightAboveZ)
double m_lambda
the carrier wavelength
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#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.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)