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/double.h"
10#include "ns3/log.h"
11#include "ns3/mobility-building-info.h"
12
13#include <cmath>
14
15namespace ns3
16{
17namespace lorawan
18{
19
20NS_LOG_COMPONENT_DEFINE("BuildingPenetrationLoss");
21
22NS_OBJECT_ENSURE_REGISTERED(BuildingPenetrationLoss);
23
24TypeId
26{
27 static TypeId tid = TypeId("ns3::BuildingPenetrationLoss")
29 .SetGroupName("Lora")
30 .AddConstructor<BuildingPenetrationLoss>();
31 return tid;
32}
33
41
46
47double
50 Ptr<MobilityModel> b) const
51{
52 NS_LOG_FUNCTION(this << txPowerDbm << a << b);
53
56
57 // These are the components of the loss due to building penetration
58 double externalWallLoss = 0;
59 double tor1 = 0;
60 double tor3 = 0;
61 double gfh = 0;
62
63 // Go through various cases in which a and b are indoors or outdoors
64 if ((b1->IsIndoor() && !a1->IsIndoor()))
65 {
66 NS_LOG_INFO("Tx is outdoors and Rx is indoors");
67
68 externalWallLoss = GetWallLoss(b); // External wall loss due to b
69 tor1 = GetTor1(b); // Internal wall loss due to b
70 tor3 = 0.6 * m_uniformRV->GetValue(0, 15);
71 gfh = 0;
72 }
73 else if ((!b1->IsIndoor() && a1->IsIndoor()))
74 {
75 NS_LOG_INFO("Rx is outdoors and Tx is indoors");
76
77 // These are the components of the loss due to building penetration
78 externalWallLoss = GetWallLoss(a);
79 tor1 = GetTor1(a);
80 tor3 = 0.6 * m_uniformRV->GetValue(0, 15);
81 gfh = 0;
82 }
83 else if (!a1->IsIndoor() && !b1->IsIndoor())
84 {
85 NS_LOG_DEBUG("No penetration loss since both devices are outside");
86 }
87 else if (a1->IsIndoor() && b1->IsIndoor())
88 {
89 // They are in the same building
90 if (a1->GetBuilding() == b1->GetBuilding())
91 {
92 NS_LOG_INFO("Devices are in the same building");
93 // Only internal wall loss
94 tor1 = GetTor1(b);
95 tor3 = 0.6 * m_uniformRV->GetValue(0, 15);
96 }
97 // They are in different buildings
98 else
99 {
100 // These are the components of the loss due to building penetration
101 externalWallLoss = GetWallLoss(b) + GetWallLoss(a);
102 tor1 = GetTor1(b) + GetTor1(a);
103 tor3 = 0.6 * m_uniformRV->GetValue(0, 15);
104 gfh = 0;
105 }
106 }
107
108 NS_LOG_DEBUG("Building penetration loss: externalWallLoss = " << externalWallLoss << ", tor1 = "
109 << tor1 << ", tor3 = " << tor3
110 << ", GFH = " << gfh);
111
112 // Put together all the pieces
113 double loss = externalWallLoss + std::max(tor1, tor3) - gfh;
114
115 NS_LOG_DEBUG("Total loss due to building penetration: " << loss);
116
117 return txPowerDbm - loss;
118}
119
120int64_t
122{
123 m_uniformRV->SetStream(stream);
124 return 1;
125}
126
127int
129{
131
132 // We need to decide on the p value to return
133 double random = m_uniformRV->GetValue(0.0, 1.0);
134
135 // Distribution is specified in TR 45.820, page 482, first scenario
136 if (random < 0.2833)
137 {
138 return 0;
139 }
140 else if (random < 0.566)
141 {
142 return 1;
143 }
144 else if (random < 0.85)
145 {
146 return 2;
147 }
148 else
149 {
150 return 3;
151 }
152}
153
154int
156{
158
159 // We need to decide on the random value to return
160 double random = m_uniformRV->GetValue(0.0, 1.0);
161
162 // Distribution is specified in TR 45.820, page 482, first scenario
163 if (random < 0.25)
164 {
165 return 0;
166 }
167 else if (random < 0.9)
168 {
169 return 1;
170 }
171 else
172 {
173 return 2;
174 }
175}
176
177double
179{
180 NS_LOG_FUNCTION(this << b);
181
182 std::map<Ptr<MobilityModel>, int>::const_iterator it;
183
184 // Check whether the b device already has a wall loss value
185 it = m_wallLossMap.find(b);
186 if (it == m_wallLossMap.end())
187 {
188 // Create a random value and insert it on the map
190 NS_LOG_DEBUG("Inserted a new wall loss value: " << m_wallLossMap.find(b)->second);
191 }
192
193 switch (m_wallLossMap.find(b)->second)
194 {
195 case 0:
196 return m_uniformRV->GetValue(4, 11);
197 case 1:
198 return m_uniformRV->GetValue(11, 19);
199 case 2:
200 return m_uniformRV->GetValue(19, 23);
201 }
202
203 // Case in which something goes wrong
204 return 0;
205}
206
207double
209{
210 NS_LOG_FUNCTION(this << b);
211
212 std::map<Ptr<MobilityModel>, int>::const_iterator it;
213
214 // Check whether the b device already has a p value
215 it = m_pMap.find(b);
216 if (it == m_pMap.end())
217 {
218 // Create a random p value and insert it on the map
219 m_pMap[b] = GetPValue();
220 NS_LOG_DEBUG("Inserted a new p value: " << m_pMap.find(b)->second);
221 }
222 return m_uniformRV->GetValue(4, 10) * m_pMap.find(b)->second;
223}
224} // namespace lorawan
225} // 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.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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.