14#include "ns3/boolean.h"
15#include "ns3/double.h"
17#include "ns3/mobility-model.h"
18#include "ns3/pointer.h"
19#include "ns3/string.h"
69 self =
m_next->CalcRxPower(self, a, b);
77 int64_t currentStream = stream;
81 currentStream +=
m_next->AssignStreams(currentStream);
83 return (currentStream - stream);
94 TypeId(
"ns3::RandomPropagationLossModel")
96 .SetGroupName(
"Propagation")
100 "The random variable used to pick a loss every time CalcRxPower is invoked.",
101 StringValue(
"ns3::ConstantRandomVariable[Constant=1.0]"),
122 NS_LOG_DEBUG(
"attenuation coefficient=" << rxc <<
"Db");
123 return txPowerDbm + rxc;
141 TypeId(
"ns3::FriisPropagationLossModel")
143 .SetGroupName(
"Propagation")
147 "The carrier frequency (in Hz) at which propagation occurs (default is 5.15 GHz).",
152 .AddAttribute(
"SystemLoss",
153 "The system loss (linear factor >= 1, not in dB)",
158 .AddAttribute(
"MinLoss",
159 "The minimum value (dB) of the total loss, used at short ranges.",
200 static const double C = 299792458.0;
213 double mw = std::pow(10.0, dbm / 10.0);
220 double dbm = std::log10(w * 1000.0) * 10.0;
258 double distance = a->GetDistanceFrom(b);
262 "distance not within the far field region => inaccurate propagation loss value");
269 double denominator = 16 * M_PI * M_PI * distance * distance *
m_systemLoss;
270 double lossDb = -10 * log10(numerator / denominator);
271 NS_LOG_DEBUG(
"distance=" << distance <<
"m, loss=" << lossDb <<
"dB");
272 return txPowerDbm - std::max(lossDb,
m_minLoss);
290 TypeId(
"ns3::TwoRayGroundPropagationLossModel")
292 .SetGroupName(
"Propagation")
296 "The carrier frequency (in Hz) at which propagation occurs (default is 5.15 GHz).",
301 .AddAttribute(
"SystemLoss",
302 "The system loss (linear factor >= 1, not in dB)",
309 "The distance under which the propagation model refuses to give results (m)",
314 .AddAttribute(
"HeightAboveZ",
315 "The height of the antenna (m) above the node's Z coordinate",
361 static const double C = 299792458.0;
374 double mw = std::pow(10.0, dbm / 10.0);
381 double dbm = std::log10(w * 1000.0) * 10.0;
416 double distance = a->GetDistanceFrom(b);
433 double dCross = (4 * M_PI * txAntHeight * rxAntHeight) /
m_lambda;
435 if (distance <= dCross)
439 tmp = M_PI * distance;
441 double pr = 10 * std::log10(numerator / denominator);
442 NS_LOG_DEBUG(
"Receiver within crossover (" << dCross <<
"m) for Two_ray path; using Friis");
443 NS_LOG_DEBUG(
"distance=" << distance <<
"m, attenuation coefficient=" << pr <<
"dB");
444 return txPowerDbm + pr;
448 tmp = txAntHeight * rxAntHeight;
449 double rayNumerator = tmp * tmp;
450 tmp = distance * distance;
452 double rayPr = 10 * std::log10(rayNumerator / rayDenominator);
453 NS_LOG_DEBUG(
"distance=" << distance <<
"m, attenuation coefficient=" << rayPr <<
"dB");
454 return txPowerDbm + rayPr;
472 TypeId(
"ns3::LogDistancePropagationLossModel")
474 .SetGroupName(
"Propagation")
476 .AddAttribute(
"Exponent",
477 "The exponent of the Path Loss propagation model",
481 .AddAttribute(
"ReferenceDistance",
482 "The distance at which the reference loss is calculated (m)",
486 .AddAttribute(
"ReferenceLoss",
487 "The reference loss at reference distance (dB). (Default is Friis at 1m "
523 double distance = a->GetDistanceFrom(b);
527 <<
"dB, no further attenuation");
548 <<
"attenuation coefficient=" << rxc <<
"db");
549 return txPowerDbm + rxc;
566 TypeId(
"ns3::ThreeLogDistancePropagationLossModel")
568 .SetGroupName(
"Propagation")
570 .AddAttribute(
"Distance0",
571 "Beginning of the first (near) distance field",
575 .AddAttribute(
"Distance1",
576 "Beginning of the second (middle) distance field.",
580 .AddAttribute(
"Distance2",
581 "Beginning of the third (far) distance field.",
585 .AddAttribute(
"Exponent0",
586 "The exponent for the first field.",
590 .AddAttribute(
"Exponent1",
591 "The exponent for the second field.",
595 .AddAttribute(
"Exponent2",
596 "The exponent for the third field.",
602 "The reference loss at distance d0 (dB). (Default is Friis at 1m with 5.15 GHz)",
618 double distance = a->GetDistanceFrom(b);
645 NS_LOG_DEBUG(
"ThreeLogDistance distance=" << distance <<
"m, "
646 <<
"attenuation=" << pathLossDb <<
"dB");
648 return txPowerDbm - pathLossDb;
665 TypeId(
"ns3::NakagamiPropagationLossModel")
667 .SetGroupName(
"Propagation")
669 .AddAttribute(
"Distance1",
670 "Beginning of the second distance field. Default is 80m.",
674 .AddAttribute(
"Distance2",
675 "Beginning of the third distance field. Default is 200m.",
680 "m0 for distances smaller than Distance1. Default is 1.5.",
685 "m1 for distances smaller than Distance2. Default is 0.75.",
690 "m2 for distances greater than Distance2. Default is 0.75.",
696 "Access to the underlying ErlangRandomVariable",
700 .AddAttribute(
"GammaRv",
701 "Access to the underlying GammaRandomVariable",
720 double distance = a->GetDistanceFrom(b);
739 double powerW = std::pow(10, (txPowerDbm - 30) / 10);
745 auto int_m =
static_cast<unsigned int>(std::floor(m));
756 double resultPowerDbm = 10 * std::log10(resultPowerW) + 30;
759 <<
"power=" << powerW <<
"W, "
760 <<
"resultPower=" << resultPowerW <<
"W=" << resultPowerDbm
763 return resultPowerDbm;
783 .SetGroupName(
"Propagation")
786 "The fixed receiver Rss.",
830 TypeId(
"ns3::MatrixPropagationLossModel")
832 .SetGroupName(
"Propagation")
834 .AddAttribute(
"DefaultLoss",
835 "The default value for propagation loss, dB.",
844 m_default(
std::numeric_limits<
double>::max())
871 m_loss.insert(std::make_pair(p, loss));
889 auto i =
m_loss.find(std::make_pair(a, b));
893 return txPowerDbm - i->second;
914 static TypeId tid =
TypeId(
"ns3::RangePropagationLossModel")
916 .SetGroupName(
"Propagation")
918 .AddAttribute(
"MaxRange",
919 "Maximum Transmission Range (meters)",
935 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 > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
#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.
Ptr< const AttributeChecker > MakeDoubleChecker()
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)