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 rxPow -=
GetLoss (cond, distance2d, distance3d, heights.first, heights.second);
158 if (cond->GetLosCondition () == ChannelCondition::LosConditionValue::LOS)
160 loss =
GetLossLos (distance2d, distance3d, hUt, hBs);
162 else if (cond->GetLosCondition () == ChannelCondition::LosConditionValue::NLOSv)
166 else if (cond->GetLosCondition () == ChannelCondition::LosConditionValue::NLOS)
168 loss =
GetLossNlos (distance2d, distance3d, hUt, hBs);
190 double shadowingValue;
193 uint32_t key =
GetKey (a, b);
195 bool notFound =
false;
196 bool newCondition =
false;
204 newCondition = (it->second.m_condition != cond);
215 if (notFound || newCondition)
223 Vector2D displacement (newDistance.x - it->second.m_distance.x, newDistance.y - it->second.m_distance.y);
229 it->second.m_shadowing = shadowingValue;
230 it->second.m_distance = newDistance;
231 it->second.m_condition = cond;
233 return shadowingValue;
236 std::pair<double, double>
244 return std::pair<double, double> (hUt, hBs);
259 double x = a.x - b.x;
260 double y = a.y - b.y;
261 double distance2D = sqrt (
x *
x + y * y);
275 uint32_t key = (((x1 + x2) * (x1 + x2 + 1)) / 2) + x2;
303 static TypeId tid =
TypeId (
"ns3::ThreeGppRmaPropagationLossModel")
305 .SetGroupName (
"Propagation")
307 .AddAttribute (
"AvgBuildingHeight",
"The average building height in meters.",
310 MakeDoubleChecker<double> (5.0, 50.0))
311 .AddAttribute (
"AvgStreetWidth",
"The average street width in meters.",
314 MakeDoubleChecker<double> (5.0, 50.0))
340 if (hUt < 1.0 || hUt > 10.0)
342 NS_LOG_WARN (
"The height of the UT should be between 1 and 10 m (see TR 38.901, Table 7.4.1-1)");
345 if (hBs < 10.0 || hBs > 150.0)
347 NS_LOG_WARN (
"The height of the BS should be between 10 and 150 m (see TR 38.901, Table 7.4.1-1)");
361 if (distance2D < 10.0 || distance2D > 10.0e3)
363 NS_LOG_WARN (
"The 2D distance is outside the validity range, the pathloss value may not be accurate");
368 if (distance2D <= distanceBp)
391 if (hUt < 1.0 || hUt > 10.0)
393 NS_LOG_WARN (
"The height of the UT should be between 1 and 10 m (see TR 38.901, Table 7.4.1-1)");
396 if (hBs < 10.0 || hBs > 150.0)
398 NS_LOG_WARN (
"The height of the BS should be between 10 and 150 m (see TR 38.901, Table 7.4.1-1)");
409 if (distance2D < 10.0 || distance2D > 5.0e3)
411 NS_LOG_WARN (
"The 2D distance is outside the validity range, the pathloss value may not be accurate");
415 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);
430 if (cond == ChannelCondition::LosConditionValue::LOS)
438 if (distance2d <= distanceBp)
447 else if (cond == ChannelCondition::LosConditionValue::NLOS)
463 double correlationDistance;
466 if (cond == ChannelCondition::LosConditionValue::LOS)
468 correlationDistance = 37;
470 else if (cond == ChannelCondition::LosConditionValue::NLOS)
472 correlationDistance = 120;
479 return correlationDistance;
485 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;
492 double distanceBp = 2.0 * M_PI * hA * hB * frequency /
M_C;
503 static TypeId tid =
TypeId (
"ns3::ThreeGppUmaPropagationLossModel")
505 .SetGroupName (
"Propagation")
533 if (distance2D > 18.0)
535 g = 5.0 / 4.0 * pow (distance2D / 100.0, 3) * exp (-distance2D / 150.0);
542 c = pow ((hUt - 13.0) / 10.0, 1.5) * g;
546 double prob = 1.0 / (1.0 + c);
555 hE = (double)floor (random / 3.0) * 3.0;
559 double distanceBp = 4 * (hBs - hE) * (hUt - hE) *
m_frequency /
M_C;
570 if (hUt < 1.5 || hUt > 22.5)
572 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)");
577 NS_LOG_WARN (
"The height of the BS should be equal to 25 m (see TR 38.901, Table 7.4.1-1)");
592 if (distance2D < 10.0 || distance2D > 5.0e3)
594 NS_LOG_WARN (
"The 2D distance is outside the validity range, the pathloss value may not be accurate");
599 if (distance2D <= distanceBp)
602 loss = 28.0 + 22.0 * log10 (distance3D) + 20.0 * log10 (
m_frequency / 1e9);
607 loss = 28.0 + 40.0 * log10 (distance3D) + 20.0 * log10 (
m_frequency / 1e9) - 9.0 * log10 (pow (distanceBp, 2) + pow (hBs - hUt, 2));
621 if (hUt < 1.5 || hUt > 22.5)
623 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)");
628 NS_LOG_WARN (
"The height of the BS should be equal to 25 m (see TR 38.901, Table 7.4.1-1)");
639 if (distance2D < 10.0 || distance2D > 5.0e3)
641 NS_LOG_WARN (
"The 2D distance is outside the validity range, the pathloss value may not be accurate");
645 double plNlos = 13.54 + 39.08 * log10 (distance3D) + 20.0 * log10 (
m_frequency / 1e9) - 0.6 * (hUt - 1.5);
660 if (cond == ChannelCondition::LosConditionValue::LOS)
664 else if (cond == ChannelCondition::LosConditionValue::NLOS)
680 double correlationDistance;
683 if (cond == ChannelCondition::LosConditionValue::LOS)
685 correlationDistance = 37;
687 else if (cond == ChannelCondition::LosConditionValue::NLOS)
689 correlationDistance = 50;
696 return correlationDistance;
716 static TypeId tid =
TypeId (
"ns3::ThreeGppUmiStreetCanyonPropagationLossModel")
718 .SetGroupName (
"Propagation")
739 [[maybe_unused]]
double distance2D)
const
747 double distanceBp = 4 * (hBs - hE) * (hUt - hE) *
m_frequency /
M_C;
758 if (hUt < 1.5 || hUt >= 10.0)
760 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");
765 NS_LOG_WARN (
"The height of the BS should be equal to 10 m (see TR 38.901, Table 7.4.1-1)");
780 if (distance2D < 10.0 || distance2D > 5.0e3)
782 NS_LOG_WARN (
"The 2D distance is outside the validity range, the pathloss value may not be accurate");
787 if (distance2D <= distanceBp)
790 loss = 32.4 + 21.0 * log10 (distance3D) + 20.0 * log10 (
m_frequency / 1e9);
795 loss = 32.4 + 40.0 * log10 (distance3D) + 20.0 * log10 (
m_frequency / 1e9) - 9.5 * log10 (pow (distanceBp, 2) + pow (hBs - hUt, 2));
809 if (hUt < 1.5 || hUt >= 10.0)
811 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");
816 NS_LOG_WARN (
"The height of the BS should be equal to 10 m (see TR 38.901, Table 7.4.1-1)");
827 if (distance2D < 10.0 || distance2D > 5.0e3)
829 NS_LOG_WARN (
"The 2D distance is outside the validity range, the pathloss value may not be accurate");
833 double plNlos = 22.4 + 35.3 * log10 (distance3D) + 21.3 * log10 (
m_frequency / 1e9) - 0.3 * (hUt - 1.5);
840 std::pair<double, double>
866 return std::pair<double, double> (hUt, hBs);
877 if (cond == ChannelCondition::LosConditionValue::LOS)
881 else if (cond == ChannelCondition::LosConditionValue::NLOS)
897 double correlationDistance;
900 if (cond == ChannelCondition::LosConditionValue::LOS)
902 correlationDistance = 10;
904 else if (cond == ChannelCondition::LosConditionValue::NLOS)
906 correlationDistance = 13;
913 return correlationDistance;
923 static TypeId tid =
TypeId (
"ns3::ThreeGppIndoorOfficePropagationLossModel")
925 .SetGroupName (
"Propagation")
946 [[maybe_unused]]
double distance3D,
947 [[maybe_unused]]
double hUt,
948 [[maybe_unused]]
double hBs)
const
953 if (distance3D < 1.0 || distance3D > 150.0)
955 NS_LOG_WARN (
"The 3D distance is outside the validity range, the pathloss value may not be accurate");
959 double loss = 32.4 + 17.3 * log10 (distance3D) + 20.0 * log10 (
m_frequency / 1e9);
972 if (distance3D < 1.0 || distance3D > 150.0)
974 NS_LOG_WARN (
"The 3D distance is outside the validity range, the pathloss value may not be accurate");
978 double plNlos = 17.3 + 38.3 * log10 (distance3D) + 24.9 * log10 (
m_frequency / 1e9);
994 if (cond == ChannelCondition::LosConditionValue::LOS)
998 else if (cond == ChannelCondition::LosConditionValue::NLOS)
1000 shadowingStd = 8.03;
1007 return shadowingStd;
1016 double correlationDistance;
1018 if (cond == ChannelCondition::LosConditionValue::LOS)
1020 correlationDistance = 10;
1022 else if (cond == ChannelCondition::LosConditionValue::NLOS)
1024 correlationDistance = 6;
1031 return correlationDistance;
double f(double x, void *params)
AttributeValue implementation for Boolean.
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'.
Vector GetPosition(void) const
uint32_t GetId(void) const
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Hold objects of type Ptr<T>.
Models the propagation loss through a transmission medium.
Smart pointer class similar to boost::intrusive_ptr.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Implements the pathloss model defined in 3GPP TR 38.901, Table 7.4.1-1 for the Indoor Office scenario...
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.
virtual ~ThreeGppIndoorOfficePropagationLossModel() override
Destructor.
static TypeId GetTypeId(void)
Get the type ID.
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.
ThreeGppIndoorOfficePropagationLossModel()
Constructor.
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.
Base class for the 3GPP propagation models.
double GetLoss(Ptr< ChannelCondition > cond, double distance2D, double distance3D, double hUt, double hBs) const
Computes the pathloss between a and b.
Ptr< ChannelConditionModel > GetChannelConditionModel(void) const
Returns the associated channel condition model.
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.
double GetShadowing(Ptr< MobilityModel > a, Ptr< MobilityModel > b, ChannelCondition::LosConditionValue cond) const
Retrieves the shadowing value by looking at m_shadowingMap.
static double Calculate2dDistance(Vector a, Vector b)
Computes the 2D distance between two 3D vectors.
void SetChannelConditionModel(Ptr< ChannelConditionModel > model)
Set the channel condition model used to determine the channel state (e.g., the LOS/NLOS condition)
static TypeId GetTypeId(void)
Get the type ID.
std::unordered_map< uint32_t, ShadowingMapItem > m_shadowingMap
map to store the shadowing values
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.
virtual int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
virtual double GetShadowingCorrelationDistance(ChannelCondition::LosConditionValue cond) const =0
Returns the shadow fading correlation distance.
ThreeGppPropagationLossModel()
Constructor.
Ptr< NormalRandomVariable > m_normRandomVariable
normal random variable
Ptr< ChannelConditionModel > m_channelConditionModel
pointer to the channel condition model
virtual ~ThreeGppPropagationLossModel() override
Destructor.
double GetFrequency(void) const
Return the current central frequency.
void SetFrequency(double f)
Set the central frequency of the model.
virtual void DoDispose() override
Destructor implementation.
static uint32_t GetKey(Ptr< MobilityModel > a, Ptr< MobilityModel > b)
Returns an unique key for the channel between a and b.
double m_frequency
operating frequency in Hz
virtual double GetShadowingStd(Ptr< MobilityModel > a, Ptr< MobilityModel > b, ChannelCondition::LosConditionValue cond) const =0
Returns the shadow fading standard deviation.
virtual double GetLossNlosv(double distance2D, double distance3D, double hUt, double hBs) const
Computes the pathloss between a and b considering that the line of sight is obstructed by a vehicle.
virtual std::pair< double, double > GetUtAndBsHeights(double za, double zb) const
Determines hUT and hBS.
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....
bool m_shadowingEnabled
enable/disable shadowing
static Vector GetVectorDifference(Ptr< MobilityModel > a, Ptr< MobilityModel > b)
Get the difference between the node position.
Implements the pathloss model defined in 3GPP TR 38.901, Table 7.4.1-1 for the RMa scenario.
virtual double GetShadowingStd(Ptr< MobilityModel > a, Ptr< MobilityModel > b, ChannelCondition::LosConditionValue cond) const override
Returns the shadow fading standard deviation.
static double Pl1(double frequency, double distance3D, double h, double w)
Computes the PL1 formula for the RMa scenario.
ThreeGppRmaPropagationLossModel()
Constructor.
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.
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.
virtual ~ThreeGppRmaPropagationLossModel() override
Destructor.
virtual double GetShadowingCorrelationDistance(ChannelCondition::LosConditionValue cond) const override
Returns the shadow fading correlation distance.
double m_h
average building height in meters
static TypeId GetTypeId(void)
Get the type ID.
static double GetBpDistance(double frequency, double hA, double hB)
Computes the breakpoint distance for the RMa scenario.
double m_w
average street width in meters
Implements the pathloss model defined in 3GPP TR 38.901, Table 7.4.1-1 for the UMa scenario.
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 GetBpDistance(double hUt, double hBs, double distance2D) const
Computes the breakpoint distance.
virtual ~ThreeGppUmaPropagationLossModel() override
Destructor.
ThreeGppUmaPropagationLossModel()
Constructor.
virtual int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
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< UniformRandomVariable > m_uniformVar
a uniform random variable used for the computation of the breakpoint distance
static TypeId GetTypeId(void)
Get the type ID.
virtual double GetShadowingStd(Ptr< MobilityModel > a, Ptr< MobilityModel > b, ChannelCondition::LosConditionValue cond) const override
Returns the shadow fading standard deviation.
virtual double GetShadowingCorrelationDistance(ChannelCondition::LosConditionValue cond) const override
Returns the shadow fading correlation distance.
Implements the pathloss model defined in 3GPP TR 38.901, Table 7.4.1-1 for the UMi-Street Canyon scen...
std::pair< double, double > GetUtAndBsHeights(double za, double zb) const override
Determines hUT and hBS.
virtual ~ThreeGppUmiStreetCanyonPropagationLossModel() override
Destructor.
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.
virtual double GetShadowingStd(Ptr< MobilityModel > a, Ptr< MobilityModel > b, ChannelCondition::LosConditionValue cond) const override
Returns the shadow fading standard deviation.
double GetBpDistance(double hUt, double hBs, double distance2D) const
Computes the breakpoint distance.
ThreeGppUmiStreetCanyonPropagationLossModel()
Constructor.
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.
virtual double GetShadowingCorrelationDistance(ChannelCondition::LosConditionValue cond) const override
Returns the shadow fading correlation distance.
static TypeId GetTypeId(void)
Get the type ID.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
double GetLength() const
Compute the length (magnitude) of the vector.
#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 AttributeChecker > MakeBooleanChecker(void)
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
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_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#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_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#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.
static const double M_C
propagation velocity in free space
double CalculateDistance(const Vector3D &a, const Vector3D &b)
list x
Random number samples.
Define a struct for the m_shadowingMap entries.