A Discrete-Event Network Simulator
API
lena-pathloss-traces.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Manuel Requena <manuel.requena@cttc.es>
19  * Nicola Baldo <nbaldo@cttc.es>
20  */
21 
22 
23 #include "ns3/core-module.h"
24 #include "ns3/network-module.h"
25 #include "ns3/mobility-module.h"
26 #include "ns3/lte-module.h"
27 #include "ns3/config-store.h"
28 #include "ns3/radio-bearer-stats-calculator.h"
29 #include "ns3/lte-global-pathloss-database.h"
30 
31 #include <iomanip>
32 #include <string>
33 
34 #include <ns3/log.h>
35 
36 using namespace ns3;
37 
38 NS_LOG_COMPONENT_DEFINE ("LenaPathlossTraces");
39 
40 
41 int main (int argc, char *argv[])
42 {
43  double enbDist = 20.0;
44  double radius = 10.0;
45  uint32_t numUes = 1;
46 
47 
48  CommandLine cmd (__FILE__);
49  cmd.AddValue ("enbDist", "distance between the two eNBs", enbDist);
50  cmd.AddValue ("radius", "the radius of the disc where UEs are placed around an eNB", radius);
51  cmd.AddValue ("numUes", "how many UEs are attached to each eNB", numUes);
52  cmd.Parse (argc, argv);
53 
54  ConfigStore inputConfig;
55  inputConfig.ConfigureDefaults ();
56 
57  // parse again so you can override default values from the command line
58  cmd.Parse (argc, argv);
59 
60  // determine the string tag that identifies this simulation run
61  // this tag is then appended to all filenames
62 
63  UintegerValue runValue;
64  GlobalValue::GetValueByName ("RngRun", runValue);
65 
66  std::ostringstream tag;
67  tag << "_enbDist" << std::setw (3) << std::setfill ('0') << std::fixed << std::setprecision (0) << enbDist
68  << "_radius" << std::setw (3) << std::setfill ('0') << std::fixed << std::setprecision (0) << radius
69  << "_numUes" << std::setw (3) << std::setfill ('0') << numUes
70  << "_rngRun" << std::setw (3) << std::setfill ('0') << runValue.Get () ;
71 
72  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
73 
74 
75  // NOTE: the PropagationLoss trace source of the SpectrumChannel
76  // works only for single-frequency path loss model.
77  // e.g., it will work with the following models:
78  // ns3::FriisPropagationLossModel,
79  // ns3::TwoRayGroundPropagationLossModel,
80  // ns3::LogDistancePropagationLossModel,
81  // ns3::ThreeLogDistancePropagationLossModel,
82  // ns3::NakagamiPropagationLossModel
83  // ns3::BuildingsPropagationLossModel
84  // etc.
85  // but it WON'T work if you ONLY use SpectrumPropagationLossModels such as:
86  // ns3::FriisSpectrumPropagationLossModel
87  // ns3::ConstantSpectrumPropagationLossModel
88  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::Cost231PropagationLossModel"));
89 
90 
91  // Create Nodes: eNodeB and UE
92  NodeContainer enbNodes;
93  NodeContainer ueNodes1, ueNodes2;
94  enbNodes.Create (2);
95  ueNodes1.Create (numUes);
96  ueNodes2.Create (numUes);
97 
98  // Position of eNBs
99  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
100  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
101  positionAlloc->Add (Vector (enbDist, 0.0, 0.0));
102  MobilityHelper enbMobility;
103  enbMobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
104  enbMobility.SetPositionAllocator (positionAlloc);
105  enbMobility.Install (enbNodes);
106 
107  // Position of UEs attached to eNB 1
108  MobilityHelper ue1mobility;
109  ue1mobility.SetPositionAllocator ("ns3::UniformDiscPositionAllocator",
110  "X", DoubleValue (0.0),
111  "Y", DoubleValue (0.0),
112  "rho", DoubleValue (radius));
113  ue1mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
114  ue1mobility.Install (ueNodes1);
115 
116  // Position of UEs attached to eNB 2
117  MobilityHelper ue2mobility;
118  ue2mobility.SetPositionAllocator ("ns3::UniformDiscPositionAllocator",
119  "X", DoubleValue (enbDist),
120  "Y", DoubleValue (0.0),
121  "rho", DoubleValue (radius));
122  ue2mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
123  ue2mobility.Install (ueNodes2);
124 
125  // Create Devices and install them in the Nodes (eNB and UE)
126  NetDeviceContainer enbDevs;
127  NetDeviceContainer ueDevs1;
128  NetDeviceContainer ueDevs2;
129  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
130  ueDevs1 = lteHelper->InstallUeDevice (ueNodes1);
131  ueDevs2 = lteHelper->InstallUeDevice (ueNodes2);
132 
133  // Attach UEs to a eNB
134  lteHelper->Attach (ueDevs1, enbDevs.Get (0));
135  lteHelper->Attach (ueDevs2, enbDevs.Get (1));
136 
137  // Activate an EPS bearer on all UEs
139  EpsBearer bearer (q);
140  lteHelper->ActivateDataRadioBearer (ueDevs1, bearer);
141  lteHelper->ActivateDataRadioBearer (ueDevs2, bearer);
142 
143  Simulator::Stop (Seconds (0.5));
144 
145  // Insert RLC Performance Calculator
146  std::string dlOutFname = "DlRlcStats";
147  dlOutFname.append (tag.str ());
148  std::string ulOutFname = "UlRlcStats";
149  ulOutFname.append (tag.str ());
150 
151  lteHelper->EnableMacTraces ();
152  lteHelper->EnableRlcTraces ();
153 
154 
155 
156  // keep track of all path loss values in two centralized objects
158  UplinkLteGlobalPathlossDatabase ulPathlossDb;
159  // we rely on the fact that LteHelper creates the DL channel object first, then the UL channel object,
160  // hence the former will have index 0 and the latter 1
161  Config::Connect ("/ChannelList/0/PathLoss",
163  Config::Connect ("/ChannelList/1/PathLoss",
165 
166  Simulator::Run ();
167 
168 
169  // print the pathloss values at the end of the simulation
170  std::cout << std::endl << "Downlink pathloss:" << std::endl;
171  dlPathlossDb.Print ();
172  std::cout << std::endl << "Uplink pathloss:" << std::endl;
173  ulPathlossDb.Print ();
174 
175 
177  return 0;
178 }
void Print()
print the stored pathloss values to standard output
Introspection did not find any typical Config paths.
Definition: config-store.h:59
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:474
Hold variables of type string.
Definition: string.h:41
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
void Attach(NetDeviceContainer ueDevices)
Enables automatic attachment of a set of UE devices to a suitable cell using Idle mode initial cell s...
Definition: lte-helper.cc:961
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
void EnableRlcTraces(void)
Enable trace sinks for RLC layer.
Definition: lte-helper.cc:1436
cmd
Definition: second.py:35
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Activate a Data Radio Bearer on a given UE devices (for LTE-only simulation).
Definition: lte-helper.cc:1314
Hold an unsigned integer type.
Definition: uinteger.h:44
holds a vector of ns3::NetDevice pointers
Parse command-line arguments.
Definition: command-line.h:226
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:918
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
void ConfigureDefaults(void)
Configure the default values.
uint64_t Get(void) const
Definition: uinteger.cc:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:91
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:489
Helper class used to assign positions and mobility models to nodes.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1278
GBR Conversational Voice.
Definition: eps-bearer.h:108
void Add(Vector v)
Add a position to the list of positions.
static void GetValueByName(std::string name, AttributeValue &value)
Finds the GlobalValue with the given name and returns its value.
Qci
QoS Class Indicator.
Definition: eps-bearer.h:106
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void EnableMacTraces(void)
Enable trace sinks for MAC layer.
Definition: lte-helper.cc:1530
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642