A Discrete-Event Network Simulator
API
itu-r-1238-propagation-loss-model.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, 2012 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  */
22 
23 #include "mobility-building-info.h"
24 
25 #include "ns3/double.h"
26 #include "ns3/enum.h"
27 #include "ns3/log.h"
28 #include "ns3/mobility-model.h"
29 
30 #include <cmath>
31 
32 namespace ns3
33 {
34 
35 NS_LOG_COMPONENT_DEFINE("ItuR1238PropagationLossModel");
36 
37 NS_OBJECT_ENSURE_REGISTERED(ItuR1238PropagationLossModel);
38 
39 TypeId
41 {
42  static TypeId tid =
43  TypeId("ns3::ItuR1238PropagationLossModel")
44 
46  .SetGroupName("Buildings")
47 
48  .AddAttribute("Frequency",
49  "The Frequency (default is 2.106 GHz).",
50  DoubleValue(2160e6),
52  MakeDoubleChecker<double>());
53 
54  return tid;
55 }
56 
57 double
59 {
60  NS_LOG_FUNCTION(this << a1 << b1);
63  NS_ASSERT_MSG(a && b, "ItuR1238PropagationLossModel only works with MobilityBuildingInfo");
64  NS_ASSERT_MSG(a->GetBuilding()->GetId() == b->GetBuilding()->GetId(),
65  "ITU-R 1238 applies only to nodes that are in the same building");
66  double N = 0.0;
67  int n = std::abs(a->GetFloorNumber() - b->GetFloorNumber());
68  NS_LOG_LOGIC(this << " A floor " << (uint16_t)a->GetFloorNumber() << " B floor "
69  << (uint16_t)b->GetFloorNumber() << " n " << n);
70  double Lf = 0.0;
71  Ptr<Building> aBuilding = a->GetBuilding();
72  if (aBuilding->GetBuildingType() == Building::Residential)
73  {
74  N = 28;
75  if (n >= 1)
76  {
77  Lf = 4 * n;
78  }
79  NS_LOG_LOGIC(this << " Residential ");
80  }
81  else if (aBuilding->GetBuildingType() == Building::Office)
82  {
83  N = 30;
84  if (n >= 1)
85  {
86  Lf = 15 + (4 * (n - 1));
87  }
88  NS_LOG_LOGIC(this << " Office ");
89  }
90  else if (aBuilding->GetBuildingType() == Building::Commercial)
91  {
92  N = 22;
93  if (n >= 1)
94  {
95  Lf = 6 + (3 * (n - 1));
96  }
97  NS_LOG_LOGIC(this << " Commercial ");
98  }
99  else
100  {
101  NS_LOG_ERROR(this << " Unkwnon Wall Type");
102  }
103  double loss = 20 * std::log10(m_frequency / 1e6 /*MHz*/) +
104  N * std::log10(a1->GetDistanceFrom(b1)) + Lf - 28.0;
105  NS_LOG_INFO(this << " Node " << a1->GetPosition() << " <-> " << b1->GetPosition()
106  << " loss = " << loss << " dB");
107 
108  return loss;
109 }
110 
111 double
114  Ptr<MobilityModel> b) const
115 {
116  return (txPowerDbm - GetLoss(a, b));
117 }
118 
119 int64_t
121 {
122  return 0;
123 }
124 
125 } // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
double GetLoss(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const override
PropagationLossModel.
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
Models the propagation loss through a transmission medium.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#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
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43