A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lena-pathloss-traces.cc
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 
39 NS_LOG_COMPONENT_DEFINE ("LenaPathlossTraces");
40 
41 
42 
43 int main (int argc, char *argv[])
44 {
45  double enbDist = 20.0;
46  double radius = 10.0;
47  uint32_t numUes = 1;
48 
49 
50  CommandLine cmd;
51  cmd.AddValue ("enbDist", "distance between the two eNBs", enbDist);
52  cmd.AddValue ("radius", "the radius of the disc where UEs are placed around an eNB", radius);
53  cmd.AddValue ("numUes", "how many UEs are attached to each eNB", numUes);
54  cmd.Parse (argc, argv);
55 
56  ConfigStore inputConfig;
57  inputConfig.ConfigureDefaults ();
58 
59  // parse again so you can override default values from the command line
60  cmd.Parse (argc, argv);
61 
62  // determine the string tag that identifies this simulation run
63  // this tag is then appended to all filenames
64 
65  IntegerValue runValue;
66  GlobalValue::GetValueByName ("RngRun", runValue);
67 
68  std::ostringstream tag;
69  tag << "_enbDist" << std::setw (3) << std::setfill ('0') << std::fixed << std::setprecision (0) << enbDist
70  << "_radius" << std::setw (3) << std::setfill ('0') << std::fixed << std::setprecision (0) << radius
71  << "_numUes" << std::setw (3) << std::setfill ('0') << numUes
72  << "_rngRun" << std::setw (3) << std::setfill ('0') << runValue.Get () ;
73 
74  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
75 
76 
77  // NOTE: the PropagationLoss trace source of the SpectrumChannel
78  // works only for single-frequency path loss model.
79  // e.g., it will work with the following models:
80  // ns3::FriisPropagationLossModel,
81  // ns3::TwoRayGroundPropagationLossModel,
82  // ns3::LogDistancePropagationLossModel,
83  // ns3::ThreeLogDistancePropagationLossModel,
84  // ns3::NakagamiPropagationLossModel
85  // ns3::BuildingsPropagationLossModel
86  // etc.
87  // but it WON'T work if you ONLY use SpectrumPropagationLossModels such as:
88  // ns3::FriisSpectrumPropagationLossModel
89  // ns3::ConstantSpectrumPropagationLossModel
90  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::Cost231PropagationLossModel"));
91 
92 
93  // Create Nodes: eNodeB and UE
94  NodeContainer enbNodes;
95  NodeContainer ueNodes1, ueNodes2;
96  enbNodes.Create (2);
97  ueNodes1.Create (numUes);
98  ueNodes2.Create (numUes);
99 
100  // Position of eNBs
101  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
102  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
103  positionAlloc->Add (Vector (enbDist, 0.0, 0.0));
104  MobilityHelper enbMobility;
105  enbMobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
106  enbMobility.SetPositionAllocator (positionAlloc);
107  enbMobility.Install (enbNodes);
108 
109  // Position of UEs attached to eNB 1
110  MobilityHelper ue1mobility;
111  ue1mobility.SetPositionAllocator ("ns3::UniformDiscPositionAllocator",
112  "X", DoubleValue (0.0),
113  "Y", DoubleValue (0.0),
114  "rho", DoubleValue (radius));
115  ue1mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
116  ue1mobility.Install (ueNodes1);
117 
118  // Position of UEs attached to eNB 2
119  MobilityHelper ue2mobility;
120  ue2mobility.SetPositionAllocator ("ns3::UniformDiscPositionAllocator",
121  "X", DoubleValue (enbDist),
122  "Y", DoubleValue (0.0),
123  "rho", DoubleValue (radius));
124  ue2mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
125  ue2mobility.Install (ueNodes2);
126 
127  // Create Devices and install them in the Nodes (eNB and UE)
128  NetDeviceContainer enbDevs;
129  NetDeviceContainer ueDevs1;
130  NetDeviceContainer ueDevs2;
131  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
132  ueDevs1 = lteHelper->InstallUeDevice (ueNodes1);
133  ueDevs2 = lteHelper->InstallUeDevice (ueNodes2);
134 
135  // Attach UEs to a eNB
136  lteHelper->Attach (ueDevs1, enbDevs.Get (0));
137  lteHelper->Attach (ueDevs2, enbDevs.Get (1));
138 
139  // Activate an EPS bearer on all UEs
140  enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
141  EpsBearer bearer (q);
142  lteHelper->ActivateDataRadioBearer (ueDevs1, bearer);
143  lteHelper->ActivateDataRadioBearer (ueDevs2, bearer);
144 
145  Simulator::Stop (Seconds (0.5));
146 
147  // Insert RLC Performance Calculator
148  std::string dlOutFname = "DlRlcStats";
149  dlOutFname.append (tag.str ());
150  std::string ulOutFname = "UlRlcStats";
151  ulOutFname.append (tag.str ());
152 
153  lteHelper->EnableMacTraces ();
154  lteHelper->EnableRlcTraces ();
155 
156 
157 
158  // keep track of all path loss values in two centralized objects
160  UplinkLteGlobalPathlossDatabase ulPathlossDb;
161  // we rely on the fact that LteHelper creates the DL channel object first, then the UL channel object,
162  // hence the former will have index 0 and the latter 1
163  Config::Connect ("/ChannelList/0/PathLoss",
165  Config::Connect ("/ChannelList/1/PathLoss",
167 
168  Simulator::Run ();
169 
170 
171  // print the pathloss values at the end of the simulation
172  std::cout << std::endl << "Downlink pathloss:" << std::endl;
173  dlPathlossDb.Print ();
174  std::cout << std::endl << "Uplink pathloss:" << std::endl;
175  ulPathlossDb.Print ();
176 
177 
179  return 0;
180 }
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Definition: lte-helper.cc:285
hold variables of type string
Definition: string.h:19
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
static void Run(void)
Definition: simulator.cc:157
Hold a signed integer type.
Definition: integer.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
void EnableRlcTraces(void)
Definition: lte-helper.cc:829
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:728
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Definition: lte-helper.cc:773
a 3d vector
Definition: vector.h:31
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void Attach(NetDeviceContainer ueDevices, Ptr< NetDevice > enbDevice)
Definition: lte-helper.cc:562
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:502
parse command-line argumentsInstances of this class can be used to parse command-line arguments: user...
Definition: command-line.h:50
static void Destroy(void)
Definition: simulator.cc:121
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())
NetDeviceContainer InstallUeDevice(NodeContainer c)
Definition: lte-helper.cc:300
Helper class used to assign positions and mobility models to nodes.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
void AddValue(const std::string &name, const std::string &help, T &value)
Definition: command-line.h:134
static void Stop(void)
Definition: simulator.cc:164
void Parse(int argc, char *argv[]) const
Definition: command-line.cc:84
static void GetValueByName(std::string name, AttributeValue &value)
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void EnableMacTraces(void)
Definition: lte-helper.cc:1204
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Hold an floating point type.
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Definition: object-base.cc:160