A Discrete-Event Network Simulator
API
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 "ns3/propagation-loss-model.h"
24 #include "ns3/log.h"
25 #include "ns3/mobility-model.h"
26 #include "ns3/double.h"
27 #include "ns3/pointer.h"
28 #include <cmath>
30 #include <ns3/mobility-building-info.h>
31 #include "ns3/enum.h"
32 
33 
34 namespace ns3 {
35 
36 NS_LOG_COMPONENT_DEFINE ("BuildingsPropagationLossModel");
37 
38 NS_OBJECT_ENSURE_REGISTERED (BuildingsPropagationLossModel);
39 
41 {
42 }
43 
45  : m_shadowingValue (shadowingValue), m_receiver (receiver)
46 {
47  NS_LOG_INFO (this << " New Shadowing value " << m_shadowingValue);
48 }
49 
50 double
52 {
53  return (m_shadowingValue);
54 }
55 
58 {
59  return m_receiver;
60 }
61 
62 TypeId
64 {
65  static TypeId tid = TypeId ("ns3::BuildingsPropagationLossModel")
66 
68  .SetGroupName ("Buildings")
69 
70 
71  .AddAttribute ("ShadowSigmaOutdoor",
72  "Standard deviation of the normal distribution used for calculate the shadowing for outdoor nodes",
73  DoubleValue (7.0),
75  MakeDoubleChecker<double> ())
76 
77  .AddAttribute ("ShadowSigmaIndoor",
78  "Standard deviation of the normal distribution used for calculate the shadowing for indoor nodes ",
79  DoubleValue (8.0),
81  MakeDoubleChecker<double> ())
82  .AddAttribute ("ShadowSigmaExtWalls",
83  "Standard deviation of the normal distribution used for calculate the shadowing due to ext walls ",
84  DoubleValue (5.0),
86  MakeDoubleChecker<double> ())
87 
88  .AddAttribute ("InternalWallLoss",
89  "Additional loss for each internal wall [dB]",
90  DoubleValue (5.0),
92  MakeDoubleChecker<double> ());
93 
94 
95  return tid;
96 }
97 
99 {
100  m_randVariable = CreateObject<NormalRandomVariable> ();
101 }
102 
103 double
105 {
106  double loss = 0.0;
107  Ptr<Building> aBuilding = a->GetBuilding ();
108  if (aBuilding->GetExtWallsType () == Building::Wood)
109  {
110  loss = 4;
111  }
112  else if (aBuilding->GetExtWallsType () == Building::ConcreteWithWindows)
113  {
114  loss = 7;
115  }
116  else if (aBuilding->GetExtWallsType () == Building::ConcreteWithoutWindows)
117  {
118  loss = 15; // 10 ~ 20 dB
119  }
120  else if (aBuilding->GetExtWallsType () == Building::StoneBlocks)
121  {
122  loss = 12;
123  }
124  return (loss);
125 }
126 
127 double
129 {
130  double loss = 0.0;
131 
132  int nfloors = node->GetFloorNumber () - 1;
133  loss = -2 * (nfloors);
134  return (loss);
135 }
136 
137 double
139 {
140  // approximate the number of internal walls with the Manhattan distance in "rooms" units
141  double dx = std::abs (a->GetRoomNumberX () - b->GetRoomNumberX ());
142  double dy = std::abs (a->GetRoomNumberY () - b->GetRoomNumberY ());
143  return m_lossInternalWall * (dx+dy);
144 }
145 
146 
147 
148 double
150 const
151 {
154  NS_ASSERT_MSG ((a1 != 0) && (b1 != 0), "BuildingsPropagationLossModel only works with MobilityBuildingInfo");
155 
156  std::map<Ptr<MobilityModel>, std::map<Ptr<MobilityModel>, ShadowingLoss> >::iterator ait = m_shadowingLossMap.find (a);
157  if (ait != m_shadowingLossMap.end ())
158  {
159  std::map<Ptr<MobilityModel>, ShadowingLoss>::iterator bit = ait->second.find (b);
160  if (bit != ait->second.end ())
161  {
162  return (bit->second.GetLoss ());
163  }
164  else
165  {
166  double sigma = EvaluateSigma (a1, b1);
167  // side effect: will create new entry
168  // sigma is standard deviation, not variance
169  double shadowingValue = m_randVariable->GetValue (0.0, (sigma*sigma));
170  ait->second[b] = ShadowingLoss (shadowingValue, b);
171  return (ait->second[b].GetLoss ());
172  }
173  }
174  else
175  {
176  double sigma = EvaluateSigma (a1, b1);
177  // side effect: will create new entries in both maps
178  // sigma is standard deviation, not variance
179  double shadowingValue = m_randVariable->GetValue (0.0, (sigma*sigma));
180  m_shadowingLossMap[a][b] = ShadowingLoss (shadowingValue, b);
181  return (m_shadowingLossMap[a][b].GetLoss ());
182  }
183 }
184 
185 
186 
187 double
189 const
190 {
191  if (a->IsOutdoor ())
192  {
193  if (b->IsOutdoor ())
194  {
195  return (m_shadowingSigmaOutdoor);
196  }
197  else
198  {
200  return (sigma);
201  }
202  }
203  else
204  if (b->IsIndoor ())
205  {
206  return (m_shadowingSigmaIndoor);
207  }
208  else
209  {
211  return (sigma);
212  }
213 }
214 
215 
216 double
218 {
219  return txPowerDbm - GetLoss (a, b) - GetShadowing (a, b);
220 }
221 
222 int64_t
224 {
225  m_randVariable->SetStream (stream);
226  return 1;
227 }
228 
229 
230 } // namespace ns3
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account only the particular PropagationLossModel.
#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 EvaluateSigma(Ptr< MobilityBuildingInfo > a, Ptr< MobilityBuildingInfo > b) const
#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
virtual double GetLoss(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const =0
std::map< Ptr< MobilityModel >, std::map< Ptr< MobilityModel >, ShadowingLoss > > m_shadowingLossMap
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
Models the propagation loss through a transmission medium.
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 GetShadowing(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero. ...