A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
building-penetration-loss.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 * Author: Davide Magrin <magrinda@dei.unipd.it>
5 */
6
8
9#include "ns3/mobility-building-info.h"
10
11namespace ns3
12{
13namespace lorawan
14{
15
16NS_LOG_COMPONENT_DEFINE("BuildingPenetrationLoss");
17
19
20TypeId
22{
23 static TypeId tid = TypeId("ns3::BuildingPenetrationLoss")
25 .SetGroupName("Lora")
26 .AddConstructor<BuildingPenetrationLoss>();
27 return tid;
28}
29
37
42
43double
46 Ptr<MobilityModel> b) const
47{
48 NS_LOG_FUNCTION(this << txPowerDbm << a << b);
49
52
53 // These are the components of the loss due to building penetration
54 double externalWallLoss = 0;
55 double tor1 = 0;
56 double tor3 = 0;
57 double gfh = 0;
58
59 // Go through various cases in which a and b are indoors or outdoors
60 if ((b1->IsIndoor() && !a1->IsIndoor()))
61 {
62 NS_LOG_INFO("Tx is outdoors and Rx is indoors");
63
64 externalWallLoss = GetWallLoss(b); // External wall loss due to b
65 tor1 = GetTor1(b); // Internal wall loss due to b
66 tor3 = 0.6 * m_uniformRV->GetValue(0, 15);
67 gfh = 0;
68 }
69 else if ((!b1->IsIndoor() && a1->IsIndoor()))
70 {
71 NS_LOG_INFO("Rx is outdoors and Tx is indoors");
72
73 // These are the components of the loss due to building penetration
74 externalWallLoss = GetWallLoss(a);
75 tor1 = GetTor1(a);
76 tor3 = 0.6 * m_uniformRV->GetValue(0, 15);
77 gfh = 0;
78 }
79 else if (!a1->IsIndoor() && !b1->IsIndoor())
80 {
81 NS_LOG_DEBUG("No penetration loss since both devices are outside");
82 }
83 else if (a1->IsIndoor() && b1->IsIndoor())
84 {
85 // They are in the same building
86 if (a1->GetBuilding() == b1->GetBuilding())
87 {
88 NS_LOG_INFO("Devices are in the same building");
89 // Only internal wall loss
90 tor1 = GetTor1(b);
91 tor3 = 0.6 * m_uniformRV->GetValue(0, 15);
92 }
93 // They are in different buildings
94 else
95 {
96 // These are the components of the loss due to building penetration
97 externalWallLoss = GetWallLoss(b) + GetWallLoss(a);
98 tor1 = GetTor1(b) + GetTor1(a);
99 tor3 = 0.6 * m_uniformRV->GetValue(0, 15);
100 gfh = 0;
101 }
102 }
103
104 NS_LOG_DEBUG("Building penetration loss: externalWallLoss = " << externalWallLoss << ", tor1 = "
105 << tor1 << ", tor3 = " << tor3
106 << ", GFH = " << gfh);
107
108 // Put together all the pieces
109 double loss = externalWallLoss + std::max(tor1, tor3) - gfh;
110
111 NS_LOG_DEBUG("Total loss due to building penetration: " << loss);
112
113 return txPowerDbm - loss;
114}
115
116int64_t
118{
119 m_uniformRV->SetStream(stream);
120 return 1;
121}
122
123int
125{
127
128 // We need to decide on the p value to return
129 double random = m_uniformRV->GetValue(0.0, 1.0);
130
131 // Distribution is specified in TR 45.820, page 482, first scenario
132 if (random < 0.2833)
133 {
134 return 0;
135 }
136 else if (random < 0.566)
137 {
138 return 1;
139 }
140 else if (random < 0.85)
141 {
142 return 2;
143 }
144 else
145 {
146 return 3;
147 }
148}
149
150int
152{
154
155 // We need to decide on the random value to return
156 double random = m_uniformRV->GetValue(0.0, 1.0);
157
158 // Distribution is specified in TR 45.820, page 482, first scenario
159 if (random < 0.25)
160 {
161 return 0;
162 }
163 else if (random < 0.9)
164 {
165 return 1;
166 }
167 else
168 {
169 return 2;
170 }
171}
172
173double
175{
176 NS_LOG_FUNCTION(this << b);
177
178 std::map<Ptr<MobilityModel>, int>::const_iterator it;
179
180 // Check whether the b device already has a wall loss value
181 it = m_wallLossMap.find(b);
182 if (it == m_wallLossMap.end())
183 {
184 // Create a random value and insert it on the map
186 NS_LOG_DEBUG("Inserted a new wall loss value: " << m_wallLossMap.find(b)->second);
187 }
188
189 switch (m_wallLossMap.find(b)->second)
190 {
191 case 0:
192 return m_uniformRV->GetValue(4, 11);
193 case 1:
194 return m_uniformRV->GetValue(11, 19);
195 case 2:
196 return m_uniformRV->GetValue(19, 23);
197 }
198
199 // Case in which something goes wrong
200 return 0;
201}
202
203double
205{
206 NS_LOG_FUNCTION(this << b);
207
208 std::map<Ptr<MobilityModel>, int>::const_iterator it;
209
210 // Check whether the b device already has a p value
211 it = m_pMap.find(b);
212 if (it == m_pMap.end())
213 {
214 // Create a random p value and insert it on the map
215 m_pMap[b] = GetPValue();
216 NS_LOG_DEBUG("Inserted a new p value: " << m_pMap.find(b)->second);
217 }
218 return m_uniformRV->GetValue(4, 10) * m_pMap.find(b)->second;
219}
220
221} // namespace lorawan
222} // namespace ns3
mobility buildings information (to be used by mobility models)
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
A class implementing the TR 45.820 model for building losses.
int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
int GetWallLossValue() const
Get a value to compute the wall loss.
int GetPValue() const
Generate a random p value.
std::map< Ptr< MobilityModel >, int > m_wallLossMap
A map linking each mobility model to a value deciding its external wall loss.
Ptr< UniformRandomVariable > m_uniformRV
An uniform RV.
static TypeId GetTypeId()
Register this type.
double GetTor1(Ptr< MobilityModel > b) const
Get the Tor1 value used in the TR 45.820 standard to account for internal wall loss.
double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const override
PropagationLossModel.
std::map< Ptr< MobilityModel >, int > m_pMap
A map linking each mobility model to a p value.
double GetWallLoss(Ptr< MobilityModel > b) const
Compute the wall loss associated to this mobility model.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:260
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:267
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.