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"
46 .SetGroupName (
"Propagation")
88 int64_t currentStream = stream;
94 return (currentStream - stream);
104 static TypeId tid =
TypeId (
"ns3::RandomPropagationLossModel")
106 .SetGroupName (
"Propagation")
108 .AddAttribute (
"Variable",
"The random variable used to pick a loss every time CalcRxPower is invoked.",
109 StringValue (
"ns3::ConstantRandomVariable[Constant=1.0]"),
111 MakePointerChecker<RandomVariableStream> ())
131 return txPowerDbm + rxc;
148 static TypeId tid =
TypeId (
"ns3::FriisPropagationLossModel")
150 .SetGroupName (
"Propagation")
152 .AddAttribute (
"Frequency",
153 "The carrier frequency (in Hz) at which propagation occurs (default is 5.15 GHz).",
157 MakeDoubleChecker<double> ())
158 .AddAttribute (
"SystemLoss",
"The system loss",
161 MakeDoubleChecker<double> ())
162 .AddAttribute (
"MinLoss",
163 "The minimum value (dB) of the total loss, used at short ranges. Note: ",
167 MakeDoubleChecker<double> ())
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;
261 NS_LOG_WARN (
"distance not within the far field region => inaccurate propagation loss value");
268 double denominator = 16 * M_PI * M_PI * distance * distance *
m_systemLoss;
269 double lossDb = -10 * log10 (numerator / denominator);
270 NS_LOG_DEBUG (
"distance=" << distance<<
"m, loss=" << lossDb <<
"dB");
288 static TypeId tid =
TypeId (
"ns3::TwoRayGroundPropagationLossModel")
290 .SetGroupName (
"Propagation")
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 * M_PI * txAntHeight * rxAntHeight) /
m_lambda;
424 if (distance <= dCross)
428 tmp = M_PI * distance;
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 .SetGroupName (
"Propagation")
465 .AddAttribute (
"Exponent",
466 "The exponent of the Path Loss propagation model",
469 MakeDoubleChecker<double> ())
470 .AddAttribute (
"ReferenceDistance",
471 "The distance at which the reference loss is calculated (m)",
474 MakeDoubleChecker<double> ())
475 .AddAttribute (
"ReferenceLoss",
476 "The reference loss at reference distance (dB). (Default is Friis at 1m with 5.15 GHz)",
479 MakeDoubleChecker<double> ())
533 "attenuation coefficient="<<rxc<<
"db");
534 return txPowerDbm + rxc;
550 static TypeId tid =
TypeId (
"ns3::ThreeLogDistancePropagationLossModel")
552 .SetGroupName (
"Propagation")
554 .AddAttribute (
"Distance0",
555 "Beginning of the first (near) distance field",
558 MakeDoubleChecker<double> ())
559 .AddAttribute (
"Distance1",
560 "Beginning of the second (middle) distance field.",
563 MakeDoubleChecker<double> ())
564 .AddAttribute (
"Distance2",
565 "Beginning of the third (far) distance field.",
568 MakeDoubleChecker<double> ())
569 .AddAttribute (
"Exponent0",
570 "The exponent for the first field.",
573 MakeDoubleChecker<double> ())
574 .AddAttribute (
"Exponent1",
575 "The exponent for the second field.",
578 MakeDoubleChecker<double> ())
579 .AddAttribute (
"Exponent2",
580 "The exponent for the third field.",
583 MakeDoubleChecker<double> ())
584 .AddAttribute (
"ReferenceLoss",
585 "The reference loss at distance d0 (dB). (Default is Friis at 1m with 5.15 GHz)",
588 MakeDoubleChecker<double> ())
633 NS_LOG_DEBUG (
"ThreeLogDistance distance=" << distance <<
"m, " <<
634 "attenuation=" << pathLossDb <<
"dB");
636 return txPowerDbm - pathLossDb;
652 static TypeId tid =
TypeId (
"ns3::NakagamiPropagationLossModel")
654 .SetGroupName (
"Propagation")
656 .AddAttribute (
"Distance1",
657 "Beginning of the second distance field. Default is 80m.",
660 MakeDoubleChecker<double> ())
661 .AddAttribute (
"Distance2",
662 "Beginning of the third distance field. Default is 200m.",
665 MakeDoubleChecker<double> ())
667 "m0 for distances smaller than Distance1. Default is 1.5.",
670 MakeDoubleChecker<double> ())
672 "m1 for distances smaller than Distance2. Default is 0.75.",
675 MakeDoubleChecker<double> ())
677 "m2 for distances greater than Distance2. Default is 0.75.",
680 MakeDoubleChecker<double> ())
681 .AddAttribute (
"ErlangRv",
682 "Access to the underlying ErlangRandomVariable",
685 MakePointerChecker<ErlangRandomVariable> ())
686 .AddAttribute (
"GammaRv",
687 "Access to the underlying GammaRandomVariable",
690 MakePointerChecker<GammaRandomVariable> ());
726 double powerW = std::pow (10, (txPowerDbm - 30) / 10);
732 unsigned int int_m =
static_cast<unsigned int>(std::floor (m));
743 double resultPowerDbm = 10 * std::log10 (resultPowerW) + 30;
745 NS_LOG_DEBUG (
"Nakagami distance=" << distance <<
"m, " <<
746 "power=" << powerW <<
"W, " <<
747 "resultPower=" << resultPowerW <<
"W=" << resultPowerDbm <<
"dBm");
749 return resultPowerDbm;
769 .SetGroupName (
"Propagation")
771 .AddAttribute (
"Rss",
"The fixed receiver Rss.",
774 MakeDoubleChecker<double> ())
814 static TypeId tid =
TypeId (
"ns3::MatrixPropagationLossModel")
816 .SetGroupName (
"Propagation")
818 .AddAttribute (
"DefaultLoss",
"The default value for propagation loss, dB.",
821 MakeDoubleChecker<double> ())
847 std::map<MobilityPair, double>::iterator i =
m_loss.find (p);
851 m_loss.insert (std::make_pair (p, loss));
869 std::map<MobilityPair, double>::const_iterator i =
m_loss.find (std::make_pair (a, b));
873 return txPowerDbm - i->second;
894 static TypeId tid =
TypeId (
"ns3::RangePropagationLossModel")
896 .SetGroupName (
"Propagation")
898 .AddAttribute (
"MaxRange",
899 "Maximum Transmission Range (meters)",
902 MakeDoubleChecker<double> ())
This class can be used to hold variables of floating point type such as 'double' or 'float'.
a Friis propagation loss model
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero.
double m_lambda
the carrier wavelength
double DbmFromW(double w) const
Transforms a Watt value to Dbm.
double GetFrequency(void) const
double m_frequency
the carrier frequency
void SetSystemLoss(double systemLoss)
void SetFrequency(double frequency)
double DbmToW(double dbm) const
Transforms a Dbm value to Watt.
static TypeId GetTypeId(void)
Get the type ID.
double GetMinLoss(void) const
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 PropagationLossModel.
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
void SetReference(double referenceDistance, double referenceLoss)
Set the reference path loss at a given distance.
LogDistancePropagationLossModel()
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero.
double m_exponent
model exponent
double GetPathLossExponent(void) const
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account only the particular PropagationLossModel.
static TypeId GetTypeId(void)
Get the type ID.
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.
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero.
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.
MatrixPropagationLossModel()
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 PropagationLossModel.
virtual ~MatrixPropagationLossModel()
double m_default
default loss
std::pair< Ptr< MobilityModel >, Ptr< MobilityModel > > MobilityPair
Typedef: Mobility models pair.
std::map< MobilityPair, double > m_loss
Propagation loss between pair of nodes.
double GetDistanceFrom(Ptr< const MobilityModel > position) const
Vector GetPosition(void) 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.
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account only the particular PropagationLossModel.
double m_distance1
Distance1.
double m_distance2
Distance2.
NakagamiPropagationLossModel()
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_m1
m for distances smaller than Distance2
double m_m2
m for distances greater than Distance2
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
Subclasses must implement this; those not using random variables can return zero.
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.
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const =0
Returns the Rx Power taking into account only the particular PropagationLossModel.
int64_t AssignStreams(int64_t stream)
If this loss model uses objects of type RandomVariableStream, set the stream numbers to the integers ...
void SetNext(Ptr< PropagationLossModel > next)
Enables a chain of loss models to act on the signal.
static TypeId GetTypeId(void)
Get the type ID.
virtual ~PropagationLossModel()
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()
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account only the particular PropagationLossModel.
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.
Ptr< RandomVariableStream > m_variable
random generator
virtual ~RandomPropagationLossModel()
virtual double GetValue(void)=0
Get the next random value as a double 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.
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero.
RangePropagationLossModel()
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 PropagationLossModel.
double m_range
Maximum Transmission Range (meters)
Hold variables of type string.
A log distance path loss propagation model with three distance fields.
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero.
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account only the particular PropagationLossModel.
double m_referenceLoss
The reference loss at distance d0 (dB).
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(void)
Get the type ID.
ThreeLogDistancePropagationLossModel()
double m_exponent0
The exponent for the first field.
double m_exponent1
The exponent for the second field.
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(void) const
double m_heightAboveZ
antenna height above the node's Z coordinate
TwoRayGroundPropagationLossModel()
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account only the particular PropagationLossModel.
double DbmFromW(double w) const
Transforms a Watt value to Dbm.
void SetSystemLoss(double systemLoss)
void SetMinDistance(double minDistance)
double GetSystemLoss(void) const
void SetFrequency(double frequency)
double m_systemLoss
the system loss
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_frequency
the carrier frequency
void SetHeightAboveZ(double heightAboveZ)
double m_lambda
the carrier wavelength
double GetFrequency(void) const
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)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#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.
double max(double x, double y)