A Discrete-Event Network Simulator
API
radio-environment-map-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 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: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 
23 
24 #include <ns3/abort.h>
25 #include <ns3/log.h>
26 #include <ns3/double.h>
27 #include <ns3/integer.h>
28 #include <ns3/uinteger.h>
29 #include <ns3/string.h>
30 #include <ns3/boolean.h>
31 #include <ns3/spectrum-channel.h>
32 #include <ns3/config.h>
33 #include <ns3/rem-spectrum-phy.h>
34 #include <ns3/mobility-building-info.h>
35 #include <ns3/constant-position-mobility-model.h>
36 #include <ns3/simulator.h>
37 #include <ns3/node.h>
38 #include <ns3/buildings-helper.h>
39 #include <ns3/lte-spectrum-value-helper.h>
40 
41 #include <fstream>
42 #include <limits>
43 
44 namespace ns3 {
45 
46 NS_LOG_COMPONENT_DEFINE ("RadioEnvironmentMapHelper");
47 
48 NS_OBJECT_ENSURE_REGISTERED (RadioEnvironmentMapHelper);
49 
51 {
52 }
53 
54 
56 {
57 }
58 
59 
60 
61 void
63 {
64  NS_LOG_FUNCTION (this);
65 }
66 
67 TypeId
69 {
70  NS_LOG_FUNCTION ("RadioEnvironmentMapHelper::GetTypeId");
71  static TypeId tid = TypeId ("ns3::RadioEnvironmentMapHelper")
72  .SetParent<Object> ()
73  .AddConstructor<RadioEnvironmentMapHelper> ()
74  .AddAttribute ("ChannelPath", "The path to the channel for which the Radio Environment Map is to be generated",
75  StringValue ("/ChannelList/0"),
78  .AddAttribute ("OutputFile", "the filename to which the Radio Environment Map is saved",
79  StringValue ("rem.out"),
82  .AddAttribute ("XMin", "The min x coordinate of the map.",
83  DoubleValue (0.0),
85  MakeDoubleChecker<double> ())
86  .AddAttribute ("YMin", "The min y coordinate of the map.",
87  DoubleValue (0.0),
89  MakeDoubleChecker<double> ())
90  .AddAttribute ("XMax", "The max x coordinate of the map.",
91  DoubleValue (1.0),
93  MakeDoubleChecker<double> ())
94  .AddAttribute ("YMax", "The max y coordinate of the map.",
95  DoubleValue (1.0),
97  MakeDoubleChecker<double> ())
98  .AddAttribute ("XRes", "The resolution (number of points) of the map along the x axis.",
99  UintegerValue (100),
101  MakeUintegerChecker<uint32_t> (2,std::numeric_limits<uint16_t>::max ()))
102  .AddAttribute ("YRes", "The resolution (number of points) of the map along the y axis.",
103  UintegerValue (100),
105  MakeUintegerChecker<uint16_t> (2,std::numeric_limits<uint16_t>::max ()))
106  .AddAttribute ("Z", "The value of the z coordinate for which the map is to be generated",
107  DoubleValue (0.0),
109  MakeDoubleChecker<double> ())
110  .AddAttribute ("StopWhenDone", "If true, Simulator::Stop () will be called as soon as the REM has been generated",
111  BooleanValue (true),
114  .AddAttribute ("NoisePower",
115  "the power of the measuring instrument noise, in Watts. Default to a kT of -174 dBm with a noise figure of 9 dB and a bandwidth of 25 LTE Resource Blocks",
116  DoubleValue (1.4230e-13),
118  MakeDoubleChecker<double> ())
119  .AddAttribute ("MaxPointsPerIteration", "Maximum number of REM points to be calculated per iteration. Every point consumes approximately 5KB of memory.",
120  UintegerValue (20000),
122  MakeUintegerChecker<uint32_t> (1,std::numeric_limits<uint32_t>::max ()))
123  .AddAttribute ("Earfcn",
124  "E-UTRA Absolute Radio Frequency Channel Number (EARFCN) "
125  "as per 3GPP 36.101 Section 5.7.3. ",
126  UintegerValue (100),
128  MakeUintegerChecker<uint16_t> ())
129  .AddAttribute ("Bandwidth",
130  "Transmission Bandwidth Configuration (in number of RBs) over which the SINR will be calculated",
131  UintegerValue (25),
134  MakeUintegerChecker<uint16_t> ())
135  .AddAttribute ("UseDataChannel",
136  "If true, REM will be generated for PDSCH and for PDCCH otherwise ",
137  BooleanValue (false),
140  .AddAttribute ("RbId",
141  "Resource block Id, for which REM will be generated,"
142  "default value is -1, what means REM will be averaged from all RBs",
143  IntegerValue (-1),
145  MakeIntegerChecker<int32_t> ())
146  ;
147  return tid;
148 }
149 
150 
151 uint8_t
153 {
154  return m_bandwidth;
155 }
156 
157 void
159 {
160  switch (bw)
161  {
162  case 6:
163  case 15:
164  case 25:
165  case 50:
166  case 75:
167  case 100:
168  m_bandwidth = bw;
169  break;
170 
171  default:
172  NS_FATAL_ERROR ("invalid bandwidth value " << (uint16_t) bw);
173  break;
174  }
175 }
176 
177 
178 
179 void
181 {
182  NS_LOG_FUNCTION (this);
183  if (!m_rem.empty ())
184  {
185  NS_FATAL_ERROR ("only one REM supported per instance of RadioEnvironmentMapHelper");
186  }
188  if (match.GetN () != 1)
189  {
190  NS_FATAL_ERROR ("Lookup " << m_channelPath << " should have exactly one match");
191  }
192  m_channel = match.Get (0)->GetObject<SpectrumChannel> ();
193  NS_ABORT_MSG_IF (m_channel == 0, "object at " << m_channelPath << "is not of type SpectrumChannel");
194 
195  m_outFile.open (m_outputFile.c_str ());
196  if (!m_outFile.is_open ())
197  {
198  NS_FATAL_ERROR ("Can't open file " << (m_outputFile));
199  return;
200  }
201 
202  double startDelay = 0.0026;
203 
204  if (m_useDataChannel)
205  {
206  //need time to start transmission of data channel
207  startDelay = 0.5001;
208  }
209 
210  Simulator::Schedule (Seconds (startDelay),
212  this);
213 }
214 
215 
216 void
218 {
219  NS_LOG_FUNCTION (this);
220  m_xStep = (m_xMax - m_xMin)/(m_xRes-1);
221  m_yStep = (m_yMax - m_yMin)/(m_yRes-1);
222 
223  if ((double)m_xRes * (double) m_yRes < (double) m_maxPointsPerIteration)
224  {
226  }
227 
228  for (uint32_t i = 0; i < m_maxPointsPerIteration; ++i)
229  {
230  RemPoint p;
231  p.phy = CreateObject<RemSpectrumPhy> ();
232  p.bmm = CreateObject<ConstantPositionMobilityModel> ();
233  Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo> ();
234  p.bmm->AggregateObject (buildingInfo); // operation usually done by BuildingsHelper::Install
236  p.phy->SetMobility (p.bmm);
237  p.phy->SetUseDataChannel (m_useDataChannel);
238  p.phy->SetRbId (m_rbId);
239  m_channel->AddRx (p.phy);
240  m_rem.push_back (p);
241  }
242 
243  double remIterationStartTime = 0.0001;
244  double xMinNext = m_xMin;
245  double yMinNext = m_yMin;
246  uint32_t numPointsCurrentIteration = 0;
247  bool justScheduled = false;
248  for (double x = m_xMin; x < m_xMax + 0.5*m_xStep; x += m_xStep)
249  {
250  for (double y = m_yMin; y < m_yMax + 0.5*m_yStep ; y += m_yStep)
251  {
252  if (justScheduled)
253  {
254  xMinNext = x;
255  yMinNext = y;
256  justScheduled = false;
257  }
258 
259  ++numPointsCurrentIteration;
260  if ((numPointsCurrentIteration == m_maxPointsPerIteration)
261  || ((x > m_xMax - 0.5*m_xStep) && (y > m_yMax - 0.5*m_yStep)) )
262  {
263  Simulator::Schedule (Seconds (remIterationStartTime),
265  this, xMinNext, x, yMinNext, y);
266  remIterationStartTime += 0.001;
267  justScheduled = true;
268  numPointsCurrentIteration = 0;
269  }
270  }
271  }
272 
273  Simulator::Schedule (Seconds (remIterationStartTime),
275  this);
276 }
277 
278 
279 void
280 RadioEnvironmentMapHelper::RunOneIteration (double xMin, double xMax, double yMin, double yMax)
281 {
282  NS_LOG_FUNCTION (this << xMin << xMax << yMin << yMax);
283  std::list<RemPoint>::iterator remIt = m_rem.begin ();
284  double x;
285  double y;
286  for (x = xMin; x < xMax + 0.5*m_xStep; x += m_xStep)
287  {
288  for (y = (x == xMin) ? yMin : m_yMin;
289  y < ((x == xMax) ? yMax : m_yMax) + 0.5*m_yStep;
290  y += m_yStep)
291  {
292  NS_ASSERT (remIt != m_rem.end ());
293  remIt->bmm->SetPosition (Vector (x, y, m_z));
294  BuildingsHelper::MakeConsistent (remIt->bmm);
295  ++remIt;
296  }
297  }
298 
299  if (remIt != m_rem.end ())
300  {
301  NS_ASSERT ((x > m_xMax - 0.5*m_xStep) && (y > m_yMax - 0.5*m_yStep));
302  NS_LOG_LOGIC ("deactivating RemSpectrumPhys that are unneeded in the last iteration");
303  while (remIt != m_rem.end ())
304  {
305  remIt->phy->Deactivate ();
306  ++remIt;
307  }
308  }
309 
311 }
312 
313 void
315 {
316  NS_LOG_FUNCTION (this);
317 
318  for (std::list<RemPoint>::iterator it = m_rem.begin ();
319  it != m_rem.end ();
320  ++it)
321  {
322  if (!(it->phy->IsActive ()))
323  {
324  // should occur only upon last iteration when some RemPoint
325  // at the end of the list can be unused
326  break;
327  }
328  Vector pos = it->bmm->GetPosition ();
329  NS_LOG_LOGIC ("output: " << pos.x << "\t"
330  << pos.y << "\t"
331  << pos.z << "\t"
332  << it->phy->GetSinr (m_noisePower));
333  m_outFile << pos.x << "\t"
334  << pos.y << "\t"
335  << pos.z << "\t"
336  << it->phy->GetSinr (m_noisePower)
337  << std::endl;
338  it->phy->Reset ();
339  }
340 }
341 
342 void
344 {
345  NS_LOG_FUNCTION (this);
346  m_outFile.close ();
347  if (m_stopWhenDone)
348  {
349  Simulator::Stop ();
350  }
351 }
352 
353 
354 } // namespace ns3
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void PrintAndReset()
Go through every listener, write the computed SINR, and then reset it.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
AttributeValue implementation for Boolean.
Definition: boolean.h:34
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
void DelayedInstall()
Scheduled by Install() to perform the actual generation of map.
Hold variables of type string.
Definition: string.h:41
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: boolean.h:81
std::ofstream m_outFile
Stream the output to a file.
Ptr< MobilityModel > bmm
Position of the listener in the environment.
uint32_t m_maxPointsPerIteration
The MaxPointsPerIteration attribute.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
static TypeId GetTypeId(void)
Register this type.
Hold a signed integer type.
Definition: integer.h:44
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void Finalize()
Called when the map generation procedure has been completed.
#define NS_FATAL_ERROR(msg)
Fatal error handling.
Definition: fatal-error.h:100
static Ptr< SpectrumModel > GetSpectrumModel(uint16_t earfcn, uint8_t bandwidth)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:819
bool m_stopWhenDone
The StopWhenDone attribute.
Ptr< RemSpectrumPhy > phy
Simplified listener which compute SINR over the DL channel.
uint16_t m_bandwidth
The Bandwidth attribute.
static void MakeConsistent(Ptr< MobilityModel > bmm)
Make the given mobility model consistent, by determining whether its position falls inside any of the...
Ptr< const AttributeAccessor > MakeIntegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: integer.h:45
Config::MatchContainer LookupMatches(std::string path)
Definition: config.cc:749
void RunOneIteration(double xMin, double xMax, double yMin, double yMax)
Mobilize all the listeners to a specified area.
Hold an unsigned integer type.
Definition: uinteger.h:44
std::list< RemPoint > m_rem
List of listeners in the environment.
bool m_useDataChannel
The UseDataChannel attribute.
double m_yStep
Distance along Y axis between adjacent listening points.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:245
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
uint32_t GetN(void) const
Definition: config.cc:63
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
void Install()
Deploy the RemSpectrumPhy objects that generate the map according to the specified settings...
Ptr< Object > Get(uint32_t i) const
Definition: config.cc:69
std::string m_channelPath
The ChannelPath attribute.
hold a set of objects which match a specific search string.
Definition: config.h:127
A complete Radio Environment Map is composed of many of this structure.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: double.h:42
uint16_t m_earfcn
The Earfcn attribute.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
Ptr< SpectrumChannel > m_channel
The channel object taken from the ChannelPath attribute.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:208
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:859
Defines the interface for spectrum-aware channel implementations.
A base class which provides memory management and object aggregation.
Definition: object.h:87
std::string m_outputFile
The OutputFile attribute.
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: string.h:42
double m_xStep
Distance along X axis between adjacent listening points.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
virtual void DoDispose(void)
Destructor implementation.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:455
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:51
double m_noisePower
The NoisePower attribute.
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631