-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathtgax-residential-propagation-loss-model.cc
211 lines (189 loc) · 7.41 KB
/
tgax-residential-propagation-loss-model.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
* Copyright (c) 2023 University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "tgax-residential-propagation-loss-model.h"
#include "ns3/double.h"
#include "ns3/enum.h"
#include "ns3/log.h"
#include "ns3/mobility-model.h"
#include "ns3/pointer.h"
#include <ns3/mobility-building-info.h>
#include <cmath>
namespace ns3
{
NS_LOG_COMPONENT_DEFINE("TgaxResidentialPropagationLossModel");
NS_OBJECT_ENSURE_REGISTERED(TgaxResidentialPropagationLossModel);
TypeId
TgaxResidentialPropagationLossModel::GetTypeId()
{
static TypeId tid =
TypeId("ns3::TgaxResidentialPropagationLossModel")
.SetParent<PropagationLossModel>()
.SetGroupName("Wifi")
.AddConstructor<TgaxResidentialPropagationLossModel>()
.AddAttribute("Frequency",
"The carrier frequency (in Hz) at which propagation occurs",
DoubleValue(2.437e9),
MakeDoubleAccessor(&TgaxResidentialPropagationLossModel::m_frequencyHz),
MakeDoubleChecker<double>())
.AddAttribute(
"ShadowSigma",
"Standard deviation (dB) of the normal distribution used to calculate shadowing "
"loss",
DoubleValue(5.0),
MakeDoubleAccessor(&TgaxResidentialPropagationLossModel::m_shadowingSigma),
MakeDoubleChecker<double>());
return tid;
}
TgaxResidentialPropagationLossModel::TgaxResidentialPropagationLossModel()
{
m_shadowingRandomVariable = CreateObject<NormalRandomVariable>();
}
double
TgaxResidentialPropagationLossModel::GetRxPower(double txPowerDbm,
Ptr<MobilityModel> a,
Ptr<MobilityModel> b) const
{
double distance = a->GetDistanceFrom(b);
if (distance == 0)
{
return txPowerDbm;
}
distance = std::max(1.0, distance); // 1m minimum distance
//
// Based on the IEEE 802.11-14/0980r6 document, 1 - Residential Scenario
//
// PL(d) = 40.05 + 20 * log10(fc/2.4) + 20 * log10(min(d,5)) +
// 18.3 * (d/floors)^(((d/floors)+2)/((d/floors)+1) - 0.46) + 5 * (d/walls)
//
// if d>5 then
// PL(d) += 35 * log10(d/5)
//
double pathlossDb;
// double shadowingDb = 0;
double breakpointDistance = 5; // meters
double fc = 2.4e9; // carrier frequency, Hz
uint16_t floors = 0;
uint16_t walls = 0;
Ptr<MobilityBuildingInfo> aInfo = a->GetObject<MobilityBuildingInfo>();
Ptr<MobilityBuildingInfo> bInfo = b->GetObject<MobilityBuildingInfo>();
if (aInfo && bInfo)
{
if (!aInfo->IsIndoor() || !bInfo->IsIndoor())
{
NS_LOG_DEBUG("One or both nodes is outdoor, so returning zero signal power");
return 0;
}
floors = std::abs(aInfo->GetFloorNumber() - bInfo->GetFloorNumber());
walls = std::abs(aInfo->GetRoomNumberX() - bInfo->GetRoomNumberX()) +
std::abs(aInfo->GetRoomNumberY() - bInfo->GetRoomNumberY());
}
pathlossDb = 40.05 + 20 * std::log10(m_frequencyHz / fc) +
20 * std::log10(std::min(distance, breakpointDistance));
if (distance > breakpointDistance)
{
pathlossDb += 35 * std::log10(distance / 5);
}
if (floors)
{
pathlossDb +=
18.3 * std::pow((distance / floors),
((distance / floors) + 2.0) / ((distance / floors) + 1.0) - 0.46);
}
if (walls)
{
pathlossDb += 5.0 * (walls); // Changed (distance/walls) to only (walls) because the
// pathloss would isolate the rooms
}
// TODO: cache the shadowingDb value and reuse until positions change
// shadowingDb = m_shadowingRandomVariable->GetValue(
// 0,
// m_shadowingSigma * m_shadowingSigma); // Disabled shadowing because nodes do not move
// std::cout << "Distance " << distance << " Pathloss " << pathlossDb << " Floor " << floors
// << " walls " << walls << std::endl;
return txPowerDbm - pathlossDb;
// -shadowingDb;
}
double
TgaxResidentialPropagationLossModel::DoCalcRxPower(double txPowerDbm,
Ptr<MobilityModel> a,
Ptr<MobilityModel> b) const
{
double distance = a->GetDistanceFrom(b);
if (distance == 0)
{
return txPowerDbm;
}
distance = std::max(1.0, distance); // 1m minimum distance
//
// Based on the IEEE 802.11-14/0980r6 document, 1 - Residential Scenario
//
// PL(d) = 40.05 + 20 * log10(fc/2.4) + 20 * log10(min(d,5)) +
// 18.3 * (d/floors)^(((d/floors)+2)/((d/floors)+1) - 0.46) + 5 * (d/walls)
//
// if d>5 then
// PL(d) += 35 * log10(d/5)
//
double pathlossDb;
// double shadowingDb = 0;
double breakpointDistance = 5; // meters
double fc = 2.4e9; // carrier frequency, Hz
uint16_t floors = 0;
uint16_t walls = 0;
Ptr<MobilityBuildingInfo> aInfo = a->GetObject<MobilityBuildingInfo>();
Ptr<MobilityBuildingInfo> bInfo = b->GetObject<MobilityBuildingInfo>();
if (aInfo && bInfo)
{
if (!aInfo->IsIndoor() || !bInfo->IsIndoor())
{
NS_LOG_DEBUG("One or both nodes is outdoor, so returning zero signal power");
return 0;
}
floors = std::abs(aInfo->GetFloorNumber() - bInfo->GetFloorNumber());
walls = std::abs(aInfo->GetRoomNumberX() - bInfo->GetRoomNumberX()) +
std::abs(aInfo->GetRoomNumberY() - bInfo->GetRoomNumberY());
}
pathlossDb = 40.05 + 20 * std::log10(m_frequencyHz / fc) +
20 * std::log10(std::min(distance, breakpointDistance));
if (distance > breakpointDistance)
{
pathlossDb += 35 * std::log10(distance / 5);
}
if (floors)
{
pathlossDb +=
18.3 * std::pow((distance / floors),
((distance / floors) + 2.0) / ((distance / floors) + 1.0) - 0.46);
}
if (walls)
{
pathlossDb += 5.0 * (walls); // Changed (distance/walls) to only (walls) because the
// pathloss would isolate the rooms
}
// TODO: cache the shadowingDb value and reuse until positions change
// shadowingDb = m_shadowingRandomVariable->GetValue(0, m_shadowingSigma * m_shadowingSigma);
// // std::cout << "Distance " << distance << " Pathloss " << pathlossDb << " Floor " <<
// floors
// // << " walls " << walls << std::endl;
return txPowerDbm - pathlossDb;
}
int64_t
TgaxResidentialPropagationLossModel::DoAssignStreams(int64_t stream)
{
m_shadowingRandomVariable->SetStream(stream);
return 1;
}
} // namespace ns3