A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("HybridBuildingsPropagationLossModel");
41 
42 namespace ns3 {
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 
70  .AddAttribute ("Frequency",
71  "The Frequency (default is 2.106 GHz).",
72  DoubleValue (2160e6),
74  MakeDoubleChecker<double> ())
75 
76  .AddAttribute ("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  SubUrbanEnvironment, "SubUrban",
88  OpenAreasEnvironment, "OpenAreas"))
89 
90  .AddAttribute ("CitySize",
91  "Dimension of the city",
94  MakeEnumChecker (SmallCity, "Small",
95  MediumCity, "Medium",
96  LargeCity, "Large"))
97 
98  .AddAttribute ("RooftopLevel",
99  "The height of the rooftop level in meters",
100  DoubleValue (20.0),
102  MakeDoubleChecker<double> (0.0, 90.0))
103 
104  ;
105 
106  return tid;
107 }
108 
109 void
111 {
112  m_okumuraHata->SetAttribute ("Environment", EnumValue (env));
113  m_ituR1411NlosOverRooftop->SetAttribute ("Environment", EnumValue (env));
114 }
115 
116 void
118 {
119  m_okumuraHata->SetAttribute ("CitySize", EnumValue (size));
120  m_ituR1411NlosOverRooftop->SetAttribute ("CitySize", EnumValue (size));
121 }
122 
123 void
125 {
126  m_okumuraHata->SetAttribute ("Frequency", DoubleValue (freq));
127  m_ituR1411Los->SetAttribute ("Frequency", DoubleValue (freq));
128  m_ituR1411NlosOverRooftop->SetAttribute ("Frequency", DoubleValue (freq));
129  m_ituR1238->SetAttribute ("Frequency", DoubleValue (freq));
130  m_frequency = freq;
131 }
132 
133 void
135 {
136  m_rooftopHeight = rooftopHeight;
137  m_ituR1411NlosOverRooftop->SetAttribute ("RooftopLevel", DoubleValue (rooftopHeight));
138 }
139 
140 
141 double
143 {
144  NS_ASSERT_MSG ((a->GetPosition ().z >= 0) && (b->GetPosition ().z >= 0), "HybridBuildingsPropagationLossModel does not support underground nodes (placed at z < 0)");
145 
146 
147  double distance = a->GetDistanceFrom (b);
148 
149  // get the MobilityBuildingInfo pointers
152  NS_ASSERT_MSG ((a1 != 0) && (b1 != 0), "HybridBuildingsPropagationLossModel only works with MobilityBuildingInfo");
153 
154  double loss = 0.0;
155 
156  if (a1->IsOutdoor ())
157  {
158  if (b1->IsOutdoor ())
159  {
160  if (distance > 1000)
161  {
162  NS_LOG_INFO (this << a->GetPosition ().z << b->GetPosition ().z << m_rooftopHeight);
163  if ((a->GetPosition ().z < m_rooftopHeight)
164  && (b->GetPosition ().z < m_rooftopHeight))
165  {
166  loss = ItuR1411 (a, b);
167  NS_LOG_INFO (this << " 0-0 (>1000): below rooftop -> ITUR1411 : " << loss);
168  }
169  else
170  {
171  // Over the rooftop tranmission -> Okumura Hata
172  loss = OkumuraHata (a, b);
173  NS_LOG_INFO (this << " O-O (>1000): above rooftop -> OH : " << loss);
174  }
175  }
176  else
177  {
178  // short range outdoor communication
179  loss = ItuR1411 (a, b);
180  NS_LOG_INFO (this << " 0-0 (<1000) Street canyon -> ITUR1411 : " << loss);
181  }
182  }
183  else
184  {
185  // b indoor
186  if (distance > 1000)
187  {
188  if ((a->GetPosition ().z < m_rooftopHeight)
189  && (b->GetPosition ().z < m_rooftopHeight))
190  {
191  loss = ItuR1411 (a, b) + ExternalWallLoss (b1) + HeightLoss (b1);
192  NS_LOG_INFO (this << " 0-I (>1000): below rooftop -> ITUR1411 : " << loss);
193  }
194  else
195  {
196  loss = OkumuraHata (a, b) + ExternalWallLoss (b1);
197  NS_LOG_INFO (this << " O-I (>1000): above the rooftop -> OH : " << loss);
198  }
199  }
200  else
201  {
202  loss = ItuR1411 (a, b) + ExternalWallLoss (b1) + HeightLoss (b1);
203  NS_LOG_INFO (this << " 0-I (<1000) ITUR1411 + BEL : " << loss);
204  }
205  } // end b1->isIndoor ()
206  }
207  else
208  {
209  // a is indoor
210  if (b1->IsIndoor ())
211  {
212  if (a1->GetBuilding () == b1->GetBuilding ())
213  {
214  // nodes are in same building -> indoor communication ITU-R P.1238
215  loss = ItuR1238 (a, b) + InternalWallsLoss (a1, b1);;
216  NS_LOG_INFO (this << " I-I (same building) ITUR1238 : " << loss);
217 
218  }
219  else
220  {
221  // nodes are in different buildings
222  loss = ItuR1411 (a, b) + ExternalWallLoss (a1) + ExternalWallLoss (b1);
223  NS_LOG_INFO (this << " I-I (different) ITUR1238 + 2*BEL : " << loss);
224  }
225  }
226  else
227  {
228  // b is outdoor
229  if (distance > 1000)
230  {
231  if ((a->GetPosition ().z < m_rooftopHeight)
232  && (b->GetPosition ().z < m_rooftopHeight))
233  {
234  loss = ItuR1411 (a, b) + ExternalWallLoss (a1) + HeightLoss (a1);
235  NS_LOG_INFO (this << " I-O (>1000): down rooftop -> ITUR1411 : " << loss);
236  }
237  else
238  {
239  // above rooftop -> OH
240  loss = OkumuraHata (a, b) + ExternalWallLoss (a1) + HeightLoss (a1);
241  NS_LOG_INFO (this << " =I-O (>1000) over rooftop OH + BEL + HG: " << loss);
242  }
243  }
244  else
245  {
246  loss = ItuR1411 (a, b) + ExternalWallLoss (a1) + HeightLoss (a1);
247  NS_LOG_INFO (this << " I-O (<1000) ITUR1411 + BEL + HG: " << loss);
248  }
249  } // end b1->IsIndoor ()
250  } // end a1->IsOutdoor ()
251 
252  loss = std::max (loss, 0.0);
253 
254  return loss;
255 }
256 
257 
258 double
260 {
261  if (m_frequency <= 2.3e9)
262  {
263  return m_okumuraHata->GetLoss (a, b);
264  }
265  else
266  {
267  return m_kun2600Mhz->GetLoss (a, b);
268  }
269 }
270 
271 double
273 {
275  {
276  return (m_ituR1411Los->GetLoss (a, b));
277  }
278  else
279  {
280  return (m_ituR1411NlosOverRooftop->GetLoss (a, b));
281  }
282 }
283 
284 double
286 {
287  return m_ituR1238->GetLoss (a,b);
288 }
289 
290 
291 } // namespace ns3
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)
Definition: enum.cc:178
void SetEnvironment(EnvironmentType env)
set the environment type
EnvironmentType
The type of propagation environment.
void SetFrequency(double freq)
set the propagation frequency
double GetDistanceFrom(Ptr< const MobilityModel > position) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
double ItuR1411(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
virtual double GetLoss(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
Vector GetPosition(void) const
double HeightLoss(Ptr< MobilityBuildingInfo > n) const
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:223
This model provides means for simulating the following propagation phenomena in the presence of build...
double OkumuraHata(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
hold variables of type 'enum'
Definition: enum.h:37
Ptr< ItuR1411NlosOverRooftopPropagationLossModel > m_ituR1411NlosOverRooftop
double ItuR1238(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
void SetRooftopHeight(double rooftopHeight)
set the rooftop height
void SetCitySize(CitySize size)
set the size of the city
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition: enum.h:118
#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:84
CitySize
The size of the city in which propagation takes place.
mobility buildings information (to be used by mobility models)
double ExternalWallLoss(Ptr< MobilityBuildingInfo > a) const
Hold a floating point type.
Definition: double.h:41
Ptr< T > GetObject(void) const
Definition: object.h:362
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
double InternalWallsLoss(Ptr< MobilityBuildingInfo > a, Ptr< MobilityBuildingInfo > b) const
double z
z coordinate of vector
Definition: vector.h:57