A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lena-profiling.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: Jaume Nin <jnin@cttc.es>
19  */
20 
21 #include "ns3/core-module.h"
22 #include "ns3/network-module.h"
23 #include "ns3/mobility-module.h"
24 #include "ns3/lte-module.h"
25 #include "ns3/config-store.h"
26 #include <ns3/buildings-module.h>
27 #include <iomanip>
28 #include <string>
29 #include <vector>
30 //#include "ns3/gtk-config-store.h"
31 
32 using namespace ns3;
33 
34 int
35 main (int argc, char *argv[])
36 {
37  uint32_t nEnbPerFloor = 1;
38  uint32_t nUe = 1;
39  uint32_t nFloors = 0;
40  double simTime = 1.0;
41  CommandLine cmd;
42 
43  cmd.AddValue ("nEnb", "Number of eNodeBs per floor", nEnbPerFloor);
44  cmd.AddValue ("nUe", "Number of UEs", nUe);
45  cmd.AddValue ("nFloors", "Number of floors, 0 for Friis propagation model",
46  nFloors);
47  cmd.AddValue ("simTime", "Total duration of the simulation (in seconds)",
48  simTime);
49  cmd.Parse (argc, argv);
50 
51  ConfigStore inputConfig;
52  inputConfig.ConfigureDefaults ();
53 
54  // parse again so you can override default values from the command line
55  cmd.Parse (argc, argv);
56 
57  // Geometry of the scenario (in meters)
58  // Assume squared building
59  double nodeHeight = 1.5;
60  double roomHeight = 3;
61  double roomLength = 8;
62  uint32_t nRooms = std::ceil (std::sqrt (nEnbPerFloor));
63  uint32_t nEnb;
64 
65  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
66  //lteHelper->EnableLogComponents ();
67  //LogComponentEnable ("BuildingsPropagationLossModel", LOG_LEVEL_ALL);
68  if (nFloors == 0)
69  {
70  lteHelper->SetAttribute ("PathlossModel",
71  StringValue ("ns3::FriisPropagationLossModel"));
72  nEnb = nEnbPerFloor;
73  }
74  else
75  {
76  lteHelper->SetAttribute ("PathlossModel",
77  StringValue ("ns3::HybridBuildingsPropagationLossModel"));
78  nEnb = nFloors * nEnbPerFloor;
79  }
80 
81  // Create Nodes: eNodeB and UE
82  NodeContainer enbNodes;
83  std::vector<NodeContainer> ueNodes;
84 
85  enbNodes.Create (nEnb);
86  for (uint32_t i = 0; i < nEnb; i++)
87  {
88  NodeContainer ueNode;
89  ueNode.Create (nUe);
90  ueNodes.push_back (ueNode);
91  }
92 
93  MobilityHelper mobility;
94  mobility.SetMobilityModel ("ns3::BuildingsMobilityModel");
95  std::vector<Vector> enbPosition;
96  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
97  Ptr<Building> building;
98 
99  if (nFloors == 0)
100  {
101  // Position of eNBs
102  uint32_t plantedEnb = 0;
103  for (uint32_t row = 0; row < nRooms; row++)
104  {
105  for (uint32_t column = 0; column < nRooms && plantedEnb < nEnbPerFloor; column++, plantedEnb++)
106  {
107  Vector v (roomLength * (column + 0.5), roomLength * (row + 0.5), nodeHeight);
108  positionAlloc->Add (v);
109  enbPosition.push_back (v);
110  mobility.Install (ueNodes.at(plantedEnb));
111  }
112  }
113  mobility.SetPositionAllocator (positionAlloc);
114  mobility.Install (enbNodes);
115 
116  // Position of UEs attached to eNB
117  for (uint32_t i = 0; i < nEnb; i++)
118  {
119  Ptr<UniformRandomVariable> posX = CreateObject<UniformRandomVariable> ();
120  posX->SetAttribute ("Min", DoubleValue (enbPosition.at(i).x - roomLength * 0.5));
121  posX->SetAttribute ("Max", DoubleValue (enbPosition.at(i).x + roomLength * 0.5));
122  Ptr<UniformRandomVariable> posY = CreateObject<UniformRandomVariable> ();
123  posY->SetAttribute ("Min", DoubleValue (enbPosition.at(i).y - roomLength * 0.5));
124  posY->SetAttribute ("Max", DoubleValue (enbPosition.at(i).y + roomLength * 0.5));
125  positionAlloc = CreateObject<ListPositionAllocator> ();
126  for (uint32_t j = 0; j < nUe; j++)
127  {
128  positionAlloc->Add (Vector (posX->GetValue (), posY->GetValue (), nodeHeight));
129  mobility.SetPositionAllocator (positionAlloc);
130  }
131  mobility.Install (ueNodes.at(i));
132  }
133 
134  }
135  else
136  {
137  building = CreateObject<Building> ();
138  building->SetBoundaries (Box (0.0, nRooms * roomLength,
139  0.0, nRooms * roomLength,
140  0.0, nFloors* roomHeight));
141  building->SetBuildingType (Building::Residential);
142  building->SetExtWallsType (Building::ConcreteWithWindows);
143  building->SetNFloors (nFloors);
144  building->SetNRoomsX (nRooms);
145  building->SetNRoomsY (nRooms);
146  mobility.Install (enbNodes);
147  uint32_t plantedEnb = 0;
148  for (uint32_t floor = 0; floor < nFloors; floor++)
149  {
150  uint32_t plantedEnbPerFloor = 0;
151  for (uint32_t row = 0; row < nRooms; row++)
152  {
153  for (uint32_t column = 0; column < nRooms && plantedEnbPerFloor < nEnbPerFloor; column++, plantedEnb++, plantedEnbPerFloor++)
154  {
155  Vector v (roomLength * (column + 0.5),
156  roomLength * (row + 0.5),
157  nodeHeight + roomHeight * floor);
158  positionAlloc->Add (v);
159  enbPosition.push_back (v);
160  Ptr<BuildingsMobilityModel> mmEnb = enbNodes.Get (plantedEnb)->GetObject<BuildingsMobilityModel> ();
161  mmEnb->SetPosition (v);
162 
163  // Positioning UEs attached to eNB
164  mobility.Install (ueNodes.at(plantedEnb));
165  for (uint32_t ue = 0; ue < nUe; ue++)
166  {
167  Ptr<BuildingsMobilityModel> mmUe = ueNodes.at(plantedEnb).Get (ue)->GetObject<BuildingsMobilityModel> ();
168  Vector vUe (v.x, v.y, v.z);
169  mmUe->SetPosition (vUe);
170  }
171  }
172  }
173  }
174  }
175 
176 
177  // Create Devices and install them in the Nodes (eNB and UE)
178  NetDeviceContainer enbDevs;
179  std::vector<NetDeviceContainer> ueDevs;
180  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
181  for (uint32_t i = 0; i < nEnb; i++)
182  {
183  NetDeviceContainer ueDev = lteHelper->InstallUeDevice (ueNodes.at(i));
184  ueDevs.push_back (ueDev);
185  lteHelper->Attach (ueDev, enbDevs.Get (i));
186  enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
187  EpsBearer bearer (q);
188  lteHelper->ActivateDataRadioBearer (ueDev, bearer);
189  }
190 
191 
192  BuildingsHelper::MakeMobilityModelConsistent ();
193 
194  Simulator::Stop (Seconds (simTime));
195  lteHelper->EnableTraces ();
196 
197  Simulator::Run ();
198 
199  /*GtkConfigStore config;
200  config.ConfigureAttributes ();*/
201 
203  return 0;
204 }
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
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Definition: lte-helper.cc:773
a 3d vector
Definition: vector.h:31
a 3d box
Definition: box.h:33
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void EnableTraces(void)
Definition: lte-helper.cc:820
void Attach(NetDeviceContainer ueDevices, Ptr< NetDevice > enbDevice)
Definition: lte-helper.cc:562
Buildings mobility model.
holds a vector of ns3::NetDevice pointers
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())
double GetValue(double min, double max)
Returns a random double from the uniform distribution with the specified range.
void SetPosition(const Vector &position)
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
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
void Parse(int argc, char *argv[]) const
Definition: command-line.cc:84
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
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
Ptr< T > GetObject(void) const
Definition: object.h:332