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