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 "ns3/double.h"
24#include "ns3/enum.h"
25#include "ns3/log.h"
26#include "ns3/mobility-model.h"
27#include <ns3/mobility-building-info.h>
28
29#include <cmath>
30
31namespace ns3
32{
33
34NS_LOG_COMPONENT_DEFINE("ItuR1238PropagationLossModel");
35
36NS_OBJECT_ENSURE_REGISTERED(ItuR1238PropagationLossModel);
37
38TypeId
40{
41 static TypeId tid =
42 TypeId("ns3::ItuR1238PropagationLossModel")
43
45 .SetGroupName("Buildings")
46
47 .AddAttribute("Frequency",
48 "The Frequency (default is 2.106 GHz).",
49 DoubleValue(2160e6),
51 MakeDoubleChecker<double>());
52
53 return tid;
54}
55
56double
58{
59 NS_LOG_FUNCTION(this << a1 << b1);
62 NS_ASSERT_MSG(a && b, "ItuR1238PropagationLossModel only works with MobilityBuildingInfo");
63 NS_ASSERT_MSG(a->GetBuilding()->GetId() == b->GetBuilding()->GetId(),
64 "ITU-R 1238 applies only to nodes that are in the same building");
65 double N = 0.0;
66 int n = std::abs(a->GetFloorNumber() - b->GetFloorNumber());
67 NS_LOG_LOGIC(this << " A floor " << (uint16_t)a->GetFloorNumber() << " B floor "
68 << (uint16_t)b->GetFloorNumber() << " n " << n);
69 double Lf = 0.0;
70 Ptr<Building> aBuilding = a->GetBuilding();
71 if (aBuilding->GetBuildingType() == Building::Residential)
72 {
73 N = 28;
74 if (n >= 1)
75 {
76 Lf = 4 * n;
77 }
78 NS_LOG_LOGIC(this << " Residential ");
79 }
80 else if (aBuilding->GetBuildingType() == Building::Office)
81 {
82 N = 30;
83 if (n >= 1)
84 {
85 Lf = 15 + (4 * (n - 1));
86 }
87 NS_LOG_LOGIC(this << " Office ");
88 }
89 else if (aBuilding->GetBuildingType() == Building::Commercial)
90 {
91 N = 22;
92 if (n >= 1)
93 {
94 Lf = 6 + (3 * (n - 1));
95 }
96 NS_LOG_LOGIC(this << " Commercial ");
97 }
98 else
99 {
100 NS_LOG_ERROR(this << " Unkwnon Wall Type");
101 }
102 double loss = 20 * std::log10(m_frequency / 1e6 /*MHz*/) +
103 N * std::log10(a1->GetDistanceFrom(b1)) + Lf - 28.0;
104 NS_LOG_INFO(this << " Node " << a1->GetPosition() << " <-> " << b1->GetPosition()
105 << " loss = " << loss << " dB");
106
107 return loss;
108}
109
110double
113 Ptr<MobilityModel> b) const
114{
115 return (txPowerDbm - GetLoss(a, b));
116}
117
118int64_t
120{
121 return 0;
122}
123
124} // 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:935
#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
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43
#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.