A Discrete-Event Network Simulator
API
hybrid-buildings-propagation-loss-model.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Marco Miozzo <marco.miozzo@cttc.es>
19  * Nicola Baldo <nbaldo@cttc.es>
20  *
21  */
22 
23 #include <cmath>
24 
25 #include "ns3/log.h"
26 #include "ns3/mobility-model.h"
27 #include "ns3/double.h"
28 #include "ns3/pointer.h"
29 #include "ns3/okumura-hata-propagation-loss-model.h"
30 #include "ns3/itu-r-1411-los-propagation-loss-model.h"
31 #include "ns3/itu-r-1411-nlos-over-rooftop-propagation-loss-model.h"
32 #include "ns3/itu-r-1238-propagation-loss-model.h"
33 #include "ns3/kun-2600-mhz-propagation-loss-model.h"
34 #include <ns3/mobility-building-info.h>
35 #include "ns3/enum.h"
36 
38 
39 
40 namespace ns3 {
41 
42 NS_LOG_COMPONENT_DEFINE ("HybridBuildingsPropagationLossModel");
43 
44 NS_OBJECT_ENSURE_REGISTERED (HybridBuildingsPropagationLossModel);
45 
46 
47 
49 {
50  m_okumuraHata = CreateObject<OkumuraHataPropagationLossModel> ();
51  m_ituR1411Los = CreateObject<ItuR1411LosPropagationLossModel> ();
52  m_ituR1411NlosOverRooftop = CreateObject<ItuR1411NlosOverRooftopPropagationLossModel> ();
53  m_ituR1238 = CreateObject<ItuR1238PropagationLossModel> ();
54  m_kun2600Mhz = CreateObject<Kun2600MhzPropagationLossModel> ();
55 }
56 
58 {
59 }
60 
61 TypeId
63 {
64  static TypeId tid = TypeId ("ns3::HybridBuildingsPropagationLossModel")
65 
67 
68  .AddConstructor<HybridBuildingsPropagationLossModel> ()
69  .SetGroupName ("Buildings")
70 
71  .AddAttribute ("Frequency",
72  "The Frequency (default is 2.106 GHz).",
73  DoubleValue (2160e6),
75  MakeDoubleChecker<double> ())
76 
77  .AddAttribute ("Los2NlosThr",
78  " Threshold from LoS to NLoS in ITU 1411 [m].",
79  DoubleValue (200.0),
81  MakeDoubleChecker<double> ())
82 
83  .AddAttribute ("Environment",
84  "Environment Scenario",
88  SubUrbanEnvironment, "SubUrban",
89  OpenAreasEnvironment, "OpenAreas"))
90 
91  .AddAttribute ("CitySize",
92  "Dimension of the city",
95  MakeEnumChecker (SmallCity, "Small",
96  MediumCity, "Medium",
97  LargeCity, "Large"))
98 
99  .AddAttribute ("RooftopLevel",
100  "The height of the rooftop level in meters",
101  DoubleValue (20.0),
103  MakeDoubleChecker<double> (0.0, 90.0))
104 
105  ;
106 
107  return tid;
108 }
109 
110 void
112 {
113  m_okumuraHata->SetAttribute ("Environment", EnumValue (env));
114  m_ituR1411NlosOverRooftop->SetAttribute ("Environment", EnumValue (env));
115 }
116 
117 void
119 {
120  m_okumuraHata->SetAttribute ("CitySize", EnumValue (size));
121  m_ituR1411NlosOverRooftop->SetAttribute ("CitySize", EnumValue (size));
122 }
123 
124 void
126 {
127  m_okumuraHata->SetAttribute ("Frequency", DoubleValue (freq));
128  m_ituR1411Los->SetAttribute ("Frequency", DoubleValue (freq));
129  m_ituR1411NlosOverRooftop->SetAttribute ("Frequency", DoubleValue (freq));
130  m_ituR1238->SetAttribute ("Frequency", DoubleValue (freq));
131  m_frequency = freq;
132 }
133 
134 void
136 {
137  m_rooftopHeight = rooftopHeight;
138  m_ituR1411NlosOverRooftop->SetAttribute ("RooftopLevel", DoubleValue (rooftopHeight));
139 }
140 
141 
142 double
144 {
145  NS_ASSERT_MSG ((a->GetPosition ().z >= 0) && (b->GetPosition ().z >= 0), "HybridBuildingsPropagationLossModel does not support underground nodes (placed at z < 0)");
146 
147 
148  double distance = a->GetDistanceFrom (b);
149 
150  // get the MobilityBuildingInfo pointers
153  NS_ASSERT_MSG ((a1 != 0) && (b1 != 0), "HybridBuildingsPropagationLossModel only works with MobilityBuildingInfo");
154 
155  double loss = 0.0;
156 
157  if (a1->IsOutdoor ())
158  {
159  if (b1->IsOutdoor ())
160  {
161  if (distance > 1000)
162  {
163  NS_LOG_INFO (this << a->GetPosition ().z << b->GetPosition ().z << m_rooftopHeight);
164  if ((a->GetPosition ().z < m_rooftopHeight)
165  && (b->GetPosition ().z < m_rooftopHeight))
166  {
167  loss = ItuR1411 (a, b);
168  NS_LOG_INFO (this << " 0-0 (>1000): below rooftop -> ITUR1411 : " << loss);
169  }
170  else
171  {
172  // Over the rooftop tranmission -> Okumura Hata
173  loss = OkumuraHata (a, b);
174  NS_LOG_INFO (this << " O-O (>1000): above rooftop -> OH : " << loss);
175  }
176  }
177  else
178  {
179  // short range outdoor communication
180  loss = ItuR1411 (a, b);
181  NS_LOG_INFO (this << " 0-0 (<1000) Street canyon -> ITUR1411 : " << loss);
182  }
183  }
184  else
185  {
186  // b indoor
187  if (distance > 1000)
188  {
189  if ((a->GetPosition ().z < m_rooftopHeight)
190  && (b->GetPosition ().z < m_rooftopHeight))
191  {
192  loss = ItuR1411 (a, b) + ExternalWallLoss (b1) + HeightLoss (b1);
193  NS_LOG_INFO (this << " 0-I (>1000): below rooftop -> ITUR1411 : " << loss);
194  }
195  else
196  {
197  loss = OkumuraHata (a, b) + ExternalWallLoss (b1);
198  NS_LOG_INFO (this << " O-I (>1000): above the rooftop -> OH : " << loss);
199  }
200  }
201  else
202  {
203  loss = ItuR1411 (a, b) + ExternalWallLoss (b1) + HeightLoss (b1);
204  NS_LOG_INFO (this << " 0-I (<1000) ITUR1411 + BEL : " << loss);
205  }
206  } // end b1->isIndoor ()
207  }
208  else
209  {
210  // a is indoor
211  if (b1->IsIndoor ())
212  {
213  if (a1->GetBuilding () == b1->GetBuilding ())
214  {
215  // nodes are in same building -> indoor communication ITU-R P.1238
216  loss = ItuR1238 (a, b) + InternalWallsLoss (a1, b1);;
217  NS_LOG_INFO (this << " I-I (same building) ITUR1238 : " << loss);
218 
219  }
220  else
221  {
222  // nodes are in different buildings
223  loss = ItuR1411 (a, b) + ExternalWallLoss (a1) + ExternalWallLoss (b1);
224  NS_LOG_INFO (this << " I-I (different) ITUR1238 + 2*BEL : " << loss);
225  }
226  }
227  else
228  {
229  // b is outdoor
230  if (distance > 1000)
231  {
232  if ((a->GetPosition ().z < m_rooftopHeight)
233  && (b->GetPosition ().z < m_rooftopHeight))
234  {
235  loss = ItuR1411 (a, b) + ExternalWallLoss (a1) + HeightLoss (a1);
236  NS_LOG_INFO (this << " I-O (>1000): down rooftop -> ITUR1411 : " << loss);
237  }
238  else
239  {
240  // above rooftop -> OH
241  loss = OkumuraHata (a, b) + ExternalWallLoss (a1) + HeightLoss (a1);
242  NS_LOG_INFO (this << " =I-O (>1000) over rooftop OH + BEL + HG: " << loss);
243  }
244  }
245  else
246  {
247  loss = ItuR1411 (a, b) + ExternalWallLoss (a1) + HeightLoss (a1);
248  NS_LOG_INFO (this << " I-O (<1000) ITUR1411 + BEL + HG: " << loss);
249  }
250  } // end b1->IsIndoor ()
251  } // end a1->IsOutdoor ()
252 
253  loss = std::max (loss, 0.0);
254 
255  return loss;
256 }
257 
258 
259 double
261 {
262  if (m_frequency <= 2.3e9)
263  {
264  return m_okumuraHata->GetLoss (a, b);
265  }
266  else
267  {
268  return m_kun2600Mhz->GetLoss (a, b);
269  }
270 }
271 
272 double
274 {
276  {
277  return (m_ituR1411Los->GetLoss (a, b));
278  }
279  else
280  {
281  return (m_ituR1411NlosOverRooftop->GetLoss (a, b));
282  }
283 }
284 
285 double
287 {
288  return m_ituR1238->GetLoss (a,b);
289 }
290 
291 
292 } // namespace ns3
void SetEnvironment(EnvironmentType env)
set the environment type
EnvironmentType
The type of propagation environment.
void SetFrequency(double freq)
set the propagation frequency
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
double OkumuraHata(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
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:209
#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:278
double HeightLoss(Ptr< MobilityBuildingInfo > n) const
This model provides means for simulating the following propagation phenomena in the presence of build...
virtual double GetLoss(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Hold variables of type enum.
Definition: enum.h:54
#define max(a, b)
Definition: 80211b.c:43
Ptr< ItuR1411NlosOverRooftopPropagationLossModel > m_ituR1411NlosOverRooftop
double ItuR1238(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
double GetDistanceFrom(Ptr< const MobilityModel > position) const
void SetRooftopHeight(double rooftopHeight)
set the rooftop height
void SetCitySize(CitySize size)
set the size of the city
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double ExternalWallLoss(Ptr< MobilityBuildingInfo > a) const
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:42
double InternalWallsLoss(Ptr< MobilityBuildingInfo > a, Ptr< MobilityBuildingInfo > b) const
Vector GetPosition(void) const
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.cc:184
CitySize
The size of the city in which propagation takes place.
mobility buildings information (to be used by mobility models)
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
double ItuR1411(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const