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  .SetGroupName("Lte")
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"),
79  .AddAttribute ("OutputFile", "the filename to which the Radio Environment Map is saved",
80  StringValue ("rem.out"),
83  .AddAttribute ("XMin", "The min x coordinate of the map.",
84  DoubleValue (0.0),
86  MakeDoubleChecker<double> ())
87  .AddAttribute ("YMin", "The min y coordinate of the map.",
88  DoubleValue (0.0),
90  MakeDoubleChecker<double> ())
91  .AddAttribute ("XMax", "The max x coordinate of the map.",
92  DoubleValue (1.0),
94  MakeDoubleChecker<double> ())
95  .AddAttribute ("YMax", "The max y coordinate of the map.",
96  DoubleValue (1.0),
98  MakeDoubleChecker<double> ())
99  .AddAttribute ("XRes", "The resolution (number of points) of the map along the x axis.",
100  UintegerValue (100),
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),
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),
110  MakeDoubleChecker<double> ())
111  .AddAttribute ("StopWhenDone", "If true, Simulator::Stop () will be called as soon as the REM has been generated",
112  BooleanValue (true),
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),
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),
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),
135  MakeUintegerChecker<uint16_t> ())
136  .AddAttribute ("UseDataChannel",
137  "If true, REM will be generated for PDSCH and for PDCCH otherwise ",
138  BooleanValue (false),
141  .AddAttribute ("RbId",
142  "Resource block Id, for which REM will be generated,"
143  "default value is -1, what means REM will be averaged from all RBs",
144  IntegerValue (-1),
146  MakeIntegerChecker<int32_t> ())
147  ;
148  return tid;
149 }
150 
151 
152 uint8_t
154 {
155  return m_bandwidth;
156 }
157 
158 void
160 {
161  switch (bw)
162  {
163  case 6:
164  case 15:
165  case 25:
166  case 50:
167  case 75:
168  case 100:
169  m_bandwidth = bw;
170  break;
171 
172  default:
173  NS_FATAL_ERROR ("invalid bandwidth value " << (uint16_t) bw);
174  break;
175  }
176 }
177 
178 
179 
180 void
182 {
183  NS_LOG_FUNCTION (this);
184  if (!m_rem.empty ())
185  {
186  NS_FATAL_ERROR ("only one REM supported per instance of RadioEnvironmentMapHelper");
187  }
189  if (match.GetN () != 1)
190  {
191  NS_FATAL_ERROR ("Lookup " << m_channelPath << " should have exactly one match");
192  }
193  m_channel = match.Get (0)->GetObject<SpectrumChannel> ();
194  NS_ABORT_MSG_IF (m_channel == 0, "object at " << m_channelPath << "is not of type SpectrumChannel");
195 
196  m_outFile.open (m_outputFile.c_str ());
197  if (!m_outFile.is_open ())
198  {
199  NS_FATAL_ERROR ("Can't open file " << (m_outputFile));
200  return;
201  }
202 
203  double startDelay = 0.0026;
204 
205  if (m_useDataChannel)
206  {
207  //need time to start transmission of data channel
208  startDelay = 0.5001;
209  }
210 
211  Simulator::Schedule (Seconds (startDelay),
213  this);
214 }
215 
216 
217 void
219 {
220  NS_LOG_FUNCTION (this);
221  m_xStep = (m_xMax - m_xMin)/(m_xRes-1);
222  m_yStep = (m_yMax - m_yMin)/(m_yRes-1);
223 
224  if ((double)m_xRes * (double) m_yRes < (double) m_maxPointsPerIteration)
225  {
227  }
228 
229  for (uint32_t i = 0; i < m_maxPointsPerIteration; ++i)
230  {
231  RemPoint p;
232  p.phy = CreateObject<RemSpectrumPhy> ();
233  p.bmm = CreateObject<ConstantPositionMobilityModel> ();
234  Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo> ();
235  p.bmm->AggregateObject (buildingInfo); // operation usually done by BuildingsHelper::Install
237  p.phy->SetMobility (p.bmm);
238  p.phy->SetUseDataChannel (m_useDataChannel);
239  p.phy->SetRbId (m_rbId);
240  m_channel->AddRx (p.phy);
241  m_rem.push_back (p);
242  }
243 
244  double remIterationStartTime = 0.0001;
245  double xMinNext = m_xMin;
246  double yMinNext = m_yMin;
247  uint32_t numPointsCurrentIteration = 0;
248  bool justScheduled = false;
249  for (double x = m_xMin; x < m_xMax + 0.5*m_xStep; x += m_xStep)
250  {
251  for (double y = m_yMin; y < m_yMax + 0.5*m_yStep ; y += m_yStep)
252  {
253  if (justScheduled)
254  {
255  xMinNext = x;
256  yMinNext = y;
257  justScheduled = false;
258  }
259 
260  ++numPointsCurrentIteration;
261  if ((numPointsCurrentIteration == m_maxPointsPerIteration)
262  || ((x > m_xMax - 0.5*m_xStep) && (y > m_yMax - 0.5*m_yStep)) )
263  {
264  Simulator::Schedule (Seconds (remIterationStartTime),
266  this, xMinNext, x, yMinNext, y);
267  remIterationStartTime += 0.001;
268  justScheduled = true;
269  numPointsCurrentIteration = 0;
270  }
271  }
272  }
273 
274  Simulator::Schedule (Seconds (remIterationStartTime),
276  this);
277 }
278 
279 
280 void
281 RadioEnvironmentMapHelper::RunOneIteration (double xMin, double xMax, double yMin, double yMax)
282 {
283  NS_LOG_FUNCTION (this << xMin << xMax << yMin << yMax);
284  std::list<RemPoint>::iterator remIt = m_rem.begin ();
285  double x = 0.0;
286  double y = 0.0;
287  for (x = xMin; x < xMax + 0.5*m_xStep; x += m_xStep)
288  {
289  for (y = (x == xMin) ? yMin : m_yMin;
290  y < ((x == xMax) ? yMax : m_yMax) + 0.5*m_yStep;
291  y += m_yStep)
292  {
293  NS_ASSERT (remIt != m_rem.end ());
294  remIt->bmm->SetPosition (Vector (x, y, m_z));
295  Ptr <MobilityBuildingInfo> buildingInfo = (remIt->bmm)->GetObject <MobilityBuildingInfo> ();
296  buildingInfo->MakeConsistent (remIt->bmm);
297  ++remIt;
298  }
299  }
300 
301  if (remIt != m_rem.end ())
302  {
303  NS_ASSERT ((x > m_xMax - 0.5*m_xStep) && (y > m_yMax - 0.5*m_yStep));
304  NS_LOG_LOGIC ("deactivating RemSpectrumPhys that are unneeded in the last iteration");
305  while (remIt != m_rem.end ())
306  {
307  remIt->phy->Deactivate ();
308  ++remIt;
309  }
310  }
311 
313 }
314 
315 void
317 {
318  NS_LOG_FUNCTION (this);
319 
320  for (std::list<RemPoint>::iterator it = m_rem.begin ();
321  it != m_rem.end ();
322  ++it)
323  {
324  if (!(it->phy->IsActive ()))
325  {
326  // should occur only upon last iteration when some RemPoint
327  // at the end of the list can be unused
328  break;
329  }
330  Vector pos = it->bmm->GetPosition ();
331  NS_LOG_LOGIC ("output: " << pos.x << "\t"
332  << pos.y << "\t"
333  << pos.z << "\t"
334  << it->phy->GetSinr (m_noisePower));
335  m_outFile << pos.x << "\t"
336  << pos.y << "\t"
337  << pos.z << "\t"
338  << it->phy->GetSinr (m_noisePower)
339  << std::endl;
340  it->phy->Reset ();
341  }
342 }
343 
344 void
346 {
347  NS_LOG_FUNCTION (this);
348  m_outFile.close ();
349  if (m_stopWhenDone)
350  {
351  Simulator::Stop ();
352  }
353 }
354 
355 
356 } // namespace ns3
Generates a 2D map of the SINR from the strongest transmitter in the downlink of an LTE FDD system...
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:36
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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:84
std::ofstream m_outFile
Stream the output to a file.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
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:67
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:204
void Finalize()
Called when the map generation procedure has been completed.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
Ptr< Object > Get(std::size_t i) const
Definition: config.cc:75
std::size_t GetN(void) const
Definition: config.cc:69
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.
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
void RunOneIteration(double xMin, double xMax, double yMin, double yMax)
Mobilize all the listeners to a specified area.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1389
#define max(a, b)
Definition: 80211b.c:43
Hold an unsigned integer type.
Definition: uinteger.h:44
std::list< RemPoint > m_rem
List of listeners in the environment.
static Ptr< SpectrumModel > GetSpectrumModel(uint32_t earfcn, uint8_t bandwidth)
bool m_useDataChannel
The UseDataChannel attribute.
double m_yStep
Distance along Y axis between adjacent listening points.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
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...
std::string m_channelPath
The ChannelPath attribute.
hold a set of objects which match a specific search string.
Definition: config.h:151
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
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.
MatchContainer LookupMatches(std::string path)
Definition: config.cc:882
#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:178
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
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 &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
virtual void DoDispose(void)
Destructor implementation.
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:58
double m_noisePower
The NoisePower attribute.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915