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;
146 static TypeId tid =
TypeId (
"ns3::FriisPropagationLossModel")
148 .SetGroupName (
"Propagation")
150 .AddAttribute (
"Frequency",
151 "The carrier frequency (in Hz) at which propagation occurs (default is 5.15 GHz).",
155 MakeDoubleChecker<double> ())
156 .AddAttribute (
"SystemLoss",
"The system loss",
159 MakeDoubleChecker<double> ())
160 .AddAttribute (
"MinLoss",
161 "The minimum value (dB) of the total loss, used at short ranges. Note: ",
165 MakeDoubleChecker<double> ())
198 static const double C = 299792458.0;
211 double mw = std::pow (10.0,dbm/10.0);
218 double dbm = std::log10 (w * 1000.0) * 10.0;
259 NS_LOG_WARN (
"distance not within the far field region => inaccurate propagation loss value");
266 double denominator = 16 * M_PI * M_PI * distance * distance *
m_systemLoss;
267 double lossDb = -10 * log10 (numerator / denominator);
268 NS_LOG_DEBUG (
"distance=" << distance<<
"m, loss=" << lossDb <<
"dB");
286 static TypeId tid =
TypeId (
"ns3::TwoRayGroundPropagationLossModel")
288 .AddConstructor<TwoRayGroundPropagationLossModel> ()
289 .AddAttribute (
"Frequency",
290 "The carrier frequency (in Hz) at which propagation occurs (default is 5.15 GHz).",
294 MakeDoubleChecker<double> ())
295 .AddAttribute (
"SystemLoss",
"The system loss",
298 MakeDoubleChecker<double> ())
299 .AddAttribute (
"MinDistance",
300 "The distance under which the propagation model refuses to give results (m)",
304 MakeDoubleChecker<double> ())
305 .AddAttribute (
"HeightAboveZ",
306 "The height of the antenna (m) above the node's Z coordinate",
309 MakeDoubleChecker<double> ())
347 static const double C = 299792458.0;
360 double mw = std::pow (10.0,dbm / 10.0);
367 double dbm = std::log10 (w * 1000.0) * 10.0;
419 double dCross = (4 * M_PI * txAntHeight * rxAntHeight) /
m_lambda;
421 if (distance <= dCross)
425 tmp = M_PI * distance;
427 double pr = 10 * std::log10 (numerator / denominator);
428 NS_LOG_DEBUG (
"Receiver within crossover (" << dCross <<
"m) for Two_ray path; using Friis");
429 NS_LOG_DEBUG (
"distance=" << distance <<
"m, attenuation coefficient=" << pr <<
"dB");
430 return txPowerDbm + pr;
434 tmp = txAntHeight * rxAntHeight;
435 double rayNumerator = tmp * tmp;
436 tmp = distance * distance;
438 double rayPr = 10 * std::log10 (rayNumerator / rayDenominator);
439 NS_LOG_DEBUG (
"distance=" << distance <<
"m, attenuation coefficient=" << rayPr <<
"dB");
440 return txPowerDbm + rayPr;
458 static TypeId tid =
TypeId (
"ns3::LogDistancePropagationLossModel")
460 .SetGroupName (
"Propagation")
462 .AddAttribute (
"Exponent",
463 "The exponent of the Path Loss propagation model",
466 MakeDoubleChecker<double> ())
467 .AddAttribute (
"ReferenceDistance",
468 "The distance at which the reference loss is calculated (m)",
471 MakeDoubleChecker<double> ())
472 .AddAttribute (
"ReferenceLoss",
473 "The reference loss at reference distance (dB). (Default is Friis at 1m with 5.15 GHz)",
476 MakeDoubleChecker<double> ())
530 "attenuation coefficient="<<rxc<<
"db");
531 return txPowerDbm + rxc;
547 static TypeId tid =
TypeId (
"ns3::ThreeLogDistancePropagationLossModel")
549 .AddConstructor<ThreeLogDistancePropagationLossModel> ()
550 .AddAttribute (
"Distance0",
551 "Beginning of the first (near) distance field",
554 MakeDoubleChecker<double> ())
555 .AddAttribute (
"Distance1",
556 "Beginning of the second (middle) distance field.",
559 MakeDoubleChecker<double> ())
560 .AddAttribute (
"Distance2",
561 "Beginning of the third (far) distance field.",
564 MakeDoubleChecker<double> ())
565 .AddAttribute (
"Exponent0",
566 "The exponent for the first field.",
569 MakeDoubleChecker<double> ())
570 .AddAttribute (
"Exponent1",
571 "The exponent for the second field.",
574 MakeDoubleChecker<double> ())
575 .AddAttribute (
"Exponent2",
576 "The exponent for the third field.",
579 MakeDoubleChecker<double> ())
580 .AddAttribute (
"ReferenceLoss",
581 "The reference loss at distance d0 (dB). (Default is Friis at 1m with 5.15 GHz)",
584 MakeDoubleChecker<double> ())
629 NS_LOG_DEBUG (
"ThreeLogDistance distance=" << distance <<
"m, " <<
630 "attenuation=" << pathLossDb <<
"dB");
632 return txPowerDbm - pathLossDb;
648 static TypeId tid =
TypeId (
"ns3::NakagamiPropagationLossModel")
650 .SetGroupName (
"Propagation")
652 .AddAttribute (
"Distance1",
653 "Beginning of the second distance field. Default is 80m.",
656 MakeDoubleChecker<double> ())
657 .AddAttribute (
"Distance2",
658 "Beginning of the third distance field. Default is 200m.",
661 MakeDoubleChecker<double> ())
663 "m0 for distances smaller than Distance1. Default is 1.5.",
666 MakeDoubleChecker<double> ())
668 "m1 for distances smaller than Distance2. Default is 0.75.",
671 MakeDoubleChecker<double> ())
673 "m2 for distances greater than Distance2. Default is 0.75.",
676 MakeDoubleChecker<double> ())
677 .AddAttribute (
"ErlangRv",
678 "Access to the underlying ErlangRandomVariable",
681 MakePointerChecker<ErlangRandomVariable> ())
682 .AddAttribute (
"GammaRv",
683 "Access to the underlying GammaRandomVariable",
686 MakePointerChecker<GammaRandomVariable> ());
722 double powerW = std::pow (10, (txPowerDbm - 30) / 10);
728 unsigned int int_m =
static_cast<unsigned int>(std::floor (m));
739 double resultPowerDbm = 10 * std::log10 (resultPowerW) + 30;
741 NS_LOG_DEBUG (
"Nakagami distance=" << distance <<
"m, " <<
742 "power=" << powerW <<
"W, " <<
743 "resultPower=" << resultPowerW <<
"W=" << resultPowerDbm <<
"dBm");
745 return resultPowerDbm;
765 .SetGroupName (
"Propagation")
767 .AddAttribute (
"Rss",
"The fixed receiver Rss.",
770 MakeDoubleChecker<double> ())
810 static TypeId tid =
TypeId (
"ns3::MatrixPropagationLossModel")
812 .SetGroupName (
"Propagation")
814 .AddAttribute (
"DefaultLoss",
"The default value for propagation loss, dB.",
817 MakeDoubleChecker<double> ())
843 std::map<MobilityPair, double>::iterator i =
m_loss.find (p);
847 m_loss.insert (std::make_pair (p, loss));
865 std::map<MobilityPair, double>::const_iterator i =
m_loss.find (std::make_pair (a, b));
869 return txPowerDbm - i->second;
890 static TypeId tid =
TypeId (
"ns3::RangePropagationLossModel")
892 .AddConstructor<RangePropagationLossModel> ()
893 .AddAttribute (
"MaxRange",
894 "Maximum Transmission Range (meters)",
897 MakeDoubleChecker<double> ())
double m_m0
m for distances smaller than Distance1
double m_distance2
Beginning of the third (far) distance field.
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
Returns the Rx Power taking into account only the particular PropagatinLossModel. ...
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account only the particular PropagatinLossModel. ...
void SetDefaultLoss(double defaultLoss)
Set the default propagation loss (in dB, positive) to be used, infinity if not set.
double GetDistanceFrom(Ptr< const MobilityModel > position) const
void SetPathLossExponent(double n)
double m_m2
m for distances greater than Distance2
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
void SetNext(Ptr< PropagationLossModel > next)
Enables a chain of loss models to act on the signal.
Hold variables of type string.
double m_frequency
the carrier frequency
double m_range
Maximum Transmission Range (meters)
a Two-Ray Ground propagation loss model ported from NS2
double m_heightAboveZ
antenna height above the node's Z coordinate
double m_lambda
the carrier wavelength
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
double m_frequency
the carrier frequency
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
double GetFrequency(void) const
double m_referenceLoss
The reference loss at distance d0 (dB).
Vector GetPosition(void) const
void SetMinLoss(double minLoss)
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account only the particular PropagatinLossModel. ...
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account only the particular PropagatinLossModel. ...
double m_exponent1
The exponent for the second field.
double m_systemLoss
the system loss
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
double m_minDistance
minimum distance for the model
Ptr< RandomVariableStream > m_variable
random generator
static TypeId GetTypeId(void)
Get the type ID.
static TypeId GetTypeId(void)
Get the type ID.
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account only the particular PropagatinLossModel. ...
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
Get the next random value as a double drawn from the distribution.
A log distance path loss propagation model with three distance fields.
static TypeId GetTypeId(void)
Get the type ID.
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero. ...
double m_exponent0
The exponent for the first field.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Ptr< PropagationLossModel > GetNext()
Gets the next PropagationLossModel in the chain of loss models that act on the signal.
double m_lambda
the carrier wavelength
double DbmToW(double dbm) const
Transforms a Dbm value to Watt.
static TypeId GetTypeId(void)
Get the type ID.
virtual ~RandomPropagationLossModel()
static TypeId GetTypeId(void)
Get the type ID.
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account only the particular PropagatinLossModel. ...
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const =0
Returns the Rx Power taking into account only the particular PropagatinLossModel. ...
double m_distance2
Distance2.
static TypeId GetTypeId(void)
Get the type ID.
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account all the PropagatinLossModel(s) chained to the current one...
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
Gamma random variable.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double m_exponent
model exponent
virtual ~PropagationLossModel()
double m_distance0
Beginning of the first (near) distance field.
FriisPropagationLossModel()
NakagamiPropagationLossModel()
Ptr< PropagationLossModel > m_next
Next propagation loss model in the list.
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
Erlang random variable.
void SetSystemLoss(double systemLoss)
double m_distance1
Beginning of the second (middle) distance field.
virtual ~MatrixPropagationLossModel()
double m_referenceDistance
reference distance
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
double m_minLoss
the minimum loss
double GetSystemLoss(void) const
double m_exponent2
The exponent for the third field.
Models the propagation loss through a transmission medium.
static TypeId GetTypeId(void)
Get the type ID.
double GetSystemLoss(void) const
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account only the particular PropagatinLossModel. ...
static TypeId GetTypeId(void)
Get the type ID.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
double m_m1
m for distances smaller than Distance2
#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
Transforms a Dbm value to Watt.
void SetFrequency(double frequency)
double m_referenceLoss
reference loss
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)
Set the reference path loss at a given distance.
A base class which provides memory management and object aggregation.
std::pair< Ptr< MobilityModel >, Ptr< MobilityModel > > MobilityPair
Typedef: Mobility models pair.
static TypeId GetTypeId(void)
Get the type ID.
void SetSystemLoss(double systemLoss)
double GetMinLoss(void) const
a log distance propagation model.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
MatrixPropagationLossModel()
double m_systemLoss
the system loss
a unique identifier for an interface.
double m_distance1
Distance1.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
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
Transforms a Watt value to Dbm.
double DbmFromW(double w) const
Transforms a Watt value to Dbm.
std::map< MobilityPair, double > m_loss
Propagation loss between pair of nodes.
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account only the particular PropagatinLossModel. ...
virtual int64_t DoAssignStreams(int64_t stream)=0
Subclasses must implement this; those not using random variables can return zero. ...