A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lena-pathloss-traces.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
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: Manuel Requena <manuel.requena@cttc.es>
18 * Nicola Baldo <nbaldo@cttc.es>
19 */
20
21#include "ns3/config-store.h"
22#include "ns3/core-module.h"
23#include "ns3/lte-global-pathloss-database.h"
24#include "ns3/lte-module.h"
25#include "ns3/mobility-module.h"
26#include "ns3/network-module.h"
27#include "ns3/radio-bearer-stats-calculator.h"
28#include <ns3/log.h>
29
30#include <iomanip>
31#include <string>
32
33using namespace ns3;
34
35NS_LOG_COMPONENT_DEFINE("LenaPathlossTraces");
36
37int
38main(int argc, char* argv[])
39{
40 double enbDist = 20.0;
41 double radius = 10.0;
42 uint32_t numUes = 1;
43
44 CommandLine cmd(__FILE__);
45 cmd.AddValue("enbDist", "distance between the two eNBs", enbDist);
46 cmd.AddValue("radius", "the radius of the disc where UEs are placed around an eNB", radius);
47 cmd.AddValue("numUes", "how many UEs are attached to each eNB", numUes);
48 cmd.Parse(argc, argv);
49
50 ConfigStore inputConfig;
51 inputConfig.ConfigureDefaults();
52
53 // parse again so you can override default values from the command line
54 cmd.Parse(argc, argv);
55
56 // determine the string tag that identifies this simulation run
57 // this tag is then appended to all filenames
58
59 UintegerValue runValue;
60 GlobalValue::GetValueByName("RngRun", runValue);
61
62 std::ostringstream tag;
63 tag << "_enbDist" << std::setw(3) << std::setfill('0') << std::fixed << std::setprecision(0)
64 << enbDist << "_radius" << std::setw(3) << std::setfill('0') << std::fixed
65 << std::setprecision(0) << radius << "_numUes" << std::setw(3) << std::setfill('0')
66 << numUes << "_rngRun" << std::setw(3) << std::setfill('0') << runValue.Get();
67
68 Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
69
70 // NOTE: the PropagationLoss trace source of the SpectrumChannel
71 // works only for single-frequency path loss model.
72 // e.g., it will work with the following models:
73 // ns3::FriisPropagationLossModel,
74 // ns3::TwoRayGroundPropagationLossModel,
75 // ns3::LogDistancePropagationLossModel,
76 // ns3::ThreeLogDistancePropagationLossModel,
77 // ns3::NakagamiPropagationLossModel
78 // ns3::BuildingsPropagationLossModel
79 // etc.
80 // but it WON'T work if you ONLY use SpectrumPropagationLossModels such as:
81 // ns3::FriisSpectrumPropagationLossModel
82 // ns3::ConstantSpectrumPropagationLossModel
83 lteHelper->SetAttribute("PathlossModel", StringValue("ns3::Cost231PropagationLossModel"));
84
85 // Create Nodes: eNodeB and UE
86 NodeContainer enbNodes;
87 NodeContainer ueNodes1;
88 NodeContainer ueNodes2;
89 enbNodes.Create(2);
90 ueNodes1.Create(numUes);
91 ueNodes2.Create(numUes);
92
93 // Position of eNBs
94 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
95 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
96 positionAlloc->Add(Vector(enbDist, 0.0, 0.0));
97 MobilityHelper enbMobility;
98 enbMobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
99 enbMobility.SetPositionAllocator(positionAlloc);
100 enbMobility.Install(enbNodes);
101
102 // Position of UEs attached to eNB 1
103 MobilityHelper ue1mobility;
104 ue1mobility.SetPositionAllocator("ns3::UniformDiscPositionAllocator",
105 "X",
106 DoubleValue(0.0),
107 "Y",
108 DoubleValue(0.0),
109 "rho",
110 DoubleValue(radius));
111 ue1mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
112 ue1mobility.Install(ueNodes1);
113
114 // Position of UEs attached to eNB 2
115 MobilityHelper ue2mobility;
116 ue2mobility.SetPositionAllocator("ns3::UniformDiscPositionAllocator",
117 "X",
118 DoubleValue(enbDist),
119 "Y",
120 DoubleValue(0.0),
121 "rho",
122 DoubleValue(radius));
123 ue2mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
124 ue2mobility.Install(ueNodes2);
125
126 // Create Devices and install them in the Nodes (eNB and UE)
127 NetDeviceContainer enbDevs;
128 NetDeviceContainer ueDevs1;
129 NetDeviceContainer ueDevs2;
130 enbDevs = lteHelper->InstallEnbDevice(enbNodes);
131 ueDevs1 = lteHelper->InstallUeDevice(ueNodes1);
132 ueDevs2 = lteHelper->InstallUeDevice(ueNodes2);
133
134 // Attach UEs to a eNB
135 lteHelper->Attach(ueDevs1, enbDevs.Get(0));
136 lteHelper->Attach(ueDevs2, enbDevs.Get(1));
137
138 // Activate an EPS bearer on all UEs
140 EpsBearer bearer(q);
141 lteHelper->ActivateDataRadioBearer(ueDevs1, bearer);
142 lteHelper->ActivateDataRadioBearer(ueDevs2, bearer);
143
145
146 // Insert RLC Performance Calculator
147 std::string dlOutFname = "DlRlcStats";
148 dlOutFname.append(tag.str());
149 std::string ulOutFname = "UlRlcStats";
150 ulOutFname.append(tag.str());
151
152 lteHelper->EnableMacTraces();
153 lteHelper->EnableRlcTraces();
154
155 // keep track of all path loss values in two centralized objects
158 // we rely on the fact that LteHelper creates the DL channel object first, then the UL channel
159 // object, hence the former will have index 0 and the latter 1
161 "/ChannelList/0/PathLoss",
163 Config::Connect("/ChannelList/1/PathLoss",
165
167
168 // print the pathloss values at the end of the simulation
169 std::cout << std::endl << "Downlink pathloss:" << std::endl;
170 dlPathlossDb.Print();
171 std::cout << std::endl << "Uplink pathloss:" << std::endl;
172 ulPathlossDb.Print();
173
175 return 0;
176}
Parse command-line arguments.
Definition: command-line.h:232
Introspection did not find any typical Config paths.
Definition: config-store.h:61
void ConfigureDefaults()
Configure the default values.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
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
static void GetValueByName(std::string name, AttributeValue &value)
Finds the GlobalValue with the given name and returns its value.
void Print()
print the stored pathloss values to standard output
Helper class used to assign positions and mobility models to nodes.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void SetMobilityModel(std::string type, Ts &&... args)
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
holds a vector of ns3::NetDevice pointers
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.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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
Hold variables of type string.
Definition: string.h:56
Hold an unsigned integer type.
Definition: uinteger.h:45
uint64_t Get() const
Definition: uinteger.cc:37
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:978
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:706
ns cmd
Definition: second.py:40