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/core-module.h"
22#include "ns3/lte-module.h"
23#include "ns3/mobility-module.h"
24#include "ns3/network-module.h"
25#include <ns3/buildings-helper.h>
26#include <ns3/log.h>
27#include <ns3/spectrum-module.h>
28
29using namespace ns3;
30
31NS_LOG_COMPONENT_DEFINE("LenaFrequencyReuse");
32
33void
34PrintGnuplottableUeListToFile(std::string filename)
35{
36 std::ofstream outFile;
37 outFile.open(filename, std::ios_base::out | std::ios_base::trunc);
38 if (!outFile.is_open())
39 {
40 NS_LOG_ERROR("Can't open file " << filename);
41 return;
42 }
43 for (auto it = NodeList::Begin(); it != NodeList::End(); ++it)
44 {
45 Ptr<Node> node = *it;
46 int nDevs = node->GetNDevices();
47 for (int j = 0; j < nDevs; j++)
48 {
49 Ptr<LteUeNetDevice> uedev = node->GetDevice(j)->GetObject<LteUeNetDevice>();
50 if (uedev)
51 {
52 Vector pos = node->GetObject<MobilityModel>()->GetPosition();
53 outFile << "set label \"" << uedev->GetImsi() << "\" at " << pos.x << "," << pos.y
54 << " left font \"Helvetica,4\" textcolor rgb \"grey\" front point pt 1 ps "
55 "0.3 lc rgb \"grey\" offset 0,0"
56 << std::endl;
57 }
58 }
59 }
60}
61
62void
63PrintGnuplottableEnbListToFile(std::string filename)
64{
65 std::ofstream outFile;
66 outFile.open(filename, std::ios_base::out | std::ios_base::trunc);
67 if (!outFile.is_open())
68 {
69 NS_LOG_ERROR("Can't open file " << filename);
70 return;
71 }
72 for (auto it = NodeList::Begin(); it != NodeList::End(); ++it)
73 {
74 Ptr<Node> node = *it;
75 int nDevs = node->GetNDevices();
76 for (int j = 0; j < nDevs; j++)
77 {
78 Ptr<LteEnbNetDevice> enbdev = node->GetDevice(j)->GetObject<LteEnbNetDevice>();
79 if (enbdev)
80 {
81 Vector pos = node->GetObject<MobilityModel>()->GetPosition();
82 outFile << "set label \"" << enbdev->GetCellId() << "\" at " << pos.x << ","
83 << pos.y
84 << " left font \"Helvetica,4\" textcolor rgb \"white\" front point pt 2 "
85 "ps 0.3 lc rgb \"white\" offset 0,0"
86 << std::endl;
87 }
88 }
89 }
90}
91
92int
93main(int argc, char* argv[])
94{
95 Config::SetDefault("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue(true));
96 Config::SetDefault("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue(true));
97 Config::SetDefault("ns3::LteHelper::UseIdealRrc", BooleanValue(true));
98 Config::SetDefault("ns3::LteHelper::UsePdschForCqiGeneration", BooleanValue(true));
99
100 // Uplink Power Control
101 Config::SetDefault("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue(true));
102 Config::SetDefault("ns3::LteUePowerControl::ClosedLoop", BooleanValue(true));
103 Config::SetDefault("ns3::LteUePowerControl::AccumulationEnabled", BooleanValue(false));
104
105 uint32_t runId = 3;
106 uint16_t numberOfRandomUes = 0;
107 double simTime = 2.500;
108 bool generateSpectrumTrace = false;
109 bool generateRem = false;
110 int32_t remRbId = -1;
111 uint16_t bandwidth = 25;
112 double distance = 1000;
113 Box macroUeBox =
114 Box(-distance * 0.5, distance * 1.5, -distance * 0.5, distance * 1.5, 1.5, 1.5);
115
116 // Command line arguments
117 CommandLine cmd(__FILE__);
118 cmd.AddValue("numberOfUes", "Number of random UEs", numberOfRandomUes);
119 cmd.AddValue("simTime", "Total duration of the simulation (in seconds)", simTime);
120 cmd.AddValue("generateSpectrumTrace",
121 "if true, will generate a Spectrum Analyzer trace",
122 generateSpectrumTrace);
123 cmd.AddValue("generateRem",
124 "if true, will generate a REM and then abort the simulation",
125 generateRem);
126 cmd.AddValue("remRbId",
127 "Resource Block Id, for which REM will be generated,"
128 "default value is -1, what means REM will be averaged from all RBs",
129 remRbId);
130 cmd.AddValue("runId", "runId", runId);
131 cmd.Parse(argc, argv);
132
135
136 Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
137
138 // Create Nodes: eNodeB and UE
139 NodeContainer enbNodes;
140 NodeContainer centerUeNodes;
141 NodeContainer edgeUeNodes;
142 NodeContainer randomUeNodes;
143 enbNodes.Create(3);
144 centerUeNodes.Create(3);
145 edgeUeNodes.Create(3);
146 randomUeNodes.Create(numberOfRandomUes);
147
148 /* the topology is the following:
149 * eNB3
150 * / \
151 * / \
152 * / \
153 * / \
154 * distance / \ distance
155 * / UEs \
156 * / \
157 * / \
158 * / \
159 * / \
160 * eNB1-------------------------eNB2
161 * distance
162 */
163
164 // Install Mobility Model
165 Ptr<ListPositionAllocator> enbPositionAlloc = CreateObject<ListPositionAllocator>();
166 enbPositionAlloc->Add(Vector(0.0, 0.0, 0.0)); // eNB1
167 enbPositionAlloc->Add(Vector(distance, 0.0, 0.0)); // eNB2
168 enbPositionAlloc->Add(Vector(distance * 0.5, distance * 0.866, 0.0)); // eNB3
170 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
171 mobility.SetPositionAllocator(enbPositionAlloc);
172 mobility.Install(enbNodes);
173
174 Ptr<ListPositionAllocator> edgeUePositionAlloc = CreateObject<ListPositionAllocator>();
175 edgeUePositionAlloc->Add(Vector(distance * 0.5, distance * 0.28867, 0.0)); // edgeUE1
176 edgeUePositionAlloc->Add(Vector(distance * 0.5, distance * 0.28867, 0.0)); // edgeUE2
177 edgeUePositionAlloc->Add(Vector(distance * 0.5, distance * 0.28867, 0.0)); // edgeUE3
178 mobility.SetPositionAllocator(edgeUePositionAlloc);
179 mobility.Install(edgeUeNodes);
180
181 Ptr<ListPositionAllocator> centerUePositionAlloc = CreateObject<ListPositionAllocator>();
182 centerUePositionAlloc->Add(Vector(0.0, 0.0, 0.0)); // centerUE1
183 centerUePositionAlloc->Add(Vector(distance, 0.0, 0.0)); // centerUE2
184 centerUePositionAlloc->Add(Vector(distance * 0.5, distance * 0.866, 0.0)); // centerUE3
185 mobility.SetPositionAllocator(centerUePositionAlloc);
186 mobility.Install(centerUeNodes);
187
188 Ptr<RandomBoxPositionAllocator> randomUePositionAlloc =
189 CreateObject<RandomBoxPositionAllocator>();
190 Ptr<UniformRandomVariable> xVal = CreateObject<UniformRandomVariable>();
191 xVal->SetAttribute("Min", DoubleValue(macroUeBox.xMin));
192 xVal->SetAttribute("Max", DoubleValue(macroUeBox.xMax));
193 randomUePositionAlloc->SetAttribute("X", PointerValue(xVal));
194 Ptr<UniformRandomVariable> yVal = CreateObject<UniformRandomVariable>();
195 yVal->SetAttribute("Min", DoubleValue(macroUeBox.yMin));
196 yVal->SetAttribute("Max", DoubleValue(macroUeBox.yMax));
197 randomUePositionAlloc->SetAttribute("Y", PointerValue(yVal));
198 Ptr<UniformRandomVariable> zVal = CreateObject<UniformRandomVariable>();
199 zVal->SetAttribute("Min", DoubleValue(macroUeBox.zMin));
200 zVal->SetAttribute("Max", DoubleValue(macroUeBox.zMax));
201 randomUePositionAlloc->SetAttribute("Z", PointerValue(zVal));
202 mobility.SetPositionAllocator(randomUePositionAlloc);
203 mobility.Install(randomUeNodes);
204
205 // Create Devices and install them in the Nodes (eNB and UE)
206 NetDeviceContainer enbDevs;
207 NetDeviceContainer edgeUeDevs;
208 NetDeviceContainer centerUeDevs;
209 NetDeviceContainer randomUeDevs;
210 lteHelper->SetSchedulerType("ns3::PfFfMacScheduler");
211 lteHelper->SetSchedulerAttribute("UlCqiFilter", EnumValue(FfMacScheduler::PUSCH_UL_CQI));
212 lteHelper->SetEnbDeviceAttribute("DlBandwidth", UintegerValue(bandwidth));
213 lteHelper->SetEnbDeviceAttribute("UlBandwidth", UintegerValue(bandwidth));
214
215 std::string frAlgorithmType = lteHelper->GetFfrAlgorithmType();
216 NS_LOG_DEBUG("FrAlgorithmType: " << frAlgorithmType);
217
218 if (frAlgorithmType == "ns3::LteFrHardAlgorithm")
219 {
220 // Nothing to configure here in automatic mode
221 }
222 else if (frAlgorithmType == "ns3::LteFrStrictAlgorithm")
223 {
224 lteHelper->SetFfrAlgorithmAttribute("RsrqThreshold", UintegerValue(32));
225 lteHelper->SetFfrAlgorithmAttribute("CenterPowerOffset",
227 lteHelper->SetFfrAlgorithmAttribute("EdgePowerOffset",
229 lteHelper->SetFfrAlgorithmAttribute("CenterAreaTpc", UintegerValue(0));
230 lteHelper->SetFfrAlgorithmAttribute("EdgeAreaTpc", UintegerValue(3));
231
232 // ns3::LteFrStrictAlgorithm works with Absolute Mode Uplink Power Control
233 Config::SetDefault("ns3::LteUePowerControl::AccumulationEnabled", BooleanValue(false));
234 }
235 else if (frAlgorithmType == "ns3::LteFrSoftAlgorithm")
236 {
237 lteHelper->SetFfrAlgorithmAttribute("AllowCenterUeUseEdgeSubBand", BooleanValue(true));
238 lteHelper->SetFfrAlgorithmAttribute("RsrqThreshold", UintegerValue(25));
239 lteHelper->SetFfrAlgorithmAttribute("CenterPowerOffset",
241 lteHelper->SetFfrAlgorithmAttribute("EdgePowerOffset",
243 lteHelper->SetFfrAlgorithmAttribute("CenterAreaTpc", UintegerValue(0));
244 lteHelper->SetFfrAlgorithmAttribute("EdgeAreaTpc", UintegerValue(3));
245
246 // ns3::LteFrSoftAlgorithm works with Absolute Mode Uplink Power Control
247 Config::SetDefault("ns3::LteUePowerControl::AccumulationEnabled", BooleanValue(false));
248 }
249 else if (frAlgorithmType == "ns3::LteFfrSoftAlgorithm")
250 {
251 lteHelper->SetFfrAlgorithmAttribute("CenterRsrqThreshold", UintegerValue(30));
252 lteHelper->SetFfrAlgorithmAttribute("EdgeRsrqThreshold", UintegerValue(25));
253 lteHelper->SetFfrAlgorithmAttribute("CenterAreaPowerOffset",
255 lteHelper->SetFfrAlgorithmAttribute(
256 "MediumAreaPowerOffset",
258 lteHelper->SetFfrAlgorithmAttribute("EdgeAreaPowerOffset",
260 lteHelper->SetFfrAlgorithmAttribute("CenterAreaTpc", UintegerValue(1));
261 lteHelper->SetFfrAlgorithmAttribute("MediumAreaTpc", UintegerValue(2));
262 lteHelper->SetFfrAlgorithmAttribute("EdgeAreaTpc", UintegerValue(3));
263
264 // ns3::LteFfrSoftAlgorithm works with Absolute Mode Uplink Power Control
265 Config::SetDefault("ns3::LteUePowerControl::AccumulationEnabled", BooleanValue(false));
266 }
267 else if (frAlgorithmType == "ns3::LteFfrEnhancedAlgorithm")
268 {
269 lteHelper->SetFfrAlgorithmAttribute("RsrqThreshold", UintegerValue(25));
270 lteHelper->SetFfrAlgorithmAttribute("DlCqiThreshold", UintegerValue(10));
271 lteHelper->SetFfrAlgorithmAttribute("UlCqiThreshold", UintegerValue(10));
272 lteHelper->SetFfrAlgorithmAttribute("CenterAreaPowerOffset",
274 lteHelper->SetFfrAlgorithmAttribute("EdgeAreaPowerOffset",
276 lteHelper->SetFfrAlgorithmAttribute("CenterAreaTpc", UintegerValue(0));
277 lteHelper->SetFfrAlgorithmAttribute("EdgeAreaTpc", UintegerValue(3));
278
279 // ns3::LteFfrEnhancedAlgorithm works with Absolute Mode Uplink Power Control
280 Config::SetDefault("ns3::LteUePowerControl::AccumulationEnabled", BooleanValue(false));
281 }
282 else if (frAlgorithmType == "ns3::LteFfrDistributedAlgorithm")
283 {
284 NS_FATAL_ERROR("ns3::LteFfrDistributedAlgorithm not supported in this example. Please run "
285 "lena-distributed-ffr");
286 }
287 else
288 {
289 lteHelper->SetFfrAlgorithmType("ns3::LteFrNoOpAlgorithm");
290 }
291
292 lteHelper->SetFfrAlgorithmAttribute("FrCellTypeId", UintegerValue(1));
293 enbDevs.Add(lteHelper->InstallEnbDevice(enbNodes.Get(0)));
294
295 lteHelper->SetFfrAlgorithmAttribute("FrCellTypeId", UintegerValue(2));
296 enbDevs.Add(lteHelper->InstallEnbDevice(enbNodes.Get(1)));
297
298 lteHelper->SetFfrAlgorithmAttribute("FrCellTypeId", UintegerValue(3));
299 enbDevs.Add(lteHelper->InstallEnbDevice(enbNodes.Get(2)));
300
301 // FR algorithm reconfiguration if needed
302 PointerValue tmp;
303 enbDevs.Get(0)->GetAttribute("LteFfrAlgorithm", tmp);
304 Ptr<LteFfrAlgorithm> ffrAlgorithm = DynamicCast<LteFfrAlgorithm>(tmp.GetObject());
305 ffrAlgorithm->SetAttribute("FrCellTypeId", UintegerValue(1));
306
307 // Install Ue Device
308 edgeUeDevs = lteHelper->InstallUeDevice(edgeUeNodes);
309 centerUeDevs = lteHelper->InstallUeDevice(centerUeNodes);
310 randomUeDevs = lteHelper->InstallUeDevice(randomUeNodes);
311
312 // Attach edge UEs to eNbs
313 for (uint32_t i = 0; i < edgeUeDevs.GetN(); i++)
314 {
315 lteHelper->Attach(edgeUeDevs.Get(i), enbDevs.Get(i));
316 }
317 // Attach center UEs to eNbs
318 for (uint32_t i = 0; i < centerUeDevs.GetN(); i++)
319 {
320 lteHelper->Attach(centerUeDevs.Get(i), enbDevs.Get(i));
321 }
322
323 // Attach UE to a eNB
324 lteHelper->AttachToClosestEnb(randomUeDevs, enbDevs);
325
326 // Activate a data radio bearer
328 EpsBearer bearer(q);
329 lteHelper->ActivateDataRadioBearer(edgeUeDevs, bearer);
330 lteHelper->ActivateDataRadioBearer(centerUeDevs, bearer);
331 lteHelper->ActivateDataRadioBearer(randomUeDevs, bearer);
332
333 // Spectrum analyzer
334 NodeContainer spectrumAnalyzerNodes;
335 spectrumAnalyzerNodes.Create(1);
336 SpectrumAnalyzerHelper spectrumAnalyzerHelper;
337
338 if (generateSpectrumTrace)
339 {
340 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
341 // position of Spectrum Analyzer
342 // positionAlloc->Add (Vector (0.0, 0.0, 0.0)); // eNB1
343 // positionAlloc->Add (Vector (distance, 0.0, 0.0)); // eNB2
344 positionAlloc->Add(Vector(distance * 0.5, distance * 0.866, 0.0)); // eNB3
345
347 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
348 mobility.SetPositionAllocator(positionAlloc);
349 mobility.Install(spectrumAnalyzerNodes);
350
351 Ptr<LteSpectrumPhy> enbDlSpectrumPhy = enbDevs.Get(0)
352 ->GetObject<LteEnbNetDevice>()
353 ->GetPhy()
354 ->GetDownlinkSpectrumPhy()
356 Ptr<SpectrumChannel> dlChannel = enbDlSpectrumPhy->GetChannel();
357
358 spectrumAnalyzerHelper.SetChannel(dlChannel);
360 spectrumAnalyzerHelper.SetRxSpectrumModel(sm);
361 spectrumAnalyzerHelper.SetPhyAttribute("Resolution", TimeValue(MicroSeconds(10)));
362 spectrumAnalyzerHelper.SetPhyAttribute("NoisePowerSpectralDensity",
363 DoubleValue(1e-15)); // -120 dBm/Hz
364 spectrumAnalyzerHelper.EnableAsciiAll("spectrum-analyzer-output");
365 spectrumAnalyzerHelper.Install(spectrumAnalyzerNodes);
366 }
367
369 if (generateRem)
370 {
373
374 remHelper = CreateObject<RadioEnvironmentMapHelper>();
375 remHelper->SetAttribute("ChannelPath", StringValue("/ChannelList/0"));
376 remHelper->SetAttribute("OutputFile", StringValue("lena-frequency-reuse.rem"));
377 remHelper->SetAttribute("XMin", DoubleValue(macroUeBox.xMin));
378 remHelper->SetAttribute("XMax", DoubleValue(macroUeBox.xMax));
379 remHelper->SetAttribute("YMin", DoubleValue(macroUeBox.yMin));
380 remHelper->SetAttribute("YMax", DoubleValue(macroUeBox.yMax));
381 remHelper->SetAttribute("Z", DoubleValue(1.5));
382 remHelper->SetAttribute("XRes", UintegerValue(500));
383 remHelper->SetAttribute("YRes", UintegerValue(500));
384 if (remRbId >= 0)
385 {
386 remHelper->SetAttribute("UseDataChannel", BooleanValue(true));
387 remHelper->SetAttribute("RbId", IntegerValue(remRbId));
388 }
389
390 remHelper->Install();
391 // simulation will stop right after the REM has been generated
392 }
393 else
394 {
395 Simulator::Stop(Seconds(simTime));
396 }
397
400 return 0;
401}
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:62
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:522
AttributeValue implementation for Pointer.
Definition: pointer.h:48
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:77
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:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
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:1406
Hold an unsigned integer type.
Definition: uinteger.h:45
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:894
#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:1343
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
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:40
ns mobility
Definition: third.py:105