22 #include "radio-environment-map-helper.h"
24 #include <ns3/abort.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/buildings-mobility-model.h>
34 #include <ns3/simulator.h>
36 #include <ns3/buildings-helper.h>
37 #include <ns3/lte-spectrum-value-helper.h>
48 NS_OBJECT_ENSURE_REGISTERED (RadioEnvironmentMapHelper);
50 RadioEnvironmentMapHelper::RadioEnvironmentMapHelper ()
55 RadioEnvironmentMapHelper::~RadioEnvironmentMapHelper ()
68 RadioEnvironmentMapHelper::GetTypeId (
void)
71 static TypeId tid =
TypeId (
"ns3::RadioEnvironmentMapHelper")
73 .AddConstructor<RadioEnvironmentMapHelper> ()
74 .AddAttribute (
"ChannelPath",
"The path to the channel for which the Radio Environment Map is to be generated",
76 MakeStringAccessor (&RadioEnvironmentMapHelper::m_channelPath),
78 .AddAttribute (
"OutputFile",
"the filename to which the Radio Environment Map is saved",
80 MakeStringAccessor (&RadioEnvironmentMapHelper::m_outputFile),
82 .AddAttribute (
"XMin",
"The min x coordinate of the map.",
84 MakeDoubleAccessor (&RadioEnvironmentMapHelper::m_xMin),
85 MakeDoubleChecker<double> ())
86 .AddAttribute (
"YMin",
"The min y coordinate of the map.",
88 MakeDoubleAccessor (&RadioEnvironmentMapHelper::m_yMin),
89 MakeDoubleChecker<double> ())
90 .AddAttribute (
"XMax",
"The max x coordinate of the map.",
92 MakeDoubleAccessor (&RadioEnvironmentMapHelper::m_xMax),
93 MakeDoubleChecker<double> ())
94 .AddAttribute (
"YMax",
"The max y coordinate of the map.",
96 MakeDoubleAccessor (&RadioEnvironmentMapHelper::m_yMax),
97 MakeDoubleChecker<double> ())
98 .AddAttribute (
"XRes",
"The resolution (number of points) of the map along the x axis.",
100 MakeUintegerAccessor (&RadioEnvironmentMapHelper::m_xRes),
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.",
104 MakeUintegerAccessor (&RadioEnvironmentMapHelper::m_yRes),
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",
108 MakeDoubleAccessor (&RadioEnvironmentMapHelper::m_z),
109 MakeDoubleChecker<double> ())
110 .AddAttribute (
"StopWhenDone",
"If true, Simulator::Stop () will be called as soon as the REM has been generated",
112 MakeBooleanAccessor (&RadioEnvironmentMapHelper::m_stopWhenDone),
113 MakeBooleanChecker ())
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",
117 MakeDoubleAccessor (&RadioEnvironmentMapHelper::m_noisePower),
118 MakeDoubleChecker<double> ())
119 .AddAttribute (
"MaxPointsPerIteration",
"Maximum number of REM points to be calculated per iteration. Every point consumes approximately 5KB of memory.",
121 MakeUintegerAccessor (&RadioEnvironmentMapHelper::m_maxPointsPerIteration),
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. ",
127 MakeUintegerAccessor (&RadioEnvironmentMapHelper::m_earfcn),
128 MakeUintegerChecker<uint16_t> ())
129 .AddAttribute (
"Bandwidth",
130 "Transmission Bandwidth Configuration (in number of RBs) over which the SINR will be calculated",
134 MakeUintegerChecker<uint16_t> ())
174 NS_FATAL_ERROR (
"only one REM supported per instance of RadioEnvironmentMapHelper");
177 if (match.
GetN () != 1)
179 NS_FATAL_ERROR (
"Lookup " << m_channelPath <<
" should have exactly one match");
182 NS_ABORT_MSG_IF (m_channel == 0,
"object at " << m_channelPath <<
"is not of type SpectrumChannel");
184 m_outFile.open (m_outputFile.c_str ());
185 if (!m_outFile.is_open ())
192 &RadioEnvironmentMapHelper::DelayedInstall,
198 RadioEnvironmentMapHelper::DelayedInstall ()
201 m_xStep = (m_xMax - m_xMin)/(m_xRes-1);
202 m_yStep = (m_yMax - m_yMin)/(m_yRes-1);
204 if ((
double)m_xRes * (double) m_yRes < (
double) m_maxPointsPerIteration)
206 m_maxPointsPerIteration = m_xRes * m_yRes;
209 for (uint32_t i = 0; i < m_maxPointsPerIteration; ++i)
212 p.phy = CreateObject<RemSpectrumPhy> ();
213 p.bmm = CreateObject<BuildingsMobilityModel> ();
215 p.phy->SetMobility (p.bmm);
216 m_channel->AddRx (p.phy);
220 double remIterationStartTime = 0.0001;
221 double xMinNext = m_xMin;
222 double yMinNext = m_yMin;
223 uint32_t numPointsCurrentIteration = 0;
224 bool justScheduled =
false;
225 for (
double x = m_xMin; x < m_xMax + 0.5*m_xStep; x += m_xStep)
227 for (
double y = m_yMin; y < m_yMax + 0.5*m_yStep ; y += m_yStep)
233 justScheduled =
false;
236 ++numPointsCurrentIteration;
237 if ((numPointsCurrentIteration == m_maxPointsPerIteration)
238 || ((x > m_xMax - 0.5*m_xStep) && (y > m_yMax - 0.5*m_yStep)) )
241 &RadioEnvironmentMapHelper::RunOneIteration,
242 this, xMinNext, x, yMinNext, y);
243 remIterationStartTime += 0.001;
244 justScheduled =
true;
245 numPointsCurrentIteration = 0;
250 &RadioEnvironmentMapHelper::Finalize,
256 RadioEnvironmentMapHelper::RunOneIteration (
double xMin,
double xMax,
double yMin,
double yMax)
259 std::list<RemPoint>::iterator remIt = m_rem.begin ();
262 for (x = xMin; x < xMax + 0.5*m_xStep; x += m_xStep)
264 for (y = (x == xMin) ? yMin : m_yMin;
265 y < ((x == xMax) ? yMax : m_yMax) + 0.5*m_yStep;
269 remIt->bmm->SetPosition (Vector (x, y, m_z));
270 BuildingsHelper::MakeConsistent (remIt->bmm);
275 if (remIt != m_rem.end ())
277 NS_ASSERT ((x > m_xMax - 0.5*m_xStep) && (y > m_yMax - 0.5*m_yStep));
278 NS_LOG_LOGIC (
"deactivating RemSpectrumPhys that are unneeded in the last iteration");
279 while (remIt != m_rem.end ())
281 remIt->phy->Deactivate ();
290 RadioEnvironmentMapHelper::PrintAndReset ()
294 for (std::list<RemPoint>::iterator it = m_rem.begin ();
298 if (!(it->phy->IsActive ()))
304 Vector pos = it->bmm->GetPosition ();
308 << it->phy->GetSinr (m_noisePower));
309 m_outFile << pos.x <<
"\t"
312 << it->phy->GetSinr (m_noisePower)
319 RadioEnvironmentMapHelper::Finalize ()
#define NS_LOG_FUNCTION(parameters)
hold variables of type string
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
static Ptr< SpectrumModel > GetSpectrumModel(uint16_t earfcn, uint8_t bandwidth)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
#define NS_FATAL_ERROR(msg)
fatal error handling
Config::MatchContainer LookupMatches(std::string path)
Hold an unsigned integer type.
uint8_t GetBandwidth() const
#define NS_LOG_LOGIC(msg)
uint32_t GetN(void) const
void SetBandwidth(uint8_t bw)
Ptr< Object > Get(uint32_t i) const
hold a set of objects which match a specific search string.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
a base class which provides memory management and object aggregation
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if cond is true.
Hold an floating point type.
virtual void DoDispose(void)
Ptr< T > GetObject(void) const
a unique identifier for an interface.
TypeId SetParent(TypeId tid)