22 #include "ns3/mobility-model.h" 23 #include "ns3/channel-condition-model.h" 24 #include "ns3/double.h" 25 #include "ns3/boolean.h" 26 #include "ns3/pointer.h" 29 #include "ns3/simulator.h" 35 static const double M_C = 3.0e8;
44 static TypeId tid =
TypeId (
"ns3::ThreeGppPropagationLossModel")
46 .SetGroupName (
"Propagation")
47 .AddAttribute (
"Frequency",
"The centre frequency in Hz.",
51 MakeDoubleChecker<double> ())
52 .AddAttribute (
"ShadowingEnabled",
"Enable/disable shadowing.",
56 .AddAttribute (
"ChannelConditionModel",
"Pointer to the channel condition model.",
60 MakePointerChecker<ChannelConditionModel> ())
107 NS_ASSERT_MSG (
f >= 500.0e6 &&
f <= 100.0e9,
"Frequency should be between 0.5 and 100 GHz but is " <<
f);
141 double rxPow = txPowerDbm;
142 if (cond->GetLosCondition () == ChannelCondition::LosConditionValue::LOS)
144 rxPow -=
GetLossLos (distance2d, distance3d, heights.first, heights.second);
145 NS_LOG_DEBUG (
"Channel codition is LOS, rxPower = " << rxPow);
147 else if (cond->GetLosCondition () == ChannelCondition::LosConditionValue::NLOS)
149 rxPow -=
GetLossNlos (distance2d, distance3d, heights.first, heights.second);
150 NS_LOG_DEBUG (
"Channel codition is NLOS, rxPower = " << rxPow);
170 double shadowingValue;
173 uint32_t key =
GetKey (a, b);
175 bool notFound =
false;
176 bool newCondition =
false;
184 newCondition = (it->second.m_condition != cond);
195 if (notFound || newCondition)
203 Vector2D displacement (newDistance.x - it->second.m_distance.x, newDistance.y - it->second.m_distance.y);
209 it->second.m_shadowing = shadowingValue;
210 it->second.m_distance = newDistance;
211 it->second.m_condition = cond;
213 return shadowingValue;
216 std::pair<double, double>
224 return std::pair<double, double> (hUt, hBs);
239 double x = a.x - b.x;
240 double y = a.y - b.y;
241 double distance2D = sqrt (
x *
x + y * y);
255 uint32_t key = (((x1 + x2) * (x1 + x2 + 1)) / 2) + x2;
283 static TypeId tid =
TypeId (
"ns3::ThreeGppRmaPropagationLossModel")
285 .SetGroupName (
"Propagation")
287 .AddAttribute (
"AvgBuildingHeight",
"The average building height in meters.",
290 MakeDoubleChecker<double> (5.0, 50.0))
291 .AddAttribute (
"AvgStreetWidth",
"The average street width in meters.",
294 MakeDoubleChecker<double> (5.0, 50.0))
320 if (hUt < 1.0 || hUt > 10.0)
322 NS_LOG_WARN (
"The height of the UT should be between 1 and 10 m (see TR 38.901, Table 7.4.1-1)");
325 if (hBs < 10.0 || hBs > 150.0)
327 NS_LOG_WARN (
"The height of the BS should be between 10 and 150 m (see TR 38.901, Table 7.4.1-1)");
341 if (distance2D < 10.0 || distance2D > 10.0e3)
343 NS_LOG_WARN (
"The 2D distance is outside the validity range, the pathloss value may not be accurate");
348 if (distance2D <= distanceBp)
371 if (hUt < 1.0 || hUt > 10.0)
373 NS_LOG_WARN (
"The height of the UT should be between 1 and 10 m (see TR 38.901, Table 7.4.1-1)");
376 if (hBs < 10.0 || hBs > 150.0)
378 NS_LOG_WARN (
"The height of the BS should be between 10 and 150 m (see TR 38.901, Table 7.4.1-1)");
389 if (distance2D < 10.0 || distance2D > 5.0e3)
391 NS_LOG_WARN (
"The 2D distance is outside the validity range, the pathloss value may not be accurate");
395 double plNlos = 161.04 - 7.1 * log10 (
m_w) + 7.5 * log10 (
m_h) - (24.37 - 3.7 * pow ((
m_h / hBs), 2)) * log10 (hBs) + (43.42 - 3.1 * log10 (hBs)) * (log10 (distance3D) - 3.0) + 20.0 * log10 (
m_frequency / 1e9) - (3.2 * pow (log10 (11.75 * hUt), 2) - 4.97);
410 if (cond == ChannelCondition::LosConditionValue::LOS)
418 if (distance2d <= distanceBp)
427 else if (cond == ChannelCondition::LosConditionValue::NLOS)
443 double correlationDistance;
446 if (cond == ChannelCondition::LosConditionValue::LOS)
448 correlationDistance = 37;
450 else if (cond == ChannelCondition::LosConditionValue::NLOS)
452 correlationDistance = 120;
459 return correlationDistance;
466 double loss = 20.0 * log10 (40.0 * M_PI * distance3D * frequency / 1e9 / 3.0) +
std::min (0.03 * pow (h, 1.72), 10.0) * log10 (distance3D) -
std::min (0.044 * pow (h, 1.72), 14.77) + 0.002 * log10 (h) * distance3D;
473 double distanceBp = 2.0 * M_PI * hA * hB * frequency /
M_C;
484 static TypeId tid =
TypeId (
"ns3::ThreeGppUmaPropagationLossModel")
486 .SetGroupName (
"Propagation")
514 if (distance2D > 18.0)
516 g = 5.0 / 4.0 * pow (distance2D / 100.0, 3) * exp (-distance2D / 150.0);
523 c = pow ((hUt - 13.0) / 10.0, 1.5) * g;
527 double prob = 1.0 / (1.0 + c);
536 hE = (double)floor (random / 3.0) * 3.0;
540 double distanceBp = 4 * (hBs - hE) * (hUt - hE) *
m_frequency /
M_C;
551 if (hUt < 1.5 || hUt > 22.5)
553 NS_LOG_WARN (
"The height of the UT should be between 1.5 and 22.5 m (see TR 38.901, Table 7.4.1-1)");
558 NS_LOG_WARN (
"The height of the BS should be equal to 25 m (see TR 38.901, Table 7.4.1-1)");
573 if (distance2D < 10.0 || distance2D > 5.0e3)
575 NS_LOG_WARN (
"The 2D distance is outside the validity range, the pathloss value may not be accurate");
580 if (distance2D <= distanceBp)
583 loss = 28.0 + 22.0 * log10 (distance3D) + 20.0 * log10 (
m_frequency / 1e9);
588 loss = 28.0 + 40.0 * log10 (distance3D) + 20.0 * log10 (
m_frequency / 1e9) - 9.0 * log10 (pow (distanceBp, 2) + pow (hBs - hUt, 2));
602 if (hUt < 1.5 || hUt > 22.5)
604 NS_LOG_WARN (
"The height of the UT should be between 1.5 and 22.5 m (see TR 38.901, Table 7.4.1-1)");
609 NS_LOG_WARN (
"The height of the BS should be equal to 25 m (see TR 38.901, Table 7.4.1-1)");
620 if (distance2D < 10.0 || distance2D > 5.0e3)
622 NS_LOG_WARN (
"The 2D distance is outside the validity range, the pathloss value may not be accurate");
626 double plNlos = 13.54 + 39.08 * log10 (distance3D) + 20.0 * log10 (
m_frequency / 1e9) - 0.6 * (hUt - 1.5);
641 if (cond == ChannelCondition::LosConditionValue::LOS)
645 else if (cond == ChannelCondition::LosConditionValue::NLOS)
661 double correlationDistance;
664 if (cond == ChannelCondition::LosConditionValue::LOS)
666 correlationDistance = 37;
668 else if (cond == ChannelCondition::LosConditionValue::NLOS)
670 correlationDistance = 50;
677 return correlationDistance;
697 static TypeId tid =
TypeId (
"ns3::ThreeGppUmiStreetCanyonPropagationLossModel")
699 .SetGroupName (
"Propagation")
728 double distanceBp = 4 * (hBs - hE) * (hUt - hE) *
m_frequency /
M_C;
739 if (hUt < 1.5 || hUt >= 10.0)
741 NS_LOG_WARN (
"The height of the UT should be between 1.5 and 22.5 m (see TR 38.901, Table 7.4.1-1). We further assume hUT < hBS, then hUT is upper bounded by hBS, which should be 10 m");
746 NS_LOG_WARN (
"The height of the BS should be equal to 10 m (see TR 38.901, Table 7.4.1-1)");
761 if (distance2D < 10.0 || distance2D > 5.0e3)
763 NS_LOG_WARN (
"The 2D distance is outside the validity range, the pathloss value may not be accurate");
768 if (distance2D <= distanceBp)
771 loss = 32.4 + 21.0 * log10 (distance3D) + 20.0 * log10 (
m_frequency / 1e9);
776 loss = 32.4 + 40.0 * log10 (distance3D) + 20.0 * log10 (
m_frequency / 1e9) - 9.5 * log10 (pow (distanceBp, 2) + pow (hBs - hUt, 2));
790 if (hUt < 1.5 || hUt >= 10.0)
792 NS_LOG_WARN (
"The height of the UT should be between 1.5 and 22.5 m (see TR 38.901, Table 7.4.1-1). We further assume hUT < hBS, then hUT is upper bounded by hBS, which should be 10 m");
797 NS_LOG_WARN (
"The height of the BS should be equal to 10 m (see TR 38.901, Table 7.4.1-1)");
808 if (distance2D < 10.0 || distance2D > 5.0e3)
810 NS_LOG_WARN (
"The 2D distance is outside the validity range, the pathloss value may not be accurate");
814 double plNlos = 22.4 + 35.3 * log10 (distance3D) + 21.3 * log10 (
m_frequency / 1e9) - 0.3 * (hUt - 1.5);
821 std::pair<double, double>
847 return std::pair<double, double> (hUt, hBs);
858 if (cond == ChannelCondition::LosConditionValue::LOS)
862 else if (cond == ChannelCondition::LosConditionValue::NLOS)
878 double correlationDistance;
881 if (cond == ChannelCondition::LosConditionValue::LOS)
883 correlationDistance = 10;
885 else if (cond == ChannelCondition::LosConditionValue::NLOS)
887 correlationDistance = 13;
894 return correlationDistance;
904 static TypeId tid =
TypeId (
"ns3::ThreeGppIndoorOfficePropagationLossModel")
906 .SetGroupName (
"Propagation")
935 if (distance3D < 1.0 || distance3D > 150.0)
937 NS_LOG_WARN (
"The 2D distance is outside the validity range, the pathloss value may not be accurate");
941 double loss = 32.4 + 17.3 * log10 (distance3D) + 20.0 * log10 (
m_frequency / 1e9);
954 if (distance3D < 1.0 || distance3D > 150.0)
956 NS_LOG_WARN (
"The 2D distance is outside the validity range, the pathloss value may not be accurate");
960 double plNlos = 17.3 + 38.3 * log10 (distance3D) + 24.9 * log10 (
m_frequency / 1e9);
976 if (cond == ChannelCondition::LosConditionValue::LOS)
980 else if (cond == ChannelCondition::LosConditionValue::NLOS)
998 double correlationDistance;
1000 if (cond == ChannelCondition::LosConditionValue::LOS)
1002 correlationDistance = 10;
1004 else if (cond == ChannelCondition::LosConditionValue::NLOS)
1006 correlationDistance = 6;
1013 return correlationDistance;
std::unordered_map< uint32_t, ShadowingMapItem > m_shadowingMap
map to store the shadowing values
Implements the pathloss model defined in 3GPP TR 38.901, Table 7.4.1-1 for the UMi-Street Canyon scen...
ThreeGppRmaPropagationLossModel()
Constructor.
Ptr< ChannelConditionModel > m_channelConditionModel
pointer to the channel condition model
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
virtual int64_t DoAssignStreams(int64_t stream) override
If this model uses objects of type RandomVariableStream, set the stream numbers to the integers start...
AttributeValue implementation for Boolean.
virtual double GetShadowingCorrelationDistance(ChannelCondition::LosConditionValue cond) const =0
Returns the shadow fading correlation distance.
uint32_t GetId(void) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
double GetLossNlos(double distance2D, double distance3D, double hUt, double hBs) const override
Computes the pathloss between a and b considering that the line of sight is obstructed.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual double GetShadowingStd(Ptr< MobilityModel > a, Ptr< MobilityModel > b, ChannelCondition::LosConditionValue cond) const override
Returns the shadow fading standard deviation.
virtual double GetLossLos(double distance2D, double distance3D, double hUt, double hBs) const =0
Computes the pathloss between a and b considering that the line of sight is not obstructed.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
virtual double GetShadowingStd(Ptr< MobilityModel > a, Ptr< MobilityModel > b, ChannelCondition::LosConditionValue cond) const override
Returns the shadow fading standard deviation.
#define NS_UNUSED(x)
Mark a local variable as unused.
static double GetBpDistance(double frequency, double hA, double hB)
Computes the breakpoint distance for the RMa scenario.
virtual ~ThreeGppUmaPropagationLossModel() override
Destructor.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
virtual double GetShadowingCorrelationDistance(ChannelCondition::LosConditionValue cond) const override
Returns the shadow fading correlation distance.
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const override
Computes the received power by applying the pathloss model described in 3GPP TR 38.901.
ThreeGppPropagationLossModel()
Constructor.
virtual ~ThreeGppIndoorOfficePropagationLossModel() override
Destructor.
static TypeId GetTypeId(void)
Get the type ID.
double GetBpDistance(double hUt, double hBs, double distance2D) const
Computes the breakpoint distance.
ThreeGppIndoorOfficePropagationLossModel()
Constructor.
double GetLossNlos(double distance2D, double distance3D, double hUt, double hBs) const override
Computes the pathloss between a and b considering that the line of sight is obstructed.
double GetBpDistance(double hUt, double hBs, double distance2D) const
Computes the breakpoint distance.
virtual double GetShadowingStd(Ptr< MobilityModel > a, Ptr< MobilityModel > b, ChannelCondition::LosConditionValue cond) const override
Returns the shadow fading standard deviation.
static double Calculate2dDistance(Vector a, Vector b)
Computes the 2D distance between two 3D vectors.
virtual double GetShadowingCorrelationDistance(ChannelCondition::LosConditionValue cond) const override
Returns the shadow fading correlation distance.
virtual ~ThreeGppUmiStreetCanyonPropagationLossModel() override
Destructor.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual double GetLossNlos(double distance2D, double distance3D, double hUt, double hBs) const =0
Computes the pathloss between a and b considering that the line of sight is obstructed.
Implements the pathloss model defined in 3GPP TR 38.901, Table 7.4.1-1 for the RMa scenario...
double CalculateDistance(const Vector3D &a, const Vector3D &b)
double GetFrequency(void) const
Return the current central frequency.
bool m_shadowingEnabled
enable/disable shadowing
double GetLossLos(double distance2D, double distance3D, double hUt, double hBs) const override
Computes the pathloss between a and b considering that the line of sight is not obstructed.
double m_w
average street width in meters
Define a struct for the m_shadowingMap entries.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
double f(double x, void *params)
virtual double GetShadowingCorrelationDistance(ChannelCondition::LosConditionValue cond) const override
Returns the shadow fading correlation distance.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr<T>.
virtual void DoDispose() override
Destructor implementation.
virtual double GetLossLos(double distance2D, double distance3D, double hUt, double hBs) const override
Computes the pathloss between a and b considering that the line of sight is not obstructed.
static Vector GetVectorDifference(Ptr< MobilityModel > a, Ptr< MobilityModel > b)
Get the difference between the node position.
ThreeGppUmaPropagationLossModel()
Constructor.
double GetShadowing(Ptr< MobilityModel > a, Ptr< MobilityModel > b, ChannelCondition::LosConditionValue cond) const
Retrieves the shadowing value by looking at m_shadowingMap.
static double Pl1(double frequency, double distance3D, double h, double w)
Computes the PL1 formula for the RMa scenario.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Vector GetPosition(void) const
static TypeId GetTypeId(void)
Get the type ID.
Ptr< ChannelConditionModel > GetChannelConditionModel(void) const
Returns the associated channel condition model.
Models the propagation loss through a transmission medium.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
std::pair< double, double > GetUtAndBsHeights(double za, double zb) const override
Determines hUT and hBS.
double GetLossNlos(double distance2D, double distance3D, double hUt, double hBs) const override
Computes the pathloss between a and b considering that the line of sight is obstructed.
void SetFrequency(double f)
Set the central frequency of the model.
static TypeId GetTypeId(void)
Get the type ID.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
void SetChannelConditionModel(Ptr< ChannelConditionModel > model)
Set the channel condition model used to determine the channel state (e.g., the LOS/NLOS condition) ...
Ptr< const AttributeChecker > MakeBooleanChecker(void)
double GetLossLos(double distance2D, double distance3D, double hUt, double hBs) const override
Computes the pathloss between a and b considering that the line of sight is not obstructed.
double m_frequency
operating frequency in Hz
virtual double GetShadowingCorrelationDistance(ChannelCondition::LosConditionValue cond) const override
Returns the shadow fading correlation distance.
virtual double GetShadowingStd(Ptr< MobilityModel > a, Ptr< MobilityModel > b, ChannelCondition::LosConditionValue cond) const override
Returns the shadow fading standard deviation.
Base class for the 3GPP propagation models.
virtual int64_t DoAssignStreams(int64_t stream) override
If this model uses objects of type RandomVariableStream, set the stream numbers to the integers start...
virtual double GetLossNlos(double distance2D, double distance3D, double hUt, double hBs) const override
Computes the pathloss between a and b considering that the line of sight is obstructed.
double m_h
average building height in meters
static TypeId GetTypeId(void)
Get the type ID.
ThreeGppUmiStreetCanyonPropagationLossModel()
Constructor.
static uint32_t GetKey(Ptr< MobilityModel > a, Ptr< MobilityModel > b)
Returns an unique key for the channel between a and b.
LosConditionValue
Possible values for Line-of-Sight condition.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
virtual std::pair< double, double > GetUtAndBsHeights(double za, double zb) const
Determines hUT and hBS.
a unique identifier for an interface.
Ptr< UniformRandomVariable > m_uniformVar
a uniform random variable used for the computation of the breakpoint distance
Implements the pathloss model defined in 3GPP TR 38.901, Table 7.4.1-1 for the UMa scenario...
TypeId SetParent(TypeId tid)
Set the parent TypeId.
double GetLossLos(double distance2D, double distance3D, double hUt, double hBs) const override
Computes the pathloss between a and b considering that the line of sight is not obstructed.
Implements the pathloss model defined in 3GPP TR 38.901, Table 7.4.1-1 for the Indoor Office scenario...
static TypeId GetTypeId(void)
Get the type ID.
double GetLength() const
Compute the length (magnitude) of the vector.
virtual ~ThreeGppPropagationLossModel() override
Destructor.
virtual ~ThreeGppRmaPropagationLossModel() override
Destructor.
virtual double GetShadowingStd(Ptr< MobilityModel > a, Ptr< MobilityModel > b, ChannelCondition::LosConditionValue cond) const =0
Returns the shadow fading standard deviation.
Ptr< NormalRandomVariable > m_normRandomVariable
normal random variable