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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Manuel Requena <manuel.requena@cttc.es>
7 * Nicola Baldo <nbaldo@cttc.es>
8 */
9
10#include "ns3/config-store.h"
11#include "ns3/core-module.h"
12#include "ns3/lte-global-pathloss-database.h"
13#include "ns3/lte-module.h"
14#include "ns3/mobility-module.h"
15#include "ns3/network-module.h"
16#include "ns3/radio-bearer-stats-calculator.h"
17#include <ns3/log.h>
18
19#include <iomanip>
20#include <string>
21
22using namespace ns3;
23
24NS_LOG_COMPONENT_DEFINE("LenaPathlossTraces");
25
26int
27main(int argc, char* argv[])
28{
29 double enbDist = 20.0;
30 double radius = 10.0;
31 uint32_t numUes = 1;
32
33 CommandLine cmd(__FILE__);
34 cmd.AddValue("enbDist", "distance between the two eNBs", enbDist);
35 cmd.AddValue("radius", "the radius of the disc where UEs are placed around an eNB", radius);
36 cmd.AddValue("numUes", "how many UEs are attached to each eNB", numUes);
37 cmd.Parse(argc, argv);
38
39 ConfigStore inputConfig;
40 inputConfig.ConfigureDefaults();
41
42 // parse again so you can override default values from the command line
43 cmd.Parse(argc, argv);
44
45 // determine the string tag that identifies this simulation run
46 // this tag is then appended to all filenames
47
48 UintegerValue runValue;
49 GlobalValue::GetValueByName("RngRun", runValue);
50
51 std::ostringstream tag;
52 tag << "_enbDist" << std::setw(3) << std::setfill('0') << std::fixed << std::setprecision(0)
53 << enbDist << "_radius" << std::setw(3) << std::setfill('0') << std::fixed
54 << std::setprecision(0) << radius << "_numUes" << std::setw(3) << std::setfill('0')
55 << numUes << "_rngRun" << std::setw(3) << std::setfill('0') << runValue.Get();
56
58
59 // NOTE: the PropagationLoss trace source of the SpectrumChannel
60 // works only for single-frequency path loss model.
61 // e.g., it will work with the following models:
62 // ns3::FriisPropagationLossModel,
63 // ns3::TwoRayGroundPropagationLossModel,
64 // ns3::LogDistancePropagationLossModel,
65 // ns3::ThreeLogDistancePropagationLossModel,
66 // ns3::NakagamiPropagationLossModel
67 // ns3::BuildingsPropagationLossModel
68 // etc.
69 // but it WON'T work if you ONLY use SpectrumPropagationLossModels such as:
70 // ns3::FriisSpectrumPropagationLossModel
71 // ns3::ConstantSpectrumPropagationLossModel
72 lteHelper->SetAttribute("PathlossModel", StringValue("ns3::Cost231PropagationLossModel"));
73
74 // Create Nodes: eNodeB and UE
75 NodeContainer enbNodes;
76 NodeContainer ueNodes1;
77 NodeContainer ueNodes2;
78 enbNodes.Create(2);
79 ueNodes1.Create(numUes);
80 ueNodes2.Create(numUes);
81
82 // Position of eNBs
84 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
85 positionAlloc->Add(Vector(enbDist, 0.0, 0.0));
86 MobilityHelper enbMobility;
87 enbMobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
88 enbMobility.SetPositionAllocator(positionAlloc);
89 enbMobility.Install(enbNodes);
90
91 // Position of UEs attached to eNB 1
92 MobilityHelper ue1mobility;
93 ue1mobility.SetPositionAllocator("ns3::UniformDiscPositionAllocator",
94 "X",
95 DoubleValue(0.0),
96 "Y",
97 DoubleValue(0.0),
98 "rho",
99 DoubleValue(radius));
100 ue1mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
101 ue1mobility.Install(ueNodes1);
102
103 // Position of UEs attached to eNB 2
104 MobilityHelper ue2mobility;
105 ue2mobility.SetPositionAllocator("ns3::UniformDiscPositionAllocator",
106 "X",
107 DoubleValue(enbDist),
108 "Y",
109 DoubleValue(0.0),
110 "rho",
111 DoubleValue(radius));
112 ue2mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
113 ue2mobility.Install(ueNodes2);
114
115 // Create Devices and install them in the Nodes (eNB and UE)
116 NetDeviceContainer enbDevs;
117 NetDeviceContainer ueDevs1;
118 NetDeviceContainer ueDevs2;
119 enbDevs = lteHelper->InstallEnbDevice(enbNodes);
120 ueDevs1 = lteHelper->InstallUeDevice(ueNodes1);
121 ueDevs2 = lteHelper->InstallUeDevice(ueNodes2);
122
123 // Attach UEs to a eNB
124 lteHelper->Attach(ueDevs1, enbDevs.Get(0));
125 lteHelper->Attach(ueDevs2, enbDevs.Get(1));
126
127 // Activate an EPS bearer on all UEs
129 EpsBearer bearer(q);
130 lteHelper->ActivateDataRadioBearer(ueDevs1, bearer);
131 lteHelper->ActivateDataRadioBearer(ueDevs2, bearer);
132
134
135 // Insert RLC Performance Calculator
136 std::string dlOutFname = "DlRlcStats";
137 dlOutFname.append(tag.str());
138 std::string ulOutFname = "UlRlcStats";
139 ulOutFname.append(tag.str());
140
141 lteHelper->EnableMacTraces();
142 lteHelper->EnableRlcTraces();
143
144 // keep track of all path loss values in two centralized objects
147 // we rely on the fact that LteHelper creates the DL channel object first, then the UL channel
148 // object, hence the former will have index 0 and the latter 1
150 "/ChannelList/0/PathLoss",
152 Config::Connect("/ChannelList/1/PathLoss",
154
156
157 // print the pathloss values at the end of the simulation
158 std::cout << std::endl << "Downlink pathloss:" << std::endl;
159 dlPathlossDb.Print();
160 std::cout << std::endl << "Uplink pathloss:" << std::endl;
161 ulPathlossDb.Print();
162
164 return 0;
165}
Parse command-line arguments.
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:31
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
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.
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
Hold variables of type string.
Definition string.h:45
Hold an unsigned integer type.
Definition uinteger.h:34
uint64_t Get() const
Definition uinteger.cc:26
void Connect(std::string path, const CallbackBase &cb)
Definition config.cc:967
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
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:684