A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lena-profiling.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: 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::BuildingsPropagationLossModel"));
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> (0.0, nRooms * roomLength,
138  0.0, nRooms * roomLength,
139  0.0, nFloors* roomHeight);
140  building->SetBuildingType (Building::Residential);
141  building->SetExtWallsType (Building::ConcreteWithWindows);
142  building->SetNFloors (nFloors);
143  building->SetNRoomsX (nRooms);
144  building->SetNRoomsY (nRooms);
145  mobility.Install (enbNodes);
146  uint32_t plantedEnb = 0;
147  for (uint32_t floor = 0; floor < nFloors; floor++)
148  {
149  uint32_t plantedEnbPerFloor = 0;
150  for (uint32_t row = 0; row < nRooms; row++)
151  {
152  for (uint32_t column = 0; column < nRooms && plantedEnbPerFloor < nEnbPerFloor; column++, plantedEnb++, plantedEnbPerFloor++)
153  {
154  Vector v (roomLength * (column + 0.5),
155  roomLength * (row + 0.5),
156  nodeHeight + roomHeight * floor);
157  positionAlloc->Add (v);
158  enbPosition.push_back (v);
159  Ptr<BuildingsMobilityModel> mmEnb = enbNodes.Get (plantedEnb)->GetObject<BuildingsMobilityModel> ();
160  mmEnb->SetPosition (v);
161 
162  // Positioning UEs attached to eNB
163  mobility.Install (ueNodes.at(plantedEnb));
164  for (uint32_t ue = 0; ue < nUe; ue++)
165  {
166  Ptr<BuildingsMobilityModel> mmUe = ueNodes.at(plantedEnb).Get (ue)->GetObject<BuildingsMobilityModel> ();
167  Vector vUe (v.x, v.y, v.z);
168  mmUe->SetPosition (vUe);
169  }
170  }
171  }
172  }
173 
174 
175  }
176 
177 
178 
179 
180  // Create Devices and install them in the Nodes (eNB and UE)
181  NetDeviceContainer enbDevs;
182  std::vector<NetDeviceContainer> ueDevs;
183  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
184  for (uint32_t i = 0; i < nEnb; i++)
185  {
186  NetDeviceContainer ueDev = lteHelper->InstallUeDevice (ueNodes.at(i));
187  ueDevs.push_back (ueDev);
188  lteHelper->Attach (ueDev, enbDevs.Get (i));
190  EpsBearer bearer (q);
191  lteHelper->ActivateEpsBearer (ueDev, bearer, EpcTft::Default ());
192  }
193 
194 
196 
197  Simulator::Stop (Seconds (simTime));
198  lteHelper->EnableTraces ();
199 
200  Simulator::Run ();
201 
202  /*GtkConfigStore config;
203  config.ConfigureAttributes ();*/
204 
206  return 0;
207 }