A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("ItuR1238PropagationLossModel");
32 
33 namespace ns3 {
34 
35 NS_OBJECT_ENSURE_REGISTERED (ItuR1238PropagationLossModel)
36  ;
37 
38 
39 TypeId
41 {
42  static TypeId tid = TypeId ("ns3::ItuR1238PropagationLossModel")
43 
45 
46  .AddAttribute ("Frequency",
47  "The Frequency (default is 2.106 GHz).",
48  DoubleValue (2160e6),
49  MakeDoubleAccessor (&ItuR1238PropagationLossModel::m_frequency),
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)
Definition: log.h:345
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
double GetDistanceFrom(Ptr< const MobilityModel > position) const
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
Vector GetPosition(void) const
#define NS_LOG_INFO(msg)
Definition: log.h:298
double GetLoss(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
Modelize the propagation loss through a transmission medium.
NS_LOG_COMPONENT_DEFINE("ItuR1238PropagationLossModel")
mobility buildings information (to be used by mobility models)
#define NS_LOG_ERROR(msg)
Definition: log.h:271
Hold a floating point type.
Definition: double.h:41
Ptr< T > GetObject(void) const
Definition: object.h:361
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611