A Discrete-Event Network Simulator
API
buildings-channel-condition-model.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, NYU WIRELESS, Tandon School of Engineering, New York
3  * University
4  * Copyright (c) 2019 SIGNET Lab, Department of Information Engineering,
5  * University of Padova
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation;
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
22 
23 #include "building-list.h"
24 #include "mobility-building-info.h"
25 
26 #include "ns3/log.h"
27 #include "ns3/mobility-model.h"
28 
29 namespace ns3
30 {
31 
32 NS_LOG_COMPONENT_DEFINE("BuildingsChannelConditionModel");
33 
34 NS_OBJECT_ENSURE_REGISTERED(BuildingsChannelConditionModel);
35 
36 TypeId
38 {
39  static TypeId tid = TypeId("ns3::BuildingsChannelConditionModel")
41  .SetGroupName("Buildings")
42  .AddConstructor<BuildingsChannelConditionModel>();
43  return tid;
44 }
45 
48 {
49 }
50 
52 {
53 }
54 
58 {
59  NS_LOG_FUNCTION(this);
62  NS_ASSERT_MSG(a1 && b1, "BuildingsChannelConditionModel only works with MobilityBuildingInfo");
63 
64  Ptr<ChannelCondition> cond = CreateObject<ChannelCondition>();
65 
66  bool isAIndoor = a1->IsIndoor();
67  bool isBIndoor = b1->IsIndoor();
68 
69  if (!isAIndoor && !isBIndoor) // a and b are outdoor
70  {
71  cond->SetO2iCondition(ChannelCondition::O2iConditionValue::O2O);
72 
73  // The outdoor case, determine LOS/NLOS
74  // The channel condition should be LOS if the line of sight is not blocked,
75  // otherwise NLOS
76  bool blocked = IsLineOfSightBlocked(a->GetPosition(), b->GetPosition());
77  NS_LOG_DEBUG("a and b are outdoor, blocked " << blocked);
78  if (!blocked)
79  {
80  NS_LOG_DEBUG("Set LOS");
81  cond->SetLosCondition(ChannelCondition::LosConditionValue::LOS);
82  }
83  else
84  {
85  cond->SetLosCondition(ChannelCondition::LosConditionValue::NLOS);
86  }
87  }
88  else if (isAIndoor && isBIndoor) // a and b are indoor
89  {
90  cond->SetO2iCondition(ChannelCondition::O2iConditionValue::I2I);
91 
92  // Indoor case, determine is the two nodes are inside the same building
93  // or not
94  if (a1->GetBuilding() == b1->GetBuilding())
95  {
96  NS_LOG_DEBUG("a and b are indoor in the same building");
97  cond->SetLosCondition(ChannelCondition::LosConditionValue::LOS);
98  }
99  else
100  {
101  NS_LOG_DEBUG("a and b are indoor in different buildings");
102  cond->SetLosCondition(ChannelCondition::LosConditionValue::NLOS);
103 
104  ChannelCondition::O2iLowHighConditionValue lowHighLossConditionA1;
105  ChannelCondition::O2iLowHighConditionValue lowHighLossConditionB1;
106 
107  // Low losses considered for Wood or ConcreteWithWindows, while
108  // high losses for ConcreteWithoutWindows and StoneBlocks
109  lowHighLossConditionA1 =
110  a1->GetBuilding()->GetExtWallsType() == Building::ExtWallsType_t::Wood ||
111  a1->GetBuilding()->GetExtWallsType() ==
112  Building::ExtWallsType_t::ConcreteWithWindows
115 
116  lowHighLossConditionB1 =
117  b1->GetBuilding()->GetExtWallsType() == Building::ExtWallsType_t::Wood ||
118  b1->GetBuilding()->GetExtWallsType() ==
119  Building::ExtWallsType_t::ConcreteWithWindows
122 
123  if (lowHighLossConditionA1 == ChannelCondition::O2iLowHighConditionValue::HIGH ||
124  lowHighLossConditionB1 == ChannelCondition::O2iLowHighConditionValue::HIGH)
125  {
126  cond->SetO2iLowHighCondition(ChannelCondition::O2iLowHighConditionValue::HIGH);
127  }
128  else
129  {
130  cond->SetO2iLowHighCondition(ChannelCondition::O2iLowHighConditionValue::LOW);
131  }
132  }
133  }
134  else // outdoor to indoor case
135  {
136  cond->SetO2iCondition(ChannelCondition::O2iConditionValue::O2I);
137 
138  NS_LOG_DEBUG("a is indoor and b outdoor or vice-versa");
139  cond->SetLosCondition(ChannelCondition::LosConditionValue::NLOS);
140 
141  ChannelCondition::O2iLowHighConditionValue lowHighLossCondition;
142  if (isAIndoor)
143  {
144  // Low losses considered for Wood or ConcreteWithWindows, while
145  // high losses for ConcreteWithoutWindows and StoneBlocks
146  lowHighLossCondition =
147  a1->GetBuilding()->GetExtWallsType() == Building::ExtWallsType_t::Wood ||
148  a1->GetBuilding()->GetExtWallsType() ==
149  Building::ExtWallsType_t::ConcreteWithWindows
152 
153  cond->SetO2iLowHighCondition(lowHighLossCondition);
154  }
155  else
156  {
157  lowHighLossCondition =
158  b1->GetBuilding()->GetExtWallsType() == Building::ExtWallsType_t::Wood ||
159  b1->GetBuilding()->GetExtWallsType() ==
160  Building::ExtWallsType_t::ConcreteWithWindows
163  cond->SetO2iLowHighCondition(lowHighLossCondition);
164  }
165  }
166 
167  return cond;
168 }
169 
170 bool
172  const ns3::Vector& l2) const
173 {
174  for (auto bit = BuildingList::Begin(); bit != BuildingList::End(); ++bit)
175  {
176  if ((*bit)->IsIntersect(l1, l2))
177  {
178  // The line of sight should be blocked if the line-segment between
179  // l1 and l2 intersects one of the buildings.
180  return true;
181  }
182  }
183 
184  // The line of sight should not be blocked if the line-segment between
185  // l1 and l2 did not intersect any building.
186  return false;
187 }
188 
189 int64_t
191 {
192  return 0;
193 }
194 
195 } // end namespace ns3
static Iterator End()
static Iterator Begin()
Determines the channel condition based on the buildings deployed in the scenario.
int64_t AssignStreams(int64_t stream) override
If this model uses objects of type RandomVariableStream, set the stream numbers to the integers start...
Ptr< ChannelCondition > GetChannelCondition(Ptr< const MobilityModel > a, Ptr< const MobilityModel > b) const override
Computes the condition of the channel between a and b.
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.
BuildingsChannelConditionModel()
Constructor for the BuildingsChannelConditionModel class.
~BuildingsChannelConditionModel() override
Destructor for the BuildingsChannelConditionModel class.
O2iLowHighConditionValue
Possible values for Low-High Penetration Loss condition.
Models the channel condition.
mobility buildings information (to be used by mobility models)
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#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.