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
21#include "ns3/buildings-channel-condition-model.h"
22
23#include "ns3/building-list.h"
24#include "ns3/log.h"
25#include "ns3/mobility-building-info.h"
26#include "ns3/mobility-model.h"
27
28namespace ns3
29{
30
31NS_LOG_COMPONENT_DEFINE("BuildingsChannelConditionModel");
32
33NS_OBJECT_ENSURE_REGISTERED(BuildingsChannelConditionModel);
34
35TypeId
37{
38 static TypeId tid = TypeId("ns3::BuildingsChannelConditionModel")
40 .SetGroupName("Buildings")
41 .AddConstructor<BuildingsChannelConditionModel>();
42 return tid;
43}
44
47{
48}
49
51{
52}
53
57{
58 NS_LOG_FUNCTION(this);
61 NS_ASSERT_MSG(a1 && b1, "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 if (!isAIndoor && !isBIndoor) // a and b are outdoor
69 {
70 cond->SetO2iCondition(ChannelCondition::O2iConditionValue::O2O);
71
72 // The outdoor case, determine LOS/NLOS
73 // The channel condition should be LOS if the line of sight is not blocked,
74 // otherwise NLOS
75 bool blocked = IsLineOfSightBlocked(a->GetPosition(), b->GetPosition());
76 NS_LOG_DEBUG("a and b are outdoor, blocked " << blocked);
77 if (!blocked)
78 {
79 NS_LOG_DEBUG("Set LOS");
80 cond->SetLosCondition(ChannelCondition::LosConditionValue::LOS);
81 }
82 else
83 {
84 cond->SetLosCondition(ChannelCondition::LosConditionValue::NLOS);
85 }
86 }
87 else if (isAIndoor && isBIndoor) // a and b are indoor
88 {
89 cond->SetO2iCondition(ChannelCondition::O2iConditionValue::I2I);
90
91 // Indoor case, determine is the two nodes are inside the same building
92 // or not
93 if (a1->GetBuilding() == b1->GetBuilding())
94 {
95 NS_LOG_DEBUG("a and b are indoor in the same building");
96 cond->SetLosCondition(ChannelCondition::LosConditionValue::LOS);
97 }
98 else
99 {
100 NS_LOG_DEBUG("a and b are indoor in different buildings");
101 cond->SetLosCondition(ChannelCondition::LosConditionValue::NLOS);
102 }
103 }
104 else // outdoor to indoor case
105 {
106 cond->SetO2iCondition(ChannelCondition::O2iConditionValue::O2I);
107
108 NS_LOG_DEBUG("a is indoor and b outdoor or viceversa");
109 cond->SetLosCondition(ChannelCondition::LosConditionValue::NLOS);
110 }
111
112 return cond;
113}
114
115bool
117 const ns3::Vector& l2) const
118{
120 {
121 if ((*bit)->IsIntersect(l1, l2))
122 {
123 // The line of sight should be blocked if the line-segment between
124 // l1 and l2 intersects one of the buildings.
125 return true;
126 }
127 }
128
129 // The line of sight should not be blocked if the line-segment between
130 // l1 and l2 did not intersect any building.
131 return false;
132}
133
134int64_t
136{
137 return 0;
138}
139
140} // end namespace ns3
std::vector< Ptr< Building > >::const_iterator Iterator
Const Iterator.
Definition: building-list.h:41
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.
Models the channel condition.
mobility buildings information (to be used by mobility models)
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
a unique identifier for an interface.
Definition: type-id.h:60
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
#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:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.