A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lena-dual-stripe.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 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: Nicola Baldo <nbaldo@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/internet-module.h>
25 #include <ns3/lte-module.h>
26 #include <ns3/config-store-module.h>
27 #include <ns3/buildings-module.h>
28 #include <ns3/point-to-point-helper.h>
29 #include <ns3/applications-module.h>
30 #include <ns3/log.h>
31 #include <iomanip>
32 #include <string>
33 #include <vector>
34 
35 // The topology of this simulation program is inspired from
36 // 3GPP R4-092042, Section 4.2.1 Dual Stripe Model
37 // note that the term "apartments" used in that document matches with
38 // the term "room" used in the BuildingsMobilityModel
39 
40 using namespace ns3;
41 
42 
43 NS_LOG_COMPONENT_DEFINE ("LenaDualStripe");
44 
45 
46 bool AreOverlapping (Box a, Box b)
47 {
48  return !((a.xMin > b.xMax) || (b.xMin > a.xMax) || (a.yMin > b.yMax) || (b.yMin > a.yMax));
49 }
50 
52 {
53 public:
54  FemtocellBlockAllocator (Box area, uint32_t nApartmentsX, uint32_t nFloors);
55  void Create (uint32_t n);
56  void Create ();
57 
58 private:
59  bool OverlapsWithAnyPrevious (Box);
61  uint32_t m_nApartmentsX;
62  uint32_t m_nFloors;
63  std::list<Box> m_previousBlocks;
64  double m_xSize;
65  double m_ySize;
68 
69 };
70 
71 FemtocellBlockAllocator::FemtocellBlockAllocator (Box area, uint32_t nApartmentsX, uint32_t nFloors)
72  : m_area (area),
73  m_nApartmentsX (nApartmentsX),
74  m_nFloors (nFloors),
75  m_xSize (nApartmentsX*10 + 20),
76  m_ySize (70)
77 {
78  m_xMinVar = CreateObject<UniformRandomVariable> ();
79  m_xMinVar->SetAttribute ("Min", DoubleValue (area.xMin));
80  m_xMinVar->SetAttribute ("Max", DoubleValue (area.xMax - m_xSize));
81  m_yMinVar = CreateObject<UniformRandomVariable> ();
82  m_yMinVar->SetAttribute ("Min", DoubleValue (area.yMin));
83  m_yMinVar->SetAttribute ("Max", DoubleValue (area.yMax - m_ySize));
84 }
85 
86 void
88 {
89  for (uint32_t i = 0; i < n; ++i)
90  {
91  Create ();
92  }
93 }
94 
95 void
97 {
98  Box box;
99  uint32_t attempt = 0;
100  do
101  {
102  NS_ASSERT_MSG (attempt < 100, "Too many failed attemtps to position apartment block. Too many blocks? Too small area?");
103  box.xMin = m_xMinVar->GetValue ();
104  box.xMax = box.xMin + m_xSize;
105  box.yMin = m_yMinVar->GetValue ();
106  box.yMax = box.yMin + m_ySize;
107  ++attempt;
108  }
109  while (OverlapsWithAnyPrevious (box));
110 
111  NS_LOG_LOGIC ("allocated non overlapping block " << box);
112  m_previousBlocks.push_back (box);
113  Ptr<GridBuildingAllocator> gridBuildingAllocator;
114  gridBuildingAllocator = CreateObject<GridBuildingAllocator> ();
115  gridBuildingAllocator->SetAttribute ("GridWidth", UintegerValue (1));
116  gridBuildingAllocator->SetAttribute ("LengthX", DoubleValue (10*m_nApartmentsX));
117  gridBuildingAllocator->SetAttribute ("LengthY", DoubleValue (10*2));
118  gridBuildingAllocator->SetAttribute ("DeltaX", DoubleValue (10));
119  gridBuildingAllocator->SetAttribute ("DeltaY", DoubleValue (10));
120  gridBuildingAllocator->SetAttribute ("Height", DoubleValue (3*m_nFloors));
121  gridBuildingAllocator->SetBuildingAttribute ("NRoomsX", UintegerValue (m_nApartmentsX));
122  gridBuildingAllocator->SetBuildingAttribute ("NRoomsY", UintegerValue (2));
123  gridBuildingAllocator->SetBuildingAttribute ("NFloors", UintegerValue (m_nFloors));
124  gridBuildingAllocator->SetAttribute ("MinX", DoubleValue (box.xMin + 10));
125  gridBuildingAllocator->SetAttribute ("MinY", DoubleValue (box.yMin + 10));
126  gridBuildingAllocator->Create (2);
127 }
128 
129 bool
131 {
132  for (std::list<Box>::iterator it = m_previousBlocks.begin (); it != m_previousBlocks.end (); ++it)
133  {
134  if (AreOverlapping (*it, box))
135  {
136  return true;
137  }
138  }
139  return false;
140 }
141 
142 void
144 {
145  std::ofstream outFile;
146  outFile.open (filename.c_str ());
147  if (!outFile.is_open ())
148  {
149  NS_LOG_ERROR ("Can't open file " << filename);
150  return;
151  }
152  uint32_t index = 0;
153  for (BuildingList::Iterator it = BuildingList::Begin (); it != BuildingList::End (); ++it)
154  {
155  ++index;
156  Box box = (*it)->GetBoundaries ();
157  outFile << "set object " << index
158  << " rect from " << box.xMin << "," << box.yMin
159  << " to " << box.xMax << "," << box.yMax
160  << " front fs empty "
161  << std::endl;
162  }
163 }
164 
165 void
166 PrintGnuplottableUeListToFile (std::string filename)
167 {
168  std::ofstream outFile;
169  outFile.open (filename.c_str ());
170  if (!outFile.is_open ())
171  {
172  NS_LOG_ERROR ("Can't open file " << filename);
173  return;
174  }
175  for (NodeList::Iterator it = NodeList::Begin (); it != NodeList::End (); ++it)
176  {
177  Ptr<Node> node = *it;
178  int nDevs = node->GetNDevices ();
179  for (int j = 0; j < nDevs; j++)
180  {
181  Ptr<LteUeNetDevice> uedev = node->GetDevice (j)->GetObject <LteUeNetDevice> ();
182  if (uedev)
183  {
184  Vector pos = node->GetObject<MobilityModel> ()->GetPosition ();
185  outFile << "set label \"" << uedev->GetImsi ()
186  << "\" at "<< pos.x << "," << pos.y << " left font \"Helvetica,4\" textcolor rgb \"grey\" front point pt 1 ps 0.3 lc rgb \"grey\" offset 0,0"
187  << std::endl;
188  }
189  }
190  }
191 }
192 
193 void
194 PrintGnuplottableEnbListToFile (std::string filename)
195 {
196  std::ofstream outFile;
197  outFile.open (filename.c_str ());
198  if (!outFile.is_open ())
199  {
200  NS_LOG_ERROR ("Can't open file " << filename);
201  return;
202  }
203  for (NodeList::Iterator it = NodeList::Begin (); it != NodeList::End (); ++it)
204  {
205  Ptr<Node> node = *it;
206  int nDevs = node->GetNDevices ();
207  for (int j = 0; j < nDevs; j++)
208  {
209  Ptr<LteEnbNetDevice> enbdev = node->GetDevice (j)->GetObject <LteEnbNetDevice> ();
210  if (enbdev)
211  {
212  Vector pos = node->GetObject<MobilityModel> ()->GetPosition ();
213  outFile << "set label \"" << enbdev->GetCellId ()
214  << "\" at "<< pos.x << "," << pos.y << " left font \"Helvetica,4\" textcolor rgb \"white\" front point pt 2 ps 0.3 lc rgb \"white\" offset 0,0"
215  << std::endl;
216  }
217  }
218  }
219 }
220 
221 
222 static ns3::GlobalValue g_nBlocks ("nBlocks",
223  "Number of femtocell blocks",
224  ns3::UintegerValue (10),
225  ns3::MakeUintegerChecker<uint32_t> ());
226 static ns3::GlobalValue g_nApartmentsX ("nApartmentsX",
227  "Number of apartments along the X axis in a femtocell block",
228  ns3::UintegerValue (10),
229  ns3::MakeUintegerChecker<uint32_t> ());
230 static ns3::GlobalValue g_nFloors ("nFloors",
231  "Number of floors",
232  ns3::UintegerValue (1),
233  ns3::MakeUintegerChecker<uint32_t> ());
234 static ns3::GlobalValue g_nMacroEnbSites ("nMacroEnbSites",
235  "How many macro sites there are",
236  ns3::UintegerValue (3),
237  ns3::MakeUintegerChecker<uint32_t> ());
238 static ns3::GlobalValue g_nMacroEnbSitesX ("nMacroEnbSitesX",
239  "(minimum) number of sites along the X-axis of the hex grid",
240  ns3::UintegerValue (1),
241  ns3::MakeUintegerChecker<uint32_t> ());
242 static ns3::GlobalValue g_interSiteDistance ("interSiteDistance",
243  "min distance between two nearby macro cell sites",
244  ns3::DoubleValue (500),
245  ns3::MakeDoubleChecker<double> ());
246 static ns3::GlobalValue g_areaMarginFactor ("areaMarginFactor",
247  "how much the UE area extends outside the macrocell grid, "
248  "expressed as fraction of the interSiteDistance",
249  ns3::DoubleValue (0.5),
250  ns3::MakeDoubleChecker<double> ());
251 static ns3::GlobalValue g_macroUeDensity ("macroUeDensity",
252  "How many macrocell UEs there are per square meter",
253  ns3::DoubleValue (0.0001),
254  ns3::MakeDoubleChecker<double> ());
255 static ns3::GlobalValue g_homeEnbDeploymentRatio ("homeEnbDeploymentRatio",
256  "The HeNB deployment ratio as per 3GPP R4-092042",
257  ns3::DoubleValue (0.2),
258  ns3::MakeDoubleChecker<double> ());
259 static ns3::GlobalValue g_homeEnbActivationRatio ("homeEnbActivationRatio",
260  "The HeNB activation ratio as per 3GPP R4-092042",
261  ns3::DoubleValue (0.5),
262  ns3::MakeDoubleChecker<double> ());
263 static ns3::GlobalValue g_homeUesHomeEnbRatio ("homeUesHomeEnbRatio",
264  "How many (on average) home UEs per HeNB there are in the simulation",
265  ns3::DoubleValue (1.0),
266  ns3::MakeDoubleChecker<double> ());
267 static ns3::GlobalValue g_macroEnbTxPowerDbm ("macroEnbTxPowerDbm",
268  "TX power [dBm] used by macro eNBs",
269  ns3::DoubleValue (46.0),
270  ns3::MakeDoubleChecker<double> ());
271 static ns3::GlobalValue g_homeEnbTxPowerDbm ("homeEnbTxPowerDbm",
272  "TX power [dBm] used by HeNBs",
273  ns3::DoubleValue (20.0),
274  ns3::MakeDoubleChecker<double> ());
275 static ns3::GlobalValue g_macroEnbDlEarfcn ("macroEnbDlEarfcn",
276  "DL EARFCN used by macro eNBs",
277  ns3::UintegerValue (100),
278  ns3::MakeUintegerChecker<uint16_t> ());
279 static ns3::GlobalValue g_homeEnbDlEarfcn ("homeEnbDlEarfcn",
280  "DL EARFCN used by HeNBs",
281  ns3::UintegerValue (100),
282  ns3::MakeUintegerChecker<uint16_t> ());
283 static ns3::GlobalValue g_macroEnbBandwidth ("macroEnbBandwidth",
284  "bandwidth [num RBs] used by macro eNBs",
285  ns3::UintegerValue (25),
286  ns3::MakeUintegerChecker<uint16_t> ());
287 static ns3::GlobalValue g_homeEnbBandwidth ("homeEnbBandwidth",
288  "bandwidth [num RBs] used by HeNBs",
289  ns3::UintegerValue (25),
290  ns3::MakeUintegerChecker<uint16_t> ());
291 static ns3::GlobalValue g_simTime ("simTime",
292  "Total duration of the simulation [s]",
293  ns3::DoubleValue (0.25),
294  ns3::MakeDoubleChecker<double> ());
295 static ns3::GlobalValue g_generateRem ("generateRem",
296  "if true, will generate a REM and then abort the simulation;"
297  "if false, will run the simulation normally (without generating any REM)",
298  ns3::BooleanValue (false),
299  ns3::MakeBooleanChecker ());
300 static ns3::GlobalValue g_epc ("epc",
301  "if true, will setup the EPC to simulate an end-to-end topology;"
302  "if false, only the LTE radio access will be simulated.",
303  ns3::BooleanValue (false),
304  ns3::MakeBooleanChecker ());
305 static ns3::GlobalValue g_epcDl ("epcDl",
306  "if true, will activate data flows in the downlink when EPC is being used. "
307  "If false, downlink flows won't be activated. "
308  "If EPC is not used, this parameter will be ignored.",
309  ns3::BooleanValue (true),
310  ns3::MakeBooleanChecker ());
311 static ns3::GlobalValue g_epcUl ("epcUl",
312  "if true, will activate data flows in the uplink when EPC is being used. "
313  "If false, uplink flows won't be activated. "
314  "If EPC is not used, this parameter will be ignored.",
315  ns3::BooleanValue (true),
316  ns3::MakeBooleanChecker ());
317 static ns3::GlobalValue g_useUdp ("useUdp",
318  "if true, the UdpClient application will be used. "
319  "Otherwise, the BulkSend application will be used over a TCP connection. "
320  "If EPC is not used, this parameter will be ignored.",
321  ns3::BooleanValue (true),
322  ns3::MakeBooleanChecker ());
323 static ns3::GlobalValue g_fadingTrace ("fadingTrace",
324  "The path of the fading trace (by default no fading trace "
325  "is loaded, i.e., fading is not considered)",
326  ns3::StringValue (""),
327  ns3::MakeStringChecker ());
328 
329 
330 int
331 main (int argc, char *argv[])
332 {
333  // change some default attributes so that they are reasonable for
334  // this scenario, but do this before processing command line
335  // arguments, so that the user is allowed to override these settings
336  Config::SetDefault ("ns3::UdpClient::Interval", TimeValue (MilliSeconds(1)));
337  Config::SetDefault ("ns3::UdpClient::MaxPackets", UintegerValue(1000000));
338 
339  CommandLine cmd;
340  cmd.Parse (argc, argv);
341  ConfigStore inputConfig;
342  inputConfig.ConfigureDefaults ();
343  // parse again so you can override input file default values via command line
344  cmd.Parse (argc, argv);
345 
346  // the scenario parameters get their values from the global attributes definde above
347  UintegerValue uintegerValue;
348  DoubleValue doubleValue;
349  BooleanValue booleanValue;
350  StringValue stringValue;
351  GlobalValue::GetValueByName ("nBlocks", uintegerValue);
352  uint32_t nBlocks = uintegerValue.Get ();
353  GlobalValue::GetValueByName ("nApartmentsX", uintegerValue);
354  uint32_t nApartmentsX = uintegerValue.Get ();
355  GlobalValue::GetValueByName ("nFloors", uintegerValue);
356  uint32_t nFloors = uintegerValue.Get ();
357  GlobalValue::GetValueByName ("nMacroEnbSites", uintegerValue);
358  uint32_t nMacroEnbSites = uintegerValue.Get ();
359  GlobalValue::GetValueByName ("nMacroEnbSitesX", uintegerValue);
360  uint32_t nMacroEnbSitesX = uintegerValue.Get ();
361  GlobalValue::GetValueByName ("interSiteDistance", doubleValue);
362  double interSiteDistance = doubleValue.Get ();
363  GlobalValue::GetValueByName ("areaMarginFactor", doubleValue);
364  double areaMarginFactor = doubleValue.Get ();
365  GlobalValue::GetValueByName ("macroUeDensity", doubleValue);
366  double macroUeDensity = doubleValue.Get ();
367  GlobalValue::GetValueByName ("homeEnbDeploymentRatio", doubleValue);
368  double homeEnbDeploymentRatio = doubleValue.Get ();
369  GlobalValue::GetValueByName ("homeEnbActivationRatio", doubleValue);
370  double homeEnbActivationRatio = doubleValue.Get ();
371  GlobalValue::GetValueByName ("homeUesHomeEnbRatio", doubleValue);
372  double homeUesHomeEnbRatio = doubleValue.Get ();
373  GlobalValue::GetValueByName ("macroEnbTxPowerDbm", doubleValue);
374  double macroEnbTxPowerDbm = doubleValue.Get ();
375  GlobalValue::GetValueByName ("homeEnbTxPowerDbm", doubleValue);
376  double homeEnbTxPowerDbm = doubleValue.Get ();
377  GlobalValue::GetValueByName ("macroEnbDlEarfcn", uintegerValue);
378  uint16_t macroEnbDlEarfcn = uintegerValue.Get ();
379  GlobalValue::GetValueByName ("homeEnbDlEarfcn", uintegerValue);
380  uint16_t homeEnbDlEarfcn = uintegerValue.Get ();
381  GlobalValue::GetValueByName ("macroEnbBandwidth", uintegerValue);
382  uint16_t macroEnbBandwidth = uintegerValue.Get ();
383  GlobalValue::GetValueByName ("homeEnbBandwidth", uintegerValue);
384  uint16_t homeEnbBandwidth = uintegerValue.Get ();
385  GlobalValue::GetValueByName ("simTime", doubleValue);
386  double simTime = doubleValue.Get ();
387  GlobalValue::GetValueByName ("epc", booleanValue);
388  bool epc = booleanValue.Get ();
389  GlobalValue::GetValueByName ("epcDl", booleanValue);
390  bool epcDl = booleanValue.Get ();
391  GlobalValue::GetValueByName ("epcUl", booleanValue);
392  bool epcUl = booleanValue.Get ();
393  GlobalValue::GetValueByName ("useUdp", booleanValue);
394  bool useUdp = booleanValue.Get ();
395  GlobalValue::GetValueByName ("generateRem", booleanValue);
396  bool generateRem = booleanValue.Get ();
397  GlobalValue::GetValueByName ("fadingTrace", stringValue);
398  std::string fadingTrace = stringValue.Get ();
399 
400  Box macroUeBox;
401 
402  if (nMacroEnbSites > 0)
403  {
404  uint32_t currentSite = nMacroEnbSites -1;
405  uint32_t biRowIndex = (currentSite / (nMacroEnbSitesX + nMacroEnbSitesX + 1));
406  uint32_t biRowRemainder = currentSite % (nMacroEnbSitesX + nMacroEnbSitesX + 1);
407  uint32_t rowIndex = biRowIndex*2 + 1;
408  if (biRowRemainder >= nMacroEnbSitesX)
409  {
410  ++rowIndex;
411  }
412  uint32_t nMacroEnbSitesY = rowIndex;
413  NS_LOG_LOGIC ("nMacroEnbSitesY = " << nMacroEnbSitesY);
414 
415  macroUeBox = Box (-areaMarginFactor*interSiteDistance,
416  (nMacroEnbSitesX + areaMarginFactor)*interSiteDistance,
417  -areaMarginFactor*interSiteDistance,
418  (nMacroEnbSitesY -1)*interSiteDistance*sqrt(0.75) + areaMarginFactor*interSiteDistance,
419  1.0, 2.0);
420  }
421  else
422  {
423  // still need the box to place femtocell blocks
424  macroUeBox = Box (0, 150, 0, 150, 1.0, 2.0);
425  }
426 
427  FemtocellBlockAllocator blockAllocator (macroUeBox, nApartmentsX, nFloors);
428  blockAllocator.Create (nBlocks);
429 
430 
431  uint32_t nHomeEnbs = round (4 * nApartmentsX * nBlocks * nFloors * homeEnbDeploymentRatio * homeEnbActivationRatio);
432  NS_LOG_LOGIC ("nHomeEnbs = " << nHomeEnbs);
433  uint32_t nHomeUes = round (nHomeEnbs * homeUesHomeEnbRatio);
434  NS_LOG_LOGIC ("nHomeUes = " << nHomeUes);
435  double macroUeAreaSize = (macroUeBox.xMax - macroUeBox.xMin) * (macroUeBox.yMax - macroUeBox.yMin);
436  uint32_t nMacroUes = round (macroUeAreaSize * macroUeDensity) ;
437  NS_LOG_LOGIC ("nMacroUes = " << nMacroUes << " (density=" << macroUeDensity << ")");
438 
439  NodeContainer homeEnbs;
440  homeEnbs.Create (nHomeEnbs);
441  NodeContainer macroEnbs;
442  macroEnbs.Create (3 * nMacroEnbSites);
443  NodeContainer homeUes;
444  homeUes.Create (nHomeUes);
445  NodeContainer macroUes;
446  macroUes.Create (nMacroUes);
447 
448  MobilityHelper mobility;
449  mobility.SetMobilityModel ("ns3::BuildingsMobilityModel");
450 
451 
452  Ptr <LteHelper> lteHelper = CreateObject<LteHelper> ();
453  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
454  lteHelper->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0));
455  lteHelper->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (1));
456  lteHelper->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (1.5));
457  // use always LOS model
458  lteHelper->SetPathlossModelAttribute ("Los2NlosThr", DoubleValue (1e6));
459  lteHelper->SetSpectrumChannelType ("ns3::MultiModelSpectrumChannel");
460 
461  if (!fadingTrace.empty ())
462  {
463  lteHelper->SetAttribute ("FadingModel", StringValue ("ns3::TraceFadingLossModel"));
464  lteHelper->SetFadingModelAttribute("TraceFilename", StringValue (fadingTrace));
465  }
466 
467  Ptr<EpcHelper> epcHelper;
468  if (epc)
469  {
470  NS_LOG_LOGIC ("enabling EPC");
471  epcHelper = CreateObject<EpcHelper> ();
472  lteHelper->SetEpcHelper (epcHelper);
473  }
474 
475  // Macro eNBs in 3-sector hex grid
476 
477  mobility.Install (macroEnbs);
478  Ptr<LteHexGridEnbTopologyHelper> lteHexGridEnbTopologyHelper = CreateObject<LteHexGridEnbTopologyHelper> ();
479  lteHexGridEnbTopologyHelper->SetLteHelper (lteHelper);
480  lteHexGridEnbTopologyHelper->SetAttribute ("InterSiteDistance", DoubleValue (interSiteDistance));
481  lteHexGridEnbTopologyHelper->SetAttribute ("MinX", DoubleValue (interSiteDistance/2));
482  lteHexGridEnbTopologyHelper->SetAttribute ("GridWidth", UintegerValue (nMacroEnbSitesX));
483  Config::SetDefault ("ns3::LteEnbPhy::TxPower", DoubleValue (macroEnbTxPowerDbm));
484  lteHelper->SetEnbAntennaModelType ("ns3::ParabolicAntennaModel");
485  lteHelper->SetEnbAntennaModelAttribute ("Beamwidth", DoubleValue (70));
486  lteHelper->SetEnbAntennaModelAttribute ("MaxAttenuation", DoubleValue (20.0));
487  lteHelper->SetEnbDeviceAttribute ("DlEarfcn", UintegerValue (macroEnbDlEarfcn));
488  lteHelper->SetEnbDeviceAttribute ("UlEarfcn", UintegerValue (macroEnbDlEarfcn + 18000));
489  lteHelper->SetEnbDeviceAttribute ("DlBandwidth", UintegerValue (macroEnbBandwidth));
490  lteHelper->SetEnbDeviceAttribute ("UlBandwidth", UintegerValue (macroEnbBandwidth));
491  NetDeviceContainer macroEnbDevs = lteHexGridEnbTopologyHelper->SetPositionAndInstallEnbDevice (macroEnbs);
492 
493 
494  // HomeEnbs randomly indoor
495 
496  Ptr<PositionAllocator> positionAlloc = CreateObject<RandomRoomPositionAllocator> ();
497  mobility.SetPositionAllocator (positionAlloc);
498  mobility.Install (homeEnbs);
499  Config::SetDefault ("ns3::LteEnbPhy::TxPower", DoubleValue (homeEnbTxPowerDbm));
500  lteHelper->SetEnbAntennaModelType ("ns3::IsotropicAntennaModel");
501  lteHelper->SetEnbDeviceAttribute ("DlEarfcn", UintegerValue (homeEnbDlEarfcn));
502  lteHelper->SetEnbDeviceAttribute ("UlEarfcn", UintegerValue (homeEnbDlEarfcn + 18000));
503  lteHelper->SetEnbDeviceAttribute ("DlBandwidth", UintegerValue (homeEnbBandwidth));
504  lteHelper->SetEnbDeviceAttribute ("UlBandwidth", UintegerValue (homeEnbBandwidth));
505  NetDeviceContainer homeEnbDevs = lteHelper->InstallEnbDevice (homeEnbs);
506 
507 
508  // macro Ues
509  NS_LOG_LOGIC ("randomly allocating macro UEs in " << macroUeBox);
510  positionAlloc = CreateObject<RandomBoxPositionAllocator> ();
511  Ptr<UniformRandomVariable> xVal = CreateObject<UniformRandomVariable> ();
512  xVal->SetAttribute ("Min", DoubleValue (macroUeBox.xMin));
513  xVal->SetAttribute ("Max", DoubleValue (macroUeBox.xMax));
514  positionAlloc->SetAttribute ("X", PointerValue (xVal));
515  Ptr<UniformRandomVariable> yVal = CreateObject<UniformRandomVariable> ();
516  yVal->SetAttribute ("Min", DoubleValue (macroUeBox.yMin));
517  yVal->SetAttribute ("Max", DoubleValue (macroUeBox.yMax));
518  positionAlloc->SetAttribute ("Y", PointerValue (yVal));
519  Ptr<UniformRandomVariable> zVal = CreateObject<UniformRandomVariable> ();
520  zVal->SetAttribute ("Min", DoubleValue (macroUeBox.zMin));
521  zVal->SetAttribute ("Max", DoubleValue (macroUeBox.zMax));
522  positionAlloc->SetAttribute ("Z", PointerValue (zVal));
523  mobility.SetPositionAllocator (positionAlloc);
524  mobility.Install (macroUes);
525  NetDeviceContainer macroUeDevs = lteHelper->InstallUeDevice (macroUes);
526  lteHelper->AttachToClosestEnb (macroUeDevs, macroEnbDevs);
527 
528 
529  // home UEs located in the same apartment in which there are the Home eNBs
530  positionAlloc = CreateObject<SameRoomPositionAllocator> (homeEnbs);
531  mobility.SetPositionAllocator (positionAlloc);
532  mobility.Install (homeUes);
533  NetDeviceContainer homeUeDevs = lteHelper->InstallUeDevice (homeUes);
534 
536  NetDeviceContainer::Iterator enbDevIt = homeEnbDevs.Begin ();
537  // attach explicitly each home UE to its home eNB
538  for (ueDevIt = homeUeDevs.Begin ();
539  ueDevIt != homeUeDevs.End ();
540  ++ueDevIt, ++enbDevIt)
541  {
542  // this because of the order in which SameRoomPositionAllocator
543  // will place the UEs
544  if (enbDevIt == homeEnbDevs.End ())
545  {
546  enbDevIt = homeEnbDevs.Begin ();
547  }
548  lteHelper->Attach (*ueDevIt, *enbDevIt);
549  }
550 
551 
552  if (epc)
553  {
554  NS_LOG_LOGIC ("setting up internet, remote host and applications");
555 
556  // Create a single RemoteHost
557  NodeContainer remoteHostContainer;
558  remoteHostContainer.Create (1);
559  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
560  InternetStackHelper internet;
561  internet.Install (remoteHostContainer);
562 
563  // Create the Internet
564  PointToPointHelper p2ph;
565  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
566  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
567  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
568  Ptr<Node> pgw = epcHelper->GetPgwNode ();
569  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
570  Ipv4AddressHelper ipv4h;
571  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
572  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
573  // in this container, interface 0 is the pgw, 1 is the remoteHost
574  Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1);
575 
576  Ipv4StaticRoutingHelper ipv4RoutingHelper;
577  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
578  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
579 
580  // for internetworking purposes, consider together home UEs and macro UEs
581  NodeContainer ues;
582  ues.Add (homeUes);
583  ues.Add (macroUes);
584  NetDeviceContainer ueDevs;
585  ueDevs.Add (homeUeDevs);
586  ueDevs.Add (macroUeDevs);
587 
588  // Install the IP stack on the UEs
589  internet.Install (ues);
590  Ipv4InterfaceContainer ueIpIfaces;
591  ueIpIfaces = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDevs));
592 
593  // Install and start applications on UEs and remote host
594  uint16_t dlPort = 10000;
595  uint16_t ulPort = 20000;
596 
597  ApplicationContainer clientApps;
598  ApplicationContainer serverApps;
599  for (uint32_t u = 0; u < ues.GetN (); ++u)
600  {
601  Ptr<Node> ue = ues.Get (u);
602  // Set the default gateway for the UE
603  Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ue->GetObject<Ipv4> ());
604  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
605  ++dlPort;
606  ++ulPort;
607  if (useUdp)
608  {
609  if (epcDl)
610  {
611  NS_LOG_LOGIC ("installing UDP DL app for UE " << u);
612  UdpClientHelper dlClientHelper (ueIpIfaces.GetAddress (u), dlPort);
613  clientApps.Add (dlClientHelper.Install (remoteHost));
614  PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory",
615  InetSocketAddress (Ipv4Address::GetAny (), dlPort));
616  serverApps.Add (dlPacketSinkHelper.Install (ue));
617  }
618  if (epcUl)
619  {
620  NS_LOG_LOGIC ("installing UDP UL app for UE " << u);
621  UdpClientHelper ulClientHelper (remoteHostAddr, ulPort);
622  clientApps.Add (ulClientHelper.Install (ue));
623  PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory",
624  InetSocketAddress (Ipv4Address::GetAny (), ulPort));
625  serverApps.Add (ulPacketSinkHelper.Install (remoteHost));
626  }
627  }
628  else // use TCP
629  {
630  if (epcDl)
631  {
632  NS_LOG_LOGIC ("installing TCP DL app for UE " << u);
633  BulkSendHelper dlClientHelper ("ns3::TcpSocketFactory",
634  InetSocketAddress (ueIpIfaces.GetAddress (u), dlPort));
635  dlClientHelper.SetAttribute ("MaxBytes", UintegerValue (0));
636  clientApps.Add (dlClientHelper.Install (remoteHost));
637  PacketSinkHelper dlPacketSinkHelper ("ns3::TcpSocketFactory",
638  InetSocketAddress (Ipv4Address::GetAny (), dlPort));
639  serverApps.Add (dlPacketSinkHelper.Install (ue));
640  }
641  if (epcUl)
642  {
643  NS_LOG_LOGIC ("installing TCP UL app for UE " << u);
644  BulkSendHelper ulClientHelper ("ns3::TcpSocketFactory",
645  InetSocketAddress (remoteHostAddr, ulPort));
646  ulClientHelper.SetAttribute ("MaxBytes", UintegerValue (0));
647  clientApps.Add (ulClientHelper.Install (ue));
648  PacketSinkHelper ulPacketSinkHelper ("ns3::TcpSocketFactory",
649  InetSocketAddress (Ipv4Address::GetAny (), ulPort));
650  serverApps.Add (ulPacketSinkHelper.Install (remoteHost));
651  }
652  }
653  }
654  serverApps.Start (Seconds (0.0));
655  clientApps.Start (Seconds (0.0));
656 
657  } // end if (epc)
658 
659 
660 
661  // activate bearer for all UEs
662  enum EpsBearer::Qci q = EpsBearer::NGBR_VIDEO_TCP_DEFAULT;
663  EpsBearer bearer (q);
664  lteHelper->ActivateEpsBearer (homeUeDevs, bearer, EpcTft::Default ());
665  lteHelper->ActivateEpsBearer (macroUeDevs, bearer, EpcTft::Default ());
666 
667 
668 
669  BuildingsHelper::MakeMobilityModelConsistent ();
670 
672  if (generateRem)
673  {
674  PrintGnuplottableBuildingListToFile ("buildings.txt");
675  PrintGnuplottableEnbListToFile ("enbs.txt");
676  PrintGnuplottableUeListToFile ("ues.txt");
677 
678  remHelper = CreateObject<RadioEnvironmentMapHelper> ();
679  remHelper->SetAttribute ("ChannelPath", StringValue ("/ChannelList/0"));
680  remHelper->SetAttribute ("OutputFile", StringValue ("lena-dual-stripe.rem"));
681  remHelper->SetAttribute ("XMin", DoubleValue (macroUeBox.xMin));
682  remHelper->SetAttribute ("XMax", DoubleValue (macroUeBox.xMax));
683  remHelper->SetAttribute ("YMin", DoubleValue (macroUeBox.yMin));
684  remHelper->SetAttribute ("YMax", DoubleValue (macroUeBox.yMax));
685  remHelper->SetAttribute ("Z", DoubleValue (1.5));
686  remHelper->Install ();
687  // simulation will stop right after the REM has been generated
688 
689 
690  }
691  else
692  {
693  Simulator::Stop (Seconds (simTime));
694  }
695 
696  lteHelper->EnableMacTraces ();
697  lteHelper->EnableRlcTraces ();
698  if (epc)
699  {
700  lteHelper->EnablePdcpTraces ();
701  }
702 
703  Simulator::Run ();
704 
705  //GtkConfigStore config;
706  //config.ConfigureAttributes ();
707 
708  lteHelper = 0;
709  Simulator::Destroy ();
710  return 0;
711 }