A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lena-frequency-reuse.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 Piotr Gawlowicz
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Piotr Gawlowicz <gawlowicz.p@gmail.com>
18 *
19 */
20
21#include "ns3/config-store.h"
22#include "ns3/core-module.h"
23#include "ns3/lte-module.h"
24#include "ns3/mobility-module.h"
25#include "ns3/network-module.h"
26#include <ns3/buildings-helper.h>
27#include <ns3/log.h>
28#include <ns3/spectrum-module.h>
29
30using namespace ns3;
31
32NS_LOG_COMPONENT_DEFINE("LenaFrequencyReuse");
33
34void
35PrintGnuplottableUeListToFile(std::string filename)
36{
37 std::ofstream outFile;
38 outFile.open(filename, std::ios_base::out | std::ios_base::trunc);
39 if (!outFile.is_open())
40 {
41 NS_LOG_ERROR("Can't open file " << filename);
42 return;
43 }
44 for (auto it = NodeList::Begin(); it != NodeList::End(); ++it)
45 {
46 Ptr<Node> node = *it;
47 int nDevs = node->GetNDevices();
48 for (int j = 0; j < nDevs; j++)
49 {
50 Ptr<LteUeNetDevice> uedev = node->GetDevice(j)->GetObject<LteUeNetDevice>();
51 if (uedev)
52 {
53 Vector pos = node->GetObject<MobilityModel>()->GetPosition();
54 outFile << "set label \"" << uedev->GetImsi() << "\" at " << pos.x << "," << pos.y
55 << " left font \"Helvetica,4\" textcolor rgb \"grey\" front point pt 1 ps "
56 "0.3 lc rgb \"grey\" offset 0,0"
57 << std::endl;
58 }
59 }
60 }
61}
62
63void
64PrintGnuplottableEnbListToFile(std::string filename)
65{
66 std::ofstream outFile;
67 outFile.open(filename, std::ios_base::out | std::ios_base::trunc);
68 if (!outFile.is_open())
69 {
70 NS_LOG_ERROR("Can't open file " << filename);
71 return;
72 }
73 for (auto it = NodeList::Begin(); it != NodeList::End(); ++it)
74 {
75 Ptr<Node> node = *it;
76 int nDevs = node->GetNDevices();
77 for (int j = 0; j < nDevs; j++)
78 {
79 Ptr<LteEnbNetDevice> enbdev = node->GetDevice(j)->GetObject<LteEnbNetDevice>();
80 if (enbdev)
81 {
82 Vector pos = node->GetObject<MobilityModel>()->GetPosition();
83 outFile << "set label \"" << enbdev->GetCellId() << "\" at " << pos.x << ","
84 << pos.y
85 << " left font \"Helvetica,4\" textcolor rgb \"white\" front point pt 2 "
86 "ps 0.3 lc rgb \"white\" offset 0,0"
87 << std::endl;
88 }
89 }
90 }
91}
92
93int
94main(int argc, char* argv[])
95{
96 Config::SetDefault("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue(true));
97 Config::SetDefault("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue(true));
98 Config::SetDefault("ns3::LteHelper::UseIdealRrc", BooleanValue(true));
99 Config::SetDefault("ns3::LteHelper::UsePdschForCqiGeneration", BooleanValue(true));
100
101 // Uplink Power Control
102 Config::SetDefault("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue(true));
103 Config::SetDefault("ns3::LteUePowerControl::ClosedLoop", BooleanValue(true));
104 Config::SetDefault("ns3::LteUePowerControl::AccumulationEnabled", BooleanValue(false));
105
106 uint32_t runId = 3;
107 uint16_t numberOfRandomUes = 0;
108 double simTime = 2.500;
109 bool generateSpectrumTrace = false;
110 bool generateRem = false;
111 int32_t remRbId = -1;
112 uint16_t bandwidth = 25;
113 double distance = 1000;
114 Box macroUeBox =
115 Box(-distance * 0.5, distance * 1.5, -distance * 0.5, distance * 1.5, 1.5, 1.5);
116
117 // Command line arguments
118 CommandLine cmd(__FILE__);
119 cmd.AddValue("numberOfUes", "Number of random UEs", numberOfRandomUes);
120 cmd.AddValue("simTime", "Total duration of the simulation (in seconds)", simTime);
121 cmd.AddValue("generateSpectrumTrace",
122 "if true, will generate a Spectrum Analyzer trace",
123 generateSpectrumTrace);
124 cmd.AddValue("generateRem",
125 "if true, will generate a REM and then abort the simulation",
126 generateRem);
127 cmd.AddValue("remRbId",
128 "Resource Block Id, for which REM will be generated,"
129 "default value is -1, what means REM will be averaged from all RBs",
130 remRbId);
131 cmd.AddValue("runId", "runId", runId);
132 cmd.Parse(argc, argv);
133
136
137 Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
138
139 // Create Nodes: eNodeB and UE
140 NodeContainer enbNodes;
141 NodeContainer centerUeNodes;
142 NodeContainer edgeUeNodes;
143 NodeContainer randomUeNodes;
144 enbNodes.Create(3);
145 centerUeNodes.Create(3);
146 edgeUeNodes.Create(3);
147 randomUeNodes.Create(numberOfRandomUes);
148
149 /* the topology is the following:
150 * eNB3
151 * / \
152 * / \
153 * / \
154 * / \
155 * distance / \ distance
156 * / UEs \
157 * / \
158 * / \
159 * / \
160 * / \
161 * eNB1-------------------------eNB2
162 * distance
163 */
164
165 // Install Mobility Model
166 Ptr<ListPositionAllocator> enbPositionAlloc = CreateObject<ListPositionAllocator>();
167 enbPositionAlloc->Add(Vector(0.0, 0.0, 0.0)); // eNB1
168 enbPositionAlloc->Add(Vector(distance, 0.0, 0.0)); // eNB2
169 enbPositionAlloc->Add(Vector(distance * 0.5, distance * 0.866, 0.0)); // eNB3
171 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
172 mobility.SetPositionAllocator(enbPositionAlloc);
173 mobility.Install(enbNodes);
174
175 Ptr<ListPositionAllocator> edgeUePositionAlloc = CreateObject<ListPositionAllocator>();
176 edgeUePositionAlloc->Add(Vector(distance * 0.5, distance * 0.28867, 0.0)); // edgeUE1
177 edgeUePositionAlloc->Add(Vector(distance * 0.5, distance * 0.28867, 0.0)); // edgeUE2
178 edgeUePositionAlloc->Add(Vector(distance * 0.5, distance * 0.28867, 0.0)); // edgeUE3
179 mobility.SetPositionAllocator(edgeUePositionAlloc);
180 mobility.Install(edgeUeNodes);
181
182 Ptr<ListPositionAllocator> centerUePositionAlloc = CreateObject<ListPositionAllocator>();
183 centerUePositionAlloc->Add(Vector(0.0, 0.0, 0.0)); // centerUE1
184 centerUePositionAlloc->Add(Vector(distance, 0.0, 0.0)); // centerUE2
185 centerUePositionAlloc->Add(Vector(distance * 0.5, distance * 0.866, 0.0)); // centerUE3
186 mobility.SetPositionAllocator(centerUePositionAlloc);
187 mobility.Install(centerUeNodes);
188
189 Ptr<RandomBoxPositionAllocator> randomUePositionAlloc =
190 CreateObject<RandomBoxPositionAllocator>();
191 Ptr<UniformRandomVariable> xVal = CreateObject<UniformRandomVariable>();
192 xVal->SetAttribute("Min", DoubleValue(macroUeBox.xMin));
193 xVal->SetAttribute("Max", DoubleValue(macroUeBox.xMax));
194 randomUePositionAlloc->SetAttribute("X", PointerValue(xVal));
195 Ptr<UniformRandomVariable> yVal = CreateObject<UniformRandomVariable>();
196 yVal->SetAttribute("Min", DoubleValue(macroUeBox.yMin));
197 yVal->SetAttribute("Max", DoubleValue(macroUeBox.yMax));
198 randomUePositionAlloc->SetAttribute("Y", PointerValue(yVal));
199 Ptr<UniformRandomVariable> zVal = CreateObject<UniformRandomVariable>();
200 zVal->SetAttribute("Min", DoubleValue(macroUeBox.zMin));
201 zVal->SetAttribute("Max", DoubleValue(macroUeBox.zMax));
202 randomUePositionAlloc->SetAttribute("Z", PointerValue(zVal));
203 mobility.SetPositionAllocator(randomUePositionAlloc);
204 mobility.Install(randomUeNodes);
205
206 // Create Devices and install them in the Nodes (eNB and UE)
207 NetDeviceContainer enbDevs;
208 NetDeviceContainer edgeUeDevs;
209 NetDeviceContainer centerUeDevs;
210 NetDeviceContainer randomUeDevs;
211 lteHelper->SetSchedulerType("ns3::PfFfMacScheduler");
212 lteHelper->SetSchedulerAttribute("UlCqiFilter", EnumValue(FfMacScheduler::PUSCH_UL_CQI));
213 lteHelper->SetEnbDeviceAttribute("DlBandwidth", UintegerValue(bandwidth));
214 lteHelper->SetEnbDeviceAttribute("UlBandwidth", UintegerValue(bandwidth));
215
216 std::string frAlgorithmType = lteHelper->GetFfrAlgorithmType();
217 NS_LOG_DEBUG("FrAlgorithmType: " << frAlgorithmType);
218
219 if (frAlgorithmType == "ns3::LteFrHardAlgorithm")
220 {
221 // Nothing to configure here in automatic mode
222 }
223 else if (frAlgorithmType == "ns3::LteFrStrictAlgorithm")
224 {
225 lteHelper->SetFfrAlgorithmAttribute("RsrqThreshold", UintegerValue(32));
226 lteHelper->SetFfrAlgorithmAttribute("CenterPowerOffset",
228 lteHelper->SetFfrAlgorithmAttribute("EdgePowerOffset",
230 lteHelper->SetFfrAlgorithmAttribute("CenterAreaTpc", UintegerValue(0));
231 lteHelper->SetFfrAlgorithmAttribute("EdgeAreaTpc", UintegerValue(3));
232
233 // ns3::LteFrStrictAlgorithm works with Absolute Mode Uplink Power Control
234 Config::SetDefault("ns3::LteUePowerControl::AccumulationEnabled", BooleanValue(false));
235 }
236 else if (frAlgorithmType == "ns3::LteFrSoftAlgorithm")
237 {
238 lteHelper->SetFfrAlgorithmAttribute("AllowCenterUeUseEdgeSubBand", BooleanValue(true));
239 lteHelper->SetFfrAlgorithmAttribute("RsrqThreshold", UintegerValue(25));
240 lteHelper->SetFfrAlgorithmAttribute("CenterPowerOffset",
242 lteHelper->SetFfrAlgorithmAttribute("EdgePowerOffset",
244 lteHelper->SetFfrAlgorithmAttribute("CenterAreaTpc", UintegerValue(0));
245 lteHelper->SetFfrAlgorithmAttribute("EdgeAreaTpc", UintegerValue(3));
246
247 // ns3::LteFrSoftAlgorithm works with Absolute Mode Uplink Power Control
248 Config::SetDefault("ns3::LteUePowerControl::AccumulationEnabled", BooleanValue(false));
249 }
250 else if (frAlgorithmType == "ns3::LteFfrSoftAlgorithm")
251 {
252 lteHelper->SetFfrAlgorithmAttribute("CenterRsrqThreshold", UintegerValue(30));
253 lteHelper->SetFfrAlgorithmAttribute("EdgeRsrqThreshold", UintegerValue(25));
254 lteHelper->SetFfrAlgorithmAttribute("CenterAreaPowerOffset",
256 lteHelper->SetFfrAlgorithmAttribute(
257 "MediumAreaPowerOffset",
259 lteHelper->SetFfrAlgorithmAttribute("EdgeAreaPowerOffset",
261 lteHelper->SetFfrAlgorithmAttribute("CenterAreaTpc", UintegerValue(1));
262 lteHelper->SetFfrAlgorithmAttribute("MediumAreaTpc", UintegerValue(2));
263 lteHelper->SetFfrAlgorithmAttribute("EdgeAreaTpc", UintegerValue(3));
264
265 // ns3::LteFfrSoftAlgorithm works with Absolute Mode Uplink Power Control
266 Config::SetDefault("ns3::LteUePowerControl::AccumulationEnabled", BooleanValue(false));
267 }
268 else if (frAlgorithmType == "ns3::LteFfrEnhancedAlgorithm")
269 {
270 lteHelper->SetFfrAlgorithmAttribute("RsrqThreshold", UintegerValue(25));
271 lteHelper->SetFfrAlgorithmAttribute("DlCqiThreshold", UintegerValue(10));
272 lteHelper->SetFfrAlgorithmAttribute("UlCqiThreshold", UintegerValue(10));
273 lteHelper->SetFfrAlgorithmAttribute("CenterAreaPowerOffset",
275 lteHelper->SetFfrAlgorithmAttribute("EdgeAreaPowerOffset",
277 lteHelper->SetFfrAlgorithmAttribute("CenterAreaTpc", UintegerValue(0));
278 lteHelper->SetFfrAlgorithmAttribute("EdgeAreaTpc", UintegerValue(3));
279
280 // ns3::LteFfrEnhancedAlgorithm works with Absolute Mode Uplink Power Control
281 Config::SetDefault("ns3::LteUePowerControl::AccumulationEnabled", BooleanValue(false));
282 }
283 else if (frAlgorithmType == "ns3::LteFfrDistributedAlgorithm")
284 {
285 NS_FATAL_ERROR("ns3::LteFfrDistributedAlgorithm not supported in this example. Please run "
286 "lena-distributed-ffr");
287 }
288 else
289 {
290 lteHelper->SetFfrAlgorithmType("ns3::LteFrNoOpAlgorithm");
291 }
292
293 lteHelper->SetFfrAlgorithmAttribute("FrCellTypeId", UintegerValue(1));
294 enbDevs.Add(lteHelper->InstallEnbDevice(enbNodes.Get(0)));
295
296 lteHelper->SetFfrAlgorithmAttribute("FrCellTypeId", UintegerValue(2));
297 enbDevs.Add(lteHelper->InstallEnbDevice(enbNodes.Get(1)));
298
299 lteHelper->SetFfrAlgorithmAttribute("FrCellTypeId", UintegerValue(3));
300 enbDevs.Add(lteHelper->InstallEnbDevice(enbNodes.Get(2)));
301
302 // FR algorithm reconfiguration if needed
303 PointerValue tmp;
304 enbDevs.Get(0)->GetAttribute("LteFfrAlgorithm", tmp);
305 Ptr<LteFfrAlgorithm> ffrAlgorithm = DynamicCast<LteFfrAlgorithm>(tmp.GetObject());
306 ffrAlgorithm->SetAttribute("FrCellTypeId", UintegerValue(1));
307
308 // Install Ue Device
309 edgeUeDevs = lteHelper->InstallUeDevice(edgeUeNodes);
310 centerUeDevs = lteHelper->InstallUeDevice(centerUeNodes);
311 randomUeDevs = lteHelper->InstallUeDevice(randomUeNodes);
312
313 // Attach edge UEs to eNbs
314 for (uint32_t i = 0; i < edgeUeDevs.GetN(); i++)
315 {
316 lteHelper->Attach(edgeUeDevs.Get(i), enbDevs.Get(i));
317 }
318 // Attach center UEs to eNbs
319 for (uint32_t i = 0; i < centerUeDevs.GetN(); i++)
320 {
321 lteHelper->Attach(centerUeDevs.Get(i), enbDevs.Get(i));
322 }
323
324 // Attach UE to a eNB
325 lteHelper->AttachToClosestEnb(randomUeDevs, enbDevs);
326
327 // Activate a data radio bearer
329 EpsBearer bearer(q);
330 lteHelper->ActivateDataRadioBearer(edgeUeDevs, bearer);
331 lteHelper->ActivateDataRadioBearer(centerUeDevs, bearer);
332 lteHelper->ActivateDataRadioBearer(randomUeDevs, bearer);
333
334 // Spectrum analyzer
335 NodeContainer spectrumAnalyzerNodes;
336 spectrumAnalyzerNodes.Create(1);
337 SpectrumAnalyzerHelper spectrumAnalyzerHelper;
338
339 if (generateSpectrumTrace)
340 {
341 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
342 // position of Spectrum Analyzer
343 // positionAlloc->Add (Vector (0.0, 0.0, 0.0)); // eNB1
344 // positionAlloc->Add (Vector (distance, 0.0, 0.0)); // eNB2
345 positionAlloc->Add(Vector(distance * 0.5, distance * 0.866, 0.0)); // eNB3
346
348 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
349 mobility.SetPositionAllocator(positionAlloc);
350 mobility.Install(spectrumAnalyzerNodes);
351
352 Ptr<LteSpectrumPhy> enbDlSpectrumPhy = enbDevs.Get(0)
353 ->GetObject<LteEnbNetDevice>()
354 ->GetPhy()
355 ->GetDownlinkSpectrumPhy()
357 Ptr<SpectrumChannel> dlChannel = enbDlSpectrumPhy->GetChannel();
358
359 spectrumAnalyzerHelper.SetChannel(dlChannel);
361 spectrumAnalyzerHelper.SetRxSpectrumModel(sm);
362 spectrumAnalyzerHelper.SetPhyAttribute("Resolution", TimeValue(MicroSeconds(10)));
363 spectrumAnalyzerHelper.SetPhyAttribute("NoisePowerSpectralDensity",
364 DoubleValue(1e-15)); // -120 dBm/Hz
365 spectrumAnalyzerHelper.EnableAsciiAll("spectrum-analyzer-output");
366 spectrumAnalyzerHelper.Install(spectrumAnalyzerNodes);
367 }
368
370 if (generateRem)
371 {
374
375 remHelper = CreateObject<RadioEnvironmentMapHelper>();
376 remHelper->SetAttribute("ChannelPath", StringValue("/ChannelList/0"));
377 remHelper->SetAttribute("OutputFile", StringValue("lena-frequency-reuse.rem"));
378 remHelper->SetAttribute("XMin", DoubleValue(macroUeBox.xMin));
379 remHelper->SetAttribute("XMax", DoubleValue(macroUeBox.xMax));
380 remHelper->SetAttribute("YMin", DoubleValue(macroUeBox.yMin));
381 remHelper->SetAttribute("YMax", DoubleValue(macroUeBox.yMax));
382 remHelper->SetAttribute("Z", DoubleValue(1.5));
383 remHelper->SetAttribute("XRes", UintegerValue(500));
384 remHelper->SetAttribute("YRes", UintegerValue(500));
385 if (remRbId >= 0)
386 {
387 remHelper->SetAttribute("UseDataChannel", BooleanValue(true));
388 remHelper->SetAttribute("RbId", IntegerValue(remRbId));
389 }
390
391 remHelper->Install();
392 // simulation will stop right after the REM has been generated
393 }
394 else
395 {
396 Simulator::Stop(Seconds(simTime));
397 }
398
401 return 0;
402}
AttributeValue implementation for Boolean.
Definition: boolean.h:37
a 3d box
Definition: box.h:35
double yMax
The y coordinate of the top bound of the box.
Definition: box.h:116
double xMin
The x coordinate of the left bound of the box.
Definition: box.h:110
double yMin
The y coordinate of the bottom bound of the box.
Definition: box.h:114
double xMax
The x coordinate of the right bound of the box.
Definition: box.h:112
double zMin
The z coordinate of the down bound of the box.
Definition: box.h:118
double zMax
The z coordinate of the up bound of the box.
Definition: box.h:120
Parse command-line arguments.
Definition: command-line.h:232
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Hold variables of type enum.
Definition: enum.h:56
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:91
Qci
QoS Class Indicator.
Definition: eps-bearer.h:106
@ GBR_CONV_VOICE
GBR Conversational Voice.
Definition: eps-bearer.h:107
Hold a signed integer type.
Definition: integer.h:45
The eNodeB device implementation.
The LteSpectrumPhy models the physical layer of LTE.
static Ptr< SpectrumModel > GetSpectrumModel(uint32_t earfcn, uint16_t bandwidth)
The LteUeNetDevice class implements the UE net device.
Helper class used to assign positions and mobility models to nodes.
Keep track of the current position and velocity of an object.
holds a vector of ns3::NetDevice pointers
uint32_t GetN() const
Get the number of Ptr<NetDevice> stored in this container.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
static Iterator Begin()
Definition: node-list.cc:237
static Iterator End()
Definition: node-list.cc:244
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Ptr< Object > GetObject() const
Get the Object referenced by the PointerValue.
Definition: pointer.cc:57
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static void Run()
Run the simulation.
Definition: simulator.cc:176
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:184
Class to allow the Spectrum Analysis.
NetDeviceContainer Install(NodeContainer c) const
void SetPhyAttribute(std::string name, const AttributeValue &v)
void SetChannel(Ptr< SpectrumChannel > channel)
Set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper.
void EnableAsciiAll(std::string prefix)
Enable ASCII output.
void SetRxSpectrumModel(Ptr< SpectrumModel > m)
Set the spectrum model used by the created SpectrumAnalyzer instances to represent incoming signals.
Hold variables of type string.
Definition: string.h:56
AttributeValue implementation for Time.
Definition: nstime.h:1412
Hold an unsigned integer type.
Definition: uinteger.h:45
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:890
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1349
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1325
void PrintGnuplottableEnbListToFile(std::string filename)
void PrintGnuplottableUeListToFile(std::string filename)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns cmd
Definition: second.py:33
ns mobility
Definition: third.py:96