A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/uinteger.h>
28 #include <ns3/string.h>
29 #include <ns3/boolean.h>
30 #include <ns3/spectrum-channel.h>
31 #include <ns3/config.h>
32 #include <ns3/rem-spectrum-phy.h>
33 #include <ns3/mobility-building-info.h>
34 #include <ns3/constant-position-mobility-model.h>
35 #include <ns3/simulator.h>
36 #include <ns3/node.h>
37 #include <ns3/buildings-helper.h>
38 #include <ns3/lte-spectrum-value-helper.h>
39 
40 #include <fstream>
41 #include <limits>
42 
43 NS_LOG_COMPONENT_DEFINE ("RadioEnvironmentMapHelper");
44 
45 namespace ns3 {
46 
47 
48 
49 NS_OBJECT_ENSURE_REGISTERED (RadioEnvironmentMapHelper);
50 
52 {
53 }
54 
55 
57 {
58 }
59 
60 
61 
62 void
64 {
65  NS_LOG_FUNCTION (this);
66 }
67 
68 TypeId
70 {
71  NS_LOG_FUNCTION ("RadioEnvironmentMapHelper::GetTypeId");
72  static TypeId tid = TypeId ("ns3::RadioEnvironmentMapHelper")
73  .SetParent<Object> ()
74  .AddConstructor<RadioEnvironmentMapHelper> ()
75  .AddAttribute ("ChannelPath", "The path to the channel for which the Radio Environment Map is to be generated",
76  StringValue ("/ChannelList/0"),
77  MakeStringAccessor (&RadioEnvironmentMapHelper::m_channelPath),
78  MakeStringChecker ())
79  .AddAttribute ("OutputFile", "the filename to which the Radio Environment Map is saved",
80  StringValue ("rem.out"),
81  MakeStringAccessor (&RadioEnvironmentMapHelper::m_outputFile),
82  MakeStringChecker ())
83  .AddAttribute ("XMin", "The min x coordinate of the map.",
84  DoubleValue (0.0),
85  MakeDoubleAccessor (&RadioEnvironmentMapHelper::m_xMin),
86  MakeDoubleChecker<double> ())
87  .AddAttribute ("YMin", "The min y coordinate of the map.",
88  DoubleValue (0.0),
89  MakeDoubleAccessor (&RadioEnvironmentMapHelper::m_yMin),
90  MakeDoubleChecker<double> ())
91  .AddAttribute ("XMax", "The max x coordinate of the map.",
92  DoubleValue (1.0),
93  MakeDoubleAccessor (&RadioEnvironmentMapHelper::m_xMax),
94  MakeDoubleChecker<double> ())
95  .AddAttribute ("YMax", "The max y coordinate of the map.",
96  DoubleValue (1.0),
97  MakeDoubleAccessor (&RadioEnvironmentMapHelper::m_yMax),
98  MakeDoubleChecker<double> ())
99  .AddAttribute ("XRes", "The resolution (number of points) of the map along the x axis.",
100  UintegerValue (100),
101  MakeUintegerAccessor (&RadioEnvironmentMapHelper::m_xRes),
102  MakeUintegerChecker<uint32_t> (2,std::numeric_limits<uint16_t>::max ()))
103  .AddAttribute ("YRes", "The resolution (number of points) of the map along the y axis.",
104  UintegerValue (100),
105  MakeUintegerAccessor (&RadioEnvironmentMapHelper::m_yRes),
106  MakeUintegerChecker<uint16_t> (2,std::numeric_limits<uint16_t>::max ()))
107  .AddAttribute ("Z", "The value of the z coordinate for which the map is to be generated",
108  DoubleValue (0.0),
109  MakeDoubleAccessor (&RadioEnvironmentMapHelper::m_z),
110  MakeDoubleChecker<double> ())
111  .AddAttribute ("StopWhenDone", "If true, Simulator::Stop () will be called as soon as the REM has been generated",
112  BooleanValue (true),
113  MakeBooleanAccessor (&RadioEnvironmentMapHelper::m_stopWhenDone),
114  MakeBooleanChecker ())
115  .AddAttribute ("NoisePower",
116  "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",
117  DoubleValue (1.4230e-13),
118  MakeDoubleAccessor (&RadioEnvironmentMapHelper::m_noisePower),
119  MakeDoubleChecker<double> ())
120  .AddAttribute ("MaxPointsPerIteration", "Maximum number of REM points to be calculated per iteration. Every point consumes approximately 5KB of memory.",
121  UintegerValue (20000),
123  MakeUintegerChecker<uint32_t> (1,std::numeric_limits<uint32_t>::max ()))
124  .AddAttribute ("Earfcn",
125  "E-UTRA Absolute Radio Frequency Channel Number (EARFCN) "
126  "as per 3GPP 36.101 Section 5.7.3. ",
127  UintegerValue (100),
128  MakeUintegerAccessor (&RadioEnvironmentMapHelper::m_earfcn),
129  MakeUintegerChecker<uint16_t> ())
130  .AddAttribute ("Bandwidth",
131  "Transmission Bandwidth Configuration (in number of RBs) over which the SINR will be calculated",
132  UintegerValue (25),
133  MakeUintegerAccessor (&RadioEnvironmentMapHelper::SetBandwidth,
135  MakeUintegerChecker<uint16_t> ())
136  ;
137  return tid;
138 }
139 
140 
141 uint8_t
143 {
144  return m_bandwidth;
145 }
146 
147 void
149 {
150  switch (bw)
151  {
152  case 6:
153  case 15:
154  case 25:
155  case 50:
156  case 75:
157  case 100:
158  m_bandwidth = bw;
159  break;
160 
161  default:
162  NS_FATAL_ERROR ("invalid bandwidth value " << (uint16_t) bw);
163  break;
164  }
165 }
166 
167 
168 
169 void
171 {
172  NS_LOG_FUNCTION (this);
173  if (!m_rem.empty ())
174  {
175  NS_FATAL_ERROR ("only one REM supported per instance of RadioEnvironmentMapHelper");
176  }
178  if (match.GetN () != 1)
179  {
180  NS_FATAL_ERROR ("Lookup " << m_channelPath << " should have exactly one match");
181  }
182  m_channel = match.Get (0)->GetObject<SpectrumChannel> ();
183  NS_ABORT_MSG_IF (m_channel == 0, "object at " << m_channelPath << "is not of type SpectrumChannel");
184 
185  m_outFile.open (m_outputFile.c_str ());
186  if (!m_outFile.is_open ())
187  {
188  NS_FATAL_ERROR ("Can't open file " << (m_outputFile));
189  return;
190  }
191 
192  Simulator::Schedule (Seconds (0.0026),
194  this);
195 }
196 
197 
198 void
200 {
201  NS_LOG_FUNCTION (this);
202  m_xStep = (m_xMax - m_xMin)/(m_xRes-1);
203  m_yStep = (m_yMax - m_yMin)/(m_yRes-1);
204 
205  if ((double)m_xRes * (double) m_yRes < (double) m_maxPointsPerIteration)
206  {
208  }
209 
210  for (uint32_t i = 0; i < m_maxPointsPerIteration; ++i)
211  {
212  RemPoint p;
213  p.phy = CreateObject<RemSpectrumPhy> ();
214  p.bmm = CreateObject<ConstantPositionMobilityModel> ();
215  Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo> ();
216  p.bmm->AggregateObject (buildingInfo); // operation usually done by BuildingsHelper::Install
218  p.phy->SetMobility (p.bmm);
219  m_channel->AddRx (p.phy);
220  m_rem.push_back (p);
221  }
222 
223  double remIterationStartTime = 0.0001;
224  double xMinNext = m_xMin;
225  double yMinNext = m_yMin;
226  uint32_t numPointsCurrentIteration = 0;
227  bool justScheduled = false;
228  for (double x = m_xMin; x < m_xMax + 0.5*m_xStep; x += m_xStep)
229  {
230  for (double y = m_yMin; y < m_yMax + 0.5*m_yStep ; y += m_yStep)
231  {
232  if (justScheduled)
233  {
234  xMinNext = x;
235  yMinNext = y;
236  justScheduled = false;
237  }
238 
239  ++numPointsCurrentIteration;
240  if ((numPointsCurrentIteration == m_maxPointsPerIteration)
241  || ((x > m_xMax - 0.5*m_xStep) && (y > m_yMax - 0.5*m_yStep)) )
242  {
243  Simulator::Schedule (Seconds (remIterationStartTime),
245  this, xMinNext, x, yMinNext, y);
246  remIterationStartTime += 0.001;
247  justScheduled = true;
248  numPointsCurrentIteration = 0;
249  }
250  }
251  }
252  Simulator::Schedule (Seconds (remIterationStartTime),
254  this);
255 }
256 
257 
258 void
259 RadioEnvironmentMapHelper::RunOneIteration (double xMin, double xMax, double yMin, double yMax)
260 {
261  NS_LOG_FUNCTION (this << xMin << xMax << yMin << yMax);
262  std::list<RemPoint>::iterator remIt = m_rem.begin ();
263  double x;
264  double y;
265  for (x = xMin; x < xMax + 0.5*m_xStep; x += m_xStep)
266  {
267  for (y = (x == xMin) ? yMin : m_yMin;
268  y < ((x == xMax) ? yMax : m_yMax) + 0.5*m_yStep;
269  y += m_yStep)
270  {
271  NS_ASSERT (remIt != m_rem.end ());
272  remIt->bmm->SetPosition (Vector (x, y, m_z));
273  BuildingsHelper::MakeConsistent (remIt->bmm);
274  ++remIt;
275  }
276  }
277 
278  if (remIt != m_rem.end ())
279  {
280  NS_ASSERT ((x > m_xMax - 0.5*m_xStep) && (y > m_yMax - 0.5*m_yStep));
281  NS_LOG_LOGIC ("deactivating RemSpectrumPhys that are unneeded in the last iteration");
282  while (remIt != m_rem.end ())
283  {
284  remIt->phy->Deactivate ();
285  ++remIt;
286  }
287  }
288 
290 }
291 
292 void
294 {
295  NS_LOG_FUNCTION (this);
296 
297  for (std::list<RemPoint>::iterator it = m_rem.begin ();
298  it != m_rem.end ();
299  ++it)
300  {
301  if (!(it->phy->IsActive ()))
302  {
303  // should occur only upon last iteration when some RemPoint
304  // at the end of the list can be unused
305  break;
306  }
307  Vector pos = it->bmm->GetPosition ();
308  NS_LOG_LOGIC ("output: " << pos.x << "\t"
309  << pos.y << "\t"
310  << pos.z << "\t"
311  << it->phy->GetSinr (m_noisePower));
312  m_outFile << pos.x << "\t"
313  << pos.y << "\t"
314  << pos.z << "\t"
315  << it->phy->GetSinr (m_noisePower)
316  << std::endl;
317  it->phy->Reset ();
318  }
319 }
320 
321 void
323 {
324  NS_LOG_FUNCTION (this);
325  m_outFile.close ();
326  if (m_stopWhenDone)
327  {
328  Simulator::Stop ();
329  }
330 }
331 
332 
333 } // namespace ns3
double x
x coordinate of vector
Definition: vector.h:49
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Hold a bool native type.
Definition: boolean.h:38
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
hold variables of type string
Definition: string.h:18
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:95
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:825
a 3d vector
Definition: vector.h:31
static void MakeConsistent(Ptr< MobilityModel > bmm)
Make the given mobility model consistent, by determining whether its position falls inside any of the...
Config::MatchContainer LookupMatches(std::string path)
Definition: config.cc:739
void RunOneIteration(double xMin, double xMax, double yMin, double yMax)
Hold an unsigned integer type.
Definition: uinteger.h:46
void AggregateObject(Ptr< Object > other)
Definition: object.cc:242
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:233
uint32_t GetN(void) const
Definition: config.cc:63
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
double y
y coordinate of vector
Definition: vector.h:53
hold a set of objects which match a specific search string.
Definition: config.h:127
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if cond is true.
Definition: abort.h:101
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition: simulator.cc:165
Defines the interface for spectrum-aware channel implementations.
a base class which provides memory management and object aggregation
Definition: object.h:64
Hold a floating point type.
Definition: double.h:41
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Ptr< T > GetObject(void) const
Definition: object.h:362
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
double z
z coordinate of vector
Definition: vector.h:57