A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
radio-environment-map-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012 CTTC
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
10
11#include <ns3/abort.h>
12#include <ns3/boolean.h>
13#include <ns3/buildings-helper.h>
14#include <ns3/config.h>
15#include <ns3/constant-position-mobility-model.h>
16#include <ns3/double.h>
17#include <ns3/integer.h>
18#include <ns3/log.h>
19#include <ns3/lte-spectrum-value-helper.h>
20#include <ns3/mobility-building-info.h>
21#include <ns3/node.h>
22#include <ns3/pointer.h>
23#include <ns3/rem-spectrum-phy.h>
24#include <ns3/simulator.h>
25#include <ns3/spectrum-channel.h>
26#include <ns3/string.h>
27#include <ns3/uinteger.h>
28
29#include <fstream>
30#include <limits>
31
32namespace ns3
33{
34
35NS_LOG_COMPONENT_DEFINE("RadioEnvironmentMapHelper");
36
37NS_OBJECT_ENSURE_REGISTERED(RadioEnvironmentMapHelper);
38
42
46
47void
52
55{
56 NS_LOG_FUNCTION("RadioEnvironmentMapHelper::GetTypeId");
57 static TypeId tid =
58 TypeId("ns3::RadioEnvironmentMapHelper")
60 .SetGroupName("Lte")
61 .AddConstructor<RadioEnvironmentMapHelper>()
62 .AddAttribute(
63 "Channel",
64 "The DL spectrum channel for which the RadioEnvironment Map is to be generated. "
65 "Alternatively ChannelPath attribute can be used."
66 "Only one of the two (Channel or ChannelPath) should be set.",
67 PointerValue(nullptr),
70 .AddAttribute(
71 "ChannelPath",
72 "The path to the channel for which the Radio Environment Map is to be generated."
73 "This attribute is an alternative to Channel attribute and is only used if Channel "
74 "is not set (equal to nullptr). "
75 "Only one of the two (Channel or ChannelPath) should be set.",
76 StringValue("/ChannelList/0"),
79 .AddAttribute("OutputFile",
80 "the filename to which the Radio Environment Map is saved",
81 StringValue("rem.out"),
84 .AddAttribute("XMin",
85 "The min x coordinate of the map.",
86 DoubleValue(0.0),
89 .AddAttribute("YMin",
90 "The min y coordinate of the map.",
91 DoubleValue(0.0),
94 .AddAttribute("XMax",
95 "The max x coordinate of the map.",
96 DoubleValue(1.0),
99 .AddAttribute("YMax",
100 "The max y coordinate of the map.",
101 DoubleValue(1.0),
104 .AddAttribute("XRes",
105 "The resolution (number of points) of the map along the x axis.",
106 UintegerValue(100),
108 MakeUintegerChecker<uint32_t>(2, std::numeric_limits<uint16_t>::max()))
109 .AddAttribute("YRes",
110 "The resolution (number of points) of the map along the y axis.",
111 UintegerValue(100),
113 MakeUintegerChecker<uint16_t>(2, std::numeric_limits<uint16_t>::max()))
114 .AddAttribute("Z",
115 "The value of the z coordinate for which the map is to be generated",
116 DoubleValue(0.0),
119 .AddAttribute(
120 "StopWhenDone",
121 "If true, Simulator::Stop () will be called as soon as the REM has been generated",
122 BooleanValue(true),
125 .AddAttribute(
126 "NoisePower",
127 "the power of the measuring instrument noise, in Watts. Default to a kT of -174 "
128 "dBm with a noise figure of 9 dB and a bandwidth of 25 LTE Resource Blocks",
129 DoubleValue(1.4230e-13),
132 .AddAttribute("MaxPointsPerIteration",
133 "Maximum number of REM points to be calculated per iteration. Every "
134 "point consumes approximately 5KB of memory.",
135 UintegerValue(20000),
137 MakeUintegerChecker<uint32_t>(1, std::numeric_limits<uint32_t>::max()))
138 .AddAttribute("Earfcn",
139 "E-UTRA Absolute Radio Frequency Channel Number (EARFCN) "
140 "as per 3GPP 36.101 Section 5.7.3.",
141 UintegerValue(100),
144 .AddAttribute("Bandwidth",
145 "Transmission Bandwidth Configuration (in number of RBs) over which the "
146 "SINR will be calculated",
147 UintegerValue(25),
151 .AddAttribute("UseDataChannel",
152 "If true, REM will be generated for PDSCH and for PDCCH otherwise",
153 BooleanValue(false),
156 .AddAttribute("RbId",
157 "Resource block Id, for which REM will be generated, "
158 "default value is -1, what means REM will be averaged from all RBs",
159 IntegerValue(-1),
162 return tid;
163}
164
165uint16_t
170
171void
173{
174 switch (bw)
175 {
176 case 6:
177 case 15:
178 case 25:
179 case 50:
180 case 75:
181 case 100:
182 m_bandwidth = bw;
183 break;
184
185 default:
186 NS_FATAL_ERROR("invalid bandwidth value " << bw);
187 break;
188 }
189}
190
191void
193{
194 NS_LOG_FUNCTION(this);
195 if (!m_rem.empty())
196 {
197 NS_FATAL_ERROR("only one REM supported per instance of RadioEnvironmentMapHelper");
198 }
199
200 if (!m_channel) // if Channel attribute is not set, then use the ChannelPath attribute
201 {
203 if (match.GetN() != 1)
204 {
205 NS_FATAL_ERROR("Lookup " << m_channelPath << " should have exactly one match");
206 }
207 m_channel = match.Get(0)->GetObject<SpectrumChannel>();
209 "object at " << m_channelPath << " is not of type SpectrumChannel");
210 }
211
212 m_outFile.open(m_outputFile.c_str());
213 if (!m_outFile.is_open())
214 {
215 NS_FATAL_ERROR("Can't open file " << (m_outputFile));
216 return;
217 }
218
219 double startDelay = 0.0026;
220
222 {
223 // need time to start transmission of data channel
224 startDelay = 0.5001;
225 }
226
228}
229
230void
232{
233 NS_LOG_FUNCTION(this);
234 m_xStep = (m_xMax - m_xMin) / (m_xRes - 1);
235 m_yStep = (m_yMax - m_yMin) / (m_yRes - 1);
236
237 if ((double)m_xRes * (double)m_yRes < (double)m_maxPointsPerIteration)
238 {
240 }
241
242 for (uint32_t i = 0; i < m_maxPointsPerIteration; ++i)
243 {
244 RemPoint p;
248 p.bmm->AggregateObject(buildingInfo); // operation usually done by BuildingsHelper::Install
250 p.phy->SetMobility(p.bmm);
251 p.phy->SetUseDataChannel(m_useDataChannel);
252 p.phy->SetRbId(m_rbId);
253 m_channel->AddRx(p.phy);
254 m_rem.push_back(p);
255 }
256
257 double remIterationStartTime = 0.0001;
258 double xMinNext = m_xMin;
259 double yMinNext = m_yMin;
260 uint32_t numPointsCurrentIteration = 0;
261 bool justScheduled = false;
262 for (double x = m_xMin; x < m_xMax + 0.5 * m_xStep; x += m_xStep)
263 {
264 for (double y = m_yMin; y < m_yMax + 0.5 * m_yStep; y += m_yStep)
265 {
266 if (justScheduled)
267 {
268 xMinNext = x;
269 yMinNext = y;
270 justScheduled = false;
271 }
272
273 ++numPointsCurrentIteration;
274 if ((numPointsCurrentIteration == m_maxPointsPerIteration) ||
275 ((x > m_xMax - 0.5 * m_xStep) && (y > m_yMax - 0.5 * m_yStep)))
276 {
277 Simulator::Schedule(Seconds(remIterationStartTime),
279 this,
280 xMinNext,
281 x,
282 yMinNext,
283 y);
284 remIterationStartTime += 0.001;
285 justScheduled = true;
286 numPointsCurrentIteration = 0;
287 }
288 }
289 }
290
292}
293
294void
295RadioEnvironmentMapHelper::RunOneIteration(double xMin, double xMax, double yMin, double yMax)
296{
297 NS_LOG_FUNCTION(this << xMin << xMax << yMin << yMax);
298 auto remIt = m_rem.begin();
299 double x = 0.0;
300 double y = 0.0;
301 for (x = xMin; x < xMax + 0.5 * m_xStep; x += m_xStep)
302 {
303 for (y = (x == xMin) ? yMin : m_yMin; y < ((x == xMax) ? yMax : m_yMax) + 0.5 * m_yStep;
304 y += m_yStep)
305 {
306 NS_ASSERT(remIt != m_rem.end());
307 remIt->bmm->SetPosition(Vector(x, y, m_z));
308 Ptr<MobilityBuildingInfo> buildingInfo =
309 (remIt->bmm)->GetObject<MobilityBuildingInfo>();
310 buildingInfo->MakeConsistent(remIt->bmm);
311 ++remIt;
312 }
313 }
314
315 if (remIt != m_rem.end())
316 {
317 NS_ASSERT((x > m_xMax - 0.5 * m_xStep) && (y > m_yMax - 0.5 * m_yStep));
318 NS_LOG_LOGIC("deactivating RemSpectrumPhys that are unneeded in the last iteration");
319 while (remIt != m_rem.end())
320 {
321 remIt->phy->Deactivate();
322 ++remIt;
323 }
324 }
325
327}
328
329void
331{
332 NS_LOG_FUNCTION(this);
333
334 for (auto it = m_rem.begin(); it != m_rem.end(); ++it)
335 {
336 if (!(it->phy->IsActive()))
337 {
338 // should occur only upon last iteration when some RemPoint
339 // at the end of the list can be unused
340 break;
341 }
342 Vector pos = it->bmm->GetPosition();
343 NS_LOG_LOGIC("output: " << pos.x << "\t" << pos.y << "\t" << pos.z << "\t"
344 << it->phy->GetSinr(m_noisePower));
345 m_outFile << pos.x << "\t" << pos.y << "\t" << pos.z << "\t"
346 << it->phy->GetSinr(m_noisePower) << std::endl;
347 it->phy->Reset();
348 }
349}
350
351void
353{
354 NS_LOG_FUNCTION(this);
355 m_outFile.close();
356 if (m_stopWhenDone)
357 {
359 }
360}
361
362} // namespace ns3
AttributeValue implementation for Boolean.
Definition boolean.h:26
hold a set of objects which match a specific search string.
Definition config.h:184
Ptr< Object > Get(std::size_t i) const
Definition config.cc:75
std::size_t GetN() const
Definition config.cc:68
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Hold a signed integer type.
Definition integer.h:34
static Ptr< SpectrumModel > GetSpectrumModel(uint32_t earfcn, uint16_t bandwidth)
A base class which provides memory management and object aggregation.
Definition object.h:78
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
Generates a 2D map of the SINR from the strongest transmitter in the downlink of an LTE FDD system.
void Install()
Deploy the RemSpectrumPhy objects that generate the map according to the specified settings.
static TypeId GetTypeId()
Register this type.
std::list< RemPoint > m_rem
List of listeners in the environment.
Ptr< SpectrumChannel > m_channel
The Channel attribute, which is a direct pointer to the DL channel object for which will be created t...
std::ofstream m_outFile
Stream the output to a file.
bool m_useDataChannel
The UseDataChannel attribute.
std::string m_outputFile
The OutputFile attribute.
double m_noisePower
The NoisePower attribute.
void Finalize()
Called when the map generation procedure has been completed.
void DoDispose() override
Destructor implementation.
uint32_t m_maxPointsPerIteration
The MaxPointsPerIteration attribute.
double m_xStep
Distance along X axis between adjacent listening points.
void DelayedInstall()
Scheduled by Install() to perform the actual generation of map.
std::string m_channelPath
The ChannelPath attribute.
void PrintAndReset()
Go through every listener, write the computed SINR, and then reset it.
uint16_t m_bandwidth
The Bandwidth attribute.
void RunOneIteration(double xMin, double xMax, double yMin, double yMax)
Mobilize all the listeners to a specified area.
double m_yStep
Distance along Y axis between adjacent listening points.
bool m_stopWhenDone
The StopWhenDone attribute.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Defines the interface for spectrum-aware channel implementations.
Hold variables of type string.
Definition string.h:45
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
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:70
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
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:32
Ptr< const AttributeChecker > MakeIntegerChecker()
Definition integer.h:99
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:35
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition pointer.h:248
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Definition pointer.h:269
Ptr< const AttributeChecker > MakeStringChecker()
Definition string.cc:19
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:46
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
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:35
MatchContainer LookupMatches(std::string path)
Definition config.cc:991
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Every class exported by the ns3 library is enclosed in the ns3 namespace.
A complete Radio Environment Map is composed of many of this structure.
Ptr< RemSpectrumPhy > phy
Simplified listener which compute SINR over the DL channel.
Ptr< MobilityModel > bmm
Position of the listener in the environment.