A Discrete-Event Network Simulator
API
itu-r-1238-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, 2012 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 #include "ns3/log.h"
23 #include "ns3/double.h"
24 #include "ns3/enum.h"
25 #include "ns3/mobility-model.h"
26 #include <cmath>
27 
29 #include <ns3/mobility-building-info.h>
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("ItuR1238PropagationLossModel");
34 
35 NS_OBJECT_ENSURE_REGISTERED (ItuR1238PropagationLossModel);
36 
37 
38 TypeId
40 {
41  static TypeId tid = TypeId ("ns3::ItuR1238PropagationLossModel")
42 
44  .SetGroupName ("Buildings")
45 
46  .AddAttribute ("Frequency",
47  "The Frequency (default is 2.106 GHz).",
48  DoubleValue (2160e6),
50  MakeDoubleChecker<double> ());
51 
52  return tid;
53 }
54 
55 double
57 {
58  NS_LOG_FUNCTION (this << a1 << b1);
61  NS_ASSERT_MSG ((a != 0) && (b != 0), "ItuR1238PropagationLossModel only works with MobilityBuildingInfo");
62  NS_ASSERT_MSG (a->GetBuilding ()->GetId () == b->GetBuilding ()->GetId (), "ITU-R 1238 applies only to nodes that are in the same building");
63  double N = 0.0;
64  int n = std::abs (a->GetFloorNumber () - b->GetFloorNumber ());
65  NS_LOG_LOGIC (this << " A floor " << (uint16_t)a->GetFloorNumber () << " B floor " << (uint16_t)b->GetFloorNumber () << " n " << n);
66  double Lf = 0.0;
67  Ptr<Building> aBuilding = a->GetBuilding ();
68  if (aBuilding->GetBuildingType () == Building::Residential)
69  {
70  N = 28;
71  if (n >= 1)
72  {
73  Lf = 4 * n;
74  }
75  NS_LOG_LOGIC (this << " Residential ");
76  }
77  else if (aBuilding->GetBuildingType () == Building::Office)
78  {
79  N = 30;
80  if (n >= 1)
81  {
82  Lf = 15 + (4 * (n - 1));
83  }
84  NS_LOG_LOGIC (this << " Office ");
85  }
86  else if (aBuilding->GetBuildingType () == Building::Commercial)
87  {
88  N = 22;
89  if (n >= 1)
90  {
91  Lf = 6 + (3 * (n - 1));
92  }
93  NS_LOG_LOGIC (this << " Commercial ");
94  }
95  else
96  {
97  NS_LOG_ERROR (this << " Unkwnon Wall Type");
98  }
99  double loss = 20 * std::log10 (m_frequency / 1e6 /*MHz*/) + N * std::log10 (a1->GetDistanceFrom (b1)) + Lf - 28.0;
100  NS_LOG_INFO (this << " Node " << a1->GetPosition () << " <-> " << b1->GetPosition () << " loss = " << loss << " dB");
101 
102  return loss;
103 }
104 
105 
106 double
109  Ptr<MobilityModel> b) const
110 {
111  return (txPowerDbm - GetLoss (a, b));
112 }
113 
114 
115 int64_t
117 {
118  return 0;
119 }
120 
121 
122 } // namespace ns3
virtual int64_t DoAssignStreams(int64_t stream)
Subclasses must implement this; those not using random variables can return zero. ...
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account only the particular PropagatinLossModel. ...
double GetDistanceFrom(Ptr< const MobilityModel > position) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Vector GetPosition(void) const
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
double GetLoss(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
NS_ASSERT_MSG(false,"Ipv4AddressGenerator::MaskToIndex(): Impossible")
Every class exported by the ns3 library is enclosed in the ns3 namespace.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
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
Models the propagation loss through a transmission medium.
mobility buildings information (to be used by mobility models)
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
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