A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
building-penetration-loss.cc
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation;
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 *
15 * Author: Davide Magrin <magrinda@dei.unipd.it>
16 */
17
19
20#include "ns3/double.h"
21#include "ns3/log.h"
22#include "ns3/mobility-building-info.h"
23
24#include <cmath>
25
26namespace ns3
27{
28namespace lorawan
29{
30
31NS_LOG_COMPONENT_DEFINE("BuildingPenetrationLoss");
32
33NS_OBJECT_ENSURE_REGISTERED(BuildingPenetrationLoss);
34
35TypeId
37{
38 static TypeId tid = TypeId("ns3::BuildingPenetrationLoss")
40 .SetGroupName("Lora")
41 .AddConstructor<BuildingPenetrationLoss>();
42 return tid;
43}
44
46{
48
49 // Initialize the random variable
50 m_uniformRV = CreateObject<UniformRandomVariable>();
51}
52
54{
56}
57
58double
61 Ptr<MobilityModel> b) const
62{
63 NS_LOG_FUNCTION(this << txPowerDbm << a << b);
64
67
68 // These are the components of the loss due to building penetration
69 double externalWallLoss = 0;
70 double tor1 = 0;
71 double tor3 = 0;
72 double gfh = 0;
73
74 // Go through various cases in which a and b are indoors or outdoors
75 if ((b1->IsIndoor() && !a1->IsIndoor()))
76 {
77 NS_LOG_INFO("Tx is outdoors and Rx is indoors");
78
79 externalWallLoss = GetWallLoss(b); // External wall loss due to b
80 tor1 = GetTor1(b); // Internal wall loss due to b
81 tor3 = 0.6 * m_uniformRV->GetValue(0, 15);
82 gfh = 0;
83 }
84 else if ((!b1->IsIndoor() && a1->IsIndoor()))
85 {
86 NS_LOG_INFO("Rx is outdoors and Tx is indoors");
87
88 // These are the components of the loss due to building penetration
89 externalWallLoss = GetWallLoss(a);
90 tor1 = GetTor1(a);
91 tor3 = 0.6 * m_uniformRV->GetValue(0, 15);
92 gfh = 0;
93 }
94 else if (!a1->IsIndoor() && !b1->IsIndoor())
95 {
96 NS_LOG_DEBUG("No penetration loss since both devices are outside");
97 }
98 else if (a1->IsIndoor() && b1->IsIndoor())
99 {
100 // They are in the same building
101 if (a1->GetBuilding() == b1->GetBuilding())
102 {
103 NS_LOG_INFO("Devices are in the same building");
104 // Only internal wall loss
105 tor1 = GetTor1(b);
106 tor3 = 0.6 * m_uniformRV->GetValue(0, 15);
107 }
108 // They are in different buildings
109 else
110 {
111 // These are the components of the loss due to building penetration
112 externalWallLoss = GetWallLoss(b) + GetWallLoss(a);
113 tor1 = GetTor1(b) + GetTor1(a);
114 tor3 = 0.6 * m_uniformRV->GetValue(0, 15);
115 gfh = 0;
116 }
117 }
118
119 NS_LOG_DEBUG("Building penetration loss:"
120 << " externalWallLoss = " << externalWallLoss << ", tor1 = " << tor1
121 << ", tor3 = " << tor3 << ", GFH = " << gfh);
122
123 // Put together all the pieces
124 double loss = externalWallLoss + std::max(tor1, tor3) - gfh;
125
126 NS_LOG_DEBUG("Total loss due to building penetration: " << loss);
127
128 return txPowerDbm - loss;
129}
130
131int64_t
133{
134 m_uniformRV->SetStream(stream);
135 return 1;
136}
137
138int
140{
142
143 // We need to decide on the p value to return
144 double random = m_uniformRV->GetValue(0.0, 1.0);
145
146 // Distribution is specified in TR 45.820, page 482, first scenario
147 if (random < 0.2833)
148 {
149 return 0;
150 }
151 else if (random < 0.566)
152 {
153 return 1;
154 }
155 else if (random < 0.85)
156 {
157 return 2;
158 }
159 else
160 {
161 return 3;
162 }
163}
164
165int
167{
169
170 // We need to decide on the random value to return
171 double random = m_uniformRV->GetValue(0.0, 1.0);
172
173 // Distribution is specified in TR 45.820, page 482, first scenario
174 if (random < 0.25)
175 {
176 return 0;
177 }
178 else if (random < 0.9)
179 {
180 return 1;
181 }
182 else
183 {
184 return 2;
185 }
186}
187
188double
190{
191 NS_LOG_FUNCTION(this << b);
192
193 std::map<Ptr<MobilityModel>, int>::const_iterator it;
194
195 // Check whether the b device already has a wall loss value
196 it = m_wallLossMap.find(b);
197 if (it == m_wallLossMap.end())
198 {
199 // Create a random value and insert it on the map
201 NS_LOG_DEBUG("Inserted a new wall loss value: " << m_wallLossMap.find(b)->second);
202 }
203
204 switch (m_wallLossMap.find(b)->second)
205 {
206 case 0:
207 return m_uniformRV->GetValue(4, 11);
208 case 1:
209 return m_uniformRV->GetValue(11, 19);
210 case 2:
211 return m_uniformRV->GetValue(19, 23);
212 }
213
214 // Case in which something goes wrong
215 return 0;
216}
217
218double
220{
221 NS_LOG_FUNCTION(this << b);
222
223 std::map<Ptr<MobilityModel>, int>::const_iterator it;
224
225 // Check whether the b device already has a p value
226 it = m_pMap.find(b);
227 if (it == m_pMap.end())
228 {
229 // Create a random p value and insert it on the map
230 m_pMap[b] = GetPValue();
231 NS_LOG_DEBUG("Inserted a new p value: " << m_pMap.find(b)->second);
232 }
233 return m_uniformRV->GetValue(4, 10) * m_pMap.find(b)->second;
234}
235} // namespace lorawan
236} // namespace ns3
mobility buildings information (to be used by mobility models)
Models the propagation loss through a transmission medium.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
double GetValue(double min, double max)
Get the next random value drawn from the distribution.
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:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.