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
28namespace ns3 {
29
30NS_LOG_COMPONENT_DEFINE ("BuildingsChannelConditionModel");
31
32NS_OBJECT_ENSURE_REGISTERED (BuildingsChannelConditionModel);
33
34TypeId
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 NS_LOG_FUNCTION (this);
61 NS_ASSERT_MSG ((a1 != nullptr) && (b1 != nullptr),
62 "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
70 if (!isAIndoor && !isBIndoor) // a and b are outdoor
71 {
72 cond->SetO2iCondition (ChannelCondition::O2iConditionValue::O2O);
73
74 // The outdoor case, determine LOS/NLOS
75 // The channel condition should be LOS if the line of sight is not blocked,
76 // otherwise NLOS
77 bool blocked = IsLineOfSightBlocked (a->GetPosition (), b->GetPosition ());
78 NS_LOG_DEBUG ("a and b are outdoor, blocked " << blocked);
79 if (!blocked)
80 {
81 NS_LOG_DEBUG ("Set LOS");
82 cond->SetLosCondition (ChannelCondition::LosConditionValue::LOS);
83 }
84 else
85 {
86 cond->SetLosCondition (ChannelCondition::LosConditionValue::NLOS);
87 }
88 }
89 else if (isAIndoor && isBIndoor) // a and b are indoor
90 {
91 cond->SetO2iCondition (ChannelCondition::O2iConditionValue::I2I);
92
93 // Indoor case, determine is the two nodes are inside the same building
94 // or not
95 if (a1->GetBuilding () == b1->GetBuilding ())
96 {
97 NS_LOG_DEBUG ("a and b are indoor in the same building");
98 cond->SetLosCondition (ChannelCondition::LosConditionValue::LOS);
99 }
100 else
101 {
102 NS_LOG_DEBUG ("a and b are indoor in different buildings");
103 cond->SetLosCondition (ChannelCondition::LosConditionValue::NLOS);
104 }
105 }
106 else //outdoor to indoor case
107 {
108 cond->SetO2iCondition (ChannelCondition::O2iConditionValue::O2I);
109
110 NS_LOG_DEBUG ("a is indoor and b outdoor or viceversa");
111 cond->SetLosCondition (ChannelCondition::LosConditionValue::NLOS);
112 }
113
114 return cond;
115}
116
117bool
118BuildingsChannelConditionModel::IsLineOfSightBlocked (const ns3::Vector &l1, const ns3::Vector &l2) const
119{
120 for (BuildingList::Iterator bit = BuildingList::Begin (); bit != BuildingList::End (); ++bit)
121 {
122 if ((*bit)->IsIntersect (l1, l2))
123 {
124 // The line of sight should be blocked if the line-segment between
125 // l1 and l2 intersects one of the buildings.
126 return true;
127 }
128 }
129
130 // The line of sight should not be blocked if the line-segment between
131 // l1 and l2 did not intersect any building.
132 return false;
133}
134
135int64_t
136BuildingsChannelConditionModel::AssignStreams ([[maybe_unused]] int64_t stream)
137{
138 return 0;
139}
140
141} // end namespace ns3
std::vector< Ptr< Building > >::const_iterator Iterator
Const Iterator.
Definition: building-list.h:40
static Iterator End(void)
static Iterator Begin(void)
Determines the channel condition based on the buildings deployed in the scenario.
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.
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.
static TypeId GetTypeId(void)
Get the type ID.
virtual ~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:74
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#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.