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",
164 "The system loss (linear factor >= 1, not in dB)",
168 MakeDoubleChecker<double>())
169 .AddAttribute(
"MinLoss",
170 "The minimum value (dB) of the total loss, used at short ranges.",
174 MakeDoubleChecker<double>());
211 static const double C = 299792458.0;
224 double mw = std::pow(10.0, dbm / 10.0);
231 double dbm = std::log10(w * 1000.0) * 10.0;
269 double distance = a->GetDistanceFrom(b);
273 "distance not within the far field region => inaccurate propagation loss value");
280 double denominator = 16 * M_PI * M_PI * distance * distance *
m_systemLoss;
281 double lossDb = -10 * log10(numerator / denominator);
282 NS_LOG_DEBUG(
"distance=" << distance <<
"m, loss=" << lossDb <<
"dB");
283 return txPowerDbm - std::max(lossDb,
m_minLoss);
301 TypeId(
"ns3::TwoRayGroundPropagationLossModel")
303 .SetGroupName(
"Propagation")
307 "The carrier frequency (in Hz) at which propagation occurs (default is 5.15 GHz).",
311 MakeDoubleChecker<double>())
312 .AddAttribute(
"SystemLoss",
313 "The system loss (linear factor >= 1, not in dB)",
317 MakeDoubleChecker<double>())
320 "The distance under which the propagation model refuses to give results (m)",
324 MakeDoubleChecker<double>())
325 .AddAttribute(
"HeightAboveZ",
326 "The height of the antenna (m) above the node's Z coordinate",
329 MakeDoubleChecker<double>());
372 static const double C = 299792458.0;
385 double mw = std::pow(10.0, dbm / 10.0);
392 double dbm = std::log10(w * 1000.0) * 10.0;
427 double distance = a->GetDistanceFrom(b);
444 double dCross = (4 * M_PI * txAntHeight * rxAntHeight) /
m_lambda;
446 if (distance <= dCross)
450 tmp = M_PI * distance;
452 double pr = 10 * std::log10(numerator / denominator);
453 NS_LOG_DEBUG(
"Receiver within crossover (" << dCross <<
"m) for Two_ray path; using Friis");
454 NS_LOG_DEBUG(
"distance=" << distance <<
"m, attenuation coefficient=" << pr <<
"dB");
455 return txPowerDbm + pr;
459 tmp = txAntHeight * rxAntHeight;
460 double rayNumerator = tmp * tmp;
461 tmp = distance * distance;
463 double rayPr = 10 * std::log10(rayNumerator / rayDenominator);
464 NS_LOG_DEBUG(
"distance=" << distance <<
"m, attenuation coefficient=" << rayPr <<
"dB");
465 return txPowerDbm + rayPr;
483 TypeId(
"ns3::LogDistancePropagationLossModel")
485 .SetGroupName(
"Propagation")
487 .AddAttribute(
"Exponent",
488 "The exponent of the Path Loss propagation model",
491 MakeDoubleChecker<double>())
492 .AddAttribute(
"ReferenceDistance",
493 "The distance at which the reference loss is calculated (m)",
496 MakeDoubleChecker<double>())
497 .AddAttribute(
"ReferenceLoss",
498 "The reference loss at reference distance (dB). (Default is Friis at 1m "
502 MakeDoubleChecker<double>());
534 double distance = a->GetDistanceFrom(b);
538 <<
"dB, no further attenuation");
559 <<
"attenuation coefficient=" << rxc <<
"db");
560 return txPowerDbm + rxc;
577 TypeId(
"ns3::ThreeLogDistancePropagationLossModel")
579 .SetGroupName(
"Propagation")
581 .AddAttribute(
"Distance0",
582 "Beginning of the first (near) distance field",
585 MakeDoubleChecker<double>())
586 .AddAttribute(
"Distance1",
587 "Beginning of the second (middle) distance field.",
590 MakeDoubleChecker<double>())
591 .AddAttribute(
"Distance2",
592 "Beginning of the third (far) distance field.",
595 MakeDoubleChecker<double>())
596 .AddAttribute(
"Exponent0",
597 "The exponent for the first field.",
600 MakeDoubleChecker<double>())
601 .AddAttribute(
"Exponent1",
602 "The exponent for the second field.",
605 MakeDoubleChecker<double>())
606 .AddAttribute(
"Exponent2",
607 "The exponent for the third field.",
610 MakeDoubleChecker<double>())
613 "The reference loss at distance d0 (dB). (Default is Friis at 1m with 5.15 GHz)",
616 MakeDoubleChecker<double>());
629 double distance = a->GetDistanceFrom(b);
656 NS_LOG_DEBUG(
"ThreeLogDistance distance=" << distance <<
"m, "
657 <<
"attenuation=" << pathLossDb <<
"dB");
659 return txPowerDbm - pathLossDb;
676 TypeId(
"ns3::NakagamiPropagationLossModel")
678 .SetGroupName(
"Propagation")
680 .AddAttribute(
"Distance1",
681 "Beginning of the second distance field. Default is 80m.",
684 MakeDoubleChecker<double>())
685 .AddAttribute(
"Distance2",
686 "Beginning of the third distance field. Default is 200m.",
689 MakeDoubleChecker<double>())
691 "m0 for distances smaller than Distance1. Default is 1.5.",
694 MakeDoubleChecker<double>())
696 "m1 for distances smaller than Distance2. Default is 0.75.",
699 MakeDoubleChecker<double>())
701 "m2 for distances greater than Distance2. Default is 0.75.",
704 MakeDoubleChecker<double>())
707 "Access to the underlying ErlangRandomVariable",
710 MakePointerChecker<ErlangRandomVariable>())
711 .AddAttribute(
"GammaRv",
712 "Access to the underlying GammaRandomVariable",
715 MakePointerChecker<GammaRandomVariable>());
731 double distance = a->GetDistanceFrom(b);
750 double powerW = std::pow(10, (txPowerDbm - 30) / 10);
756 auto int_m =
static_cast<unsigned int>(std::floor(m));
767 double resultPowerDbm = 10 * std::log10(resultPowerW) + 30;
770 <<
"power=" << powerW <<
"W, "
771 <<
"resultPower=" << resultPowerW <<
"W=" << resultPowerDbm
774 return resultPowerDbm;
794 .SetGroupName(
"Propagation")
797 "The fixed receiver Rss.",
800 MakeDoubleChecker<double>());
841 TypeId(
"ns3::MatrixPropagationLossModel")
843 .SetGroupName(
"Propagation")
845 .AddAttribute(
"DefaultLoss",
846 "The default value for propagation loss, dB.",
849 MakeDoubleChecker<double>());
855 m_default(
std::numeric_limits<
double>::max())
882 m_loss.insert(std::make_pair(p, loss));
900 auto i =
m_loss.find(std::make_pair(a, b));
904 return txPowerDbm - i->second;
925 static TypeId tid =
TypeId(
"ns3::RangePropagationLossModel")
927 .SetGroupName(
"Propagation")
929 .AddAttribute(
"MaxRange",
930 "Maximum Transmission Range (meters)",
933 MakeDoubleChecker<double>());
946 double distance = a->GetDistanceFrom(b);
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 (linear factor)
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.
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.
Smart pointer class similar to boost::intrusive_ptr.
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 (linear factor)
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,...
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
#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.