A Discrete-Event Network Simulator
API
buildings-channel-condition-model.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015, NYU WIRELESS, Tandon School of Engineering, New York
4  * University
5  * Copyright (c) 2019 SIGNET Lab, Department of Information Engineering,
6  * University of Padova
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation;
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */
21 
22 #include "ns3/buildings-channel-condition-model.h"
23 #include "ns3/mobility-model.h"
24 #include "ns3/mobility-building-info.h"
25 #include "ns3/building-list.h"
26 #include "ns3/log.h"
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("BuildingsChannelConditionModel");
31 
32 NS_OBJECT_ENSURE_REGISTERED (BuildingsChannelConditionModel);
33 
34 TypeId
36 {
37  static TypeId tid = TypeId ("ns3::BuildingsChannelConditionModel")
39  .SetGroupName ("Buildings")
40  .AddConstructor<BuildingsChannelConditionModel> ()
41  ;
42  return tid;
43 }
44 
47 {
48 }
49 
51 {
52 }
53 
57 {
58  Ptr<MobilityBuildingInfo> a1 = a->GetObject<MobilityBuildingInfo> ();
59  Ptr<MobilityBuildingInfo> b1 = b->GetObject<MobilityBuildingInfo> ();
60  NS_ASSERT_MSG ((a1 != nullptr) && (b1 != nullptr),
61  "BuildingsChannelConditionModel only works with MobilityBuildingInfo");
62 
63  Ptr<ChannelCondition> cond = CreateObject<ChannelCondition> ();
64 
65  bool isAIndoor = a1->IsIndoor ();
66  bool isBIndoor = b1->IsIndoor ();
67 
68 
69  if (!isAIndoor && !isBIndoor) // a and b are outdoor
70  {
71  // The outdoor case, determine LOS/NLOS
72  // The channel condition should be LOS if the line of sight is not blocked,
73  // otherwise NLOS
74  bool blocked = IsLineOfSightBlocked (a->GetPosition (), b->GetPosition ());
75  if (!blocked)
76  {
77  cond->SetLosCondition (ChannelCondition::LosConditionValue::LOS);
78  }
79  else
80  {
81  cond->SetLosCondition (ChannelCondition::LosConditionValue::NLOS);
82  }
83 
84  }
85  else if (isAIndoor && isBIndoor) // a and b are indoor
86  {
87  // Indoor case, determine is the two nodes are inside the same building
88  // or not
89  if (a1->GetBuilding () == b1->GetBuilding ())
90  {
91  cond->SetLosCondition (ChannelCondition::LosConditionValue::LOS);
92  }
93  else
94  {
95  cond->SetLosCondition (ChannelCondition::LosConditionValue::NLOS);
96  }
97  }
98  else //outdoor to indoor case
99  {
100  cond->SetLosCondition (ChannelCondition::LosConditionValue::NLOS);
101  }
102 
103  return cond;
104 }
105 
106 bool
107 BuildingsChannelConditionModel::IsLineOfSightBlocked (const ns3::Vector &l1, const ns3::Vector &l2) const
108 {
109  for (BuildingList::Iterator bit = BuildingList::Begin (); bit != BuildingList::End (); ++bit)
110  {
111  if ((*bit)->IsIntersect (l1, l2))
112  {
113  // The line of sight should be blocked if the line-segment between
114  // l1 and l2 intersects one of the buildings.
115  return true;
116  }
117  }
118 
119  // The line of sight should not be blocked if the line-segment between
120  // l1 and l2 did not intersect any building.
121  return false;
122 }
123 
124 int64_t
126 {
127  NS_UNUSED (stream);
128  return 0;
129 }
130 
131 } // end namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Models the channel condition.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
static Iterator End(void)
static Iterator Begin(void)
static TypeId GetTypeId(void)
Get the type ID.
std::vector< Ptr< Building > >::const_iterator Iterator
Definition: building-list.h:36
Determines the channel condition based on the buildings deployed in the scenario. ...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual int64_t AssignStreams(int64_t stream) override
If this model uses objects of type RandomVariableStream, set the stream numbers to the integers start...
virtual Ptr< ChannelCondition > GetChannelCondition(Ptr< const MobilityModel > a, Ptr< const MobilityModel > b) const override
Computes the condition of the channel between a and b.
#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:88
bool IsLineOfSightBlocked(const Vector &l1, const Vector &l2) const
Checks if the line of sight between position l1 and position l2 is blocked by a building.
mobility buildings information (to be used by mobility models)
virtual ~BuildingsChannelConditionModel() override
Destructor for the BuildingsChannelConditionModel class.
BuildingsChannelConditionModel()
Constructor for the BuildingsChannelConditionModel class.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923