A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
itu-r-1411-los-propagation-loss-model.cc
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 
28 #include "itu-r-1411-los-propagation-loss-model.h"
29 
30 NS_LOG_COMPONENT_DEFINE ("ItuR1411LosPropagationLossModel");
31 
32 namespace ns3 {
33 
34 NS_OBJECT_ENSURE_REGISTERED (ItuR1411LosPropagationLossModel);
35 
36 TypeId
37 ItuR1411LosPropagationLossModel::GetTypeId (void)
38 {
39  static TypeId tid = TypeId ("ns3::ItuR1411LosPropagationLossModel")
40 
41  .SetParent<PropagationLossModel> ()
42 
43  .AddAttribute ("Frequency",
44  "The propagation frequency in Hz",
45  DoubleValue (2160e6),
47  MakeDoubleChecker<double> ());
48 
49  return tid;
50 }
51 
52 double
54 {
55  NS_LOG_FUNCTION (this);
56  double dist = a->GetDistanceFrom (b);
57  double lossLow = 0.0;
58  double lossUp = 0.0;
59  NS_ASSERT_MSG (a->GetPosition ().z > 0 && b->GetPosition ().z > 0, "nodes' height must be greater than 0");
60  double Lbp = std::fabs (20 * std::log10 ((m_lambda * m_lambda) / (8 * M_PI * a->GetPosition ().z * b->GetPosition ().z)));
61  double Rbp = (4 * a->GetPosition ().z * b->GetPosition ().z) / m_lambda;
62  NS_LOG_LOGIC (this << " Lbp " << Lbp << " Rbp " << Rbp << " lambda " << m_lambda);
63  if (dist <= Rbp)
64  {
65  lossLow = Lbp + 20 * std::log10 (dist / Rbp);
66  lossUp = Lbp + 20 + 25 * std::log10 (dist / Rbp);
67  }
68  else
69  {
70  lossLow = Lbp + 40 * std::log10 (dist / Rbp);
71  lossUp = Lbp + 20 + 40 * std::log10 (dist / Rbp);
72  }
73 
74  double loss = (lossUp + lossLow) / 2;
75 
76  return loss;
77 }
78 
79 
80 void
82 {
83  NS_ASSERT (freq > 0.0);
84  m_lambda = 299792458.0 / freq;
85 }
86 
87 
88 double
89 ItuR1411LosPropagationLossModel::DoCalcRxPower (double txPowerDbm,
91  Ptr<MobilityModel> b) const
92 {
93  return (txPowerDbm - GetLoss (a, b));
94 }
95 
96 int64_t
98 {
99  return 0;
100 }
101 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
double GetDistanceFrom(Ptr< const MobilityModel > position) const
#define NS_ASSERT(condition)
Definition: assert.h:64
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
Vector GetPosition(void) const
double GetLoss(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
#define NS_LOG_LOGIC(msg)
Definition: log.h:334
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
double z
Definition: vector.h:57