A Discrete-Event Network Simulator
API
hybrid-buildings-propagation-loss-model.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Marco Miozzo <marco.miozzo@cttc.es>
18  * Nicola Baldo <nbaldo@cttc.es>
19  *
20  */
21 
23 
24 #include "ns3/double.h"
25 #include "ns3/enum.h"
26 #include "ns3/itu-r-1238-propagation-loss-model.h"
27 #include "ns3/itu-r-1411-los-propagation-loss-model.h"
28 #include "ns3/itu-r-1411-nlos-over-rooftop-propagation-loss-model.h"
29 #include "ns3/kun-2600-mhz-propagation-loss-model.h"
30 #include "ns3/log.h"
31 #include "ns3/mobility-model.h"
32 #include "ns3/okumura-hata-propagation-loss-model.h"
33 #include "ns3/pointer.h"
34 #include <ns3/mobility-building-info.h>
35 
36 #include <cmath>
37 
38 namespace ns3
39 {
40 
41 NS_LOG_COMPONENT_DEFINE("HybridBuildingsPropagationLossModel");
42 
43 NS_OBJECT_ENSURE_REGISTERED(HybridBuildingsPropagationLossModel);
44 
46 {
47  m_okumuraHata = CreateObject<OkumuraHataPropagationLossModel>();
48  m_ituR1411Los = CreateObject<ItuR1411LosPropagationLossModel>();
49  m_ituR1411NlosOverRooftop = CreateObject<ItuR1411NlosOverRooftopPropagationLossModel>();
50  m_ituR1238 = CreateObject<ItuR1238PropagationLossModel>();
51  m_kun2600Mhz = CreateObject<Kun2600MhzPropagationLossModel>();
52 }
53 
55 {
56 }
57 
58 TypeId
60 {
61  static TypeId tid =
62  TypeId("ns3::HybridBuildingsPropagationLossModel")
63 
65 
66  .AddConstructor<HybridBuildingsPropagationLossModel>()
67  .SetGroupName("Buildings")
68 
69  .AddAttribute("Frequency",
70  "The Frequency (default is 2.106 GHz).",
71  DoubleValue(2160e6),
73  MakeDoubleChecker<double>())
74 
75  .AddAttribute(
76  "Los2NlosThr",
77  " Threshold from LoS to NLoS in ITU 1411 [m].",
78  DoubleValue(200.0),
80  MakeDoubleChecker<double>())
81 
82  .AddAttribute("Environment",
83  "Environment Scenario",
87  "Urban",
89  "SubUrban",
91  "OpenAreas"))
92 
93  .AddAttribute(
94  "CitySize",
95  "Dimension of the city",
98  MakeEnumChecker(SmallCity, "Small", MediumCity, "Medium", LargeCity, "Large"))
99 
100  .AddAttribute(
101  "RooftopLevel",
102  "The height of the rooftop level in meters",
103  DoubleValue(20.0),
105  MakeDoubleChecker<double>(0.0, 90.0))
106 
107  ;
108 
109  return tid;
110 }
111 
112 void
114 {
115  m_okumuraHata->SetAttribute("Environment", EnumValue(env));
116  m_ituR1411NlosOverRooftop->SetAttribute("Environment", EnumValue(env));
117 }
118 
119 void
121 {
122  m_okumuraHata->SetAttribute("CitySize", EnumValue(size));
123  m_ituR1411NlosOverRooftop->SetAttribute("CitySize", EnumValue(size));
124 }
125 
126 void
128 {
129  m_okumuraHata->SetAttribute("Frequency", DoubleValue(freq));
130  m_ituR1411Los->SetAttribute("Frequency", DoubleValue(freq));
131  m_ituR1411NlosOverRooftop->SetAttribute("Frequency", DoubleValue(freq));
132  m_ituR1238->SetAttribute("Frequency", DoubleValue(freq));
133  m_frequency = freq;
134 }
135 
136 void
138 {
139  m_rooftopHeight = rooftopHeight;
140  m_ituR1411NlosOverRooftop->SetAttribute("RooftopLevel", DoubleValue(rooftopHeight));
141 }
142 
143 double
145 {
147  (a->GetPosition().z >= 0) && (b->GetPosition().z >= 0),
148  "HybridBuildingsPropagationLossModel does not support underground nodes (placed at z < 0)");
149 
150  double distance = a->GetDistanceFrom(b);
151 
152  // get the MobilityBuildingInfo pointers
155  NS_ASSERT_MSG(a1 && b1,
156  "HybridBuildingsPropagationLossModel only works with MobilityBuildingInfo");
157 
158  double loss = 0.0;
159  bool isAIndoor = a1->IsIndoor();
160  bool isBIndoor = b1->IsIndoor();
161 
162  if (!isAIndoor) // a is outdoor
163  {
164  if (!isBIndoor) // b is outdoor
165  {
166  if (distance > 1000)
167  {
168  NS_LOG_INFO(this << a->GetPosition().z << b->GetPosition().z << m_rooftopHeight);
169  if ((a->GetPosition().z < m_rooftopHeight) &&
170  (b->GetPosition().z < m_rooftopHeight))
171  {
172  loss = ItuR1411(a, b);
173  NS_LOG_INFO(this << " 0-0 (>1000): below rooftop -> ITUR1411 : " << loss);
174  }
175  else
176  {
177  // Over the rooftop transmission -> Okumura Hata
178  loss = OkumuraHata(a, b);
179  NS_LOG_INFO(this << " O-O (>1000): above rooftop -> OH : " << loss);
180  }
181  }
182  else
183  {
184  // short range outdoor communication
185  loss = ItuR1411(a, b);
186  NS_LOG_INFO(this << " 0-0 (<1000) Street canyon -> ITUR1411 : " << loss);
187  }
188  }
189  else
190  {
191  // b indoor
192  if (distance > 1000)
193  {
194  if ((a->GetPosition().z < m_rooftopHeight) &&
195  (b->GetPosition().z < m_rooftopHeight))
196  {
197  loss = ItuR1411(a, b) + ExternalWallLoss(b1) + HeightLoss(b1);
198  NS_LOG_INFO(this << " 0-I (>1000): below rooftop -> ITUR1411 : " << loss);
199  }
200  else
201  {
202  loss = OkumuraHata(a, b) + ExternalWallLoss(b1);
203  NS_LOG_INFO(this << " O-I (>1000): above the rooftop -> OH : " << loss);
204  }
205  }
206  else
207  {
208  loss = ItuR1411(a, b) + ExternalWallLoss(b1) + HeightLoss(b1);
209  NS_LOG_INFO(this << " 0-I (<1000) ITUR1411 + BEL : " << loss);
210  }
211  } // end b1->isIndoor ()
212  }
213  else
214  {
215  // a is indoor
216  if (isBIndoor) // b is indoor
217  {
218  if (a1->GetBuilding() == b1->GetBuilding())
219  {
220  // nodes are in same building -> indoor communication ITU-R P.1238
221  loss = ItuR1238(a, b) + InternalWallsLoss(a1, b1);
222  NS_LOG_INFO(this << " I-I (same building) ITUR1238 : " << loss);
223  }
224  else
225  {
226  // nodes are in different buildings
227  loss = ItuR1411(a, b) + ExternalWallLoss(a1) + ExternalWallLoss(b1);
228  NS_LOG_INFO(this << " I-I (different) ITUR1238 + 2*BEL : " << loss);
229  }
230  }
231  else
232  {
233  // b is outdoor
234  if (distance > 1000)
235  {
236  if ((a->GetPosition().z < m_rooftopHeight) &&
237  (b->GetPosition().z < m_rooftopHeight))
238  {
239  loss = ItuR1411(a, b) + ExternalWallLoss(a1) + HeightLoss(a1);
240  NS_LOG_INFO(this << " I-O (>1000): down rooftop -> ITUR1411 : " << loss);
241  }
242  else
243  {
244  // above rooftop -> OH
245  loss = OkumuraHata(a, b) + ExternalWallLoss(a1) + HeightLoss(a1);
246  NS_LOG_INFO(this << " =I-O (>1000) over rooftop OH + BEL + HG: " << loss);
247  }
248  }
249  else
250  {
251  loss = ItuR1411(a, b) + ExternalWallLoss(a1) + HeightLoss(a1);
252  NS_LOG_INFO(this << " I-O (<1000) ITUR1411 + BEL + HG: " << loss);
253  }
254  } // end if (isBIndoor)
255  } // end if (!isAIndoor)
256 
257  loss = std::max(loss, 0.0);
258 
259  return loss;
260 }
261 
262 double
264 {
265  if (m_frequency <= 2.3e9)
266  {
267  return m_okumuraHata->GetLoss(a, b);
268  }
269  else
270  {
271  return m_kun2600Mhz->GetLoss(a, b);
272  }
273 }
274 
275 double
277 {
279  {
280  return (m_ituR1411Los->GetLoss(a, b));
281  }
282  else
283  {
284  return (m_ituR1411NlosOverRooftop->GetLoss(a, b));
285  }
286 }
287 
288 double
290 {
291  return m_ituR1238->GetLoss(a, b);
292 }
293 
294 } // namespace ns3
#define max(a, b)
Definition: 80211b.c:43
This model provides means for simulating the following propagation phenomena in the presence of build...
double HeightLoss(Ptr< MobilityBuildingInfo > n) const
Calculate the height loss.
double ExternalWallLoss(Ptr< MobilityBuildingInfo > a) const
Calculate the external wall loss.
double InternalWallsLoss(Ptr< MobilityBuildingInfo > a, Ptr< MobilityBuildingInfo > b) const
Calculate the internal wall loss.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Hold variables of type enum.
Definition: enum.h:56
void SetCitySize(CitySize size)
set the size of the city
double OkumuraHata(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Compute the path loss using either OkumuraHataPropagationLossModel or Kun2600MhzPropagationLossModel.
Ptr< ItuR1411NlosOverRooftopPropagationLossModel > m_ituR1411NlosOverRooftop
ItuR1411NlosOverRooftopPropagationLossModel.
void SetFrequency(double freq)
set the propagation frequency
void SetRooftopHeight(double rooftopHeight)
set the rooftop height
Ptr< ItuR1411LosPropagationLossModel > m_ituR1411Los
ItuR1411LosPropagationLossModel.
double ItuR1411(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Compute the path loss using either ItuR1411LosPropagationLossModel or ItuR1411NlosOverRooftopPropagat...
Ptr< Kun2600MhzPropagationLossModel > m_kun2600Mhz
Kun2600MhzPropagationLossModel.
double ItuR1238(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Compute the path loss using ItuR1238PropagationLossModel.
Ptr< OkumuraHataPropagationLossModel > m_okumuraHata
OkumuraHataPropagationLossModel.
void SetEnvironment(EnvironmentType env)
set the environment type
double GetLoss(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const override
Compute the path loss according to the nodes position using the appropriate model.
Ptr< ItuR1238PropagationLossModel > m_ituR1238
ItuR1238PropagationLossModel.
mobility buildings information (to be used by mobility models)
double GetDistanceFrom(Ptr< const MobilityModel > position) const
Vector GetPosition() const
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: double.h:43
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: enum.h:205
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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
EnvironmentType
The type of propagation environment.
CitySize
The size of the city in which propagation takes place.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:163